Changeset 346643c in mainline for uspace/drv/audio
- Timestamp:
- 2012-07-11T12:05:30Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 039337e8
- Parents:
- 94694a4
- Location:
- uspace/drv/audio/sb16
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/dsp.c
r94694a4 r346643c 147 147 } 148 148 149 static inline size_t sample_count(unsigned sample_size, size_t byte_count) 150 { 151 if (sample_size == 16) { 152 return byte_count / 2; 153 } 154 return byte_count; 149 static inline size_t sample_count(pcm_sample_format_t format, size_t byte_count) 150 { 151 return byte_count / pcm_sample_format_size(format); 155 152 } 156 153 … … 261 258 262 259 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned parts, 263 unsigned sampling_rate, unsigned sample_size, unsigned channels, bool sign)260 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format) 264 261 { 265 262 assert(dsp); … … 276 273 /* Check supported parameters */ 277 274 ddf_log_debug("Requested playback on buffer \"%u\" (%u parts): %uHz, " 278 "%ssinged %u bit, %u channel(s).", id, parts, sampling_rate, 279 sign ? "" : "un", sample_size, channels); 280 if (id != BUFFER_ID) 281 return ENOENT; 282 if (sample_size != 16) // FIXME We only support 16 bit playback 283 return ENOTSUP; 275 "%s, %u channel(s).", id, parts, sampling_rate, 276 pcm_sample_format_str(format), channels); 277 if (id != BUFFER_ID) 278 return ENOENT; 284 279 if (channels != 1 && channels != 2) 285 280 return ENOTSUP; 286 281 if (sampling_rate > 44100) 282 return ENOTSUP; 283 // FIXME We only support 16 bit playback 284 if (format != PCM_SAMPLE_UINT16_LE && format != PCM_SAMPLE_SINT16_LE) 287 285 return ENOTSUP; 288 286 … … 291 289 return ENOMEM; 292 290 291 const bool sign = (format == PCM_SAMPLE_SINT16_LE); 292 293 293 sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT); 294 294 sb_dsp_write(dsp, sampling_rate >> 8); 295 295 sb_dsp_write(dsp, sampling_rate & 0xff); 296 296 297 ddf_log_verbose("Sampl ingrate: %hhx:%hhx.",297 ddf_log_verbose("Sample rate: %hhx:%hhx.", 298 298 sampling_rate >> 8, sampling_rate & 0xff); 299 299 … … 308 308 sb_dsp_write(dsp, dsp->active.mode); 309 309 310 dsp->active.samples = sample_count( sample_size, play_block_size);310 dsp->active.samples = sample_count(format, play_block_size); 311 311 sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff); 312 312 sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8); … … 314 314 ddf_log_verbose("Playback started, interrupt every %u samples " 315 315 "(~1/%u sec)", dsp->active.samples, 316 sampling_rate / dsp->active.samples);316 sampling_rate / (dsp->active.samples * channels)); 317 317 318 318 dsp->active.playing = true; … … 332 332 333 333 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned parts, 334 unsigned sampling_rate, unsigned sample_size, unsigned channels, bool sign)334 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format) 335 335 { 336 336 assert(dsp); … … 347 347 /* Check supported parameters */ 348 348 ddf_log_debug("Requested recording on buffer \"%u\" (%u parts): %uHz, " 349 "%ssinged %u bit, %u channel(s).", id, parts, sampling_rate, 350 sign ? "" : "un", sample_size, channels); 351 if (id != BUFFER_ID) 352 return ENOENT; 353 if (sample_size != 16) // FIXME We only support 16 bit playback 354 return ENOTSUP; 349 "%s, %u channel(s).", id, parts, sampling_rate, 350 pcm_sample_format_str(format), channels); 351 if (id != BUFFER_ID) 352 return ENOENT; 355 353 if (channels != 1 && channels != 2) 356 354 return ENOTSUP; 357 355 if (sampling_rate > 44100) 356 return ENOTSUP; 357 // FIXME We only support 16 bit recording 358 if (format != PCM_SAMPLE_UINT16_LE && format != PCM_SAMPLE_SINT16_LE) 358 359 return ENOTSUP; 359 360 … … 361 362 if (!dsp->event_exchange) 362 363 return ENOMEM; 364 365 const bool sign = (format == PCM_SAMPLE_SINT16_LE); 363 366 364 367 sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT); … … 379 382 sb_dsp_write(dsp, dsp->active.mode); 380 383 381 dsp->active.samples = sample_count( sample_size, play_block_size);384 dsp->active.samples = sample_count(format, play_block_size); 382 385 sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff); 383 386 sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8); … … 385 388 ddf_log_verbose("Recording started started, interrupt every %u samples " 386 389 "(~1/%u sec)", dsp->active.samples, 387 sampling_rate / dsp->active.samples);390 sampling_rate / (dsp->active.samples * channels)); 388 391 dsp->active.playing = false; 389 392 -
uspace/drv/audio/sb16/dsp.h
r94694a4 r346643c 38 38 #include <libarch/ddi.h> 39 39 #include <errno.h> 40 #include <pcm_sample_format.h> 40 41 41 42 #include "registers.h" … … 71 72 int sb_dsp_release_buffer(sb_dsp_t *dsp, unsigned id); 72 73 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned id, unsigned parts, 73 unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign);74 unsigned channels, unsigned sample_rate, pcm_sample_format_t format); 74 75 int sb_dsp_stop_playback(sb_dsp_t *dsp, unsigned id); 75 76 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned id, unsigned parts, 76 unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign);77 unsigned channels, unsigned sample_rate, pcm_sample_format_t format); 77 78 int sb_dsp_stop_record(sb_dsp_t *dsp, unsigned id); 78 79 -
uspace/drv/audio/sb16/pcm_iface.c
r94694a4 r346643c 36 36 #include <errno.h> 37 37 #include <audio_pcm_iface.h> 38 #include <pcm_sample_format.h> 38 39 39 40 #include "dsp.h" … … 71 72 72 73 static int sb_start_playback(ddf_fun_t *fun, unsigned id, unsigned parts, 73 unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign)74 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 74 75 { 75 76 assert(fun); … … 77 78 sb_dsp_t *dsp = fun->driver_data; 78 79 return sb_dsp_start_playback( 79 dsp, id, parts, sample_rate, sample_size, channels, sign);80 dsp, id, parts, channels, sample_rate, format); 80 81 } 81 82 … … 89 90 90 91 static int sb_start_record(ddf_fun_t *fun, unsigned id, unsigned parts, 91 unsigned sample_rate, unsigned sample_size, unsigned channels, bool sign)92 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 92 93 { 93 94 assert(fun); … … 95 96 sb_dsp_t *dsp = fun->driver_data; 96 97 return sb_dsp_start_record( 97 dsp, id, parts, sample_rate, sample_size, channels, sign);98 dsp, id, parts, channels, sample_rate, format); 98 99 } 99 100
Note:
See TracChangeset
for help on using the changeset viewer.