How make read audio from microphone, or simulate audio stream?
faranaziz opened this issue · 2 comments
faranaziz commented
Want process audio in chunks, how can make?
Thanks you
adamstark commented
This is a little beyond the scope of this library, but if you look at the loadAudioFileAndProcessSamples()
example in examples.cpp
, then you could replace part 3 with...
float gain = 0.5f;
constexpr int frameSize = 512;
for (int i = 0; i < (a.getNumSamplesPerChannel() - frameSize); i += frameSize)
{
for (int channel = 0; channel < a.getNumChannels(); channel++)
{
float frame[frameSize];
// copy samples into frame
for (int k = 0; k < frameSize; k++)
frame[k] = a.samples[channel][i + k];
// !
// do something with the frame here
// !
// copy samples back to audio file buffer
for (int k = 0; k < frameSize; k++)
a.samples[channel][i + k] = frame[k];
a.samples[channel][i] = a.samples[channel][i];
}
}
Hope that helps!
adamstark commented
Note also that the above code will process left and right channels for stereo files so you'll need to handle that yourself by looking at the channel
variable and acting accordingly (depending on your needs).