From: <sag...@us...> - 2014-02-02 01:18:53
|
Revision: 3627 http://sourceforge.net/p/modplug/code/3627 Author: saga-games Date: 2014-02-02 01:18:44 +0000 (Sun, 02 Feb 2014) Log Message: ----------- [Ref/Fix] Inconsistencies between ModChannel::pSample and ModChannel::pModSample could lead to a crash in the new loop wraparound code. Remedy this by throwing away the unnecessary ModChannel::pSample. [Fix] Some noise could be generated when stopping the song (this was supposed to be fixed, but sneaked in again when merging the new float/intmixer code) Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/soundlib/ModChannel.cpp trunk/OpenMPT/soundlib/ModChannel.h trunk/OpenMPT/soundlib/Snd_fx.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndmix.cpp trunk/OpenMPT/soundlib/modsmp_ctrl.cpp trunk/OpenMPT/soundlib/modsmp_ctrl.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -908,8 +908,8 @@ for(CHANNELINDEX k = 0; k < MAX_CHANNELS; k++) { const ModChannel &chn = m_pSndFile->Chn[k]; - if(chn.pSample == m_pSndFile->GetSample(smp).pSample && chn.nLength != 0 // Corrent sample is set up on this channel - && (!chn.dwFlags[CHN_NOTEFADE] || chn.nFadeOutVol)) // And it hasn't completely faded out yet, so it's still playing + if(chn.pModSample == &m_pSndFile->GetSample(smp) && chn.nLength != 0 // Corrent sample is set up on this channel + && (!chn.dwFlags[CHN_NOTEFADE] || chn.nFadeOutVol)) // And it hasn't completely faded out yet, so it's still playing { notification.pos[k] = chn.nPos; } else Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -1094,7 +1094,6 @@ chn.pCurrentSample = sample.pSample; chn.pModInstrument = nullptr; chn.pModSample = &sample; - chn.pSample = sample.pSample; chn.nFineTune = sample.nFineTune; chn.nC5Speed = sample.nC5Speed; chn.nLoopStart = sample.nLoopStart; Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -2042,7 +2042,7 @@ p[i] = (signed char) ((*((short int *)(p+i*2))) / 256); } sample.uFlags.reset(CHN_16BIT); - for (CHANNELINDEX j = 0; j < MAX_CHANNELS; j++) if (sndFile.Chn[j].pSample == sample.pSample) + for (CHANNELINDEX j = 0; j < MAX_CHANNELS; j++) if (sndFile.Chn[j].pModSample == &sample) { sndFile.Chn[j].dwFlags.reset(CHN_16BIT); } Modified: trunk/OpenMPT/soundlib/ModChannel.cpp =================================================================== --- trunk/OpenMPT/soundlib/ModChannel.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/soundlib/ModChannel.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -47,7 +47,6 @@ nLoopStart = 0; nLoopEnd = 0; nROfs = nLOfs = 0; - pSample = nullptr; pModSample = nullptr; pModInstrument = nullptr; nCutOff = 0x7F; Modified: trunk/OpenMPT/soundlib/ModChannel.h =================================================================== --- trunk/OpenMPT/soundlib/ModChannel.h 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/soundlib/ModChannel.h 2014-02-02 01:18:44 UTC (rev 3627) @@ -59,8 +59,7 @@ uint32 nRampLength; // Up to here: 100 bytes - const void *pSample; // Currently playing sample, or previously played sample if no sample is playing. - ModSample *pModSample; // Currently assigned sample slot + ModSample *pModSample; // Currently assigned sample slot (can already be stopped) // Information not used in the mixer ModInstrument *pModInstrument; // Currently assigned instrument slot Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -947,7 +947,6 @@ } - pChn->pSample = pSmp->pSample; pChn->nTranspose = pSmp->RelativeTone; // FT2 compatibility: Don't reset portamento target with new instrument numbers. @@ -1121,7 +1120,6 @@ if(!bPorta || (!pChn->nLength && !(GetType() & MOD_TYPE_S3M))) { pChn->pModSample = pSmp; - pChn->pSample = pSmp->pSample; pChn->nLength = pSmp->nLength; pChn->nLoopEnd = pSmp->nLength; pChn->nLoopStart = 0; @@ -1384,7 +1382,7 @@ return; } if(instr >= MAX_INSTRUMENTS) instr = 0; - const void *pSample = pChn->pSample; + const ModSample *pSample = pChn->pModSample; pIns = pChn->pModInstrument; if(instr && note) { @@ -1398,7 +1396,7 @@ note = pIns->NoteMap[note - 1]; if ((n) && (n < MAX_SAMPLES)) { - pSample = Samples[n].pSample; + pSample = &Samples[n]; } else if(IsCompatibleMode(TRK_IMPULSETRACKER) && !pIns->HasValidMIDIChannel()) { // Impulse Tracker ignores empty slots. @@ -1432,7 +1430,7 @@ break; // Sample case DCT_SAMPLE: - if(pSample != nullptr && pSample == p->pSample) bOk = true; + if(pSample != nullptr && pSample == p->pModSample) bOk = true; break; // Instrument case DCT_INSTRUMENT: @@ -1955,7 +1953,7 @@ } else { // Sample mode - if(instr < MAX_SAMPLES && pChn->pSample != Samples[instr].pSample) + if(instr < MAX_SAMPLES && pChn->pModSample != &Samples[instr]) note = pChn->nNote; } } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -990,7 +990,6 @@ Chn[i].pModInstrument = nullptr; Chn[i].pModSample = nullptr; Chn[i].pCurrentSample = nullptr; - Chn[i].pSample = nullptr; Chn[i].nLength = 0; } @@ -1633,11 +1632,11 @@ for(CHANNELINDEX i = 0; i < MAX_CHANNELS; i++) { - if(Chn[i].pSample == sample.pSample) + if(Chn[i].pModSample == &sample) { Chn[i].nPos = 0; Chn[i].nLength = 0; - Chn[i].pSample = Chn[i].pCurrentSample = nullptr; + Chn[i].pCurrentSample = nullptr; } } Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -123,7 +123,7 @@ if (nsamples <= 0) return FALSE; if (nsamples > 0x100000) nsamples = 0x100000; m_nBufferCount = nsamples; - uint32 nRampLength = static_cast<uint32>(m_nBufferCount); + int32 nRampLength = static_cast<int32>(m_nBufferCount); // Ramp everything down for (UINT noff=0; noff < m_nMixChannels; noff++) { @@ -392,7 +392,6 @@ Chn[i].nLoopStart = 0; Chn[i].nLoopEnd = 0; Chn[i].pModInstrument = nullptr; - Chn[i].pSample = nullptr; Chn[i].pModSample = nullptr; } } @@ -1877,7 +1876,7 @@ // Check for too big nInc //if (((pChn->nInc >> 16) + 1) >= (int32)(pChn->nLoopEnd - pChn->nLoopStart)) pChn->dwFlags.reset(CHN_LOOP); pChn->newLeftVol = pChn->newRightVol = 0; - pChn->pCurrentSample = ((pChn->pSample) && (pChn->nLength) && (pChn->nInc)) ? pChn->pSample : NULL; + pChn->pCurrentSample = (pChn->pModSample && pChn->pModSample->pSample && pChn->nLength && pChn->nInc) ? pChn->pModSample->pSample : nullptr; if (pChn->pCurrentSample) { // Update VU-Meter (nRealVolume is 14-bit) Modified: trunk/OpenMPT/soundlib/modsmp_ctrl.cpp =================================================================== --- trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2014-02-02 01:18:44 UTC (rev 3627) @@ -32,7 +32,7 @@ CriticalSection cs; - ctrlChn::ReplaceSample(sndFile.Chn, pOldSmp, pNewSample, nNewLength, setFlags, resetFlags); + ctrlChn::ReplaceSample(sndFile.Chn, &smp, pNewSample, nNewLength, setFlags, resetFlags); smp.pSample = pNewSample; smp.nLength = nNewLength; ModSample::FreeSample(pOldSmp); @@ -500,7 +500,7 @@ smp.nGlobalVol = MIN((WORD)(smp.nGlobalVol / dAmplify), 64); for (CHANNELINDEX i = 0; i < MAX_CHANNELS; i++) { - if(sndFile.Chn[i].pSample == smp.pSample) + if(sndFile.Chn[i].pModSample == &smp) { sndFile.Chn[i].nGlobalVol = smp.nGlobalVol; } @@ -714,7 +714,7 @@ smp.uFlags.reset(CHN_STEREO); for (CHANNELINDEX i = 0; i < MAX_CHANNELS; i++) { - if(sndFile.Chn[i].pSample == smp.pSample) + if(sndFile.Chn[i].pModSample == &smp) { sndFile.Chn[i].dwFlags.reset(CHN_STEREO); } @@ -733,7 +733,7 @@ { void ReplaceSample( ModChannel (&Chn)[MAX_CHANNELS], - const void * const pOldSample, + const ModSample * const pSample, const void * const pNewSample, const SmpLength nNewLength, FlagSet<ChannelFlags> setFlags, @@ -741,9 +741,8 @@ { for (CHANNELINDEX i = 0; i < MAX_CHANNELS; i++) { - if (Chn[i].pSample == pOldSample) + if (Chn[i].pModSample == pSample) { - Chn[i].pSample = pNewSample; if (Chn[i].pCurrentSample != nullptr) Chn[i].pCurrentSample = pNewSample; if (Chn[i].nPos > nNewLength) Modified: trunk/OpenMPT/soundlib/modsmp_ctrl.h =================================================================== --- trunk/OpenMPT/soundlib/modsmp_ctrl.h 2014-02-01 23:53:08 UTC (rev 3626) +++ trunk/OpenMPT/soundlib/modsmp_ctrl.h 2014-02-02 01:18:44 UTC (rev 3627) @@ -91,7 +91,7 @@ // Replaces sample from sound channels by given sample. void ReplaceSample( ModChannel (&Chn)[MAX_CHANNELS], - const void * const pOldSample, + const ModSample * const pSample, const void * const pNewSample, const SmpLength nNewLength, FlagSet<ChannelFlags> setFlags, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |