diff options
Diffstat (limited to 'drivers/alsa/audio_driver_alsa.cpp')
-rw-r--r-- | drivers/alsa/audio_driver_alsa.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp index 90c3d3af83..61475c74e7 100644 --- a/drivers/alsa/audio_driver_alsa.cpp +++ b/drivers/alsa/audio_driver_alsa.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -32,13 +32,19 @@ #ifdef ALSA_ENABLED +#include "core/config/project_settings.h" #include "core/os/os.h" -#include "core/project_settings.h" #include <errno.h> +#ifdef PULSEAUDIO_ENABLED +extern "C" { +extern int initialize_pulse(int verbose); +} +#endif + Error AudioDriverALSA::init_device() { - mix_rate = GLOBAL_GET("audio/mix_rate"); + mix_rate = GLOBAL_GET("audio/driver/mix_rate"); speaker_mode = SPEAKER_MODE_STEREO; channels = 2; @@ -104,7 +110,7 @@ Error AudioDriverALSA::init_device() { // In ALSA the period size seems to be the one that will determine the actual latency // Ref: https://www.alsa-project.org/main/index.php/FramesPeriods unsigned int periods = 2; - int latency = GLOBAL_GET("audio/output_latency"); + int latency = GLOBAL_GET("audio/driver/output_latency"); buffer_frames = closest_power_of_2(latency * mix_rate / 1000); buffer_size = buffer_frames * periods; period_size = buffer_frames; @@ -147,13 +153,28 @@ Error AudioDriverALSA::init_device() { } Error AudioDriverALSA::init() { +#ifdef DEBUG_ENABLED + int dylibloader_verbose = 1; +#else + int dylibloader_verbose = 0; +#endif +#ifdef PULSEAUDIO_ENABLED + // On pulse enabled systems Alsa will silently use pulse. + // It doesn't matter if this fails as that likely means there is no pulse + initialize_pulse(dylibloader_verbose); +#endif + + if (initialize_asound(dylibloader_verbose)) { + return ERR_CANT_OPEN; + } + active = false; thread_exited = false; exit_thread = false; Error err = init_device(); if (err == OK) { - thread = Thread::create(AudioDriverALSA::thread_func, this); + thread.start(AudioDriverALSA::thread_func, this); } return err; @@ -183,7 +204,7 @@ void AudioDriverALSA::thread_func(void *p_udata) { int total = 0; while (todo && !ad->exit_thread) { - uint8_t *src = (uint8_t *)ad->samples_out.ptr(); + int16_t *src = (int16_t *)ad->samples_out.ptr(); int wrote = snd_pcm_writei(ad->pcm_handle, (void *)(src + (total * ad->channels)), todo); if (wrote > 0) { @@ -291,16 +312,10 @@ void AudioDriverALSA::set_device(String device) { } void AudioDriverALSA::lock() { - if (!thread) { - return; - } mutex.lock(); } void AudioDriverALSA::unlock() { - if (!thread) { - return; - } mutex.unlock(); } @@ -312,13 +327,8 @@ void AudioDriverALSA::finish_device() { } void AudioDriverALSA::finish() { - if (thread) { - exit_thread = true; - Thread::wait_to_finish(thread); - - memdelete(thread); - thread = nullptr; - } + exit_thread = true; + thread.wait_to_finish(); finish_device(); } |