Reading and recording at the same time with AudioUnit

Hi,
I am trying to read and record at the same time on the iPhone with AudioUnit. For the reading part I made an AUGraph which works fine, constructed like that:
NewAUGraph(&_graph);
_outputUnitComponentDescription.componentType = kAudioUnitType_Output;
_outputUnitComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
_outputUnitComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
_outputUnitComponentDescription.componentFlags = 0;
_outputUnitComponentDescription.componentFlagsMask = 0;
AUGraphAddNode(_graph, &_outputUnitComponentDescription, &_outputNode);
_mixerUnitComponentDescription.componentType = kAudioUnitType_Mixer;
_mixerUnitComponentDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;
_mixerUnitComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
_mixerUnitComponentDescription.componentFlags = 0;
_mixerUnitComponentDescription.componentFlagsMask = 0;
AUGraphAddNode(_graph, &_mixerUnitComponentDescription, &_mixerNode);
AUGraphConnectNodeInput(_graph, _mixerNode, 0, _outputNode, 0);
AUGraphOpen(_graph);
AUGraphNodeInfo(_graph, _outputNode, NULL, &_outputUnit);
AUGraphNodeInfo(_graph, _mixerNode, NULL, &_mixerUnit);
_generatorUnitComponentDescription.componentType = kAudioUnitType_MusicDevice;
_generatorUnitComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
_generatorUnitComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
_generatorUnitComponentDescription.componentFlags = 0;
_generatorUnitComponentDescription.componentFlagsMask = 0;
for(int i=0; i< [_urlList count]; i++)
SoundBuffer* soundBufferTemp = [_bufferSoundList objectAtIndex:i];
AURenderCallbackStruct renderCallbackStruct;
renderCallbackStruct.inputProc = MyFileRenderCallback;
renderCallbackStruct.inputProcRefCon = soundBufferTemp;
AudioStreamBasicDescription* inputAsbd = [soundBufferTemp getASBD];
err = AudioUnitSetProperty(_mixerUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
i,
inputAsbd,
sizeof(AudioStreamBasicDescription));
UInt32 zero = 0;
err = AudioUnitSetProperty(_mixerUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&zero,
sizeof(zero));
err = AUGraphSetNodeInputCallback(_graph,
_mixerNode,
i,
&renderCallbackStruct);
This works well, for the recording AudioUnit I did the following:
OSStatus err;
AudioComponentDescription audioComponentDescription;
AudioComponent audioComponent;
audioComponentDescription.componentType = kAudioUnitType_Output;
audioComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
audioComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
audioComponentDescription.componentFlags = 0;
audioComponentDescription.componentFlagsMask = 0;
audioComponent = AudioComponentFindNext(NULL, &audioComponentDescription);
err = AudioComponentInstanceNew(audioComponent, &_audioUnit);
UInt32 size;
size = sizeof(AudioStreamBasicDescription);
err = AudioUnitGetProperty(_audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
1,
&_soundFileDataFormat,
&size);
_soundFileDataFormat.mSampleRate = 44100.00;
AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
kInputBus,
&_soundFileDataFormat,
size);
AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
kOutputBus,
&_soundFileDataFormat,
size);
AURenderCallbackStruct renderCallbackStruct;
renderCallbackStruct.inputProc = MyRecorderCallback;
renderCallbackStruct.inputProcRefCon = self;
UInt32 one = 1;
UInt32 zero = 0;
err = AudioUnitSetProperty(_audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&one,
sizeof(one));
err = AudioUnitSetProperty(_audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
kOutputBus,
&zero,
sizeof(zero));
err = AudioUnitSetProperty (_audioUnit,
kAudioOutputUnitProperty_SetInputCallback,
kAudioUnitScope_Global,
0,
&renderCallbackStruct,
sizeof(AURenderCallbackStruct));
err = AudioUnitInitialize(_audioUnit);
Then in I setup a file to write in:
- (void) openFile
OSStatus err;
err = ExtAudioFileCreateWithURL((CFURLRef) _soundFileUrl,
kAudioFileCAFType,
&_soundFileDataFormat,
NULL,
kAudioFileFlags_EraseFile,
&_extAudioFileRef);
err = ExtAudioFileSetProperty(_extAudioFileRef,
kExtAudioFileProperty_ClientDataFormat,
sizeof(AudioStreamBasicDescription),
&_soundFileDataFormat);
err = ExtAudioFileWriteAsync(_extAudioFileRef,
0,
NULL);
All this things works well (I check by printing err in the log which I removed here for clarity).
And then in the callback for recording I do the following:
static OSStatus MyRecorderCallback(void *inRefCon,
AudioUnitRenderActionFlags* inActionFlags,
const AudioTimeStamp* inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumFrames,
AudioBufferList* ioData)
OSStatus err= noErr;
AudioUnitRecorder* auRec = (AudioUnitRecorder*) inRefCon;
[auRec allocateAudioBufferList:1 size:inNumFrames*4];
err = AudioUnitRender(auRec.audioUnit,
inActionFlags,
inTimeStamp,
inBusNumber,
inNumFrames,
auRec.audioBufferList);
err = ExtAudioFileWriteAsync(auRec.extAudioFileRef,
inNumFrames,
auRec.audioBufferList);
return err;
(Then I close the file after recording at the same time I close the AudioUnit)
Now the strange thing is that all this works perfectly well in the simulator: I can record and play at the same time but on the device, the callback for recording is not ran (I check by trying to print something in the log in the callback function.) which men no writing in the file and an empty file in the end.
Any one has any idea of what could be causing this?
Thanks
Alexandre

