Skip to content

Commit

Permalink
Examples RTAudio fixes (#8228)
Browse files Browse the repository at this point in the history
* rtAudio example fix buffer order

(cherry picked from commit 91789094d0d023abd9068d1f66f9b05e3718eddf)

* Minor fix to audioOutput Example
  • Loading branch information
danoli3 authored Dec 9, 2024
1 parent af33e91 commit cd9e9cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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

0 comments on commit cd9e9cf

Please sign in to comment.