Changeset 0b4f060 in mainline


Ignore:
Timestamp:
2011-10-24T21:36:52Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6233c4e
Parents:
7785e951
Message:

sb16: Fix sample counts. Add barriers.

DSP takes count in samples not bytes.

File:
1 edited

Legend:

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

    r7785e951 r0b4f060  
    3434
    3535#include <libarch/ddi.h>
     36#include <libarch/barrier.h>
    3637#include <str_error.h>
    3738
     
    4142#include "dsp_commands.h"
    4243#include "dsp.h"
     44
     45#define PLAYBACK_16BIT 0x10
     46#define PLAYBACK_STEREO 0x20
    4347
    4448#define BUFFER_SIZE (PAGE_SIZE / 4)
     
    139143}
    140144/*----------------------------------------------------------------------------*/
     145static inline size_t sample_count(uint8_t mode, size_t byte_count)
     146{
     147        if (mode & PLAYBACK_16BIT) {
     148                return byte_count / 2;
     149        }
     150        return byte_count;
     151}
     152/*----------------------------------------------------------------------------*/
    141153int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs)
    142154{
     
    195207                /* This is the last block */
    196208                memcpy(dsp->buffer.position, dsp->playing.position, remain_size);
     209                write_barrier();
    197210                dsp->playing.position += remain_size;
    198211                dsp->buffer.position += remain_size;
     212                const size_t samples =
     213                    sample_count(dsp->playing.mode, remain_size);
    199214                sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
    200215                sb_dsp_write(dsp, dsp->playing.mode);
    201                 sb_dsp_write(dsp, (remain_size - 1) & 0xff);
    202                 sb_dsp_write(dsp, (remain_size - 1) >> 8);
     216                sb_dsp_write(dsp, (samples - 1) & 0xff);
     217                sb_dsp_write(dsp, (samples - 1) >> 8);
    203218                return;
    204219        }
    205220        ddf_log_note("Playing full block.\n");
    206221        memcpy(dsp->buffer.position, dsp->playing.position, PLAY_BLOCK_SIZE);
     222        write_barrier();
    207223        dsp->playing.position += PLAY_BLOCK_SIZE;
    208224        dsp->buffer.position += PLAY_BLOCK_SIZE;
     
    236252/*----------------------------------------------------------------------------*/
    237253int sb_dsp_play(sb_dsp_t *dsp, const uint8_t *data, size_t size,
    238     uint16_t sampling_rate, unsigned channels, unsigned bit_depth)
     254    uint16_t sampling_rate, unsigned channels, unsigned sample_size)
    239255{
    240256        assert(dsp);
     
    243259
    244260        /* Check supported parameters */
    245         if (bit_depth != 8 && bit_depth != 16)
     261        if (sample_size != 8 && sample_size != 16)
    246262                return ENOTSUP;
    247263        if (channels != 1 && channels != 2)
     
    258274            size < BUFFER_SIZE ? size : BUFFER_SIZE;
    259275
    260 
    261276        dsp->playing.data = data;
    262277        dsp->playing.position = data + copy_size;
    263278        dsp->playing.size = size;
    264         dsp->playing.mode =
    265             (bit_depth == 16 ? 0x10 : 0) | (channels == 2 ? 0x20 : 0);
    266         ddf_log_debug("Setting DSP mode %hhx.\n", dsp->playing.mode);
    267 
    268         ddf_log_debug("Playing sound: %zu(%zu) bytes.\n", play_size, size);
     279        dsp->playing.mode = 0;
     280        if (sample_size == 16)
     281                dsp->playing.mode |= PLAYBACK_16BIT;
     282        if (channels == 2)
     283                dsp->playing.mode |= PLAYBACK_STEREO;
     284
     285        const size_t samples = sample_count(dsp->playing.mode, play_size);
     286
     287        ddf_log_debug("Playing sound(%hhx): %zu(%zu) bytes => %zu samples.\n",
     288            dsp->playing.mode, play_size, size, samples);
     289
    269290        memcpy(dsp->buffer.data, dsp->playing.data, copy_size);
     291        write_barrier();
    270292
    271293        sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
     
    273295        sb_dsp_write(dsp, sampling_rate & 0xff);
    274296
    275         ddf_log_debug("Set sampling rate %hhx:%hhx.\n",
     297        ddf_log_debug("Sampling rate: %hhx:%hhx.\n",
    276298            sampling_rate >> 8, sampling_rate & 0xff);
    277299
     
    282304        }
    283305        sb_dsp_write(dsp, dsp->playing.mode);
    284         sb_dsp_write(dsp, (play_size - 1) & 0xff);
    285         sb_dsp_write(dsp, (play_size - 1) >> 8);
     306        sb_dsp_write(dsp, (samples - 1) & 0xff);
     307        sb_dsp_write(dsp, (samples - 1) >> 8);
    286308
    287309        return EOK;
Note: See TracChangeset for help on using the changeset viewer.