From: <sv...@op...> - 2024-08-11 07:39:07
|
Author: manx Date: Sun Aug 11 09:38:54 2024 New Revision: 21379 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21379 Log: [Ref] Playback Test: Factor out PlaybackTestSettings. Modified: trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/test/PlaybackTest.cpp trunk/OpenMPT/test/PlaybackTest.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp ============================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp Sat Aug 10 08:41:08 2024 (r21378) +++ trunk/OpenMPT/mptrack/MainFrm.cpp Sun Aug 11 09:38:54 2024 (r21379) @@ -3265,7 +3265,7 @@ continue; if(!sndFile->Create(GetFileReader(f))) continue; - auto playTest = sndFile->CreatePlaybackTest(); + auto playTest = sndFile->CreatePlaybackTest(PlaybackTestSettings{}); mpt::ofstream outFile(fileName + P_(".testdata.gz"), std::ios::binary | std::ios::trunc); if(outFile) playTest.Serialize(outFile, fileName.GetFilename().ToUnicode() + U_(".testdata")); @@ -3303,7 +3303,7 @@ auto sndFile = std::make_unique<CSoundFile>(); sndFile->Create(GetFileReader(modFile)); - const auto result = playTest.Compare(*sndFile); + const auto result = PlaybackTest::Compare(playTest, sndFile->CreatePlaybackTest(playTest.GetSettings())); if(!result.empty()) { InfoDialog infoDlg{this}; Modified: trunk/OpenMPT/soundlib/Sndfile.h ============================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h Sat Aug 10 08:41:08 2024 (r21378) +++ trunk/OpenMPT/soundlib/Sndfile.h Sun Aug 11 09:38:54 2024 (r21379) @@ -376,6 +376,30 @@ using NoteName = mpt::uchar[4]; +struct PlaybackTestSettings +{ + uint32 mixingFreq = 48000; + uint32 outputChannels = 2; + uint32 mixerChannels = MAX_CHANNELS; + ResamplingMode srcMode = SRCMODE_CUBIC; + void Sanitize() + { + if(mixingFreq < 1000) + { + mixingFreq = 48000; + } + if(outputChannels != 1 && outputChannels != 2 && outputChannels != 4) + { + outputChannels = 2; + } + if(mixerChannels < 1) + { + mixerChannels = MAX_CHANNELS; + } + } +}; + + class CSoundFile { friend class GetLengthMemory; @@ -1244,7 +1268,7 @@ public: PLUGINDEX GetBestPlugin(const PlayState &playState, CHANNELINDEX nChn, PluginPriority priority, PluginMutePriority respectMutes) const; - PlaybackTest CreatePlaybackTest(uint32 mixingFreq = 0, uint32 outputChannels = 0, uint32 mixerChannels = 0, ResamplingMode srcMode = SRCMODE_CUBIC); + PlaybackTest CreatePlaybackTest(PlaybackTestSettings settings); }; Modified: trunk/OpenMPT/test/PlaybackTest.cpp ============================================================================== --- trunk/OpenMPT/test/PlaybackTest.cpp Sat Aug 10 08:41:08 2024 (r21378) +++ trunk/OpenMPT/test/PlaybackTest.cpp Sun Aug 11 09:38:54 2024 (r21379) @@ -121,6 +121,16 @@ TestDataHeader header; std::vector<SampleDataHash> sampleDataHashes; std::vector<Row> rows; + + PlaybackTestSettings GetSettings() const + { + PlaybackTestSettings result; + result.mixingFreq = header.mixingFreq; + result.outputChannels = header.outputChannels; + result.mixerChannels = header.mixerChannels; + result.srcMode = Resampling::ToKnownMode(header.srcMode); + return result; + } }; @@ -469,6 +479,13 @@ } +PlaybackTestSettings PlaybackTest::GetSettings() const noexcept +{ + return m_testData->GetSettings(); +} + + + static bool FuzzyEquals(const double left, const double right, const double epsilon) noexcept { return std::abs(left - right) <= std::min(std::abs(left), std::abs(right)) * epsilon; @@ -484,9 +501,9 @@ errors.push_back(mpt::ToUnicode(mpt::Charset::UTF8, MPT_AFORMAT("{} differs in test row {} (order {}, row {}, tick {}), channel {}: {} vs {}") \ (propName, row, lRow.header.order, lRow.header.row, lTick, chn, left, right))); -std::vector<mpt::ustring> PlaybackTest::Compare(CSoundFile &sndFile) const +std::vector<mpt::ustring> PlaybackTest::Compare(const PlaybackTest &lhs, const PlaybackTest &rhs) { - return Compare(sndFile.CreatePlaybackTest(m_testData->header.mixingFreq, m_testData->header.outputChannels, m_testData->header.mixerChannels, Resampling::ToKnownMode(m_testData->header.srcMode))); + return lhs.Compare(rhs); } std::vector<mpt::ustring> PlaybackTest::Compare(const PlaybackTest &otherTest) const @@ -605,26 +622,21 @@ } -PlaybackTest CSoundFile::CreatePlaybackTest(uint32 mixingFreq, uint32 outputChannels, uint32 mixerChannels, ResamplingMode srcMode) +PlaybackTest CSoundFile::CreatePlaybackTest(PlaybackTestSettings settings) { - PlaybackTestData testData{}; + settings.Sanitize(); - if(mixingFreq < 1000) - mixingFreq = 48000; - if(outputChannels != 1 && outputChannels != 2 && outputChannels != 4) - outputChannels = 2; - if(mixerChannels < 1) - mixerChannels = MAX_CHANNELS; + PlaybackTestData testData{}; m_bIsRendering = true; const auto origResamplerSettings = m_Resampler.m_Settings; - m_Resampler.m_Settings.SrcMode = srcMode; + m_Resampler.m_Settings.SrcMode = settings.srcMode; m_Resampler.m_Settings.emulateAmiga = m_SongFlags[SONG_ISAMIGA] ? Resampling::AmigaFilter::A1200 : Resampling::AmigaFilter::Off; const auto origMixerSettings = m_MixerSettings; MixerSettings testSettings; - testSettings.gdwMixingFreq = mixingFreq; - testSettings.gnChannels = outputChannels; - testSettings.m_nMaxMixChannels = mixerChannels; + testSettings.gdwMixingFreq = settings.mixingFreq; + testSettings.gnChannels = settings.outputChannels; + testSettings.m_nMaxMixChannels = settings.mixerChannels; testSettings.VolumeRampUpMicroseconds = 0; testSettings.VolumeRampDownMicroseconds = 0; SetMixerSettings(testSettings); @@ -649,7 +661,7 @@ header.isAmiga = m_SongFlags[SONG_ISAMIGA] ? 1 : 0; header.positionPrecisionBits = static_cast<uint8>(mpt::bit_width(static_cast<typename std::make_unsigned<SamplePosition::value_t>::type>(SamplePosition{1, 0}.GetRaw())) - 1); header.filterPrecisionBits = MIXING_FILTER_PRECISION; - header.srcMode = srcMode; + header.srcMode = m_Resampler.m_Settings.SrcMode; header.outputChannels = static_cast<uint8>(m_MixerSettings.gnChannels); header.mixerChannels = static_cast<uint16>(m_MixerSettings.m_nMaxMixChannels); header.synthVolume = static_cast<uint16>(m_nVSTiVolume); Modified: trunk/OpenMPT/test/PlaybackTest.h ============================================================================== --- trunk/OpenMPT/test/PlaybackTest.h Sat Aug 10 08:41:08 2024 (r21378) +++ trunk/OpenMPT/test/PlaybackTest.h Sun Aug 11 09:38:54 2024 (r21379) @@ -18,6 +18,7 @@ OPENMPT_NAMESPACE_BEGIN struct PlaybackTestData; +struct PlaybackTestSettings; class CSoundFile; class PlaybackTest @@ -36,7 +37,11 @@ void Serialize(std::ostream &output, const mpt::ustring &filename) const noexcept(false); void ToTSV(std::ostream &output) const noexcept(false); - std::vector<mpt::ustring> Compare(CSoundFile &sndFile) const; + PlaybackTestSettings GetSettings() const noexcept; + + static std::vector<mpt::ustring> Compare(const PlaybackTest &lhs, const PlaybackTest &rhs); + +private: std::vector<mpt::ustring> Compare(const PlaybackTest &otherTest) const; private: |