- Timestamp:
- Nov 13, 2013, 1:25:30 PM (11 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 4bc92c0
- Parents:
- c101fe1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/audio_unit.c
rc101fe1 rd3066e2 110 110 /* check for some sizes */ 111 111 if ( o->hw_output_channels != o->output_frames->height ) { 112 AUBIO_ERR ("got hw_output_channels = %d, but output_frames has %d rows ",112 AUBIO_ERR ("got hw_output_channels = %d, but output_frames has %d rows\n", 113 113 o->hw_output_channels, o->output_frames->height); 114 114 } 115 115 if ( o->blocksize != o->output_frames->length ) { 116 AUBIO_ERR ("got blocksize = %d, but output_frames has length %d ",116 AUBIO_ERR ("got blocksize = %d, but output_frames has length %d\n", 117 117 o->blocksize, o->output_frames->length); 118 118 } 119 119 if ( o->hw_input_channels != o->input_frames->height ) { 120 AUBIO_ERR ("got hw_input_channels = %d, but input_frames has %d rows ",120 AUBIO_ERR ("got hw_input_channels = %d, but input_frames has %d rows\n", 121 121 o->hw_input_channels, o->input_frames->height); 122 122 } 123 123 if ( o->blocksize != o->input_frames->length ) { 124 AUBIO_ERR ("got blocksize = %d, but input_frames has length %d ",124 AUBIO_ERR ("got blocksize = %d, but input_frames has length %d\n", 125 125 o->blocksize, o->input_frames->length); 126 126 } … … 159 159 /* setting up audio session with interruption listener */ 160 160 err = AudioSessionInitialize(NULL, NULL, audio_unit_interruption_listener, o); 161 if (err) { AUBIO_ERR("audio_unit: could not initialize audio session (% ld)",err); goto fail; }161 if (err) { AUBIO_ERR("audio_unit: could not initialize audio session (%d)\n", (int)err); goto fail; } 162 162 163 163 audio_unit_set_audio_session_category(o->input_enabled, o->verbose); … … 167 167 err = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, 168 168 audio_unit_route_change_listener, o); 169 if (err) { AUBIO_ERR("audio_unit: could not set route change listener (% ld)",err); goto fail; }169 if (err) { AUBIO_ERR("audio_unit: could not set route change listener (%d)\n", (int)err); goto fail; } 170 170 171 171 /* set latency */ 172 172 err = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, 173 173 sizeof(latency), &latency); 174 if (err) { AUBIO_ERR("audio_unit: could not set preferred latency (% ld)",err); goto fail; }174 if (err) { AUBIO_ERR("audio_unit: could not set preferred latency (%d)\n", (int)err); goto fail; } 175 175 176 176 #if 0 // only for iphone OS >= 3.1 … … 178 178 err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, 179 179 sizeof(UInt32), &val); 180 if (err) { AUBIO_ERR("audio_unit: could not set session property to default to speaker "); }180 if (err) { AUBIO_ERR("audio_unit: could not set session property to default to speaker\n"); } 181 181 #endif 182 182 … … 198 198 199 199 err = AudioComponentInstanceNew(comp, &(o->audio_unit)); 200 if (err) { AUBIO_ERR("audio_unit: failed creating the audio unit "); goto fail; }200 if (err) { AUBIO_ERR("audio_unit: failed creating the audio unit\n"); goto fail; } 201 201 202 202 /* enable IO */ … … 205 205 kAudioUnitScope_Input, 1, &enabled, sizeof(enabled)); 206 206 if (err) { 207 AUBIO_ERR("audio_unit: failed enabling input of audio unit ");207 AUBIO_ERR("audio_unit: failed enabling input of audio unit\n"); 208 208 goto fail; 209 209 } … … 214 214 kAudioUnitScope_Global, 0, &max_fps, sizeof(max_fps)); 215 215 if (err) { 216 AUBIO_ERR("audio_unit: could not set maximum frames per slice property (% ld)",err);216 AUBIO_ERR("audio_unit: could not set maximum frames per slice property (%d)\n", (int)err); 217 217 goto fail; 218 218 } … … 220 220 AudioUnitSetProperty (*audio_unit, kAudioUnitProperty_SetRenderCallback, 221 221 kAudioUnitScope_Input, 0, &(o->au_ios_cb_struct), sizeof(o->au_ios_cb_struct)); 222 if (err) { AUBIO_ERR("audio_unit: failed setting audio unit render callback "); goto fail; }222 if (err) { AUBIO_ERR("audio_unit: failed setting audio unit render callback\n"); goto fail; } 223 223 224 224 #if 0 225 225 err = AudioUnitSetProperty (*audio_unit, kAudioUnitProperty_SampleRate, 226 226 kAudioUnitScope_Input, 0, &samplerate, sizeof(Float64)); 227 if (err) { AUBIO_ERR("audio_unit: could not set audio input sample rate "); goto fail; }227 if (err) { AUBIO_ERR("audio_unit: could not set audio input sample rate\n"); goto fail; } 228 228 err = AudioUnitSetProperty (*audio_unit, kAudioUnitProperty_SampleRate, 229 229 kAudioUnitScope_Output, 1, &samplerate, sizeof(Float64)); 230 if (err) { AUBIO_ERR("audio_unit: could not set audio input sample rate "); goto fail; }230 if (err) { AUBIO_ERR("audio_unit: could not set audio input sample rate\n"); goto fail; } 231 231 #endif 232 232 … … 247 247 err = AudioUnitSetProperty (*audio_unit, kAudioUnitProperty_StreamFormat, 248 248 kAudioUnitScope_Input, 0, &audioFormat, sizeof(audioFormat)); 249 if (err) { AUBIO_ERR("audio_unit: could not set audio output format "); goto fail; }249 if (err) { AUBIO_ERR("audio_unit: could not set audio output format\n"); goto fail; } 250 250 err = AudioUnitSetProperty (*audio_unit, kAudioUnitProperty_StreamFormat, 251 251 kAudioUnitScope_Output, 1, &audioFormat, sizeof(audioFormat)); 252 if (err) { AUBIO_ERR("audio_unit: could not set audio input format "); goto fail; }252 if (err) { AUBIO_ERR("audio_unit: could not set audio input format\n"); goto fail; } 253 253 254 254 #if 0 … … 257 257 err = AudioUnitGetProperty (*audio_unit, kAudioUnitProperty_StreamFormat, 258 258 kAudioUnitScope_Input, 0, &thruFormat, &thissize); 259 if (err) { AUBIO_ERR("audio_unit: could not get speaker output format, err: %d ", (int)err); goto fail; }259 if (err) { AUBIO_ERR("audio_unit: could not get speaker output format, err: %d\n", (int)err); goto fail; } 260 260 err = AudioUnitSetProperty (*audio_unit, kAudioUnitProperty_StreamFormat, 261 261 kAudioUnitScope_Output, 1, &thruFormat, sizeof(thruFormat)); 262 if (err) { AUBIO_ERR("audio_unit: could not set input audio format, err: %d ", (int)err); goto fail; }262 if (err) { AUBIO_ERR("audio_unit: could not set input audio format, err: %d\n", (int)err); goto fail; } 263 263 #endif 264 264 265 265 /* time to initialize the unit */ 266 266 err = AudioUnitInitialize(*audio_unit); 267 if (err) { AUBIO_ERR("audio_unit: failed initializing audio, err: %d ", (int)err); goto fail; }267 if (err) { AUBIO_ERR("audio_unit: failed initializing audio, err: %d\n", (int)err); goto fail; } 268 268 269 269 return 0; … … 287 287 inNumber_frames, input_output); 288 288 if (err) { 289 AUBIO_ERR("audio_unit: error performing AudioUnitRender (%d) ", err);289 AUBIO_ERR("audio_unit: error performing AudioUnitRender (%d)\n", err); 290 290 return err; 291 291 } … … 297 297 // FIXME find out why this happens 298 298 if (number_frames < 10) { 299 AUBIO_ERR("audio_unit: got number_frames %d ", (int)number_frames);299 AUBIO_ERR("audio_unit: got number_frames %d\n", (int)number_frames); 300 300 return -1; 301 301 } … … 373 373 374 374 if (o->dio_error) { 375 AUBIO_WRN("audio_unit: dio error %d ", o->total_frames);375 AUBIO_WRN("audio_unit: dio error %d\n", o->total_frames); 376 376 o->dio_error = 0; 377 377 } … … 421 421 422 422 fail: 423 AUBIO_ERR("audio_unit: callback() failed ");423 AUBIO_ERR("audio_unit: callback() failed\n"); 424 424 o->total_frames += AU_IOS_MAX_FRAMES; 425 425 return 1; … … 439 439 err = AudioUnitGetProperty (o->audio_unit, kAudioUnitProperty_SampleRate, 440 440 kAudioUnitScope_Output, 1, &samplerate, &thissize); 441 if (err) { AUBIO_ERR("audio_unit: could not get audio unit sample rate (% ld)",442 err); goto fail; }441 if (err) { AUBIO_ERR("audio_unit: could not get audio unit sample rate (%d)\n", 442 (int)err); goto fail; } 443 443 444 444 /* get hardware input channels */ … … 446 446 err = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareInputNumberChannels, 447 447 &thissize, &input_hw_channels); 448 if (err) { AUBIO_ERR("audio_unit: could not get hardware input channels (% ld)",449 err); goto fail; }448 if (err) { AUBIO_ERR("audio_unit: could not get hardware input channels (%d)\n", 449 (int)err); goto fail; } 450 450 451 451 /* get hardware output channels */ … … 453 453 err = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareOutputNumberChannels, 454 454 &thissize, &output_hw_channels); 455 if (err) { AUBIO_ERR("audio_unit: could not get hardware output channels (% ld)",456 err); goto fail; }455 if (err) { AUBIO_ERR("audio_unit: could not get hardware output channels (%d)\n", 456 (int)err); goto fail; } 457 457 458 458 /* get hardware input volume */ … … 460 460 err = AudioSessionGetProperty(kAudioSessionProperty_InputGainScalar, 461 461 &thissize, &input_hw_volume); 462 if (err) { AUBIO_ERR("audio_unit: could not get hardware input volume (% ld)",463 err); goto fail; }462 if (err) { AUBIO_ERR("audio_unit: could not get hardware input volume (%d)\n", 463 (int)err); goto fail; } 464 464 465 465 /* get hardware output volume */ … … 467 467 err = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareOutputVolume, 468 468 &thissize, &output_hw_volume); 469 if (err) { AUBIO_ERR("audio_unit: could not get hardware output volume (% ld)",470 err); goto fail; }471 472 AUBIO_MSG("audio_unit: opened at %.0fHz, sw channels %din/%dout, hw channels % ldin/%ldout, hw vol %.2fin/%.2fout",469 if (err) { AUBIO_ERR("audio_unit: could not get hardware output volume (%d)\n", 470 (int)err); goto fail; } 471 472 AUBIO_MSG("audio_unit: opened at %.0fHz, sw channels %din/%dout, hw channels %din/%dout, hw vol %.2fin/%.2fout\n", 473 473 samplerate, 474 474 o->sw_input_channels, o->sw_output_channels, 475 input_hw_channels,output_hw_channels,475 (unsigned int)input_hw_channels, (unsigned int)output_hw_channels, 476 476 input_hw_volume, output_hw_volume); 477 477 … … 480 480 err = AudioUnitGetProperty (o->audio_unit, kAudioUnitProperty_MaximumFramesPerSlice, 481 481 kAudioUnitScope_Global, 0, &max_fps, &thissize); 482 if (err) { AUBIO_ERR("audio_unit: could not get maximum frames per slice property % ld",483 err); goto fail; }482 if (err) { AUBIO_ERR("audio_unit: could not get maximum frames per slice property %d\n", 483 (int)err); goto fail; } 484 484 485 485 /* get hardware latency */ … … 487 487 err = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration, 488 488 &thissize, &latency); 489 if (err) { AUBIO_ERR("audio_unit: could not get hardware latency % ld",490 err); goto fail; }489 if (err) { AUBIO_ERR("audio_unit: could not get hardware latency %d\n", 490 (int)err); goto fail; } 491 491 492 492 /* get input latency */ … … 494 494 err = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareInputLatency, 495 495 &thissize, &input_latency); 496 if (err) { AUBIO_ERR("audio_unit: could not get input latency % ld",497 err); goto fail; }496 if (err) { AUBIO_ERR("audio_unit: could not get input latency %d\n", 497 (int)err); goto fail; } 498 498 499 499 /* get output harlatency */ … … 501 501 err = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareOutputLatency, 502 502 &thissize, &output_latency); 503 if (err) { AUBIO_ERR("audio_unit: could not get output latency % ld",504 err); goto fail; }505 506 AUBIO_MSG("audio_unit: I/O latency: %.2fms, %d frames, (%.2fms, %d frames in, %.2fms %d frames out) ",503 if (err) { AUBIO_ERR("audio_unit: could not get output latency %d\n", 504 (int)err); goto fail; } 505 506 AUBIO_MSG("audio_unit: I/O latency: %.2fms, %d frames, (%.2fms, %d frames in, %.2fms %d frames out)\n", 507 507 latency*1000., (sint_t)round(latency*samplerate), 508 508 input_latency*1000., (sint_t)ROUND(input_latency*samplerate), … … 523 523 /* time to start the unit */ 524 524 err = AudioOutputUnitStart (o->audio_unit); 525 if (err) { AUBIO_ERR("audio_unit: could not start unit (% ld)",err); }525 if (err) { AUBIO_ERR("audio_unit: could not start unit (%d)\n", (int)err); } 526 526 return err; 527 527 } … … 531 531 if (o->audio_unit == NULL) return -1; 532 532 OSStatus err = AudioOutputUnitStop (o->audio_unit); 533 if (err) { AUBIO_WRN("audio_unit: failed stopping audio unit (% ld)",err); }533 if (err) { AUBIO_WRN("audio_unit: failed stopping audio unit (%d)\n", (int)err); } 534 534 err = AudioUnitUninitialize (o->audio_unit); 535 if (err) { AUBIO_WRN("audio_unit: failed unitializing audio unit (% ld)",err); }535 if (err) { AUBIO_WRN("audio_unit: failed unitializing audio unit (%d)\n", (int)err); } 536 536 err = AudioSessionSetActive(false); 537 if (err) { AUBIO_WRN("audio_unit: failed stopping audio session (% ld)",err); }537 if (err) { AUBIO_WRN("audio_unit: failed stopping audio session (%d)\n", (int)err); } 538 538 return err; 539 539 } … … 554 554 555 555 if (inInterruptionState == kAudioSessionEndInterruption) { 556 AUBIO_WRN("audio_unit: session interruption ended ");556 AUBIO_WRN("audio_unit: session interruption ended\n"); 557 557 err = AudioSessionSetActive(true); 558 558 if (err) { 559 AUBIO_ERR("audio_unit: could not make session active after interruption (% ld)",err);559 AUBIO_ERR("audio_unit: could not make session active after interruption (%d)\n", (int)err); 560 560 goto fail; 561 561 } 562 562 err = AudioOutputUnitStart(this_unit); 563 563 if (err) { 564 AUBIO_ERR("audio_unit: failed starting unit (% ld)",err);564 AUBIO_ERR("audio_unit: failed starting unit (%d)\n", (int)err); 565 565 goto fail; 566 566 } 567 567 } 568 568 if (inInterruptionState == kAudioSessionBeginInterruption) { 569 AUBIO_WRN("audio_unit: session interruption started ");569 AUBIO_WRN("audio_unit: session interruption started\n"); 570 570 err = AudioOutputUnitStop(this_unit); 571 571 if (err) { 572 AUBIO_ERR("audio_unit: could not stop unit at interruption (% ld)",err);572 AUBIO_ERR("audio_unit: could not stop unit at interruption (%d)\n", (int)err); 573 573 goto fail; 574 574 } 575 575 err = AudioSessionSetActive(false); 576 576 if (err) { 577 AUBIO_ERR("audio_unit: could not make session inactive after interruption (% ld)",err);577 AUBIO_ERR("audio_unit: could not make session inactive after interruption (%d)\n", (int)err); 578 578 goto fail; 579 579 } … … 589 589 &thissize, &category); 590 590 if (err) { 591 AUBIO_ERR("audio_unit: could not get audio category (% ld)",err);591 AUBIO_ERR("audio_unit: could not get audio category (%d)\n", (int)err); 592 592 return err; 593 593 } 594 594 if (category == kAudioSessionCategory_AmbientSound) { 595 AUBIO_MSG("audio_unit: session category is AmbiantSound ");595 AUBIO_MSG("audio_unit: session category is AmbiantSound\n"); 596 596 } else if (category == kAudioSessionCategory_SoloAmbientSound) { 597 AUBIO_MSG("audio_unit: session category is SoloAmbiantSound ");597 AUBIO_MSG("audio_unit: session category is SoloAmbiantSound\n"); 598 598 } else if (category == kAudioSessionCategory_MediaPlayback) { 599 AUBIO_MSG("audio_unit: session category is MediaPlayback ");599 AUBIO_MSG("audio_unit: session category is MediaPlayback\n"); 600 600 } else if (category == kAudioSessionCategory_RecordAudio) { 601 AUBIO_MSG("audio_unit: session category is RecordAudio ");601 AUBIO_MSG("audio_unit: session category is RecordAudio\n"); 602 602 } else if (category == kAudioSessionCategory_PlayAndRecord) { 603 AUBIO_MSG("audio_unit: session category is PlayAndRecord ");603 AUBIO_MSG("audio_unit: session category is PlayAndRecord\n"); 604 604 } else if (category == kAudioSessionCategory_AudioProcessing) { 605 AUBIO_MSG("audio_unit: session category is AudioProcessing ");605 AUBIO_MSG("audio_unit: session category is AudioProcessing\n"); 606 606 } 607 607 return category; … … 615 615 if (has_input) { 616 616 category = kAudioSessionCategory_PlayAndRecord; 617 if (verbose) AUBIO_MSG("audio_unit: setting category to PlayAndRecord ");617 if (verbose) AUBIO_MSG("audio_unit: setting category to PlayAndRecord\n"); 618 618 } else { 619 619 category = kAudioSessionCategory_MediaPlayback; 620 if (verbose) AUBIO_MSG("audio_unit: setting category to MediaPlayback ");620 if (verbose) AUBIO_MSG("audio_unit: setting category to MediaPlayback\n"); 621 621 } 622 622 err = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, 623 623 sizeof(category), &category); 624 624 if (err) { 625 AUBIO_ERR("audio_unit: could not set audio category ");625 AUBIO_ERR("audio_unit: could not set audio category\n"); 626 626 } 627 627 … … 631 631 sizeof (allowMixing), &allowMixing); 632 632 if (err) { 633 AUBIO_ERR("audio_unit: could not set audio session to mix with others ");633 AUBIO_ERR("audio_unit: could not set audio session to mix with others\n"); 634 634 } 635 635 … … 641 641 UInt32 val, thissize = sizeof(currentRoute); 642 642 OSStatus err = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &thissize, ¤tRoute); 643 if (err) { AUBIO_ERR("audio_unit: could not get current route "); goto fail; }643 if (err) { AUBIO_ERR("audio_unit: could not get current route\n"); goto fail; } 644 644 else { 645 645 char *route = (char *)CFStringGetCStringPtr ( currentRoute, kCFStringEncodingUTF8); … … 651 651 } 652 652 if (o->verbose) { 653 AUBIO_MSG ("audio_unit: current route is %s ", route);653 AUBIO_MSG ("audio_unit: current route is %s\n", route); 654 654 } 655 655 free(route); … … 677 677 o->input_enabled = false; 678 678 if (o->verbose) { 679 AUBIO_MSG ("audio_unit: disabling input to avoid feedback ");679 AUBIO_MSG ("audio_unit: disabling input to avoid feedback\n"); 680 680 } 681 681 } else { 682 AUBIO_WRN ("audio_unit: input not disabled as prevent_feedback set to 0, risking feedback ");682 AUBIO_WRN ("audio_unit: input not disabled as prevent_feedback set to 0, risking feedback\n"); 683 683 } 684 684 } … … 686 686 err = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, 687 687 sizeof(UInt32), &val); 688 if (err) { AUBIO_ERR("audio_unit: could not set session OverrideAudioRoute to Speaker "); }688 if (err) { AUBIO_ERR("audio_unit: could not set session OverrideAudioRoute to Speaker\n"); } 689 689 690 690 } … … 704 704 switch (change_reason_number) { 705 705 case kAudioSessionRouteChangeReason_NewDeviceAvailable: 706 AUBIO_MSG("audio_unit: route changed to NewDeviceAvailable ");706 AUBIO_MSG("audio_unit: route changed to NewDeviceAvailable\n"); 707 707 break; 708 708 case kAudioSessionRouteChangeReason_OldDeviceUnavailable: 709 AUBIO_MSG("audio_unit: route changed to OldDeviceUnavailable ");709 AUBIO_MSG("audio_unit: route changed to OldDeviceUnavailable\n"); 710 710 break; 711 711 case kAudioSessionRouteChangeReason_CategoryChange: 712 AUBIO_MSG("audio_unit: route changed to CategoryChange ");712 AUBIO_MSG("audio_unit: route changed to CategoryChange\n"); 713 713 audio_unit_get_audio_session_category(); 714 714 break; 715 715 case kAudioSessionRouteChangeReason_Override: 716 AUBIO_MSG("audio_unit: route changed to Override ");716 AUBIO_MSG("audio_unit: route changed to Override\n"); 717 717 break; 718 718 case kAudioSessionRouteChangeReason_WakeFromSleep: 719 AUBIO_MSG("audio_unit: route changed to WakeFromSleep ");719 AUBIO_MSG("audio_unit: route changed to WakeFromSleep\n"); 720 720 break; 721 721 case kAudioSessionRouteChangeReason_NoSuitableRouteForCategory: 722 AUBIO_MSG("audio_unit: route changed to NoSuitableRouteForCategory ");722 AUBIO_MSG("audio_unit: route changed to NoSuitableRouteForCategory\n"); 723 723 break; 724 724 case kAudioSessionRouteChangeReason_Unknown: 725 725 default: 726 AUBIO_ERR("audio_unit: route changed for an unknown reason!? ");726 AUBIO_ERR("audio_unit: route changed for an unknown reason!?\n"); 727 727 break; 728 728 }
Note: See TracChangeset
for help on using the changeset viewer.