| 1 | /* |
| 2 | * This source code is public domain. |
| 3 | * |
| 4 | * Authors: Olivier Lapicque <[email protected]> |
| 5 | * Markus Fick <[email protected]> spline + fir-resampler |
| 6 | */ |
| 7 | |
| 8 | #include "stdafx.h" |
| 9 | #include "sndfile.h" |
| 10 | #include <math.h> |
| 11 | |
| 12 | #ifdef MSC_VER |
| 13 | #pragma bss_seg(".modplug") |
| 14 | #endif |
| 15 | |
| 16 | // Front Mix Buffer (Also room for interleaved rear mix) |
| 17 | int MixSoundBuffer[MIXBUFFERSIZE*4]; |
| 18 | |
| 19 | // Reverb Mix Buffer |
| 20 | #ifndef MODPLUG_NO_REVERB |
| 21 | int MixReverbBuffer[MIXBUFFERSIZE*2]; |
| 22 | extern UINT gnReverbSend; |
| 23 | #endif |
| 24 | |
| 25 | int MixRearBuffer[MIXBUFFERSIZE*2]; |
| 26 | float MixFloatBuffer[MIXBUFFERSIZE*2]; |
| 27 | |
| 28 | #ifdef MSC_VER |
| 29 | #pragma bss_seg() |
| 30 | #endif |
| 31 | |
| 32 | |
| 33 | extern LONG gnDryROfsVol; |
| 34 | extern LONG gnDryLOfsVol; |
| 35 | extern LONG gnRvbROfsVol; |
| 36 | extern LONG gnRvbLOfsVol; |
| 37 | |
| 38 | /* |
| 39 | *----------------------------------------------------------------------------- |
| 40 | cubic spline interpolation doc, |
| 41 | (derived from "digital image warping", g. wolberg) |
| 42 | |
| 43 | interpolation polynomial: f(x) = A3*(x-floor(x))**3 + A2*(x-floor(x))**2 + |
| 44 | A1*(x-floor(x)) + A0 |
| 45 | |
| 46 | with Y = equispaced data points (dist=1), YD = first derivates of data points and IP = floor(x) |
| 47 | the A[0..3] can be found by solving |
| 48 | A0 = Y[IP] |
| 49 | A1 = YD[IP] |
| 50 | A2 = 3*(Y[IP+1]-Y[IP])-2.0*YD[IP]-YD[IP+1] |
| 51 | A3 = -2.0 * (Y[IP+1]-Y[IP]) + YD[IP] - YD[IP+1] |
| 52 | |
| 53 | with the first derivates as |
| 54 | YD[IP] = 0.5 * (Y[IP+1] - Y[IP-1]); |
| 55 | YD[IP+1] = 0.5 * (Y[IP+2] - Y[IP]) |
| 56 | |
| 57 | the coefs becomes |
| 58 | A0 = Y[IP] |
| 59 | A1 = YD[IP] |
| 60 | = 0.5*(Y[IP+1] - Y[IP-1]); |
| 61 | A2 = 3.0*(Y[IP+1]-Y[IP])-2.0*YD[IP]-YD[IP+1] |
| 62 | = 3.0*(Y[IP+1]-Y[IP]) - 0.5*2.0*(Y[IP+1]-Y[IP-1]) - 0.5*(Y[IP+2]-Y[IP]) |
| 63 | = 3.0*Y[IP+1] - 3.0*Y[IP] - Y[IP+1] + Y[IP-1] - 0.5*Y[IP+2] + 0.5*Y[IP] |
| 64 | = -0.5*Y[IP+2] + 2.0 * Y[IP+1] - 2.5*Y[IP] + Y[IP-1] |
| 65 | = Y[IP-1] + 2 * Y[IP+1] - 0.5 * (5.0 * Y[IP] + Y[IP+2]) |
| 66 | A3 = -2.0*(Y[IP+1]-Y[IP]) + YD[IP] + YD[IP+1] |
| 67 | = -2.0*Y[IP+1] + 2.0*Y[IP] + 0.5*(Y[IP+1]-Y[IP-1]) + 0.5*(Y[IP+2]-Y[IP]) |
| 68 | = -2.0*Y[IP+1] + 2.0*Y[IP] + 0.5*Y[IP+1] - 0.5*Y[IP-1] + 0.5*Y[IP+2] - 0.5*Y[IP] |
| 69 | = 0.5 * Y[IP+2] - 1.5 * Y[IP+1] + 1.5 * Y[IP] - 0.5 * Y[IP-1] |
| 70 | = 0.5 * (3.0 * (Y[IP] - Y[IP+1]) - Y[IP-1] + YP[IP+2]) |
| 71 | |
| 72 | then interpolated data value is (horner rule) |
| 73 | out = (((A3*x)+A2)*x+A1)*x+A0 |
| 74 | |
| 75 | this gives parts of data points Y[IP-1] to Y[IP+2] of |
| 76 | part x**3 x**2 x**1 x**0 |
| 77 | Y[IP-1] -0.5 1 -0.5 0 |
| 78 | Y[IP] 1.5 -2.5 0 1 |
| 79 | Y[IP+1] -1.5 2 0.5 0 |
| 80 | Y[IP+2] 0.5 -0.5 0 0 |
| 81 | *--------------------------------------------------------------------------- |
| 82 | */ |
| 83 | // number of bits used to scale spline coefs |
| 84 | #define SPLINE_QUANTBITS 14 |
| 85 | #define SPLINE_QUANTSCALE (1L<<SPLINE_QUANTBITS) |
| 86 | #define SPLINE_8SHIFT (SPLINE_QUANTBITS-8) |
| 87 | #define SPLINE_16SHIFT (SPLINE_QUANTBITS) |
| 88 | // forces coefsset to unity gain |
| 89 | #define SPLINE_CLAMPFORUNITY |
| 90 | // log2(number) of precalculated splines (range is [4..14]) |
| 91 | #define SPLINE_FRACBITS 10 |
| 92 | #define SPLINE_LUTLEN (1L<<SPLINE_FRACBITS) |
| 93 | |
| 94 | class CzCUBICSPLINE |
| 95 | { public: |
| 96 | CzCUBICSPLINE( ); |
| 97 | ~CzCUBICSPLINE( ); |
| 98 | static signed short lut[4*(1L<<SPLINE_FRACBITS)]; |
| 99 | }; |
| 100 | |
| 101 | signed short CzCUBICSPLINE::lut[4*(1L<<SPLINE_FRACBITS)]; |
| 102 | |
| 103 | CzCUBICSPLINE::CzCUBICSPLINE( ) |
| 104 | { int _LIi; |
| 105 | int _LLen = (1L<<SPLINE_FRACBITS); |
| 106 | float _LFlen = 1.0f / (float)_LLen; |
| 107 | float _LScale = (float)SPLINE_QUANTSCALE; |
| 108 | for(_LIi=0;_LIi<_LLen;_LIi++) |
| 109 | { float _LCm1, _LC0, _LC1, _LC2; |
| 110 | float _LX = ((float)_LIi)*_LFlen; |
| 111 | int _LSum,_LIdx = _LIi<<2; |
| 112 | _LCm1 = (float)floor( 0.5 + _LScale*(-0.5*_LX*_LX*_LX + 1.0*_LX*_LX - 0.5*_LX ) ); |
| 113 | _LC0 = (float)floor( 0.5 + _LScale*( 1.5*_LX*_LX*_LX - 2.5*_LX*_LX + 1.0 ) ); |
| 114 | _LC1 = (float)floor( 0.5 + _LScale*(-1.5*_LX*_LX*_LX + 2.0*_LX*_LX + 0.5*_LX ) ); |
| 115 | _LC2 = (float)floor( 0.5 + _LScale*( 0.5*_LX*_LX*_LX - 0.5*_LX*_LX) ); |
| 116 | lut[_LIdx+0] = (signed short)( (_LCm1 < -_LScale) ? -_LScale : ((_LCm1 > _LScale) ? _LScale : _LCm1) ); |
| 117 | lut[_LIdx+1] = (signed short)( (_LC0 < -_LScale) ? -_LScale : ((_LC0 > _LScale) ? _LScale : _LC0 ) ); |
| 118 | lut[_LIdx+2] = (signed short)( (_LC1 < -_LScale) ? -_LScale : ((_LC1 > _LScale) ? _LScale : _LC1 ) ); |
| 119 | lut[_LIdx+3] = (signed short)( (_LC2 < -_LScale) ? -_LScale : ((_LC2 > _LScale) ? _LScale : _LC2 ) ); |
| 120 | #ifdef SPLINE_CLAMPFORUNITY |
| 121 | _LSum = lut[_LIdx+0]+lut[_LIdx+1]+lut[_LIdx+2]+lut[_LIdx+3]; |
| 122 | if( _LSum != SPLINE_QUANTSCALE ) |
| 123 | { int _LMax = _LIdx; |
| 124 | if( lut[_LIdx+1]>lut[_LMax] ) _LMax = _LIdx+1; |
| 125 | if( lut[_LIdx+2]>lut[_LMax] ) _LMax = _LIdx+2; |
| 126 | if( lut[_LIdx+3]>lut[_LMax] ) _LMax = _LIdx+3; |
| 127 | lut[_LMax] += ((signed short)SPLINE_QUANTSCALE-_LSum); |
| 128 | } |
| 129 | #endif |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | CzCUBICSPLINE::~CzCUBICSPLINE( ) |
| 134 | { // nothing todo |
| 135 | } |
| 136 | |
| 137 | CzCUBICSPLINE sspline; |
| 138 | |
| 139 | /* |
| 140 | ------------------------------------------------------------------------------ |
| 141 | fir interpolation doc, |
| 142 | (derived from "an engineer's guide to fir digital filters", n.j. loy) |
| 143 | |
| 144 | calculate coefficients for ideal lowpass filter (with cutoff = fc in |
| 145 | 0..1 (mapped to 0..nyquist)) |
| 146 | c[-N..N] = (i==0) ? fc : sin(fc*pi*i)/(pi*i) |
| 147 | |
| 148 | then apply selected window to coefficients |
| 149 | c[-N..N] *= w(0..N) |
| 150 | with n in 2*N and w(n) being a window function (see loy) |
| 151 | |
| 152 | then calculate gain and scale filter coefs to have unity gain. |
| 153 | ------------------------------------------------------------------------------ |
| 154 | */ |
| 155 | // quantizer scale of window coefs |
| 156 | #define WFIR_QUANTBITS 15 |
| 157 | #define WFIR_QUANTSCALE (1L<<WFIR_QUANTBITS) |
| 158 | #define WFIR_8SHIFT (WFIR_QUANTBITS-8) |
| 159 | #define WFIR_16BITSHIFT (WFIR_QUANTBITS) |
| 160 | // log2(number)-1 of precalculated taps range is [4..12] |
| 161 | #define WFIR_FRACBITS 10 |
| 162 | #define WFIR_LUTLEN ((1L<<(WFIR_FRACBITS+1))+1) |
| 163 | // number of samples in window |
| 164 | #define WFIR_LOG2WIDTH 3 |
| 165 | #define WFIR_WIDTH (1L<<WFIR_LOG2WIDTH) |
| 166 | #define WFIR_SMPSPERWING ((WFIR_WIDTH-1)>>1) |
| 167 | // cutoff (1.0 == pi/2) |
| 168 | #define WFIR_CUTOFF 0.90f |
| 169 | // wfir type |
| 170 | #define WFIR_HANN 0 |
| 171 | #define WFIR_HAMMING 1 |
| 172 | #define WFIR_BLACKMANEXACT 2 |
| 173 | #define WFIR_BLACKMAN3T61 3 |
| 174 | #define WFIR_BLACKMAN3T67 4 |
| 175 | #define WFIR_BLACKMAN4T92 5 |
| 176 | #define WFIR_BLACKMAN4T74 6 |
| 177 | #define WFIR_KAISER4T 7 |
| 178 | #define WFIR_TYPE WFIR_BLACKMANEXACT |
| 179 | // wfir help |
| 180 | #ifndef M_zPI |
| 181 | #define M_zPI 3.1415926535897932384626433832795 |
| 182 | #endif |
| 183 | #define M_zEPS 1e-8 |
| 184 | #define M_zBESSELEPS 1e-21 |
| 185 | |
| 186 | class CzWINDOWEDFIR |
| 187 | { |
| 188 | public: |
| 189 | CzWINDOWEDFIR( ); |
| 190 | ~CzWINDOWEDFIR( ); |
| 191 | float coef( int _PCnr, float _POfs, float _PCut, int _PWidth, int _PType ) |
| 192 | //OLD args to coef: float _PPos, float _PFc, int _PLen ) |
| 193 | { |
| 194 | double _LWidthM1 = _PWidth-1; |
| 195 | double _LWidthM1Half = 0.5*_LWidthM1; |
| 196 | double _LPosU = ((double)_PCnr - _POfs); |
| 197 | double _LPos = _LPosU-_LWidthM1Half; |
| 198 | double _LPIdl = 2.0*M_zPI/_LWidthM1; |
| 199 | double _LWc,_LSi; |
| 200 | if( fabs(_LPos)<M_zEPS ) { |
| 201 | _LWc = 1.0; |
| 202 | _LSi = _PCut; |
| 203 | } else { |
| 204 | switch( _PType ) |
| 205 | { |
| 206 | case WFIR_HANN: |
| 207 | _LWc = 0.50 - 0.50 * cos(_LPIdl*_LPosU); |
| 208 | break; |
| 209 | case WFIR_HAMMING: |
| 210 | _LWc = 0.54 - 0.46 * cos(_LPIdl*_LPosU); |
| 211 | break; |
| 212 | case WFIR_BLACKMANEXACT: |
| 213 | _LWc = 0.42 - 0.50 * cos(_LPIdl*_LPosU) + |
| 214 | 0.08 * cos(2.0*_LPIdl*_LPosU); |
| 215 | break; |
| 216 | case WFIR_BLACKMAN3T61: |
| 217 | _LWc = 0.44959 - 0.49364 * cos(_LPIdl*_LPosU) + |
| 218 | 0.05677 * cos(2.0*_LPIdl*_LPosU); |
| 219 | break; |
| 220 | case WFIR_BLACKMAN3T67: |
| 221 | _LWc = 0.42323 - 0.49755 * cos(_LPIdl*_LPosU) + |
| 222 | 0.07922 * cos(2.0*_LPIdl*_LPosU); |
| 223 | break; |
| 224 | case WFIR_BLACKMAN4T92: |
| 225 | _LWc = 0.35875 - 0.48829 * cos(_LPIdl*_LPosU) + |
| 226 | 0.14128 * cos(2.0*_LPIdl*_LPosU) - |
| 227 | 0.01168 * cos(3.0*_LPIdl*_LPosU); |
| 228 | break; |
| 229 | case WFIR_BLACKMAN4T74: |
| 230 | _LWc = 0.40217 - 0.49703 * cos(_LPIdl*_LPosU) + |
| 231 | 0.09392 * cos(2.0*_LPIdl*_LPosU) - |
| 232 | 0.00183 * cos(3.0*_LPIdl*_LPosU); |
| 233 | break; |
| 234 | case WFIR_KAISER4T: |
| 235 | _LWc = 0.40243 - 0.49804 * cos(_LPIdl*_LPosU) + |
| 236 | 0.09831 * cos(2.0*_LPIdl*_LPosU) - |
| 237 | 0.00122 * cos(3.0*_LPIdl*_LPosU); |
| 238 | break; |
| 239 | default: |
| 240 | _LWc = 1.0; |
| 241 | break; |
| 242 | } |
| 243 | _LPos *= M_zPI; |
| 244 | _LSi = sin(_PCut*_LPos)/_LPos; |
| 245 | } |
| 246 | return (float)(_LWc*_LSi); |
| 247 | } |
| 248 | static signed short lut[WFIR_LUTLEN*WFIR_WIDTH]; |
| 249 | }; |
| 250 | |
| 251 | signed short CzWINDOWEDFIR::lut[WFIR_LUTLEN*WFIR_WIDTH]; |
| 252 | |
| 253 | CzWINDOWEDFIR::CzWINDOWEDFIR() |
| 254 | { |
| 255 | int _LPcl; |
| 256 | float _LPcllen = (float)(1L<<WFIR_FRACBITS); // number of precalculated lines for 0..1 (-1..0) |
| 257 | float _LNorm = 1.0f / (float)(2.0f * _LPcllen); |
| 258 | float _LCut = WFIR_CUTOFF; |
| 259 | float _LScale = (float)WFIR_QUANTSCALE; |
| 260 | for( _LPcl=0;_LPcl<WFIR_LUTLEN;_LPcl++ ) |
| 261 | { |
| 262 | float _LGain,_LCoefs[WFIR_WIDTH]; |
| 263 | float _LOfs = ((float)_LPcl-_LPcllen)*_LNorm; |
| 264 | int _LCc,_LIdx = _LPcl<<WFIR_LOG2WIDTH; |
| 265 | for( _LCc=0,_LGain=0.0f;_LCc<WFIR_WIDTH;_LCc++ ) |
| 266 | { _LGain += (_LCoefs[_LCc] = coef( _LCc, _LOfs, _LCut, WFIR_WIDTH, WFIR_TYPE )); |
| 267 | } |
| 268 | _LGain = 1.0f/_LGain; |
| 269 | for( _LCc=0;_LCc<WFIR_WIDTH;_LCc++ ) |
| 270 | { float _LCoef = (float)floor( 0.5 + _LScale*_LCoefs[_LCc]*_LGain ); |
| 271 | lut[_LIdx+_LCc] = (signed short)( (_LCoef<-_LScale)?-_LScale:((_LCoef>_LScale)?_LScale:_LCoef) ); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | CzWINDOWEDFIR::~CzWINDOWEDFIR() |
| 277 | { // nothing todo |
| 278 | } |
| 279 | |
| 280 | CzWINDOWEDFIR sfir; |
| 281 | |
| 282 | // ---------------------------------------------------------------------------- |
| 283 | // MIXING MACROS |
| 284 | // ---------------------------------------------------------------------------- |
| 285 | #define SNDMIX_BEGINSAMPLELOOP8\ |
| 286 | MODCHANNEL * const pChn = pChannel;\ |
| 287 | nPos = pChn->nPosLo;\ |
| 288 | const signed char *p = (signed char *)(pChn->pCurrentSample+pChn->nPos);\ |
| 289 | if (pChn->dwFlags & CHN_STEREO) p += pChn->nPos;\ |
| 290 | int *pvol = pbuffer;\ |
| 291 | do { |
| 292 | |
| 293 | #define SNDMIX_BEGINSAMPLELOOP16\ |
| 294 | MODCHANNEL * const pChn = pChannel;\ |
| 295 | nPos = pChn->nPosLo;\ |
| 296 | const signed short *p = (signed short *)(pChn->pCurrentSample+(pChn->nPos*2));\ |
| 297 | if (pChn->dwFlags & CHN_STEREO) p += pChn->nPos;\ |
| 298 | int *pvol = pbuffer;\ |
| 299 | do { |
| 300 | |
| 301 | #define SNDMIX_ENDSAMPLELOOP\ |
| 302 | nPos += pChn->nInc;\ |
| 303 | } while (pvol < pbufmax);\ |
| 304 | pChn->nPos += nPos >> 16;\ |
| 305 | pChn->nPosLo = nPos & 0xFFFF; |
| 306 | |
| 307 | #define SNDMIX_ENDSAMPLELOOP8 SNDMIX_ENDSAMPLELOOP |
| 308 | #define SNDMIX_ENDSAMPLELOOP16 SNDMIX_ENDSAMPLELOOP |
| 309 | |
| 310 | ////////////////////////////////////////////////////////////////////////////// |
| 311 | // Mono |
| 312 | |
| 313 | // No interpolation |
| 314 | #define SNDMIX_GETMONOVOL8NOIDO\ |
| 315 | int vol = p[nPos >> 16] << 8; |
| 316 | |
| 317 | #define SNDMIX_GETMONOVOL16NOIDO\ |
| 318 | int vol = p[nPos >> 16]; |
| 319 | |
| 320 | // Linear Interpolation |
| 321 | #define SNDMIX_GETMONOVOL8LINEAR\ |
| 322 | int poshi = nPos >> 16;\ |
| 323 | int poslo = (nPos >> 8) & 0xFF;\ |
| 324 | int srcvol = p[poshi];\ |
| 325 | int destvol = p[poshi+1];\ |
| 326 | int vol = (srcvol<<8) + ((int)(poslo * (destvol - srcvol))); |
| 327 | |
| 328 | #define SNDMIX_GETMONOVOL16LINEAR\ |
| 329 | int poshi = nPos >> 16;\ |
| 330 | int poslo = (nPos >> 8) & 0xFF;\ |
| 331 | int srcvol = p[poshi];\ |
| 332 | int destvol = p[poshi+1];\ |
| 333 | int vol = srcvol + ((int)(poslo * (destvol - srcvol)) >> 8); |
| 334 | |
| 335 | // spline interpolation (2 guard bits should be enough???) |
| 336 | #define SPLINE_FRACSHIFT ((16-SPLINE_FRACBITS)-2) |
| 337 | #define SPLINE_FRACMASK (((1L<<(16-SPLINE_FRACSHIFT))-1)&~3) |
| 338 | |
| 339 | #define SNDMIX_GETMONOVOL8SPLINE \ |
| 340 | int poshi = nPos >> 16; \ |
| 341 | int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \ |
| 342 | int vol = (CzCUBICSPLINE::lut[poslo ]*(int)p[poshi-1] + \ |
| 343 | CzCUBICSPLINE::lut[poslo+1]*(int)p[poshi ] + \ |
| 344 | CzCUBICSPLINE::lut[poslo+3]*(int)p[poshi+2] + \ |
| 345 | CzCUBICSPLINE::lut[poslo+2]*(int)p[poshi+1]) >> SPLINE_8SHIFT; |
| 346 | |
| 347 | #define SNDMIX_GETMONOVOL16SPLINE \ |
| 348 | int poshi = nPos >> 16; \ |
| 349 | int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \ |
| 350 | int vol = (CzCUBICSPLINE::lut[poslo ]*(int)p[poshi-1] + \ |
| 351 | CzCUBICSPLINE::lut[poslo+1]*(int)p[poshi ] + \ |
| 352 | CzCUBICSPLINE::lut[poslo+3]*(int)p[poshi+2] + \ |
| 353 | CzCUBICSPLINE::lut[poslo+2]*(int)p[poshi+1]) >> SPLINE_16SHIFT; |
| 354 | |
| 355 | |
| 356 | // fir interpolation |
| 357 | #define WFIR_FRACSHIFT (16-(WFIR_FRACBITS+1+WFIR_LOG2WIDTH)) |
| 358 | #define WFIR_FRACMASK ((((1L<<(17-WFIR_FRACSHIFT))-1)&~((1L<<WFIR_LOG2WIDTH)-1))) |
| 359 | #define WFIR_FRACHALVE (1L<<(16-(WFIR_FRACBITS+2))) |
| 360 | |
| 361 | #define SNDMIX_GETMONOVOL8FIRFILTER \ |
| 362 | int poshi = nPos >> 16;\ |
| 363 | int poslo = (nPos & 0xFFFF);\ |
| 364 | int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \ |
| 365 | int vol = (CzWINDOWEDFIR::lut[firidx+0]*(int)p[poshi+1-4]); \ |
| 366 | vol += (CzWINDOWEDFIR::lut[firidx+1]*(int)p[poshi+2-4]); \ |
| 367 | vol += (CzWINDOWEDFIR::lut[firidx+2]*(int)p[poshi+3-4]); \ |
| 368 | vol += (CzWINDOWEDFIR::lut[firidx+3]*(int)p[poshi+4-4]); \ |
| 369 | vol += (CzWINDOWEDFIR::lut[firidx+4]*(int)p[poshi+5-4]); \ |
| 370 | vol += (CzWINDOWEDFIR::lut[firidx+5]*(int)p[poshi+6-4]); \ |
| 371 | vol += (CzWINDOWEDFIR::lut[firidx+6]*(int)p[poshi+7-4]); \ |
| 372 | vol += (CzWINDOWEDFIR::lut[firidx+7]*(int)p[poshi+8-4]); \ |
| 373 | vol >>= WFIR_8SHIFT; |
| 374 | |
| 375 | #define SNDMIX_GETMONOVOL16FIRFILTER \ |
| 376 | int poshi = nPos >> 16;\ |
| 377 | int poslo = (nPos & 0xFFFF);\ |
| 378 | int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \ |
| 379 | int vol1 = (CzWINDOWEDFIR::lut[firidx+0]*(int)p[poshi+1-4]); \ |
| 380 | vol1 += (CzWINDOWEDFIR::lut[firidx+1]*(int)p[poshi+2-4]); \ |
| 381 | vol1 += (CzWINDOWEDFIR::lut[firidx+2]*(int)p[poshi+3-4]); \ |
| 382 | vol1 += (CzWINDOWEDFIR::lut[firidx+3]*(int)p[poshi+4-4]); \ |
| 383 | int vol2 = (CzWINDOWEDFIR::lut[firidx+4]*(int)p[poshi+5-4]); \ |
| 384 | vol2 += (CzWINDOWEDFIR::lut[firidx+5]*(int)p[poshi+6-4]); \ |
| 385 | vol2 += (CzWINDOWEDFIR::lut[firidx+6]*(int)p[poshi+7-4]); \ |
| 386 | vol2 += (CzWINDOWEDFIR::lut[firidx+7]*(int)p[poshi+8-4]); \ |
| 387 | int vol = ((vol1>>1)+(vol2>>1)) >> (WFIR_16BITSHIFT-1); |
| 388 | |
| 389 | ///////////////////////////////////////////////////////////////////////////// |
| 390 | // Stereo |
| 391 | |
| 392 | // No interpolation |
| 393 | #define SNDMIX_GETSTEREOVOL8NOIDO\ |
| 394 | int vol_l = p[(nPos>>16)*2] << 8;\ |
| 395 | int vol_r = p[(nPos>>16)*2+1] << 8; |
| 396 | |
| 397 | #define SNDMIX_GETSTEREOVOL16NOIDO\ |
| 398 | int vol_l = p[(nPos>>16)*2];\ |
| 399 | int vol_r = p[(nPos>>16)*2+1]; |
| 400 | |
| 401 | // Linear Interpolation |
| 402 | #define SNDMIX_GETSTEREOVOL8LINEAR\ |
| 403 | int poshi = nPos >> 16;\ |
| 404 | int poslo = (nPos >> 8) & 0xFF;\ |
| 405 | int srcvol_l = p[poshi*2];\ |
| 406 | int vol_l = (srcvol_l<<8) + ((int)(poslo * (p[poshi*2+2] - srcvol_l)));\ |
| 407 | int srcvol_r = p[poshi*2+1];\ |
| 408 | int vol_r = (srcvol_r<<8) + ((int)(poslo * (p[poshi*2+3] - srcvol_r))); |
| 409 | |
| 410 | #define SNDMIX_GETSTEREOVOL16LINEAR\ |
| 411 | int poshi = nPos >> 16;\ |
| 412 | int poslo = (nPos >> 8) & 0xFF;\ |
| 413 | int srcvol_l = p[poshi*2];\ |
| 414 | int vol_l = srcvol_l + ((int)(poslo * (p[poshi*2+2] - srcvol_l)) >> 8);\ |
| 415 | int srcvol_r = p[poshi*2+1];\ |
| 416 | int vol_r = srcvol_r + ((int)(poslo * (p[poshi*2+3] - srcvol_r)) >> 8);\ |
| 417 | |
| 418 | // Spline Interpolation |
| 419 | #define SNDMIX_GETSTEREOVOL8SPLINE \ |
| 420 | int poshi = nPos >> 16; \ |
| 421 | int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \ |
| 422 | int vol_l = (CzCUBICSPLINE::lut[poslo ]*(int)p[(poshi-1)*2 ] + \ |
| 423 | CzCUBICSPLINE::lut[poslo+1]*(int)p[(poshi )*2 ] + \ |
| 424 | CzCUBICSPLINE::lut[poslo+2]*(int)p[(poshi+1)*2 ] + \ |
| 425 | CzCUBICSPLINE::lut[poslo+3]*(int)p[(poshi+2)*2 ]) >> SPLINE_8SHIFT; \ |
| 426 | int vol_r = (CzCUBICSPLINE::lut[poslo ]*(int)p[(poshi-1)*2+1] + \ |
| 427 | CzCUBICSPLINE::lut[poslo+1]*(int)p[(poshi )*2+1] + \ |
| 428 | CzCUBICSPLINE::lut[poslo+2]*(int)p[(poshi+1)*2+1] + \ |
| 429 | CzCUBICSPLINE::lut[poslo+3]*(int)p[(poshi+2)*2+1]) >> SPLINE_8SHIFT; |
| 430 | |
| 431 | #define SNDMIX_GETSTEREOVOL16SPLINE \ |
| 432 | int poshi = nPos >> 16; \ |
| 433 | int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \ |
| 434 | int vol_l = (CzCUBICSPLINE::lut[poslo ]*(int)p[(poshi-1)*2 ] + \ |
| 435 | CzCUBICSPLINE::lut[poslo+1]*(int)p[(poshi )*2 ] + \ |
| 436 | CzCUBICSPLINE::lut[poslo+2]*(int)p[(poshi+1)*2 ] + \ |
| 437 | CzCUBICSPLINE::lut[poslo+3]*(int)p[(poshi+2)*2 ]) >> SPLINE_16SHIFT; \ |
| 438 | int vol_r = (CzCUBICSPLINE::lut[poslo ]*(int)p[(poshi-1)*2+1] + \ |
| 439 | CzCUBICSPLINE::lut[poslo+1]*(int)p[(poshi )*2+1] + \ |
| 440 | CzCUBICSPLINE::lut[poslo+2]*(int)p[(poshi+1)*2+1] + \ |
| 441 | CzCUBICSPLINE::lut[poslo+3]*(int)p[(poshi+2)*2+1]) >> SPLINE_16SHIFT; |
| 442 | |
| 443 | // fir interpolation |
| 444 | #define SNDMIX_GETSTEREOVOL8FIRFILTER \ |
| 445 | int poshi = nPos >> 16;\ |
| 446 | int poslo = (nPos & 0xFFFF);\ |
| 447 | int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \ |
| 448 | int vol_l = (CzWINDOWEDFIR::lut[firidx+0]*(int)p[(poshi+1-4)*2 ]); \ |
| 449 | vol_l += (CzWINDOWEDFIR::lut[firidx+1]*(int)p[(poshi+2-4)*2 ]); \ |
| 450 | vol_l += (CzWINDOWEDFIR::lut[firidx+2]*(int)p[(poshi+3-4)*2 ]); \ |
| 451 | vol_l += (CzWINDOWEDFIR::lut[firidx+3]*(int)p[(poshi+4-4)*2 ]); \ |
| 452 | vol_l += (CzWINDOWEDFIR::lut[firidx+4]*(int)p[(poshi+5-4)*2 ]); \ |
| 453 | vol_l += (CzWINDOWEDFIR::lut[firidx+5]*(int)p[(poshi+6-4)*2 ]); \ |
| 454 | vol_l += (CzWINDOWEDFIR::lut[firidx+6]*(int)p[(poshi+7-4)*2 ]); \ |
| 455 | vol_l += (CzWINDOWEDFIR::lut[firidx+7]*(int)p[(poshi+8-4)*2 ]); \ |
| 456 | vol_l >>= WFIR_8SHIFT; \ |
| 457 | int vol_r = (CzWINDOWEDFIR::lut[firidx+0]*(int)p[(poshi+1-4)*2+1]); \ |
| 458 | vol_r += (CzWINDOWEDFIR::lut[firidx+1]*(int)p[(poshi+2-4)*2+1]); \ |
| 459 | vol_r += (CzWINDOWEDFIR::lut[firidx+2]*(int)p[(poshi+3-4)*2+1]); \ |
| 460 | vol_r += (CzWINDOWEDFIR::lut[firidx+3]*(int)p[(poshi+4-4)*2+1]); \ |
| 461 | vol_r += (CzWINDOWEDFIR::lut[firidx+4]*(int)p[(poshi+5-4)*2+1]); \ |
| 462 | vol_r += (CzWINDOWEDFIR::lut[firidx+5]*(int)p[(poshi+6-4)*2+1]); \ |
| 463 | vol_r += (CzWINDOWEDFIR::lut[firidx+6]*(int)p[(poshi+7-4)*2+1]); \ |
| 464 | vol_r += (CzWINDOWEDFIR::lut[firidx+7]*(int)p[(poshi+8-4)*2+1]); \ |
| 465 | vol_r >>= WFIR_8SHIFT; |
| 466 | |
| 467 | #define SNDMIX_GETSTEREOVOL16FIRFILTER \ |
| 468 | int poshi = nPos >> 16;\ |
| 469 | int poslo = (nPos & 0xFFFF);\ |
| 470 | int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \ |
| 471 | int vol1_l = (CzWINDOWEDFIR::lut[firidx+0]*(int)p[(poshi+1-4)*2 ]); \ |
| 472 | vol1_l += (CzWINDOWEDFIR::lut[firidx+1]*(int)p[(poshi+2-4)*2 ]); \ |
| 473 | vol1_l += (CzWINDOWEDFIR::lut[firidx+2]*(int)p[(poshi+3-4)*2 ]); \ |
| 474 | vol1_l += (CzWINDOWEDFIR::lut[firidx+3]*(int)p[(poshi+4-4)*2 ]); \ |
| 475 | int vol2_l = (CzWINDOWEDFIR::lut[firidx+4]*(int)p[(poshi+5-4)*2 ]); \ |
| 476 | vol2_l += (CzWINDOWEDFIR::lut[firidx+5]*(int)p[(poshi+6-4)*2 ]); \ |
| 477 | vol2_l += (CzWINDOWEDFIR::lut[firidx+6]*(int)p[(poshi+7-4)*2 ]); \ |
| 478 | vol2_l += (CzWINDOWEDFIR::lut[firidx+7]*(int)p[(poshi+8-4)*2 ]); \ |
| 479 | int vol_l = ((vol1_l>>1)+(vol2_l>>1)) >> (WFIR_16BITSHIFT-1); \ |
| 480 | int vol1_r = (CzWINDOWEDFIR::lut[firidx+0]*(int)p[(poshi+1-4)*2+1]); \ |
| 481 | vol1_r += (CzWINDOWEDFIR::lut[firidx+1]*(int)p[(poshi+2-4)*2+1]); \ |
| 482 | vol1_r += (CzWINDOWEDFIR::lut[firidx+2]*(int)p[(poshi+3-4)*2+1]); \ |
| 483 | vol1_r += (CzWINDOWEDFIR::lut[firidx+3]*(int)p[(poshi+4-4)*2+1]); \ |
| 484 | int vol2_r = (CzWINDOWEDFIR::lut[firidx+4]*(int)p[(poshi+5-4)*2+1]); \ |
| 485 | vol2_r += (CzWINDOWEDFIR::lut[firidx+5]*(int)p[(poshi+6-4)*2+1]); \ |
| 486 | vol2_r += (CzWINDOWEDFIR::lut[firidx+6]*(int)p[(poshi+7-4)*2+1]); \ |
| 487 | vol2_r += (CzWINDOWEDFIR::lut[firidx+7]*(int)p[(poshi+8-4)*2+1]); \ |
| 488 | int vol_r = ((vol1_r>>1)+(vol2_r>>1)) >> (WFIR_16BITSHIFT-1); |
| 489 | |
| 490 | ///////////////////////////////////////////////////////////////////////////// |
| 491 | |
| 492 | #define SNDMIX_STOREMONOVOL\ |
| 493 | pvol[0] += vol * pChn->nRightVol;\ |
| 494 | pvol[1] += vol * pChn->nLeftVol;\ |
| 495 | pvol += 2; |
| 496 | |
| 497 | #define SNDMIX_STORESTEREOVOL\ |
| 498 | pvol[0] += vol_l * pChn->nRightVol;\ |
| 499 | pvol[1] += vol_r * pChn->nLeftVol;\ |
| 500 | pvol += 2; |
| 501 | |
| 502 | #define SNDMIX_STOREFASTMONOVOL\ |
| 503 | int v = vol * pChn->nRightVol;\ |
| 504 | pvol[0] += v;\ |
| 505 | pvol[1] += v;\ |
| 506 | pvol += 2; |
| 507 | |
| 508 | #define SNDMIX_RAMPMONOVOL\ |
| 509 | nRampLeftVol += pChn->nLeftRamp;\ |
| 510 | nRampRightVol += pChn->nRightRamp;\ |
| 511 | pvol[0] += vol * (nRampRightVol >> VOLUMERAMPPRECISION);\ |
| 512 | pvol[1] += vol * (nRampLeftVol >> VOLUMERAMPPRECISION);\ |
| 513 | pvol += 2; |
| 514 | |
| 515 | #define SNDMIX_RAMPFASTMONOVOL\ |
| 516 | nRampRightVol += pChn->nRightRamp;\ |
| 517 | int fastvol = vol * (nRampRightVol >> VOLUMERAMPPRECISION);\ |
| 518 | pvol[0] += fastvol;\ |
| 519 | pvol[1] += fastvol;\ |
| 520 | pvol += 2; |
| 521 | |
| 522 | #define SNDMIX_RAMPSTEREOVOL\ |
| 523 | nRampLeftVol += pChn->nLeftRamp;\ |
| 524 | nRampRightVol += pChn->nRightRamp;\ |
| 525 | pvol[0] += vol_l * (nRampRightVol >> VOLUMERAMPPRECISION);\ |
| 526 | pvol[1] += vol_r * (nRampLeftVol >> VOLUMERAMPPRECISION);\ |
| 527 | pvol += 2; |
| 528 | |
| 529 | |
| 530 | /////////////////////////////////////////////////// |
| 531 | // Resonant Filters |
| 532 | |
| 533 | // Mono |
| 534 | #define MIX_BEGIN_FILTER\ |
| 535 | int fy1 = pChannel->nFilter_Y1;\ |
| 536 | int fy2 = pChannel->nFilter_Y2;\ |
| 537 | |
| 538 | #define MIX_END_FILTER\ |
| 539 | pChannel->nFilter_Y1 = fy1;\ |
| 540 | pChannel->nFilter_Y2 = fy2; |
| 541 | |
| 542 | #define SNDMIX_PROCESSFILTER\ |
| 543 | vol = (vol * pChn->nFilter_A0 + fy1 * pChn->nFilter_B0 + fy2 * pChn->nFilter_B1 + 4096) >> 13;\ |
| 544 | fy2 = fy1;\ |
| 545 | fy1 = vol;\ |
| 546 | |
| 547 | // Stereo |
| 548 | #define MIX_BEGIN_STEREO_FILTER\ |
| 549 | int fy1 = pChannel->nFilter_Y1;\ |
| 550 | int fy2 = pChannel->nFilter_Y2;\ |
| 551 | int fy3 = pChannel->nFilter_Y3;\ |
| 552 | int fy4 = pChannel->nFilter_Y4;\ |
| 553 | |
| 554 | #define MIX_END_STEREO_FILTER\ |
| 555 | pChannel->nFilter_Y1 = fy1;\ |
| 556 | pChannel->nFilter_Y2 = fy2;\ |
| 557 | pChannel->nFilter_Y3 = fy3;\ |
| 558 | pChannel->nFilter_Y4 = fy4;\ |
| 559 | |
| 560 | #define SNDMIX_PROCESSSTEREOFILTER\ |
| 561 | vol_l = (vol_l * pChn->nFilter_A0 + fy1 * pChn->nFilter_B0 + fy2 * pChn->nFilter_B1 + 4096) >> 13;\ |
| 562 | vol_r = (vol_r * pChn->nFilter_A0 + fy3 * pChn->nFilter_B0 + fy4 * pChn->nFilter_B1 + 4096) >> 13;\ |
| 563 | fy2 = fy1; fy1 = vol_l;\ |
| 564 | fy4 = fy3; fy3 = vol_r;\ |
| 565 | |
| 566 | ////////////////////////////////////////////////////////// |
| 567 | // Interfaces |
| 568 | |
| 569 | typedef VOID (MPPASMCALL * LPMIXINTERFACE)(MODCHANNEL *, int *, int *); |
| 570 | |
| 571 | #define BEGIN_MIX_INTERFACE(func)\ |
| 572 | VOID MPPASMCALL func(MODCHANNEL *pChannel, int *pbuffer, int *pbufmax)\ |
| 573 | {\ |
| 574 | LONG nPos; |
| 575 | |
| 576 | #define END_MIX_INTERFACE()\ |
| 577 | SNDMIX_ENDSAMPLELOOP\ |
| 578 | } |
| 579 | |
| 580 | // Volume Ramps |
| 581 | #define BEGIN_RAMPMIX_INTERFACE(func)\ |
| 582 | BEGIN_MIX_INTERFACE(func)\ |
| 583 | LONG nRampRightVol = pChannel->nRampRightVol;\ |
| 584 | LONG nRampLeftVol = pChannel->nRampLeftVol; |
| 585 | |
| 586 | #define END_RAMPMIX_INTERFACE()\ |
| 587 | SNDMIX_ENDSAMPLELOOP\ |
| 588 | pChannel->nRampRightVol = nRampRightVol;\ |
| 589 | pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\ |
| 590 | pChannel->nRampLeftVol = nRampLeftVol;\ |
| 591 | pChannel->nLeftVol = nRampLeftVol >> VOLUMERAMPPRECISION;\ |
| 592 | } |
| 593 | |
| 594 | #define BEGIN_FASTRAMPMIX_INTERFACE(func)\ |
| 595 | BEGIN_MIX_INTERFACE(func)\ |
| 596 | LONG nRampRightVol = pChannel->nRampRightVol; |
| 597 | |
| 598 | #define END_FASTRAMPMIX_INTERFACE()\ |
| 599 | SNDMIX_ENDSAMPLELOOP\ |
| 600 | pChannel->nRampRightVol = nRampRightVol;\ |
| 601 | pChannel->nRampLeftVol = nRampRightVol;\ |
| 602 | pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\ |
| 603 | pChannel->nLeftVol = pChannel->nRightVol;\ |
| 604 | } |
| 605 | |
| 606 | |
| 607 | // Mono Resonant Filters |
| 608 | #define BEGIN_MIX_FLT_INTERFACE(func)\ |
| 609 | BEGIN_MIX_INTERFACE(func)\ |
| 610 | MIX_BEGIN_FILTER |
| 611 | |
| 612 | |
| 613 | #define END_MIX_FLT_INTERFACE()\ |
| 614 | SNDMIX_ENDSAMPLELOOP\ |
| 615 | MIX_END_FILTER\ |
| 616 | } |
| 617 | |
| 618 | #define BEGIN_RAMPMIX_FLT_INTERFACE(func)\ |
| 619 | BEGIN_MIX_INTERFACE(func)\ |
| 620 | LONG nRampRightVol = pChannel->nRampRightVol;\ |
| 621 | LONG nRampLeftVol = pChannel->nRampLeftVol;\ |
| 622 | MIX_BEGIN_FILTER |
| 623 | |
| 624 | #define END_RAMPMIX_FLT_INTERFACE()\ |
| 625 | SNDMIX_ENDSAMPLELOOP\ |
| 626 | MIX_END_FILTER\ |
| 627 | pChannel->nRampRightVol = nRampRightVol;\ |
| 628 | pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\ |
| 629 | pChannel->nRampLeftVol = nRampLeftVol;\ |
| 630 | pChannel->nLeftVol = nRampLeftVol >> VOLUMERAMPPRECISION;\ |
| 631 | } |
| 632 | |
| 633 | // Stereo Resonant Filters |
| 634 | #define BEGIN_MIX_STFLT_INTERFACE(func)\ |
| 635 | BEGIN_MIX_INTERFACE(func)\ |
| 636 | MIX_BEGIN_STEREO_FILTER |
| 637 | |
| 638 | |
| 639 | #define END_MIX_STFLT_INTERFACE()\ |
| 640 | SNDMIX_ENDSAMPLELOOP\ |
| 641 | MIX_END_STEREO_FILTER\ |
| 642 | } |
| 643 | |
| 644 | #define BEGIN_RAMPMIX_STFLT_INTERFACE(func)\ |
| 645 | BEGIN_MIX_INTERFACE(func)\ |
| 646 | LONG nRampRightVol = pChannel->nRampRightVol;\ |
| 647 | LONG nRampLeftVol = pChannel->nRampLeftVol;\ |
| 648 | MIX_BEGIN_STEREO_FILTER |
| 649 | |
| 650 | #define END_RAMPMIX_STFLT_INTERFACE()\ |
| 651 | SNDMIX_ENDSAMPLELOOP\ |
| 652 | MIX_END_STEREO_FILTER\ |
| 653 | pChannel->nRampRightVol = nRampRightVol;\ |
| 654 | pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\ |
| 655 | pChannel->nRampLeftVol = nRampLeftVol;\ |
| 656 | pChannel->nLeftVol = nRampLeftVol >> VOLUMERAMPPRECISION;\ |
| 657 | } |
| 658 | |
| 659 | |
| 660 | ///////////////////////////////////////////////////// |
| 661 | // |
| 662 | |
| 663 | static void MPPASMCALL X86_InitMixBuffer(int *pBuffer, UINT nSamples); |
| 664 | static void MPPASMCALL X86_EndChannelOfs(MODCHANNEL *pChannel, int *pBuffer, UINT nSamples); |
| 665 | void MPPASMCALL X86_StereoFill(int *pBuffer, UINT nSamples, LPLONG lpROfs, LPLONG lpLOfs); |
| 666 | |
| 667 | ///////////////////////////////////////////////////// |
| 668 | // Mono samples functions |
| 669 | |
| 670 | BEGIN_MIX_INTERFACE(Mono8BitMix) |
| 671 | SNDMIX_BEGINSAMPLELOOP8 |
| 672 | SNDMIX_GETMONOVOL8NOIDO |
| 673 | SNDMIX_STOREMONOVOL |
| 674 | END_MIX_INTERFACE() |
| 675 | |
| 676 | BEGIN_MIX_INTERFACE(Mono16BitMix) |
| 677 | SNDMIX_BEGINSAMPLELOOP16 |
| 678 | SNDMIX_GETMONOVOL16NOIDO |
| 679 | SNDMIX_STOREMONOVOL |
| 680 | END_MIX_INTERFACE() |
| 681 | |
| 682 | BEGIN_MIX_INTERFACE(Mono8BitLinearMix) |
| 683 | SNDMIX_BEGINSAMPLELOOP8 |
| 684 | SNDMIX_GETMONOVOL8LINEAR |
| 685 | SNDMIX_STOREMONOVOL |
| 686 | END_MIX_INTERFACE() |
| 687 | |
| 688 | BEGIN_MIX_INTERFACE(Mono16BitLinearMix) |
| 689 | SNDMIX_BEGINSAMPLELOOP16 |
| 690 | SNDMIX_GETMONOVOL16LINEAR |
| 691 | SNDMIX_STOREMONOVOL |
| 692 | END_MIX_INTERFACE() |
| 693 | |
| 694 | BEGIN_MIX_INTERFACE(Mono8BitSplineMix) |
| 695 | SNDMIX_BEGINSAMPLELOOP8 |
| 696 | SNDMIX_GETMONOVOL8SPLINE |
| 697 | SNDMIX_STOREMONOVOL |
| 698 | END_MIX_INTERFACE() |
| 699 | |
| 700 | BEGIN_MIX_INTERFACE(Mono16BitSplineMix) |
| 701 | SNDMIX_BEGINSAMPLELOOP16 |
| 702 | SNDMIX_GETMONOVOL16SPLINE |
| 703 | SNDMIX_STOREMONOVOL |
| 704 | END_MIX_INTERFACE() |
| 705 | |
| 706 | BEGIN_MIX_INTERFACE(Mono8BitFirFilterMix) |
| 707 | SNDMIX_BEGINSAMPLELOOP8 |
| 708 | SNDMIX_GETMONOVOL8FIRFILTER |
| 709 | SNDMIX_STOREMONOVOL |
| 710 | END_MIX_INTERFACE() |
| 711 | |
| 712 | BEGIN_MIX_INTERFACE(Mono16BitFirFilterMix) |
| 713 | SNDMIX_BEGINSAMPLELOOP16 |
| 714 | SNDMIX_GETMONOVOL16FIRFILTER |
| 715 | SNDMIX_STOREMONOVOL |
| 716 | END_MIX_INTERFACE() |
| 717 | |
| 718 | |
| 719 | // Volume Ramps |
| 720 | BEGIN_RAMPMIX_INTERFACE(Mono8BitRampMix) |
| 721 | SNDMIX_BEGINSAMPLELOOP8 |
| 722 | SNDMIX_GETMONOVOL8NOIDO |
| 723 | SNDMIX_RAMPMONOVOL |
| 724 | END_RAMPMIX_INTERFACE() |
| 725 | |
| 726 | BEGIN_RAMPMIX_INTERFACE(Mono16BitRampMix) |
| 727 | SNDMIX_BEGINSAMPLELOOP16 |
| 728 | SNDMIX_GETMONOVOL16NOIDO |
| 729 | SNDMIX_RAMPMONOVOL |
| 730 | END_RAMPMIX_INTERFACE() |
| 731 | |
| 732 | BEGIN_RAMPMIX_INTERFACE(Mono8BitLinearRampMix) |
| 733 | SNDMIX_BEGINSAMPLELOOP8 |
| 734 | SNDMIX_GETMONOVOL8LINEAR |
| 735 | SNDMIX_RAMPMONOVOL |
| 736 | END_RAMPMIX_INTERFACE() |
| 737 | |
| 738 | BEGIN_RAMPMIX_INTERFACE(Mono16BitLinearRampMix) |
| 739 | SNDMIX_BEGINSAMPLELOOP16 |
| 740 | SNDMIX_GETMONOVOL16LINEAR |
| 741 | SNDMIX_RAMPMONOVOL |
| 742 | END_RAMPMIX_INTERFACE() |
| 743 | |
| 744 | BEGIN_RAMPMIX_INTERFACE(Mono8BitSplineRampMix) |
| 745 | SNDMIX_BEGINSAMPLELOOP8 |
| 746 | SNDMIX_GETMONOVOL8SPLINE |
| 747 | SNDMIX_RAMPMONOVOL |
| 748 | END_RAMPMIX_INTERFACE() |
| 749 | |
| 750 | BEGIN_RAMPMIX_INTERFACE(Mono16BitSplineRampMix) |
| 751 | SNDMIX_BEGINSAMPLELOOP16 |
| 752 | SNDMIX_GETMONOVOL16SPLINE |
| 753 | SNDMIX_RAMPMONOVOL |
| 754 | END_RAMPMIX_INTERFACE() |
| 755 | |
| 756 | BEGIN_RAMPMIX_INTERFACE(Mono8BitFirFilterRampMix) |
| 757 | SNDMIX_BEGINSAMPLELOOP8 |
| 758 | SNDMIX_GETMONOVOL8FIRFILTER |
| 759 | SNDMIX_RAMPMONOVOL |
| 760 | END_RAMPMIX_INTERFACE() |
| 761 | |
| 762 | BEGIN_RAMPMIX_INTERFACE(Mono16BitFirFilterRampMix) |
| 763 | SNDMIX_BEGINSAMPLELOOP16 |
| 764 | SNDMIX_GETMONOVOL16FIRFILTER |
| 765 | SNDMIX_RAMPMONOVOL |
| 766 | END_RAMPMIX_INTERFACE() |
| 767 | |
| 768 | |
| 769 | ////////////////////////////////////////////////////// |
| 770 | // Fast mono mix for leftvol=rightvol (1 less imul) |
| 771 | |
| 772 | BEGIN_MIX_INTERFACE(FastMono8BitMix) |
| 773 | SNDMIX_BEGINSAMPLELOOP8 |
| 774 | SNDMIX_GETMONOVOL8NOIDO |
| 775 | SNDMIX_STOREFASTMONOVOL |
| 776 | END_MIX_INTERFACE() |
| 777 | |
| 778 | BEGIN_MIX_INTERFACE(FastMono16BitMix) |
| 779 | SNDMIX_BEGINSAMPLELOOP16 |
| 780 | SNDMIX_GETMONOVOL16NOIDO |
| 781 | SNDMIX_STOREFASTMONOVOL |
| 782 | END_MIX_INTERFACE() |
| 783 | |
| 784 | BEGIN_MIX_INTERFACE(FastMono8BitLinearMix) |
| 785 | SNDMIX_BEGINSAMPLELOOP8 |
| 786 | SNDMIX_GETMONOVOL8LINEAR |
| 787 | SNDMIX_STOREFASTMONOVOL |
| 788 | END_MIX_INTERFACE() |
| 789 | |
| 790 | BEGIN_MIX_INTERFACE(FastMono16BitLinearMix) |
| 791 | SNDMIX_BEGINSAMPLELOOP16 |
| 792 | SNDMIX_GETMONOVOL16LINEAR |
| 793 | SNDMIX_STOREFASTMONOVOL |
| 794 | END_MIX_INTERFACE() |
| 795 | |
| 796 | BEGIN_MIX_INTERFACE(FastMono8BitSplineMix) |
| 797 | SNDMIX_BEGINSAMPLELOOP8 |
| 798 | SNDMIX_GETMONOVOL8SPLINE |
| 799 | SNDMIX_STOREFASTMONOVOL |
| 800 | END_MIX_INTERFACE() |
| 801 | |
| 802 | BEGIN_MIX_INTERFACE(FastMono16BitSplineMix) |
| 803 | SNDMIX_BEGINSAMPLELOOP16 |
| 804 | SNDMIX_GETMONOVOL16SPLINE |
| 805 | SNDMIX_STOREFASTMONOVOL |
| 806 | END_MIX_INTERFACE() |
| 807 | |
| 808 | BEGIN_MIX_INTERFACE(FastMono8BitFirFilterMix) |
| 809 | SNDMIX_BEGINSAMPLELOOP8 |
| 810 | SNDMIX_GETMONOVOL8FIRFILTER |
| 811 | SNDMIX_STOREFASTMONOVOL |
| 812 | END_MIX_INTERFACE() |
| 813 | |
| 814 | BEGIN_MIX_INTERFACE(FastMono16BitFirFilterMix) |
| 815 | SNDMIX_BEGINSAMPLELOOP16 |
| 816 | SNDMIX_GETMONOVOL16FIRFILTER |
| 817 | SNDMIX_STOREFASTMONOVOL |
| 818 | END_MIX_INTERFACE() |
| 819 | |
| 820 | |
| 821 | // Fast Ramps |
| 822 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitRampMix) |
| 823 | SNDMIX_BEGINSAMPLELOOP8 |
| 824 | SNDMIX_GETMONOVOL8NOIDO |
| 825 | SNDMIX_RAMPFASTMONOVOL |
| 826 | END_FASTRAMPMIX_INTERFACE() |
| 827 | |
| 828 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitRampMix) |
| 829 | SNDMIX_BEGINSAMPLELOOP16 |
| 830 | SNDMIX_GETMONOVOL16NOIDO |
| 831 | SNDMIX_RAMPFASTMONOVOL |
| 832 | END_FASTRAMPMIX_INTERFACE() |
| 833 | |
| 834 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitLinearRampMix) |
| 835 | SNDMIX_BEGINSAMPLELOOP8 |
| 836 | SNDMIX_GETMONOVOL8LINEAR |
| 837 | SNDMIX_RAMPFASTMONOVOL |
| 838 | END_FASTRAMPMIX_INTERFACE() |
| 839 | |
| 840 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitLinearRampMix) |
| 841 | SNDMIX_BEGINSAMPLELOOP16 |
| 842 | SNDMIX_GETMONOVOL16LINEAR |
| 843 | SNDMIX_RAMPFASTMONOVOL |
| 844 | END_FASTRAMPMIX_INTERFACE() |
| 845 | |
| 846 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitSplineRampMix) |
| 847 | SNDMIX_BEGINSAMPLELOOP8 |
| 848 | SNDMIX_GETMONOVOL8SPLINE |
| 849 | SNDMIX_RAMPFASTMONOVOL |
| 850 | END_FASTRAMPMIX_INTERFACE() |
| 851 | |
| 852 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitSplineRampMix) |
| 853 | SNDMIX_BEGINSAMPLELOOP16 |
| 854 | SNDMIX_GETMONOVOL16SPLINE |
| 855 | SNDMIX_RAMPFASTMONOVOL |
| 856 | END_FASTRAMPMIX_INTERFACE() |
| 857 | |
| 858 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitFirFilterRampMix) |
| 859 | SNDMIX_BEGINSAMPLELOOP8 |
| 860 | SNDMIX_GETMONOVOL8FIRFILTER |
| 861 | SNDMIX_RAMPFASTMONOVOL |
| 862 | END_FASTRAMPMIX_INTERFACE() |
| 863 | |
| 864 | BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitFirFilterRampMix) |
| 865 | SNDMIX_BEGINSAMPLELOOP16 |
| 866 | SNDMIX_GETMONOVOL16FIRFILTER |
| 867 | SNDMIX_RAMPFASTMONOVOL |
| 868 | END_FASTRAMPMIX_INTERFACE() |
| 869 | |
| 870 | |
| 871 | ////////////////////////////////////////////////////// |
| 872 | // Stereo samples |
| 873 | |
| 874 | BEGIN_MIX_INTERFACE(Stereo8BitMix) |
| 875 | SNDMIX_BEGINSAMPLELOOP8 |
| 876 | SNDMIX_GETSTEREOVOL8NOIDO |
| 877 | SNDMIX_STORESTEREOVOL |
| 878 | END_MIX_INTERFACE() |
| 879 | |
| 880 | BEGIN_MIX_INTERFACE(Stereo16BitMix) |
| 881 | SNDMIX_BEGINSAMPLELOOP16 |
| 882 | SNDMIX_GETSTEREOVOL16NOIDO |
| 883 | SNDMIX_STORESTEREOVOL |
| 884 | END_MIX_INTERFACE() |
| 885 | |
| 886 | BEGIN_MIX_INTERFACE(Stereo8BitLinearMix) |
| 887 | SNDMIX_BEGINSAMPLELOOP8 |
| 888 | SNDMIX_GETSTEREOVOL8LINEAR |
| 889 | SNDMIX_STORESTEREOVOL |
| 890 | END_MIX_INTERFACE() |
| 891 | |
| 892 | BEGIN_MIX_INTERFACE(Stereo16BitLinearMix) |
| 893 | SNDMIX_BEGINSAMPLELOOP16 |
| 894 | SNDMIX_GETSTEREOVOL16LINEAR |
| 895 | SNDMIX_STORESTEREOVOL |
| 896 | END_MIX_INTERFACE() |
| 897 | |
| 898 | BEGIN_MIX_INTERFACE(Stereo8BitSplineMix) |
| 899 | SNDMIX_BEGINSAMPLELOOP8 |
| 900 | SNDMIX_GETSTEREOVOL8SPLINE |
| 901 | SNDMIX_STORESTEREOVOL |
| 902 | END_MIX_INTERFACE() |
| 903 | |
| 904 | BEGIN_MIX_INTERFACE(Stereo16BitSplineMix) |
| 905 | SNDMIX_BEGINSAMPLELOOP16 |
| 906 | SNDMIX_GETSTEREOVOL16SPLINE |
| 907 | SNDMIX_STORESTEREOVOL |
| 908 | END_MIX_INTERFACE() |
| 909 | |
| 910 | BEGIN_MIX_INTERFACE(Stereo8BitFirFilterMix) |
| 911 | SNDMIX_BEGINSAMPLELOOP8 |
| 912 | SNDMIX_GETSTEREOVOL8FIRFILTER |
| 913 | SNDMIX_STORESTEREOVOL |
| 914 | END_MIX_INTERFACE() |
| 915 | |
| 916 | BEGIN_MIX_INTERFACE(Stereo16BitFirFilterMix) |
| 917 | SNDMIX_BEGINSAMPLELOOP16 |
| 918 | SNDMIX_GETSTEREOVOL16FIRFILTER |
| 919 | SNDMIX_STORESTEREOVOL |
| 920 | END_MIX_INTERFACE() |
| 921 | |
| 922 | |
| 923 | // Volume Ramps |
| 924 | BEGIN_RAMPMIX_INTERFACE(Stereo8BitRampMix) |
| 925 | SNDMIX_BEGINSAMPLELOOP8 |
| 926 | SNDMIX_GETSTEREOVOL8NOIDO |
| 927 | SNDMIX_RAMPSTEREOVOL |
| 928 | END_RAMPMIX_INTERFACE() |
| 929 | |
| 930 | BEGIN_RAMPMIX_INTERFACE(Stereo16BitRampMix) |
| 931 | SNDMIX_BEGINSAMPLELOOP16 |
| 932 | SNDMIX_GETSTEREOVOL16NOIDO |
| 933 | SNDMIX_RAMPSTEREOVOL |
| 934 | END_RAMPMIX_INTERFACE() |
| 935 | |
| 936 | BEGIN_RAMPMIX_INTERFACE(Stereo8BitLinearRampMix) |
| 937 | SNDMIX_BEGINSAMPLELOOP8 |
| 938 | SNDMIX_GETSTEREOVOL8LINEAR |
| 939 | SNDMIX_RAMPSTEREOVOL |
| 940 | END_RAMPMIX_INTERFACE() |
| 941 | |
| 942 | BEGIN_RAMPMIX_INTERFACE(Stereo16BitLinearRampMix) |
| 943 | SNDMIX_BEGINSAMPLELOOP16 |
| 944 | SNDMIX_GETSTEREOVOL16LINEAR |
| 945 | SNDMIX_RAMPSTEREOVOL |
| 946 | END_RAMPMIX_INTERFACE() |
| 947 | |
| 948 | BEGIN_RAMPMIX_INTERFACE(Stereo8BitSplineRampMix) |
| 949 | SNDMIX_BEGINSAMPLELOOP8 |
| 950 | SNDMIX_GETSTEREOVOL8SPLINE |
| 951 | SNDMIX_RAMPSTEREOVOL |
| 952 | END_RAMPMIX_INTERFACE() |
| 953 | |
| 954 | BEGIN_RAMPMIX_INTERFACE(Stereo16BitSplineRampMix) |
| 955 | SNDMIX_BEGINSAMPLELOOP16 |
| 956 | SNDMIX_GETSTEREOVOL16SPLINE |
| 957 | SNDMIX_RAMPSTEREOVOL |
| 958 | END_RAMPMIX_INTERFACE() |
| 959 | |
| 960 | BEGIN_RAMPMIX_INTERFACE(Stereo8BitFirFilterRampMix) |
| 961 | SNDMIX_BEGINSAMPLELOOP8 |
| 962 | SNDMIX_GETSTEREOVOL8FIRFILTER |
| 963 | SNDMIX_RAMPSTEREOVOL |
| 964 | END_RAMPMIX_INTERFACE() |
| 965 | |
| 966 | BEGIN_RAMPMIX_INTERFACE(Stereo16BitFirFilterRampMix) |
| 967 | SNDMIX_BEGINSAMPLELOOP16 |
| 968 | SNDMIX_GETSTEREOVOL16FIRFILTER |
| 969 | SNDMIX_RAMPSTEREOVOL |
| 970 | END_RAMPMIX_INTERFACE() |
| 971 | |
| 972 | |
| 973 | |
| 974 | ////////////////////////////////////////////////////// |
| 975 | // Resonant Filter Mix |
| 976 | |
| 977 | #ifndef NO_FILTER |
| 978 | |
| 979 | // Mono Filter Mix |
| 980 | BEGIN_MIX_FLT_INTERFACE(FilterMono8BitMix) |
| 981 | SNDMIX_BEGINSAMPLELOOP8 |
| 982 | SNDMIX_GETMONOVOL8NOIDO |
| 983 | SNDMIX_PROCESSFILTER |
| 984 | SNDMIX_STOREMONOVOL |
| 985 | END_MIX_FLT_INTERFACE() |
| 986 | |
| 987 | BEGIN_MIX_FLT_INTERFACE(FilterMono16BitMix) |
| 988 | SNDMIX_BEGINSAMPLELOOP16 |
| 989 | SNDMIX_GETMONOVOL16NOIDO |
| 990 | SNDMIX_PROCESSFILTER |
| 991 | SNDMIX_STOREMONOVOL |
| 992 | END_MIX_FLT_INTERFACE() |
| 993 | |
| 994 | BEGIN_MIX_FLT_INTERFACE(FilterMono8BitLinearMix) |
| 995 | SNDMIX_BEGINSAMPLELOOP8 |
| 996 | SNDMIX_GETMONOVOL8LINEAR |
| 997 | SNDMIX_PROCESSFILTER |
| 998 | SNDMIX_STOREMONOVOL |
| 999 | END_MIX_FLT_INTERFACE() |
| 1000 | |
| 1001 | BEGIN_MIX_FLT_INTERFACE(FilterMono16BitLinearMix) |
| 1002 | SNDMIX_BEGINSAMPLELOOP16 |
| 1003 | SNDMIX_GETMONOVOL16LINEAR |
| 1004 | SNDMIX_PROCESSFILTER |
| 1005 | SNDMIX_STOREMONOVOL |
| 1006 | END_MIX_FLT_INTERFACE() |
| 1007 | |
| 1008 | BEGIN_MIX_FLT_INTERFACE(FilterMono8BitSplineMix) |
| 1009 | SNDMIX_BEGINSAMPLELOOP8 |
| 1010 | SNDMIX_GETMONOVOL8SPLINE |
| 1011 | SNDMIX_PROCESSFILTER |
| 1012 | SNDMIX_STOREMONOVOL |
| 1013 | END_MIX_FLT_INTERFACE() |
| 1014 | |
| 1015 | BEGIN_MIX_FLT_INTERFACE(FilterMono16BitSplineMix) |
| 1016 | SNDMIX_BEGINSAMPLELOOP16 |
| 1017 | SNDMIX_GETMONOVOL16SPLINE |
| 1018 | SNDMIX_PROCESSFILTER |
| 1019 | SNDMIX_STOREMONOVOL |
| 1020 | END_MIX_FLT_INTERFACE() |
| 1021 | |
| 1022 | BEGIN_MIX_FLT_INTERFACE(FilterMono8BitFirFilterMix) |
| 1023 | SNDMIX_BEGINSAMPLELOOP8 |
| 1024 | SNDMIX_GETMONOVOL8FIRFILTER |
| 1025 | SNDMIX_PROCESSFILTER |
| 1026 | SNDMIX_STOREMONOVOL |
| 1027 | END_MIX_FLT_INTERFACE() |
| 1028 | |
| 1029 | BEGIN_MIX_FLT_INTERFACE(FilterMono16BitFirFilterMix) |
| 1030 | SNDMIX_BEGINSAMPLELOOP16 |
| 1031 | SNDMIX_GETMONOVOL16FIRFILTER |
| 1032 | SNDMIX_PROCESSFILTER |
| 1033 | SNDMIX_STOREMONOVOL |
| 1034 | END_MIX_FLT_INTERFACE() |
| 1035 | |
| 1036 | // Filter + Ramp |
| 1037 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitRampMix) |
| 1038 | SNDMIX_BEGINSAMPLELOOP8 |
| 1039 | SNDMIX_GETMONOVOL8NOIDO |
| 1040 | SNDMIX_PROCESSFILTER |
| 1041 | SNDMIX_RAMPMONOVOL |
| 1042 | END_RAMPMIX_FLT_INTERFACE() |
| 1043 | |
| 1044 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitRampMix) |
| 1045 | SNDMIX_BEGINSAMPLELOOP16 |
| 1046 | SNDMIX_GETMONOVOL16NOIDO |
| 1047 | SNDMIX_PROCESSFILTER |
| 1048 | SNDMIX_RAMPMONOVOL |
| 1049 | END_RAMPMIX_FLT_INTERFACE() |
| 1050 | |
| 1051 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitLinearRampMix) |
| 1052 | SNDMIX_BEGINSAMPLELOOP8 |
| 1053 | SNDMIX_GETMONOVOL8LINEAR |
| 1054 | SNDMIX_PROCESSFILTER |
| 1055 | SNDMIX_RAMPMONOVOL |
| 1056 | END_RAMPMIX_FLT_INTERFACE() |
| 1057 | |
| 1058 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitLinearRampMix) |
| 1059 | SNDMIX_BEGINSAMPLELOOP16 |
| 1060 | SNDMIX_GETMONOVOL16LINEAR |
| 1061 | SNDMIX_PROCESSFILTER |
| 1062 | SNDMIX_RAMPMONOVOL |
| 1063 | END_RAMPMIX_FLT_INTERFACE() |
| 1064 | |
| 1065 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitSplineRampMix) |
| 1066 | SNDMIX_BEGINSAMPLELOOP8 |
| 1067 | SNDMIX_GETMONOVOL8SPLINE |
| 1068 | SNDMIX_PROCESSFILTER |
| 1069 | SNDMIX_RAMPMONOVOL |
| 1070 | END_RAMPMIX_FLT_INTERFACE() |
| 1071 | |
| 1072 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitSplineRampMix) |
| 1073 | SNDMIX_BEGINSAMPLELOOP16 |
| 1074 | SNDMIX_GETMONOVOL16SPLINE |
| 1075 | SNDMIX_PROCESSFILTER |
| 1076 | SNDMIX_RAMPMONOVOL |
| 1077 | END_RAMPMIX_FLT_INTERFACE() |
| 1078 | |
| 1079 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitFirFilterRampMix) |
| 1080 | SNDMIX_BEGINSAMPLELOOP8 |
| 1081 | SNDMIX_GETMONOVOL8FIRFILTER |
| 1082 | SNDMIX_PROCESSFILTER |
| 1083 | SNDMIX_RAMPMONOVOL |
| 1084 | END_RAMPMIX_FLT_INTERFACE() |
| 1085 | |
| 1086 | BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitFirFilterRampMix) |
| 1087 | SNDMIX_BEGINSAMPLELOOP16 |
| 1088 | SNDMIX_GETMONOVOL16FIRFILTER |
| 1089 | SNDMIX_PROCESSFILTER |
| 1090 | SNDMIX_RAMPMONOVOL |
| 1091 | END_RAMPMIX_FLT_INTERFACE() |
| 1092 | |
| 1093 | |
| 1094 | // Stereo Filter Mix |
| 1095 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitMix) |
| 1096 | SNDMIX_BEGINSAMPLELOOP8 |
| 1097 | SNDMIX_GETSTEREOVOL8NOIDO |
| 1098 | SNDMIX_PROCESSSTEREOFILTER |
| 1099 | SNDMIX_STORESTEREOVOL |
| 1100 | END_MIX_STFLT_INTERFACE() |
| 1101 | |
| 1102 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitMix) |
| 1103 | SNDMIX_BEGINSAMPLELOOP16 |
| 1104 | SNDMIX_GETSTEREOVOL16NOIDO |
| 1105 | SNDMIX_PROCESSSTEREOFILTER |
| 1106 | SNDMIX_STORESTEREOVOL |
| 1107 | END_MIX_STFLT_INTERFACE() |
| 1108 | |
| 1109 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitLinearMix) |
| 1110 | SNDMIX_BEGINSAMPLELOOP8 |
| 1111 | SNDMIX_GETSTEREOVOL8LINEAR |
| 1112 | SNDMIX_PROCESSSTEREOFILTER |
| 1113 | SNDMIX_STORESTEREOVOL |
| 1114 | END_MIX_STFLT_INTERFACE() |
| 1115 | |
| 1116 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitLinearMix) |
| 1117 | SNDMIX_BEGINSAMPLELOOP16 |
| 1118 | SNDMIX_GETSTEREOVOL16LINEAR |
| 1119 | SNDMIX_PROCESSSTEREOFILTER |
| 1120 | SNDMIX_STORESTEREOVOL |
| 1121 | END_MIX_STFLT_INTERFACE() |
| 1122 | |
| 1123 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitSplineMix) |
| 1124 | SNDMIX_BEGINSAMPLELOOP8 |
| 1125 | SNDMIX_GETSTEREOVOL8SPLINE |
| 1126 | SNDMIX_PROCESSSTEREOFILTER |
| 1127 | SNDMIX_STORESTEREOVOL |
| 1128 | END_MIX_STFLT_INTERFACE() |
| 1129 | |
| 1130 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitSplineMix) |
| 1131 | SNDMIX_BEGINSAMPLELOOP16 |
| 1132 | SNDMIX_GETSTEREOVOL16SPLINE |
| 1133 | SNDMIX_PROCESSSTEREOFILTER |
| 1134 | SNDMIX_STORESTEREOVOL |
| 1135 | END_MIX_STFLT_INTERFACE() |
| 1136 | |
| 1137 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitFirFilterMix) |
| 1138 | SNDMIX_BEGINSAMPLELOOP8 |
| 1139 | SNDMIX_GETSTEREOVOL8FIRFILTER |
| 1140 | SNDMIX_PROCESSSTEREOFILTER |
| 1141 | SNDMIX_STORESTEREOVOL |
| 1142 | END_MIX_STFLT_INTERFACE() |
| 1143 | |
| 1144 | BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitFirFilterMix) |
| 1145 | SNDMIX_BEGINSAMPLELOOP16 |
| 1146 | SNDMIX_GETSTEREOVOL16FIRFILTER |
| 1147 | SNDMIX_PROCESSSTEREOFILTER |
| 1148 | SNDMIX_STORESTEREOVOL |
| 1149 | END_MIX_STFLT_INTERFACE() |
| 1150 | |
| 1151 | // Stereo Filter + Ramp |
| 1152 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitRampMix) |
| 1153 | SNDMIX_BEGINSAMPLELOOP8 |
| 1154 | SNDMIX_GETSTEREOVOL8NOIDO |
| 1155 | SNDMIX_PROCESSSTEREOFILTER |
| 1156 | SNDMIX_RAMPSTEREOVOL |
| 1157 | END_RAMPMIX_STFLT_INTERFACE() |
| 1158 | |
| 1159 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitRampMix) |
| 1160 | SNDMIX_BEGINSAMPLELOOP16 |
| 1161 | SNDMIX_GETSTEREOVOL16NOIDO |
| 1162 | SNDMIX_PROCESSSTEREOFILTER |
| 1163 | SNDMIX_RAMPSTEREOVOL |
| 1164 | END_RAMPMIX_STFLT_INTERFACE() |
| 1165 | |
| 1166 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitLinearRampMix) |
| 1167 | SNDMIX_BEGINSAMPLELOOP8 |
| 1168 | SNDMIX_GETSTEREOVOL8LINEAR |
| 1169 | SNDMIX_PROCESSSTEREOFILTER |
| 1170 | SNDMIX_RAMPSTEREOVOL |
| 1171 | END_RAMPMIX_STFLT_INTERFACE() |
| 1172 | |
| 1173 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitLinearRampMix) |
| 1174 | SNDMIX_BEGINSAMPLELOOP16 |
| 1175 | SNDMIX_GETSTEREOVOL16LINEAR |
| 1176 | SNDMIX_PROCESSSTEREOFILTER |
| 1177 | SNDMIX_RAMPSTEREOVOL |
| 1178 | END_RAMPMIX_STFLT_INTERFACE() |
| 1179 | |
| 1180 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitSplineRampMix) |
| 1181 | SNDMIX_BEGINSAMPLELOOP8 |
| 1182 | SNDMIX_GETSTEREOVOL8SPLINE |
| 1183 | SNDMIX_PROCESSSTEREOFILTER |
| 1184 | SNDMIX_RAMPSTEREOVOL |
| 1185 | END_RAMPMIX_STFLT_INTERFACE() |
| 1186 | |
| 1187 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitSplineRampMix) |
| 1188 | SNDMIX_BEGINSAMPLELOOP16 |
| 1189 | SNDMIX_GETSTEREOVOL16SPLINE |
| 1190 | SNDMIX_PROCESSSTEREOFILTER |
| 1191 | SNDMIX_RAMPSTEREOVOL |
| 1192 | END_RAMPMIX_STFLT_INTERFACE() |
| 1193 | |
| 1194 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitFirFilterRampMix) |
| 1195 | SNDMIX_BEGINSAMPLELOOP8 |
| 1196 | SNDMIX_GETSTEREOVOL8FIRFILTER |
| 1197 | SNDMIX_PROCESSSTEREOFILTER |
| 1198 | SNDMIX_RAMPSTEREOVOL |
| 1199 | END_RAMPMIX_STFLT_INTERFACE() |
| 1200 | |
| 1201 | BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitFirFilterRampMix) |
| 1202 | SNDMIX_BEGINSAMPLELOOP16 |
| 1203 | SNDMIX_GETSTEREOVOL16FIRFILTER |
| 1204 | SNDMIX_PROCESSSTEREOFILTER |
| 1205 | SNDMIX_RAMPSTEREOVOL |
| 1206 | END_RAMPMIX_STFLT_INTERFACE() |
| 1207 | |
| 1208 | |
| 1209 | #else |
| 1210 | // Mono |
| 1211 | #define FilterMono8BitMix Mono8BitMix |
| 1212 | #define FilterMono16BitMix Mono16BitMix |
| 1213 | #define FilterMono8BitLinearMix Mono8BitLinearMix |
| 1214 | #define FilterMono16BitLinearMix Mono16BitLinearMix |
| 1215 | #define FilterMono8BitSplineMix Mono8BitSplineMix |
| 1216 | #define FilterMono16BitSplineMix Mono16BitSplineMix |
| 1217 | #define FilterMono8BitFirFilterMix Mono8BitFirFilterMix |
| 1218 | #define FilterMono16BitFirFilterMix Mono16BitFirFilterMix |
| 1219 | #define FilterMono8BitRampMix Mono8BitRampMix |
| 1220 | #define FilterMono16BitRampMix Mono16BitRampMix |
| 1221 | #define FilterMono8BitLinearRampMix Mono8BitLinearRampMix |
| 1222 | #define FilterMono16BitLinearRampMix Mono16BitLinearRampMix |
| 1223 | #define FilterMono8BitSplineRampMix Mono8BitSplineRampMix |
| 1224 | #define FilterMono16BitSplineRampMix Mono16BitSplineRampMix |
| 1225 | #define FilterMono8BitFirFilterRampMix Mono8BitFirFilterRampMix |
| 1226 | #define FilterMono16BitFirFilterRampMix Mono16BitFirFilterRampMix |
| 1227 | // Stereo |
| 1228 | #define FilterStereo8BitMix Stereo8BitMix |
| 1229 | #define FilterStereo16BitMix Stereo16BitMix |
| 1230 | #define FilterStereo8BitLinearMix Stereo8BitLinearMix |
| 1231 | #define FilterStereo16BitLinearMix Stereo16BitLinearMix |
| 1232 | #define FilterStereo8BitSplineMix Stereo8BitSplineMix |
| 1233 | #define FilterStereo16BitSplineMix Stereo16BitSplineMix |
| 1234 | #define FilterStereo8BitFirFilterMix Stereo8BitFirFilterMix |
| 1235 | #define FilterStereo16BitFirFilterMix Stereo16BitFirFilterMix |
| 1236 | #define FilterStereo8BitRampMix Stereo8BitRampMix |
| 1237 | #define FilterStereo16BitRampMix Stereo16BitRampMix |
| 1238 | #define FilterStereo8BitLinearRampMix Stereo8BitLinearRampMix |
| 1239 | #define FilterStereo16BitLinearRampMix Stereo16BitLinearRampMix |
| 1240 | #define FilterStereo8BitSplineRampMix Stereo8BitSplineRampMix |
| 1241 | #define FilterStereo16BitSplineRampMix Stereo16BitSplineRampMix |
| 1242 | #define FilterStereo8BitFirFilterRampMix Stereo8BitFirFilterRampMix |
| 1243 | #define FilterStereo16BitFirFilterRampMix Stereo16BitFirFilterRampMix |
| 1244 | |
| 1245 | #endif |
| 1246 | |
| 1247 | /////////////////////////////////////////////////////////////////////////////// |
| 1248 | // |
| 1249 | // Mix function tables |
| 1250 | // |
| 1251 | // |
| 1252 | // Index is as follow: |
| 1253 | // [b1-b0] format (8-bit-mono, 16-bit-mono, 8-bit-stereo, 16-bit-stereo) |
| 1254 | // [b2] ramp |
| 1255 | // [b3] filter |
| 1256 | // [b5-b4] src type |
| 1257 | // |
| 1258 | |
| 1259 | #define MIXNDX_16BIT 0x01 |
| 1260 | #define MIXNDX_STEREO 0x02 |
| 1261 | #define MIXNDX_RAMP 0x04 |
| 1262 | #define MIXNDX_FILTER 0x08 |
| 1263 | #define MIXNDX_LINEARSRC 0x10 |
| 1264 | #define MIXNDX_SPLINESRC 0x20 |
| 1265 | #define MIXNDX_FIRSRC 0x30 |
| 1266 | |
| 1267 | static const LPMIXINTERFACE gpMixFunctionTable[2*2*16] = |
| 1268 | { |
| 1269 | // No SRC |
| 1270 | Mono8BitMix, Mono16BitMix, Stereo8BitMix, Stereo16BitMix, |
| 1271 | Mono8BitRampMix, Mono16BitRampMix, Stereo8BitRampMix, |
| 1272 | Stereo16BitRampMix, |
| 1273 | // No SRC, Filter |
| 1274 | FilterMono8BitMix, FilterMono16BitMix, FilterStereo8BitMix, |
| 1275 | FilterStereo16BitMix, FilterMono8BitRampMix, FilterMono16BitRampMix, |
| 1276 | FilterStereo8BitRampMix, FilterStereo16BitRampMix, |
| 1277 | // Linear SRC |
| 1278 | Mono8BitLinearMix, Mono16BitLinearMix, Stereo8BitLinearMix, |
| 1279 | Stereo16BitLinearMix, Mono8BitLinearRampMix, Mono16BitLinearRampMix, |
| 1280 | Stereo8BitLinearRampMix,Stereo16BitLinearRampMix, |
| 1281 | // Linear SRC, Filter |
| 1282 | FilterMono8BitLinearMix, FilterMono16BitLinearMix, |
| 1283 | FilterStereo8BitLinearMix, FilterStereo16BitLinearMix, |
| 1284 | FilterMono8BitLinearRampMix, FilterMono16BitLinearRampMix, |
| 1285 | FilterStereo8BitLinearRampMix, FilterStereo16BitLinearRampMix, |
| 1286 | |
| 1287 | // FirFilter SRC |
| 1288 | Mono8BitSplineMix, Mono16BitSplineMix, Stereo8BitSplineMix, |
| 1289 | Stereo16BitSplineMix, Mono8BitSplineRampMix, Mono16BitSplineRampMix, |
| 1290 | Stereo8BitSplineRampMix,Stereo16BitSplineRampMix, |
| 1291 | // Spline SRC, Filter |
| 1292 | FilterMono8BitSplineMix, FilterMono16BitSplineMix, |
| 1293 | FilterStereo8BitSplineMix, FilterStereo16BitSplineMix, |
| 1294 | FilterMono8BitSplineRampMix, FilterMono16BitSplineRampMix, |
| 1295 | FilterStereo8BitSplineRampMix, FilterStereo16BitSplineRampMix, |
| 1296 | |
| 1297 | // FirFilter SRC |
| 1298 | Mono8BitFirFilterMix, Mono16BitFirFilterMix, Stereo8BitFirFilterMix, |
| 1299 | Stereo16BitFirFilterMix, Mono8BitFirFilterRampMix, |
| 1300 | Mono16BitFirFilterRampMix, Stereo8BitFirFilterRampMix, |
| 1301 | Stereo16BitFirFilterRampMix, |
| 1302 | // FirFilter SRC, Filter |
| 1303 | FilterMono8BitFirFilterMix, FilterMono16BitFirFilterMix, |
| 1304 | FilterStereo8BitFirFilterMix, FilterStereo16BitFirFilterMix, |
| 1305 | FilterMono8BitFirFilterRampMix, FilterMono16BitFirFilterRampMix, |
| 1306 | FilterStereo8BitFirFilterRampMix, FilterStereo16BitFirFilterRampMix |
| 1307 | }; |
| 1308 | |
| 1309 | static const LPMIXINTERFACE gpFastMixFunctionTable[2*2*16] = |
| 1310 | { |
| 1311 | // No SRC |
| 1312 | FastMono8BitMix, FastMono16BitMix, Stereo8BitMix, Stereo16BitMix, |
| 1313 | FastMono8BitRampMix, FastMono16BitRampMix, Stereo8BitRampMix, |
| 1314 | Stereo16BitRampMix, |
| 1315 | // No SRC, Filter |
| 1316 | FilterMono8BitMix, FilterMono16BitMix, FilterStereo8BitMix, |
| 1317 | FilterStereo16BitMix, FilterMono8BitRampMix, FilterMono16BitRampMix, |
| 1318 | FilterStereo8BitRampMix, FilterStereo16BitRampMix, |
| 1319 | // Linear SRC |
| 1320 | FastMono8BitLinearMix, FastMono16BitLinearMix, Stereo8BitLinearMix, |
| 1321 | Stereo16BitLinearMix, FastMono8BitLinearRampMix, |
| 1322 | FastMono16BitLinearRampMix, Stereo8BitLinearRampMix, |
| 1323 | Stereo16BitLinearRampMix, |
| 1324 | // Linear SRC, Filter |
| 1325 | FilterMono8BitLinearMix, FilterMono16BitLinearMix, |
| 1326 | FilterStereo8BitLinearMix, FilterStereo16BitLinearMix, |
| 1327 | FilterMono8BitLinearRampMix, FilterMono16BitLinearRampMix, |
| 1328 | FilterStereo8BitLinearRampMix, FilterStereo16BitLinearRampMix, |
| 1329 | |
| 1330 | // Spline SRC |
| 1331 | Mono8BitSplineMix, Mono16BitSplineMix, Stereo8BitSplineMix, |
| 1332 | Stereo16BitSplineMix, Mono8BitSplineRampMix, Mono16BitSplineRampMix, |
| 1333 | Stereo8BitSplineRampMix, Stereo16BitSplineRampMix, |
| 1334 | // Spline SRC, Filter |
| 1335 | FilterMono8BitSplineMix, FilterMono16BitSplineMix, |
| 1336 | FilterStereo8BitSplineMix, FilterStereo16BitSplineMix, |
| 1337 | FilterMono8BitSplineRampMix, FilterMono16BitSplineRampMix, |
| 1338 | FilterStereo8BitSplineRampMix, FilterStereo16BitSplineRampMix, |
| 1339 | |
| 1340 | // FirFilter SRC |
| 1341 | Mono8BitFirFilterMix, Mono16BitFirFilterMix, Stereo8BitFirFilterMix, |
| 1342 | Stereo16BitFirFilterMix, Mono8BitFirFilterRampMix, |
| 1343 | Mono16BitFirFilterRampMix, Stereo8BitFirFilterRampMix, |
| 1344 | Stereo16BitFirFilterRampMix, |
| 1345 | // FirFilter SRC, Filter |
| 1346 | FilterMono8BitFirFilterMix, FilterMono16BitFirFilterMix, |
| 1347 | FilterStereo8BitFirFilterMix, FilterStereo16BitFirFilterMix, |
| 1348 | FilterMono8BitFirFilterRampMix, FilterMono16BitFirFilterRampMix, |
| 1349 | FilterStereo8BitFirFilterRampMix, FilterStereo16BitFirFilterRampMix, |
| 1350 | }; |
| 1351 | |
| 1352 | |
| 1353 | ///////////////////////////////////////////////////////////////////////// |
| 1354 | |
| 1355 | static LONG MPPFASTCALL GetSampleCount(MODCHANNEL *pChn, LONG nSamples) |
| 1356 | //--------------------------------------------------------------------- |
| 1357 | { |
| 1358 | LONG nLoopStart = (pChn->dwFlags & CHN_LOOP) ? pChn->nLoopStart : 0; |
| 1359 | LONG nInc = pChn->nInc; |
| 1360 | |
| 1361 | if ((nSamples <= 0) || (!nInc) || (!pChn->nLength)) return 0; |
| 1362 | // Under zero ? |
| 1363 | if ((LONG)pChn->nPos < nLoopStart) |
| 1364 | { |
| 1365 | if (nInc < 0) |
| 1366 | { |
| 1367 | // Invert loop for bidi loops |
| 1368 | LONG nDelta = ((nLoopStart - pChn->nPos) << 16) - (pChn->nPosLo & 0xffff); |
| 1369 | pChn->nPos = nLoopStart | (nDelta>>16); |
| 1370 | pChn->nPosLo = nDelta & 0xffff; |
| 1371 | if (((LONG)pChn->nPos < nLoopStart) || |
| 1372 | (pChn->nPos >= (nLoopStart+pChn->nLength)/2)) |
| 1373 | { |
| 1374 | pChn->nPos = nLoopStart; pChn->nPosLo = 0; |
| 1375 | } |
| 1376 | nInc = -nInc; |
| 1377 | pChn->nInc = nInc; |
| 1378 | pChn->dwFlags &= ~(CHN_PINGPONGFLAG); // go forward |
| 1379 | if ((!(pChn->dwFlags & CHN_LOOP)) || (pChn->nPos >= pChn->nLength)) |
| 1380 | { |
| 1381 | pChn->nPos = pChn->nLength; |
| 1382 | pChn->nPosLo = 0; |
| 1383 | return 0; |
| 1384 | } |
| 1385 | } else |
| 1386 | { |
| 1387 | // We probably didn't hit the loop end yet |
| 1388 | // (first loop), so we do nothing |
| 1389 | if ((LONG)pChn->nPos < 0) pChn->nPos = 0; |
| 1390 | } |
| 1391 | } else |
| 1392 | // Past the end |
| 1393 | if (pChn->nPos >= pChn->nLength) |
| 1394 | { |
| 1395 | if (!(pChn->dwFlags & CHN_LOOP)) return 0; // not looping -> stop this channel |
| 1396 | if (pChn->dwFlags & CHN_PINGPONGLOOP) |
| 1397 | { |
| 1398 | // Invert loop |
| 1399 | if (nInc > 0) |
| 1400 | { |
| 1401 | nInc = -nInc; |
| 1402 | pChn->nInc = nInc; |
| 1403 | } |
| 1404 | pChn->dwFlags |= CHN_PINGPONGFLAG; |
| 1405 | // adjust loop position |
| 1406 | LONG nDeltaHi = (pChn->nPos - pChn->nLength); |
| 1407 | LONG nDeltaLo = 0x10000 - (pChn->nPosLo & 0xffff); |
| 1408 | pChn->nPos = pChn->nLength - nDeltaHi - (nDeltaLo>>16); |
| 1409 | pChn->nPosLo = nDeltaLo & 0xffff; |
| 1410 | if ((pChn->nPos <= pChn->nLoopStart) || |
| 1411 | (pChn->nPos >= pChn->nLength)) |
| 1412 | pChn->nPos = pChn->nLength-1; |
| 1413 | } else |
| 1414 | { |
| 1415 | if (nInc < 0) // This is a bug |
| 1416 | { |
| 1417 | nInc = -nInc; |
| 1418 | pChn->nInc = nInc; |
| 1419 | } |
| 1420 | // Restart at loop start |
| 1421 | pChn->nPos += nLoopStart - pChn->nLength; |
| 1422 | if ((LONG)pChn->nPos < nLoopStart) |
| 1423 | pChn->nPos = pChn->nLoopStart; |
| 1424 | } |
| 1425 | } |
| 1426 | LONG nPos = pChn->nPos; |
| 1427 | // too big increment, and/or too small loop length |
| 1428 | if (nPos < nLoopStart) |
| 1429 | { |
| 1430 | if ((nPos < 0) || (nInc < 0)) return 0; |
| 1431 | } |
| 1432 | if ((nPos < 0) || (nPos >= (LONG)pChn->nLength)) return 0; |
| 1433 | LONG nPosLo = (USHORT)pChn->nPosLo, nSmpCount = nSamples; |
| 1434 | if (nInc < 0) |
| 1435 | { |
| 1436 | LONG nInv = -nInc; |
| 1437 | LONG maxsamples = 16384 / ((nInv>>16)+1); |
| 1438 | if (maxsamples < 2) maxsamples = 2; |
| 1439 | if (nSamples > maxsamples) nSamples = maxsamples; |
| 1440 | LONG nDeltaHi = (nInv>>16) * (nSamples - 1); |
| 1441 | LONG nDeltaLo = (nInv&0xffff) * (nSamples - 1); |
| 1442 | LONG nPosDest = nPos - nDeltaHi + ((nPosLo - nDeltaLo) >> 16); |
| 1443 | if (nPosDest < nLoopStart) |
| 1444 | { |
| 1445 | nSmpCount = (ULONG)(((((LONGLONG)nPos - nLoopStart) << 16) + nPosLo - 1) / nInv) + 1; |
| 1446 | } |
| 1447 | } else |
| 1448 | { |
| 1449 | LONG maxsamples = 16384 / ((nInc>>16)+1); |
| 1450 | if (maxsamples < 2) maxsamples = 2; |
| 1451 | if (nSamples > maxsamples) nSamples = maxsamples; |
| 1452 | LONG nDeltaHi = (nInc>>16) * (nSamples - 1); |
| 1453 | LONG nDeltaLo = (nInc&0xffff) * (nSamples - 1); |
| 1454 | LONG nPosDest = nPos + nDeltaHi + ((nPosLo + nDeltaLo)>>16); |
| 1455 | if (nPosDest >= (LONG)pChn->nLength) |
| 1456 | { |
| 1457 | nSmpCount = (ULONG)(((((LONGLONG)pChn->nLength - nPos) << 16) - nPosLo - 1) / nInc) + 1; |
| 1458 | } |
| 1459 | } |
| 1460 | if (nSmpCount <= 1) return 1; |
| 1461 | if (nSmpCount > nSamples) return nSamples; |
| 1462 | return nSmpCount; |
| 1463 | } |
| 1464 | |
| 1465 | |
| 1466 | UINT CSoundFile::CreateStereoMix(int count) |
| 1467 | //----------------------------------------- |
| 1468 | { |
| 1469 | LPLONG pOfsL, pOfsR; |
| 1470 | DWORD nchused, nchmixed; |
| 1471 | |
| 1472 | if (!count) return 0; |
| 1473 | if (gnChannels > 2) X86_InitMixBuffer(MixRearBuffer, count*2); |
| 1474 | nchused = nchmixed = 0; |
| 1475 | for (UINT nChn=0; nChn<m_nMixChannels; nChn++) |
| 1476 | { |
| 1477 | const LPMIXINTERFACE *pMixFuncTable; |
| 1478 | MODCHANNEL * const pChannel = &Chn[ChnMix[nChn]]; |
| 1479 | UINT nFlags; |
| 1480 | LONG nSmpCount; |
| 1481 | int nsamples; |
| 1482 | int *pbuffer; |
| 1483 | |
| 1484 | if (!pChannel->pCurrentSample) continue; |
| 1485 | pOfsR = &gnDryROfsVol; |
| 1486 | pOfsL = &gnDryLOfsVol; |
| 1487 | nFlags = 0; |
| 1488 | if (pChannel->dwFlags & CHN_16BIT) nFlags |= MIXNDX_16BIT; |
| 1489 | if (pChannel->dwFlags & CHN_STEREO) nFlags |= MIXNDX_STEREO; |
| 1490 | #ifndef NO_FILTER |
| 1491 | if (pChannel->dwFlags & CHN_FILTER) nFlags |= MIXNDX_FILTER; |
| 1492 | #endif |
| 1493 | if (!(pChannel->dwFlags & CHN_NOIDO)) |
| 1494 | { |
| 1495 | // use hq-fir mixer? |
| 1496 | if( (gdwSoundSetup & (SNDMIX_HQRESAMPLER|SNDMIX_ULTRAHQSRCMODE)) == |
| 1497 | (SNDMIX_HQRESAMPLER|SNDMIX_ULTRAHQSRCMODE) ) |
| 1498 | nFlags += MIXNDX_FIRSRC; |
| 1499 | else if( (gdwSoundSetup & (SNDMIX_HQRESAMPLER)) == SNDMIX_HQRESAMPLER ) |
| 1500 | nFlags += MIXNDX_SPLINESRC; |
| 1501 | else |
| 1502 | nFlags += MIXNDX_LINEARSRC; // use |
| 1503 | } |
| 1504 | if ((nFlags < 0x40) && (pChannel->nLeftVol == pChannel->nRightVol) |
| 1505 | && ((!pChannel->nRampLength) || (pChannel->nLeftRamp == pChannel->nRightRamp))) |
| 1506 | { |
| 1507 | pMixFuncTable = gpFastMixFunctionTable; |
| 1508 | } else |
| 1509 | { |
| 1510 | pMixFuncTable = gpMixFunctionTable; |
| 1511 | } |
| 1512 | nsamples = count; |
| 1513 | #ifndef MODPLUG_NO_REVERB |
| 1514 | pbuffer = (gdwSoundSetup & SNDMIX_REVERB) ? MixReverbBuffer : MixSoundBuffer; |
| 1515 | if (pChannel->dwFlags & CHN_NOREVERB) pbuffer = MixSoundBuffer; |
| 1516 | if (pChannel->dwFlags & CHN_REVERB) pbuffer = MixReverbBuffer; |
| 1517 | if (pbuffer == MixReverbBuffer) |
| 1518 | { |
| 1519 | if (!gnReverbSend) memset(MixReverbBuffer, 0, count * 8); |
| 1520 | gnReverbSend += count; |
| 1521 | } |
| 1522 | #else |
| 1523 | pbuffer = MixSoundBuffer; |
| 1524 | #endif |
| 1525 | nchused++; |
| 1526 | //////////////////////////////////////////////////// |
| 1527 | SampleLooping: |
| 1528 | UINT nrampsamples = nsamples; |
| 1529 | if (pChannel->nRampLength > 0) |
| 1530 | { |
| 1531 | if ((LONG)nrampsamples > pChannel->nRampLength) nrampsamples = pChannel->nRampLength; |
| 1532 | } |
| 1533 | if ((nSmpCount = GetSampleCount(pChannel, nrampsamples)) <= 0) |
| 1534 | { |
| 1535 | // Stopping the channel |
| 1536 | pChannel->pCurrentSample = NULL; |
| 1537 | pChannel->nLength = 0; |
| 1538 | pChannel->nPos = 0; |
| 1539 | pChannel->nPosLo = 0; |
| 1540 | pChannel->nRampLength = 0; |
| 1541 | X86_EndChannelOfs(pChannel, pbuffer, nsamples); |
| 1542 | *pOfsR += pChannel->nROfs; |
| 1543 | *pOfsL += pChannel->nLOfs; |
| 1544 | pChannel->nROfs = pChannel->nLOfs = 0; |
| 1545 | pChannel->dwFlags &= ~CHN_PINGPONGFLAG; |
| 1546 | continue; |
| 1547 | } |
| 1548 | // Should we mix this channel ? |
| 1549 | UINT naddmix; |
| 1550 | if (((nchmixed >= m_nMaxMixChannels) && (!(gdwSoundSetup & SNDMIX_DIRECTTODISK))) |
| 1551 | || ((!pChannel->nRampLength) && (!(pChannel->nLeftVol|pChannel->nRightVol)))) |
| 1552 | { |
| 1553 | LONG delta = (pChannel->nInc * (LONG)nSmpCount) + (LONG)pChannel->nPosLo; |
| 1554 | pChannel->nPosLo = delta & 0xFFFF; |
| 1555 | pChannel->nPos += (delta >> 16); |
| 1556 | pChannel->nROfs = pChannel->nLOfs = 0; |
| 1557 | pbuffer += nSmpCount*2; |
| 1558 | naddmix = 0; |
| 1559 | } else |
| 1560 | // Do mixing |
| 1561 | { |
| 1562 | // Choose function for mixing |
| 1563 | LPMIXINTERFACE pMixFunc; |
| 1564 | pMixFunc = (pChannel->nRampLength) ? pMixFuncTable[nFlags|MIXNDX_RAMP] : pMixFuncTable[nFlags]; |
| 1565 | int *pbufmax = pbuffer + (nSmpCount*2); |
| 1566 | pChannel->nROfs = - *(pbufmax-2); |
| 1567 | pChannel->nLOfs = - *(pbufmax-1); |
| 1568 | pMixFunc(pChannel, pbuffer, pbufmax); |
| 1569 | pChannel->nROfs += *(pbufmax-2); |
| 1570 | pChannel->nLOfs += *(pbufmax-1); |
| 1571 | pbuffer = pbufmax; |
| 1572 | naddmix = 1; |
| 1573 | |
| 1574 | } |
| 1575 | nsamples -= nSmpCount; |
| 1576 | if (pChannel->nRampLength) |
| 1577 | { |
| 1578 | pChannel->nRampLength -= nSmpCount; |
| 1579 | if (pChannel->nRampLength <= 0) |
| 1580 | { |
| 1581 | pChannel->nRampLength = 0; |
| 1582 | pChannel->nRightVol = pChannel->nNewRightVol; |
| 1583 | pChannel->nLeftVol = pChannel->nNewLeftVol; |
| 1584 | pChannel->nRightRamp = pChannel->nLeftRamp = 0; |
| 1585 | if ((pChannel->dwFlags & CHN_NOTEFADE) && (!(pChannel->nFadeOutVol))) |
| 1586 | { |
| 1587 | pChannel->nLength = 0; |
| 1588 | pChannel->pCurrentSample = NULL; |
| 1589 | } |
| 1590 | } |
| 1591 | } |
| 1592 | if (nsamples > 0) goto SampleLooping; |
| 1593 | nchmixed += naddmix; |
| 1594 | } |
| 1595 | return nchused; |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | #ifdef MSC_VER |
| 1600 | #pragma warning (disable:4100) |
| 1601 | #endif |
| 1602 | |
| 1603 | // Clip and convert to 8 bit |
| 1604 | // The C version was written by Rani Assaf <[email protected]>, I believe |
| 1605 | DWORD MPPASMCALL X86_Convert32To8(LPVOID lp8, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax) |
| 1606 | { |
| 1607 | int vumin = *lpMin, vumax = *lpMax; |
| 1608 | unsigned char *p = (unsigned char *)lp8; |
| 1609 | for (UINT i=0; i<lSampleCount; i++) |
| 1610 | { |
| 1611 | int n = pBuffer[i]; |
| 1612 | if (n < MIXING_CLIPMIN) |
| 1613 | n = MIXING_CLIPMIN; |
| 1614 | else if (n > MIXING_CLIPMAX) |
| 1615 | n = MIXING_CLIPMAX; |
| 1616 | if (n < vumin) |
| 1617 | vumin = n; |
| 1618 | else if (n > vumax) |
| 1619 | vumax = n; |
| 1620 | p[i] = (n >> (24-MIXING_ATTENUATION)) ^ 0x80; // 8-bit unsigned |
| 1621 | } |
| 1622 | *lpMin = vumin; |
| 1623 | *lpMax = vumax; |
| 1624 | return lSampleCount; |
| 1625 | } |
| 1626 | |
| 1627 | // Clip and convert to 16 bit |
| 1628 | // The C version was written by Rani Assaf <[email protected]>, I believe |
| 1629 | DWORD MPPASMCALL X86_Convert32To16(LPVOID lp16, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax) |
| 1630 | { |
| 1631 | int vumin = *lpMin, vumax = *lpMax; |
| 1632 | signed short *p = (signed short *)lp16; |
| 1633 | for (UINT i=0; i<lSampleCount; i++) |
| 1634 | { |
| 1635 | int n = pBuffer[i]; |
| 1636 | if (n < MIXING_CLIPMIN) |
| 1637 | n = MIXING_CLIPMIN; |
| 1638 | else if (n > MIXING_CLIPMAX) |
| 1639 | n = MIXING_CLIPMAX; |
| 1640 | if (n < vumin) |
| 1641 | vumin = n; |
| 1642 | else if (n > vumax) |
| 1643 | vumax = n; |
| 1644 | p[i] = n >> (16-MIXING_ATTENUATION); // 16-bit signed |
| 1645 | } |
| 1646 | *lpMin = vumin; |
| 1647 | *lpMax = vumax; |
| 1648 | return lSampleCount * 2; |
| 1649 | } |
| 1650 | |
| 1651 | // Clip and convert to 24 bit |
| 1652 | DWORD MPPASMCALL X86_Convert32To24(LPVOID lp16, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax) |
| 1653 | { |
| 1654 | UINT i ; |
| 1655 | int vumin = *lpMin, vumax = *lpMax; |
| 1656 | int n,p ; |
| 1657 | unsigned char* buf = (unsigned char*)lp16 ; |
| 1658 | |
| 1659 | for ( i=0; i<lSampleCount; i++) |
| 1660 | { |
| 1661 | n = pBuffer[i]; |
| 1662 | if (n < MIXING_CLIPMIN) |
| 1663 | n = MIXING_CLIPMIN; |
| 1664 | else if (n > MIXING_CLIPMAX) |
| 1665 | n = MIXING_CLIPMAX; |
| 1666 | if (n < vumin) |
| 1667 | vumin = n; |
| 1668 | else if (n > vumax) |
| 1669 | vumax = n; |
| 1670 | p = n >> (8-MIXING_ATTENUATION) ; // 24-bit signed |
| 1671 | #ifdef WORDS_BIGENDIAN |
| 1672 | buf[i*3+0] = p & 0xFF0000 >> 24; |
| 1673 | buf[i*3+1] = p & 0x00FF00 >> 16 ; |
| 1674 | buf[i*3+2] = p & 0x0000FF ; |
| 1675 | #else |
| 1676 | buf[i*3+0] = p & 0x0000FF ; |
| 1677 | buf[i*3+1] = p & 0x00FF00 >> 16; |
| 1678 | buf[i*3+2] = p & 0xFF0000 >> 24; |
| 1679 | #endif |
| 1680 | } |
| 1681 | *lpMin = vumin; |
| 1682 | *lpMax = vumax; |
| 1683 | return lSampleCount * 3; |
| 1684 | } |
| 1685 | |
| 1686 | // Clip and convert to 32 bit |
| 1687 | DWORD MPPASMCALL X86_Convert32To32(LPVOID lp16, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax) |
| 1688 | { |
| 1689 | UINT i ; |
| 1690 | int vumin = *lpMin, vumax = *lpMax; |
| 1691 | int32_t *p = (int32_t *)lp16; |
| 1692 | |
| 1693 | for ( i=0; i<lSampleCount; i++) |
| 1694 | { |
| 1695 | int n = pBuffer[i]; |
| 1696 | if (n < MIXING_CLIPMIN) |
| 1697 | n = MIXING_CLIPMIN; |
| 1698 | else if (n > MIXING_CLIPMAX) |
| 1699 | n = MIXING_CLIPMAX; |
| 1700 | if (n < vumin) |
| 1701 | vumin = n; |
| 1702 | else if (n > vumax) |
| 1703 | vumax = n; |
| 1704 | p[i] = n << MIXING_ATTENUATION; // 32-bit signed |
| 1705 | } |
| 1706 | *lpMin = vumin; |
| 1707 | *lpMax = vumax; |
| 1708 | return lSampleCount * 4; |
| 1709 | } |
| 1710 | |
| 1711 | // Will fill in later. |
| 1712 | static void MPPASMCALL X86_InitMixBuffer(int *pBuffer, UINT nSamples) |
| 1713 | { |
| 1714 | memset(pBuffer, 0, nSamples * sizeof(int)); |
| 1715 | } |
| 1716 | |
| 1717 | // Multichannel not supported. |
| 1718 | void MPPASMCALL X86_InterleaveFrontRear(int *, int *, DWORD) |
| 1719 | { |
| 1720 | } |
| 1721 | |
| 1722 | VOID MPPASMCALL X86_MonoFromStereo(int *pMixBuf, UINT nSamples) |
| 1723 | { |
| 1724 | UINT j; |
| 1725 | for(UINT i = 0; i < nSamples; i++) |
| 1726 | { |
| 1727 | j = i << 1; |
| 1728 | pMixBuf[i] = (pMixBuf[j] + pMixBuf[j + 1]) >> 1; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | #define OFSDECAYSHIFT 8 |
| 1733 | #define OFSDECAYMASK 0xFF |
| 1734 | |
| 1735 | void MPPASMCALL X86_StereoFill(int *pBuffer, UINT nSamples, LPLONG lpROfs, LPLONG lpLOfs) |
| 1736 | //---------------------------------------------------------------------------- |
| 1737 | { |
| 1738 | int rofs = *lpROfs; |
| 1739 | int lofs = *lpLOfs; |
| 1740 | |
| 1741 | if ((!rofs) && (!lofs)) |
| 1742 | { |
| 1743 | X86_InitMixBuffer(pBuffer, nSamples*2); |
| 1744 | return; |
| 1745 | } |
| 1746 | for (UINT i=0; i<nSamples; i++) |
| 1747 | { |
| 1748 | int x_r = (rofs + (((-rofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT; |
| 1749 | int x_l = (lofs + (((-lofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT; |
| 1750 | rofs -= x_r; |
| 1751 | lofs -= x_l; |
| 1752 | pBuffer[i*2] = x_r; |
| 1753 | pBuffer[i*2+1] = x_l; |
| 1754 | } |
| 1755 | *lpROfs = rofs; |
| 1756 | *lpLOfs = lofs; |
| 1757 | } |
| 1758 | |
| 1759 | // Will fill in later. |
| 1760 | static void MPPASMCALL X86_EndChannelOfs(MODCHANNEL *pChannel, int *pBuffer, UINT nSamples) |
| 1761 | { |
| 1762 | int rofs = pChannel->nROfs; |
| 1763 | int lofs = pChannel->nLOfs; |
| 1764 | |
| 1765 | if ((!rofs) && (!lofs)) return; |
| 1766 | for (UINT i=0; i<nSamples; i++) |
| 1767 | { |
| 1768 | int x_r = (rofs + (((-rofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT; |
| 1769 | int x_l = (lofs + (((-lofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT; |
| 1770 | rofs -= x_r; |
| 1771 | lofs -= x_l; |
| 1772 | pBuffer[i*2] += x_r; |
| 1773 | pBuffer[i*2+1] += x_l; |
| 1774 | } |
| 1775 | pChannel->nROfs = rofs; |
| 1776 | pChannel->nLOfs = lofs; |
| 1777 | } |