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_filter_sw.cpp242
-rw-r--r--servers/audio/audio_filter_sw.h43
-rw-r--r--servers/audio/audio_mixer_sw.cpp974
-rw-r--r--servers/audio/audio_mixer_sw.h85
-rw-r--r--servers/audio/audio_rb_resampler.cpp321
-rw-r--r--servers/audio/audio_rb_resampler.h92
-rw-r--r--servers/audio/audio_server_sw.cpp593
-rw-r--r--servers/audio/audio_server_sw.h98
-rw-r--r--servers/audio/reverb_sw.cpp620
-rw-r--r--servers/audio/reverb_sw.h16
-rw-r--r--servers/audio/sample_manager_sw.cpp159
-rw-r--r--servers/audio/sample_manager_sw.h57
-rw-r--r--servers/audio/voice_rb_sw.h36
15 files changed, 1560 insertions, 1827 deletions
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp
index 6fe14b0fc..470f79971 100644
--- a/servers/audio/audio_driver_dummy.cpp
+++ b/servers/audio/audio_driver_dummy.cpp
@@ -31,42 +31,37 @@
#include "globals.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;
output_format = OUTPUT_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() {
@@ -135,12 +127,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 c91a0db43..d07ee9c21 100644
--- a/servers/audio/audio_driver_dummy.h
+++ b/servers/audio/audio_driver_dummy.h
@@ -31,18 +31,17 @@
#include "servers/audio/audio_server_sw.h"
-#include "core/os/thread.h"
#include "core/os/mutex.h"
-
+#include "core/os/thread.h"
class AudioDriverDummy : public AudioDriverSW {
- 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 AudioDriverSW {
bool pcm_open;
public:
-
- const char* get_name() const {
+ const char *get_name() const {
return "Dummy";
};
diff --git a/servers/audio/audio_filter_sw.cpp b/servers/audio/audio_filter_sw.cpp
index cdfe1a29f..aa141a031 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(2);
- omega=2.0*Math_PI*centercutoff/sampling_rate;
- alpha = Math::sin(omega)*Math::sinh( Math::log(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(2);
+ omega = 2.0 * Math_PI * centercutoff / sampling_rate;
+ alpha = Math::sin(omega) * Math::sinh(Math::log(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 0f3e2410f..3954e4918 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();
- inline void process_one(float& p_sample);
+ 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_mixer_sw.cpp b/servers/audio/audio_mixer_sw.cpp
index faed6905e..bf2a2c905 100644
--- a/servers/audio/audio_mixer_sw.cpp
+++ b/servers/audio/audio_mixer_sw.cpp
@@ -27,33 +27,32 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "audio_mixer_sw.h"
-#include "print_string.h"
#include "os/os.h"
+#include "print_string.h"
//TODO implement FAST_AUDIO macro
#ifdef FAST_AUDIO
#define NO_REVERB
#endif
-template<class Depth,bool is_stereo,bool is_ima_adpcm,bool use_filter,bool use_fx,AudioMixerSW::InterpolationType type,AudioMixerSW::MixChannels mix_mode>
-void AudioMixerSW::do_resample(const Depth* p_src, int32_t *p_dst, ResamplerState *p_state) {
+template <class Depth, bool is_stereo, bool is_ima_adpcm, bool use_filter, bool use_fx, AudioMixerSW::InterpolationType type, AudioMixerSW::MixChannels mix_mode>
+void AudioMixerSW::do_resample(const Depth *p_src, int32_t *p_dst, ResamplerState *p_state) {
// this function will be compiled branchless by any decent compiler
- int32_t final,final_r,next,next_r;
+ int32_t final, final_r, next, next_r;
int32_t *reverb_dst = p_state->reverb_buffer;
while (p_state->amount--) {
- int32_t pos=p_state->pos >> MIX_FRAC_BITS;
+ int32_t pos = p_state->pos >> MIX_FRAC_BITS;
if (is_stereo && !is_ima_adpcm)
- pos<<=1;
+ pos <<= 1;
if (is_ima_adpcm) {
int sample_pos = pos + p_state->ima_adpcm[0].window_ofs;
- while(sample_pos>p_state->ima_adpcm[0].last_nibble) {
-
+ while (sample_pos > p_state->ima_adpcm[0].last_nibble) {
static const int16_t _ima_adpcm_step_table[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
@@ -72,238 +71,223 @@ void AudioMixerSW::do_resample(const Depth* p_src, int32_t *p_dst, ResamplerStat
-1, -1, -1, -1, 2, 4, 6, 8
};
- for(int i=0;i<(is_stereo?2:1);i++) {
+ for (int i = 0; i < (is_stereo ? 2 : 1); i++) {
-
- int16_t nibble,diff,step;
+ int16_t nibble, diff, step;
p_state->ima_adpcm[i].last_nibble++;
- const uint8_t *src_ptr=p_state->ima_adpcm[i].ptr;
-
-
- uint8_t nbb = src_ptr[ (p_state->ima_adpcm[i].last_nibble>>1) * (is_stereo?2:1) + i ];
- nibble = (p_state->ima_adpcm[i].last_nibble&1)?(nbb>>4):(nbb&0xF);
- step=_ima_adpcm_step_table[p_state->ima_adpcm[i].step_index];
+ const uint8_t *src_ptr = p_state->ima_adpcm[i].ptr;
+ uint8_t nbb = src_ptr[(p_state->ima_adpcm[i].last_nibble >> 1) * (is_stereo ? 2 : 1) + i];
+ nibble = (p_state->ima_adpcm[i].last_nibble & 1) ? (nbb >> 4) : (nbb & 0xF);
+ step = _ima_adpcm_step_table[p_state->ima_adpcm[i].step_index];
p_state->ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble];
- if (p_state->ima_adpcm[i].step_index<0)
- p_state->ima_adpcm[i].step_index=0;
- if (p_state->ima_adpcm[i].step_index>88)
- p_state->ima_adpcm[i].step_index=88;
+ if (p_state->ima_adpcm[i].step_index < 0)
+ p_state->ima_adpcm[i].step_index = 0;
+ if (p_state->ima_adpcm[i].step_index > 88)
+ p_state->ima_adpcm[i].step_index = 88;
- diff = step >> 3 ;
+ diff = step >> 3;
if (nibble & 1)
- diff += step >> 2 ;
+ diff += step >> 2;
if (nibble & 2)
- diff += step >> 1 ;
+ diff += step >> 1;
if (nibble & 4)
- diff += step ;
+ diff += step;
if (nibble & 8)
- diff = -diff ;
-
- p_state->ima_adpcm[i].predictor+=diff;
- if (p_state->ima_adpcm[i].predictor<-0x8000)
- p_state->ima_adpcm[i].predictor=-0x8000;
- else if (p_state->ima_adpcm[i].predictor>0x7FFF)
- p_state->ima_adpcm[i].predictor=0x7FFF;
+ diff = -diff;
+ p_state->ima_adpcm[i].predictor += diff;
+ if (p_state->ima_adpcm[i].predictor < -0x8000)
+ p_state->ima_adpcm[i].predictor = -0x8000;
+ else if (p_state->ima_adpcm[i].predictor > 0x7FFF)
+ p_state->ima_adpcm[i].predictor = 0x7FFF;
/* store loop if there */
- if (p_state->ima_adpcm[i].last_nibble==p_state->ima_adpcm[i].loop_pos) {
+ if (p_state->ima_adpcm[i].last_nibble == p_state->ima_adpcm[i].loop_pos) {
p_state->ima_adpcm[i].loop_step_index = p_state->ima_adpcm[i].step_index;
p_state->ima_adpcm[i].loop_predictor = p_state->ima_adpcm[i].predictor;
}
//printf("%i - %i - pred %i\n",int(p_state->ima_adpcm[i].last_nibble),int(nibble),int(p_state->ima_adpcm[i].predictor));
-
}
-
}
- final=p_state->ima_adpcm[0].predictor;
+ final = p_state->ima_adpcm[0].predictor;
if (is_stereo) {
- final_r=p_state->ima_adpcm[1].predictor;
+ final_r = p_state->ima_adpcm[1].predictor;
}
} else {
- final=p_src[pos];
+ final = p_src[pos];
if (is_stereo)
- final_r=p_src[pos+1];
+ final_r = p_src[pos + 1];
- if (sizeof(Depth)==1) { /* conditions will not exist anymore when compiled! */
- final<<=8;
+ if (sizeof(Depth) == 1) { /* conditions will not exist anymore when compiled! */
+ final <<= 8;
if (is_stereo)
- final_r<<=8;
+ final_r <<= 8;
}
- if (type==INTERPOLATION_LINEAR) {
+ if (type == INTERPOLATION_LINEAR) {
if (is_stereo) {
- next=p_src[pos+2];
- next_r=p_src[pos+3];
+ next = p_src[pos + 2];
+ next_r = p_src[pos + 3];
} else {
- next=p_src[pos+1];
+ next = p_src[pos + 1];
}
- if (sizeof(Depth)==1) {
- next<<=8;
+ if (sizeof(Depth) == 1) {
+ next <<= 8;
if (is_stereo)
- next_r<<=8;
+ next_r <<= 8;
}
- int32_t frac=int32_t(p_state->pos&MIX_FRAC_MASK);
+ int32_t frac = int32_t(p_state->pos & MIX_FRAC_MASK);
- final=final+((next-final)*frac >> MIX_FRAC_BITS);
+ final = final + ((next - final) * frac >> MIX_FRAC_BITS);
if (is_stereo)
- final_r=final_r+((next_r-final_r)*frac >> MIX_FRAC_BITS);
+ final_r = final_r + ((next_r - final_r) * frac >> MIX_FRAC_BITS);
}
}
if (use_filter) {
Channel::Mix::Filter *f = p_state->filter_l;
- float finalf=final;
+ float finalf = final;
float pre = finalf;
- finalf = ((finalf*p_state->coefs.b0) + (f->hb[0]*p_state->coefs.b1) + (f->hb[1]*p_state->coefs.b2) + (f->ha[0]*p_state->coefs.a1) + (f->ha[1]*p_state->coefs.a2)
- );
+ finalf = ((finalf * p_state->coefs.b0) + (f->hb[0] * p_state->coefs.b1) + (f->hb[1] * p_state->coefs.b2) + (f->ha[0] * p_state->coefs.a1) + (f->ha[1] * p_state->coefs.a2));
- f->ha[1]=f->ha[0];
- f->hb[1]=f->hb[0];
- f->hb[0]=pre;
- f->ha[0]=finalf;
+ f->ha[1] = f->ha[0];
+ f->hb[1] = f->hb[0];
+ f->hb[0] = pre;
+ f->ha[0] = finalf;
- final=Math::fast_ftoi(finalf);
+ final = Math::fast_ftoi(finalf);
if (is_stereo) {
f = p_state->filter_r;
- finalf=final_r;
+ finalf = final_r;
pre = finalf;
- finalf = ((finalf*p_state->coefs.b0) + (f->hb[0]*p_state->coefs.b1) + (f->hb[1]*p_state->coefs.b2) + (f->ha[0]*p_state->coefs.a1) + (f->ha[1]*p_state->coefs.a2)
- );
- f->ha[1]=f->ha[0];
- f->hb[1]=f->hb[0];
- f->hb[0]=pre;
- f->ha[0]=finalf;
-
- final_r=Math::fast_ftoi(finalf);
+ finalf = ((finalf * p_state->coefs.b0) + (f->hb[0] * p_state->coefs.b1) + (f->hb[1] * p_state->coefs.b2) + (f->ha[0] * p_state->coefs.a1) + (f->ha[1] * p_state->coefs.a2));
+ f->ha[1] = f->ha[0];
+ f->hb[1] = f->hb[0];
+ f->hb[0] = pre;
+ f->ha[0] = finalf;
+ final_r = Math::fast_ftoi(finalf);
}
- p_state->coefs.b0+=p_state->coefs_inc.b0;
- p_state->coefs.b1+=p_state->coefs_inc.b1;
- p_state->coefs.b2+=p_state->coefs_inc.b2;
- p_state->coefs.a1+=p_state->coefs_inc.a1;
- p_state->coefs.a2+=p_state->coefs_inc.a2;
+ p_state->coefs.b0 += p_state->coefs_inc.b0;
+ p_state->coefs.b1 += p_state->coefs_inc.b1;
+ p_state->coefs.b2 += p_state->coefs_inc.b2;
+ p_state->coefs.a1 += p_state->coefs_inc.a1;
+ p_state->coefs.a2 += p_state->coefs_inc.a2;
}
if (!is_stereo) {
- final_r=final; //copy to right channel if stereo
+ final_r = final; //copy to right channel if stereo
}
//convert back to 24 bits and mix to buffers
- if (mix_mode==MIX_STEREO) {
- *p_dst++ +=(final*(p_state->vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- *p_dst++ +=(final_r*(p_state->vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
+ if (mix_mode == MIX_STEREO) {
+ *p_dst++ += (final * (p_state->vol[0] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ *p_dst++ += (final_r * (p_state->vol[1] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
- p_state->vol[0]+=p_state->vol_inc[0];
- p_state->vol[1]+=p_state->vol_inc[1];
+ p_state->vol[0] += p_state->vol_inc[0];
+ p_state->vol[1] += p_state->vol_inc[1];
if (use_fx) {
- *reverb_dst++ +=(final*(p_state->reverb_vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- *reverb_dst++ +=(final_r*(p_state->reverb_vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- p_state->reverb_vol[0]+=p_state->reverb_vol_inc[0];
- p_state->reverb_vol[1]+=p_state->reverb_vol_inc[1];
+ *reverb_dst++ += (final * (p_state->reverb_vol[0] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ *reverb_dst++ += (final_r * (p_state->reverb_vol[1] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ p_state->reverb_vol[0] += p_state->reverb_vol_inc[0];
+ p_state->reverb_vol[1] += p_state->reverb_vol_inc[1];
}
+ } else if (mix_mode == MIX_QUAD) {
- } else if (mix_mode==MIX_QUAD) {
-
- *p_dst++ +=(final*(p_state->vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- *p_dst++ +=(final_r*(p_state->vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
+ *p_dst++ += (final * (p_state->vol[0] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ *p_dst++ += (final_r * (p_state->vol[1] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
- *p_dst++ +=(final*(p_state->vol[2]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- *p_dst++ +=(final_r*(p_state->vol[3]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
+ *p_dst++ += (final * (p_state->vol[2] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ *p_dst++ += (final_r * (p_state->vol[3] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
- p_state->vol[0]+=p_state->vol_inc[0];
- p_state->vol[1]+=p_state->vol_inc[1];
- p_state->vol[2]+=p_state->vol_inc[2];
- p_state->vol[3]+=p_state->vol_inc[3];
+ p_state->vol[0] += p_state->vol_inc[0];
+ p_state->vol[1] += p_state->vol_inc[1];
+ p_state->vol[2] += p_state->vol_inc[2];
+ p_state->vol[3] += p_state->vol_inc[3];
if (use_fx) {
- *reverb_dst++ +=(final*(p_state->reverb_vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- *reverb_dst++ +=(final_r*(p_state->reverb_vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- *reverb_dst++ +=(final*(p_state->reverb_vol[2]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- *reverb_dst++ +=(final_r*(p_state->reverb_vol[3]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24;
- p_state->reverb_vol[0]+=p_state->reverb_vol_inc[0];
- p_state->reverb_vol[1]+=p_state->reverb_vol_inc[1];
- p_state->reverb_vol[2]+=p_state->reverb_vol_inc[2];
- p_state->reverb_vol[3]+=p_state->reverb_vol_inc[3];
+ *reverb_dst++ += (final * (p_state->reverb_vol[0] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ *reverb_dst++ += (final_r * (p_state->reverb_vol[1] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ *reverb_dst++ += (final * (p_state->reverb_vol[2] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ *reverb_dst++ += (final_r * (p_state->reverb_vol[3] >> MIX_VOLRAMP_FRAC_BITS)) >> MIX_VOL_MOVE_TO_24;
+ p_state->reverb_vol[0] += p_state->reverb_vol_inc[0];
+ p_state->reverb_vol[1] += p_state->reverb_vol_inc[1];
+ p_state->reverb_vol[2] += p_state->reverb_vol_inc[2];
+ p_state->reverb_vol[3] += p_state->reverb_vol_inc[3];
}
}
- p_state->pos+=p_state->increment;
+ p_state->pos += p_state->increment;
}
}
-
-void AudioMixerSW::mix_channel(Channel& c) {
-
+void AudioMixerSW::mix_channel(Channel &c) {
if (!sample_manager->is_sample(c.sample)) {
// sample is gone!
- c.active=false;
+ c.active = false;
return;
}
-
/* some 64-bit fixed point precaches */
- int64_t loop_begin_fp=((int64_t)sample_manager->sample_get_loop_begin(c.sample) << MIX_FRAC_BITS);
- int64_t loop_end_fp=((int64_t)sample_manager->sample_get_loop_end(c.sample) << MIX_FRAC_BITS);
- int64_t length_fp=((int64_t)sample_manager->sample_get_length(c.sample) << MIX_FRAC_BITS);
- int64_t begin_limit=(sample_manager->sample_get_loop_format(c.sample)!=AS::SAMPLE_LOOP_NONE)?loop_begin_fp:0;
- int64_t end_limit=(sample_manager->sample_get_loop_format(c.sample)!=AS::SAMPLE_LOOP_NONE)?loop_end_fp:length_fp;
- bool is_stereo=sample_manager->sample_is_stereo(c.sample);
+ int64_t loop_begin_fp = ((int64_t)sample_manager->sample_get_loop_begin(c.sample) << MIX_FRAC_BITS);
+ int64_t loop_end_fp = ((int64_t)sample_manager->sample_get_loop_end(c.sample) << MIX_FRAC_BITS);
+ int64_t length_fp = ((int64_t)sample_manager->sample_get_length(c.sample) << MIX_FRAC_BITS);
+ int64_t begin_limit = (sample_manager->sample_get_loop_format(c.sample) != AS::SAMPLE_LOOP_NONE) ? loop_begin_fp : 0;
+ int64_t end_limit = (sample_manager->sample_get_loop_format(c.sample) != AS::SAMPLE_LOOP_NONE) ? loop_end_fp : length_fp;
+ bool is_stereo = sample_manager->sample_is_stereo(c.sample);
- int32_t todo=mix_chunk_size;
-// int mixed=0;
- bool use_filter=false;
+ int32_t todo = mix_chunk_size;
+ // int mixed=0;
+ bool use_filter = false;
ResamplerState rstate;
/* compute voume ramps, increment, etc */
-
-
- for(int i=0;i<mix_channels;i++) {
- c.mix.old_vol[i]=c.mix.vol[i];
- c.mix.old_reverb_vol[i]=c.mix.reverb_vol[i];
- c.mix.old_chorus_vol[i]=c.mix.chorus_vol[i];
+ for (int i = 0; i < mix_channels; i++) {
+ c.mix.old_vol[i] = c.mix.vol[i];
+ c.mix.old_reverb_vol[i] = c.mix.reverb_vol[i];
+ c.mix.old_chorus_vol[i] = c.mix.chorus_vol[i];
}
- float vol = c.vol*channel_nrg;
+ float vol = c.vol * channel_nrg;
- float reverb_vol = c.reverb_send*channel_nrg;
- float chorus_vol = c.chorus_send*channel_nrg;
+ float reverb_vol = c.reverb_send * channel_nrg;
+ float chorus_vol = c.chorus_send * channel_nrg;
- if (mix_channels==2) {
+ if (mix_channels == 2) {
//stereo pan
float pan = c.pan * 0.5 + 0.5;
- float panv[2]={
- (1.0 - pan)*(1<<MIX_VOL_FRAC_BITS),
- (pan)*(1<<MIX_VOL_FRAC_BITS)
+ float panv[2] = {
+ (1.0 - pan) * (1 << MIX_VOL_FRAC_BITS),
+ (pan) * (1 << MIX_VOL_FRAC_BITS)
};
- for(int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
- c.mix.vol[i]=Math::fast_ftoi(vol*panv[i]);
- c.mix.reverb_vol[i]=Math::fast_ftoi(reverb_vol*panv[i]);
- c.mix.chorus_vol[i]=Math::fast_ftoi(chorus_vol*panv[i]);
+ c.mix.vol[i] = Math::fast_ftoi(vol * panv[i]);
+ c.mix.reverb_vol[i] = Math::fast_ftoi(reverb_vol * panv[i]);
+ c.mix.chorus_vol[i] = Math::fast_ftoi(chorus_vol * panv[i]);
}
} else {
@@ -311,79 +295,74 @@ void AudioMixerSW::mix_channel(Channel& c) {
float panx = c.pan * 0.5 + 0.5;
float pany = c.depth * 0.5 + 0.5;
// with this model every speaker plays at 0.25 energy at the center.. i'm not sure if it's correct but it seems to be balanced
- float panv[4]={
- (1.0-pany)*(1.0-panx)*(1<<MIX_VOL_FRAC_BITS),
- (1.0-pany)*( panx)*(1<<MIX_VOL_FRAC_BITS),
- ( pany)*(1.0-panx)*(1<<MIX_VOL_FRAC_BITS),
- ( pany)*( panx)*(1<<MIX_VOL_FRAC_BITS)
+ float panv[4] = {
+ (1.0 - pany) * (1.0 - panx) * (1 << MIX_VOL_FRAC_BITS),
+ (1.0 - pany) * (panx) * (1 << MIX_VOL_FRAC_BITS),
+ (pany) * (1.0 - panx) * (1 << MIX_VOL_FRAC_BITS),
+ (pany) * (panx) * (1 << MIX_VOL_FRAC_BITS)
};
- for(int i=0;i<4;i++) {
+ for (int i = 0; i < 4; i++) {
- c.mix.vol[i]=Math::fast_ftoi(vol*panv[i]);
- c.mix.reverb_vol[i]=Math::fast_ftoi(reverb_vol*panv[i]);
- c.mix.chorus_vol[i]=Math::fast_ftoi(chorus_vol*panv[i]);
+ c.mix.vol[i] = Math::fast_ftoi(vol * panv[i]);
+ c.mix.reverb_vol[i] = Math::fast_ftoi(reverb_vol * panv[i]);
+ c.mix.chorus_vol[i] = Math::fast_ftoi(chorus_vol * panv[i]);
}
-
}
if (c.first_mix) { // avoid ramp up
- for(int i=0;i<mix_channels;i++) {
- c.mix.old_vol[i]=c.mix.vol[i];
- c.mix.old_reverb_vol[i]=c.mix.reverb_vol[i];
- c.mix.old_chorus_vol[i]=c.mix.chorus_vol[i];
+ for (int i = 0; i < mix_channels; i++) {
+ c.mix.old_vol[i] = c.mix.vol[i];
+ c.mix.old_reverb_vol[i] = c.mix.reverb_vol[i];
+ c.mix.old_chorus_vol[i] = c.mix.chorus_vol[i];
}
- c.first_mix=false;
+ c.first_mix = false;
}
-
-
Channel::Filter::Coefs filter_coefs;
Channel::Filter::Coefs filter_inc;
- if (c.filter.type!=AudioMixer::FILTER_NONE) {
+ if (c.filter.type != AudioMixer::FILTER_NONE) {
- filter_coefs=c.filter.old_coefs;
- filter_inc.b0=(c.filter.coefs.b0-filter_coefs.b0)/(1<<mix_chunk_bits);
- filter_inc.b1=(c.filter.coefs.b1-filter_coefs.b1)/(1<<mix_chunk_bits);
- filter_inc.b2=(c.filter.coefs.b2-filter_coefs.b2)/(1<<mix_chunk_bits);
- filter_inc.a1=(c.filter.coefs.a1-filter_coefs.a1)/(1<<mix_chunk_bits);
- filter_inc.a2=(c.filter.coefs.a2-filter_coefs.a2)/(1<<mix_chunk_bits);
- use_filter=true;
+ filter_coefs = c.filter.old_coefs;
+ filter_inc.b0 = (c.filter.coefs.b0 - filter_coefs.b0) / (1 << mix_chunk_bits);
+ filter_inc.b1 = (c.filter.coefs.b1 - filter_coefs.b1) / (1 << mix_chunk_bits);
+ filter_inc.b2 = (c.filter.coefs.b2 - filter_coefs.b2) / (1 << mix_chunk_bits);
+ filter_inc.a1 = (c.filter.coefs.a1 - filter_coefs.a1) / (1 << mix_chunk_bits);
+ filter_inc.a2 = (c.filter.coefs.a2 - filter_coefs.a2) / (1 << mix_chunk_bits);
+ use_filter = true;
}
- if (c.mix.increment>0)
- c.mix.increment=((int64_t)c.speed<<MIX_FRAC_BITS)/mix_rate;
+ if (c.mix.increment > 0)
+ c.mix.increment = ((int64_t)c.speed << MIX_FRAC_BITS) / mix_rate;
else
- c.mix.increment=-((int64_t)c.speed<<MIX_FRAC_BITS)/mix_rate;
+ c.mix.increment = -((int64_t)c.speed << MIX_FRAC_BITS) / mix_rate;
//volume ramp
-
- for(int i=0;i<mix_channels;i++) {
- rstate.vol_inc[i]=((c.mix.vol[i]-c.mix.old_vol[i])<<MIX_VOLRAMP_FRAC_BITS)>>mix_chunk_bits;
- rstate.vol[i]=c.mix.old_vol[i]<<MIX_VOLRAMP_FRAC_BITS;
- rstate.reverb_vol_inc[i]=((c.mix.reverb_vol[i]-c.mix.old_reverb_vol[i])<<MIX_VOLRAMP_FRAC_BITS)>>mix_chunk_bits;
- rstate.reverb_vol[i]=c.mix.old_reverb_vol[i]<<MIX_VOLRAMP_FRAC_BITS;
- rstate.chorus_vol_inc[i]=((c.mix.chorus_vol[i]-c.mix.old_chorus_vol[i])<<MIX_VOLRAMP_FRAC_BITS)>>mix_chunk_bits;
- rstate.chorus_vol[i]=c.mix.old_chorus_vol[i]<<MIX_VOLRAMP_FRAC_BITS;
+ for (int i = 0; i < mix_channels; i++) {
+ rstate.vol_inc[i] = ((c.mix.vol[i] - c.mix.old_vol[i]) << MIX_VOLRAMP_FRAC_BITS) >> mix_chunk_bits;
+ rstate.vol[i] = c.mix.old_vol[i] << MIX_VOLRAMP_FRAC_BITS;
+ rstate.reverb_vol_inc[i] = ((c.mix.reverb_vol[i] - c.mix.old_reverb_vol[i]) << MIX_VOLRAMP_FRAC_BITS) >> mix_chunk_bits;
+ rstate.reverb_vol[i] = c.mix.old_reverb_vol[i] << MIX_VOLRAMP_FRAC_BITS;
+ rstate.chorus_vol_inc[i] = ((c.mix.chorus_vol[i] - c.mix.old_chorus_vol[i]) << MIX_VOLRAMP_FRAC_BITS) >> mix_chunk_bits;
+ rstate.chorus_vol[i] = c.mix.old_chorus_vol[i] << MIX_VOLRAMP_FRAC_BITS;
}
-
//looping
- AS::SampleLoopFormat loop_format=sample_manager->sample_get_loop_format(c.sample);
- AS::SampleFormat format=sample_manager->sample_get_format(c.sample);
+ AS::SampleLoopFormat loop_format = sample_manager->sample_get_loop_format(c.sample);
+ AS::SampleFormat format = sample_manager->sample_get_format(c.sample);
- bool use_fx=false;
+ bool use_fx = false;
if (fx_enabled) {
- for(int i=0;i<mix_channels;i++) {
- if (c.mix.old_reverb_vol[i] || c.mix.reverb_vol[i] || c.mix.old_chorus_vol[i] || c.mix.chorus_vol[i] ) {
- use_fx=true;
+ for (int i = 0; i < mix_channels; i++) {
+ if (c.mix.old_reverb_vol[i] || c.mix.reverb_vol[i] || c.mix.old_chorus_vol[i] || c.mix.chorus_vol[i]) {
+ use_fx = true;
break;
}
}
@@ -391,87 +370,86 @@ void AudioMixerSW::mix_channel(Channel& c) {
/* audio data */
- const void *data=sample_manager->sample_get_data_ptr(c.sample);
- int32_t *dst_buff=mix_buffer;
+ const void *data = sample_manager->sample_get_data_ptr(c.sample);
+ int32_t *dst_buff = mix_buffer;
#ifndef NO_REVERB
- rstate.reverb_buffer=reverb_state[c.reverb_room].buffer;
+ rstate.reverb_buffer = reverb_state[c.reverb_room].buffer;
#endif
/* @TODO validar loops al registrar? */
- rstate.coefs=filter_coefs;
- rstate.coefs_inc=filter_inc;
- rstate.filter_l=&c.mix.filter_l;
- rstate.filter_r=&c.mix.filter_r;
+ rstate.coefs = filter_coefs;
+ rstate.coefs_inc = filter_inc;
+ rstate.filter_l = &c.mix.filter_l;
+ rstate.filter_r = &c.mix.filter_r;
- if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) {
+ if (format == AS::SAMPLE_FORMAT_IMA_ADPCM) {
- rstate.ima_adpcm=c.mix.ima_adpcm;
- if (loop_format!=AS::SAMPLE_LOOP_NONE) {
- c.mix.ima_adpcm[0].loop_pos=loop_begin_fp>>MIX_FRAC_BITS;
- c.mix.ima_adpcm[1].loop_pos=loop_begin_fp>>MIX_FRAC_BITS;
- loop_format=AS::SAMPLE_LOOP_FORWARD;
+ rstate.ima_adpcm = c.mix.ima_adpcm;
+ if (loop_format != AS::SAMPLE_LOOP_NONE) {
+ c.mix.ima_adpcm[0].loop_pos = loop_begin_fp >> MIX_FRAC_BITS;
+ c.mix.ima_adpcm[1].loop_pos = loop_begin_fp >> MIX_FRAC_BITS;
+ loop_format = AS::SAMPLE_LOOP_FORWARD;
}
}
- while (todo>0) {
+ while (todo > 0) {
- int64_t limit=0;
- int32_t target=0,aux=0;
+ int64_t limit = 0;
+ int32_t target = 0, aux = 0;
/** LOOP CHECKING **/
- if ( c.mix.increment < 0 ) {
+ if (c.mix.increment < 0) {
/* going backwards */
- if ( loop_format!=AS::SAMPLE_LOOP_NONE && c.mix.offset < loop_begin_fp ) {
+ if (loop_format != AS::SAMPLE_LOOP_NONE && c.mix.offset < loop_begin_fp) {
/* loopstart reached */
- if ( loop_format==AS::SAMPLE_LOOP_PING_PONG ) {
+ if (loop_format == AS::SAMPLE_LOOP_PING_PONG) {
/* bounce ping pong */
- c.mix.offset= loop_begin_fp + ( loop_begin_fp-c.mix.offset );
- c.mix.increment=-c.mix.increment;
+ c.mix.offset = loop_begin_fp + (loop_begin_fp - c.mix.offset);
+ c.mix.increment = -c.mix.increment;
} else {
/* go to loop-end */
- c.mix.offset=loop_end_fp-(loop_begin_fp-c.mix.offset);
+ c.mix.offset = loop_end_fp - (loop_begin_fp - c.mix.offset);
}
} else {
/* check for sample not reaching begining */
- if(c.mix.offset < 0) {
+ if (c.mix.offset < 0) {
- c.active=false;
+ c.active = false;
break;
}
}
} else {
/* going forward */
- if( loop_format!=AS::SAMPLE_LOOP_NONE && c.mix.offset >= loop_end_fp ) {
+ if (loop_format != AS::SAMPLE_LOOP_NONE && c.mix.offset >= loop_end_fp) {
/* loopend reached */
- if ( loop_format==AS::SAMPLE_LOOP_PING_PONG ) {
+ if (loop_format == AS::SAMPLE_LOOP_PING_PONG) {
/* bounce ping pong */
- c.mix.offset=loop_end_fp-(c.mix.offset-loop_end_fp);
- c.mix.increment=-c.mix.increment;
+ c.mix.offset = loop_end_fp - (c.mix.offset - loop_end_fp);
+ c.mix.increment = -c.mix.increment;
} else {
/* go to loop-begin */
- if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) {
- for(int i=0;i<2;i++) {
- c.mix.ima_adpcm[i].step_index=c.mix.ima_adpcm[i].loop_step_index;
- c.mix.ima_adpcm[i].predictor=c.mix.ima_adpcm[i].loop_predictor;
- c.mix.ima_adpcm[i].last_nibble=loop_begin_fp>>MIX_FRAC_BITS;
+ if (format == AS::SAMPLE_FORMAT_IMA_ADPCM) {
+ for (int i = 0; i < 2; i++) {
+ c.mix.ima_adpcm[i].step_index = c.mix.ima_adpcm[i].loop_step_index;
+ c.mix.ima_adpcm[i].predictor = c.mix.ima_adpcm[i].loop_predictor;
+ c.mix.ima_adpcm[i].last_nibble = loop_begin_fp >> MIX_FRAC_BITS;
}
- c.mix.offset=loop_begin_fp;
+ c.mix.offset = loop_begin_fp;
} else {
- c.mix.offset=loop_begin_fp+(c.mix.offset-loop_end_fp);
+ c.mix.offset = loop_begin_fp + (c.mix.offset - loop_end_fp);
}
-
}
} else {
/* no loop, check for end of sample */
- if(c.mix.offset >= length_fp) {
+ if (c.mix.offset >= length_fp) {
- c.active=false;
+ c.active = false;
break;
}
}
@@ -480,214 +458,202 @@ void AudioMixerSW::mix_channel(Channel& c) {
/** MIXCOUNT COMPUTING **/
/* next possible limit (looppoints or sample begin/end */
- limit=(c.mix.increment < 0) ?begin_limit:end_limit;
+ limit = (c.mix.increment < 0) ? begin_limit : end_limit;
/* compute what is shorter, the todo or the limit? */
- aux=(limit-c.mix.offset)/c.mix.increment+1;
- target=(aux<todo)?aux:todo; /* mix target is the shorter buffer */
+ aux = (limit - c.mix.offset) / c.mix.increment + 1;
+ target = (aux < todo) ? aux : todo; /* mix target is the shorter buffer */
/* check just in case */
- if ( target<=0 ) {
- c.active=false;
+ if (target <= 0) {
+ c.active = false;
break;
}
- todo-=target;
+ todo -= target;
- int32_t offset=c.mix.offset&mix_chunk_mask; /* strip integer */
- c.mix.offset-=offset;
+ int32_t offset = c.mix.offset & mix_chunk_mask; /* strip integer */
+ c.mix.offset -= offset;
- rstate.increment=c.mix.increment;
- rstate.amount=target;
- rstate.pos=offset;
+ rstate.increment = c.mix.increment;
+ rstate.amount = target;
+ rstate.pos = offset;
/* Macros to call the resample function for all possibilities, creating a dedicated-non branchy function call for each thanks to template magic*/
-#define CALL_RESAMPLE_FUNC( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\
- do_resample<m_depth,m_stereo,m_ima_adpcm, m_use_filter,m_use_fx,m_interp, m_mode>(\
- src_ptr,\
- dst_buff,&rstate);
-
-
-#define CALL_RESAMPLE_INTERP( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\
- if(m_interp==INTERPOLATION_RAW) {\
- CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_RAW,m_mode);\
- } else if(m_interp==INTERPOLATION_LINEAR) {\
- CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_LINEAR,m_mode);\
- } else if(m_interp==INTERPOLATION_CUBIC) {\
- CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_CUBIC,m_mode);\
- }\
-
-#define CALL_RESAMPLE_FX( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\
- if(m_use_fx) {\
- CALL_RESAMPLE_INTERP(m_depth,m_stereo, m_ima_adpcm,m_use_filter,true,m_interp, m_mode);\
- } else {\
- CALL_RESAMPLE_INTERP(m_depth,m_stereo, m_ima_adpcm,m_use_filter,false,m_interp, m_mode);\
- }\
-
+#define CALL_RESAMPLE_FUNC(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode) \
+ do_resample<m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode>( \
+ src_ptr, \
+ dst_buff, &rstate);
-#define CALL_RESAMPLE_FILTER( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\
- if(m_use_filter) {\
- CALL_RESAMPLE_FX(m_depth,m_stereo, m_ima_adpcm,true,m_use_fx,m_interp, m_mode);\
- } else {\
- CALL_RESAMPLE_FX(m_depth,m_stereo, m_ima_adpcm,false,m_use_fx,m_interp, m_mode);\
- }\
-
-#define CALL_RESAMPLE_STEREO( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\
- if(m_stereo) {\
- CALL_RESAMPLE_FILTER(m_depth,true,m_ima_adpcm, m_use_filter,m_use_fx,m_interp, m_mode);\
- } else {\
- CALL_RESAMPLE_FILTER(m_depth,false,m_ima_adpcm,m_use_filter,m_use_fx,m_interp, m_mode);\
- }\
+#define CALL_RESAMPLE_INTERP(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode) \
+ if (m_interp == INTERPOLATION_RAW) { \
+ CALL_RESAMPLE_FUNC(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, INTERPOLATION_RAW, m_mode); \
+ } else if (m_interp == INTERPOLATION_LINEAR) { \
+ CALL_RESAMPLE_FUNC(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, INTERPOLATION_LINEAR, m_mode); \
+ } else if (m_interp == INTERPOLATION_CUBIC) { \
+ CALL_RESAMPLE_FUNC(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, INTERPOLATION_CUBIC, m_mode); \
+ }
-#define CALL_RESAMPLE_MODE( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\
- if(m_mode==MIX_STEREO) {\
- CALL_RESAMPLE_STEREO(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,m_interp, MIX_STEREO);\
- } else {\
- CALL_RESAMPLE_STEREO(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,m_interp, MIX_QUAD);\
- }\
+#define CALL_RESAMPLE_FX(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode) \
+ if (m_use_fx) { \
+ CALL_RESAMPLE_INTERP(m_depth, m_stereo, m_ima_adpcm, m_use_filter, true, m_interp, m_mode); \
+ } else { \
+ CALL_RESAMPLE_INTERP(m_depth, m_stereo, m_ima_adpcm, m_use_filter, false, m_interp, m_mode); \
+ }
+#define CALL_RESAMPLE_FILTER(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode) \
+ if (m_use_filter) { \
+ CALL_RESAMPLE_FX(m_depth, m_stereo, m_ima_adpcm, true, m_use_fx, m_interp, m_mode); \
+ } else { \
+ CALL_RESAMPLE_FX(m_depth, m_stereo, m_ima_adpcm, false, m_use_fx, m_interp, m_mode); \
+ }
+#define CALL_RESAMPLE_STEREO(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode) \
+ if (m_stereo) { \
+ CALL_RESAMPLE_FILTER(m_depth, true, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode); \
+ } else { \
+ CALL_RESAMPLE_FILTER(m_depth, false, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode); \
+ }
+#define CALL_RESAMPLE_MODE(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode) \
+ if (m_mode == MIX_STEREO) { \
+ CALL_RESAMPLE_STEREO(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, MIX_STEREO); \
+ } else { \
+ CALL_RESAMPLE_STEREO(m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, MIX_QUAD); \
+ }
- if (format==AS::SAMPLE_FORMAT_PCM8) {
+ if (format == AS::SAMPLE_FORMAT_PCM8) {
- int8_t *src_ptr = &((int8_t*)data)[(c.mix.offset >> MIX_FRAC_BITS)<<(is_stereo?1:0) ];
- CALL_RESAMPLE_MODE(int8_t,is_stereo,false,use_filter,use_fx,interpolation_type,mix_channels);
+ int8_t *src_ptr = &((int8_t *)data)[(c.mix.offset >> MIX_FRAC_BITS) << (is_stereo ? 1 : 0)];
+ CALL_RESAMPLE_MODE(int8_t, is_stereo, false, use_filter, use_fx, interpolation_type, mix_channels);
- } else if (format==AS::SAMPLE_FORMAT_PCM16) {
- int16_t *src_ptr = &((int16_t*)data)[(c.mix.offset >> MIX_FRAC_BITS)<<(is_stereo?1:0) ];
- CALL_RESAMPLE_MODE(int16_t,is_stereo,false,use_filter,use_fx,interpolation_type,mix_channels);
+ } else if (format == AS::SAMPLE_FORMAT_PCM16) {
+ int16_t *src_ptr = &((int16_t *)data)[(c.mix.offset >> MIX_FRAC_BITS) << (is_stereo ? 1 : 0)];
+ CALL_RESAMPLE_MODE(int16_t, is_stereo, false, use_filter, use_fx, interpolation_type, mix_channels);
- } else if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) {
- for(int i=0;i<2;i++) {
- c.mix.ima_adpcm[i].window_ofs=c.mix.offset>>MIX_FRAC_BITS;
- c.mix.ima_adpcm[i].ptr=(const uint8_t*)data;
+ } else if (format == AS::SAMPLE_FORMAT_IMA_ADPCM) {
+ for (int i = 0; i < 2; i++) {
+ c.mix.ima_adpcm[i].window_ofs = c.mix.offset >> MIX_FRAC_BITS;
+ c.mix.ima_adpcm[i].ptr = (const uint8_t *)data;
}
- int8_t *src_ptr = NULL;
- CALL_RESAMPLE_MODE(int8_t,is_stereo,true,use_filter,use_fx,interpolation_type,mix_channels);
-
+ int8_t *src_ptr = NULL;
+ CALL_RESAMPLE_MODE(int8_t, is_stereo, true, use_filter, use_fx, interpolation_type, mix_channels);
}
- c.mix.offset+=rstate.pos;
- dst_buff+=target*mix_channels;
- rstate.reverb_buffer+=target*mix_channels;
+ c.mix.offset += rstate.pos;
+ dst_buff += target * mix_channels;
+ rstate.reverb_buffer += target * mix_channels;
}
- c.filter.old_coefs=c.filter.coefs;
+ c.filter.old_coefs = c.filter.coefs;
}
void AudioMixerSW::mix_chunk() {
ERR_FAIL_COND(mix_chunk_left);
- inside_mix=true;
+ inside_mix = true;
// emit tick in usecs
- for (int i=0;i<mix_chunk_size*mix_channels;i++) {
+ for (int i = 0; i < mix_chunk_size * mix_channels; i++) {
- mix_buffer[i]=0;
+ mix_buffer[i] = 0;
}
#ifndef NO_REVERB
- for(int i=0;i<max_reverbs;i++)
- reverb_state[i].used_in_chunk=false;
+ for (int i = 0; i < max_reverbs; i++)
+ reverb_state[i].used_in_chunk = false;
#endif
-
audio_mixer_chunk_call(mix_chunk_size);
- int ac=0;
- for (int i=0;i<MAX_CHANNELS;i++) {
+ int ac = 0;
+ for (int i = 0; i < MAX_CHANNELS; i++) {
if (!channels[i].active)
continue;
ac++;
/* process volume */
- Channel&c=channels[i];
+ Channel &c = channels[i];
#ifndef NO_REVERB
- bool has_reverb = c.reverb_send>CMP_EPSILON && fx_enabled;
+ bool has_reverb = c.reverb_send > CMP_EPSILON && fx_enabled;
if (has_reverb || c.had_prev_reverb) {
if (!reverb_state[c.reverb_room].used_in_chunk) {
//zero the room
int32_t *buff = reverb_state[c.reverb_room].buffer;
- int len = mix_chunk_size*mix_channels;
- for (int j=0;j<len;j++) {
+ int len = mix_chunk_size * mix_channels;
+ for (int j = 0; j < len; j++) {
- buff[j]=0; // buffer in use, clear it for appending
+ buff[j] = 0; // buffer in use, clear it for appending
}
- reverb_state[c.reverb_room].used_in_chunk=true;
+ reverb_state[c.reverb_room].used_in_chunk = true;
}
}
#else
bool has_reverb = false;
#endif
- bool has_chorus = c.chorus_send>CMP_EPSILON && fx_enabled;
-
+ bool has_chorus = c.chorus_send > CMP_EPSILON && fx_enabled;
mix_channel(c);
- c.had_prev_reverb=has_reverb;
- c.had_prev_chorus=has_chorus;
-
+ c.had_prev_reverb = has_reverb;
+ c.had_prev_chorus = has_chorus;
}
- //process reverb
+//process reverb
#ifndef NO_REVERB
if (fx_enabled) {
-
- for(int i=0;i<max_reverbs;i++) {
+ for (int i = 0; i < max_reverbs; i++) {
if (!reverb_state[i].enabled && !reverb_state[i].used_in_chunk)
continue; //this reverb is not in use
- int32_t *src=NULL;
+ int32_t *src = NULL;
if (reverb_state[i].used_in_chunk)
- src=reverb_state[i].buffer;
+ src = reverb_state[i].buffer;
else
- src=zero_buffer;
+ src = zero_buffer;
- bool in_use=false;
+ bool in_use = false;
- int passes=mix_channels/2;
+ int passes = mix_channels / 2;
- for(int j=0;j<passes;j++) {
+ for (int j = 0; j < passes; j++) {
- if (reverb_state[i].reverb[j].process((int*)&src[j*2],(int*)&mix_buffer[j*2],mix_chunk_size,passes))
- in_use=true;
+ if (reverb_state[i].reverb[j].process((int *)&src[j * 2], (int *)&mix_buffer[j * 2], mix_chunk_size, passes))
+ in_use = true;
}
if (in_use) {
- reverb_state[i].enabled=true;
- reverb_state[i].frames_idle=0;
+ reverb_state[i].enabled = true;
+ reverb_state[i].frames_idle = 0;
//copy data over
} else {
- reverb_state[i].frames_idle+=mix_chunk_size;
+ reverb_state[i].frames_idle += mix_chunk_size;
if (false) { // go idle because too many frames passed
//disable this reverb, as nothing important happened on it
- reverb_state[i].enabled=false;
- reverb_state[i].frames_idle=0;
+ reverb_state[i].enabled = false;
+ reverb_state[i].frames_idle = 0;
}
}
-
}
}
#endif
- mix_chunk_left=mix_chunk_size;
- inside_mix=false;
+ mix_chunk_left = mix_chunk_size;
+ inside_mix = false;
}
-int AudioMixerSW::mix(int32_t *p_buffer,int p_frames) {
-
- int todo=p_frames;
- int mixes=0;
+int AudioMixerSW::mix(int32_t *p_buffer, int p_frames) {
- while(todo) {
+ int todo = p_frames;
+ int mixes = 0;
+ while (todo) {
if (!mix_chunk_left) {
@@ -697,16 +663,16 @@ int AudioMixerSW::mix(int32_t *p_buffer,int p_frames) {
mixes++;
}
- int to_mix=MIN(mix_chunk_left,todo);
- int from=mix_chunk_size-mix_chunk_left;
+ int to_mix = MIN(mix_chunk_left, todo);
+ int from = mix_chunk_size - mix_chunk_left;
- for (int i=0;i<to_mix*2;i++) {
+ for (int i = 0; i < to_mix * 2; i++) {
- (*p_buffer++)=mix_buffer[from*2+i];
+ (*p_buffer++) = mix_buffer[from * 2 + i];
}
- mix_chunk_left-=to_mix;
- todo-=to_mix;
+ mix_chunk_left -= to_mix;
+ todo -= to_mix;
}
return mixes;
@@ -714,20 +680,20 @@ int AudioMixerSW::mix(int32_t *p_buffer,int p_frames) {
uint64_t AudioMixerSW::get_step_usecs() const {
- double mct = (1<<mix_chunk_bits)/double(mix_rate);
- return mct*1000000.0;
+ double mct = (1 << mix_chunk_bits) / double(mix_rate);
+ return mct * 1000000.0;
}
int AudioMixerSW::_get_channel(ChannelID p_channel) const {
- if (p_channel<0) {
+ if (p_channel < 0) {
return -1;
}
- int idx=p_channel%MAX_CHANNELS;
- int check=p_channel/MAX_CHANNELS;
- ERR_FAIL_INDEX_V(idx,MAX_CHANNELS,-1);
- if (channels[idx].check!=check) {
+ int idx = p_channel % MAX_CHANNELS;
+ int check = p_channel / MAX_CHANNELS;
+ ERR_FAIL_INDEX_V(idx, MAX_CHANNELS, -1);
+ if (channels[idx].check != check) {
return -1;
}
if (!channels[idx].active) {
@@ -739,130 +705,123 @@ int AudioMixerSW::_get_channel(ChannelID p_channel) const {
AudioMixer::ChannelID AudioMixerSW::channel_alloc(RID p_sample) {
- ERR_FAIL_COND_V( !sample_manager->is_sample(p_sample), INVALID_CHANNEL );
+ ERR_FAIL_COND_V(!sample_manager->is_sample(p_sample), INVALID_CHANNEL);
-
- int index=-1;
- for (int i=0;i<MAX_CHANNELS;i++) {
+ int index = -1;
+ for (int i = 0; i < MAX_CHANNELS; i++) {
if (!channels[i].active) {
- index=i;
+ index = i;
break;
}
}
- if (index==-1)
+ if (index == -1)
return INVALID_CHANNEL;
- Channel &c=channels[index];
+ Channel &c = channels[index];
// init variables
- c.sample=p_sample;
- c.vol=1;
- c.pan=0;
- c.depth=0;
- c.height=0;
- c.chorus_send=0;
- c.reverb_send=0;
- c.reverb_room=REVERB_HALL;
- c.positional=false;
- c.filter.type=FILTER_NONE;
- c.speed=sample_manager->sample_get_mix_rate(p_sample);
- c.active=true;
- c.check=channel_id_count++;
- c.first_mix=true;
+ c.sample = p_sample;
+ c.vol = 1;
+ c.pan = 0;
+ c.depth = 0;
+ c.height = 0;
+ c.chorus_send = 0;
+ c.reverb_send = 0;
+ c.reverb_room = REVERB_HALL;
+ c.positional = false;
+ c.filter.type = FILTER_NONE;
+ c.speed = sample_manager->sample_get_mix_rate(p_sample);
+ c.active = true;
+ c.check = channel_id_count++;
+ c.first_mix = true;
// init mix variables
- c.mix.offset=0;
- c.mix.increment=1;
+ c.mix.offset = 0;
+ c.mix.increment = 1;
//zero everything when this errors
- for(int i=0;i<4;i++) {
- c.mix.vol[i]=0;
- c.mix.reverb_vol[i]=0;
- c.mix.chorus_vol[i]=0;
+ for (int i = 0; i < 4; i++) {
+ c.mix.vol[i] = 0;
+ c.mix.reverb_vol[i] = 0;
+ c.mix.chorus_vol[i] = 0;
- c.mix.old_vol[i]=0;
- c.mix.old_reverb_vol[i]=0;
- c.mix.old_chorus_vol[i]=0;
+ c.mix.old_vol[i] = 0;
+ c.mix.old_reverb_vol[i] = 0;
+ c.mix.old_chorus_vol[i] = 0;
}
- c.had_prev_chorus=false;
- c.had_prev_reverb=false;
- c.had_prev_vol=false;
-
+ c.had_prev_chorus = false;
+ c.had_prev_reverb = false;
+ c.had_prev_vol = false;
- if (sample_manager->sample_get_format(c.sample)==AudioServer::SAMPLE_FORMAT_IMA_ADPCM) {
+ if (sample_manager->sample_get_format(c.sample) == AudioServer::SAMPLE_FORMAT_IMA_ADPCM) {
- for(int i=0;i<2;i++) {
- c.mix.ima_adpcm[i].step_index=0;
- c.mix.ima_adpcm[i].predictor=0;
- c.mix.ima_adpcm[i].loop_step_index=0;
- c.mix.ima_adpcm[i].loop_predictor=0;
- c.mix.ima_adpcm[i].last_nibble=-1;
- c.mix.ima_adpcm[i].loop_pos=0x7FFFFFFF;
- c.mix.ima_adpcm[i].window_ofs=0;
- c.mix.ima_adpcm[i].ptr=NULL;
+ for (int i = 0; i < 2; i++) {
+ c.mix.ima_adpcm[i].step_index = 0;
+ c.mix.ima_adpcm[i].predictor = 0;
+ c.mix.ima_adpcm[i].loop_step_index = 0;
+ c.mix.ima_adpcm[i].loop_predictor = 0;
+ c.mix.ima_adpcm[i].last_nibble = -1;
+ c.mix.ima_adpcm[i].loop_pos = 0x7FFFFFFF;
+ c.mix.ima_adpcm[i].window_ofs = 0;
+ c.mix.ima_adpcm[i].ptr = NULL;
}
}
- ChannelID ret_id = index+c.check*MAX_CHANNELS;
+ ChannelID ret_id = index + c.check * MAX_CHANNELS;
return ret_id;
-
}
void AudioMixerSW::channel_set_volume(ChannelID p_channel, float p_gain) {
- if (p_gain>3) // avoid gain going too high
- p_gain=3;
- if (p_gain<0)
- p_gain=0;
+ if (p_gain > 3) // avoid gain going too high
+ p_gain = 3;
+ if (p_gain < 0)
+ p_gain = 0;
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
Channel &c = channels[chan];
//Math::exp( p_db * 0.11512925464970228420089957273422 );
- c.vol=p_gain;
-
+ c.vol = p_gain;
}
-void AudioMixerSW::channel_set_pan(ChannelID p_channel, float p_pan, float p_depth,float p_height) {
+void AudioMixerSW::channel_set_pan(ChannelID p_channel, float p_pan, float p_depth, float p_height) {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
Channel &c = channels[chan];
- c.pan=p_pan;
- c.depth=p_depth;
- c.height=p_height;
-
+ c.pan = p_pan;
+ c.depth = p_depth;
+ c.height = p_height;
}
void AudioMixerSW::channel_set_filter(ChannelID p_channel, FilterType p_type, float p_cutoff, float p_resonance, float p_gain) {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
Channel &c = channels[chan];
- if (c.filter.type==p_type && c.filter.cutoff==p_cutoff && c.filter.resonance==p_resonance && c.filter.gain==p_gain)
+ if (c.filter.type == p_type && c.filter.cutoff == p_cutoff && c.filter.resonance == p_resonance && c.filter.gain == p_gain)
return; //bye
+ bool type_changed = p_type != c.filter.type;
- bool type_changed = p_type!=c.filter.type;
-
- c.filter.type=p_type;
- c.filter.cutoff=p_cutoff;
- c.filter.resonance=p_resonance;
- c.filter.gain=p_gain;
-
+ c.filter.type = p_type;
+ c.filter.cutoff = p_cutoff;
+ c.filter.resonance = p_resonance;
+ c.filter.gain = p_gain;
AudioFilterSW filter;
- switch(p_type) {
+ switch (p_type) {
case FILTER_NONE: {
return; //do nothing else
@@ -903,77 +862,71 @@ void AudioMixerSW::channel_set_filter(ChannelID p_channel, FilterType p_type, fl
filter.prepare_coefficients(&coefs);
if (!type_changed)
- c.filter.old_coefs=c.filter.coefs;
-
- c.filter.coefs.b0=coefs.b0;
- c.filter.coefs.b1=coefs.b1;
- c.filter.coefs.b2=coefs.b2;
- c.filter.coefs.a1=coefs.a1;
- c.filter.coefs.a2=coefs.a2;
+ c.filter.old_coefs = c.filter.coefs;
+ c.filter.coefs.b0 = coefs.b0;
+ c.filter.coefs.b1 = coefs.b1;
+ c.filter.coefs.b2 = coefs.b2;
+ c.filter.coefs.a1 = coefs.a1;
+ c.filter.coefs.a2 = coefs.a2;
if (type_changed) {
//type changed reset filter
- c.filter.old_coefs=c.filter.coefs;
- c.mix.filter_l.ha[0]=0;
- c.mix.filter_l.ha[1]=0;
- c.mix.filter_l.hb[0]=0;
- c.mix.filter_l.hb[1]=0;
- c.mix.filter_r.ha[0]=0;
- c.mix.filter_r.ha[1]=0;
- c.mix.filter_r.hb[0]=0;
- c.mix.filter_r.hb[1]=0;
+ c.filter.old_coefs = c.filter.coefs;
+ c.mix.filter_l.ha[0] = 0;
+ c.mix.filter_l.ha[1] = 0;
+ c.mix.filter_l.hb[0] = 0;
+ c.mix.filter_l.hb[1] = 0;
+ c.mix.filter_r.ha[0] = 0;
+ c.mix.filter_r.ha[1] = 0;
+ c.mix.filter_r.hb[0] = 0;
+ c.mix.filter_r.hb[1] = 0;
}
-
-
}
-void AudioMixerSW::channel_set_chorus(ChannelID p_channel, float p_chorus ) {
+void AudioMixerSW::channel_set_chorus(ChannelID p_channel, float p_chorus) {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
Channel &c = channels[chan];
- c.chorus_send=p_chorus;
-
+ c.chorus_send = p_chorus;
}
void AudioMixerSW::channel_set_reverb(ChannelID p_channel, ReverbRoomType p_room_type, float p_reverb) {
- ERR_FAIL_INDEX(p_room_type,MAX_REVERBS);
+ ERR_FAIL_INDEX(p_room_type, MAX_REVERBS);
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
Channel &c = channels[chan];
- c.reverb_room=p_room_type;
- c.reverb_send=p_reverb;
-
+ c.reverb_room = p_room_type;
+ c.reverb_send = p_reverb;
}
void AudioMixerSW::channel_set_mix_rate(ChannelID p_channel, int p_mix_rate) {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
Channel &c = channels[chan];
- c.speed=p_mix_rate;
-
+ c.speed = p_mix_rate;
}
void AudioMixerSW::channel_set_positional(ChannelID p_channel, bool p_positional) {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
Channel &c = channels[chan];
- c.positional=p_positional;
+ c.positional = p_positional;
}
float AudioMixerSW::channel_get_volume(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
@@ -984,7 +937,7 @@ float AudioMixerSW::channel_get_volume(ChannelID p_channel) const {
float AudioMixerSW::channel_get_pan(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
@@ -993,7 +946,7 @@ float AudioMixerSW::channel_get_pan(ChannelID p_channel) const {
float AudioMixerSW::channel_get_pan_depth(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
@@ -1002,17 +955,16 @@ float AudioMixerSW::channel_get_pan_depth(ChannelID p_channel) const {
float AudioMixerSW::channel_get_pan_height(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
return c.height;
-
}
AudioMixer::FilterType AudioMixerSW::channel_get_filter_type(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return FILTER_NONE;
const Channel &c = channels[chan];
@@ -1020,61 +972,55 @@ AudioMixer::FilterType AudioMixerSW::channel_get_filter_type(ChannelID p_channel
}
float AudioMixerSW::channel_get_filter_cutoff(ChannelID p_channel) const {
-
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
return c.filter.cutoff;
-
}
float AudioMixerSW::channel_get_filter_resonance(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
return c.filter.resonance;
-
}
float AudioMixerSW::channel_get_filter_gain(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
return c.filter.gain;
}
-
float AudioMixerSW::channel_get_chorus(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
return c.chorus_send;
-
}
AudioMixer::ReverbRoomType AudioMixerSW::channel_get_reverb_type(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return REVERB_HALL;
const Channel &c = channels[chan];
return c.reverb_room;
-
}
float AudioMixerSW::channel_get_reverb(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
@@ -1084,7 +1030,7 @@ float AudioMixerSW::channel_get_reverb(ChannelID p_channel) const {
int AudioMixerSW::channel_get_mix_rate(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return 0;
const Channel &c = channels[chan];
@@ -1093,7 +1039,7 @@ int AudioMixerSW::channel_get_mix_rate(ChannelID p_channel) const {
bool AudioMixerSW::channel_is_positional(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return false;
const Channel &c = channels[chan];
@@ -1103,106 +1049,100 @@ bool AudioMixerSW::channel_is_positional(ChannelID p_channel) const {
bool AudioMixerSW::channel_is_valid(ChannelID p_channel) const {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return false;
return channels[chan].active;
}
-
void AudioMixerSW::channel_free(ChannelID p_channel) {
int chan = _get_channel(p_channel);
- if (chan<0 || chan >=MAX_CHANNELS)
+ if (chan < 0 || chan >= MAX_CHANNELS)
return;
- Channel &c=channels[chan];
+ Channel &c = channels[chan];
if (!c.active)
return;
- bool has_vol=false;
+ bool has_vol = false;
- for(int i=0;i<mix_channels;i++) {
+ for (int i = 0; i < mix_channels; i++) {
if (c.mix.vol[i])
- has_vol=true;
+ has_vol = true;
if (c.mix.reverb_vol[i])
- has_vol=true;
+ has_vol = true;
if (c.mix.chorus_vol[i])
- has_vol=true;
+ has_vol = true;
}
if (c.active && has_vol && inside_mix) {
// drive voice to zero, and run a chunk, the VRAMP will fade it good
- c.vol=0;
- c.reverb_send=0;
- c.chorus_send=0;
+ c.vol = 0;
+ c.reverb_send = 0;
+ c.chorus_send = 0;
mix_channel(c);
}
/* @TODO RAMP DOWN ON STOP */
- c.active=false;
+ c.active = false;
}
-
-
-AudioMixerSW::AudioMixerSW(SampleManagerSW *p_sample_manager,int p_desired_latency_ms,int p_mix_rate,MixChannels p_mix_channels,bool p_use_fx,InterpolationType p_interp,MixStepCallback p_step_callback,void *p_step_udata) {
+AudioMixerSW::AudioMixerSW(SampleManagerSW *p_sample_manager, int p_desired_latency_ms, int p_mix_rate, MixChannels p_mix_channels, bool p_use_fx, InterpolationType p_interp, MixStepCallback p_step_callback, void *p_step_udata) {
if (OS::get_singleton()->is_stdout_verbose()) {
print_line("AudioServerSW Params: ");
- print_line(" -mix chans: "+itos(p_mix_channels));
- print_line(" -mix rate: "+itos(p_mix_rate));
- print_line(" -latency: "+itos(p_desired_latency_ms));
- print_line(" -fx: "+itos(p_use_fx));
- print_line(" -interp: "+itos(p_interp));
+ print_line(" -mix chans: " + itos(p_mix_channels));
+ print_line(" -mix rate: " + itos(p_mix_rate));
+ print_line(" -latency: " + itos(p_desired_latency_ms));
+ print_line(" -fx: " + itos(p_use_fx));
+ print_line(" -interp: " + itos(p_interp));
}
- sample_manager=p_sample_manager;
- mix_channels=p_mix_channels;
- mix_rate=p_mix_rate;
- step_callback=p_step_callback;
- step_udata=p_step_udata;
-
+ sample_manager = p_sample_manager;
+ mix_channels = p_mix_channels;
+ mix_rate = p_mix_rate;
+ step_callback = p_step_callback;
+ step_udata = p_step_udata;
- mix_chunk_bits=nearest_shift( p_desired_latency_ms * p_mix_rate / 1000 );
+ mix_chunk_bits = nearest_shift(p_desired_latency_ms * p_mix_rate / 1000);
- mix_chunk_size=(1<<mix_chunk_bits);
- mix_chunk_mask=mix_chunk_size-1;
- mix_buffer = memnew_arr(int32_t,mix_chunk_size*mix_channels);
+ mix_chunk_size = (1 << mix_chunk_bits);
+ mix_chunk_mask = mix_chunk_size - 1;
+ mix_buffer = memnew_arr(int32_t, mix_chunk_size * mix_channels);
#ifndef NO_REVERB
- zero_buffer = memnew_arr(int32_t,mix_chunk_size*mix_channels);
- for(int i=0;i<mix_chunk_size*mix_channels;i++)
- zero_buffer[i]=0; //zero buffer is zero...
+ zero_buffer = memnew_arr(int32_t, mix_chunk_size * mix_channels);
+ for (int i = 0; i < mix_chunk_size * mix_channels; i++)
+ zero_buffer[i] = 0; //zero buffer is zero...
- max_reverbs=MAX_REVERBS;
- int reverberators=mix_channels/2;
+ max_reverbs = MAX_REVERBS;
+ int reverberators = mix_channels / 2;
- reverb_state = memnew_arr(ReverbState,max_reverbs);
- for(int i=0;i<max_reverbs;i++) {
- reverb_state[i].enabled=false;
- reverb_state[i].reverb = memnew_arr(ReverbSW,reverberators);
- reverb_state[i].buffer = memnew_arr(int32_t,mix_chunk_size*mix_channels);
- reverb_state[i].frames_idle=0;
- for(int j=0;j<reverberators;j++) {
- static ReverbSW::ReverbMode modes[MAX_REVERBS]={ReverbSW::REVERB_MODE_STUDIO_SMALL,ReverbSW::REVERB_MODE_STUDIO_MEDIUM,ReverbSW::REVERB_MODE_STUDIO_LARGE,ReverbSW::REVERB_MODE_HALL};
+ reverb_state = memnew_arr(ReverbState, max_reverbs);
+ for (int i = 0; i < max_reverbs; i++) {
+ reverb_state[i].enabled = false;
+ reverb_state[i].reverb = memnew_arr(ReverbSW, reverberators);
+ reverb_state[i].buffer = memnew_arr(int32_t, mix_chunk_size * mix_channels);
+ reverb_state[i].frames_idle = 0;
+ for (int j = 0; j < reverberators; j++) {
+ static ReverbSW::ReverbMode modes[MAX_REVERBS] = { ReverbSW::REVERB_MODE_STUDIO_SMALL, ReverbSW::REVERB_MODE_STUDIO_MEDIUM, ReverbSW::REVERB_MODE_STUDIO_LARGE, ReverbSW::REVERB_MODE_HALL };
reverb_state[i].reverb[j].set_mix_rate(p_mix_rate);
reverb_state[i].reverb[j].set_mode(modes[i]);
}
-
}
- fx_enabled=p_use_fx;
+ fx_enabled = p_use_fx;
#else
- fx_enabled=false;
+ fx_enabled = false;
#endif
- mix_chunk_left=0;
-
- interpolation_type=p_interp;
- channel_id_count=1;
- inside_mix=false;
- channel_nrg=1.0;
+ mix_chunk_left = 0;
+ interpolation_type = p_interp;
+ channel_id_count = 1;
+ inside_mix = false;
+ channel_nrg = 1.0;
}
void AudioMixerSW::set_mixer_volume(float p_volume) {
- channel_nrg=p_volume;
+ channel_nrg = p_volume;
}
AudioMixerSW::~AudioMixerSW() {
@@ -1211,12 +1151,10 @@ AudioMixerSW::~AudioMixerSW() {
#ifndef NO_REVERB
memdelete_arr(zero_buffer);
- for(int i=0;i<max_reverbs;i++) {
+ for (int i = 0; i < max_reverbs; i++) {
memdelete_arr(reverb_state[i].reverb);
memdelete_arr(reverb_state[i].buffer);
}
memdelete_arr(reverb_state);
#endif
-
-
}
diff --git a/servers/audio/audio_mixer_sw.h b/servers/audio/audio_mixer_sw.h
index 952cad4cf..a02133199 100644
--- a/servers/audio/audio_mixer_sw.h
+++ b/servers/audio/audio_mixer_sw.h
@@ -29,14 +29,13 @@
#ifndef AUDIO_MIXER_SW_H
#define AUDIO_MIXER_SW_H
-#include "servers/audio_server.h"
-#include "servers/audio/sample_manager_sw.h"
#include "servers/audio/audio_filter_sw.h"
#include "servers/audio/reverb_sw.h"
+#include "servers/audio/sample_manager_sw.h"
+#include "servers/audio_server.h"
class AudioMixerSW : public AudioMixer {
public:
-
enum InterpolationType {
INTERPOLATION_RAW,
@@ -46,33 +45,32 @@ public:
enum MixChannels {
- MIX_STEREO=2,
- MIX_QUAD=4
+ MIX_STEREO = 2,
+ MIX_QUAD = 4
};
- typedef void (*MixStepCallback)(void*);
+ typedef void (*MixStepCallback)(void *);
private:
SampleManagerSW *sample_manager;
enum {
- MAX_CHANNELS=64,
+ MAX_CHANNELS = 64,
// fixed point defs
- MIX_FRAC_BITS=13,
- MIX_FRAC_LEN=(1<<MIX_FRAC_BITS),
- MIX_FRAC_MASK=MIX_FRAC_LEN-1,
- MIX_VOL_FRAC_BITS=12,
- MIX_VOLRAMP_FRAC_BITS=16,
- MIX_VOLRAMP_FRAC_LEN=(1<<MIX_VOLRAMP_FRAC_BITS),
- MIX_VOLRAMP_FRAC_MASK=MIX_VOLRAMP_FRAC_LEN-1,
- MIX_FILTER_FRAC_BITS=16,
- MIX_FILTER_RAMP_FRAC_BITS=8,
- MIX_VOL_MOVE_TO_24=4
+ MIX_FRAC_BITS = 13,
+ MIX_FRAC_LEN = (1 << MIX_FRAC_BITS),
+ MIX_FRAC_MASK = MIX_FRAC_LEN - 1,
+ MIX_VOL_FRAC_BITS = 12,
+ MIX_VOLRAMP_FRAC_BITS = 16,
+ MIX_VOLRAMP_FRAC_LEN = (1 << MIX_VOLRAMP_FRAC_BITS),
+ MIX_VOLRAMP_FRAC_MASK = MIX_VOLRAMP_FRAC_LEN - 1,
+ MIX_FILTER_FRAC_BITS = 16,
+ MIX_FILTER_RAMP_FRAC_BITS = 8,
+ MIX_VOL_MOVE_TO_24 = 4
};
-
struct Channel {
RID sample;
@@ -88,10 +86,9 @@ private:
int32_t old_reverb_vol[4];
int32_t old_chorus_vol[4];
-
struct Filter { //history (stereo)
- float ha[2],hb[2];
- } filter_l,filter_r;
+ float ha[2], hb[2];
+ } filter_l, filter_r;
struct IMA_ADPCM_State {
@@ -135,14 +132,23 @@ private:
struct Coefs {
- float a1,a2,b0,b1,b2; // fixed point coefficients
- } coefs,old_coefs;
+ float a1, a2, b0, b1, b2; // fixed point coefficients
+ } coefs, old_coefs;
} filter;
bool first_mix;
bool active;
- Channel() { active=false; check=-1; first_mix=false; filter.dirty=true; filter.type=FILTER_NONE; filter.cutoff=8000; filter.resonance=0; filter.gain=0; }
+ Channel() {
+ active = false;
+ check = -1;
+ first_mix = false;
+ filter.dirty = true;
+ filter.type = FILTER_NONE;
+ filter.cutoff = 8000;
+ filter.resonance = 0;
+ filter.gain = 0;
+ }
};
Channel channels[MAX_CHANNELS];
@@ -163,10 +169,8 @@ private:
uint32_t amount;
int32_t increment;
-
int32_t pos;
-
int32_t vol[4];
int32_t reverb_vol[4];
int32_t chorus_vol[4];
@@ -175,8 +179,6 @@ private:
int32_t reverb_vol_inc[4];
int32_t chorus_vol_inc[4];
-
-
Channel::Mix::Filter *filter_l;
Channel::Mix::Filter *filter_r;
Channel::Filter::Coefs coefs;
@@ -187,14 +189,12 @@ private:
int32_t *reverb_buffer;
};
-
-
- template<class Depth,bool is_stereo,bool use_filter,bool is_ima_adpcm,bool use_fx,InterpolationType type,MixChannels>
- _FORCE_INLINE_ void do_resample(const Depth* p_src, int32_t *p_dst, ResamplerState *p_state);
+ template <class Depth, bool is_stereo, bool use_filter, bool is_ima_adpcm, bool use_fx, InterpolationType type, MixChannels>
+ _FORCE_INLINE_ void do_resample(const Depth *p_src, int32_t *p_dst, ResamplerState *p_state);
MixChannels mix_channels;
- void mix_channel(Channel& p_channel);
+ void mix_channel(Channel &p_channel);
int mix_chunk_left;
void mix_chunk();
@@ -213,21 +213,22 @@ private:
ReverbSW *reverb;
int frames_idle;
int32_t *buffer; //reverb is sent here
- ReverbState() { enabled=false; frames_idle=0; used_in_chunk=false; }
+ ReverbState() {
+ enabled = false;
+ frames_idle = 0;
+ used_in_chunk = false;
+ }
};
ReverbState *reverb_state;
-
public:
-
-
virtual ChannelID channel_alloc(RID p_sample);
virtual void channel_set_volume(ChannelID p_channel, float p_gain);
- virtual void channel_set_pan(ChannelID p_channel, float p_pan, float p_depth=0,float height=0); //pan and depth go from -1 to 1
- virtual void channel_set_filter(ChannelID p_channel, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=1.0);
- virtual void channel_set_chorus(ChannelID p_channel, float p_chorus );
+ virtual void channel_set_pan(ChannelID p_channel, float p_pan, float p_depth = 0, float height = 0); //pan and depth go from -1 to 1
+ virtual void channel_set_filter(ChannelID p_channel, FilterType p_type, float p_cutoff, float p_resonance, float p_gain = 1.0);
+ virtual void channel_set_chorus(ChannelID p_channel, float p_chorus);
virtual void channel_set_reverb(ChannelID p_channel, ReverbRoomType p_room_type, float p_reverb);
virtual void channel_set_mix_rate(ChannelID p_channel, int p_mix_rate);
virtual void channel_set_positional(ChannelID p_channel, bool p_positional);
@@ -252,12 +253,12 @@ public:
virtual void channel_free(ChannelID p_channel);
- int mix(int32_t *p_buffer,int p_frames); //return amount of mixsteps
+ int mix(int32_t *p_buffer, int p_frames); //return amount of mixsteps
uint64_t get_step_usecs() const;
virtual void set_mixer_volume(float p_volume);
- AudioMixerSW(SampleManagerSW *p_sample_manager,int p_desired_latency_ms,int p_mix_rate,MixChannels p_mix_channels,bool p_use_fx=true,InterpolationType p_interp=INTERPOLATION_LINEAR,MixStepCallback p_step_callback=NULL,void *p_callback_udata=NULL);
+ AudioMixerSW(SampleManagerSW *p_sample_manager, int p_desired_latency_ms, int p_mix_rate, MixChannels p_mix_channels, bool p_use_fx = true, InterpolationType p_interp = INTERPOLATION_LINEAR, MixStepCallback p_step_callback = NULL, void *p_callback_udata = NULL);
~AudioMixerSW();
};
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_server_sw.cpp b/servers/audio/audio_server_sw.cpp
index b786d9d53..5b394e585 100644
--- a/servers/audio/audio_server_sw.cpp
+++ b/servers/audio/audio_server_sw.cpp
@@ -32,9 +32,12 @@
struct _AudioDriverLock {
- _AudioDriverLock() { if (AudioDriverSW::get_singleton()) AudioDriverSW::get_singleton()->lock(); }
- ~_AudioDriverLock() { if (AudioDriverSW::get_singleton()) AudioDriverSW::get_singleton()->unlock(); }
-
+ _AudioDriverLock() {
+ if (AudioDriverSW::get_singleton()) AudioDriverSW::get_singleton()->lock();
+ }
+ ~_AudioDriverLock() {
+ if (AudioDriverSW::get_singleton()) AudioDriverSW::get_singleton()->unlock();
+ }
};
#define AUDIO_LOCK _AudioDriverLock _adlock;
@@ -47,7 +50,7 @@ AudioMixer *AudioServerSW::get_mixer() {
/* CALLBACKS */
void AudioServerSW::audio_mixer_chunk_callback(int p_frames) {
-/*
+ /*
for(List<Stream*>::Element *E=event_streams.front();E;E=E->next()) {
if (E->get()->active)
@@ -58,45 +61,42 @@ void AudioServerSW::audio_mixer_chunk_callback(int p_frames) {
void AudioServerSW::_mixer_callback(void *p_udata) {
- AudioServerSW *self = (AudioServerSW*)p_udata;
- for(List<Stream*>::Element *E=self->active_audio_streams.front();E;E=E->next()) {
+ AudioServerSW *self = (AudioServerSW *)p_udata;
+ for (List<Stream *>::Element *E = self->active_audio_streams.front(); E; E = E->next()) {
if (!E->get()->active)
continue;
- EventStream *es=E->get()->event_stream;
+ EventStream *es = E->get()->event_stream;
if (!es)
continue;
es->update(self->mixer_step_usecs);
}
-
}
-void AudioServerSW::driver_process_chunk(int p_frames,int32_t *p_buffer) {
-
-
+void AudioServerSW::driver_process_chunk(int p_frames, int32_t *p_buffer) {
- int samples=p_frames*internal_buffer_channels;
+ int samples = p_frames * internal_buffer_channels;
- for(int i=0;i<samples;i++) {
- internal_buffer[i]=0;
+ for (int i = 0; i < samples; i++) {
+ internal_buffer[i] = 0;
}
- while(voice_rb.commands_left()) {
+ while (voice_rb.commands_left()) {
VoiceRBSW::Command cmd = voice_rb.pop_command();
- if (cmd.type==VoiceRBSW::Command::CMD_CHANGE_ALL_FX_VOLUMES) {
+ if (cmd.type == VoiceRBSW::Command::CMD_CHANGE_ALL_FX_VOLUMES) {
- SelfList<Voice>*al = active_list.first();
- while(al) {
+ SelfList<Voice> *al = active_list.first();
+ while (al) {
- Voice *v=al->self();
- if (v->channel!=AudioMixer::INVALID_CHANNEL) {
- mixer->channel_set_volume(v->channel,v->volume*fx_volume_scale);
+ Voice *v = al->self();
+ if (v->channel != AudioMixer::INVALID_CHANNEL) {
+ mixer->channel_set_volume(v->channel, v->volume * fx_volume_scale);
}
- al=al->next();
+ al = al->next();
}
continue;
@@ -104,246 +104,234 @@ void AudioServerSW::driver_process_chunk(int p_frames,int32_t *p_buffer) {
if (!voice_owner.owns(cmd.voice))
continue;
-
Voice *v = voice_owner.get(cmd.voice);
- switch(cmd.type) {
+ switch (cmd.type) {
case VoiceRBSW::Command::CMD_NONE: {
-
} break;
case VoiceRBSW::Command::CMD_PLAY: {
- if (v->channel!=AudioMixer::INVALID_CHANNEL)
+ if (v->channel != AudioMixer::INVALID_CHANNEL)
mixer->channel_free(v->channel);
RID sample = cmd.play.sample;
if (!sample_manager->is_sample(sample))
continue;
- v->channel=mixer->channel_alloc(sample);
- v->volume=1.0;
- mixer->channel_set_volume(v->channel,fx_volume_scale);
- if (v->channel==AudioMixer::INVALID_CHANNEL) {
+ v->channel = mixer->channel_alloc(sample);
+ v->volume = 1.0;
+ mixer->channel_set_volume(v->channel, fx_volume_scale);
+ if (v->channel == AudioMixer::INVALID_CHANNEL) {
#ifdef AUDIO_DEBUG
WARN_PRINT("AUDIO: all channels used, failed to allocate voice");
#endif
- v->active=false;
+ v->active = false;
break; // no voices left?
}
- v->active=true; // this kind of ensures it works
+ v->active = true; // this kind of ensures it works
if (!v->active_item.in_list())
active_list.add(&v->active_item);
} break;
case VoiceRBSW::Command::CMD_STOP: {
- if (v->channel!=AudioMixer::INVALID_CHANNEL) {
+ if (v->channel != AudioMixer::INVALID_CHANNEL) {
mixer->channel_free(v->channel);
if (v->active_item.in_list()) {
active_list.remove(&v->active_item);
}
}
- v->active=false;
+ v->active = false;
} break;
case VoiceRBSW::Command::CMD_SET_VOLUME: {
-
- if (v->channel!=AudioMixer::INVALID_CHANNEL) {
- v->volume=cmd.volume.volume;
- mixer->channel_set_volume(v->channel,cmd.volume.volume*fx_volume_scale);
+ if (v->channel != AudioMixer::INVALID_CHANNEL) {
+ v->volume = cmd.volume.volume;
+ mixer->channel_set_volume(v->channel, cmd.volume.volume * fx_volume_scale);
}
} break;
case VoiceRBSW::Command::CMD_SET_PAN: {
- if (v->channel!=AudioMixer::INVALID_CHANNEL)
- mixer->channel_set_pan(v->channel,cmd.pan.pan,cmd.pan.depth,cmd.pan.height);
+ if (v->channel != AudioMixer::INVALID_CHANNEL)
+ mixer->channel_set_pan(v->channel, cmd.pan.pan, cmd.pan.depth, cmd.pan.height);
} break;
case VoiceRBSW::Command::CMD_SET_FILTER: {
-
- if (v->channel!=AudioMixer::INVALID_CHANNEL)
- mixer->channel_set_filter(v->channel,(AudioMixer::FilterType)cmd.filter.type,cmd.filter.cutoff,cmd.filter.resonance,cmd.filter.gain);
+ if (v->channel != AudioMixer::INVALID_CHANNEL)
+ mixer->channel_set_filter(v->channel, (AudioMixer::FilterType)cmd.filter.type, cmd.filter.cutoff, cmd.filter.resonance, cmd.filter.gain);
} break;
case VoiceRBSW::Command::CMD_SET_CHORUS: {
- if (v->channel!=AudioMixer::INVALID_CHANNEL)
- mixer->channel_set_chorus(v->channel,cmd.chorus.send);
+ if (v->channel != AudioMixer::INVALID_CHANNEL)
+ mixer->channel_set_chorus(v->channel, cmd.chorus.send);
} break;
case VoiceRBSW::Command::CMD_SET_REVERB: {
- if (v->channel!=AudioMixer::INVALID_CHANNEL)
- mixer->channel_set_reverb(v->channel,(AudioMixer::ReverbRoomType)cmd.reverb.room,cmd.reverb.send);
+ if (v->channel != AudioMixer::INVALID_CHANNEL)
+ mixer->channel_set_reverb(v->channel, (AudioMixer::ReverbRoomType)cmd.reverb.room, cmd.reverb.send);
} break;
case VoiceRBSW::Command::CMD_SET_MIX_RATE: {
- if (v->channel!=AudioMixer::INVALID_CHANNEL)
- mixer->channel_set_mix_rate(v->channel,cmd.mix_rate.mix_rate);
+ if (v->channel != AudioMixer::INVALID_CHANNEL)
+ mixer->channel_set_mix_rate(v->channel, cmd.mix_rate.mix_rate);
} break;
case VoiceRBSW::Command::CMD_SET_POSITIONAL: {
- if (v->channel!=AudioMixer::INVALID_CHANNEL)
- mixer->channel_set_positional(v->channel,cmd.positional.positional);
+ if (v->channel != AudioMixer::INVALID_CHANNEL)
+ mixer->channel_set_positional(v->channel, cmd.positional.positional);
} break;
default: {}
-
}
}
- mixer->mix(internal_buffer,p_frames);
+ mixer->mix(internal_buffer, p_frames);
//uint64_t stepsize=mixer->get_step_usecs();
-
- for(List<Stream*>::Element *E=active_audio_streams.front();E;E=E->next()) {
+ for (List<Stream *>::Element *E = active_audio_streams.front(); E; E = E->next()) {
ERR_CONTINUE(!E->get()->active); // bug?
-
- AudioStream *as=E->get()->audio_stream;
+ AudioStream *as = E->get()->audio_stream;
if (!as)
continue;
- int channels=as->get_channel_count();
- if (channels==0)
+ int channels = as->get_channel_count();
+ if (channels == 0)
continue; // does not want mix
- if (!as->mix(stream_buffer,p_frames))
+ if (!as->mix(stream_buffer, p_frames))
continue; //nothing was mixed!!
- int32_t stream_vol_scale=(stream_volume*stream_volume_scale*E->get()->volume_scale)*(1<<STREAM_SCALE_BITS);
+ int32_t stream_vol_scale = (stream_volume * stream_volume_scale * E->get()->volume_scale) * (1 << STREAM_SCALE_BITS);
-#define STRSCALE(m_val) (((m_val>>STREAM_SCALE_BITS)*stream_vol_scale)>>8)
- switch(internal_buffer_channels) {
+#define STRSCALE(m_val) (((m_val >> STREAM_SCALE_BITS) * stream_vol_scale) >> 8)
+ switch (internal_buffer_channels) {
case 2: {
- switch(channels) {
+ switch (channels) {
case 1: {
- for(int i=0;i<p_frames;i++) {
+ for (int i = 0; i < p_frames; i++) {
- internal_buffer[(i<<1)+0]+=STRSCALE(stream_buffer[i]);
- internal_buffer[(i<<1)+1]+=STRSCALE(stream_buffer[i]);
+ internal_buffer[(i << 1) + 0] += STRSCALE(stream_buffer[i]);
+ internal_buffer[(i << 1) + 1] += STRSCALE(stream_buffer[i]);
}
} break;
case 2: {
- for(int i=0;i<p_frames*2;i++) {
+ for (int i = 0; i < p_frames * 2; i++) {
- internal_buffer[i]+=STRSCALE(stream_buffer[i]);
+ internal_buffer[i] += STRSCALE(stream_buffer[i]);
}
} break;
case 4: {
- for(int i=0;i<p_frames;i++) {
+ for (int i = 0; i < p_frames; i++) {
- internal_buffer[(i<<2)+0]+=STRSCALE((stream_buffer[(i<<2)+0]+stream_buffer[(i<<2)+2])>>1);
- internal_buffer[(i<<2)+1]+=STRSCALE((stream_buffer[(i<<2)+1]+stream_buffer[(i<<2)+3])>>1);
+ internal_buffer[(i << 2) + 0] += STRSCALE((stream_buffer[(i << 2) + 0] + stream_buffer[(i << 2) + 2]) >> 1);
+ internal_buffer[(i << 2) + 1] += STRSCALE((stream_buffer[(i << 2) + 1] + stream_buffer[(i << 2) + 3]) >> 1);
}
} break;
-
- } break;
+ }
+ break;
} break;
case 4: {
- switch(channels) {
+ switch (channels) {
case 1: {
- for(int i=0;i<p_frames;i++) {
+ for (int i = 0; i < p_frames; i++) {
- internal_buffer[(i<<2)+0]+=STRSCALE(stream_buffer[i]);
- internal_buffer[(i<<2)+1]+=STRSCALE(stream_buffer[i]);
- internal_buffer[(i<<2)+2]+=STRSCALE(stream_buffer[i]);
- internal_buffer[(i<<2)+3]+=STRSCALE(stream_buffer[i]);
+ internal_buffer[(i << 2) + 0] += STRSCALE(stream_buffer[i]);
+ internal_buffer[(i << 2) + 1] += STRSCALE(stream_buffer[i]);
+ internal_buffer[(i << 2) + 2] += STRSCALE(stream_buffer[i]);
+ internal_buffer[(i << 2) + 3] += STRSCALE(stream_buffer[i]);
}
} break;
case 2: {
- for(int i=0;i<p_frames*2;i++) {
+ for (int i = 0; i < p_frames * 2; i++) {
- internal_buffer[(i<<2)+0]+=STRSCALE(stream_buffer[(i<<1)+0]);
- internal_buffer[(i<<2)+1]+=STRSCALE(stream_buffer[(i<<1)+1]);
- internal_buffer[(i<<2)+2]+=STRSCALE(stream_buffer[(i<<1)+0]);
- internal_buffer[(i<<2)+3]+=STRSCALE(stream_buffer[(i<<1)+1]);
+ internal_buffer[(i << 2) + 0] += STRSCALE(stream_buffer[(i << 1) + 0]);
+ internal_buffer[(i << 2) + 1] += STRSCALE(stream_buffer[(i << 1) + 1]);
+ internal_buffer[(i << 2) + 2] += STRSCALE(stream_buffer[(i << 1) + 0]);
+ internal_buffer[(i << 2) + 3] += STRSCALE(stream_buffer[(i << 1) + 1]);
}
} break;
case 4: {
- for(int i=0;i<p_frames*4;i++) {
- internal_buffer[i]+=STRSCALE(stream_buffer[i]);
+ for (int i = 0; i < p_frames * 4; i++) {
+ internal_buffer[i] += STRSCALE(stream_buffer[i]);
}
} break;
-
- } break;
+ }
+ break;
} break;
case 6: {
-
} break;
}
#undef STRSCALE
}
- SelfList<Voice> *activeE=active_list.first();
- while(activeE) {
+ SelfList<Voice> *activeE = active_list.first();
+ while (activeE) {
- SelfList<Voice> *activeN=activeE->next();
- if (activeE->self()->channel==AudioMixer::INVALID_CHANNEL || !mixer->channel_is_valid(activeE->self()->channel)) {
+ SelfList<Voice> *activeN = activeE->next();
+ if (activeE->self()->channel == AudioMixer::INVALID_CHANNEL || !mixer->channel_is_valid(activeE->self()->channel)) {
active_list.remove(activeE);
- activeE->self()->active=false;
-
+ activeE->self()->active = false;
}
- activeE=activeN;
+ activeE = activeN;
}
- uint32_t peak=0;
- for(int i=0;i<samples;i++) {
+ uint32_t peak = 0;
+ for (int i = 0; i < samples; i++) {
//clamp to (1<<24) using branchless code
int32_t in = internal_buffer[i];
#ifdef DEBUG_ENABLED
{
- int mask = (in >> (32 - 1));
- uint32_t p = (in + mask) ^ mask;
- if (p>peak)
- peak=p;
+ int mask = (in >> (32 - 1));
+ uint32_t p = (in + mask) ^ mask;
+ if (p > peak)
+ peak = p;
}
#endif
- int32_t lo = -0x800000, hi=0x7FFFFF;
- lo-=in;
- hi-=in;
+ int32_t lo = -0x800000, hi = 0x7FFFFF;
+ lo -= in;
+ hi -= in;
in += (lo & ((lo < 0) - 1)) + (hi & ((hi > 0) - 1));
- p_buffer[i]=in<<8;
+ p_buffer[i] = in << 8;
}
- if (peak>max_peak)
- max_peak=peak;
+ if (peak > max_peak)
+ max_peak = peak;
}
-void AudioServerSW::driver_process(int p_frames,int32_t *p_buffer) {
-
+void AudioServerSW::driver_process(int p_frames, int32_t *p_buffer) {
- _output_delay=p_frames/double(AudioDriverSW::get_singleton()->get_mix_rate());
+ _output_delay = p_frames / double(AudioDriverSW::get_singleton()->get_mix_rate());
//process in chunks to make sure to never process more than INTERNAL_BUFFER_SIZE
- int todo=p_frames;
- while(todo) {
+ int todo = p_frames;
+ while (todo) {
- int tomix=MIN(todo,INTERNAL_BUFFER_SIZE);
- driver_process_chunk(tomix,p_buffer);
- p_buffer+=tomix;
- todo-=tomix;
+ int tomix = MIN(todo, INTERNAL_BUFFER_SIZE);
+ driver_process_chunk(tomix, p_buffer);
+ p_buffer += tomix;
+ todo -= tomix;
}
-
-
}
/* SAMPLE API */
@@ -352,13 +340,13 @@ RID AudioServerSW::sample_create(SampleFormat p_format, bool p_stereo, int p_len
AUDIO_LOCK
- return sample_manager->sample_create(p_format,p_stereo,p_length);
+ return sample_manager->sample_create(p_format, p_stereo, p_length);
}
-void AudioServerSW::sample_set_description(RID p_sample, const String& p_description) {
+void AudioServerSW::sample_set_description(RID p_sample, const String &p_description) {
AUDIO_LOCK
- sample_manager->sample_set_description(p_sample,p_description);
+ sample_manager->sample_set_description(p_sample, p_description);
}
String AudioServerSW::sample_get_description(RID p_sample) const {
@@ -374,55 +362,55 @@ bool AudioServerSW::sample_is_stereo(RID p_sample) const {
//AUDIO_LOCK
return sample_manager->sample_is_stereo(p_sample);
}
-int AudioServerSW::sample_get_length(RID p_sample) const {
+int AudioServerSW::sample_get_length(RID p_sample) const {
///AUDIO_LOCK
return sample_manager->sample_get_length(p_sample);
}
-const void* AudioServerSW::sample_get_data_ptr(RID p_sample) const {
+const void *AudioServerSW::sample_get_data_ptr(RID p_sample) const {
///AUDIO_LOCK
return sample_manager->sample_get_data_ptr(p_sample);
}
-void AudioServerSW::sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer) {
+void AudioServerSW::sample_set_data(RID p_sample, const DVector<uint8_t> &p_buffer) {
AUDIO_LOCK
- sample_manager->sample_set_data(p_sample,p_buffer);
+ sample_manager->sample_set_data(p_sample, p_buffer);
}
DVector<uint8_t> AudioServerSW::sample_get_data(RID p_sample) const {
AUDIO_LOCK
return sample_manager->sample_get_data(p_sample);
}
-void AudioServerSW::sample_set_mix_rate(RID p_sample,int p_rate) {
+void AudioServerSW::sample_set_mix_rate(RID p_sample, int p_rate) {
AUDIO_LOCK
- sample_manager->sample_set_mix_rate(p_sample,p_rate);
+ sample_manager->sample_set_mix_rate(p_sample, p_rate);
}
int AudioServerSW::sample_get_mix_rate(RID p_sample) const {
AUDIO_LOCK
return sample_manager->sample_get_mix_rate(p_sample);
}
-void AudioServerSW::sample_set_loop_format(RID p_sample,SampleLoopFormat p_format) {
+void AudioServerSW::sample_set_loop_format(RID p_sample, SampleLoopFormat p_format) {
AUDIO_LOCK
- sample_manager->sample_set_loop_format(p_sample,p_format);
+ sample_manager->sample_set_loop_format(p_sample, p_format);
}
AS::SampleLoopFormat AudioServerSW::sample_get_loop_format(RID p_sample) const {
AUDIO_LOCK
return sample_manager->sample_get_loop_format(p_sample);
}
-void AudioServerSW::sample_set_loop_begin(RID p_sample,int p_pos) {
+void AudioServerSW::sample_set_loop_begin(RID p_sample, int p_pos) {
AUDIO_LOCK
- sample_manager->sample_set_loop_begin(p_sample,p_pos);
+ sample_manager->sample_set_loop_begin(p_sample, p_pos);
}
int AudioServerSW::sample_get_loop_begin(RID p_sample) const {
AUDIO_LOCK
return sample_manager->sample_get_loop_begin(p_sample);
}
-void AudioServerSW::sample_set_loop_end(RID p_sample,int p_pos) {
+void AudioServerSW::sample_set_loop_end(RID p_sample, int p_pos) {
AUDIO_LOCK
- sample_manager->sample_set_loop_end(p_sample,p_pos);
+ sample_manager->sample_set_loop_end(p_sample, p_pos);
}
int AudioServerSW::sample_get_loop_end(RID p_sample) const {
AUDIO_LOCK
@@ -433,226 +421,203 @@ int AudioServerSW::sample_get_loop_end(RID p_sample) const {
RID AudioServerSW::voice_create() {
- Voice * v = memnew( Voice );
- v->channel=AudioMixer::INVALID_CHANNEL;
+ Voice *v = memnew(Voice);
+ v->channel = AudioMixer::INVALID_CHANNEL;
AUDIO_LOCK
return voice_owner.make_rid(v);
-
}
void AudioServerSW::voice_play(RID p_voice, RID p_sample) {
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND(!v);
- v->active=true; // force actvive (will be disabled later i gues..)
+ v->active = true; // force actvive (will be disabled later i gues..)
//stop old, start new
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_PLAY;
- cmd.voice=p_voice;
- cmd.play.sample=p_sample;
+ cmd.type = VoiceRBSW::Command::CMD_PLAY;
+ cmd.voice = p_voice;
+ cmd.play.sample = p_sample;
voice_rb.push_command(cmd);
-
}
void AudioServerSW::voice_set_volume(RID p_voice, float p_volume) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_SET_VOLUME;
- cmd.voice=p_voice;
- cmd.volume.volume=p_volume;
+ cmd.type = VoiceRBSW::Command::CMD_SET_VOLUME;
+ cmd.voice = p_voice;
+ cmd.volume.volume = p_volume;
voice_rb.push_command(cmd);
-
}
-void AudioServerSW::voice_set_pan(RID p_voice, float p_pan, float p_depth,float p_height) {
+void AudioServerSW::voice_set_pan(RID p_voice, float p_pan, float p_depth, float p_height) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_SET_PAN;
- cmd.voice=p_voice;
- cmd.pan.pan=p_pan;
- cmd.pan.depth=p_depth;
- cmd.pan.height=p_height;
+ cmd.type = VoiceRBSW::Command::CMD_SET_PAN;
+ cmd.voice = p_voice;
+ cmd.pan.pan = p_pan;
+ cmd.pan.depth = p_depth;
+ cmd.pan.height = p_height;
voice_rb.push_command(cmd);
-
}
-void AudioServerSW::voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance,float p_gain) {
+void AudioServerSW::voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_SET_FILTER;
- cmd.voice=p_voice;
- cmd.filter.type=p_type;
- cmd.filter.cutoff=p_cutoff;
- cmd.filter.resonance=p_resonance;
- cmd.filter.gain=p_gain;
+ cmd.type = VoiceRBSW::Command::CMD_SET_FILTER;
+ cmd.voice = p_voice;
+ cmd.filter.type = p_type;
+ cmd.filter.cutoff = p_cutoff;
+ cmd.filter.resonance = p_resonance;
+ cmd.filter.gain = p_gain;
voice_rb.push_command(cmd);
-
}
-void AudioServerSW::voice_set_chorus(RID p_voice, float p_chorus ) {
+void AudioServerSW::voice_set_chorus(RID p_voice, float p_chorus) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_SET_CHORUS;
- cmd.voice=p_voice;
- cmd.chorus.send=p_chorus;
+ cmd.type = VoiceRBSW::Command::CMD_SET_CHORUS;
+ cmd.voice = p_voice;
+ cmd.chorus.send = p_chorus;
voice_rb.push_command(cmd);
-
}
void AudioServerSW::voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_SET_REVERB;
- cmd.voice=p_voice;
- cmd.reverb.room=p_room_type;
- cmd.reverb.send=p_reverb;
+ cmd.type = VoiceRBSW::Command::CMD_SET_REVERB;
+ cmd.voice = p_voice;
+ cmd.reverb.room = p_room_type;
+ cmd.reverb.send = p_reverb;
voice_rb.push_command(cmd);
-
}
void AudioServerSW::voice_set_mix_rate(RID p_voice, int p_mix_rate) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_SET_MIX_RATE;
- cmd.voice=p_voice;
- cmd.mix_rate.mix_rate=p_mix_rate;
+ cmd.type = VoiceRBSW::Command::CMD_SET_MIX_RATE;
+ cmd.voice = p_voice;
+ cmd.mix_rate.mix_rate = p_mix_rate;
voice_rb.push_command(cmd);
-
}
void AudioServerSW::voice_set_positional(RID p_voice, bool p_positional) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_SET_POSITIONAL;
- cmd.voice=p_voice;
- cmd.positional.positional=p_positional;
+ cmd.type = VoiceRBSW::Command::CMD_SET_POSITIONAL;
+ cmd.voice = p_voice;
+ cmd.positional.positional = p_positional;
voice_rb.push_command(cmd);
-
}
float AudioServerSW::voice_get_volume(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_volume( v->channel );
-
+ return mixer->channel_get_volume(v->channel);
}
float AudioServerSW::voice_get_pan(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_pan( v->channel );
-
+ return mixer->channel_get_pan(v->channel);
}
float AudioServerSW::voice_get_pan_depth(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_pan_depth( v->channel );
-
+ return mixer->channel_get_pan_depth(v->channel);
}
float AudioServerSW::voice_get_pan_height(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_pan_height( v->channel );
-
+ return mixer->channel_get_pan_height(v->channel);
}
AS::FilterType AudioServerSW::voice_get_filter_type(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, AS::FILTER_NONE);
return (AS::FilterType)mixer->channel_get_filter_type(v->channel);
-
}
float AudioServerSW::voice_get_filter_cutoff(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_filter_cutoff( v->channel );
-
+ return mixer->channel_get_filter_cutoff(v->channel);
}
float AudioServerSW::voice_get_filter_resonance(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_filter_resonance( v->channel );
-
+ return mixer->channel_get_filter_resonance(v->channel);
}
float AudioServerSW::voice_get_chorus(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_chorus( v->channel );
-
+ return mixer->channel_get_chorus(v->channel);
}
AS::ReverbRoomType AudioServerSW::voice_get_reverb_type(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, REVERB_SMALL);
- return (AS::ReverbRoomType)mixer->channel_get_reverb_type( v->channel );
-
+ return (AS::ReverbRoomType)mixer->channel_get_reverb_type(v->channel);
}
float AudioServerSW::voice_get_reverb(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_reverb( v->channel );
-
+ return mixer->channel_get_reverb(v->channel);
}
int AudioServerSW::voice_get_mix_rate(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_get_mix_rate( v->channel );
-
+ return mixer->channel_get_mix_rate(v->channel);
}
bool AudioServerSW::voice_is_positional(RID p_voice) const {
AUDIO_LOCK
- Voice *v = voice_owner.get( p_voice );
+ Voice *v = voice_owner.get(p_voice);
ERR_FAIL_COND_V(!v, 0);
- return mixer->channel_is_positional( v->channel );
-
+ return mixer->channel_is_positional(v->channel);
}
void AudioServerSW::voice_stop(RID p_voice) {
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_STOP;
- cmd.voice=p_voice;
+ cmd.type = VoiceRBSW::Command::CMD_STOP;
+ cmd.voice = p_voice;
voice_rb.push_command(cmd);
//return mixer->channel_free( v->channel );
-
}
bool AudioServerSW::voice_is_active(RID p_voice) const {
Voice *v = voice_owner.get(p_voice);
- ERR_FAIL_COND_V(!v,false);
+ ERR_FAIL_COND_V(!v, false);
return v->active;
-
}
/* STREAM API */
@@ -661,11 +626,11 @@ RID AudioServerSW::audio_stream_create(AudioStream *p_stream) {
AUDIO_LOCK
Stream *s = memnew(Stream);
- s->audio_stream=p_stream;
- s->event_stream=NULL;
- s->active=false;
- s->E=NULL;
- s->volume_scale=1.0;
+ s->audio_stream = p_stream;
+ s->event_stream = NULL;
+ s->active = false;
+ s->E = NULL;
+ s->volume_scale = 1.0;
p_stream->set_mix_rate(AudioDriverSW::get_singleton()->get_mix_rate());
return stream_owner.make_rid(s);
@@ -675,44 +640,38 @@ RID AudioServerSW::event_stream_create(EventStream *p_stream) {
AUDIO_LOCK
Stream *s = memnew(Stream);
- s->audio_stream=NULL;
- s->event_stream=p_stream;
- s->active=false;
- s->E=NULL;
- s->volume_scale=1.0;
+ s->audio_stream = NULL;
+ s->event_stream = p_stream;
+ s->active = false;
+ s->E = NULL;
+ s->volume_scale = 1.0;
//p_stream->set_mix_rate(AudioDriverSW::get_singleton()->get_mix_rate());
return stream_owner.make_rid(s);
-
-
}
-
void AudioServerSW::stream_set_active(RID p_stream, bool p_active) {
-
Stream *s = stream_owner.get(p_stream);
ERR_FAIL_COND(!s);
_THREAD_SAFE_METHOD_
- if (s->active==p_active)
+ if (s->active == p_active)
return;
AUDIO_LOCK;
- s->active=p_active;
+ s->active = p_active;
if (p_active)
- s->E=active_audio_streams.push_back(s);
+ s->E = active_audio_streams.push_back(s);
else {
active_audio_streams.erase(s->E);
- s->E=NULL;
+ s->E = NULL;
}
-
-
}
bool AudioServerSW::stream_is_active(RID p_stream) const {
Stream *s = stream_owner.get(p_stream);
- ERR_FAIL_COND_V(!s,false);
+ ERR_FAIL_COND_V(!s, false);
return s->active;
}
@@ -720,36 +679,32 @@ void AudioServerSW::stream_set_volume_scale(RID p_stream, float p_scale) {
Stream *s = stream_owner.get(p_stream);
ERR_FAIL_COND(!s);
- s->volume_scale=p_scale;
-
+ s->volume_scale = p_scale;
}
float AudioServerSW::stream_set_volume_scale(RID p_stream) const {
Stream *s = stream_owner.get(p_stream);
- ERR_FAIL_COND_V(!s,0);
+ ERR_FAIL_COND_V(!s, 0);
return s->volume_scale;
-
}
-
void AudioServerSW::free(RID p_id) {
- if(voice_owner.owns(p_id)) {
+ if (voice_owner.owns(p_id)) {
Voice *v = voice_owner.get(p_id);
AUDIO_LOCK
- mixer->channel_free( v->channel );
+ mixer->channel_free(v->channel);
voice_owner.free(p_id);
memdelete(v);
} else if (stream_owner.owns(p_id)) {
-
- Stream *s=stream_owner.get(p_id);
+ Stream *s = stream_owner.get(p_id);
if (s->active) {
- stream_set_active(p_id,false);
+ stream_set_active(p_id, false);
}
memdelete(s);
@@ -760,63 +715,60 @@ void AudioServerSW::free(RID p_id) {
AUDIO_LOCK
sample_manager->free(p_id);
}
-
}
void AudioServerSW::_thread_func(void *self) {
Thread::set_name("AudioServerSW");
- AudioServerSW *as=(AudioServerSW *)self;
+ AudioServerSW *as = (AudioServerSW *)self;
while (!as->exit_update_thread) {
as->_update_streams(true);
OS::get_singleton()->delay_usec(5000);
}
-
}
void AudioServerSW::init() {
- int latency = GLOBAL_DEF("audio/mixer_latency",10);
- internal_buffer_channels=2; // read from driver
- internal_buffer = memnew_arr(int32_t,INTERNAL_BUFFER_SIZE*internal_buffer_channels);
- stream_buffer = memnew_arr(int32_t,INTERNAL_BUFFER_SIZE*4); //max 4 channels
+ int latency = GLOBAL_DEF("audio/mixer_latency", 10);
+ internal_buffer_channels = 2; // read from driver
+ internal_buffer = memnew_arr(int32_t, INTERNAL_BUFFER_SIZE * internal_buffer_channels);
+ stream_buffer = memnew_arr(int32_t, INTERNAL_BUFFER_SIZE * 4); //max 4 channels
AudioMixerSW::MixChannels mix_chans = AudioMixerSW::MIX_STEREO;
- switch(AudioDriverSW::get_singleton()->get_output_format()) {
+ switch (AudioDriverSW::get_singleton()->get_output_format()) {
case AudioDriverSW::OUTPUT_MONO:
case AudioDriverSW::OUTPUT_STEREO:
- mix_chans=AudioMixerSW::MIX_STEREO;
+ mix_chans = AudioMixerSW::MIX_STEREO;
break;
case AudioDriverSW::OUTPUT_QUAD:
case AudioDriverSW::OUTPUT_5_1:
- mix_chans=AudioMixerSW::MIX_QUAD;
+ mix_chans = AudioMixerSW::MIX_QUAD;
break;
}
- mixer = memnew( AudioMixerSW( sample_manager, latency, AudioDriverSW::get_singleton()->get_mix_rate(),mix_chans,mixer_use_fx,mixer_interp,_mixer_callback,this ) );
- mixer_step_usecs=mixer->get_step_usecs();
+ mixer = memnew(AudioMixerSW(sample_manager, latency, AudioDriverSW::get_singleton()->get_mix_rate(), mix_chans, mixer_use_fx, mixer_interp, _mixer_callback, this));
+ mixer_step_usecs = mixer->get_step_usecs();
- _output_delay=0;
+ _output_delay = 0;
- stream_volume=0.3;
+ stream_volume = 0.3;
// start the audio driver
if (AudioDriverSW::get_singleton())
AudioDriverSW::get_singleton()->start();
#ifndef NO_THREADS
- exit_update_thread=false;
- thread = Thread::create(_thread_func,this);
+ exit_update_thread = false;
+ thread = Thread::create(_thread_func, this);
#endif
-
}
void AudioServerSW::finish() {
#ifndef NO_THREADS
- exit_update_thread=true;
+ exit_update_thread = true;
Thread::wait_to_finish(thread);
memdelete(thread);
#endif
@@ -827,22 +779,20 @@ void AudioServerSW::finish() {
memdelete_arr(internal_buffer);
memdelete_arr(stream_buffer);
memdelete(mixer);
-
}
void AudioServerSW::_update_streams(bool p_thread) {
_THREAD_SAFE_METHOD_
- for(List<Stream*>::Element *E=active_audio_streams.front();E;) { //stream might be removed durnig this callback
+ for (List<Stream *>::Element *E = active_audio_streams.front(); E;) { //stream might be removed durnig this callback
- List<Stream*>::Element *N=E->next();
+ List<Stream *>::Element *N = E->next();
if (E->get()->audio_stream && p_thread == E->get()->audio_stream->can_update_mt())
E->get()->audio_stream->update();
- E=N;
+ E = N;
}
-
}
void AudioServerSW::update() {
@@ -854,7 +804,6 @@ void AudioServerSW::update() {
#endif
}
-
void AudioServerSW::lock() {
AudioDriverSW::get_singleton()->lock();
@@ -862,7 +811,6 @@ void AudioServerSW::lock() {
void AudioServerSW::unlock() {
AudioDriverSW::get_singleton()->unlock();
-
}
int AudioServerSW::get_default_mix_rate() const {
@@ -875,35 +823,31 @@ int AudioServerSW::get_default_channel_count() const {
void AudioServerSW::set_mixer_params(AudioMixerSW::InterpolationType p_interp, bool p_use_fx) {
- mixer_interp=p_interp;
- mixer_use_fx=p_use_fx;
+ mixer_interp = p_interp;
+ mixer_use_fx = p_use_fx;
}
void AudioServerSW::set_stream_global_volume_scale(float p_volume) {
- stream_volume_scale=p_volume;
+ stream_volume_scale = p_volume;
}
float AudioServerSW::get_stream_global_volume_scale() const {
return stream_volume_scale;
-
-
}
void AudioServerSW::set_fx_global_volume_scale(float p_volume) {
- fx_volume_scale=p_volume;
+ fx_volume_scale = p_volume;
//mixer->set_mixer_volume(fx_volume_scale);
VoiceRBSW::Command cmd;
- cmd.type=VoiceRBSW::Command::CMD_CHANGE_ALL_FX_VOLUMES;
- cmd.voice=RID();
- cmd.volume.volume=p_volume;
+ cmd.type = VoiceRBSW::Command::CMD_CHANGE_ALL_FX_VOLUMES;
+ cmd.voice = RID();
+ cmd.volume.volume = p_volume;
voice_rb.push_command(cmd);
-
}
-
float AudioServerSW::get_fx_global_volume_scale() const {
return fx_volume_scale;
@@ -911,11 +855,10 @@ float AudioServerSW::get_fx_global_volume_scale() const {
void AudioServerSW::set_event_voice_global_volume_scale(float p_volume) {
- event_voice_volume_scale=p_volume;
+ event_voice_volume_scale = p_volume;
//mixer->set_mixer_volume(event_voice_volume_scale);
}
-
float AudioServerSW::get_event_voice_global_volume_scale() const {
return event_voice_volume_scale;
@@ -923,7 +866,7 @@ float AudioServerSW::get_event_voice_global_volume_scale() const {
double AudioServerSW::get_output_delay() const {
- return _output_delay+AudioDriverSW::get_singleton()->get_latency();
+ return _output_delay + AudioDriverSW::get_singleton()->get_latency();
}
double AudioServerSW::get_mix_time() const {
@@ -934,37 +877,33 @@ double AudioServerSW::get_mix_time() const {
uint32_t AudioServerSW::read_output_peak() const {
uint32_t val = max_peak;
- uint32_t *p = (uint32_t*)&max_peak;
- *p=0;
+ uint32_t *p = (uint32_t *)&max_peak;
+ *p = 0;
return val;
}
AudioServerSW::AudioServerSW(SampleManagerSW *p_sample_manager) {
- sample_manager=p_sample_manager;
- String interp = GLOBAL_DEF("audio/mixer_interp","linear");
- Globals::get_singleton()->set_custom_property_info("audio/mixer_interp",PropertyInfo(Variant::STRING,"audio/mixer_interp",PROPERTY_HINT_ENUM,"raw,linear,cubic"));
- if (interp=="raw")
- mixer_interp=AudioMixerSW::INTERPOLATION_RAW;
- else if (interp=="cubic")
- mixer_interp=AudioMixerSW::INTERPOLATION_CUBIC;
+ sample_manager = p_sample_manager;
+ String interp = GLOBAL_DEF("audio/mixer_interp", "linear");
+ Globals::get_singleton()->set_custom_property_info("audio/mixer_interp", PropertyInfo(Variant::STRING, "audio/mixer_interp", PROPERTY_HINT_ENUM, "raw,linear,cubic"));
+ if (interp == "raw")
+ mixer_interp = AudioMixerSW::INTERPOLATION_RAW;
+ else if (interp == "cubic")
+ mixer_interp = AudioMixerSW::INTERPOLATION_CUBIC;
else
- mixer_interp=AudioMixerSW::INTERPOLATION_LINEAR;
- mixer_use_fx = GLOBAL_DEF("audio/use_chorus_reverb",true);
- stream_volume_scale=GLOBAL_DEF("audio/stream_volume_scale",1.0);
- fx_volume_scale=GLOBAL_DEF("audio/fx_volume_scale",1.0);
- event_voice_volume_scale=GLOBAL_DEF("audio/event_voice_volume_scale",0.5);
- max_peak=0;
-
-
+ mixer_interp = AudioMixerSW::INTERPOLATION_LINEAR;
+ mixer_use_fx = GLOBAL_DEF("audio/use_chorus_reverb", true);
+ stream_volume_scale = GLOBAL_DEF("audio/stream_volume_scale", 1.0);
+ fx_volume_scale = GLOBAL_DEF("audio/fx_volume_scale", 1.0);
+ event_voice_volume_scale = GLOBAL_DEF("audio/event_voice_volume_scale", 0.5);
+ max_peak = 0;
}
AudioServerSW::~AudioServerSW() {
-
}
-
-AudioDriverSW *AudioDriverSW::singleton=NULL;
+AudioDriverSW *AudioDriverSW::singleton = NULL;
AudioDriverSW *AudioDriverSW::get_singleton() {
return singleton;
@@ -972,48 +911,43 @@ AudioDriverSW *AudioDriverSW::get_singleton() {
void AudioDriverSW::set_singleton() {
- singleton=this;
+ singleton = this;
}
-void AudioDriverSW::audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time) {
+void AudioDriverSW::audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time) {
- AudioServerSW * audio_server = static_cast<AudioServerSW*>(AudioServer::get_singleton());
+ AudioServerSW *audio_server = static_cast<AudioServerSW *>(AudioServer::get_singleton());
if (p_update_mix_time)
update_mix_time(p_frames);
- audio_server->driver_process(p_frames,p_buffer);
+ audio_server->driver_process(p_frames, p_buffer);
}
void AudioDriverSW::update_mix_time(int p_frames) {
- _mix_amount+=p_frames;
- _last_mix_time=OS::get_singleton()->get_ticks_usec();
+ _mix_amount += p_frames;
+ _last_mix_time = OS::get_singleton()->get_ticks_usec();
}
double AudioDriverSW::get_mix_time() const {
double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
- total+=_mix_amount/(double)get_mix_rate();
+ total += _mix_amount / (double)get_mix_rate();
return total;
-
}
-
AudioDriverSW::AudioDriverSW() {
- _last_mix_time=0;
- _mix_amount=0;
+ _last_mix_time = 0;
+ _mix_amount = 0;
}
-
AudioDriverSW *AudioDriverManagerSW::drivers[MAX_DRIVERS];
-int AudioDriverManagerSW::driver_count=0;
-
-
+int AudioDriverManagerSW::driver_count = 0;
void AudioDriverManagerSW::add_driver(AudioDriverSW *p_driver) {
- ERR_FAIL_COND(driver_count>=MAX_DRIVERS);
- drivers[driver_count++]=p_driver;
+ ERR_FAIL_COND(driver_count >= MAX_DRIVERS);
+ drivers[driver_count++] = p_driver;
}
int AudioDriverManagerSW::get_driver_count() {
@@ -1022,7 +956,6 @@ int AudioDriverManagerSW::get_driver_count() {
}
AudioDriverSW *AudioDriverManagerSW::get_driver(int p_driver) {
- ERR_FAIL_INDEX_V(p_driver,driver_count,NULL);
+ ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
return drivers[p_driver];
}
-
diff --git a/servers/audio/audio_server_sw.h b/servers/audio/audio_server_sw.h
index 60af87e6f..2a166395f 100644
--- a/servers/audio/audio_server_sw.h
+++ b/servers/audio/audio_server_sw.h
@@ -29,21 +29,21 @@
#ifndef AUDIO_SERVER_SW_H
#define AUDIO_SERVER_SW_H
-#include "servers/audio_server.h"
+#include "os/thread.h"
+#include "os/thread_safe.h"
+#include "self_list.h"
#include "servers/audio/audio_mixer_sw.h"
#include "servers/audio/voice_rb_sw.h"
-#include "self_list.h"
-#include "os/thread_safe.h"
-#include "os/thread.h"
+#include "servers/audio_server.h"
class AudioServerSW : public AudioServer {
- OBJ_TYPE( AudioServerSW, AudioServer );
+ OBJ_TYPE(AudioServerSW, AudioServer);
_THREAD_SAFE_CLASS_
enum {
- INTERNAL_BUFFER_SIZE=4096,
- STREAM_SCALE_BITS=12
+ INTERNAL_BUFFER_SIZE = 4096,
+ STREAM_SCALE_BITS = 12
};
@@ -60,8 +60,11 @@ class AudioServerSW : public AudioServer {
SelfList<Voice> active_item;
AudioMixer::ChannelID channel;
-
- Voice () : active_item(this) { channel=AudioMixer::INVALID_CHANNEL; active=false;}
+ Voice()
+ : active_item(this) {
+ channel = AudioMixer::INVALID_CHANNEL;
+ active = false;
+ }
};
mutable RID_Owner<Voice> voice_owner;
@@ -69,19 +72,19 @@ class AudioServerSW : public AudioServer {
struct Stream {
bool active;
- List<Stream*>::Element *E;
+ List<Stream *>::Element *E;
AudioStream *audio_stream;
EventStream *event_stream;
float volume_scale;
};
- List<Stream*> active_audio_streams;
+ List<Stream *> active_audio_streams;
//List<Stream*> event_streams;
- int32_t * internal_buffer;
+ int32_t *internal_buffer;
int internal_buffer_channels;
- int32_t * stream_buffer;
+ int32_t *stream_buffer;
mutable RID_Owner<Stream> stream_owner;
@@ -89,7 +92,7 @@ class AudioServerSW : public AudioServer {
float stream_volume_scale;
float fx_volume_scale;
float event_voice_volume_scale;
- float peak_left,peak_right;
+ float peak_left, peak_right;
uint32_t max_peak;
double _output_delay;
@@ -101,43 +104,42 @@ class AudioServerSW : public AudioServer {
static void _thread_func(void *self);
void _update_streams(bool p_thread);
- void driver_process_chunk(int p_frames,int32_t *p_buffer);
+ void driver_process_chunk(int p_frames, int32_t *p_buffer);
AudioMixerSW::InterpolationType mixer_interp;
bool mixer_use_fx;
uint64_t mixer_step_usecs;
static void _mixer_callback(void *p_udata);
-friend class AudioDriverSW;
- void driver_process(int p_frames,int32_t *p_buffer);
-public:
-
+ friend class AudioDriverSW;
+ void driver_process(int p_frames, int32_t *p_buffer);
+public:
/* SAMPLE API */
virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length);
- virtual void sample_set_description(RID p_sample, const String& p_description);
+ virtual void sample_set_description(RID p_sample, const String &p_description);
virtual String sample_get_description(RID p_sample) const;
virtual SampleFormat sample_get_format(RID p_sample) const;
virtual bool sample_is_stereo(RID p_sample) const;
virtual int sample_get_length(RID p_sample) const;
- const void* sample_get_data_ptr(RID p_sample) const;
+ const void *sample_get_data_ptr(RID p_sample) const;
- virtual void sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer);
+ virtual void sample_set_data(RID p_sample, const DVector<uint8_t> &p_buffer);
virtual DVector<uint8_t> sample_get_data(RID p_sample) const;
- virtual void sample_set_mix_rate(RID p_sample,int p_rate);
+ virtual void sample_set_mix_rate(RID p_sample, int p_rate);
virtual int sample_get_mix_rate(RID p_sample) const;
- virtual void sample_set_loop_format(RID p_sample,SampleLoopFormat p_format);
+ virtual void sample_set_loop_format(RID p_sample, SampleLoopFormat p_format);
virtual SampleLoopFormat sample_get_loop_format(RID p_sample) const;
- virtual void sample_set_loop_begin(RID p_sample,int p_pos);
+ virtual void sample_set_loop_begin(RID p_sample, int p_pos);
virtual int sample_get_loop_begin(RID p_sample) const;
- virtual void sample_set_loop_end(RID p_sample,int p_pos);
+ virtual void sample_set_loop_end(RID p_sample, int p_pos);
virtual int sample_get_loop_end(RID p_sample) const;
/* VOICE API */
@@ -147,9 +149,9 @@ public:
virtual void voice_play(RID p_voice, RID p_sample);
virtual void voice_set_volume(RID p_voice, float p_volume);
- virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth=0,float height=0); //pan and depth go from -1 to 1
- virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance,float p_gain=0);
- virtual void voice_set_chorus(RID p_voice, float p_chorus );
+ virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth = 0, float height = 0); //pan and depth go from -1 to 1
+ virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain = 0);
+ virtual void voice_set_chorus(RID p_voice, float p_chorus);
virtual void voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb);
virtual void voice_set_mix_rate(RID p_voice, int p_mix_rate);
virtual void voice_set_positional(RID p_voice, bool p_positional);
@@ -199,7 +201,6 @@ public:
virtual void set_fx_global_volume_scale(float p_volume);
virtual void set_event_voice_global_volume_scale(float p_volume);
-
virtual float get_stream_global_volume_scale() const;
virtual float get_fx_global_volume_scale() const;
virtual float get_event_voice_global_volume_scale() const;
@@ -210,29 +211,21 @@ public:
virtual double get_output_delay() const;
-
AudioServerSW(SampleManagerSW *p_sample_manager);
~AudioServerSW();
-
};
-
class AudioDriverSW {
-
static AudioDriverSW *singleton;
uint64_t _last_mix_time;
uint64_t _mix_amount;
-
protected:
-
- void audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time=true);
+ void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);
void update_mix_time(int p_frames);
public:
-
-
double get_mix_time() const; //useful for video -> audio sync
enum OutputFormat {
@@ -246,38 +239,33 @@ public:
static AudioDriverSW *get_singleton();
void set_singleton();
- virtual const char* get_name() const=0;
+ virtual const char *get_name() const = 0;
- virtual Error init()=0;
- virtual void start()=0;
- virtual int get_mix_rate() const =0;
- virtual OutputFormat get_output_format() const=0;
- virtual void lock()=0;
- virtual void unlock()=0;
- virtual void finish()=0;
+ virtual Error init() = 0;
+ virtual void start() = 0;
+ virtual int get_mix_rate() const = 0;
+ virtual OutputFormat get_output_format() const = 0;
+ virtual void lock() = 0;
+ virtual void unlock() = 0;
+ virtual void finish() = 0;
virtual float get_latency() { return 0; }
-
-
-
AudioDriverSW();
- virtual ~AudioDriverSW() {};
+ virtual ~AudioDriverSW(){};
};
-
-
class AudioDriverManagerSW {
enum {
- MAX_DRIVERS=10
+ MAX_DRIVERS = 10
};
static AudioDriverSW *drivers[MAX_DRIVERS];
static int driver_count;
-public:
+public:
static void add_driver(AudioDriverSW *p_driver);
static int get_driver_count();
static AudioDriverSW *get_driver(int p_driver);
diff --git a/servers/audio/reverb_sw.cpp b/servers/audio/reverb_sw.cpp
index 0050dbede..c00a91d24 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,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x6D80, 0x54B8, -0x4130, 0x0000, 0x0000, -0x4580,
-// gReva gRevb gInputL gInputR
- 0x5800, 0x5300, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x01B4 - 0x007D, 0x0136 - 0x007D, 0x00B8 - 0x005B, 0x005C - 0x005B,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x04D6, 0x0333, 0x03F0, 0x0227, 0x0374, 0x01EF,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x0334, 0x01B5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x0000, 0x0000, 0x01B4, 0x0136, 0x00B8, 0x005C
+ 0x26C0 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x6D80, 0x54B8, -0x4130, 0x0000, 0x0000, -0x4580,
+ // gReva gRevb gInputL gInputR
+ 0x5800, 0x5300, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x01B4 - 0x007D, 0x0136 - 0x007D, 0x00B8 - 0x005B, 0x005C - 0x005B,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x04D6, 0x0333, 0x03F0, 0x0227, 0x0374, 0x01EF,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x0334, 0x01B5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x0000, 0x0000, 0x01B4, 0x0136, 0x00B8, 0x005C
};
static ReverbParamsSW reverb_params_StudioSmall = {
- 0x1F40/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x70F0, 0x4FA8, -0x4320, 0x4410, -0x3F10, -0x6400,
-// gReva gRevb gInputL gInputR
- 0x5280, 0x4EC0, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x00B4 - 0x0033, 0x0080 - 0x0033, 0x004C - 0x0025, 0x0026 - 0x0025,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x03E4, 0x031B, 0x03A4, 0x02AF, 0x0372, 0x0266,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x031C, 0x025D, 0x025C, 0x018E, 0x022F, 0x0135, 0x01D2, 0x00B7,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x018F, 0x00B5, 0x00B4, 0x0080, 0x004C, 0x0026
+ 0x1F40 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x70F0, 0x4FA8, -0x4320, 0x4410, -0x3F10, -0x6400,
+ // gReva gRevb gInputL gInputR
+ 0x5280, 0x4EC0, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x00B4 - 0x0033, 0x0080 - 0x0033, 0x004C - 0x0025, 0x0026 - 0x0025,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x03E4, 0x031B, 0x03A4, 0x02AF, 0x0372, 0x0266,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x031C, 0x025D, 0x025C, 0x018E, 0x022F, 0x0135, 0x01D2, 0x00B7,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x018F, 0x00B5, 0x00B4, 0x0080, 0x004C, 0x0026
};
static ReverbParamsSW reverb_params_StudioMedium = {
- 0x4840/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x4B40,
-// gReva gRevb gInputL gInputR
- 0x5280, 0x4EC0, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x0264 - 0x00B1, 0x01B2 - 0x00B1, 0x0100 - 0x007F, 0x0080 - 0x007F,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x0904, 0x076B, 0x0824, 0x065F, 0x07A2, 0x0616,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x076C, 0x05ED, 0x05EC, 0x042E, 0x050F, 0x0305, 0x0462, 0x02B7,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x042F, 0x0265, 0x0264, 0x01B2, 0x0100, 0x0080
+ 0x4840 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x4B40,
+ // gReva gRevb gInputL gInputR
+ 0x5280, 0x4EC0, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x0264 - 0x00B1, 0x01B2 - 0x00B1, 0x0100 - 0x007F, 0x0080 - 0x007F,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x0904, 0x076B, 0x0824, 0x065F, 0x07A2, 0x0616,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x076C, 0x05ED, 0x05EC, 0x042E, 0x050F, 0x0305, 0x0462, 0x02B7,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x042F, 0x0265, 0x0264, 0x01B2, 0x0100, 0x0080
};
static ReverbParamsSW reverb_params_StudioLarge = {
- 0x6FE0/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x6F60, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x5980,
-// gReva gRevb gInputL gInputR
- 0x5680, 0x52C0, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x031C - 0x00E3, 0x0238 - 0x00E3, 0x0154 - 0x00A9, 0x00AA - 0x00A9,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x0DFB, 0x0B58, 0x0D09, 0x0A3C, 0x0BD9, 0x0973,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x0B59, 0x08DA, 0x08D9, 0x05E9, 0x07EC, 0x04B0, 0x06EF, 0x03D2,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x05EA, 0x031D, 0x031C, 0x0238, 0x0154, 0x00AA
+ 0x6FE0 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x6F60, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x5980,
+ // gReva gRevb gInputL gInputR
+ 0x5680, 0x52C0, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x031C - 0x00E3, 0x0238 - 0x00E3, 0x0154 - 0x00A9, 0x00AA - 0x00A9,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x0DFB, 0x0B58, 0x0D09, 0x0A3C, 0x0BD9, 0x0973,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x0B59, 0x08DA, 0x08D9, 0x05E9, 0x07EC, 0x04B0, 0x06EF, 0x03D2,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x05EA, 0x031D, 0x031C, 0x0238, 0x0154, 0x00AA
};
static ReverbParamsSW reverb_params_Hall = {
- 0xADE0/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x6000, 0x5000, 0x4C00, -0x4800, -0x4400, -0x4000,
-// gReva gRevb gInputL gInputR
- 0x6000, 0x5C00, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x05C0 - 0x01A5, 0x041A - 0x01A5, 0x0274 - 0x0139, 0x013A - 0x0139,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x15BA, 0x11BB, 0x14C2, 0x10BD, 0x11BC, 0x0DC1,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x11C0, 0x0DC3, 0x0DC0, 0x09C1, 0x0BC4, 0x07C1, 0x0A00, 0x06CD,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x09C2, 0x05C1, 0x05C0, 0x041A, 0x0274, 0x013A
+ 0xADE0 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x6000, 0x5000, 0x4C00, -0x4800, -0x4400, -0x4000,
+ // gReva gRevb gInputL gInputR
+ 0x6000, 0x5C00, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x05C0 - 0x01A5, 0x041A - 0x01A5, 0x0274 - 0x0139, 0x013A - 0x0139,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x15BA, 0x11BB, 0x14C2, 0x10BD, 0x11BC, 0x0DC1,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x11C0, 0x0DC3, 0x0DC0, 0x09C1, 0x0BC4, 0x07C1, 0x0A00, 0x06CD,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x09C2, 0x05C1, 0x05C0, 0x041A, 0x0274, 0x013A
};
static ReverbParamsSW reverb_params_SpaceEcho = {
- 0xF6C0/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x7E00, 0x5000, -0x4C00, -0x5000, 0x4C00, -0x5000,
-// gReva gRevb gInputL gInputR
- 0x6000, 0x5400, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x0AE0 - 0x033D, 0x07A2 - 0x033D, 0x0464 - 0x0231, 0x0232 - 0x0231,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x1ED6, 0x1A31, 0x1D14, 0x183B, 0x1BC2, 0x16B2,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x1A32, 0x15EF, 0x15EE, 0x1055, 0x1334, 0x0F2D, 0x11F6, 0x0C5D,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x1056, 0x0AE1, 0x0AE0, 0x07A2, 0x0464, 0x0232
+ 0xF6C0 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x7E00, 0x5000, -0x4C00, -0x5000, 0x4C00, -0x5000,
+ // gReva gRevb gInputL gInputR
+ 0x6000, 0x5400, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x0AE0 - 0x033D, 0x07A2 - 0x033D, 0x0464 - 0x0231, 0x0232 - 0x0231,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x1ED6, 0x1A31, 0x1D14, 0x183B, 0x1BC2, 0x16B2,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x1A32, 0x15EF, 0x15EE, 0x1055, 0x1334, 0x0F2D, 0x11F6, 0x0C5D,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x1056, 0x0AE1, 0x0AE0, 0x07A2, 0x0464, 0x0232
};
static ReverbParamsSW reverb_params_Echo = {
- 0x18040/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, -0x7F00,
-// gReva gRevb gInputL gInputR
- 0x0000, 0x0000, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
+ 0x18040 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, -0x7F00,
+ // gReva gRevb gInputL gInputR
+ 0x0000, 0x0000, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
};
static ReverbParamsSW reverb_params_Delay = {
- 0x18040/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000,
-// gReva gRevb gInputL gInputR
- 0x0000, 0x0000, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
+ 0x18040 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000,
+ // gReva gRevb gInputL gInputR
+ 0x0000, 0x0000, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x1004 - 0x0001, 0x1002 - 0x0001, 0x0004 - 0x0001, 0x0002 - 0x0001,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x1FFF, 0x0FFF, 0x1005, 0x0005, 0x0000, 0x0000,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x1005, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 0x0000, 0x0000, 0x1004, 0x1002, 0x0004, 0x0002
};
static ReverbParamsSW reverb_params_HalfEcho = {
- 0x3C00/2,
-// gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
- 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x7B00,
-// gReva gRevb gInputL gInputR
- 0x5F80, 0x54C0, -0x8000, -0x8000,
-// nRevaOldL nRevaOldR nRevbOldL nRevbOldR
- 0x0058 - 0x0017, 0x0040 - 0x0017, 0x0028 - 0x0013, 0x0014 - 0x0013,
-// nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
- 0x0371, 0x02AF, 0x02E5, 0x01DF, 0x02B0, 0x01D7,
-// nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
- 0x0358, 0x026A, 0x01D6, 0x011E, 0x012D, 0x00B1, 0x011F, 0x0059,
-// nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
- 0x01A0, 0x00E3, 0x0058, 0x0040, 0x0028, 0x0014
+ 0x3C00 / 2,
+ // gLPF gEcho0 gEcho1 gEcho2 gEcho3 gWall
+ 0x70F0, 0x4FA8, -0x4320, 0x4510, -0x4110, -0x7B00,
+ // gReva gRevb gInputL gInputR
+ 0x5F80, 0x54C0, -0x8000, -0x8000,
+ // nRevaOldL nRevaOldR nRevbOldL nRevbOldR
+ 0x0058 - 0x0017, 0x0040 - 0x0017, 0x0028 - 0x0013, 0x0014 - 0x0013,
+ // nLwlNew nRwrNew nEcho0L nEcho0R nEcho1L nEcho1R
+ 0x0371, 0x02AF, 0x02E5, 0x01DF, 0x02B0, 0x01D7,
+ // nLwlOld nRwrOld nLwrNew nRwlNew nEcho2L nEcho2R nEcho3L nEcho3R
+ 0x0358, 0x026A, 0x01D6, 0x011E, 0x012D, 0x00B1, 0x011F, 0x0059,
+ // nLwrOld nRwlOld nRevaNewL nRevaNewR nRevbNewL nRevbNewR
+ 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,35 +279,34 @@ 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 ������۲
unsigned int Offset;
int lwl, lwr, rwl, rwr;
-// unsigned char HZShift;
+ // unsigned char HZShift;
// �������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/sample_manager_sw.cpp b/servers/audio/sample_manager_sw.cpp
index 623bb0f9c..b28291165 100644
--- a/servers/audio/sample_manager_sw.cpp
+++ b/servers/audio/sample_manager_sw.cpp
@@ -30,36 +30,33 @@
#include "print_string.h"
-SampleManagerSW::~SampleManagerSW()
-{
+SampleManagerSW::~SampleManagerSW() {
}
-
-
RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length) {
- Sample *s = memnew( Sample );
+ Sample *s = memnew(Sample);
int datalen = p_length;
- if (p_format==AS::SAMPLE_FORMAT_PCM16)
- datalen*=2;
- else if (p_format==AS::SAMPLE_FORMAT_IMA_ADPCM) {
- if (datalen&1) {
+ if (p_format == AS::SAMPLE_FORMAT_PCM16)
+ datalen *= 2;
+ else if (p_format == AS::SAMPLE_FORMAT_IMA_ADPCM) {
+ if (datalen & 1) {
datalen++;
}
- datalen/=2;
- datalen+=4;
+ datalen /= 2;
+ datalen += 4;
}
if (p_stereo)
- datalen*=2;
+ datalen *= 2;
#define SAMPLE_EXTRA 16
- s->data = memalloc(datalen+SAMPLE_EXTRA); //help the interpolator by allocating a little more..
- for(int i=0;i<SAMPLE_EXTRA;i++) {
+ s->data = memalloc(datalen + SAMPLE_EXTRA); //help the interpolator by allocating a little more..
+ for (int i = 0; i < SAMPLE_EXTRA; i++) {
- uint8_t *data = (uint8_t*)s->data;
- data[datalen+i]=0;
+ uint8_t *data = (uint8_t *)s->data;
+ data[datalen + i] = 0;
}
if (!s->data) {
@@ -68,14 +65,14 @@ RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stere
ERR_FAIL_V(RID());
}
- s->format=p_format;
- s->length=p_length;
- s->length_bytes=datalen;
- s->stereo=p_stereo;
- s->loop_begin=0;
- s->loop_end=0;
- s->loop_format=AS::SAMPLE_LOOP_NONE;
- s->mix_rate=44100;
+ s->format = p_format;
+ s->length = p_length;
+ s->length_bytes = datalen;
+ s->stereo = p_stereo;
+ s->loop_begin = 0;
+ s->loop_end = 0;
+ s->loop_format = AS::SAMPLE_LOOP_NONE;
+ s->mix_rate = 44100;
AudioServer::get_singleton()->lock();
RID rid = sample_owner.make_rid(s);
@@ -84,27 +81,26 @@ RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stere
return rid;
}
-void SampleManagerMallocSW::sample_set_description(RID p_sample, const String& p_description) {
+void SampleManagerMallocSW::sample_set_description(RID p_sample, const String &p_description) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- s->description=p_description;
+ s->description = p_description;
}
String SampleManagerMallocSW::sample_get_description(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,String());
+ ERR_FAIL_COND_V(!s, String());
return s->description;
}
-
AS::SampleFormat SampleManagerMallocSW::sample_get_format(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,AS::SAMPLE_FORMAT_PCM8);
+ ERR_FAIL_COND_V(!s, AS::SAMPLE_FORMAT_PCM8);
return s->format;
}
@@ -112,89 +108,83 @@ AS::SampleFormat SampleManagerMallocSW::sample_get_format(RID p_sample) const {
bool SampleManagerMallocSW::sample_is_stereo(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,false);
+ ERR_FAIL_COND_V(!s, false);
return s->stereo;
-
}
int SampleManagerMallocSW::sample_get_length(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->length;
}
-void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer) {
+void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t> &p_buffer) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- int buff_size=p_buffer.size();
- ERR_FAIL_COND(buff_size==0);
-
+ int buff_size = p_buffer.size();
+ ERR_FAIL_COND(buff_size == 0);
ERR_EXPLAIN("Sample buffer size does not match sample size.");
//print_line("len bytes: "+itos(s->length_bytes)+" bufsize: "+itos(buff_size));
- ERR_FAIL_COND(s->length_bytes!=buff_size);
- DVector<uint8_t>::Read buffer_r=p_buffer.read();
+ ERR_FAIL_COND(s->length_bytes != buff_size);
+ DVector<uint8_t>::Read buffer_r = p_buffer.read();
const uint8_t *src = buffer_r.ptr();
- uint8_t *dst = (uint8_t*)s->data;
+ uint8_t *dst = (uint8_t *)s->data;
//print_line("set data: "+itos(s->length_bytes));
- for(int i=0;i<s->length_bytes;i++) {
+ for (int i = 0; i < s->length_bytes; i++) {
- dst[i]=src[i];
+ dst[i] = src[i];
}
- switch(s->format) {
+ switch (s->format) {
case AS::SAMPLE_FORMAT_PCM8: {
if (s->stereo) {
- dst[s->length]=dst[s->length-2];
- dst[s->length+1]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 2];
+ dst[s->length + 1] = dst[s->length - 1];
} else {
- dst[s->length]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 1];
}
} break;
case AS::SAMPLE_FORMAT_PCM16: {
if (s->stereo) {
- dst[s->length]=dst[s->length-4];
- dst[s->length+1]=dst[s->length-3];
- dst[s->length+2]=dst[s->length-2];
- dst[s->length+3]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 4];
+ dst[s->length + 1] = dst[s->length - 3];
+ dst[s->length + 2] = dst[s->length - 2];
+ dst[s->length + 3] = dst[s->length - 1];
} else {
- dst[s->length]=dst[s->length-2];
- dst[s->length+1]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 2];
+ dst[s->length + 1] = dst[s->length - 1];
}
} break;
-
}
-
-
-
}
const DVector<uint8_t> SampleManagerMallocSW::sample_get_data(RID p_sample) const {
Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,DVector<uint8_t>());
+ ERR_FAIL_COND_V(!s, DVector<uint8_t>());
DVector<uint8_t> ret_buffer;
ret_buffer.resize(s->length_bytes);
- DVector<uint8_t>::Write buffer_w=ret_buffer.write();
+ DVector<uint8_t>::Write buffer_w = ret_buffer.write();
uint8_t *dst = buffer_w.ptr();
- const uint8_t *src = (const uint8_t*)s->data;
+ const uint8_t *src = (const uint8_t *)s->data;
- for(int i=0;i<s->length_bytes;i++) {
+ for (int i = 0; i < s->length_bytes; i++) {
- dst[i]=src[i];
+ dst[i] = src[i];
}
buffer_w = DVector<uint8_t>::Write(); //unlock
@@ -205,76 +195,70 @@ const DVector<uint8_t> SampleManagerMallocSW::sample_get_data(RID p_sample) cons
void *SampleManagerMallocSW::sample_get_data_ptr(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,NULL);
+ ERR_FAIL_COND_V(!s, NULL);
return s->data;
-
}
-void SampleManagerMallocSW::sample_set_mix_rate(RID p_sample,int p_rate) {
+void SampleManagerMallocSW::sample_set_mix_rate(RID p_sample, int p_rate) {
- ERR_FAIL_COND(p_rate<1);
+ ERR_FAIL_COND(p_rate < 1);
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- s->mix_rate=p_rate;
-
-
+ s->mix_rate = p_rate;
}
int SampleManagerMallocSW::sample_get_mix_rate(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->mix_rate;
-
}
-void SampleManagerMallocSW::sample_set_loop_format(RID p_sample,AS::SampleLoopFormat p_format) {
+void SampleManagerMallocSW::sample_set_loop_format(RID p_sample, AS::SampleLoopFormat p_format) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- s->loop_format=p_format;
-
+ s->loop_format = p_format;
}
AS::SampleLoopFormat SampleManagerMallocSW::sample_get_loop_format(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,AS::SAMPLE_LOOP_NONE);
+ ERR_FAIL_COND_V(!s, AS::SAMPLE_LOOP_NONE);
return s->loop_format;
}
-void SampleManagerMallocSW::sample_set_loop_begin(RID p_sample,int p_pos) {
+void SampleManagerMallocSW::sample_set_loop_begin(RID p_sample, int p_pos) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- ERR_FAIL_INDEX(p_pos,s->length);
+ ERR_FAIL_INDEX(p_pos, s->length);
- s->loop_begin=p_pos;
+ s->loop_begin = p_pos;
}
int SampleManagerMallocSW::sample_get_loop_begin(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->loop_begin;
}
-void SampleManagerMallocSW::sample_set_loop_end(RID p_sample,int p_pos) {
+void SampleManagerMallocSW::sample_set_loop_end(RID p_sample, int p_pos) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- if (p_pos>s->length)
- p_pos=s->length;
- s->loop_end=p_pos;
-
+ if (p_pos > s->length)
+ p_pos = s->length;
+ s->loop_end = p_pos;
}
int SampleManagerMallocSW::sample_get_loop_end(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->loop_end;
}
@@ -282,7 +266,6 @@ int SampleManagerMallocSW::sample_get_loop_end(RID p_sample) const {
bool SampleManagerMallocSW::is_sample(RID p_sample) const {
return sample_owner.owns(p_sample);
-
}
void SampleManagerMallocSW::free(RID p_sample) {
@@ -294,12 +277,9 @@ void SampleManagerMallocSW::free(RID p_sample) {
memfree(s->data);
memdelete(s);
-
}
SampleManagerMallocSW::SampleManagerMallocSW() {
-
-
}
SampleManagerMallocSW::~SampleManagerMallocSW() {
@@ -308,13 +288,12 @@ SampleManagerMallocSW::~SampleManagerMallocSW() {
List<RID> owned_list;
sample_owner.get_owned_list(&owned_list);
- while(owned_list.size()) {
+ while (owned_list.size()) {
Sample *s = sample_owner.get(owned_list.front()->get());
- String err="Leaked sample of size: "+itos(s->length_bytes)+" description: "+s->description;
+ String err = "Leaked sample of size: " + itos(s->length_bytes) + " description: " + s->description;
ERR_PRINT(err.utf8().get_data());
free(owned_list.front()->get());
owned_list.pop_front();
}
-
}
diff --git a/servers/audio/sample_manager_sw.h b/servers/audio/sample_manager_sw.h
index c0b5661a1..79cd603a5 100644
--- a/servers/audio/sample_manager_sw.h
+++ b/servers/audio/sample_manager_sw.h
@@ -33,47 +33,42 @@
class SampleManagerSW {
public:
-
/* SAMPLE API */
- virtual RID sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length)=0;
-
- virtual void sample_set_description(RID p_sample, const String& p_description)=0;
- virtual String sample_get_description(RID p_sample) const=0;
+ virtual RID sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length) = 0;
- virtual AS::SampleFormat sample_get_format(RID p_sample) const=0;
- virtual bool sample_is_stereo(RID p_sample) const=0;
- virtual int sample_get_length(RID p_sample) const=0;
+ virtual void sample_set_description(RID p_sample, const String &p_description) = 0;
+ virtual String sample_get_description(RID p_sample) const = 0;
- virtual void sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer)=0;
- virtual const DVector<uint8_t> sample_get_data(RID p_sample) const=0;
+ virtual AS::SampleFormat sample_get_format(RID p_sample) const = 0;
+ virtual bool sample_is_stereo(RID p_sample) const = 0;
+ virtual int sample_get_length(RID p_sample) const = 0;
- virtual void *sample_get_data_ptr(RID p_sample) const=0;
+ virtual void sample_set_data(RID p_sample, const DVector<uint8_t> &p_buffer) = 0;
+ virtual const DVector<uint8_t> sample_get_data(RID p_sample) const = 0;
- virtual void sample_set_mix_rate(RID p_sample,int p_rate)=0;
- virtual int sample_get_mix_rate(RID p_sample) const=0;
+ virtual void *sample_get_data_ptr(RID p_sample) const = 0;
- virtual void sample_set_loop_format(RID p_sample,AS::SampleLoopFormat p_format)=0;
- virtual AS::SampleLoopFormat sample_get_loop_format(RID p_sample) const=0;
+ virtual void sample_set_mix_rate(RID p_sample, int p_rate) = 0;
+ virtual int sample_get_mix_rate(RID p_sample) const = 0;
- virtual void sample_set_loop_begin(RID p_sample,int p_pos)=0;
- virtual int sample_get_loop_begin(RID p_sample) const=0;
+ virtual void sample_set_loop_format(RID p_sample, AS::SampleLoopFormat p_format) = 0;
+ virtual AS::SampleLoopFormat sample_get_loop_format(RID p_sample) const = 0;
- virtual void sample_set_loop_end(RID p_sample,int p_pos)=0;
- virtual int sample_get_loop_end(RID p_sample) const=0;
-
- virtual bool is_sample(RID) const=0;
- virtual void free(RID p_sample)=0;
+ virtual void sample_set_loop_begin(RID p_sample, int p_pos) = 0;
+ virtual int sample_get_loop_begin(RID p_sample) const = 0;
+ virtual void sample_set_loop_end(RID p_sample, int p_pos) = 0;
+ virtual int sample_get_loop_end(RID p_sample) const = 0;
+ virtual bool is_sample(RID) const = 0;
+ virtual void free(RID p_sample) = 0;
virtual ~SampleManagerSW();
};
-
class SampleManagerMallocSW : public SampleManagerSW {
-
struct Sample {
void *data;
@@ -89,34 +84,34 @@ class SampleManagerMallocSW : public SampleManagerSW {
};
mutable RID_Owner<Sample> sample_owner;
-public:
+public:
/* SAMPLE API */
virtual RID sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length);
- virtual void sample_set_description(RID p_sample, const String& p_description);
+ virtual void sample_set_description(RID p_sample, const String &p_description);
virtual String sample_get_description(RID p_sample) const;
virtual AS::SampleFormat sample_get_format(RID p_sample) const;
virtual bool sample_is_stereo(RID p_sample) const;
virtual int sample_get_length(RID p_sample) const;
- virtual void sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer);
+ virtual void sample_set_data(RID p_sample, const DVector<uint8_t> &p_buffer);
virtual const DVector<uint8_t> sample_get_data(RID p_sample) const;
virtual void *sample_get_data_ptr(RID p_sample) const;
- virtual void sample_set_mix_rate(RID p_sample,int p_rate);
+ virtual void sample_set_mix_rate(RID p_sample, int p_rate);
virtual int sample_get_mix_rate(RID p_sample) const;
- virtual void sample_set_loop_format(RID p_sample,AS::SampleLoopFormat p_format);
+ virtual void sample_set_loop_format(RID p_sample, AS::SampleLoopFormat p_format);
virtual AS::SampleLoopFormat sample_get_loop_format(RID p_sample) const;
- virtual void sample_set_loop_begin(RID p_sample,int p_pos);
+ virtual void sample_set_loop_begin(RID p_sample, int p_pos);
virtual int sample_get_loop_begin(RID p_sample) const;
- virtual void sample_set_loop_end(RID p_sample,int p_pos);
+ virtual void sample_set_loop_end(RID p_sample, int p_pos);
virtual int sample_get_loop_end(RID p_sample) const;
virtual bool is_sample(RID) const;
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