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


Ignore:
Timestamp:
2011-12-05T15:20:50Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c0149cc
Parents:
b499127
Message:

sb16, dsp: Remove internal playback functions.

External playback works reasonably well.

File:
1 edited

Legend:

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

    rb499127 rc17c872c  
    128128        if (ret == EOK) {
    129129                dsp->buffer.data = buffer;
    130                 dsp->buffer.position = buffer;
    131130                dsp->buffer.size = BUFFER_SIZE;
    132131                bzero(buffer, BUFFER_SIZE);
     
    143142        dma_destroy_buffer(dsp->buffer.data);
    144143        dsp->buffer.data = NULL;
    145         dsp->buffer.position = NULL;
    146144        dsp->buffer.size = 0;
    147145}
     
    187185void sb_dsp_interrupt(sb_dsp_t *dsp)
    188186{
    189 #if 0
    190         assert(dsp);
    191         const size_t remain_size =
    192             dsp->playing.size - (dsp->playing.position - dsp->playing.data);
    193 
    194         if (remain_size == 0) {
    195 #ifdef AUTO_DMA_MODE
    196                 sb_dsp_write(dsp, DMA_16B_EXIT);
     187#ifndef AUTO_DMA_MODE
     188        assert(dsp);
     189        sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
     190        sb_dsp_write(dsp, dsp->playing.mode);
     191        sb_dsp_write(dsp, (dsp->playing.samples - 1) & 0xff);
     192        sb_dsp_write(dsp, (dsp->playing.samples - 1) >> 8);
    197193#endif
    198                 ddf_log_note("Nothing more to play");
    199                 sb_clear_buffer(dsp);
    200                 return;
    201         }
    202         if (remain_size <= PLAY_BLOCK_SIZE) {
    203                 ddf_log_note("Last %zu bytes to play.\n", remain_size);
    204                 /* This is the last block */
    205                 memcpy(dsp->buffer.position, dsp->playing.position, remain_size);
    206                 write_barrier();
    207                 dsp->playing.position += remain_size;
    208                 dsp->buffer.position += remain_size;
    209                 const size_t samples =
    210                     sample_count(dsp->playing.mode, remain_size);
    211                 sb_dsp_write(dsp, SINGLE_DMA_16B_DA);
    212                 sb_dsp_write(dsp, dsp->playing.mode);
    213                 sb_dsp_write(dsp, (samples - 1) & 0xff);
    214                 sb_dsp_write(dsp, (samples - 1) >> 8);
    215                 return;
    216         }
    217         /* Copy new data */
    218         memcpy(dsp->buffer.position, dsp->playing.position, PLAY_BLOCK_SIZE);
    219         write_barrier();
    220         /* Adjust position */
    221         dsp->playing.position += PLAY_BLOCK_SIZE;
    222         dsp->buffer.position += PLAY_BLOCK_SIZE;
    223         /* Wrap around */
    224         if (dsp->buffer.position == (dsp->buffer.data + dsp->buffer.size))
    225                 dsp->buffer.position = dsp->buffer.data;
    226 #ifndef AUTO_DMA_MODE
    227         const size_t samples = sample_count(dsp->playing.mode, PLAY_BLOCK_SIZE);
    228         sb_dsp_write(dsp, SINGLE_DMA_16B_DA_FIFO);
    229         sb_dsp_write(dsp, dsp->playing.mode);
    230         sb_dsp_write(dsp, (samples - 1) & 0xff);
    231         sb_dsp_write(dsp, (samples - 1) >> 8);
    232 #endif
    233 #endif
    234 }
    235 /*----------------------------------------------------------------------------*/
    236 int sb_dsp_play_direct(sb_dsp_t *dsp, const uint8_t *data, size_t size,
    237     unsigned sampling_rate, unsigned channels, unsigned bit_depth)
    238 {
    239         assert(dsp);
    240         if (channels != 1 || bit_depth != 8)
    241                 return EIO;
    242         /* In microseconds */
    243         const unsigned wait_period = 1000000 / sampling_rate;
    244         while (size--) {
    245                 pio_write_8(&dsp->regs->dsp_write, DIRECT_8B_OUTPUT);
    246                 pio_write_8(&dsp->regs->dsp_write, *data++);
    247                 udelay(wait_period);
    248         }
    249         return EOK;
    250 }
    251 /*----------------------------------------------------------------------------*/
    252 int sb_dsp_play(sb_dsp_t *dsp, const void *data, size_t size,
    253     uint16_t sampling_rate, unsigned channels, unsigned sample_size)
    254 {
    255         assert(dsp);
    256         if (!data)
    257                 return EOK;
    258 
    259         /* Check supported parameters */
    260         if (sample_size != 16) // FIXME We only support 16 bit playback
    261                 return ENOTSUP;
    262         if (channels != 1 && channels != 2)
    263                 return ENOTSUP;
    264 
    265         ddf_log_debug("Buffer prepare.\n");
    266         const int ret = sb_setup_buffer(dsp);
    267         if (ret != EOK)
    268                 return ret;
    269 
    270         const size_t copy_size = size < BUFFER_SIZE ? size : BUFFER_SIZE;
    271         const size_t play_size =
    272             size < PLAY_BLOCK_SIZE ? size : PLAY_BLOCK_SIZE;
    273 
    274         dsp->playing.data = data;
    275         dsp->playing.position = data + copy_size;
    276         dsp->playing.size = size;
    277         dsp->playing.mode = 0;
    278 
    279                 dsp->playing.mode |= DSP_MODE_SIGNED;
    280         if (channels == 2)
    281                 dsp->playing.mode |= DSP_MODE_STEREO;
    282 
    283         const size_t samples = sample_count(sample_size, play_size);
    284 
    285         ddf_log_debug("Playing %s sound: %zu(%zu) bytes => %zu samples.\n",
    286             mode_to_str(dsp->playing.mode), play_size, size, samples);
    287 
    288         memcpy(dsp->buffer.data, dsp->playing.data, copy_size);
    289         write_barrier();
    290 
    291         sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
    292         sb_dsp_write(dsp, sampling_rate >> 8);
    293         sb_dsp_write(dsp, sampling_rate & 0xff);
    294 
    295         ddf_log_debug("Sampling rate: %hhx:%hhx.\n",
    296             sampling_rate >> 8, sampling_rate & 0xff);
    297 
    298 #ifdef AUTO_DMA_MODE
    299         if (play_size < size) {
    300                 sb_dsp_write(dsp, AUTO_DMA_16B_DA_FIFO);
    301         } else {
    302                 sb_dsp_write(dsp, SINGLE_DMA_16B_DA_FIFO);
    303         }
    304 #else
    305         sb_dsp_write(dsp, SINGLE_DMA_16B_DA_FIFO);
    306 #endif
    307 
    308         sb_dsp_write(dsp, dsp->playing.mode);
    309         sb_dsp_write(dsp, (samples - 1) & 0xff);
    310         sb_dsp_write(dsp, (samples - 1) >> 8);
    311 
    312         return EOK;
    313194}
    314195/*----------------------------------------------------------------------------*/
     
    369250#endif
    370251
    371         const uint8_t mode =
     252        dsp->playing.mode = 0 |
    372253            (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);
     254        sb_dsp_write(dsp, dsp->playing.mode);
     255
     256        dsp->playing.samples = sample_count(sample_size, PLAY_BLOCK_SIZE);
     257        sb_dsp_write(dsp, (dsp->playing.samples - 1) & 0xff);
     258        sb_dsp_write(dsp, (dsp->playing.samples - 1) >> 8);
    378259
    379260        return EOK;
Note: See TracChangeset for help on using the changeset viewer.