Skip to content
Merged
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
18 changes: 12 additions & 6 deletions examples/sound/audioInputExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ void ofApp::setup(){

soundStream.printDeviceList();

int bufferSize = 256;
int bufferSize = 512;

left.assign(bufferSize, 0.0);
right.assign(bufferSize, 0.0);

volHistory.assign(400, 0.0);

bufferCounter = 0;
Expand All @@ -28,14 +27,16 @@ void ofApp::setup(){
// settings.device = devices[4];

// you can also get devices for an specific api
// auto devices = soundStream.getDevicesByApi(ofSoundDevice::Api::PULSE);
// auto devices = soundStream.getDeviceList(ofSoundDevice::Api::PULSE);
// settings.device = devices[0];

// or get the default device for an specific api:
// settings.api = ofSoundDevice::Api::PULSE;

// or by name

auto devices = soundStream.getMatchingDevices("default");

if(!devices.empty()){
settings.setInDevice(devices[0]);
}
Expand All @@ -51,6 +52,11 @@ void ofApp::setup(){
settings.bufferSize = bufferSize;
soundStream.setup(settings);

bufferSize = soundStream.getBufferSize();

left.assign(bufferSize, 0.0);
right.assign(bufferSize, 0.0);

}

//--------------------------------------------------------------
Expand Down Expand Up @@ -167,8 +173,8 @@ void ofApp::audioIn(ofSoundBuffer & input){

//lets go through each sample and calculate the root mean square which is a rough way to calculate volume
for (size_t i = 0; i < input.getNumFrames(); i++){
left[i] = input[i*2]*0.5;
right[i] = input[i*2+1]*0.5;
left[i] = input[i]*0.5;
right[i] = input[i]*0.5;

curVol += left[i] * left[i];
curVol += right[i] * right[i];
Expand Down
4 changes: 2 additions & 2 deletions examples/sound/audioOutputExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ void ofApp::setup(){
// settings.setOutDevice(devices[0]);
// }

#ifdef TARGET_LINUX

// Latest linux versions default to the HDMI output
// this usually fixes that. Also check the list of available
// devices if sound doesn't work
auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setOutDevice(devices[0]);
}
#endif


settings.setOutListener(this);
settings.sampleRate = sampleRate;
Expand Down
Loading