I’m very new to Cpp and open frameworks. I was hoping someone could point me in the right direction so that I can learn by working on a project I’ve been kicking around.
Basically, I want to control the playback of a video file with sound input from a microphone. I would like he file to advance frames based on the volume and duration of the sound detected. Are there any tutorials or similar projects that I can use to get started?
a simple way is to get peak amplitude from the audio stream
and map the values to the speed of the movie. this will roll the movie as long as there’s sound.
some basic code to get you going:
testApp.h
...
//this is just for the audio part
void audioReceived (float * input, int bufferSize, int nChannels);
float maxLevel;
testApp.cpp
void testApp::setup(){
movie.loadMovie("movie.mov");
movie.play();
ofSoundStreamSetup(0,2,this, 44100, 256, 4);
}
void testApp::audioReceived (float * input, int bufferSize, int nChannels){
maxLevel = 0.0f; //reset max to minimum each snd buffer
for (int i = 0; i < bufferSize; i++){
float abs1 = ABS(input[i*2]);
if (maxLevel < abs1) maxLevel = abs1; // grab highest value
}
//now maxLevel is peak amplitude and you can map values
//there are more accurate methods like rms, but this is ok
//this handles only left input channel
}
void testApp::update(){
float movieSpeed = ofMap(maxLevel,0,.1,0,10); // fiddle with these
movie.setSpeed(movieSpeed);
movie.idleMovie();
}