Changeset a3ab774 in mainline


Ignore:
Timestamp:
2012-07-07T21:26:04Z (12 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
Files:
5 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
  • uspace/lib/drv/generic/remote_audio_pcm_buffer.c

    ref246b9 ra3ab774  
    140140
    141141int audio_pcm_buffer_start_record(async_exch_t *exch, unsigned id,
    142     unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign)
    143 {
    144         if (!exch || sample_size > UINT16_MAX || channels > (UINT16_MAX >> 1))
    145                 return EINVAL;
    146         sysarg_t packed = sample_size << 16 | channels << 1 | sign ? 1 : 0;
     142    unsigned parts, unsigned sample_rate, uint16_t sample_size,
     143    uint8_t channels, bool sign)
     144{
     145        if (!exch)
     146                return EINVAL;
     147        sysarg_t packed =
     148            (sample_size << 16) | (channels << 8) |
     149            ((parts & 0x7f) << 1) | (sign ? 1 : 0);
    147150        return async_req_4_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
    148151            IPC_M_AUDIO_PCM_START_RECORD, id, sample_rate, packed);
     
    336339        const unsigned rate = DEV_IPC_GET_ARG2(*call);
    337340        const unsigned size = DEV_IPC_GET_ARG3(*call) >> 16;
    338         const unsigned channels = (DEV_IPC_GET_ARG3(*call) & UINT16_MAX) >> 1;
     341        const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 8) & UINT8_MAX;
     342        const unsigned parts = (DEV_IPC_GET_ARG3(*call) >> 1) & 0x7f;
    339343        const bool sign = (bool)(DEV_IPC_GET_ARG3(*call) & 1);
    340344
    341345        const int ret = pcm_iface->start_record
    342             ? pcm_iface->start_record(fun, id, rate, size, channels, sign)
     346            ? pcm_iface->start_record(fun, id, parts, rate, size, channels, sign)
    343347            : ENOTSUP;
    344348        async_answer_0(callid, ret);
  • uspace/lib/drv/include/audio_pcm_buffer_iface.h

    ref246b9 ra3ab774  
    5151int audio_pcm_buffer_stop_playback(async_exch_t *, unsigned);
    5252
    53 int audio_pcm_buffer_start_record(async_exch_t *, unsigned,
    54     unsigned, unsigned, unsigned, bool);
     53int audio_pcm_buffer_start_record(async_exch_t *, unsigned, unsigned,
     54    unsigned, uint16_t, uint8_t, bool);
    5555int audio_pcm_buffer_stop_record(async_exch_t *, unsigned);
    5656
     
    6464            unsigned, unsigned, unsigned, bool);
    6565        int (*stop_playback)(ddf_fun_t *, unsigned);
    66         int (*start_record)(ddf_fun_t *, unsigned,
     66        int (*start_record)(ddf_fun_t *, unsigned, unsigned,
    6767            unsigned, unsigned, unsigned, bool);
    6868        int (*stop_record)(ddf_fun_t *, unsigned);
Note: See TracChangeset for help on using the changeset viewer.