From: <man...@us...> - 2013-10-19 14:21:38
|
Revision: 2935 http://sourceforge.net/p/modplug/code/2935 Author: manxorist Date: 2013-10-19 14:21:30 +0000 (Sat, 19 Oct 2013) Log Message: ----------- Merged revision(s) 2923-2934 from branches/manx/sounddev: [New] Add button to re-enumerate sound device to soundcard options dialog. This allows selecting sound devices that got added/installed while OpenMPT was already running. [Ref] sounddev: Cache the supported sample rates for ASIO and PortAudio devices, so that selecting such a device does not potentially stall the GUI (because querying sample rates for ASIO could take some time or even fail if the hardware is unavailable). ........ [Imp] sounddev: Only show supported sample rates for DirectSound devices (mainly affects XP and older or Wine systems). ........ [Fix] sounddev: Use uint32 instead of std::uint32_t. ........ [Ref] sounddev: Tiny cleanups. ........ [Ref] sounddev: Simplify device caps handling. ........ [Ref] sounddev: Shorten portaudio device names. ........ [Var] Make soundcard options dialog less ugly. ........ [Var] Make sound device combobox a bit wider. ........ Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Mpdlgs.h trunk/OpenMPT/mptrack/mptrack.rc 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 Property Changed: ---------------- trunk/OpenMPT/ Index: trunk/OpenMPT =================================================================== --- trunk/OpenMPT 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT 2013-10-19 14:21:30 UTC (rev 2935) Property changes on: trunk/OpenMPT ___________________________________________________________________ Modified: svn:mergeinfo ## -14,6 +14,7 ## /branches/manx/serialization-utils-cleanup:2382-2386,2395 /branches/manx/snddev:2780-2788 /branches/manx/snddev-fixes:1605-1713 +/branches/manx/sounddev:2923-2934 /branches/manx/stdstring-names:2223,2228 /branches/manx/stdstring-song-name:2462-2463 /branches/manx/unarchiver:1887-1888 \ No newline at end of property Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-10-19 14:21:30 UTC (rev 2935) @@ -256,13 +256,7 @@ // If no mixing rate is specified and we're using ASIO, get a mixing rate supported by the device. if(TrackerSettings::Instance().m_nWaveDevice.GetType() == SNDDEV_ASIO) { - ISoundDevice *dummy = theApp.GetSoundDevicesManager()->CreateSoundDevice(TrackerSettings::Instance().m_nWaveDevice); - if(dummy) - { - dummy->SetMessageReceiver(CMainFrame::GetMainFrame()); - TrackerSettings::Instance().m_MixerSettings.gdwMixingFreq = dummy->GetCurrentSampleRate(); - delete dummy; - } + TrackerSettings::Instance().m_MixerSettings.gdwMixingFreq = theApp.GetSoundDevicesManager()->GetDeviceCaps(TrackerSettings::Instance().m_nWaveDevice, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice).currentSampleRate; } #endif // NO_ASIO } Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-10-19 14:21:30 UTC (rev 2935) @@ -76,6 +76,7 @@ ON_CBN_SELCHANGE(IDC_COMBO6, OnSettingsChanged) ON_CBN_EDITCHANGE(IDC_COMBO2, OnSettingsChanged) ON_CBN_EDITCHANGE(IDC_COMBO_UPDATEINTERVAL, OnSettingsChanged) + ON_COMMAND(IDC_BUTTON1, OnSoundCardRescan) END_MESSAGE_MAP() @@ -98,23 +99,45 @@ } +void COptionsSoundcard::OnSoundCardRescan() +//----------------------------------------- +{ + { + // Close sound device because IDs might change when re-enumerating which could cause all kinds of havoc. + CMainFrame::GetMainFrame()->audioCloseDevice(); + delete CMainFrame::GetMainFrame()->gpSoundDevice; + CMainFrame::GetMainFrame()->gpSoundDevice = nullptr; + } + theApp.GetSoundDevicesManager()->ReEnumerate(); + UpdateEverything(); +} + + BOOL COptionsSoundcard::OnInitDialog() //------------------------------------ { - CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); - BOOL bAsio = FALSE; + CPropertyPage::OnInitDialog(); + UpdateEverything(); + return TRUE; +} + + +void COptionsSoundcard::UpdateEverything() +//---------------------------------------- +{ + CHAR s[128]; - CPropertyPage::OnInitDialog(); - if(TrackerSettings::Instance().m_MixerSettings.MixerFlags & SNDMIX_SOFTPANNING) CheckDlgButton(IDC_CHECK2, MF_CHECKED); - if(m_Settings.ExclusiveMode) CheckDlgButton(IDC_CHECK4, MF_CHECKED); - if(m_Settings.BoostThreadPriority) CheckDlgButton(IDC_CHECK5, MF_CHECKED); + CheckDlgButton(IDC_CHECK2, (TrackerSettings::Instance().m_MixerSettings.MixerFlags & SNDMIX_SOFTPANNING) ? MF_CHECKED : MF_UNCHECKED); + CheckDlgButton(IDC_CHECK4, m_Settings.ExclusiveMode ? MF_CHECKED : MF_UNCHECKED); + CheckDlgButton(IDC_CHECK5, m_Settings.BoostThreadPriority ? MF_CHECKED : MF_UNCHECKED); // Sampling Rate UpdateSampleRates(m_nSoundDevice); // Max Mixing Channels { + m_CbnPolyphony.ResetContent(); for (UINT n = 0; n < CountOf(nCPUMix); n++) { wsprintf(s, "%d (%s)", nCPUMix[n], szCPUNames[n]); @@ -124,6 +147,7 @@ } // latency { + m_CbnLatencyMS.ResetContent(); wsprintf(s, "%d ms", m_Settings.LatencyMS); m_CbnLatencyMS.SetWindowText(s); m_CbnLatencyMS.AddString("1 ms"); @@ -146,6 +170,7 @@ } // update interval { + m_CbnUpdateIntervalMS.ResetContent(); wsprintf(s, "%d ms", m_Settings.UpdateIntervalMS); m_CbnUpdateIntervalMS.SetWindowText(s); m_CbnUpdateIntervalMS.AddString("1 ms"); @@ -179,10 +204,9 @@ } // Sound Device { - if (pMainFrm) - { - m_CbnDevice.SetImageList(pMainFrm->GetImageList()); - } + m_CbnDevice.ResetContent(); + m_CbnDevice.SetImageList(CMainFrame::GetMainFrame()->GetImageList()); + COMBOBOXEXITEM cbi; UINT iItem = 0; @@ -212,7 +236,6 @@ break; case SNDDEV_ASIO: case SNDDEV_PORTAUDIO_ASIO: - bAsio = TRUE; cbi.iImage = IMAGE_ASIO; break; default: @@ -237,7 +260,6 @@ UpdateChannels(m_nSoundDevice); UpdateSampleFormat(m_nSoundDevice); - return TRUE; } @@ -382,36 +404,11 @@ { m_CbnMixingFreq.ResetContent(); - std::vector<uint32> samplerates = TrackerSettings::Instance().GetSampleRates(); + std::vector<uint32> samplerates; { Util::lock_guard<Util::mutex> lock(CMainFrame::GetMainFrame()->m_SoundDeviceMutex); - ISoundDevice *dummy = nullptr; - bool justCreated = false; - if(TrackerSettings::Instance().m_nWaveDevice == dev) - { - // If this is the currently active sound device, it might already be playing something, so we shouldn't create yet another instance of it. - dummy = CMainFrame::GetMainFrame()->gpSoundDevice; - } - if(dummy == nullptr) - { - justCreated = true; - dummy = theApp.GetSoundDevicesManager()->CreateSoundDevice(dev); - if(dummy) - { - dummy->SetMessageReceiver(CMainFrame::GetMainFrame()); - } - } - - if(dummy != nullptr) - { - // Now we can query the supported sample rates. - samplerates = dummy->GetSampleRates(samplerates); - if(justCreated) - { - delete dummy; - } - } + samplerates = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice).supportedSampleRates; } if(samplerates.empty()) Modified: trunk/OpenMPT/mptrack/Mpdlgs.h =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.h 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/mptrack/Mpdlgs.h 2013-10-19 14:21:30 UTC (rev 2935) @@ -22,6 +22,7 @@ CComboBox m_CbnLatencyMS, m_CbnUpdateIntervalMS, m_CbnMixingFreq, m_CbnPolyphony, m_CbnChannels, m_CbnSampleFormat; CSliderCtrl m_SliderStereoSep, m_SliderPreAmp; CEdit m_EditStatistics; + CButton m_BtnRescan; SoundDeviceSettings m_Settings; SoundDeviceID m_nSoundDevice; bool m_PreAmpNoteShowed; @@ -33,6 +34,7 @@ void UpdateStatistics(); private: + void UpdateEverything(); void UpdateSampleRates(SoundDeviceID dev); void UpdateChannels(SoundDeviceID dev); void UpdateSampleFormat(SoundDeviceID dev); @@ -49,6 +51,7 @@ afx_msg void OnSettingsChanged() { SetModified(TRUE); } afx_msg void OnHScroll(UINT, UINT, CScrollBar *); afx_msg void OnVScroll(UINT, UINT, CScrollBar *); + afx_msg void OnSoundCardRescan(); DECLARE_MESSAGE_MAP() }; Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/mptrack/mptrack.rc 2013-10-19 14:21:30 UTC (rev 2935) @@ -1269,14 +1269,15 @@ LTEXT "Description",IDC_TEXT1,144,126,111,138 END -IDD_OPTIONS_SOUNDCARD DIALOGEX 0, 0, 272, 263 +IDD_OPTIONS_SOUNDCARD DIALOGEX 0, 0, 268, 263 STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION CAPTION "Sound Card" FONT 8, "MS Shell Dlg", 0, 0, 0x0 BEGIN GROUPBOX "",IDC_STATIC,6,6,258,114 - LTEXT "Sound Device:",IDC_STATIC,12,18,54,8 - CONTROL "",IDC_COMBO1,"ComboBoxEx32",CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP,12,30,246,96 + LTEXT "Sound Device:",IDC_STATIC,12,18,47,8 + CONTROL "",IDC_COMBO1,"ComboBoxEx32",CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP,12,30,204,96 + PUSHBUTTON "Rescan",IDC_BUTTON1,222,30,36,12 LTEXT "Latency:",IDC_STATIC,12,48,54,12,SS_CENTERIMAGE COMBOBOX IDC_COMBO2,72,48,66,83,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP CONTROL "Use device exclusively",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,144,48,102,12 @@ -1745,7 +1746,7 @@ IDD_OPTIONS_SOUNDCARD, DIALOG BEGIN RIGHTMARGIN, 246 - BOTTOMMARGIN, 166 + BOTTOMMARGIN, 160 END IDD_MIDIMACRO, DIALOG Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-19 14:21:30 UTC (rev 2935) @@ -54,6 +54,15 @@ } +SoundDeviceCaps ISoundDevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) +//------------------------------------------------------------------------------------- +{ + SoundDeviceCaps result; + result.supportedSampleRates = baseSampleRates; + return result; +} + + bool ISoundDevice::FillWaveFormatExtensible(WAVEFORMATEXTENSIBLE &WaveFormat) //--------------------------------------------------------------------------- { @@ -620,7 +629,12 @@ void SoundDevicesManager::ReEnumerate() //------------------------------------- { +#ifndef NO_PORTAUDIO + SndDevPortaudioUnnitialize(); + SndDevPortaudioInitialize(); +#endif // NO_PORTAUDIO m_SoundDevices.clear(); + m_DeviceCaps.clear(); for(int type = 0; type < SNDDEV_NUM_DEVTYPES; ++type) { std::vector<SoundDeviceInfo> infos; @@ -673,6 +687,29 @@ } +SoundDeviceCaps SoundDevicesManager::GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver, ISoundDevice *currentSoundDevice) +//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +{ + if(m_DeviceCaps.find(id) == m_DeviceCaps.end()) + { + if(currentSoundDevice && FindDeviceInfo(id) && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id)->internalID)) + { + m_DeviceCaps[id] = currentSoundDevice->GetDeviceCaps(baseSampleRates); + } else + { + ISoundDevice *dummy = CreateSoundDevice(id); + if(dummy) + { + dummy->SetMessageReceiver(messageReceiver); + m_DeviceCaps[id] = dummy->GetDeviceCaps(baseSampleRates); + } + delete dummy; + } + } + return m_DeviceCaps[id]; +} + + ISoundDevice * SoundDevicesManager::CreateSoundDevice(SoundDeviceID id) //--------------------------------------------------------------------- { @@ -708,9 +745,6 @@ SoundDevicesManager::SoundDevicesManager() //---------------------------------------- { -#ifndef NO_PORTAUDIO - SndDevPortaudioInitialize(); -#endif // NO_PORTAUDIO ReEnumerate(); } Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-19 14:21:30 UTC (rev 2935) @@ -14,6 +14,7 @@ #include "../common/mutex.h" #include "../soundlib/SampleFormat.h" +#include <map> #include <vector> @@ -114,6 +115,10 @@ { return (type != cmp.type) || (index != cmp.index); } + bool operator < (const SoundDeviceID &cmp) const + { + return (type < cmp.type) || (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> @@ -181,6 +186,18 @@ }; +struct SoundDeviceCaps +{ + uint32 currentSampleRate; + std::vector<uint32> supportedSampleRates; // Which samplerates are actually supported by the device. Currently only implemented properly for ASIO, DirectSound and PortAudio. + SoundDeviceCaps() + : currentSampleRate(0) + { + return; + } +}; + + class SoundDevicesManager; @@ -231,6 +248,8 @@ SoundDeviceIndex GetDeviceIndex() const { return m_ID.GetIndex(); } std::wstring GetDeviceInternalID() const { return m_InternalID; } + virtual SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); + public: float GetRealLatencyMS() const { return m_RealLatencyMS; } float GetRealUpdateIntervalMS() const { return m_RealUpdateIntervalMS; } @@ -259,9 +278,6 @@ virtual bool IsOpen() const = 0; virtual UINT GetNumBuffers() { return 0; } virtual float GetCurrentRealLatencyMS() { return GetRealLatencyMS(); } - virtual UINT GetCurrentSampleRate() { return 0; } - // Return which samplerates are actually supported by the device. Currently only implemented properly for ASIO and PortAudio. - virtual std::vector<uint32> GetSampleRates(const std::vector<uint32> &samplerates) { return samplerates; } }; @@ -287,6 +303,7 @@ { private: std::vector<SoundDeviceInfo> m_SoundDevices; + std::map<SoundDeviceID, SoundDeviceCaps> m_DeviceCaps; public: SoundDevicesManager(); @@ -302,6 +319,8 @@ const SoundDeviceInfo * FindDeviceInfo(SoundDeviceID id) const; + SoundDeviceCaps GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr); + ISoundDevice * CreateSoundDevice(SoundDeviceID id); }; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-10-19 14:21:30 UTC (rev 2935) @@ -717,63 +717,43 @@ } -std::vector<uint32> CASIODevice::GetSampleRates(const std::vector<uint32> &samplerates) -//------------------------------------------------------------------------------------- +SoundDeviceCaps CASIODevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) +//------------------------------------------------------------------------------------ { - std::vector<uint32> results; + SoundDeviceCaps caps; + const bool wasOpen = (m_pAsioDrv != NULL); if(!wasOpen) { OpenDevice(); if(m_pAsioDrv == NULL) { - return results; + return caps; } } - for(size_t i = 0; i < samplerates.size(); i++) + ASIOSampleRate samplerate; + if(m_pAsioDrv->getSampleRate(&samplerate) != ASE_OK) { - if(m_pAsioDrv->canSampleRate((ASIOSampleRate)samplerates[i]) == ASE_OK) - { - results.push_back(samplerates[i]); - } + samplerate = 0; } + caps.currentSampleRate = Util::Round<uint32>(samplerate); - if(!wasOpen) + for(size_t i = 0; i < baseSampleRates.size(); i++) { - CloseDevice(); - } - - return results; -} - - -// If the device is open, this returns the current sample rate. If it's not open, it returns some sample rate supported by the device. -UINT CASIODevice::GetCurrentSampleRate() -//-------------------------------------- -{ - const bool wasOpen = (m_pAsioDrv != NULL); - if(!wasOpen) - { - OpenDevice(); - if(m_pAsioDrv == NULL) + if(m_pAsioDrv->canSampleRate((ASIOSampleRate)baseSampleRates[i]) == ASE_OK) { - return 0; + caps.supportedSampleRates.push_back(baseSampleRates[i]); } } - ASIOSampleRate samplerate; - if(m_pAsioDrv->getSampleRate(&samplerate) != ASE_OK) - { - samplerate = 0; - } - if(!wasOpen) { CloseDevice(); } - return (UINT)samplerate; + return caps; } + #endif // NO_ASIO Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-10-19 14:21:30 UTC (rev 2935) @@ -66,8 +66,7 @@ UINT GetNumBuffers() { return 2; } float GetCurrentRealLatencyMS() { return m_nAsioBufferLen * 2 * 1000.0f / m_Settings.Samplerate; } - std::vector<uint32> GetSampleRates(const std::vector<uint32> &samplerates); - UINT GetCurrentSampleRate(); + SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); public: static std::vector<SoundDeviceInfo> EnumerateDevices(); Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-10-19 14:21:30 UTC (rev 2935) @@ -28,6 +28,10 @@ #ifndef NO_DSOUND +#define DSOUND_MINBUFFERSIZE 1024 +#define DSOUND_MAXBUFFERSIZE SNDDEV_MAXBUFFERSIZE + + static std::wstring GuidToString(GUID guid) //----------------------------------------- { @@ -108,6 +112,58 @@ } +SoundDeviceCaps CDSoundDevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) +//-------------------------------------------------------------------------------------- +{ + SoundDeviceCaps caps; + IDirectSound *dummy = nullptr; + IDirectSound *ds = nullptr; + if(IsOpen()) + { + ds = m_piDS; + } else + { + const std::wstring internalID = GetDeviceInternalID(); + GUID guid = internalID.empty() ? GUID() : StringToGuid(internalID); + if(DirectSoundCreate(internalID.empty() ? NULL : &guid, &dummy, NULL) != DS_OK) + { + return caps; + } + if(!dummy) + { + return caps; + } + ds = dummy; + } + DSCAPS dscaps; + MemsetZero(dscaps); + dscaps.dwSize = sizeof(dscaps); + if(DS_OK != ds->GetCaps(&dscaps)) + { + // nothing known about supported sample rates + } else if(dscaps.dwMaxSecondarySampleRate == 0) + { + // nothing known about supported sample rates + } else + { + for(std::size_t i = 0; i < baseSampleRates.size(); ++i) + { + if(dscaps.dwMinSecondarySampleRate <= baseSampleRates[i] && baseSampleRates[i] <= dscaps.dwMaxSecondarySampleRate) + { + caps.supportedSampleRates.push_back(baseSampleRates[i]); + } + } + } + if(dummy) + { + dummy->Release(); + dummy = nullptr; + } + ds = nullptr; + return caps; +} + + bool CDSoundDevice::InternalOpen() //-------------------------------- { Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-10-19 14:21:30 UTC (rev 2935) @@ -24,9 +24,6 @@ #ifndef NO_DSOUND -#define DSOUND_MINBUFFERSIZE 1024 -#define DSOUND_MAXBUFFERSIZE SNDDEV_MAXBUFFERSIZE - //================================================ class CDSoundDevice: public CSoundDeviceWithThread //================================================ @@ -54,6 +51,7 @@ bool IsOpen() const { return (m_pMixBuffer != NULL); } UINT GetNumBuffers() { return 1; } // meaning 1 ring buffer float GetCurrentRealLatencyMS() { return m_dwLatency * 1000.0f / m_nBytesPerSec; } + SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); protected: DWORD LockBuffer(DWORD dwBytes, LPVOID *lpBuf1, LPDWORD lpSize1, LPVOID *lpBuf2, LPDWORD lpSize2); Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-10-19 14:21:30 UTC (rev 2935) @@ -160,16 +160,16 @@ } -std::vector<uint32> CPortaudioDevice::GetSampleRates(const std::vector<uint32> &samplerates) -//------------------------------------------------------------------------------------------ +SoundDeviceCaps CPortaudioDevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) +//----------------------------------------------------------------------------------------- { - std::vector<uint32> results; + SoundDeviceCaps caps; PaDeviceIndex device = HostApiOutputIndexToGlobalDeviceIndex(GetDeviceIndex(), m_HostApi); if(device == -1) { - return results; + return caps; } - for(UINT n=0; n<samplerates.size(); n++) + for(UINT n=0; n<baseSampleRates.size(); n++) { PaStreamParameters StreamParameters; MemsetZero(StreamParameters); @@ -187,12 +187,12 @@ m_WasapiStreamInfo.flags = paWinWasapiExclusive; m_StreamParameters.hostApiSpecificStreamInfo = &m_WasapiStreamInfo; } - if(Pa_IsFormatSupported(NULL, &StreamParameters, samplerates[n]) == paFormatIsSupported) + if(Pa_IsFormatSupported(NULL, &StreamParameters, baseSampleRates[n]) == paFormatIsSupported) { - results.push_back(samplerates[n]); + caps.supportedSampleRates.push_back(baseSampleRates[n]); } } - return results; + return caps; } @@ -299,6 +299,18 @@ } +std::string CPortaudioDevice::HostApiToString(PaHostApiIndex hostapi) +//------------------------------------------------------------------- +{ + if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paWASAPI)) return "WASAPI"; + if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paWDMKS)) return "WDM-KS"; + if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paMME)) return "MME"; + if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paDirectSound)) return "DS"; + if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paASIO)) return "ASIO"; + return "PortAudio"; +} + + bool CPortaudioDevice::EnumerateDevices(SoundDeviceInfo &result, SoundDeviceIndex index, PaHostApiIndex hostapi) //-------------------------------------------------------------------------------------------------------------- { @@ -310,8 +322,8 @@ return false; 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, + mpt::String::Format("%s - %s%s", + HostApiToString(Pa_GetDeviceInfo(dev)->hostApi).c_str(), Pa_GetDeviceInfo(dev)->name, Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == (PaDeviceIndex)dev ? " (Default)" : "" ), Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-10-19 14:21:30 UTC (rev 2935) @@ -54,7 +54,7 @@ float GetCurrentRealLatencyMS(); bool InternalHasGetStreamPosition() const { return false; } int64 InternalGetStreamPositionSamples() const; - std::vector<uint32> GetSampleRates(const std::vector<uint32> &samplerates); + SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); int StreamCallback( const void *input, void *output, @@ -72,6 +72,8 @@ void *userData ); + static std::string HostApiToString(PaHostApiIndex hostapi); + static PaDeviceIndex HostApiOutputIndexToGlobalDeviceIndex(int hostapioutputdeviceindex, PaHostApiIndex hostapi); static SoundDeviceType HostApiToSndDevType(PaHostApiIndex hostapi); static PaHostApiIndex SndDevTypeToHostApi(SoundDeviceType snddevtype); Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-10-19 14:21:30 UTC (rev 2935) @@ -25,6 +25,11 @@ // +#define WAVEOUT_MAXBUFFERS 256 +#define WAVEOUT_MINBUFFERSIZE 1024 +#define WAVEOUT_MAXBUFFERSIZE 65536 + + CWaveDevice::CWaveDevice(SoundDeviceID id, const std::wstring &internalID) //------------------------------------------------------------------------ : CSoundDeviceWithThread(id, internalID) Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-10-19 14:17:52 UTC (rev 2934) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-10-19 14:21:30 UTC (rev 2935) @@ -20,10 +20,6 @@ // MMSYSTEM WaveOut device // -#define WAVEOUT_MAXBUFFERS 256 -#define WAVEOUT_MINBUFFERSIZE 1024 -#define WAVEOUT_MAXBUFFERSIZE 65536 - //============================================== class CWaveDevice: public CSoundDeviceWithThread //============================================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |