diff options
author | zeldakatze <coffee@zeldakatze.de> | 2025-08-06 23:28:30 +0200 |
---|---|---|
committer | zeldakatze <coffee@zeldakatze.de> | 2025-08-06 23:28:30 +0200 |
commit | 0fce665f5da7119809b2d5ce13eb763a6c2eb4c6 (patch) | |
tree | 7374bbfd647520aabe259b7a18e222f4fe462058 /src/audio/devices.cpp | |
parent | 041cc20d66ac91a0f5f6917f1ffb6247bdc5923a (diff) | |
download | abaddon-portaudio-0fce665f5da7119809b2d5ce13eb763a6c2eb4c6.tar.gz abaddon-portaudio-0fce665f5da7119809b2d5ce13eb763a6c2eb4c6.zip |
add portaudio
Diffstat (limited to 'src/audio/devices.cpp')
-rw-r--r-- | src/audio/devices.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/audio/devices.cpp b/src/audio/devices.cpp index dfb7164..09fc156 100644 --- a/src/audio/devices.cpp +++ b/src/audio/devices.cpp @@ -21,6 +21,75 @@ Glib::RefPtr<Gtk::ListStore> AudioDevices::GetCaptureDeviceModel() { return m_capture; } +#ifdef USE_PORTAUDIO +void AudioDevices::SetDevices() { + const PaDeviceInfo *deviceInfo; + int i; + + /* clear the lists */ + m_playback->clear(); + m_capture->clear(); + + /* iterate over all available devices */ + int numDevices = Pa_GetDeviceCount(); + +#if 0 + for(i=0; i<numDevices; i++) { + deviceInfo = Pa_GetDeviceInfo(i); + + /* add it as an input if maxInputChannels > 0 */ + if(deviceInfo->maxInputChannels > 0) { + auto row = *m_playback->append(); + row[m_playback_columns.Name] = deviceInfo->name; + row[m_playback_columns.DeviceID] = i; + + /* if it is the default, mark it as such */ + if(i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) { + m_default_capture_iter = row; + SetActiveCaptureDevice(row); + } + } + + /* add it as an input if maxInputChannels > 0 */ + if(deviceInfo->maxOutputChannels > 0) { + auto row = *m_capture->append(); + row[m_capture_columns.Name] = deviceInfo->name; + row[m_capture_columns.DeviceID] = i; + + /* if it is the default, mark it as such */ + if(i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice) { + m_default_playback_iter = row; + SetActivePlaybackDevice(row); + } + } + + } +#endif + { + auto row = *m_playback->append(); + row[m_playback_columns.Name] = "Default Output"; + row[m_playback_columns.DeviceID] = Pa_GetDefaultOutputDevice(); + m_default_playback_iter = row; + SetActivePlaybackDevice(row); + } + + { + auto row = *m_capture->append(); + row[m_capture_columns.Name] = "Default Input"; + row[m_capture_columns.DeviceID] = Pa_GetDefaultInputDevice(); + m_default_capture_iter = row; + SetActiveCaptureDevice(row); + } + + if (!m_default_playback_iter) { + spdlog::get("audio")->warn("No default playback device found"); + } + + if (!m_default_capture_iter) { + spdlog::get("audio")->warn("No default capture device found"); + } +} +#else /* USE_PORTAUDIO */ void AudioDevices::SetDevices(ma_device_info *pPlayback, ma_uint32 playback_count, ma_device_info *pCapture, ma_uint32 capture_count) { m_playback->clear(); @@ -60,7 +129,39 @@ void AudioDevices::SetDevices(ma_device_info *pPlayback, ma_uint32 playback_coun spdlog::get("audio")->warn("No default capture device found"); } } +#endif /* USE_PORTAUDIO */ +#ifdef USE_PORTAUDIO +std::optional<PaDeviceIndex> AudioDevices::GetPlaybackDeviceIDFromModel(const Gtk::TreeModel::iterator &iter) const { + if (iter) { + return static_cast<PaDeviceIndex>((*iter)[m_playback_columns.DeviceID]); + } + + return std::nullopt; +} + +std::optional<PaDeviceIndex> AudioDevices::GetCaptureDeviceIDFromModel(const Gtk::TreeModel::iterator &iter) const { + if (iter) { + return static_cast<PaDeviceIndex>((*iter)[m_capture_columns.DeviceID]); + } + + return std::nullopt; +} + +std::optional<PaDeviceIndex> AudioDevices::GetDefaultPlayback() const { + PaDeviceIndex pi = Pa_GetHostApiInfo(Pa_GetHostApiCount()-1)->defaultOutputDevice; + if(pi == paNoDevice) + return std::nullopt; + return pi; +} + +std::optional<PaDeviceIndex> AudioDevices::GetDefaultCapture() const { + PaDeviceIndex pi = Pa_GetHostApiInfo(Pa_GetHostApiCount()-1)->defaultInputDevice; + if(pi == paNoDevice) + return std::nullopt; + return pi; +} +#else /* USE_PORTAUDIO */ std::optional<ma_device_id> AudioDevices::GetPlaybackDeviceIDFromModel(const Gtk::TreeModel::iterator &iter) const { if (iter) { return static_cast<ma_device_id>((*iter)[m_playback_columns.DeviceID]); @@ -92,6 +193,7 @@ std::optional<ma_device_id> AudioDevices::GetDefaultCapture() const { return std::nullopt; } +#endif /* USE_PORTAUDIO */ void AudioDevices::SetActivePlaybackDevice(const Gtk::TreeModel::iterator &iter) { m_active_playback_iter = iter; |