From: <sv...@op...> - 2024-03-17 12:33:31
|
Author: sagamusix Date: Sun Mar 17 13:33:14 2024 New Revision: 20406 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20406 Log: [Fix] MED: Some samples were playing too low (e.g. in mix94.mmd1, see https://www.un4seen.com/forum/?topic=15448.msg142556#msg142556) Modified: trunk/OpenMPT/soundlib/Load_med.cpp Modified: trunk/OpenMPT/soundlib/Load_med.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Load_med.cpp Sun Mar 17 08:46:17 2024 (r20405) +++ trunk/OpenMPT/soundlib/Load_med.cpp Sun Mar 17 13:33:14 2024 (r20406) @@ -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,17 +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]; -#if MPT_COMPILER_GCC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - instr.NoteMap[12 * octave + note] += OctTransposeMap[numSamples - 2][octave - 4]; -#if MPT_COMPILER_GCC -#pragma GCC diagnostic pop -#endif + 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) @@ -869,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) { @@ -1160,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++) { |