How to use ofxAudioUnitRecorder

i am looking at the newest version of this great addon but can’t figure out how to use ofxAudioUnitRecorder correctly.

the error message says:
Recorder couldn’t determine proper stream format. Is the recorder directly after an Audio Unit?

so i guess somewhere i need to update record ???

thanks, stephan

void testApp::setup(){
    ofSetBackgroundColor(0);

	isRecording = false;

    input.connectTo(output);
	input.start();
    output.start();
}

//--------------------------------------------------------------
void testApp::update(){
    
}

//--------------------------------------------------------------
void testApp::draw(){
    
    ofSetColor(255);
    ofDrawBitmapString("press r to record, s to stop, p to replay", 10,10);
    
    if(isRecording){
        ofSetColor(255, 0, 0);
        ofDrawBitmapString("is recording", 10,30);
    }else{
        ofSetColor(0, 0, 255);
        ofDrawBitmapString("is NOT recording", 10,30);
    }
}

void testApp::exit(){
    
}
void testApp::keyPressed(int key) {
    if(key == 'r'){
        isRecording = true;
        newFileName = ofGetTimestampString()+".m4a";
        
        recorder.startRecording(newFileName);
      //  startRecording(ofToDataPath(newFileName));
    }
	if(key == 's'){
        isRecording = false;
       // stopRecording();
        recorder.stopRecording();
    }
    if(key == 'p'){
        
        
        filePlayer.setFile(ofToDataPath(newFileName));
        UInt32 framesToPlay = filePlayer.getLength();
        cout<<"file frame length "<<framesToPlay<<endl;
        framesToPlay = framesToPlay*2; ///2;// replace with however many frame you want to trim
        filePlayer.setLength(framesToPlay);
        filePlayer.loop();
        filePlayer.connectTo(output);
    }
}

Hey Stephan! The ofxAudioUnitRecorder is a DSP node, and you use it like other audio units in the graph (i.e. you have to connect it into the chain).

So in your case you could do:

input.connectTo(recorder).connectTo(output);

and then the recorder should work.

The design lets you record “Before and After” by having more than one recorder in your chain, like this:

in.connectTo(recordA).connectTo(effect).connectTo(recordB).connectTo(out);

Then, recordA would record a file containing the sound before effect, and recordB would get the sound after effect.

ofxAudioUnit is due for some new examples I think :slight_smile: The DSP stuff doesn’t have a real example yet either.

thanks.

after adding your code, i now get this error when staring to record:

Couldn’t create audio file: 1718449215

I think the recorder’s expecting an absolute path, so can you try it with

newFileName = ofToDataPath(ofGetTimestampString()+".m4a");

That’s actually a bit of a mistake on my part, it should be more consistent for relative vs absolute paths :confused:

sorry should have mentioned that i already tried it and did not work either.

Hey @stephanschulz , sorry this went unreplied From your sample code, it looks like the recorder isn’t actually hooked up in the chain? It’d need to be like:

input.connectTo(recorder).connectTo(output); 

after a long time not working with this i’m finally back.

i downloaded the most recent ofxaudiounit addon and use OF 0.8.1

still can’t get it to work.

option A:

void ofApp::setup(){

    input.listInputDevices();
    input.start();
    input.setDevice("Built-in Microphone");
    input.connectTo(audioRecorder).connectTo(output);
    
  // output.start();
}
 void ofApp::keyReleased(int key){
    if(key == 'r'){
         audioRecorder.startRecording(ofToDataPath("test.m4a"));
         }
	if(key == 's'){
        audioRecorder.stopRecording();
    }
}

gives this error: Couldn’t create audio file: 1718449215

commenting out input.start(); creates no error but a 557 byte file that does not play.

commenting in output.start(); gives this error when starting to record.