Qingyao Li
Qingyao Li

Reputation: 173

Unexpected conflict using GCD in iOS

I am developing an app for real-time audio processing, I use the 'EZAudio' to get real-time samples from microphone(which is using GCD) and process them with filters to extract information in a certain band width. When information extracting is succeed I make iPhone vibrate. But iPhone does not vibrate.

Here is the samples getting from the microphone using GCD in EZMicrophoneDelegate, buffer reloads after a bufferSize is filled.

// EZMicrophoneDelegate

-(void)    microphone:(EZMicrophone *)microphone
     hasAudioReceived:(float **)buffer
       withBufferSize:(UInt32)bufferSize
 withNumberOfChannels:(UInt32)numberOfChannels {
    dispatch_async(dispatch_get_main_queue(), ^{
       // filtering
       .
       .
       .
       // information extracting
       .
       .
       .
       // if extracting succeeded, iPhone vibrate
       AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    });
}

I have check the general setting, the vibrate mode is on. I test other apps without microphone delegate, they can vibrate as expected. I also call vibrate in viewDidLoad, also can not vibrate. So I guess the conflict is related to the multithreading using GCD.

Can someone give me some advice on how to solve this problem? Thanks!

Upvotes: 0

Views: 161

Answers (1)

Peter Lapisu
Peter Lapisu

Reputation: 21005

you have to stop microphone listening, before calling

AudioServicesPlaySystemSound

Upvotes: 2

Related Questions