Skip to content

Commit 0bcc1d0

Browse files
committed
[Switch] Audren Audio Driver
Separated the Switch audio driver into its own directory, behind a preprocessor flag. There may be other audio drivers provided by the LibNX in the future.
1 parent 6b1fb9c commit 0bcc1d0

File tree

7 files changed

+39
-26
lines changed

7 files changed

+39
-26
lines changed

drivers/SCsub

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ SConscript("windows/SCsub")
1010

1111
# Sounds drivers
1212
SConscript("alsa/SCsub")
13+
if env["platform"] == "switch":
14+
SConscript("audren/SCsub")
1315
SConscript("coreaudio/SCsub")
1416
SConscript("pulseaudio/SCsub")
1517
if env["platform"] == "windows":

drivers/audren/SCsub

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
3+
Import("env")
4+
5+
# Driver source files
6+
env.add_source_files(env.drivers_sources, "audio_driver_audren.cpp")
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* audio_driver_switch.cpp */
2+
/* audio_driver_audren.cpp */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -28,7 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#include "audio_driver_switch.h"
31+
#include "audio_driver_audren.h"
3232

3333
#include "core/os/os.h"
3434
#include "core/project_settings.h"
@@ -45,7 +45,7 @@ static const AudioRendererConfig arConfig = {
4545
.num_mix_buffers = 2,
4646
};
4747

48-
Error AudioDriverSwitch::init_device() {
48+
Error AudioDriverAudren::init_device() {
4949
int latency = GLOBAL_GET("audio/output_latency");
5050
mix_rate = GLOBAL_GET("audio/mix_rate");
5151
channels = 2;
@@ -98,21 +98,21 @@ Error AudioDriverSwitch::init_device() {
9898
return OK;
9999
}
100100

101-
Error AudioDriverSwitch::init() {
101+
Error AudioDriverAudren::init() {
102102
active = false;
103103
thread_exited = false;
104104
exit_thread = false;
105105

106106
Error err = init_device();
107107
if (err == OK) {
108-
thread.start(AudioDriverSwitch::thread_func, this);
108+
thread.start(AudioDriverAudren::thread_func, this);
109109
}
110110

111111
return err;
112112
}
113113

114-
void AudioDriverSwitch::thread_func(void *p_udata) {
115-
AudioDriverSwitch *ad = (AudioDriverSwitch *)p_udata;
114+
void AudioDriverAudren::thread_func(void *p_udata) {
115+
AudioDriverAudren *ad = (AudioDriverAudren *)p_udata;
116116

117117
svcSetThreadPriority(CUR_THREAD_HANDLE, 0x2B);
118118

@@ -168,54 +168,54 @@ void AudioDriverSwitch::thread_func(void *p_udata) {
168168
ad->thread_exited = true;
169169
}
170170

171-
void AudioDriverSwitch::start() {
171+
void AudioDriverAudren::start() {
172172
active = true;
173173
}
174174

175-
int AudioDriverSwitch::get_mix_rate() const {
175+
int AudioDriverAudren::get_mix_rate() const {
176176
return mix_rate;
177177
}
178178

179-
AudioDriver::SpeakerMode AudioDriverSwitch::get_speaker_mode() const {
179+
AudioDriver::SpeakerMode AudioDriverAudren::get_speaker_mode() const {
180180
return speaker_mode;
181181
}
182182

183-
Array AudioDriverSwitch::get_device_list() {
183+
Array AudioDriverAudren::get_device_list() {
184184
Array list;
185185
list.push_back("Default");
186186
return list;
187187
}
188188

189-
String AudioDriverSwitch::get_device() {
189+
String AudioDriverAudren::get_device() {
190190
return device_name;
191191
}
192192

193-
void AudioDriverSwitch::set_device(String device) {
193+
void AudioDriverAudren::set_device(String device) {
194194
lock();
195195
new_device = device;
196196
unlock();
197197
}
198198

199-
void AudioDriverSwitch::lock() {
199+
void AudioDriverAudren::lock() {
200200
mutex.lock();
201201
}
202202

203-
void AudioDriverSwitch::unlock() {
203+
void AudioDriverAudren::unlock() {
204204
mutex.unlock();
205205
}
206206

207-
void AudioDriverSwitch::finish() {
207+
void AudioDriverAudren::finish() {
208208
exit_thread = true;
209209
thread.wait_to_finish();
210210

211211
audrvClose(&audren_driver);
212212
audrenExit();
213213
}
214214

215-
AudioDriverSwitch::AudioDriverSwitch() :
215+
AudioDriverAudren::AudioDriverAudren() :
216216
device_name("Default"),
217217
new_device("Default") {
218218
}
219219

220-
AudioDriverSwitch::~AudioDriverSwitch() {
220+
AudioDriverAudren::~AudioDriverAudren() {
221221
}
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* audio_driver_switch.h */
2+
/* audio_driver_audren.h */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -28,13 +28,17 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31+
#pragma once
32+
#ifndef AUDIO_DRIVER_AUDREN_H
33+
#define AUDIO_DRIVER_AUDREN_H
34+
3135
#include "servers/audio_server.h"
3236
#include "switch_wrapper.h"
3337

3438
#include "core/os/mutex.h"
3539
#include "core/os/thread.h"
3640

37-
class AudioDriverSwitch : public AudioDriver {
41+
class AudioDriverAudren : public AudioDriver {
3842
Thread thread;
3943
Mutex mutex;
4044

@@ -79,6 +83,8 @@ class AudioDriverSwitch : public AudioDriver {
7983
virtual void unlock();
8084
virtual void finish();
8185

82-
AudioDriverSwitch();
83-
~AudioDriverSwitch();
86+
AudioDriverAudren();
87+
~AudioDriverAudren();
8488
};
89+
90+
#endif // !AUDIO_DRIVER_AUDREN_H

platform/switch/SCsub

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ files = [
99
"os_switch.cpp",
1010
"power_switch.cpp",
1111
"joypad_switch.cpp",
12-
"audio_driver_switch.cpp",
1312
"context_gl_switch_egl.cpp",
1413
]
1514

platform/switch/os_switch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ OS_Switch::OS_Switch() {
556556
input = nullptr;
557557
power_manager = nullptr;
558558
gl_context = nullptr;
559-
AudioDriverManager::add_driver(&driver_switch);
559+
AudioDriverManager::add_driver(&driver_audren);
560560

561561
swkbdInlineCreate(&inline_keyboard);
562562
}

platform/switch/os_switch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#include "audio_driver_switch.h"
3231
#include "context_gl_switch_egl.h"
3332
#include "core/os/input.h"
3433
#include "core/os/os.h"
34+
#include "drivers/audren/audio_driver_audren.h"
3535
#include "joypad_switch.h"
3636
#include "main/input_default.h"
3737
#include "power_switch.h"
@@ -46,7 +46,7 @@ class OS_Switch : public OS {
4646
PowerSwitch *power_manager;
4747
ContextGLSwitchEGL *gl_context;
4848
JoypadSwitch *joypad;
49-
AudioDriverSwitch driver_switch;
49+
AudioDriverAudren driver_audren;
5050
String switch_execpath;
5151

5252
SwkbdInline inline_keyboard;

0 commit comments

Comments
 (0)