Changeset 346643c in mainline
- Timestamp:
- 2012-07-11T12:05:30Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 039337e8
- Parents:
- 94694a4
- Location:
- uspace
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dplay/dplay.c
r94694a4 r346643c 112 112 113 113 114 static void play(playback_t *pb, unsigned sampling_rate, unsigned sample_size,115 unsigned channels, bool sign)114 static void play(playback_t *pb, unsigned channels, unsigned sampling_rate, 115 pcm_sample_format_t format) 116 116 { 117 117 assert(pb); 118 118 assert(pb->device); 119 119 pb->buffer.position = pb->buffer.base; 120 printf("Playing: %dHz, % d-bit %ssigned samples, %d channel(s).\n",121 sampling_rate, sample_size, sign ? "": "un", channels);120 printf("Playing: %dHz, %s, %d channel(s).\n", 121 sampling_rate, pcm_sample_format_str(format), channels); 122 122 const size_t bytes = fread(pb->buffer.base, sizeof(uint8_t), 123 123 pb->buffer.size, pb->source); … … 127 127 fibril_mutex_lock(&pb->mutex); 128 128 int ret = audio_pcm_start_playback(pb->device, pb->buffer.id, 129 SUBBUFFERS, sampling_rate, sample_size, channels, sign);129 SUBBUFFERS, channels, sampling_rate, format); 130 130 if (ret != EOK) { 131 131 fibril_mutex_unlock(&pb->mutex); … … 212 212 wave_header_t header; 213 213 fread(&header, sizeof(header), 1, pb.source); 214 unsigned rate, sample_size,channels;215 bool sign;214 unsigned rate, channels; 215 pcm_sample_format_t format; 216 216 const char *error; 217 ret = wav_parse_header(&header, NULL, NULL, & rate, &sample_size,218 & channels, &sign, &error);217 ret = wav_parse_header(&header, NULL, NULL, &channels, &rate, &format, 218 &error); 219 219 if (ret != EOK) { 220 220 printf("Error parsing wav header: %s.\n", error); … … 223 223 } 224 224 225 play(&pb, rate, sample_size, channels, sign);225 play(&pb, channels, rate, format); 226 226 fclose(pb.source); 227 227 -
uspace/app/dplay/wave.c
r94694a4 r346643c 40 40 41 41 int wav_parse_header(void *file, const void **data, size_t *data_size, 42 unsigned * sampling_rate, unsigned *sample_size, unsigned *channels,43 bool *sign,const char **error)42 unsigned *channels, unsigned *sampling_rate, pcm_sample_format_t *format, 43 const char **error) 44 44 { 45 45 if (!file) { … … 86 86 } 87 87 88 88 89 if (data) 89 90 *data = header->data; … … 93 94 if (sampling_rate) 94 95 *sampling_rate = uint32_t_le2host(header->sampling_rate); 95 if (sample_size)96 *sample_size = uint32_t_le2host(header->sample_size);97 96 if (channels) 98 97 *channels = uint16_t_le2host(header->channels); 99 if (sign) 100 *sign = uint32_t_le2host(header->sample_size) == 16 101 ? true : false; 98 if (format) { 99 const unsigned size = uint32_t_le2host(header->sample_size); 100 switch (size) { 101 case 8: *format = PCM_SAMPLE_UINT8; break; 102 case 16: *format = PCM_SAMPLE_SINT16_LE; break; 103 case 24: *format = PCM_SAMPLE_SINT24_LE; break; 104 case 32: *format = PCM_SAMPLE_SINT32_LE; break; 105 default: 106 *error = "Unknown format"; 107 return ENOTSUP; 108 } 109 } 102 110 if (error) 103 111 *error = "no error"; -
uspace/app/dplay/wave.h
r94694a4 r346643c 37 37 #include <stdint.h> 38 38 #include <bool.h> 39 #include <pcm_sample_format.h> 39 40 40 41 /** Wave file header format. … … 90 91 91 92 int wav_parse_header(void *, const void**, size_t *, unsigned *, unsigned *, 92 unsigned *, bool *, const char **error_str);93 pcm_sample_format_t *, const char **); 93 94 94 95 #endif -
uspace/app/drec/drec.c
r94694a4 r346643c 47 47 #include <stdio.h> 48 48 #include <macros.h> 49 #include <pcm_sample_format.h> 49 50 50 51 #include "wave.h" … … 53 54 #define SUBBUFFERS 2 54 55 55 const unsigned sampling_rate = 44100, sample_size = 16, channels = 2;56 bool sign = true;56 const unsigned sampling_rate = 44100, channels = 2, sample_size = 16; 57 const pcm_sample_format_t format = PCM_SAMPLE_SINT16_LE; 57 58 58 59 typedef struct { … … 104 105 105 106 106 static void record(record_t *rec, unsigned sampling_rate, unsigned sample_size,107 unsigned channels, bool sign)107 static void record(record_t *rec, unsigned channels, unsigned sampling_rate, 108 pcm_sample_format_t format) 108 109 { 109 110 assert(rec); 110 111 assert(rec->device); 111 112 rec->buffer.position = rec->buffer.base; 112 printf("Recording: %dHz, % d-bit %ssigned samples, %d channel(s).\n",113 sampling_rate, sample_size, sign ? "": "un", channels);113 printf("Recording: %dHz, %s, %d channel(s).\n", 114 sampling_rate, pcm_sample_format_str(format), channels); 114 115 int ret = audio_pcm_start_record(rec->device, rec->buffer.id, 115 SUBBUFFERS, sampling_rate, sample_size, channels, sign);116 SUBBUFFERS, channels, sampling_rate, format); 116 117 if (ret != EOK) { 117 118 printf("Failed to start recording: %s.\n", str_error(ret)); … … 201 202 .sampling_rate = sampling_rate, 202 203 .sample_size = sample_size, 203 .byte_rate = (sampling_rate / 8) * channels,204 .block_align = (sampl ing_rate / 8) * channels,204 .byte_rate = sampling_rate * (sample_size / 8) * channels, 205 .block_align = (sample_size / 8) * channels, 205 206 .subchunk2_id = SUBCHUNK2_ID, 206 207 }; 207 208 fwrite(&header, sizeof(header), 1, rec.file); 208 record(&rec, sampling_rate, sample_size, channels, sign);209 record(&rec, sampling_rate, channels, format); 209 210 fclose(rec.file); 210 211 -
uspace/app/drec/wave.c
r94694a4 r346643c 40 40 41 41 int wav_parse_header(void *file, const void **data, size_t *data_size, 42 unsigned * sampling_rate, unsigned *sample_size, unsigned *channels,43 bool *sign,const char **error)42 unsigned *channels, unsigned *sampling_rate, pcm_sample_format_t *format, 43 const char **error) 44 44 { 45 45 if (!file) { … … 86 86 } 87 87 88 88 89 if (data) 89 90 *data = header->data; … … 93 94 if (sampling_rate) 94 95 *sampling_rate = uint32_t_le2host(header->sampling_rate); 95 if (sample_size)96 *sample_size = uint32_t_le2host(header->sample_size);97 96 if (channels) 98 97 *channels = uint16_t_le2host(header->channels); 99 if (sign) 100 *sign = uint32_t_le2host(header->sample_size) == 16 101 ? true : false; 98 if (format) { 99 const unsigned size = uint32_t_le2host(header->sample_size); 100 switch (size) { 101 case 8: *format = PCM_SAMPLE_UINT8; break; 102 case 16: *format = PCM_SAMPLE_SINT16_LE; break; 103 case 24: *format = PCM_SAMPLE_SINT24_LE; break; 104 case 32: *format = PCM_SAMPLE_SINT32_LE; break; 105 default: 106 *error = "Unknown format"; 107 return ENOTSUP; 108 } 109 } 102 110 if (error) 103 111 *error = "no error"; -
uspace/app/drec/wave.h
r94694a4 r346643c 37 37 #include <stdint.h> 38 38 #include <bool.h> 39 #include <pcm_sample_format.h> 39 40 40 41 /** Wave file header format. … … 90 91 91 92 int wav_parse_header(void *, const void**, size_t *, unsigned *, unsigned *, 92 unsigned *, bool *, const char **error_str);93 pcm_sample_format_t *, const char **); 93 94 94 95 #endif -
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 -
uspace/lib/drv/generic/remote_audio_pcm.c
r94694a4 r346643c 118 118 } 119 119 120 int audio_pcm_start_playback(async_exch_t *exch, unsigned id, 121 unsigned parts, unsigned sample_rate, uint16_t sample_size, 122 uint8_t channels, bool sign) 120 int audio_pcm_start_playback(async_exch_t *exch, unsigned id, unsigned parts, 121 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 123 122 { 124 123 if (!exch) 125 124 return EINVAL; 125 if (parts > UINT8_MAX || channels > UINT8_MAX) 126 return EINVAL; 127 assert((format & UINT16_MAX) == format); 126 128 const sysarg_t packed = 127 (sample_size << 16) | (channels << 8) | 128 ((parts & 0x7f) << 1) | (sign ? 1 : 0); 129 (parts << 24) | (channels << 16) | (format & UINT16_MAX); 129 130 return async_req_4_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 130 131 IPC_M_AUDIO_PCM_START_PLAYBACK, id, sample_rate, packed); … … 139 140 } 140 141 141 int audio_pcm_start_record(async_exch_t *exch, unsigned id, 142 unsigned parts, unsigned sample_rate, uint16_t sample_size, 143 uint8_t channels, bool sign) 142 int audio_pcm_start_record(async_exch_t *exch, unsigned id, unsigned parts, 143 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 144 144 { 145 145 if (!exch) 146 146 return EINVAL; 147 sysarg_t packed = 148 (sample_size << 16) | (channels << 8) | 149 ((parts & 0x7f) << 1) | (sign ? 1 : 0); 147 if (parts > UINT8_MAX || channels > UINT8_MAX) 148 return EINVAL; 149 assert((format & UINT16_MAX) == format); 150 const sysarg_t packed = 151 (parts << 24) | (channels << 16) | (format & UINT16_MAX); 150 152 return async_req_4_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 151 153 IPC_M_AUDIO_PCM_START_RECORD, id, sample_rate, packed); … … 309 311 const unsigned id = DEV_IPC_GET_ARG1(*call); 310 312 const unsigned rate = DEV_IPC_GET_ARG2(*call); 311 const unsigned size = DEV_IPC_GET_ARG3(*call) >> 16; 312 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 8) & UINT8_MAX; 313 const unsigned parts = (DEV_IPC_GET_ARG3(*call) >> 1) & 0x7f; 314 const bool sign = (bool)(DEV_IPC_GET_ARG3(*call) & 1); 313 const unsigned parts = (DEV_IPC_GET_ARG3(*call) >> 24) & UINT8_MAX; 314 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT8_MAX; 315 const pcm_sample_format_t format =DEV_IPC_GET_ARG3(*call) & UINT16_MAX; 315 316 316 317 const int ret = pcm_iface->start_playback 317 ? pcm_iface->start_playback(fun, id, parts, rate, size, channels, sign)318 ? pcm_iface->start_playback(fun, id, parts, channels, rate, format) 318 319 : ENOTSUP; 319 320 async_answer_0(callid, ret); … … 338 339 const unsigned id = DEV_IPC_GET_ARG1(*call); 339 340 const unsigned rate = DEV_IPC_GET_ARG2(*call); 340 const unsigned size = DEV_IPC_GET_ARG3(*call) >> 16; 341 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 8) & UINT8_MAX; 342 const unsigned parts = (DEV_IPC_GET_ARG3(*call) >> 1) & 0x7f; 343 const bool sign = (bool)(DEV_IPC_GET_ARG3(*call) & 1); 341 const unsigned parts = (DEV_IPC_GET_ARG3(*call) >> 24) & UINT8_MAX; 342 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT8_MAX; 343 const pcm_sample_format_t format =DEV_IPC_GET_ARG3(*call) & UINT16_MAX; 344 344 345 345 const int ret = pcm_iface->start_record 346 ? pcm_iface->start_record(fun, id, parts, rate, size, channels, sign)346 ? pcm_iface->start_record(fun, id, parts, channels, rate, format) 347 347 : ENOTSUP; 348 348 async_answer_0(callid, ret); -
uspace/lib/drv/include/audio_pcm_iface.h
r94694a4 r346643c 39 39 #include <async.h> 40 40 #include <bool.h> 41 #include <pcm_sample_format.h> 41 42 42 43 #include "ddf/driver.h" … … 48 49 49 50 int audio_pcm_start_playback(async_exch_t *, unsigned, unsigned, 50 unsigned, u int16_t, uint8_t, bool);51 unsigned, unsigned, pcm_sample_format_t); 51 52 int audio_pcm_stop_playback(async_exch_t *, unsigned); 52 53 53 54 int audio_pcm_start_record(async_exch_t *, unsigned, unsigned, 54 unsigned, u int16_t, uint8_t, bool);55 unsigned, unsigned, pcm_sample_format_t); 55 56 int audio_pcm_stop_record(async_exch_t *, unsigned); 56 57 … … 62 63 int (*set_event_session)(ddf_fun_t *, unsigned, async_sess_t *); 63 64 int (*start_playback)(ddf_fun_t *, unsigned, unsigned, 64 unsigned, unsigned, unsigned, bool);65 unsigned, unsigned, pcm_sample_format_t); 65 66 int (*stop_playback)(ddf_fun_t *, unsigned); 66 67 int (*start_record)(ddf_fun_t *, unsigned, unsigned, 67 unsigned, unsigned, unsigned, bool);68 unsigned, unsigned, pcm_sample_format_t); 68 69 int (*stop_record)(ddf_fun_t *, unsigned); 69 70 } audio_pcm_iface_t;
Note:
See TracChangeset
for help on using the changeset viewer.