### Namespace and Compatibility Setup Source: https://www.voxengo.com/public/avir/Documentation/a00017_source.html Standard library imports and compatibility workarounds for pre-C++11 compilers. ```cpp namespace avir { using std :: memcpy; using std :: memset; using std :: fabs; using std :: floor; using std :: ceil; using std :: sin; using std :: cos; using std :: size_t; #if __cplusplus >= 201103L using std :: intptr_t; using std :: uintptr_t; #else // __cplusplus >= 201103L // Workaround for pre-C++11 compilers. `nullptr` is a keyword, and not a // macro, but check if such workaround is already in place. #if !defined( nullptr ) #define nullptr NULL #define LANCIR_NULLPTR #endif // !defined( nullptr ) #endif // __cplusplus >= 201103L ``` -------------------------------- ### startAllWorkloads() Source: https://www.voxengo.com/public/avir/Documentation/a00056.html Starts all workloads associated with threads previously added. ```APIDOC ## void avir::CImageResizerThreadPool::startAllWorkloads() ### Description Starts all workloads associated with threads previously added via the addWorkload() function. This function performs the necessary memory barrier operations to ensure thread synchronization. ``` -------------------------------- ### Resize Macros Source: https://www.voxengo.com/public/avir/Documentation/a00017_source.html Preprocessor macros for handling loop setup and teardown in resizing operations. ```cpp #define LANCIR_LF_PRE \ const CResizePos* const rpe = rp + DstLen; \ while( rp != rpe ) \ { \ const float* flt = rp -> flt; \ const float* ip; \ if( UseSP ) \ { \ ip = (const float*) ( (intptr_t) sp + rp -> spo ); \ } \ else \ { \ ip = (const float*) rp -> spo; \ } ``` ```cpp #define LANCIR_LF_POST \ op += opinc; \ rp++; \ } ``` -------------------------------- ### startAllWorkloads Source: https://www.voxengo.com/public/avir/Documentation/a00056.html Starts all workloads associated with threads previously added to the pool. ```APIDOC ## void startAllWorkloads() ### Description Starts all workloads associated with threads previously added via the addWorkload() function. Each thread will execute its workload's process() function. ``` -------------------------------- ### CSineGen Constructor Source: https://www.voxengo.com/public/avir/Documentation/a00032.html Initializes the sine signal generator with a specific increment and starting phase. ```APIDOC ## CSineGen(const double si, const double ph) ### Description Initializes the sine signal generator. This generator uses an efficient oscillator instead of the standard sin() function. ### Parameters - **si** (double) - Sine function increment, in radians. - **ph** (double) - Starting phase, in radians. Add 0.5 * AVIR_PI for cosine function. ``` -------------------------------- ### init() Source: https://www.voxengo.com/public/avir/Documentation/a00120.html Initializes the ditherer object with scanline length, resizing variables, truncation multiplier, and peak output value. ```APIDOC ## void init(const int aLen, const CImageResizerVars &aVars, const double aTrMul, const double aPkOut) ### Description Initializes the ditherer object. ### Parameters - **aLen** (int) - Scanline length in pixels to process. - **aVars** (CImageResizerVars) - Image resizing-related variables. - **aTrMul** (double) - Bit-depth truncation multiplier. 1 - no additional truncation. - **aPkOut** (double) - Peak output value allowed. ``` -------------------------------- ### void init(const int aLen, const CImageResizerVars &aVars, const double aTrMul, const double aPkOut) Source: https://www.voxengo.com/public/avir/Documentation/a00152.html Initializes the ditherer object with scanline length, resizing variables, and dithering parameters. ```APIDOC ## void init(const int aLen, const CImageResizerVars &aVars, const double aTrMul, const double aPkOut) ### Description Initializes the ditherer object for processing. ### Parameters - **aLen** (int) - Required - Scanline length in pixels to process. - **aVars** (CImageResizerVars &) - Required - Image resizing-related variables. - **aTrMul** (double) - Required - Bit-depth truncation multiplier (1 indicates no additional truncation). - **aPkOut** (double) - Required - Peak output value allowed. ``` -------------------------------- ### void init(const int aLen, const CImageResizerVars &aVars, const double aTrMul, const double aPkOut) Source: https://www.voxengo.com/public/avir/Documentation/a00148.html Initializes the ditherer object with scanline length, resizing variables, and bit-depth parameters. ```APIDOC ## void init(const int aLen, const CImageResizerVars &aVars, const double aTrMul, const double aPkOut) ### Description Initializes the ditherer object for processing. ### Parameters - **aLen** (int) - Required - Scanline length in pixels to process. - **aVars** (const CImageResizerVars &) - Required - Image resizing-related variables. - **aTrMul** (double) - Required - Bit-depth truncation multiplier (1 means no additional truncation). - **aPkOut** (double) - Required - Peak output value allowed. ``` -------------------------------- ### init() Source: https://www.voxengo.com/public/avir/Documentation/a00052.html Initializes or builds the filter bank based on the provided parameters. If parameters match existing ones, the function performs no action. ```APIDOC ## void init(const int _ReqFracCount_, const int _ReqOrder_, const double _BaseLen_, const double _Cutoff_, const double _aWFAlpha_, const CFltBuffer & _aExtFilter_, const int _aAlignment_ = 0, const int _FltLenAlign_ = 1) ### Description Initializes the filter bank. If the supplied parameters are equal to previously defined parameters, the function does nothing. ### Parameters - **_ReqFracCount_** (int) - Required number of fractional delays in the filter bank (min 2). - **_ReqOrder_** (int) - Required order of the interpolation polynomial (0 or 1). - **_BaseLen_** (double) - Low-pass filter's base length in samples. - **_Cutoff_** (double) - Normalized cutoff frequency [0; 1]. - **_aWFAlpha_** (double) - Peaked Cosine window function's Alpha parameter. - **_aExtFilter_** (CFltBuffer) - External filter to apply to each fractional delay filter. - **_aAlignment_** (int) - Memory alignment of the filter bank (power-of-2). - **_FltLenAlign_** (int) - Filter's length alignment (power-of-2). ``` -------------------------------- ### void resizeImage(const Tin *const _SrcBuf_, const int _SrcWidth_, const int _SrcHeight_, int _SrcScanlineSize_, Tout *const _NewBuf_, const int _NewWidth_, const int _NewHeight_, const int _ElCountIO_, const double _k_, CImageResizerVars *const _aVars_) Source: https://www.voxengo.com/public/avir/Documentation/a00132.html Resizes an image from a source buffer into a destination buffer using specified dimensions and scaling parameters. ```APIDOC ## void resizeImage(const Tin *const _SrcBuf_, const int _SrcWidth_, const int _SrcHeight_, int _SrcScanlineSize_, Tout *const _NewBuf_, const int _NewWidth_, const int _NewHeight_, const int _ElCountIO_, const double _k_, CImageResizerVars *const _aVars_) ### Description Resizes the image based on provided dimensions and scaling factors. This function supports various input and output buffer types. ### Parameters - **_SrcBuf_** (const Tin *const) - Source image buffer. - **_SrcWidth_** (const int) - Source image width. - **_SrcHeight_** (const int) - Source image height. - **_SrcScanlineSize_** (int) - Physical size of source scanline in elements. If < 1, defaults to SrcWidth * ElCountIO. - **_NewBuf_** (Tout *const) - Buffer to accept the resized image. - **_NewWidth_** (const int) - New image width. - **_NewHeight_** (const int) - New image height. - **_ElCountIO_** (const int) - Number of elements (channels) per pixel (1-4). - **_k_** (const double) - Resizing step. Downsizing factor if > 1.0; upsizing if < 1.0. Multiply by -1 to bypass default centering. 0 for automatic calculation. - **_aVars_** (CImageResizerVars *const) - Pointer to variables structure. Optional, can be nullptr. ### Template Parameters - **Tin** - Input buffer element type (uint8_t, uint16_t, float, double). - **Tout** - Output buffer element type (uint8_t, uint16_t, float, double). ``` -------------------------------- ### CImageResizerDithererDefDIL Class Initialization Source: https://www.voxengo.com/public/avir/Documentation/a00008_source.html Initialization method for the dithering class, setting up length and configuration variables. ```cpp void init( const int aLen, const CImageResizerVars& aVars, const double aTrMul, const double aPkOut ) { Len = aLen; ``` -------------------------------- ### void avir::CDSPFIREQ::init Source: https://www.voxengo.com/public/avir/Documentation/a00040.html Initializes the CDSPFIREQ object with specific processing parameters including sample rate, filter length, and frequency band settings. ```APIDOC ## void avir::CDSPFIREQ::init(const double SampleRate, const double aFilterLength, const int aBandCount, const double MinFreq, const double MaxFreq, const bool IsLogBands, const double WFAlpha) ### Description Initializes this object with the required parameters. The gain of frequencies beyond the MinFreq..MaxFreq range are controlled by the first and the last band's gain. ### Parameters - **SampleRate** (double) - Processing sample rate (use 2 for image processing). - **aFilterLength** (double) - Required filter length in samples (taps). The actual filter length is truncated to an integer value. - **aBandCount** (int) - Number of band crossover points required to control, including bands at MinFreq and MaxFreq. - **MinFreq** (double) - Minimal frequency that should be controlled. - **MaxFreq** (double) - Maximal frequency that should be controlled. - **IsLogBands** (bool) - true, if the bands should be spaced logarithmically. - **WFAlpha** (double) - Peaked Cosine window function's Alpha parameter. ``` -------------------------------- ### Prepare Input Buffer Source: https://www.voxengo.com/public/avir/Documentation/a00008_source.html Prepares the input buffer by replicating array boundaries based on prefix and suffix lengths. ```cpp void prepareInBuf( fptype* Src ) const { if( IsUpsample || InPrefix + InSuffix == 0 ) { return; } int j; for( j = 0; j < Vars -> ElCount; j++ ) { replicateArray( Src, 1, Src - InPrefix, InPrefix, 1 ); fptype* const Src2 = Src + InLen - 1; replicateArray( Src2, 1, Src2 + 1, InSuffix, 1 ); Src += InElIncr; } } ``` -------------------------------- ### Default Ditherer Initialization Source: https://www.voxengo.com/public/avir/Documentation/a00008_source.html Initializes the default ditherer with length, variables, and truncation/output parameters. ```cpp 796 Vars = &aVars; 797 LenE = aLen * Vars -> ElCount; 798 TrMul0 = aTrMul; 799 PkOut0 = aPkOut; 800 } 792 void init( const int aLen, const CImageResizerVars& aVars, {…} ``` -------------------------------- ### Memory Loading and Storing Methods Source: https://www.voxengo.com/public/avir/Documentation/a00014_source.html Static methods for loading data into float8 and instance methods for storing data back to memory, including support for partial limits. ```cpp static float8 load( const float* const p ) { return( _mm256_load_ps( p )); } static float8 loadu( const float* const p ) { return( _mm256_loadu_ps( p )); } static float8 loadu( const float* const p, const int lim ) { __m128 lo; __m128 hi; if( lim > 4 ) { lo = _mm_loadu_ps( p ); hi = loadu4( p + 4, lim - 4 ); } else { lo = loadu4( p, lim ); hi = _mm_setzero_ps(); } return( _mm256_insertf128_ps( _mm256_castps128_ps256( lo ), hi, 1 )); } void store( float* const p ) const { _mm256_store_ps( p, value ); } void storeu( float* const p ) const { _mm256_storeu_ps( p, value ); } void storeu( float* p, int lim ) const { __m128 v; if( lim > 4 ) { _mm_storeu_ps( p, _mm256_extractf128_ps( value, 0 )); v = _mm256_extractf128_ps( value, 1 ); p += 4; lim -= 4; } else { v = _mm256_extractf128_ps( value, 0 ); } if( lim > 2 ) { if( lim > 3 ) { _mm_storeu_ps( p, v ); } else { _mm_storel_pi( (__m64*) p, v ); _mm_store_ss( p + 2, _mm_movehl_ps( v, v )); } } else { if( lim == 2 ) { _mm_storel_pi( (__m64*) p, v ); } else { _mm_store_ss( p, v ); } } } ``` -------------------------------- ### CDSPFIREQ::init Source: https://www.voxengo.com/public/avir/Documentation/a00040.html Initializes the CDSPFIREQ object with specific filter parameters including sample rate, filter length, and frequency band settings. ```APIDOC ## void init (const double SampleRate, const double aFilterLength, const int aBandCount, const double MinFreq, const double MaxFreq, const bool IsLogBands, const double WFAlpha) ### Description Initializes the object with the required parameters for FIR filter generation. ### Parameters - **SampleRate** (double) - The sample rate of the audio. - **aFilterLength** (double) - The length of the filter. - **aBandCount** (int) - The number of frequency bands. - **MinFreq** (double) - The minimum frequency. - **MaxFreq** (double) - The maximum frequency. - **IsLogBands** (bool) - Whether to use logarithmic bands. - **WFAlpha** (double) - The window function alpha parameter. ``` -------------------------------- ### CDSPFracFilterBankLin::init Source: https://www.voxengo.com/public/avir/Documentation/a00052.html Initializes and builds the filter bank based on the provided parameters. ```APIDOC ## void init(const int ReqFracCount, const int ReqOrder, const double BaseLen, const double Cutoff, const double aWFAlpha, const CFltBuffer &aExtFilter, const int aAlignment=0, const int FltLenAlign=1) ### Description Initializes (builds) the filter bank based on the supplied parameters. ### Parameters - **ReqFracCount** (int) - Required - The number of fractional filters. - **ReqOrder** (int) - Required - The order of the interpolation polynomial. - **BaseLen** (double) - Required - The base length of the filter. - **Cutoff** (double) - Required - The cutoff frequency. - **aWFAlpha** (double) - Required - The window function alpha parameter. - **aExtFilter** (CFltBuffer) - Required - The external filter buffer. - **aAlignment** (int) - Optional - Alignment value, defaults to 0. - **FltLenAlign** (int) - Optional - Filter length alignment, defaults to 1. ``` -------------------------------- ### Resize2 Implementation Source: https://www.voxengo.com/public/avir/Documentation/a00017_source.html Template-based resize function with AVX and custom vector support. ```cpp 2224 template< bool UseSP > 2225 static void resize2( const float* const sp, float* op, const size_t opinc, 2226 const CResizePos* rp, const int kl, const int DstLen ) 2227 { 2228 #if LANCIR_ALIGN > 4 2229 const int ci = kl >> 2; 2230 const int cir = kl & 3; 2231 #else // LANCIR_ALIGN > 4 2232 const int ci = kl >> 1; 2233 #endif // LANCIR_ALIGN > 4 2234 2235 LANCIR_LF_PRE 2236 2237 int c = ci; 2238 2239 #if defined( LANCIR_AVX ) 2240 2241 __m256 sum = _mm256_mul_ps( _mm256_load_ps( flt ), 2242 _mm256_loadu_ps( ip )); 2243 2244 while( --c != 0 ) 2245 { 2246 flt += 8; 2247 ip += 8; 2248 sum = _mm256_add_ps( sum, _mm256_mul_ps( _mm256_load_ps( flt ), 2249 _mm256_loadu_ps( ip ))); 2250 } 2251 2252 __m128 res = _mm_add_ps( _mm256_extractf128_ps( sum, 0 ), 2253 _mm256_extractf128_ps( sum, 1 )); 2254 2255 if( cir == 2 ) 2256 { 2257 res = _mm_add_ps( res, _mm_mul_ps( _mm_load_ps( flt + 8 ), 2258 _mm_loadu_ps( ip + 8 ))); 2259 } 2260 2261 _mm_storel_pi( (__m64*) op, 2262 _mm_add_ps( res, _mm_movehl_ps( res, res ))); 2263 2264 #elif LANCIR_ALIGN > 4 2265 2266 lancvec_t sumA = lancvec_mul( 2267 lancvec_load( flt ), lancvec_loadu( ip )); 2268 2269 lancvec_t sumB = lancvec_mul( 2270 lancvec_load( flt + 4 ), lancvec_loadu( ip + 4 )); 2271 2272 while( --c != 0 ) 2273 { 2274 flt += 8; 2275 ip += 8; 2276 sumA = lancvec_madd( sumA, lancvec_load( flt ), 2277 lancvec_loadu( ip )); 2278 2279 sumB = lancvec_madd( sumB, lancvec_load( flt + 4 ), 2280 lancvec_loadu( ip + 4 )); 2281 } 2282 2283 sumA = lancvec_add( sumA, sumB ); 2284 2285 if( cir == 2 ) 2286 { 2287 sumA = lancvec_madd( sumA, lancvec_load( flt + 8 ), 2288 lancvec_loadu( ip + 8 )); 2289 } 2290 2291 lancvec_store64_addhl( op, sumA ); 2292 2293 #else // LANCIR_ALIGN > 4 2294 2295 const float xx = flt[ 0 ]; 2296 const float xx2 = flt[ 1 ]; 2297 float sum0 = xx * ip[ 0 ]; 2298 float sum1 = xx * ip[ 1 ]; 2299 float sum2 = xx2 * ip[ 2 ]; 2300 float sum3 = xx2 * ip[ 3 ]; 2301 2302 while( --c != 0 ) 2303 { 2304 flt += 2; 2305 ip += 4; 2306 const float xx = flt[ 0 ]; 2307 const float xx2 = flt[ 1 ]; 2308 sum0 += xx * ip[ 0 ]; 2309 sum1 += xx * ip[ 1 ]; 2310 sum2 += xx2 * ip[ 2 ]; 2311 sum3 += xx2 * ip[ 3 ]; 2312 } 2313 2314 op[ 0 ] = sum0 + sum2; 2315 op[ 1 ] = sum1 + sum3; 2316 2317 #endif // LANCIR_ALIGN > 4 2318 2319 LANCIR_LF_POST 2320 } ``` -------------------------------- ### void buildFilter(const double *const _BandGains_, double *const _Filter_) Source: https://www.voxengo.com/public/avir/Documentation/a00040.html Creates a symmetric-odd FIR filter based on specified gain levels at band crossover points. ```APIDOC ## void buildFilter(const double *const _BandGains_, double *const _Filter_) ### Description Creates symmetric-odd FIR filter with the specified gain levels at band crossover points. ### Parameters - **_BandGains_** (const double *const) - Array of linear gain levels, count equals BandCount specified in the init() function. - **_Filter_** (double *const) - Output filter buffer, length equals getFilterLength(). ``` -------------------------------- ### doResize Method Implementation Source: https://www.voxengo.com/public/avir/Documentation/a00008_source.html Core resizing logic handling different filter orders and element counts using SIMD instructions. ```cpp void doResize( const fptype* SrcLine, fptype* DstLine, int DstLineIncr, fptype* const xx ) const { const int IntFltLen = FltBank -> getFilterLen(); const int ElCount = Vars -> ElCount; const int elalign = Vars -> elalign; const typename CImageResizerFilterStep< fptype, fptype > :: CResizePos* rpos = &(*RPosBuf)[ 0 ]; int DstLineLen = OutLen; int i; int j; #define AVIR_RESIZE_PART1 \ while( DstLineLen > 0 ) \ { \ const fptypesimd x = (fptypesimd) rpos -> x; \ const fptype* ftp = rpos -> ftp; \ const fptype* ftp2 = rpos -> ftp + IntFltLen; \ const fptype* Src = SrcLine + rpos -> SrcOffs; #define AVIR_RESIZE_PART1nx \ while( DstLineLen > 0 ) \ { \ const fptype* ftp = rpos -> ftp; \ const fptype* Src = SrcLine + rpos -> SrcOffs; #define AVIR_RESIZE_PART2 \ DstLine += DstLineIncr; \ rpos++; \ DstLineLen--; \ } if( ElCount == 1 ) { if( FltBank -> getOrder() == 1 ) { AVIR_RESIZE_PART1 fptypesimd sum = ( fptypesimd :: load( ftp ) + fptypesimd :: load( ftp2 ) * x ) * fptypesimd :: loadu( Src ); for( i = elalign; i < IntFltLen; i += elalign ) { sum += ( fptypesimd :: load( ftp + i ) + fptypesimd :: load( ftp2 + i ) * x ) * fptypesimd :: loadu( Src + i ); } DstLine[ 0 ] = sum.hadd(); AVIR_RESIZE_PART2 } else { AVIR_RESIZE_PART1nx fptypesimd sum = fptypesimd :: load( ftp ) * fptypesimd :: loadu( Src ); for( i = elalign; i < IntFltLen; i += elalign ) { sum += fptypesimd :: load( ftp + i ) * fptypesimd :: loadu( Src + i ); } DstLine[ 0 ] = sum.hadd(); AVIR_RESIZE_PART2 } } else if( DstLineIncr == 1 ) { // Horizontal-oriented processing, element loop is outer. const int SrcIncr = InElIncr; const int DstLineElIncr = OutElIncr - DstLineIncr * DstLineLen; if( FltBank -> getOrder() == 1 ) { for( j = 0; j < ElCount; j++ ) { AVIR_RESIZE_PART1 fptypesimd sum = 0.0; for( i = 0; i < IntFltLen; i += elalign ) { sum += ( fptypesimd :: load( ftp + i ) + fptypesimd :: load( ftp2 + i ) * x ) * fptypesimd :: loadu( Src + i ); } DstLine[ 0 ] = sum.hadd(); AVIR_RESIZE_PART2 DstLine += DstLineElIncr; SrcLine += SrcIncr; DstLineLen = OutLen; rpos = &(*RPosBuf)[ 0 ]; } } else { for( j = 0; j < ElCount; j++ ) { AVIR_RESIZE_PART1nx fptypesimd sum = fptypesimd :: load( ftp ) * fptypesimd :: loadu( Src ); for( i = elalign; i < IntFltLen; i += elalign ) { sum += fptypesimd :: load( ftp + i ) * fptypesimd :: loadu( Src + i ); } DstLine[ 0 ] = sum.hadd(); AVIR_RESIZE_PART2 DstLine += DstLineElIncr; SrcLine += SrcIncr; DstLineLen = OutLen; rpos = &(*RPosBuf)[ 0 ]; } } } else { const int SrcIncr = InElIncr; const int DstLineElIncr = OutElIncr; DstLineIncr -= DstLineElIncr * ElCount; if( FltBank -> getOrder() == 1 ) { AVIR_RESIZE_PART1 for( i = 0; i < IntFltLen; i += elalign ) { ( fptypesimd :: load( ftp + i ) + fptypesimd :: load( ftp2 + i ) * x ).store( xx + i ); } for( j = 0; j < ElCount; j++ ) { fptypesimd sum = fptypesimd :: load( xx ) * fptypesimd :: loadu( Src ); for( i = elalign; i < IntFltLen; i += elalign ) { sum += fptypesimd :: load( xx + i ) * fptypesimd :: loadu( Src + i ); } DstLine[ 0 ] = sum.hadd(); DstLine += DstLineElIncr; Src += SrcIncr; } AVIR_RESIZE_PART2 } else { AVIR_RESIZE_PART1nx for( j = 0; j < ElCount; j++ ) { fptypesimd sum = fptypesimd :: load( ftp ) * fptypesimd :: loadu( Src ); for( i = elalign; i < IntFltLen; i += elalign ) { sum += fptypesimd :: load( ftp + i ) * fptypesimd :: loadu( Src + i ); } DstLine[ 0 ] = sum.hadd(); DstLine += DstLineElIncr; Src += SrcIncr; } AVIR_RESIZE_PART2 } } #undef AVIR_RESIZE_PART2 #undef AVIR_RESIZE_PART1nx #undef AVIR_RESIZE_PART1 } ``` -------------------------------- ### Resize3 Implementation Source: https://www.voxengo.com/public/avir/Documentation/a00017_source.html Template-based resize function with AVX optimization for larger vector operations. ```cpp 2322 template< bool UseSP > 2323 static void resize3( const float* const sp, float* op, const size_t opinc, 2324 const CResizePos* rp, const int kl, const int DstLen ) 2325 { 2326 #if LANCIR_ALIGN > 4 2327 2328 const int ci = kl >> 2; 2329 const int cir = kl & 3; 2330 2331 LANCIR_LF_PRE 2332 2333 float res[ 12 ]; 2334 int c = ci; 2335 2336 #if defined( LANCIR_AVX ) 2337 2338 __m128 sumA = _mm_mul_ps( _mm_load_ps( flt ), _mm_loadu_ps( ip )); 2339 __m256 sumB = _mm256_mul_ps( _mm256_loadu_ps( flt + 4 ), 2340 _mm256_loadu_ps( ip + 4 )); 2341 2342 while( --c != 0 ) 2343 { 2344 flt += 12; 2345 ip += 12; 2346 sumA = _mm_add_ps( sumA, _mm_mul_ps( _mm_load_ps( flt ), 2347 _mm_loadu_ps( ip ))); 2348 2349 sumB = _mm256_add_ps( sumB, _mm256_mul_ps( 2350 _mm256_loadu_ps( flt + 4 ), _mm256_loadu_ps( ip + 4 ))); 2351 } 2352 2353 if( cir == 2 ) ``` -------------------------------- ### Private Helper Methods Source: https://www.voxengo.com/public/avir/Documentation/a00014_source.html Internal helper methods for handling partial vector loads. ```cpp static __m128 loadu4( const float* const p, const int lim ) { if( lim > 2 ) { if( lim > 3 ) { return( _mm_loadu_ps( p )); } else { return( _mm_set_ps( 0.0f, p[ 2 ], p[ 1 ], p[ 0 ])); } } else { if( lim == 2 ) { ``` -------------------------------- ### CDSPPeakedCosineLPF Constructor Source: https://www.voxengo.com/public/avir/Documentation/a00044.html Initializes the CDSPPeakedCosineLPF object with specified filter parameters. ```APIDOC ## CDSPPeakedCosineLPF(const double aLen2, const double aFreq2, const double aAlpha) ### Description Initializes the object with the specified filter length, corner frequency, and window alpha parameter. ### Parameters - **aLen2** (double) - Half-length (non-truncated) of low-pass filter, in samples (taps). - **aFreq2** (double) - Low-pass filter's corner frequency, [0; pi]. - **aAlpha** (double) - Peaked Cosine window function Alpha parameter. ``` -------------------------------- ### Include Required Headers Source: https://www.voxengo.com/public/avir/Documentation/a00017.html Standard library headers required for the LANCIR implementation. ```cpp #include #include #include ``` -------------------------------- ### static void addu(float *const p, const float8 &v) Source: https://www.voxengo.com/public/avir/Documentation/a00164.html Performs in-place addition of a value located in memory and the specified float8 value. ```APIDOC ## static void addu(float *const p, const float8 &v) ### Description Performs in-place addition of a value located in memory, and the specified value. ### Parameters - **p** (float *const) - Pointer to value where addition happens. May be unaligned. - **v** (const float8 &) - Value to add. ``` -------------------------------- ### prepareInBuf() Source: https://www.voxengo.com/public/avir/Documentation/a00144.html Prepares the input scanline buffer for the filtering step by replicating edge pixels to prevent buffer overruns. ```APIDOC ## void prepareInBuf(fptype *Src) ### Description Prepares input scanline buffer for this filtering step. Left- and right-most pixels are replicated to make sure no buffer overrun happens, allowing the bypass of pointer range checks. ### Parameters - **Src** (fptype*) - Required - Source buffer. ``` -------------------------------- ### int calcInitComplexity(const CBuffer &FracUseMap) Source: https://www.voxengo.com/public/avir/Documentation/a00052.html Calculates the approximate initialization complexity in terms of multiply-add operations for the fractional delay filter bank. ```APIDOC ## int calcInitComplexity(const CBuffer &FracUseMap) ### Description Returns an approximate initialization complexity, expressed in the number of multiply-add operations. This includes fractional delay filters calculation and multiplication by an external filter. This function can only be called after the init() function. ### Parameters #### Parameters - **FracUseMap** (const CBuffer &) - Required - Fractional delays use map, each element corresponds to a single fractional delay, will be compared to the internal table fill flags. This map should include 0 and 1 values only. ### Returns - **int** - The complexity of the initialization, expressed in the number of multiply-add operations. ``` -------------------------------- ### alloc() Source: https://www.voxengo.com/public/avir/Documentation/a00024.html Allocates memory to store a specified number of elements in the buffer. ```APIDOC ## void alloc(const capint _aCapacity_, const int _aAlignment_ = 0) ### Description Allocates memory so that the specified number of elements can be stored in this buffer object. ### Parameters - **_aCapacity_** (capint) - Required - Storage for this number of elements to allocate. - **_aAlignment_** (int) - Optional - Buffer's required memory address alignment, power-of-2 values only. 0 - use stdlib's default alignment. ``` -------------------------------- ### CImageResizerParamsUltra Configuration Parameters Source: https://www.voxengo.com/public/avir/Documentation/a00088.html This class defines the configuration parameters used for ultra low-aliasing image resizing. These parameters control the behavior of the interpolation, low-pass, and correction filters. ```APIDOC ## CImageResizerParamsUltra ### Description A set of resizing algorithm parameters for ultra low-aliasing resizing. This configuration provides high anti-aliasing performance and frequency response linearity, though it is computationally expensive and may introduce ringing artifacts on sharp features. ### Parameters - **CorrFltAlpha** (double) - Alpha parameter of the Peaked Cosine window function for the correction filter (Usable range: 1.0 to 1.5). - **CorrFltLen** (double) - Correction filter length in samples (Usable range: 5.5 to 8). - **HBFltAlpha** (double) - Half-band filter Alpha (Assigned internally). - **HBFltCutoff** (double) - Half-band filter cutoff point [0; 1] (Assigned internally). - **HBFltLen** (double) - Length of the half-band low-pass filter (Assigned internally). - **IntFltAlpha** (double) - Alpha parameter of the Peaked Cosine window function for the interpolation low-pass filter (Usable range: 1.5 to 2.5). - **IntFltCutoff** (double) - Interpolation low-pass filter cutoff frequency [0; 1] (Usable range: 0.6 to 0.8). - **IntFltLen** (double) - Interpolation low-pass filter length in samples (Should be at least 18). - **LPFltAlpha** (double) - Alpha parameter of the Peaked Cosine window function for the low-pass filter (Usable range: 1.5 to 6.5). - **LPFltBaseLen** (double) - Base length of the low-pass filter in samples (Usable range: 6 to 9). - **LPFltCutoffMult** (double) - Low-pass filter cutoff frequency multiplier (Usable range: 0.3 to 1.0). ``` -------------------------------- ### getRPosBuf Source: https://www.voxengo.com/public/avir/Documentation/a00112.html Retrieves a resizing positions buffer with the specified stepping, creating it if it does not already exist. ```APIDOC ## CRPosBuf & getRPosBuf(const double k, const double o, const int FracCount) ### Description Returns the resizing positions buffer with the required stepping. If no such buffer exists, it is created. ### Parameters - **k** (double) - Resizing step. - **o** (double) - Resizing offset. - **FracCount** (int) - The number of fractional delay filters in a filter bank used together with this buffer. ### Returns - **CRPosBuf &** - Reference to the CRPosBuf object. ``` -------------------------------- ### Error-Diffusion Ditherer Initialization Source: https://www.voxengo.com/public/avir/Documentation/a00008_source.html Initializes the error-diffusion ditherer and allocates memory for the scanline buffer. ```cpp 895 void init( const int aLen, const CImageResizerVars& aVars, 896 const double aTrMul, const double aPkOut ) 897 { 898 Len = aLen; 899 Vars = &aVars; 900 LenE = aLen * Vars -> ElCount; 901 TrMul0 = aTrMul; 902 PkOut0 = aPkOut; 903 904 ResScanlineDith0.alloc( LenE + Vars -> ElCount, sizeof( fptype )); 905 ResScanlineDith = ResScanlineDith0 + Vars -> ElCount; 906 int i; 907 908 for( i = 0; i < LenE + Vars -> ElCount; i++ ) 909 { 910 ResScanlineDith0[ i ] = 0.0; 911 } 912 } 895 void init( const int aLen, const CImageResizerVars& aVars, {…} ``` -------------------------------- ### copyInitParams() Source: https://www.voxengo.com/public/avir/Documentation/a00052.html Copies a limited set of parameters from a source filter bank. Note that actual filters are not copied and a subsequent init() call is required. ```APIDOC ## void copyInitParams(const CDSPFracFilterBankLin &s) ### Description Copies a limited set of parameters of the source filter bank. The actual filters are not copied. Such copying is used during filtering steps "modeling" stage. A further init() function call is required. ### Parameters - **s** (const CDSPFracFilterBankLin &) - Required - Source filter bank. ``` -------------------------------- ### Resize Kernel Implementation Source: https://www.voxengo.com/public/avir/Documentation/a00017_source.html Template-based resize function using either SIMD vectors or scalar accumulation. ```cpp template< bool UseSP > static void resize1( const float* const sp, float* op, const size_t opinc, const CResizePos* rp, const int kl, const int DstLen ) { const int ci = kl >> 2; if(( kl & 3 ) == 0 ) { LANCIR_LF_PRE int c = ci; #if LANCIR_ALIGN > 4 lancvec_t sum = lancvec_mul( lancvec_load( flt ), lancvec_loadu( ip )); while( --c != 0 ) { flt += 4; ip += 4; sum = lancvec_madd( sum, lancvec_load( flt ), lancvec_loadu( ip )); } lancvec_store32_hadd( op, sum ); #else // LANCIR_ALIGN > 4 float sum0 = flt[ 0 ] * ip[ 0 ]; float sum1 = flt[ 1 ] * ip[ 1 ]; float sum2 = flt[ 2 ] * ip[ 2 ]; float sum3 = flt[ 3 ] * ip[ 3 ]; while( --c != 0 ) { flt += 4; ip += 4; sum0 += flt[ 0 ] * ip[ 0 ]; sum1 += flt[ 1 ] * ip[ 1 ]; sum2 += flt[ 2 ] * ip[ 2 ]; sum3 += flt[ 3 ] * ip[ 3 ]; } op[ 0 ] = ( sum0 + sum1 ) + ( sum2 + sum3 ); #endif // LANCIR_ALIGN > 4 ``` -------------------------------- ### prepareInBuf Source: https://www.voxengo.com/public/avir/Documentation/a00144.html Prepares input scanline buffer for this filtering step. ```APIDOC ## void prepareInBuf(fptype *Src) const ### Description Prepares input scanline buffer for this filtering step. ### Parameters - **Src** (fptype *) - Source buffer ``` -------------------------------- ### Buffer Reallocation Utilities Source: https://www.voxengo.com/public/avir/Documentation/a00017_source.html Static template functions for managing memory buffers with alignment support. ```cpp template< typename Tb, typename Tl > static void reallocBuf( Tb*& buf0, Tb*& buf, Tl& len, Tl newlen ) { newlen += LANCIR_ALIGN; if( newlen > len ) { if( buf0 != nullptr ) { delete[] buf0; buf0 = nullptr; len = 0; } buf0 = new Tb[ newlen ]; len = newlen; buf = (Tb*) (( (uintptr_t) buf0 + LANCIR_ALIGN - 1 ) & ~(uintptr_t) ( LANCIR_ALIGN - 1 )); } } ``` ```cpp template< typename Tb, typename Tl > static void reallocBuf( Tb*& buf, Tl& len, const Tl newlen ) { if( newlen > len ) { if( buf != nullptr ) { delete[] buf; buf = nullptr; len = 0; } buf = new Tb[ newlen ]; len = newlen; } } ``` -------------------------------- ### Define LANCIR Macros Source: https://www.voxengo.com/public/avir/Documentation/a00017.html Configuration macros for address alignment and compatibility. ```cpp #define LANCIR_ALIGN 4 ``` ```cpp #define LANCIR_NULLPTR ``` ```cpp #define nullptr NULL ``` -------------------------------- ### CImageResizer Constructor Source: https://www.voxengo.com/public/avir/Documentation/a00129.html Initializes a new instance of the CImageResizer class with specified bit depths and parameters. ```APIDOC ## CImageResizer(const int aResBitDepth, const int aSrcBitDepth, const CImageResizerParams &aParams) ### Description Constructs the image resizer object with defined bit depth settings and resizing parameters. ### Parameters - **aResBitDepth** (int) - Optional - The bit depth of the result image (default: 8). - **aSrcBitDepth** (int) - Optional - The bit depth of the source image (default: 0). - **aParams** (CImageResizerParams) - Optional - The resizing parameters to use (default: CImageResizerParamsDef()). ``` -------------------------------- ### void doResize(const fptype *SrcLine, fptype *DstLine, const int DstLineIncr, fptype * const _) Source: https://www.voxengo.com/public/avir/Documentation/a00116.html Performs resizing of a single scanline. Requires the source buffer to be padded to prevent out-of-bounds access. ```APIDOC ## void doResize(const fptype *SrcLine, fptype *DstLine, const int DstLineIncr, fptype * const _) ### Description Performs resizing of a single scanline. This function does not "know" about the length of the source scanline buffer. This buffer should be padded with enough pixels so that SrcPos - FilterLenD2 is always greater or equal to 0, and SrcPos + ( DstLineLen - 1 ) * k + FilterLenD2 + 1 does not exceed source scanline's buffer length. SrcLine increment is assumed to be equal to ElCount. ### Parameters - **SrcLine** (const fptype *) - Source scanline buffer. - **DstLine** (fptype *) - Destination (resized) scanline buffer. - **DstLineIncr** (const int) - Destination scanline position increment, used for horizontal or vertical scanline stepping. - **_** (fptype * const) - Additional parameter. ``` -------------------------------- ### static void addu(float *const p, const float8 &v, const int lim) Source: https://www.voxengo.com/public/avir/Documentation/a00164.html Performs in-place addition of a value located in memory and the specified float8 value, limited to the specified number of elements. ```APIDOC ## static void addu(float *const p, const float8 &v, const int lim) ### Description Performs in-place addition of a value located in memory, and the specified value. Limited to the specified number of elements. ```