From: <man...@us...> - 2015-04-23 17:48:37
|
Revision: 4975 http://sourceforge.net/p/modplug/code/4975 Author: manxorist Date: 2015-04-23 17:48:24 +0000 (Thu, 23 Apr 2015) Log Message: ----------- [Ref] sounddev: Provide the instantaneous stream position also in seconds in addition to frames. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2015-04-23 13:03:08 UTC (rev 4974) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2015-04-23 17:48:24 UTC (rev 4975) @@ -596,7 +596,7 @@ int64 currenttotalsamples = 0; if(gpSoundDevice) { - currenttotalsamples = gpSoundDevice->GetStreamPositionFrames(); + currenttotalsamples = gpSoundDevice->GetStreamPosition().Frames; } { // advance to the newest notification, drop the obsolete ones @@ -747,8 +747,8 @@ } -void CMainFrame::SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition) -//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +void CMainFrame::SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, SoundDevice::StreamPosition streamPosition) +//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { MPT_TRACE(); MPT_UNREFERENCED_PARAMETER(settings); @@ -757,7 +757,7 @@ MPT_UNREFERENCED_PARAMETER(timeInfo); ASSERT(InAudioThread()); OPENMPT_PROFILE_FUNCTION(Profiler::Notify); - DoNotification(numFrames, streamPosition); + DoNotification(numFrames, streamPosition.Frames); //m_pSndFile->m_TimingInfo = TimingInfo(); // reset } Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2015-04-23 13:03:08 UTC (rev 4974) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2015-04-23 17:48:24 UTC (rev 4975) @@ -411,7 +411,7 @@ bool SoundSourceIsLockedByCurrentThread() const; void SoundSourceLock(); void SoundSourceRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer); - void SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition); + void SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, SoundDevice::StreamPosition streamPosition); void SoundSourceUnlock(); // from SoundDevice::IMessageReceiver Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2015-04-23 13:03:08 UTC (rev 4974) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2015-04-23 17:48:24 UTC (rev 4975) @@ -350,7 +350,7 @@ m_StreamPositionOutputFrames = m_StreamPositionRenderFrames - framesLatency; framesRendered = m_StreamPositionRenderFrames; } - m_Source->SoundSourceDone(m_Settings, m_Flags, GetEffectiveBufferAttributes(), m_TimeInfo, numFrames, framesRendered); + m_Source->SoundSourceDone(m_Settings, m_Flags, GetEffectiveBufferAttributes(), m_TimeInfo, numFrames, StreamPosition(framesRendered, StreamPositionFramesToSeconds(framesRendered))); } @@ -428,19 +428,28 @@ } -int64 Base::GetStreamPositionFrames() const -//----------------------------------------- +SoundDevice::StreamPosition Base::GetStreamPosition() const +//--------------------------------------------------------- { MPT_TRACE(); - if(!IsOpen()) return 0; + if(!IsOpen()) + { + return StreamPosition(); + } + if(m_Settings.Samplerate <= 0) + { + return StreamPosition(); + } + int64 frames = 0; if(InternalHasGetStreamPosition()) { - return InternalGetStreamPositionFrames(); + frames = InternalGetStreamPositionFrames(); } else { Util::lock_guard<Util::mutex> lock(m_StreamPositionMutex); - return m_StreamPositionOutputFrames; + frames = m_StreamPositionOutputFrames; } + return StreamPosition(frames, StreamPositionFramesToSeconds(frames)); } Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2015-04-23 13:03:08 UTC (rev 4974) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2015-04-23 17:48:24 UTC (rev 4975) @@ -52,6 +52,15 @@ }; +struct StreamPosition +{ + int64 Frames; // relative to Start() + double Seconds; // relative to Start() + StreamPosition() : Frames(0), Seconds(0.0) { } + StreamPosition(int64 frames, double seconds) : Frames(frames), Seconds(seconds) { } +}; + + struct Settings; struct Flags; struct BufferAttributes; @@ -68,7 +77,7 @@ virtual bool SoundSourceIsLockedByCurrentThread() const = 0; virtual void SoundSourceLock() = 0; virtual void SoundSourceRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer) = 0; - virtual void SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition) = 0; // in sample frames + virtual void SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, SoundDevice::StreamPosition streamPosition) = 0; virtual void SoundSourceUnlock() = 0; public: class Guard @@ -534,7 +543,7 @@ virtual SoundDevice::BufferAttributes GetEffectiveBufferAttributes() const = 0; virtual SoundDevice::TimeInfo GetTimeInfo() const = 0; - virtual int64 GetStreamPositionFrames() const = 0; + virtual SoundDevice::StreamPosition GetStreamPosition() const = 0; // Debugging aids in case of a crash virtual bool DebugIsFragileDevice() const = 0; @@ -615,6 +624,8 @@ void UpdateTimeInfo(SoundDevice::TimeInfo timeInfo); + double StreamPositionFramesToSeconds(int64 frames) const { return static_cast<double>(frames) / static_cast<double>(m_Settings.Samplerate); } + virtual bool InternalHasTimeInfo() const { return false; } virtual bool InternalHasGetStreamPosition() const { return false; } @@ -670,7 +681,7 @@ SoundDevice::BufferAttributes GetEffectiveBufferAttributes() const { return (IsOpen() && IsPlaying()) ? InternalGetEffectiveBufferAttributes() : SoundDevice::BufferAttributes(); } SoundDevice::TimeInfo GetTimeInfo() const { return m_TimeInfo; } - int64 GetStreamPositionFrames() const; + SoundDevice::StreamPosition GetStreamPosition() const; virtual bool DebugIsFragileDevice() const { return false; } virtual bool DebugInRealtimeCallback() const { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |