cwDspTypes.h,cwDspTransforms.h/cpp : Removed the 'real_t' and replaced it with more specific types which identify how the type is being used (e.g. coeff_t, ftime_t).
This commit is contained in:
parent
a7a38fa9f4
commit
a0b4e9c120
@ -21,9 +21,9 @@ namespace cw
|
||||
{
|
||||
namespace compressor
|
||||
{
|
||||
void _ms_to_samples( obj_t*p, real_t ms, unsigned& outRef )
|
||||
void _ms_to_samples( obj_t*p, ftime_t ms, unsigned& outRef )
|
||||
{
|
||||
outRef = std::max((real_t)1,(real_t)floor(ms * p->srate / 1000.0));
|
||||
outRef = std::max(1u,(unsigned)floor(ms * p->srate / 1000.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ namespace cw
|
||||
// compressor
|
||||
//
|
||||
|
||||
cw::rc_t cw::dsp::compressor::create( obj_t*& p, real_t srate, unsigned procSmpCnt, real_t inGain, real_t rmsWndMaxMs, real_t rmsWndMs, real_t threshDb, real_t ratio_num, real_t atkMs, real_t rlsMs, real_t outGain, bool bypassFl )
|
||||
cw::rc_t cw::dsp::compressor::create( obj_t*& p, srate_t srate, unsigned procSmpCnt, coeff_t inGain, ftime_t rmsWndMaxMs, ftime_t rmsWndMs, coeff_t threshDb, coeff_t ratio_num, ftime_t atkMs, ftime_t rlsMs, coeff_t outGain, bool bypassFl )
|
||||
{
|
||||
p = mem::allocZ<obj_t>();
|
||||
|
||||
@ -105,8 +105,8 @@ cw::rc_t cw::dsp::compressor::exec( obj_t* p, const sample_t* x, sample_t* y, un
|
||||
p->rmsWnd[ p->rmsWndIdx ] = vop::rms(xx, n); // calc and store signal RMS
|
||||
p->rmsWndIdx = (p->rmsWndIdx + 1) % p->rmsWndCnt; // advance the RMS storage buffer
|
||||
|
||||
real_t rmsLin = vop::mean(p->rmsWnd,p->rmsWndCnt); // calc avg RMS
|
||||
real_t rmsDb = std::max(-100.0,20 * log10(std::max((real_t)0.00001,rmsLin))); // convert avg RMS to dB
|
||||
coeff_t rmsLin = vop::mean(p->rmsWnd,p->rmsWndCnt); // calc avg RMS
|
||||
coeff_t rmsDb = std::max(-100.0,20 * log10(std::max((coeff_t)0.00001,rmsLin))); // convert avg RMS to dB
|
||||
rmsDb += 100.0;
|
||||
|
||||
// if the compressor is bypassed
|
||||
@ -147,17 +147,17 @@ cw::rc_t cw::dsp::compressor::exec( obj_t* p, const sample_t* x, sample_t* y, un
|
||||
}
|
||||
|
||||
|
||||
void cw::dsp::compressor::set_attack_ms( obj_t* p, real_t ms )
|
||||
void cw::dsp::compressor::set_attack_ms( obj_t* p, ftime_t ms )
|
||||
{
|
||||
_ms_to_samples(p,ms,p->atkSmp);
|
||||
}
|
||||
|
||||
void cw::dsp::compressor::set_release_ms( obj_t* p, real_t ms )
|
||||
void cw::dsp::compressor::set_release_ms( obj_t* p, ftime_t ms )
|
||||
{
|
||||
_ms_to_samples(p,ms,p->rlsSmp);
|
||||
}
|
||||
|
||||
void cw::dsp::compressor::set_rms_wnd_ms( obj_t* p, real_t ms )
|
||||
void cw::dsp::compressor::set_rms_wnd_ms( obj_t* p, ftime_t ms )
|
||||
{
|
||||
p->rmsWndCnt = std::max((unsigned)1,(unsigned)floor(ms * p->srate / (1000.0 * p->procSmpCnt)));
|
||||
|
||||
@ -170,7 +170,7 @@ void cw::dsp::compressor::set_rms_wnd_ms( obj_t* p, real_t ms )
|
||||
// Limiter
|
||||
//
|
||||
|
||||
cw::rc_t cw::dsp::limiter::create( obj_t*& p, real_t srate, unsigned procSmpCnt, real_t thresh, real_t igain, real_t ogain, bool bypassFl )
|
||||
cw::rc_t cw::dsp::limiter::create( obj_t*& p, srate_t srate, unsigned procSmpCnt, coeff_t thresh, coeff_t igain, coeff_t ogain, bool bypassFl )
|
||||
{
|
||||
p = mem::allocZ<obj_t>();
|
||||
|
||||
@ -196,7 +196,7 @@ cw::rc_t cw::dsp::limiter::exec( obj_t* p, const sample_t* x, sample_t* y, unsig
|
||||
}
|
||||
else
|
||||
{
|
||||
real_t T = p->thresh * p->ogain;
|
||||
coeff_t T = p->thresh * p->ogain;
|
||||
|
||||
for(unsigned i=0; i<n; ++i)
|
||||
{
|
||||
@ -227,7 +227,7 @@ cw::rc_t cw::dsp::limiter::exec( obj_t* p, const sample_t* x, sample_t* y, unsig
|
||||
// dc-filter
|
||||
//
|
||||
|
||||
cw::rc_t cw::dsp::dc_filter::create( obj_t*& p, real_t srate, unsigned procSmpCnt, real_t gain, bool bypassFl )
|
||||
cw::rc_t cw::dsp::dc_filter::create( obj_t*& p, srate_t srate, unsigned procSmpCnt, coeff_t gain, bool bypassFl )
|
||||
{
|
||||
p = mem::allocZ<obj_t>();
|
||||
|
||||
@ -255,12 +255,12 @@ cw::rc_t cw::dsp::dc_filter::exec( obj_t* p, const sample_t* x, sample_t* y, uns
|
||||
if( p->bypassFl )
|
||||
vop::copy(y,x,n);
|
||||
else
|
||||
vop::filter<sample_t,real_t>(y,n,x,n,p->b0, p->b, p->a, p->d, 1 );
|
||||
vop::filter<sample_t,coeff_t>(y,n,x,n,p->b0, p->b, p->a, p->d, 1 );
|
||||
|
||||
return kOkRC;
|
||||
}
|
||||
|
||||
cw::rc_t cw::dsp::dc_filter::set( obj_t* p, real_t gain, bool bypassFl )
|
||||
cw::rc_t cw::dsp::dc_filter::set( obj_t* p, coeff_t gain, bool bypassFl )
|
||||
{
|
||||
p->gain = gain;
|
||||
p->bypassFl = bypassFl;
|
||||
@ -272,7 +272,7 @@ cw::rc_t cw::dsp::dc_filter::set( obj_t* p, real_t gain, bool bypassFl )
|
||||
// Recorder
|
||||
//
|
||||
|
||||
cw::rc_t cw::dsp::recorder::create( obj_t*& pRef, real_t srate, real_t max_secs, unsigned chN )
|
||||
cw::rc_t cw::dsp::recorder::create( obj_t*& pRef, srate_t srate, ftime_t max_secs, unsigned chN )
|
||||
{
|
||||
obj_t* p = mem::allocZ<obj_t>();
|
||||
p->srate = srate;
|
||||
@ -383,7 +383,7 @@ namespace cw {
|
||||
}
|
||||
}
|
||||
|
||||
cw::rc_t cw::dsp::audio_meter::create( obj_t*& p, real_t srate, real_t maxWndMs, real_t wndMs, real_t peakThreshDb )
|
||||
cw::rc_t cw::dsp::audio_meter::create( obj_t*& p, srate_t srate, ftime_t maxWndMs, ftime_t wndMs, coeff_t peakThreshDb )
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
|
||||
@ -475,7 +475,7 @@ void cw::dsp::audio_meter::reset( obj_t* p )
|
||||
p->clipCnt = 0;
|
||||
}
|
||||
|
||||
void cw::dsp::audio_meter::set_window_ms( obj_t* p, real_t wndMs )
|
||||
void cw::dsp::audio_meter::set_window_ms( obj_t* p, ftime_t wndMs )
|
||||
{
|
||||
unsigned wndSmpN = (unsigned)((wndMs * p->srate)/1000.0);
|
||||
|
||||
|
@ -14,36 +14,36 @@ namespace cw
|
||||
|
||||
typedef struct
|
||||
{
|
||||
real_t srate; // system sample rate
|
||||
srate_t srate; // system sample rate
|
||||
unsigned procSmpCnt; // samples per exec cycle
|
||||
real_t inGain; // input gain
|
||||
real_t threshDb; // threshold in dB (max:100 min:0)
|
||||
real_t ratio_num; // numerator of the ratio
|
||||
coeff_t inGain; // input gain
|
||||
coeff_t threshDb; // threshold in dB (max:100 min:0)
|
||||
coeff_t ratio_num; // numerator of the ratio
|
||||
unsigned atkSmp; // time to reduce the signal by 10.0 db
|
||||
unsigned rlsSmp; // time to increase the signal by 10.0 db
|
||||
real_t outGain; // makeup gain
|
||||
coeff_t outGain; // makeup gain
|
||||
bool bypassFl; // bypass enable
|
||||
sample_t* rmsWnd; // rmsWnd[rmsWndAllocCnt]
|
||||
unsigned rmsWndAllocCnt; //
|
||||
unsigned rmsWndCnt; // current RMS window size (rmsWndCnt must be <= rmsWndAllocCnt)
|
||||
unsigned rmsWndIdx; // next RMS window input index
|
||||
unsigned state; // env. state
|
||||
real_t rmsDb; // current incoming signal RMS (max:100 min:0)
|
||||
real_t gain; // current compressor gain
|
||||
real_t timeConstDb; // the atk/rls will incr/decr by 'timeConstDb' per atkMs/rlsMs.
|
||||
real_t pkDb; //
|
||||
real_t accumDb; //
|
||||
coeff_t rmsDb; // current incoming signal RMS (max:100 min:0)
|
||||
coeff_t gain; // current compressor gain
|
||||
coeff_t timeConstDb; // the atk/rls will incr/decr by 'timeConstDb' per atkMs/rlsMs.
|
||||
coeff_t pkDb; //
|
||||
coeff_t accumDb; //
|
||||
|
||||
} obj_t;
|
||||
|
||||
rc_t create( obj_t*& p, real_t srate, unsigned procSmpCnt, real_t inGain, real_t rmsWndMaxMs, real_t rmsWndMs, real_t threshDb, real_t ratio, real_t atkMs, real_t rlsMs, real_t outGain, bool bypassFl );
|
||||
rc_t create( obj_t*& p, srate_t srate, unsigned procSmpCnt, coeff_t inGain, ftime_t rmsWndMaxMs, ftime_t rmsWndMs, coeff_t threshDb, coeff_t ratio, ftime_t atkMs, ftime_t rlsMs, coeff_t outGain, bool bypassFl );
|
||||
rc_t destroy( obj_t*& pp );
|
||||
rc_t exec( obj_t* p, const sample_t* x, sample_t* y, unsigned n );
|
||||
|
||||
void set_attack_ms( obj_t* p, real_t ms );
|
||||
void set_release_ms( obj_t* p, real_t ms );
|
||||
void set_thresh_db( obj_t* p, real_t thresh );
|
||||
void set_rms_wnd_ms( obj_t* p, real_t ms );
|
||||
void set_attack_ms( obj_t* p, ftime_t ms );
|
||||
void set_release_ms( obj_t* p, ftime_t ms );
|
||||
void set_thresh_db( obj_t* p, coeff_t thresh );
|
||||
void set_rms_wnd_ms( obj_t* p, ftime_t ms );
|
||||
}
|
||||
|
||||
namespace limiter
|
||||
@ -51,13 +51,13 @@ namespace cw
|
||||
typedef struct
|
||||
{
|
||||
unsigned procSmpCnt;
|
||||
real_t igain; // applied before thresholding
|
||||
real_t thresh; // linear (0.0-1.0) threshold.
|
||||
real_t ogain; // applied after thresholding
|
||||
coeff_t igain; // applied before thresholding
|
||||
coeff_t thresh; // linear (0.0-1.0) threshold.
|
||||
coeff_t ogain; // applied after thresholding
|
||||
bool bypassFl;
|
||||
} obj_t;
|
||||
|
||||
rc_t create( obj_t*& p, real_t srate, unsigned procSmpCnt, real_t thresh, real_t igain, real_t ogain, bool bypassFl );
|
||||
rc_t create( obj_t*& p, srate_t srate, unsigned procSmpCnt, coeff_t thresh, coeff_t igain, coeff_t ogain, bool bypassFl );
|
||||
rc_t destroy( obj_t*& pp );
|
||||
rc_t exec( obj_t* p, const sample_t* x, sample_t* y, unsigned n );
|
||||
}
|
||||
@ -66,32 +66,32 @@ namespace cw
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
real_t d[2]; //
|
||||
real_t b[1]; //
|
||||
real_t a[1]; // a[dn] feedback coeff's
|
||||
real_t b0; // feedforward coeff 0
|
||||
coeff_t d[2]; //
|
||||
coeff_t b[1]; //
|
||||
coeff_t a[1]; // a[dn] feedback coeff's
|
||||
coeff_t b0; // feedforward coeff 0
|
||||
bool bypassFl;
|
||||
real_t gain;
|
||||
coeff_t gain;
|
||||
} obj_t;
|
||||
|
||||
rc_t create( obj_t*& p, real_t srate, unsigned procSmpCnt, real_t gain, bool bypassFl );
|
||||
rc_t create( obj_t*& p, srate_t srate, unsigned procSmpCnt, coeff_t gain, bool bypassFl );
|
||||
rc_t destroy( obj_t*& pp );
|
||||
rc_t exec( obj_t* p, const sample_t* x, sample_t* y, unsigned n );
|
||||
rc_t set( obj_t* p, real_t gain, bool bypassFl );
|
||||
rc_t set( obj_t* p, coeff_t gain, bool bypassFl );
|
||||
}
|
||||
|
||||
namespace recorder
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
real_t srate; //
|
||||
srate_t srate; //
|
||||
unsigned maxFrameN; //
|
||||
unsigned chN; // channel count
|
||||
unsigned frameIdx; // next frame to write
|
||||
sample_t* buf; // [ [maxFrameN] [maxFrameN] ]
|
||||
} obj_t; // ch0 ch1
|
||||
|
||||
rc_t create( obj_t*& pRef, real_t srate, real_t max_secs, unsigned chN );
|
||||
rc_t create( obj_t*& pRef, srate_t srate, ftime_t max_secs, unsigned chN );
|
||||
rc_t destroy( obj_t*& pRef);
|
||||
|
||||
rc_t exec( obj_t* p, const sample_t* buf, unsigned chN, unsigned frameN );
|
||||
@ -107,10 +107,10 @@ namespace cw
|
||||
unsigned maxWndSmpN;
|
||||
unsigned wndSmpN;
|
||||
sample_t* wndV;
|
||||
real_t srate;
|
||||
real_t peakThreshDb;
|
||||
real_t outLin;
|
||||
real_t outDb;
|
||||
srate_t srate;
|
||||
coeff_t peakThreshDb;
|
||||
coeff_t outLin;
|
||||
coeff_t outDb;
|
||||
bool peakFl;
|
||||
bool clipFl;
|
||||
unsigned peakCnt;
|
||||
@ -118,11 +118,11 @@ namespace cw
|
||||
unsigned wi;
|
||||
} obj_t;
|
||||
|
||||
rc_t create( obj_t*& p, real_t srate, real_t maxWndMs, real_t wndMs, real_t peakThreshDb );
|
||||
rc_t create( obj_t*& p, srate_t srate, ftime_t maxWndMs, ftime_t wndMs, coeff_t peakThreshDb );
|
||||
rc_t destroy( obj_t*& pp );
|
||||
rc_t exec( obj_t* p, const sample_t* x, unsigned n );
|
||||
void reset( obj_t* p );
|
||||
void set_window_ms( obj_t* p, real_t wndMs );
|
||||
void set_window_ms( obj_t* p, ftime_t wndMs );
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,11 @@ namespace cw
|
||||
{
|
||||
namespace dsp
|
||||
{
|
||||
typedef float real_t;
|
||||
typedef float sample_t;
|
||||
typedef float fd_real_t;
|
||||
typedef float fd_sample_t; // Frequency domain sample - type used by magnitude,phase,real,imag. part of spectral values
|
||||
typedef float srate_t;
|
||||
typedef float coeff_t; // values that are directly applied to signals of sample_t.
|
||||
typedef double ftime_t; // any time value expressed as a floating point value - could be seconds, milliseconds, etc
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user