Changeset 193
- Timestamp:
- 05/12/06 09:09:06 (17 years ago)
- Files:
-
- trunk/alsa-plugin/freebob/pcm_freebob.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/alsa-plugin/freebob/pcm_freebob.c
r184 r193 36 36 #include <pthread.h> 37 37 38 #define FREEBOB_PLUGIN_VERSION "0.0. 7"38 #define FREEBOB_PLUGIN_VERSION "0.0.8" 39 39 40 40 #define FREEBOB_USE_RT 1 … … 46 46 #define FREEBOB_RT_PRIORITY_MIDI 59 47 47 48 // undef this to disable midi support 48 49 #define FREEBOB_WITH_MIDI 49 50 … … 122 123 #endif 123 124 124 // unused 125 static snd_pcm_sframes_t snd_pcm_freebob_write(snd_pcm_ioplug_t *io, 126 const snd_pcm_channel_area_t *areas, 127 snd_pcm_uframes_t offset, 128 snd_pcm_uframes_t size) 129 { 130 PRINT_FUNCTION_ENTRY; 131 132 int retval=0; 133 int i=0; 134 135 snd_pcm_sframes_t frames; 125 static int snd_pcm_freebob_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) { 126 127 PRINT_FUNCTION_ENTRY; 136 128 137 129 snd_pcm_freebob_t *freebob = io->private_data; 138 const char *buf; 139 ssize_t result; 140 141 int sampleswritten; 142 143 freebob_streaming_transfer_playback_buffers(freebob->streaming_device); 144 145 for(i=0;i<freebob->channels;i++) { 146 freebob_sample_t *buff=(freebob_sample_t *)((char *)areas[i].addr + (areas[i].step * offset / 8)); 147 sampleswritten=freebob_streaming_write(freebob->streaming_device, i, buff, freebob->dev_options.period_size); 148 } 149 150 frames = sampleswritten / freebob->channels; 151 152 freebob->hw_ptr += frames; 153 freebob->hw_ptr %= io->buffer_size; 154 155 return frames ; 156 } 157 158 static int snd_pcm_freebob_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) { 159 160 PRINT_FUNCTION_ENTRY; 161 162 snd_pcm_freebob_t *freebob = io->private_data; 163 int i=0; 130 unsigned int i=0; 164 131 165 132 freebob->channels=0; 166 133 if (freebob->stream == SND_PCM_STREAM_PLAYBACK) { 167 134 //fixme: assumes that the audio streams are always the first streams 168 for (i=0;i <freebob_streaming_get_nb_playback_streams(freebob->streaming_device);i++) {135 for (i=0;i < (unsigned int)freebob_streaming_get_nb_playback_streams(freebob->streaming_device);i++) { 169 136 if(freebob_streaming_get_playback_stream_type(freebob->streaming_device,i)==freebob_stream_type_audio) { 170 137 freebob->channels++; … … 177 144 } else { 178 145 //fixme: assumes that the audio streams are always the first streams 179 for (i=0;i <freebob_streaming_get_nb_capture_streams(freebob->streaming_device);i++) {146 for (i=0;i < (unsigned int)freebob_streaming_get_nb_capture_streams(freebob->streaming_device);i++) { 180 147 if(freebob_streaming_get_capture_stream_type(freebob->streaming_device,i)==freebob_stream_type_audio) { 181 148 freebob->channels++; … … 200 167 snd_pcm_ioplug_t *io=&freebob->io; 201 168 const snd_pcm_channel_area_t *areas; 202 snd_pcm_uframes_t xfer = 0; 203 int i; 169 unsigned int i; 204 170 205 171 assert(freebob); … … 213 179 } 214 180 215 216 181 areas = snd_pcm_ioplug_mmap_areas(io); 217 182 … … 279 244 PRINT_FUNCTION_ENTRY; 280 245 if (freebob) { 281 // if (freebob->client)282 // jack_client_close(freebob->client);283 246 if(freebob->fb_handle) 284 247 freebob_destroy_handle(freebob->fb_handle ); … … 286 249 close(freebob->fd); 287 250 close(freebob->io.poll_fd); 288 // free(freebob->areas);289 251 free(freebob); 290 252 } … … 312 274 snd_pcm_freebob_t *freebob = io->private_data; 313 275 314 // printf("%d\n", freebob->hw_ptr);315 276 return freebob->hw_ptr; 316 277 } … … 348 309 static int snd_pcm_freebob_prepare(snd_pcm_ioplug_t *io) 349 310 { 350 snd_pcm_freebob_t *freebob = io->private_data;311 // snd_pcm_freebob_t *freebob = io->private_data; 351 312 PRINT_FUNCTION_ENTRY; 352 313 … … 359 320 .stop = snd_pcm_freebob_stop, 360 321 .pointer = snd_pcm_freebob_pointer, 361 // .transfer = snd_pcm_freebob_write,362 322 .hw_params = snd_pcm_freebob_hw_params, 363 323 .prepare = snd_pcm_freebob_prepare, 364 324 .poll_revents = snd_pcm_freebob_poll_revents, 365 325 }; 366 /* 367 static snd_pcm_ioplug_callback_t jack_pcm_callback = { 368 .close = snd_pcm_jack_close, 369 .start = snd_pcm_jack_start, 370 .stop = snd_pcm_jack_stop, 371 .pointer = snd_pcm_jack_pointer, 372 .prepare = snd_pcm_jack_prepare, 373 .poll_revents = snd_pcm_jack_poll_revents, 374 }; 375 */ 326 376 327 #define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) 377 328 … … 383 334 SND_PCM_ACCESS_RW_NONINTERLEAVED, 384 335 }; 385 /* 386 unsigned int rate_list[] = { 387 44100, 388 48000, 389 88200, 390 96000, 391 }; 392 */ 336 393 337 unsigned int *rate_list=NULL; 394 unsigned int nb_rates;395 338 396 339 unsigned int format = SND_PCM_FORMAT_S24; … … 398 341 int i; 399 342 400 // FIXME: this fixes the plugin to the first discovered device!343 // FIXME: this restricts the plugin to the first discovered device! 401 344 freebob->dev_options.node_id=freebob_get_device_node_id(freebob->fb_handle, 0); 402 345 403 346 freebob_supported_stream_format_info_t* stream_info; 404 printf(" port = %d, node_id = %d\n", freebob->dev_options.port, freebob->dev_options.node_id); 405 347 348 // printf(" port = %d, node_id = %d\n", freebob->dev_options.port, freebob->dev_options.node_id); 349 350 // find the supported samplerate nb channels combinations 406 351 stream_info = freebob_get_supported_stream_format_info( freebob->fb_handle, 407 352 freebob->dev_options.node_id, 408 353 freebob->stream == SND_PCM_STREAM_PLAYBACK ? 1 : 0 ); 409 410 411 412 freebob_print_supported_stream_format_info( stream_info ); 354 355 // debug statement 356 // freebob_print_supported_stream_format_info( stream_info ); 413 357 414 358 if(!(rate_list=calloc(stream_info->nb_formats, sizeof(unsigned int)))) { … … 434 378 } 435 379 436 SNDERR("minchannels: %d \n",min_channels); 437 SNDERR("maxchannels: %d \n",max_channels); 438 380 // SNDERR("minchannels: %d \n",min_channels); 381 // SNDERR("maxchannels: %d \n",max_channels); 439 382 440 383 freebob_free_supported_stream_format_info( stream_info ); … … 442 385 freebob->sample_bits = snd_pcm_format_physical_width(format); 443 386 387 // setup the plugin capabilities 444 388 if ((err = snd_pcm_ioplug_set_param_list(&freebob->io, SND_PCM_IOPLUG_HW_ACCESS, 445 389 ARRAY_SIZE(access_list), access_list)) < 0 || … … 470 414 int err; 471 415 int fd[2]; 472 static unsigned int num = 0;473 416 474 417 printf("FreeBob plugin for ALSA\n version %s compiled %s %s\n using %s\n", … … 494 437 495 438 if ( freebob_discover_devices( freebob->fb_handle, 0 ) != 0 ) { 496 // if ( freebob_discover_devices( freebob->fb_handle ) != 0 ) {497 439 SNDERR("Could not discover devices\n" ); 498 440 freebob_destroy_handle( freebob->fb_handle ); … … 527 469 #endif 528 470 529 /*530 freebob->playback_channels = 0;531 if (freebob->channels == 0) {532 snd_pcm_freebob_free(freebob);533 return -EINVAL;534 }535 */536 /*537 freebob->areas = calloc(freebob->channels, sizeof(snd_pcm_channel_area_t));538 if (! freebob->areas) {539 snd_pcm_freebob_free(jack);540 return -ENOMEM;541 }542 */543 544 545 471 socketpair(AF_LOCAL, SOCK_STREAM, 0, fd); 546 472 … … 575 501 { 576 502 snd_config_iterator_t i, next; 577 // snd_config_t *playback_conf = NULL;578 // snd_config_t *capture_conf = NULL;579 503 int err; 580 504 long tmp_int; … … 588 512 dev_options.period_size=512; 589 513 dev_options.nb_buffers=3; 590 dev_options.iso_buffers=100;591 dev_options.iso_prebuffers=0;592 dev_options.iso_irq_interval=4;593 514 594 515 /* packetizer thread options */ … … 628 549 continue; 629 550 } 630 /* 631 if (strcmp(id, "playback_ports") == 0) { 632 if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { 633 SNDERR("Invalid type for %s", id); 634 return -EINVAL; 635 } 636 playback_conf = n; 637 continue; 638 } 639 if (strcmp(id, "capture_ports") == 0) { 640 if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { 641 SNDERR("Invalid type for %s", id); 642 return -EINVAL; 643 } 644 capture_conf = n; 645 continue; 646 } 647 */ 551 648 552 SNDERR("Unknown field %s", id); 649 553 return -EINVAL;