From: <man...@us...> - 2013-10-13 06:49:55
|
Revision: 2880 http://sourceforge.net/p/modplug/code/2880 Author: manxorist Date: 2013-10-13 06:49:47 +0000 (Sun, 13 Oct 2013) Log Message: ----------- [Ref] sounddev: Make SoundDevice type and index more type-safe and remove old macros. [Ref] sounddev: Some related small refactorings. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Mpdlgs.h trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/TrackerSettings.h trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.h trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp trunk/OpenMPT/sounddev/SoundDeviceWaveout.h trunk/OpenMPT/sounddev/SoundDevices.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -247,14 +247,14 @@ if(!theApp.GetSoundDevicesManager()->FindDeviceInfo(TrackerSettings::Instance().m_nWaveDevice)) { // Fall back to default WaveOut device - TrackerSettings::Instance().m_nWaveDevice = SNDDEV_BUILD_ID(0, SNDDEV_WAVEOUT); + TrackerSettings::Instance().m_nWaveDevice = SoundDeviceID(); } if(TrackerSettings::Instance().m_MixerSettings.gdwMixingFreq == 0) { TrackerSettings::Instance().m_MixerSettings.gdwMixingFreq = MixerSettings().gdwMixingFreq; #ifndef NO_ASIO // If no mixing rate is specified and we're using ASIO, get a mixing rate supported by the device. - if(SNDDEV_GET_TYPE(TrackerSettings::Instance().m_nWaveDevice) == SNDDEV_ASIO) + if(TrackerSettings::Instance().m_nWaveDevice.GetType() == SNDDEV_ASIO) { ISoundDevice *dummy = theApp.GetSoundDevicesManager()->CreateSoundDevice(TrackerSettings::Instance().m_nWaveDevice); if(dummy) @@ -890,15 +890,15 @@ //-------------------------------------- { Util::lock_guard<Util::mutex> lock(m_SoundDeviceMutex); - const UINT nDevID = TrackerSettings::Instance().m_nWaveDevice; - if(gpSoundDevice && (gpSoundDevice->GetDeviceID() != nDevID)) + const SoundDeviceID deviceID = TrackerSettings::Instance().m_nWaveDevice; + if(gpSoundDevice && (gpSoundDevice->GetDeviceID() != deviceID)) { delete gpSoundDevice; gpSoundDevice = nullptr; } if(!gpSoundDevice) { - gpSoundDevice = theApp.GetSoundDevicesManager()->CreateSoundDevice(nDevID); + gpSoundDevice = theApp.GetSoundDevicesManager()->CreateSoundDevice(deviceID); } if(!gpSoundDevice) { @@ -1724,13 +1724,13 @@ } -BOOL CMainFrame::SetupSoundCard(DWORD deviceflags, DWORD rate, SampleFormat sampleformat, UINT nChns, UINT latency_ms, UINT updateinterval_ms, LONG wd) -//----------------------------------------------------------------------------------------------------------------------------------------------------- +BOOL CMainFrame::SetupSoundCard(DWORD deviceflags, DWORD rate, SampleFormat sampleformat, UINT nChns, UINT latency_ms, UINT updateinterval_ms, SoundDeviceID deviceID) +//-------------------------------------------------------------------------------------------------------------------------------------------------------------------- { const bool isPlaying = IsPlaying(); if ((TrackerSettings::Instance().GetSoundDeviceFlags() != deviceflags) || (TrackerSettings::Instance().m_MixerSettings.gdwMixingFreq != rate) - || (TrackerSettings::Instance().m_nWaveDevice != wd) + || (TrackerSettings::Instance().m_nWaveDevice != deviceID) || (TrackerSettings::Instance().m_LatencyMS != latency_ms) || (TrackerSettings::Instance().m_UpdateIntervalMS != updateinterval_ms) || (TrackerSettings::Instance().m_SampleFormat != sampleformat) @@ -1742,7 +1742,7 @@ if ((m_pSndFile) && (!m_pSndFile->IsPaused())) pActiveMod = GetModPlaying(); PauseMod(); } - TrackerSettings::Instance().m_nWaveDevice = wd; + TrackerSettings::Instance().m_nWaveDevice = deviceID; TrackerSettings::Instance().m_MixerSettings.gdwMixingFreq = rate; TrackerSettings::Instance().SetSoundDeviceFlags(deviceflags); TrackerSettings::Instance().m_LatencyMS = latency_ms; Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -440,7 +440,7 @@ BOOL StopRenderer(CSoundFile*); void SwitchToActiveView(); - BOOL SetupSoundCard(DWORD deviceflags, DWORD rate, SampleFormat sampleformat, UINT chns, UINT latency_ms, UINT updateinterval_ms, LONG wd); + BOOL SetupSoundCard(DWORD deviceflags, DWORD rate, SampleFormat sampleformat, UINT chns, UINT latency_ms, UINT updateinterval_ms, SoundDeviceID deviceID); BOOL SetupMiscOptions(); BOOL SetupPlayer(); Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -191,7 +191,7 @@ if(!TrackerSettings::Instance().m_MorePortaudio) { - if(it->type == SNDDEV_PORTAUDIO_ASIO || it->type == SNDDEV_PORTAUDIO_DS || it->type == SNDDEV_PORTAUDIO_WMME) + if(it->id.GetType() == SNDDEV_PORTAUDIO_ASIO || it->id.GetType() == SNDDEV_PORTAUDIO_DS || it->id.GetType() == SNDDEV_PORTAUDIO_WMME) { // skip those portaudio apis that are already implemented via our own ISoundDevice class // can be overwritten via [Sound Settings]MorePortaudio=1 @@ -204,7 +204,7 @@ cbi.mask = CBEIF_IMAGE | CBEIF_LPARAM | CBEIF_TEXT | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY; cbi.iItem = iItem; cbi.cchTextMax = 0; - switch(it->type) + switch(it->id.GetType()) { case SNDDEV_DSOUND: case SNDDEV_PORTAUDIO_DS: @@ -221,10 +221,13 @@ cbi.iSelectedImage = cbi.iImage; cbi.iOverlay = cbi.iImage; cbi.iIndent = 0; - cbi.lParam = SNDDEV_BUILD_ID(it->index, it->type); + cbi.lParam = it->id.GetIdRaw(); cbi.pszText = s; int pos = m_CbnDevice.InsertItem(&cbi); - if (cbi.lParam == (LONG)m_nSoundDevice) m_CbnDevice.SetCurSel(pos); + if(cbi.lParam == m_nSoundDevice.GetIdRaw()) + { + m_CbnDevice.SetCurSel(pos); + } iItem++; } } @@ -238,8 +241,8 @@ } -void COptionsSoundcard::UpdateChannels(int dev) -//--------------------------------------------- +void COptionsSoundcard::UpdateChannels(SoundDeviceID dev) +//------------------------------------------------------- { MPT_UNREFERENCED_PARAMETER(dev); CHAR s[128]; @@ -259,12 +262,12 @@ } -void COptionsSoundcard::UpdateSampleFormat(int dev) -//------------------------------------------------- +void COptionsSoundcard::UpdateSampleFormat(SoundDeviceID dev) +//----------------------------------------------------------- { UINT n = 0; m_CbnSampleFormat.ResetContent(); - const bool asio = SNDDEV_GET_TYPE(dev) == SNDDEV_ASIO; + const bool asio = dev.GetType() == SNDDEV_ASIO; if(asio) { m_SampleFormat = TrackerSettings::Instance().m_SampleFormat; @@ -363,7 +366,7 @@ int n = m_CbnDevice.GetCurSel(); if (n >= 0) { - int dev = m_CbnDevice.GetItemData(n); + SoundDeviceID dev = SoundDeviceID::FromIdRaw(m_CbnDevice.GetItemData(n)); UpdateControls(dev); UpdateSampleRates(dev); UpdateChannels(dev); @@ -374,8 +377,8 @@ // Fill the dropdown box with a list of valid sample rates, depending on the selected sound device. -void COptionsSoundcard::UpdateSampleRates(int dev) -//------------------------------------------------ +void COptionsSoundcard::UpdateSampleRates(SoundDeviceID dev) +//---------------------------------------------------------- { m_CbnMixingFreq.ResetContent(); @@ -426,13 +429,13 @@ } -void COptionsSoundcard::UpdateControls(int dev) -//--------------------------------------------- +void COptionsSoundcard::UpdateControls(SoundDeviceID dev) +//------------------------------------------------------- { - GetDlgItem(IDC_CHECK4)->EnableWindow((SNDDEV_GET_TYPE(dev) == SNDDEV_DSOUND || SNDDEV_GET_TYPE(dev) == SNDDEV_PORTAUDIO_WASAPI) ? TRUE : FALSE); - GetDlgItem(IDC_STATIC_UPDATEINTERVAL)->EnableWindow((SNDDEV_GET_TYPE(dev) == SNDDEV_ASIO) ? FALSE : TRUE); - GetDlgItem(IDC_COMBO_UPDATEINTERVAL)->EnableWindow((SNDDEV_GET_TYPE(dev) == SNDDEV_ASIO) ? FALSE : TRUE); - if(SNDDEV_GET_TYPE(dev) == SNDDEV_DSOUND) + GetDlgItem(IDC_CHECK4)->EnableWindow((dev.GetType() == SNDDEV_DSOUND || dev.GetType() == SNDDEV_PORTAUDIO_WASAPI) ? TRUE : FALSE); + GetDlgItem(IDC_STATIC_UPDATEINTERVAL)->EnableWindow((dev.GetType() == SNDDEV_ASIO) ? FALSE : TRUE); + GetDlgItem(IDC_COMBO_UPDATEINTERVAL)->EnableWindow((dev.GetType() == SNDDEV_ASIO) ? FALSE : TRUE); + if(dev.GetType() == SNDDEV_DSOUND) { GetDlgItem(IDC_CHECK4)->SetWindowText("Use primary buffer"); } else @@ -484,7 +487,10 @@ // Sound Device { int n = m_CbnDevice.GetCurSel(); - if (n >= 0) m_nSoundDevice = m_CbnDevice.GetItemData(n); + if(n >= 0) + { + m_nSoundDevice = SoundDeviceID::FromIdRaw(m_CbnDevice.GetItemData(n)); + } } // Latency { Modified: trunk/OpenMPT/mptrack/Mpdlgs.h =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/mptrack/Mpdlgs.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -29,21 +29,21 @@ DWORD m_nChannels; DWORD m_LatencyMS; DWORD m_UpdateIntervalMS; - DWORD m_nSoundDevice; + SoundDeviceID m_nSoundDevice; bool m_PreAmpNoteShowed; public: - COptionsSoundcard(DWORD rate, DWORD flags, SampleFormat sampleformat, DWORD chns, DWORD latency_ms, DWORD updateinterval_ms, DWORD sd):CPropertyPage(IDD_OPTIONS_SOUNDCARD) + COptionsSoundcard(DWORD rate, DWORD flags, SampleFormat sampleformat, DWORD chns, DWORD latency_ms, DWORD updateinterval_ms, SoundDeviceID sd):CPropertyPage(IDD_OPTIONS_SOUNDCARD) { m_dwRate = rate; m_SoundDeviceFlags = flags; m_SampleFormat = sampleformat; m_nChannels = chns; m_LatencyMS = latency_ms; m_UpdateIntervalMS = updateinterval_ms; m_nSoundDevice = sd; m_PreAmpNoteShowed = false; } void UpdateStatistics(); private: - void UpdateSampleRates(int dev); - void UpdateChannels(int dev); - void UpdateSampleFormat(int dev); - void UpdateControls(int dev); + void UpdateSampleRates(SoundDeviceID dev); + void UpdateChannels(SoundDeviceID dev); + void UpdateSampleFormat(SoundDeviceID dev); + void UpdateControls(SoundDeviceID dev); void SetPreAmpSliderPosition(); protected: Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -70,7 +70,7 @@ // Audio device gbLoopSong = TRUE; m_MorePortaudio = false; - m_nWaveDevice = SNDDEV_BUILD_ID(0, SNDDEV_WAVEOUT); // Default value will be overridden + m_nWaveDevice = SoundDeviceID(); // Default value will be overridden m_LatencyMS = SNDDEV_DEFAULT_LATENCY_MS; m_UpdateIntervalMS = SNDDEV_DEFAULT_UPDATEINTERVAL_MS; m_SoundDeviceExclusiveMode = false; @@ -332,11 +332,10 @@ } m_MorePortaudio = CMainFrame::GetPrivateProfileBool("Sound Settings", "MorePortaudio", m_MorePortaudio, iniFile); - DWORD defaultDevice = SNDDEV_BUILD_ID(0, SNDDEV_WAVEOUT); // first WaveOut device #ifndef NO_ASIO CASIODevice::baseChannel = GetPrivateProfileInt("Sound Settings", "ASIOBaseChannel", CASIODevice::baseChannel, iniFile); #endif // NO_ASIO - m_nWaveDevice = CMainFrame::GetPrivateProfileLong("Sound Settings", "WaveDevice", defaultDevice, iniFile); + m_nWaveDevice = SoundDeviceID::FromIdRaw(CMainFrame::GetPrivateProfileLong("Sound Settings", "WaveDevice", SoundDeviceID().GetIdRaw(), iniFile)); if(vIniVersion < MAKE_VERSION_NUMERIC(1, 22, 01, 03)) m_MixerSettings.MixerFlags |= OLD_SOUNDSETUP_SECONDARY; m_MixerSettings.MixerFlags = CMainFrame::GetPrivateProfileDWord("Sound Settings", "SoundSetup", m_MixerSettings.MixerFlags, iniFile); m_SoundDeviceExclusiveMode = CMainFrame::GetPrivateProfileBool("Sound Settings", "ExclusiveMode", m_SoundDeviceExclusiveMode, iniFile); @@ -364,7 +363,7 @@ { if(BufferLengthMS < OLD_SNDDEV_MINBUFFERLEN) BufferLengthMS = OLD_SNDDEV_MINBUFFERLEN; if(BufferLengthMS > OLD_SNDDEV_MAXBUFFERLEN) BufferLengthMS = OLD_SNDDEV_MAXBUFFERLEN; - if(SNDDEV_GET_TYPE(m_nWaveDevice) == SNDDEV_ASIO) + if(m_nWaveDevice.GetType() == SNDDEV_ASIO) { m_LatencyMS = BufferLengthMS; m_UpdateIntervalMS = BufferLengthMS / 8; @@ -612,7 +611,7 @@ if(BufferLengthMS != 0) { if((BufferLengthMS < OLD_SNDDEV_MINBUFFERLEN) || (BufferLengthMS > OLD_SNDDEV_MAXBUFFERLEN)) BufferLengthMS = 100; - if(SNDDEV_GET_TYPE(m_nWaveDevice) == SNDDEV_ASIO) + if(m_nWaveDevice.GetType() == SNDDEV_ASIO) { m_LatencyMS = BufferLengthMS; m_UpdateIntervalMS = BufferLengthMS / 8; @@ -810,7 +809,7 @@ CMainFrame::WritePrivateProfileDWord("Display", s, rgbCustomColors[ncol], iniFile); } - CMainFrame::WritePrivateProfileLong("Sound Settings", "WaveDevice", m_nWaveDevice, iniFile); + CMainFrame::WritePrivateProfileLong("Sound Settings", "WaveDevice", m_nWaveDevice.GetIdRaw(), iniFile); CMainFrame::WritePrivateProfileDWord("Sound Settings", "SoundSetup", m_MixerSettings.MixerFlags, iniFile); CMainFrame::WritePrivateProfileBool("Sound Settings", "ExclusiveMode", m_SoundDeviceExclusiveMode, iniFile); CMainFrame::WritePrivateProfileBool("Sound Settings", "BoostThreadPriority", m_SoundDeviceBoostThreadPriority, iniFile); Modified: trunk/OpenMPT/mptrack/TrackerSettings.h =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/mptrack/TrackerSettings.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -17,6 +17,7 @@ #include "../sounddsp/EQ.h" #include "../sounddsp/DSP.h" #include "../sounddsp/Reverb.h" +#include "../sounddev/SoundDevice.h" #include <bitset> ///////////////////////////////////////////////////////////////////////// @@ -180,7 +181,7 @@ // Audio Setup DWORD gbLoopSong; bool m_MorePortaudio; - LONG m_nWaveDevice; // use the SNDDEV_GET_NUMBER and SNDDEV_GET_TYPE macros to decode + SoundDeviceID m_nWaveDevice; DWORD m_LatencyMS; DWORD m_UpdateIntervalMS; bool m_SoundDeviceExclusiveMode; Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -31,13 +31,13 @@ // ISoundDevice base class // -ISoundDevice::ISoundDevice() -//-------------------------- +ISoundDevice::ISoundDevice(SoundDeviceID id, const std::wstring &internalID) +//-------------------------------------------------------------------------- + : m_Source(nullptr) + , m_ID(id) + , m_InternalID(internalID) { - m_Source = nullptr; - m_Index = 0; - m_RealLatencyMS = static_cast<float>(m_Settings.LatencyMS); m_RealUpdateIntervalMS = static_cast<float>(m_Settings.UpdateIntervalMS); @@ -53,14 +53,6 @@ } -void ISoundDevice::SetDevice(UINT index, const std::wstring &internalID) -//---------------------------------------------------------------------- -{ - m_Index = index; - m_InternalID = internalID; -} - - bool ISoundDevice::FillWaveFormatExtensible(WAVEFORMATEXTENSIBLE &WaveFormat) //--------------------------------------------------------------------------- { @@ -646,7 +638,7 @@ case SNDDEV_PORTAUDIO_WMME: case SNDDEV_PORTAUDIO_DS: case SNDDEV_PORTAUDIO_ASIO: - infos = CPortaudioDevice::EnumerateDevices(type); + infos = CPortaudioDevice::EnumerateDevices((SoundDeviceType)type); break; #endif // NO_PORTAUDIO @@ -656,12 +648,12 @@ } -const SoundDeviceInfo * SoundDevicesManager::FindDeviceInfo(UINT type, UINT index) const -//-------------------------------------------------------------------------------------- +const SoundDeviceInfo * SoundDevicesManager::FindDeviceInfo(SoundDeviceID id) const +//--------------------------------------------------------------------------------- { for(std::vector<SoundDeviceInfo>::const_iterator it = begin(); it != end(); ++it) { - if(it->type == type && it->index == index) + if(it->id == id) { return &(*it); } @@ -670,23 +662,23 @@ } -ISoundDevice * SoundDevicesManager::CreateSoundDevice(UINT type, UINT index) -//-------------------------------------------------------------------------- +ISoundDevice * SoundDevicesManager::CreateSoundDevice(SoundDeviceID id) +//--------------------------------------------------------------------- { - const SoundDeviceInfo *info = FindDeviceInfo(type, index); + const SoundDeviceInfo *info = FindDeviceInfo(id); if(!info) { return nullptr; } ISoundDevice *result = nullptr; - switch(type) + switch(id.GetType()) { - case SNDDEV_WAVEOUT: result = new CWaveDevice(); break; + case SNDDEV_WAVEOUT: result = new CWaveDevice(id, info->internalID); break; #ifndef NO_DSOUND - case SNDDEV_DSOUND: result = new CDSoundDevice(); break; + case SNDDEV_DSOUND: result = new CDSoundDevice(id, info->internalID); break; #endif // NO_DSOUND #ifndef NO_ASIO - case SNDDEV_ASIO: result = new CASIODevice(); break; + case SNDDEV_ASIO: result = new CASIODevice(id, info->internalID); break; #endif // NO_ASIO #ifndef NO_PORTAUDIO case SNDDEV_PORTAUDIO_WASAPI: @@ -694,14 +686,10 @@ case SNDDEV_PORTAUDIO_WMME: case SNDDEV_PORTAUDIO_DS: case SNDDEV_PORTAUDIO_ASIO: - result = SndDevPortaudioIsInitialized() ? new CPortaudioDevice(CPortaudioDevice::SndDevTypeToHostApi(type)) : nullptr; + result = SndDevPortaudioIsInitialized() ? new CPortaudioDevice(id, info->internalID) : nullptr; break; #endif // NO_PORTAUDIO } - if(result) - { - result->SetDevice(index, info->internalID); - } return result; } Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -53,9 +53,10 @@ // ISoundDevice Interface // -// Sound Device Types -enum // do not change old values, these get saved to the ini +enum SoundDeviceType { + // do not change old values, these get saved to the ini + SNDDEV_INVALID =-1, SNDDEV_WAVEOUT = 0, SNDDEV_DSOUND = 1, SNDDEV_ASIO = 2, @@ -67,12 +68,54 @@ SNDDEV_NUM_DEVTYPES }; -#define SNDDEV_DEVICE_MASK 0xFF // Mask for getting the device number -#define SNDDEV_DEVICE_SHIFT 8 // Shift amount for getting the device type -#define SNDDEV_GET_NUMBER(x) (x & SNDDEV_DEVICE_MASK) // Use this for getting the device number -#define SNDDEV_GET_TYPE(x) (x >> SNDDEV_DEVICE_SHIFT) // ...and this for getting the device type -#define SNDDEV_BUILD_ID(number, type) ((number & SNDDEV_DEVICE_MASK) | (type << SNDDEV_DEVICE_SHIFT)) // Build a sound device ID from device number and device type. +typedef uint8 SoundDeviceIndex; +template<typename T> +bool SoundDeviceIndexIsValid(const T & x) +{ + return 0 <= x && x <= std::numeric_limits<SoundDeviceIndex>::max(); +} + +//================= +class SoundDeviceID +//================= +{ +private: + SoundDeviceType type; + SoundDeviceIndex index; +public: + SoundDeviceID() : type(SNDDEV_WAVEOUT), index(0) {} + SoundDeviceID(SoundDeviceType type, SoundDeviceIndex index) + : type(type) + , index(index) + { + return; + } + SoundDeviceType GetType() const { return type; } + SoundDeviceIndex GetIndex() const { return index; } + bool operator == (const SoundDeviceID &cmp) const + { + return (type == cmp.type) && (index == cmp.index); + } + + bool operator != (const SoundDeviceID &cmp) const + { + return (type != cmp.type) || (index != cmp.index); + } +public: + // Do not change these. These functions are used to manipulate the value that gets stored in the settings. + template<typename T> + static SoundDeviceID FromIdRaw(T id_) + { + uint16 id = static_cast<uint16>(id_); + return SoundDeviceID((SoundDeviceType)((id>>8)&0xff), (id>>0)&0xff); + } + uint16 GetIdRaw() const + { + return static_cast<uint16>(((int)type<<8) | (index<<0)); + } +}; + #define SNDDEV_DEFAULT_LATENCY_MS 100 #define SNDDEV_DEFAULT_UPDATEINTERVAL_MS 5 @@ -120,11 +163,13 @@ friend class SoundDevicesManager; private: + ISoundSource *m_Source; + const SoundDeviceID m_ID; + protected: - UINT m_Index; std::wstring m_InternalID; SoundDeviceSettings m_Settings; @@ -144,16 +189,14 @@ void SourceAudioDone(ULONG NumSamples, ULONG SamplesLatency); public: - ISoundDevice(); + ISoundDevice(SoundDeviceID id, const std::wstring &internalID); virtual ~ISoundDevice(); void SetSource(ISoundSource *source) { m_Source = source; } ISoundSource *GetSource() const { return m_Source; } -protected: - void SetDevice(UINT index, const std::wstring &internalID); public: - UINT GetDeviceIndex() const { return m_Index; } - UINT GetDeviceID() const { return SNDDEV_BUILD_ID(GetDeviceIndex(), GetDeviceType()); } - + SoundDeviceID GetDeviceID() const { return m_ID; } + SoundDeviceType GetDeviceType() const { return m_ID.GetType(); } + SoundDeviceIndex GetDeviceIndex() const { return m_ID.GetIndex(); } std::wstring GetDeviceInternalID() const { return m_InternalID; } public: @@ -174,7 +217,6 @@ virtual int64 InternalGetStreamPositionSamples() const { return 0; } public: - virtual UINT GetDeviceType() const = 0; bool Open(const SoundDeviceSettings &settings); // Open a device bool Close(); // Close the currently open device void Start(); @@ -193,21 +235,14 @@ struct SoundDeviceInfo { - UINT type; - UINT index; + SoundDeviceID id; std::wstring name; std::wstring internalID; - SoundDeviceInfo() - : type(0) - , index(0) - { - return; - } - SoundDeviceInfo(UINT type, UINT index, const std::wstring &name, const std::wstring &id = std::wstring()) - : type(type) - , index(index) + SoundDeviceInfo() { } + SoundDeviceInfo(SoundDeviceID id, const std::wstring &name, const std::wstring &internalID = std::wstring()) + : id(id) , name(name) - , internalID(id) + , internalID(internalID) { return; } @@ -233,10 +268,8 @@ std::vector<SoundDeviceInfo>::const_iterator end() const { return m_SoundDevices.end(); } const std::vector<SoundDeviceInfo> & GetDeviceInfos() const { return m_SoundDevices; } - const SoundDeviceInfo * FindDeviceInfo(UINT type, UINT index) const; - const SoundDeviceInfo * FindDeviceInfo(UINT id) const { return FindDeviceInfo(SNDDEV_GET_TYPE(id), SNDDEV_GET_NUMBER(id)); } + const SoundDeviceInfo * FindDeviceInfo(SoundDeviceID id) const; - ISoundDevice * CreateSoundDevice(UINT type, UINT index); - ISoundDevice * CreateSoundDevice(UINT id) { return CreateSoundDevice(SNDDEV_GET_TYPE(id), SNDDEV_GET_NUMBER(id)); } + ISoundDevice * CreateSoundDevice(SoundDeviceID id); }; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -134,8 +134,11 @@ Log(" clsid=\"%s\"\n", s); #endif - // everything ok - devices.push_back(SoundDeviceInfo(SNDDEV_ASIO, devices.size(), mpt::String::Decode(description, mpt::CharsetLocale), internalID)); + if(SoundDeviceIndexIsValid(devices.size())) + { + // everything ok + devices.push_back(SoundDeviceInfo(SoundDeviceID(SNDDEV_ASIO, static_cast<SoundDeviceIndex>(devices.size())), mpt::String::Decode(description, mpt::CharsetLocale), internalID)); + } } } @@ -155,8 +158,9 @@ } -CASIODevice::CASIODevice() -//------------------------ +CASIODevice::CASIODevice(SoundDeviceID id, const std::wstring &internalID) +//------------------------------------------------------------------------ + : ISoundDevice(id, internalID) { m_pAsioDrv = NULL; m_nAsioBufferLen = 0; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -52,11 +52,10 @@ static int baseChannel; public: - CASIODevice(); + CASIODevice(SoundDeviceID id, const std::wstring &internalID); ~CASIODevice(); public: - UINT GetDeviceType() const { return SNDDEV_ASIO; } bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -62,9 +62,12 @@ { return TRUE; } + if(!SoundDeviceIndexIsValid(devices.size())) + { + return FALSE; + } SoundDeviceInfo info; - info.type = SNDDEV_DSOUND; - info.index = devices.size(); + info.id = SoundDeviceID(SNDDEV_DSOUND, static_cast<SoundDeviceIndex>(devices.size())); info.name = lpstrDescription; if(lpGuid) { @@ -84,8 +87,9 @@ } -CDSoundDevice::CDSoundDevice() -//---------------------------- +CDSoundDevice::CDSoundDevice(SoundDeviceID id, const std::wstring &internalID) +//---------------------------------------------------------------------------- + : CSoundDeviceWithThread(id, internalID) { m_piDS = NULL; m_pPrimary = NULL; Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -41,11 +41,10 @@ DWORD m_dwWritePos, m_dwLatency; public: - CDSoundDevice(); + CDSoundDevice(SoundDeviceID id, const std::wstring &internalID); ~CDSoundDevice(); public: - UINT GetDeviceType() const { return SNDDEV_DSOUND; } bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -26,10 +26,11 @@ #ifndef NO_PORTAUDIO -CPortaudioDevice::CPortaudioDevice(PaHostApiIndex hostapi) -//-------------------------------------------------------- +CPortaudioDevice::CPortaudioDevice(SoundDeviceID id, const std::wstring &internalID) +//---------------------------------------------------------------------------------- + : ISoundDevice(id, internalID) { - m_HostApi = hostapi; + m_HostApi = SndDevTypeToHostApi(id.GetType()); MemsetZero(m_StreamParameters); m_Stream = 0; m_CurrentFrameCount = 0; @@ -274,20 +275,20 @@ } -int CPortaudioDevice::HostApiToSndDevType(PaHostApiIndex hostapi) -//--------------------------------------------------------------- +SoundDeviceType CPortaudioDevice::HostApiToSndDevType(PaHostApiIndex hostapi) +//--------------------------------------------------------------------------- { if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paWASAPI)) return SNDDEV_PORTAUDIO_WASAPI; if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paWDMKS)) return SNDDEV_PORTAUDIO_WDMKS; if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paMME)) return SNDDEV_PORTAUDIO_WMME; if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paDirectSound)) return SNDDEV_PORTAUDIO_DS; if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paASIO)) return SNDDEV_PORTAUDIO_ASIO; - return -1; + return SNDDEV_INVALID; } -PaHostApiIndex CPortaudioDevice::SndDevTypeToHostApi(int snddevtype) -//------------------------------------------------------------------ +PaHostApiIndex CPortaudioDevice::SndDevTypeToHostApi(SoundDeviceType snddevtype) +//------------------------------------------------------------------------------ { if(snddevtype == SNDDEV_PORTAUDIO_WASAPI) return Pa_HostApiTypeIdToHostApiIndex(paWASAPI); if(snddevtype == SNDDEV_PORTAUDIO_WDMKS) return Pa_HostApiTypeIdToHostApiIndex(paWDMKS); @@ -298,17 +299,16 @@ } -bool CPortaudioDevice::EnumerateDevices(SoundDeviceInfo &result, UINT nIndex, PaHostApiIndex hostapi) -//--------------------------------------------------------------------------------------------------- +bool CPortaudioDevice::EnumerateDevices(SoundDeviceInfo &result, SoundDeviceIndex index, PaHostApiIndex hostapi) +//-------------------------------------------------------------------------------------------------------------- { result = SoundDeviceInfo(); - PaDeviceIndex dev = HostApiOutputIndexToGlobalDeviceIndex(nIndex, hostapi); + PaDeviceIndex dev = HostApiOutputIndexToGlobalDeviceIndex(index, hostapi); if(dev == -1) return false; if(!Pa_GetDeviceInfo(dev)) return false; - result.type = HostApiToSndDevType(hostapi); - result.index = nIndex; + result.id = SoundDeviceID(HostApiToSndDevType(hostapi), index); result.name = mpt::String::Decode( mpt::String::Format("%s - %s%s (portaudio)", Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->name, @@ -320,15 +320,15 @@ } -std::vector<SoundDeviceInfo> CPortaudioDevice::EnumerateDevices(UINT type) -//------------------------------------------------------------------------ +std::vector<SoundDeviceInfo> CPortaudioDevice::EnumerateDevices(SoundDeviceType type) +//----------------------------------------------------------------------------------- { std::vector<SoundDeviceInfo> devices; if(!SndDevPortaudioIsInitialized()) { return devices; } - for(UINT index = 0; ; ++index) + for(SoundDeviceIndex index = 0; ; ++index) { SoundDeviceInfo info; if(!EnumerateDevices(info, index, CPortaudioDevice::SndDevTypeToHostApi(type))) Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -39,11 +39,10 @@ float m_CurrentRealLatencyMS; public: - CPortaudioDevice(PaHostApiIndex hostapi); + CPortaudioDevice(SoundDeviceID id, const std::wstring &internalID); ~CPortaudioDevice(); public: - UINT GetDeviceType() const { return HostApiToSndDevType(m_HostApi); } bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); @@ -74,13 +73,13 @@ ); static PaDeviceIndex HostApiOutputIndexToGlobalDeviceIndex(int hostapioutputdeviceindex, PaHostApiIndex hostapi); - static int HostApiToSndDevType(PaHostApiIndex hostapi); - static PaHostApiIndex SndDevTypeToHostApi(int snddevtype); + static SoundDeviceType HostApiToSndDevType(PaHostApiIndex hostapi); + static PaHostApiIndex SndDevTypeToHostApi(SoundDeviceType snddevtype); - static std::vector<SoundDeviceInfo> EnumerateDevices(UINT type); + static std::vector<SoundDeviceInfo> EnumerateDevices(SoundDeviceType type); private: - static bool EnumerateDevices(SoundDeviceInfo &result, UINT nIndex, PaHostApiIndex hostapi); + static bool EnumerateDevices(SoundDeviceInfo &result, SoundDeviceIndex index, PaHostApiIndex hostapi); }; Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-10-13 06:49:47 UTC (rev 2880) @@ -25,8 +25,9 @@ // -CWaveDevice::CWaveDevice() -//------------------------ +CWaveDevice::CWaveDevice(SoundDeviceID id, const std::wstring &internalID) +//------------------------------------------------------------------------ + : CSoundDeviceWithThread(id, internalID) { m_hWaveOut = NULL; m_nWaveBufferSize = 0; @@ -223,9 +224,12 @@ UINT numDevs = waveOutGetNumDevs(); for(UINT index = 0; index <= numDevs; ++index) { + if(!SoundDeviceIndexIsValid(index)) + { + break; + } SoundDeviceInfo info; - info.type = SNDDEV_WAVEOUT; - info.index = index; + info.id = SoundDeviceID(SNDDEV_WAVEOUT, static_cast<SoundDeviceIndex>(index)); if(index == 0) { info.name = L"Auto (Wave Mapper)"; Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -40,11 +40,10 @@ std::vector<std::vector<char> > m_WaveBuffersData; public: - CWaveDevice(); + CWaveDevice(SoundDeviceID id, const std::wstring &internalID); ~CWaveDevice(); public: - UINT GetDeviceType() const { return SNDDEV_WAVEOUT; } bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); Modified: trunk/OpenMPT/sounddev/SoundDevices.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevices.h 2013-10-13 06:29:24 UTC (rev 2879) +++ trunk/OpenMPT/sounddev/SoundDevices.h 2013-10-13 06:49:47 UTC (rev 2880) @@ -63,7 +63,7 @@ private: void FillAudioBufferLocked(); public: - CSoundDeviceWithThread() : m_AudioThread(*this) {} + CSoundDeviceWithThread(SoundDeviceID id, const std::wstring &internalID) : ISoundDevice(id, internalID), m_AudioThread(*this) {} virtual ~CSoundDeviceWithThread() {} void InternalStart(); void InternalStop(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |