From: <sag...@us...> - 2010-10-05 16:55:27
|
Revision: 734 http://modplug.svn.sourceforge.net/modplug/?rev=734&view=rev Author: saga-games Date: 2010-10-05 16:55:20 +0000 (Tue, 05 Oct 2010) Log Message: ----------- [Imp] When there's no mix rate specified in the INI file and the current audio device is an ASIO device, the default frequency is now obtained from the driver (previously, it was 44KHz in all cases, which some ASIO drivers doesn't support) [Imp] Some improvements to the Registry / INI reading (if there were no Registry settings because MPT 1.16 was previously not installed, the INI file is now read as it might contain some lines created by the installer) [Ref] Minor refactoring in the ASIO device class [Ref] Removed some unused #include lines Modified Paths: -------------- trunk/OpenMPT/mptrack/KeyConfigDlg.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/soundlib/SNDDEV.H trunk/OpenMPT/soundlib/SNDDEVX.H trunk/OpenMPT/soundlib/Snddev.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/mptrack/KeyConfigDlg.h =================================================================== --- trunk/OpenMPT/mptrack/KeyConfigDlg.h 2010-10-04 17:44:27 UTC (rev 733) +++ trunk/OpenMPT/mptrack/KeyConfigDlg.h 2010-10-05 16:55:20 UTC (rev 734) @@ -1,15 +1,8 @@ #include "stdafx.h" #include "mptrack.h" #include "MainFrm.h" -#include "snddev.h" -#include "moddoc.h" -#include "childfrm.h" -#include "dlsbank.h" #include "mpdlgs.h" #include "moptions.h" -#include "vstplug.h" -#include "moptions.h" -//#include "KeyConfigDlg.h" // Might promote to class so we can add rules // (eg automatically do note off stuff, generate chord keybindings from notes based just on modifier. Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2010-10-04 17:44:27 UTC (rev 733) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2010-10-05 16:55:20 UTC (rev 734) @@ -137,7 +137,6 @@ BOOL CMainFrame::gbMdiMaximize = FALSE; bool CMainFrame::gbShowHackControls = false; //rewbs.varWindowSize -LONG CMainFrame::glCtrlWindowHeight = 188; //obsolete, for backwards compat only LONG CMainFrame::glGeneralWindowHeight = 178; LONG CMainFrame::glPatternWindowHeight = 152; LONG CMainFrame::glSampleWindowHeight = 188; @@ -319,15 +318,15 @@ { if (i == DIR_TUNING) // Hack: Tuning folder is set already so don't reset it. continue; - m_szDefaultDirectory[i][0] = 0; - m_szWorkingDirectory[i][0] = 0; + MemsetZero(m_szDefaultDirectory[i]); + MemsetZero(m_szWorkingDirectory[i]); } m_dTotalCPU=0; - memset(gpenVuMeter, 0, sizeof(gpenVuMeter)); + MemsetZero(gpenVuMeter); // Default chords - memset(Chords, 0, sizeof(Chords)); + MemsetZero(Chords); for (UINT ichord=0; ichord<3*12; ichord++) { Chords[ichord].key = (BYTE)ichord; @@ -359,12 +358,12 @@ m_csRegWindow.Format("%s%s", m_csRegKey, MAINFRAME_REGEXT_WINDOW); CString storedVersion = GetPrivateProfileCString("Version", "Version", "", theApp.GetConfigFileName()); - //If version number stored in INI is 1.17.02.40 or later, load setting from INI file. - //Else load settings from Registry - if (storedVersion >= "1.17.02.40") + // If version number stored in INI is 1.17.02.40 or later, always load setting from INI file. + // If it isn't, try loading from Registry first, then from the INI file. + if (storedVersion >= "1.17.02.40" || !LoadRegistrySettings()) + { LoadIniSettings(); - else - LoadRegistrySettings(); + } m_InputHandler = new CInputHandler(this); //rewbs.customKeys m_pPerfCounter= new CPerformanceCounter(); @@ -411,17 +410,40 @@ rgbCustomColors[ncol] = GetPrivateProfileDWord("Display", s, rgbCustomColors[ncol], iniFile); } - LONG defaultDevice = EnumerateSoundDevices(SNDDEV_ASIO, 0, nullptr, 0) ? SNDDEV_ASIO : SNDDEV_DSOUND; - m_nWaveDevice = GetPrivateProfileLong("Sound Settings", "WaveDevice", (defaultDevice << 8), iniFile); + DWORD defaultDevice = SNDDEV_DSOUND << 8; // first DirectSound device +#ifndef NO_ASIO + // If there's an ASIO device available, prefer it over DirectSound + if(EnumerateSoundDevices(SNDDEV_ASIO, 0, nullptr, 0)) + { + defaultDevice = SNDDEV_ASIO << 8; + } +#endif // NO_ASIO + m_nWaveDevice = GetPrivateProfileLong("Sound Settings", "WaveDevice", defaultDevice, iniFile); m_dwSoundSetup = GetPrivateProfileDWord("Sound Settings", "SoundSetup", SOUNDSETUP_SECONDARY, iniFile); m_dwQuality = GetPrivateProfileDWord("Sound Settings", "Quality", 0, iniFile); m_nSrcMode = GetPrivateProfileDWord("Sound Settings", "SrcMode", SRCMODE_POLYPHASE, iniFile); - m_dwRate = GetPrivateProfileDWord("Sound Settings", "Mixing_Rate", 44100, iniFile); + m_dwRate = GetPrivateProfileDWord("Sound Settings", "Mixing_Rate", 0, iniFile); m_nBitsPerSample = GetPrivateProfileDWord("Sound Settings", "BitsPerSample", 16, iniFile); m_nChannels = GetPrivateProfileDWord("Sound Settings", "ChannelMode", 2, iniFile); - m_nBufferLength = GetPrivateProfileDWord("Sound Settings", "BufferLength", 75, iniFile); + m_nBufferLength = GetPrivateProfileDWord("Sound Settings", "BufferLength", 50, iniFile); if(m_nBufferLength < SNDDEV_MINBUFFERLEN) m_nBufferLength = SNDDEV_MINBUFFERLEN; if(m_nBufferLength > SNDDEV_MAXBUFFERLEN) m_nBufferLength = SNDDEV_MAXBUFFERLEN; + if(m_dwRate == 0) + { + m_dwRate = 44100; +#ifndef NO_ASIO + // If no mixing rate is specified and we're using ASIO, get a mixing rate supported by the device. + if((m_nWaveDevice >> 8) == SNDDEV_ASIO) + { + ISoundDevice *dummy; + if(CreateSoundDevice(SNDDEV_ASIO, &dummy)) + { + m_dwRate = dummy->GetCurrentSampleRate(m_nWaveDevice & 0xFF); + delete dummy; + } + } +#endif // NO_ASIO + } m_nPreAmp = GetPrivateProfileDWord("Sound Settings", "PreAmp", 128, iniFile); CSoundFile::m_nStereoSeparation = GetPrivateProfileLong("Sound Settings", "StereoSeparation", 128, iniFile); @@ -498,7 +520,7 @@ m_pAutoSaver->SetFilenameTemplate(GetPrivateProfileCString("AutoSave", "FileNameTemplate", "", iniFile)); } -void CMainFrame::LoadRegistrySettings() +bool CMainFrame::LoadRegistrySettings() //------------------------------------- { @@ -523,7 +545,6 @@ if (d) theApp.m_nCmdShow = SW_SHOWMAXIMIZED; RegQueryValueEx(key, "MDIMaximize", NULL, &dwREG_DWORD, (LPBYTE)&gbMdiMaximize, &dwDWORDSize); RegQueryValueEx(key, "MDITreeWidth", NULL, &dwREG_DWORD, (LPBYTE)&glTreeWindowWidth, &dwDWORDSize); - RegQueryValueEx(key, "MDICtrlHeight", NULL, &dwREG_DWORD, (LPBYTE)&glCtrlWindowHeight, &dwDWORDSize); //obsolete, for backwards compat only RegQueryValueEx(key, "MDIGeneralHeight", NULL, &dwREG_DWORD, (LPBYTE)&glGeneralWindowHeight, &dwDWORDSize); RegQueryValueEx(key, "MDIPatternHeight", NULL, &dwREG_DWORD, (LPBYTE)&glPatternWindowHeight, &dwDWORDSize); RegQueryValueEx(key, "MDISampleHeight", NULL, &dwREG_DWORD, (LPBYTE)&glSampleWindowHeight, &dwDWORDSize); @@ -579,7 +600,7 @@ RegQueryValueEx(key, "MidiSetup", NULL, &dwREG_DWORD, (LPBYTE)&m_dwMidiSetup, &dwDWORDSize); RegQueryValueEx(key, "MidiDevice", NULL, &dwREG_DWORD, (LPBYTE)&m_nMidiDevice, &dwDWORDSize); RegQueryValueEx(key, "PatternSetup", NULL, &dwREG_DWORD, (LPBYTE)&m_dwPatternSetup, &dwDWORDSize); - m_dwPatternSetup |= PATTERN_NOTEFADE; // Set flag to maintain old behaviour(was changed in 1.17.02.50). + m_dwPatternSetup |= PATTERN_NOTEFADE; // Set flag to maintain old behaviour (was changed in 1.17.02.50). m_dwPatternSetup |= PATTERN_RESETCHANNELS; // Set flag to reset channels on loop was changed in 1.17.03.01). m_dwPatternSetup &= ~0x800; // quick paste autorepeat is now a keymap option RegQueryValueEx(key, "RowSpacing", NULL, &dwREG_DWORD, (LPBYTE)&m_nRowSpacing, &dwDWORDSize); @@ -643,6 +664,9 @@ //end rewbs.autoSave RegCloseKey(key); + } else + { + return false; } if (RegOpenKeyEx(HKEY_CURRENT_USER, m_csRegSettings, 0, KEY_READ, &key) == ERROR_SUCCESS) @@ -659,6 +683,8 @@ gnPatternSpacing = theApp.GetProfileInt("Pattern Editor", "Spacing", 0); gbPatternVUMeters = theApp.GetProfileInt("Pattern Editor", "VU-Meters", 0); gbPatternPluginNames = theApp.GetProfileInt("Pattern Editor", "Plugin-Names", 1); + + return true; } Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2010-10-04 17:44:27 UTC (rev 733) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2010-10-05 16:55:20 UTC (rev 734) @@ -412,7 +412,7 @@ static UINT m_nLastOptionsPage; static BOOL gbMdiMaximize; static bool gbShowHackControls; - static LONG glCtrlWindowHeight, glTreeWindowWidth, glTreeSplitRatio; + static LONG glTreeWindowWidth, glTreeSplitRatio; static LONG glGeneralWindowHeight, glPatternWindowHeight, glSampleWindowHeight, glInstrumentWindowHeight, glCommentsWindowHeight, glGraphWindowHeight; //rewbs.varWindowSize static HHOOK ghKbdHook; @@ -423,7 +423,8 @@ // Audio Setup static DWORD m_dwSoundSetup, m_dwRate, m_dwQuality, m_nSrcMode, m_nBitsPerSample, m_nPreAmp, gbLoopSong, m_nChannels; - static LONG m_nWaveDevice, m_nMidiDevice; + static LONG m_nWaveDevice; // lower 8 bits: device number (for this type). higher 8 bits: device type + static LONG m_nMidiDevice; static DWORD m_nBufferLength; static EQPRESET m_EqSettings; // Pattern Setup @@ -702,7 +703,7 @@ afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); private: - void LoadRegistrySettings(); + bool LoadRegistrySettings(); void LoadIniSettings(); void SaveIniSettings(); }; Modified: trunk/OpenMPT/soundlib/SNDDEV.H =================================================================== --- trunk/OpenMPT/soundlib/SNDDEV.H 2010-10-04 17:44:27 UTC (rev 733) +++ trunk/OpenMPT/soundlib/SNDDEV.H 2010-10-05 16:55:20 UTC (rev 734) @@ -73,6 +73,7 @@ virtual BOOL IsOpen() = 0; virtual UINT GetCurrentLatency() = 0; virtual void SilenceAudioBuffer(ISoundSource *pSource, ULONG nMaxLatency, DWORD dwUser=0) = 0; + virtual UINT GetCurrentSampleRate(UINT nDevice) { return 0; } }; Modified: trunk/OpenMPT/soundlib/SNDDEVX.H =================================================================== --- trunk/OpenMPT/soundlib/SNDDEVX.H 2010-10-04 17:44:27 UTC (rev 733) +++ trunk/OpenMPT/soundlib/SNDDEVX.H 2010-10-05 16:55:20 UTC (rev 734) @@ -1,6 +1,14 @@ #ifndef _SNDDEVX_H_ #define _SNDDEVX_H_ +#include <mmsystem.h> +#include <dsound.h> + +#ifndef NO_ASIO +#include <iasiodrv.h> +#define ASIO_LOG +#endif + //////////////////////////////////////////////////////////////////////////////////// // // MMSYSTEM WaveOut device @@ -123,11 +131,16 @@ UINT GetCurrentLatency() { return m_nAsioBufferLen; } void SilenceAudioBuffer(ISoundSource *pSource, ULONG nMaxLatency, DWORD dwBuffer); + UINT GetCurrentSampleRate(UINT nDevice); public: static BOOL EnumerateDevices(UINT nIndex, LPSTR pszDescription, UINT cbSize); protected: + void OpenDevice(UINT nDevice); + void CloseDevice(); + +protected: static CASIODevice *gpCurrentAsio; static LONG gnFillBuffers; static void BufferSwitch(long doubleBufferIndex, ASIOBool directProcess); Modified: trunk/OpenMPT/soundlib/Snddev.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snddev.cpp 2010-10-04 17:44:27 UTC (rev 733) +++ trunk/OpenMPT/soundlib/Snddev.cpp 2010-10-05 16:55:20 UTC (rev 734) @@ -1,12 +1,5 @@ #include "stdafx.h" -#include <mmsystem.h> -#include <dsound.h> -#ifndef NO_ASIO -#include <iasiodrv.h> -#define ASIO_LOG -#endif - #include "snddev.h" #include "snddevx.h" @@ -652,18 +645,13 @@ { gpCurrentAsio = NULL; } - if (m_pAsioDrv) - { - m_pAsioDrv->Release(); - m_pAsioDrv = NULL; - } + CloseDevice(); } BOOL CASIODevice::Open(UINT nDevice, LPWAVEFORMATEX pwfx) //------------------------------------------------------- { - CLSID clsid; BOOL bOk = FALSE; if (m_pAsioDrv) Close(); @@ -678,17 +666,8 @@ Log("CASIODevice::Open(%d:\"%s\"): %d-bit, %d channels, %dHz\n", nDevice, gAsioDrivers[nDevice].name, pwfx->wBitsPerSample, pwfx->nChannels, pwfx->nSamplesPerSec); #endif - clsid = gAsioDrivers[nDevice].clsid; - if (CoCreateInstance(clsid,0,CLSCTX_INPROC_SERVER, clsid, (VOID **)&m_pAsioDrv) == S_OK) - { - m_pAsioDrv->init((void *)m_hWnd); - } else - { - #ifdef ASIO_LOG - Log(" CoCreateInstance failed!\n"); - #endif - m_pAsioDrv = NULL; - } + OpenDevice(nDevice); + if (m_pAsioDrv) { long nInputChannels = 0, nOutputChannels = 0; @@ -812,11 +791,7 @@ #ifdef ASIO_LOG Log("Error opening ASIO device!\n"); #endif - if (m_pAsioDrv) - { - m_pAsioDrv->Release(); - m_pAsioDrv = NULL; - } + CloseDevice(); } return bOk; } @@ -856,12 +831,7 @@ } catch(...) { CASIODevice::ReportASIOException("ASIO crash in disposeBuffers()\n"); } - try { - m_pAsioDrv->Release(); - } catch(...) { - CASIODevice::ReportASIOException("ASIO crash in Release()\n"); - } - m_pAsioDrv = NULL; + CloseDevice(); } if (gpCurrentAsio == this) { @@ -885,7 +855,48 @@ } } + +void CASIODevice::OpenDevice(UINT nDevice) +//---------------------------------------- +{ + if (m_pAsioDrv) + { + return; + } + + CLSID clsid = gAsioDrivers[nDevice].clsid; + if (CoCreateInstance(clsid,0,CLSCTX_INPROC_SERVER, clsid, (VOID **)&m_pAsioDrv) == S_OK) + { + m_pAsioDrv->init((void *)m_hWnd); + } else + { +#ifdef ASIO_LOG + Log(" CoCreateInstance failed!\n"); +#endif + m_pAsioDrv = NULL; + } +} + + +void CASIODevice::CloseDevice() +//----------------------------- +{ + if (m_pAsioDrv) + { + try + { + m_pAsioDrv->Release(); + } catch(...) + { + CASIODevice::ReportASIOException("ASIO crash in Release()\n"); + } + m_pAsioDrv = NULL; + } +} + + void CASIODevice::SilenceAudioBuffer(ISoundSource *pSource, ULONG nMaxLatency, DWORD dwBuffer) +//-------------------------------------------------------------------------------------------- { for (UINT ich=0; ich<m_nChannels; ich++){ memset(m_BufferInfo[ich].buffers[dwBuffer], 0, m_nAsioBufferLen); @@ -1276,7 +1287,7 @@ } BOOL CASIODevice::ReportASIOException(LPCSTR format,...) -//------------------------------------------------------- +//------------------------------------------------------ { CHAR cBuf[1024]; va_list va; @@ -1289,6 +1300,36 @@ return TRUE; } + +// 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(UINT nDevice) +//-------------------------------------------------- +{ + const bool wasOpen = (m_pAsioDrv != NULL); + if(!wasOpen) + { + OpenDevice(nDevice); + if(m_pAsioDrv == NULL) + { + return 0; + } + } + + ASIOSampleRate samplerate; + if(m_pAsioDrv->getSampleRate(&samplerate) != ASE_OK) + { + samplerate = 0; + } + + if(!wasOpen) + { + CloseDevice(); + } + + return (UINT)samplerate; +} + + #endif // NO_ASIO /////////////////////////////////////////////////////////////////////////////////////// Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2010-10-04 17:44:27 UTC (rev 733) +++ trunk/OpenMPT/soundlib/Sndfile.h 2010-10-05 16:55:20 UTC (rev 734) @@ -40,7 +40,7 @@ BYTE nVibSweep; // Auto vibrato sweep (i.e. how long it takes until the vibrato effect reaches its full strength) BYTE nVibDepth; // Auto vibrato depth BYTE nVibRate; // Auto vibrato rate (speed) - //CHAR name[32]; // Maybe it would be nicer to have sample names here, but that would require some refactoring. Also, would this slow down the mixer (cache misses)? + //CHAR name[MAX_SAMPLENAME]; // Maybe it would be nicer to have sample names here, but that would require some refactoring. Also, would this slow down the mixer (cache misses)? CHAR filename[MAX_SAMPLEFILENAME]; // Return the size of one (elementary) sample in bytes. @@ -106,8 +106,8 @@ BYTE nDNA; // Duplicate note action BYTE nPanSwing; // Random panning factor BYTE nVolSwing; // Random volume factor - BYTE nIFC; // Default filter cutoff - BYTE nIFR; // Default filter resonance + BYTE nIFC; // Default filter cutoff (00...7F). Used if the high bit is set + BYTE nIFR; // Default filter resonance (00...7F). Used if the high bit is set WORD wMidiBank; // MIDI bank BYTE nMidiProgram; // MIDI program This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |