Changeset c17c872c in mainline
- Timestamp:
- 2011-12-05T15:20:50Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c0149cc
- Parents:
- b499127
- Location:
- uspace/drv/audio/sb16
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/dsp.c
rb499127 rc17c872c 128 128 if (ret == EOK) { 129 129 dsp->buffer.data = buffer; 130 dsp->buffer.position = buffer;131 130 dsp->buffer.size = BUFFER_SIZE; 132 131 bzero(buffer, BUFFER_SIZE); … … 143 142 dma_destroy_buffer(dsp->buffer.data); 144 143 dsp->buffer.data = NULL; 145 dsp->buffer.position = NULL;146 144 dsp->buffer.size = 0; 147 145 } … … 187 185 void sb_dsp_interrupt(sb_dsp_t *dsp) 188 186 { 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); 197 193 #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_MODE227 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 #endif233 #endif234 }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 playback261 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_MODE299 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 #else305 sb_dsp_write(dsp, SINGLE_DMA_16B_DA_FIFO);306 #endif307 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;313 194 } 314 195 /*----------------------------------------------------------------------------*/ … … 369 250 #endif 370 251 371 const uint8_t mode =252 dsp->playing.mode = 0 | 372 253 (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0); 373 sb_dsp_write(dsp, mode);374 375 const uint16_tsamples = 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); 378 259 379 260 return EOK; -
uspace/drv/audio/sb16/dsp.h
rb499127 rc17c872c 51 51 struct { 52 52 uint8_t *data; 53 uint8_t *position;54 53 size_t size; 55 54 } buffer; 56 55 struct { 57 const uint8_t *data;58 const uint8_t *position;59 size_t size;60 56 uint8_t mode; 57 uint16_t samples; 61 58 } playing; 62 59 ddf_dev_t *sb_dev; … … 66 63 int dma8, int dma16); 67 64 void sb_dsp_interrupt(sb_dsp_t *dsp); 68 int sb_dsp_play_direct(sb_dsp_t *dsp, const uint8_t *data, size_t size,69 unsigned sample_rate, unsigned channels, unsigned bit_depth);70 int sb_dsp_play(sb_dsp_t *dsp, const void *data, size_t size,71 uint16_t sample_rate, unsigned channels, unsigned bit_depth);72 65 73 66 int sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size, unsigned *id);
Note:
See TracChangeset
for help on using the changeset viewer.