Changeset 43dec08 in mainline
- Timestamp:
- 2011-12-05T00:51:42Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e44385d
- Parents:
- c09ad29e
- Location:
- uspace/drv/audio/sb16
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/dsp.c
rc09ad29e r43dec08 45 45 #include "dsp.h" 46 46 47 #define BUFFER_ID 1 47 48 #define BUFFER_SIZE (PAGE_SIZE) 48 49 #define PLAY_BLOCK_SIZE (BUFFER_SIZE / 2) … … 146 147 } 147 148 /*----------------------------------------------------------------------------*/ 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) { 149 static inline size_t sample_count(unsigned sample_size, size_t byte_count) 150 { 151 if (sample_size == 16) { 154 152 return byte_count / 2; 155 153 } … … 189 187 void sb_dsp_interrupt(sb_dsp_t *dsp) 190 188 { 189 #if 0 191 190 assert(dsp); 192 191 const size_t remain_size = … … 232 231 sb_dsp_write(dsp, (samples - 1) >> 8); 233 232 #endif 234 233 #endif 235 234 } 236 235 /*----------------------------------------------------------------------------*/ … … 282 281 dsp->playing.mode |= DSP_MODE_STEREO; 283 282 284 const size_t samples = sample_count( dsp->playing.mode, play_size);283 const size_t samples = sample_count(sample_size, play_size); 285 284 286 285 ddf_log_debug("Playing %s sound: %zu(%zu) bytes => %zu samples.\n", … … 313 312 return EOK; 314 313 } 314 /*----------------------------------------------------------------------------*/ 315 int 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 /*----------------------------------------------------------------------------*/ 330 int 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 /*----------------------------------------------------------------------------*/ 339 int 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 /*----------------------------------------------------------------------------*/ 383 int 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 /*----------------------------------------------------------------------------*/ 392 int 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 /*----------------------------------------------------------------------------*/ 398 int sb_dsp_stop_record(sb_dsp_t *dsp, unsigned id) 399 { 400 return ENOTSUP; 401 } 315 402 /** 316 403 * @} -
uspace/drv/audio/sb16/dsp.h
rc09ad29e r43dec08 71 71 uint16_t sample_rate, unsigned channels, unsigned bit_depth); 72 72 73 int sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size, unsigned *id); 74 int sb_dsp_release_buffer(sb_dsp_t *dsp, unsigned id); 75 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned sample_rate, 76 unsigned sample_size, unsigned channels, bool sign); 77 int sb_dsp_stop_playback(sb_dsp_t *dsp, unsigned id); 78 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned sample_rate, 79 unsigned sample_size, unsigned channels, bool sign); 80 int sb_dsp_stop_record(sb_dsp_t *dsp, unsigned id); 81 73 82 #endif 74 83 /**
Note:
See TracChangeset
for help on using the changeset viewer.