diff --git a/ofxVideoRecorderExample/src/ofApp.cpp b/ofxVideoRecorderExample/src/ofApp.cpp index 3579897..d97e624 100644 --- a/ofxVideoRecorderExample/src/ofApp.cpp +++ b/ofxVideoRecorderExample/src/ofApp.cpp @@ -23,11 +23,18 @@ void ofApp::setup(){ ofAddListener(vidRecorder.outputFileCompleteEvent, this, &ofApp::recordingComplete); -// soundStream.listDevices(); -// soundStream.setDeviceID(11); - soundStream.setup(this, 0, channels, sampleRate, 256, 4); - - ofSetWindowShape(vidGrabber.getWidth(), vidGrabber.getHeight() ); +// soundStream.printDeviceList(); + ofSoundStreamSettings settings; + auto devices = soundStream.getDeviceList(); + settings.setInDevice(devices[0]); + settings.setInListener(this); + settings.sampleRate = sampleRate; + settings.bufferSize = 256; + settings.numInputChannels = 2; + settings.numOutputChannels = 0; + soundStream.setup(settings); + + ofSetWindowShape(vidGrabber.getWidth(), vidGrabber.getHeight() ); bRecording = false; ofEnableAlphaBlending(); } @@ -82,9 +89,9 @@ void ofApp::draw(){ } //-------------------------------------------------------------- -void ofApp::audioIn(float *input, int bufferSize, int nChannels){ +void ofApp::audioIn(ofSoundBuffer& buffer){ if(bRecording) - vidRecorder.addAudioSamples(input, bufferSize, nChannels); + vidRecorder.addAudioSamples(buffer); } //-------------------------------------------------------------- diff --git a/ofxVideoRecorderExample/src/ofApp.h b/ofxVideoRecorderExample/src/ofApp.h index 301d3a0..14f1fb8 100644 --- a/ofxVideoRecorderExample/src/ofApp.h +++ b/ofxVideoRecorderExample/src/ofApp.h @@ -20,7 +20,7 @@ class ofApp : public ofBaseApp{ void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); - void audioIn(float * input, int bufferSize, int nChannels); + void audioIn(ofSoundBuffer& buffer); ofVideoGrabber vidGrabber; ofxVideoRecorder vidRecorder; diff --git a/src/ofxVideoRecorder.cpp b/src/ofxVideoRecorder.cpp index b20079e..8a0640c 100644 --- a/src/ofxVideoRecorder.cpp +++ b/src/ofxVideoRecorder.cpp @@ -431,6 +431,27 @@ void ofxVideoRecorder::addAudioSamples(float *samples, int bufferSize, int numCh } } +//-------------------------------------------------------------- +void ofxVideoRecorder::addAudioSamples(ofSoundBuffer& buffer) { + if (!bIsRecording || bIsPaused) return; + + if(bIsInitialized && bRecordAudio){ + int size = buffer.getNumFrames() * buffer.getNumChannels(); + audioFrameShort * shortSamples = new audioFrameShort; + shortSamples->data = new short[size]; + shortSamples->size = size; + + for(int i=0; i < buffer.getNumFrames(); i++){ + for(int j=0; j < buffer.getNumChannels(); j++){ + shortSamples->data[i * buffer.getNumChannels() + j] = (short) (buffer.getSample(i, j) * 32767.0f); + } + } + audioFrames.Produce(shortSamples); + audioThread.signal(); + audioSamplesRecorded += size; + } +} + //-------------------------------------------------------------- void ofxVideoRecorder::start(){ if(!bIsInitialized) return; diff --git a/src/ofxVideoRecorder.h b/src/ofxVideoRecorder.h index c3095b7..b143eb2 100644 --- a/src/ofxVideoRecorder.h +++ b/src/ofxVideoRecorder.h @@ -131,6 +131,7 @@ class ofxVideoRecorder : public ofThread bool addFrame(const ofPixels &pixels); void addAudioSamples(float * samples, int bufferSize, int numChannels); + void addAudioSamples(ofSoundBuffer& buffer); void start(); void close();