From: <sag...@us...> - 2012-01-08 22:04:40
|
Revision: 1162 http://modplug.svn.sourceforge.net/modplug/?rev=1162&view=rev Author: saga-games Date: 2012-01-08 22:04:33 +0000 (Sun, 08 Jan 2012) Log Message: ----------- [Ref] Refactored some plugin mixing code [Mod] Minor other changes Modified Paths: -------------- trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/soundlib/MIDIMacros.cpp trunk/OpenMPT/soundlib/PluginMixBuffer.h trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2012-01-08 21:28:20 UTC (rev 1161) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2012-01-08 22:04:33 UTC (rev 1162) @@ -2060,37 +2060,18 @@ } -void CVstPlugin::Process(float *pOutL, float *pOutR, unsigned long nSamples) -//-------------------------------------------------------------------------- +void CVstPlugin::Process(float *pOutL, float *pOutR, size_t nSamples) +//------------------------------------------------------------------- { - float wetRatio, dryRatio; // rewbs.dryRatio [20040123] - ProcessVSTEvents(); -// -> DESC="effect plugin mixing mode combo" -// -> mixop == 0 : normal processing -// -> mixop == 1 : MIX += DRY - WET * wetRatio -// -> mixop == 2 : MIX += WET - DRY * dryRatio -// -> mixop == 3 : MIX -= WET - DRY * wetRatio -// -> mixop == 4 : MIX -= middle - WET * wetRatio + middle - DRY -// -> mixop == 5 : MIX_L += wetRatio * (WET_L - DRY_L) + dryRatio * (DRY_R - WET_R) -// MIX_R += dryRatio * (WET_L - DRY_L) + wetRatio * (DRY_R - WET_R) - //If the plug is found & ok, continue if ((m_pEffect) && (m_pProcessFP) && (mixBuffer.GetInputBufferArray()) && (mixBuffer.GetOutputBufferArray()) && (m_pMixStruct)) { - int mixop; - if (m_bIsInstrument) - { - mixop = 0; //force normal mix mode for instruments - } else - { - mixop = m_pMixStruct ? (m_pMixStruct->Info.dwInputRouting>>8) & 0xff : 0; - } //RecalculateGain(); - //Merge stereo input before sending to the plug if the plug can only handle one input. + // Merge stereo input before sending to the plug if the plug can only handle one input. if (m_pEffect->numInputs == 1) { for (size_t i = 0; i < nSamples; i++) @@ -2103,7 +2084,7 @@ mixBuffer.ClearOutputBuffers(nSamples); m_dwTimeAtStartOfProcess = timeGetTime(); - //Do the VST processing magic + // Do the VST processing magic try { ASSERT(nSamples <= MIXBUFFERSIZE); @@ -2119,8 +2100,8 @@ ASSERT(outputBuffers != nullptr); - //mix outputs of multi-output VSTs: - if(m_nOutputs>2) + // Mix outputs of multi-output VSTs: + if(m_nOutputs > 2) { // first, mix extra outputs on a stereo basis UINT nOuts = m_nOutputs; @@ -2130,15 +2111,17 @@ // mix extra stereo outputs for(UINT iOut = 2; iOut < nOuts; iOut++) { - for(UINT i = 0; i < nSamples; i++) - outputBuffers[iOut % 2][i] += outputBuffers[iOut][i]; //assumed stereo. + for(size_t i = 0; i < nSamples; i++) + { + outputBuffers[iOut % 2][i] += outputBuffers[iOut][i]; // assumed stereo. + } } // if m_nOutputs is odd, mix half the signal of last output to each channel if(nOuts != m_nOutputs) { // trick : if we are here, nOuts = m_nOutputs - 1 !!! - for(UINT i=0; i<nSamples; i++) + for(size_t i = 0; i < nSamples; i++) { float v = 0.5f * outputBuffers[nOuts][i]; outputBuffers[0][i] += v; @@ -2147,237 +2130,141 @@ } } - // If there was just the one plugin output we copy it into our 2 outputs - if(m_pEffect->numOutputs == 1) - { - wetRatio = 1 - m_pMixStruct->fDryRatio; //rewbs.dryRatio - dryRatio = m_bIsInstrument ? 1 : m_pMixStruct->fDryRatio; //always mix full dry if this is an instrument + ProcessMixOps(pOutL, pOutR, nSamples); -// -> CODE#0028 -// -> DESC="effect plugin mixing mode combo" -/* - for (UINT i=0; i<nSamples; i++) + // If dry mix is ticked, we add the unprocessed buffer, + // except if this is an instrument since this it has already been done: + if((m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_WETMIX) && !m_bIsInstrument) + { + for(size_t i = 0; i < nSamples; i++) { - //rewbs.wetratio - added the factors. [20040123] - pOutL[i] += outputBuffers[0][i]*wetRatio + m_MixState.pOutBufferL[i]*dryRatio; - pOutR[i] += outputBuffers[0][i]*wetRatio + m_MixState.pOutBufferR[i]*dryRatio; - - //If dry mix is ticked we add the unprocessed buffer, - //except if this is an instrument since this it already been done: - if ((m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_WETMIX) && !isInstrument) - { - pOutL[i] += m_MixState.pOutBufferL[i]; - pOutR[i] += m_MixState.pOutBufferR[i]; - } + pOutL[i] += m_MixState.pOutBufferL[i]; + pOutR[i] += m_MixState.pOutBufferR[i]; } -*/ - // Wet/Dry range expansion [0,1] -> [-1,1] update#02 - if(m_pEffect->numInputs > 0 && m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_MIXEXPAND) - { - wetRatio = 2.0f * wetRatio - 1.0f; - dryRatio = -wetRatio; - } + } + } - wetRatio *= m_fGain; // update#02 - dryRatio *= m_fGain; // update#02 + ClearVSTEvents(); + //SetEvent(processCalled); +} - // Mix operation - switch(mixop) - { - // Default mix (update#02) - case 0: - for(UINT i = 0; i < nSamples; i++) - { - //rewbs.wetratio - added the factors. [20040123] - pOutL[i] += outputBuffers[0][i]*wetRatio + m_MixState.pOutBufferL[i]*dryRatio; - pOutR[i] += outputBuffers[0][i]*wetRatio + m_MixState.pOutBufferR[i]*dryRatio; - } - break; +void CVstPlugin::ProcessMixOps(float *pOutL, float *pOutR, size_t nSamples) +//------------------------------------------------------------------------- +{ + float *leftPlugOutput; + float *rightPlugOutput; - // Wet subtract - case 1: - for(UINT i = 0; i < nSamples; i++) - { - pOutL[i] += m_MixState.pOutBufferL[i] - outputBuffers[0][i]*wetRatio; - pOutR[i] += m_MixState.pOutBufferR[i] - outputBuffers[0][i]*wetRatio; - } - break; + if(m_pEffect->numOutputs == 1) + { + // If there was just the one plugin output we copy it into our 2 outputs + leftPlugOutput = rightPlugOutput = mixBuffer.GetOutputBuffer(0); + } else if(m_pEffect->numOutputs > 1) + { + // Otherwise we actually only cater for two outputs max (outputs > 2 have been mixed together already). + leftPlugOutput = mixBuffer.GetOutputBuffer(0); + rightPlugOutput = mixBuffer.GetOutputBuffer(1); + } else + { + return; + } - // Dry subtract - case 2: - for(UINT i = 0; i < nSamples; i++) - { - pOutL[i] += outputBuffers[0][i] - m_MixState.pOutBufferL[i]*dryRatio; - pOutR[i] += outputBuffers[0][i] - m_MixState.pOutBufferR[i]*dryRatio; - } - break; + // -> mixop == 0 : normal processing + // -> mixop == 1 : MIX += DRY - WET * wetRatio + // -> mixop == 2 : MIX += WET - DRY * dryRatio + // -> mixop == 3 : MIX -= WET - DRY * wetRatio + // -> mixop == 4 : MIX -= middle - WET * wetRatio + middle - DRY + // -> mixop == 5 : MIX_L += wetRatio * (WET_L - DRY_L) + dryRatio * (DRY_R - WET_R) + // MIX_R += dryRatio * (WET_L - DRY_L) + wetRatio * (DRY_R - WET_R) - // Mix subtract - case 3: - for(UINT i = 0; i < nSamples; i++) - { - pOutL[i] -= outputBuffers[0][i] - m_MixState.pOutBufferL[i]*wetRatio; - pOutR[i] -= outputBuffers[0][i] - m_MixState.pOutBufferR[i]*wetRatio; - } - break; + int mixop; + if(m_bIsInstrument) + { + mixop = 0; // Force normal mix mode for instruments + } else + { + mixop = m_pMixStruct ? (m_pMixStruct->Info.dwInputRouting >> 8) & 0xFF : 0; + } - // Middle subtract - case 4: - for(UINT i = 0; i < nSamples; i++) - { - float middle = ( pOutL[i] + m_MixState.pOutBufferL[i] + pOutR[i] + m_MixState.pOutBufferR[i] )/2.0f; - pOutL[i] -= middle - outputBuffers[0][i]*wetRatio + middle - m_MixState.pOutBufferL[i]; - pOutR[i] -= middle - outputBuffers[0][i]*wetRatio + middle - m_MixState.pOutBufferR[i]; - } - break; + float wetRatio = 1 - m_pMixStruct->fDryRatio; + float dryRatio = m_bIsInstrument ? 1 : m_pMixStruct->fDryRatio; // Always mix full dry if this is an instrument - // Left/Right balance - case 5: - if(m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_MIXEXPAND) - { - wetRatio /= 2.0f; - dryRatio /= 2.0f; - } - for(UINT i = 0; i < nSamples; i++) - { - pOutL[i] += wetRatio * (outputBuffers[0][i] - m_MixState.pOutBufferL[i]) + dryRatio * (m_MixState.pOutBufferR[i] - outputBuffers[0][i]); - pOutR[i] += dryRatio * (outputBuffers[0][i] - m_MixState.pOutBufferL[i]) + wetRatio * (m_MixState.pOutBufferR[i] - outputBuffers[0][i]); - } - break; - } + // Wet / Dry range expansion [0,1] -> [-1,1] + if(m_pEffect->numInputs > 0 && m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_MIXEXPAND) + { + wetRatio = 2.0f * wetRatio - 1.0f; + dryRatio = -wetRatio; + } - //If dry mix is ticked we add the unprocessed buffer, - //except if this is an instrument since this it has already been done: - if((m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_WETMIX) && !m_bIsInstrument) - { - for (UINT i=0; i<nSamples; i++) - { - pOutL[i] += m_MixState.pOutBufferL[i]; - pOutR[i] += m_MixState.pOutBufferR[i]; - } - } -// -! BEHAVIOUR_CHANGE#0028 + wetRatio *= m_fGain; + dryRatio *= m_fGain; + // Mix operation + switch(mixop) + { + + // Default mix + case 0: + for(size_t i = 0; i < nSamples; i++) + { + //rewbs.wetratio - added the factors. [20040123] + pOutL[i] += leftPlugOutput[i] * wetRatio + m_MixState.pOutBufferL[i] * dryRatio; + pOutR[i] += rightPlugOutput[i] * wetRatio + m_MixState.pOutBufferR[i] * dryRatio; } - //Otherwise we actually only cater for two outputs max. - else if (m_pEffect->numOutputs > 1) + break; + + // Wet subtract + case 1: + for(size_t i = 0; i < nSamples; i++) { - wetRatio = 1-m_pMixStruct->fDryRatio; //rewbs.dryRatio - dryRatio = m_bIsInstrument ? 1 : m_pMixStruct->fDryRatio; //always mix full dry if this is an instrument + pOutL[i] += m_MixState.pOutBufferL[i] - leftPlugOutput[i] * wetRatio; + pOutR[i] += m_MixState.pOutBufferR[i] - rightPlugOutput[i] * wetRatio; + } + break; -// -> CODE#0028 -// -> DESC="effect plugin mixing mode combo" -/* - for (UINT i=0; i<nSamples; i++) - { + // Dry subtract + case 2: + for(size_t i = 0; i < nSamples; i++) + { + pOutL[i] += leftPlugOutput[i] - m_MixState.pOutBufferL[i] * dryRatio; + pOutR[i] += rightPlugOutput[i] - m_MixState.pOutBufferR[i] * dryRatio; + } + break; - //rewbs.wetratio - added the factors. [20040123] + // Mix subtract + case 3: + for(size_t i = 0; i < nSamples; i++) + { + pOutL[i] -= leftPlugOutput[i] - m_MixState.pOutBufferL[i] * wetRatio; + pOutR[i] -= rightPlugOutput[i] - m_MixState.pOutBufferR[i] * wetRatio; + } + break; - pOutL[i] += outputBuffers[0][i]*wetRatio + m_MixState.pOutBufferL[i]*dryRatio; - pOutR[i] += outputBuffers[1][i]*wetRatio + m_MixState.pOutBufferR[i]*dryRatio; + // Middle subtract + case 4: + for(size_t i = 0; i < nSamples; i++) + { + float middle = (pOutL[i] + m_MixState.pOutBufferL[i] + pOutR[i] + m_MixState.pOutBufferR[i]) / 2.0f; + pOutL[i] -= middle - leftPlugOutput[i] * wetRatio + middle - m_MixState.pOutBufferL[i]; + pOutR[i] -= middle - rightPlugOutput[i] * wetRatio + middle - m_MixState.pOutBufferR[i]; + } + break; - //If dry mix is ticked, we add the unprocessed buffer, - //except if this is an instrument since it has already been done: - if ((m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_WETMIX) && !isInstrument) - { - pOutL[i] += m_MixState.pOutBufferL[i]; - pOutR[i] += m_MixState.pOutBufferR[i]; - } - } -*/ - // Wet/Dry range expansion [0,1] -> [-1,1] update#02 - if(m_pEffect->numInputs > 0 && m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_MIXEXPAND) - { - wetRatio = 2.0f * wetRatio - 1.0f; - dryRatio = -wetRatio; - } - - wetRatio *= m_fGain; // update#02 - dryRatio *= m_fGain; // update#02 - - // Mix operation - switch(mixop){ - - // Default mix (update#02) - case 0: - for(UINT i=0; i<nSamples; i++) - { - //rewbs.wetratio - added the factors. [20040123] - pOutL[i] += outputBuffers[0][i]*wetRatio + m_MixState.pOutBufferL[i]*dryRatio; - pOutR[i] += outputBuffers[1][i]*wetRatio + m_MixState.pOutBufferR[i]*dryRatio; - } - break; - - // Wet subtract - case 1: - for(UINT i=0; i<nSamples; i++) - { - pOutL[i] += m_MixState.pOutBufferL[i] - outputBuffers[0][i]*wetRatio; - pOutR[i] += m_MixState.pOutBufferR[i] - outputBuffers[1][i]*wetRatio; - } - break; - - // Dry subtract - case 2: - for(UINT i=0; i<nSamples; i++) - { - pOutL[i] += outputBuffers[0][i] - m_MixState.pOutBufferL[i]*dryRatio; - pOutR[i] += outputBuffers[1][i] - m_MixState.pOutBufferR[i]*dryRatio; - } - break; - - // Mix subtract - case 3: - for(UINT i=0; i<nSamples; i++) - { - pOutL[i] -= outputBuffers[0][i] - m_MixState.pOutBufferL[i]*wetRatio; - pOutR[i] -= outputBuffers[1][i] - m_MixState.pOutBufferR[i]*wetRatio; - } - break; - - // Middle subtract - case 4: - for(UINT i=0; i<nSamples; i++) - { - float middle = ( pOutL[i] + m_MixState.pOutBufferL[i] + pOutR[i] + m_MixState.pOutBufferR[i] )/2.0f; - pOutL[i] -= middle - outputBuffers[0][i]*wetRatio + middle - m_MixState.pOutBufferL[i]; - pOutR[i] -= middle - outputBuffers[1][i]*wetRatio + middle - m_MixState.pOutBufferR[i]; - } - break; - - // Left/Right balance - case 5: - if(m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_MIXEXPAND) - { - wetRatio /= 2.0f; - dryRatio /= 2.0f; - } - for(UINT i=0; i<nSamples; i++) - { - pOutL[i] += wetRatio * (outputBuffers[0][i] - m_MixState.pOutBufferL[i]) + dryRatio * (m_MixState.pOutBufferR[i] - outputBuffers[1][i]); - pOutR[i] += dryRatio * (outputBuffers[0][i] - m_MixState.pOutBufferL[i]) + wetRatio * (m_MixState.pOutBufferR[i] - outputBuffers[1][i]); - } - break; - } - - //If dry mix is ticked we add the unprocessed buffer, - //except if this is an instrument since this it has already been done: - if((m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_WETMIX) && !m_bIsInstrument) - { - for (UINT i=0; i<nSamples; i++) - { - pOutL[i] += m_MixState.pOutBufferL[i]; - pOutR[i] += m_MixState.pOutBufferR[i]; - } - } -// -! BEHAVIOUR_CHANGE#0028 + // Left / Right balance + case 5: + if(m_pMixStruct->Info.dwInputRouting & MIXPLUG_INPUTF_MIXEXPAND) + { + wetRatio /= 2.0f; + dryRatio /= 2.0f; } + for(size_t i = 0; i < nSamples; i++) + { + pOutL[i] += wetRatio * (leftPlugOutput[i] - m_MixState.pOutBufferL[i]) + dryRatio * (m_MixState.pOutBufferR[i] - rightPlugOutput[i]); + pOutR[i] += dryRatio * (leftPlugOutput[i] - m_MixState.pOutBufferL[i]) + wetRatio * (m_MixState.pOutBufferR[i] - rightPlugOutput[i]); + } + break; } - - ClearVSTEvents(); - //SetEvent(processCalled); } @@ -2464,13 +2351,13 @@ MidiSend(0xB0|mc|(0x7b<<8)); // all notes off MidiSend(0xB0|mc|(0x78<<8)); // all sounds off - for (UINT i=0; i<128; i++) //all notes + for (size_t i = 0; i < CountOf(pCh->uNoteOnMap); i++) //all notes { - for (UINT c=0; c<MAX_CHANNELS; c++) + for (CHANNELINDEX c = 0; c < CountOf(pCh->uNoteOnMap[i]); c++) { while (pCh->uNoteOnMap[i][c] && !overflow) { - overflow=!(MidiSend(dwMidiCode|(i<<8))); + overflow=!(MidiSend(dwMidiCode | (i << 8))); pCh->uNoteOnMap[i][c]--; } if (overflow) break; //yuck @@ -2502,19 +2389,13 @@ //------------------------------------------------------------------------------------------ { //Error checking - if (nController>127) - { - nController=127; - } - if (nParam>127) - { - nParam=127; - } + LimitMax(nController, 127u); + LimitMax(nParam, 127u); if(m_pSndFile && m_pSndFile->GetModFlag(MSF_MIDICC_BUGEMULATION)) - MidiSend(nController<<16 | nParam<<8 | 0xB0|nMidiCh); + MidiSend((nController << 16) | (nParam << 8) | (0xB0 | nMidiCh)); else - MidiSend(nParam<<16 | nController<<8 | 0xB0|nMidiCh); + MidiSend((nParam << 16) | (nController << 8) | (0xB0 | nMidiCh)); } short CVstPlugin::getMIDI14bitValueFromShort(short value) Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2012-01-08 21:28:20 UTC (rev 1161) +++ trunk/OpenMPT/mptrack/Vstplug.h 2012-01-08 22:04:33 UTC (rev 1162) @@ -82,8 +82,8 @@ VSTINSTCH m_MidiCh[16]; short m_nMidiPitchBendPos[16]; - int m_MixBuffer[MIXBUFFERSIZE*2+2]; // Stereo interleaved - PluginMixBuffer<float> mixBuffer; // Float buffers (input and output) for plugins + int m_MixBuffer[MIXBUFFERSIZE*2+2]; // Stereo interleaved + PluginMixBuffer<float, MIXBUFFERSIZE> mixBuffer; // Float buffers (input and output) for plugins VstMidiEvent m_ev_queue[VSTEVENT_QUEUE_LEN]; CModDoc* m_pModDoc; //rewbs.plugDocAware @@ -172,7 +172,7 @@ void ProcessVSTEvents(); //rewbs.VSTiNoteHoldonStopFix void ClearVSTEvents(); //rewbs.VSTiNoteHoldonStopFix void RecalculateGain(); - void Process(float *pOutL, float *pOutR, unsigned long nSamples); + void Process(float *pOutL, float *pOutR, size_t nSamples); void Init(unsigned long nFreq, int bReset); bool MidiSend(DWORD dwMidiCode); void MidiCC(UINT nMidiCh, UINT nController, UINT nParam, UINT trackChannel); @@ -208,6 +208,8 @@ // Set up input / output buffers. bool InitializeIOBuffers(); + void ProcessMixOps(float *pOutL, float *pOutR, size_t nSamples); + #else // case: NO_VST public: PlugParamIndex GetNumParameters() {return 0;} Modified: trunk/OpenMPT/soundlib/MIDIMacros.cpp =================================================================== --- trunk/OpenMPT/soundlib/MIDIMacros.cpp 2012-01-08 21:28:20 UTC (rev 1161) +++ trunk/OpenMPT/soundlib/MIDIMacros.cpp 2012-01-08 22:04:33 UTC (rev 1162) @@ -123,19 +123,19 @@ switch(macro) { case zxx_reso4Bit: - return _T("Z80 - Z8F controls resonant filter resonance"); + return _T("Z80 - Z8F controls Resonant Filter Resonance"); case zxx_reso7Bit: - return _T("Z80 - ZFF controls resonant filter resonance"); + return _T("Z80 - ZFF controls Resonant Filter Resonance"); case zxx_cutoff: - return _T("Z80 - ZFF controls resonant filter cutoff"); + return _T("Z80 - ZFF controls Resonant Filter Cutoff"); case zxx_mode: - return _T("Z80 - ZFF controls resonant filter mode"); + return _T("Z80 - ZFF controls Resonant Filter Mode"); case zxx_resomode: - return _T("Z80 - Z9F controls resonance + filter mode"); + return _T("Z80 - Z9F controls Resonance + Filter Mode"); case zxx_channelAT: return _T("Z80 - ZFF controls Channel Aftertouch"); case zxx_polyAT: - return _T("Z80 - ZFF controls Poly Aftertouch"); + return _T("Z80 - ZFF controls Polyphonic Aftertouch"); case zxx_custom: default: return _T("Custom"); Modified: trunk/OpenMPT/soundlib/PluginMixBuffer.h =================================================================== --- trunk/OpenMPT/soundlib/PluginMixBuffer.h 2012-01-08 21:28:20 UTC (rev 1161) +++ trunk/OpenMPT/soundlib/PluginMixBuffer.h 2012-01-08 22:04:33 UTC (rev 1162) @@ -11,7 +11,9 @@ #define PLUGINMIXBUFFER_H // At least this part of the code is ready for double-precision rendering... :> -template<typename buffer_t> +// buffer_t: Sample buffer type (float, double, ...) +// bufferSize: Buffer size in samples +template<typename buffer_t, size_t bufferSize> //=================== class PluginMixBuffer //=================== @@ -19,6 +21,7 @@ protected: buffer_t *mixBuffer; // Actual buffer, contains all input and output buffers + buffer_t *alignedBuffer; // Aligned pointer to the buffer buffer_t **inputsArray; // Pointers to input buffers buffer_t **outputsArray; // Pointers to output buffers @@ -35,7 +38,7 @@ //------------------------------------- { ASSERT(index < inputs + outputs); - return reinterpret_cast<buffer_t *>((reinterpret_cast<intptr_t>(&mixBuffer[MIXBUFFERSIZE * index]) + bufferAlignmentInBytes) & ~bufferAlignmentInBytes); + return &alignedBuffer[bufferSize * index]; } public: @@ -58,10 +61,13 @@ try { // Create inputs + outputs buffers with additional alignment. - const size_t bufferSize = MIXBUFFERSIZE * (inputs + outputs) + additionalBuffer; - mixBuffer = new buffer_t[bufferSize]; - memset(mixBuffer, 0, bufferSize * sizeof(buffer_t)); + const size_t totalBufferSize = bufferSize * (inputs + outputs) + additionalBuffer; + mixBuffer = new buffer_t[totalBufferSize]; + memset(mixBuffer, 0, totalBufferSize * sizeof(buffer_t)); + // Align buffer start. + alignedBuffer = reinterpret_cast<buffer_t *>((reinterpret_cast<intptr_t>(mixBuffer) + bufferAlignmentInBytes) & ~bufferAlignmentInBytes); + inputsArray = new (buffer_t *[inputs]); outputsArray = new (buffer_t *[outputs]); } catch(MPTMemoryException) @@ -87,7 +93,7 @@ //--------- { delete[] mixBuffer; - mixBuffer = nullptr; + mixBuffer = alignedBuffer = nullptr; delete[] inputsArray; inputsArray = nullptr; @@ -104,7 +110,7 @@ void ClearOutputBuffers(size_t numSamples) //---------------------------------------- { - ASSERT(numSamples <= MIXBUFFERSIZE); + ASSERT(numSamples <= bufferSize); for(size_t i = 0; i < outputs; i++) { memset(outputsArray[i], 0, numSamples * sizeof(buffer_t)); @@ -115,6 +121,7 @@ //--------------- { mixBuffer = nullptr; + alignedBuffer = nullptr; inputsArray = nullptr; outputsArray = nullptr; Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2012-01-08 21:28:20 UTC (rev 1161) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2012-01-08 22:04:33 UTC (rev 1162) @@ -2933,15 +2933,20 @@ { SetModFlag(MSF_COMPATIBLE_PLAY, false); SetModFlag(MSF_MIDICC_BUGEMULATION, false); - // If there are any plugins, enable volume bug emulation. - for(PLUGINDEX i = 0; i < MAX_MIXPLUGINS; i++) + + if(m_dwLastSavedWithVersion >= MAKE_VERSION_NUMERIC(1, 17, 00, 00)) { - if(m_MixPlugins[i].Info.dwPluginId1 | m_MixPlugins[i].Info.dwPluginId2) + // If there are any plugins, enable volume bug emulation. + for(PLUGINDEX i = 0; i < MAX_MIXPLUGINS; i++) { - SetModFlag(MSF_MIDICC_BUGEMULATION, true); - break; + if(m_MixPlugins[i].Info.dwPluginId1 | m_MixPlugins[i].Info.dwPluginId2) + { + SetModFlag(MSF_MIDICC_BUGEMULATION, true); + break; + } } } + // If there are any instruments with random variation, enable the old random variation behaviour. for(INSTRUMENTINDEX i = 1; i <= GetNumInstruments(); i++) { Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2012-01-08 21:28:20 UTC (rev 1161) +++ trunk/OpenMPT/soundlib/Sndfile.h 2012-01-08 22:04:33 UTC (rev 1162) @@ -392,7 +392,7 @@ virtual int Release() = 0; virtual void SaveAllParameters() = 0; virtual void RestoreAllParameters(long nProg=-1) = 0; //rewbs.plugDefaultProgram: added param - virtual void Process(float *pOutL, float *pOutR, unsigned long nSamples) = 0; + virtual void Process(float *pOutL, float *pOutR, size_t nSamples) = 0; virtual void Init(unsigned long nFreq, int bReset) = 0; virtual bool MidiSend(DWORD dwMidiCode) = 0; virtual void MidiCC(UINT nMidiCh, UINT nController, UINT nParam, UINT trackChannel) = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |