Problem with Simple Audio Engine and Microphone

Forums Programming sound engine: CocosDenshion et al Problem with Simple Audio Engine and Microphone

This topic contains 14 replies, has 7 voices, and was last updated by  tudorizer 2 years, 8 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
Author Posts
Author Posts
November 17, 2009 at 4:10 am #218476

thyphuong
@thyphuong

Hi all, I just got a problem with the SimpleAudioEng. Whenever I add a background music, even still let it run, stop or pause, I still can’t get the blowing received from microphone.

Besides, when I replace the scene and return, the blowing not work. Then I must exit the app and return, it works again and just one time. So what problem I met ? Thanks in advance.

Here my blowing code:

http://www.mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/

And add background music:

[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"Kids.wav"]

I use replaceScene to change between my Scenes.

November 17, 2009 at 5:18 am #266548

Steffen Altwiese
Moderator
@steve-oldmeadow

If you want to record audio then you need to understand about audio sessions. Read the following:

http://developer.apple.com/IPhone/library/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Configuration/Configuration.html#//apple_ref/doc/uid/TP40007875-CH3-SW1

http://www.cocos2d-iphone.org/forum/topic/740#post-4414

November 17, 2009 at 7:05 am #266549

thyphuong
@thyphuong

I think the problem is at the replacescene. When I replace scene, the old scene seems not to be dealloc(maybe it’s just hidden). How can we change scene and dealloc the old scene?

November 17, 2009 at 7:20 am #266550

Steffen Altwiese
Moderator
@steve-oldmeadow

You said that whenever you add background music you can’t get the blowing into the microphone, correct? How can that possibly have anything to do with replaceScene?

November 17, 2009 at 7:47 am #266551

thyphuong
@thyphuong

@Steve: That’s the 1st problem I met. The second one (I did remove the background code line and reinstall the app on iPhone) is that the microphone just received the blowing into the microphone at the 1st time the app start. When I change scene around(using replace) and return to the blowing scene, the blowing can’t be received anymore. It’s still ok on the simulator but not work twice on iPhone. So what’s happened? Thanks Steve.

November 17, 2009 at 7:54 am #266552

Steffen Altwiese
Moderator
@steve-oldmeadow

I can’t help you with the second problem, it sounds like an issue with AVAudioRecorder which I know very little about.

November 17, 2009 at 11:01 am #266553

thyphuong
@thyphuong

Thanks anyway,Steve.

I think that SimpleAudioEngine and AVAudioRecorder can’t use at the same time(even with AVAudioPlayer and AVAudioRecorder). Whenever I use AVAudioPlayer or SimpleAudioEngine, the AVAudioRecorder seems not working. Help! :(

P.S: Run on Simulator but not on iPhone! :((

November 17, 2009 at 11:15 am #266554

Steffen Altwiese
Moderator
@steve-oldmeadow

Yes, they can’t be used at the same time without changing the audio session category. There is only one category that allows simultaneous play and record – that Apple document explains it all.

September 28, 2010 at 10:05 pm #266555

Puddleglum
@puddleglum

The Apple doc has moved; the new location:

https://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Basics/Basics.html#//apple_ref/doc/uid/TP40007875-CH2-SW1

July 4, 2011 at 4:01 pm #266556

phynet
@phynet

I have exactly the same problem…gaaah! what can we do.

July 13, 2011 at 7:36 pm #266557

czyang
Participant
@czyang

Same problem +1.

Is there has a simple solution to let SimpleAudioEngine and AVAudioRecorder working together? or has a solution to receive data from microphone and play sound at one time?

July 19, 2011 at 10:22 am #266558

czyang
Participant
@czyang

I solved my problem:

How to let [[SimpleAudioEngine sharedEngine] playEffect:@”1.aifc”]; and AVAudioRecorder woriking together?

1. Add #import “CDAudioManager.h” to AppDelegate.m

2. Add [CDAudioManager initAsynchronously:kAMM_PlayAndRecord]; to – (void) applicationDidFinishLaunching:(UIApplication*)application

For my situation, it works fine :)

July 22, 2011 at 2:41 am #266559

huyleit
@huyleit

Same problem.

I had used AVAudioPlayer to play music and effect. But solved like czyang is the best:)

July 24, 2011 at 10:08 am #266560

phynet
@phynet

Hi, I solved by putting this code in the init method and that’s all:

UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);

AudioSessionSetActive(true);

I find this solution in the Audio Session cookbook and this post: http://www.cocos2d-iphone.org/forum/topic/14837

August 17, 2011 at 8:46 pm #266561

tudorizer
Participant
@tudorizer

Thanks @phynet. I can add that I added this after calling preloadBackgroundMusic.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.