|
From: <man...@us...> - 2013-05-02 23:29:05
|
Revision: 2005
http://sourceforge.net/p/modplug/code/2005
Author: manxorist
Date: 2013-05-02 23:28:58 +0000 (Thu, 02 May 2013)
Log Message:
-----------
[Fix] Fix volume ramping on samples played on the first row/tick of a song. In r188, a fix for an audible click on song start when the global volume was >0 and got set to 0 right in the first row was commited (see http://forum.openmpt.org/index.php?topic=523.0 ). This completely disabled not only global volume ramping but also sample volume ramping for all samples triggered directly at song start. The new fix works by checking if the global volume was unset before (which is afaik only the case at song start (so, IsGlobalVolumeUnset() just returns IsFirstTick()). In this case, the global volume is directly applyed and any global volume ramping is skipped.
[Fix] Also reset global volume ramping state when SetCurrentPos(0) is called.
Revision Links:
--------------
http://sourceforge.net/p/modplug/code/188
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Sndfile.cpp
trunk/OpenMPT/soundlib/Sndfile.h
trunk/OpenMPT/soundlib/Sndmix.cpp
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-05-01 21:47:50 UTC (rev 2004)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-05-02 23:28:58 UTC (rev 2005)
@@ -406,7 +406,6 @@
MemsetZero(MixFloatBuffer);
gnDryLOfsVol = 0;
gnDryROfsVol = 0;
- gnVolumeRampUpSamplesActual = 42;
m_nType = MOD_TYPE_NONE;
m_nChannels = 0;
m_nMixChannels = 0;
@@ -933,11 +932,18 @@
for (CHANNELINDEX i = 0; i < MAX_CHANNELS; i++)
Chn[i].Reset(resetMask, *this, i);
- if (!nPos)
+ if(nPos == 0)
{
m_nGlobalVolume = m_nDefaultGlobalVolume;
m_nMusicSpeed = m_nDefaultSpeed;
m_nMusicTempo = m_nDefaultTempo;
+
+ // do not ramp global volume when starting playback
+ m_lHighResRampingGlobalVolume = m_nGlobalVolume<<VOLUMERAMPPRECISION;
+ m_nGlobalVolumeDestination = m_nGlobalVolume;
+ m_nSamplesToGlobalVolRampDest = 0;
+ m_nGlobalVolumeRampAmount = 0;
+
visitedSongRows.Initialize(true);
}
m_SongFlags.reset(SONG_FADINGSONG | SONG_ENDREACHED | SONG_GLOBALFADE);
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2013-05-01 21:47:50 UTC (rev 2004)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2013-05-02 23:28:58 UTC (rev 2005)
@@ -297,7 +297,7 @@
#ifndef NO_AGC
CAGC m_AGC;
#endif
- UINT gnVolumeRampUpSamplesActual;
+
#ifdef MODPLUG_TRACKER
static LPSNDMIXHOOKPROC gpSndMixHook;
#endif
@@ -342,6 +342,7 @@
UINT m_nGlobalVolume, m_nSamplesToGlobalVolRampDest, m_nGlobalVolumeRampAmount,
m_nGlobalVolumeDestination, m_nSamplePreAmp, m_nVSTiVolume;
long m_lHighResRampingGlobalVolume;
+ bool IsGlobalVolumeUnset() const { return IsFirstTick(); }
UINT m_nFreqFactor, m_nTempoFactor, m_nOldGlbVolSlide;
LONG m_nMinPeriod, m_nMaxPeriod; // min period = highest possible frequency, max period = lowest possible frequency
LONG m_nRepeatCount; // -1 means repeat infinitely.
@@ -459,6 +460,7 @@
const char *GetInstrumentName(INSTRUMENTINDEX nInstr) const;
UINT GetMusicSpeed() const { return m_nMusicSpeed; }
UINT GetMusicTempo() const { return m_nMusicTempo; }
+ bool IsFirstTick() const { return (m_lTotalSampleCount == 0); }
//Get modlength in various cases: total length, length to
//specific order&row etc. Return value is in seconds.
Modified: trunk/OpenMPT/soundlib/Sndmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-05-01 21:47:50 UTC (rev 2004)
+++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-05-02 23:28:58 UTC (rev 2005)
@@ -88,9 +88,6 @@
void CSoundFile::SetMixerSettings(const MixerSettings &mixersettings)
//-------------------------------------------------------------------
{
- // Start with ramping disabled to avoid clicks on first read.
- // Ramping is now set after the first read in CSoundFile::Read();
- gnVolumeRampUpSamplesActual = 0;
SetPreAmp(mixersettings.m_nPreAmp); // adjust agc
bool reset = false;
if(
@@ -379,8 +376,6 @@
lRead -= lCount;
m_nBufferCount -= lCount;
m_lTotalSampleCount += lCount; // increase sample count for VSTTimeInfo.
- // Turn on ramping after first read (fix http://forum.openmpt.org/index.php?topic=523.0 )
- gnVolumeRampUpSamplesActual = m_MixerSettings.glVolumeRampUpSamples;
}
MixDone:
if (lRead) memset(lpBuffer, (m_MixerSettings.m_SampleFormat == SampleFormatUnsigned8) ? 0x80 : 0, lRead * lSampleSize);
@@ -1571,7 +1566,7 @@
{
const bool rampUp = (pChn->newLeftVol > pChn->leftVol) || (pChn->newRightVol > pChn->rightVol);
int32 rampLength, globalRampLength, instrRampLength = 0;
- rampLength = globalRampLength = (rampUp ? gnVolumeRampUpSamplesActual : m_MixerSettings.glVolumeRampDownSamples);
+ rampLength = globalRampLength = (rampUp ? m_MixerSettings.glVolumeRampUpSamples : m_MixerSettings.glVolumeRampDownSamples);
//XXXih: add real support for bidi ramping here
if(pChn->pModInstrument != nullptr && rampUp)
@@ -2234,12 +2229,18 @@
{
long step = 0;
- if (m_nGlobalVolumeDestination != m_nGlobalVolume)
+ if(IsGlobalVolumeUnset())
{
+ // do not ramp if no global volume was set before (which is the case at song start), to prevent audible glitches when default volume is > 0 and it is set to 0 in the first row
+ m_nGlobalVolumeDestination = m_nGlobalVolume;
+ m_nSamplesToGlobalVolRampDest = 0;
+ m_nGlobalVolumeRampAmount = 0;
+ } else if(m_nGlobalVolumeDestination != m_nGlobalVolume)
+ {
// User has provided new global volume
const bool rampUp = m_nGlobalVolumeDestination > m_nGlobalVolume;
m_nGlobalVolumeDestination = m_nGlobalVolume;
- m_nSamplesToGlobalVolRampDest = m_nGlobalVolumeRampAmount = rampUp ? gnVolumeRampUpSamplesActual : m_MixerSettings.glVolumeRampDownSamples;
+ m_nSamplesToGlobalVolRampDest = m_nGlobalVolumeRampAmount = rampUp ? m_MixerSettings.glVolumeRampUpSamples : m_MixerSettings.glVolumeRampDownSamples;
}
if (m_nSamplesToGlobalVolRampDest > 0)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|