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


Ignore:
Timestamp:
2012-07-11T12:05:30Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
039337e8
Parents:
94694a4
Message:

audio: Use enum for sample format.

File:
1 edited

Legend:

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

    r94694a4 r346643c  
    147147}
    148148
    149 static inline size_t sample_count(unsigned sample_size, size_t byte_count)
    150 {
    151         if (sample_size == 16) {
    152                 return byte_count / 2;
    153         }
    154         return byte_count;
     149static inline size_t sample_count(pcm_sample_format_t format, size_t byte_count)
     150{
     151        return byte_count / pcm_sample_format_size(format);
    155152}
    156153
     
    261258
    262259int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned parts,
    263     unsigned sampling_rate, unsigned sample_size, unsigned channels, bool sign)
     260    unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
    264261{
    265262        assert(dsp);
     
    276273        /* Check supported parameters */
    277274        ddf_log_debug("Requested playback on buffer \"%u\" (%u parts): %uHz, "
    278             "%ssinged %u bit, %u channel(s).", id, parts, sampling_rate,
    279             sign ? "" : "un", sample_size, channels);
    280         if (id != BUFFER_ID)
    281                 return ENOENT;
    282         if (sample_size != 16) // FIXME We only support 16 bit playback
    283                 return ENOTSUP;
     275            "%s, %u channel(s).", id, parts, sampling_rate,
     276            pcm_sample_format_str(format), channels);
     277        if (id != BUFFER_ID)
     278                return ENOENT;
    284279        if (channels != 1 && channels != 2)
    285280                return ENOTSUP;
    286281        if (sampling_rate > 44100)
     282                return ENOTSUP;
     283        // FIXME We only support 16 bit playback
     284        if (format != PCM_SAMPLE_UINT16_LE && format != PCM_SAMPLE_SINT16_LE)
    287285                return ENOTSUP;
    288286
     
    291289                return ENOMEM;
    292290
     291        const bool sign = (format == PCM_SAMPLE_SINT16_LE);
     292
    293293        sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
    294294        sb_dsp_write(dsp, sampling_rate >> 8);
    295295        sb_dsp_write(dsp, sampling_rate & 0xff);
    296296
    297         ddf_log_verbose("Sampling rate: %hhx:%hhx.",
     297        ddf_log_verbose("Sample rate: %hhx:%hhx.",
    298298            sampling_rate >> 8, sampling_rate & 0xff);
    299299
     
    308308        sb_dsp_write(dsp, dsp->active.mode);
    309309
    310         dsp->active.samples = sample_count(sample_size, play_block_size);
     310        dsp->active.samples = sample_count(format, play_block_size);
    311311        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    312312        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     
    314314        ddf_log_verbose("Playback started, interrupt every %u samples "
    315315            "(~1/%u sec)", dsp->active.samples,
    316             sampling_rate / dsp->active.samples);
     316            sampling_rate / (dsp->active.samples * channels));
    317317
    318318        dsp->active.playing = true;
     
    332332
    333333int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned parts,
    334     unsigned sampling_rate, unsigned sample_size, unsigned channels, bool sign)
     334    unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
    335335{
    336336        assert(dsp);
     
    347347        /* Check supported parameters */
    348348        ddf_log_debug("Requested recording on buffer \"%u\" (%u parts): %uHz, "
    349             "%ssinged %u bit, %u channel(s).", id, parts, sampling_rate,
    350             sign ? "" : "un", sample_size, channels);
    351         if (id != BUFFER_ID)
    352                 return ENOENT;
    353         if (sample_size != 16) // FIXME We only support 16 bit playback
    354                 return ENOTSUP;
     349            "%s, %u channel(s).", id, parts, sampling_rate,
     350            pcm_sample_format_str(format), channels);
     351        if (id != BUFFER_ID)
     352                return ENOENT;
    355353        if (channels != 1 && channels != 2)
    356354                return ENOTSUP;
    357355        if (sampling_rate > 44100)
     356                return ENOTSUP;
     357        // FIXME We only support 16 bit recording
     358        if (format != PCM_SAMPLE_UINT16_LE && format != PCM_SAMPLE_SINT16_LE)
    358359                return ENOTSUP;
    359360
     
    361362        if (!dsp->event_exchange)
    362363                return ENOMEM;
     364
     365        const bool sign = (format == PCM_SAMPLE_SINT16_LE);
    363366
    364367        sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
     
    379382        sb_dsp_write(dsp, dsp->active.mode);
    380383
    381         dsp->active.samples = sample_count(sample_size, play_block_size);
     384        dsp->active.samples = sample_count(format, play_block_size);
    382385        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    383386        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     
    385388        ddf_log_verbose("Recording started started, interrupt every %u samples "
    386389            "(~1/%u sec)", dsp->active.samples,
    387             sampling_rate / dsp->active.samples);
     390            sampling_rate / (dsp->active.samples * channels));
    388391        dsp->active.playing = false;
    389392
Note: See TracChangeset for help on using the changeset viewer.