Skip to content

Commit

Permalink
RtAudio / ofRtAudioSoundStream / ofSoundBaseTypes (#8231)
Browse files Browse the repository at this point in the history
* RTAudio fixes for missing constants

* ofRtAudioSoundStream - Fix for device api not being set in setup.
Fix for ofSoundBaseTypes for printing device list and spelling of unknown
  • Loading branch information
danoli3 authored Dec 11, 2024
1 parent cd9e9cf commit ba02087
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
7 changes: 7 additions & 0 deletions examples/sound/audioOutputExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ void ofApp::setup(){
// Latest linux versions default to the HDMI output
// this usually fixes that. Also check the list of available
// devices if sound doesn't work

//settings.setApi(ofSoundDevice::MS_ASIO);
//settings.setApi(ofSoundDevice::MS_WASAPI);
//settings.setApi(ofSoundDevice::MS_DS);

auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setOutDevice(devices[0]);
}




settings.setOutListener(this);
settings.sampleRate = sampleRate;
settings.numOutputChannels = 2;
Expand Down
7 changes: 6 additions & 1 deletion libs/openFrameworks/sound/ofRtAudioSoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ bool ofRtAudioSoundStream::setup(const ofSoundStreamSettings & settings_)

try {
if (settings.getApi() != ofSoundDevice::Api::UNSPECIFIED) {
ofLogNotice() << "Initialing RtAudio Requested API: " << settings.getApi();
audio = std::make_shared<RtAudio>(toRtAudio(settings.getApi()));
}else{
ofLogNotice() << "Initialing RtAudio with UNSPECIFIED API";
audio = std::make_shared<RtAudio>();
}
ofLogNotice() << "Initialized RtAudio with API: " << RtAudio::getApiName(audio->getCurrentApi());
}
catch (std::exception &error) {
ofLogError() << error.what();
ofLogError() << "Failed to initialize RtAudio: " << error.what();
return false;
}

Expand All @@ -155,6 +158,7 @@ bool ofRtAudioSoundStream::setup(const ofSoundStreamSettings & settings_)
if (settings.numInputChannels > 0) {
if (!settings.getInDevice()) {
ofSoundDevice device;
device.api = settings.getApi();
device.deviceID = audio->getDefaultInputDevice();
settings.setInDevice(device);
}
Expand All @@ -165,6 +169,7 @@ bool ofRtAudioSoundStream::setup(const ofSoundStreamSettings & settings_)
if (settings.numOutputChannels > 0) {
if (!settings.getOutDevice()) {
ofSoundDevice device;
device.api = settings.getApi();
device.deviceID = audio->getDefaultOutputDevice();
settings.setOutDevice(device);
}
Expand Down
15 changes: 11 additions & 4 deletions libs/openFrameworks/sound/ofSoundBaseTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ std::string toString(ofSoundDevice::Api api){
case ofSoundDevice::MS_DS:
return "MS DirectShow";
default:
return "Unkown API";
return "Unknown API";
}
}


void ofBaseSoundStream::printDeviceList() const {
ofLogNotice("ofBaseSoundStream::printDeviceList") << std::endl;
#ifndef TARGET_EMSCRIPTEN
for(int i=ofSoundDevice::ALSA; i<ofSoundDevice::NUM_APIS; ++i){
ofSoundDevice::Api api = (ofSoundDevice::Api)i;
std::vector<ofSoundDevice::Api> platformApis;
#ifdef TARGET_LINUX
platformApis = { ofSoundDevice::ALSA, ofSoundDevice::PULSE, ofSoundDevice::OSS, ofSoundDevice::JACK };
#elif defined(TARGET_OSX)
platformApis = { ofSoundDevice::OSX_CORE };
#elif defined(TARGET_WIN32)
platformApis = { ofSoundDevice::MS_WASAPI, ofSoundDevice::MS_ASIO, ofSoundDevice::MS_DS };
#endif
for (auto api : platformApis) {
auto devices = getDeviceList(api);
if(!devices.empty()){
if (!devices.empty()) {
ofLogNotice("ofBaseSoundStream::printDeviceList") << "Api: " << toString(api);
ofLogNotice("ofBaseSoundStream::printDeviceList") << devices;
}
Expand Down
4 changes: 3 additions & 1 deletion libs/openFrameworks/sound/ofSoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ bool ofSoundStreamSettings::setInDevice(const ofSoundDevice & device){
}
api = device.api;
inDevice = device;
inDevice.api = api;
return true;
}

Expand All @@ -76,6 +77,7 @@ bool ofSoundStreamSettings::setOutDevice(const ofSoundDevice & device){
}
api = device.api;
outDevice = device;
outDevice.api = api;
return true;
}

Expand All @@ -86,7 +88,7 @@ bool ofSoundStreamSettings::setApi(ofSoundDevice::Api api){
return false;
}
if(api!=ofSoundDevice::UNSPECIFIED && outDevice.deviceID!=-1 && outDevice.api != api){
ofLogError("ofSoundStreamSettings") << "Setting API after setting IN device with api: " << toString(outDevice.api) << " won't do anything";
ofLogError("ofSoundStreamSettings") << "Setting API after setting OUT device with api: " << toString(outDevice.api) << " won't do anything";
return false;
}
this->api = api;
Expand Down
18 changes: 10 additions & 8 deletions libs/openFrameworks/utils/ofConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ enum ofTargetPlatform{
#define GLEW_NO_GLU
#define TARGET_GLFW_WINDOW
#define OF_CAIRO
#define OF_RTAUDIO
#include "GL/glew.h"
#include "GL/wglew.h"
#define OF_RTAUDIO
#define __WINDOWS_DS__
#define __WINDOWS_MM__
#define __WINDOWS_WASAPI__
#define __WINDOWS_ASIO__
#define __WINDOWS_MM__ // rtMidi?
#if (_MSC_VER) // microsoft visual studio
//TODO: Fix this in the code instead of disabling the warnings
#define _CRT_SECURE_NO_WARNINGS
Expand Down Expand Up @@ -200,18 +202,15 @@ enum ofTargetPlatform{
#endif

#if defined(TARGET_OS_OSX) && !defined(TARGET_OF_IOS)
#ifndef __MACOSX_CORE__
#define __MACOSX_CORE__
#endif
#define TARGET_GLFW_WINDOW
#define OF_CAIRO
#define OF_RTAUDIO

#ifndef __MACOSX_CORE__
#define __MACOSX_CORE__ // rtAudio
#endif
#ifndef OF_NO_FMOD
#define OF_NO_FMOD
#endif


#include "GL/glew.h"
#include "OpenGL/OpenGL.h"

Expand Down Expand Up @@ -245,6 +244,9 @@ enum ofTargetPlatform{
#else // desktop linux
#define TARGET_GLFW_WINDOW
#define OF_RTAUDIO
#define __LINUX_PULSE__
#define __LINUX_ALSA__
#define __LINUX_OSS__
#include <GL/glew.h>
#endif

Expand Down

0 comments on commit ba02087

Please sign in to comment.