From: <man...@us...> - 2013-06-03 20:18:57
|
Revision: 2299 http://sourceforge.net/p/modplug/code/2299 Author: manxorist Date: 2013-06-03 20:18:48 +0000 (Mon, 03 Jun 2013) Log Message: ----------- [Ref] Fix UINT to CHANNELINDEX conversion warning in Fastmix.cpp. [Fix] ASSERT(lCount <= MIXBUFFERSIZE) before we fill the buffer. [Ref] Cleanup mixer statistics calculation. [Ref] Transfer mixer statistics via Notification system. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Notification.h trunk/OpenMPT/soundlib/Fastmix.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-06-03 20:18:48 UTC (rev 2299) @@ -975,8 +975,6 @@ notifyType = m_pSndFile->m_pModDoc->GetNotificationType(); notifyItem = m_pSndFile->m_pModDoc->GetNotificationItem(); } - if(m_nMixChn < m_pSndFile->m_nMixStat) m_nMixChn++; - if(m_nMixChn > m_pSndFile->m_nMixStat) m_nMixChn--; // Notify Client //if(m_NotifyBuffer.read_size() > 0) { @@ -984,7 +982,7 @@ } // Add an entry to the notification history - Notification notification(notifyType, notifyItem, notificationtimestamp, m_pSndFile->m_nRow, m_pSndFile->m_nTickCount, m_pSndFile->m_nCurrentOrder, m_pSndFile->m_nPattern); + Notification notification(notifyType, notifyItem, notificationtimestamp, m_pSndFile->m_nRow, m_pSndFile->m_nTickCount, m_pSndFile->m_nCurrentOrder, m_pSndFile->m_nPattern, m_pSndFile->m_nMixStat); if(endOfStream) notification.type.set(Notification::EOS); @@ -1322,8 +1320,6 @@ if(m_pSndFile) { m_pSndFile->SuspendPlugins(); - m_nMixChn = 0; - m_nAvgMixChn = 0; if(m_pSndFile->GetpModDoc()) { m_wndTree.UpdatePlayPos(m_pSndFile->GetpModDoc(), nullptr); @@ -1398,8 +1394,6 @@ gnLVuMeter = gnRVuMeter = 0; gnClipLeft = gnClipRight = false; - m_nMixChn = 0; - m_nAvgMixChn = 0; if(!StartPlayback()) { @@ -2305,6 +2299,7 @@ if (GetFollowSong()) ::SendMessage(GetFollowSong(), WM_MOD_UPDATEPOSITION, 0, lParam); } + m_nMixChn = pnotify->mixedChannels; m_wndToolBar.m_VuMeter.SetVuMeter(pnotify->masterVU[0], pnotify->masterVU[1], pnotify->type[Notification::Stop]); } return 0; Modified: trunk/OpenMPT/mptrack/Notification.h =================================================================== --- trunk/OpenMPT/mptrack/Notification.h 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/mptrack/Notification.h 2013-06-03 20:18:48 UTC (rev 2299) @@ -47,10 +47,11 @@ uint32 tick; // dito ORDERINDEX order; // dito PATTERNINDEX pattern; // dito + uint32 mixedChannels; // dito uint32 masterVU[2]; // dito SmpLength pos[MAX_CHANNELS]; // Sample / envelope pos for each channel if != PosInvalid, or pattern channel VUs - Notification(Type t = Default, Item i = 0, int64 s = 0, ROWINDEX r = 0, uint32 ti = 0, ORDERINDEX o = 0, PATTERNINDEX p = 0) : timestampSamples(s), type(t), item(i), row(r), tick(ti), order(o), pattern(p) + Notification(Type t = Default, Item i = 0, int64 s = 0, ROWINDEX r = 0, uint32 ti = 0, ORDERINDEX o = 0, PATTERNINDEX p = 0, uint32 x = 0) : timestampSamples(s), type(t), item(i), row(r), tick(ti), order(o), pattern(p), mixedChannels(x) { MemsetZero(masterVU); } Modified: trunk/OpenMPT/soundlib/Fastmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-03 20:18:48 UTC (rev 2299) @@ -1441,17 +1441,17 @@ -UINT CSoundFile::CreateStereoMix(int count) +void CSoundFile::CreateStereoMix(int count) //----------------------------------------- { LPLONG pOfsL, pOfsR; - DWORD nchused, nchmixed; + CHANNELINDEX nchused, nchmixed; - if (!count) return 0; + if (!count) return; bool ITPingPongMode = IsITPingPongMode(); if (m_MixerSettings.gnChannels > 2) InitMixBuffer(MixRearBuffer, count*2); nchused = nchmixed = 0; - for (UINT nChn=0; nChn<m_nMixChannels; nChn++) + for(CHANNELINDEX nChn=0; nChn<m_nMixChannels; nChn++) { const LPMIXINTERFACE *pMixFuncTable; ModChannel * const pChannel = &Chn[ChnMix[nChn]]; @@ -1548,7 +1548,7 @@ continue; } // Should we mix this channel ? - UINT naddmix; + bool addmix; if (((nchmixed >= m_MixerSettings.m_nMaxMixChannels) && !IsRenderingToDisc()) || ((!pChannel->nRampLength) && (!(pChannel->rightVol|pChannel->leftVol)))) { @@ -1557,7 +1557,7 @@ pChannel->nPos += (delta >> 16); pChannel->nROfs = pChannel->nLOfs = 0; pbuffer += nSmpCount*2; - naddmix = 0; + addmix = false; } else // Do mixing { @@ -1571,7 +1571,7 @@ pChannel->nROfs += *(pbufmax-2); pChannel->nLOfs += *(pbufmax-1); pbuffer = pbufmax; - naddmix = 1; + addmix = true; } nsamples -= nSmpCount; if (pChannel->nRampLength) @@ -1591,9 +1591,9 @@ } } if (nsamples > 0) goto SampleLooping; - nchmixed += naddmix; + nchmixed += addmix?1:0; } - return nchused; + m_nMixStat += nchused; } Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-03 20:18:48 UTC (rev 2299) @@ -336,7 +336,8 @@ INSTRUMENTINDEX m_nInstruments; UINT m_nDefaultSpeed, m_nDefaultTempo, m_nDefaultGlobalVolume; FlagSet<SongFlags> m_SongFlags; - UINT m_nMixChannels, m_nMixStat; + CHANNELINDEX m_nMixChannels; + UINT m_nMixStat; samplecount_t m_nBufferCount; double m_dBufferDiff; UINT m_nTickCount; @@ -371,7 +372,7 @@ LONG m_nRepeatCount; // -1 means repeat infinitely. DWORD m_nGlobalFadeSamples, m_nGlobalFadeMaxSamples; UINT m_nMaxOrderPosition; - UINT ChnMix[MAX_CHANNELS]; // Channels to be mixed + CHANNELINDEX ChnMix[MAX_CHANNELS]; // Channels to be mixed ModChannel Chn[MAX_CHANNELS]; // Mixing channels... First m_nChannel channels are master channels (i.e. they are never NNA channels)! ModChannelSettings ChnSettings[MAX_BASECHANNELS]; // Initial channels settings CPatternContainer Patterns; // Patterns @@ -596,7 +597,7 @@ void RecalculateGainForAllPlugs(); void ResetChannels(); UINT Read(LPVOID lpBuffer, UINT cbBuffer, void * const *outputBuffers = nullptr); - UINT CreateStereoMix(int count); + void CreateStereoMix(int count); BOOL FadeSong(UINT msec); BOOL GlobalFadeSong(UINT msec); void ProcessPlugins(UINT nCount); Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-03 20:18:48 UTC (rev 2299) @@ -202,13 +202,13 @@ LPCONVERTPROC pCvt = nullptr; samplecount_t lMax, lCount, lSampleCount; size_t lSampleSize; - UINT nStat = 0; UINT nMaxPlugins; std::size_t renderedCount = 0; nMaxPlugins = MAX_MIXPLUGINS; while ((nMaxPlugins > 0) && (!m_MixPlugins[nMaxPlugins-1].pMixPlugin)) nMaxPlugins--; - m_nMixStat = 0; + + UINT nMixStatCount = 0; lSampleSize = m_MixerSettings.gnChannels; switch(m_MixerSettings.m_SampleFormat) @@ -279,20 +279,28 @@ if (!lCount) break; + ASSERT(lCount <= MIXBUFFERSIZE); // ensure MIXBUFFERSIZE really is our max buffer size + lSampleCount = lCount; #ifndef NO_REVERB m_Reverb.gnReverbSend = 0; #endif // NO_REVERB + if(nMixStatCount == 0) + { + // reset mixer channel count before we are calling CreateStereoMix the first time this round, if we are not updating the mixer state, we do not reset statistics + m_nMixStat = 0; + } + nMixStatCount++; + // Resetting sound buffer StereoFill(MixSoundBuffer, lCount, &gnDryROfsVol, &gnDryLOfsVol); - ASSERT(lCount<=MIXBUFFERSIZE); // ensure MIXBUFFERSIZE really is our max buffer size if (m_MixerSettings.gnChannels >= 2) { lSampleCount *= 2; - m_nMixStat += CreateStereoMix(lCount); + CreateStereoMix(lCount); #ifndef NO_REVERB m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount, GetProcSupport()); @@ -307,7 +315,7 @@ } } else { - m_nMixStat += CreateStereoMix(lCount); + CreateStereoMix(lCount); #ifndef NO_REVERB m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount, GetProcSupport()); @@ -338,8 +346,6 @@ } #endif // NO_EQ - nStat++; - #ifndef MODPLUG_TRACKER if(!m_MixerSettings.IsFloatSampleFormat()) { @@ -431,7 +437,10 @@ } MixDone: if (lRead && lpBuffer) memset(lpBuffer, (m_MixerSettings.m_SampleFormat == SampleFormatUnsigned8) ? 0x80 : 0, lRead * lSampleSize); // clear remaining interleaved output buffer - if (nStat) { m_nMixStat += nStat-1; m_nMixStat /= nStat; } + if(nMixStatCount > 0) + { + m_nMixStat = (m_nMixStat + nMixStatCount - 1) / nMixStatCount; // round up + } return renderedCount; } @@ -2113,12 +2122,12 @@ // Checking Max Mix Channels reached: ordering by volume if ((m_nMixChannels >= m_MixerSettings.m_nMaxMixChannels) && !IsRenderingToDisc()) { - for (UINT i=0; i<m_nMixChannels; i++) + for(CHANNELINDEX i=0; i<m_nMixChannels; i++) { - UINT j=i; + CHANNELINDEX j=i; while ((j+1<m_nMixChannels) && (Chn[ChnMix[j]].nRealVolume < Chn[ChnMix[j+1]].nRealVolume)) { - UINT n = ChnMix[j]; + CHANNELINDEX n = ChnMix[j]; ChnMix[j] = ChnMix[j+1]; ChnMix[j+1] = n; j++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |