Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 43dec08 in mainline


Ignore:
Timestamp:
2011-12-05T00:51:42Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
e44385d
Parents:
c09ad29e
Message:

sb16, dsp: Add external buffer manipulation.

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

Legend:

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

    rc09ad29e r43dec08  
    4545#include "dsp.h"
    4646
     47#define BUFFER_ID 1
    4748#define BUFFER_SIZE (PAGE_SIZE)
    4849#define PLAY_BLOCK_SIZE (BUFFER_SIZE / 2)
     
    146147}
    147148/*----------------------------------------------------------------------------*/
    148 static inline size_t sample_count(uint8_t mode, size_t byte_count)
    149 {
    150         // FIXME we only support 16 bit playback for now.
    151         return byte_count / 2;
    152 
    153         if (mode & DSP_MODE_SIGNED) {
     149static inline size_t sample_count(unsigned sample_size, size_t byte_count)
     150{
     151        if (sample_size == 16) {
    154152                return byte_count / 2;
    155153        }
     
    189187void sb_dsp_interrupt(sb_dsp_t *dsp)
    190188{
     189#if 0
    191190        assert(dsp);
    192191        const size_t remain_size =
     
    232231        sb_dsp_write(dsp, (samples - 1) >> 8);
    233232#endif
    234 
     233#endif
    235234}
    236235/*----------------------------------------------------------------------------*/
     
    282281                dsp->playing.mode |= DSP_MODE_STEREO;
    283282
    284         const size_t samples = sample_count(dsp->playing.mode, play_size);
     283        const size_t samples = sample_count(sample_size, play_size);
    285284
    286285        ddf_log_debug("Playing %s sound: %zu(%zu) bytes => %zu samples.\n",
     
    313312        return EOK;
    314313}
     314/*----------------------------------------------------------------------------*/
     315int sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size, unsigned *id)
     316{
     317        assert(dsp);
     318        const int ret = sb_setup_buffer(dsp);
     319        ddf_log_debug("Providing buffer(%u): %p, %zu.\n",
     320            BUFFER_ID, dsp->buffer.data, dsp->buffer.size);
     321        if (ret == EOK && buffer)
     322                *buffer = dsp->buffer.data;
     323        if (ret == EOK && size)
     324                *size = dsp->buffer.size;
     325        if (ret == EOK && id)
     326                *id = BUFFER_ID;
     327        return ret;
     328}
     329/*----------------------------------------------------------------------------*/
     330int sb_dsp_release_buffer(sb_dsp_t *dsp, unsigned id)
     331{
     332        assert(dsp);
     333        if (id != BUFFER_ID)
     334                return ENOENT;
     335        sb_clear_buffer(dsp);
     336        return EOK;
     337}
     338/*----------------------------------------------------------------------------*/
     339int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned sampling_rate,
     340    unsigned sample_size, unsigned channels, bool sign)
     341{
     342        assert(dsp);
     343
     344        /* Check supported parameters */
     345        ddf_log_debug("Starting playback on buffer(%u): rate: %u, size: %u, "
     346            " channels: %u, signed: %s.\n", id, sampling_rate, sample_size,
     347            channels, sign ? "YES" : "NO" );
     348        if (id != BUFFER_ID)
     349                return ENOENT;
     350        if (sample_size != 16) // FIXME We only support 16 bit playback
     351                return ENOTSUP;
     352        if (channels != 1 && channels != 2)
     353                return ENOTSUP;
     354        if (sampling_rate > 44100)
     355                return ENOTSUP;
     356
     357
     358        sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
     359        sb_dsp_write(dsp, sampling_rate >> 8);
     360        sb_dsp_write(dsp, sampling_rate & 0xff);
     361
     362        ddf_log_debug("Sampling rate: %hhx:%hhx.\n",
     363            sampling_rate >> 8, sampling_rate & 0xff);
     364
     365#ifdef AUTO_DMA_MODE
     366        sb_dsp_write(dsp, AUTO_DMA_16B_DA_FIFO);
     367#else
     368        sb_dsp_write(dsp, SINGLE_DMA_16B_DA_FIFO);
     369#endif
     370
     371        const uint8_t mode =
     372            (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0);
     373        sb_dsp_write(dsp, mode);
     374
     375        const uint16_t samples = sample_count(sample_size, PLAY_BLOCK_SIZE);
     376        sb_dsp_write(dsp, (samples - 1) & 0xff);
     377        sb_dsp_write(dsp, (samples - 1) >> 8);
     378
     379        return EOK;
     380        return ENOTSUP;
     381}
     382/*----------------------------------------------------------------------------*/
     383int sb_dsp_stop_playback(sb_dsp_t *dsp, unsigned id)
     384{
     385        assert(dsp);
     386        if (id != BUFFER_ID)
     387                return ENOENT;
     388        sb_dsp_write(dsp, DMA_16B_EXIT);
     389        return EOK;
     390}
     391/*----------------------------------------------------------------------------*/
     392int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned sample_rate,
     393    unsigned sample_size, unsigned channels, bool sign)
     394{
     395        return ENOTSUP;
     396}
     397/*----------------------------------------------------------------------------*/
     398int sb_dsp_stop_record(sb_dsp_t *dsp, unsigned id)
     399{
     400        return ENOTSUP;
     401}
    315402/**
    316403 * @}
  • uspace/drv/audio/sb16/dsp.h

    rc09ad29e r43dec08  
    7171    uint16_t sample_rate, unsigned channels, unsigned bit_depth);
    7272
     73int sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size, unsigned *id);
     74int sb_dsp_release_buffer(sb_dsp_t *dsp, unsigned id);
     75int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned sample_rate,
     76    unsigned sample_size, unsigned channels, bool sign);
     77int sb_dsp_stop_playback(sb_dsp_t *dsp, unsigned id);
     78int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned sample_rate,
     79    unsigned sample_size, unsigned channels, bool sign);
     80int sb_dsp_stop_record(sb_dsp_t *dsp, unsigned id);
     81
    7382#endif
    7483/**
Note: See TracChangeset for help on using the changeset viewer.