diff options
Diffstat (limited to 'servers/audio_server.cpp')
-rw-r--r-- | servers/audio_server.cpp | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 3139c6bb7a..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; @@ -203,8 +225,9 @@ void AudioServer::_mix_step() { if (!bus_map.has(bus->send)) { bus = buses[0]; //send to master } else { + int prev_index_cache = bus->index_cache; bus = bus_map[bus->send]; - if (bus->index_cache >= bus->index_cache) { //invalid, send to master + if (prev_index_cache >= bus->index_cache) { //invalid, send to master bus = buses[0]; } } @@ -423,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; @@ -493,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; @@ -797,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); @@ -815,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 @@ -991,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); |