Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to ofSoundStreamSettings and ofSoundBuffer #66

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions ofxVideoRecorderExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}

//--------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ofxVideoRecorderExample/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/ofxVideoRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ofxVideoRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down