From: <sag...@us...> - 2011-01-16 21:39:51
|
Revision: 788 http://modplug.svn.sourceforge.net/modplug/?rev=788&view=rev Author: saga-games Date: 2011-01-16 21:39:44 +0000 (Sun, 16 Jan 2011) Log Message: ----------- [Fix] Sample Editor: rev.781 broke the Downsample button. It was allocating too much memory (if it actually succeeded in requesting it). [Imp] Sound Setup: For ASIO devices, only supported sampling rates are now shown. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/soundlib/SNDDEV.H trunk/OpenMPT/soundlib/SNDDEVX.H trunk/OpenMPT/soundlib/Snddev.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2011-01-15 16:41:51 UTC (rev 787) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2011-01-16 21:39:44 UTC (rev 788) @@ -1526,7 +1526,7 @@ dwStart = 0; dwEnd = pSmp->nLength; } - smplsize = pSmp->GetSampleSizeInBytes(); + smplsize = pSmp->GetBytesPerSample(); pOriginal = pSmp->pSample; dwRemove = (dwEnd-dwStart+1)>>1; dwNewLen = pSmp->nLength - dwRemove; @@ -1633,7 +1633,7 @@ #define MAX_BUFFER_LENGTH 8192 -#define CLIP_SOUND(v) v = v < -1.0f ? -1.0f : v > 1.0f ? 1.0f : v +#define CLIP_SOUND(v) Limit(v, -1.0f, 1.0f); void CCtrlSamples::ReadTimeStretchParameters() //-------------------------------------------- @@ -2122,7 +2122,8 @@ for(UINT j = startoffset ; j < len + finaloffset ; j++){ // Just perform a little bit of clipping... - float v = outbuf[j]; CLIP_SOUND(v); + float v = outbuf[j]; + CLIP_SOUND(v); // ...before converting back to buffer switch(smpsize){ case 2: @@ -3060,7 +3061,7 @@ return points; } -// Set the currently select part of the sample. +// Set the currently selected part of the sample. // To reset the selection, use nStart = nEnd = 0. void CCtrlSamples::SetSelectionPoints(UINT nStart, UINT nEnd) //----------------------------------------------------------- Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2011-01-15 16:41:51 UTC (rev 787) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2011-01-16 21:39:44 UTC (rev 788) @@ -217,7 +217,7 @@ cbi.iSelectedImage = cbi.iImage; cbi.iOverlay = cbi.iImage; cbi.iIndent = 0; - cbi.lParam = (nDevType<<8)|(nDev&0xff); + cbi.lParam = SNDDEV_BUILD_ID(nDev, nDevType); cbi.pszText = s; int pos = m_CbnDevice.InsertItem(&cbi); if (cbi.lParam == (LONG)m_nSoundDevice) m_CbnDevice.SetCurSel(pos); @@ -310,7 +310,52 @@ if (n >= 0) { int dev = m_CbnDevice.GetItemData(n); - GetDlgItem(IDC_CHECK4)->EnableWindow(((dev>>8)==SNDDEV_DSOUND) ? TRUE : FALSE); + GetDlgItem(IDC_CHECK4)->EnableWindow((SNDDEV_GET_TYPE(dev) == SNDDEV_DSOUND) ? TRUE : FALSE); + + CHAR s[128]; + m_CbnMixingFreq.ResetContent(); + + bool knowRates = false; + vector<bool> supportedRates; + vector<UINT> samplerates; + for(size_t i = 0; i < NUMMIXRATE; i++) + { + samplerates.push_back(nMixingRates[i]); + } + + ISoundDevice *dummy; + if(CreateSoundDevice(SNDDEV_GET_TYPE(dev), &dummy)) + { + knowRates = dummy->CanSampleRate(SNDDEV_GET_NUMBER(dev), samplerates, supportedRates); + delete dummy; + } + + if(knowRates) + { + // We have a valid list of supported playback rates. + int n = 1; + for(size_t i = 0; i < NUMMIXRATE; i++) + { + if(supportedRates[i]) + { + wsprintf(s, "%u Hz", nMixingRates[i]); + int pos = m_CbnMixingFreq.AddString(s); + if (m_dwRate == nMixingRates[i]) n = pos; + } + } + m_CbnMixingFreq.SetCurSel(n); + } else + { + // Rates supported by the device are not known, show all rates supported by OpenMPT instead. + UINT n = 1; + for (UINT i=0; i<NUMMIXRATE; i++) + { + wsprintf(s, "%u Hz", nMixingRates[i]); + m_CbnMixingFreq.AddString(s); + if (m_dwRate == nMixingRates[i]) n = i; + } + m_CbnMixingFreq.SetCurSel(n); + } OnSettingsChanged(); } } Modified: trunk/OpenMPT/soundlib/SNDDEV.H =================================================================== --- trunk/OpenMPT/soundlib/SNDDEV.H 2011-01-15 16:41:51 UTC (rev 787) +++ trunk/OpenMPT/soundlib/SNDDEV.H 2011-01-16 21:39:44 UTC (rev 788) @@ -30,10 +30,11 @@ 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_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. #define SNDDEV_MINBUFFERS 2 #define SNDDEV_MAXBUFFERS 16 @@ -80,6 +81,8 @@ virtual UINT GetCurrentLatency() = 0; virtual void SilenceAudioBuffer(ISoundSource *pSource, ULONG nMaxLatency, DWORD dwUser=0) = 0; virtual UINT GetCurrentSampleRate(UINT nDevice) { UNREFERENCED_PARAMETER(nDevice); return 0; } + // Return which samplerates are actually supported by the device. Currently only implemented properly for ASIO. + virtual bool CanSampleRate(UINT nDevice, vector<UINT> &samplerates, vector<bool> &result) { UNREFERENCED_PARAMETER(nDevice); result.assign(samplerates.size(), true); return true; } ; }; Modified: trunk/OpenMPT/soundlib/SNDDEVX.H =================================================================== --- trunk/OpenMPT/soundlib/SNDDEVX.H 2011-01-15 16:41:51 UTC (rev 787) +++ trunk/OpenMPT/soundlib/SNDDEVX.H 2011-01-16 21:39:44 UTC (rev 788) @@ -131,6 +131,7 @@ UINT GetCurrentLatency() { return m_nAsioBufferLen; } void SilenceAudioBuffer(ISoundSource *pSource, ULONG nMaxLatency, DWORD dwBuffer); + bool CanSampleRate(UINT nDevice, vector<UINT> &samplerates, vector<bool> &result); UINT GetCurrentSampleRate(UINT nDevice); public: Modified: trunk/OpenMPT/soundlib/Snddev.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snddev.cpp 2011-01-15 16:41:51 UTC (rev 787) +++ trunk/OpenMPT/soundlib/Snddev.cpp 2011-01-16 21:39:44 UTC (rev 788) @@ -1,4 +1,6 @@ #include "stdafx.h" +#include <vector> +using std::vector; #include "snddev.h" #include "snddevx.h" @@ -1301,6 +1303,39 @@ } +bool CASIODevice::CanSampleRate(UINT nDevice, vector<UINT> &samplerates, vector<bool> &result) +//-------------------------------------------------------------------------------------------- +{ + const bool wasOpen = (m_pAsioDrv != NULL); + if(!wasOpen) + { + OpenDevice(nDevice); + if(m_pAsioDrv == NULL) + { + return false; + } + } + + bool foundSomething = false; // is at least one sample rate supported by the device? + result.clear(); + for(size_t i = 0; i < samplerates.size(); i++) + { + result.push_back((m_pAsioDrv->canSampleRate((ASIOSampleRate)samplerates[i]) == ASE_OK)); + if(result.back()) + { + foundSomething = true; + } + } + + if(!wasOpen) + { + CloseDevice(); + } + + return foundSomething; +} + + // 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) //-------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |