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 ];
87 LatencyFrac = PrevLatency * 0.5;
88 Latency = (int) LatencyFrac;
89 LatencyFrac -= Latency;
93 R8BCONSOLE(
"CDSPHBDownsampler: taps=%i third=%i att=%.1f io=1/2\n",
94 fltt, (
int) IsThird, att );
101 return( flo + (
int) (( Latency + LatencyFrac + ReqOutPos ) * 2.0 ));
111 return( LatencyFrac );
118 return(( MaxInLen + 1 ) >> 1 );
123 LatencyLeft = Latency;
129 memset( &Buf[ ReadPos ], 0,
130 (
size_t) ( BufLen - flb ) *
sizeof( Buf[ 0 ]));
132 memset( &Buf[ BufLenPad + ReadPos ], 0,
133 (
size_t) ( BufLen - flb ) *
sizeof( Buf[ 0 ]));
136 virtual int process(
double* ip,
int l,
double*& op0 )
146 if( WritePos1 != WritePos2 )
151 double*
const wp2 = Buf + BufLenPad + WritePos2;
154 if( WritePos2 < flo )
160 WritePos2 = WritePos1;
165 const int b1 =
min(( l + 1 ) >> 1,
166 min( BufLen - WritePos1, flb - BufLeft ));
168 const int b2 = b1 - ( b1 * 2 > l );
170 double*
const wp1 = Buf + WritePos1;
171 double*
const wp2 = Buf + BufLenPad + WritePos1;
174 for( i = 0; i < b2; i++ )
187 const int ec = flo - WritePos1;
191 memcpy( wp1 + BufLen, wp1,
192 (
size_t)
min( b1, ec ) *
sizeof( wp1[ 0 ]));
194 memcpy( wp2 + BufLen, wp2,
195 (
size_t)
min( b2, ec ) *
sizeof( wp2[ 0 ]));
198 WritePos1 = ( WritePos1 + b1 ) & BufLenMask;
199 WritePos2 = ( WritePos2 + b2 ) & BufLenMask;
205 int c = BufLeft - fl2;
209 const int cb =
min( c, BufLen - ReadPos );
210 double*
const opend = op + cb;
211 ( *convfn )( op, opend, fltp, BufRP + ReadPos );
214 ReadPos = ( ReadPos + cb ) & BufLenMask;
220 int ol = (int) ( op - op0 );
222 if( LatencyLeft != 0 )
224 if( LatencyLeft >= ol )
239 static const int BufLenBits = 10;
245 static const int BufLen = 1 << BufLenBits;
248 static const int BufLenMask = BufLen - 1;
250 static const int BufLenPad = BufLen + 27;
252 double Buf[ BufLenPad * 2 ];
254 double FltBuf[ 14 + 2 ];
272 typedef void( *CConvolveFn )(
double* op,
double*
const opend,
273 const double*
const flt,
const double* rp1 );
277#define R8BHBC1( fn ) \
278 static void fn( double* op, double* const opend, const double* const flt, \
279 const double* rp1 ) \
281 while( op != opend ) \
283 const double* const rp = rp1 + BufLenPad - 1;
291#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:269
T min(const T &v1, const T &v2)
Returns minimum of two values.
Definition r8bbase.h:1092
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:99
virtual int process(double *ip, int l, double *&op0)
Performs DSP processing.
Definition CDSPHBDownsampler.h:136
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:104
virtual void clear()
Clears (resets) the state of this object and returns it to the state after construction.
Definition CDSPHBDownsampler.h:121
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:114
virtual double getLatencyFrac() const
Returns fractional latency, in samples, which is present in the output signal.
Definition CDSPHBDownsampler.h:109