hi all
i am completely new to audio in openframesworks.
I started off with examples/sound/audioInputExample
and created a stripped down version of the example as a separate class that I load in my app.
Then I try to grab microphone input but i only get zeros…
I have a HUGE question mark about the member function “audioIn”, this is not called from anyway in the example, so I assume this is a callback function that is setup… somewhere else???
I am not sure. can someone please clarify?
my application is in a testApp.cpp/.h pair of files, and I am #including the cAudioIn.cpp/.h which are based on the aforementioned example (and which I attach below).
Since the ofSoundStream::setup(…) member function requires the ofBaseApp pointer to be passed in , I had to modify the constructor of my “classAudioIn” abit to get that from testApp and pass it on to ofSoundStream. Regardless, it seems that the “audioIn” member function, is never called on its own (as is the case in the example)
Any clues as to why I get no input? note that from the example I do get input without any problem…
this is audioIn.h
#pragma once
#include "ofMain.h"
class classAudioIn {
public:
void setup(ofBaseApp *app);
float updateVol();
bool audioInEnabled ; //enable - disable processing
void audioIn(float * input, int bufferSize, int nChannels);
private:
//void draw();
vector <float> left;
vector <float> right;
//vector <float> volHistory;
float smoothedVol;
ofSoundStream soundStream;
};
and this is audioIn.cpp
void classAudioIn::setup(ofBaseApp *app){
soundStream.listDevices();
int bufferSize = 256;
smoothedVol = 0.0;
left.assign(bufferSize, 0.0);
right.assign(bufferSize, 0.0);
audioInEnabled = false ;
soundStream.setup(app, 0, 2, 44100, bufferSize, 4);
}
float classAudioIn::updateVol(){
float outVol;
//lets scale the vol up to a 0-1 range
outVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true);
return outVol;
}
//--------------------------------------------------------------
void classAudioIn::audioIn(float * input, int bufferSize, int nChannels){
if ( audioInEnabled ){
float curVol = 0.0;
int numCounted = 0; // samples are "interleaved"
//lets go through each sample and calculate the root mean square which is a rough way to calculate volume
for (int i = 0; i < bufferSize; i++){
left[i] = input[i*2]*0.5;
right[i] = input[i*2+1]*0.5;
curVol += left[i] * left[i];
curVol += right[i] * right[i];
numCounted+=2;
}
//this is how we get the mean of rms :)
curVol /= (float)numCounted;
// this is how we get the root of rms :)
curVol = sqrt( curVol );
smoothedVol *= 0.93;
smoothedVol += 0.07 * curVol;
}
}
running the application I get the following info on startup:
[notice ] ofxBox2d:: - world created -
[notice ] ofRtAudioSoundStream: device 0 hw:HDA Intel,0
[notice ] ofRtAudioSoundStream: ----* default ----*
[notice ] ofRtAudioSoundStream: maximum output channels 8
[notice ] ofRtAudioSoundStream: maximum input channels 2
[notice ] ofRtAudioSoundStream: -----------------------------------------
[notice ] ofRtAudioSoundStream: device 1 hw:HDA Intel,1
[notice ] ofRtAudioSoundStream: maximum output channels 2
[notice ] ofRtAudioSoundStream: maximum input channels 0
[notice ] ofRtAudioSoundStream: -----------------------------------------
[notice ] ofRtAudioSoundStream: device 2 hw:HDA Intel,2
[notice ] ofRtAudioSoundStream: maximum output channels 0
[notice ] ofRtAudioSoundStream: maximum input channels 2
[notice ] ofRtAudioSoundStream: -----------------------------------------
[notice ] ofRtAudioSoundStream: device 3 default
[notice ] ofRtAudioSoundStream: maximum output channels 32
[notice ] ofRtAudioSoundStream: maximum input channels 32
[notice ] ofRtAudioSoundStream: -----------------------------------------
thank you in advance for your help