2012-11-20 4 views
2

kAudioUnitSubType_VoiceProcessingIOAudioUnit을 사용하는 앱이 있습니다. 입력은 네트워크 스트림에서 가져옵니다. 그 잘 작동하지만 지금은 파일에서 단순한 소리 (푸시 알림을받은 후 경고 소리) 재생 싶어요. AudioUnit이 아직 시작되지 않았거나 이미 처리되지 않은 경우에만 작동합니다. 사운드 파일이 여전히 재생되어 최종 샘플을 듣기 때문에 AudioUnit을 멈출 수도 있습니다. 따라서 재생은 작동하는 것으로 보이지만 조용합니다.AudioUnit과 함께 사운드 파일 재생

실제 장치에서는 성공하지 못했으며 (시뮬레이터에서 작동 할 수도 있음) AudioServicesPlaySystemSoundAVAudioPlayer을 시도했습니다.

이 간단한 작업에 대한 간단한 해결책이 있습니까? 아니면 파일 기반 오디오 콘텐츠를 수동으로 혼합해야합니까?

미리 감사드립니다.

답변

2

오디오 단위로 AUGraph를 만들고 kAudioUnitSubType_AudioFilePlayer 단위를 통해 오디오 파일을 재생할 수 있습니다.

+0

답장을 보내 주셔서 감사합니다. 더 쉬운 해결책이 없다고 이상합니다. 필자는 Apples [MixerHost example] (http://developer.apple.com/library/ios/#samplecode/MixerHost/Introduction/Intro.html)의 도움으로'ExtAudioFileOpenURL' +'ExtAudioFileRead'를 사용하여 AudioBuffers 파일을 읽었습니다.). 그런 다음 준비된 버퍼를 사용하여 네트워크 스트림 대신 경고음을 재생합니다. 현재 저는 믹서 유닛을 사용하지 않습니다. 그것은 완벽한 해결책이 될 것이지만 짧은 경고음에는 필요하지 않습니다. – MrJ

0

이것은 시스템 제한 사항 일 수 있습니다. PlayAndRecord 범주를 사용하는 동안 AudioServicesPlaySystemSound를 호출 할 때 iOS 장치가 아무 것도하지 않으면 AudioUnit을 먼저 중지 한 다음이 함수를 호출하십시오.

2

OSStatus propertySetError = 0; 
UInt32 allowMixing = true; 

propertySetError = AudioSessionSetProperty (
         kAudioSessionProperty_OverrideCategoryMixWithOthers, // 1 
         sizeof (allowMixing),         // 2 
         &allowMixing           // 3 
        ); 

을 시도하거나 당신은 kAudioUnitType_Mixer 유형의 AudioUnit을 사용할 수 있습니다.

(mixer_unit, voice_processing_unit)을 AUGraph에 추가하십시오. 믹서 유닛에 대해 입력 버스 카운트 2를 설정하십시오. u'll 리더 전화 받기,

status = AUGraphConnectNodeInput (_mixSaveGraph, 
             mixerNode,   // source node 
             0,     // source node output bus number 
             saveNode,   // destination node 
             0     // desintation node input bus number 
            ); 

시작 그래프 :

for (UInt16 busNumber = 0; busNumber < busCount; ++busNumber) { 
     AURenderCallbackStruct inputCallbackStruct; 
     inputCallbackStruct.inputProc  = &VoiceMixRenderCallback; 
     inputCallbackStruct.inputProcRefCon = self; 

     status = AUGraphSetNodeInputCallback (_mixSaveGraph, 
               mixerNode, 
               busNumber, 
               &inputCallbackStruct 
              ); 
     if (status) { printf("AudioUnitSetProperty set callback"); return NO; }    

    } 

이 io_unit의 입력 버스에 mixer_unit의 출력 버스를 연결합니다

UInt32 busCount = 2; // bus count for mixer unit input 
status = AudioUnitSetProperty (mixer_unit, 
           kAudioUnitProperty_ElementCount, 
           kAudioUnitScope_Input, 
           0, 
           &busCount, 
           sizeof(busCount) 
           ); 

는 mixer_unit의 각 버스에 대한 콜백을 렌더링 추가 다음과 같이 다른 버스 번호 (0과 1)를 사용하십시오.