iphone + mic / audio in

hello forum

is it possible to get access to the iphone’s build in mic ? and how about the ipod mic on the head set?

i know there are voice recording app on the app store but i have found much on how to do that, even on the cocoa developer sites.

cheers,
stephan.

it certainly is!

make sure to grab a newish version of the system from the repo: http://code.google.com/p/ofxiphone

then you can use the sound stream pretty much the same as the main version of openframeworks. I have not tested it out with the main of audio example app, but over here: http://work.mrkbrz.com/node/21 there is an example.

thanks for the info.

i downloaded the newest version as suggested. (i already had one but am not sure if it was the newest)

but if i try running an example i get the following error:

  
error: conflicting declaration 'typedef int32_t BOOL'  

someone suggested to do this to FreeImage.h

  
//typedef int32_t BOOL;    
#define BOOL int32_t;  

but this throws even more errors.

any ideas?

thanks, stephan.

I’m able to get the mic input working on the iPhone but anything going in is coming out the earpiece. I can disable audio output in the ofSoundStreamSetup, which fixes this, but now I’m curious about sound output on the iPhone.

Can you route sound to the earpiece and the speakers separately/simultaneously? If no, how do you choose which to route to?

As far as I know, if you want audio in at the same time as audio out, it forces the output to the earpiece. There must be a workaround, but I haven’t found it yet. I guess the reason they did this is to prevent feedback, seeming as the mic and the speaker are in the same space.

If you look at line 195 or so of iPhoneSoundStream.mm, you’ll see

// this is supposed to make the audio come out of the speaker rather
// than the receiver, but I don’t think it works when using the microphone as well.
UInt32 category = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(category), &category);

That’s where it’s chosen. It is possible in software - speakerphone works without a problem, but it might be in the private frameworks somewhere, along with DSP code to supress feedback.

for the BOOL error, I always get this one, then never remember how I fixed it. Try changing your testApp.cpp’s file name to testApp.mm, it might work. The conflict exists between objective-c’s BOOL primitive type and freeImage’s own BOOL typedef. I know you can get around it without making too much of a mess. Send me the code if you’re really stuck.

[quote author=“stephanschulz”]thanks for the info.

i downloaded the newest version as suggested. (i already had one but am not sure if it was the newest)

but if i try running an example i get the following error:

  
error: conflicting declaration 'typedef int32_t BOOL'  

someone suggested to do this to FreeImage.h

  
//typedef int32_t BOOL;    
#define BOOL int32_t;  

but this throws even more errors.

any ideas?

thanks, stephan.[/quote]

I had this issue to.
All you need to do is

  1. Make sure you have:
  
//typedef int32_t BOOL;    
#define BOOL int32_t;  

  1. At the bottom of FreeImage.h do:

change:

  
#endif // FREEIMAGE_H  

to:

  
 #undef BOOL  
  
#endif // FREEIMAGE_H  

It is a bit of a hack but it works.
Theo

thank you all. it is working great now.
i really enjoy working in openframeworks.

stephan.

I am not getting the actual idea for audio in i-phone because it will be operate in i-tune only but tell me all things from basic because i can not able to understand.
tell me.

what’s the latest on this? I’m having trouble getting ofSoundStream to work on iphone. The examples compile fine. I’d like to do some real time audio io stuff, but I’m stuck.

I’m guessing I need to update to the latest version of the iphone code from the svn (Is that still the case, or does the latest version of the main iphone download have working ofSoundStream code?). Memo describes how to update to the latest versions in his post here:

http://forum.openframeworks.cc/t/problems-with-ofxiphone/2885/2

I’ve been unable to get anything to compile after following Memo’s instructions. Any more specific instructions would help (e.g. you have to replace the directories manually in finder, or you have to replace them in a certain way using xcode, etc).

this is super not final - but you can check the sound in / out examples in the tmp 0061 release: http://www.openframeworks.cc/versions/p-…-ne-FAT.zip

make sure to read the notes about the sound simulator in testApp::setup

Theo

amazing. thanks!

audio in and out both work in the simulator and the phone, with one exception: on the phone, I only get audio out through the headphones, not from the speaker. Is that expected behavior?

anyway you guys rock!

hmm it works for me - did you try switching the switch on the side from vibrate to sound?

Alright! Turns out the issue was that the audio was just really quiet. I realized that the audio is being sent out the “receiver” (on the top front of the phone) rather than the louder “speaker” (on the bottom). So the question became, how do I change the audio routing?

I found some info in the iphone docs, and eventually stumbled a super hacky way to make it work. Hopefully someone can provide a more “correct” way, but here it is:

  
  
#include "AudioServices.h"  
  

  
	  
UInt32 audioRouteOverride = 'spkr';   
AudioSessionSetProperty (		  
   'ovrd',  
   sizeof (audioRouteOverride),  
   &audioRouteOverride           
);  
  

oh, also, you will have to find that header file (I just used spotlight) and drag and drop it into your src file in xcode.

:shock: whoa, thanks for this, I wondered why my sound has been so quiet for the last little bit.