Changeset a3ab774 in mainline for uspace/drv/audio/sb16


Ignore:
Timestamp:
2012-07-07T21:26:04Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e1b7e36
Parents:
ef246b9
Message:

libdrv/audio,drv/audio/sb16: Update and implement recording interface.

Untested.

Location:
uspace/drv/audio/sb16
Files:
3 edited

Legend:

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

    ref246b9 ra3ab774  
    196196        }
    197197#ifndef AUTO_DMA_MODE
    198         sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
    199         sb_dsp_write(dsp, dsp->playing.mode);
    200         sb_dsp_write(dsp, (dsp->playing.samples - 1) & 0xff);
    201         sb_dsp_write(dsp, (dsp->playing.samples - 1) >> 8);
     198        if (dsp->active.playing)
     199                sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
     200        else
     201                sb_dsp_write(dsp, SINGLE_DMA_16B_AD);
     202
     203        sb_dsp_write(dsp, dsp->active.mode);
     204        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
     205        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
    202206#endif
    203207}
     
    271275
    272276        /* Check supported parameters */
    273         ddf_log_debug("Requested playback on buffer \"%u\" (%u parts): %uHz, "
     277        ddf_log_debug("Requested recording on buffer \"%u\" (%u parts): %uHz, "
    274278            "%ssinged %u bit, %u channel(s).", id, parts, sampling_rate,
    275279            sign ? "" : "un", sample_size, channels);
     
    300304#endif
    301305
    302         dsp->playing.mode = 0 |
     306        dsp->active.mode = 0 |
    303307            (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0);
    304         sb_dsp_write(dsp, dsp->playing.mode);
    305 
    306         dsp->playing.samples = sample_count(sample_size, play_block_size);
    307         sb_dsp_write(dsp, (dsp->playing.samples - 1) & 0xff);
    308         sb_dsp_write(dsp, (dsp->playing.samples - 1) >> 8);
     308        sb_dsp_write(dsp, dsp->active.mode);
     309
     310        dsp->active.samples = sample_count(sample_size, play_block_size);
     311        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
     312        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
    309313
    310314        ddf_log_verbose("Playback started, interrupt every %u samples "
    311             "(~1/%u sec)", dsp->playing.samples,
    312             sampling_rate / dsp->playing.samples);
     315            "(~1/%u sec)", dsp->active.samples,
     316            sampling_rate / dsp->active.samples);
     317
     318        dsp->active.playing = true;
    313319
    314320        return EOK;
     
    325331}
    326332
    327 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned sample_rate,
    328     unsigned sample_size, unsigned channels, bool sign)
    329 {
    330         return ENOTSUP;
     333int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned parts,
     334    unsigned sampling_rate, unsigned sample_size, unsigned channels, bool sign)
     335{
     336        assert(dsp);
     337
     338        if (!dsp->event_session)
     339                return EINVAL;
     340
     341        /* Play block size must be even number (we use DMA 16)*/
     342        if (dsp->buffer.size % (parts * 2))
     343                return EINVAL;
     344
     345        const unsigned play_block_size = dsp->buffer.size / parts;
     346
     347        /* Check supported parameters */
     348        ddf_log_debug("Requested playback 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;
     355        if (channels != 1 && channels != 2)
     356                return ENOTSUP;
     357        if (sampling_rate > 44100)
     358                return ENOTSUP;
     359
     360        dsp->event_exchange = async_exchange_begin(dsp->event_session);
     361        if (!dsp->event_exchange)
     362                return ENOMEM;
     363
     364        sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
     365        sb_dsp_write(dsp, sampling_rate >> 8);
     366        sb_dsp_write(dsp, sampling_rate & 0xff);
     367
     368        ddf_log_verbose("Sampling rate: %hhx:%hhx.",
     369            sampling_rate >> 8, sampling_rate & 0xff);
     370
     371#ifdef AUTO_DMA_MODE
     372        sb_dsp_write(dsp, AUTO_DMA_16B_AD_FIFO);
     373#else
     374        sb_dsp_write(dsp, SINGLE_DMA_16B_AD_FIFO);
     375#endif
     376
     377        dsp->active.mode = 0 |
     378            (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0);
     379        sb_dsp_write(dsp, dsp->active.mode);
     380
     381        dsp->active.samples = sample_count(sample_size, play_block_size);
     382        sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff);
     383        sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8);
     384
     385        ddf_log_verbose("Recording started started, interrupt every %u samples "
     386            "(~1/%u sec)", dsp->active.samples,
     387            sampling_rate / dsp->active.samples);
     388        dsp->active.playing = false;
     389
     390        return EOK;
    331391}
    332392
    333393int sb_dsp_stop_record(sb_dsp_t *dsp, unsigned id)
    334394{
    335         return ENOTSUP;
     395        assert(dsp);
     396        if (id != BUFFER_ID)
     397                return ENOENT;
     398        async_exchange_end(dsp->event_exchange);
     399        sb_dsp_write(dsp, DMA_16B_EXIT);
     400        return EOK;
    336401}
    337402/**
  • uspace/drv/audio/sb16/dsp.h

    ref246b9 ra3ab774  
    5656                uint8_t mode;
    5757                uint16_t samples;
    58         } playing;
     58                bool playing;
     59        } active;
    5960        async_sess_t *event_session;
    6061        async_exch_t *event_exchange;
     
    7273    unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign);
    7374int sb_dsp_stop_playback(sb_dsp_t *dsp, unsigned id);
    74 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned sample_rate,
    75     unsigned sample_size, unsigned channels, bool sign);
     75int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned parts,
     76    unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign);
    7677int sb_dsp_stop_record(sb_dsp_t *dsp, unsigned id);
    7778
  • uspace/drv/audio/sb16/pcm_iface.c

    ref246b9 ra3ab774  
    8888}
    8989
    90 static int sb_start_record(ddf_fun_t *fun, unsigned id,
     90static int sb_start_record(ddf_fun_t *fun, unsigned id, unsigned parts,
    9191    unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign)
    9292{
     
    9595        sb_dsp_t *dsp = fun->driver_data;
    9696        return sb_dsp_start_record(
    97             dsp, id, sample_rate, sample_size, channels, sign);
     97            dsp, id, parts, sample_rate, sample_size, channels, sign);
    9898}
    9999
Note: See TracChangeset for help on using the changeset viewer.