Recording and Playing back audio soon after

I’m trying to find a way of recording audio input and soon after play it back, change speed, reverse, etc.
In fact it would be great to load an ofSoundPlayer with ofSoundBuffer data.

my first approach was to create an empty ofSoundBuffer and append it while recording, but no idea how to play it back and transform the sound. any advices?
Thank you

void ofApp::audioIn(ofSoundBuffer &inBuffer) {
	if (recording) {
		rec.append(inBuffer);
	}
	cout << rec.getNumFrames() << endl;
}

if you open both input and output with the same number of channels, you can use a queue to send buffers from the audioIn to the audioOut callbacks, then just copy the buffer to the audio out and it should play back the recorded input.

super! thanks @arturo.
And any way of inserting recorded buffers in an ofSoundPlayer object to be able to reverse, change speed?

no you would need to do that manually. there’s plans to add an ofSoundFile that would allow to load and save sounds in different formats but it’s not there yet

I had some success of recording / playing back with this code:

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
	if (key == ' ') {
		if (recording == false) {
			rec.clear();
			recording = true;
		}
	}
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
	if (key == ' ') {
		recording = false;
	}
}

//--------------------------------------------------------------
void ofApp::audioIn(ofSoundBuffer &inBuffer) {
	if (recording) {
		rec.append(inBuffer);
	}
}

//--------------------------------------------------------------
void ofApp::audioOut(ofSoundBuffer &outBuffer) {
	if (rec.getNumFrames() > 0 &&  !recording) {
		int pos = (outBuffer.getTickCount() * outBuffer.getNumFrames()) % rec.getNumFrames();
		rec.copyTo(outBuffer, outBuffer.getNumFrames(), outBuffer.getNumChannels(), pos);
	}
}

It would be really great in the future to be able to push an ofSoundBuffer data inside an ofSoundPlayer
something like: soundPlayer.setFromBuffer(recBuffer);