summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
Diffstat (limited to 'servers')
-rw-r--r--servers/audio_server.cpp49
-rw-r--r--servers/audio_server.h24
2 files changed, 46 insertions, 27 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 29014a7ced..ed62e65846 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -77,6 +77,28 @@ double AudioDriver::get_mix_time() const {
return total;
}
+AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {
+ switch (p_channels) {
+ case 4: return SPEAKER_SURROUND_31;
+ case 6: return SPEAKER_SURROUND_51;
+ case 8: return SPEAKER_SURROUND_71;
+ }
+
+ // Default to STEREO
+ return SPEAKER_MODE_STEREO;
+}
+
+int AudioDriver::get_total_channels_by_speaker_mode(AudioDriver::SpeakerMode p_mode) const {
+ switch (p_mode) {
+ case SPEAKER_MODE_STEREO: return 2;
+ case SPEAKER_SURROUND_31: return 4;
+ case SPEAKER_SURROUND_51: return 6;
+ case SPEAKER_SURROUND_71: return 8;
+ }
+
+ ERR_FAIL_V(2);
+}
+
AudioDriver::AudioDriver() {
_last_mix_time = 0;
@@ -424,8 +446,8 @@ void AudioServer::set_bus_count(int p_count) {
}
buses[i] = memnew(Bus);
- buses[i]->channels.resize(_get_channel_count());
- for (int j = 0; j < _get_channel_count(); j++) {
+ buses[i]->channels.resize(get_channel_count());
+ for (int j = 0; j < get_channel_count(); j++) {
buses[i]->channels[j].buffer.resize(buffer_size);
}
buses[i]->name = attempt;
@@ -494,8 +516,8 @@ void AudioServer::add_bus(int p_at_pos) {
}
Bus *bus = memnew(Bus);
- bus->channels.resize(_get_channel_count());
- for (int j = 0; j < _get_channel_count(); j++) {
+ bus->channels.resize(get_channel_count());
+ for (int j = 0; j < get_channel_count(); j++) {
bus->channels[j].buffer.resize(buffer_size);
}
bus->name = attempt;
@@ -798,17 +820,8 @@ void AudioServer::init() {
channel_disable_threshold_db = GLOBAL_DEF("audio/channel_disable_threshold_db", -60.0);
channel_disable_frames = float(GLOBAL_DEF("audio/channel_disable_time", 2.0)) * get_mix_rate();
buffer_size = 1024; //harcoded for now
- switch (get_speaker_mode()) {
- case SPEAKER_MODE_STEREO: {
- temp_buffer.resize(1);
- } break;
- case SPEAKER_SURROUND_51: {
- temp_buffer.resize(3);
- } break;
- case SPEAKER_SURROUND_71: {
- temp_buffer.resize(4);
- } break;
- }
+
+ temp_buffer.resize(get_channel_count());
for (int i = 0; i < temp_buffer.size(); i++) {
temp_buffer[i].resize(buffer_size);
@@ -816,11 +829,11 @@ void AudioServer::init() {
mix_count = 0;
set_bus_count(1);
- ;
set_bus_name(0, "Master");
if (AudioDriver::get_singleton())
AudioDriver::get_singleton()->start();
+
#ifdef TOOLS_ENABLED
set_edited(false); //avoid editors from thinking this was edited
#endif
@@ -992,8 +1005,8 @@ void AudioServer::set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout) {
bus_map[bus->name] = bus;
buses[i] = bus;
- buses[i]->channels.resize(_get_channel_count());
- for (int j = 0; j < _get_channel_count(); j++) {
+ buses[i]->channels.resize(get_channel_count());
+ for (int j = 0; j < get_channel_count(); j++) {
buses[i]->channels[j].buffer.resize(buffer_size);
}
_update_bus_effects(i);
diff --git a/servers/audio_server.h b/servers/audio_server.h
index 13a74856c8..c479d09a3c 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -50,6 +50,7 @@ public:
enum SpeakerMode {
SPEAKER_MODE_STEREO,
+ SPEAKER_SURROUND_31,
SPEAKER_SURROUND_51,
SPEAKER_SURROUND_71,
};
@@ -72,6 +73,9 @@ public:
virtual float get_latency() { return 0; }
+ SpeakerMode get_speaker_mode_by_total_channels(int p_channels) const;
+ int get_total_channels_by_speaker_mode(SpeakerMode) const;
+
AudioDriver();
virtual ~AudioDriver() {}
};
@@ -101,6 +105,7 @@ public:
//re-expose this her, as AudioDriver is not exposed to script
enum SpeakerMode {
SPEAKER_MODE_STEREO,
+ SPEAKER_SURROUND_31,
SPEAKER_SURROUND_51,
SPEAKER_SURROUND_71,
};
@@ -163,15 +168,6 @@ private:
Vector<Bus *> buses;
Map<StringName, Bus *> bus_map;
- _FORCE_INLINE_ int _get_channel_count() const {
- switch (AudioDriver::get_singleton()->get_speaker_mode()) {
- case AudioDriver::SPEAKER_MODE_STEREO: return 1;
- case AudioDriver::SPEAKER_SURROUND_51: return 3;
- case AudioDriver::SPEAKER_SURROUND_71: return 4;
- }
- ERR_FAIL_V(1);
- }
-
void _update_bus_effects(int p_bus);
static AudioServer *singleton;
@@ -205,6 +201,16 @@ protected:
static void _bind_methods();
public:
+ _FORCE_INLINE_ int get_channel_count() const {
+ switch (get_speaker_mode()) {
+ case SPEAKER_MODE_STEREO: return 1;
+ case SPEAKER_SURROUND_31: return 2;
+ case SPEAKER_SURROUND_51: return 3;
+ case SPEAKER_SURROUND_71: return 4;
+ }
+ ERR_FAIL_V(1);
+ }
+
//do not use from outside audio thread
AudioFrame *thread_get_channel_mix_buffer(int p_bus, int p_buffer);
int thread_get_mix_buffer_size() const;