15 #ifndef R8B_CDSPHBDOWNSAMPLER_INCLUDED 16 #define R8B_CDSPHBDOWNSAMPLER_INCLUDED 47 const bool IsThird,
const double PrevLatency )
49 static const CConvolveFn FltConvFn[ 14 ] = {
50 &CDSPHBDownsampler :: convolve1, &CDSPHBDownsampler :: convolve2,
51 &CDSPHBDownsampler :: convolve3, &CDSPHBDownsampler :: convolve4,
52 &CDSPHBDownsampler :: convolve5, &CDSPHBDownsampler :: convolve6,
53 &CDSPHBDownsampler :: convolve7, &CDSPHBDownsampler :: convolve8,
54 &CDSPHBDownsampler :: convolve9, &CDSPHBDownsampler :: convolve10,
55 &CDSPHBDownsampler :: convolve11, &CDSPHBDownsampler :: convolve12,
56 &CDSPHBDownsampler :: convolve13,
57 &CDSPHBDownsampler :: convolve14 };
73 convfn = FltConvFn[ fltt - 1 ];
78 LatencyFrac = PrevLatency * 0.5;
79 Latency = (int) LatencyFrac;
80 LatencyFrac -= Latency;
82 R8BCONSOLE(
"CDSPHBDownsampler: taps=%i third=%i att=%.1f io=1/2\n",
83 fltt, (
int) IsThird, att );
95 return( LatencyFrac );
102 return(( MaxInLen + 1 ) / 2 );
107 LatencyLeft = Latency;
110 ReadPos = BufLen - fll;
113 memset( &Buf[ ReadPos ], 0, fll *
sizeof(
double ));
116 virtual int process(
double* ip,
int l,
double*& op0 )
126 const int b =
min(
min( l, BufLen - WritePos ),
127 BufLen - fll - BufLeft );
129 double*
const wp1 = Buf + WritePos;
130 memcpy( wp1, ip, b *
sizeof(
double ));
134 const int c =
min( b, flo - WritePos );
135 memcpy( wp1 + BufLen, wp1, c *
sizeof(
double ));
139 WritePos = ( WritePos + b ) & BufLenMask;
145 const int c = ( BufLeft - fl2 + 1 ) >> 1;
147 double*
const opend = op + c;
148 ( *convfn )( op, opend, fltp, Buf + fll, ReadPos );
155 int ol = (int) ( op - op0 );
157 if( LatencyLeft > 0 )
159 if( LatencyLeft >= ol )
174 static const int BufLenBits = 8;
175 static const int BufLen = 1 << BufLenBits;
182 static const int BufLenMask = BufLen - 1;
186 double Buf[ BufLen + 54 ];
213 typedef void( *CConvolveFn )(
double* op,
double*
const opend,
215 const double*
const flt,
const double*
const rp0,
int& ReadPos0 );
221 #define R8BHBC1( fn ) \ 222 static void fn( double* op, double* const opend, const double* const flt, \ 223 const double* const rp0, int& ReadPos0 ) \ 225 int rpos = ReadPos0; \ 226 while( op < opend ) \ 228 const double* const rp = rp0 + rpos; \ 232 rpos = ( rpos + 2 ) & BufLenMask; \ 239 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]);
243 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
244 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]);
248 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
249 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
250 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]);
254 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
255 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
256 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
257 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]);
261 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
262 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
263 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
264 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
265 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]);
269 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
270 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
271 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
272 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
273 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
274 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]);
278 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
279 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
280 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
281 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
282 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
283 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
284 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]);
288 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
289 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
290 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
291 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
292 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
293 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
294 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]) +
295 flt[ 7 ] * ( rp[ 15 ] + rp[ -15 ]);
299 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
300 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
301 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
302 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
303 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
304 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
305 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]) +
306 flt[ 7 ] * ( rp[ 15 ] + rp[ -15 ]) +
307 flt[ 8 ] * ( rp[ 17 ] + rp[ -17 ]);
310 R8BHBC1( convolve10 )
311 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
312 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
313 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
314 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
315 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
316 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
317 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]) +
318 flt[ 7 ] * ( rp[ 15 ] + rp[ -15 ]) +
319 flt[ 8 ] * ( rp[ 17 ] + rp[ -17 ]) +
320 flt[ 9 ] * ( rp[ 19 ] + rp[ -19 ]);
323 R8BHBC1( convolve11 )
324 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
325 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
326 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
327 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
328 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
329 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
330 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]) +
331 flt[ 7 ] * ( rp[ 15 ] + rp[ -15 ]) +
332 flt[ 8 ] * ( rp[ 17 ] + rp[ -17 ]) +
333 flt[ 9 ] * ( rp[ 19 ] + rp[ -19 ]) +
334 flt[ 10 ] * ( rp[ 21 ] + rp[ -21 ]);
337 R8BHBC1( convolve12 )
338 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
339 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
340 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
341 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
342 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
343 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
344 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]) +
345 flt[ 7 ] * ( rp[ 15 ] + rp[ -15 ]) +
346 flt[ 8 ] * ( rp[ 17 ] + rp[ -17 ]) +
347 flt[ 9 ] * ( rp[ 19 ] + rp[ -19 ]) +
348 flt[ 10 ] * ( rp[ 21 ] + rp[ -21 ]) +
349 flt[ 11 ] * ( rp[ 23 ] + rp[ -23 ]);
352 R8BHBC1( convolve13 )
353 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
354 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
355 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
356 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
357 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
358 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
359 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]) +
360 flt[ 7 ] * ( rp[ 15 ] + rp[ -15 ]) +
361 flt[ 8 ] * ( rp[ 17 ] + rp[ -17 ]) +
362 flt[ 9 ] * ( rp[ 19 ] + rp[ -19 ]) +
363 flt[ 10 ] * ( rp[ 21 ] + rp[ -21 ]) +
364 flt[ 11 ] * ( rp[ 23 ] + rp[ -23 ]) +
365 flt[ 12 ] * ( rp[ 25 ] + rp[ -25 ]);
368 R8BHBC1( convolve14 )
369 flt[ 0 ] * ( rp[ 1 ] + rp[ -1 ]) +
370 flt[ 1 ] * ( rp[ 3 ] + rp[ -3 ]) +
371 flt[ 2 ] * ( rp[ 5 ] + rp[ -5 ]) +
372 flt[ 3 ] * ( rp[ 7 ] + rp[ -7 ]) +
373 flt[ 4 ] * ( rp[ 9 ] + rp[ -9 ]) +
374 flt[ 5 ] * ( rp[ 11 ] + rp[ -11 ]) +
375 flt[ 6 ] * ( rp[ 13 ] + rp[ -13 ]) +
376 flt[ 7 ] * ( rp[ 15 ] + rp[ -15 ]) +
377 flt[ 8 ] * ( rp[ 17 ] + rp[ -17 ]) +
378 flt[ 9 ] * ( rp[ 19 ] + rp[ -19 ]) +
379 flt[ 10 ] * ( rp[ 21 ] + rp[ -21 ]) +
380 flt[ 11 ] * ( rp[ 23 ] + rp[ -23 ]) +
381 flt[ 12 ] * ( rp[ 25 ] + rp[ -25 ]) +
382 flt[ 13 ] * ( rp[ 27 ] + rp[ -27 ]);
393 #endif // R8B_CDSPHBDOWNSAMPLER_INCLUDED static void getHBFilterThird(const double ReqAtten, const int SteepIndex, const double *&flt, int &fltt, double &att)
Function that provides filter data for various steepness indices and attenuations.
Definition: CDSPHBUpsampler.h:301
#define R8BCONSOLE(...)
Console output macro, used to output various resampler status strings, including filter design parame...
Definition: r8bconf.h:85
virtual void clear()
Function clears (resets) the state of *this object and returns it to the state after construction...
Definition: CDSPHBDownsampler.h:105
virtual double getLatencyFrac() const
Definition: CDSPHBDownsampler.h:93
virtual int getMaxOutLen(const int MaxInLen) const
Definition: CDSPHBDownsampler.h:98
#define R8BASSERT(e)
Assertion macro used to check for certain run-time conditions.
Definition: r8bconf.h:72
virtual int getLatency() const
Definition: CDSPHBDownsampler.h:88
Half-band downsampler class.
Definition: CDSPHBDownsampler.h:29
T min(const T &v1, const T &v2)
Definition: r8bbase.h:1118
CDSPHBDownsampler(const double ReqAtten, const int SteepIndex, const bool IsThird, const double PrevLatency)
Constructor initalizes the half-band downsampler.
Definition: CDSPHBDownsampler.h:46
static void getHBFilter(const double ReqAtten, const int SteepIndex, const double *&flt, int &fltt, double &att)
Function that provides filter data for various steepness indices and attenuations.
Definition: CDSPHBUpsampler.h:43
virtual int process(double *ip, int l, double *&op0)
Function performs DSP processing.
Definition: CDSPHBDownsampler.h:116
The base virtual class for DSP processing algorithms.
Definition: CDSPProcessor.h:31
The "r8brain-free-src" library namespace.
Definition: CDSPBlockConvolver.h:21
Half-band upsampling class.