From: <sv...@op...> - 2024-05-30 20:54:21
|
Author: sagamusix Date: Thu May 30 22:54:12 2024 New Revision: 20868 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20868 Log: [Ref] Move samplecount_t out of CSoundFile. Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Mod2wave.cpp trunk/OpenMPT/mptrack/OPLExport.cpp trunk/OpenMPT/mptrack/mod2midi.cpp trunk/OpenMPT/soundlib/Snd_defs.h trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp ============================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp Thu May 30 22:54:12 2024 (r20868) @@ -512,7 +512,7 @@ OpenMPT::AudioTargetBufferWithGain<mpt::audio_span_planar<std::int16_t>> target( mpt::audio_span_planar<std::int16_t>( buffers, valid_channels( buffers, std::size( buffers ) ), count ), *m_Dithers, m_Gain ); while ( count > 0 ) { std::size_t count_chunk = m_sndFile->Read( - static_cast<OpenMPT::CSoundFile::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::CSoundFile::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels + static_cast<OpenMPT::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels target ); if ( count_chunk == 0 ) { @@ -535,7 +535,7 @@ OpenMPT::AudioTargetBufferWithGain<mpt::audio_span_planar<float>> target( mpt::audio_span_planar<float>( buffers, valid_channels( buffers, std::size( buffers ) ), count ), *m_Dithers, m_Gain ); while ( count > 0 ) { std::size_t count_chunk = m_sndFile->Read( - static_cast<OpenMPT::CSoundFile::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::CSoundFile::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels + static_cast<OpenMPT::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels target ); if ( count_chunk == 0 ) { @@ -557,7 +557,7 @@ OpenMPT::AudioTargetBufferWithGain<mpt::audio_span_interleaved<std::int16_t>> target( mpt::audio_span_interleaved<std::int16_t>( interleaved, channels, count ), *m_Dithers, m_Gain ); while ( count > 0 ) { std::size_t count_chunk = m_sndFile->Read( - static_cast<OpenMPT::CSoundFile::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::CSoundFile::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels + static_cast<OpenMPT::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels target ); if ( count_chunk == 0 ) { @@ -579,7 +579,7 @@ OpenMPT::AudioTargetBufferWithGain<mpt::audio_span_interleaved<float>> target( mpt::audio_span_interleaved<float>( interleaved, channels, count ), *m_Dithers, m_Gain ); while ( count > 0 ) { std::size_t count_chunk = m_sndFile->Read( - static_cast<OpenMPT::CSoundFile::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::CSoundFile::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels + static_cast<OpenMPT::samplecount_t>( std::min( static_cast<std::uint64_t>( count ), static_cast<std::uint64_t>( std::numeric_limits<OpenMPT::samplecount_t>::max() / 2 / 4 / 4 ) ) ), // safety margin / samplesize / channels target ); if ( count_chunk == 0 ) { Modified: trunk/OpenMPT/mptrack/MainFrm.cpp ============================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/mptrack/MainFrm.cpp Thu May 30 22:54:12 2024 (r20868) @@ -812,12 +812,12 @@ OPENMPT_PROFILE_FUNCTION(Profiler::Audio); BufferInputWrapper source(buffer); BufferOutputWrapper target(buffer); - MPT_ASSERT(buffer.GetNumFrames() <= std::numeric_limits<CSoundFile::samplecount_t>::max()); - CSoundFile::samplecount_t framesToRender = static_cast<CSoundFile::samplecount_t>(buffer.GetNumFrames()); + MPT_ASSERT(buffer.GetNumFrames() <= std::numeric_limits<samplecount_t>::max()); + samplecount_t framesToRender = static_cast<samplecount_t>(buffer.GetNumFrames()); MPT_ASSERT(framesToRender > 0); - CSoundFile::samplecount_t renderedFrames = m_pSndFile->Read(framesToRender, target, source, std::ref(m_VUMeterOutput), std::ref(m_VUMeterInput)); + samplecount_t renderedFrames = m_pSndFile->Read(framesToRender, target, source, std::ref(m_VUMeterOutput), std::ref(m_VUMeterInput)); MPT_ASSERT(renderedFrames <= framesToRender); - [[maybe_unused]] CSoundFile::samplecount_t remainingFrames = framesToRender - renderedFrames; + [[maybe_unused]] samplecount_t remainingFrames = framesToRender - renderedFrames; MPT_ASSERT(remainingFrames >= 0); // remaining buffer is filled with silence automatically } @@ -827,8 +827,8 @@ MPT_TRACE_SCOPE(); MPT_ASSERT(InAudioThread()); OPENMPT_PROFILE_FUNCTION(Profiler::Notify); - MPT_ASSERT((timeInfo.RenderStreamPositionAfter.Frames - timeInfo.RenderStreamPositionBefore.Frames) < std::numeric_limits<CSoundFile::samplecount_t>::max()); - CSoundFile::samplecount_t framesRendered = static_cast<CSoundFile::samplecount_t>(timeInfo.RenderStreamPositionAfter.Frames - timeInfo.RenderStreamPositionBefore.Frames); + MPT_ASSERT((timeInfo.RenderStreamPositionAfter.Frames - timeInfo.RenderStreamPositionBefore.Frames) < std::numeric_limits<samplecount_t>::max()); + samplecount_t framesRendered = static_cast<samplecount_t>(timeInfo.RenderStreamPositionAfter.Frames - timeInfo.RenderStreamPositionBefore.Frames); int64 streamPosition = timeInfo.RenderStreamPositionAfter.Frames; DoNotification(framesRendered, streamPosition); //m_pSndFile->m_TimingInfo = TimingInfo(); // reset @@ -2114,7 +2114,7 @@ IdleHandlerSounddevice(); // Display Time in status bar - CSoundFile::samplecount_t time = 0; + samplecount_t time = 0; if(m_pSndFile != nullptr && m_pSndFile->GetSampleRate() != 0) { time = m_pSndFile->GetTotalSampleCount() / m_pSndFile->GetSampleRate(); Modified: trunk/OpenMPT/mptrack/Mainfrm.h ============================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/mptrack/Mainfrm.h Thu May 30 22:54:12 2024 (r20868) @@ -183,7 +183,7 @@ CMainToolBar m_wndToolBar; CSoundFile *m_pSndFile = nullptr; // != NULL only when currently playing or rendering HWND m_hWndMidi = nullptr; - CSoundFile::samplecount_t m_dwTimeSec = 0; + samplecount_t m_dwTimeSec = 0; UINT_PTR m_nTimer = 0; UINT m_nAvgMixChn = 0, m_nMixChn = 0; // Misc @@ -281,7 +281,7 @@ void UpdateTree(CModDoc *pModDoc, UpdateHint hint, CObject *pHint = nullptr); void RefreshDlsBanks(); static CInputHandler* GetInputHandler() { return m_InputHandler; } - void SetElapsedTime(double t) { m_dwTimeSec = static_cast<CSoundFile::samplecount_t>(t); } + void SetElapsedTime(double t) { m_dwTimeSec = static_cast<samplecount_t>(t); } #if defined(MPT_ENABLE_UPDATE) bool ShowUpdateIndicator(const UpdateCheckResult &result, const CString &releaseVersion, const CString &infoURL, bool showHighlight); Modified: trunk/OpenMPT/mptrack/Mod2wave.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Mod2wave.cpp Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/mptrack/Mod2wave.cpp Thu May 30 22:54:12 2024 (r20868) @@ -41,7 +41,7 @@ template <typename Tsample> -static CSoundFile::samplecount_t ReadInterleaved(CSoundFile &sndFile, Tsample *outputBuffer, std::size_t channels, CSoundFile::samplecount_t count, DithersOpenMPT &dithers) +static samplecount_t ReadInterleaved(CSoundFile &sndFile, Tsample *outputBuffer, std::size_t channels, samplecount_t count, DithersOpenMPT &dithers) { sndFile.ResetMixStat(); MPT_ASSERT(sndFile.m_MixerSettings.gnChannels == channels); Modified: trunk/OpenMPT/mptrack/OPLExport.cpp ============================================================================== --- trunk/OpenMPT/mptrack/OPLExport.cpp Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/mptrack/OPLExport.cpp Thu May 30 22:54:12 2024 (r20868) @@ -86,7 +86,7 @@ { struct RegisterDump { - CSoundFile::samplecount_t sampleOffset; + samplecount_t sampleOffset; uint8 regLo; uint8 regHi; uint8 value; @@ -124,7 +124,7 @@ mpt::IO::Write(f, header); - CSoundFile::samplecount_t prevOffset = 0, prevOffsetMs = 0; + samplecount_t prevOffset = 0, prevOffsetMs = 0; bool prevHigh = false; for(const auto ® : m_registerDump) { @@ -177,7 +177,7 @@ mpt::IO::Write(f, header); } - void WriteVGZ(std::ostream &f, const CSoundFile::samplecount_t loopStart, const FileTags &fileTags, const mpt::ustring &filename) const + void WriteVGZ(std::ostream &f, const samplecount_t loopStart, const FileTags &fileTags, const mpt::ustring &filename) const { std::ostringstream outStream; WriteVGM(outStream, loopStart, fileTags); @@ -186,7 +186,7 @@ WriteGzip(f, outData, filename); } - void WriteVGM(std::ostream &f, const CSoundFile::samplecount_t loopStart, const FileTags &fileTags) const + void WriteVGM(std::ostream &f, const samplecount_t loopStart, const FileTags &fileTags) const { VGMHeader header{}; memcpy(header.magic, VGMHeader::VgmMagic, 4); @@ -200,7 +200,7 @@ mpt::IO::Write(f, header); bool wroteLoopStart = (header.loopNumSamples == 0); - CSoundFile::samplecount_t prevOffset = 0; + samplecount_t prevOffset = 0; for(const auto ® : m_registerDump) { if(reg.sampleOffset >= loopStart && !wroteLoopStart) @@ -284,7 +284,7 @@ return bytesWritten; } - static void WriteVGMDelay(std::ostream &f, CSoundFile::samplecount_t delay) + static void WriteVGMDelay(std::ostream &f, samplecount_t delay) { while(delay) { @@ -524,7 +524,7 @@ m_sndFile.m_opl = std::make_unique<OPL>(m_oplLogger); auto prevTime = timeGetTime(); - CSoundFile::samplecount_t loopStart = std::numeric_limits<CSoundFile::samplecount_t>::max(), subsongSamples = 0; + samplecount_t loopStart = std::numeric_limits<samplecount_t>::max(), subsongSamples = 0; while(!m_abort) { auto count = m_sndFile.ReadOneTick(); Modified: trunk/OpenMPT/mptrack/mod2midi.cpp ============================================================================== --- trunk/OpenMPT/mptrack/mod2midi.cpp Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/mptrack/mod2midi.cpp Thu May 30 22:54:12 2024 (r20868) @@ -71,9 +71,9 @@ std::ostringstream f; double m_tempo = 0.0; - double m_ticks = 0.0; // MIDI ticks since previous event - CSoundFile::samplecount_t m_samplePos = 0; // Current sample position - CSoundFile::samplecount_t m_prevEventTime = 0; // Sample position of previous event + double m_ticks = 0.0; // MIDI ticks since previous event + samplecount_t m_samplePos = 0; // Current sample position + samplecount_t m_prevEventTime = 0; // Sample position of previous event uint32 m_sampleRate; uint32 m_oldSigNumerator = 0; int32 m_oldGlobalVol = -1; Modified: trunk/OpenMPT/soundlib/Snd_defs.h ============================================================================== --- trunk/OpenMPT/soundlib/Snd_defs.h Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/soundlib/Snd_defs.h Thu May 30 22:54:12 2024 (r20868) @@ -57,6 +57,8 @@ enum { FREQ_FRACBITS = 4 }; // Number of fractional bits in return value of CSoundFile::GetFreqFromPeriod() +using samplecount_t = uint32; // Number of rendered samples + // String lengths (including trailing null char) enum { Modified: trunk/OpenMPT/soundlib/Sndfile.h ============================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/soundlib/Sndfile.h Thu May 30 22:54:12 2024 (r20868) @@ -457,8 +457,6 @@ BitCrush m_BitCrush; #endif - using samplecount_t = uint32; // Number of rendered samples - static constexpr uint32 TICKS_ROW_FINISHED = uint32_max - 1u; public: // for Editing Modified: trunk/OpenMPT/soundlib/Sndmix.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp Thu May 30 20:45:22 2024 (r20867) +++ trunk/OpenMPT/soundlib/Sndmix.cpp Thu May 30 22:54:12 2024 (r20868) @@ -196,7 +196,7 @@ // Read one tick but skip all expensive rendering options -CSoundFile::samplecount_t CSoundFile::ReadOneTick() +samplecount_t CSoundFile::ReadOneTick() { const auto origMaxMixChannels = m_MixerSettings.m_nMaxMixChannels; m_MixerSettings.m_nMaxMixChannels = 0; @@ -216,7 +216,7 @@ } -CSoundFile::samplecount_t CSoundFile::Read(samplecount_t count, IAudioTarget &target, IAudioSource &source, std::optional<std::reference_wrapper<IMonitorOutput>> outputMonitor, std::optional<std::reference_wrapper<IMonitorInput>> inputMonitor) +samplecount_t CSoundFile::Read(samplecount_t count, IAudioTarget &target, IAudioSource &source, std::optional<std::reference_wrapper<IMonitorOutput>> outputMonitor, std::optional<std::reference_wrapper<IMonitorInput>> inputMonitor) { MPT_ASSERT_ALWAYS(m_MixerSettings.IsValid()); |