From: <man...@us...> - 2013-08-11 17:59:08
|
Revision: 2600 http://sourceforge.net/p/modplug/code/2600 Author: manxorist Date: 2013-08-11 17:58:59 +0000 (Sun, 11 Aug 2013) Log Message: ----------- [Ref] Move SampleFormat from MixerSettings.h into its own header SampleFormat.h . [Fix] Fix ASIO floating point output (broke in r2599 ). [Ref] Use SampleFormat.h in sounddev/ code. Revision Links: -------------- http://sourceforge.net/p/modplug/code/2599 Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/TrackerSettings.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDevices.h trunk/OpenMPT/soundlib/AudioReadTarget.h trunk/OpenMPT/soundlib/MixerSettings.h Added Paths: ----------- trunk/OpenMPT/soundlib/SampleFormat.h Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-08-11 17:58:59 UTC (rev 2600) @@ -448,6 +448,7 @@ <ClInclude Include="..\soundlib\Resampler.h" /> <ClInclude Include="..\soundlib\RowVisitor.h" /> <ClInclude Include="..\soundlib\S3MTools.h" /> + <ClInclude Include="..\soundlib\SampleFormat.h" /> <ClInclude Include="..\soundlib\SampleFormatConverters.h" /> <ClInclude Include="..\soundlib\SampleIO.h" /> <ClInclude Include="..\soundlib\Sndfile.h" /> Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-08-11 17:58:59 UTC (rev 2600) @@ -242,6 +242,9 @@ <ClInclude Include="..\soundlib\MixerLoops.h"> <Filter>Header Files\soundlib</Filter> </ClInclude> + <ClInclude Include="..\soundlib\SampleFormat.h"> + <Filter>Header Files\soundlib</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\common\AudioCriticalSection.cpp"> Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-08-11 17:58:59 UTC (rev 2600) @@ -915,8 +915,7 @@ settings.fulCfgOptions = TrackerSettings::Instance().GetSoundDeviceFlags(); settings.Samplerate = samplespersec; settings.Channels = (uint8)channels; - settings.BitsPerSample = (uint8)sampleFormat.GetBitsPerSample(); - settings.FloatingPoint = sampleFormat.IsFloat(); + settings.sampleFormat = sampleFormat; return gpSoundDevice->Open(SNDDEV_GET_NUMBER(TrackerSettings::Instance().m_nWaveDevice), settings); } Modified: trunk/OpenMPT/mptrack/TrackerSettings.h =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.h 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/mptrack/TrackerSettings.h 2013-08-11 17:58:59 UTC (rev 2600) @@ -13,6 +13,7 @@ #include "../soundlib/MixerSettings.h" #include "../soundlib/Resampler.h" +#include "../soundlib/SampleFormat.h" #include "../sounddsp/EQ.h" #include "../sounddsp/DSP.h" #include "../sounddsp/Reverb.h" Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-08-11 17:58:59 UTC (rev 2600) @@ -1085,6 +1085,10 @@ > </File> <File + RelativePath="..\soundlib\SampleFormat.h" + > + </File> + <File RelativePath="..\soundlib\SampleFormatConverters.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-08-11 17:58:59 UTC (rev 2600) @@ -511,6 +511,7 @@ <ClInclude Include="..\soundlib\Resampler.h" /> <ClInclude Include="..\soundlib\RowVisitor.h" /> <ClInclude Include="..\soundlib\S3MTools.h" /> + <ClInclude Include="..\soundlib\SampleFormat.h" /> <ClInclude Include="..\soundlib\SampleFormatConverters.h" /> <ClInclude Include="..\soundlib\SampleIO.h" /> <ClInclude Include="..\soundlib\Sndfile.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-08-11 17:58:59 UTC (rev 2600) @@ -894,6 +894,9 @@ <ClInclude Include="..\soundlib\MixerLoops.h"> <Filter>Header Files\soundlib</Filter> </ClInclude> + <ClInclude Include="..\soundlib\SampleFormat.h"> + <Filter>Header Files\soundlib</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-08-11 17:58:59 UTC (rev 2600) @@ -53,16 +53,16 @@ //--------------------------------------------------------------------------- { MemsetZero(WaveFormat); - UINT bytespersample = (m_Settings.BitsPerSample/8) * m_Settings.Channels; - if(m_Settings.FloatingPoint && m_Settings.BitsPerSample != 32) return false; - WaveFormat.Format.wFormatTag = m_Settings.FloatingPoint ? WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM; + if(!m_Settings.sampleFormat.IsValid()) return false; + UINT bytespersample = (m_Settings.sampleFormat.GetBitsPerSample()/8) * m_Settings.Channels; + WaveFormat.Format.wFormatTag = m_Settings.sampleFormat.IsFloat() ? WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM; WaveFormat.Format.nChannels = (WORD)m_Settings.Channels; WaveFormat.Format.nSamplesPerSec = m_Settings.Samplerate; WaveFormat.Format.nAvgBytesPerSec = m_Settings.Samplerate * bytespersample; WaveFormat.Format.nBlockAlign = (WORD)bytespersample; - WaveFormat.Format.wBitsPerSample = (WORD)m_Settings.BitsPerSample; + WaveFormat.Format.wBitsPerSample = (WORD)m_Settings.sampleFormat.GetBitsPerSample(); WaveFormat.Format.cbSize = 0; - if((WaveFormat.Format.wBitsPerSample > 16 && !m_Settings.FloatingPoint) || (WaveFormat.Format.nChannels > 2)) + if((WaveFormat.Format.wBitsPerSample > 16 && m_Settings.sampleFormat.IsInt()) || (WaveFormat.Format.nChannels > 2)) { WaveFormat.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; WaveFormat.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); @@ -77,7 +77,7 @@ } const GUID guid_MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x0, 0xAA, 0x0, 0x38, 0x9B, 0x71}; const GUID guid_MEDIASUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}; - WaveFormat.SubFormat = m_Settings.FloatingPoint ? guid_MEDIASUBTYPE_IEEE_FLOAT : guid_MEDIASUBTYPE_PCM; + WaveFormat.SubFormat = m_Settings.sampleFormat.IsFloat() ? guid_MEDIASUBTYPE_IEEE_FLOAT : guid_MEDIASUBTYPE_PCM; } return true; } @@ -1242,8 +1242,6 @@ { bool bOk = false; - if(m_Settings.FloatingPoint) return false; // for now - if (IsOpen()) Close(); if (!gbAsioEnumerated) EnumerateDevices(nDevice, NULL, 0); if (nDevice >= gnNumAsioDrivers) return false; @@ -1253,7 +1251,7 @@ } #ifdef ASIO_LOG Log("CASIODevice::Open(%d:\"%s\"): %d-bit, %d channels, %dHz\n", - nDevice, gAsioDrivers[nDevice].name, m_Settings.BitsPerSample, m_Settings.Channels, m_Settings.Samplerate); + nDevice, gAsioDrivers[nDevice].name, (int)m_Settings.sampleFormat.GetBitsPerSample(), m_Settings.Channels, m_Settings.Samplerate); #endif OpenDevice(nDevice); @@ -1262,8 +1260,14 @@ long nInputChannels = 0, nOutputChannels = 0; long minSize = 0, maxSize = 0, preferredSize = 0, granularity = 0; - if ((m_Settings.Channels > ASIO_MAX_CHANNELS) - || ((m_Settings.BitsPerSample != 16) && (m_Settings.BitsPerSample != 32))) goto abort; + if(m_Settings.Channels > ASIO_MAX_CHANNELS) + { + goto abort; + } + if((m_Settings.sampleFormat != SampleFormatInt32) && (m_Settings.sampleFormat != SampleFormatFloat32)) + { + goto abort; + } m_nChannels = m_Settings.Channels; m_pAsioDrv->getChannels(&nInputChannels, &nOutputChannels); #ifdef ASIO_LOG @@ -1290,10 +1294,6 @@ m_BufferInfo[ich].channelNum = ich + CASIODevice::baseChannel; // map MPT channel i to ASIO channel i m_BufferInfo[ich].buffers[0] = NULL; m_BufferInfo[ich].buffers[1] = NULL; - if(m_Settings.BitsPerSample != 32 && m_Settings.BitsPerSample != 32+128) - { - goto abort; - } m_Float = false; switch(m_ChannelInfo[ich].type) { @@ -1888,13 +1888,13 @@ m_StreamParameters.device = HostApiOutputIndexToGlobalDeviceIndex(nDevice, m_HostApi); if(m_StreamParameters.device == -1) return false; m_StreamParameters.channelCount = m_Settings.Channels; - if(m_Settings.FloatingPoint) + if(m_Settings.sampleFormat.IsFloat()) { - if(m_Settings.BitsPerSample != 32) return false; + if(m_Settings.sampleFormat.GetBitsPerSample() != 32) return false; m_StreamParameters.sampleFormat = paFloat32; } else { - switch(m_Settings.BitsPerSample) + switch(m_Settings.sampleFormat.GetBitsPerSample()) { case 8: m_StreamParameters.sampleFormat = paUInt8; break; case 16: m_StreamParameters.sampleFormat = paInt16; break; Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-08-11 17:58:59 UTC (rev 2600) @@ -11,6 +11,8 @@ #pragma once +#include "../soundlib/SampleFormat.h" + #include <vector> @@ -93,8 +95,7 @@ ULONG fulCfgOptions; uint32 Samplerate; uint8 Channels; - uint8 BitsPerSample; - bool FloatingPoint; + SampleFormat sampleFormat; SoundDeviceSettings() : hWnd(NULL) , LatencyMS(SNDDEV_DEFAULT_LATENCY_MS) @@ -102,8 +103,7 @@ , fulCfgOptions(0) , Samplerate(48000) , Channels(2) - , BitsPerSample(16) - , FloatingPoint(false) + , sampleFormat(SampleFormatInt16) { return; } @@ -160,7 +160,7 @@ void Start(); void Stop(); void Reset(); - virtual int HasFixedSampleFormat() { return 0; } + virtual SampleFormat HasFixedSampleFormat() { return SampleFormatInvalid; } virtual bool IsOpen() const = 0; virtual UINT GetNumBuffers() { return 0; } virtual float GetCurrentRealLatencyMS() { return GetRealLatencyMS(); } Modified: trunk/OpenMPT/sounddev/SoundDevices.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevices.h 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/sounddev/SoundDevices.h 2013-08-11 17:58:59 UTC (rev 2600) @@ -233,7 +233,7 @@ void InternalStart(); void InternalStop(); bool IsOpen() const { return (m_pAsioDrv != NULL); } - int HasFixedSampleFormat() { return m_Float ? 32+128 : 32; } + SampleFormat HasFixedSampleFormat() { return m_Float ? SampleFormatFloat32 : SampleFormatInt32; } UINT GetNumBuffers() { return 2; } float GetCurrentRealLatencyMS() { return m_nAsioBufferLen * 2 * 1000.0f / m_Settings.Samplerate; } Modified: trunk/OpenMPT/soundlib/AudioReadTarget.h =================================================================== --- trunk/OpenMPT/soundlib/AudioReadTarget.h 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/soundlib/AudioReadTarget.h 2013-08-11 17:58:59 UTC (rev 2600) @@ -11,6 +11,7 @@ #include "Sndfile.h" #include "Dither.h" #include "SampleFormatConverters.h" +#include "SampleFormat.h" #include "MixerLoops.h" Modified: trunk/OpenMPT/soundlib/MixerSettings.h =================================================================== --- trunk/OpenMPT/soundlib/MixerSettings.h 2013-08-11 17:33:10 UTC (rev 2599) +++ trunk/OpenMPT/soundlib/MixerSettings.h 2013-08-11 17:58:59 UTC (rev 2600) @@ -10,108 +10,6 @@ #pragma once -enum SampleFormatEnum -{ - SampleFormatUnsigned8 = 8, // do not change value (for compatibility with old configuration settings) - SampleFormatInt16 = 16, // do not change value (for compatibility with old configuration settings) - SampleFormatInt24 = 24, // do not change value (for compatibility with old configuration settings) - SampleFormatInt32 = 32, // do not change value (for compatibility with old configuration settings) - SampleFormatFloat32 = 32 + 128, // Only supported as mixer output and ISoundDevice format, NOT supported by Mod2Wave settings dialog yet. Keep in mind to update all 3 cases at once. - SampleFormatFixed5p27 = 255, // mixbuffer format - SampleFormatInvalid = 0 -}; - -template<typename Tsample> struct SampleFormatTraits; -template<> struct SampleFormatTraits<uint8> { static const SampleFormatEnum sampleFormat = SampleFormatUnsigned8; }; -template<> struct SampleFormatTraits<int16> { static const SampleFormatEnum sampleFormat = SampleFormatInt16; }; -template<> struct SampleFormatTraits<int24> { static const SampleFormatEnum sampleFormat = SampleFormatInt24; }; -template<> struct SampleFormatTraits<int32> { static const SampleFormatEnum sampleFormat = SampleFormatInt32; }; -template<> struct SampleFormatTraits<float> { static const SampleFormatEnum sampleFormat = SampleFormatFloat32; }; -template<> struct SampleFormatTraits<fixed5p27> { static const SampleFormatEnum sampleFormat = SampleFormatFixed5p27; }; - -template<SampleFormatEnum sampleFormat> struct SampleFormatToType; -template<> struct SampleFormatToType<SampleFormatUnsigned8> { typedef uint8 type; }; -template<> struct SampleFormatToType<SampleFormatInt16> { typedef int16 type; }; -template<> struct SampleFormatToType<SampleFormatInt24> { typedef int24 type; }; -template<> struct SampleFormatToType<SampleFormatInt32> { typedef int32 type; }; -template<> struct SampleFormatToType<SampleFormatFloat32> { typedef float type; }; -template<> struct SampleFormatToType<SampleFormatFixed5p27> { typedef fixed5p27 type; }; - - -struct SampleFormat -{ - SampleFormatEnum value; - SampleFormat(SampleFormatEnum v = SampleFormatInvalid) : value(v) { } - bool operator == (SampleFormat other) const { return value == other.value; } - bool operator != (SampleFormat other) const { return value != other.value; } - operator SampleFormatEnum () const - { - return value; - } - bool IsValid() const - { - return value != SampleFormatInvalid; - } - bool IsUnsigned() const - { - if(!IsValid()) return false; - return value == SampleFormatUnsigned8; - } - bool IsFloat() const - { - if(!IsValid()) return false; - return value == SampleFormatFloat32; - } - bool IsInt() const - { - if(!IsValid()) return false; - return value != SampleFormatFloat32; - } - bool IsMixBuffer() const - { - if(!IsValid()) return false; - return value == SampleFormatFixed5p27; - } - uint8 GetBitsPerSample() const - { - if(!IsValid()) return 0; - switch(value) - { - case SampleFormatUnsigned8: - return 8; - break; - case SampleFormatInt16: - return 16; - break; - case SampleFormatInt24: - return 24; - break; - case SampleFormatInt32: - return 32; - break; - case SampleFormatFloat32: - return 32; - break; - case SampleFormatFixed5p27: - return 32; - break; - default: - return 0; - break; - } - } - - // backward compatibility, conversion to/from integers - operator int () const { return value; } - SampleFormat(int v) : value(SampleFormatEnum(v)) { } - operator long () const { return value; } - SampleFormat(long v) : value(SampleFormatEnum(v)) { } - operator unsigned int () const { return value; } - SampleFormat(unsigned int v) : value(SampleFormatEnum(v)) { } - operator unsigned long () const { return value; } - SampleFormat(unsigned long v) : value(SampleFormatEnum(v)) { } -}; - struct MixerSettings { Added: trunk/OpenMPT/soundlib/SampleFormat.h =================================================================== --- trunk/OpenMPT/soundlib/SampleFormat.h (rev 0) +++ trunk/OpenMPT/soundlib/SampleFormat.h 2013-08-11 17:58:59 UTC (rev 2600) @@ -0,0 +1,115 @@ +/* + * SampleFormat.h + * --------------- + * Purpose: Utility enum and funcion to describe sample formats. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + +#pragma once + + +enum SampleFormatEnum +{ + SampleFormatUnsigned8 = 8, // do not change value (for compatibility with old configuration settings) + SampleFormatInt16 = 16, // do not change value (for compatibility with old configuration settings) + SampleFormatInt24 = 24, // do not change value (for compatibility with old configuration settings) + SampleFormatInt32 = 32, // do not change value (for compatibility with old configuration settings) + SampleFormatFloat32 = 32 + 128, // Only supported as mixer output and ISoundDevice format, NOT supported by Mod2Wave settings dialog yet. Keep in mind to update all 3 cases at once. + SampleFormatFixed5p27 = 255, // mixbuffer format + SampleFormatInvalid = 0 +}; + +template<typename Tsample> struct SampleFormatTraits; +template<> struct SampleFormatTraits<uint8> { static const SampleFormatEnum sampleFormat = SampleFormatUnsigned8; }; +template<> struct SampleFormatTraits<int16> { static const SampleFormatEnum sampleFormat = SampleFormatInt16; }; +template<> struct SampleFormatTraits<int24> { static const SampleFormatEnum sampleFormat = SampleFormatInt24; }; +template<> struct SampleFormatTraits<int32> { static const SampleFormatEnum sampleFormat = SampleFormatInt32; }; +template<> struct SampleFormatTraits<float> { static const SampleFormatEnum sampleFormat = SampleFormatFloat32; }; +template<> struct SampleFormatTraits<fixed5p27> { static const SampleFormatEnum sampleFormat = SampleFormatFixed5p27; }; + +template<SampleFormatEnum sampleFormat> struct SampleFormatToType; +template<> struct SampleFormatToType<SampleFormatUnsigned8> { typedef uint8 type; }; +template<> struct SampleFormatToType<SampleFormatInt16> { typedef int16 type; }; +template<> struct SampleFormatToType<SampleFormatInt24> { typedef int24 type; }; +template<> struct SampleFormatToType<SampleFormatInt32> { typedef int32 type; }; +template<> struct SampleFormatToType<SampleFormatFloat32> { typedef float type; }; +template<> struct SampleFormatToType<SampleFormatFixed5p27> { typedef fixed5p27 type; }; + + +struct SampleFormat +{ + SampleFormatEnum value; + SampleFormat(SampleFormatEnum v = SampleFormatInvalid) : value(v) { } + bool operator == (SampleFormat other) const { return value == other.value; } + bool operator != (SampleFormat other) const { return value != other.value; } + bool operator == (SampleFormatEnum other) const { return value == other; } + bool operator != (SampleFormatEnum other) const { return value != other; } + operator SampleFormatEnum () const + { + return value; + } + bool IsValid() const + { + return value != SampleFormatInvalid; + } + bool IsUnsigned() const + { + if(!IsValid()) return false; + return value == SampleFormatUnsigned8; + } + bool IsFloat() const + { + if(!IsValid()) return false; + return value == SampleFormatFloat32; + } + bool IsInt() const + { + if(!IsValid()) return false; + return value != SampleFormatFloat32; + } + bool IsMixBuffer() const + { + if(!IsValid()) return false; + return value == SampleFormatFixed5p27; + } + uint8 GetBitsPerSample() const + { + if(!IsValid()) return 0; + switch(value) + { + case SampleFormatUnsigned8: + return 8; + break; + case SampleFormatInt16: + return 16; + break; + case SampleFormatInt24: + return 24; + break; + case SampleFormatInt32: + return 32; + break; + case SampleFormatFloat32: + return 32; + break; + case SampleFormatFixed5p27: + return 32; + break; + default: + return 0; + break; + } + } + + // backward compatibility, conversion to/from integers + operator int () const { return value; } + SampleFormat(int v) : value(SampleFormatEnum(v)) { } + operator long () const { return value; } + SampleFormat(long v) : value(SampleFormatEnum(v)) { } + operator unsigned int () const { return value; } + SampleFormat(unsigned int v) : value(SampleFormatEnum(v)) { } + operator unsigned long () const { return value; } + SampleFormat(unsigned long v) : value(SampleFormatEnum(v)) { } +}; Property changes on: trunk/OpenMPT/soundlib/SampleFormat.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |