Changeset 57e8b3b in mainline
- Timestamp:
- 2012-07-15T15:25:43Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5cd5079
- Parents:
- 2cc5c835
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dplay/dplay.c
r2cc5c835 r57e8b3b 51 51 52 52 #define DEFAULT_DEVICE "/hw/pci0/00:01.0/sb16/pcm" 53 #define SUBBUFFERS 253 #define BUFFER_PARTS 2 54 54 55 55 typedef struct { … … 85 85 async_answer_0(iid, EOK); 86 86 playback_t *pb = arg; 87 const size_t buffer_part = pb->buffer.size / SUBBUFFERS;87 const size_t buffer_part = pb->buffer.size / BUFFER_PARTS; 88 88 while (1) { 89 89 ipc_call_t call; 90 90 ipc_callid_t callid = async_get_call(&call); 91 91 switch(IPC_GET_IMETHOD(call)) { 92 case PCM_EVENT_ PLAYBACK_DONE:93 printf(" +");92 case PCM_EVENT_FRAMES_PLAYED: 93 printf("%u frames\n", IPC_GET_ARG1(call)); 94 94 async_answer_0(callid, EOK); 95 95 break; 96 96 case PCM_EVENT_PLAYBACK_TERMINATED: 97 printf(" \nPlayback terminated\n");97 printf("Playback terminated\n"); 98 98 fibril_mutex_lock(&pb->mutex); 99 99 pb->playing = false; … … 136 136 printf("Buffer data ready.\n"); 137 137 fibril_mutex_lock(&pb->mutex); 138 const unsigned frames = pb->buffer.size / 139 (BUFFER_PARTS * channels * pcm_sample_format_size(format)); 138 140 int ret = audio_pcm_start_playback(pb->device, 139 SUBBUFFERS, channels, sampling_rate, format);141 frames, channels, sampling_rate, format); 140 142 if (ret != EOK) { 141 143 fibril_mutex_unlock(&pb->mutex); -
uspace/app/drec/drec.c
r2cc5c835 r57e8b3b 52 52 53 53 #define DEFAULT_DEVICE "/hw/pci0/00:01.0/sb16/pcm" 54 #define SUBBUFFERS 254 #define BUFFER_PARTS 2 55 55 56 56 const unsigned sampling_rate = 44100, channels = 2, sample_size = 16; … … 84 84 async_answer_0(iid, EOK); 85 85 record_t *rec = arg; 86 const size_t buffer_part = rec->buffer.size / SUBBUFFERS;86 const size_t buffer_part = rec->buffer.size / BUFFER_PARTS; 87 87 while (1) { 88 88 ipc_call_t call; 89 89 ipc_callid_t callid = async_get_call(&call); 90 90 switch(IPC_GET_IMETHOD(call)) { 91 case PCM_EVENT_ RECORDING_DONE:92 printf(" +");91 case PCM_EVENT_FRAMES_RECORDED: 92 printf("%u frames\n", IPC_GET_ARG1(call)); 93 93 async_answer_0(callid, EOK); 94 94 break; 95 95 case PCM_EVENT_RECORDING_TERMINATED: 96 printf(" \nRecording terminated\n");96 printf("Recording terminated\n"); 97 97 return; 98 98 default: … … 122 122 printf("Recording: %dHz, %s, %d channel(s).\n", 123 123 sampling_rate, pcm_sample_format_str(format), channels); 124 const unsigned frames = rec->buffer.size / 125 (BUFFER_PARTS * channels * pcm_sample_format_size(format)); 124 126 int ret = audio_pcm_start_record(rec->device, 125 SUBBUFFERS, channels, sampling_rate, format);127 frames, channels, sampling_rate, format); 126 128 if (ret != EOK) { 127 129 printf("Failed to start recording: %s.\n", str_error(ret)); -
uspace/drv/audio/sb16/dsp.c
r2cc5c835 r57e8b3b 188 188 { 189 189 assert(dsp); 190 dsp->active.frame_count += 191 dsp->active.samples / ((dsp->active.mode & DSP_MODE_STEREO) ? 2 : 1); 192 190 193 if (dsp->event_exchange) { 191 194 switch (dsp->status) { 192 195 case DSP_PLAYBACK: 193 async_msg_ 0(dsp->event_exchange,194 PCM_EVENT_ PLAYBACK_DONE);196 async_msg_1(dsp->event_exchange, 197 PCM_EVENT_FRAMES_PLAYED, dsp->active.frame_count); 195 198 break; 196 199 case DSP_RECORDING: 197 async_msg_ 0(dsp->event_exchange,198 PCM_EVENT_ RECORDING_DONE);200 async_msg_1(dsp->event_exchange, 201 PCM_EVENT_FRAMES_RECORDED, dsp->active.frame_count); 199 202 break; 200 203 default: … … 267 270 } 268 271 269 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned parts,272 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames, 270 273 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format) 271 274 { … … 275 278 return EINVAL; 276 279 277 /* Play block size must be even number (we use DMA 16)*/278 if (dsp->buffer.size % (parts * 2))279 return EINVAL;280 281 const unsigned play_block_size = dsp->buffer.size / parts;282 283 280 /* Check supported parameters */ 284 ddf_log_debug("Requested playback (%u parts):%uHz, %s, %u channel(s).",285 parts, sampling_rate, pcm_sample_format_str(format), channels);281 ddf_log_debug("Requested playback: %u frames, %uHz, %s, %u channel(s).", 282 frames, sampling_rate, pcm_sample_format_str(format), channels); 286 283 if (channels != 1 && channels != 2) 287 284 return ENOTSUP; … … 311 308 #endif 312 309 313 dsp->active.mode = 0 | 314 (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0); 310 dsp->active.mode = 0 311 | (sign ? DSP_MODE_SIGNED : 0) 312 | (channels == 2 ? DSP_MODE_STEREO : 0); 313 dsp->active.samples = frames * channels; 314 dsp->active.frame_count = 0; 315 315 316 sb_dsp_write(dsp, dsp->active.mode); 316 317 dsp->active.samples = sample_count(format, play_block_size);318 317 sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff); 319 318 sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8); … … 339 338 } 340 339 341 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned parts,340 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned frames, 342 341 unsigned channels, unsigned sampling_rate, pcm_sample_format_t format) 343 342 { … … 347 346 return EINVAL; 348 347 349 /* Play block size must be even number (we use DMA 16)*/350 if (dsp->buffer.size % (parts * 2))351 return EINVAL;352 353 const unsigned play_block_size = dsp->buffer.size / parts;354 355 348 /* Check supported parameters */ 356 ddf_log_debug("Requested record (%u parts):%uHz, %s, %u channel(s).",357 parts, sampling_rate, pcm_sample_format_str(format), channels);349 ddf_log_debug("Requested record: %u frames, %uHz, %s, %u channel(s).", 350 frames, sampling_rate, pcm_sample_format_str(format), channels); 358 351 if (channels != 1 && channels != 2) 359 352 return ENOTSUP; … … 384 377 385 378 dsp->active.mode = 0 | 386 (sign ? DSP_MODE_SIGNED : 0) | (channels == 2 ? DSP_MODE_STEREO : 0); 379 (sign ? DSP_MODE_SIGNED : 0) | 380 (channels == 2 ? DSP_MODE_STEREO : 0); 381 dsp->active.samples = frames * channels; 382 dsp->active.frame_count = 0; 383 387 384 sb_dsp_write(dsp, dsp->active.mode); 388 389 dsp->active.samples = sample_count(format, play_block_size);390 385 sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff); 391 386 sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8); -
uspace/drv/audio/sb16/dsp.h
r2cc5c835 r57e8b3b 57 57 uint8_t mode; 58 58 uint16_t samples; 59 unsigned frame_count; 59 60 } active; 60 61 enum { … … 75 76 int sb_dsp_set_event_session(sb_dsp_t *dsp, async_sess_t *session); 76 77 int sb_dsp_release_buffer(sb_dsp_t *dsp); 77 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned parts,78 int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames, 78 79 unsigned channels, unsigned sample_rate, pcm_sample_format_t format); 79 80 int sb_dsp_stop_playback(sb_dsp_t *dsp); 80 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned parts,81 int sb_dsp_start_record(sb_dsp_t *dsp, unsigned frames, 81 82 unsigned channels, unsigned sample_rate, pcm_sample_format_t format); 82 83 int sb_dsp_stop_record(sb_dsp_t *dsp); -
uspace/drv/audio/sb16/pcm_iface.c
r2cc5c835 r57e8b3b 70 70 } 71 71 72 static int sb_start_playback(ddf_fun_t *fun, unsigned parts,72 static int sb_start_playback(ddf_fun_t *fun, unsigned frames, 73 73 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 74 74 { … … 77 77 sb_dsp_t *dsp = fun->driver_data; 78 78 return sb_dsp_start_playback( 79 dsp, parts, channels, sample_rate, format);79 dsp, frames, channels, sample_rate, format); 80 80 } 81 81 … … 88 88 } 89 89 90 static int sb_start_record(ddf_fun_t *fun, unsigned parts,90 static int sb_start_record(ddf_fun_t *fun, unsigned frames, 91 91 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 92 92 { … … 95 95 sb_dsp_t *dsp = fun->driver_data; 96 96 return sb_dsp_start_record( 97 dsp, parts, channels, sample_rate, format);97 dsp, frames, channels, sample_rate, format); 98 98 } 99 99 -
uspace/lib/drv/generic/remote_audio_pcm.c
r2cc5c835 r57e8b3b 148 148 } 149 149 150 int audio_pcm_start_playback(audio_pcm_sess_t *sess, unsigned parts,150 int audio_pcm_start_playback(audio_pcm_sess_t *sess, unsigned frames, 151 151 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 152 152 { 153 if ( parts > UINT8_MAX || channels > UINT8_MAX)153 if (channels > UINT16_MAX) 154 154 return EINVAL; 155 155 assert((format & UINT16_MAX) == format); 156 const sysarg_t packed = 157 (parts << 24) | (channels << 16) | (format & UINT16_MAX); 158 async_exch_t *exch = async_exchange_begin(sess); 159 const int ret = async_req_3_0(exch, 156 const sysarg_t packed = (channels << 16) | (format & UINT16_MAX); 157 async_exch_t *exch = async_exchange_begin(sess); 158 const int ret = async_req_4_0(exch, 160 159 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 161 160 IPC_M_AUDIO_PCM_START_PLAYBACK, 162 sample_rate, packed);161 frames, sample_rate, packed); 163 162 async_exchange_end(exch); 164 163 return ret; … … 175 174 } 176 175 177 int audio_pcm_start_record(audio_pcm_sess_t *sess, unsigned parts,176 int audio_pcm_start_record(audio_pcm_sess_t *sess, unsigned frames, 178 177 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 179 178 { 180 if ( parts > UINT8_MAX || channels > UINT8_MAX)179 if (channels > UINT16_MAX) 181 180 return EINVAL; 182 181 assert((format & UINT16_MAX) == format); 183 const sysarg_t packed = 184 (parts << 24) | (channels << 16) | (format & UINT16_MAX); 185 async_exch_t *exch = async_exchange_begin(sess); 186 const int ret = async_req_3_0(exch, 182 const sysarg_t packed = (channels << 16) | (format & UINT16_MAX); 183 async_exch_t *exch = async_exchange_begin(sess); 184 const int ret = async_req_4_0(exch, 187 185 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_START_RECORD, 188 sample_rate, packed);186 frames, sample_rate, packed); 189 187 async_exchange_end(exch); 190 188 return ret; … … 345 343 const audio_pcm_iface_t *pcm_iface = iface; 346 344 347 const unsigned rate= DEV_IPC_GET_ARG1(*call);348 const unsigned parts = (DEV_IPC_GET_ARG2(*call) >> 24) & UINT8_MAX;349 const unsigned channels = (DEV_IPC_GET_ARG 2(*call) >> 16) & UINT8_MAX;350 const pcm_sample_format_t format = DEV_IPC_GET_ARG 2(*call) & UINT16_MAX;345 const unsigned frames = DEV_IPC_GET_ARG1(*call); 346 const unsigned rate = DEV_IPC_GET_ARG2(*call); 347 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT8_MAX; 348 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX; 351 349 352 350 const int ret = pcm_iface->start_playback 353 ? pcm_iface->start_playback(fun, parts, channels, rate, format)351 ? pcm_iface->start_playback(fun, frames, channels, rate, format) 354 352 : ENOTSUP; 355 353 async_answer_0(callid, ret); … … 371 369 const audio_pcm_iface_t *pcm_iface = iface; 372 370 373 const unsigned rate= DEV_IPC_GET_ARG1(*call);374 const unsigned parts = (DEV_IPC_GET_ARG2(*call) >> 24) & UINT8_MAX;375 const unsigned channels = (DEV_IPC_GET_ARG 2(*call) >> 16) & UINT8_MAX;376 const pcm_sample_format_t format = DEV_IPC_GET_ARG 2(*call) & UINT16_MAX;371 const unsigned frames = DEV_IPC_GET_ARG1(*call); 372 const unsigned rate = DEV_IPC_GET_ARG2(*call); 373 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT16_MAX; 374 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX; 377 375 378 376 const int ret = pcm_iface->start_record 379 ? pcm_iface->start_record(fun, parts, channels, rate, format)377 ? pcm_iface->start_record(fun, frames, channels, rate, format) 380 378 : ENOTSUP; 381 379 async_answer_0(callid, ret); -
uspace/lib/drv/include/audio_pcm_iface.h
r2cc5c835 r57e8b3b 45 45 46 46 enum { 47 PCM_EVENT_ PLAYBACK_DONE= IPC_FIRST_USER_METHOD,48 PCM_EVENT_ RECORDING_DONE,47 PCM_EVENT_FRAMES_PLAYED = IPC_FIRST_USER_METHOD, 48 PCM_EVENT_FRAMES_RECORDED, 49 49 PCM_EVENT_PLAYBACK_TERMINATED, 50 50 PCM_EVENT_RECORDING_TERMINATED -
uspace/srv/audio/hound/audio_device.c
r2cc5c835 r57e8b3b 46 46 #include "log.h" 47 47 48 #define BUFFER_ BLOCKS 248 #define BUFFER_PARTS 2 49 49 50 50 static int device_sink_connection_callback(audio_sink_t *sink, bool new); … … 107 107 dev->buffer.base, dev->buffer.size); 108 108 109 ret = audio_pcm_start_playback(dev->sess, BUFFER_BLOCKS, 109 const unsigned frames = dev->buffer.size / 110 (BUFFER_PARTS * audio_format_frame_size(&dev->sink.format)); 111 ret = audio_pcm_start_playback(dev->sess, frames, 110 112 dev->sink.format.channels, dev->sink.format.sampling_rate, 111 113 dev->sink.format.sample_format); … … 148 150 return ret; 149 151 } 150 ret = audio_pcm_start_record(dev->sess, BUFFER_BLOCKS, 152 const unsigned frames = dev->buffer.size / 153 (BUFFER_PARTS * audio_format_frame_size(&dev->sink.format)); 154 ret = audio_pcm_start_record(dev->sess, frames, 151 155 dev->sink.format.channels, dev->sink.format.sampling_rate, 152 156 dev->sink.format.sample_format); … … 187 191 async_answer_0(callid, EOK); 188 192 switch(IPC_GET_IMETHOD(call)) { 189 case PCM_EVENT_PLAYBACK_DONE: { 193 case PCM_EVENT_FRAMES_PLAYED: { 194 //TODO add underrun protection. 190 195 if (dev->buffer.position) { 191 196 dev->buffer.position += 192 (dev->buffer.size / BUFFER_ BLOCKS);197 (dev->buffer.size / BUFFER_PARTS); 193 198 } 194 199 if ((!dev->buffer.position) || … … 199 204 } 200 205 audio_sink_mix_inputs(&dev->sink, dev->buffer.position, 201 dev->buffer.size / BUFFER_ BLOCKS);206 dev->buffer.size / BUFFER_PARTS); 202 207 break; 203 208 } … … 206 211 return; 207 212 } 208 case PCM_EVENT_ RECORDING_DONE: {213 case PCM_EVENT_FRAMES_RECORDED: { 209 214 //TODO implement 210 215 break; -
uspace/srv/audio/hound/audio_format.h
r2cc5c835 r57e8b3b 61 61 62 62 63 63 static inline size_t audio_format_frame_size(const audio_format_t *a) 64 { 65 return a->channels * pcm_sample_format_size(a->sample_format); 66 } 64 67 65 68 bool audio_format_same(const audio_format_t *a, const audio_format_t* b);
Note:
See TracChangeset
for help on using the changeset viewer.