aboutsummaryrefslogtreecommitdiff
path: root/servers/audio
diff options
context:
space:
mode:
Diffstat (limited to 'servers/audio')
-rw-r--r--servers/audio/audio_driver_dummy.cpp37
-rw-r--r--servers/audio/audio_driver_dummy.h14
-rw-r--r--servers/audio/audio_effect.cpp4
-rw-r--r--servers/audio/audio_effect.h13
-rw-r--r--servers/audio/audio_filter_sw.cpp242
-rw-r--r--servers/audio/audio_filter_sw.h43
-rw-r--r--servers/audio/audio_rb_resampler.cpp321
-rw-r--r--servers/audio/audio_rb_resampler.h92
-rw-r--r--servers/audio/audio_stream.cpp52
-rw-r--r--servers/audio/audio_stream.h59
-rw-r--r--servers/audio/effects/audio_effect_amplify.cpp31
-rw-r--r--servers/audio/effects/audio_effect_amplify.h18
-rw-r--r--servers/audio/effects/audio_effect_chorus.cpp368
-rw-r--r--servers/audio/effects/audio_effect_chorus.h64
-rw-r--r--servers/audio/effects/audio_effect_compressor.cpp152
-rw-r--r--servers/audio/effects/audio_effect_compressor.h28
-rw-r--r--servers/audio/effects/audio_effect_delay.cpp313
-rw-r--r--servers/audio/effects/audio_effect_delay.h25
-rw-r--r--servers/audio/effects/audio_effect_distortion.cpp148
-rw-r--r--servers/audio/effects/audio_effect_distortion.h23
-rw-r--r--servers/audio/effects/audio_effect_eq.cpp78
-rw-r--r--servers/audio/effects/audio_effect_eq.h48
-rw-r--r--servers/audio/effects/audio_effect_filter.cpp115
-rw-r--r--servers/audio/effects/audio_effect_filter.h77
-rw-r--r--servers/audio/effects/audio_effect_limiter.cpp77
-rw-r--r--servers/audio/effects/audio_effect_limiter.h21
-rw-r--r--servers/audio/effects/audio_effect_panner.cpp28
-rw-r--r--servers/audio/effects/audio_effect_panner.h18
-rw-r--r--servers/audio/effects/audio_effect_phaser.cpp128
-rw-r--r--servers/audio/effects/audio_effect_phaser.h35
-rw-r--r--servers/audio/effects/audio_effect_pitch_shift.cpp30
-rw-r--r--servers/audio/effects/audio_effect_pitch_shift.h52
-rw-r--r--servers/audio/effects/audio_effect_reverb.cpp157
-rw-r--r--servers/audio/effects/audio_effect_reverb.h19
-rw-r--r--servers/audio/effects/audio_effect_stereo_enhance.cpp119
-rw-r--r--servers/audio/effects/audio_effect_stereo_enhance.h20
-rw-r--r--servers/audio/effects/eq.cpp145
-rw-r--r--servers/audio/effects/eq.h43
-rw-r--r--servers/audio/effects/reverb.cpp277
-rw-r--r--servers/audio/effects/reverb.h39
-rw-r--r--servers/audio/reverb_sw.cpp510
-rw-r--r--servers/audio/reverb_sw.h16
-rw-r--r--servers/audio/voice_rb_sw.h36
43 files changed, 1873 insertions, 2262 deletions
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp
index 6c1295785..e3022225a 100644
--- a/servers/audio/audio_driver_dummy.cpp
+++ b/servers/audio/audio_driver_dummy.cpp
@@ -31,42 +31,37 @@
#include "global_config.h"
#include "os/os.h"
-
-
Error AudioDriverDummy::init() {
- active=false;
- thread_exited=false;
- exit_thread=false;
+ active = false;
+ thread_exited = false;
+ exit_thread = false;
pcm_open = false;
samples_in = NULL;
-
mix_rate = 44100;
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;
- int latency = GLOBAL_DEF("audio/output_latency",25);
- buffer_size = nearest_power_of_2( latency * mix_rate / 1000 );
+ int latency = GLOBAL_DEF("audio/output_latency", 25);
+ buffer_size = nearest_power_of_2(latency * mix_rate / 1000);
- samples_in = memnew_arr(int32_t, buffer_size*channels);
+ samples_in = memnew_arr(int32_t, buffer_size * channels);
- mutex=Mutex::create();
+ mutex = Mutex::create();
thread = Thread::create(AudioDriverDummy::thread_func, this);
return OK;
};
-void AudioDriverDummy::thread_func(void* p_udata) {
+void AudioDriverDummy::thread_func(void *p_udata) {
- AudioDriverDummy* ad = (AudioDriverDummy*)p_udata;
-
- uint64_t usdelay = (ad->buffer_size / float(ad->mix_rate))*1000000;
+ AudioDriverDummy *ad = (AudioDriverDummy *)p_udata;
+ uint64_t usdelay = (ad->buffer_size / float(ad->mix_rate)) * 1000000;
while (!ad->exit_thread) {
-
if (!ad->active) {
} else {
@@ -76,15 +71,12 @@ void AudioDriverDummy::thread_func(void* p_udata) {
ad->audio_server_process(ad->buffer_size, ad->samples_in);
ad->unlock();
-
};
OS::get_singleton()->delay_usec(usdelay);
-
};
- ad->thread_exited=true;
-
+ ad->thread_exited = true;
};
void AudioDriverDummy::start() {
@@ -137,12 +129,9 @@ void AudioDriverDummy::finish() {
AudioDriverDummy::AudioDriverDummy() {
mutex = NULL;
- thread=NULL;
-
+ thread = NULL;
};
-AudioDriverDummy::~AudioDriverDummy() {
+AudioDriverDummy::~AudioDriverDummy(){
};
-
-
diff --git a/servers/audio/audio_driver_dummy.h b/servers/audio/audio_driver_dummy.h
index 78ec41ea0..02f6a5407 100644
--- a/servers/audio/audio_driver_dummy.h
+++ b/servers/audio/audio_driver_dummy.h
@@ -31,18 +31,17 @@
#include "servers/audio_server.h"
-#include "core/os/thread.h"
#include "core/os/mutex.h"
-
+#include "core/os/thread.h"
class AudioDriverDummy : public AudioDriver {
- Thread* thread;
- Mutex* mutex;
+ Thread *thread;
+ Mutex *mutex;
- int32_t* samples_in;
+ int32_t *samples_in;
- static void thread_func(void* p_udata);
+ static void thread_func(void *p_udata);
int buffer_size;
unsigned int mix_rate;
@@ -56,8 +55,7 @@ class AudioDriverDummy : public AudioDriver {
bool pcm_open;
public:
-
- const char* get_name() const {
+ const char *get_name() const {
return "Dummy";
};
diff --git a/servers/audio/audio_effect.cpp b/servers/audio/audio_effect.cpp
index b0844ff92..bb1179134 100644
--- a/servers/audio/audio_effect.cpp
+++ b/servers/audio/audio_effect.cpp
@@ -28,7 +28,5 @@
/*************************************************************************/
#include "audio_effect.h"
-AudioEffect::AudioEffect()
-{
-
+AudioEffect::AudioEffect() {
}
diff --git a/servers/audio/audio_effect.h b/servers/audio/audio_effect.h
index db3ec9119..6981cf0db 100644
--- a/servers/audio/audio_effect.h
+++ b/servers/audio/audio_effect.h
@@ -32,22 +32,17 @@
#include "audio_frame.h"
#include "resource.h"
-
class AudioEffectInstance : public Reference {
- GDCLASS(AudioEffectInstance,Reference)
+ GDCLASS(AudioEffectInstance, Reference)
public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count)=0;
-
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) = 0;
};
-
class AudioEffect : public Resource {
- GDCLASS(AudioEffect,Resource)
+ GDCLASS(AudioEffect, Resource)
public:
-
- virtual Ref<AudioEffectInstance> instance()=0;
+ virtual Ref<AudioEffectInstance> instance() = 0;
AudioEffect();
};
diff --git a/servers/audio/audio_filter_sw.cpp b/servers/audio/audio_filter_sw.cpp
index e97eb75d0..b3ed76f22 100644
--- a/servers/audio/audio_filter_sw.cpp
+++ b/servers/audio/audio_filter_sw.cpp
@@ -34,62 +34,57 @@ void AudioFilterSW::set_mode(Mode p_mode) {
}
void AudioFilterSW::set_cutoff(float p_cutoff) {
- cutoff=p_cutoff;
+ cutoff = p_cutoff;
}
void AudioFilterSW::set_resonance(float p_resonance) {
- resonance=p_resonance;
+ resonance = p_resonance;
}
void AudioFilterSW::set_gain(float p_gain) {
- gain=p_gain;
+ gain = p_gain;
}
void AudioFilterSW::set_sampling_rate(float p_srate) {
- sampling_rate=p_srate;
+ sampling_rate = p_srate;
}
-
void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
- int sr_limit = (sampling_rate/2)+512;
-
-
- double final_cutoff=(cutoff>sr_limit)?sr_limit:cutoff;
- if (final_cutoff<1) //avoid crapness
- final_cutoff=1; //dont allow less than this
+ int sr_limit = (sampling_rate / 2) + 512;
+ double final_cutoff = (cutoff > sr_limit) ? sr_limit : cutoff;
+ if (final_cutoff < 1) //avoid crapness
+ final_cutoff = 1; //dont allow less than this
+ double omega = 2.0 * Math_PI * final_cutoff / sampling_rate;
- double omega=2.0*Math_PI*final_cutoff/sampling_rate;
+ double sin_v = Math::sin(omega);
+ double cos_v = Math::cos(omega);
- double sin_v=Math::sin(omega);
- double cos_v=Math::cos(omega);
-
- double Q=resonance;
- if (Q<=0.0) {
- Q=0.0001;
+ double Q = resonance;
+ if (Q <= 0.0) {
+ Q = 0.0001;
}
+ if (mode == BANDPASS)
+ Q *= 2.0;
+ else if (mode == PEAK)
+ Q *= 3.0;
- if (mode==BANDPASS)
- Q*=2.0;
- else if (mode==PEAK)
- Q*=3.0;
-
- double tmpgain=gain;
+ double tmpgain = gain;
- if (tmpgain<0.001)
- tmpgain=0.001;
+ if (tmpgain < 0.001)
+ tmpgain = 0.001;
- if (stages>1) {
+ if (stages > 1) {
- Q=(Q>1.0 ? Math::pow(Q,1.0/stages) : Q);
- tmpgain = Math::pow(tmpgain,1.0/(stages+1));
+ Q = (Q > 1.0 ? Math::pow(Q, 1.0 / stages) : Q);
+ tmpgain = Math::pow(tmpgain, 1.0 / (stages + 1));
}
- double alpha = sin_v/(2*Q);
+ double alpha = sin_v / (2 * Q);
double a0 = 1.0 + alpha;
@@ -97,169 +92,159 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
case LOWPASS: {
- p_coeffs->b0= (1.0 - cos_v)/2.0 ;
- p_coeffs->b1= 1.0 - cos_v ;
- p_coeffs->b2= (1.0 - cos_v)/2.0 ;
- p_coeffs->a1= -2.0*cos_v;
- p_coeffs->a2= 1.0 - alpha ;
+ p_coeffs->b0 = (1.0 - cos_v) / 2.0;
+ p_coeffs->b1 = 1.0 - cos_v;
+ p_coeffs->b2 = (1.0 - cos_v) / 2.0;
+ p_coeffs->a1 = -2.0 * cos_v;
+ p_coeffs->a2 = 1.0 - alpha;
} break;
-
case HIGHPASS: {
- p_coeffs->b0 = (1.0 + cos_v)/2.0;
+ p_coeffs->b0 = (1.0 + cos_v) / 2.0;
p_coeffs->b1 = -(1.0 + cos_v);
- p_coeffs->b2 = (1.0 + cos_v)/2.0;
- p_coeffs->a1 = -2.0*cos_v;
- p_coeffs->a2 = 1.0 - alpha;
+ p_coeffs->b2 = (1.0 + cos_v) / 2.0;
+ p_coeffs->a1 = -2.0 * cos_v;
+ p_coeffs->a2 = 1.0 - alpha;
} break;
case BANDPASS: {
- p_coeffs->b0 = alpha*sqrt(Q+1);
- p_coeffs->b1 = 0.0 ;
- p_coeffs->b2 = -alpha*sqrt(Q+1);
- p_coeffs->a1 = -2.0*cos_v;
- p_coeffs->a2 = 1.0 - alpha;
+ p_coeffs->b0 = alpha * sqrt(Q + 1);
+ p_coeffs->b1 = 0.0;
+ p_coeffs->b2 = -alpha * sqrt(Q + 1);
+ p_coeffs->a1 = -2.0 * cos_v;
+ p_coeffs->a2 = 1.0 - alpha;
} break;
case NOTCH: {
- p_coeffs->b0 = 1.0;
- p_coeffs->b1 = -2.0*cos_v;
- p_coeffs->b2 = 1.0;
- p_coeffs->a1 = -2.0*cos_v;
- p_coeffs->a2 = 1.0 - alpha;
+ p_coeffs->b0 = 1.0;
+ p_coeffs->b1 = -2.0 * cos_v;
+ p_coeffs->b2 = 1.0;
+ p_coeffs->a1 = -2.0 * cos_v;
+ p_coeffs->a2 = 1.0 - alpha;
} break;
case PEAK: {
- p_coeffs->b0 = (1.0+alpha*tmpgain);
- p_coeffs->b1 = (-2.0*cos_v);
- p_coeffs->b2 = (1.0-alpha*tmpgain);
- p_coeffs->a1 = -2*cos_v;
- p_coeffs->a2 = (1-alpha/tmpgain);
+ p_coeffs->b0 = (1.0 + alpha * tmpgain);
+ p_coeffs->b1 = (-2.0 * cos_v);
+ p_coeffs->b2 = (1.0 - alpha * tmpgain);
+ p_coeffs->a1 = -2 * cos_v;
+ p_coeffs->a2 = (1 - alpha / tmpgain);
} break;
case BANDLIMIT: {
//this one is extra tricky
- double hicutoff=resonance;
- double centercutoff = (cutoff+resonance)/2.0;
- double bandwidth=(Math::log(centercutoff)-Math::log(hicutoff))/Math::log((double)2);
- omega=2.0*Math_PI*centercutoff/sampling_rate;
- alpha = Math::sin(omega)*Math::sinh( Math::log((double)2)/2 * bandwidth * omega/Math::sin(omega) );
- a0=1+alpha;
+ double hicutoff = resonance;
+ double centercutoff = (cutoff + resonance) / 2.0;
+ double bandwidth = (Math::log(centercutoff) - Math::log(hicutoff)) / Math::log((double)2);
+ omega = 2.0 * Math_PI * centercutoff / sampling_rate;
+ alpha = Math::sin(omega) * Math::sinh(Math::log((double)2) / 2 * bandwidth * omega / Math::sin(omega));
+ a0 = 1 + alpha;
- p_coeffs->b0 = alpha;
- p_coeffs->b1 = 0;
- p_coeffs->b2 = -alpha;
- p_coeffs->a1 = -2*Math::cos(omega);
- p_coeffs->a2 = 1-alpha;
+ p_coeffs->b0 = alpha;
+ p_coeffs->b1 = 0;
+ p_coeffs->b2 = -alpha;
+ p_coeffs->a1 = -2 * Math::cos(omega);
+ p_coeffs->a2 = 1 - alpha;
} break;
case LOWSHELF: {
- double tmpq = Math::sqrt(Q);
- if (tmpq<=0)
- tmpq=0.001;
+ double tmpq = Math::sqrt(Q);
+ if (tmpq <= 0)
+ tmpq = 0.001;
alpha = sin_v / (2 * tmpq);
- double beta = Math::sqrt(tmpgain) / tmpq;
+ double beta = Math::sqrt(tmpgain) / tmpq;
- a0=(tmpgain+1.0)+(tmpgain-1.0)*cos_v+beta*sin_v;
- p_coeffs->b0=tmpgain*((tmpgain+1.0)-(tmpgain-1.0)*cos_v+beta*sin_v);
- p_coeffs->b1=2.0*tmpgain*((tmpgain-1.0)-(tmpgain+1.0)*cos_v);
- p_coeffs->b2=tmpgain*((tmpgain+1.0)-(tmpgain-1.0)*cos_v-beta*sin_v);
- p_coeffs->a1=-2.0*((tmpgain-1.0)+(tmpgain+1.0)*cos_v);
- p_coeffs->a2=((tmpgain+1.0)+(tmpgain-1.0)*cos_v-beta*sin_v);
+ a0 = (tmpgain + 1.0) + (tmpgain - 1.0) * cos_v + beta * sin_v;
+ p_coeffs->b0 = tmpgain * ((tmpgain + 1.0) - (tmpgain - 1.0) * cos_v + beta * sin_v);
+ p_coeffs->b1 = 2.0 * tmpgain * ((tmpgain - 1.0) - (tmpgain + 1.0) * cos_v);
+ p_coeffs->b2 = tmpgain * ((tmpgain + 1.0) - (tmpgain - 1.0) * cos_v - beta * sin_v);
+ p_coeffs->a1 = -2.0 * ((tmpgain - 1.0) + (tmpgain + 1.0) * cos_v);
+ p_coeffs->a2 = ((tmpgain + 1.0) + (tmpgain - 1.0) * cos_v - beta * sin_v);
} break;
case HIGHSHELF: {
- double tmpq= Math::sqrt(Q);
- if (tmpq<=0)
- tmpq=0.001;
+ double tmpq = Math::sqrt(Q);
+ if (tmpq <= 0)
+ tmpq = 0.001;
alpha = sin_v / (2 * tmpq);
- double beta = Math::sqrt(tmpgain) / tmpq;
-
- a0=(tmpgain+1.0)-(tmpgain-1.0)*cos_v+beta*sin_v;
- p_coeffs->b0=tmpgain*((tmpgain+1.0)+(tmpgain-1.0)*cos_v+beta*sin_v);
- p_coeffs->b1=-2.0*tmpgain*((tmpgain-1.0)+(tmpgain+1.0)*cos_v);
- p_coeffs->b2=tmpgain*((tmpgain+1.0)+(tmpgain-1.0)*cos_v-beta*sin_v);
- p_coeffs->a1=2.0*((tmpgain-1.0)-(tmpgain+1.0)*cos_v);
- p_coeffs->a2=((tmpgain+1.0)-(tmpgain-1.0)*cos_v-beta*sin_v);
+ double beta = Math::sqrt(tmpgain) / tmpq;
+ a0 = (tmpgain + 1.0) - (tmpgain - 1.0) * cos_v + beta * sin_v;
+ p_coeffs->b0 = tmpgain * ((tmpgain + 1.0) + (tmpgain - 1.0) * cos_v + beta * sin_v);
+ p_coeffs->b1 = -2.0 * tmpgain * ((tmpgain - 1.0) + (tmpgain + 1.0) * cos_v);
+ p_coeffs->b2 = tmpgain * ((tmpgain + 1.0) + (tmpgain - 1.0) * cos_v - beta * sin_v);
+ p_coeffs->a1 = 2.0 * ((tmpgain - 1.0) - (tmpgain + 1.0) * cos_v);
+ p_coeffs->a2 = ((tmpgain + 1.0) - (tmpgain - 1.0) * cos_v - beta * sin_v);
} break;
+ };
- };
+ p_coeffs->b0 /= a0;
+ p_coeffs->b1 /= a0;
+ p_coeffs->b2 /= a0;
+ p_coeffs->a1 /= 0.0 - a0;
+ p_coeffs->a2 /= 0.0 - a0;
- p_coeffs->b0/=a0;
- p_coeffs->b1/=a0;
- p_coeffs->b2/=a0;
- p_coeffs->a1/=0.0-a0;
- p_coeffs->a2/=0.0-a0;
-
- //undenormalise
-/* p_coeffs->b0=undenormalise(p_coeffs->b0);
+ //undenormalise
+ /* p_coeffs->b0=undenormalise(p_coeffs->b0);
p_coeffs->b1=undenormalise(p_coeffs->b1);
p_coeffs->b2=undenormalise(p_coeffs->b2);
p_coeffs->a1=undenormalise(p_coeffs->a1);
p_coeffs->a2=undenormalise(p_coeffs->a2);*/
-
}
void AudioFilterSW::set_stages(int p_stages) { //adjust for multiple stages
- stages=p_stages;
+ stages = p_stages;
}
/* Fouriertransform kernel to obtain response */
-float AudioFilterSW::get_response(float p_freq,Coeffs *p_coeffs) {
+float AudioFilterSW::get_response(float p_freq, Coeffs *p_coeffs) {
- float freq=p_freq / sampling_rate * Math_PI * 2.0f;
+ float freq = p_freq / sampling_rate * Math_PI * 2.0f;
- float cx=p_coeffs->b0,cy=0.0;
+ float cx = p_coeffs->b0, cy = 0.0;
cx += cos(freq) * p_coeffs->b1;
cy -= sin(freq) * p_coeffs->b1;
- cx += cos(2*freq) * p_coeffs->b2;
- cy -= sin(2*freq) * p_coeffs->b2;
-
-
- float H=cx*cx+cy*cy;
- cx=1.0;
- cy=0.0;
+ cx += cos(2 * freq) * p_coeffs->b2;
+ cy -= sin(2 * freq) * p_coeffs->b2;
+ float H = cx * cx + cy * cy;
+ cx = 1.0;
+ cy = 0.0;
cx -= cos(freq) * p_coeffs->a1;
cy += sin(freq) * p_coeffs->a1;
- cx -= cos(2*freq) * p_coeffs->a2;
- cy += sin(2*freq) * p_coeffs->a2;
-
+ cx -= cos(2 * freq) * p_coeffs->a2;
+ cy += sin(2 * freq) * p_coeffs->a2;
- H=H/(cx*cx+cy*cy);
+ H = H / (cx * cx + cy * cy);
return H;
}
-
AudioFilterSW::AudioFilterSW() {
-
- sampling_rate=44100;
- resonance=0.5;
- cutoff=5000;
- gain=1.0;
- mode=LOWPASS;
- stages=1;
+ sampling_rate = 44100;
+ resonance = 0.5;
+ cutoff = 5000;
+ gain = 1.0;
+ mode = LOWPASS;
+ stages = 1;
}
AudioFilterSW::Processor::Processor() {
set_filter(NULL);
-
}
-void AudioFilterSW::Processor::set_filter(AudioFilterSW * p_filter) {
+void AudioFilterSW::Processor::set_filter(AudioFilterSW *p_filter) {
- ha1=ha2=hb1=hb2=0;
- filter=p_filter;
+ ha1 = ha2 = hb1 = hb2 = 0;
+ filter = p_filter;
}
void AudioFilterSW::Processor::update_coeffs() {
@@ -268,19 +253,16 @@ void AudioFilterSW::Processor::update_coeffs() {
return;
filter->prepare_coefficients(&coeffs);
-
}
-void AudioFilterSW::Processor::process(float *p_samples,int p_amount, int p_stride) {
+void AudioFilterSW::Processor::process(float *p_samples, int p_amount, int p_stride) {
if (!filter)
return;
- for (int i=0;i<p_amount;i++) {
+ for (int i = 0; i < p_amount; i++) {
process_one(*p_samples);
- p_samples+=p_stride;
+ p_samples += p_stride;
}
-
-
}
diff --git a/servers/audio/audio_filter_sw.h b/servers/audio/audio_filter_sw.h
index b711944ca..bbd006e52 100644
--- a/servers/audio/audio_filter_sw.h
+++ b/servers/audio/audio_filter_sw.h
@@ -29,19 +29,17 @@
#ifndef AUDIO_FILTER_SW_H
#define AUDIO_FILTER_SW_H
-
#include "math_funcs.h"
class AudioFilterSW {
public:
-
struct Coeffs {
- float a1,a2;
- float b0,b1,b2;
+ float a1, a2;
+ float b0, b1, b2;
//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; }
+ Coeffs() { a1 = a2 = b0 = b1 = b2 = 0.0; }
};
enum Mode {
@@ -58,21 +56,19 @@ public:
class Processor { // simple filter processor
- AudioFilterSW * filter;
+ AudioFilterSW *filter;
Coeffs coeffs;
- float ha1,ha2,hb1,hb2; //history
+ float ha1, ha2, hb1, hb2; //history
public:
- void set_filter(AudioFilterSW * p_filter);
- void process(float *p_samples,int p_amount, int p_stride=1);
+ void set_filter(AudioFilterSW *p_filter);
+ void process(float *p_samples, int p_amount, int p_stride = 1);
void update_coeffs();
- _ALWAYS_INLINE_ void process_one(float& p_sample);
+ _ALWAYS_INLINE_ void process_one(float &p_sample);
Processor();
};
private:
-
-
float cutoff;
float resonance;
float gain;
@@ -80,11 +76,8 @@ private:
int stages;
Mode mode;
-
-
public:
-
- float get_response(float p_freq,Coeffs *p_coeffs);
+ float get_response(float p_freq, Coeffs *p_coeffs);
void set_mode(Mode p_mode);
void set_cutoff(float p_cutoff);
@@ -96,24 +89,18 @@ public:
void prepare_coefficients(Coeffs *p_coeffs);
AudioFilterSW();
-
};
-
-
-
/* inline methods */
-
void AudioFilterSW::Processor::process_one(float &p_val) {
- float pre=p_val;
- p_val = (p_val * coeffs.b0 + hb1 * coeffs.b1 + hb2 * coeffs.b2 + ha1 * coeffs.a1 + ha2 * coeffs.a2);
- ha2=ha1;
- hb2=hb1;
- hb1=pre;
- ha1=p_val;
+ float pre = p_val;
+ p_val = (p_val * coeffs.b0 + hb1 * coeffs.b1 + hb2 * coeffs.b2 + ha1 * coeffs.a1 + ha2 * coeffs.a2);
+ ha2 = ha1;
+ hb2 = hb1;
+ hb1 = pre;
+ ha1 = p_val;
}
-
#endif // AUDIO_FILTER_SW_H
diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cpp
index 28f0007b5..bf10f813a 100644
--- a/servers/audio/audio_rb_resampler.cpp
+++ b/servers/audio/audio_rb_resampler.cpp
@@ -28,7 +28,6 @@
/*************************************************************************/
#include "audio_rb_resampler.h"
-
int AudioRBResampler::get_channel_count() const {
if (!rb)
@@ -37,153 +36,142 @@ int AudioRBResampler::get_channel_count() const {
return channels;
}
+template <int C>
+uint32_t AudioRBResampler::_resample(int32_t *p_dest, int p_todo, int32_t p_increment) {
-template<int C>
-uint32_t AudioRBResampler::_resample(int32_t *p_dest,int p_todo,int32_t p_increment) {
-
- uint32_t read=offset&MIX_FRAC_MASK;
+ uint32_t read = offset & MIX_FRAC_MASK;
- for (int i=0;i<p_todo;i++) {
+ for (int i = 0; i < p_todo; i++) {
- offset = (offset + p_increment)&(((1<<(rb_bits+MIX_FRAC_BITS))-1));
- read+=p_increment;
+ offset = (offset + p_increment) & (((1 << (rb_bits + MIX_FRAC_BITS)) - 1));
+ read += p_increment;
uint32_t pos = offset >> MIX_FRAC_BITS;
uint32_t frac = offset & MIX_FRAC_MASK;
#ifndef FAST_AUDIO
- ERR_FAIL_COND_V(pos>=rb_len,0);
+ ERR_FAIL_COND_V(pos >= rb_len, 0);
#endif
- uint32_t pos_next = (pos+1)&rb_mask;
+ uint32_t pos_next = (pos + 1) & rb_mask;
//printf("rb pos %i\n",pos);
// since this is a template with a known compile time value (C), conditionals go away when compiling.
- if (C==1) {
+ if (C == 1) {
int32_t v0 = rb[pos];
- int32_t v0n=rb[pos_next];
+ int32_t v0n = rb[pos_next];
#ifndef FAST_AUDIO
- v0+=(v0n-v0)*(int32_t)frac >> MIX_FRAC_BITS;
+ v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
#endif
- v0<<=16;
- p_dest[i]=v0;
-
+ v0 <<= 16;
+ p_dest[i] = v0;
}
- if (C==2) {
+ if (C == 2) {
- int32_t v0 = rb[(pos<<1)+0];
- int32_t v1 = rb[(pos<<1)+1];
- int32_t v0n=rb[(pos_next<<1)+0];
- int32_t v1n=rb[(pos_next<<1)+1];
+ int32_t v0 = rb[(pos << 1) + 0];
+ int32_t v1 = rb[(pos << 1) + 1];
+ int32_t v0n = rb[(pos_next << 1) + 0];
+ int32_t v1n = rb[(pos_next << 1) + 1];
#ifndef FAST_AUDIO
- v0+=(v0n-v0)*(int32_t)frac >> MIX_FRAC_BITS;
- v1+=(v1n-v1)*(int32_t)frac >> MIX_FRAC_BITS;
+ v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
+ v1 += (v1n - v1) * (int32_t)frac >> MIX_FRAC_BITS;
#endif
- v0<<=16;
- v1<<=16;
- p_dest[(i<<1)+0]=v0;
- p_dest[(i<<1)+1]=v1;
-
+ v0 <<= 16;
+ v1 <<= 16;
+ p_dest[(i << 1) + 0] = v0;
+ p_dest[(i << 1) + 1] = v1;
}
- if (C==4) {
+ if (C == 4) {
- int32_t v0 = rb[(pos<<2)+0];
- int32_t v1 = rb[(pos<<2)+1];
- int32_t v2 = rb[(pos<<2)+2];
- int32_t v3 = rb[(pos<<2)+3];
- int32_t v0n = rb[(pos_next<<2)+0];
- int32_t v1n=rb[(pos_next<<2)+1];
- int32_t v2n=rb[(pos_next<<2)+2];
- int32_t v3n=rb[(pos_next<<2)+3];
+ int32_t v0 = rb[(pos << 2) + 0];
+ int32_t v1 = rb[(pos << 2) + 1];
+ int32_t v2 = rb[(pos << 2) + 2];
+ int32_t v3 = rb[(pos << 2) + 3];
+ int32_t v0n = rb[(pos_next << 2) + 0];
+ int32_t v1n = rb[(pos_next << 2) + 1];
+ int32_t v2n = rb[(pos_next << 2) + 2];
+ int32_t v3n = rb[(pos_next << 2) + 3];
#ifndef FAST_AUDIO
- v0+=(v0n-v0)*(int32_t)frac >> MIX_FRAC_BITS;
- v1+=(v1n-v1)*(int32_t)frac >> MIX_FRAC_BITS;
- v2+=(v2n-v2)*(int32_t)frac >> MIX_FRAC_BITS;
- v3+=(v3n-v3)*(int32_t)frac >> MIX_FRAC_BITS;
+ v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
+ v1 += (v1n - v1) * (int32_t)frac >> MIX_FRAC_BITS;
+ v2 += (v2n - v2) * (int32_t)frac >> MIX_FRAC_BITS;
+ v3 += (v3n - v3) * (int32_t)frac >> MIX_FRAC_BITS;
#endif
- v0<<=16;
- v1<<=16;
- v2<<=16;
- v3<<=16;
- p_dest[(i<<2)+0]=v0;
- p_dest[(i<<2)+1]=v1;
- p_dest[(i<<2)+2]=v2;
- p_dest[(i<<2)+3]=v3;
-
+ v0 <<= 16;
+ v1 <<= 16;
+ v2 <<= 16;
+ v3 <<= 16;
+ p_dest[(i << 2) + 0] = v0;
+ p_dest[(i << 2) + 1] = v1;
+ p_dest[(i << 2) + 2] = v2;
+ p_dest[(i << 2) + 3] = v3;
}
- if (C==6) {
+ if (C == 6) {
- int32_t v0 = rb[(pos*6)+0];
- int32_t v1 = rb[(pos*6)+1];
- int32_t v2 = rb[(pos*6)+2];
- int32_t v3 = rb[(pos*6)+3];
- int32_t v4 = rb[(pos*6)+4];
- int32_t v5 = rb[(pos*6)+5];
- int32_t v0n = rb[(pos_next*6)+0];
- int32_t v1n=rb[(pos_next*6)+1];
- int32_t v2n=rb[(pos_next*6)+2];
- int32_t v3n=rb[(pos_next*6)+3];
- int32_t v4n=rb[(pos_next*6)+4];
- int32_t v5n=rb[(pos_next*6)+5];
+ int32_t v0 = rb[(pos * 6) + 0];
+ int32_t v1 = rb[(pos * 6) + 1];
+ int32_t v2 = rb[(pos * 6) + 2];
+ int32_t v3 = rb[(pos * 6) + 3];
+ int32_t v4 = rb[(pos * 6) + 4];
+ int32_t v5 = rb[(pos * 6) + 5];
+ int32_t v0n = rb[(pos_next * 6) + 0];
+ int32_t v1n = rb[(pos_next * 6) + 1];
+ int32_t v2n = rb[(pos_next * 6) + 2];
+ int32_t v3n = rb[(pos_next * 6) + 3];
+ int32_t v4n = rb[(pos_next * 6) + 4];
+ int32_t v5n = rb[(pos_next * 6) + 5];
#ifndef FAST_AUDIO
- v0+=(v0n-v0)*(int32_t)frac >> MIX_FRAC_BITS;
- v1+=(v1n-v1)*(int32_t)frac >> MIX_FRAC_BITS;
- v2+=(v2n-v2)*(int32_t)frac >> MIX_FRAC_BITS;
- v3+=(v3n-v3)*(int32_t)frac >> MIX_FRAC_BITS;
- v4+=(v4n-v4)*(int32_t)frac >> MIX_FRAC_BITS;
- v5+=(v5n-v5)*(int32_t)frac >> MIX_FRAC_BITS;
+ v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
+ v1 += (v1n - v1) * (int32_t)frac >> MIX_FRAC_BITS;
+ v2 += (v2n - v2) * (int32_t)frac >> MIX_FRAC_BITS;
+ v3 += (v3n - v3) * (int32_t)frac >> MIX_FRAC_BITS;
+ v4 += (v4n - v4) * (int32_t)frac >> MIX_FRAC_BITS;
+ v5 += (v5n - v5) * (int32_t)frac >> MIX_FRAC_BITS;
#endif
- v0<<=16;
- v1<<=16;
- v2<<=16;
- v3<<=16;
- v4<<=16;
- v5<<=16;
- p_dest[(i*6)+0]=v0;
- p_dest[(i*6)+1]=v1;
- p_dest[(i*6)+2]=v2;
- p_dest[(i*6)+3]=v3;
- p_dest[(i*6)+4]=v4;
- p_dest[(i*6)+5]=v5;
-
+ v0 <<= 16;
+ v1 <<= 16;
+ v2 <<= 16;
+ v3 <<= 16;
+ v4 <<= 16;
+ v5 <<= 16;
+ p_dest[(i * 6) + 0] = v0;
+ p_dest[(i * 6) + 1] = v1;
+ p_dest[(i * 6) + 2] = v2;
+ p_dest[(i * 6) + 3] = v3;
+ p_dest[(i * 6) + 4] = v4;
+ p_dest[(i * 6) + 5] = v5;
}
-
-
}
-
- return read>>MIX_FRAC_BITS;//rb_read_pos=offset>>MIX_FRAC_BITS;
-
+ return read >> MIX_FRAC_BITS; //rb_read_pos=offset>>MIX_FRAC_BITS;
}
-
bool AudioRBResampler::mix(int32_t *p_dest, int p_frames) {
-
if (!rb)
return false;
- int write_pos_cache=rb_write_pos;
+ int write_pos_cache = rb_write_pos;
- int32_t increment=(src_mix_rate*MIX_FRAC_LEN)/target_mix_rate;
+ int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate;
int rb_todo;
- if (write_pos_cache==rb_read_pos) {
+ if (write_pos_cache == rb_read_pos) {
return false; //out of buffer
- } else if (rb_read_pos<write_pos_cache) {
+ } else if (rb_read_pos < write_pos_cache) {
- rb_todo=write_pos_cache-rb_read_pos; //-1?
+ rb_todo = write_pos_cache - rb_read_pos; //-1?
} else {
- rb_todo=(rb_len-rb_read_pos)+write_pos_cache; //-1?
+ rb_todo = (rb_len - rb_read_pos) + write_pos_cache; //-1?
}
- int todo = MIN( ((int64_t(rb_todo)<<MIX_FRAC_BITS)/increment)+1, p_frames );
+ int todo = MIN(((int64_t(rb_todo) << MIX_FRAC_BITS) / increment) + 1, p_frames);
#if 0
if (int(src_mix_rate)==target_mix_rate) {
@@ -224,118 +212,104 @@ bool AudioRBResampler::mix(int32_t *p_dest, int p_frames) {
#endif
{
- uint32_t read=0;
- switch(channels) {
- case 1: read=_resample<1>(p_dest,todo,increment); break;
- case 2: read=_resample<2>(p_dest,todo,increment); break;
- case 4: read=_resample<4>(p_dest,todo,increment); break;
- case 6: read=_resample<6>(p_dest,todo,increment); break;
+ uint32_t read = 0;
+ switch (channels) {
+ case 1: read = _resample<1>(p_dest, todo, increment); break;
+ case 2: read = _resample<2>(p_dest, todo, increment); break;
+ case 4: read = _resample<4>(p_dest, todo, increment); break;
+ case 6: read = _resample<6>(p_dest, todo, increment); break;
}
#if 1
//end of stream, fadeout
- int remaining = p_frames-todo;
- if (remaining && todo>0) {
+ int remaining = p_frames - todo;
+ if (remaining && todo > 0) {
//print_line("fadeout");
- for(int c=0;c<channels;c++) {
+ for (int c = 0; c < channels; c++) {
- for(int i=0;i<todo;i++) {
+ for (int i = 0; i < todo; i++) {
- int32_t samp = p_dest[i*channels+c]>>8;
- uint32_t mul = (todo-i) * 256 /todo;
+ int32_t samp = p_dest[i * channels + c] >> 8;
+ uint32_t mul = (todo - i) * 256 / todo;
//print_line("mul: "+itos(i)+" "+itos(mul));
- p_dest[i*channels+c]=samp*mul;
+ p_dest[i * channels + c] = samp * mul;
}
-
}
-
}
#else
- int remaining = p_frames-todo;
- if (remaining && todo>0) {
-
+ int remaining = p_frames - todo;
+ if (remaining && todo > 0) {
- for(int c=0;c<channels;c++) {
+ for (int c = 0; c < channels; c++) {
- int32_t from = p_dest[(todo-1)*channels+c]>>8;
+ int32_t from = p_dest[(todo - 1) * channels + c] >> 8;
- for(int i=0;i<remaining;i++) {
+ for (int i = 0; i < remaining; i++) {
- uint32_t mul = (remaining-i) * 256 /remaining;
- p_dest[(todo+i)*channels+c]=from*mul;
+ uint32_t mul = (remaining - i) * 256 / remaining;
+ p_dest[(todo + i) * channels + c] = from * mul;
}
-
}
-
}
#endif
//zero out what remains there to avoid glitches
- for(int i=todo*channels;i<int(p_frames)*channels;i++) {
+ for (int i = todo * channels; i < int(p_frames) * channels; i++) {
- p_dest[i]=0;
+ p_dest[i] = 0;
}
- if (read>rb_todo)
- read=rb_todo;
-
- rb_read_pos = (rb_read_pos+read)&rb_mask;
-
-
-
+ if (read > rb_todo)
+ read = rb_todo;
+ rb_read_pos = (rb_read_pos + read) & rb_mask;
}
return true;
}
+Error AudioRBResampler::setup(int p_channels, int p_src_mix_rate, int p_target_mix_rate, int p_buffer_msec, int p_minbuff_needed) {
-Error AudioRBResampler::setup(int p_channels,int p_src_mix_rate,int p_target_mix_rate,int p_buffer_msec,int p_minbuff_needed) {
-
- ERR_FAIL_COND_V(p_channels!=1 && p_channels!=2 && p_channels!=4 && p_channels!=6,ERR_INVALID_PARAMETER);
-
+ ERR_FAIL_COND_V(p_channels != 1 && p_channels != 2 && p_channels != 4 && p_channels != 6, ERR_INVALID_PARAMETER);
//float buffering_sec = int(GLOBAL_DEF("audio/stream_buffering_ms",500))/1000.0;
- int desired_rb_bits =nearest_shift(MAX((p_buffer_msec/1000.0)*p_src_mix_rate,p_minbuff_needed));
+ int desired_rb_bits = nearest_shift(MAX((p_buffer_msec / 1000.0) * p_src_mix_rate, p_minbuff_needed));
- bool recreate=!rb;
+ bool recreate = !rb;
- if (rb && (uint32_t(desired_rb_bits)!=rb_bits || channels!=uint32_t(p_channels))) {
+ if (rb && (uint32_t(desired_rb_bits) != rb_bits || channels != uint32_t(p_channels))) {
//recreate
memdelete_arr(rb);
memdelete_arr(read_buf);
- recreate=true;
-
+ recreate = true;
}
if (recreate) {
- channels=p_channels;
- rb_bits=desired_rb_bits;
- rb_len=(1<<rb_bits);
- rb_mask=rb_len-1;
- rb = memnew_arr( int16_t, rb_len * p_channels );
- read_buf = memnew_arr( int16_t, rb_len * p_channels );
-
+ channels = p_channels;
+ rb_bits = desired_rb_bits;
+ rb_len = (1 << rb_bits);
+ rb_mask = rb_len - 1;
+ rb = memnew_arr(int16_t, rb_len * p_channels);
+ read_buf = memnew_arr(int16_t, rb_len * p_channels);
}
- src_mix_rate=p_src_mix_rate;
- target_mix_rate=p_target_mix_rate;
- offset=0;
- rb_read_pos=0;
- rb_write_pos=0;
+ src_mix_rate = p_src_mix_rate;
+ target_mix_rate = p_target_mix_rate;
+ offset = 0;
+ rb_read_pos = 0;
+ rb_write_pos = 0;
//avoid maybe strange noises upon load
- for (int i=0;i<(rb_len*channels);i++) {
+ for (int i = 0; i < (rb_len * channels); i++) {
- rb[i]=0;
- read_buf[i]=0;
+ rb[i] = 0;
+ read_buf[i] = 0;
}
return OK;
-
}
void AudioRBResampler::clear() {
@@ -348,29 +322,28 @@ void AudioRBResampler::clear() {
memdelete_arr(rb);
memdelete_arr(read_buf);
}
- rb=NULL;
- offset=0;
- rb_read_pos=0;
- rb_write_pos=0;
- read_buf=NULL;
+ rb = NULL;
+ offset = 0;
+ rb_read_pos = 0;
+ rb_write_pos = 0;
+ read_buf = NULL;
}
AudioRBResampler::AudioRBResampler() {
- rb=NULL;
- offset=0;
- read_buf=NULL;
- rb_read_pos=0;
- rb_write_pos=0;
-
- rb_bits=0;
- rb_len=0;
- rb_mask=0;
- read_buff_len=0;
- channels=0;
- src_mix_rate=0;
- target_mix_rate=0;
+ rb = NULL;
+ offset = 0;
+ read_buf = NULL;
+ rb_read_pos = 0;
+ rb_write_pos = 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() {
@@ -379,6 +352,4 @@ AudioRBResampler::~AudioRBResampler() {
memdelete_arr(rb);
memdelete_arr(read_buf);
}
-
}
-
diff --git a/servers/audio/audio_rb_resampler.h b/servers/audio/audio_rb_resampler.h
index e97e275b6..d775aed0d 100644
--- a/servers/audio/audio_rb_resampler.h
+++ b/servers/audio/audio_rb_resampler.h
@@ -29,8 +29,8 @@
#ifndef AUDIO_RB_RESAMPLER_H
#define AUDIO_RB_RESAMPLER_H
-#include "typedefs.h"
#include "os/memory.h"
+#include "typedefs.h"
struct AudioRBResampler {
@@ -47,58 +47,53 @@ struct AudioRBResampler {
int32_t offset; //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,
+ MIX_FRAC_BITS = 13,
+ MIX_FRAC_LEN = (1 << MIX_FRAC_BITS),
+ MIX_FRAC_MASK = MIX_FRAC_LEN - 1,
};
int16_t *read_buf;
int16_t *rb;
-
- template<int C>
- uint32_t _resample(int32_t *p_dest,int p_todo,int32_t p_increment);
-
+ template <int C>
+ uint32_t _resample(int32_t *p_dest, int p_todo, int32_t p_increment);
public:
-
_FORCE_INLINE_ void flush() {
- rb_read_pos=0;
- rb_write_pos=0;
- offset=0;
+ rb_read_pos = 0;
+ rb_write_pos = 0;
+ offset = 0;
}
- _FORCE_INLINE_ bool is_ready() const{
- return rb!=NULL;
+ _FORCE_INLINE_ bool is_ready() const {
+ return rb != NULL;
}
-
_FORCE_INLINE_ int get_total() const {
- return rb_len-1;
+ return rb_len - 1;
}
_FORCE_INLINE_ int get_todo() const { //return amount of frames to mix
int todo;
- int read_pos_cache=rb_read_pos;
+ int read_pos_cache = rb_read_pos;
- if (read_pos_cache==rb_write_pos) {
- todo=rb_len-1;
- } else if (read_pos_cache>rb_write_pos) {
+ if (read_pos_cache == rb_write_pos) {
+ todo = rb_len - 1;
+ } else if (read_pos_cache > rb_write_pos) {
- todo=read_pos_cache-rb_write_pos-1;
+ todo = read_pos_cache - rb_write_pos - 1;
} else {
- todo=(rb_len-rb_write_pos)+read_pos_cache-1;
+ todo = (rb_len - rb_write_pos) + read_pos_cache - 1;
}
return todo;
}
-
_FORCE_INLINE_ bool has_data() const {
- return rb && rb_read_pos!=rb_write_pos;
+ return rb && rb_read_pos != rb_write_pos;
}
_FORCE_INLINE_ int16_t *get_write_buffer() { return read_buf; }
@@ -106,57 +101,54 @@ public:
ERR_FAIL_COND(p_frames >= rb_len);
- switch(channels) {
+ switch (channels) {
case 1: {
- for(uint32_t i=0;i<p_frames;i++) {
+ for (uint32_t i = 0; i < p_frames; i++) {
- rb[ rb_write_pos ] = read_buf[i];
- rb_write_pos=(rb_write_pos+1)&rb_mask;
+ rb[rb_write_pos] = read_buf[i];
+ rb_write_pos = (rb_write_pos + 1) & rb_mask;
}
} break;
case 2: {
- for(uint32_t i=0;i<p_frames;i++) {
+ for (uint32_t i = 0; i < p_frames; i++) {
- rb[ (rb_write_pos<<1)+0 ] = read_buf[(i<<1)+0];
- rb[ (rb_write_pos<<1)+1 ] = read_buf[(i<<1)+1];
- rb_write_pos=(rb_write_pos+1)&rb_mask;
+ rb[(rb_write_pos << 1) + 0] = read_buf[(i << 1) + 0];
+ rb[(rb_write_pos << 1) + 1] = read_buf[(i << 1) + 1];
+ rb_write_pos = (rb_write_pos + 1) & rb_mask;
}
} break;
case 4: {
- for(uint32_t i=0;i<p_frames;i++) {
+ for (uint32_t i = 0; i < p_frames; i++) {
- rb[ (rb_write_pos<<2)+0 ] = read_buf[(i<<2)+0];
- rb[ (rb_write_pos<<2)+1 ] = read_buf[(i<<2)+1];
- rb[ (rb_write_pos<<2)+2 ] = read_buf[(i<<2)+2];
- rb[ (rb_write_pos<<2)+3 ] = read_buf[(i<<2)+3];
- rb_write_pos=(rb_write_pos+1)&rb_mask;
+ rb[(rb_write_pos << 2) + 0] = read_buf[(i << 2) + 0];
+ rb[(rb_write_pos << 2) + 1] = read_buf[(i << 2) + 1];
+ rb[(rb_write_pos << 2) + 2] = read_buf[(i << 2) + 2];
+ rb[(rb_write_pos << 2) + 3] = read_buf[(i << 2) + 3];
+ rb_write_pos = (rb_write_pos + 1) & rb_mask;
}
} break;
case 6: {
- for(uint32_t i=0;i<p_frames;i++) {
+ for (uint32_t i = 0; i < p_frames; i++) {
- rb[ (rb_write_pos*6)+0 ] = read_buf[(i*6)+0];
- rb[ (rb_write_pos*6)+1 ] = read_buf[(i*6)+1];
- rb[ (rb_write_pos*6)+2 ] = read_buf[(i*6)+2];
- rb[ (rb_write_pos*6)+3 ] = read_buf[(i*6)+3];
- rb[ (rb_write_pos*6)+4 ] = read_buf[(i*6)+4];
- rb[ (rb_write_pos*6)+5 ] = read_buf[(i*6)+5];
- rb_write_pos=(rb_write_pos+1)&rb_mask;
+ rb[(rb_write_pos * 6) + 0] = read_buf[(i * 6) + 0];
+ rb[(rb_write_pos * 6) + 1] = read_buf[(i * 6) + 1];
+ rb[(rb_write_pos * 6) + 2] = read_buf[(i * 6) + 2];
+ rb[(rb_write_pos * 6) + 3] = read_buf[(i * 6) + 3];
+ rb[(rb_write_pos * 6) + 4] = read_buf[(i * 6) + 4];
+ rb[(rb_write_pos * 6) + 5] = read_buf[(i * 6) + 5];
+ rb_write_pos = (rb_write_pos + 1) & rb_mask;
}
} break;
-
-
}
-
}
int get_channel_count() const;
- Error setup(int p_channels, int p_src_mix_rate, int p_target_mix_rate, int p_buffer_msec, int p_minbuff_needed=-1);
+ Error setup(int p_channels, int p_src_mix_rate, int p_target_mix_rate, int p_buffer_msec, int p_minbuff_needed = -1);
void clear();
bool mix(int32_t *p_dest, int p_frames);
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index f4214838a..5f77eb54f 100644
--- a/servers/audio/audio_stream.cpp
+++ b/servers/audio/audio_stream.cpp
@@ -30,57 +30,53 @@
//////////////////////////////
-
-
void AudioStreamPlaybackResampled::_begin_resample() {
//clear cubic interpolation history
- internal_buffer[0]=AudioFrame(0.0,0.0);
- internal_buffer[1]=AudioFrame(0.0,0.0);
- internal_buffer[2]=AudioFrame(0.0,0.0);
- internal_buffer[3]=AudioFrame(0.0,0.0);
+ internal_buffer[0] = AudioFrame(0.0, 0.0);
+ internal_buffer[1] = AudioFrame(0.0, 0.0);
+ internal_buffer[2] = AudioFrame(0.0, 0.0);
+ internal_buffer[3] = AudioFrame(0.0, 0.0);
//mix buffer
- _mix_internal(internal_buffer+4,INTERNAL_BUFFER_LEN);
- mix_offset=0;
+ _mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN);
+ mix_offset = 0;
}
-void AudioStreamPlaybackResampled::mix(AudioFrame* p_buffer,float p_rate_scale,int p_frames) {
+void AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {
float target_rate = AudioServer::get_singleton()->get_mix_rate() * p_rate_scale;
- uint64_t mix_increment = uint64_t((get_stream_sampling_rate() / double(target_rate)) * double( FP_LEN ));
-
- for(int i=0;i<p_frames;i++) {
-
+ uint64_t mix_increment = uint64_t((get_stream_sampling_rate() / double(target_rate)) * double(FP_LEN));
+ for (int i = 0; i < p_frames; i++) {
uint32_t idx = CUBIC_INTERP_HISTORY + uint32_t(mix_offset >> FP_BITS);
//standard cubic interpolation (great quality/performance ratio)
//this used to be moved to a LUT for greater performance, but nowadays CPU speed is generally faster than memory.
- float mu = (mix_offset&FP_MASK)/float(FP_LEN);
- AudioFrame y0 = internal_buffer[idx-3];
- AudioFrame y1 = internal_buffer[idx-2];
- AudioFrame y2 = internal_buffer[idx-1];
- AudioFrame y3 = internal_buffer[idx-0];
+ float mu = (mix_offset & FP_MASK) / float(FP_LEN);
+ AudioFrame y0 = internal_buffer[idx - 3];
+ AudioFrame y1 = internal_buffer[idx - 2];
+ AudioFrame y2 = internal_buffer[idx - 1];
+ AudioFrame y3 = internal_buffer[idx - 0];
- float mu2 = mu*mu;
+ float mu2 = mu * mu;
AudioFrame a0 = y3 - y2 - y0 + y1;
AudioFrame a1 = y0 - y1 - a0;
AudioFrame a2 = y2 - y0;
AudioFrame a3 = y1;
- p_buffer[i] = (a0*mu*mu2 + a1*mu2 + a2*mu + a3);
+ p_buffer[i] = (a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3);
- mix_offset+=mix_increment;
+ mix_offset += mix_increment;
- while ( (mix_offset >> FP_BITS) >= INTERNAL_BUFFER_LEN ) {
+ while ((mix_offset >> FP_BITS) >= INTERNAL_BUFFER_LEN) {
- internal_buffer[0]=internal_buffer[INTERNAL_BUFFER_LEN+0];
- internal_buffer[1]=internal_buffer[INTERNAL_BUFFER_LEN+1];
- internal_buffer[2]=internal_buffer[INTERNAL_BUFFER_LEN+2];
- internal_buffer[3]=internal_buffer[INTERNAL_BUFFER_LEN+3];
- _mix_internal(internal_buffer+4,INTERNAL_BUFFER_LEN);
- mix_offset-=(INTERNAL_BUFFER_LEN<<FP_BITS);
+ internal_buffer[0] = internal_buffer[INTERNAL_BUFFER_LEN + 0];
+ internal_buffer[1] = internal_buffer[INTERNAL_BUFFER_LEN + 1];
+ internal_buffer[2] = internal_buffer[INTERNAL_BUFFER_LEN + 2];
+ internal_buffer[3] = internal_buffer[INTERNAL_BUFFER_LEN + 3];
+ _mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN);
+ mix_offset -= (INTERNAL_BUFFER_LEN << FP_BITS);
}
}
}
diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h
index d08fedb08..0d7b4adbf 100644
--- a/servers/audio/audio_stream.h
+++ b/servers/audio/audio_stream.h
@@ -34,68 +34,57 @@
class AudioStreamPlayback : public Reference {
- GDCLASS( AudioStreamPlayback, Reference )
+ GDCLASS(AudioStreamPlayback, Reference)
public:
+ virtual void start(float p_from_pos = 0.0) = 0;
+ virtual void stop() = 0;
+ virtual bool is_playing() const = 0;
- virtual void start(float p_from_pos=0.0)=0;
- virtual void stop()=0;
- virtual bool is_playing() const=0;
+ virtual int get_loop_count() const = 0; //times it looped
- virtual int get_loop_count() const=0; //times it looped
-
- virtual float get_pos() const=0;
- virtual void seek_pos(float p_time)=0;
-
- virtual void mix(AudioFrame* p_bufer,float p_rate_scale,int p_frames)=0;
-
- virtual float get_length() const=0; //if supported, otherwise return 0
+ virtual float get_pos() const = 0;
+ virtual void seek_pos(float p_time) = 0;
+ virtual void mix(AudioFrame *p_bufer, float p_rate_scale, int p_frames) = 0;
+ virtual float get_length() const = 0; //if supported, otherwise return 0
};
class AudioStreamPlaybackResampled : public AudioStreamPlayback {
- GDCLASS( AudioStreamPlaybackResampled, AudioStreamPlayback )
-
-
+ GDCLASS(AudioStreamPlaybackResampled, AudioStreamPlayback)
enum {
- FP_BITS=16, //fixed point used for resampling
- FP_LEN=(1<<FP_BITS),
- FP_MASK=FP_LEN-1,
- INTERNAL_BUFFER_LEN=256,
- CUBIC_INTERP_HISTORY=4
+ FP_BITS = 16, //fixed point used for resampling
+ FP_LEN = (1 << FP_BITS),
+ FP_MASK = FP_LEN - 1,
+ INTERNAL_BUFFER_LEN = 256,
+ CUBIC_INTERP_HISTORY = 4
};
- AudioFrame internal_buffer[INTERNAL_BUFFER_LEN+CUBIC_INTERP_HISTORY];
+ AudioFrame internal_buffer[INTERNAL_BUFFER_LEN + CUBIC_INTERP_HISTORY];
uint64_t mix_offset;
protected:
void _begin_resample();
- virtual void _mix_internal(AudioFrame* p_bufer,int p_frames)=0;
- virtual float get_stream_sampling_rate()=0;
+ virtual void _mix_internal(AudioFrame *p_bufer, int p_frames) = 0;
+ virtual float get_stream_sampling_rate() = 0;
public:
+ virtual void mix(AudioFrame *p_bufer, float p_rate_scale, int p_frames);
- virtual void mix(AudioFrame* p_bufer,float p_rate_scale,int p_frames);
-
- AudioStreamPlaybackResampled() { mix_offset=0; }
+ AudioStreamPlaybackResampled() { mix_offset = 0; }
};
class AudioStream : public Resource {
- GDCLASS( AudioStream, Resource )
- OBJ_SAVE_TYPE( AudioStream ) //children are all saved as AudioStream, so they can be exchanged
-
+ GDCLASS(AudioStream, Resource)
+ OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged
public:
-
- virtual Ref<AudioStreamPlayback> instance_playback()=0;
- virtual String get_stream_name() const=0;
-
-
+ virtual Ref<AudioStreamPlayback> instance_playback() = 0;
+ virtual String get_stream_name() const = 0;
};
-
#endif // AUDIO_STREAM_H
diff --git a/servers/audio/effects/audio_effect_amplify.cpp b/servers/audio/effects/audio_effect_amplify.cpp
index a0796f522..6a4d03e51 100644
--- a/servers/audio/effects/audio_effect_amplify.cpp
+++ b/servers/audio/effects/audio_effect_amplify.cpp
@@ -28,35 +28,31 @@
/*************************************************************************/
#include "audio_effect_amplify.h"
-
-void AudioEffectAmplifyInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
-
+void AudioEffectAmplifyInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
//multiply volume interpolating to avoid clicks if this changes
float volume_db = base->volume_db;
float vol = Math::db2linear(mix_volume_db);
- float vol_inc = (Math::db2linear(volume_db) - vol)/float(p_frame_count);
+ float vol_inc = (Math::db2linear(volume_db) - vol) / float(p_frame_count);
- for(int i=0;i<p_frame_count;i++) {
- p_dst_frames[i]=p_src_frames[i]*vol;
- vol+=vol_inc;
+ for (int i = 0; i < p_frame_count; i++) {
+ p_dst_frames[i] = p_src_frames[i] * vol;
+ vol += vol_inc;
}
//set volume for next mix
mix_volume_db = volume_db;
-
}
-
Ref<AudioEffectInstance> AudioEffectAmplify::instance() {
Ref<AudioEffectAmplifyInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectAmplify>(this);
- ins->mix_volume_db=volume_db;
+ ins->base = Ref<AudioEffectAmplify>(this);
+ ins->mix_volume_db = volume_db;
return ins;
}
void AudioEffectAmplify::set_volume_db(float p_volume) {
- volume_db=p_volume;
+ volume_db = p_volume;
}
float AudioEffectAmplify::get_volume_db() const {
@@ -66,13 +62,12 @@ float AudioEffectAmplify::get_volume_db() const {
void AudioEffectAmplify::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_volume_db","volume"),&AudioEffectAmplify::set_volume_db);
- ClassDB::bind_method(D_METHOD("get_volume_db"),&AudioEffectAmplify::get_volume_db);
+ ClassDB::bind_method(D_METHOD("set_volume_db", "volume"), &AudioEffectAmplify::set_volume_db);
+ ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioEffectAmplify::get_volume_db);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"volume_db",PROPERTY_HINT_RANGE,"-80,24,0.01"),"set_volume_db","get_volume_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_volume_db", "get_volume_db");
}
-AudioEffectAmplify::AudioEffectAmplify()
-{
- volume_db=0;
+AudioEffectAmplify::AudioEffectAmplify() {
+ volume_db = 0;
}
diff --git a/servers/audio/effects/audio_effect_amplify.h b/servers/audio/effects/audio_effect_amplify.h
index 03f558e52..0c75b4369 100644
--- a/servers/audio/effects/audio_effect_amplify.h
+++ b/servers/audio/effects/audio_effect_amplify.h
@@ -34,30 +34,26 @@
class AudioEffectAmplify;
class AudioEffectAmplifyInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectAmplifyInstance,AudioEffectInstance)
-friend class AudioEffectAmplify;
+ GDCLASS(AudioEffectAmplifyInstance, AudioEffectInstance)
+ friend class AudioEffectAmplify;
Ref<AudioEffectAmplify> base;
float mix_volume_db;
-public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+public:
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectAmplify : public AudioEffect {
- GDCLASS(AudioEffectAmplify,AudioEffect)
+ GDCLASS(AudioEffectAmplify, AudioEffect)
-friend class AudioEffectAmplifyInstance;
+ friend class AudioEffectAmplifyInstance;
float volume_db;
protected:
-
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
void set_volume_db(float p_volume);
float get_volume_db() const;
diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp
index 20b45b572..fa3a571c6 100644
--- a/servers/audio/effects/audio_effect_chorus.cpp
+++ b/servers/audio/effects/audio_effect_chorus.cpp
@@ -27,161 +27,153 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "audio_effect_chorus.h"
-#include "servers/audio_server.h"
#include "math_funcs.h"
+#include "servers/audio_server.h"
-void AudioEffectChorusInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectChorusInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
int todo = p_frame_count;
- while(todo) {
+ while (todo) {
- int to_mix = MIN(todo,256); //can't mix too much
+ int to_mix = MIN(todo, 256); //can't mix too much
- _process_chunk(p_src_frames,p_dst_frames,to_mix);
+ _process_chunk(p_src_frames, p_dst_frames, to_mix);
- p_src_frames+=to_mix;
- p_dst_frames+=to_mix;
+ p_src_frames += to_mix;
+ p_dst_frames += to_mix;
- todo-=to_mix;
+ todo -= to_mix;
}
}
-void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
-
+void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
//fill ringbuffer
- for(int i=0;i<p_frame_count;i++) {
- audio_buffer[(buffer_pos+i)&buffer_mask]=p_src_frames[i];
- p_dst_frames[i]=p_src_frames[i]*base->dry;
+ for (int i = 0; i < p_frame_count; i++) {
+ audio_buffer[(buffer_pos + i) & buffer_mask] = p_src_frames[i];
+ p_dst_frames[i] = p_src_frames[i] * base->dry;
}
float mix_rate = AudioServer::get_singleton()->get_mix_rate();
/* process voices */
- for (int vc=0;vc<base->voice_count;vc++) {
+ for (int vc = 0; vc < base->voice_count; vc++) {
- AudioEffectChorus::Voice &v=base->voice[vc];
+ AudioEffectChorus::Voice &v = base->voice[vc];
+ double time_to_mix = (float)p_frame_count / mix_rate;
+ double cycles_to_mix = time_to_mix * v.rate;
- double time_to_mix=(float)p_frame_count/mix_rate;
- double cycles_to_mix=time_to_mix*v.rate;
+ unsigned int local_rb_pos = buffer_pos;
+ AudioFrame *dst_buff = p_dst_frames;
+ AudioFrame *rb_buff = audio_buffer.ptr();
- unsigned int local_rb_pos=buffer_pos;
- AudioFrame *dst_buff=p_dst_frames;
- AudioFrame *rb_buff=audio_buffer.ptr();
+ double delay_msec = v.delay;
+ unsigned int delay_frames = Math::fast_ftoi((delay_msec / 1000.0) * mix_rate);
+ float max_depth_frames = (v.depth / 1000.0) * mix_rate;
- double delay_msec=v.delay;
- unsigned int delay_frames=Math::fast_ftoi((delay_msec/1000.0)*mix_rate);
- float max_depth_frames=(v.depth/1000.0)*mix_rate;
-
- uint64_t local_cycles=cycles[vc];
- uint64_t increment=llrint(cycles_to_mix/(double)p_frame_count*(double)(1<<AudioEffectChorus::CYCLES_FRAC));
+ uint64_t local_cycles = cycles[vc];
+ uint64_t increment = llrint(cycles_to_mix / (double)p_frame_count * (double)(1 << AudioEffectChorus::CYCLES_FRAC));
//check the LFO doesnt read ahead of the write pos
- if ((((int)max_depth_frames)+10)>delay_frames) { //10 as some threshold to avoid precision stuff
- delay_frames+=(int)max_depth_frames-delay_frames;
- delay_frames+=10; //threshold to avoid precision stuff
-
+ if ((((int)max_depth_frames) + 10) > delay_frames) { //10 as some threshold to avoid precision stuff
+ delay_frames += (int)max_depth_frames - delay_frames;
+ delay_frames += 10; //threshold to avoid precision stuff
}
-
-
//low pass filter
- if (v.cutoff==0)
+ if (v.cutoff == 0)
continue;
- float auxlp=expf(-2.0*Math_PI*v.cutoff/mix_rate);
- float c1=1.0-auxlp;
- float c2=auxlp;
- AudioFrame h=filter_h[vc];
- if (v.cutoff>=AudioEffectChorus::MS_CUTOFF_MAX) {
- c1=1.0; c2=0.0;
+ float auxlp = expf(-2.0 * Math_PI * v.cutoff / mix_rate);
+ float c1 = 1.0 - auxlp;
+ float c2 = auxlp;
+ AudioFrame h = filter_h[vc];
+ if (v.cutoff >= AudioEffectChorus::MS_CUTOFF_MAX) {
+ c1 = 1.0;
+ c2 = 0.0;
}
//vol modifier
- AudioFrame vol_modifier=AudioFrame(base->wet,base->wet) * Math::db2linear(v.level);
- vol_modifier.l*=CLAMP( 1.0 - v.pan, 0, 1);
- vol_modifier.r*=CLAMP( 1.0 + v.pan, 0, 1);
-
+ AudioFrame vol_modifier = AudioFrame(base->wet, base->wet) * Math::db2linear(v.level);
+ vol_modifier.l *= CLAMP(1.0 - v.pan, 0, 1);
+ vol_modifier.r *= CLAMP(1.0 + v.pan, 0, 1);
-
- for (int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
/** COMPUTE WAVEFORM **/
- float phase=(float)(local_cycles&AudioEffectChorus::CYCLES_MASK)/(float)(1<<AudioEffectChorus::CYCLES_FRAC);
+ float phase = (float)(local_cycles & AudioEffectChorus::CYCLES_MASK) / (float)(1 << AudioEffectChorus::CYCLES_FRAC);
- float wave_delay=sinf(phase*2.0*Math_PI)*max_depth_frames;
+ float wave_delay = sinf(phase * 2.0 * Math_PI) * max_depth_frames;
- int wave_delay_frames=lrint(floor(wave_delay));
- float wave_delay_frac=wave_delay-(float)wave_delay_frames;
+ int wave_delay_frames = lrint(floor(wave_delay));
+ float wave_delay_frac = wave_delay - (float)wave_delay_frames;
/** COMPUTE RINGBUFFER POS**/
- unsigned int rb_source=local_rb_pos;
- rb_source-=delay_frames;
+ unsigned int rb_source = local_rb_pos;
+ rb_source -= delay_frames;
- rb_source-=wave_delay_frames;
+ rb_source -= wave_delay_frames;
/** READ FROM RINGBUFFER, LINEARLY INTERPOLATE */
- AudioFrame val=rb_buff[rb_source&buffer_mask];
- AudioFrame val_next=rb_buff[(rb_source-1)&buffer_mask];
+ AudioFrame val = rb_buff[rb_source & buffer_mask];
+ AudioFrame val_next = rb_buff[(rb_source - 1) & buffer_mask];
- val+=(val_next-val)*wave_delay_frac;
+ val += (val_next - val) * wave_delay_frac;
- val=val*c1+h*c2;
- h=val;
+ val = val * c1 + h * c2;
+ h = val;
/** MIX VALUE TO OUTPUT **/
- dst_buff[i]+=val*vol_modifier;
+ dst_buff[i] += val * vol_modifier;
- local_cycles+=increment;
+ local_cycles += increment;
local_rb_pos++;
-
}
- filter_h[vc]=h;
- cycles[vc]+=Math::fast_ftoi(cycles_to_mix*(double)(1<<AudioEffectChorus::CYCLES_FRAC));
+ filter_h[vc] = h;
+ cycles[vc] += Math::fast_ftoi(cycles_to_mix * (double)(1 << AudioEffectChorus::CYCLES_FRAC));
}
- buffer_pos+=p_frame_count;
+ buffer_pos += p_frame_count;
}
-
Ref<AudioEffectInstance> AudioEffectChorus::instance() {
Ref<AudioEffectChorusInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectChorus>(this);
- for(int i=0;i<4;i++) {
- ins->filter_h[i]=AudioFrame(0,0);
- ins->cycles[i]=0;
+ ins->base = Ref<AudioEffectChorus>(this);
+ for (int i = 0; i < 4; i++) {
+ ins->filter_h[i] = AudioFrame(0, 0);
+ ins->cycles[i] = 0;
}
- float ring_buffer_max_size=AudioEffectChorus::MAX_DELAY_MS+AudioEffectChorus::MAX_DEPTH_MS+AudioEffectChorus::MAX_WIDTH_MS;
+ float ring_buffer_max_size = AudioEffectChorus::MAX_DELAY_MS + AudioEffectChorus::MAX_DEPTH_MS + AudioEffectChorus::MAX_WIDTH_MS;
- ring_buffer_max_size*=2; //just to avoid complications
- ring_buffer_max_size/=1000.0;//convert to seconds
- ring_buffer_max_size*=AudioServer::get_singleton()->get_mix_rate();
+ ring_buffer_max_size *= 2; //just to avoid complications
+ ring_buffer_max_size /= 1000.0; //convert to seconds
+ ring_buffer_max_size *= AudioServer::get_singleton()->get_mix_rate();
- int ringbuff_size=ring_buffer_max_size;
+ int ringbuff_size = ring_buffer_max_size;
- int bits=0;
+ int bits = 0;
- while(ringbuff_size>0) {
+ while (ringbuff_size > 0) {
bits++;
- ringbuff_size/=2;
+ ringbuff_size /= 2;
}
- ringbuff_size=1<<bits;
- ins->buffer_mask=ringbuff_size-1;
- ins->buffer_pos=0;
+ ringbuff_size = 1 << bits;
+ ins->buffer_mask = ringbuff_size - 1;
+ ins->buffer_pos = 0;
ins->audio_buffer.resize(ringbuff_size);
- for(int i=0;i<ringbuff_size;i++) {
- ins->audio_buffer[i]=AudioFrame(0,0);
+ for (int i = 0; i < ringbuff_size; i++) {
+ ins->audio_buffer[i] = AudioFrame(0, 0);
}
return ins;
@@ -189,205 +181,195 @@ Ref<AudioEffectInstance> AudioEffectChorus::instance() {
void AudioEffectChorus::set_voice_count(int p_voices) {
- ERR_FAIL_COND(p_voices<1 || p_voices>=MAX_VOICES);
- voice_count=p_voices;
+ ERR_FAIL_COND(p_voices < 1 || p_voices >= MAX_VOICES);
+ voice_count = p_voices;
_change_notify();
}
-
-int AudioEffectChorus::get_voice_count() const{
+int AudioEffectChorus::get_voice_count() const {
return voice_count;
}
-void AudioEffectChorus::set_voice_delay_ms(int p_voice,float p_delay_ms){
-
- ERR_FAIL_INDEX(p_voice,MAX_VOICES);
+void AudioEffectChorus::set_voice_delay_ms(int p_voice, float p_delay_ms) {
- voice[p_voice].delay=p_delay_ms;
+ ERR_FAIL_INDEX(p_voice, MAX_VOICES);
+ voice[p_voice].delay = p_delay_ms;
}
-float AudioEffectChorus::get_voice_delay_ms(int p_voice) const{
+float AudioEffectChorus::get_voice_delay_ms(int p_voice) const {
- ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0);
+ ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0);
return voice[p_voice].delay;
}
-void AudioEffectChorus::set_voice_rate_hz(int p_voice,float p_rate_hz){
- ERR_FAIL_INDEX(p_voice,MAX_VOICES);
+void AudioEffectChorus::set_voice_rate_hz(int p_voice, float p_rate_hz) {
+ ERR_FAIL_INDEX(p_voice, MAX_VOICES);
- voice[p_voice].rate=p_rate_hz;
+ voice[p_voice].rate = p_rate_hz;
}
-float AudioEffectChorus::get_voice_rate_hz(int p_voice) const{
+float AudioEffectChorus::get_voice_rate_hz(int p_voice) const {
- ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0);
+ ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0);
return voice[p_voice].rate;
}
-void AudioEffectChorus::set_voice_depth_ms(int p_voice,float p_depth_ms){
+void AudioEffectChorus::set_voice_depth_ms(int p_voice, float p_depth_ms) {
- ERR_FAIL_INDEX(p_voice,MAX_VOICES);
+ ERR_FAIL_INDEX(p_voice, MAX_VOICES);
- voice[p_voice].depth=p_depth_ms;
+ voice[p_voice].depth = p_depth_ms;
}
-float AudioEffectChorus::get_voice_depth_ms(int p_voice) const{
+float AudioEffectChorus::get_voice_depth_ms(int p_voice) const {
- ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0);
+ ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0);
return voice[p_voice].depth;
}
-void AudioEffectChorus::set_voice_level_db(int p_voice,float p_level_db){
+void AudioEffectChorus::set_voice_level_db(int p_voice, float p_level_db) {
- ERR_FAIL_INDEX(p_voice,MAX_VOICES);
+ ERR_FAIL_INDEX(p_voice, MAX_VOICES);
- voice[p_voice].level=p_level_db;
+ voice[p_voice].level = p_level_db;
}
-float AudioEffectChorus::get_voice_level_db(int p_voice) const{
+float AudioEffectChorus::get_voice_level_db(int p_voice) const {
- ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0);
+ ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0);
return voice[p_voice].level;
}
+void AudioEffectChorus::set_voice_cutoff_hz(int p_voice, float p_cutoff_hz) {
-void AudioEffectChorus::set_voice_cutoff_hz(int p_voice,float p_cutoff_hz){
+ ERR_FAIL_INDEX(p_voice, MAX_VOICES);
- ERR_FAIL_INDEX(p_voice,MAX_VOICES);
-
- voice[p_voice].cutoff=p_cutoff_hz;
+ voice[p_voice].cutoff = p_cutoff_hz;
}
-float AudioEffectChorus::get_voice_cutoff_hz(int p_voice) const{
+float AudioEffectChorus::get_voice_cutoff_hz(int p_voice) const {
- ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0);
+ ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0);
return voice[p_voice].cutoff;
}
-void AudioEffectChorus::set_voice_pan(int p_voice,float p_pan){
+void AudioEffectChorus::set_voice_pan(int p_voice, float p_pan) {
- ERR_FAIL_INDEX(p_voice,MAX_VOICES);
+ ERR_FAIL_INDEX(p_voice, MAX_VOICES);
- voice[p_voice].pan=p_pan;
+ voice[p_voice].pan = p_pan;
}
-float AudioEffectChorus::get_voice_pan(int p_voice) const{
+float AudioEffectChorus::get_voice_pan(int p_voice) const {
- ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0);
+ ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0);
return voice[p_voice].pan;
}
+void AudioEffectChorus::set_wet(float amount) {
-void AudioEffectChorus::set_wet(float amount){
-
-
- wet=amount;
+ wet = amount;
}
-float AudioEffectChorus::get_wet() const{
+float AudioEffectChorus::get_wet() const {
return wet;
}
-void AudioEffectChorus::set_dry(float amount){
-
- dry=amount;
+void AudioEffectChorus::set_dry(float amount) {
+ dry = amount;
}
-float AudioEffectChorus::get_dry() const{
+float AudioEffectChorus::get_dry() const {
return dry;
}
-void AudioEffectChorus::_validate_property(PropertyInfo& property) const {
+void AudioEffectChorus::_validate_property(PropertyInfo &property) const {
if (property.name.begins_with("voice/")) {
- int voice_idx = property.name.get_slice("/",1).to_int();
- if (voice_idx>voice_count) {
- property.usage=0;
+ int voice_idx = property.name.get_slice("/", 1).to_int();
+ if (voice_idx > voice_count) {
+ property.usage = 0;
}
}
}
-
void AudioEffectChorus::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_voice_count","voices"),&AudioEffectChorus::set_voice_count);
- ClassDB::bind_method(D_METHOD("get_voice_count"),&AudioEffectChorus::get_voice_count);
-
-
- ClassDB::bind_method(D_METHOD("set_voice_delay_ms","voice_idx","delay_ms"),&AudioEffectChorus::set_voice_delay_ms);
- ClassDB::bind_method(D_METHOD("get_voice_delay_ms","voice_idx"),&AudioEffectChorus::get_voice_delay_ms);
+ ClassDB::bind_method(D_METHOD("set_voice_count", "voices"), &AudioEffectChorus::set_voice_count);
+ ClassDB::bind_method(D_METHOD("get_voice_count"), &AudioEffectChorus::get_voice_count);
- ClassDB::bind_method(D_METHOD("set_voice_rate_hz","voice_idx","rate_hz"),&AudioEffectChorus::set_voice_rate_hz);
- ClassDB::bind_method(D_METHOD("get_voice_rate_hz","voice_idx"),&AudioEffectChorus::get_voice_rate_hz);
+ ClassDB::bind_method(D_METHOD("set_voice_delay_ms", "voice_idx", "delay_ms"), &AudioEffectChorus::set_voice_delay_ms);
+ ClassDB::bind_method(D_METHOD("get_voice_delay_ms", "voice_idx"), &AudioEffectChorus::get_voice_delay_ms);
- ClassDB::bind_method(D_METHOD("set_voice_depth_ms","voice_idx","depth_ms"),&AudioEffectChorus::set_voice_depth_ms);
- ClassDB::bind_method(D_METHOD("get_voice_depth_ms","voice_idx"),&AudioEffectChorus::get_voice_depth_ms);
+ ClassDB::bind_method(D_METHOD("set_voice_rate_hz", "voice_idx", "rate_hz"), &AudioEffectChorus::set_voice_rate_hz);
+ ClassDB::bind_method(D_METHOD("get_voice_rate_hz", "voice_idx"), &AudioEffectChorus::get_voice_rate_hz);
- ClassDB::bind_method(D_METHOD("set_voice_level_db","voice_idx","level_db"),&AudioEffectChorus::set_voice_level_db);
- ClassDB::bind_method(D_METHOD("get_voice_level_db","voice_idx"),&AudioEffectChorus::get_voice_level_db);
+ ClassDB::bind_method(D_METHOD("set_voice_depth_ms", "voice_idx", "depth_ms"), &AudioEffectChorus::set_voice_depth_ms);
+ ClassDB::bind_method(D_METHOD("get_voice_depth_ms", "voice_idx"), &AudioEffectChorus::get_voice_depth_ms);
- ClassDB::bind_method(D_METHOD("set_voice_cutoff_hz","voice_idx","cutoff_hz"),&AudioEffectChorus::set_voice_cutoff_hz);
- ClassDB::bind_method(D_METHOD("get_voice_cutoff_hz","voice_idx"),&AudioEffectChorus::get_voice_cutoff_hz);
+ ClassDB::bind_method(D_METHOD("set_voice_level_db", "voice_idx", "level_db"), &AudioEffectChorus::set_voice_level_db);
+ ClassDB::bind_method(D_METHOD("get_voice_level_db", "voice_idx"), &AudioEffectChorus::get_voice_level_db);
- ClassDB::bind_method(D_METHOD("set_voice_pan","voice_idx","pan"),&AudioEffectChorus::set_voice_pan);
- ClassDB::bind_method(D_METHOD("get_voice_pan","voice_idx"),&AudioEffectChorus::get_voice_pan);
+ ClassDB::bind_method(D_METHOD("set_voice_cutoff_hz", "voice_idx", "cutoff_hz"), &AudioEffectChorus::set_voice_cutoff_hz);
+ ClassDB::bind_method(D_METHOD("get_voice_cutoff_hz", "voice_idx"), &AudioEffectChorus::get_voice_cutoff_hz);
- ClassDB::bind_method(D_METHOD("set_wet","amount"),&AudioEffectChorus::set_wet);
- ClassDB::bind_method(D_METHOD("get_wet"),&AudioEffectChorus::get_wet);
+ ClassDB::bind_method(D_METHOD("set_voice_pan", "voice_idx", "pan"), &AudioEffectChorus::set_voice_pan);
+ ClassDB::bind_method(D_METHOD("get_voice_pan", "voice_idx"), &AudioEffectChorus::get_voice_pan);
- ClassDB::bind_method(D_METHOD("set_dry","amount"),&AudioEffectChorus::set_dry);
- ClassDB::bind_method(D_METHOD("get_dry"),&AudioEffectChorus::get_dry);
+ ClassDB::bind_method(D_METHOD("set_wet", "amount"), &AudioEffectChorus::set_wet);
+ ClassDB::bind_method(D_METHOD("get_wet"), &AudioEffectChorus::get_wet);
- ADD_PROPERTY(PropertyInfo(Variant::INT,"voice_count",PROPERTY_HINT_RANGE,"1,4,1"),"set_voice_count","get_voice_count");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"dry",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_dry","get_dry");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"wet",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_wet","get_wet");
+ ClassDB::bind_method(D_METHOD("set_dry", "amount"), &AudioEffectChorus::set_dry);
+ ClassDB::bind_method(D_METHOD("get_dry"), &AudioEffectChorus::get_dry);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),"set_voice_delay_ms","get_voice_delay_ms",0);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),"set_voice_rate_hz","get_voice_rate_hz",0);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),"set_voice_depth_ms","get_voice_depth_ms",0);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),"set_voice_level_db","get_voice_level_db",0);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),"set_voice_cutoff_hz","get_voice_cutoff_hz",0);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_voice_pan","get_voice_pan",0);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "voice_count", PROPERTY_HINT_RANGE, "1,4,1"), "set_voice_count", "get_voice_count");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "dry", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dry", "get_dry");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "wet", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_wet", "get_wet");
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),"set_voice_delay_ms","get_voice_delay_ms",1);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),"set_voice_rate_hz","get_voice_rate_hz",1);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),"set_voice_depth_ms","get_voice_depth_ms",1);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),"set_voice_level_db","get_voice_level_db",1);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),"set_voice_cutoff_hz","get_voice_cutoff_hz",1);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_voice_pan","get_voice_pan",1);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/delay_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_voice_delay_ms", "get_voice_delay_ms", 0);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 0);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 0);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 0);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 0);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 0);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),"set_voice_delay_ms","get_voice_delay_ms",2);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),"set_voice_rate_hz","get_voice_rate_hz",2);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),"set_voice_depth_ms","get_voice_depth_ms",2);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),"set_voice_level_db","get_voice_level_db",2);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),"set_voice_cutoff_hz","get_voice_cutoff_hz",2);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_voice_pan","get_voice_pan",2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/delay_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_voice_delay_ms", "get_voice_delay_ms", 1);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 1);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 1);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 1);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 1);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 1);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),"set_voice_delay_ms","get_voice_delay_ms",3);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),"set_voice_rate_hz","get_voice_rate_hz",3);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),"set_voice_depth_ms","get_voice_depth_ms",3);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),"set_voice_level_db","get_voice_level_db",3);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),"set_voice_cutoff_hz","get_voice_cutoff_hz",3);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_voice_pan","get_voice_pan",3);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/delay_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_voice_delay_ms", "get_voice_delay_ms", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/delay_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_voice_delay_ms", "get_voice_delay_ms", 3);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 3);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 3);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 3);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 3);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 3);
}
-AudioEffectChorus::AudioEffectChorus()
-{
- voice_count=2;
- voice[0].delay=15;
- voice[1].delay=20;
- voice[0].rate=0.8;
- voice[1].rate=1.2;
- voice[0].depth=2;
- voice[1].depth=3;
- voice[0].cutoff=8000;
- voice[1].cutoff=8000;
- voice[0].pan=-0.5;
- voice[1].pan=0.5;
+AudioEffectChorus::AudioEffectChorus() {
+ voice_count = 2;
+ voice[0].delay = 15;
+ voice[1].delay = 20;
+ voice[0].rate = 0.8;
+ voice[1].rate = 1.2;
+ voice[0].depth = 2;
+ voice[1].depth = 3;
+ voice[0].cutoff = 8000;
+ voice[1].cutoff = 8000;
+ voice[0].pan = -0.5;
+ voice[1].pan = 0.5;
- wet=0.5;
- dry=1.0;
+ wet = 0.5;
+ dry = 1.0;
}
diff --git a/servers/audio/effects/audio_effect_chorus.h b/servers/audio/effects/audio_effect_chorus.h
index ae0964bd5..9af9ab1b9 100644
--- a/servers/audio/effects/audio_effect_chorus.h
+++ b/servers/audio/effects/audio_effect_chorus.h
@@ -29,14 +29,13 @@
#ifndef AUDIOEFFECTCHORUS_H
#define AUDIOEFFECTCHORUS_H
-
#include "servers/audio/audio_effect.h"
class AudioEffectChorus;
class AudioEffectChorusInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectChorusInstance,AudioEffectInstance)
-friend class AudioEffectChorus;
+ GDCLASS(AudioEffectChorusInstance, AudioEffectInstance)
+ friend class AudioEffectChorus;
Ref<AudioEffectChorus> base;
Vector<AudioFrame> audio_buffer;
@@ -46,34 +45,31 @@ friend class AudioEffectChorus;
AudioFrame filter_h[4];
uint64_t cycles[4];
- void _process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+ void _process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
-
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectChorus : public AudioEffect {
- GDCLASS(AudioEffectChorus,AudioEffect)
+ GDCLASS(AudioEffectChorus, AudioEffect)
+
+ friend class AudioEffectChorusInstance;
-friend class AudioEffectChorusInstance;
public:
enum {
- MAX_DELAY_MS=50,
- MAX_DEPTH_MS=20,
- MAX_WIDTH_MS=50,
- MAX_VOICES=4,
- CYCLES_FRAC=16,
- CYCLES_MASK=(1<<CYCLES_FRAC)-1,
- MAX_CHANNELS=4,
- MS_CUTOFF_MAX=16000
+ MAX_DELAY_MS = 50,
+ MAX_DEPTH_MS = 20,
+ MAX_WIDTH_MS = 50,
+ MAX_VOICES = 4,
+ CYCLES_FRAC = 16,
+ CYCLES_MASK = (1 << CYCLES_FRAC) - 1,
+ MAX_CHANNELS = 4,
+ MS_CUTOFF_MAX = 16000
};
private:
-
struct Voice {
float delay;
@@ -85,13 +81,12 @@ private:
Voice() {
- delay=12.0;
- rate=1;
- depth=0;
- level=0;
- cutoff=MS_CUTOFF_MAX;
- pan=0;
-
+ delay = 12.0;
+ rate = 1;
+ depth = 0;
+ level = 0;
+ cutoff = MS_CUTOFF_MAX;
+ pan = 0;
}
} voice[MAX_VOICES];
@@ -101,32 +96,31 @@ private:
float wet;
float dry;
-
protected:
- void _validate_property(PropertyInfo& property) const;
+ void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
-public:
+public:
void set_voice_count(int p_voices);
int get_voice_count() const;
- void set_voice_delay_ms(int p_voice,float p_delay_ms);
+ void set_voice_delay_ms(int p_voice, float p_delay_ms);
float get_voice_delay_ms(int p_voice) const;
- void set_voice_rate_hz(int p_voice,float p_rate_hz);
+ void set_voice_rate_hz(int p_voice, float p_rate_hz);
float get_voice_rate_hz(int p_voice) const;
- void set_voice_depth_ms(int p_voice,float p_depth_ms);
+ void set_voice_depth_ms(int p_voice, float p_depth_ms);
float get_voice_depth_ms(int p_voice) const;
- void set_voice_level_db(int p_voice,float p_level_db);
+ void set_voice_level_db(int p_voice, float p_level_db);
float get_voice_level_db(int p_voice) const;
- void set_voice_cutoff_hz(int p_voice,float p_cutoff_hz);
+ void set_voice_cutoff_hz(int p_voice, float p_cutoff_hz);
float get_voice_cutoff_hz(int p_voice) const;
- void set_voice_pan(int p_voice,float p_pan);
+ void set_voice_pan(int p_voice, float p_pan);
float get_voice_pan(int p_voice) const;
void set_wet(float amount);
diff --git a/servers/audio/effects/audio_effect_compressor.cpp b/servers/audio/effects/audio_effect_compressor.cpp
index c08302c58..8b6735322 100644
--- a/servers/audio/effects/audio_effect_compressor.cpp
+++ b/servers/audio/effects/audio_effect_compressor.cpp
@@ -29,11 +29,10 @@
#include "audio_effect_compressor.h"
#include "servers/audio_server.h"
-void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
-
+void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
float treshold = Math::db2linear(base->treshold);
- float sample_rate=AudioServer::get_singleton()->get_mix_rate();
+ float sample_rate = AudioServer::get_singleton()->get_mix_rate();
float ratatcoef = exp(-1 / (0.00001f * sample_rate));
float ratrelcoef = exp(-1 / (0.5f * sample_rate));
@@ -49,35 +48,35 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames,Audio
const AudioFrame *src = p_src_frames;
- if (base->sidechain!=StringName() && current_channel!=-1) {
+ if (base->sidechain != StringName() && current_channel != -1) {
int bus = AudioServer::get_singleton()->thread_find_bus_index(base->sidechain);
- if (bus>=0) {
- src = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus,current_channel);
+ if (bus >= 0) {
+ src = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus, current_channel);
}
}
- for(int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
AudioFrame s = src[i];
//convert to positive
s.l = Math::abs(s.l);
s.r = Math::abs(s.r);
- float peak = MAX(s.l,s.r);
+ float peak = MAX(s.l, s.r);
- float overdb = 2.08136898f * Math::linear2db(peak/treshold);
+ float overdb = 2.08136898f * Math::linear2db(peak / treshold);
- if (overdb<0.0) //we only care about what goes over to compress
- overdb=0.0;
+ if (overdb < 0.0) //we only care about what goes over to compress
+ overdb = 0.0;
- if(overdb-rundb>5) // diffeence is too large
+ if (overdb - rundb > 5) // diffeence is too large
averatio = 4;
- if(overdb > rundb) {
+ if (overdb > rundb) {
rundb = overdb + atcoef * (rundb - overdb);
runratio = averatio + ratatcoef * (runratio - averatio);
- } else {
+ } else {
rundb = overdb + relcoef * (rundb - overdb);
runratio = averatio + ratrelcoef * (runratio - averatio);
}
@@ -87,52 +86,47 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames,Audio
float cratio;
- if(false) { //rato all-in
+ if (false) { //rato all-in
cratio = 12 + averatio;
} else {
cratio = base->ratio;
}
- float gr = -overdb * (cratio-1)/cratio;
+ float gr = -overdb * (cratio - 1) / cratio;
float grv = Math::db2linear(gr);
- runmax = maxover + relcoef * (runmax - maxover); // highest peak for setting att/rel decays in reltime
+ runmax = maxover + relcoef * (runmax - maxover); // highest peak for setting att/rel decays in reltime
maxover = runmax;
if (grv < gr_meter) {
- gr_meter=grv;
+ gr_meter = grv;
} else {
- gr_meter*=gr_meter_decay;
- if(gr_meter>1)
- gr_meter=1;
+ gr_meter *= gr_meter_decay;
+ if (gr_meter > 1)
+ gr_meter = 1;
}
-
- p_dst_frames[i] = p_src_frames[i] * grv * makeup * mix + p_src_frames[i] * (1.0-mix);
-
+ p_dst_frames[i] = p_src_frames[i] * grv * makeup * mix + p_src_frames[i] * (1.0 - mix);
}
-
}
-
Ref<AudioEffectInstance> AudioEffectCompressor::instance() {
Ref<AudioEffectCompressorInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectCompressor>(this);
- ins->rundb=0;
- ins->runratio=0;
- ins->averatio=0;
- ins->runmax=0;
- ins->maxover=0;
- ins->gr_meter=1.0;
- ins->current_channel=-1;
+ ins->base = Ref<AudioEffectCompressor>(this);
+ ins->rundb = 0;
+ ins->runratio = 0;
+ ins->averatio = 0;
+ ins->runmax = 0;
+ ins->maxover = 0;
+ ins->gr_meter = 1.0;
+ ins->current_channel = -1;
return ins;
}
-
void AudioEffectCompressor::set_treshold(float p_treshold) {
- treshold=p_treshold;
+ treshold = p_treshold;
}
float AudioEffectCompressor::get_treshold() const {
@@ -142,7 +136,7 @@ float AudioEffectCompressor::get_treshold() const {
void AudioEffectCompressor::set_ratio(float p_ratio) {
- ratio=p_ratio;
+ ratio = p_ratio;
}
float AudioEffectCompressor::get_ratio() const {
@@ -151,7 +145,7 @@ float AudioEffectCompressor::get_ratio() const {
void AudioEffectCompressor::set_gain(float p_gain) {
- gain=p_gain;
+ gain = p_gain;
}
float AudioEffectCompressor::get_gain() const {
@@ -160,7 +154,7 @@ float AudioEffectCompressor::get_gain() const {
void AudioEffectCompressor::set_attack_us(float p_attack_us) {
- attack_us=p_attack_us;
+ attack_us = p_attack_us;
}
float AudioEffectCompressor::get_attack_us() const {
@@ -169,7 +163,7 @@ float AudioEffectCompressor::get_attack_us() const {
void AudioEffectCompressor::set_release_ms(float p_release_ms) {
- release_ms=p_release_ms;
+ release_ms = p_release_ms;
}
float AudioEffectCompressor::get_release_ms() const {
@@ -178,17 +172,17 @@ float AudioEffectCompressor::get_release_ms() const {
void AudioEffectCompressor::set_mix(float p_mix) {
- mix=p_mix;
+ mix = p_mix;
}
float AudioEffectCompressor::get_mix() const {
return mix;
}
-void AudioEffectCompressor::set_sidechain(const StringName& p_sidechain) {
+void AudioEffectCompressor::set_sidechain(const StringName &p_sidechain) {
AudioServer::get_singleton()->lock();
- sidechain=p_sidechain;
+ sidechain = p_sidechain;
AudioServer::get_singleton()->unlock();
}
@@ -197,59 +191,57 @@ StringName AudioEffectCompressor::get_sidechain() const {
return sidechain;
}
-void AudioEffectCompressor::_validate_property(PropertyInfo& property) const {
+void AudioEffectCompressor::_validate_property(PropertyInfo &property) const {
- if (property.name=="sidechain") {
+ if (property.name == "sidechain") {
- String buses="";
- for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) {
- buses+=",";
- buses+=AudioServer::get_singleton()->get_bus_name(i);
+ String buses = "";
+ for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
+ buses += ",";
+ buses += AudioServer::get_singleton()->get_bus_name(i);
}
- property.hint_string=buses;
+ property.hint_string = buses;
}
}
void AudioEffectCompressor::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_treshold","treshold"),&AudioEffectCompressor::set_treshold);
- ClassDB::bind_method(D_METHOD("get_treshold"),&AudioEffectCompressor::get_treshold);
-
- ClassDB::bind_method(D_METHOD("set_ratio","ratio"),&AudioEffectCompressor::set_ratio);
- ClassDB::bind_method(D_METHOD("get_ratio"),&AudioEffectCompressor::get_ratio);
+ ClassDB::bind_method(D_METHOD("set_treshold", "treshold"), &AudioEffectCompressor::set_treshold);
+ ClassDB::bind_method(D_METHOD("get_treshold"), &AudioEffectCompressor::get_treshold);
- ClassDB::bind_method(D_METHOD("set_gain","gain"),&AudioEffectCompressor::set_gain);
- ClassDB::bind_method(D_METHOD("get_gain"),&AudioEffectCompressor::get_gain);
+ ClassDB::bind_method(D_METHOD("set_ratio", "ratio"), &AudioEffectCompressor::set_ratio);
+ ClassDB::bind_method(D_METHOD("get_ratio"), &AudioEffectCompressor::get_ratio);
- ClassDB::bind_method(D_METHOD("set_attack_us","attack_us"),&AudioEffectCompressor::set_attack_us);
- ClassDB::bind_method(D_METHOD("get_attack_us"),&AudioEffectCompressor::get_attack_us);
+ ClassDB::bind_method(D_METHOD("set_gain", "gain"), &AudioEffectCompressor::set_gain);
+ ClassDB::bind_method(D_METHOD("get_gain"), &AudioEffectCompressor::get_gain);
- ClassDB::bind_method(D_METHOD("set_release_ms","release_ms"),&AudioEffectCompressor::set_release_ms);
- ClassDB::bind_method(D_METHOD("get_release_ms"),&AudioEffectCompressor::get_release_ms);
+ ClassDB::bind_method(D_METHOD("set_attack_us", "attack_us"), &AudioEffectCompressor::set_attack_us);
+ ClassDB::bind_method(D_METHOD("get_attack_us"), &AudioEffectCompressor::get_attack_us);
- ClassDB::bind_method(D_METHOD("set_mix","mix"),&AudioEffectCompressor::set_mix);
- ClassDB::bind_method(D_METHOD("get_mix"),&AudioEffectCompressor::get_mix);
+ ClassDB::bind_method(D_METHOD("set_release_ms", "release_ms"), &AudioEffectCompressor::set_release_ms);
+ ClassDB::bind_method(D_METHOD("get_release_ms"), &AudioEffectCompressor::get_release_ms);
- ClassDB::bind_method(D_METHOD("set_sidechain","sidechain"),&AudioEffectCompressor::set_sidechain);
- ClassDB::bind_method(D_METHOD("get_sidechain"),&AudioEffectCompressor::get_sidechain);
+ ClassDB::bind_method(D_METHOD("set_mix", "mix"), &AudioEffectCompressor::set_mix);
+ ClassDB::bind_method(D_METHOD("get_mix"), &AudioEffectCompressor::get_mix);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"treshold",PROPERTY_HINT_RANGE,"-60,0,0.1"),"set_treshold","get_treshold");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"ratio",PROPERTY_HINT_RANGE,"1,48,0.1"),"set_ratio","get_ratio");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"gain",PROPERTY_HINT_RANGE,"-20,20,0.1"),"set_gain","get_gain");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"attack_us",PROPERTY_HINT_RANGE,"20,2000,1"),"set_attack_us","get_attack_us");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"release_ms",PROPERTY_HINT_RANGE,"20,2000,1"),"set_release_ms","get_release_ms");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"mix",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_mix","get_mix");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"sidechain",PROPERTY_HINT_ENUM),"set_sidechain","get_sidechain");
+ ClassDB::bind_method(D_METHOD("set_sidechain", "sidechain"), &AudioEffectCompressor::set_sidechain);
+ ClassDB::bind_method(D_METHOD("get_sidechain"), &AudioEffectCompressor::get_sidechain);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "treshold", PROPERTY_HINT_RANGE, "-60,0,0.1"), "set_treshold", "get_treshold");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "ratio", PROPERTY_HINT_RANGE, "1,48,0.1"), "set_ratio", "get_ratio");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gain", PROPERTY_HINT_RANGE, "-20,20,0.1"), "set_gain", "get_gain");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "attack_us", PROPERTY_HINT_RANGE, "20,2000,1"), "set_attack_us", "get_attack_us");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "release_ms", PROPERTY_HINT_RANGE, "20,2000,1"), "set_release_ms", "get_release_ms");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "mix", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_mix", "get_mix");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sidechain", PROPERTY_HINT_ENUM), "set_sidechain", "get_sidechain");
}
-AudioEffectCompressor::AudioEffectCompressor()
-{
- treshold=0;
- ratio=4;
- gain=0;
- attack_us=20;
- release_ms=250;
- mix=1;
+AudioEffectCompressor::AudioEffectCompressor() {
+ treshold = 0;
+ ratio = 4;
+ gain = 0;
+ attack_us = 20;
+ release_ms = 250;
+ mix = 1;
}
diff --git a/servers/audio/effects/audio_effect_compressor.h b/servers/audio/effects/audio_effect_compressor.h
index 3988ad152..34f80348d 100644
--- a/servers/audio/effects/audio_effect_compressor.h
+++ b/servers/audio/effects/audio_effect_compressor.h
@@ -29,30 +29,27 @@
#ifndef AUDIOEFFECTCOMPRESSOR_H
#define AUDIOEFFECTCOMPRESSOR_H
-
#include "servers/audio/audio_effect.h"
class AudioEffectCompressor;
class AudioEffectCompressorInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectCompressorInstance,AudioEffectInstance)
-friend class AudioEffectCompressor;
+ GDCLASS(AudioEffectCompressorInstance, AudioEffectInstance)
+ friend class AudioEffectCompressor;
Ref<AudioEffectCompressor> base;
- float rundb,averatio,runratio,runmax,maxover,gr_meter;
+ float rundb, averatio, runratio, runmax, maxover, gr_meter;
int current_channel;
-public:
-
- void set_current_channel(int p_channel) { current_channel=p_channel; }
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+public:
+ void set_current_channel(int p_channel) { current_channel = p_channel; }
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectCompressor : public AudioEffect {
- GDCLASS(AudioEffectCompressor,AudioEffect)
+ GDCLASS(AudioEffectCompressor, AudioEffect)
-friend class AudioEffectCompressorInstance;
+ friend class AudioEffectCompressorInstance;
float treshold;
float ratio;
float gain;
@@ -61,16 +58,13 @@ friend class AudioEffectCompressorInstance;
float mix;
StringName sidechain;
-
protected:
- void _validate_property(PropertyInfo& property) const;
+ void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
-
void set_treshold(float p_treshold);
float get_treshold() const;
@@ -89,7 +83,7 @@ public:
void set_mix(float p_mix);
float get_mix() const;
- void set_sidechain(const StringName& p_sidechain);
+ void set_sidechain(const StringName &p_sidechain);
StringName get_sidechain() const;
AudioEffectCompressor();
diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp
index a6d204889..b643f801a 100644
--- a/servers/audio/effects/audio_effect_delay.cpp
+++ b/servers/audio/effects/audio_effect_delay.cpp
@@ -27,328 +27,315 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "audio_effect_delay.h"
-#include "servers/audio_server.h"
#include "math_funcs.h"
+#include "servers/audio_server.h"
-void AudioEffectDelayInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectDelayInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
int todo = p_frame_count;
- while(todo) {
+ while (todo) {
- int to_mix = MIN(todo,256); //can't mix too much
+ int to_mix = MIN(todo, 256); //can't mix too much
- _process_chunk(p_src_frames,p_dst_frames,to_mix);
+ _process_chunk(p_src_frames, p_dst_frames, to_mix);
- p_src_frames+=to_mix;
- p_dst_frames+=to_mix;
+ p_src_frames += to_mix;
+ p_dst_frames += to_mix;
- todo-=to_mix;
+ todo -= to_mix;
}
}
-void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
-
-
-
- float main_level_f=base->dry;
+void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
+ float main_level_f = base->dry;
float mix_rate = AudioServer::get_singleton()->get_mix_rate();
- float tap_1_level_f=base->tap_1_active?Math::db2linear(base->tap_1_level):0.0;
- int tap_1_delay_frames=int((base->tap_1_delay_ms/1000.0)*mix_rate);;
+ float tap_1_level_f = base->tap_1_active ? Math::db2linear(base->tap_1_level) : 0.0;
+ int tap_1_delay_frames = int((base->tap_1_delay_ms / 1000.0) * mix_rate);
+ ;
- float tap_2_level_f=base->tap_2_active?Math::db2linear(base->tap_2_level):0.0;
- int tap_2_delay_frames=int((base->tap_2_delay_ms/1000.0)*mix_rate);;
+ float tap_2_level_f = base->tap_2_active ? Math::db2linear(base->tap_2_level) : 0.0;
+ int tap_2_delay_frames = int((base->tap_2_delay_ms / 1000.0) * mix_rate);
+ ;
- float feedback_level_f=base->feedback_active?Math::db2linear(base->feedback_level):0.0;
- unsigned int feedback_delay_frames=int((base->feedback_delay_ms/1000.0)*mix_rate);;
+ float feedback_level_f = base->feedback_active ? Math::db2linear(base->feedback_level) : 0.0;
+ unsigned int feedback_delay_frames = int((base->feedback_delay_ms / 1000.0) * mix_rate);
+ ;
+ AudioFrame tap1_vol = AudioFrame(tap_1_level_f, tap_1_level_f);
- AudioFrame tap1_vol=AudioFrame(tap_1_level_f,tap_1_level_f);
+ tap1_vol.l *= CLAMP(1.0 - base->tap_1_pan, 0, 1);
+ tap1_vol.r *= CLAMP(1.0 + base->tap_1_pan, 0, 1);
- tap1_vol.l*=CLAMP( 1.0 - base->tap_1_pan, 0, 1);
- tap1_vol.r*=CLAMP( 1.0 + base->tap_1_pan, 0, 1);
+ AudioFrame tap2_vol = AudioFrame(tap_2_level_f, tap_2_level_f);
- AudioFrame tap2_vol=AudioFrame(tap_2_level_f,tap_2_level_f);
-
- tap2_vol.l*=CLAMP( 1.0 - base->tap_2_pan, 0, 1);
- tap2_vol.r*=CLAMP( 1.0 + base->tap_2_pan, 0, 1);
+ tap2_vol.l *= CLAMP(1.0 - base->tap_2_pan, 0, 1);
+ tap2_vol.r *= CLAMP(1.0 + base->tap_2_pan, 0, 1);
// feedback lowpass here
- float lpf_c=expf(-2.0*Math_PI*base->feedback_lowpass/mix_rate); // 0 .. 10khz
- float lpf_ic=1.0-lpf_c;
-
- const AudioFrame *src=p_src_frames;
- AudioFrame *dst=p_dst_frames;
- AudioFrame *rb_buf=ring_buffer.ptr();
- AudioFrame *fb_buf=feedback_buffer.ptr();
+ float lpf_c = expf(-2.0 * Math_PI * base->feedback_lowpass / mix_rate); // 0 .. 10khz
+ float lpf_ic = 1.0 - lpf_c;
+ const AudioFrame *src = p_src_frames;
+ AudioFrame *dst = p_dst_frames;
+ AudioFrame *rb_buf = ring_buffer.ptr();
+ AudioFrame *fb_buf = feedback_buffer.ptr();
- for (int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
+ rb_buf[ring_buffer_pos & ring_buffer_mask] = src[i];
- rb_buf[ring_buffer_pos&ring_buffer_mask]=src[i];
+ AudioFrame main_val = src[i] * main_level_f;
+ AudioFrame tap_1_val = rb_buf[(ring_buffer_pos - tap_1_delay_frames) & ring_buffer_mask] * tap1_vol;
+ AudioFrame tap_2_val = rb_buf[(ring_buffer_pos - tap_2_delay_frames) & ring_buffer_mask] * tap2_vol;
- AudioFrame main_val=src[i]*main_level_f;
- AudioFrame tap_1_val=rb_buf[(ring_buffer_pos-tap_1_delay_frames)&ring_buffer_mask]*tap1_vol;
- AudioFrame tap_2_val=rb_buf[(ring_buffer_pos-tap_2_delay_frames)&ring_buffer_mask]*tap2_vol;
+ AudioFrame out = main_val + tap_1_val + tap_2_val;
- AudioFrame out=main_val+tap_1_val+tap_2_val;
-
- out+=fb_buf[ feedback_buffer_pos ];
+ out += fb_buf[feedback_buffer_pos];
//apply lowpass and feedback gain
- AudioFrame fb_in=out*feedback_level_f*lpf_ic+h*lpf_c;
+ AudioFrame fb_in = out * feedback_level_f * lpf_ic + h * lpf_c;
fb_in.undenormalise(); //avoid denormals
- h=fb_in;
- fb_buf[ feedback_buffer_pos ]=fb_in;
+ h = fb_in;
+ fb_buf[feedback_buffer_pos] = fb_in;
- dst[i]=out;
+ dst[i] = out;
ring_buffer_pos++;
- if ( (++feedback_buffer_pos) >= feedback_delay_frames )
- feedback_buffer_pos=0;
+ if ((++feedback_buffer_pos) >= feedback_delay_frames)
+ feedback_buffer_pos = 0;
}
}
-
-
Ref<AudioEffectInstance> AudioEffectDelay::instance() {
Ref<AudioEffectDelayInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectDelay>(this);
+ ins->base = Ref<AudioEffectDelay>(this);
- float ring_buffer_max_size=MAX_DELAY_MS+100; //add 100ms of extra room, just in case
- ring_buffer_max_size/=1000.0;//convert to seconds
- ring_buffer_max_size*=AudioServer::get_singleton()->get_mix_rate();
+ float ring_buffer_max_size = MAX_DELAY_MS + 100; //add 100ms of extra room, just in case
+ ring_buffer_max_size /= 1000.0; //convert to seconds
+ ring_buffer_max_size *= AudioServer::get_singleton()->get_mix_rate();
- int ringbuff_size=ring_buffer_max_size;
+ int ringbuff_size = ring_buffer_max_size;
- int bits=0;
+ int bits = 0;
- while(ringbuff_size>0) {
+ while (ringbuff_size > 0) {
bits++;
- ringbuff_size/=2;
+ ringbuff_size /= 2;
}
- ringbuff_size=1<<bits;
- ins->ring_buffer_mask=ringbuff_size-1;
- ins->ring_buffer_pos=0;
+ ringbuff_size = 1 << bits;
+ ins->ring_buffer_mask = ringbuff_size - 1;
+ ins->ring_buffer_pos = 0;
- ins->ring_buffer.resize( ringbuff_size );
- ins->feedback_buffer.resize( ringbuff_size );
+ ins->ring_buffer.resize(ringbuff_size);
+ ins->feedback_buffer.resize(ringbuff_size);
- ins->feedback_buffer_pos=0;
+ ins->feedback_buffer_pos = 0;
- ins->h=AudioFrame(0,0);
+ ins->h = AudioFrame(0, 0);
return ins;
}
-
void AudioEffectDelay::set_dry(float p_dry) {
- dry=p_dry;
+ dry = p_dry;
}
-float AudioEffectDelay::get_dry(){
+float AudioEffectDelay::get_dry() {
return dry;
}
-void AudioEffectDelay::set_tap1_active(bool p_active){
+void AudioEffectDelay::set_tap1_active(bool p_active) {
- tap_1_active=p_active;
+ tap_1_active = p_active;
}
-bool AudioEffectDelay::is_tap1_active() const{
+bool AudioEffectDelay::is_tap1_active() const {
return tap_1_active;
}
-void AudioEffectDelay::set_tap1_delay_ms(float p_delay_ms){
+void AudioEffectDelay::set_tap1_delay_ms(float p_delay_ms) {
- tap_1_delay_ms=p_delay_ms;
+ tap_1_delay_ms = p_delay_ms;
}
-float AudioEffectDelay::get_tap1_delay_ms() const{
+float AudioEffectDelay::get_tap1_delay_ms() const {
return tap_1_delay_ms;
}
-void AudioEffectDelay::set_tap1_level_db(float p_level_db){
+void AudioEffectDelay::set_tap1_level_db(float p_level_db) {
- tap_1_level=p_level_db;
+ tap_1_level = p_level_db;
}
-float AudioEffectDelay::get_tap1_level_db() const{
+float AudioEffectDelay::get_tap1_level_db() const {
return tap_1_level;
}
-void AudioEffectDelay::set_tap1_pan(float p_pan){
+void AudioEffectDelay::set_tap1_pan(float p_pan) {
- tap_1_pan=p_pan;
+ tap_1_pan = p_pan;
}
-float AudioEffectDelay::get_tap1_pan() const{
+float AudioEffectDelay::get_tap1_pan() const {
return tap_1_pan;
}
+void AudioEffectDelay::set_tap2_active(bool p_active) {
-void AudioEffectDelay::set_tap2_active(bool p_active){
-
- tap_2_active=p_active;
+ tap_2_active = p_active;
}
-bool AudioEffectDelay::is_tap2_active() const{
+bool AudioEffectDelay::is_tap2_active() const {
return tap_2_active;
}
-void AudioEffectDelay::set_tap2_delay_ms(float p_delay_ms){
+void AudioEffectDelay::set_tap2_delay_ms(float p_delay_ms) {
- tap_2_delay_ms=p_delay_ms;
+ tap_2_delay_ms = p_delay_ms;
}
-float AudioEffectDelay::get_tap2_delay_ms() const{
+float AudioEffectDelay::get_tap2_delay_ms() const {
return tap_2_delay_ms;
}
-void AudioEffectDelay::set_tap2_level_db(float p_level_db){
+void AudioEffectDelay::set_tap2_level_db(float p_level_db) {
- tap_2_level=p_level_db;
+ tap_2_level = p_level_db;
}
-float AudioEffectDelay::get_tap2_level_db() const{
+float AudioEffectDelay::get_tap2_level_db() const {
return tap_2_level;
}
-void AudioEffectDelay::set_tap2_pan(float p_pan){
+void AudioEffectDelay::set_tap2_pan(float p_pan) {
- tap_2_pan=p_pan;
+ tap_2_pan = p_pan;
}
-float AudioEffectDelay::get_tap2_pan() const{
+float AudioEffectDelay::get_tap2_pan() const {
return tap_2_pan;
}
-void AudioEffectDelay::set_feedback_active(bool p_active){
+void AudioEffectDelay::set_feedback_active(bool p_active) {
- feedback_active=p_active;
+ feedback_active = p_active;
}
-bool AudioEffectDelay::is_feedback_active() const{
+bool AudioEffectDelay::is_feedback_active() const {
return feedback_active;
}
-void AudioEffectDelay::set_feedback_delay_ms(float p_delay_ms){
+void AudioEffectDelay::set_feedback_delay_ms(float p_delay_ms) {
- feedback_delay_ms=p_delay_ms;
+ feedback_delay_ms = p_delay_ms;
}
-float AudioEffectDelay::get_feedback_delay_ms() const{
+float AudioEffectDelay::get_feedback_delay_ms() const {
return feedback_delay_ms;
}
-void AudioEffectDelay::set_feedback_level_db(float p_level_db){
+void AudioEffectDelay::set_feedback_level_db(float p_level_db) {
- feedback_level=p_level_db;
+ feedback_level = p_level_db;
}
-float AudioEffectDelay::get_feedback_level_db() const{
+float AudioEffectDelay::get_feedback_level_db() const {
return feedback_level;
}
-void AudioEffectDelay::set_feedback_lowpass(float p_lowpass){
+void AudioEffectDelay::set_feedback_lowpass(float p_lowpass) {
- feedback_lowpass=p_lowpass;
+ feedback_lowpass = p_lowpass;
}
-float AudioEffectDelay::get_feedback_lowpass() const{
+float AudioEffectDelay::get_feedback_lowpass() const {
return feedback_lowpass;
}
-
void AudioEffectDelay::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_dry","amount"),&AudioEffectDelay::set_dry);
- ClassDB::bind_method(D_METHOD("get_dry"),&AudioEffectDelay::get_dry);
+ ClassDB::bind_method(D_METHOD("set_dry", "amount"), &AudioEffectDelay::set_dry);
+ ClassDB::bind_method(D_METHOD("get_dry"), &AudioEffectDelay::get_dry);
- ClassDB::bind_method(D_METHOD("set_tap1_active","amount"),&AudioEffectDelay::set_tap1_active);
- ClassDB::bind_method(D_METHOD("is_tap1_active"),&AudioEffectDelay::is_tap1_active);
+ ClassDB::bind_method(D_METHOD("set_tap1_active", "amount"), &AudioEffectDelay::set_tap1_active);
+ ClassDB::bind_method(D_METHOD("is_tap1_active"), &AudioEffectDelay::is_tap1_active);
- ClassDB::bind_method(D_METHOD("set_tap1_delay_ms","amount"),&AudioEffectDelay::set_tap1_delay_ms);
- ClassDB::bind_method(D_METHOD("get_tap1_delay_ms"),&AudioEffectDelay::get_tap1_delay_ms);
+ ClassDB::bind_method(D_METHOD("set_tap1_delay_ms", "amount"), &AudioEffectDelay::set_tap1_delay_ms);
+ ClassDB::bind_method(D_METHOD("get_tap1_delay_ms"), &AudioEffectDelay::get_tap1_delay_ms);
- ClassDB::bind_method(D_METHOD("set_tap1_level_db","amount"),&AudioEffectDelay::set_tap1_level_db);
- ClassDB::bind_method(D_METHOD("get_tap1_level_db"),&AudioEffectDelay::get_tap1_level_db);
+ ClassDB::bind_method(D_METHOD("set_tap1_level_db", "amount"), &AudioEffectDelay::set_tap1_level_db);
+ ClassDB::bind_method(D_METHOD("get_tap1_level_db"), &AudioEffectDelay::get_tap1_level_db);
- ClassDB::bind_method(D_METHOD("set_tap1_pan","amount"),&AudioEffectDelay::set_tap1_pan);
- ClassDB::bind_method(D_METHOD("get_tap1_pan"),&AudioEffectDelay::get_tap1_pan);
+ ClassDB::bind_method(D_METHOD("set_tap1_pan", "amount"), &AudioEffectDelay::set_tap1_pan);
+ ClassDB::bind_method(D_METHOD("get_tap1_pan"), &AudioEffectDelay::get_tap1_pan);
- ClassDB::bind_method(D_METHOD("set_tap2_active","amount"),&AudioEffectDelay::set_tap2_active);
- ClassDB::bind_method(D_METHOD("is_tap2_active"),&AudioEffectDelay::is_tap2_active);
+ ClassDB::bind_method(D_METHOD("set_tap2_active", "amount"), &AudioEffectDelay::set_tap2_active);
+ ClassDB::bind_method(D_METHOD("is_tap2_active"), &AudioEffectDelay::is_tap2_active);
- ClassDB::bind_method(D_METHOD("set_tap2_delay_ms","amount"),&AudioEffectDelay::set_tap2_delay_ms);
- ClassDB::bind_method(D_METHOD("get_tap2_delay_ms"),&AudioEffectDelay::get_tap2_delay_ms);
+ ClassDB::bind_method(D_METHOD("set_tap2_delay_ms", "amount"), &AudioEffectDelay::set_tap2_delay_ms);
+ ClassDB::bind_method(D_METHOD("get_tap2_delay_ms"), &AudioEffectDelay::get_tap2_delay_ms);
- ClassDB::bind_method(D_METHOD("set_tap2_level_db","amount"),&AudioEffectDelay::set_tap2_level_db);
- ClassDB::bind_method(D_METHOD("get_tap2_level_db"),&AudioEffectDelay::get_tap2_level_db);
+ ClassDB::bind_method(D_METHOD("set_tap2_level_db", "amount"), &AudioEffectDelay::set_tap2_level_db);
+ ClassDB::bind_method(D_METHOD("get_tap2_level_db"), &AudioEffectDelay::get_tap2_level_db);
- ClassDB::bind_method(D_METHOD("set_tap2_pan","amount"),&AudioEffectDelay::set_tap2_pan);
- ClassDB::bind_method(D_METHOD("get_tap2_pan"),&AudioEffectDelay::get_tap2_pan);
+ ClassDB::bind_method(D_METHOD("set_tap2_pan", "amount"), &AudioEffectDelay::set_tap2_pan);
+ ClassDB::bind_method(D_METHOD("get_tap2_pan"), &AudioEffectDelay::get_tap2_pan);
+ ClassDB::bind_method(D_METHOD("set_feedback_active", "amount"), &AudioEffectDelay::set_feedback_active);
+ ClassDB::bind_method(D_METHOD("is_feedback_active"), &AudioEffectDelay::is_feedback_active);
- ClassDB::bind_method(D_METHOD("set_feedback_active","amount"),&AudioEffectDelay::set_feedback_active);
- ClassDB::bind_method(D_METHOD("is_feedback_active"),&AudioEffectDelay::is_feedback_active);
+ ClassDB::bind_method(D_METHOD("set_feedback_delay_ms", "amount"), &AudioEffectDelay::set_feedback_delay_ms);
+ ClassDB::bind_method(D_METHOD("get_feedback_delay_ms"), &AudioEffectDelay::get_feedback_delay_ms);
- ClassDB::bind_method(D_METHOD("set_feedback_delay_ms","amount"),&AudioEffectDelay::set_feedback_delay_ms);
- ClassDB::bind_method(D_METHOD("get_feedback_delay_ms"),&AudioEffectDelay::get_feedback_delay_ms);
+ ClassDB::bind_method(D_METHOD("set_feedback_level_db", "amount"), &AudioEffectDelay::set_feedback_level_db);
+ ClassDB::bind_method(D_METHOD("get_feedback_level_db"), &AudioEffectDelay::get_feedback_level_db);
- ClassDB::bind_method(D_METHOD("set_feedback_level_db","amount"),&AudioEffectDelay::set_feedback_level_db);
- ClassDB::bind_method(D_METHOD("get_feedback_level_db"),&AudioEffectDelay::get_feedback_level_db);
+ ClassDB::bind_method(D_METHOD("set_feedback_lowpass", "amount"), &AudioEffectDelay::set_feedback_lowpass);
+ ClassDB::bind_method(D_METHOD("get_feedback_lowpass"), &AudioEffectDelay::get_feedback_lowpass);
- ClassDB::bind_method(D_METHOD("set_feedback_lowpass","amount"),&AudioEffectDelay::set_feedback_lowpass);
- ClassDB::bind_method(D_METHOD("get_feedback_lowpass"),&AudioEffectDelay::get_feedback_lowpass);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "dry", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dry", "get_dry");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"dry",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_dry","get_dry");
-
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"tap1/active"),"set_tap1_active","is_tap1_active");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap1/delay_ms",PROPERTY_HINT_RANGE,"0,1500,1"),"set_tap1_delay_ms","get_tap1_delay_ms");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap1/level_db",PROPERTY_HINT_RANGE,"-60,0,0.01"),"set_tap1_level_db","get_tap1_level_db");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap1/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_tap1_pan","get_tap1_pan");
-
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"tap2/active"),"set_tap2_active","is_tap2_active");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap2/delay_ms",PROPERTY_HINT_RANGE,"0,1500,1"),"set_tap2_delay_ms","get_tap2_delay_ms");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap2/level_db",PROPERTY_HINT_RANGE,"-60,0,0.01"),"set_tap2_level_db","get_tap2_level_db");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap2/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_tap2_pan","get_tap2_pan");
-
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"feedback/active"),"set_feedback_active","is_feedback_active");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback/delay_ms",PROPERTY_HINT_RANGE,"0,1500,1"),"set_feedback_delay_ms","get_feedback_delay_ms");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback/level_db",PROPERTY_HINT_RANGE,"-60,0,0.01"),"set_feedback_level_db","get_feedback_level_db");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback/lowpass",PROPERTY_HINT_RANGE,"1,16000,1"),"set_feedback_lowpass","get_feedback_lowpass");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tap1/active"), "set_tap1_active", "is_tap1_active");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tap1/delay_ms", PROPERTY_HINT_RANGE, "0,1500,1"), "set_tap1_delay_ms", "get_tap1_delay_ms");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tap1/level_db", PROPERTY_HINT_RANGE, "-60,0,0.01"), "set_tap1_level_db", "get_tap1_level_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tap1/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_tap1_pan", "get_tap1_pan");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tap2/active"), "set_tap2_active", "is_tap2_active");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tap2/delay_ms", PROPERTY_HINT_RANGE, "0,1500,1"), "set_tap2_delay_ms", "get_tap2_delay_ms");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tap2/level_db", PROPERTY_HINT_RANGE, "-60,0,0.01"), "set_tap2_level_db", "get_tap2_level_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tap2/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_tap2_pan", "get_tap2_pan");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "feedback/active"), "set_feedback_active", "is_feedback_active");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "feedback/delay_ms", PROPERTY_HINT_RANGE, "0,1500,1"), "set_feedback_delay_ms", "get_feedback_delay_ms");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "feedback/level_db", PROPERTY_HINT_RANGE, "-60,0,0.01"), "set_feedback_level_db", "get_feedback_level_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "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;
+AudioEffectDelay::AudioEffectDelay() {
+ tap_1_active = true;
+ tap_1_delay_ms = 250;
+ tap_1_level = -6;
+ tap_1_pan = 0.2;
- feedback_active=false;
- feedback_delay_ms=340;
- feedback_level=-6;
- feedback_lowpass=16000;
+ tap_2_active = true;
+ tap_2_delay_ms = 500;
+ tap_2_level = -12;
+ tap_2_pan = -0.4;
- dry=1.0;
+ feedback_active = false;
+ feedback_delay_ms = 340;
+ feedback_level = -6;
+ feedback_lowpass = 16000;
+ dry = 1.0;
}
diff --git a/servers/audio/effects/audio_effect_delay.h b/servers/audio/effects/audio_effect_delay.h
index 3e9f7f058..247fddac0 100644
--- a/servers/audio/effects/audio_effect_delay.h
+++ b/servers/audio/effects/audio_effect_delay.h
@@ -34,8 +34,8 @@
class AudioEffectDelay;
class AudioEffectDelayInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectDelayInstance,AudioEffectInstance)
-friend class AudioEffectDelay;
+ GDCLASS(AudioEffectDelayInstance, AudioEffectInstance)
+ friend class AudioEffectDelay;
Ref<AudioEffectDelay> base;
Vector<AudioFrame> ring_buffer;
@@ -49,23 +49,20 @@ friend class AudioEffectDelay;
unsigned int feedback_buffer_pos;
AudioFrame h;
- void _process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+ void _process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
-
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectDelay : public AudioEffect {
- GDCLASS(AudioEffectDelay,AudioEffect)
+ GDCLASS(AudioEffectDelay, AudioEffect)
-friend class AudioEffectDelayInstance;
+ friend class AudioEffectDelayInstance;
enum {
- MAX_DELAY_MS=3000,
- MAX_TAPS=2
+ MAX_DELAY_MS = 3000,
+ MAX_TAPS = 2
};
float dry;
@@ -85,13 +82,10 @@ friend class AudioEffectDelayInstance;
float feedback_level;
float feedback_lowpass;
-
-
protected:
-
static void _bind_methods();
-public:
+public:
void set_dry(float p_dry);
float get_dry();
@@ -136,5 +130,4 @@ public:
AudioEffectDelay();
};
-
#endif // AUDIOEFFECTDELAY_H
diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp
index b72cd8e0a..e5430fcd2 100644
--- a/servers/audio/effects/audio_effect_distortion.cpp
+++ b/servers/audio/effects/audio_effect_distortion.cpp
@@ -27,173 +27,159 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "audio_effect_distortion.h"
-#include "servers/audio_server.h"
#include "math_funcs.h"
+#include "servers/audio_server.h"
+void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
-
-void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
-
- const float *src = (const float*)p_src_frames;
- float *dst = (float*)p_dst_frames;
+ const float *src = (const float *)p_src_frames;
+ float *dst = (float *)p_dst_frames;
//float lpf_c=expf(-2.0*Math_PI*keep_hf_hz.get()/(mix_rate*(float)OVERSAMPLE));
- float lpf_c=expf(-2.0*Math_PI*base->keep_hf_hz/(AudioServer::get_singleton()->get_mix_rate()));
- float lpf_ic=1.0-lpf_c;
+ float lpf_c = expf(-2.0 * Math_PI * base->keep_hf_hz / (AudioServer::get_singleton()->get_mix_rate()));
+ float lpf_ic = 1.0 - lpf_c;
- float drive_f=base->drive;
- float pregain_f=Math::db2linear(base->pre_gain);
- float postgain_f=Math::db2linear(base->post_gain);
+ float drive_f = base->drive;
+ float pregain_f = Math::db2linear(base->pre_gain);
+ float postgain_f = Math::db2linear(base->post_gain);
- float atan_mult=pow(10,drive_f*drive_f*3.0)-1.0+0.001;
- float atan_div=1.0/(atanf(atan_mult)*(1.0+drive_f*8));
+ float atan_mult = pow(10, drive_f * drive_f * 3.0) - 1.0 + 0.001;
+ float atan_div = 1.0 / (atanf(atan_mult) * (1.0 + drive_f * 8));
- float lofi_mult=powf(2.0,2.0+(1.0-drive_f)*14); //goes from 16 to 2 bits
+ float lofi_mult = powf(2.0, 2.0 + (1.0 - drive_f) * 14); //goes from 16 to 2 bits
- for (int i=0;i<p_frame_count*2;i++) {
+ for (int i = 0; i < p_frame_count * 2; i++) {
- float out=undenormalise(src[i]*lpf_ic+lpf_c*h[i&1]);
- h[i&1]=out;
- float a=out;
- float ha=src[i]-out; //high freqs
- a*=pregain_f;
+ float out = undenormalise(src[i] * lpf_ic + lpf_c * h[i & 1]);
+ h[i & 1] = out;
+ float a = out;
+ float ha = src[i] - out; //high freqs
+ a *= pregain_f;
switch (base->mode) {
case AudioEffectDistortion::MODE_CLIP: {
- a=powf(a,1.0001-drive_f);
- if (a>1.0)
- a=1.0;
- else if (a<(-1.0))
- a=-1.0;
+ a = powf(a, 1.0001 - drive_f);
+ if (a > 1.0)
+ a = 1.0;
+ else if (a < (-1.0))
+ a = -1.0;
} break;
case AudioEffectDistortion::MODE_ATAN: {
-
- a=atanf(a*atan_mult)*atan_div;
+ a = atanf(a * atan_mult) * atan_div;
} break;
case AudioEffectDistortion::MODE_LOFI: {
- a = floorf(a*lofi_mult+0.5)/lofi_mult;
+ a = floorf(a * lofi_mult + 0.5) / lofi_mult;
} break;
case AudioEffectDistortion::MODE_OVERDRIVE: {
-
const double x = a * 0.686306;
- const double z = 1 + exp (sqrt (fabs (x)) * -0.75);
+ const double z = 1 + exp(sqrt(fabs(x)) * -0.75);
a = (expf(x) - expf(-x * z)) / (expf(x) + expf(-x));
} break;
case AudioEffectDistortion::MODE_WAVESHAPE: {
float x = a;
- float k= 2*drive_f/(1.00001-drive_f);
-
- a = (1.0+k)*x/(1.0+k*fabsf(x));
+ float k = 2 * drive_f / (1.00001 - drive_f);
+ a = (1.0 + k) * x / (1.0 + k * fabsf(x));
} break;
}
- dst[i]=a*postgain_f+ha;
-
+ dst[i] = a * postgain_f + ha;
}
-
-
}
-
Ref<AudioEffectInstance> AudioEffectDistortion::instance() {
Ref<AudioEffectDistortionInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectDistortion>(this);
- ins->h[0]=0;
- ins->h[1]=0;
+ ins->base = Ref<AudioEffectDistortion>(this);
+ ins->h[0] = 0;
+ ins->h[1] = 0;
return ins;
}
-
void AudioEffectDistortion::set_mode(Mode p_mode) {
- mode=p_mode;
+ mode = p_mode;
}
-AudioEffectDistortion::Mode AudioEffectDistortion::get_mode() const{
+AudioEffectDistortion::Mode AudioEffectDistortion::get_mode() const {
return mode;
}
-void AudioEffectDistortion::set_pre_gain(float p_pre_gain){
+void AudioEffectDistortion::set_pre_gain(float p_pre_gain) {
- pre_gain=p_pre_gain;
+ pre_gain = p_pre_gain;
}
-float AudioEffectDistortion::get_pre_gain() const{
+float AudioEffectDistortion::get_pre_gain() const {
return pre_gain;
}
-void AudioEffectDistortion::set_keep_hf_hz(float p_keep_hf_hz){
+void AudioEffectDistortion::set_keep_hf_hz(float p_keep_hf_hz) {
- keep_hf_hz=p_keep_hf_hz;
+ keep_hf_hz = p_keep_hf_hz;
}
-float AudioEffectDistortion::get_keep_hf_hz() const{
+float AudioEffectDistortion::get_keep_hf_hz() const {
return keep_hf_hz;
}
-void AudioEffectDistortion::set_drive(float p_drive){
+void AudioEffectDistortion::set_drive(float p_drive) {
- drive=p_drive;
+ drive = p_drive;
}
-float AudioEffectDistortion::get_drive() const{
+float AudioEffectDistortion::get_drive() const {
return drive;
}
-void AudioEffectDistortion::set_post_gain(float p_post_gain){
+void AudioEffectDistortion::set_post_gain(float p_post_gain) {
- post_gain=p_post_gain;
+ post_gain = p_post_gain;
}
-float AudioEffectDistortion::get_post_gain() const{
+float AudioEffectDistortion::get_post_gain() const {
return post_gain;
}
-
void AudioEffectDistortion::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_mode","mode"),&AudioEffectDistortion::set_mode);
- ClassDB::bind_method(D_METHOD("get_mode"),&AudioEffectDistortion::get_mode);
-
- ClassDB::bind_method(D_METHOD("set_pre_gain","pre_gain"),&AudioEffectDistortion::set_pre_gain);
- ClassDB::bind_method(D_METHOD("get_pre_gain"),&AudioEffectDistortion::get_pre_gain);
+ ClassDB::bind_method(D_METHOD("set_mode", "mode"), &AudioEffectDistortion::set_mode);
+ ClassDB::bind_method(D_METHOD("get_mode"), &AudioEffectDistortion::get_mode);
- ClassDB::bind_method(D_METHOD("set_keep_hf_hz","keep_hf_hz"),&AudioEffectDistortion::set_keep_hf_hz);
- ClassDB::bind_method(D_METHOD("get_keep_hf_hz"),&AudioEffectDistortion::get_keep_hf_hz);
+ ClassDB::bind_method(D_METHOD("set_pre_gain", "pre_gain"), &AudioEffectDistortion::set_pre_gain);
+ ClassDB::bind_method(D_METHOD("get_pre_gain"), &AudioEffectDistortion::get_pre_gain);
- ClassDB::bind_method(D_METHOD("set_drive","drive"),&AudioEffectDistortion::set_drive);
- ClassDB::bind_method(D_METHOD("get_drive"),&AudioEffectDistortion::get_drive);
+ ClassDB::bind_method(D_METHOD("set_keep_hf_hz", "keep_hf_hz"), &AudioEffectDistortion::set_keep_hf_hz);
+ ClassDB::bind_method(D_METHOD("get_keep_hf_hz"), &AudioEffectDistortion::get_keep_hf_hz);
+ ClassDB::bind_method(D_METHOD("set_drive", "drive"), &AudioEffectDistortion::set_drive);
+ ClassDB::bind_method(D_METHOD("get_drive"), &AudioEffectDistortion::get_drive);
- ClassDB::bind_method(D_METHOD("set_post_gain","post_gain"),&AudioEffectDistortion::set_post_gain);
- ClassDB::bind_method(D_METHOD("get_post_gain"),&AudioEffectDistortion::get_post_gain);
+ ClassDB::bind_method(D_METHOD("set_post_gain", "post_gain"), &AudioEffectDistortion::set_post_gain);
+ ClassDB::bind_method(D_METHOD("get_post_gain"), &AudioEffectDistortion::get_post_gain);
- ADD_PROPERTY(PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Clip,ATan,LoFi,Overdrive,WaveShape"),"set_mode","get_mode");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"pre_gain",PROPERTY_HINT_RANGE,"-60,60,0.01"),"set_pre_gain","get_pre_gain");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"keep_hf_hz",PROPERTY_HINT_RANGE,"1,20000,1"),"set_keep_hf_hz","get_keep_hf_hz");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"drive",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_drive","get_drive");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"post_gain",PROPERTY_HINT_RANGE,"-80,24,0.01"),"set_post_gain","get_post_gain");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Clip,ATan,LoFi,Overdrive,WaveShape"), "set_mode", "get_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pre_gain", PROPERTY_HINT_RANGE, "-60,60,0.01"), "set_pre_gain", "get_pre_gain");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "keep_hf_hz", PROPERTY_HINT_RANGE, "1,20000,1"), "set_keep_hf_hz", "get_keep_hf_hz");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "drive", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drive", "get_drive");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "post_gain", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_post_gain", "get_post_gain");
}
-AudioEffectDistortion::AudioEffectDistortion()
-{
- mode=MODE_CLIP;
- pre_gain=0;
- post_gain=0;
- keep_hf_hz=16000;
- drive=0;
+AudioEffectDistortion::AudioEffectDistortion() {
+ mode = MODE_CLIP;
+ pre_gain = 0;
+ post_gain = 0;
+ keep_hf_hz = 16000;
+ drive = 0;
}
-
diff --git a/servers/audio/effects/audio_effect_distortion.h b/servers/audio/effects/audio_effect_distortion.h
index c4388f025..6cd92dea1 100644
--- a/servers/audio/effects/audio_effect_distortion.h
+++ b/servers/audio/effects/audio_effect_distortion.h
@@ -34,19 +34,17 @@
class AudioEffectDistortion;
class AudioEffectDistortionInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectDistortionInstance,AudioEffectInstance)
-friend class AudioEffectDistortion;
+ GDCLASS(AudioEffectDistortionInstance, AudioEffectInstance)
+ friend class AudioEffectDistortion;
Ref<AudioEffectDistortion> base;
float h[2];
-public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+public:
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectDistortion : public AudioEffect {
- GDCLASS(AudioEffectDistortion,AudioEffect)
+ GDCLASS(AudioEffectDistortion, AudioEffect)
public:
enum Mode {
MODE_CLIP,
@@ -56,7 +54,7 @@ public:
MODE_WAVESHAPE,
};
-friend class AudioEffectDistortionInstance;
+ friend class AudioEffectDistortionInstance;
Mode mode;
float pre_gain;
float post_gain;
@@ -64,14 +62,11 @@ friend class AudioEffectDistortionInstance;
float drive;
protected:
-
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
-
void set_mode(Mode p_mode);
Mode get_mode() const;
@@ -87,11 +82,9 @@ public:
void set_post_gain(float post_gain);
float get_post_gain() const;
-
-
AudioEffectDistortion();
};
-VARIANT_ENUM_CAST( AudioEffectDistortion::Mode )
+VARIANT_ENUM_CAST(AudioEffectDistortion::Mode)
#endif // AUDIOEFFECTDISTORTION_H
diff --git a/servers/audio/effects/audio_effect_eq.cpp b/servers/audio/effects/audio_effect_eq.cpp
index 2caec9e49..a103d34d0 100644
--- a/servers/audio/effects/audio_effect_eq.cpp
+++ b/servers/audio/effects/audio_effect_eq.cpp
@@ -29,24 +29,22 @@
#include "audio_effect_eq.h"
#include "servers/audio_server.h"
-
-void AudioEffectEQInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectEQInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
int band_count = bands[0].size();
EQ::BandProcess *proc_l = bands[0].ptr();
EQ::BandProcess *proc_r = bands[1].ptr();
float *bgain = gains.ptr();
- for(int i=0;i<band_count;i++) {
- bgain[i]=Math::db2linear(base->gain[i]);
+ for (int i = 0; i < band_count; i++) {
+ bgain[i] = Math::db2linear(base->gain[i]);
}
-
- for(int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
AudioFrame src = p_src_frames[i];
- AudioFrame dst = AudioFrame(0,0);
+ AudioFrame dst = AudioFrame(0, 0);
- for(int j=0;j<band_count;j++) {
+ for (int j = 0; j < band_count; j++) {
float l = src.l;
float r = src.r;
@@ -54,38 +52,36 @@ void AudioEffectEQInstance::process(const AudioFrame *p_src_frames,AudioFrame *p
proc_l[j].process_one(l);
proc_r[j].process_one(r);
- dst.l+=l * bgain[j];
- dst.r+=r * bgain[j];
+ dst.l += l * bgain[j];
+ dst.r += r * bgain[j];
}
- p_dst_frames[i]=dst;
+ p_dst_frames[i] = dst;
}
-
}
-
Ref<AudioEffectInstance> AudioEffectEQ::instance() {
Ref<AudioEffectEQInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectEQ>(this);
+ ins->base = Ref<AudioEffectEQ>(this);
ins->gains.resize(eq.get_band_count());
- for(int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
ins->bands[i].resize(eq.get_band_count());
- for(int j=0;j<ins->bands[i].size();j++) {
- ins->bands[i][j]=eq.get_band_processor(j);
+ for (int j = 0; j < ins->bands[i].size(); j++) {
+ ins->bands[i][j] = eq.get_band_processor(j);
}
}
return ins;
}
-void AudioEffectEQ::set_band_gain_db(int p_band,float p_volume) {
- ERR_FAIL_INDEX(p_band,gain.size());
- gain[p_band]=p_volume;
+void AudioEffectEQ::set_band_gain_db(int p_band, float p_volume) {
+ ERR_FAIL_INDEX(p_band, gain.size());
+ gain[p_band] = p_volume;
}
float AudioEffectEQ::get_band_gain_db(int p_band) const {
- ERR_FAIL_INDEX_V(p_band,gain.size(),0);
+ ERR_FAIL_INDEX_V(p_band, gain.size(), 0);
return gain[p_band];
}
@@ -93,58 +89,52 @@ int AudioEffectEQ::get_band_count() const {
return gain.size();
}
-bool AudioEffectEQ::_set(const StringName& p_name, const Variant& p_value) {
+bool AudioEffectEQ::_set(const StringName &p_name, const Variant &p_value) {
- const Map<StringName,int>::Element *E=prop_band_map.find(p_name);
+ const Map<StringName, int>::Element *E = prop_band_map.find(p_name);
if (E) {
- set_band_gain_db(E->get(),p_value);
+ set_band_gain_db(E->get(), p_value);
return true;
}
return false;
}
-bool AudioEffectEQ::_get(const StringName& p_name,Variant &r_ret) const{
+bool AudioEffectEQ::_get(const StringName &p_name, Variant &r_ret) const {
- const Map<StringName,int>::Element *E=prop_band_map.find(p_name);
+ const Map<StringName, int>::Element *E = prop_band_map.find(p_name);
if (E) {
- r_ret=get_band_gain_db(E->get());
+ r_ret = get_band_gain_db(E->get());
return true;
}
return false;
-
}
-void AudioEffectEQ::_get_property_list( List<PropertyInfo> *p_list) const{
+void AudioEffectEQ::_get_property_list(List<PropertyInfo> *p_list) const {
- for(int i=0;i<band_names.size();i++) {
+ for (int i = 0; i < band_names.size(); i++) {
- p_list->push_back(PropertyInfo(Variant::REAL,band_names[i],PROPERTY_HINT_RANGE,"-60,24,0.1"));
+ p_list->push_back(PropertyInfo(Variant::REAL, band_names[i], PROPERTY_HINT_RANGE, "-60,24,0.1"));
}
}
-
-
void AudioEffectEQ::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_band_gain_db","band_idx","volume_db"),&AudioEffectEQ::set_band_gain_db);
- ClassDB::bind_method(D_METHOD("get_band_gain_db","band_idx"),&AudioEffectEQ::get_band_gain_db);
- ClassDB::bind_method(D_METHOD("get_band_count"),&AudioEffectEQ::get_band_count);
-
+ ClassDB::bind_method(D_METHOD("set_band_gain_db", "band_idx", "volume_db"), &AudioEffectEQ::set_band_gain_db);
+ ClassDB::bind_method(D_METHOD("get_band_gain_db", "band_idx"), &AudioEffectEQ::get_band_gain_db);
+ ClassDB::bind_method(D_METHOD("get_band_count"), &AudioEffectEQ::get_band_count);
}
-AudioEffectEQ::AudioEffectEQ(EQ::Preset p_preset)
-{
-
+AudioEffectEQ::AudioEffectEQ(EQ::Preset p_preset) {
eq.set_mix_rate(AudioServer::get_singleton()->get_mix_rate());
eq.set_preset_band_mode(p_preset);
gain.resize(eq.get_band_count());
- for(int i=0;i<gain.size();i++) {
- gain[i]=0.0;
- String name = "band_db/"+itos(eq.get_band_frequency(i))+"_hz";
- prop_band_map[name]=i;
+ for (int i = 0; i < gain.size(); i++) {
+ gain[i] = 0.0;
+ String name = "band_db/" + itos(eq.get_band_frequency(i)) + "_hz";
+ prop_band_map[name] = i;
band_names.push_back(name);
}
}
diff --git a/servers/audio/effects/audio_effect_eq.h b/servers/audio/effects/audio_effect_eq.h
index 2f577ffd2..917bf584c 100644
--- a/servers/audio/effects/audio_effect_eq.h
+++ b/servers/audio/effects/audio_effect_eq.h
@@ -29,72 +29,68 @@
#ifndef AUDIOEFFECTEQ_H
#define AUDIOEFFECTEQ_H
-
#include "servers/audio/audio_effect.h"
#include "servers/audio/effects/eq.h"
class AudioEffectEQ;
class AudioEffectEQInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectEQInstance,AudioEffectInstance)
-friend class AudioEffectEQ;
+ GDCLASS(AudioEffectEQInstance, AudioEffectInstance)
+ friend class AudioEffectEQ;
Ref<AudioEffectEQ> base;
Vector<EQ::BandProcess> bands[2];
Vector<float> gains;
-public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+public:
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectEQ : public AudioEffect {
- GDCLASS(AudioEffectEQ,AudioEffect)
+ GDCLASS(AudioEffectEQ, AudioEffect)
-friend class AudioEffectEQInstance;
+ friend class AudioEffectEQInstance;
EQ eq;
Vector<float> gain;
- Map<StringName,int> prop_band_map;
+ Map<StringName, int> prop_band_map;
Vector<String> band_names;
protected:
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
-
-
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
- void set_band_gain_db(int p_band,float p_volume);
+ void set_band_gain_db(int p_band, float p_volume);
float get_band_gain_db(int p_band) const;
int get_band_count() const;
- AudioEffectEQ(EQ::Preset p_preset=EQ::PRESET_6_BANDS);
+ AudioEffectEQ(EQ::Preset p_preset = EQ::PRESET_6_BANDS);
};
-
class AudioEffectEQ6 : public AudioEffectEQ {
- GDCLASS(AudioEffectEQ6,AudioEffectEQ)
+ GDCLASS(AudioEffectEQ6, AudioEffectEQ)
public:
- AudioEffectEQ6() : AudioEffectEQ(EQ::PRESET_6_BANDS) {}
+ AudioEffectEQ6()
+ : AudioEffectEQ(EQ::PRESET_6_BANDS) {}
};
class AudioEffectEQ10 : public AudioEffectEQ {
- GDCLASS(AudioEffectEQ10,AudioEffectEQ)
+ GDCLASS(AudioEffectEQ10, AudioEffectEQ)
public:
- AudioEffectEQ10() : AudioEffectEQ(EQ::PRESET_10_BANDS) {}
+ AudioEffectEQ10()
+ : AudioEffectEQ(EQ::PRESET_10_BANDS) {}
};
class AudioEffectEQ21 : public AudioEffectEQ {
- GDCLASS(AudioEffectEQ21,AudioEffectEQ)
+ GDCLASS(AudioEffectEQ21, AudioEffectEQ)
public:
- AudioEffectEQ21() : AudioEffectEQ(EQ::PRESET_21_BANDS) {}
+ AudioEffectEQ21()
+ : AudioEffectEQ(EQ::PRESET_21_BANDS) {}
};
#endif // AUDIOEFFECTEQ_H
diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp
index c85484294..4c158ce44 100644
--- a/servers/audio/effects/audio_effect_filter.cpp
+++ b/servers/audio/effects/audio_effect_filter.cpp
@@ -29,118 +29,110 @@
#include "audio_effect_filter.h"
#include "servers/audio_server.h"
-template<int S>
-void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+template <int S>
+void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
- for(int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
float f = p_src_frames[i].l;
filter_process[0][0].process_one(f);
- if (S>1)
+ if (S > 1)
filter_process[0][1].process_one(f);
- if (S>2)
+ if (S > 2)
filter_process[0][2].process_one(f);
- if (S>3)
+ if (S > 3)
filter_process[0][3].process_one(f);
- p_dst_frames[i].l=f;
+ p_dst_frames[i].l = f;
}
- for(int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
float f = p_src_frames[i].r;
filter_process[1][0].process_one(f);
- if (S>1)
+ if (S > 1)
filter_process[1][1].process_one(f);
- if (S>2)
+ if (S > 2)
filter_process[1][2].process_one(f);
- if (S>3)
+ if (S > 3)
filter_process[1][3].process_one(f);
- p_dst_frames[i].r=f;
+ p_dst_frames[i].r = f;
}
-
}
-void AudioEffectFilterInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectFilterInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
filter.set_cutoff(base->cutoff);
filter.set_gain(base->gain);
filter.set_resonance(base->resonance);
filter.set_mode(base->mode);
- int stages = int(base->db)+1;
+ int stages = int(base->db) + 1;
filter.set_stages(stages);
filter.set_sampling_rate(AudioServer::get_singleton()->get_mix_rate());
- for(int i=0;i<2;i++) {
- for(int j=0;j<4;j++) {
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 4; j++) {
filter_process[i][j].update_coeffs();
}
}
-
- if (stages==1) {
- _process_filter<1>(p_src_frames,p_dst_frames,p_frame_count);
- } else if (stages==2) {
- _process_filter<2>(p_src_frames,p_dst_frames,p_frame_count);
- } else if (stages==3) {
- _process_filter<3>(p_src_frames,p_dst_frames,p_frame_count);
- } else if (stages==4) {
- _process_filter<4>(p_src_frames,p_dst_frames,p_frame_count);
+ if (stages == 1) {
+ _process_filter<1>(p_src_frames, p_dst_frames, p_frame_count);
+ } else if (stages == 2) {
+ _process_filter<2>(p_src_frames, p_dst_frames, p_frame_count);
+ } else if (stages == 3) {
+ _process_filter<3>(p_src_frames, p_dst_frames, p_frame_count);
+ } else if (stages == 4) {
+ _process_filter<4>(p_src_frames, p_dst_frames, p_frame_count);
}
-
}
-
AudioEffectFilterInstance::AudioEffectFilterInstance() {
- for(int i=0;i<2;i++) {
- for(int j=0;j<4;j++) {
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 4; j++) {
filter_process[i][j].set_filter(&filter);
}
}
-
}
-
Ref<AudioEffectInstance> AudioEffectFilter::instance() {
Ref<AudioEffectFilterInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectFilter>(this);
+ ins->base = Ref<AudioEffectFilter>(this);
return ins;
}
void AudioEffectFilter::set_cutoff(float p_freq) {
- cutoff=p_freq;
+ cutoff = p_freq;
}
-float AudioEffectFilter::get_cutoff() const{
+float AudioEffectFilter::get_cutoff() const {
return cutoff;
}
-void AudioEffectFilter::set_resonance(float p_amount){
+void AudioEffectFilter::set_resonance(float p_amount) {
- resonance=p_amount;
+ resonance = p_amount;
}
-float AudioEffectFilter::get_resonance() const{
+float AudioEffectFilter::get_resonance() const {
return resonance;
}
-void AudioEffectFilter::set_gain(float p_amount){
+void AudioEffectFilter::set_gain(float p_amount) {
- gain=p_amount;
+ gain = p_amount;
}
float AudioEffectFilter::get_gain() const {
return gain;
}
-
-
void AudioEffectFilter::set_db(FilterDB p_db) {
- db=p_db;
+ db = p_db;
}
AudioEffectFilter::FilterDB AudioEffectFilter::get_db() const {
@@ -150,30 +142,29 @@ AudioEffectFilter::FilterDB AudioEffectFilter::get_db() const {
void AudioEffectFilter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_cutoff","freq"),&AudioEffectFilter::set_cutoff);
- ClassDB::bind_method(D_METHOD("get_cutoff"),&AudioEffectFilter::get_cutoff);
+ ClassDB::bind_method(D_METHOD("set_cutoff", "freq"), &AudioEffectFilter::set_cutoff);
+ ClassDB::bind_method(D_METHOD("get_cutoff"), &AudioEffectFilter::get_cutoff);
- ClassDB::bind_method(D_METHOD("set_resonance","amount"),&AudioEffectFilter::set_resonance);
- ClassDB::bind_method(D_METHOD("get_resonance"),&AudioEffectFilter::get_resonance);
+ ClassDB::bind_method(D_METHOD("set_resonance", "amount"), &AudioEffectFilter::set_resonance);
+ ClassDB::bind_method(D_METHOD("get_resonance"), &AudioEffectFilter::get_resonance);
- ClassDB::bind_method(D_METHOD("set_gain","amount"),&AudioEffectFilter::set_gain);
- ClassDB::bind_method(D_METHOD("get_gain"),&AudioEffectFilter::get_gain);
+ ClassDB::bind_method(D_METHOD("set_gain", "amount"), &AudioEffectFilter::set_gain);
+ ClassDB::bind_method(D_METHOD("get_gain"), &AudioEffectFilter::get_gain);
- ClassDB::bind_method(D_METHOD("set_db","amount"),&AudioEffectFilter::set_db);
- ClassDB::bind_method(D_METHOD("get_db"),&AudioEffectFilter::get_db);
+ ClassDB::bind_method(D_METHOD("set_db", "amount"), &AudioEffectFilter::set_db);
+ ClassDB::bind_method(D_METHOD("get_db"), &AudioEffectFilter::get_db);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"cutoff_hz",PROPERTY_HINT_RANGE,"1,40000,0.1"),"set_cutoff","get_cutoff");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"resonance",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_resonance","get_resonance");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"gain",PROPERTY_HINT_RANGE,"0,4,0.01"),"set_gain","get_gain");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"dB",PROPERTY_HINT_ENUM,"6db,12db,18db,24db"),"set_db","get_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "cutoff_hz", PROPERTY_HINT_RANGE, "1,40000,0.1"), "set_cutoff", "get_cutoff");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "resonance", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_resonance", "get_resonance");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gain", PROPERTY_HINT_RANGE, "0,4,0.01"), "set_gain", "get_gain");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "dB", PROPERTY_HINT_ENUM, "6db,12db,18db,24db"), "set_db", "get_db");
}
-AudioEffectFilter::AudioEffectFilter(AudioFilterSW::Mode p_mode)
-{
+AudioEffectFilter::AudioEffectFilter(AudioFilterSW::Mode p_mode) {
- mode=p_mode;
- cutoff=2000;
- resonance=0.5;
- gain=1.0;
- db=FILTER_6DB;
+ mode = p_mode;
+ cutoff = 2000;
+ resonance = 0.5;
+ gain = 1.0;
+ db = FILTER_6DB;
}
diff --git a/servers/audio/effects/audio_effect_filter.h b/servers/audio/effects/audio_effect_filter.h
index 0215f5a14..497363019 100644
--- a/servers/audio/effects/audio_effect_filter.h
+++ b/servers/audio/effects/audio_effect_filter.h
@@ -35,33 +35,31 @@
class AudioEffectFilter;
class AudioEffectFilterInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectFilterInstance,AudioEffectInstance)
-friend class AudioEffectFilter;
+ GDCLASS(AudioEffectFilterInstance, AudioEffectInstance)
+ friend class AudioEffectFilter;
Ref<AudioEffectFilter> base;
AudioFilterSW filter;
AudioFilterSW::Processor filter_process[2][4];
- template<int S>
- void _process_filter(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
-public:
+ template <int S>
+ void _process_filter(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+public:
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
AudioEffectFilterInstance();
};
-
class AudioEffectFilter : public AudioEffect {
- GDCLASS(AudioEffectFilter,AudioEffect)
+ GDCLASS(AudioEffectFilter, AudioEffect)
public:
-
enum FilterDB {
- FILTER_6DB,
- FILTER_12DB,
- FILTER_18DB,
- FILTER_24DB,
+ FILTER_6DB,
+ FILTER_12DB,
+ FILTER_18DB,
+ FILTER_24DB,
};
friend class AudioEffectFilterInstance;
@@ -71,13 +69,10 @@ public:
float gain;
FilterDB db;
-
protected:
-
-
static void _bind_methods();
-public:
+public:
void set_cutoff(float p_freq);
float get_cutoff() const;
@@ -92,62 +87,58 @@ public:
Ref<AudioEffectInstance> instance();
- AudioEffectFilter(AudioFilterSW::Mode p_mode=AudioFilterSW::LOWPASS);
+ AudioEffectFilter(AudioFilterSW::Mode p_mode = AudioFilterSW::LOWPASS);
};
VARIANT_ENUM_CAST(AudioEffectFilter::FilterDB)
class AudioEffectLowPassFilter : public AudioEffectFilter {
- GDCLASS(AudioEffectLowPassFilter,AudioEffectFilter)
+ GDCLASS(AudioEffectLowPassFilter, AudioEffectFilter)
public:
-
- AudioEffectLowPassFilter() : AudioEffectFilter(AudioFilterSW::LOWPASS) {}
+ AudioEffectLowPassFilter()
+ : AudioEffectFilter(AudioFilterSW::LOWPASS) {}
};
class AudioEffectHighPassFilter : public AudioEffectFilter {
- GDCLASS(AudioEffectHighPassFilter,AudioEffectFilter)
+ GDCLASS(AudioEffectHighPassFilter, AudioEffectFilter)
public:
-
- AudioEffectHighPassFilter() : AudioEffectFilter(AudioFilterSW::HIGHPASS) {}
+ AudioEffectHighPassFilter()
+ : AudioEffectFilter(AudioFilterSW::HIGHPASS) {}
};
class AudioEffectBandPassFilter : public AudioEffectFilter {
- GDCLASS(AudioEffectBandPassFilter,AudioEffectFilter)
+ GDCLASS(AudioEffectBandPassFilter, AudioEffectFilter)
public:
-
- AudioEffectBandPassFilter() : AudioEffectFilter(AudioFilterSW::BANDPASS) {}
+ AudioEffectBandPassFilter()
+ : AudioEffectFilter(AudioFilterSW::BANDPASS) {}
};
class AudioEffectNotchFilter : public AudioEffectFilter {
- GDCLASS(AudioEffectNotchFilter,AudioEffectFilter)
+ GDCLASS(AudioEffectNotchFilter, AudioEffectFilter)
public:
-
- AudioEffectNotchFilter() : AudioEffectFilter(AudioFilterSW::NOTCH) {}
+ AudioEffectNotchFilter()
+ : AudioEffectFilter(AudioFilterSW::NOTCH) {}
};
class AudioEffectBandLimitFilter : public AudioEffectFilter {
- GDCLASS(AudioEffectBandLimitFilter,AudioEffectFilter)
+ GDCLASS(AudioEffectBandLimitFilter, AudioEffectFilter)
public:
-
- AudioEffectBandLimitFilter() : AudioEffectFilter(AudioFilterSW::BANDLIMIT) {}
+ AudioEffectBandLimitFilter()
+ : AudioEffectFilter(AudioFilterSW::BANDLIMIT) {}
};
-
class AudioEffectLowShelfFilter : public AudioEffectFilter {
- GDCLASS(AudioEffectLowShelfFilter,AudioEffectFilter)
+ GDCLASS(AudioEffectLowShelfFilter, AudioEffectFilter)
public:
-
- AudioEffectLowShelfFilter() : AudioEffectFilter(AudioFilterSW::LOWSHELF) {}
+ AudioEffectLowShelfFilter()
+ : AudioEffectFilter(AudioFilterSW::LOWSHELF) {}
};
-
class AudioEffectHighShelfFilter : public AudioEffectFilter {
- GDCLASS(AudioEffectHighShelfFilter,AudioEffectFilter)
+ GDCLASS(AudioEffectHighShelfFilter, AudioEffectFilter)
public:
-
- AudioEffectHighShelfFilter() : AudioEffectFilter(AudioFilterSW::HIGHSHELF) {}
+ AudioEffectHighShelfFilter()
+ : AudioEffectFilter(AudioFilterSW::HIGHSHELF) {}
};
-
-
#endif // AUDIOEFFECTFILTER_H
diff --git a/servers/audio/effects/audio_effect_limiter.cpp b/servers/audio/effects/audio_effect_limiter.cpp
index a44bb5176..022d2d9aa 100644
--- a/servers/audio/effects/audio_effect_limiter.cpp
+++ b/servers/audio/effects/audio_effect_limiter.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "audio_effect_limiter.h"
-void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
float thresh = Math::db2linear(base->treshold);
float threshdb = base->treshold;
@@ -44,25 +44,23 @@ void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames,AudioFra
float scratio = base->soft_clip_ratio;
float scmult = Math::abs((ceildb - sc) / (peakdb - sc));
- for(int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
float spl0 = p_src_frames[i].l;
float spl1 = p_src_frames[i].r;
spl0 = spl0 * makeup;
spl1 = spl1 * makeup;
- float sign0 = (spl0 < 0.0 ? -1.0 : 1.0 );
- float sign1 = (spl1 < 0.0 ? -1.0 : 1.0 );
+ float sign0 = (spl0 < 0.0 ? -1.0 : 1.0);
+ float sign1 = (spl1 < 0.0 ? -1.0 : 1.0);
float abs0 = Math::abs(spl0);
float abs1 = Math::abs(spl1);
float overdb0 = Math::linear2db(abs0) - ceildb;
float overdb1 = Math::linear2db(abs1) - ceildb;
- if (abs0 > scv)
- {
+ if (abs0 > scv) {
spl0 = sign0 * (scv + Math::db2linear(overdb0 * scmult));
}
- if (abs1 > scv)
- {
+ if (abs1 > scv) {
spl1 = sign1 * (scv + Math::db2linear(overdb1 * scmult));
}
@@ -72,81 +70,76 @@ void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames,AudioFra
p_dst_frames[i].l = spl0;
p_dst_frames[i].r = spl1;
}
-
}
-
Ref<AudioEffectInstance> AudioEffectLimiter::instance() {
Ref<AudioEffectLimiterInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectLimiter>(this);
+ ins->base = Ref<AudioEffectLimiter>(this);
return ins;
}
-
void AudioEffectLimiter::set_treshold_db(float p_treshold) {
- treshold=p_treshold;
+ treshold = p_treshold;
}
-float AudioEffectLimiter::get_treshold_db() const{
+float AudioEffectLimiter::get_treshold_db() const {
return treshold;
}
-void AudioEffectLimiter::set_ceiling_db(float p_ceiling){
+void AudioEffectLimiter::set_ceiling_db(float p_ceiling) {
- ceiling=p_ceiling;
+ ceiling = p_ceiling;
}
-float AudioEffectLimiter::get_ceiling_db() const{
+float AudioEffectLimiter::get_ceiling_db() const {
return ceiling;
}
-void AudioEffectLimiter::set_soft_clip_db(float p_soft_clip){
+void AudioEffectLimiter::set_soft_clip_db(float p_soft_clip) {
- soft_clip=p_soft_clip;
+ soft_clip = p_soft_clip;
}
-float AudioEffectLimiter::get_soft_clip_db() const{
+float AudioEffectLimiter::get_soft_clip_db() const {
return soft_clip;
}
-void AudioEffectLimiter::set_soft_clip_ratio(float p_soft_clip){
+void AudioEffectLimiter::set_soft_clip_ratio(float p_soft_clip) {
- soft_clip_ratio=p_soft_clip;
+ soft_clip_ratio = p_soft_clip;
}
-float AudioEffectLimiter::get_soft_clip_ratio() const{
+float AudioEffectLimiter::get_soft_clip_ratio() const {
return soft_clip;
}
-
void AudioEffectLimiter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_ceiling_db","ceiling"),&AudioEffectLimiter::set_ceiling_db);
- ClassDB::bind_method(D_METHOD("get_ceiling_db"),&AudioEffectLimiter::get_ceiling_db);
+ ClassDB::bind_method(D_METHOD("set_ceiling_db", "ceiling"), &AudioEffectLimiter::set_ceiling_db);
+ ClassDB::bind_method(D_METHOD("get_ceiling_db"), &AudioEffectLimiter::get_ceiling_db);
- ClassDB::bind_method(D_METHOD("set_treshold_db","treshold"),&AudioEffectLimiter::set_treshold_db);
- ClassDB::bind_method(D_METHOD("get_treshold_db"),&AudioEffectLimiter::get_treshold_db);
+ ClassDB::bind_method(D_METHOD("set_treshold_db", "treshold"), &AudioEffectLimiter::set_treshold_db);
+ ClassDB::bind_method(D_METHOD("get_treshold_db"), &AudioEffectLimiter::get_treshold_db);
- ClassDB::bind_method(D_METHOD("set_soft_clip_db","soft_clip"),&AudioEffectLimiter::set_soft_clip_db);
- ClassDB::bind_method(D_METHOD("get_soft_clip_db"),&AudioEffectLimiter::get_soft_clip_db);
+ ClassDB::bind_method(D_METHOD("set_soft_clip_db", "soft_clip"), &AudioEffectLimiter::set_soft_clip_db);
+ ClassDB::bind_method(D_METHOD("get_soft_clip_db"), &AudioEffectLimiter::get_soft_clip_db);
- ClassDB::bind_method(D_METHOD("set_soft_clip_ratio","soft_clip"),&AudioEffectLimiter::set_soft_clip_ratio);
- ClassDB::bind_method(D_METHOD("get_soft_clip_ratio"),&AudioEffectLimiter::get_soft_clip_ratio);
+ ClassDB::bind_method(D_METHOD("set_soft_clip_ratio", "soft_clip"), &AudioEffectLimiter::set_soft_clip_ratio);
+ ClassDB::bind_method(D_METHOD("get_soft_clip_ratio"), &AudioEffectLimiter::get_soft_clip_ratio);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"ceiling_db",PROPERTY_HINT_RANGE,"-20,-0.1,0.1"),"set_ceiling_db","get_ceiling_db");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"treshold_db",PROPERTY_HINT_RANGE,"-30,0,0.1"),"set_treshold_db","get_treshold_db");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"soft_clip_db",PROPERTY_HINT_RANGE,"0,6,0.1"),"set_soft_clip_db","get_soft_clip_db");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"soft_clip_ratio",PROPERTY_HINT_RANGE,"3,20,0.1"),"set_soft_clip_ratio","get_soft_clip_ratio");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "ceiling_db", PROPERTY_HINT_RANGE, "-20,-0.1,0.1"), "set_ceiling_db", "get_ceiling_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "treshold_db", PROPERTY_HINT_RANGE, "-30,0,0.1"), "set_treshold_db", "get_treshold_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "soft_clip_db", PROPERTY_HINT_RANGE, "0,6,0.1"), "set_soft_clip_db", "get_soft_clip_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "soft_clip_ratio", PROPERTY_HINT_RANGE, "3,20,0.1"), "set_soft_clip_ratio", "get_soft_clip_ratio");
}
-AudioEffectLimiter::AudioEffectLimiter()
-{
- treshold=0;
- ceiling=-0.1;
- soft_clip=2;
- soft_clip_ratio=10;
+AudioEffectLimiter::AudioEffectLimiter() {
+ treshold = 0;
+ ceiling = -0.1;
+ soft_clip = 2;
+ soft_clip_ratio = 10;
}
diff --git a/servers/audio/effects/audio_effect_limiter.h b/servers/audio/effects/audio_effect_limiter.h
index 12639498d..9863a788f 100644
--- a/servers/audio/effects/audio_effect_limiter.h
+++ b/servers/audio/effects/audio_effect_limiter.h
@@ -29,39 +29,34 @@
#ifndef AUDIO_EFFECT_LIMITER_H
#define AUDIO_EFFECT_LIMITER_H
-
#include "servers/audio/audio_effect.h"
class AudioEffectLimiter;
class AudioEffectLimiterInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectLimiterInstance,AudioEffectInstance)
-friend class AudioEffectLimiter;
+ GDCLASS(AudioEffectLimiterInstance, AudioEffectInstance)
+ friend class AudioEffectLimiter;
Ref<AudioEffectLimiter> base;
float mix_volume_db;
-public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+public:
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectLimiter : public AudioEffect {
- GDCLASS(AudioEffectLimiter,AudioEffect)
+ GDCLASS(AudioEffectLimiter, AudioEffect)
-friend class AudioEffectLimiterInstance;
+ friend class AudioEffectLimiterInstance;
float treshold;
float ceiling;
float soft_clip;
float soft_clip_ratio;
protected:
-
static void _bind_methods();
-public:
-
+public:
void set_treshold_db(float p_treshold);
float get_treshold_db() const;
@@ -74,7 +69,6 @@ public:
void set_soft_clip_ratio(float p_soft_clip);
float get_soft_clip_ratio() const;
-
Ref<AudioEffectInstance> instance();
void set_volume_db(float p_volume);
float get_volume_db() const;
@@ -82,5 +76,4 @@ public:
AudioEffectLimiter();
};
-
#endif // AUDIO_EFFECT_LIMITER_H
diff --git a/servers/audio/effects/audio_effect_panner.cpp b/servers/audio/effects/audio_effect_panner.cpp
index 937575a5b..ec0ccab45 100644
--- a/servers/audio/effects/audio_effect_panner.cpp
+++ b/servers/audio/effects/audio_effect_panner.cpp
@@ -28,32 +28,27 @@
/*************************************************************************/
#include "audio_effect_panner.h"
+void AudioEffectPannerInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
-void AudioEffectPannerInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+ float lvol = CLAMP(1.0 - base->pan, 0, 1);
+ float rvol = CLAMP(1.0 + base->pan, 0, 1);
-
- float lvol = CLAMP( 1.0 - base->pan, 0, 1);
- float rvol = CLAMP( 1.0 + base->pan, 0, 1);
-
- for(int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
p_dst_frames[i].l = p_src_frames[i].l * lvol + p_src_frames[i].r * (1.0 - rvol);
p_dst_frames[i].r = p_src_frames[i].r * rvol + p_src_frames[i].l * (1.0 - lvol);
-
}
-
}
-
Ref<AudioEffectInstance> AudioEffectPanner::instance() {
Ref<AudioEffectPannerInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectPanner>(this);
+ ins->base = Ref<AudioEffectPanner>(this);
return ins;
}
void AudioEffectPanner::set_pan(float p_cpanume) {
- pan=p_cpanume;
+ pan = p_cpanume;
}
float AudioEffectPanner::get_pan() const {
@@ -63,13 +58,12 @@ float AudioEffectPanner::get_pan() const {
void AudioEffectPanner::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_pan","cpanume"),&AudioEffectPanner::set_pan);
- ClassDB::bind_method(D_METHOD("get_pan"),&AudioEffectPanner::get_pan);
+ ClassDB::bind_method(D_METHOD("set_pan", "cpanume"), &AudioEffectPanner::set_pan);
+ ClassDB::bind_method(D_METHOD("get_pan"), &AudioEffectPanner::get_pan);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_pan","get_pan");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_pan", "get_pan");
}
-AudioEffectPanner::AudioEffectPanner()
-{
- pan=0;
+AudioEffectPanner::AudioEffectPanner() {
+ pan = 0;
}
diff --git a/servers/audio/effects/audio_effect_panner.h b/servers/audio/effects/audio_effect_panner.h
index 999b5f564..19bef45f1 100644
--- a/servers/audio/effects/audio_effect_panner.h
+++ b/servers/audio/effects/audio_effect_panner.h
@@ -34,29 +34,24 @@
class AudioEffectPanner;
class AudioEffectPannerInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectPannerInstance,AudioEffectInstance)
-friend class AudioEffectPanner;
+ GDCLASS(AudioEffectPannerInstance, AudioEffectInstance)
+ friend class AudioEffectPanner;
Ref<AudioEffectPanner> base;
public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
-
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectPanner : public AudioEffect {
- GDCLASS(AudioEffectPanner,AudioEffect)
+ GDCLASS(AudioEffectPanner, AudioEffect)
-friend class AudioEffectPannerInstance;
+ friend class AudioEffectPannerInstance;
float pan;
protected:
-
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
void set_pan(float p_volume);
float get_pan() const;
@@ -64,5 +59,4 @@ public:
AudioEffectPanner();
};
-
#endif // AUDIOEFFECTPANNER_H
diff --git a/servers/audio/effects/audio_effect_phaser.cpp b/servers/audio/effects/audio_effect_phaser.cpp
index c9576404f..72549009c 100644
--- a/servers/audio/effects/audio_effect_phaser.cpp
+++ b/servers/audio/effects/audio_effect_phaser.cpp
@@ -27,113 +27,107 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "audio_effect_phaser.h"
-#include "servers/audio_server.h"
#include "math_funcs.h"
+#include "servers/audio_server.h"
-void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
float sampling_rate = AudioServer::get_singleton()->get_mix_rate();
- float dmin = base->range_min / (sampling_rate/2.0);
- float dmax = base->range_max / (sampling_rate/2.0);
+ float dmin = base->range_min / (sampling_rate / 2.0);
+ float dmax = base->range_max / (sampling_rate / 2.0);
float increment = 2.f * Math_PI * (base->rate / sampling_rate);
- for(int i=0;i<p_frame_count;i++) {
+ for (int i = 0; i < p_frame_count; i++) {
phase += increment;
- while ( phase >= Math_PI * 2.f ) {
+ while (phase >= Math_PI * 2.f) {
phase -= Math_PI * 2.f;
}
- float d = dmin + (dmax-dmin) * ((sin( phase ) + 1.f)/2.f);
-
+ float d = dmin + (dmax - dmin) * ((sin(phase) + 1.f) / 2.f);
//update filter coeffs
- for( int j=0; j<6; j++ ) {
- allpass[0][j].delay( d );
- allpass[1][j].delay( d );
+ for (int j = 0; j < 6; j++) {
+ allpass[0][j].delay(d);
+ allpass[1][j].delay(d);
}
//calculate output
- float y = allpass[0][0].update(
- allpass[0][1].update(
- allpass[0][2].update(
- allpass[0][3].update(
- allpass[0][4].update(
- allpass[0][5].update( p_src_frames[i].l + h.l * base->feedback ))))));
- h.l=y;
+ float y = allpass[0][0].update(
+ allpass[0][1].update(
+ allpass[0][2].update(
+ allpass[0][3].update(
+ allpass[0][4].update(
+ allpass[0][5].update(p_src_frames[i].l + h.l * base->feedback))))));
+ h.l = y;
p_dst_frames[i].l = p_src_frames[i].l + y * base->depth;
- y = allpass[1][0].update(
- allpass[1][1].update(
- allpass[1][2].update(
- allpass[1][3].update(
- allpass[1][4].update(
- allpass[1][5].update( p_src_frames[i].r + h.r * base->feedback ))))));
- h.r=y;
+ y = allpass[1][0].update(
+ allpass[1][1].update(
+ allpass[1][2].update(
+ allpass[1][3].update(
+ allpass[1][4].update(
+ allpass[1][5].update(p_src_frames[i].r + h.r * base->feedback))))));
+ h.r = y;
p_dst_frames[i].r = p_src_frames[i].r + y * base->depth;
-
-
}
-
}
-
Ref<AudioEffectInstance> AudioEffectPhaser::instance() {
Ref<AudioEffectPhaserInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectPhaser>(this);
- ins->phase=0;
- ins->h=AudioFrame(0,0);
+ ins->base = Ref<AudioEffectPhaser>(this);
+ ins->phase = 0;
+ ins->h = AudioFrame(0, 0);
return ins;
}
-
void AudioEffectPhaser::set_range_min_hz(float p_hz) {
- range_min=p_hz;
+ range_min = p_hz;
}
-float AudioEffectPhaser::get_range_min_hz() const{
+float AudioEffectPhaser::get_range_min_hz() const {
return range_min;
}
-void AudioEffectPhaser::set_range_max_hz(float p_hz){
+void AudioEffectPhaser::set_range_max_hz(float p_hz) {
- range_max=p_hz;
+ range_max = p_hz;
}
-float AudioEffectPhaser::get_range_max_hz() const{
+float AudioEffectPhaser::get_range_max_hz() const {
return range_max;
}
-void AudioEffectPhaser::set_rate_hz(float p_hz){
+void AudioEffectPhaser::set_rate_hz(float p_hz) {
- rate=p_hz;
+ rate = p_hz;
}
-float AudioEffectPhaser::get_rate_hz() const{
+float AudioEffectPhaser::get_rate_hz() const {
return rate;
}
-void AudioEffectPhaser::set_feedback(float p_fbk){
+void AudioEffectPhaser::set_feedback(float p_fbk) {
- feedback=p_fbk;
+ feedback = p_fbk;
}
-float AudioEffectPhaser::get_feedback() const{
+float AudioEffectPhaser::get_feedback() const {
return feedback;
}
void AudioEffectPhaser::set_depth(float p_depth) {
- depth=p_depth;
+ depth = p_depth;
}
float AudioEffectPhaser::get_depth() const {
@@ -143,34 +137,32 @@ float AudioEffectPhaser::get_depth() const {
void AudioEffectPhaser::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_range_min_hz","hz"),&AudioEffectPhaser::set_range_min_hz);
- ClassDB::bind_method(D_METHOD("get_range_min_hz"),&AudioEffectPhaser::get_range_min_hz);
-
- ClassDB::bind_method(D_METHOD("set_range_max_hz","hz"),&AudioEffectPhaser::set_range_max_hz);
- ClassDB::bind_method(D_METHOD("get_range_max_hz"),&AudioEffectPhaser::get_range_max_hz);
+ ClassDB::bind_method(D_METHOD("set_range_min_hz", "hz"), &AudioEffectPhaser::set_range_min_hz);
+ ClassDB::bind_method(D_METHOD("get_range_min_hz"), &AudioEffectPhaser::get_range_min_hz);
- ClassDB::bind_method(D_METHOD("set_rate_hz","hz"),&AudioEffectPhaser::set_rate_hz);
- ClassDB::bind_method(D_METHOD("get_rate_hz"),&AudioEffectPhaser::get_rate_hz);
+ ClassDB::bind_method(D_METHOD("set_range_max_hz", "hz"), &AudioEffectPhaser::set_range_max_hz);
+ ClassDB::bind_method(D_METHOD("get_range_max_hz"), &AudioEffectPhaser::get_range_max_hz);
- ClassDB::bind_method(D_METHOD("set_feedback","fbk"),&AudioEffectPhaser::set_feedback);
- ClassDB::bind_method(D_METHOD("get_feedback"),&AudioEffectPhaser::get_feedback);
+ ClassDB::bind_method(D_METHOD("set_rate_hz", "hz"), &AudioEffectPhaser::set_rate_hz);
+ ClassDB::bind_method(D_METHOD("get_rate_hz"), &AudioEffectPhaser::get_rate_hz);
- ClassDB::bind_method(D_METHOD("set_depth","depth"),&AudioEffectPhaser::set_depth);
- ClassDB::bind_method(D_METHOD("get_depth"),&AudioEffectPhaser::get_depth);
+ ClassDB::bind_method(D_METHOD("set_feedback", "fbk"), &AudioEffectPhaser::set_feedback);
+ ClassDB::bind_method(D_METHOD("get_feedback"), &AudioEffectPhaser::get_feedback);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"range_min_hz",PROPERTY_HINT_RANGE,"10,10000"),"set_range_min_hz","get_range_min_hz");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"range_max_hz",PROPERTY_HINT_RANGE,"10,10000"),"set_range_max_hz","get_range_max_hz");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"rate_hz",PROPERTY_HINT_RANGE,"0.01,20"),"set_rate_hz","get_rate_hz");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback",PROPERTY_HINT_RANGE,"0.1,0.9,0.1"),"set_feedback","get_feedback");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"depth",PROPERTY_HINT_RANGE,"0.1,4,0.1"),"set_depth","get_depth");
+ ClassDB::bind_method(D_METHOD("set_depth", "depth"), &AudioEffectPhaser::set_depth);
+ ClassDB::bind_method(D_METHOD("get_depth"), &AudioEffectPhaser::get_depth);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "range_min_hz", PROPERTY_HINT_RANGE, "10,10000"), "set_range_min_hz", "get_range_min_hz");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "range_max_hz", PROPERTY_HINT_RANGE, "10,10000"), "set_range_max_hz", "get_range_max_hz");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "rate_hz", PROPERTY_HINT_RANGE, "0.01,20"), "set_rate_hz", "get_rate_hz");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "feedback", PROPERTY_HINT_RANGE, "0.1,0.9,0.1"), "set_feedback", "get_feedback");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth", PROPERTY_HINT_RANGE, "0.1,4,0.1"), "set_depth", "get_depth");
}
-AudioEffectPhaser::AudioEffectPhaser()
-{
- range_min=440;
- range_max=1600;
- rate=0.5;
- feedback=0.7;
- depth=1;
+AudioEffectPhaser::AudioEffectPhaser() {
+ range_min = 440;
+ range_max = 1600;
+ rate = 0.5;
+ feedback = 0.7;
+ depth = 1;
}
diff --git a/servers/audio/effects/audio_effect_phaser.h b/servers/audio/effects/audio_effect_phaser.h
index a7294183f..70b3a3a4c 100644
--- a/servers/audio/effects/audio_effect_phaser.h
+++ b/servers/audio/effects/audio_effect_phaser.h
@@ -29,50 +29,48 @@
#ifndef AUDIO_EFFECT_PHASER_H
#define AUDIO_EFFECT_PHASER_H
-
-
#include "servers/audio/audio_effect.h"
class AudioEffectPhaser;
class AudioEffectPhaserInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectPhaserInstance,AudioEffectInstance)
-friend class AudioEffectPhaser;
+ GDCLASS(AudioEffectPhaserInstance, AudioEffectInstance)
+ friend class AudioEffectPhaser;
Ref<AudioEffectPhaser> base;
float phase;
AudioFrame h;
- class AllpassDelay{
+ class AllpassDelay {
float a, h;
- public:
- _ALWAYS_INLINE_ void delay( float d ) {
+ public:
+ _ALWAYS_INLINE_ void delay(float d) {
a = (1.f - d) / (1.f + d);
}
- _ALWAYS_INLINE_ float update( float s ){
+ _ALWAYS_INLINE_ float update(float s) {
float y = s * -a + h;
h = y * a + s;
return y;
}
- AllpassDelay() { a =0; h = 0;}
-
+ AllpassDelay() {
+ a = 0;
+ h = 0;
+ }
};
AllpassDelay allpass[2][6];
-public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+public:
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectPhaser : public AudioEffect {
- GDCLASS(AudioEffectPhaser,AudioEffect)
+ GDCLASS(AudioEffectPhaser, AudioEffect)
-friend class AudioEffectPhaserInstance;
+ friend class AudioEffectPhaserInstance;
float range_min;
float range_max;
float rate;
@@ -80,11 +78,9 @@ friend class AudioEffectPhaserInstance;
float depth;
protected:
-
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
void set_range_min_hz(float p_hz);
@@ -105,5 +101,4 @@ public:
AudioEffectPhaser();
};
-
#endif // AUDIO_EFFECT_PHASER_H
diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp
index e00755e1a..6a14ba715 100644
--- a/servers/audio/effects/audio_effect_pitch_shift.cpp
+++ b/servers/audio/effects/audio_effect_pitch_shift.cpp
@@ -28,8 +28,8 @@
/*************************************************************************/
#include "audio_effect_pitch_shift.h"
-#include "servers/audio_server.h"
#include "math_funcs.h"
+#include "servers/audio_server.h"
/* Thirdparty code, so disable clang-format with Godot style */
/* clang-format off */
@@ -281,34 +281,31 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign)
/* Godot code again */
/* clang-format on */
-void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
float sample_rate = AudioServer::get_singleton()->get_mix_rate();
- float *in_l = (float*)p_src_frames;
+ float *in_l = (float *)p_src_frames;
float *in_r = in_l + 1;
- float *out_l = (float*)p_dst_frames;
+ float *out_l = (float *)p_dst_frames;
float *out_r = out_l + 1;
- shift_l.PitchShift(base->pitch_scale,p_frame_count,2048,4,sample_rate,in_l,out_l,2);
- shift_r.PitchShift(base->pitch_scale,p_frame_count,2048,4,sample_rate,in_r,out_r,2);
-
+ shift_l.PitchShift(base->pitch_scale, p_frame_count, 2048, 4, sample_rate, in_l, out_l, 2);
+ shift_r.PitchShift(base->pitch_scale, p_frame_count, 2048, 4, sample_rate, in_r, out_r, 2);
}
-
Ref<AudioEffectInstance> AudioEffectPitchShift::instance() {
Ref<AudioEffectPitchShiftInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectPitchShift>(this);
-
+ ins->base = Ref<AudioEffectPitchShift>(this);
return ins;
}
void AudioEffectPitchShift::set_pitch_scale(float p_adjust) {
- pitch_scale=p_adjust;
+ pitch_scale = p_adjust;
}
float AudioEffectPitchShift::get_pitch_scale() const {
@@ -316,17 +313,14 @@ float AudioEffectPitchShift::get_pitch_scale() const {
return pitch_scale;
}
-
void AudioEffectPitchShift::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_pitch_scale","rate"),&AudioEffectPitchShift::set_pitch_scale);
- ClassDB::bind_method(D_METHOD("get_pitch_scale"),&AudioEffectPitchShift::get_pitch_scale);
-
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"pitch_scale",PROPERTY_HINT_RANGE,"0.01,16,0.01"),"set_pitch_scale","get_pitch_scale");
+ ClassDB::bind_method(D_METHOD("set_pitch_scale", "rate"), &AudioEffectPitchShift::set_pitch_scale);
+ ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioEffectPitchShift::get_pitch_scale);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_pitch_scale", "get_pitch_scale");
}
AudioEffectPitchShift::AudioEffectPitchShift() {
- pitch_scale=1.0;
-
+ pitch_scale = 1.0;
}
diff --git a/servers/audio/effects/audio_effect_pitch_shift.h b/servers/audio/effects/audio_effect_pitch_shift.h
index 1320976f5..610efdc0e 100644
--- a/servers/audio/effects/audio_effect_pitch_shift.h
+++ b/servers/audio/effects/audio_effect_pitch_shift.h
@@ -29,21 +29,20 @@
#ifndef AUDIO_EFFECT_PITCH_SHIFT_H
#define AUDIO_EFFECT_PITCH_SHIFT_H
-
#include "servers/audio/audio_effect.h"
class SMBPitchShift {
enum {
- MAX_FRAME_LENGTH=8192
+ MAX_FRAME_LENGTH = 8192
};
float gInFIFO[MAX_FRAME_LENGTH];
float gOutFIFO[MAX_FRAME_LENGTH];
- float gFFTworksp[2*MAX_FRAME_LENGTH];
- float gLastPhase[MAX_FRAME_LENGTH/2+1];
- float gSumPhase[MAX_FRAME_LENGTH/2+1];
- float gOutputAccum[2*MAX_FRAME_LENGTH];
+ float gFFTworksp[2 * MAX_FRAME_LENGTH];
+ float gLastPhase[MAX_FRAME_LENGTH / 2 + 1];
+ float gSumPhase[MAX_FRAME_LENGTH / 2 + 1];
+ float gOutputAccum[2 * MAX_FRAME_LENGTH];
float gAnaFreq[MAX_FRAME_LENGTH];
float gAnaMagn[MAX_FRAME_LENGTH];
float gSynFreq[MAX_FRAME_LENGTH];
@@ -51,47 +50,41 @@ class SMBPitchShift {
long gRover;
void smbFft(float *fftBuffer, long fftFrameSize, long sign);
+
public:
void PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata, int stride);
SMBPitchShift() {
- gRover=0;
- memset(gInFIFO, 0, MAX_FRAME_LENGTH*sizeof(float));
- memset(gOutFIFO, 0, MAX_FRAME_LENGTH*sizeof(float));
- memset(gFFTworksp, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
- memset(gLastPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float));
- memset(gSumPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float));
- memset(gOutputAccum, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
- memset(gAnaFreq, 0, MAX_FRAME_LENGTH*sizeof(float));
- memset(gAnaMagn, 0, MAX_FRAME_LENGTH*sizeof(float));
+ gRover = 0;
+ memset(gInFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
+ memset(gOutFIFO, 0, MAX_FRAME_LENGTH * sizeof(float));
+ memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(float));
+ memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float));
+ memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float));
+ memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(float));
+ memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(float));
+ memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(float));
}
-
-
};
-
class AudioEffectPitchShift;
class AudioEffectPitchShiftInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectPitchShiftInstance,AudioEffectInstance)
-friend class AudioEffectPitchShift;
+ GDCLASS(AudioEffectPitchShiftInstance, AudioEffectInstance)
+ friend class AudioEffectPitchShift;
Ref<AudioEffectPitchShift> base;
SMBPitchShift shift_l;
SMBPitchShift shift_r;
-
public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
-
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
};
-
class AudioEffectPitchShift : public AudioEffect {
- GDCLASS(AudioEffectPitchShift,AudioEffect)
+ GDCLASS(AudioEffectPitchShift, AudioEffect)
-friend class AudioEffectPitchShiftInstance;
+ friend class AudioEffectPitchShiftInstance;
float pitch_scale;
int window_size;
@@ -100,11 +93,9 @@ friend class AudioEffectPitchShiftInstance;
bool filter;
protected:
-
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
void set_pitch_scale(float p_adjust);
@@ -113,5 +104,4 @@ public:
AudioEffectPitchShift();
};
-
#endif // AUDIO_EFFECT_PITCH_SHIFT_H
diff --git a/servers/audio/effects/audio_effect_reverb.cpp b/servers/audio/effects/audio_effect_reverb.cpp
index d668c63e8..f01bd266b 100644
--- a/servers/audio/effects/audio_effect_reverb.cpp
+++ b/servers/audio/effects/audio_effect_reverb.cpp
@@ -28,99 +28,98 @@
/*************************************************************************/
#include "audio_effect_reverb.h"
#include "servers/audio_server.h"
-void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
- for(int i=0;i<2;i++) {
- Reverb &r=reverb[i];
+ for (int i = 0; i < 2; i++) {
+ Reverb &r = reverb[i];
- r.set_predelay( base->predelay);
- r.set_predelay_feedback( base->predelay_fb );
- r.set_highpass( base->hpf );
- r.set_room_size( base->room_size );
- r.set_damp( base->damping );
- r.set_extra_spread( base->spread );
- r.set_wet( base->wet );
- r.set_dry( base->dry );
+ r.set_predelay(base->predelay);
+ r.set_predelay_feedback(base->predelay_fb);
+ r.set_highpass(base->hpf);
+ r.set_room_size(base->room_size);
+ r.set_damp(base->damping);
+ r.set_extra_spread(base->spread);
+ r.set_wet(base->wet);
+ r.set_dry(base->dry);
}
int todo = p_frame_count;
- int offset=0;
+ int offset = 0;
- while(todo) {
+ while (todo) {
- int to_mix = MIN(todo,Reverb::INPUT_BUFFER_MAX_SIZE);
+ int to_mix = MIN(todo, Reverb::INPUT_BUFFER_MAX_SIZE);
- for(int j=0;j<to_mix;j++) {
- tmp_src[j]=p_src_frames[offset+j].l;
+ for (int j = 0; j < to_mix; j++) {
+ tmp_src[j] = p_src_frames[offset + j].l;
}
- reverb[0].process(tmp_src,tmp_dst,to_mix);
+ reverb[0].process(tmp_src, tmp_dst, to_mix);
- for(int j=0;j<to_mix;j++) {
- p_dst_frames[offset+j].l=tmp_dst[j];
- tmp_src[j]=p_src_frames[offset+j].r;
+ for (int j = 0; j < to_mix; j++) {
+ p_dst_frames[offset + j].l = tmp_dst[j];
+ tmp_src[j] = p_src_frames[offset + j].r;
}
- reverb[1].process(tmp_src,tmp_dst,to_mix);
+ reverb[1].process(tmp_src, tmp_dst, to_mix);
- for(int j=0;j<to_mix;j++) {
- p_dst_frames[offset+j].r=tmp_dst[j];
+ for (int j = 0; j < to_mix; j++) {
+ p_dst_frames[offset + j].r = tmp_dst[j];
}
- offset+=to_mix;
- todo-=to_mix;
+ offset += to_mix;
+ todo -= to_mix;
}
}
AudioEffectReverbInstance::AudioEffectReverbInstance() {
- reverb[0].set_mix_rate( AudioServer::get_singleton()->get_mix_rate() );
+ reverb[0].set_mix_rate(AudioServer::get_singleton()->get_mix_rate());
reverb[0].set_extra_spread_base(0);
- reverb[1].set_mix_rate( AudioServer::get_singleton()->get_mix_rate() );
+ reverb[1].set_mix_rate(AudioServer::get_singleton()->get_mix_rate());
reverb[1].set_extra_spread_base(0.000521); //for stereo effect
-
}
Ref<AudioEffectInstance> AudioEffectReverb::instance() {
Ref<AudioEffectReverbInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectReverb>(this);
+ ins->base = Ref<AudioEffectReverb>(this);
return ins;
}
void AudioEffectReverb::set_predelay_msec(float p_msec) {
- predelay=p_msec;
+ predelay = p_msec;
}
-void AudioEffectReverb::set_predelay_feedback(float p_feedback){
+void AudioEffectReverb::set_predelay_feedback(float p_feedback) {
- predelay_fb=p_feedback;
+ predelay_fb = p_feedback;
}
-void AudioEffectReverb::set_room_size(float p_size){
+void AudioEffectReverb::set_room_size(float p_size) {
- room_size=p_size;
+ room_size = p_size;
}
-void AudioEffectReverb::set_damping(float p_damping){
+void AudioEffectReverb::set_damping(float p_damping) {
- damping=p_damping;
+ damping = p_damping;
}
-void AudioEffectReverb::set_spread(float p_spread){
+void AudioEffectReverb::set_spread(float p_spread) {
- spread=p_spread;
+ spread = p_spread;
}
-void AudioEffectReverb::set_dry(float p_dry){
+void AudioEffectReverb::set_dry(float p_dry) {
- dry=p_dry;
+ dry = p_dry;
}
-void AudioEffectReverb::set_wet(float p_wet){
+void AudioEffectReverb::set_wet(float p_wet) {
- wet=p_wet;
+ wet = p_wet;
}
void AudioEffectReverb::set_hpf(float p_hpf) {
- hpf=p_hpf;
+ hpf = p_hpf;
}
float AudioEffectReverb::get_predelay_msec() const {
@@ -156,55 +155,51 @@ float AudioEffectReverb::get_hpf() const {
return hpf;
}
-
void AudioEffectReverb::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_predelay_msec", "msec"), &AudioEffectReverb::set_predelay_msec);
+ ClassDB::bind_method(D_METHOD("get_predelay_msec"), &AudioEffectReverb::get_predelay_msec);
- ClassDB::bind_method(D_METHOD("set_predelay_msec","msec"),&AudioEffectReverb::set_predelay_msec);
- ClassDB::bind_method(D_METHOD("get_predelay_msec"),&AudioEffectReverb::get_predelay_msec);
-
- ClassDB::bind_method(D_METHOD("set_predelay_feedback","feedback"),&AudioEffectReverb::set_predelay_feedback);
- ClassDB::bind_method(D_METHOD("get_predelay_feedback"),&AudioEffectReverb::get_predelay_feedback);
+ ClassDB::bind_method(D_METHOD("set_predelay_feedback", "feedback"), &AudioEffectReverb::set_predelay_feedback);
+ ClassDB::bind_method(D_METHOD("get_predelay_feedback"), &AudioEffectReverb::get_predelay_feedback);
- ClassDB::bind_method(D_METHOD("set_room_size","size"),&AudioEffectReverb::set_room_size);
- ClassDB::bind_method(D_METHOD("get_room_size"),&AudioEffectReverb::get_room_size);
+ ClassDB::bind_method(D_METHOD("set_room_size", "size"), &AudioEffectReverb::set_room_size);
+ ClassDB::bind_method(D_METHOD("get_room_size"), &AudioEffectReverb::get_room_size);
- ClassDB::bind_method(D_METHOD("set_damping","amount"),&AudioEffectReverb::set_damping);
- ClassDB::bind_method(D_METHOD("get_damping"),&AudioEffectReverb::get_damping);
+ ClassDB::bind_method(D_METHOD("set_damping", "amount"), &AudioEffectReverb::set_damping);
+ ClassDB::bind_method(D_METHOD("get_damping"), &AudioEffectReverb::get_damping);
- ClassDB::bind_method(D_METHOD("set_spread","amount"),&AudioEffectReverb::set_spread);
- ClassDB::bind_method(D_METHOD("get_spread"),&AudioEffectReverb::get_spread);
+ ClassDB::bind_method(D_METHOD("set_spread", "amount"), &AudioEffectReverb::set_spread);
+ ClassDB::bind_method(D_METHOD("get_spread"), &AudioEffectReverb::get_spread);
- ClassDB::bind_method(D_METHOD("set_dry","amount"),&AudioEffectReverb::set_dry);
- ClassDB::bind_method(D_METHOD("get_dry"),&AudioEffectReverb::get_dry);
+ ClassDB::bind_method(D_METHOD("set_dry", "amount"), &AudioEffectReverb::set_dry);
+ ClassDB::bind_method(D_METHOD("get_dry"), &AudioEffectReverb::get_dry);
- ClassDB::bind_method(D_METHOD("set_wet","amount"),&AudioEffectReverb::set_wet);
- ClassDB::bind_method(D_METHOD("get_wet"),&AudioEffectReverb::get_wet);
+ ClassDB::bind_method(D_METHOD("set_wet", "amount"), &AudioEffectReverb::set_wet);
+ ClassDB::bind_method(D_METHOD("get_wet"), &AudioEffectReverb::get_wet);
- ClassDB::bind_method(D_METHOD("set_hpf","amount"),&AudioEffectReverb::set_hpf);
- ClassDB::bind_method(D_METHOD("get_hpf"),&AudioEffectReverb::get_hpf);
+ ClassDB::bind_method(D_METHOD("set_hpf", "amount"), &AudioEffectReverb::set_hpf);
+ ClassDB::bind_method(D_METHOD("get_hpf"), &AudioEffectReverb::get_hpf);
-
- ADD_GROUP("Predelay","predelay_");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"predelay_msec",PROPERTY_HINT_RANGE,"20,500,1"),"set_predelay_msec","get_predelay_msec");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"predelay_feedback",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_predelay_msec","get_predelay_msec");
- ADD_GROUP("","");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"room_size",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_room_size","get_room_size");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"damping",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_damping","get_damping");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"spread",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_spread","get_spread");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"hipass",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_hpf","get_hpf");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"dry",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_dry","get_dry");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"wet",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_wet","get_wet");
+ ADD_GROUP("Predelay", "predelay_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "predelay_msec", PROPERTY_HINT_RANGE, "20,500,1"), "set_predelay_msec", "get_predelay_msec");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "predelay_feedback", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_predelay_msec", "get_predelay_msec");
+ ADD_GROUP("", "");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "room_size", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_room_size", "get_room_size");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "damping", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_damping", "get_damping");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "spread", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_spread", "get_spread");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "hipass", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_hpf", "get_hpf");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "dry", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dry", "get_dry");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "wet", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_wet", "get_wet");
}
AudioEffectReverb::AudioEffectReverb() {
- predelay=150;
- predelay_fb=0.4;
- hpf=0;
- room_size=0.8;
- damping=0.5;
- spread=1.0;
- dry=1.0;
- wet=0.5;
-
+ predelay = 150;
+ predelay_fb = 0.4;
+ hpf = 0;
+ room_size = 0.8;
+ damping = 0.5;
+ spread = 1.0;
+ dry = 1.0;
+ wet = 0.5;
}
diff --git a/servers/audio/effects/audio_effect_reverb.h b/servers/audio/effects/audio_effect_reverb.h
index 41b4f15cf..2c665ca91 100644
--- a/servers/audio/effects/audio_effect_reverb.h
+++ b/servers/audio/effects/audio_effect_reverb.h
@@ -29,36 +29,32 @@
#ifndef AUDIOEFFECTREVERB_H
#define AUDIOEFFECTREVERB_H
-
#include "servers/audio/audio_effect.h"
#include "servers/audio/effects/reverb.h"
class AudioEffectReverb;
class AudioEffectReverbInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectReverbInstance,AudioEffectInstance)
+ GDCLASS(AudioEffectReverbInstance, AudioEffectInstance)
Ref<AudioEffectReverb> base;
float tmp_src[Reverb::INPUT_BUFFER_MAX_SIZE];
float tmp_dst[Reverb::INPUT_BUFFER_MAX_SIZE];
-friend class AudioEffectReverb;
+ friend class AudioEffectReverb;
Reverb reverb[2];
-
public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
AudioEffectReverbInstance();
};
-
class AudioEffectReverb : public AudioEffect {
- GDCLASS(AudioEffectReverb,AudioEffect)
+ GDCLASS(AudioEffectReverb, AudioEffect)
-friend class AudioEffectReverbInstance;
+ friend class AudioEffectReverbInstance;
float predelay;
float predelay_fb;
@@ -70,11 +66,9 @@ friend class AudioEffectReverbInstance;
float wet;
protected:
-
static void _bind_methods();
-public:
-
+public:
void set_predelay_msec(float p_msec);
void set_predelay_feedback(float p_feedback);
void set_room_size(float p_size);
@@ -100,5 +94,4 @@ public:
AudioEffectReverb();
};
-
#endif // AUDIOEFFECTREVERB_H
diff --git a/servers/audio/effects/audio_effect_stereo_enhance.cpp b/servers/audio/effects/audio_effect_stereo_enhance.cpp
index 388c38ed1..9aed528bd 100644
--- a/servers/audio/effects/audio_effect_stereo_enhance.cpp
+++ b/servers/audio/effects/audio_effect_stereo_enhance.cpp
@@ -28,55 +28,50 @@
/*************************************************************************/
#include "audio_effect_stereo_enhance.h"
#include "servers/audio_server.h"
-void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) {
+void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
+ float intensity = base->pan_pullout;
+ bool surround_mode = base->surround > 0;
+ float surround_amount = base->surround;
+ unsigned int delay_frames = (base->time_pullout / 1000.0) * AudioServer::get_singleton()->get_mix_rate();
- float intensity=base->pan_pullout;
- bool surround_mode=base->surround>0;
- float surround_amount=base->surround;
- unsigned int delay_frames=(base->time_pullout/1000.0)*AudioServer::get_singleton()->get_mix_rate();
+ for (int i = 0; i < p_frame_count; i++) {
- for (int i=0;i<p_frame_count;i++) {
+ float l = p_src_frames[i].l;
+ float r = p_src_frames[i].r;
- float l=p_src_frames[i].l;
- float r=p_src_frames[i].r;
+ float center = (l + r) / 2.0f;
- float center=(l+r)/2.0f;
-
- l=( center+(l-center)*intensity );
- r=( center+(r-center)*intensity );
+ l = (center + (l - center) * intensity);
+ r = (center + (r - center) * intensity);
if (surround_mode) {
- float val=(l+r)/2.0;
+ float val = (l + r) / 2.0;
- delay_ringbuff[ringbuff_pos&ringbuff_mask]=val;
+ delay_ringbuff[ringbuff_pos & ringbuff_mask] = val;
- float out=delay_ringbuff[(ringbuff_pos-delay_frames)&ringbuff_mask]*surround_amount;
+ float out = delay_ringbuff[(ringbuff_pos - delay_frames) & ringbuff_mask] * surround_amount;
- l+=out;
- r+=-out;
+ l += out;
+ r += -out;
} else {
- float val=r;
+ float val = r;
- delay_ringbuff[ringbuff_pos&ringbuff_mask]=val;
+ delay_ringbuff[ringbuff_pos & ringbuff_mask] = val;
//r is delayed
- r=delay_ringbuff[(ringbuff_pos-delay_frames)&ringbuff_mask];;
-
-
+ r = delay_ringbuff[(ringbuff_pos - delay_frames) & ringbuff_mask];
+ ;
}
- p_dst_frames[i].l=l;
- p_dst_frames[i].r=r;
+ p_dst_frames[i].l = l;
+ p_dst_frames[i].r = r;
ringbuff_pos++;
-
}
-
}
-
AudioEffectStereoEnhanceInstance::~AudioEffectStereoEnhanceInstance() {
memdelete_arr(delay_ringbuff);
@@ -86,78 +81,76 @@ Ref<AudioEffectInstance> AudioEffectStereoEnhance::instance() {
Ref<AudioEffectStereoEnhanceInstance> ins;
ins.instance();
- ins->base=Ref<AudioEffectStereoEnhance>(this);
-
+ ins->base = Ref<AudioEffectStereoEnhance>(this);
- float ring_buffer_max_size=AudioEffectStereoEnhanceInstance::MAX_DELAY_MS+2;
- ring_buffer_max_size/=1000.0;//convert to seconds
- ring_buffer_max_size*=AudioServer::get_singleton()->get_mix_rate();
+ float ring_buffer_max_size = AudioEffectStereoEnhanceInstance::MAX_DELAY_MS + 2;
+ ring_buffer_max_size /= 1000.0; //convert to seconds
+ ring_buffer_max_size *= AudioServer::get_singleton()->get_mix_rate();
- int ringbuff_size=(int)ring_buffer_max_size;
+ int ringbuff_size = (int)ring_buffer_max_size;
- int bits=0;
+ int bits = 0;
- while(ringbuff_size>0) {
+ while (ringbuff_size > 0) {
bits++;
- ringbuff_size/=2;
+ ringbuff_size /= 2;
}
- ringbuff_size=1<<bits;
- ins->ringbuff_mask=ringbuff_size-1;
- ins->ringbuff_pos=0;
+ ringbuff_size = 1 << bits;
+ ins->ringbuff_mask = ringbuff_size - 1;
+ ins->ringbuff_pos = 0;
- ins->delay_ringbuff = memnew_arr(float,ringbuff_size );
+ ins->delay_ringbuff = memnew_arr(float, ringbuff_size);
return ins;
}
-void AudioEffectStereoEnhance::set_pan_pullout(float p_amount) {
+void AudioEffectStereoEnhance::set_pan_pullout(float p_amount) {
- pan_pullout=p_amount;
+ pan_pullout = p_amount;
}
-float AudioEffectStereoEnhance::get_pan_pullout() const {
+float AudioEffectStereoEnhance::get_pan_pullout() const {
return pan_pullout;
}
-void AudioEffectStereoEnhance::set_time_pullout(float p_amount) {
+void AudioEffectStereoEnhance::set_time_pullout(float p_amount) {
- time_pullout=p_amount;
+ time_pullout = p_amount;
}
-float AudioEffectStereoEnhance::get_time_pullout() const {
+float AudioEffectStereoEnhance::get_time_pullout() const {
return time_pullout;
}
-void AudioEffectStereoEnhance::set_surround(float p_amount) {
+void AudioEffectStereoEnhance::set_surround(float p_amount) {
- surround=p_amount;
+ surround = p_amount;
}
-float AudioEffectStereoEnhance::get_surround() const {
+float AudioEffectStereoEnhance::get_surround() const {
return surround;
}
void AudioEffectStereoEnhance::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_pan_pullout","amount"),&AudioEffectStereoEnhance::set_pan_pullout);
- ClassDB::bind_method(D_METHOD("get_pan_pullout"),&AudioEffectStereoEnhance::get_pan_pullout);
+ ClassDB::bind_method(D_METHOD("set_pan_pullout", "amount"), &AudioEffectStereoEnhance::set_pan_pullout);
+ ClassDB::bind_method(D_METHOD("get_pan_pullout"), &AudioEffectStereoEnhance::get_pan_pullout);
- ClassDB::bind_method(D_METHOD("set_time_pullout","amount"),&AudioEffectStereoEnhance::set_time_pullout);
- ClassDB::bind_method(D_METHOD("get_time_pullout"),&AudioEffectStereoEnhance::get_time_pullout);
+ ClassDB::bind_method(D_METHOD("set_time_pullout", "amount"), &AudioEffectStereoEnhance::set_time_pullout);
+ ClassDB::bind_method(D_METHOD("get_time_pullout"), &AudioEffectStereoEnhance::get_time_pullout);
- ClassDB::bind_method(D_METHOD("set_surround","amount"),&AudioEffectStereoEnhance::set_surround);
- ClassDB::bind_method(D_METHOD("get_surround"),&AudioEffectStereoEnhance::get_surround);
+ ClassDB::bind_method(D_METHOD("set_surround", "amount"), &AudioEffectStereoEnhance::set_surround);
+ ClassDB::bind_method(D_METHOD("get_surround"), &AudioEffectStereoEnhance::get_surround);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"pan_pullout",PROPERTY_HINT_RANGE,"0,4,0.01"),"set_pan_pullout","get_pan_pullout");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"time_pullout_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),"set_time_pullout","get_time_pullout");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"surround",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_surround","get_surround");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pan_pullout", PROPERTY_HINT_RANGE, "0,4,0.01"), "set_pan_pullout", "get_pan_pullout");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_pullout_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_time_pullout", "get_time_pullout");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "surround", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_surround", "get_surround");
}
-AudioEffectStereoEnhance::AudioEffectStereoEnhance()
-{
- pan_pullout=1;
- time_pullout=0;
- surround=0;
+AudioEffectStereoEnhance::AudioEffectStereoEnhance() {
+ pan_pullout = 1;
+ time_pullout = 0;
+ surround = 0;
}
diff --git a/servers/audio/effects/audio_effect_stereo_enhance.h b/servers/audio/effects/audio_effect_stereo_enhance.h
index 5eef8a33b..21331692e 100644
--- a/servers/audio/effects/audio_effect_stereo_enhance.h
+++ b/servers/audio/effects/audio_effect_stereo_enhance.h
@@ -29,38 +29,34 @@
#ifndef AUDIOEFFECTSTEREOENHANCE_H
#define AUDIOEFFECTSTEREOENHANCE_H
-
#include "servers/audio/audio_effect.h"
class AudioEffectStereoEnhance;
class AudioEffectStereoEnhanceInstance : public AudioEffectInstance {
- GDCLASS(AudioEffectStereoEnhanceInstance,AudioEffectInstance)
-friend class AudioEffectStereoEnhance;
+ GDCLASS(AudioEffectStereoEnhanceInstance, AudioEffectInstance)
+ friend class AudioEffectStereoEnhance;
Ref<AudioEffectStereoEnhance> base;
enum {
- MAX_DELAY_MS=50
+ MAX_DELAY_MS = 50
};
float *delay_ringbuff;
unsigned int ringbuff_pos;
unsigned int ringbuff_mask;
-
public:
-
- virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count);
+ virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
~AudioEffectStereoEnhanceInstance();
};
-
class AudioEffectStereoEnhance : public AudioEffect {
- GDCLASS(AudioEffectStereoEnhance,AudioEffect)
+ GDCLASS(AudioEffectStereoEnhance, AudioEffect)
-friend class AudioEffectStereoEnhanceInstance;
+ friend class AudioEffectStereoEnhanceInstance;
float volume_db;
float pan_pullout;
@@ -68,11 +64,9 @@ friend class AudioEffectStereoEnhanceInstance;
float surround;
protected:
-
static void _bind_methods();
-public:
-
+public:
Ref<AudioEffectInstance> instance();
void set_pan_pullout(float p_amount);
diff --git a/servers/audio/effects/eq.cpp b/servers/audio/effects/eq.cpp
index 4b461e97b..857f81e85 100644
--- a/servers/audio/effects/eq.cpp
+++ b/servers/audio/effects/eq.cpp
@@ -30,135 +30,119 @@
// Author: reduzio@gmail.com (C) 2006
#include "eq.h"
-#include <math.h>
#include "error_macros.h"
#include "math_funcs.h"
+#include <math.h>
-#define POW2(v) ((v)*(v))
+#define POW2(v) ((v) * (v))
/* Helper */
- static int solve_quadratic(double a,double b,double c,double *r1, double *r2) {
-//solves quadractic and returns number of roots
+static int solve_quadratic(double a, double b, double c, double *r1, double *r2) {
+ //solves quadractic and returns number of roots
- double base=2*a;
+ double base = 2 * a;
if (base == 0.0f)
return 0;
- double squared=b*b-4*a*c;
- if (squared<0.0)
+ double squared = b * b - 4 * a * c;
+ if (squared < 0.0)
return 0;
- squared=sqrt(squared);
+ squared = sqrt(squared);
- *r1=(-b+squared)/base;
- *r2=(-b-squared)/base;
+ *r1 = (-b + squared) / base;
+ *r2 = (-b - squared) / base;
- if (*r1==*r2)
+ if (*r1 == *r2)
return 1;
else
return 2;
- }
+}
EQ::BandProcess::BandProcess() {
- c1=c2=c3=history.a1=history.a2=history.a3=0;
- history.b1=history.b2=history.b3=0;
+ c1 = c2 = c3 = history.a1 = history.a2 = history.a3 = 0;
+ history.b1 = history.b2 = history.b3 = 0;
}
void EQ::recalculate_band_coefficients() {
-#define BAND_LOG( m_f ) ( log((m_f)) / log(2.) )
+#define BAND_LOG(m_f) (log((m_f)) / log(2.))
- for (int i=0;i<band.size();i++) {
+ for (int i = 0; i < band.size(); i++) {
double octave_size;
- double frq=band[i].freq;
+ double frq = band[i].freq;
- if (i==0) {
+ if (i == 0) {
- octave_size=BAND_LOG(band[1].freq)-BAND_LOG(frq);
- } else if (i==(band.size()-1)) {
+ octave_size = BAND_LOG(band[1].freq) - BAND_LOG(frq);
+ } else if (i == (band.size() - 1)) {
- octave_size=BAND_LOG(frq)-BAND_LOG(band[i-1].freq);
+ octave_size = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq);
} else {
- double next=BAND_LOG(band[i+1].freq)-BAND_LOG(frq);
- double prev=BAND_LOG(frq)-BAND_LOG(band[i-1].freq);
- octave_size=(next+prev)/2.0;
+ double next = BAND_LOG(band[i + 1].freq) - BAND_LOG(frq);
+ double prev = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq);
+ octave_size = (next + prev) / 2.0;
}
+ double frq_l = round(frq / pow(2.0, octave_size / 2.0));
+ double side_gain2 = POW2(Math_SQRT12);
+ double th = 2.0 * Math_PI * frq / mix_rate;
+ double th_l = 2.0 * Math_PI * frq_l / mix_rate;
- double frq_l=round(frq/pow(2.0,octave_size/2.0));
-
-
+ double c2a = side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) + side_gain2 - POW2(sin(th_l));
- double side_gain2=POW2(Math_SQRT12);
- double th=2.0*Math_PI*frq/mix_rate;
- double th_l=2.0*Math_PI*frq_l/mix_rate;
+ double c2b = 2.0 * side_gain2 * POW2(cos(th_l)) + side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) - side_gain2 + POW2(sin(th_l));
- double c2a=side_gain2 * POW2(cos(th))
- - 2.0 * side_gain2 * cos(th_l) * cos(th)
- + side_gain2
- - POW2(sin(th_l));
-
- double c2b=2.0 * side_gain2 * POW2(cos(th_l))
- + side_gain2 * POW2(cos(th))
- - 2.0 * side_gain2 * cos(th_l) * cos(th)
- - side_gain2
- + POW2(sin(th_l));
-
- double c2c=0.25 * side_gain2 * POW2(cos(th))
- - 0.5 * side_gain2 * cos(th_l) * cos(th)
- + 0.25 * side_gain2
- - 0.25 * POW2(sin(th_l));
+ double c2c = 0.25 * side_gain2 * POW2(cos(th)) - 0.5 * side_gain2 * cos(th_l) * cos(th) + 0.25 * side_gain2 - 0.25 * POW2(sin(th_l));
//printf("band %i, precoefs = %f,%f,%f\n",i,c2a,c2b,c2c);
- double r1,r2; //roots
- int roots=solve_quadratic(c2a,c2b,c2c,&r1,&r2);
+ double r1, r2; //roots
+ int roots = solve_quadratic(c2a, c2b, c2c, &r1, &r2);
- ERR_CONTINUE( roots==0 );
+ ERR_CONTINUE(roots == 0);
- band[i].c1=2.0 * ((0.5-r1)/2.0);
- band[i].c2=2.0 * r1;
- band[i].c3=2.0 * (0.5+r1) * cos(th);
+ band[i].c1 = 2.0 * ((0.5 - r1) / 2.0);
+ band[i].c2 = 2.0 * r1;
+ band[i].c3 = 2.0 * (0.5 + r1) * cos(th);
//printf("band %i, coefs = %f,%f,%f\n",i,(float)bands[i].c1,(float)bands[i].c2,(float)bands[i].c3);
-
}
}
void EQ::set_preset_band_mode(Preset p_preset) {
-
band.clear();
-#define PUSH_BANDS(m_bands) \
- for (int i=0;i<m_bands;i++) { \
- Band b; \
- b.freq=bands[i];\
- band.push_back(b);\
+#define PUSH_BANDS(m_bands) \
+ for (int i = 0; i < m_bands; i++) { \
+ Band b; \
+ b.freq = bands[i]; \
+ band.push_back(b); \
}
switch (p_preset) {
case PRESET_6_BANDS: {
- static const double bands[] = { 32 , 100 , 320 , 1e3, 3200, 10e3 };
+ static const double bands[] = { 32, 100, 320, 1e3, 3200, 10e3 };
PUSH_BANDS(6);
} break;
case PRESET_8_BANDS: {
- static const double bands[] = { 32,72,192,512,1200,3000,7500,16e3 };
+ static const double bands[] = { 32, 72, 192, 512, 1200, 3000, 7500, 16e3 };
PUSH_BANDS(8);
} break;
case PRESET_10_BANDS: {
- static const double bands[] = { 31.25, 62.5, 125 , 250 , 500 , 1e3, 2e3, 4e3, 8e3, 16e3 };
+ static const double bands[] = { 31.25, 62.5, 125, 250, 500, 1e3, 2e3, 4e3, 8e3, 16e3 };
PUSH_BANDS(10);
@@ -166,17 +150,16 @@ void EQ::set_preset_band_mode(Preset p_preset) {
case PRESET_21_BANDS: {
- static const double bands[] = { 22 , 32 , 44 , 63 , 90 , 125 , 175 , 250 , 350 , 500 , 700 , 1e3, 1400 , 2e3, 2800 , 4e3, 5600 , 8e3, 11e3, 16e3, 22e3 };
+ static const double bands[] = { 22, 32, 44, 63, 90, 125, 175, 250, 350, 500, 700, 1e3, 1400, 2e3, 2800, 4e3, 5600, 8e3, 11e3, 16e3, 22e3 };
PUSH_BANDS(21);
} break;
case PRESET_31_BANDS: {
- static const double bands[] = { 20, 25, 31.5, 40 , 50 , 63 , 80 , 100 , 125 , 160 , 200 , 250 , 315 , 400 , 500 , 630 , 800 , 1e3 , 1250 , 1600 , 2e3, 2500 , 3150 , 4e3, 5e3, 6300 , 8e3, 10e3, 12500 , 16e3, 20e3 };
+ static const double bands[] = { 20, 25, 31.5, 40, 50, 63, 80, 100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1e3, 1250, 1600, 2e3, 2500, 3150, 4e3, 5e3, 6300, 8e3, 10e3, 12500, 16e3, 20e3 };
PUSH_BANDS(31);
} break;
-
};
recalculate_band_coefficients();
@@ -188,52 +171,42 @@ int EQ::get_band_count() const {
}
float EQ::get_band_frequency(int p_band) {
- ERR_FAIL_INDEX_V(p_band,band.size(),0);
+ ERR_FAIL_INDEX_V(p_band, band.size(), 0);
return band[p_band].freq;
}
-void EQ::set_bands(const Vector<float>& p_bands) {
+void EQ::set_bands(const Vector<float> &p_bands) {
band.resize(p_bands.size());
- for (int i=0;i<p_bands.size();i++) {
+ for (int i = 0; i < p_bands.size(); i++) {
- band[i].freq=p_bands[i];
+ band[i].freq = p_bands[i];
}
recalculate_band_coefficients();
-
}
void EQ::set_mix_rate(float p_mix_rate) {
- mix_rate=p_mix_rate;
+ mix_rate = p_mix_rate;
recalculate_band_coefficients();
}
EQ::BandProcess EQ::get_band_processor(int p_band) const {
-
EQ::BandProcess band_proc;
- ERR_FAIL_INDEX_V(p_band,band.size(),band_proc);
+ ERR_FAIL_INDEX_V(p_band, band.size(), band_proc);
- band_proc.c1=band[p_band].c1;
- band_proc.c2=band[p_band].c2;
- band_proc.c3=band[p_band].c3;
+ band_proc.c1 = band[p_band].c1;
+ band_proc.c2 = band[p_band].c2;
+ band_proc.c3 = band[p_band].c3;
return band_proc;
-
-
}
-
-EQ::EQ()
-{
- mix_rate=44100;
+EQ::EQ() {
+ mix_rate = 44100;
}
-
-EQ::~EQ()
-{
+EQ::~EQ() {
}
-
-
diff --git a/servers/audio/effects/eq.h b/servers/audio/effects/eq.h
index 1a568ee21..a6d471cc4 100644
--- a/servers/audio/effects/eq.h
+++ b/servers/audio/effects/eq.h
@@ -32,18 +32,15 @@
#ifndef EQ_FILTER_H
#define EQ_FILTER_H
-
#include "typedefs.h"
#include "vector.h"
-
/**
@author Juan Linietsky
*/
class EQ {
public:
-
enum Preset {
PRESET_6_BANDS,
@@ -53,21 +50,18 @@ public:
PRESET_31_BANDS
};
-
-
class BandProcess {
- friend class EQ;
- float c1,c2,c3;
+ friend class EQ;
+ float c1, c2, c3;
struct History {
- float a1,a2,a3;
- float b1,b2,b3;
+ float a1, a2, a3;
+ float b1, b2, b3;
} history;
public:
-
- inline void process_one(float & p_data);
+ inline void process_one(float &p_data);
BandProcess();
};
@@ -76,7 +70,7 @@ private:
struct Band {
float freq;
- float c1,c2,c3;
+ float c1, c2, c3;
};
Vector<Band> band;
@@ -86,41 +80,32 @@ private:
void recalculate_band_coefficients();
public:
-
-
void set_mix_rate(float p_mix_rate);
int get_band_count() const;
void set_preset_band_mode(Preset p_preset);
- void set_bands(const Vector<float>& p_bands);
+ void set_bands(const Vector<float> &p_bands);
BandProcess get_band_processor(int p_band) const;
float get_band_frequency(int p_band);
EQ();
~EQ();
-
};
-
/* Inline Function */
-inline void EQ::BandProcess::process_one(float & p_data) {
+inline void EQ::BandProcess::process_one(float &p_data) {
+ history.a1 = p_data;
- history.a1=p_data;
-
- history.b1= c1 * ( history.a1 - history.a3 )
- + c3 * history.b2
- - c2 * history.b3;
+ history.b1 = c1 * (history.a1 - history.a3) + c3 * history.b2 - c2 * history.b3;
p_data = history.b1;
- history.a3=history.a2;
- history.a2=history.a1;
- history.b3=history.b2;
- history.b2=history.b1;
-
+ history.a3 = history.a2;
+ history.a2 = history.a1;
+ history.b3 = history.b2;
+ history.b2 = history.b1;
}
-
#endif
diff --git a/servers/audio/effects/reverb.cpp b/servers/audio/effects/reverb.cpp
index bc3212201..6462977d7 100644
--- a/servers/audio/effects/reverb.cpp
+++ b/servers/audio/effects/reverb.cpp
@@ -30,11 +30,10 @@
// Author: Juan Linietsky <reduzio@gmail.com>, (C) 2006
#include "reverb.h"
-#include <math.h>
#include "math_funcs.h"
+#include <math.h>
-
-const float Reverb::comb_tunings[MAX_COMBS]={
+const float Reverb::comb_tunings[MAX_COMBS] = {
//freeverb comb tunings
0.025306122448979593,
0.026938775510204082,
@@ -46,7 +45,7 @@ const float Reverb::comb_tunings[MAX_COMBS]={
0.036666666666666667
};
-const float Reverb::allpass_tunings[MAX_ALLPASS]={
+const float Reverb::allpass_tunings[MAX_ALLPASS] = {
//freeverb allpass tunings
0.0051020408163265302,
0.007732426303854875,
@@ -54,76 +53,72 @@ const float Reverb::allpass_tunings[MAX_ALLPASS]={
0.012607709750566893
};
+void Reverb::process(float *p_src, float *p_dst, int p_frames) {
+ if (p_frames > INPUT_BUFFER_MAX_SIZE)
+ p_frames = INPUT_BUFFER_MAX_SIZE;
-void Reverb::process(float *p_src,float *p_dst,int p_frames) {
-
- if (p_frames>INPUT_BUFFER_MAX_SIZE)
- p_frames=INPUT_BUFFER_MAX_SIZE;
-
- int predelay_frames=lrint((params.predelay/1000.0)*params.mix_rate);
- if (predelay_frames<10)
- predelay_frames=10;
- if (predelay_frames>=echo_buffer_size)
- predelay_frames=echo_buffer_size-1;
+ int predelay_frames = lrint((params.predelay / 1000.0) * params.mix_rate);
+ if (predelay_frames < 10)
+ predelay_frames = 10;
+ if (predelay_frames >= echo_buffer_size)
+ predelay_frames = echo_buffer_size - 1;
- for (int i=0;i<p_frames;i++) {
+ for (int i = 0; i < p_frames; i++) {
- if (echo_buffer_pos>=echo_buffer_size)
- echo_buffer_pos=0;
+ if (echo_buffer_pos >= echo_buffer_size)
+ echo_buffer_pos = 0;
- int read_pos=echo_buffer_pos-predelay_frames;
- while (read_pos<0)
- read_pos+=echo_buffer_size;
+ int read_pos = echo_buffer_pos - predelay_frames;
+ while (read_pos < 0)
+ read_pos += echo_buffer_size;
- float in=undenormalise(echo_buffer[read_pos]*params.predelay_fb+p_src[i]);
+ float in = undenormalise(echo_buffer[read_pos] * params.predelay_fb + p_src[i]);
- echo_buffer[echo_buffer_pos]=in;
+ echo_buffer[echo_buffer_pos] = in;
- input_buffer[i]=in;
+ input_buffer[i] = in;
- p_dst[i]=0; //take the chance and clear this
+ p_dst[i] = 0; //take the chance and clear this
echo_buffer_pos++;
}
- if (params.hpf>0) {
- float hpaux=expf(-2.0*Math_PI*params.hpf*6000/params.mix_rate);
- float hp_a1=(1.0+hpaux)/2.0;
- float hp_a2=-(1.0+hpaux)/2.0;
- float hp_b1=hpaux;
+ if (params.hpf > 0) {
+ float hpaux = expf(-2.0 * Math_PI * params.hpf * 6000 / params.mix_rate);
+ float hp_a1 = (1.0 + hpaux) / 2.0;
+ float hp_a2 = -(1.0 + hpaux) / 2.0;
+ float hp_b1 = hpaux;
- for (int i=0;i<p_frames;i++) {
+ for (int i = 0; i < p_frames; i++) {
- float in=input_buffer[i];
- input_buffer[i]=in*hp_a1+hpf_h1*hp_a2+hpf_h2*hp_b1;
- hpf_h2=input_buffer[i];
- hpf_h1=in;
+ float in = input_buffer[i];
+ input_buffer[i] = in * hp_a1 + hpf_h1 * hp_a2 + hpf_h2 * hp_b1;
+ hpf_h2 = input_buffer[i];
+ hpf_h1 = in;
}
}
- for (int i=0;i<MAX_COMBS;i++) {
+ for (int i = 0; i < MAX_COMBS; i++) {
- Comb &c=comb[i];
+ Comb &c = comb[i];
- int size_limit=c.size-lrintf((float)c.extra_spread_frames*(1.0-params.extra_spread));
- for (int j=0;j<p_frames;j++) {
+ int size_limit = c.size - lrintf((float)c.extra_spread_frames * (1.0 - params.extra_spread));
+ for (int j = 0; j < p_frames; j++) {
- if (c.pos>=size_limit) //reset this now just in case
- c.pos=0;
+ if (c.pos >= size_limit) //reset this now just in case
+ c.pos = 0;
- float out=undenormalise(c.buffer[c.pos]*c.feedback);
- out=out*(1.0-c.damp)+c.damp_h*c.damp; //lowpass
- c.damp_h=out;
- c.buffer[c.pos]=input_buffer[j]+out;
- p_dst[j]+=out;
+ float out = undenormalise(c.buffer[c.pos] * c.feedback);
+ out = out * (1.0 - c.damp) + c.damp_h * c.damp; //lowpass
+ c.damp_h = out;
+ c.buffer[c.pos] = input_buffer[j] + out;
+ p_dst[j] += out;
c.pos++;
}
-
}
-
- static const float allpass_feedback=0.7;
+ static const float allpass_feedback = 0.7;
/* this one works, but the other version is just nicer....
int ap_size_limit[MAX_ALLPASS];
@@ -158,170 +153,154 @@ void Reverb::process(float *p_src,float *p_dst,int p_frames) {
}
*/
- for (int i=0;i<MAX_ALLPASS;i++) {
+ for (int i = 0; i < MAX_ALLPASS; i++) {
- AllPass &a=allpass[i];
- int size_limit=a.size-lrintf((float)a.extra_spread_frames*(1.0-params.extra_spread));
+ AllPass &a = allpass[i];
+ int size_limit = a.size - lrintf((float)a.extra_spread_frames * (1.0 - params.extra_spread));
- for (int j=0;j<p_frames;j++) {
+ for (int j = 0; j < p_frames; j++) {
- if (a.pos>=size_limit)
- a.pos=0;
+ if (a.pos >= size_limit)
+ a.pos = 0;
- float aux=a.buffer[a.pos];
- a.buffer[a.pos]=undenormalise(allpass_feedback*aux+p_dst[j]);
- p_dst[j]=aux-allpass_feedback*a.buffer[a.pos];
+ float aux = a.buffer[a.pos];
+ a.buffer[a.pos] = undenormalise(allpass_feedback * aux + p_dst[j]);
+ p_dst[j] = aux - allpass_feedback * a.buffer[a.pos];
a.pos++;
-
}
}
- static const float wet_scale=0.6;
-
- for (int i=0;i<p_frames;i++) {
+ static const float wet_scale = 0.6;
+ for (int i = 0; i < p_frames; i++) {
- p_dst[i]=p_dst[i]*params.wet*wet_scale+p_src[i]*params.dry;
+ p_dst[i] = p_dst[i] * params.wet * wet_scale + p_src[i] * params.dry;
}
-
}
-
void Reverb::set_room_size(float p_size) {
- params.room_size=p_size;
+ params.room_size = p_size;
update_parameters();
-
}
void Reverb::set_damp(float p_damp) {
- params.damp=p_damp;
+ params.damp = p_damp;
update_parameters();
-
}
void Reverb::set_wet(float p_wet) {
- params.wet=p_wet;
-
+ params.wet = p_wet;
}
void Reverb::set_dry(float p_dry) {
- params.dry=p_dry;
-
+ params.dry = p_dry;
}
void Reverb::set_predelay(float p_predelay) {
- params.predelay=p_predelay;
+ params.predelay = p_predelay;
}
void Reverb::set_predelay_feedback(float p_predelay_fb) {
- params.predelay_fb=p_predelay_fb;
-
+ params.predelay_fb = p_predelay_fb;
}
void Reverb::set_highpass(float p_frq) {
- if (p_frq>1)
- p_frq=1;
- if (p_frq<0)
- p_frq=0;
- params.hpf=p_frq;
+ if (p_frq > 1)
+ p_frq = 1;
+ if (p_frq < 0)
+ p_frq = 0;
+ params.hpf = p_frq;
}
void Reverb::set_extra_spread(float p_spread) {
- params.extra_spread=p_spread;
-
+ params.extra_spread = p_spread;
}
-
void Reverb::set_mix_rate(float p_mix_rate) {
- params.mix_rate=p_mix_rate;
+ params.mix_rate = p_mix_rate;
configure_buffers();
}
void Reverb::set_extra_spread_base(float p_sec) {
- params.extra_spread_base=p_sec;
+ params.extra_spread_base = p_sec;
configure_buffers();
}
-
void Reverb::configure_buffers() {
clear_buffers(); //clear if necesary
- for (int i=0;i<MAX_COMBS;i++) {
-
- Comb &c=comb[i];
+ for (int i = 0; i < MAX_COMBS; i++) {
+ Comb &c = comb[i];
- c.extra_spread_frames=lrint(params.extra_spread_base*params.mix_rate);
+ c.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate);
- int len=lrint(comb_tunings[i]*params.mix_rate)+c.extra_spread_frames;
- if (len<5)
- len=5; //may this happen?
-
- c.buffer = memnew_arr(float,len);
- c.pos=0;
- for (int j=0;j<len;j++)
- c.buffer[j]=0;
- c.size=len;
+ int len = lrint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames;
+ if (len < 5)
+ len = 5; //may this happen?
+ c.buffer = memnew_arr(float, len);
+ c.pos = 0;
+ for (int j = 0; j < len; j++)
+ c.buffer[j] = 0;
+ c.size = len;
}
- for (int i=0;i<MAX_ALLPASS;i++) {
+ for (int i = 0; i < MAX_ALLPASS; i++) {
- AllPass &a=allpass[i];
+ AllPass &a = allpass[i];
- a.extra_spread_frames=lrint(params.extra_spread_base*params.mix_rate);
+ a.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate);
- int len=lrint(allpass_tunings[i]*params.mix_rate)+a.extra_spread_frames;
- if (len<5)
- len=5; //may this happen?
+ int len = lrint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames;
+ if (len < 5)
+ len = 5; //may this happen?
- a.buffer = memnew_arr(float,len);
- a.pos=0;
- for (int j=0;j<len;j++)
- a.buffer[j]=0;
- a.size=len;
+ a.buffer = memnew_arr(float, len);
+ a.pos = 0;
+ for (int j = 0; j < len; j++)
+ a.buffer[j] = 0;
+ a.size = len;
}
- echo_buffer_size=(int)(((float)MAX_ECHO_MS/1000.0)*params.mix_rate+1.0);
- echo_buffer = memnew_arr(float,echo_buffer_size);
- for (int i=0;i<echo_buffer_size;i++) {
+ echo_buffer_size = (int)(((float)MAX_ECHO_MS / 1000.0) * params.mix_rate + 1.0);
+ echo_buffer = memnew_arr(float, echo_buffer_size);
+ for (int i = 0; i < echo_buffer_size; i++) {
- echo_buffer[i]=0;
+ echo_buffer[i] = 0;
}
- echo_buffer_pos=0;
+ echo_buffer_pos = 0;
}
-
void Reverb::update_parameters() {
//more freeverb derived constants
static const float room_scale = 0.28f;
static const float room_offset = 0.7f;
- for (int i=0;i<MAX_COMBS;i++) {
+ for (int i = 0; i < MAX_COMBS; i++) {
- Comb &c=comb[i];
- c.feedback=room_offset+params.room_size*room_scale;
- if (c.feedback<room_offset)
- c.feedback=room_offset;
- else if (c.feedback>(room_offset+room_scale))
- c.feedback=(room_offset+room_scale);
+ Comb &c = comb[i];
+ c.feedback = room_offset + params.room_size * room_scale;
+ if (c.feedback < room_offset)
+ c.feedback = room_offset;
+ else if (c.feedback > (room_offset + room_scale))
+ c.feedback = (room_offset + room_scale);
- float auxdmp=params.damp/2.0+0.5; //only half the range (0.5 .. 1.0 is enough)
- auxdmp*=auxdmp;
+ float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough)
+ auxdmp *= auxdmp;
- c.damp=expf(-2.0*Math_PI*auxdmp*10000/params.mix_rate); // 0 .. 10khz
+ c.damp = expf(-2.0 * Math_PI * auxdmp * 10000 / params.mix_rate); // 0 .. 10khz
}
-
}
void Reverb::clear_buffers() {
@@ -329,55 +308,47 @@ void Reverb::clear_buffers() {
if (echo_buffer)
memdelete_arr(echo_buffer);
- for (int i=0;i<MAX_COMBS;i++) {
+ for (int i = 0; i < MAX_COMBS; i++) {
if (comb[i].buffer)
memdelete_arr(comb[i].buffer);
- comb[i].buffer=0;
-
+ comb[i].buffer = 0;
}
- for (int i=0;i<MAX_ALLPASS;i++) {
+ for (int i = 0; i < MAX_ALLPASS; i++) {
if (allpass[i].buffer)
memdelete_arr(allpass[i].buffer);
- allpass[i].buffer=0;
+ allpass[i].buffer = 0;
}
-
}
Reverb::Reverb() {
- params.room_size=0.8;
- params.damp=0.5;
- params.dry=1.0;
- params.wet=0.0;
- params.mix_rate=44100;
- params.extra_spread_base=0;
- params.extra_spread=1.0;
- params.predelay=150;
- params.predelay_fb=0.4;
- params.hpf=0;
- hpf_h1=0;
- hpf_h2=0;
+ params.room_size = 0.8;
+ params.damp = 0.5;
+ params.dry = 1.0;
+ params.wet = 0.0;
+ params.mix_rate = 44100;
+ params.extra_spread_base = 0;
+ params.extra_spread = 1.0;
+ params.predelay = 150;
+ params.predelay_fb = 0.4;
+ params.hpf = 0;
+ hpf_h1 = 0;
+ hpf_h2 = 0;
-
- input_buffer=memnew_arr(float,INPUT_BUFFER_MAX_SIZE);
- echo_buffer=0;
+ input_buffer = memnew_arr(float, INPUT_BUFFER_MAX_SIZE);
+ echo_buffer = 0;
configure_buffers();
update_parameters();
-
-
}
-
Reverb::~Reverb() {
memdelete_arr(input_buffer);
clear_buffers();
}
-
-
diff --git a/servers/audio/effects/reverb.h b/servers/audio/effects/reverb.h
index f0a0466f8..33f11e59f 100644
--- a/servers/audio/effects/reverb.h
+++ b/servers/audio/effects/reverb.h
@@ -32,27 +32,26 @@
#ifndef REVERB_H
#define REVERB_H
-#include "typedefs.h"
-#include "os/memory.h"
#include "audio_frame.h"
+#include "os/memory.h"
+#include "typedefs.h"
class Reverb {
public:
enum {
- INPUT_BUFFER_MAX_SIZE=1024,
+ INPUT_BUFFER_MAX_SIZE = 1024,
};
+
private:
enum {
- MAX_COMBS=8,
- MAX_ALLPASS=4,
- MAX_ECHO_MS=500
+ MAX_COMBS = 8,
+ MAX_ALLPASS = 4,
+ MAX_ECHO_MS = 500
};
-
-
static const float comb_tunings[MAX_COMBS];
static const float allpass_tunings[MAX_ALLPASS];
@@ -66,7 +65,13 @@ private:
int pos;
int extra_spread_frames;
- Comb() { size=0; buffer=0; feedback=0; damp_h=0; pos=0; }
+ Comb() {
+ size = 0;
+ buffer = 0;
+ feedback = 0;
+ damp_h = 0;
+ pos = 0;
+ }
};
struct AllPass {
@@ -75,7 +80,11 @@ private:
float *buffer;
int pos;
int extra_spread_frames;
- AllPass() { size=0; buffer=0; pos=0; }
+ AllPass() {
+ size = 0;
+ buffer = 0;
+ pos = 0;
+ }
};
Comb comb[MAX_COMBS];
@@ -85,8 +94,7 @@ private:
int echo_buffer_size;
int echo_buffer_pos;
- float hpf_h1,hpf_h2;
-
+ float hpf_h1, hpf_h2;
struct Parameters {
@@ -105,8 +113,8 @@ private:
void configure_buffers();
void update_parameters();
void clear_buffers();
-public:
+public:
void set_room_size(float p_size);
void set_damp(float p_damp);
void set_wet(float p_wet);
@@ -118,14 +126,11 @@ public:
void set_extra_spread(float p_spread);
void set_extra_spread_base(float p_sec);
- void process(float *p_src,float *p_dst,int p_frames);
+ void process(float *p_src, float *p_dst, int p_frames);
Reverb();
~Reverb();
-
};
-
-
#endif
diff --git a/servers/audio/reverb_sw.cpp b/servers/audio/reverb_sw.cpp
index 5e02f3767..ea89f7e19 100644
--- a/servers/audio/reverb_sw.cpp
+++ b/servers/audio/reverb_sw.cpp
@@ -27,223 +27,217 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "reverb_sw.h"
-#include "stdlib.h"
#include "print_string.h"
-#define SETMIN( x, y ) (x) = MIN ( (x), (y) )
-#define rangeloop( c, min, max ) \
- for ( (c) = (min) ; (c) < (max) ; (c)++ )
-
-#define ABSDIFF(x, y)\
- ( ((x) < (y)) ? ((y) - (x)) : ((x) - (y)) )
+#include "stdlib.h"
+#define SETMIN(x, y) (x) = MIN((x), (y))
+#define rangeloop(c, min, max) \
+ for ((c) = (min); (c) < (max); (c)++)
+#define ABSDIFF(x, y) \
+ (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
#ifdef bleh_MSC_VER
#if _MSC_VER >= 1400
- _FORCE_INLINE_ int32_tMULSHIFT_S32 (
+_FORCE_INLINE_ int32_tMULSHIFT_S32(
int32_t Factor1,
int32_t Factor2,
- uint8_t Bits
- ) {
+ uint8_t Bits) {
- return __ll_rshift (
- __emul ( Factor1, Factor2 ),
- Bits
- );
- }
+ return __ll_rshift(
+ __emul(Factor1, Factor2),
+ Bits);
+}
#endif
#else
-#define MULSHIFT_S32( Factor1, Factor2, Bits )\
- ( (int) (( (int64_t)(Factor1) * (Factor2) ) >> (Bits)) )
+#define MULSHIFT_S32(Factor1, Factor2, Bits) \
+ ((int)(((int64_t)(Factor1) * (Factor2)) >> (Bits)))
#endif
-
-
struct ReverbParamsSW {
- unsigned int BufferSize; // Required buffer size
- int gLPF; // Coefficient
- int gEcho0; // Coefficient
- int gEcho1; // Coefficient
- int gEcho2; // Coefficient
- int gEcho3; // Coefficient
- int gWall; // Coefficient
- int gReva; // Coefficient
- int gRevb; // Coefficient
- int gInputL; // Coefficient
- int gInputR; // Coefficient
- unsigned int nRevaOldL; // Offset
- unsigned int nRevaOldR; // Offset
- unsigned int nRevbOldL; // Offset
- unsigned int nRevbOldR; // Offset
- unsigned int nLwlNew; // Offset
- unsigned int nRwrNew; // Offset
- unsigned int nEcho0L; // Offset
- unsigned int nEcho0R; // Offset
- unsigned int nEcho1L; // Offset
- unsigned int nEcho1R; // Offset
- unsigned int nLwlOld; // Offset
- unsigned int nRwrOld; // Offset
- unsigned int nLwrNew; // Offset
- unsigned int nRwlNew; // Offset
- unsigned int nEcho2L; // Offset
- unsigned int nEcho2R; // Offset
- unsigned int nEcho3L; // Offset
- unsigned int nEcho3R; // Offset
- unsigned int nLwrOld; // Offset
- unsigned int nRwlOld; // Offset
- unsigned int nRevaNewL; // Offset
- unsigned int nRevaNewR; // Offset
- unsigned int nRevbNewL; // Offset
- unsigned int nRevbNewR; // Offset
+ unsigned int BufferSize; // Required buffer size
+ int gLPF; // Coefficient
+ int gEcho0; // Coefficient
+ int gEcho1; // Coefficient
+ int gEcho2; // Coefficient
+ int gEcho3; // Coefficient
+ int gWall; // Coefficient
+ int gReva; // Coefficient
+ int gRevb; // Coefficient
+ int gInputL; // Coefficient
+ int gInputR; // Coefficient
+ unsigned int nRevaOldL; // Offset
+ unsigned int nRevaOldR; // Offset
+ unsigned int nRevbOldL; // Offset
+ unsigned int nRevbOldR; // Offset
+ unsigned int nLwlNew; // Offset
+ unsigned int nRwrNew; // Offset
+ unsigned int nEcho0L; // Offset
+ unsigned int nEcho0R; // Offset
+ unsigned int nEcho1L; // Offset
+ unsigned int nEcho1R; // Offset
+ unsigned int nLwlOld; // Offset
+ unsigned int nRwrOld; // Offset
+ unsigned int nLwrNew; // Offset
+ unsigned int nRwlNew; // Offset
+ unsigned int nEcho2L; // Offset
+ unsigned int nEcho2R; // Offset
+ unsigned int nEcho3L; // Offset
+ unsigned int nEcho3R; // Offset
+ unsigned int nLwrOld; // Offset
+ unsigned int nRwlOld; // Offset
+ unsigned int nRevaNewL; // Offset
+ unsigned int nRevaNewR; // Offset
+ unsigned int nRevbNewL; // Offset
+ unsigned int nRevbNewR; // Offset
};
static ReverbParamsSW reverb_params_Room = {
- 0x26C0/2,
+ 0x26C0 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x6D80, 0x54B8, -0x4130, 0x0000, 0x0000, -0x4580,
+ 0x6D80, 0x54B8, -0x4130, 0x0000, 0x0000, -0x4580,
//gReva gRevb gInputL gInputR
- 0x5800, 0x5300, -0x8000, -0x8000,
+ 0x5800, 0x5300, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x01B4 - 0x007D, 0x0136 - 0x007D, 0x00B8 - 0x005B, 0x005C - 0x005B,
+ 0x01B4 - 0x007D, 0x0136 - 0x007D, 0x00B8 - 0x005B, 0x005C - 0x005B,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x04D6, 0x0333, 0x03F0, 0x0227, 0x0374, 0x01EF,
+ 0x04D6, 0x0333, 0x03F0, 0x0227, 0x0374, 0x01EF,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x0334, 0x01B5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0334, 0x01B5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x0000, 0x0000, 0x01B4, 0x0136, 0x00B8, 0x005C
+ 0x0000, 0x0000, 0x01B4, 0x0136, 0x00B8, 0x005C
};
static ReverbParamsSW reverb_params_StudioSmall = {
- 0x1F40/2,
+ 0x1F40 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x70F0, 0x4FA8, -0x4320, 0x4410, -0x3F10, -0x6400,
+ 0x70F0, 0x4FA8, -0x4320, 0x4410, -0x3F10, -0x6400,
//gReva gRevb gInputL gInputR
- 0x5280, 0x4EC0, -0x8000, -0x8000,
+ 0x5280, 0x4EC0, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x00B4 - 0x0033, 0x0080 - 0x0033, 0x004C - 0x0025, 0x0026 - 0x0025,
+ 0x00B4 - 0x0033, 0x0080 - 0x0033, 0x004C - 0x0025, 0x0026 - 0x0025,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x03E4, 0x031B, 0x03A4, 0x02AF, 0x0372, 0x0266,
+ 0x03E4, 0x031B, 0x03A4, 0x02AF, 0x0372, 0x0266,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x031C, 0x025D, 0x025C, 0x018E, 0x022F, 0x0135, 0x01D2, 0x00B7,
+ 0x031C, 0x025D, 0x025C, 0x018E, 0x022F, 0x0135, 0x01D2, 0x00B7,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x018F, 0x00B5, 0x00B4, 0x0080, 0x004C, 0x0026
+ 0x018F, 0x00B5, 0x00B4, 0x0080, 0x004C, 0x0026
};
static ReverbParamsSW reverb_params_StudioMedium = {
- 0x4840/2,
+ 0x4840 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x4B40,
+ 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x4B40,
//gReva gRevb gInputL gInputR
- 0x5280, 0x4EC0, -0x8000, -0x8000,
+ 0x5280, 0x4EC0, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x0264 - 0x00B1, 0x01B2 - 0x00B1, 0x0100 - 0x007F, 0x0080 - 0x007F,
+ 0x0264 - 0x00B1, 0x01B2 - 0x00B1, 0x0100 - 0x007F, 0x0080 - 0x007F,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x0904, 0x076B, 0x0824, 0x065F, 0x07A2, 0x0616,
+ 0x0904, 0x076B, 0x0824, 0x065F, 0x07A2, 0x0616,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x076C, 0x05ED, 0x05EC, 0x042E, 0x050F, 0x0305, 0x0462, 0x02B7,
+ 0x076C, 0x05ED, 0x05EC, 0x042E, 0x050F, 0x0305, 0x0462, 0x02B7,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x042F, 0x0265, 0x0264, 0x01B2, 0x0100, 0x0080
+ 0x042F, 0x0265, 0x0264, 0x01B2, 0x0100, 0x0080
};
static ReverbParamsSW reverb_params_StudioLarge = {
- 0x6FE0/2,
+ 0x6FE0 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x6F60, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x5980,
+ 0x6F60, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x5980,
//gReva gRevb gInputL gInputR
- 0x5680, 0x52C0, -0x8000, -0x8000,
+ 0x5680, 0x52C0, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x031C - 0x00E3, 0x0238 - 0x00E3, 0x0154 - 0x00A9, 0x00AA - 0x00A9,
+ 0x031C - 0x00E3, 0x0238 - 0x00E3, 0x0154 - 0x00A9, 0x00AA - 0x00A9,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x0DFB, 0x0B58, 0x0D09, 0x0A3C, 0x0BD9, 0x0973,
+ 0x0DFB, 0x0B58, 0x0D09, 0x0A3C, 0x0BD9, 0x0973,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x0B59, 0x08DA, 0x08D9, 0x05E9, 0x07EC, 0x04B0, 0x06EF, 0x03D2,
+ 0x0B59, 0x08DA, 0x08D9, 0x05E9, 0x07EC, 0x04B0, 0x06EF, 0x03D2,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x05EA, 0x031D, 0x031C, 0x0238, 0x0154, 0x00AA
+ 0x05EA, 0x031D, 0x031C, 0x0238, 0x0154, 0x00AA
};
static ReverbParamsSW reverb_params_Hall = {
- 0xADE0/2,
+ 0xADE0 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x6000, 0x5000, 0x4C00, -0x4800, -0x4400, -0x4000,
+ 0x6000, 0x5000, 0x4C00, -0x4800, -0x4400, -0x4000,
//gReva gRevb gInputL gInputR
- 0x6000, 0x5C00, -0x8000, -0x8000,
+ 0x6000, 0x5C00, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x05C0 - 0x01A5, 0x041A - 0x01A5, 0x0274 - 0x0139, 0x013A - 0x0139,
+ 0x05C0 - 0x01A5, 0x041A - 0x01A5, 0x0274 - 0x0139, 0x013A - 0x0139,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x15BA, 0x11BB, 0x14C2, 0x10BD, 0x11BC, 0x0DC1,
+ 0x15BA, 0x11BB, 0x14C2, 0x10BD, 0x11BC, 0x0DC1,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x11C0, 0x0DC3, 0x0DC0, 0x09C1, 0x0BC4, 0x07C1, 0x0A00, 0x06CD,
+ 0x11C0, 0x0DC3, 0x0DC0, 0x09C1, 0x0BC4, 0x07C1, 0x0A00, 0x06CD,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x09C2, 0x05C1, 0x05C0, 0x041A, 0x0274, 0x013A
+ 0x09C2, 0x05C1, 0x05C0, 0x041A, 0x0274, 0x013A
};
static ReverbParamsSW reverb_params_SpaceEcho = {
- 0xF6C0/2,
+ 0xF6C0 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x7E00, 0x5000, -0x4C00, -0x5000, 0x4C00, -0x5000,
+ 0x7E00, 0x5000, -0x4C00, -0x5000, 0x4C00, -0x5000,
//gReva gRevb gInputL gInputR
- 0x6000, 0x5400, -0x8000, -0x8000,
+ 0x6000, 0x5400, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x0AE0 - 0x033D, 0x07A2 - 0x033D, 0x0464 - 0x0231, 0x0232 - 0x0231,
+ 0x0AE0 - 0x033D, 0x07A2 - 0x033D, 0x0464 - 0x0231, 0x0232 - 0x0231,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x1ED6, 0x1A31, 0x1D14, 0x183B, 0x1BC2, 0x16B2,
+ 0x1ED6, 0x1A31, 0x1D14, 0x183B, 0x1BC2, 0x16B2,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x1A32, 0x15EF, 0x15EE, 0x1055, 0x1334, 0x0F2D, 0x11F6, 0x0C5D,
+ 0x1A32, 0x15EF, 0x15EE, 0x1055, 0x1334, 0x0F2D, 0x11F6, 0x0C5D,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x1056, 0x0AE1, 0x0AE0, 0x07A2, 0x0464, 0x0232
+ 0x1056, 0x0AE1, 0x0AE0, 0x07A2, 0x0464, 0x0232
};
static ReverbParamsSW reverb_params_Echo = {
- 0x18040/2,
+ 0x18040 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, -0x7F00,
+ 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, -0x7F00,
//gReva gRevb gInputL gInputR
- 0x0000, 0x0000, -0x8000, -0x8000,
+ 0x0000, 0x0000, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
+ 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
+ 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
+ 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
};
static ReverbParamsSW reverb_params_Delay = {
- 0x18040/2,
+ 0x18040 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000,
//gReva gRevb gInputL gInputR
- 0x0000, 0x0000, -0x8000, -0x8000,
+ 0x0000, 0x0000, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
+ 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
+ 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
+ 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
};
static ReverbParamsSW reverb_params_HalfEcho = {
- 0x3C00/2,
+ 0x3C00 / 2,
//gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x7B00,
+ 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x7B00,
//gReva gRevb gInputL gInputR
- 0x5F80, 0x54C0, -0x8000, -0x8000,
+ 0x5F80, 0x54C0, -0x8000, -0x8000,
//nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x0058 - 0x0017, 0x0040 - 0x0017, 0x0028 - 0x0013, 0x0014 - 0x0013,
+ 0x0058 - 0x0017, 0x0040 - 0x0017, 0x0028 - 0x0013, 0x0014 - 0x0013,
//nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x0371, 0x02AF, 0x02E5, 0x01DF, 0x02B0, 0x01D7,
+ 0x0371, 0x02AF, 0x02E5, 0x01DF, 0x02B0, 0x01D7,
//nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x0358, 0x026A, 0x01D6, 0x011E, 0x012D, 0x00B1, 0x011F, 0x0059,
+ 0x0358, 0x026A, 0x01D6, 0x011E, 0x012D, 0x00B1, 0x011F, 0x0059,
//nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x01A0, 0x00E3, 0x0058, 0x0040, 0x0028, 0x0014
+ 0x01A0, 0x00E3, 0x0058, 0x0040, 0x0028, 0x0014
};
-
-static ReverbParamsSW * reverb_param_modes[] = {
+static ReverbParamsSW *reverb_param_modes[] = {
&reverb_params_Room,
&reverb_params_StudioSmall,
&reverb_params_StudioMedium,
@@ -255,25 +249,24 @@ static ReverbParamsSW * reverb_param_modes[] = {
&reverb_params_HalfEcho,
};
-bool ReverbSW::process(int *p_input,int *p_output,int p_frames,int p_stereo_stride) {
+bool ReverbSW::process(int *p_input, int *p_output, int p_frames, int p_stereo_stride) {
if (!reverb_buffer)
return false;
+//
+// p_input must point to a non-looping buffer.
+// BOTH p_input and p_output must be touched (use ClearModuleBuffer).
- //
- // p_input must point to a non-looping buffer.
- // BOTH p_input and p_output must be touched (use ClearModuleBuffer).
-
- // LOCAL MACROS
+// LOCAL MACROS
#undef LM_SETSRCOFFSET
-#define LM_SETSRCOFFSET(x) \
- (x) = current_params->x + Offset; \
- if ( (x) >= reverb_buffer_size ) { \
- (x) -= reverb_buffer_size; \
- } \
- SETMIN ( aSample, reverb_buffer_size - (x) );
+#define LM_SETSRCOFFSET(x) \
+ (x) = current_params->x + Offset; \
+ if ((x) >= reverb_buffer_size) { \
+ (x) -= reverb_buffer_size; \
+ } \
+ SETMIN(aSample, reverb_buffer_size - (x));
/*
#undef LM_SETSRCOFFSET2
@@ -286,15 +279,15 @@ bool ReverbSW::process(int *p_input,int *p_output,int p_frames,int p_stereo_stri
SETMIN ( aSample, reverb_buffer_size - (x) );
*/
#undef LM_SRCADVANCE
-#define LM_SRCADVANCE(x) \
- (x) += aSample;
+#define LM_SRCADVANCE(x) \
+ (x) += aSample;
#undef LM_MUL
-#define LM_MUL(x,y) \
-MULSHIFT_S32 ( x, current_params->y, 15 )
+#define LM_MUL(x, y) \
+ MULSHIFT_S32(x, current_params->y, 15)
#undef LM_REVERB
-#define LM_REVERB(x) reverb_buffer[ (x) + cSample ]
+#define LM_REVERB(x) reverb_buffer[(x) + cSample]
// LOCAL VARIABLES
@@ -305,16 +298,15 @@ MULSHIFT_S32 ( x, current_params->y, 15 )
// CODE
-
lwl = state.lwl;
lwr = state.lwr;
rwl = state.rwl;
rwr = state.rwr;
Offset = state.Offset;
- int max=0;
+ int max = 0;
- while ( p_frames ) {
+ while (p_frames) {
// Offsets
@@ -354,109 +346,110 @@ MULSHIFT_S32 ( x, current_params->y, 15 )
// Set initial offsets
- LM_SETSRCOFFSET ( nLwlOld );
- LM_SETSRCOFFSET ( nRwrOld );
- LM_SETSRCOFFSET ( nLwlNew );
- LM_SETSRCOFFSET ( nRwrNew );
- LM_SETSRCOFFSET ( nLwrOld );
- LM_SETSRCOFFSET ( nRwlOld );
- LM_SETSRCOFFSET ( nLwrNew );
- LM_SETSRCOFFSET ( nRwlNew );
- LM_SETSRCOFFSET ( nEcho0L );
- LM_SETSRCOFFSET ( nEcho1L );
- LM_SETSRCOFFSET ( nEcho2L );
- LM_SETSRCOFFSET ( nEcho3L );
- LM_SETSRCOFFSET ( nEcho0R );
- LM_SETSRCOFFSET ( nEcho1R );
- LM_SETSRCOFFSET ( nEcho2R );
- LM_SETSRCOFFSET ( nEcho3R );
- LM_SETSRCOFFSET ( nRevaOldL );
- LM_SETSRCOFFSET ( nRevaOldR );
- LM_SETSRCOFFSET ( nRevbOldL );
- LM_SETSRCOFFSET ( nRevbOldR );
- LM_SETSRCOFFSET ( nRevaNewL );
- LM_SETSRCOFFSET ( nRevaNewR );
- LM_SETSRCOFFSET ( nRevbNewL );
- LM_SETSRCOFFSET ( nRevbNewR );
+ LM_SETSRCOFFSET(nLwlOld);
+ LM_SETSRCOFFSET(nRwrOld);
+ LM_SETSRCOFFSET(nLwlNew);
+ LM_SETSRCOFFSET(nRwrNew);
+ LM_SETSRCOFFSET(nLwrOld);
+ LM_SETSRCOFFSET(nRwlOld);
+ LM_SETSRCOFFSET(nLwrNew);
+ LM_SETSRCOFFSET(nRwlNew);
+ LM_SETSRCOFFSET(nEcho0L);
+ LM_SETSRCOFFSET(nEcho1L);
+ LM_SETSRCOFFSET(nEcho2L);
+ LM_SETSRCOFFSET(nEcho3L);
+ LM_SETSRCOFFSET(nEcho0R);
+ LM_SETSRCOFFSET(nEcho1R);
+ LM_SETSRCOFFSET(nEcho2R);
+ LM_SETSRCOFFSET(nEcho3R);
+ LM_SETSRCOFFSET(nRevaOldL);
+ LM_SETSRCOFFSET(nRevaOldR);
+ LM_SETSRCOFFSET(nRevbOldL);
+ LM_SETSRCOFFSET(nRevbOldR);
+ LM_SETSRCOFFSET(nRevaNewL);
+ LM_SETSRCOFFSET(nRevaNewR);
+ LM_SETSRCOFFSET(nRevbNewL);
+ LM_SETSRCOFFSET(nRevbNewR);
//SETMIN ( aSample, p_output.Size - p_output.Offset );
- for (unsigned int cSample=0;cSample<aSample;cSample++) {
+ for (unsigned int cSample = 0; cSample < aSample; cSample++) {
int tempL0, tempL1, tempR0, tempR1;
- tempL1 = p_input[(cSample<<p_stereo_stride)]>>8;
- tempR1 = p_input[(cSample<<p_stereo_stride) + 1]>>8;
+ tempL1 = p_input[(cSample << p_stereo_stride)] >> 8;
+ tempR1 = p_input[(cSample << p_stereo_stride) + 1] >> 8;
- tempL0 = LM_MUL ( tempL1, gInputL );
- tempR0 = LM_MUL ( tempR1, gInputR );
+ tempL0 = LM_MUL(tempL1, gInputL);
+ tempR0 = LM_MUL(tempR1, gInputR);
/*
Left -> Wall -> Left Reflection
*/
- tempL1 = tempL0 + LM_MUL ( LM_REVERB( nLwlOld ), gWall );
- tempR1 = tempR0 + LM_MUL ( LM_REVERB( nRwrOld ), gWall );
- lwl += LM_MUL ( tempL1 - lwl, gLPF );
- rwr += LM_MUL ( tempR1 - rwr, gLPF );
- LM_REVERB( nLwlNew ) = lwl;
- LM_REVERB( nRwrNew ) = rwr;
+ tempL1 = tempL0 + LM_MUL(LM_REVERB(nLwlOld), gWall);
+ tempR1 = tempR0 + LM_MUL(LM_REVERB(nRwrOld), gWall);
+ lwl += LM_MUL(tempL1 - lwl, gLPF);
+ rwr += LM_MUL(tempR1 - rwr, gLPF);
+ LM_REVERB(nLwlNew) = lwl;
+ LM_REVERB(nRwrNew) = rwr;
/*
Left -> Wall -> Right Reflection
*/
- tempL1 = tempL0 + LM_MUL ( LM_REVERB( nRwlOld ), gWall );
- tempR1 = tempR0 + LM_MUL ( LM_REVERB( nLwrOld ), gWall );
- lwr += LM_MUL ( tempL1 - lwr, gLPF );
- rwl += LM_MUL ( tempR1 - rwl, gLPF );
- LM_REVERB( nLwrNew ) = lwr;
- LM_REVERB( nRwlNew ) = rwl;
+ tempL1 = tempL0 + LM_MUL(LM_REVERB(nRwlOld), gWall);
+ tempR1 = tempR0 + LM_MUL(LM_REVERB(nLwrOld), gWall);
+ lwr += LM_MUL(tempL1 - lwr, gLPF);
+ rwl += LM_MUL(tempR1 - rwl, gLPF);
+ LM_REVERB(nLwrNew) = lwr;
+ LM_REVERB(nRwlNew) = rwl;
/*
Early Echo(Early Reflection)
*/
tempL0 =
- LM_MUL ( LM_REVERB( nEcho0L ), gEcho0 ) +
- LM_MUL ( LM_REVERB( nEcho1L ), gEcho1 ) +
- LM_MUL ( LM_REVERB( nEcho2L ), gEcho2 ) +
- LM_MUL ( LM_REVERB( nEcho3L ), gEcho3 );
+ LM_MUL(LM_REVERB(nEcho0L), gEcho0) +
+ LM_MUL(LM_REVERB(nEcho1L), gEcho1) +
+ LM_MUL(LM_REVERB(nEcho2L), gEcho2) +
+ LM_MUL(LM_REVERB(nEcho3L), gEcho3);
tempR0 =
- LM_MUL ( LM_REVERB( nEcho0R ), gEcho0 ) +
- LM_MUL ( LM_REVERB( nEcho1R ), gEcho1 ) +
- LM_MUL ( LM_REVERB( nEcho2R ), gEcho2 ) +
- LM_MUL ( LM_REVERB( nEcho3R ), gEcho3 );
+ LM_MUL(LM_REVERB(nEcho0R), gEcho0) +
+ LM_MUL(LM_REVERB(nEcho1R), gEcho1) +
+ LM_MUL(LM_REVERB(nEcho2R), gEcho2) +
+ LM_MUL(LM_REVERB(nEcho3R), gEcho3);
/*
Late Reverb
*/
- tempL1 = LM_REVERB( nRevaOldL );
- tempR1 = LM_REVERB( nRevaOldR );
- tempL0 -= LM_MUL ( tempL1, gReva );
- tempR0 -= LM_MUL ( tempR1, gReva );
- LM_REVERB( nRevaNewL ) = tempL0;
- LM_REVERB( nRevaNewR ) = tempR0;
- tempL0 = LM_MUL ( tempL0, gReva ) + tempL1;
- tempR0 = LM_MUL ( tempR0, gReva ) + tempR1;
- tempL1 = LM_REVERB( nRevbOldL );
- tempR1 = LM_REVERB( nRevbOldR );
- tempL0 -= LM_MUL ( tempL1, gRevb );
- tempR0 -= LM_MUL ( tempR1, gRevb );
- LM_REVERB( nRevbNewL ) = tempL0;
- LM_REVERB( nRevbNewR ) = tempR0;
- tempL0 = LM_MUL ( tempL0, gRevb ) + tempL1;
- tempR0 = LM_MUL ( tempR0, gRevb ) + tempR1;
+ tempL1 = LM_REVERB(nRevaOldL);
+ tempR1 = LM_REVERB(nRevaOldR);
+ tempL0 -= LM_MUL(tempL1, gReva);
+ tempR0 -= LM_MUL(tempR1, gReva);
+ LM_REVERB(nRevaNewL) = tempL0;
+ LM_REVERB(nRevaNewR) = tempR0;
+ tempL0 = LM_MUL(tempL0, gReva) + tempL1;
+ tempR0 = LM_MUL(tempR0, gReva) + tempR1;
+ tempL1 = LM_REVERB(nRevbOldL);
+ tempR1 = LM_REVERB(nRevbOldR);
+ tempL0 -= LM_MUL(tempL1, gRevb);
+ tempR0 -= LM_MUL(tempR1, gRevb);
+ LM_REVERB(nRevbNewL) = tempL0;
+ LM_REVERB(nRevbNewR) = tempR0;
+ tempL0 = LM_MUL(tempL0, gRevb) + tempL1;
+ tempR0 = LM_MUL(tempR0, gRevb) + tempR1;
/*
Output
*/
- max|=abs(tempL0);
- max|=abs(tempR0);
-
- p_output[(cSample<<p_stereo_stride)] += tempL0<<8;
- p_output[(cSample<<p_stereo_stride) + 1] += tempR0<<8;
+ max |= abs(tempL0);
+ max |= abs(tempR0);
+ p_output[(cSample << p_stereo_stride)] += tempL0 << 8;
+ p_output[(cSample << p_stereo_stride) + 1] += tempR0 << 8;
}
// Advance offsets
Offset += aSample;
- if ( Offset >= reverb_buffer_size ) { Offset -= reverb_buffer_size; }
+ if (Offset >= reverb_buffer_size) {
+ Offset -= reverb_buffer_size;
+ }
p_input += aSample << p_stereo_stride;
p_output += aSample << p_stereo_stride;
@@ -470,100 +463,91 @@ MULSHIFT_S32 ( x, current_params->y, 15 )
state.rwr = rwr;
state.Offset = Offset;
- return (max&0x7FFFFF00)!=0; // audio was mixed?
+ return (max & 0x7FFFFF00) != 0; // audio was mixed?
}
void ReverbSW::adjust_current_params() {
- *current_params=*reverb_param_modes[mode];
+ *current_params = *reverb_param_modes[mode];
- uint32_t maxofs=0;
+ uint32_t maxofs = 0;
-#define LM_CONFIG_PARAM( x )\
- current_params->x=(int)( ( (int64_t)current_params->x*(int64_t)mix_rate*8L)/(int64_t)44100);\
- if (current_params->x>maxofs)\
- maxofs=current_params->x;
+#define LM_CONFIG_PARAM(x) \
+ current_params->x = (int)(((int64_t)current_params->x * (int64_t)mix_rate * 8L) / (int64_t)44100); \
+ if (current_params->x > maxofs) \
+ maxofs = current_params->x;
+ LM_CONFIG_PARAM(nLwlOld);
+ LM_CONFIG_PARAM(nRwrOld);
+ LM_CONFIG_PARAM(nLwlNew);
+ LM_CONFIG_PARAM(nRwrNew);
+ LM_CONFIG_PARAM(nLwrOld);
+ LM_CONFIG_PARAM(nRwlOld);
+ LM_CONFIG_PARAM(nLwrNew);
+ LM_CONFIG_PARAM(nRwlNew);
+ LM_CONFIG_PARAM(nEcho0L);
+ LM_CONFIG_PARAM(nEcho1L);
+ LM_CONFIG_PARAM(nEcho2L);
+ LM_CONFIG_PARAM(nEcho3L);
+ LM_CONFIG_PARAM(nEcho0R);
+ LM_CONFIG_PARAM(nEcho1R);
+ LM_CONFIG_PARAM(nEcho2R);
+ LM_CONFIG_PARAM(nEcho3R);
+ LM_CONFIG_PARAM(nRevaOldL);
+ LM_CONFIG_PARAM(nRevaOldR);
+ LM_CONFIG_PARAM(nRevbOldL);
+ LM_CONFIG_PARAM(nRevbOldR);
+ LM_CONFIG_PARAM(nRevaNewL);
+ LM_CONFIG_PARAM(nRevaNewR);
+ LM_CONFIG_PARAM(nRevbNewL);
+ LM_CONFIG_PARAM(nRevbNewR);
- LM_CONFIG_PARAM ( nLwlOld );
- LM_CONFIG_PARAM ( nRwrOld );
- LM_CONFIG_PARAM ( nLwlNew );
- LM_CONFIG_PARAM ( nRwrNew );
- LM_CONFIG_PARAM ( nLwrOld );
- LM_CONFIG_PARAM ( nRwlOld );
- LM_CONFIG_PARAM ( nLwrNew );
- LM_CONFIG_PARAM ( nRwlNew );
- LM_CONFIG_PARAM ( nEcho0L );
- LM_CONFIG_PARAM ( nEcho1L );
- LM_CONFIG_PARAM ( nEcho2L );
- LM_CONFIG_PARAM ( nEcho3L );
- LM_CONFIG_PARAM ( nEcho0R );
- LM_CONFIG_PARAM ( nEcho1R );
- LM_CONFIG_PARAM ( nEcho2R );
- LM_CONFIG_PARAM ( nEcho3R );
- LM_CONFIG_PARAM ( nRevaOldL );
- LM_CONFIG_PARAM ( nRevaOldR );
- LM_CONFIG_PARAM ( nRevbOldL );
- LM_CONFIG_PARAM ( nRevbOldR );
- LM_CONFIG_PARAM ( nRevaNewL );
- LM_CONFIG_PARAM ( nRevaNewR );
- LM_CONFIG_PARAM ( nRevbNewL );
- LM_CONFIG_PARAM ( nRevbNewR );
-
- int needed_buffer_size=maxofs+1;
+ int needed_buffer_size = maxofs + 1;
if (reverb_buffer)
memdelete_arr(reverb_buffer);
- reverb_buffer = memnew_arr(int,needed_buffer_size);
- reverb_buffer_size=needed_buffer_size;
+ reverb_buffer = memnew_arr(int, needed_buffer_size);
+ reverb_buffer_size = needed_buffer_size;
- for (uint32_t i=0;i<reverb_buffer_size;i++)
- reverb_buffer[i]=0;
+ for (uint32_t i = 0; i < reverb_buffer_size; i++)
+ reverb_buffer[i] = 0;
state.reset();
-
-
}
void ReverbSW::set_mode(ReverbMode p_mode) {
- if (mode==p_mode)
+ if (mode == p_mode)
return;
- mode=p_mode;
+ mode = p_mode;
adjust_current_params();
}
void ReverbSW::set_mix_rate(int p_mix_rate) {
- if (p_mix_rate==mix_rate)
+ if (p_mix_rate == mix_rate)
return;
- mix_rate=p_mix_rate;
+ mix_rate = p_mix_rate;
adjust_current_params();
-
}
-
ReverbSW::ReverbSW() {
- reverb_buffer=0;
- reverb_buffer_size=0;
- mode=REVERB_MODE_ROOM;
- mix_rate=1;
+ reverb_buffer = 0;
+ reverb_buffer_size = 0;
+ mode = REVERB_MODE_ROOM;
+ mix_rate = 1;
current_params = memnew(ReverbParamsSW);
}
-
ReverbSW::~ReverbSW() {
-
if (reverb_buffer)
memdelete_arr(reverb_buffer);
memdelete(current_params);
-
}
-
diff --git a/servers/audio/reverb_sw.h b/servers/audio/reverb_sw.h
index d9f16a5fb..06a14322a 100644
--- a/servers/audio/reverb_sw.h
+++ b/servers/audio/reverb_sw.h
@@ -29,8 +29,8 @@
#ifndef REVERB_SW_H
#define REVERB_SW_H
-#include "typedefs.h"
#include "os/memory.h"
+#include "typedefs.h"
class ReverbParamsSW;
@@ -55,13 +55,18 @@ private:
int rwl;
int rwr;
unsigned int Offset;
- void reset() { lwl=0; lwr=0; rwl=0; rwr=0; Offset=0; }
+ void reset() {
+ lwl = 0;
+ lwr = 0;
+ rwl = 0;
+ rwr = 0;
+ Offset = 0;
+ }
State() { reset(); }
} state;
ReverbParamsSW *current_params;
-
int *reverb_buffer;
unsigned int reverb_buffer_size;
ReverbMode mode;
@@ -70,15 +75,12 @@ private:
void adjust_current_params();
public:
-
-
void set_mode(ReverbMode p_mode);
- bool process(int *p_input,int *p_output,int p_frames,int p_stereo_stride=1); // return tru if audio was created
+ bool process(int *p_input, int *p_output, int p_frames, int p_stereo_stride = 1); // return tru if audio was created
void set_mix_rate(int p_mix_rate);
ReverbSW();
~ReverbSW();
-
};
#endif
diff --git a/servers/audio/voice_rb_sw.h b/servers/audio/voice_rb_sw.h
index cbf139248..117a62a43 100644
--- a/servers/audio/voice_rb_sw.h
+++ b/servers/audio/voice_rb_sw.h
@@ -29,13 +29,12 @@
#ifndef VOICE_RB_SW_H
#define VOICE_RB_SW_H
-#include "servers/audio_server.h"
#include "os/os.h"
+#include "servers/audio_server.h"
class VoiceRBSW {
public:
-
enum {
- VOICE_RB_SIZE=1024
+ VOICE_RB_SIZE = 1024
};
struct Command {
@@ -72,7 +71,7 @@ public:
struct {
- float pan,depth,height;
+ float pan, depth, height;
} pan;
struct {
@@ -100,47 +99,42 @@ public:
bool positional;
} positional;
-
};
- Command() { type=CMD_NONE; }
-
+ Command() { type = CMD_NONE; }
};
-private:
+private:
Command voice_cmd_rb[VOICE_RB_SIZE];
volatile int read_pos;
volatile int write_pos;
public:
-
- _FORCE_INLINE_ bool commands_left() const { return read_pos!=write_pos; }
+ _FORCE_INLINE_ bool commands_left() const { return read_pos != write_pos; }
_FORCE_INLINE_ Command pop_command() {
- ERR_FAIL_COND_V( read_pos==write_pos, Command() );
- Command cmd=voice_cmd_rb[read_pos];
- read_pos=(read_pos+1)%VOICE_RB_SIZE;
+ ERR_FAIL_COND_V(read_pos == write_pos, Command());
+ Command cmd = voice_cmd_rb[read_pos];
+ read_pos = (read_pos + 1) % VOICE_RB_SIZE;
return cmd;
}
- _FORCE_INLINE_ void push_command(const Command& p_command) {
+ _FORCE_INLINE_ void push_command(const Command &p_command) {
- bool full = ((write_pos+1)%VOICE_RB_SIZE)==read_pos;
+ bool full = ((write_pos + 1) % VOICE_RB_SIZE) == read_pos;
if (full) {
#ifdef DEBUG_ENABLED
if (OS::get_singleton()->is_stdout_verbose()) {
ERR_EXPLAIN("Audio Ring Buffer Full (too many commands");
- ERR_FAIL_COND( ((write_pos+1)%VOICE_RB_SIZE)==read_pos);
+ ERR_FAIL_COND(((write_pos + 1) % VOICE_RB_SIZE) == read_pos);
}
#endif
return;
}
- voice_cmd_rb[write_pos]=p_command;
- write_pos=(write_pos+1)%VOICE_RB_SIZE;
-
+ voice_cmd_rb[write_pos] = p_command;
+ write_pos = (write_pos + 1) % VOICE_RB_SIZE;
}
- VoiceRBSW() { read_pos=write_pos=0; }
-
+ VoiceRBSW() { read_pos = write_pos = 0; }
};
#endif // VOICE_RB_SW_H