@@ -38,6 +38,7 @@ - (IBAction)onClickJoinButton:(id)sender {
3838@interface CustomPcmAudioSource ()<AgoraRtcEngineDelegate, AgoraPcmSourceDelegate>
3939@property (weak , nonatomic ) IBOutlet UIView *containerView;
4040@property (weak , nonatomic ) IBOutlet UISwitch *pushPcmSwitch;
41+ @property (weak , nonatomic ) IBOutlet UISwitch *pushMicrophoneSwitch;
4142@property (nonatomic , strong )VideoView *localView;
4243@property (nonatomic , strong )VideoView *remoteView;
4344@property (nonatomic , strong )AgoraRtcEngineKit *agoraKit;
@@ -72,7 +73,7 @@ - (void)viewDidLoad {
7273 [self .containerView layoutStream: @[self .localView, self .remoteView]];
7374
7475 NSString *filePath = [[NSBundle mainBundle ] pathForResource: @" output.raw" ofType: nil ];
75- self.pcmSourcePush = [[AgoraPCMSourcePush alloc ] initWithDelegate: self filePath: filePath sampleRate: 44100 channelsPerFrame: 1 bitPerSamples: 16 samples: 441 * 10 ];
76+ self.pcmSourcePush = [[AgoraPCMSourcePush alloc ] initWithDelegate: self filePath: filePath sampleRate: 44100 channelsPerFrame: 2 bitPerSamples: 16 samples: 441 * 10 ];
7677
7778 // set up agora instance when view loaded
7879 AgoraRtcEngineConfig *config = [[AgoraRtcEngineConfig alloc ] init ];
@@ -82,18 +83,9 @@ - (void)viewDidLoad {
8283 self.agoraKit = [AgoraRtcEngineKit sharedEngineWithConfig: config delegate: self ];
8384
8485 NSString *channelName = [self .configs objectForKey: @" channelName" ];
85- // make myself a broadcaster
86- [self .agoraKit setClientRole: (AgoraClientRoleBroadcaster)];
8786 // enable video module and set up video encoding configs
8887 [self .agoraKit enableAudio ];
8988
90- AgoraVideoEncoderConfiguration *encoderConfig = [[AgoraVideoEncoderConfiguration alloc ] initWithSize: CGSizeMake (960 , 540 )
91- frameRate: (AgoraVideoFrameRateFps15)
92- bitrate: 15
93- orientationMode: (AgoraVideoOutputOrientationModeFixedPortrait)
94- mirrorMode: (AgoraVideoMirrorModeAuto)];
95- [self .agoraKit setVideoEncoderConfiguration: encoderConfig];
96-
9789 AgoraAudioTrackConfig *trackConfig = [[AgoraAudioTrackConfig alloc ] init ];
9890 trackConfig.enableLocalPlayback = YES ;
9991 self.trackId = [self .agoraKit createCustomAudioTrack: (AgoraAudioTrackTypeMixable) config: trackConfig];
@@ -117,12 +109,9 @@ - (void)viewDidLoad {
117109 // when joining channel. The channel name and uid used to calculate
118110 // the token has to match the ones used for channel join
119111 AgoraRtcChannelMediaOptions *options = [[AgoraRtcChannelMediaOptions alloc ] init ];
120- options.autoSubscribeAudio = YES ;
121112 options.autoSubscribeVideo = NO ;
122- options.publishMicrophoneTrack = YES ;
113+ options.publishMicrophoneTrack = NO ;
123114 options.publishCameraTrack = NO ;
124- options.publishCustomAudioTrack = YES ;
125- options.publishCustomAudioTrackId = self.trackId ;
126115 options.clientRoleType = AgoraClientRoleBroadcaster;
127116
128117 [[NetworkManager shared ] generateTokenWithChannelName: channelName uid: 0 success: ^(NSString * _Nullable token) {
@@ -144,6 +133,13 @@ - (IBAction)pushPCM:(UISwitch *)sender {
144133 }
145134 AgoraRtcChannelMediaOptions *mediaOption = [[AgoraRtcChannelMediaOptions alloc ] init ];
146135 mediaOption.publishCustomAudioTrack = sender.isOn ;
136+ mediaOption.publishCustomAudioTrackId = self.trackId ;
137+ [self .agoraKit updateChannelWithMediaOptions: mediaOption];
138+ }
139+
140+ - (IBAction )pushMicrophone : (UISwitch*)sender {
141+ AgoraRtcChannelMediaOptions *mediaOption = [[AgoraRtcChannelMediaOptions alloc ] init ];
142+ mediaOption.publishMicrophoneTrack = sender.isOn ;
147143 [self .agoraKit updateChannelWithMediaOptions: mediaOption];
148144}
149145
@@ -159,9 +155,9 @@ - (void)viewDidDisappear:(BOOL)animated {
159155// AgoraPcmSourcePushDelegate
160156- (void )onAudioFrame : (void *)data {
161157 [self .agoraKit pushExternalAudioFrameRawData: data
162- samples: 441 * 10
158+ samples: 441 * 10 * 2
163159 sampleRate: 44100
164- channels: 1
160+ channels: 2
165161 trackId: self .trackId
166162 timestamp: 0 ];
167163}
0 commit comments