From cd9e9cf3e8234fcce4d282f04d5813108b863cbd Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Tue, 10 Dec 2024 10:21:46 +1100 Subject: [PATCH] Examples RTAudio fixes (#8228) * rtAudio example fix buffer order (cherry picked from commit 91789094d0d023abd9068d1f66f9b05e3718eddf) * Minor fix to audioOutput Example --- examples/sound/audioInputExample/src/ofApp.cpp | 18 ++++++++++++------ .../sound/audioOutputExample/src/ofApp.cpp | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/sound/audioInputExample/src/ofApp.cpp b/examples/sound/audioInputExample/src/ofApp.cpp index fef39b0d9f5..72da4ece7e6 100644 --- a/examples/sound/audioInputExample/src/ofApp.cpp +++ b/examples/sound/audioInputExample/src/ofApp.cpp @@ -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; @@ -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]); } @@ -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); + } //-------------------------------------------------------------- @@ -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]; diff --git a/examples/sound/audioOutputExample/src/ofApp.cpp b/examples/sound/audioOutputExample/src/ofApp.cpp index 9de296ef252..1d9fdd87122 100644 --- a/examples/sound/audioOutputExample/src/ofApp.cpp +++ b/examples/sound/audioOutputExample/src/ofApp.cpp @@ -41,7 +41,7 @@ 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 @@ -49,7 +49,7 @@ void ofApp::setup(){ if(!devices.empty()){ settings.setOutDevice(devices[0]); } -#endif + settings.setOutListener(this); settings.sampleRate = sampleRate;