summaryrefslogtreecommitdiff
path: root/drivers/alsa/audio_driver_alsa.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/alsa/audio_driver_alsa.cpp')
-rw-r--r--drivers/alsa/audio_driver_alsa.cpp115
1 files changed, 58 insertions, 57 deletions
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp
index f4c87da9e9..689f76389b 100644
--- a/drivers/alsa/audio_driver_alsa.cpp
+++ b/drivers/alsa/audio_driver_alsa.cpp
@@ -1,32 +1,32 @@
-/*************************************************************************/
-/* audio_driver_alsa.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
+/**************************************************************************/
+/* audio_driver_alsa.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
#include "audio_driver_alsa.h"
@@ -37,23 +37,23 @@
#include <errno.h>
-#ifdef PULSEAUDIO_ENABLED
+#if defined(PULSEAUDIO_ENABLED) && defined(SOWRAP_ENABLED)
extern "C" {
extern int initialize_pulse(int verbose);
}
#endif
-Error AudioDriverALSA::init_device() {
+Error AudioDriverALSA::init_output_device() {
mix_rate = GLOBAL_GET("audio/driver/mix_rate");
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;
- // If there is a specified device check that it is really present
- if (device_name != "Default") {
- PackedStringArray list = get_device_list();
- if (list.find(device_name) == -1) {
- device_name = "Default";
- new_device = "Default";
+ // If there is a specified output device check that it is really present
+ if (output_device_name != "Default") {
+ PackedStringArray list = get_output_device_list();
+ if (list.find(output_device_name) == -1) {
+ output_device_name = "Default";
+ new_output_device = "Default";
}
}
@@ -75,10 +75,10 @@ Error AudioDriverALSA::init_device() {
//6 chans - "plug:surround51"
//4 chans - "plug:surround40";
- if (device_name == "Default") {
+ if (output_device_name == "Default") {
status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
} else {
- String device = device_name;
+ String device = output_device_name;
int pos = device.find(";");
if (pos != -1) {
device = device.substr(0, pos);
@@ -153,6 +153,7 @@ Error AudioDriverALSA::init_device() {
}
Error AudioDriverALSA::init() {
+#ifdef SOWRAP_ENABLED
#ifdef DEBUG_ENABLED
int dylibloader_verbose = 1;
#else
@@ -167,11 +168,11 @@ Error AudioDriverALSA::init() {
if (initialize_asound(dylibloader_verbose)) {
return ERR_CANT_OPEN;
}
-
+#endif
active.clear();
exit_thread.clear();
- Error err = init_device();
+ Error err = init_output_device();
if (err == OK) {
thread.start(AudioDriverALSA::thread_func, this);
}
@@ -227,18 +228,18 @@ void AudioDriverALSA::thread_func(void *p_udata) {
}
}
- // User selected a new device, finish the current one so we'll init the new device
- if (ad->device_name != ad->new_device) {
- ad->device_name = ad->new_device;
- ad->finish_device();
+ // User selected a new output device, finish the current one so we'll init the new device.
+ if (ad->output_device_name != ad->new_output_device) {
+ ad->output_device_name = ad->new_output_device;
+ ad->finish_output_device();
- Error err = ad->init_device();
+ Error err = ad->init_output_device();
if (err != OK) {
- ERR_PRINT("ALSA: init_device error");
- ad->device_name = "Default";
- ad->new_device = "Default";
+ ERR_PRINT("ALSA: init_output_device error");
+ ad->output_device_name = "Default";
+ ad->new_output_device = "Default";
- err = ad->init_device();
+ err = ad->init_output_device();
if (err != OK) {
ad->active.clear();
ad->exit_thread.set();
@@ -263,7 +264,7 @@ AudioDriver::SpeakerMode AudioDriverALSA::get_speaker_mode() const {
return speaker_mode;
}
-PackedStringArray AudioDriverALSA::get_device_list() {
+PackedStringArray AudioDriverALSA::get_output_device_list() {
PackedStringArray list;
list.push_back("Default");
@@ -298,13 +299,13 @@ PackedStringArray AudioDriverALSA::get_device_list() {
return list;
}
-String AudioDriverALSA::get_device() {
- return device_name;
+String AudioDriverALSA::get_output_device() {
+ return output_device_name;
}
-void AudioDriverALSA::set_device(String device) {
+void AudioDriverALSA::set_output_device(const String &p_name) {
lock();
- new_device = device;
+ new_output_device = p_name;
unlock();
}
@@ -316,7 +317,7 @@ void AudioDriverALSA::unlock() {
mutex.unlock();
}
-void AudioDriverALSA::finish_device() {
+void AudioDriverALSA::finish_output_device() {
if (pcm_handle) {
snd_pcm_close(pcm_handle);
pcm_handle = nullptr;
@@ -327,7 +328,7 @@ void AudioDriverALSA::finish() {
exit_thread.set();
thread.wait_to_finish();
- finish_device();
+ finish_output_device();
}
#endif // ALSA_ENABLED