Question around void audioIn(ofSoundBuffer& buffer)

So I’ve been playing around with Kyle’s ofxFft and trying to update the examples to compatible with master version. Since audioIn now depreciated old void audioIn(float* input, int bufferSize, int nChannels) for void audioIn(ofSoundBuffer& buffer) I just want to see how to translate from the old one to new ofSoundBuffer.

In some case, I was able to simply replace index with buffer right away. But I’m having problem with this example which involve using memcpy When I replace input with &buffer it compiles just fine but won’t get the right output. I’m guessing it had something to do with sizeof(float) but I’m at my wit ends how to fix it.

Any suggestion? Thx!

to copy an audio buffer you just need to use the ’= operator, so if you get buffer in the callback and have another one called audioBuffer you just need to call:

audioBuffer = buffer;

Thanks for promptly reply @arturo! You are awesome!

When I tried that I got this error and it won’t compile.


Then I tried change type of audioInput to ofSoundBuffer instead of float and was able to get away with it for a few lines. But it still won’t compile now it now stuck at fft->setSignal which only takes float*.

I can indeed just go back to use void audioIn(float* input, int bufferSize, int nChannels) and it would works just fine. It’s just that I want to understand relationship/differences between float and ofSoundBuffer here.

you can get a *float out of an ofSoundBuffer just call:

fft->setSignal(buffer.getBuffer().data());
1 Like

Awesome, it works now!
I just put audioInput = buffer.getBuffer().data(); in the memcpy line instead and now it works just fine.

I did tried using buffer.getBuffer() but didn’t realized I had to dig to .data() to get the raw float!
Thank you so much!