Just in case some one might need it, I solved my problem:
I simply needed to initialize the AudioSession before playing/recording. I did so with the following code:
OSStatus err;
AudioSessionInitialize(NULL, NULL, MyInterruptionListener, self);
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
err = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory);
AudioSessionSetActive(TRUE);

Similar Messages

  • 16 channels of audio recording at the same time with a MAC BOOK?

    Hi,
    I want to know how many channels of audio I can record at the same-time with a MAC BOOK (2.16GHz Intel Core 2 Duo, 1GB memory 120GB hard drive, Double-layer SuperDrive), firewire audio device and Logic Pro 8?
    You see I am aiming to record a live gig and I want to come into a firewire recording interface with 16 channels of audio all at the same time (24-bit, 44Khz) Does anyone know if this is possible? Or am I looking for trouble? No plug-ins will be used just record straight in. Anyone have some experience with this?
    Thanks.

    Ok, like this:
    Macbook - FW Port - FW Cable -In- MOTU Traveler -Out- External Harddrive.
    Firewire is capable of chaining units.
    Also plugged into your motu traveler will be an optical cable coming from the ADA.
    This will carry the 8 channels of audio it outputs.
    Also another good thing to do is to also have an optical cable FROM the optical output of your Traveler into the Behringer's input.
    That way you can sync the Behringer's digital clock to that of the Traveler, giving you a slightly better sounding signal that if you were to sync the traveler to the Behringer. This is simply because the traveler has a better quality digital clock than the Behringer unit so it's best to use that. To do this you just select "Adat input" on the back of the Behringer, and leave the Travelers sync to "Internal Clock". It is only a very very slight difference and you may not be able to notice the difference but for the cost of an optical cable it's worth doing.
    It will all make a lot more sense when you have the two units and the harddrive all plugged in.

  • Can't watch a programme and record at the same time.

    I rang Sky who say it's nothing to do with them. Gave me Lovedigital number. Rang them they said contact my landlord. Rang Bristol City Council, they say it's nothing to do with them.

    What I meant is the number of cables going into your Sky box. If there is only one cable going to your Sky box, that answers the question of why you can't watch one thing and record another at the same time - your Sky + box would require two inputs to do that. From what you've said it sounds like a communal dish set up. If that is right then whoever looks after that are the people you need to contact to see about the possibility of getting a double feed into your home. 

  • Streaming Live and Recording at the same time

    Currently I allow users to stream live Audio and Video and I would like to begin recording the Audio/Video at the same time.
    The only way I can figure out streaming Live and Recording is to create two NetStreams and connect with the same NetConnection and have one netstream publish "live" and the other netstream publish "record". This just doesn't seem very efficient because it would be streaming the same thing twice to the FMS.
    Is this the only way to go about this? or am I going the wrong way with this?

    What you want to do is record to FMS.  Then use NetStream.Play(filename, -1) to only play live.

  • Intel and nVidia at the same time, with OpenGL

    Hi all,
    I'd like to set up a multi-seat Xorg config, with the onboard Intel video powering three monitors connected to that card, and an nVidia card powering two monitors connected to it.
    This seems straightforward enough to configure in the Xorg config which I have done, but when the time comes to install the "nvidia" package, it conflicts with the Intel driver.  Specifically I can't have mesa-libgl (Intel) and nvidia-libgl installed at the same time.
    I guess this is fair enough as they both want to become the default GL driver, but in my case the actual GL driver will depend on which seat is being used - sitting at the Intel monitors the GL driver should be Intel, and sitting at the nVidia monitors it should be the nvidia GL driver.
    Is there a way to install both drivers at the same time, and specify which libGL to use by e.g. changing the library search path?
    I have looked at Bumblebee but it seems aimed at duplicating displays across to the other video card, whereas I want the displays to appear on directly attached hardware.

    Short answer: No.
    Long answer: Arch wiki NVIDIA (replace nouveau with the intel driver package).
    They do not work at the same time, however.

  • How do I read and write at the same time using the NI-CAN channel API?

    Here's the situation.  I have one CAN bus, and I need to read and write channel data (using the channel API) at the same time both at an interval of 20 ms.  It's easy to do one or the other using the channel API, but you can't setup a channel task to do both.  It's either input or output, not both.  Is this even possible?

    Hi,
    yes , this is possible. But you have to create two tasks, one for input and one for output. see the attached example for LabVIEW.
    If you download and install NI-CAN 2.4 you will get this example and one for C and VB as well.
    DirkW
    Attachments:
    Single Sample Input Output same Port.vi ‏79 KB

  • Reading and writng at the same time through UrlConnection

    Hi,
    I have written an applet that communicates with a servlet through a Urlconnection. However, the outputstream from the applet must be closed before the inputstream can receive info from the servlet. The coding is as follows :
    try{
    URL url = new URL("http://"+codeBase().getHost()+":8001/servlet/gameQuizServlet");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    conn.setInput(true);
    conn.setUseCaches(false);
    conn.setRequestProperty("Content-Type", "application/octet-stream");
    out1 =new PrintStream(conn.getOutputStream());
    out1.println("how are you");
    out1.flush();
    out1.close();
    in1 = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while ((FromServer=in1.readLine())!=null) {
    if the statement 'out1.close()' is below the 'in1.readLine()', the applet can't output the "how are you" to the servlet. (although the applet can receive info from the servlet through 'in1.readLine()).
    The applet and the servlet have to communicate in an interactive mode. I have tried the command 'setAllowUserInteraction(true)' instead of 'setDoOutput(true)' but it doesn't work. How can I make the inputStream and outputStream in the Urlconnection active at the same time.
    Best regards.
    Hoifo

    Thanks for your opinion, DrClap.
    I've already written a server(using ServerSocket in server, Socket in applet) for this application but when internet user using brower behind the firewall, it stops the communications. Using HTTP is one of the ways to go through the firewall, but has limitation. Can I go through the firewall by other means?
    Regards.
    Hoifo

  • Pr Premier monthly Cloud subscription open CS6 and CC at the same time with one subscription?

    I download both CS6 and CC version.
    I have a subscription for montly Premier Pro, but open just a CC version and not a CS6
    WHY??
    Do i need a second subscription for the same program??

    Thanks!
    But as the CC version opens, the CS6 version does not open and says it has expired.
    Do I have miss to set something?

  • Read and write at the same time. Or: Read while the file is being written.

    Hello
    I'm a student working on a live streaming project. The video i get should be streamed live, so i have to read the file from disk while it is written.
    When I try to do this I get an access denied or permission denied (i can provide the detailed error if you need it) which seems obvious to me. Still, is there a way around this?
    The file which i try to read is monotonically increasing in size, so it's not a 4gb file which is truncated at the end of the video recording.
    I hope someone can help
    thanks
    lukas
    Edited by: Jossnaz on Jun 25, 2008 6:26 AM

    Jossnaz wrote:
    Hello
    I'm a student working on a live streaming project. The video i get should be streamed live, so i have to read the file from disk while it is written.
    When I try to do this I get an access denied or permission denied (i can provide the detailed error if you need it) which seems obvious to me. Still, is there a way around this?
    So you are getting the Stream from one source, writing to a file, then also steaming it live to a client?
    I would use threads, 3 of them I think:
    1) Read content from the input stream and send it into two different PippedOutputStreams
    2) A consumer thread attached to the end of one of the PippedInputStreams linked to #1 that streams to the client
    3) A consumer thread attached to the end of the second PippedInputStream linked to #1 that streams to the file

  • Watching DVR and Recording at the same time???

    Can I record one show while watching a different show I have already recorded on my DVR?

    I think both were correct.
    You can watch a previously recorded program while two programs are being recorded.
    You can not watch a third channel while two programs are being recorded.
    Essentially the DVR can only tune in two channels at a time.

  • JFM recording and streaming at the same time

    Hello Everyone,
    I was hoping someone could help me with using a webcam device for sending and recording at the same time.
    At this moment I'm only able to record. I tried to make another processor, and put the input of the streaming processor
    to the one that is recording, but problem is the streaming processor outputs not a streaming format. If I could stream
    with RTP I could embed a player in a website and view from there, while recording at the same time.
    Could somebody explain to me what do to here, or provide me a snippet of code, I really need this to work.
    I created this code, but this only records.
    import java.io.IOException;
    import javax.media.*;
    import javax.media.format.*;
    import javax.media.protocol.*;
    public class Record {
         public Processor createProcessor(){
              Format formats[] = new Format[2];
              formats[0] = new AudioFormat(AudioFormat.IMA4);//IMA4
              formats[1] = new VideoFormat(VideoFormat.CINEPAK);//CINEPAK
              FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME);
              Processor p = null;
              try {
                   p = Manager.createRealizedProcessor(new ProcessorModel(formats,outputType));
                   } catch (IOException e) {
                        System.out.println("Error! 1");
                   System.exit(-1);
                   } catch (NoProcessorException e) {
                        System.out.println("Error! 2");
                   System.exit(-1);
                   } catch (CannotRealizeException e) {
                        System.out.println("Error! 3");
                   System.exit(-1);
              return p;
         public static void main(String [] args) {
              Record record = new Record();
              Processor p = record.createProcessor();
              DataSink sink;
              MediaLocator dest = new MediaLocator("file://newfile.mpeg");
              try{
                   sink = Manager.createDataSink(p.getDataOutput(), dest);
                   sink.open();
                   p.start();
                   sink.start();
                   try {
                   Thread.currentThread().sleep(6000);
                   } catch (InterruptedException ie) {
                   p.stop();
                   p.close();
                   Thread.currentThread().sleep(6000);
                   sink.close();
              } catch (Exception exception) {
                   System.out.println("error!");
              System.out.println("finished");
    Kind regards,
    Bluesboy89

    Take a look at the following example. It demonstrates how to do 2 things with the same input (namely view and record)
    [http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/JVidCap.html]

  • Recording and listening at the same time?

    So i'm recording using a usb micrphone, which works fine, i'd like to know how to hear all the instruments through my headphones and record at the same time, so i can actually hear when i need to come in to sing! any ideas?

    JanKaratas wrote:
    So i'm recording using a usb micrphone, which works fine, i'd like to know how to hear all the instruments through my headphones and record at the same time
    you're going to have to provide more details on your setup, because that is how GB works.
    you'd have to purposefully mute or solo tracks in order to not hear everything playing in your project

  • Can I use a camera for application in Labview and VBAI at the same time ?

    Dear all,
    I'm trying to save an AVI file with Labview and make an image process with VBAI at the same time, in one machine.
    The error : "Camera already in use" displayed.
    My Camera is a GIGE and I work with Imaqdx. I've test the multicast mode but it only operate with several machines.
    How can I do this ?
    Thank's to help me,
    Yoann B

    I'm not necessarily saying that.  It's been a while since I've used VBAI, so I don't remember all of the capabilities, but if VBAI can do the inspection and recording at the same time, you should be fine.
    The trick is that only one program can access the camera at the same time.  That application reserves the camera, thus making it unavailable to others.
    Chris
    Certified LabVIEW Architect
    Certified TestStand Architect

  • Capter and edit at the same time

    Can I capture and edit at the same time with cs4, Also can i export to dvd or to tape and edit at the same time?
    Sebastian

    No.

  • Ringing and vibrating at the same time

    Is there a way to set my iPhone 3 so that it will ring and vibrate at the same time with an incoming call?

    Go to Settings > Sounds > Vibrate On.

Maybe you are looking for

  • Windows 8.1 Computer taken over.

    My daughter used my computer last night to download a movie turned off my virus protection and used a program to down load.  By the time I realized it was too late.  She down loaded something called Optimization tool and uTorrent.  I uninstalled both

  • Empty file

    Hi Guys, I have idoc to file scenario. The mapping is good and tested. The file is getting created in target directory but there are no payload values in it. Only a special character [] is present in text file. Please suggest Thanks,

  • Sapscript for J1INCERT

    In transaction J1INCERT (TDS Certificate),i want to know where can attach sapscript to take printout. I have one sapscript form and have made ztransaction by copying J1INCERT.

  • HOW CAN I GET THE "ARTIST" DESIGNATION TO APPEAR ON THE CD TRACK LISTING ?

    HOW CAN I GET THE ARTIST TO APPEAR ON THE CD TRACK LISTING? IT IS ALREADY IN THE "GET INFO" LISTING. THANKS!

  • UPGRADE  RELATED TO OSS MODIFICATIONS

    Hi all, we are on verge of upgradtion form 4.6c to ECC 6.00 we have a lot of programs where we have applied oss notes. Do i need to apply the oss notes in the new version ECC 6.00 too. How can i know whether SAP has provided the same note modificatio