summaryrefslogtreecommitdiff
path: root/servers/audio_server.h
diff options
context:
space:
mode:
Diffstat (limited to 'servers/audio_server.h')
-rw-r--r--servers/audio_server.h118
1 files changed, 59 insertions, 59 deletions
diff --git a/servers/audio_server.h b/servers/audio_server.h
index affcb3df7b..5613267909 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -43,23 +43,23 @@
class AudioDriverDummy;
class AudioStream;
-class AudioStreamSample;
+class AudioStreamWAV;
class AudioStreamPlayback;
class AudioDriver {
static AudioDriver *singleton;
- uint64_t _last_mix_time;
- uint64_t _last_mix_frames;
+ uint64_t _last_mix_time = 0;
+ uint64_t _last_mix_frames = 0;
#ifdef DEBUG_ENABLED
- uint64_t prof_ticks;
- uint64_t prof_time;
+ uint64_t prof_ticks = 0;
+ uint64_t prof_time = 0;
#endif
protected:
Vector<int32_t> input_buffer;
- unsigned int input_position;
- unsigned int input_size;
+ unsigned int input_position = 0;
+ unsigned int input_size = 0;
void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);
void update_mix_time(int p_frames);
@@ -121,7 +121,7 @@ public:
void reset_profiling_time() { prof_time = 0; }
#endif
- AudioDriver();
+ AudioDriver() {}
virtual ~AudioDriver() {}
};
@@ -163,72 +163,69 @@ public:
AUDIO_DATA_INVALID_ID = -1,
MAX_CHANNELS_PER_BUS = 4,
MAX_BUSES_PER_PLAYBACK = 6,
- LOOKAHEAD_BUFFER_SIZE = 32,
+ LOOKAHEAD_BUFFER_SIZE = 64,
};
typedef void (*AudioCallback)(void *p_userdata);
private:
- uint64_t mix_time;
- int mix_size;
+ uint64_t mix_time = 0;
+ int mix_size = 0;
- uint32_t buffer_size;
- uint64_t mix_count;
- uint64_t mix_frames;
+ uint32_t buffer_size = 0;
+ uint64_t mix_count = 0;
+ uint64_t mix_frames = 0;
#ifdef DEBUG_ENABLED
- uint64_t prof_time;
+ uint64_t prof_time = 0;
#endif
- float channel_disable_threshold_db;
- uint32_t channel_disable_frames;
+ float channel_disable_threshold_db = 0.0f;
+ uint32_t channel_disable_frames = 0;
- int channel_count;
- int to_mix;
+ int channel_count = 0;
+ int to_mix = 0;
- float playback_speed_scale;
+ float playback_speed_scale = 1.0f;
+
+ bool tag_used_audio_streams = false;
struct Bus {
StringName name;
- bool solo;
- bool mute;
- bool bypass;
+ bool solo = false;
+ bool mute = false;
+ bool bypass = false;
- bool soloed;
+ bool soloed = false;
- //Each channel is a stereo pair.
+ // Each channel is a stereo pair.
struct Channel {
- bool used;
- bool active;
- AudioFrame peak_volume;
+ bool used = false;
+ bool active = false;
+ AudioFrame peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB);
Vector<AudioFrame> buffer;
Vector<Ref<AudioEffectInstance>> effect_instances;
- uint64_t last_mix_with_audio;
- Channel() {
- last_mix_with_audio = 0;
- used = false;
- active = false;
- peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB);
- }
+ uint64_t last_mix_with_audio = 0;
+ Channel() {}
};
Vector<Channel> channels;
struct Effect {
Ref<AudioEffect> effect;
- bool enabled;
+ bool enabled = false;
#ifdef DEBUG_ENABLED
- uint64_t prof_time;
+ uint64_t prof_time = 0;
#endif
};
Vector<Effect> effects;
- float volume_db;
+ float volume_db = 0.0f;
StringName send;
- int index_cache;
+ int index_cache = 0;
};
struct AudioStreamPlaybackBusDetails {
- bool bus_active[MAX_BUSES_PER_PLAYBACK] = { false, false, false, false, false, false };
+ bool bus_active[MAX_BUSES_PER_PLAYBACK] = {};
StringName bus[MAX_BUSES_PER_PLAYBACK];
AudioFrame volume[MAX_BUSES_PER_PLAYBACK][MAX_CHANNELS_PER_BUS];
};
@@ -262,10 +259,13 @@ private:
SafeList<AudioStreamPlaybackListNode *> playback_list;
SafeList<AudioStreamPlaybackBusDetails *> bus_details_graveyard;
+ // TODO document if this is necessary.
+ SafeList<AudioStreamPlaybackBusDetails *> bus_details_graveyard_frame_old;
+
Vector<Vector<AudioFrame>> temp_buffer; //temp_buffer for each level
Vector<AudioFrame> mix_buffer;
Vector<Bus *> buses;
- Map<StringName, Bus *> bus_map;
+ HashMap<StringName, Bus *> bus_map;
void _update_bus_effects(int p_bus);
@@ -281,7 +281,7 @@ private:
struct CallbackItem {
AudioCallback callback;
- void *userdata;
+ void *userdata = nullptr;
};
SafeList<CallbackItem *> update_callback_list;
@@ -309,7 +309,7 @@ public:
ERR_FAIL_V(1);
}
- //do not use from outside audio thread
+ // Do not use from outside audio thread.
bool thread_has_channel_mix_buffer(int p_bus, int p_buffer) const;
AudioFrame *thread_get_channel_mix_buffer(int p_bus, int p_buffer);
int thread_get_mix_buffer_size() const;
@@ -364,12 +364,14 @@ public:
void set_playback_speed_scale(float p_scale);
float get_playback_speed_scale() const;
- void start_playback_stream(Ref<AudioStreamPlayback> p_playback, StringName p_bus, Vector<AudioFrame> p_volume_db_vector, float p_start_time = 0);
- void start_playback_stream(Ref<AudioStreamPlayback> p_playback, Map<StringName, Vector<AudioFrame>> p_bus_volumes, float p_start_time = 0);
+ // Convenience method.
+ void start_playback_stream(Ref<AudioStreamPlayback> p_playback, StringName p_bus, Vector<AudioFrame> p_volume_db_vector, float p_start_time = 0, float p_pitch_scale = 1);
+ // Expose all parameters.
+ void start_playback_stream(Ref<AudioStreamPlayback> p_playback, HashMap<StringName, Vector<AudioFrame>> p_bus_volumes, float p_start_time = 0, float p_pitch_scale = 1, float p_highshelf_gain = 0, float p_attenuation_cutoff_hz = 0);
void stop_playback_stream(Ref<AudioStreamPlayback> p_playback);
void set_playback_bus_exclusive(Ref<AudioStreamPlayback> p_playback, StringName p_bus, Vector<AudioFrame> p_volumes);
- void set_playback_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, Map<StringName, Vector<AudioFrame>> p_bus_volumes);
+ void set_playback_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, HashMap<StringName, Vector<AudioFrame>> p_bus_volumes);
void set_playback_all_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, Vector<AudioFrame> p_volumes);
void set_playback_pitch_scale(Ref<AudioStreamPlayback> p_playback, float p_pitch_scale);
void set_playback_paused(Ref<AudioStreamPlayback> p_playback, bool p_paused);
@@ -380,6 +382,7 @@ public:
bool is_playback_paused(Ref<AudioStreamPlayback> p_playback);
uint64_t get_mix_count() const;
+ uint64_t get_mixed_frames() const;
void notify_listener_changed();
@@ -424,6 +427,8 @@ public:
String capture_get_device();
void capture_set_device(const String &p_name);
+ void set_enable_tagging_used_audio_streams(bool p_enable);
+
AudioServer();
virtual ~AudioServer();
};
@@ -437,26 +442,21 @@ class AudioBusLayout : public Resource {
struct Bus {
StringName name;
- bool solo;
- bool mute;
- bool bypass;
+ bool solo = false;
+ bool mute = false;
+ bool bypass = false;
struct Effect {
Ref<AudioEffect> effect;
- bool enabled;
+ bool enabled = false;
};
Vector<Effect> effects;
- float volume_db;
+ float volume_db = 0.0f;
StringName send;
- Bus() {
- solo = false;
- mute = false;
- bypass = false;
- volume_db = 0;
- }
+ Bus() {}
};
Vector<Bus> buses;