dependencies/SDL_sound/libmodplug/sndmix.c in gosu-1.4.5.pre1 vs dependencies/SDL_sound/libmodplug/sndmix.c in gosu-1.4.5
- old
+ new
@@ -74,16 +74,18 @@
BOOL CSoundFile_FadeSong(CSoundFile *_this, UINT msec)
//----------------------------------
{
LONG nsamples = _muldiv(msec, _this->gdwMixingFreq, 1000);
+ LONG nRampLength;
+ UINT noff;
if (nsamples <= 0) return FALSE;
if (nsamples > 0x100000) nsamples = 0x100000;
_this->m_nBufferCount = nsamples;
- LONG nRampLength = _this->m_nBufferCount;
+ nRampLength = _this->m_nBufferCount;
// Ramp everything down
- for (UINT noff=0; noff < _this->m_nMixChannels; noff++)
+ for (noff=0; noff < _this->m_nMixChannels; noff++)
{
MODCHANNEL *pramp = &_this->Chn[_this->ChnMix[noff]];
if (!pramp) continue;
pramp->nNewLeftVol = pramp->nNewRightVol = 0;
pramp->nRightRamp = (-pramp->nRightVol << VOLUMERAMPPRECISION) / nRampLength;
@@ -126,10 +128,11 @@
if ((!lMax) || (!lpBuffer) || (!_this->m_nChannels)) return 0;
lRead = lMax;
if (_this->m_dwSongFlags & SONG_ENDREACHED) goto MixDone;
while (lRead > 0)
{
+ UINT lTotalSampleCount;
// Update Channel Data
if (!_this->m_nBufferCount)
{
if (_this->m_dwSongFlags & SONG_FADINGSONG)
{
@@ -166,11 +169,11 @@
_this->m_nMixStat += CSoundFile_CreateStereoMix(_this, lCount);
CSoundFile_ProcessStereoDSP(_this, lCount);
X86_MonoFromStereo(_this->MixSoundBuffer, lCount);
}
nStat++;
- UINT lTotalSampleCount = lSampleCount;
+ lTotalSampleCount = lSampleCount;
// Multichannel
if (_this->gnChannels > 2)
{
X86_InterleaveFrontRear(_this->MixSoundBuffer, _this->MixRearBuffer, lSampleCount);
lTotalSampleCount *= 2;
@@ -194,10 +197,14 @@
BOOL CSoundFile_ProcessRow(CSoundFile *_this)
//---------------------------
{
if (++_this->m_nTickCount >= _this->m_nMusicSpeed * (_this->m_nPatternDelay+1) + _this->m_nFrameDelay)
{
+ MODCHANNEL *pChn;
+ MODCOMMAND *m;
+ UINT nChn;
+
_this->m_nPatternDelay = 0;
_this->m_nFrameDelay = 0;
_this->m_nTickCount = 0;
_this->m_nRow = _this->m_nNextRow;
// Reset Pattern Loop Effect
@@ -214,14 +221,15 @@
{
//if (!_this->m_nRepeatCount)
return FALSE; //never repeat entire song
if (!_this->m_nRestartPos)
{
+ UINT i;
_this->m_nMusicSpeed = _this->m_nDefaultSpeed;
_this->m_nMusicTempo = _this->m_nDefaultTempo;
_this->m_nGlobalVolume = _this->m_nDefaultGlobalVolume;
- for (UINT i=0; i<MAX_CHANNELS; i++)
+ for (i=0; i<MAX_CHANNELS; i++)
{
_this->Chn[i].dwFlags |= CHN_NOTEFADE | CHN_KEYOFF;
_this->Chn[i].nFadeOutVol = 0;
if (i < _this->m_nChannels)
{
@@ -269,13 +277,13 @@
if (!(_this->m_dwSongFlags & SONG_PATTERNLOOP)) _this->m_nNextPattern = _this->m_nCurrentPattern + 1;
_this->m_nNextRow = _this->m_nNextStartRow;
_this->m_nNextStartRow = 0;
}
// Reset channel values
- MODCHANNEL *pChn = _this->Chn;
- MODCOMMAND *m = _this->Patterns[_this->m_nPattern] + _this->m_nRow * _this->m_nChannels;
- for (UINT nChn=0; nChn<_this->m_nChannels; pChn++, nChn++, m++)
+ pChn = _this->Chn;
+ m = _this->Patterns[_this->m_nPattern] + _this->m_nRow * _this->m_nChannels;
+ for (nChn=0; nChn<_this->m_nChannels; pChn++, nChn++, m++)
{
pChn->nRowNote = m->note;
pChn->nRowInstr = m->instr;
pChn->nRowVolCmd = m->volcmd;
pChn->nRowVolume = m->vol;
@@ -309,27 +317,33 @@
// Handles envelopes & mixer setup
BOOL CSoundFile_ReadNote(CSoundFile *_this)
//-------------------------
{
+ DWORD nMasterVol;
+ MODCHANNEL *pChn;
+ UINT nChn;
+
if (!CSoundFile_ProcessRow(_this)) return FALSE;
////////////////////////////////////////////////////////////////////////////////////
_this->m_nTotalCount++;
if (!_this->m_nMusicTempo) return FALSE;
_this->m_nBufferCount = (_this->gdwMixingFreq * 5 * _this->m_nTempoFactor) / (_this->m_nMusicTempo << 8);
// Master Volume + Pre-Amplification / Attenuation setup
- DWORD nMasterVol;
{
int nchn32 = (_this->m_nChannels < 32) ? _this->m_nChannels : 31;
+ int realmastervol;
+ UINT attenuation;
+ DWORD mastervol;
if ((_this->m_nType & MOD_TYPE_IT) && (_this->m_nInstruments) && (nchn32 < 6)) nchn32 = 6;
- int realmastervol = _this->m_nMasterVolume;
+ realmastervol = _this->m_nMasterVolume;
if (realmastervol > 0x80)
{
realmastervol = 0x80 + ((realmastervol - 0x80) * (nchn32+4)) / 16;
}
- UINT attenuation = (_this->gdwSoundSetup & SNDMIX_AGC) ? PreAmpAGCTable[nchn32>>1] : PreAmpTable[nchn32>>1];
- DWORD mastervol = (realmastervol * (_this->m_nSongPreAmp + 0x10)) >> 6;
+ attenuation = (_this->gdwSoundSetup & SNDMIX_AGC) ? PreAmpAGCTable[nchn32>>1] : PreAmpTable[nchn32>>1];
+ mastervol = (realmastervol * (_this->m_nSongPreAmp + 0x10)) >> 6;
if (mastervol > 0x200) mastervol = 0x200;
if ((_this->m_dwSongFlags & SONG_GLOBALFADE) && (_this->m_nGlobalFadeMaxSamples))
{
mastervol = _muldiv(mastervol, _this->m_nGlobalFadeSamples, _this->m_nGlobalFadeMaxSamples);
}
@@ -337,12 +351,12 @@
if (nMasterVol > 0x180) nMasterVol = 0x180;
}
////////////////////////////////////////////////////////////////////////////////////
// Update channels data
_this->m_nMixChannels = 0;
- MODCHANNEL *pChn = _this->Chn;
- for (UINT nChn=0; nChn<MAX_CHANNELS; nChn++,pChn++)
+ pChn = _this->Chn;
+ for (nChn=0; nChn<MAX_CHANNELS; nChn++,pChn++)
{
if ((pChn->dwFlags & CHN_NOTEFADE) && (!(pChn->nFadeOutVol|pChn->nRightVol|pChn->nLeftVol)))
{
pChn->nLength = 0;
pChn->nROfs = pChn->nLOfs = 0;
@@ -361,10 +375,12 @@
pChn->nRampLength = 0;
// Calc Frequency
if ((pChn->nPeriod) && (pChn->nLength))
{
int vol = pChn->nVolume + pChn->nVolSwing;
+ int period, nPeriodFrac;
+ UINT freq, ninc;
if (vol < 0) vol = 0;
if (vol > 256) vol = 256;
// Tremolo
if (pChn->dwFlags & CHN_TREMOLO)
@@ -396,12 +412,12 @@
// Tremor
if (pChn->nCommand == CMD_TREMOR)
{
UINT n = (pChn->nTremorParam >> 4) + (pChn->nTremorParam & 0x0F);
UINT ontime = pChn->nTremorParam >> 4;
- if ((!(_this->m_nType & MOD_TYPE_IT)) || (_this->m_dwSongFlags & SONG_ITOLDEFFECTS)) { n += 2; ontime++; }
UINT tremcount = (UINT)pChn->nTremorCount;
+ if ((!(_this->m_nType & MOD_TYPE_IT)) || (_this->m_dwSongFlags & SONG_ITOLDEFFECTS)) { n += 2; ontime++; }
if (tremcount >= n) tremcount = 0;
if ((_this->m_nTickCount) || (_this->m_nType & (MOD_TYPE_S3M|MOD_TYPE_IT)))
{
if (tremcount >= ontime) vol = 0;
pChn->nTremorCount = (BYTE)(tremcount + 1);
@@ -418,21 +434,22 @@
INSTRUMENTHEADER *penv = pChn->pHeader;
// Volume Envelope
if ((pChn->dwFlags & CHN_VOLENV) && (penv->nVolEnv))
{
int envpos = pChn->nVolEnvPosition;
+ int x1, x2, envvol;
UINT pt = penv->nVolEnv - 1;
- for (UINT i=0; i<(UINT)(penv->nVolEnv-1); i++)
+ UINT i;
+ for (i=0; i<(UINT)(penv->nVolEnv-1); i++)
{
if (envpos <= penv->VolPoints[i])
{
pt = i;
break;
}
}
- int x2 = penv->VolPoints[pt];
- int x1, envvol;
+ x2 = penv->VolPoints[pt];
if (envpos >= x2)
{
envvol = penv->VolEnv[pt] << 2;
x1 = x2;
} else
@@ -456,21 +473,22 @@
}
// Panning Envelope
if ((pChn->dwFlags & CHN_PANENV) && (penv->nPanEnv))
{
int envpos = pChn->nPanEnvPosition;
+ int x1, x2, y2, envpan, pan;
UINT pt = penv->nPanEnv - 1;
- for (UINT i=0; i<(UINT)(penv->nPanEnv-1); i++)
+ UINT i;
+ for (i=0; i<(UINT)(penv->nPanEnv-1); i++)
{
if (envpos <= penv->PanPoints[i])
{
pt = i;
break;
}
}
- int x2 = penv->PanPoints[pt], y2 = penv->PanEnv[pt];
- int x1, envpan;
+ x2 = penv->PanPoints[pt], y2 = penv->PanEnv[pt];
if (envpos >= x2)
{
envpan = y2;
x1 = x2;
} else
@@ -487,11 +505,11 @@
{
envpan += ((envpos - x1) * (y2 - envpan)) / (x2 - x1);
}
if (envpan < 0) envpan = 0;
if (envpan > 64) envpan = 64;
- int pan = pChn->nPan;
+ pan = pChn->nPan;
if (pan >= 128)
{
pan += ((envpan - 32) * (256 - pan)) / 32;
} else
{
@@ -539,11 +557,11 @@
// IMPORTANT: pChn->nRealVolume is 14 bits !!!
// -> _muldiv( 14+8, 6+6, 18); => RealVolume: 14-bit result (22+12-20)
pChn->nRealVolume = _muldiv(vol * _this->m_nGlobalVolume, pChn->nGlobalVol * pChn->nInsVol, 1 << 20);
}
if (pChn->nPeriod < _this->m_nMinPeriod) pChn->nPeriod = _this->m_nMinPeriod;
- int period = pChn->nPeriod;
+ period = pChn->nPeriod;
if ((pChn->dwFlags & (CHN_GLISSANDO|CHN_PORTAMENTO)) == (CHN_GLISSANDO|CHN_PORTAMENTO))
{
period = CSoundFile_GetPeriodFromNote(_this, CSoundFile_GetNoteFromPeriod(_this, period), pChn->nFineTune, pChn->nC4Speed);
}
@@ -566,21 +584,22 @@
// Pitch/Filter Envelope
if ((pChn->pHeader) && (pChn->dwFlags & CHN_PITCHENV) && (pChn->pHeader->nPitchEnv))
{
INSTRUMENTHEADER *penv = pChn->pHeader;
int envpos = pChn->nPitchEnvPosition;
+ int x1, x2, envpitch;
UINT pt = penv->nPitchEnv - 1;
- for (UINT i=0; i<(UINT)(penv->nPitchEnv-1); i++)
+ UINT i;
+ for (i=0; i<(UINT)(penv->nPitchEnv-1); i++)
{
if (envpos <= penv->PitchPoints[i])
{
pt = i;
break;
}
}
- int x2 = penv->PitchPoints[pt];
- int x1, envpitch;
+ x2 = penv->PitchPoints[pt];
if (envpos >= x2)
{
envpitch = (((int)penv->PitchEnv[pt]) - 32) * 8;
x1 = x2;
} else
@@ -627,10 +646,11 @@
// Vibrato
if (pChn->dwFlags & CHN_VIBRATO)
{
UINT vibpos = pChn->nVibratoPos;
LONG vdelta;
+ UINT vdepth;
switch (pChn->nVibratoType & 0x03)
{
case 1:
vdelta = ModRampDownTable[vibpos];
break;
@@ -641,11 +661,11 @@
vdelta = ModRandomTable[vibpos];
break;
default:
vdelta = ModSinusTable[vibpos];
}
- UINT vdepth = ((_this->m_nType != MOD_TYPE_IT) || (_this->m_dwSongFlags & SONG_ITOLDEFFECTS)) ? 6 : 7;
+ vdepth = ((_this->m_nType != MOD_TYPE_IT) || (_this->m_dwSongFlags & SONG_ITOLDEFFECTS)) ? 6 : 7;
vdelta = (vdelta * (int)pChn->nVibratoDepth) >> vdepth;
if ((_this->m_dwSongFlags & SONG_LINEARSLIDES) && (_this->m_nType & MOD_TYPE_IT))
{
LONG l = vdelta;
if (l < 0)
@@ -691,15 +711,16 @@
pdelta += pChn->nRealPan;
if (pdelta < 0) pdelta = 0;
if (pdelta > 256) pdelta = 256;
pChn->nRealPan = pdelta;
}
- int nPeriodFrac = 0;
+ nPeriodFrac = 0;
// Instrument Auto-Vibrato
if ((pChn->pInstrument) && (pChn->pInstrument->nVibDepth))
{
MODINSTRUMENT *pins = pChn->pInstrument;
+ int val, n;
if (pins->nVibSweep == 0)
{
pChn->nAutoVibDepth = pins->nVibDepth << 8;
} else
{
@@ -713,11 +734,10 @@
}
if ((pChn->nAutoVibDepth >> 8) > pins->nVibDepth)
pChn->nAutoVibDepth = pins->nVibDepth << 8;
}
pChn->nAutoVibPos += pins->nVibRate;
- int val;
switch(pins->nVibType)
{
case 4: // Random
val = ModRandomTable[pChn->nAutoVibPos & 0x3F];
pChn->nAutoVibPos++;
@@ -732,23 +752,24 @@
val = (pChn->nAutoVibPos & 128) ? +64 : -64;
break;
default: // Sine
val = ft2VibratoTable[pChn->nAutoVibPos & 255];
}
- int n = ((val * pChn->nAutoVibDepth) >> 8);
+ n = ((val * pChn->nAutoVibDepth) >> 8);
if (_this->m_nType & MOD_TYPE_IT)
{
int df1, df2;
+ UINT n1;
if (n < 0)
{
n = -n;
- UINT n1 = n >> 8;
+ n1 = n >> 8;
df1 = LinearSlideUpTable[n1];
df2 = LinearSlideUpTable[n1+1];
} else
{
- UINT n1 = n >> 8;
+ n1 = n >> 8;
df1 = LinearSlideDownTable[n1];
df2 = LinearSlideDownTable[n1+1];
}
n >>= 2;
period = _muldiv(period, df1 + ((df2-df1)*(n&0x3F)>>6), 256);
@@ -774,18 +795,18 @@
pChn->nRealVolume = 0;
}
period = _this->m_nMaxPeriod;
nPeriodFrac = 0;
}
- UINT freq = CSoundFile_GetFreqFromPeriod(_this, period, pChn->nC4Speed, nPeriodFrac);
+ freq = CSoundFile_GetFreqFromPeriod(_this, period, pChn->nC4Speed, nPeriodFrac);
if ((_this->m_nType & MOD_TYPE_IT) && (freq < 256))
{
pChn->nFadeOutVol = 0;
pChn->dwFlags |= CHN_NOTEFADE;
pChn->nRealVolume = 0;
}
- UINT ninc = _muldiv(freq, 0x10000, _this->gdwMixingFreq);
+ ninc = _muldiv(freq, 0x10000, _this->gdwMixingFreq);
if ((ninc >= 0xFFB0) && (ninc <= 0x10090)) ninc = 0x10000;
if (_this->m_nFreqFactor != 128) ninc = (ninc * _this->m_nFreqFactor) >> 7;
if (ninc > 0xFF0000) ninc = 0xFF0000;
pChn->nInc = (ninc+1) & ~3;
}
@@ -893,19 +914,20 @@
{
#define kChnMasterVol nMasterVol
// Adjusting volumes
if (_this->gnChannels >= 2)
{
+ LONG realvol;
int pan = ((int)pChn->nRealPan) - 128;
pan *= (int)_this->m_nStereoSeparation;
pan /= 128;
pan += 128;
if (pan < 0) pan = 0;
if (pan > 256) pan = 256;
if (_this->gdwSoundSetup & SNDMIX_REVERSESTEREO) pan = 256 - pan;
- LONG realvol = (pChn->nRealVolume * kChnMasterVol) >> (8-1);
+ realvol = (pChn->nRealVolume * kChnMasterVol) >> (8-1);
if (_this->gdwSoundSetup & SNDMIX_SOFTPANNING)
{
if (pan < 128)
{
pChn->nNewLeftVol = (realvol * pan) >> 8;
@@ -999,10 +1021,11 @@
}
}
// Checking Max Mix Channels reached: ordering by volume
if ((_this->m_nMixChannels >= _this->m_nMaxMixChannels) && (!(_this->gdwSoundSetup & SNDMIX_DIRECTTODISK)))
{
- for (UINT i=0; i<_this->m_nMixChannels; i++)
+ UINT i=0;
+ for (; i<_this->m_nMixChannels; i++)
{
UINT j=i;
while ((j+1<_this->m_nMixChannels) && (_this->Chn[_this->ChnMix[j]].nRealVolume < _this->Chn[_this->ChnMix[j+1]].nRealVolume))
{
UINT n = _this->ChnMix[j];