From: <sag...@us...> - 2013-05-20 16:37:36
|
Revision: 2148 http://sourceforge.net/p/modplug/code/2148 Author: saga-games Date: 2013-05-20 16:37:28 +0000 (Mon, 20 May 2013) Log Message: ----------- [Imp] Sample frequency is now 28.4 fixed point internally. Modified Paths: -------------- trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/soundlib/Snd_defs.h trunk/OpenMPT/soundlib/Snd_fx.cpp trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2013-05-20 13:39:23 UTC (rev 2147) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2013-05-20 16:37:28 UTC (rev 2148) @@ -2041,9 +2041,9 @@ BeginWaitCursor(); if ((pModDoc) && (m_nSample <= pModDoc->GetNumSamples())) { - CSoundFile *pSndFile = pModDoc->GetSoundFile(); - ModSample &sample = pSndFile->GetSample(m_nSample); - if ((sample.uFlags & CHN_16BIT) && (sample.pSample) && (sample.nLength)) + CSoundFile &sndFile = pModDoc->GetrSoundFile(); + ModSample &sample = sndFile.GetSample(m_nSample); + if(sample.uFlags[CHN_16BIT] && sample.pSample != nullptr && sample.nLength != 0) { pModDoc->GetSampleUndo().PrepareUndo(m_nSample, sundo_replace); @@ -2056,9 +2056,9 @@ p[i] = (signed char) ((*((short int *)(p+i*2))) / 256); } sample.uFlags.reset(CHN_16BIT); - for (UINT j=0; j<MAX_CHANNELS; j++) if (pSndFile->Chn[j].pSample == sample.pSample) + for (UINT j=0; j<MAX_CHANNELS; j++) if (sndFile.Chn[j].pSample == sample.pSample) { - pSndFile->Chn[j].dwFlags.reset(CHN_16BIT); + sndFile.Chn[j].dwFlags.reset(CHN_16BIT); } cs.Leave(); @@ -2152,12 +2152,12 @@ //nothing loaded or invalid sample slot. if(!pModDoc || m_nSample > pModDoc->GetNumSamples()) return; - CSoundFile *pSndFile = pModDoc->GetSoundFile(); - ModSample &sample = pSndFile->GetSample(m_nSample); + CSoundFile &sndFile = pModDoc->GetrSoundFile(); + ModSample &sample = sndFile.GetSample(m_nSample); if(m_dwBeginSel == m_dwEndSel) { - // Trim around loop points if there's no selection (http://forum.openmpt.org/index.php?topic=2258.0) + // Trim around loop points if there's no selection m_dwBeginSel = sample.nLoopStart; m_dwEndSel = sample.nLoopEnd; } @@ -2231,7 +2231,6 @@ } else { - CHAR s[64]; if (m_dwStatus & SMPSTATUS_KEYDOWN) pModDoc->NoteOff(note, true); else @@ -2244,15 +2243,13 @@ pModDoc->PlayNote(note, 0, m_nSample, false, -1, loopstart, loopend, CHANNELINDEX_INVALID, nStartPos); m_dwStatus |= SMPSTATUS_KEYDOWN; - s[0] = 0; - if(ModCommand::IsNote((ModCommand::NOTE)note)) - { - CSoundFile *pSndFile = pModDoc->GetSoundFile(); - ModSample &sample = pSndFile->GetSample(m_nSample); - uint32 freq = pSndFile->GetFreqFromPeriod(pSndFile->GetPeriodFromNote(note + (pSndFile->GetType() == MOD_TYPE_XM ? sample.RelativeTone : 0), sample.nFineTune, sample.nC5Speed), sample.nC5Speed, 0); - wsprintf(s, "%s (%d Hz)", szDefaultNoteNames[note - 1], freq); - } + CSoundFile &sndFile = pModDoc->GetrSoundFile(); + ModSample &sample = sndFile.GetSample(m_nSample); + uint32 freq = sndFile.GetFreqFromPeriod(pSndFile->GetPeriodFromNote(note + (pSndFile->GetType() == MOD_TYPE_XM ? sample.RelativeTone : 0), sample.nFineTune, sample.nC5Speed), sample.nC5Speed, 0); + + CHAR s[32]; + wsprintf(s, "%s (%d.%d Hz)", szDefaultNoteNames[note - 1], freq >> FREQ_FRACBITS, Util::muldiv(freq & ((1 << FREQ_FRACBITS) - 1), 100, 1 << FREQ_FRACBITS)); pMainFrm->SetInfoText(s); } } Modified: trunk/OpenMPT/soundlib/Snd_defs.h =================================================================== --- trunk/OpenMPT/soundlib/Snd_defs.h 2013-05-20 13:39:23 UTC (rev 2147) +++ trunk/OpenMPT/soundlib/Snd_defs.h 2013-05-20 16:37:28 UTC (rev 2148) @@ -62,6 +62,8 @@ #define MIN_PERIOD 0x0020 // Note: Period is an Amiga metric that is inverse to frequency. #define MAX_PERIOD 0xFFFF // Periods in MPT are 4 times as fine as Amiga periods because of extra fine frequency slides. +#define FREQ_FRACBITS 4 // Number of fractional bits in return value of CSoundFile::GetFreqFromPeriod() + // String lengths (including trailing null char) #define MAX_SAMPLENAME 32 // also affects module name! #define MAX_SAMPLEFILENAME 22 Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-05-20 13:39:23 UTC (rev 2147) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-05-20 16:37:28 UTC (rev 2148) @@ -4681,13 +4681,14 @@ } +// Converts period value to sample frequency. Return value is fixed point, with FREQ_FRACBITS fractional bits. UINT CSoundFile::GetFreqFromPeriod(UINT period, UINT nC5Speed, int nPeriodFrac) const //----------------------------------------------------------------------------------- { if (!period) return 0; if (GetType() & (MOD_TYPE_MED|MOD_TYPE_MOD|MOD_TYPE_DIGI|MOD_TYPE_MTM|MOD_TYPE_669|MOD_TYPE_AMF0)) { - return (3546895L*4) / period; + return ((3546895L * 4) << FREQ_FRACBITS) / period; } else if (GetType() == MOD_TYPE_XM) { if(m_SongFlags[SONG_LINEARSLIDES]) @@ -4703,20 +4704,20 @@ uint32 div = ((9216u + 767u - (period & 0xFFFF)) / 768); octave = ((12 - div) & 0x1F) % 29u; } - return XMLinearTable[period % 768] >> octave; + return (XMLinearTable[period % 768] << FREQ_FRACBITS) >> octave; } else { - return 8363 * 1712L / period; + return ((8363 * 1712L) << FREQ_FRACBITS) / period; } } else { if(m_SongFlags[SONG_LINEARSLIDES]) { if (!nC5Speed) nC5Speed = 8363; - return Util::muldiv(nC5Speed, 1712L << 8, (period << 8)+nPeriodFrac); + return Util::muldiv(nC5Speed, (1712L << 8) << FREQ_FRACBITS, (period << 8) + nPeriodFrac); } else { - return Util::muldiv(8363, 1712L << 8, (period << 8)+nPeriodFrac); + return Util::muldiv(8363, (1712L << 8) << FREQ_FRACBITS, (period << 8) + nPeriodFrac); } } } Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-05-20 13:39:23 UTC (rev 2147) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-05-20 16:37:28 UTC (rev 2148) @@ -1761,7 +1761,7 @@ { if(IsCompatibleMode(TRK_IMPULSETRACKER)) { - // In IT and FT2 compatible mode, envelope position indices are shifted by one for proper envelope pausing, + // In IT compatible mode, envelope position indices are shifted by one for proper envelope pausing, // so we have to update the position before we actually process the envelopes. // When using MPT behaviour, we get the envelope position for the next tick while we are still calculating the current tick, // which then results in wrong position information when the envelope is paused on the next row. @@ -1882,7 +1882,7 @@ // In this case: GetType() == MOD_TYPE_MPT and using custom tunings. if(pChn->m_CalculateFreq || (pChn->m_ReCalculateFreqOnFirstTick && m_nTickCount == 0)) { - pChn->m_Freq = Util::Round<UINT>(pChn->nC5Speed * vibratoFactor * pIns->pTuning->GetRatio(pChn->nNote - NOTE_MIDDLEC + arpeggioSteps, pChn->nFineTune+pChn->m_PortamentoFineSteps)); + pChn->m_Freq = Util::Round<uint32>((pChn->nC5Speed << FREQ_FRACBITS) * vibratoFactor * pIns->pTuning->GetRatio(pChn->nNote - NOTE_MIDDLEC + arpeggioSteps, pChn->nFineTune+pChn->m_PortamentoFineSteps)); if(!pChn->m_CalculateFreq) pChn->m_ReCalculateFreqOnFirstTick = false; else @@ -1906,7 +1906,7 @@ pChn->nCalcVolume = 0; } - int32 ninc = Util::muldiv(freq, 0x10000, m_MixerSettings.gdwMixingFreq); + int32 ninc = Util::muldiv(freq, 0x10000, m_MixerSettings.gdwMixingFreq << FREQ_FRACBITS); if ((ninc >= 0xFFB0) && (ninc <= 0x10090)) ninc = 0x10000; if (m_nFreqFactor != 128) ninc = (ninc * m_nFreqFactor) >> 7; Limit(ninc, 3, 0xFF0000); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |