Hey guys,
I am starting to dwell into the audio processing caverns, and I am not sure where I should be looking right now. I found this thread: http://www.rawmaterialsoftware.com/viewtopic.php?f=8&t=9780 which game me some general direction but I’m not sure how I should be using the classes.
Here’s the deal. I am doing some 3d rendering, and I would like the parts of the scene to be scaled depending on what the beat is. I mean, once I can get the info of the current sample, I could average, or get the highest float on the sample, etc and interpret that value as the scale. I’m not sure what the appropiate way to doing this:
READ THE FILE
AudioFormatReader* reader = formatManager.createReaderFor (file);
if (reader != nullptr)
{
currentAudioFileSource = new AudioFormatReaderSource (reader, true);
// ..and plug it into our transport source
transportSource.setSource (currentAudioFileSource,
32768, // tells it to buffer this many samples ahead
&thread, // this is the background thread to use for reading-ahead
reader->sampleRate);
transportSource.setPosition (0);
transportSource.start();
}
// Start timer to check for the current progress of what I'm playing. (UGLY, is there another way???)
startTimer (1000 / 30);
Then, I do this on my timer callback.
void OpenGLCanvas::timerCallback()
{
// Update playing audio bar
if (transportSource.isPlaying()) {
m_musicProgress = transportSource.getCurrentPosition() / transportSource.getLengthInSeconds();
// Get the next audio sample and calculate the scale based on an average.
AudioSourceChannelInfo info;
transportSource.getNextAudioBlock(info);
float* channelLeft = info.buffer->getSampleData(0);
float* channelRight = info.buffer->getSampleData(1);
float avg = 0;
for (int i = 0; i<info.numSamples; i++) {
avg += channelLeft[i] / (info.numSamples * 2);
avg += channelRight[i] / (info.numSamples * 2);
}
printf("average: %4.4f", avg);
m_scale = avg;
}
}
So this crashes, and I bet it’s because I’m doing something terribly wrong and possibly annoying to juce as well. What would be the best way to implement this? Is there somewhere I can start reading for audio processing in general? How about juce specific?