Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] it's posible to get the audio buffer to process outside? (like on ofxGist) #31

Open
moebiussurfing opened this issue Apr 22, 2020 · 1 comment

Comments

@moebiussurfing
Copy link

I would like to get the buffer values from live input or from ofxAudioFile too.

Then I can make some external processing, apart of FFT (bundled on ofxSoundObjects).
On ofxGist I am doing this to process live input, but I'll like to use ofxSoundObject to avoid the manual handle of ofSoundStream settings.

void ofApp::processAudio(float * input, int bufferSize, int nChannels) {
	//convert float array to vector
	vector<float>buffer;
	buffer.assign(&input[0], &input[bufferSize]);

	gist.processAudio(buffer, bufferSize, nChannels, sampleRate);
}

Did this have any sense or I am missing something?

@roymacdonald
Copy link
Owner

Hola Manuel! :)
That way of handling audio data is kinda (old), I recommend you to use an ofSoundBuffer, which is in a very broad way, just a vector of floats ( the data), some other properties like samplerate, number of channels etc, and a big bunch of really useful functions for dealing with the audio data. Take a look at the inline documentation in ofSoundBuffer.h which is quite complete.
So, the idea of ofxSoundObjects it that you extend the class and make your own object to process audio however you want (actually the point of the included SoundObjects is simply to demonstrate this)

So, you can do something like

#include "ofxSoundObjects.h"
class ofxGistSoundObject: public ofxSoundObject {
	
public:

	ofxGistSoundObject:ofxSoundObject(OFX_SOUND_OBJECT_PROCESSOR){
	ofxGist * gist = nullptr;// make sure that you set this properly. It could be a pointer or an instance, it is up to you.

	void process(ofSoundBuffer &input, ofSoundBuffer &output) {
		output = input; // copy the input data to the output. This will copy settings and all. It goes at the "expense" of copying the audio data as well. which in this case I think you need. Otherwise just copy the settings and not the data. 

// I am assuming that your gist.processAudio(buffer, bufferSize, nChannels, sampleRate); function operates destructively over the audio samples, this is why I copied the audio data, so the input does not get corrupted.
		if(gist){// just make sure we dont have a nullptr
			gist->processAudio(output.getBuffer().data(), output.getNumFrames(), output.getNumChannels(), output.getSampleRate()); 
		}
	}
}

Notice that I am assuming that your gist.processAudio(...) function will modify the data in the passed buffer, otherwise you need to put that data back into the output buffer.

Now simply make an instance of ofxGistSoundObject and connect as any of the other objects in the examples :).
Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants