Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize variables in servers/audio #52639

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/math/audio_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static const float AUDIO_MIN_PEAK_DB = -200.0f; // linear2db(AUDIO_PEAK_OFFSET)

struct AudioFrame {
//left and right samples
float l, r;
float l = 0, r = 0;

_ALWAYS_INLINE_ const float &operator[](int idx) const { return idx == 0 ? l : r; }
_ALWAYS_INLINE_ float &operator[](int idx) { return idx == 0 ? l : r; }
Expand Down
7 changes: 0 additions & 7 deletions servers/audio/audio_driver_dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@
#include "core/os/os.h"

Error AudioDriverDummy::init() {
active = false;
thread_exited = false;
exit_thread = false;
samples_in = nullptr;

mix_rate = GLOBAL_GET("audio/driver/mix_rate");
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;

int latency = GLOBAL_GET("audio/driver/output_latency");
buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
Expand Down
16 changes: 8 additions & 8 deletions servers/audio/audio_driver_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ class AudioDriverDummy : public AudioDriver {
Thread thread;
Mutex mutex;

int32_t *samples_in;
int32_t *samples_in = nullptr;

static void thread_func(void *p_udata);

unsigned int buffer_frames;
unsigned int mix_rate;
SpeakerMode speaker_mode;
unsigned int buffer_frames = 0;
unsigned int mix_rate = 0;
SpeakerMode speaker_mode = SPEAKER_MODE_STEREO;

int channels;
int channels = 2;

bool active;
bool thread_exited;
mutable bool exit_thread;
bool active = false;
bool thread_exited = false;
mutable bool exit_thread = false;

public:
const char *get_name() const {
Expand Down
13 changes: 2 additions & 11 deletions servers/audio/audio_filter_sw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,9 @@ float AudioFilterSW::get_response(float p_freq, Coeffs *p_coeffs) {
return H;
}

AudioFilterSW::AudioFilterSW() {
sampling_rate = 44100;
resonance = 0.5;
cutoff = 5000;
gain = 1.0;
mode = LOWPASS;
stages = 1;
}
AudioFilterSW::AudioFilterSW() {}

AudioFilterSW::Processor::Processor() {
set_filter(nullptr);
}
AudioFilterSW::Processor::Processor() {}

void AudioFilterSW::Processor::set_filter(AudioFilterSW *p_filter, bool p_clear_history) {
if (p_clear_history) {
Expand Down
21 changes: 10 additions & 11 deletions servers/audio/audio_filter_sw.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
class AudioFilterSW {
public:
struct Coeffs {
float a1, a2;
float b0, b1, b2;
float a1 = 0.0, a2 = 0.0;
float b0 = 0.0, b1 = 0.0, b2 = 0.0;

//bool operator==(const Coeffs &p_rv) { return (FLOATS_EQ(a1,p_rv.a1) && FLOATS_EQ(a2,p_rv.a2) && FLOATS_EQ(b1,p_rv.b1) && FLOATS_EQ(b2,p_rv.b2) && FLOATS_EQ(b0,p_rv.b0) ); }
Coeffs() { a1 = a2 = b0 = b1 = b2 = 0.0; }
};

enum Mode {
Expand All @@ -57,9 +56,9 @@ class AudioFilterSW {

class Processor { // simple filter processor

AudioFilterSW *filter;
AudioFilterSW *filter = nullptr;
Coeffs coeffs;
float ha1, ha2, hb1, hb2; //history
float ha1 = 0.0, ha2 = 0.0, hb1 = 0.0, hb2 = 0.0; //history
Coeffs incr_coeffs;

public:
Expand All @@ -73,12 +72,12 @@ class AudioFilterSW {
};

private:
float cutoff;
float resonance;
float gain;
float sampling_rate;
int stages;
Mode mode;
float cutoff = 5000.0;
Copy link
Contributor

@AaronRecord AaronRecord Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these have an f suffix since they are floats?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add it, but it is really needed?
Looks that both, with and without f, produce same assembly in godbolt

float resonance = 0.5;
float gain = 1.0;
float sampling_rate = 44100.0;
int stages = 1;
Mode mode = LOWPASS;

public:
float get_response(float p_freq, Coeffs *p_coeffs);
Expand Down
11 changes: 0 additions & 11 deletions servers/audio/audio_rb_resampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,8 @@ void AudioRBResampler::clear() {
}

AudioRBResampler::AudioRBResampler() {
rb = nullptr;
offset = 0;
read_buf = nullptr;
rb_read_pos.set(0);
rb_write_pos.set(0);

rb_bits = 0;
rb_len = 0;
rb_mask = 0;
read_buff_len = 0;
channels = 0;
src_mix_rate = 0;
target_mix_rate = 0;
}

AudioRBResampler::~AudioRBResampler() {
Expand Down
20 changes: 10 additions & 10 deletions servers/audio/audio_rb_resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@
#include "servers/audio_server.h"

struct AudioRBResampler {
uint32_t rb_bits;
uint32_t rb_len;
uint32_t rb_mask;
uint32_t read_buff_len;
uint32_t channels;
uint32_t src_mix_rate;
uint32_t target_mix_rate;
uint32_t rb_bits = 0;
uint32_t rb_len = 0;
uint32_t rb_mask = 0;
uint32_t read_buff_len = 0;
uint32_t channels = 0;
uint32_t src_mix_rate = 0;
uint32_t target_mix_rate = 0;

SafeNumeric<int> rb_read_pos;
SafeNumeric<int> rb_write_pos;

int32_t offset; //contains the fractional remainder of the resampler
int32_t offset = 0; //contains the fractional remainder of the resampler
enum {
MIX_FRAC_BITS = 13,
MIX_FRAC_LEN = (1 << MIX_FRAC_BITS),
MIX_FRAC_MASK = MIX_FRAC_LEN - 1,
};

float *read_buf;
float *rb;
float *read_buf = nullptr;
float *rb = nullptr;

template <int C>
uint32_t _resample(AudioFrame *p_dest, int p_todo, int32_t p_increment);
Expand Down
4 changes: 1 addition & 3 deletions servers/audio/audio_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ void AudioStreamRandomPitch::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "random_pitch", PROPERTY_HINT_RANGE, "1,16,0.01"), "set_random_pitch", "get_random_pitch");
}

AudioStreamRandomPitch::AudioStreamRandomPitch() {
random_pitch = 1.1;
}
AudioStreamRandomPitch::AudioStreamRandomPitch() {}

void AudioStreamPlaybackRandomPitch::start(float p_from_pos) {
playing = playback;
Expand Down
12 changes: 6 additions & 6 deletions servers/audio/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AudioStreamPlaybackResampled : public AudioStreamPlayback {

AudioFrame internal_buffer[INTERNAL_BUFFER_LEN + CUBIC_INTERP_HISTORY];
unsigned int internal_buffer_end = -1;
uint64_t mix_offset;
uint64_t mix_offset = 0;

protected:
void _begin_resample();
Expand All @@ -89,7 +89,7 @@ class AudioStreamPlaybackResampled : public AudioStreamPlayback {
public:
virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;

AudioStreamPlaybackResampled() { mix_offset = 0; }
AudioStreamPlaybackResampled() {}
};

class AudioStream : public Resource {
Expand Down Expand Up @@ -140,8 +140,8 @@ class AudioStreamPlaybackMicrophone : public AudioStreamPlaybackResampled {
GDCLASS(AudioStreamPlaybackMicrophone, AudioStreamPlaybackResampled);
friend class AudioStreamMicrophone;

bool active;
unsigned int input_ofs;
bool active = false;
unsigned int input_ofs = 0;

Ref<AudioStreamMicrophone> microphone;

Expand Down Expand Up @@ -175,7 +175,7 @@ class AudioStreamRandomPitch : public AudioStream {

Set<AudioStreamPlaybackRandomPitch *> playbacks;
Ref<AudioStream> audio_stream;
float random_pitch;
float random_pitch = 1.1;

protected:
static void _bind_methods();
Expand Down Expand Up @@ -203,7 +203,7 @@ class AudioStreamPlaybackRandomPitch : public AudioStreamPlayback {
Ref<AudioStreamRandomPitch> random_pitch;
Ref<AudioStreamPlayback> playback;
Ref<AudioStreamPlayback> playing;
float pitch_scale;
float pitch_scale = 1.0;

public:
virtual void start(float p_from_pos = 0.0) override;
Expand Down
4 changes: 1 addition & 3 deletions servers/audio/effects/audio_effect_amplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,4 @@ void AudioEffectAmplify::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_volume_db", "get_volume_db");
}

AudioEffectAmplify::AudioEffectAmplify() {
volume_db = 0;
}
AudioEffectAmplify::AudioEffectAmplify() {}
4 changes: 2 additions & 2 deletions servers/audio/effects/audio_effect_amplify.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AudioEffectAmplifyInstance : public AudioEffectInstance {
friend class AudioEffectAmplify;
Ref<AudioEffectAmplify> base;

float mix_volume_db;
float mix_volume_db = 0.0;

public:
virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override;
Expand All @@ -50,7 +50,7 @@ class AudioEffectAmplify : public AudioEffect {
GDCLASS(AudioEffectAmplify, AudioEffect);

friend class AudioEffectAmplifyInstance;
float volume_db;
float volume_db = 0.0;

protected:
static void _bind_methods();
Expand Down
4 changes: 0 additions & 4 deletions servers/audio/effects/audio_effect_chorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ void AudioEffectChorus::_bind_methods() {
}

AudioEffectChorus::AudioEffectChorus() {
voice_count = 2;
voice[0].delay = 15;
voice[1].delay = 20;
voice[0].rate = 0.8;
Expand All @@ -354,7 +353,4 @@ AudioEffectChorus::AudioEffectChorus() {
voice[1].cutoff = 8000;
voice[0].pan = -0.5;
voice[1].pan = 0.5;

wet = 0.5;
dry = 1.0;
}
36 changes: 13 additions & 23 deletions servers/audio/effects/audio_effect_chorus.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class AudioEffectChorusInstance : public AudioEffectInstance {
Ref<AudioEffectChorus> base;

Vector<AudioFrame> audio_buffer;
unsigned int buffer_pos;
unsigned int buffer_mask;
unsigned int buffer_pos = 0;
unsigned int buffer_mask = 0;

AudioFrame filter_h[4];
uint64_t cycles[4];
AudioFrame filter_h[4] = {};
uint64_t cycles[4] = {};

void _process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);

Expand All @@ -72,28 +72,18 @@ class AudioEffectChorus : public AudioEffect {

private:
struct Voice {
float delay;
float rate;
float depth;
float level;
float cutoff;
float pan;

Voice() {
delay = 12.0;
rate = 1;
depth = 0;
level = 0;
cutoff = MS_CUTOFF_MAX;
pan = 0;
}

float delay = 12.0;
float rate = 1.0;
float depth = 0.0;
float level = 0.0;
float cutoff = MS_CUTOFF_MAX;
float pan = 0.0;
} voice[MAX_VOICES];

int voice_count;
int voice_count = 2;

float wet;
float dry;
float wet = 0.5;
float dry = 1.0;

protected:
void _validate_property(PropertyInfo &property) const override;
Expand Down
9 changes: 1 addition & 8 deletions servers/audio/effects/audio_effect_compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,4 @@ void AudioEffectCompressor::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "sidechain", PROPERTY_HINT_ENUM), "set_sidechain", "get_sidechain");
}

AudioEffectCompressor::AudioEffectCompressor() {
threshold = 0;
ratio = 4;
gain = 0;
attack_us = 20;
release_ms = 250;
mix = 1;
}
AudioEffectCompressor::AudioEffectCompressor() {}
16 changes: 8 additions & 8 deletions servers/audio/effects/audio_effect_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class AudioEffectCompressorInstance : public AudioEffectInstance {
friend class AudioEffectCompressor;
Ref<AudioEffectCompressor> base;

float rundb, averatio, runratio, runmax, maxover, gr_meter;
int current_channel;
float rundb = 0.0, averatio = 0.0, runratio = 0.0, runmax = 0.0, maxover = 0.0, gr_meter = 0.0;
int current_channel = 0;

public:
void set_current_channel(int p_channel) { current_channel = p_channel; }
Expand All @@ -52,12 +52,12 @@ class AudioEffectCompressor : public AudioEffect {
GDCLASS(AudioEffectCompressor, AudioEffect);

friend class AudioEffectCompressorInstance;
float threshold;
float ratio;
float gain;
float attack_us;
float release_ms;
float mix;
float threshold = 0.0;
float ratio = 4.0;
float gain = 0.0;
float attack_us = 20.0;
float release_ms = 250.0;
float mix = 1.0;
StringName sidechain;

protected:
Expand Down
19 changes: 1 addition & 18 deletions servers/audio/effects/audio_effect_delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,4 @@ void AudioEffectDelay::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "feedback/lowpass", PROPERTY_HINT_RANGE, "1,16000,1"), "set_feedback_lowpass", "get_feedback_lowpass");
}

AudioEffectDelay::AudioEffectDelay() {
tap_1_active = true;
tap_1_delay_ms = 250;
tap_1_level = -6;
tap_1_pan = 0.2;

tap_2_active = true;
tap_2_delay_ms = 500;
tap_2_level = -12;
tap_2_pan = -0.4;

feedback_active = false;
feedback_delay_ms = 340;
feedback_level = -6;
feedback_lowpass = 16000;

dry = 1.0;
}
AudioEffectDelay::AudioEffectDelay() {}
Loading