From: <sv...@op...> - 2024-03-17 12:34:55
|
Author: sagamusix Date: Sun Mar 17 13:34:44 2024 New Revision: 20407 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20407 Log: Merged revision(s) 20385-20406 from trunk/OpenMPT: [Mod] Compressor DMO: Similar to Chorus / Flanger, avoid chance of reading from the wrong buffer offset at extremely high sample rates. In this particular case, the mix rate needs to be above 500 kHz before the overflow would occur. ........ [Fix] MED: Some samples were playing too low (e.g. in mix94.mmd1, see https://www.un4seen.com/forum/?topic=15448.msg142556#msg142556) ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/soundlib/Load_med.cpp branches/OpenMPT-1.31/soundlib/plugins/dmo/Compressor.cpp Modified: branches/OpenMPT-1.31/soundlib/Load_med.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/Load_med.cpp Sun Mar 17 13:33:14 2024 (r20406) +++ branches/OpenMPT-1.31/soundlib/Load_med.cpp Sun Mar 17 13:34:44 2024 (r20407) @@ -818,6 +818,9 @@ instr.AssignSample(0); } + MMD0Sample sampleHeader; + sampleHeaderChunk.ReadStruct(sampleHeader); + uint8 numSamples = 1; static constexpr uint8 SamplesPerType[] = {1, 5, 3, 2, 4, 6, 7}; if(!isSynth && maskedType < std::size(SamplesPerType)) @@ -850,10 +853,10 @@ // TODO: Move octaves so that they align better (C-4 = lowest, we don't have access to the highest four octaves) for(int octave = 4; octave < 10; octave++) { - for(int note = 0; note < 12; note++) + for(int note = 0, i = 12 * octave; note < 12; note++, i++) { - instr.Keyboard[12 * octave + note] = smp + OctSampleMap[numSamples - 2][octave - 4]; - instr.NoteMap[12 * octave + note] += OctTransposeMap[numSamples - 2][octave - 4]; + instr.Keyboard[i] = smp + OctSampleMap[numSamples - 2][octave - 4]; + instr.NoteMap[i] = static_cast<uint8>(instr.NoteMap[i] + OctTransposeMap[numSamples - 2][octave - 4]); } } } else if(maskedType == MMDInstrHeader::EXTSAMPLE) @@ -862,18 +865,14 @@ instr.Transpose(-24); } else if(!isSynth && hardwareMixSamples) { - for(int octave = 7; octave < 10; octave++) + for(auto ¬e : instr.NoteMap) { - for(int note = 0; note < 12; note++) - { - instr.NoteMap[12 * octave + note] -= static_cast<uint8>((octave - 6) * 12); - } + int realNote = note + sampleHeader.sampleTranspose; + if(realNote >= NOTE_MIDDLEC + 24) + note -= static_cast<uint8>(mpt::align_down(realNote - NOTE_MIDDLEC - 12, 12)); } } - MMD0Sample sampleHeader; - sampleHeaderChunk.ReadStruct(sampleHeader); - // midiChannel = 0xFF == midi instrument but with invalid channel, midiChannel = 0x00 == sample-based instrument? if(sampleHeader.midiChannel > 0 && sampleHeader.midiChannel <= 16) { @@ -1153,12 +1152,12 @@ if(!order.empty()) order.push_back(order.GetIgnoreIndex()); + const size_t orderStart = order.size(); size_t readOrders = playSeq.length; if(!file.CanRead(readOrders)) LimitMax(readOrders, file.BytesLeft()); LimitMax(readOrders, ORDERINDEX_MAX); - size_t orderStart = order.size(); order.reserve(orderStart + readOrders); for(size_t ord = 0; ord < readOrders; ord++) { Modified: branches/OpenMPT-1.31/soundlib/plugins/dmo/Compressor.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/plugins/dmo/Compressor.cpp Sun Mar 17 13:33:14 2024 (r20406) +++ branches/OpenMPT-1.31/soundlib/plugins/dmo/Compressor.cpp Sun Mar 17 13:34:44 2024 (r20407) @@ -88,10 +88,10 @@ } compGainPow >>= (31 - compGainInt); - int32 readOffset = m_predelay + m_bufPos * 4096 + m_bufSize - 1; + int32 readOffset = m_predelay + m_bufSize - 1; readOffset /= 4096; - readOffset %= m_bufSize; - + readOffset = (readOffset + m_bufPos) % m_bufSize; + float outGain = (static_cast<float>(compGainPow) * (1.0f / 2147483648.0f)) * m_gain; *(out[0])++ = m_buffer[readOffset * 2] * outGain; *(out[1])++ = m_buffer[readOffset * 2 + 1] * outGain; |