From: <man...@us...> - 2013-10-13 10:23:17
|
Revision: 2892 http://sourceforge.net/p/modplug/code/2892 Author: manxorist Date: 2013-10-13 10:23:09 +0000 (Sun, 13 Oct 2013) Log Message: ----------- [Ref] sounddev: Explicitly pass SoundDeviceSettings to AudioRead and AudioDone.. [Ref] sounddev: Be more clear about samples vs frames in class ISoundDevice. 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 2013-10-13 09:50:19 UTC (rev 2891) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-10-13 10:23:09 UTC (rev 2892) @@ -854,35 +854,36 @@ }; -void CMainFrame::AudioRead(PVOID pvData, ULONG NumFrames, SampleFormat sampleFormat) -//---------------------------------------------------------------------------------- +void CMainFrame::AudioRead(const SoundDeviceSettings &settings, std::size_t numFrames, void *buffer) +//-------------------------------------------------------------------------------------------------- { OPENMPT_PROFILE_FUNCTION(Profiler::Audio); - StereoVuMeterTargetWrapper target(sampleFormat, m_Dither, pvData); - CSoundFile::samplecount_t renderedFrames = m_pSndFile->Read(NumFrames, target); - ASSERT(renderedFrames <= NumFrames); - CSoundFile::samplecount_t remainingFrames = NumFrames - renderedFrames; + StereoVuMeterTargetWrapper target(settings.sampleFormat, m_Dither, buffer); + CSoundFile::samplecount_t renderedFrames = m_pSndFile->Read(numFrames, target); + ASSERT(renderedFrames <= numFrames); + CSoundFile::samplecount_t remainingFrames = numFrames - renderedFrames; if(remainingFrames > 0) { // The sound device interface expects the whole buffer to be filled, always. // Clear remaining buffer if not enough samples got rendered. - std::size_t frameSize = m_pSndFile->m_MixerSettings.gnChannels * (sampleFormat.GetBitsPerSample()/8); - if(sampleFormat.IsUnsigned()) + std::size_t frameSize = settings.Channels * (settings.sampleFormat.GetBitsPerSample()/8); + if(settings.sampleFormat.IsUnsigned()) { - std::memset((char*)(pvData) + renderedFrames * frameSize, 0x80, remainingFrames * frameSize); + std::memset((char*)(buffer) + renderedFrames * frameSize, 0x80, remainingFrames * frameSize); } else { - std::memset((char*)(pvData) + renderedFrames * frameSize, 0, remainingFrames * frameSize); + std::memset((char*)(buffer) + renderedFrames * frameSize, 0, remainingFrames * frameSize); } } } -void CMainFrame::AudioDone(ULONG NumSamples, int64 streamPosition) -//---------------------------------------------------------------- +void CMainFrame::AudioDone(const SoundDeviceSettings &settings, std::size_t numFrames, int64 streamPosition) +//---------------------------------------------------------------------------------------------------------- { + MPT_UNREFERENCED_PARAMETER(settings); OPENMPT_PROFILE_FUNCTION(Profiler::Notify); - DoNotification(NumSamples, streamPosition); + DoNotification(numFrames, streamPosition); } Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2013-10-13 09:50:19 UTC (rev 2891) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2013-10-13 10:23:09 UTC (rev 2892) @@ -325,8 +325,8 @@ // from ISoundSource void FillAudioBufferLocked(IFillAudioBuffer &callback); - void AudioRead(PVOID pData, ULONG NumSamples, SampleFormat sampleFormat); - void AudioDone(ULONG NumSamples, int64 streamPosition); + void AudioRead(const SoundDeviceSettings &settings, std::size_t numFrames, void *buffer); + void AudioDone(const SoundDeviceSettings &settings, std::size_t numFrames, int64 streamPosition); bool audioTryOpeningDevice(); bool audioOpenDevice(); Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-13 09:50:19 UTC (rev 2891) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-13 10:23:09 UTC (rev 2892) @@ -42,7 +42,7 @@ m_RealUpdateIntervalMS = static_cast<float>(m_Settings.UpdateIntervalMS); m_IsPlaying = false; - m_SamplesRendered = 0; + m_FramesRendered = 0; } @@ -118,36 +118,36 @@ } -void ISoundDevice::SourceAudioRead(void* pData, ULONG NumSamples) -//--------------------------------------------------------------- +void ISoundDevice::SourceAudioRead(void *buffer, std::size_t numFrames) +//--------------------------------------------------------------------- { - if(NumSamples <= 0) + if(numFrames <= 0) { return; } - m_Source->AudioRead(pData, NumSamples, m_Settings.sampleFormat); + m_Source->AudioRead(m_Settings, numFrames, buffer); } -void ISoundDevice::SourceAudioDone(ULONG NumSamples, ULONG SamplesLatency) -//------------------------------------------------------------------------ +void ISoundDevice::SourceAudioDone(std::size_t numFrames, int32 framesLatency) +//---------------------------------------------------------------------------- { - if(NumSamples <= 0) + if(numFrames <= 0) { return; } - int64 samplesRendered = 0; + int64 framesRendered = 0; { - Util::lock_guard<Util::mutex> lock(m_SamplesRenderedMutex); - m_SamplesRendered += NumSamples; - samplesRendered = m_SamplesRendered; + Util::lock_guard<Util::mutex> lock(m_FramesRenderedMutex); + m_FramesRendered += numFrames; + framesRendered = m_FramesRendered; } if(InternalHasGetStreamPosition()) { - m_Source->AudioDone(NumSamples, samplesRendered); + m_Source->AudioDone(m_Settings, numFrames, framesRendered); } else { - m_Source->AudioDone(NumSamples, samplesRendered + SamplesLatency); + m_Source->AudioDone(m_Settings, numFrames, framesRendered + framesLatency); } } @@ -159,8 +159,8 @@ if(!IsPlaying()) { { - Util::lock_guard<Util::mutex> lock(m_SamplesRenderedMutex); - m_SamplesRendered = 0; + Util::lock_guard<Util::mutex> lock(m_FramesRenderedMutex); + m_FramesRendered = 0; } InternalStart(); m_IsPlaying = true; @@ -177,8 +177,8 @@ InternalStop(); m_IsPlaying = false; { - Util::lock_guard<Util::mutex> lock(m_SamplesRenderedMutex); - m_SamplesRendered = 0; + Util::lock_guard<Util::mutex> lock(m_FramesRenderedMutex); + m_FramesRendered = 0; } } } @@ -201,14 +201,14 @@ return InternalGetStreamPositionSamples(); } else { - Util::lock_guard<Util::mutex> lock(m_SamplesRenderedMutex); - return m_SamplesRendered; + Util::lock_guard<Util::mutex> lock(m_FramesRenderedMutex); + return m_FramesRendered; } } CAudioThread::CAudioThread(CSoundDeviceWithThread &SoundDevice) : m_SoundDevice(SoundDevice) -//----------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------ { OSVERSIONINFO versioninfo; Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-13 09:50:19 UTC (rev 2891) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-13 10:23:09 UTC (rev 2892) @@ -28,6 +28,9 @@ // +struct SoundDeviceSettings; + + //==================== class IFillAudioBuffer //==================== @@ -43,8 +46,8 @@ { public: virtual void FillAudioBufferLocked(IFillAudioBuffer &callback) = 0; // take any locks needed while rendering audio and then call FillAudioBuffer - virtual void AudioRead(void* pData, ULONG NumSamples, SampleFormat sampleFormat) = 0; - virtual void AudioDone(ULONG NumSamples, int64 streamPosition) = 0; // in samples + virtual void AudioRead(const SoundDeviceSettings &settings, std::size_t numFrames, void *buffer) = 0; + virtual void AudioDone(const SoundDeviceSettings &settings, std::size_t numFrames, int64 streamPosition) = 0; // in sample frames }; @@ -195,14 +198,14 @@ bool m_IsPlaying; - mutable Util::mutex m_SamplesRenderedMutex; - int64 m_SamplesRendered; + mutable Util::mutex m_FramesRenderedMutex; + int64 m_FramesRendered; protected: virtual void FillAudioBuffer() = 0; void SourceFillAudioBufferLocked(); - void SourceAudioRead(void* pData, ULONG NumSamples); - void SourceAudioDone(ULONG NumSamples, ULONG SamplesLatency); + void SourceAudioRead(void *buffer, std::size_t numFrames); + void SourceAudioDone(std::size_t numFrames, int32 framesLatency); public: ISoundDevice(SoundDeviceID id, const std::wstring &internalID); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |