From: <man...@us...> - 2014-09-17 08:49:20
|
Revision: 4296 http://sourceforge.net/p/modplug/code/4296 Author: manxorist Date: 2014-09-17 08:49:10 +0000 (Wed, 17 Sep 2014) Log Message: ----------- [Ref] sounddev: Add an abstract interface for SoundDevice::Base. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2014-09-16 07:52:30 UTC (rev 4295) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2014-09-17 08:49:10 UTC (rev 4296) @@ -1652,14 +1652,14 @@ if(gpSoundDevice) { const LONG requestFlags = gpSoundDevice->GetRequestFlags(); - if(requestFlags & SoundDevice::Base::RequestFlagClose) + if(requestFlags & SoundDevice::IBase::RequestFlagClose) { StopPlayback(); audioCloseDevice(); - } else if(requestFlags & SoundDevice::Base::RequestFlagReset) + } else if(requestFlags & SoundDevice::IBase::RequestFlagReset) { ResetSoundCard(); - } else if(requestFlags & SoundDevice::Base::RequestFlagRestart) + } else if(requestFlags & SoundDevice::IBase::RequestFlagRestart) { RestartPlayback(); } else Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2014-09-16 07:52:30 UTC (rev 4295) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2014-09-17 08:49:10 UTC (rev 4296) @@ -321,7 +321,7 @@ public: // Low-Level Audio - SoundDevice::Base *gpSoundDevice; + SoundDevice::IBase *gpSoundDevice; UINT_PTR m_NotifyTimer; Dither m_Dither; Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-09-16 07:52:30 UTC (rev 4295) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-09-17 08:49:10 UTC (rev 4296) @@ -582,8 +582,8 @@ } -bool Manager::OpenDriverSettings(SoundDevice::ID id, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::Base *currentSoundDevice) -//----------------------------------------------------------------------------------------------------------------------------------------- +bool Manager::OpenDriverSettings(SoundDevice::ID id, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::IBase *currentSoundDevice) +//------------------------------------------------------------------------------------------------------------------------------------------ { bool result = false; if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) @@ -591,7 +591,7 @@ result = currentSoundDevice->OpenDriverSettings(); } else { - SoundDevice::Base *dummy = CreateSoundDevice(id); + SoundDevice::IBase *dummy = CreateSoundDevice(id); if(dummy) { dummy->SetMessageReceiver(messageReceiver); @@ -603,8 +603,8 @@ } -SoundDevice::Caps Manager::GetDeviceCaps(SoundDevice::ID id, SoundDevice::Base *currentSoundDevice) -//------------------------------------------------------------------------------------------------- +SoundDevice::Caps Manager::GetDeviceCaps(SoundDevice::ID id, SoundDevice::IBase *currentSoundDevice) +//-------------------------------------------------------------------------------------------------- { if(m_DeviceCaps.find(id) == m_DeviceCaps.end()) { @@ -613,7 +613,7 @@ m_DeviceCaps[id] = currentSoundDevice->GetDeviceCaps(); } else { - SoundDevice::Base *dummy = CreateSoundDevice(id); + SoundDevice::IBase *dummy = CreateSoundDevice(id); if(dummy) { m_DeviceCaps[id] = dummy->GetDeviceCaps(); @@ -625,8 +625,8 @@ } -SoundDevice::DynamicCaps Manager::GetDeviceDynamicCaps(SoundDevice::ID id, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::Base *currentSoundDevice, bool update) -//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SoundDevice::DynamicCaps Manager::GetDeviceDynamicCaps(SoundDevice::ID id, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::IBase *currentSoundDevice, bool update) +//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { if((m_DeviceDynamicCaps.find(id) == m_DeviceDynamicCaps.end()) || update) { @@ -635,7 +635,7 @@ m_DeviceDynamicCaps[id] = currentSoundDevice->GetDeviceDynamicCaps(baseSampleRates); } else { - SoundDevice::Base *dummy = CreateSoundDevice(id); + SoundDevice::IBase *dummy = CreateSoundDevice(id); if(dummy) { dummy->SetMessageReceiver(messageReceiver); @@ -648,15 +648,15 @@ } -SoundDevice::Base * Manager::CreateSoundDevice(SoundDevice::ID id) -//---------------------------------------------------------------- +SoundDevice::IBase * Manager::CreateSoundDevice(SoundDevice::ID id) +//----------------------------------------------------------------- { const SoundDevice::Info info = FindDeviceInfo(id); if(!info.IsValid()) { return nullptr; } - SoundDevice::Base *result = nullptr; + SoundDevice::IBase *result = nullptr; switch(id.GetType()) { case TypeWAVEOUT: result = new CWaveDevice(id, info.internalID); break; Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2014-09-16 07:52:30 UTC (rev 4295) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2014-09-17 08:49:10 UTC (rev 4296) @@ -378,11 +378,85 @@ }; -//===================================== -class Base : protected IFillAudioBuffer -//===================================== +//========= +class IBase +//========= + : protected IFillAudioBuffer { +protected: + + IBase() { } + +public: + + virtual ~IBase() { } + +protected: + + virtual void FillAudioBuffer() = 0; + +public: + + static const uint32 RequestFlagClose = 1<<0; + static const uint32 RequestFlagReset = 1<<1; + static const uint32 RequestFlagRestart = 1<<2; + +public: + + virtual void SetSource(SoundDevice::ISource *source) = 0; + virtual SoundDevice::ISource *GetSource() const = 0; + virtual void SetMessageReceiver(SoundDevice::IMessageReceiver *receiver) = 0; + virtual SoundDevice::IMessageReceiver *GetMessageReceiver() const = 0; + + virtual SoundDevice::ID GetDeviceID() const = 0; + virtual SoundDevice::Type GetDeviceType() const = 0; + virtual SoundDevice::Index GetDeviceIndex() const = 0; + virtual std::wstring GetDeviceInternalID() const = 0; + + virtual SoundDevice::Caps GetDeviceCaps() const = 0; + virtual SoundDevice::DynamicCaps GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates) = 0; + + virtual bool Init() = 0; + virtual bool Open(const SoundDevice::Settings &settings) = 0; + virtual bool Close() = 0; + virtual bool Start() = 0; + virtual void Stop(bool force = false) = 0; + + virtual uint32 GetRequestFlags() const = 0; + + virtual bool IsInited() const = 0; + virtual bool IsOpen() const = 0; + virtual bool IsPlaying() const = 0; + + virtual bool OnIdle() = 0; // return true if any work has been done + + virtual SoundDevice::Settings GetSettings() const = 0; + virtual SampleFormat GetActualSampleFormat() const = 0; + + virtual SoundDevice::BufferAttributes GetBufferAttributes() const = 0; + virtual SoundDevice::TimeInfo GetTimeInfo() const = 0; + + // Informational only, do not use for timing. + // Use GetStreamPositionFrames() for timing + virtual double GetCurrentLatency() const = 0; + virtual double GetCurrentUpdateInterval() const = 0; + + virtual int64 GetStreamPositionFrames() const = 0; + + virtual std::string GetStatistics() const = 0; + + virtual bool OpenDriverSettings() = 0; + +}; + + +//======== +class Base +//======== + : public IBase +{ + private: SoundDevice::ISource *m_Source; @@ -416,10 +490,6 @@ int64 m_StreamPositionOutputFrames; mpt::atomic_uint32_t m_RequestFlags; -public: - static const uint32 RequestFlagClose = 1<<0; - static const uint32 RequestFlagReset = 1<<1; - static const uint32 RequestFlagRestart = 1<<2; protected: @@ -493,7 +563,7 @@ bool IsOpen() const { return IsInited() && InternalIsOpen(); } bool IsPlaying() const { return m_IsPlaying; } - virtual bool OnIdle() { return false; } // return true if any work has been done + virtual bool OnIdle() { return false; } SoundDevice::Settings GetSettings() const { return m_Settings; } SampleFormat GetActualSampleFormat() const { return IsOpen() ? m_Settings.sampleFormat : SampleFormatInvalid; } @@ -501,8 +571,6 @@ SoundDevice::BufferAttributes GetBufferAttributes() const { return m_BufferAttributes; } SoundDevice::TimeInfo GetTimeInfo() const { return m_TimeInfo; } - // Informational only, do not use for timing. - // Use GetStreamPositionFrames() for timing virtual double GetCurrentLatency() const { return m_BufferAttributes.Latency; } double GetCurrentUpdateInterval() const; @@ -588,12 +656,12 @@ SoundDevice::Info FindDeviceInfo(const std::wstring &identifier) const; SoundDevice::Info FindDeviceInfoBestMatch(const std::wstring &identifier) const; - bool OpenDriverSettings(SoundDevice::ID id, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::Base *currentSoundDevice = nullptr); + bool OpenDriverSettings(SoundDevice::ID id, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr); - SoundDevice::Caps GetDeviceCaps(SoundDevice::ID id, SoundDevice::Base *currentSoundDevice = nullptr); - SoundDevice::DynamicCaps GetDeviceDynamicCaps(SoundDevice::ID id, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::Base *currentSoundDevice = nullptr, bool update = false); + SoundDevice::Caps GetDeviceCaps(SoundDevice::ID id, SoundDevice::IBase *currentSoundDevice = nullptr); + SoundDevice::DynamicCaps GetDeviceDynamicCaps(SoundDevice::ID id, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr, bool update = false); - SoundDevice::Base * CreateSoundDevice(SoundDevice::ID id); + SoundDevice::IBase * CreateSoundDevice(SoundDevice::ID id); }; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-09-16 07:52:30 UTC (rev 4295) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-09-17 08:49:10 UTC (rev 4296) @@ -184,14 +184,14 @@ //------------------------------------------------------------------------ : SoundDevice::Base(id, internalID) { - Init(); + InitMembers(); m_QueriedFeatures.reset(); m_UsedFeatures.reset(); } -void CASIODevice::Init() -//---------------------- +void CASIODevice::InitMembers() +//----------------------------- { m_pAsioDrv = nullptr; @@ -243,7 +243,7 @@ ASSERT(!IsDriverOpen()); - Init(); + InitMembers(); Log(mpt::String::Print("ASIO: Open(%1:'%2'): %3-bit, %4 channels, %5Hz, hw-timing=%6" , GetDeviceIndex() Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2014-09-16 07:52:30 UTC (rev 4295) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2014-09-17 08:49:10 UTC (rev 4296) @@ -95,7 +95,7 @@ ~CASIODevice(); private: - void Init(); + void InitMembers(); bool HandleRequests(); // return true if any work has been done void UpdateLatency(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |