00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TRAVERSO_MIXER_H
00024 #define TRAVERSO_MIXER_H
00025
00026 #include "defines.h"
00027 #include <cmath>
00028
00029
00030 static inline float f_max(float x, float a)
00031 {
00032 x -= a;
00033 x += fabsf (x);
00034 x *= 0.5f;
00035 x += a;
00036
00037 return (x);
00038 }
00039
00040
00041 static inline float dB_to_scale_factor (float dB)
00042 {
00043
00044
00045
00046
00047 return dB > -120.0f ? ::pow(10.0f, dB * 0.05f) : 0.0f;
00048 }
00049
00050
00051 static inline float coefficient_to_dB (float coeff)
00052 {
00053
00054
00055
00056
00057 if (coeff < 0.000001f)
00058 return (-120.0f);
00059 return 20.0f * log10 (coeff);
00060 }
00061
00062
00063 float default_compute_peak (const audio_sample_t* buf, nframes_t nsamples, float current);
00064 void default_apply_gain_to_buffer (audio_sample_t* buf, nframes_t nframes, float gain);
00065 void default_mix_buffers_with_gain (audio_sample_t* dst, const audio_sample_t* src, nframes_t nframes, float gain);
00066 void default_mix_buffers_no_gain (audio_sample_t* dst, const audio_sample_t* src, nframes_t nframes);
00067
00068
00069 #if defined (ARCH_X86) && defined (SSE_OPTIMIZATIONS)
00070
00071 extern "C"
00072 {
00073
00074 float x86_sse_compute_peak (const audio_sample_t* buf, nframes_t nsamples, float current);
00075 void x86_sse_apply_gain_to_buffer (audio_sample_t* buf, nframes_t nframes, float gain);
00076 void x86_sse_mix_buffers_with_gain (audio_sample_t* dst, const audio_sample_t* src, nframes_t nframes, float gain);
00077 void x86_sse_mix_buffers_no_gain (audio_sample_t* dst, const audio_sample_t* src, nframes_t nframes);
00078 }
00079 #endif
00080
00081 #if defined (__APPLE__) && defined (BUILD_VECLIB_OPTIMIZATIONS)
00082
00083 float veclib_compute_peak (const audio_sample_t* buf, nframes_t nsamples, float current);
00084 void veclib_apply_gain_to_buffer (audio_sample_t* buf, nframes_t nframes, float gain);
00085 void veclib_mix_buffers_with_gain (audio_sample_t* dst, const audio_sample_t* src, nframes_t nframes, float gain);
00086 void veclib_mix_buffers_no_gain (audio_sample_t* dst, const audio_sample_t* src, nframes_t nframes);
00087
00088 #endif
00089
00090 class Mixer
00091 {
00092 public:
00093 typedef float (*compute_peak_t) (const audio_sample_t* , nframes_t, float);
00094 typedef void (*apply_gain_to_buffer_t) (audio_sample_t* , nframes_t, float);
00095 typedef void (*mix_buffers_with_gain_t) (audio_sample_t* , const audio_sample_t* , nframes_t, float);
00096 typedef void (*mix_buffers_no_gain_t) (audio_sample_t* , const audio_sample_t* , nframes_t);
00097
00098 static compute_peak_t compute_peak;
00099 static apply_gain_to_buffer_t apply_gain_to_buffer;
00100 static mix_buffers_with_gain_t mix_buffers_with_gain;
00101 static mix_buffers_no_gain_t mix_buffers_no_gain;
00102 };
00103
00104 #endif
00105
00106
00107