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


Ignore:
Timestamp:
2011-10-21T16:48:27Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9f351c8
Parents:
1a11a16
Message:

sb16: Add lazy buffer initialization.

File:
1 edited

Legend:

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

    r1a11a16 r01aef43  
    3434
    3535#include <libarch/ddi.h>
     36#include <str_error.h>
    3637
    3738#include "dma.h"
     
    4748
    4849#define DSP_RESET_RESPONSE 0xaa
     50#define SB_DMA_CHAN_16 5
     51#define SB_DMA_CHAN_8 1
    4952
    5053static inline int sb_dsp_read(sb_dsp_t *dsp, uint8_t *data)
     
    9093}
    9194/*----------------------------------------------------------------------------*/
     95static inline int sb_setup_buffer(sb_dsp_t *dsp)
     96{
     97        assert(dsp);
     98        uint8_t *buffer = malloc24(PAGE_SIZE);
     99
     100        const uintptr_t pa = addr_to_phys(buffer);
     101        const int ret = dma_setup_channel(SB_DMA_CHAN_16, pa, PAGE_SIZE);
     102        if (ret == EOK) {
     103                dsp->buffer.buffer_data = buffer;
     104                dsp->buffer.buffer_position = buffer;
     105                dsp->buffer.buffer_size = PAGE_SIZE;
     106        } else {
     107                ddf_log_error("Failed to setup DMA buffer %s.\n",
     108                    str_error(ret));
     109                free24(buffer);
     110        }
     111        return ret;
     112}
     113/*----------------------------------------------------------------------------*/
    92114int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs)
    93115{
     
    112134        sb_dsp_read(dsp, &dsp->version.major);
    113135        sb_dsp_read(dsp, &dsp->version.minor);
    114         return EOK;
     136
     137        return ret;
    115138}
    116139/*----------------------------------------------------------------------------*/
     
    130153        return EOK;
    131154}
     155/*----------------------------------------------------------------------------*/
     156int sb_dsp_play(sb_dsp_t *dsp, const uint8_t *data, size_t size,
     157    unsigned sampling_rate, unsigned channels, unsigned bit_depth)
     158{
     159        assert(dsp);
     160        if (!data)
     161                return EOK;
     162
     163        /* Check supported parameters */
     164        if (bit_depth != 8 && bit_depth != 16)
     165                return ENOTSUP;
     166        if (channels != 1 && channels != 2)
     167                return ENOTSUP;
     168
     169        const int ret = sb_setup_buffer(dsp);
     170
     171        return ret;
     172}
    132173/**
    133174 * @}
Note: See TracChangeset for help on using the changeset viewer.