77
88#import < AudioUnit/AudioUnit.h>
99
10- static int kOutputBus = 0 ;
11- static int kInputBus = 1 ;
12-
1310@interface TIoTPCMXEchoRecord ()
1411{
1512 AudioUnit audioUnit;
@@ -54,22 +51,12 @@ - (instancetype)initWithChannel:(int)channel isEcho:(BOOL)isEcho
5451 outStreamDes.mReserved = 0 ;
5552 _pcmStreamDescription = outStreamDes;
5653
57- UInt32 enableOutput = 1 ;
58- ret = AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO , kAudioUnitScope_Output , kOutputBus , &enableOutput , sizeof (enableOutput ));
54+ UInt32 flags = 1 ;
55+ ret = AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO , kAudioUnitScope_Input , 1 , &flags , sizeof (flags ));
5956 if (ret != noErr)
6057 return nil ;
6158
62- ret = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat , kAudioUnitScope_Output , kInputBus , &outStreamDes, sizeof (outStreamDes));
63- if (ret != noErr)
64- return nil ;
65-
66- ret = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat , kAudioUnitScope_Input , kOutputBus , &outStreamDes, sizeof (outStreamDes));
67- if (ret != noErr)
68- return nil ;
69-
70- // Enable the microphone input
71- UInt32 enableInput = 1 ;
72- ret = AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO , kAudioUnitScope_Input , kInputBus , &enableInput, sizeof (enableInput));
59+ ret = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat , kAudioUnitScope_Output , 1 , &outStreamDes, sizeof (outStreamDes));
7360 if (ret != noErr)
7461 return nil ;
7562
@@ -87,9 +74,8 @@ - (instancetype)initWithChannel:(int)channel isEcho:(BOOL)isEcho
8774 if (ret != noErr)
8875 return nil ;
8976
90- AudioUnitInitialize (audioUnit);
91-
92- return self;}
77+ return self;
78+ }
9379
9480#define kTVURecoderPCMMaxBuffSize 2048
9581static int pcm_buffer_size = 0 ;
0 commit comments