16#ifndef R8B_CDSPHBDOWNSAMPLER_INCLUDED
17#define R8B_CDSPHBDOWNSAMPLER_INCLUDED
48 const bool IsThird,
const double PrevLatency )
50 static const CConvolveFn FltConvFn[ 14 ] = {
51 &CDSPHBDownsampler :: convolve1, &CDSPHBDownsampler :: convolve2,
52 &CDSPHBDownsampler :: convolve3, &CDSPHBDownsampler :: convolve4,
53 &CDSPHBDownsampler :: convolve5, &CDSPHBDownsampler :: convolve6,
54 &CDSPHBDownsampler :: convolve7, &CDSPHBDownsampler :: convolve8,
55 &CDSPHBDownsampler :: convolve9, &CDSPHBDownsampler :: convolve10,
56 &CDSPHBDownsampler :: convolve11, &CDSPHBDownsampler :: convolve12,
57 &CDSPHBDownsampler :: convolve13,
58 &CDSPHBDownsampler :: convolve14 };
66 CDSPHBUpsampler :: getHBFilterThird( ReqAtten, SteepIndex, fltp0,
71 CDSPHBUpsampler :: getHBFilter( ReqAtten, SteepIndex, fltp0, fltt,
78 memcpy( fltp, fltp0, (
size_t) fltt *
sizeof( fltp[ 0 ]));
80 convfn = FltConvFn[ fltt - 1 ];
86 BufRP2 = Buf2 + fll - 1;
88 LatencyFrac = PrevLatency * 0.5;
89 Latency = (int) LatencyFrac;
90 LatencyFrac -= Latency;
94 R8BCONSOLE(
"CDSPHBDownsampler: taps=%i third=%i att=%.1f io=1/2\n",
95 fltt, (
int) IsThird, att );
102 return( flo + (
int) (( Latency + LatencyFrac + ReqOutPos ) * 2.0 ));
112 return( LatencyFrac );
119 return(( MaxInLen + 1 ) >> 1 );
124 LatencyLeft = Latency;
130 memset( &Buf1[ ReadPos ], 0,
131 (
size_t) ( BufLen - flb ) *
sizeof( Buf1[ 0 ]));
133 memset( &Buf2[ ReadPos ], 0,
134 (
size_t) ( BufLen - flb ) *
sizeof( Buf2[ 0 ]));
137 virtual int process(
double* ip,
int l,
double*& op0 )
147 if( WritePos1 != WritePos2 )
152 double*
const wp2 = Buf2 + WritePos2;
155 if( WritePos2 < flo )
161 WritePos2 = WritePos1;
166 const int b1 =
min(( l + 1 ) >> 1,
167 min( BufLen - WritePos1, flb - BufLeft ));
169 const int b2 = b1 - ( b1 * 2 > l );
171 double* wp1 = Buf1 + WritePos1;
172 double* wp2 = Buf2 + WritePos1;
173 double*
const ipe = ip + b2 * 2;
190 const int ec = flo - WritePos1;
194 wp1 = Buf1 + WritePos1;
195 memcpy( wp1 + BufLen, wp1,
196 (
size_t)
min( b1, ec ) *
sizeof( wp1[ 0 ]));
198 wp2 = Buf2 + WritePos1;
199 memcpy( wp2 + BufLen, wp2,
200 (
size_t)
min( b2, ec ) *
sizeof( wp2[ 0 ]));
203 WritePos1 = ( WritePos1 + b1 ) & BufLenMask;
204 WritePos2 = ( WritePos2 + b2 ) & BufLenMask;
210 const int c = BufLeft - fl2;
214 double*
const opend = op + c;
215 ( *convfn )( op, opend, fltp, BufRP1, BufRP2, ReadPos );
218 ReadPos = ( ReadPos + c ) & BufLenMask;
223 int ol = (int) ( op - op0 );
225 if( LatencyLeft != 0 )
227 if( LatencyLeft >= ol )
242 static const int BufLenBits = 10;
248 static const int BufLen = 1 << BufLenBits;
251 static const int BufLenMask = BufLen - 1;
253 double Buf1[ BufLen + 27 ];
255 double Buf2[ BufLen + 27 ];
257 double FltBuf[ 14 + 2 ];
259 const double* BufRP1;
260 const double* BufRP2;
276 typedef void( *CConvolveFn )(
double* op,
double*
const opend,
277 const double*
const flt,
const double*
const rp01,
278 const double*
const rp02,
int rpos );
282#define R8BHBC1( fn ) \
283 static void fn( double* op, double* const opend, const double* const flt, \
284 const double* const rp01, const double* const rp02, int rpos ) \
286 while( op != opend ) \
288 const double* const rp1 = rp01 + rpos; \
289 const double* const rp = rp02 + rpos;
292 rpos = ( rpos + 1 ) & BufLenMask; \
297#include "CDSPHBDownsampler.inc"
Half-band upsampling class.
#define R8BASSERT(e)
Assertion macro used to check for certain run-time conditions. By default, no action is taken if asse...
Definition r8bconf.h:28
#define R8BCONSOLE(...)
Console output macro, used to output various resampler status strings, including filter design parame...
Definition r8bconf.h:41
The "r8brain-free-src" library namespace.
Definition CDSPBlockConvolver.h:22
T * alignptr(T *const ptr, const uintptr_t align)
Forces the provided ptr pointer to be aligned to align bytes.
Definition r8bbase.h:256
T min(const T &v1, const T &v2)
Returns minimum of two values.
Definition r8bbase.h:1079
virtual int getInLenBeforeOutPos(const int ReqOutPos) const
Returns the number of input samples required to advance to the specified output sample position (so t...
Definition CDSPHBDownsampler.h:100
virtual int process(double *ip, int l, double *&op0)
Performs DSP processing.
Definition CDSPHBDownsampler.h:137
CDSPHBDownsampler(const double ReqAtten, const int SteepIndex, const bool IsThird, const double PrevLatency)
Initalizes the half-band downsampler.
Definition CDSPHBDownsampler.h:47
virtual int getLatency() const
Return the latency, in samples, which is present in the output signal.
Definition CDSPHBDownsampler.h:105
virtual void clear()
Clears (resets) the state of this object and returns it to the state after construction.
Definition CDSPHBDownsampler.h:122
virtual int getMaxOutLen(const int MaxInLen) const
Returns the maximal length of the output buffer required when processing the MaxInLen number of input...
Definition CDSPHBDownsampler.h:115
virtual double getLatencyFrac() const
Returns fractional latency, in samples, which is present in the output signal.
Definition CDSPHBDownsampler.h:110