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


Ignore:
Timestamp:
2012-07-15T15:25:43Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5cd5079
Parents:
2cc5c835
Message:

Add frame count to event report.

This enables applications to detect underruns.

File:
1 edited

Legend:

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

    r2cc5c835 r57e8b3b  
    188188{
    189189        assert(dsp);
     190        dsp->active.frame_count +=
     191            dsp->active.samples / ((dsp->active.mode & DSP_MODE_STEREO) ? 2 : 1);
     192
    190193        if (dsp->event_exchange) {
    191194                switch (dsp->status) {
    192195                case DSP_PLAYBACK:
    193                         async_msg_0(dsp->event_exchange,
    194                             PCM_EVENT_PLAYBACK_DONE);
     196                        async_msg_1(dsp->event_exchange,
     197                            PCM_EVENT_FRAMES_PLAYED, dsp->active.frame_count);
    195198                        break;
    196199                case DSP_RECORDING:
    197                         async_msg_0(dsp->event_exchange,
    198                             PCM_EVENT_RECORDING_DONE);
     200                        async_msg_1(dsp->event_exchange,
     201                            PCM_EVENT_FRAMES_RECORDED, dsp->active.frame_count);
    199202                        break;
    200203                default:
     
    267270}
    268271
    269 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned parts,
     272int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames,
    270273    unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
    271274{
     
    275278                return EINVAL;
    276279
    277         /* Play block size must be even number (we use DMA 16)*/
    278         if (dsp->buffer.size % (parts * 2))
    279                 return EINVAL;
    280 
    281         const unsigned play_block_size = dsp->buffer.size / parts;
    282 
    283280        /* Check supported parameters */
    284         ddf_log_debug("Requested playback (%u parts): %uHz, %s, %u channel(s).",
    285             parts, sampling_rate, pcm_sample_format_str(format), channels);
     281        ddf_log_debug("Requested playback: %u frames, %uHz, %s, %u channel(s).",
     282            frames, sampling_rate, pcm_sample_format_str(format), channels);
    286283        if (channels != 1 && channels != 2)
    287284                return ENOTSUP;
     
    311308#endif
    312309
    313         dsp->active.mode = 0 |
    314             (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0);
     310        dsp->active.mode = 0
     311            | (sign ? DSP_MODE_SIGNED : 0)
     312            | (channels == 2 ? DSP_MODE_STEREO : 0);
     313        dsp->active.samples = frames * channels;
     314        dsp->active.frame_count = 0;
     315
    315316        sb_dsp_write(dsp, dsp->active.mode);
    316 
    317         dsp->active.samples = sample_count(format, play_block_size);
    318317        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    319318        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     
    339338}
    340339
    341 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned parts,
     340int sb_dsp_start_record(sb_dsp_t *dsp, unsigned frames,
    342341    unsigned channels, unsigned sampling_rate, pcm_sample_format_t format)
    343342{
     
    347346                return EINVAL;
    348347
    349         /* Play block size must be even number (we use DMA 16)*/
    350         if (dsp->buffer.size % (parts * 2))
    351                 return EINVAL;
    352 
    353         const unsigned play_block_size = dsp->buffer.size / parts;
    354 
    355348        /* Check supported parameters */
    356         ddf_log_debug("Requested record (%u parts): %uHz, %s, %u channel(s).",
    357             parts, sampling_rate, pcm_sample_format_str(format), channels);
     349        ddf_log_debug("Requested record: %u frames, %uHz, %s, %u channel(s).",
     350            frames, sampling_rate, pcm_sample_format_str(format), channels);
    358351        if (channels != 1 && channels != 2)
    359352                return ENOTSUP;
     
    384377
    385378        dsp->active.mode = 0 |
    386             (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0);
     379            (sign ? DSP_MODE_SIGNED : 0) |
     380            (channels == 2 ? DSP_MODE_STEREO : 0);
     381        dsp->active.samples = frames * channels;
     382        dsp->active.frame_count = 0;
     383
    387384        sb_dsp_write(dsp, dsp->active.mode);
    388 
    389         dsp->active.samples = sample_count(format, play_block_size);
    390385        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
    391386        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
Note: See TracChangeset for help on using the changeset viewer.