Changeset ad42844 in mainline for uspace/drv/audio/sb16/dsp.c


Ignore:
Timestamp:
2012-08-19T14:17:16Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d86c9736
Parents:
d758301
Message:

sb16: Use more helper functions instead of duplicating code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/dsp.c

    rd758301 rad42844  
    101101}
    102102
     103static inline void sb_dsp_start_active(sb_dsp_t *dsp, uint8_t command)
     104{
     105        sb_dsp_write(dsp, command);
     106        sb_dsp_write(dsp, dsp->active.mode);
     107        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
     108        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     109}
     110
     111static inline void sb_dsp_set_sampling_rate(sb_dsp_t *dsp, unsigned rate)
     112{
     113        sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
     114        sb_dsp_write(dsp, rate >> 8);
     115        sb_dsp_write(dsp, rate & 0xff);
     116        ddf_log_verbose("Sampling rate: %hhx:%hhx.", rate >> 8, rate & 0xff);
     117}
     118
    103119static inline int sb_setup_dma(sb_dsp_t *dsp, uintptr_t pa, size_t size)
    104120{
     
    196212#ifndef AUTO_DMA_MODE
    197213        if (dsp->status == DSP_PLAYBACK) {
    198                 sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
    199                 sb_dsp_write(dsp, dsp->active.mode);
    200                 sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    201                 sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     214                sb_dsp_start_active(dsp, SINGLE_DMA_16B_DA);
    202215        }
    203216
    204217        if (dsp->status == DSP_RECORDING) {
    205                 sb_dsp_write(dsp, SINGLE_DMA_16B_AD);
    206                 sb_dsp_write(dsp, dsp->active.mode);
    207                 sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    208                 sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     218                sb_dsp_start_active(dsp, SINGLE_DMA_16B_AD);
    209219        }
    210220#endif
     
    349359        }
    350360
    351         const bool sign = (format == PCM_SAMPLE_SINT16_LE);
    352 
    353         sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
    354         sb_dsp_write(dsp, sampling_rate >> 8);
    355         sb_dsp_write(dsp, sampling_rate & 0xff);
    356 
    357         ddf_log_verbose("Sample rate: %hhx:%hhx.",
    358             sampling_rate >> 8, sampling_rate & 0xff);
    359 
    360 #ifdef AUTO_DMA_MODE
    361         sb_dsp_write(dsp, AUTO_DMA_16B_DA_FIFO);
    362 #else
    363         sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
    364 #endif
    365 
    366361        dsp->active.mode = 0
    367             | (sign ? DSP_MODE_SIGNED : 0)
     362            | (pcm_sample_format_is_signed(format) ? DSP_MODE_SIGNED : 0)
    368363            | (channels == 2 ? DSP_MODE_STEREO : 0);
    369364        dsp->active.samples = frames * channels;
    370365        dsp->active.frame_count = 0;
    371366
    372         sb_dsp_write(dsp, dsp->active.mode);
    373         sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    374         sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     367        sb_dsp_set_sampling_rate(dsp, sampling_rate);
     368
     369#ifdef AUTO_DMA_MODE
     370        sb_dsp_start_active(dsp, AUTO_DMA_16B_DA_FIFO);
     371#else
     372        sb_dsp_start_active(dsp, SINGLE_DMA_16B_DA);
     373#endif
    375374
    376375        ddf_log_verbose("Playback started, interrupt every %u samples "
     
    417416        }
    418417
    419         const bool sign = (format == PCM_SAMPLE_SINT16_LE);
    420 
    421         sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
    422         sb_dsp_write(dsp, sampling_rate >> 8);
    423         sb_dsp_write(dsp, sampling_rate & 0xff);
    424 
    425         ddf_log_verbose("Sampling rate: %hhx:%hhx.",
    426             sampling_rate >> 8, sampling_rate & 0xff);
    427 
    428 #ifdef AUTO_DMA_MODE
    429         sb_dsp_write(dsp, AUTO_DMA_16B_AD_FIFO);
    430 #else
    431         sb_dsp_write(dsp, SINGLE_DMA_16B_AD);
    432 #endif
    433 
    434         dsp->active.mode = 0 |
    435             (sign ? DSP_MODE_SIGNED : 0) |
    436             (channels == 2 ? DSP_MODE_STEREO : 0);
     418        dsp->active.mode = 0
     419            | (pcm_sample_format_is_signed(format) ? DSP_MODE_SIGNED : 0)
     420            | (channels == 2 ? DSP_MODE_STEREO : 0);
    437421        dsp->active.samples = frames * channels;
    438422        dsp->active.frame_count = 0;
    439423
    440         sb_dsp_write(dsp, dsp->active.mode);
    441         sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    442         sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     424        sb_dsp_set_sampling_rate(dsp, sampling_rate);
     425
     426#ifdef AUTO_DMA_MODE
     427        sb_dsp_start_active(dsp, AUTO_DMA_16B_AD_FIFO);
     428#else
     429        sb_dsp_start_active(dsp, SINGLE_DMA_16B_AD);
     430#endif
    443431
    444432        ddf_log_verbose("Recording started started, interrupt every %u samples "
Note: See TracChangeset for help on using the changeset viewer.