template project, first version

This commit is contained in:
rachelchu
2017-10-11 15:01:05 +02:00
commit 8e902224cf
794 changed files with 326190 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Inc\Audio.h" />
<ClInclude Include="SoundCommon.h" />
<ClInclude Include="WaveBankReader.h" />
<ClInclude Include="WAVFileReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp" />
<ClCompile Include="SoundCommon.cpp" />
<ClCompile Include="SoundEffect.cpp" />
<ClCompile Include="SoundEffectInstance.cpp" />
<ClCompile Include="WaveBank.cpp" />
<ClCompile Include="WaveBankReader.cpp" />
<ClCompile Include="WAVFileReader.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4F150A30-CECB-49D1-8283-6A3F57438CF5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DirectXTKAudioDX</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Inc">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Src">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WaveBankReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="WAVFileReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="..\Inc\Audio.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="SoundCommon.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBankReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WAVFileReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBank.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Inc\Audio.h" />
<ClInclude Include="SoundCommon.h" />
<ClInclude Include="WaveBankReader.h" />
<ClInclude Include="WAVFileReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp" />
<ClCompile Include="SoundCommon.cpp" />
<ClCompile Include="SoundEffect.cpp" />
<ClCompile Include="SoundEffectInstance.cpp" />
<ClCompile Include="WaveBank.cpp" />
<ClCompile Include="WaveBankReader.cpp" />
<ClCompile Include="WAVFileReader.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4F150A30-CECB-49D1-8283-6A3F57438CF5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DirectXTKAudio</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2013\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Inc">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Src">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WaveBankReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="WAVFileReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="..\Inc\Audio.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="SoundCommon.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBankReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WAVFileReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBank.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Inc\Audio.h" />
<ClInclude Include="SoundCommon.h" />
<ClInclude Include="WaveBankReader.h" />
<ClInclude Include="WAVFileReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp" />
<ClCompile Include="SoundCommon.cpp" />
<ClCompile Include="SoundEffect.cpp" />
<ClCompile Include="SoundEffectInstance.cpp" />
<ClCompile Include="WaveBank.cpp" />
<ClCompile Include="WaveBankReader.cpp" />
<ClCompile Include="WAVFileReader.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4F150A30-CECB-49D1-8283-6A3F57438CF5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DirectXTKAudioDX</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Inc">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Src">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WaveBankReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="WAVFileReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="..\Inc\Audio.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="SoundCommon.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBankReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WAVFileReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBank.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Inc\Audio.h" />
<ClInclude Include="SoundCommon.h" />
<ClInclude Include="WaveBankReader.h" />
<ClInclude Include="WAVFileReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp" />
<ClCompile Include="SoundCommon.cpp" />
<ClCompile Include="SoundEffect.cpp" />
<ClCompile Include="SoundEffectInstance.cpp" />
<ClCompile Include="WaveBank.cpp" />
<ClCompile Include="WaveBankReader.cpp" />
<ClCompile Include="WAVFileReader.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4F150A30-CECB-49D1-8283-6A3F57438CF5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DirectXTKAudio</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2015\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;_DEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;_DEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;NDEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;NDEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Inc">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Src">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WaveBankReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="WAVFileReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="..\Inc\Audio.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="SoundCommon.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBankReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WAVFileReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBank.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,202 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Inc\Audio.h" />
<ClInclude Include="SoundCommon.h" />
<ClInclude Include="WaveBankReader.h" />
<ClInclude Include="WAVFileReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp" />
<ClCompile Include="SoundCommon.cpp" />
<ClCompile Include="SoundEffect.cpp" />
<ClCompile Include="SoundEffectInstance.cpp" />
<ClCompile Include="WaveBank.cpp" />
<ClCompile Include="WaveBankReader.cpp" />
<ClCompile Include="WAVFileReader.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4F150A30-CECB-49D1-8283-6A3F57438CF5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DirectXTKAudioDX</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017_DXSDK\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioDX</TargetName>
<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Inc">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Src">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WaveBankReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="WAVFileReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="..\Inc\Audio.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="SoundCommon.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBankReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WAVFileReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBank.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,194 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Inc\Audio.h" />
<ClInclude Include="SoundCommon.h" />
<ClInclude Include="WaveBankReader.h" />
<ClInclude Include="WAVFileReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp" />
<ClCompile Include="SoundCommon.cpp" />
<ClCompile Include="SoundEffect.cpp" />
<ClCompile Include="SoundEffectInstance.cpp" />
<ClCompile Include="WaveBank.cpp" />
<ClCompile Include="WaveBankReader.cpp" />
<ClCompile Include="WAVFileReader.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4F150A30-CECB-49D1-8283-6A3F57438CF5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DirectXTKAudio</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</OutDir>
<IntDir>Bin\Desktop_2017\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DirectXTKAudioWin8</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;_DEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;_DEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;NDEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>EnableAllWarnings</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x0602;WIN32;NDEBUG;_LIB;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\Inc;..\Src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<AdditionalOptions>/permissive- /Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Inc">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Src">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WaveBankReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="WAVFileReader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="..\Inc\Audio.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="SoundCommon.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioEngine.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBankReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WAVFileReader.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="WaveBank.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="SoundCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="DynamicSoundEffectInstance.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,374 @@
//--------------------------------------------------------------------------------------
// File: DynamicSoundEffectInstance.cpp
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "SoundCommon.h"
using namespace DirectX;
//======================================================================================
// DynamicSoundEffectInstance
//======================================================================================
// Internal object implementation class.
class DynamicSoundEffectInstance::Impl : public IVoiceNotify
{
public:
Impl( _In_ AudioEngine* engine,
_In_ DynamicSoundEffectInstance* object, std::function<void(DynamicSoundEffectInstance*)>& bufferNeeded,
int sampleRate, int channels, int sampleBits, SOUND_EFFECT_INSTANCE_FLAGS flags ) :
mBase(),
mBufferNeeded( nullptr ),
mObject( object )
{
if ( ( sampleRate < XAUDIO2_MIN_SAMPLE_RATE )
|| ( sampleRate > XAUDIO2_MAX_SAMPLE_RATE ) )
{
DebugTrace( "DynamicSoundEffectInstance sampleRate must be in range %u...%u\n", XAUDIO2_MIN_SAMPLE_RATE, XAUDIO2_MAX_SAMPLE_RATE );
throw std::invalid_argument( "DynamicSoundEffectInstance" );
}
if ( !channels || ( channels > 8 ) )
{
DebugTrace( "DynamicSoundEffectInstance channels must be in range 1...8\n" );
throw std::invalid_argument( "DynamicSoundEffectInstance" );
}
switch ( sampleBits )
{
case 8:
case 16:
break;
default:
DebugTrace( "DynamicSoundEffectInstance sampleBits must be 8-bit or 16-bit\n" );
throw std::invalid_argument( "DynamicSoundEffectInstance" );
}
mBufferEvent.reset( CreateEventEx( nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE ) );
if ( !mBufferEvent )
{
throw std::exception( "CreateEvent" );
}
CreateIntegerPCM( &mWaveFormat, sampleRate, channels, sampleBits );
assert( engine != 0 );
engine->RegisterNotify( this, true );
mBase.Initialize( engine, &mWaveFormat, flags );
mBufferNeeded = bufferNeeded;
}
virtual ~Impl()
{
mBase.DestroyVoice();
if ( mBase.engine )
{
mBase.engine->UnregisterNotify( this, false, true );
mBase.engine = nullptr;
}
}
void Play();
void Resume();
void SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes );
const WAVEFORMATEX* GetFormat() const { return &mWaveFormat; } ;
// IVoiceNotify
virtual void __cdecl OnBufferEnd() override
{
SetEvent( mBufferEvent.get() );
}
virtual void __cdecl OnCriticalError() override
{
mBase.OnCriticalError();
}
virtual void __cdecl OnReset() override
{
mBase.OnReset();
}
virtual void __cdecl OnUpdate() override;
virtual void __cdecl OnDestroyEngine() override
{
mBase.OnDestroy();
}
virtual void __cdecl OnTrim() override
{
mBase.OnTrim();
}
virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const override
{
mBase.GatherStatistics(stats);
}
SoundEffectInstanceBase mBase;
private:
ScopedHandle mBufferEvent;
std::function<void(DynamicSoundEffectInstance*)> mBufferNeeded;
DynamicSoundEffectInstance* mObject;
WAVEFORMATEX mWaveFormat;
};
void DynamicSoundEffectInstance::Impl::Play()
{
if ( !mBase.voice )
{
mBase.AllocateVoice( &mWaveFormat );
}
(void)mBase.Play();
if ( mBase.voice && ( mBase.state == PLAYING ) && ( mBase.GetPendingBufferCount() <= 2 ) )
{
SetEvent( mBufferEvent.get() );
}
}
void DynamicSoundEffectInstance::Impl::Resume()
{
if ( mBase.voice && ( mBase.state == PAUSED ) )
{
mBase.Resume();
if ( ( mBase.state == PLAYING ) && ( mBase.GetPendingBufferCount() <= 2 ) )
{
SetEvent( mBufferEvent.get() );
}
}
}
_Use_decl_annotations_
void DynamicSoundEffectInstance::Impl::SubmitBuffer( const uint8_t* pAudioData, uint32_t offset, size_t audioBytes )
{
if ( !pAudioData || !audioBytes )
throw std::exception( "Invalid audio data buffer" );
if ( audioBytes > UINT32_MAX )
throw std::out_of_range( "SubmitBuffer" );
XAUDIO2_BUFFER buffer = {};
buffer.AudioBytes = static_cast<UINT32>( audioBytes );
buffer.pAudioData = pAudioData;
if( offset )
{
assert( mWaveFormat.wFormatTag == WAVE_FORMAT_PCM );
buffer.PlayBegin = offset / mWaveFormat.nBlockAlign;
buffer.PlayLength = static_cast<UINT32>( ( audioBytes - offset ) / mWaveFormat.nBlockAlign );
}
buffer.pContext = this;
HRESULT hr = mBase.voice->SubmitSourceBuffer( &buffer, nullptr );
if ( FAILED(hr) )
{
#ifdef _DEBUG
DebugTrace( "ERROR: DynamicSoundEffectInstance failed (%08X) when submitting buffer:\n", hr );
DebugTrace( "\tFormat Tag %u, %u channels, %u-bit, %u Hz, %Iu bytes [%u offset)\n", mWaveFormat.wFormatTag,
mWaveFormat.nChannels, mWaveFormat.wBitsPerSample, mWaveFormat.nSamplesPerSec, audioBytes, offset );
#endif
throw std::exception( "SubmitSourceBuffer" );
}
}
void DynamicSoundEffectInstance::Impl::OnUpdate()
{
DWORD result = WaitForSingleObjectEx( mBufferEvent.get(), 0, FALSE );
switch( result )
{
case WAIT_TIMEOUT:
break;
case WAIT_OBJECT_0:
if( mBufferNeeded )
{
// This callback happens on the same thread that called AudioEngine::Update()
mBufferNeeded( mObject );
}
break;
case WAIT_FAILED:
throw std::exception( "WaitForSingleObjectEx" );
}
}
//--------------------------------------------------------------------------------------
// DynamicSoundEffectInstance
//--------------------------------------------------------------------------------------
#pragma warning( disable : 4355 )
// Public constructors
_Use_decl_annotations_
DynamicSoundEffectInstance::DynamicSoundEffectInstance( AudioEngine* engine,
std::function<void(DynamicSoundEffectInstance*)> bufferNeeded,
int sampleRate, int channels, int sampleBits, SOUND_EFFECT_INSTANCE_FLAGS flags ) :
pImpl( new Impl( engine, this, bufferNeeded, sampleRate, channels, sampleBits, flags ) )
{
}
// Move constructor.
DynamicSoundEffectInstance::DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom)
: pImpl(std::move(moveFrom.pImpl))
{
}
// Move assignment.
DynamicSoundEffectInstance& DynamicSoundEffectInstance::operator= (DynamicSoundEffectInstance&& moveFrom)
{
pImpl = std::move(moveFrom.pImpl);
return *this;
}
// Public destructor.
DynamicSoundEffectInstance::~DynamicSoundEffectInstance()
{
}
// Public methods.
void DynamicSoundEffectInstance::Play()
{
pImpl->Play();
}
void DynamicSoundEffectInstance::Stop( bool immediate )
{
bool looped = false;
pImpl->mBase.Stop( immediate, looped );
}
void DynamicSoundEffectInstance::Pause()
{
pImpl->mBase.Pause();
}
void DynamicSoundEffectInstance::Resume()
{
pImpl->Resume();
}
void DynamicSoundEffectInstance::SetVolume( float volume )
{
pImpl->mBase.SetVolume( volume );
}
void DynamicSoundEffectInstance::SetPitch( float pitch )
{
pImpl->mBase.SetPitch( pitch );
}
void DynamicSoundEffectInstance::SetPan( float pan )
{
pImpl->mBase.SetPan( pan );
}
void DynamicSoundEffectInstance::Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords )
{
pImpl->mBase.Apply3D( listener, emitter, rhcoords );
}
_Use_decl_annotations_
void DynamicSoundEffectInstance::SubmitBuffer( const uint8_t* pAudioData, size_t audioBytes )
{
pImpl->SubmitBuffer( pAudioData, 0, audioBytes );
}
_Use_decl_annotations_
void DynamicSoundEffectInstance::SubmitBuffer( const uint8_t* pAudioData, uint32_t offset, size_t audioBytes )
{
pImpl->SubmitBuffer( pAudioData, offset, audioBytes );
}
// Public accessors.
SoundState DynamicSoundEffectInstance::GetState()
{
return pImpl->mBase.GetState( false );
}
size_t DynamicSoundEffectInstance::GetSampleDuration( size_t bytes ) const
{
auto wfx = pImpl->GetFormat();
if ( !wfx || !wfx->wBitsPerSample || !wfx->nChannels )
return 0;
return static_cast<size_t>( ( uint64_t( bytes ) * 8 )
/ uint64_t( wfx->wBitsPerSample * wfx->nChannels ) );
}
size_t DynamicSoundEffectInstance::GetSampleDurationMS( size_t bytes ) const
{
auto wfx = pImpl->GetFormat();
if ( !wfx || !wfx->nAvgBytesPerSec )
return 0;
return static_cast<size_t>( ( uint64_t(bytes) * 1000 ) / wfx->nAvgBytesPerSec );
}
size_t DynamicSoundEffectInstance::GetSampleSizeInBytes( uint64_t duration ) const
{
auto wfx = pImpl->GetFormat();
if ( !wfx || !wfx->nSamplesPerSec )
return 0;
return static_cast<size_t>( ( ( duration * wfx->nSamplesPerSec ) / 1000 ) * wfx->nBlockAlign );
}
int DynamicSoundEffectInstance::GetPendingBufferCount() const
{
return pImpl->mBase.GetPendingBufferCount();
}
const WAVEFORMATEX* DynamicSoundEffectInstance::GetFormat() const
{
return pImpl->GetFormat();
}

View File

@@ -0,0 +1,789 @@
//--------------------------------------------------------------------------------------
// File: SoundCommon.cpp
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "SoundCommon.h"
using namespace DirectX;
namespace
{
template <typename T> WORD ChannelsSpecifiedInMask(T x)
{
WORD bitCount = 0;
while (x) {++bitCount; x &= (x-1);}
return bitCount;
}
}
//======================================================================================
// Wave format utilities
//======================================================================================
bool DirectX::IsValid( _In_ const WAVEFORMATEX* wfx )
{
if ( !wfx )
return false;
if ( !wfx->nChannels )
{
DebugTrace( "ERROR: Wave format must have at least 1 channel\n" );
return false;
}
if ( wfx->nChannels > XAUDIO2_MAX_AUDIO_CHANNELS )
{
DebugTrace( "ERROR: Wave format must have less than %u channels (%u)\n", XAUDIO2_MAX_AUDIO_CHANNELS, wfx->nChannels );
return false;
}
if ( !wfx->nSamplesPerSec )
{
DebugTrace( "ERROR: Wave format cannot have a sample rate of 0\n" );
return false;
}
if ( ( wfx->nSamplesPerSec < XAUDIO2_MIN_SAMPLE_RATE )
|| ( wfx->nSamplesPerSec > XAUDIO2_MAX_SAMPLE_RATE ) )
{
DebugTrace( "ERROR: Wave format channel count must be in range %u..%u (%u)\n", XAUDIO2_MIN_SAMPLE_RATE, XAUDIO2_MAX_SAMPLE_RATE, wfx->nSamplesPerSec );
return false;
}
switch ( wfx->wFormatTag )
{
case WAVE_FORMAT_PCM:
switch( wfx->wBitsPerSample )
{
case 8:
case 16:
case 24:
case 32:
break;
default:
DebugTrace( "ERROR: Wave format integer PCM must have 8, 16, 24, or 32 bits per sample (%u)\n", wfx->wBitsPerSample );
return false;
}
if ( wfx->nBlockAlign != ( wfx->nChannels * wfx->wBitsPerSample / 8 ) )
{
DebugTrace( "ERROR: Wave format integer PCM - nBlockAlign (%u) != nChannels (%u) * wBitsPerSample (%u) / 8\n",
wfx->nBlockAlign, wfx->nChannels, wfx->wBitsPerSample );
return false;
}
if ( wfx->nAvgBytesPerSec != ( wfx->nSamplesPerSec * wfx->nBlockAlign ) )
{
DebugTrace( "ERROR: Wave format integer PCM - nAvgBytesPerSec (%lu) != nSamplesPerSec (%lu) * nBlockAlign (%u)\n",
wfx->nAvgBytesPerSec, wfx->nSamplesPerSec, wfx->nBlockAlign );
return false;
}
return true;
case WAVE_FORMAT_IEEE_FLOAT:
if ( wfx->wBitsPerSample != 32 )
{
DebugTrace( "ERROR: Wave format float PCM must have 32-bits per sample (%u)\n", wfx->wBitsPerSample );
return false;
}
if ( wfx->nBlockAlign != ( wfx->nChannels * wfx->wBitsPerSample / 8 ) )
{
DebugTrace( "ERROR: Wave format float PCM - nBlockAlign (%u) != nChannels (%u) * wBitsPerSample (%u) / 8\n",
wfx->nBlockAlign, wfx->nChannels, wfx->wBitsPerSample );
return false;
}
if ( wfx->nAvgBytesPerSec != ( wfx->nSamplesPerSec * wfx->nBlockAlign ) )
{
DebugTrace( "ERROR: Wave format float PCM - nAvgBytesPerSec (%lu) != nSamplesPerSec (%lu) * nBlockAlign (%u)\n",
wfx->nAvgBytesPerSec, wfx->nSamplesPerSec, wfx->nBlockAlign );
return false;
}
return true;
case WAVE_FORMAT_ADPCM:
if ( ( wfx->nChannels != 1 ) && ( wfx->nChannels != 2 ) )
{
DebugTrace( "ERROR: Wave format ADPCM must have 1 or 2 channels (%u)\n", wfx->nChannels );
return false;
}
if ( wfx->wBitsPerSample != 4 /*MSADPCM_BITS_PER_SAMPLE*/ )
{
DebugTrace( "ERROR: Wave format ADPCM must have 4 bits per sample (%u)\n", wfx->wBitsPerSample );
return false;
}
if ( wfx->cbSize != 32 /*MSADPCM_FORMAT_EXTRA_BYTES*/ )
{
DebugTrace( "ERROR: Wave format ADPCM must have cbSize = 32 (%u)\n", wfx->cbSize );
return false;
}
else
{
auto wfadpcm = reinterpret_cast<const ADPCMWAVEFORMAT*>( wfx );
if ( wfadpcm->wNumCoef != 7 /*MSADPCM_NUM_COEFFICIENTS*/ )
{
DebugTrace( "ERROR: Wave format ADPCM must have 7 coefficients (%u)\n", wfadpcm->wNumCoef );
return false;
}
bool valid = true;
for ( int j = 0; j < 7 /*MSADPCM_NUM_COEFFICIENTS*/; ++j )
{
// Microsoft ADPCM standard encoding coefficients
static const short g_pAdpcmCoefficients1[] = {256, 512, 0, 192, 240, 460, 392};
static const short g_pAdpcmCoefficients2[] = { 0, -256, 0, 64, 0, -208, -232};
if ( wfadpcm->aCoef[j].iCoef1 != g_pAdpcmCoefficients1[j]
|| wfadpcm->aCoef[j].iCoef2 != g_pAdpcmCoefficients2[j] )
{
valid = false;
}
}
if ( !valid )
{
DebugTrace( "ERROR: Wave formt ADPCM found non-standard coefficients\n" );
return false;
}
if ( ( wfadpcm->wSamplesPerBlock < 4 /*MSADPCM_MIN_SAMPLES_PER_BLOCK*/ )
|| ( wfadpcm->wSamplesPerBlock > 64000 /*MSADPCM_MAX_SAMPLES_PER_BLOCK*/ ) )
{
DebugTrace( "ERROR: Wave format ADPCM wSamplesPerBlock must be 4..64000 (%u)\n", wfadpcm->wSamplesPerBlock );
return false;
}
if ( wfadpcm->wfx.nChannels == 1 && ( wfadpcm->wSamplesPerBlock % 2 ) )
{
DebugTrace( "ERROR: Wave format ADPCM mono files must have even wSamplesPerBlock\n" );
return false;
}
int nHeaderBytes = 7 /*MSADPCM_HEADER_LENGTH*/ * wfx->nChannels;
int nBitsPerFrame = 4 /*MSADPCM_BITS_PER_SAMPLE*/ * wfx->nChannels;
int nPcmFramesPerBlock = (wfx->nBlockAlign - nHeaderBytes) * 8 / nBitsPerFrame + 2;
if ( wfadpcm->wSamplesPerBlock != nPcmFramesPerBlock )
{
DebugTrace( "ERROR: Wave format ADPCM %u-channel with nBlockAlign = %u must have wSamplesPerBlock = %u (%u)\n",
wfx->nChannels, wfx->nBlockAlign, nPcmFramesPerBlock, wfadpcm->wSamplesPerBlock );
return false;
}
}
return true;
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
if ( wfx->wBitsPerSample != 16 )
{
DebugTrace( "ERROR: Wave format xWMA only supports 16-bit data\n" );
return false;
}
if ( !wfx->nBlockAlign )
{
DebugTrace( "ERROR: Wave format xWMA must have a non-zero nBlockAlign\n" );
return false;
}
if ( !wfx->nAvgBytesPerSec )
{
DebugTrace( "ERROR: Wave format xWMA must have a non-zero nAvgBytesPerSec\n" );
return false;
}
return true;
#else
DebugTrace( "ERROR: Wave format xWMA not supported by this version of DirectXTK for Audio\n" );
return false;
#endif
case 0x166 /* WAVE_FORMAT_XMA2 */:
#if defined(_XBOX_ONE) && defined(_TITLE)
if ( wfx->nBlockAlign != wfx->nChannels * XMA_OUTPUT_SAMPLE_BYTES)
{
DebugTrace( "ERROR: Wave format XMA2 - nBlockAlign (%u) != nChannels(%u) * %u\n", wfx->nBlockAlign, wfx->nChannels, XMA_OUTPUT_SAMPLE_BYTES );
return false;
}
if ( wfx->wBitsPerSample != XMA_OUTPUT_SAMPLE_BITS )
{
DebugTrace( "ERROR: Wave format XMA2 wBitsPerSample (%u) should be %u\n", wfx->wBitsPerSample, XMA_OUTPUT_SAMPLE_BITS );
return false;
}
if ( wfx->cbSize != ( sizeof(XMA2WAVEFORMATEX) - sizeof(WAVEFORMATEX) ) )
{
DebugTrace( "ERROR: Wave format XMA2 - cbSize must be %Iu (%u)\n", ( sizeof(XMA2WAVEFORMATEX) - sizeof(WAVEFORMATEX) ), wfx->cbSize );
return false;
}
else
{
auto xmaFmt = reinterpret_cast<const XMA2WAVEFORMATEX*>( wfx );
if ( xmaFmt->EncoderVersion < 3 )
{
DebugTrace( "ERROR: Wave format XMA2 encoder version (%u) - 3 or higher is required\n", xmaFmt->EncoderVersion );
return false;
}
if ( !xmaFmt->BlockCount )
{
DebugTrace( "ERROR: Wave format XMA2 BlockCount must be non-zero\n" );
return false;
}
if ( !xmaFmt->BytesPerBlock || ( xmaFmt->BytesPerBlock > XMA_READBUFFER_MAX_BYTES ) )
{
DebugTrace( "ERROR: Wave format XMA2 BytesPerBlock (%u) is invalid\n", xmaFmt->BytesPerBlock );
return false;
}
if ( xmaFmt->ChannelMask )
{
auto channelBits = ChannelsSpecifiedInMask( xmaFmt->ChannelMask );
if ( channelBits != wfx->nChannels )
{
DebugTrace( "ERROR: Wave format XMA2 - nChannels=%u but ChannelMask (%08X) has %u bits set\n",
xmaFmt->ChannelMask, wfx->nChannels, channelBits );
return false;
}
}
if ( xmaFmt->NumStreams != ( ( wfx->nChannels + 1) / 2 ) )
{
DebugTrace( "ERROR: Wave format XMA2 - NumStreams (%u) != ( nChannels(%u) + 1 ) / 2\n", xmaFmt->NumStreams, wfx->nChannels );
return false;
}
if ( ( xmaFmt->PlayBegin + xmaFmt->PlayLength ) > xmaFmt->SamplesEncoded )
{
DebugTrace( "ERROR: Wave format XMA2 play region too large (%u + %u > %u)\n", xmaFmt->PlayBegin, xmaFmt->PlayLength, xmaFmt->SamplesEncoded );
return false;
}
if ( ( xmaFmt->LoopBegin + xmaFmt->LoopLength ) > xmaFmt->SamplesEncoded )
{
DebugTrace( "ERROR: Wave format XMA2 loop region too large (%u + %u > %u)\n", xmaFmt->LoopBegin, xmaFmt->LoopLength, xmaFmt->SamplesEncoded );
return false;
}
}
return true;
#else
DebugTrace( "ERROR: Wave format XMA2 not supported by this version of DirectXTK for Audio\n" );
return false;
#endif
case WAVE_FORMAT_EXTENSIBLE:
if ( wfx->cbSize < ( sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) ) )
{
DebugTrace( "ERROR: Wave format WAVE_FORMAT_EXTENSIBLE - cbSize must be %Iu (%u)\n", ( sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) ), wfx->cbSize );
return false;
}
else
{
static const GUID s_wfexBase = {0x00000000, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71};
auto wfex = reinterpret_cast<const WAVEFORMATEXTENSIBLE*>( wfx );
if ( memcmp( reinterpret_cast<const BYTE*>(&wfex->SubFormat) + sizeof(DWORD),
reinterpret_cast<const BYTE*>(&s_wfexBase) + sizeof(DWORD), sizeof(GUID) - sizeof(DWORD) ) != 0 )
{
DebugTrace( "ERROR: Wave format WAVEFORMATEXTENSIBLE encountered with unknown GUID ({%8.8lX-%4.4X-%4.4X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X})\n",
wfex->SubFormat.Data1, wfex->SubFormat.Data2, wfex->SubFormat.Data3,
wfex->SubFormat.Data4[0], wfex->SubFormat.Data4[1], wfex->SubFormat.Data4[2], wfex->SubFormat.Data4[3],
wfex->SubFormat.Data4[4], wfex->SubFormat.Data4[5], wfex->SubFormat.Data4[6], wfex->SubFormat.Data4[7] );
return false;
}
switch( wfex->SubFormat.Data1 )
{
case WAVE_FORMAT_PCM:
switch( wfx->wBitsPerSample )
{
case 8:
case 16:
case 24:
case 32:
break;
default:
DebugTrace( "ERROR: Wave format integer PCM must have 8, 16, 24, or 32 bits per sample (%u)\n", wfx->wBitsPerSample );
return false;
}
switch( wfex->Samples.wValidBitsPerSample )
{
case 0:
case 8:
case 16:
case 20:
case 24:
case 32:
break;
default:
DebugTrace( "ERROR: Wave format integer PCM must have 8, 16, 20, 24, or 32 valid bits per sample (%u)\n", wfex->Samples.wValidBitsPerSample );
return false;
}
if ( wfex->Samples.wValidBitsPerSample
&& ( wfex->Samples.wValidBitsPerSample > wfx->wBitsPerSample ) )
{
DebugTrace( "ERROR: Wave format ingter PCM wValidBitsPerSample (%u) is greater than wBitsPerSample (%u)\n", wfex->Samples.wValidBitsPerSample, wfx->wBitsPerSample );
return false;
}
if ( wfx->nBlockAlign != ( wfx->nChannels * wfx->wBitsPerSample / 8 ) )
{
DebugTrace( "ERROR: Wave format integer PCM - nBlockAlign (%u) != nChannels (%u) * wBitsPerSample (%u) / 8\n",
wfx->nBlockAlign, wfx->nChannels, wfx->wBitsPerSample );
return false;
}
if ( wfx->nAvgBytesPerSec != ( wfx->nSamplesPerSec * wfx->nBlockAlign ) )
{
DebugTrace( "ERROR: Wave format integer PCM - nAvgBytesPerSec (%lu) != nSamplesPerSec (%lu) * nBlockAlign (%u)\n",
wfx->nAvgBytesPerSec, wfx->nSamplesPerSec, wfx->nBlockAlign );
return false;
}
break;
case WAVE_FORMAT_IEEE_FLOAT:
if ( wfx->wBitsPerSample != 32 )
{
DebugTrace( "ERROR: Wave format float PCM must have 32-bits per sample (%u)\n", wfx->wBitsPerSample );
return false;
}
switch( wfex->Samples.wValidBitsPerSample )
{
case 0:
case 32:
break;
default:
DebugTrace( "ERROR: Wave format float PCM must have 32 valid bits per sample (%u)\n", wfex->Samples.wValidBitsPerSample );
return false;
}
if ( wfx->nBlockAlign != ( wfx->nChannels * wfx->wBitsPerSample / 8 ) )
{
DebugTrace( "ERROR: Wave format float PCM - nBlockAlign (%u) != nChannels (%u) * wBitsPerSample (%u) / 8\n",
wfx->nBlockAlign, wfx->nChannels, wfx->wBitsPerSample );
return false;
}
if ( wfx->nAvgBytesPerSec != ( wfx->nSamplesPerSec * wfx->nBlockAlign ) )
{
DebugTrace( "ERROR: Wave format float PCM - nAvgBytesPerSec (%lu) != nSamplesPerSec (%lu) * nBlockAlign (%u)\n",
wfx->nAvgBytesPerSec, wfx->nSamplesPerSec, wfx->nBlockAlign );
return false;
}
break;
case WAVE_FORMAT_ADPCM:
DebugTrace( "ERROR: Wave format ADPCM is not supported as a WAVEFORMATEXTENSIBLE\n" );
return false;
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
if ( wfx->wBitsPerSample != 16 )
{
DebugTrace( "ERROR: Wave format xWMA only supports 16-bit data\n" );
return false;
}
if ( !wfx->nBlockAlign )
{
DebugTrace( "ERROR: Wave format xWMA must have a non-zero nBlockAlign\n" );
return false;
}
if ( !wfx->nAvgBytesPerSec )
{
DebugTrace( "ERROR: Wave format xWMA must have a non-zero nAvgBytesPerSec\n" );
return false;
}
break;
#else
DebugTrace( "ERROR: Wave format xWMA not supported by this version of DirectXTK for Audio\n" );
return false;
#endif
case 0x166 /* WAVE_FORMAT_XMA2 */:
DebugTrace( "ERROR: Wave format XMA2 is not supported as a WAVEFORMATEXTENSIBLE\n" );
return false;
default:
DebugTrace( "ERROR: Unknown WAVEFORMATEXTENSIBLE format tag (%u)\n", wfex->SubFormat.Data1 );
return false;
}
if ( wfex->dwChannelMask )
{
auto channelBits = ChannelsSpecifiedInMask( wfex->dwChannelMask );
if ( channelBits != wfx->nChannels )
{
DebugTrace( "ERROR: WAVEFORMATEXTENSIBLE: nChannels=%u but ChannelMask has %u bits set\n",
wfx->nChannels, channelBits );
return false;
}
}
return true;
}
default:
DebugTrace( "ERROR: Unknown WAVEFORMATEX format tag (%u)\n", wfx->wFormatTag );
return false;
}
}
uint32_t DirectX::GetDefaultChannelMask( int channels )
{
switch( channels )
{
case 1: return SPEAKER_MONO;
case 2: return SPEAKER_STEREO;
case 3: return SPEAKER_2POINT1;
case 4: return SPEAKER_QUAD;
case 5: return SPEAKER_4POINT1;
case 6: return SPEAKER_5POINT1;
case 7: return SPEAKER_5POINT1 | SPEAKER_BACK_CENTER;
case 8: return SPEAKER_7POINT1;
default: return 0;
}
}
_Use_decl_annotations_
void DirectX::CreateIntegerPCM( WAVEFORMATEX* wfx, int sampleRate, int channels, int sampleBits )
{
int blockAlign = channels * sampleBits / 8;
wfx->wFormatTag = WAVE_FORMAT_PCM;
wfx->nChannels = static_cast<WORD>( channels );
wfx->nSamplesPerSec = static_cast<DWORD>( sampleRate );
wfx->nAvgBytesPerSec = static_cast<DWORD>( blockAlign * sampleRate );
wfx->nBlockAlign = static_cast<WORD>( blockAlign );
wfx->wBitsPerSample = static_cast<WORD>( sampleBits );
wfx->cbSize = 0;
assert( IsValid( wfx ) );
}
_Use_decl_annotations_
void DirectX::CreateFloatPCM( WAVEFORMATEX* wfx, int sampleRate, int channels )
{
int blockAlign = channels * 4;
wfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
wfx->nChannels = static_cast<WORD>( channels );
wfx->nSamplesPerSec = static_cast<DWORD>( sampleRate );
wfx->nAvgBytesPerSec = static_cast<DWORD>( blockAlign * sampleRate );
wfx->nBlockAlign = static_cast<WORD>( blockAlign );
wfx->wBitsPerSample = 32;
wfx->cbSize = 0;
assert( IsValid( wfx ) );
}
_Use_decl_annotations_
void DirectX::CreateADPCM( WAVEFORMATEX* wfx, size_t wfxSize, int sampleRate, int channels, int samplesPerBlock )
{
if ( wfxSize < ( sizeof(WAVEFORMATEX) + 32 /*MSADPCM_FORMAT_EXTRA_BYTES*/ ) )
{
DebugTrace( "CreateADPCM needs at least %Iu bytes for the result\n", ( sizeof(WAVEFORMATEX) + 32 /*MSADPCM_FORMAT_EXTRA_BYTES*/ ) );
throw std::invalid_argument( "ADPCMWAVEFORMAT" );
}
if ( !samplesPerBlock )
{
DebugTrace( "CreateADPCM needs a non-zero samples per block count\n" );
throw std::invalid_argument( "ADPCMWAVEFORMAT" );
}
int blockAlign = (7 /*MSADPCM_HEADER_LENGTH*/) * channels
+ (samplesPerBlock - 2) * (4 /* MSADPCM_BITS_PER_SAMPLE */) * channels / 8;
wfx->wFormatTag = WAVE_FORMAT_ADPCM;
wfx->nChannels = static_cast<WORD>( channels );
wfx->nSamplesPerSec = static_cast<DWORD>( sampleRate );
wfx->nAvgBytesPerSec = static_cast<DWORD>( blockAlign * sampleRate / samplesPerBlock );
wfx->nBlockAlign = static_cast<WORD>( blockAlign );
wfx->wBitsPerSample = 4 /* MSADPCM_BITS_PER_SAMPLE */;
wfx->cbSize = 32 /*MSADPCM_FORMAT_EXTRA_BYTES*/;
auto adpcm = reinterpret_cast<ADPCMWAVEFORMAT*>( wfx );
adpcm->wSamplesPerBlock = static_cast<WORD>( samplesPerBlock );
adpcm->wNumCoef = 7 /* MSADPCM_NUM_COEFFICIENTS */;
static ADPCMCOEFSET aCoef[7] = { { 256, 0}, {512, -256}, {0,0}, {192,64}, {240,0}, {460, -208}, {392,-232} };
memcpy( &adpcm->aCoef, aCoef, sizeof(aCoef) );
assert( IsValid( wfx ) );
}
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
_Use_decl_annotations_
void DirectX::CreateXWMA( WAVEFORMATEX* wfx, int sampleRate, int channels, int blockAlign, int avgBytes, bool wma3 )
{
wfx->wFormatTag = (wma3) ? WAVE_FORMAT_WMAUDIO3 : WAVE_FORMAT_WMAUDIO2;
wfx->nChannels = static_cast<WORD>( channels );
wfx->nSamplesPerSec = static_cast<DWORD>( sampleRate );
wfx->nAvgBytesPerSec = static_cast<DWORD>( avgBytes );
wfx->nBlockAlign = static_cast<WORD>( blockAlign );
wfx->wBitsPerSample = 16;
wfx->cbSize = 0;
assert( IsValid( wfx ) );
}
#endif
#if defined(_XBOX_ONE) && defined(_TITLE)
_Use_decl_annotations_
void DirectX::CreateXMA2( WAVEFORMATEX* wfx, size_t wfxSize, int sampleRate, int channels, int bytesPerBlock, int blockCount, int samplesEncoded )
{
if ( wfxSize < sizeof(XMA2WAVEFORMATEX) )
{
DebugTrace( "XMA2 needs at least %Iu bytes for the result\n", sizeof(XMA2WAVEFORMATEX) );
throw std::invalid_argument( "XMA2WAVEFORMATEX" );
}
if ( !bytesPerBlock || ( bytesPerBlock > XMA_READBUFFER_MAX_BYTES ) )
{
DebugTrace( "XMA2 needs a valid bytes per block\n" );
throw std::invalid_argument( "XMA2WAVEFORMATEX" );
}
int blockAlign = (channels * ( 16 /*XMA_OUTPUT_SAMPLE_BITS*/ ) / 8);
wfx->wFormatTag = WAVE_FORMAT_XMA2;
wfx->nChannels = static_cast<WORD>( channels );
wfx->nSamplesPerSec = static_cast<WORD>( sampleRate );
wfx->nAvgBytesPerSec = static_cast<DWORD>( blockAlign * sampleRate );
wfx->nBlockAlign = static_cast<WORD>( blockAlign );
wfx->wBitsPerSample = 16 /* XMA_OUTPUT_SAMPLE_BITS */;
wfx->cbSize = sizeof(XMA2WAVEFORMATEX) - sizeof(WAVEFORMATEX);
auto xmaFmt = reinterpret_cast<XMA2WAVEFORMATEX*>(wfx);
xmaFmt->NumStreams = static_cast<WORD>( (channels + 1) / 2 );
xmaFmt->ChannelMask = GetDefaultChannelMask( channels );
xmaFmt->SamplesEncoded = static_cast<DWORD>( samplesEncoded );
xmaFmt->BytesPerBlock = bytesPerBlock;
xmaFmt->PlayBegin = xmaFmt->PlayLength =
xmaFmt->LoopBegin = xmaFmt->LoopLength = xmaFmt->LoopCount = 0;
xmaFmt->EncoderVersion = 4 /* XMAENCODER_VERSION_XMA2 */;
xmaFmt->BlockCount = static_cast<WORD>( blockCount );
assert( IsValid( wfx ) );
}
#endif // _XBOX_ONE && _TITLE
_Use_decl_annotations_
bool DirectX::ComputePan( float pan, int channels, float* matrix )
{
memset( matrix, 0, sizeof(float) * 16 );
if (channels == 1)
{
// Mono panning
float left = ( pan >= 0 ) ? ( 1.f - pan ) : 1.f;
left = std::min<float>( 1.f, left );
left = std::max<float>( -1.f, left );
float right = ( pan <= 0 ) ? ( - pan - 1.f ) : 1.f;
right = std::min<float>( 1.f, right );
right = std::max<float>( -1.f, right );
matrix[0] = left;
matrix[1] = right;
}
else if (channels == 2)
{
// Stereo panning
if ( -1.f <= pan && pan <= 0.f )
{
matrix[0] = .5f * pan + 1.f; // .5 when pan is -1, 1 when pan is 0
matrix[1] = .5f * -pan; // .5 when pan is -1, 0 when pan is 0
matrix[2] = 0.f; // 0 when pan is -1, 0 when pan is 0
matrix[3] = pan + 1.f; // 0 when pan is -1, 1 when pan is 0
}
else
{
matrix[0] = -pan + 1.f; // 1 when pan is 0, 0 when pan is 1
matrix[1] = 0.f; // 0 when pan is 0, 0 when pan is 1
matrix[2] = .5f * pan; // 0 when pan is 0, .5f when pan is 1
matrix[3] = .5f * -pan + 1.f; // 1 when pan is 0. .5f when pan is 1
}
}
else
{
if ( pan != 0.f )
{
DebugTrace( "WARNING: Only supports panning on mono or stereo source data, ignored\n" );
}
return false;
}
return true;
}
//======================================================================================
// SoundEffectInstanceBase
//======================================================================================
void SoundEffectInstanceBase::SetPan( float pan )
{
assert( pan >= -1.f && pan <= 1.f );
mPan = pan;
if ( !voice )
return;
float matrix[16];
if ( ComputePan( pan, mDSPSettings.SrcChannelCount, matrix ) )
{
HRESULT hr = voice->SetOutputMatrix( nullptr, mDSPSettings.SrcChannelCount, mDSPSettings.DstChannelCount, matrix );
ThrowIfFailed( hr );
}
}
void SoundEffectInstanceBase::Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords )
{
if ( !voice )
return;
if ( !( mFlags & SoundEffectInstance_Use3D ) )
{
DebugTrace( "ERROR: Apply3D called for an instance created without SoundEffectInstance_Use3D set\n" );
throw std::exception( "Apply3D" );
}
DWORD dwCalcFlags = X3DAUDIO_CALCULATE_MATRIX | X3DAUDIO_CALCULATE_DOPPLER | X3DAUDIO_CALCULATE_LPF_DIRECT;
if ( mFlags & SoundEffectInstance_UseRedirectLFE )
{
// On devices with an LFE channel, allow the mono source data to be routed to the LFE destination channel.
dwCalcFlags |= X3DAUDIO_CALCULATE_REDIRECT_TO_LFE;
}
auto reverb = mReverbVoice;
if ( reverb )
{
dwCalcFlags |= X3DAUDIO_CALCULATE_LPF_REVERB | X3DAUDIO_CALCULATE_REVERB;
}
float matrix[XAUDIO2_MAX_AUDIO_CHANNELS * 8] = {};
assert( mDSPSettings.SrcChannelCount <= XAUDIO2_MAX_AUDIO_CHANNELS );
assert( mDSPSettings.DstChannelCount <= 8 );
mDSPSettings.pMatrixCoefficients = matrix;
assert( engine != 0 );
if (rhcoords)
{
X3DAUDIO_EMITTER lhEmitter;
memcpy(&lhEmitter, &emitter, sizeof(X3DAUDIO_EMITTER));
lhEmitter.OrientFront.z = -emitter.OrientFront.z;
lhEmitter.OrientTop.z = -emitter.OrientTop.z;
lhEmitter.Position.z = -emitter.Position.z;
lhEmitter.Velocity.z = -emitter.Velocity.z;
X3DAUDIO_LISTENER lhListener;
memcpy(&lhListener, &listener, sizeof(X3DAUDIO_LISTENER));
lhListener.OrientFront.z = -listener.OrientFront.z;
lhListener.OrientTop.z = -listener.OrientTop.z;
lhListener.Position.z = -listener.Position.z;
lhListener.Velocity.z = -listener.Velocity.z;
X3DAudioCalculate( engine->Get3DHandle(), &lhListener, &lhEmitter, dwCalcFlags, &mDSPSettings );
}
else
{
X3DAudioCalculate( engine->Get3DHandle(), &listener, &emitter, dwCalcFlags, &mDSPSettings );
}
mDSPSettings.pMatrixCoefficients = nullptr;
(void)voice->SetFrequencyRatio( mFreqRatio * mDSPSettings.DopplerFactor );
auto direct = mDirectVoice;
assert( direct != 0 );
(void)voice->SetOutputMatrix( direct, mDSPSettings.SrcChannelCount, mDSPSettings.DstChannelCount, matrix );
if ( reverb )
{
for ( size_t j = 0; j < mDSPSettings.SrcChannelCount; ++j )
{
matrix[j] = mDSPSettings.ReverbLevel;
}
(void)voice->SetOutputMatrix( reverb, mDSPSettings.SrcChannelCount, 1, matrix );
}
if ( mFlags & SoundEffectInstance_ReverbUseFilters )
{
XAUDIO2_FILTER_PARAMETERS filterDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * mDSPSettings.LPFDirectCoefficient), 1.0f };
// see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here
(void)voice->SetOutputFilterParameters( direct, &filterDirect );
if ( reverb )
{
XAUDIO2_FILTER_PARAMETERS filterReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * mDSPSettings.LPFReverbCoefficient), 1.0f };
// see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here
(void)voice->SetOutputFilterParameters( reverb, &filterReverb );
}
}
}

View File

@@ -0,0 +1,370 @@
//--------------------------------------------------------------------------------------
// File: SoundCommon.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#include "Audio.h"
#include "PlatformHelpers.h"
namespace DirectX
{
// Helper for getting a format tag from a WAVEFORMATEX
inline uint32_t GetFormatTag( const WAVEFORMATEX* wfx )
{
if ( wfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE )
{
if ( wfx->cbSize < ( sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) ) )
return 0;
static const GUID s_wfexBase = {0x00000000, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71};
auto wfex = reinterpret_cast<const WAVEFORMATEXTENSIBLE*>( wfx );
if ( memcmp( reinterpret_cast<const BYTE*>(&wfex->SubFormat) + sizeof(DWORD),
reinterpret_cast<const BYTE*>(&s_wfexBase) + sizeof(DWORD), sizeof(GUID) - sizeof(DWORD) ) != 0 )
{
return 0;
}
return wfex->SubFormat.Data1;
}
else
{
return wfx->wFormatTag;
}
}
// Helper for validating wave format structure
bool IsValid( _In_ const WAVEFORMATEX* wfx );
// Helper for getting a default channel mask from channels
uint32_t GetDefaultChannelMask( int channels );
// Helpers for creating various wave format structures
void CreateIntegerPCM( _Out_ WAVEFORMATEX* wfx, int sampleRate, int channels, int sampleBits );
void CreateFloatPCM( _Out_ WAVEFORMATEX* wfx, int sampleRate, int channels );
void CreateADPCM( _Out_writes_bytes_(wfxSize) WAVEFORMATEX* wfx, size_t wfxSize, int sampleRate, int channels, int samplesPerBlock );
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
void CreateXWMA( _Out_ WAVEFORMATEX* wfx, int sampleRate, int channels, int blockAlign, int avgBytes, bool wma3 );
#endif
#if defined(_XBOX_ONE) && defined(_TITLE)
void CreateXMA2( _Out_writes_bytes_(wfxSize) WAVEFORMATEX* wfx, size_t wfxSize, int sampleRate, int channels, int bytesPerBlock, int blockCount, int samplesEncoded );
#endif
// Helper for computing pan volume matrix
bool ComputePan( float pan, int channels, _Out_writes_(16) float* matrix );
// Helper class for implementing SoundEffectInstance
class SoundEffectInstanceBase
{
public:
SoundEffectInstanceBase() :
voice( nullptr ),
state( STOPPED ),
engine( nullptr ),
mVolume( 1.f ),
mPitch( 0.f ),
mFreqRatio( 1.f ),
mPan( 0.f ),
mFlags( SoundEffectInstance_Default ),
mDirectVoice( nullptr ),
mReverbVoice( nullptr ),
mDSPSettings{}
{
}
~SoundEffectInstanceBase()
{
assert( !voice );
}
void Initialize( _In_ AudioEngine* eng, _In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags )
{
assert( eng != 0 );
engine = eng;
mDirectVoice = eng->GetMasterVoice();
mReverbVoice = eng->GetReverbVoice();
if ( eng->GetChannelMask() & SPEAKER_LOW_FREQUENCY )
mFlags = flags | SoundEffectInstance_UseRedirectLFE;
else
mFlags = static_cast<SOUND_EFFECT_INSTANCE_FLAGS>( static_cast<int>(flags) & ~SoundEffectInstance_UseRedirectLFE );
memset( &mDSPSettings, 0, sizeof(X3DAUDIO_DSP_SETTINGS) );
assert( wfx != 0 );
mDSPSettings.SrcChannelCount = wfx->nChannels;
mDSPSettings.DstChannelCount = eng->GetOutputChannels();
}
void AllocateVoice( _In_ const WAVEFORMATEX* wfx )
{
if ( voice )
return;
assert( engine != 0 );
engine->AllocateVoice( wfx, mFlags, false, &voice );
}
void DestroyVoice()
{
if ( voice )
{
assert( engine != 0 );
engine->DestroyVoice( voice );
voice = nullptr;
}
}
bool Play() // Returns true if STOPPED -> PLAYING
{
if ( voice )
{
if ( state == PAUSED )
{
HRESULT hr = voice->Start( 0 );
ThrowIfFailed( hr );
state = PLAYING;
}
else if ( state != PLAYING )
{
if ( mVolume != 1.f )
{
HRESULT hr = voice->SetVolume( mVolume );
ThrowIfFailed( hr );
}
if ( mPitch != 0.f )
{
mFreqRatio = XAudio2SemitonesToFrequencyRatio( mPitch * 12.f );
HRESULT hr = voice->SetFrequencyRatio( mFreqRatio );
ThrowIfFailed( hr );
}
if ( mPan != 0.f )
{
SetPan( mPan );
}
HRESULT hr = voice->Start( 0 );
ThrowIfFailed( hr );
state = PLAYING;
return true;
}
}
return false;
}
void Stop( bool immediate, bool& looped )
{
if ( !voice )
{
state = STOPPED;
return;
}
if ( immediate )
{
state = STOPPED;
(void)voice->Stop( 0 );
(void)voice->FlushSourceBuffers();
}
else if ( looped )
{
looped = false;
(void)voice->ExitLoop();
}
else
{
(void)voice->Stop( XAUDIO2_PLAY_TAILS );
}
}
void Pause()
{
if ( voice && state == PLAYING )
{
state = PAUSED;
(void)voice->Stop( 0 );
}
}
void Resume()
{
if ( voice && state == PAUSED )
{
HRESULT hr = voice->Start( 0 );
ThrowIfFailed( hr );
state = PLAYING;
}
}
void SetVolume( float volume )
{
assert( volume >= -XAUDIO2_MAX_VOLUME_LEVEL && volume <= XAUDIO2_MAX_VOLUME_LEVEL );
mVolume = volume;
if ( voice )
{
HRESULT hr = voice->SetVolume( volume );
ThrowIfFailed( hr );
}
}
void SetPitch( float pitch )
{
assert( pitch >= -1.f && pitch <= 1.f );
if ( ( mFlags & SoundEffectInstance_NoSetPitch ) && pitch != 0.f )
{
DebugTrace( "ERROR: Sound effect instance was created with the NoSetPitch flag\n" );
throw std::exception( "SetPitch" );
}
mPitch = pitch;
if ( voice )
{
mFreqRatio = XAudio2SemitonesToFrequencyRatio( mPitch * 12.f );
HRESULT hr = voice->SetFrequencyRatio( mFreqRatio );
ThrowIfFailed( hr );
}
}
void SetPan( float pan );
void Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords );
SoundState GetState( bool autostop )
{
if ( autostop && voice && ( state == PLAYING ) )
{
XAUDIO2_VOICE_STATE xstate;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
voice->GetState( &xstate, XAUDIO2_VOICE_NOSAMPLESPLAYED );
#else
voice->GetState( &xstate );
#endif
if ( !xstate.BuffersQueued )
{
// Automatic stop if the buffer has finished playing
(void)voice->Stop();
state = STOPPED;
}
}
return state;
}
int GetPendingBufferCount() const
{
if ( !voice )
return 0;
XAUDIO2_VOICE_STATE xstate;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
voice->GetState( &xstate, XAUDIO2_VOICE_NOSAMPLESPLAYED );
#else
voice->GetState( &xstate );
#endif
return static_cast<int>( xstate.BuffersQueued );
}
void OnCriticalError()
{
if ( voice )
{
voice->DestroyVoice();
voice = nullptr;
}
state = STOPPED;
mDirectVoice = nullptr;
mReverbVoice = nullptr;
}
void OnReset()
{
assert( engine != 0 );
mDirectVoice = engine->GetMasterVoice();
mReverbVoice = engine->GetReverbVoice();
if ( engine->GetChannelMask() & SPEAKER_LOW_FREQUENCY )
mFlags = mFlags | SoundEffectInstance_UseRedirectLFE;
else
mFlags = static_cast<SOUND_EFFECT_INSTANCE_FLAGS>( static_cast<int>(mFlags) & ~SoundEffectInstance_UseRedirectLFE );
mDSPSettings.DstChannelCount = engine->GetOutputChannels();
}
void OnDestroy()
{
if ( voice )
{
(void)voice->Stop( 0 );
(void)voice->FlushSourceBuffers();
voice->DestroyVoice();
voice = nullptr;
}
state = STOPPED;
engine = nullptr;
mDirectVoice = nullptr;
mReverbVoice = nullptr;
}
void OnTrim()
{
if ( voice && ( state == STOPPED ) )
{
engine->DestroyVoice( voice );
voice = nullptr;
}
}
void GatherStatistics( AudioStatistics& stats ) const
{
++stats.allocatedInstances;
if ( voice )
{
++stats.allocatedVoices;
if ( mFlags & SoundEffectInstance_Use3D )
++stats.allocatedVoices3d;
if ( state == PLAYING )
++stats.playingInstances;
}
}
IXAudio2SourceVoice* voice;
SoundState state;
AudioEngine* engine;
private:
float mVolume;
float mPitch;
float mFreqRatio;
float mPan;
SOUND_EFFECT_INSTANCE_FLAGS mFlags;
IXAudio2Voice* mDirectVoice;
IXAudio2Voice* mReverbVoice;
X3DAUDIO_DSP_SETTINGS mDSPSettings;
};
}

View File

@@ -0,0 +1,611 @@
//--------------------------------------------------------------------------------------
// File: SoundEffect.cpp
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "WAVFileReader.h"
#include "SoundCommon.h"
#include <list>
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <apu.h>
#endif
using namespace DirectX;
//======================================================================================
// SoundEffect
//======================================================================================
// Internal object implementation class.
class SoundEffect::Impl : public IVoiceNotify
{
public:
explicit Impl( _In_ AudioEngine* engine ) :
mWaveFormat( nullptr ),
mStartAudio( nullptr ),
mAudioBytes( 0 ),
mLoopStart( 0 ),
mLoopLength( 0 ),
mEngine( engine ),
mOneShots( 0 )
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
, mSeekCount( 0 )
, mSeekTable( nullptr )
#endif
#if defined(_XBOX_ONE) && defined(_TITLE)
, mXMAMemory( nullptr )
#endif
{
assert( mEngine != 0 );
mEngine->RegisterNotify( this, false );
}
virtual ~Impl()
{
if ( !mInstances.empty() )
{
DebugTrace( "WARNING: Destroying SoundEffect with %Iu outstanding SoundEffectInstances\n", mInstances.size() );
for( auto it = mInstances.begin(); it != mInstances.end(); ++it )
{
assert( *it != 0 );
(*it)->OnDestroyParent();
}
mInstances.clear();
}
if ( mOneShots > 0 )
{
DebugTrace( "WARNING: Destroying SoundEffect with %u outstanding one shot effects\n", mOneShots );
}
if ( mEngine )
{
mEngine->UnregisterNotify( this, true, false );
mEngine = nullptr;
}
#if defined(_XBOX_ONE) && defined(_TITLE)
if ( mXMAMemory )
{
ApuFree( mXMAMemory );
mXMAMemory = nullptr;
}
#endif
}
HRESULT Initialize( _In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
_In_reads_opt_(seekCount) const uint32_t* seekTable, size_t seekCount,
#endif
uint32_t loopStart, uint32_t loopLength );
void Play( float volume, float pitch, float pan );
// IVoiceNotify
virtual void __cdecl OnBufferEnd() override
{
InterlockedDecrement( &mOneShots );
}
virtual void __cdecl OnCriticalError() override
{
mOneShots = 0;
}
virtual void __cdecl OnReset() override
{
// No action required
}
virtual void __cdecl OnUpdate() override
{
// We do not register for update notification
assert(false);
}
virtual void __cdecl OnDestroyEngine() override
{
mEngine = nullptr;
mOneShots = 0;
}
virtual void __cdecl OnTrim() override
{
// No action required
}
virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const override
{
stats.playingOneShots += mOneShots;
stats.audioBytes += mAudioBytes;
#if defined(_XBOX_ONE) && defined(_TITLE)
if ( mXMAMemory )
stats.xmaAudioBytes += mAudioBytes;
#endif
}
const WAVEFORMATEX* mWaveFormat;
const uint8_t* mStartAudio;
uint32_t mAudioBytes;
uint32_t mLoopStart;
uint32_t mLoopLength;
AudioEngine* mEngine;
std::list<SoundEffectInstance*> mInstances;
uint32_t mOneShots;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
uint32_t mSeekCount;
const uint32_t* mSeekTable;
#endif
private:
std::unique_ptr<uint8_t[]> mWavData;
#if defined(_XBOX_ONE) && defined(_TITLE)
void* mXMAMemory;
#endif
};
_Use_decl_annotations_
HRESULT SoundEffect::Impl::Initialize( AudioEngine* engine, std::unique_ptr<uint8_t[]>& wavData,
const WAVEFORMATEX* wfx, const uint8_t* startAudio, size_t audioBytes,
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
const uint32_t* seekTable, size_t seekCount,
#endif
uint32_t loopStart, uint32_t loopLength )
{
if ( !engine || !IsValid( wfx ) || !startAudio || !audioBytes || !wavData )
return E_INVALIDARG;
if ( audioBytes > UINT32_MAX )
return E_INVALIDARG;
switch( GetFormatTag( wfx ) )
{
case WAVE_FORMAT_PCM:
case WAVE_FORMAT_IEEE_FLOAT:
case WAVE_FORMAT_ADPCM:
// Take ownership of the buffer
mWavData.reset( wavData.release() );
// WARNING: We assume the wfx and startAudio parameters are pointers into the wavData memory buffer
mWaveFormat = wfx;
mStartAudio = startAudio;
break;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
if ( !seekCount || !seekTable )
{
DebugTrace( "ERROR: SoundEffect format xWMA requires seek table\n" );
return E_FAIL;
}
if ( seekCount > UINT32_MAX )
return E_INVALIDARG;
// Take ownership of the buffer
mWavData.reset( wavData.release() );
// WARNING: We assume the wfx, startAudio, and mSeekTable parameters are pointers into the wavData memory buffer
mWaveFormat = wfx;
mStartAudio = startAudio;
mSeekCount = static_cast<uint32_t>( seekCount );
mSeekTable = seekTable;
break;
#endif // _XBOX_ONE || _WIN32_WINNT < _WIN32_WINNT_WIN8 || _WIN32_WINNT >= _WIN32_WINNT_WIN10
#if defined(_XBOX_ONE) && defined(_TITLE)
case WAVE_FORMAT_XMA2:
if ( !seekCount || !seekTable )
{
DebugTrace( "ERROR: SoundEffect format XMA2 requires seek table\n" );
return E_FAIL;
}
if ( seekCount > UINT32_MAX )
return E_INVALIDARG;
{
HRESULT hr = ApuAlloc( &mXMAMemory, nullptr,
static_cast<UINT32>( audioBytes ), SHAPE_XMA_INPUT_BUFFER_ALIGNMENT );
if ( FAILED(hr) )
{
DebugTrace( "ERROR: ApuAlloc failed. Did you allocate a large enough heap with ApuCreateHeap for all your XMA wave data?\n" );
return hr;
}
}
memcpy( mXMAMemory, startAudio, audioBytes );
mStartAudio = reinterpret_cast<const uint8_t*>( mXMAMemory );
mWavData.reset( new uint8_t[ sizeof(XMA2WAVEFORMATEX) + ( seekCount * sizeof(uint32_t) ) ] );
memcpy( mWavData.get(), wfx, sizeof(XMA2WAVEFORMATEX) );
mWaveFormat = reinterpret_cast<WAVEFORMATEX*>( mWavData.get() );
// XMA seek table is Big-Endian
{
auto dest = reinterpret_cast<uint32_t*>( mWavData.get() + sizeof(XMA2WAVEFORMATEX) );
for( size_t k = 0; k < seekCount; ++k )
{
dest[ k ] = _byteswap_ulong( seekTable[ k ]) ;
}
}
mSeekCount = static_cast<uint32_t>( seekCount );
mSeekTable = reinterpret_cast<const uint32_t*>( mWavData.get() + sizeof(XMA2WAVEFORMATEX) );
wavData.reset();
break;
#endif // _XBOX_ONE && _TITLE
default:
{
DebugTrace( "ERROR: SoundEffect encountered an unsupported format tag (%u)\n", wfx->wFormatTag );
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
}
mAudioBytes = static_cast<uint32_t>( audioBytes );
mLoopStart = loopStart;
mLoopLength = loopLength;
return S_OK;
}
void SoundEffect::Impl::Play( float volume, float pitch, float pan )
{
assert( volume >= -XAUDIO2_MAX_VOLUME_LEVEL && volume <= XAUDIO2_MAX_VOLUME_LEVEL );
assert( pitch >= -1.f && pitch <= 1.f );
assert( pan >= -1.f && pan <= 1.f );
IXAudio2SourceVoice* voice = nullptr;
mEngine->AllocateVoice( mWaveFormat, SoundEffectInstance_Default, true, &voice );
if ( !voice )
return;
if ( volume != 1.f )
{
HRESULT hr = voice->SetVolume( volume );
ThrowIfFailed( hr );
}
if ( pitch != 0.f )
{
float fr = XAudio2SemitonesToFrequencyRatio( pitch * 12.f );
HRESULT hr = voice->SetFrequencyRatio( fr );
ThrowIfFailed( hr );
}
if ( pan != 0.f )
{
float matrix[16];
if (ComputePan(pan, mWaveFormat->nChannels, matrix))
{
HRESULT hr = voice->SetOutputMatrix(nullptr, mWaveFormat->nChannels, mEngine->GetOutputChannels(), matrix);
ThrowIfFailed( hr );
}
}
HRESULT hr = voice->Start( 0 );
ThrowIfFailed( hr );
XAUDIO2_BUFFER buffer = {};
buffer.AudioBytes = mAudioBytes;
buffer.pAudioData = mStartAudio;
buffer.Flags = XAUDIO2_END_OF_STREAM;
buffer.pContext = this;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
uint32_t tag = GetFormatTag( mWaveFormat );
if ( tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3 )
{
XAUDIO2_BUFFER_WMA wmaBuffer = {};
wmaBuffer.PacketCount = mSeekCount;
wmaBuffer.pDecodedPacketCumulativeBytes = mSeekTable;
hr = voice->SubmitSourceBuffer( &buffer, &wmaBuffer );
}
else
#endif
{
hr = voice->SubmitSourceBuffer( &buffer, nullptr );
}
if ( FAILED(hr) )
{
DebugTrace( "ERROR: SoundEffect failed (%08X) when submitting buffer:\n", hr );
DebugTrace( "\tFormat Tag %u, %u channels, %u-bit, %u Hz, %u bytes\n", mWaveFormat->wFormatTag,
mWaveFormat->nChannels, mWaveFormat->wBitsPerSample, mWaveFormat->nSamplesPerSec, mAudioBytes );
throw std::exception( "SubmitSourceBuffer" );
}
InterlockedIncrement( &mOneShots );
}
//--------------------------------------------------------------------------------------
// SoundEffect
//--------------------------------------------------------------------------------------
// Public constructors.
_Use_decl_annotations_
SoundEffect::SoundEffect( AudioEngine* engine, const wchar_t* waveFileName )
: pImpl(new Impl(engine) )
{
WAVData wavInfo;
std::unique_ptr<uint8_t[]> wavData;
HRESULT hr = LoadWAVAudioFromFileEx( waveFileName, wavData, wavInfo );
if ( FAILED(hr) )
{
DebugTrace( "ERROR: SoundEffect failed (%08X) to load from .wav file \"%ls\"\n", hr, waveFileName );
throw std::exception( "SoundEffect" );
}
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
hr = pImpl->Initialize( engine, wavData, wavInfo.wfx, wavInfo.startAudio, wavInfo.audioBytes,
wavInfo.seek, wavInfo.seekCount,
wavInfo.loopStart, wavInfo.loopLength );
#else
hr = pImpl->Initialize( engine, wavData, wavInfo.wfx, wavInfo.startAudio, wavInfo.audioBytes,
wavInfo.loopStart, wavInfo.loopLength );
#endif
if ( FAILED(hr) )
{
DebugTrace( "ERROR: SoundEffect failed (%08X) to intialize from .wav file \"%ls\"\n", hr, waveFileName );
throw std::exception( "SoundEffect" );
}
}
_Use_decl_annotations_
SoundEffect::SoundEffect( AudioEngine* engine, std::unique_ptr<uint8_t[]>& wavData,
const WAVEFORMATEX* wfx, const uint8_t* startAudio, size_t audioBytes )
: pImpl(new Impl(engine) )
{
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
HRESULT hr = pImpl->Initialize( engine, wavData, wfx, startAudio, audioBytes, nullptr, 0, 0, 0 );
#else
HRESULT hr = pImpl->Initialize( engine, wavData, wfx, startAudio, audioBytes, 0, 0 );
#endif
if ( FAILED(hr) )
{
DebugTrace( "ERROR: SoundEffect failed (%08X) to intialize\n", hr );
throw std::exception( "SoundEffect" );
}
}
_Use_decl_annotations_
SoundEffect::SoundEffect( AudioEngine* engine, std::unique_ptr<uint8_t[]>& wavData,
const WAVEFORMATEX* wfx, const uint8_t* startAudio, size_t audioBytes,
uint32_t loopStart, uint32_t loopLength )
: pImpl(new Impl(engine) )
{
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
HRESULT hr = pImpl->Initialize( engine, wavData, wfx, startAudio, audioBytes, nullptr, 0, loopStart, loopLength );
#else
HRESULT hr = pImpl->Initialize( engine, wavData, wfx, startAudio, audioBytes, loopStart, loopLength );
#endif
if ( FAILED(hr) )
{
DebugTrace( "ERROR: SoundEffect failed (%08X) to intialize\n", hr );
throw std::exception( "SoundEffect" );
}
}
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
_Use_decl_annotations_
SoundEffect::SoundEffect( AudioEngine* engine, std::unique_ptr<uint8_t[]>& wavData,
const WAVEFORMATEX* wfx, const uint8_t* startAudio, size_t audioBytes,
const uint32_t* seekTable, size_t seekCount )
{
HRESULT hr = pImpl->Initialize( engine, wavData, wfx, startAudio, audioBytes, seekTable, seekCount, 0, 0 );
if ( FAILED(hr) )
{
DebugTrace( "ERROR: SoundEffect failed (%08X) to intialize\n", hr );
throw std::exception( "SoundEffect" );
}
}
#endif
// Move constructor.
SoundEffect::SoundEffect(SoundEffect&& moveFrom)
: pImpl(std::move(moveFrom.pImpl))
{
}
// Move assignment.
SoundEffect& SoundEffect::operator= (SoundEffect&& moveFrom)
{
pImpl = std::move(moveFrom.pImpl);
return *this;
}
// Public destructor.
SoundEffect::~SoundEffect()
{
}
// Public methods.
void SoundEffect::Play()
{
pImpl->Play( 1.f, 0.f, 0.f );
}
void SoundEffect::Play( float volume, float pitch, float pan )
{
pImpl->Play( volume, pitch, pan );
}
std::unique_ptr<SoundEffectInstance> SoundEffect::CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS flags )
{
auto effect = new SoundEffectInstance( pImpl->mEngine, this, flags );
assert( effect != 0 );
pImpl->mInstances.emplace_back( effect );
return std::unique_ptr<SoundEffectInstance>( effect );
}
void SoundEffect::UnregisterInstance( _In_ SoundEffectInstance* instance )
{
auto it = std::find( pImpl->mInstances.begin(), pImpl->mInstances.end(), instance );
if ( it == pImpl->mInstances.end() )
return;
pImpl->mInstances.erase( it );
}
// Public accessors.
bool SoundEffect::IsInUse() const
{
return ( pImpl->mOneShots > 0 ) || !pImpl->mInstances.empty();
}
size_t SoundEffect::GetSampleSizeInBytes() const
{
return pImpl->mAudioBytes;
}
size_t SoundEffect::GetSampleDuration() const
{
if ( !pImpl->mWaveFormat || !pImpl->mWaveFormat->nChannels )
return 0;
switch( GetFormatTag( pImpl->mWaveFormat ) )
{
case WAVE_FORMAT_ADPCM:
{
auto adpcmFmt = reinterpret_cast<const ADPCMWAVEFORMAT*>( pImpl->mWaveFormat );
uint64_t duration = uint64_t( pImpl->mAudioBytes / adpcmFmt->wfx.nBlockAlign ) * adpcmFmt->wSamplesPerBlock;
int partial = pImpl->mAudioBytes % adpcmFmt->wfx.nBlockAlign;
if ( partial )
{
if ( partial >= ( 7 * adpcmFmt->wfx.nChannels ) )
duration += ( partial * 2 / adpcmFmt->wfx.nChannels - 12 );
}
return static_cast<size_t>( duration );
}
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
if ( pImpl->mSeekTable && pImpl->mSeekCount > 0 )
{
return pImpl->mSeekTable[ pImpl->mSeekCount - 1 ] / uint32_t( 2 * pImpl->mWaveFormat->nChannels );
}
break;
#endif
#if defined(_XBOX_ONE) && defined(_TITLE)
case WAVE_FORMAT_XMA2:
return reinterpret_cast<const XMA2WAVEFORMATEX*>( pImpl->mWaveFormat )->SamplesEncoded;
#endif
default:
if ( pImpl->mWaveFormat->wBitsPerSample > 0 )
{
return static_cast<size_t>( ( uint64_t( pImpl->mAudioBytes ) * 8 )
/ uint64_t( pImpl->mWaveFormat->wBitsPerSample * pImpl->mWaveFormat->nChannels ) );
}
}
return 0;
}
size_t SoundEffect::GetSampleDurationMS() const
{
if ( !pImpl->mWaveFormat || !pImpl->mWaveFormat->nSamplesPerSec )
return 0;
uint64_t samples = GetSampleDuration();
return static_cast<size_t>( ( samples * 1000 ) / pImpl->mWaveFormat->nSamplesPerSec );
}
const WAVEFORMATEX* SoundEffect::GetFormat() const
{
return pImpl->mWaveFormat;
}
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
bool SoundEffect::FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const
{
memset( &buffer, 0, sizeof(buffer) );
memset( &wmaBuffer, 0, sizeof(wmaBuffer) );
buffer.AudioBytes = pImpl->mAudioBytes;
buffer.pAudioData = pImpl->mStartAudio;
buffer.LoopBegin = pImpl->mLoopStart;
buffer.LoopLength = pImpl->mLoopLength;
uint32_t tag = GetFormatTag( pImpl->mWaveFormat );
if ( tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3 )
{
wmaBuffer.PacketCount = pImpl->mSeekCount;
wmaBuffer.pDecodedPacketCumulativeBytes = pImpl->mSeekTable;
return true;
}
return false;
}
#else
void SoundEffect::FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer ) const
{
memset( &buffer, 0, sizeof(buffer) );
buffer.AudioBytes = pImpl->mAudioBytes;
buffer.pAudioData = pImpl->mStartAudio;
buffer.LoopBegin = pImpl->mLoopStart;
buffer.LoopLength = pImpl->mLoopLength;
}
#endif

View File

@@ -0,0 +1,334 @@
//--------------------------------------------------------------------------------------
// File: SoundEffectInstance.cpp
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "SoundCommon.h"
using namespace DirectX;
//======================================================================================
// SoundEffectInstance
//======================================================================================
// Internal object implementation class.
class SoundEffectInstance::Impl : public IVoiceNotify
{
public:
Impl( _In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags ) :
mBase(),
mEffect( effect ),
mWaveBank( nullptr ),
mIndex( 0 ),
mLooped( false )
{
assert( engine != 0 );
engine->RegisterNotify( this, false );
assert( mEffect != 0 );
mBase.Initialize( engine, effect->GetFormat(), flags );
}
Impl( _In_ AudioEngine* engine, _In_ WaveBank* waveBank, uint32_t index, SOUND_EFFECT_INSTANCE_FLAGS flags ) :
mBase(),
mEffect( nullptr ),
mWaveBank( waveBank ),
mIndex( index ),
mLooped( false )
{
assert( engine != 0 );
engine->RegisterNotify( this, false );
char buff[64];
auto wfx = reinterpret_cast<WAVEFORMATEX*>( buff );
assert( mWaveBank != 0 );
mBase.Initialize( engine, mWaveBank->GetFormat( index, wfx, 64 ), flags );
}
virtual ~Impl()
{
mBase.DestroyVoice();
if ( mBase.engine )
{
mBase.engine->UnregisterNotify( this, false, false );
mBase.engine = nullptr;
}
}
void Play( bool loop );
// IVoiceNotify
virtual void __cdecl OnBufferEnd() override
{
// We don't register for this notification for SoundEffectInstances, so this should not be invoked
assert( false );
}
virtual void __cdecl OnCriticalError() override
{
mBase.OnCriticalError();
}
virtual void __cdecl OnReset() override
{
mBase.OnReset();
}
virtual void __cdecl OnUpdate() override
{
// We do not register for update notification
assert(false);
}
virtual void __cdecl OnDestroyEngine() override
{
mBase.OnDestroy();
}
virtual void __cdecl OnTrim() override
{
mBase.OnTrim();
}
virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const override
{
mBase.GatherStatistics(stats);
}
SoundEffectInstanceBase mBase;
SoundEffect* mEffect;
WaveBank* mWaveBank;
uint32_t mIndex;
bool mLooped;
};
void SoundEffectInstance::Impl::Play( bool loop )
{
if ( !mBase.voice )
{
if ( mWaveBank )
{
char buff[64];
auto wfx = reinterpret_cast<WAVEFORMATEX*>( buff );
mBase.AllocateVoice( mWaveBank->GetFormat( mIndex, wfx, 64) );
}
else
{
assert( mEffect != 0 );
mBase.AllocateVoice( mEffect->GetFormat() );
}
}
if ( !mBase.Play() )
return;
// Submit audio data for STOPPED -> PLAYING state transition
XAUDIO2_BUFFER buffer;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
bool iswma = false;
XAUDIO2_BUFFER_WMA wmaBuffer;
if ( mWaveBank )
{
iswma = mWaveBank->FillSubmitBuffer( mIndex, buffer, wmaBuffer );
}
else
{
assert( mEffect != 0 );
iswma = mEffect->FillSubmitBuffer( buffer, wmaBuffer );
}
#else
if ( mWaveBank )
{
mWaveBank->FillSubmitBuffer( mIndex, buffer );
}
else
{
assert( mEffect != 0 );
mEffect->FillSubmitBuffer( buffer );
}
#endif
buffer.Flags = XAUDIO2_END_OF_STREAM;
if ( loop )
{
mLooped = true;
buffer.LoopCount = XAUDIO2_LOOP_INFINITE;
}
else
{
mLooped = false;
buffer.LoopCount = buffer.LoopBegin = buffer.LoopLength = 0;
}
buffer.pContext = nullptr;
HRESULT hr;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
if ( iswma )
{
hr = mBase.voice->SubmitSourceBuffer( &buffer, &wmaBuffer );
}
else
#endif
{
hr = mBase.voice->SubmitSourceBuffer( &buffer, nullptr );
}
if ( FAILED(hr) )
{
#ifdef _DEBUG
DebugTrace( "ERROR: SoundEffectInstance failed (%08X) when submitting buffer:\n", hr );
char buff[64];
auto wfx = ( mWaveBank ) ? mWaveBank->GetFormat( mIndex, reinterpret_cast<WAVEFORMATEX*>( buff ), 64 )
: mEffect->GetFormat();
size_t length = ( mWaveBank ) ? mWaveBank->GetSampleSizeInBytes( mIndex ) : mEffect->GetSampleSizeInBytes();
DebugTrace( "\tFormat Tag %u, %u channels, %u-bit, %u Hz, %Iu bytes\n", wfx->wFormatTag,
wfx->nChannels, wfx->wBitsPerSample, wfx->nSamplesPerSec, length );
#endif
mBase.Stop( true, mLooped );
throw std::exception( "SubmitSourceBuffer" );
}
}
//--------------------------------------------------------------------------------------
// SoundEffectInstance
//--------------------------------------------------------------------------------------
// Private constructors
_Use_decl_annotations_
SoundEffectInstance::SoundEffectInstance( AudioEngine* engine, SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags ) :
pImpl( new Impl( engine, effect, flags ) )
{
}
_Use_decl_annotations_
SoundEffectInstance::SoundEffectInstance( AudioEngine* engine, WaveBank* waveBank, int index, SOUND_EFFECT_INSTANCE_FLAGS flags ) :
pImpl( new Impl( engine, waveBank, index, flags ) )
{
}
// Move constructor.
SoundEffectInstance::SoundEffectInstance(SoundEffectInstance&& moveFrom)
: pImpl(std::move(moveFrom.pImpl))
{
}
// Move assignment.
SoundEffectInstance& SoundEffectInstance::operator= (SoundEffectInstance&& moveFrom)
{
pImpl = std::move(moveFrom.pImpl);
return *this;
}
// Public destructor.
SoundEffectInstance::~SoundEffectInstance()
{
if( pImpl )
{
if ( pImpl->mWaveBank )
{
pImpl->mWaveBank->UnregisterInstance( this );
pImpl->mWaveBank = nullptr;
}
if ( pImpl->mEffect )
{
pImpl->mEffect->UnregisterInstance( this );
pImpl->mEffect = nullptr;
}
}
}
// Public methods.
void SoundEffectInstance::Play( bool loop )
{
pImpl->Play( loop );
}
void SoundEffectInstance::Stop( bool immediate )
{
pImpl->mBase.Stop( immediate, pImpl->mLooped );
}
void SoundEffectInstance::Pause()
{
pImpl->mBase.Pause();
}
void SoundEffectInstance::Resume()
{
pImpl->mBase.Resume();
}
void SoundEffectInstance::SetVolume( float volume )
{
pImpl->mBase.SetVolume( volume );
}
void SoundEffectInstance::SetPitch( float pitch )
{
pImpl->mBase.SetPitch( pitch );
}
void SoundEffectInstance::SetPan( float pan )
{
pImpl->mBase.SetPan( pan );
}
void SoundEffectInstance::Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords )
{
pImpl->mBase.Apply3D( listener, emitter, rhcoords );
}
// Public accessors.
bool SoundEffectInstance::IsLooped() const
{
return pImpl->mLooped;
}
SoundState SoundEffectInstance::GetState()
{
return pImpl->mBase.GetState( true );
}
// Notifications.
void SoundEffectInstance::OnDestroyParent()
{
pImpl->mBase.OnDestroy();
pImpl->mWaveBank = nullptr;
pImpl->mEffect = nullptr;
}

View File

@@ -0,0 +1,681 @@
//--------------------------------------------------------------------------------------
// File: WAVFileReader.cpp
//
// Functions for loading WAV audio files
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//-------------------------------------------------------------------------------------
#include "pch.h"
#include "PlatformHelpers.h"
#include "WAVFileReader.h"
using namespace DirectX;
namespace
{
//--------------------------------------------------------------------------------------
// .WAV files
//--------------------------------------------------------------------------------------
const uint32_t FOURCC_RIFF_TAG = 'FFIR';
const uint32_t FOURCC_FORMAT_TAG = ' tmf';
const uint32_t FOURCC_DATA_TAG = 'atad';
const uint32_t FOURCC_WAVE_FILE_TAG = 'EVAW';
const uint32_t FOURCC_XWMA_FILE_TAG = 'AMWX';
const uint32_t FOURCC_DLS_SAMPLE = 'pmsw';
const uint32_t FOURCC_MIDI_SAMPLE = 'lpms';
const uint32_t FOURCC_XWMA_DPDS = 'sdpd';
const uint32_t FOURCC_XMA_SEEK = 'kees';
#pragma pack(push,1)
struct RIFFChunk
{
uint32_t tag;
uint32_t size;
};
struct RIFFChunkHeader
{
uint32_t tag;
uint32_t size;
uint32_t riff;
};
struct DLSLoop
{
static const uint32_t LOOP_TYPE_FORWARD = 0x00000000;
static const uint32_t LOOP_TYPE_RELEASE = 0x00000001;
uint32_t size;
uint32_t loopType;
uint32_t loopStart;
uint32_t loopLength;
};
struct RIFFDLSSample
{
static const uint32_t OPTIONS_NOTRUNCATION = 0x00000001;
static const uint32_t OPTIONS_NOCOMPRESSION = 0x00000002;
uint32_t size;
uint16_t unityNote;
int16_t fineTune;
int32_t gain;
uint32_t options;
uint32_t loopCount;
};
struct MIDILoop
{
static const uint32_t LOOP_TYPE_FORWARD = 0x00000000;
static const uint32_t LOOP_TYPE_ALTERNATING = 0x00000001;
static const uint32_t LOOP_TYPE_BACKWARD = 0x00000002;
uint32_t cuePointId;
uint32_t type;
uint32_t start;
uint32_t end;
uint32_t fraction;
uint32_t playCount;
};
struct RIFFMIDISample
{
uint32_t manufacturerId;
uint32_t productId;
uint32_t samplePeriod;
uint32_t unityNode;
uint32_t pitchFraction;
uint32_t SMPTEFormat;
uint32_t SMPTEOffset;
uint32_t loopCount;
uint32_t samplerData;
};
#pragma pack(pop)
static_assert( sizeof(RIFFChunk) == 8, "structure size mismatch");
static_assert( sizeof(RIFFChunkHeader) == 12, "structure size mismatch");
static_assert( sizeof(DLSLoop) == 16, "structure size mismatch");
static_assert( sizeof(RIFFDLSSample) == 20, "structure size mismatch");
static_assert( sizeof(MIDILoop) == 24, "structure size mismatch");
static_assert( sizeof(RIFFMIDISample) == 36, "structure size mismatch");
};
//--------------------------------------------------------------------------------------
static const RIFFChunk* FindChunk( _In_reads_bytes_(sizeBytes) const uint8_t* data, _In_ size_t sizeBytes, _In_ uint32_t tag )
{
if ( !data )
return nullptr;
const uint8_t* ptr = data;
const uint8_t* end = data + sizeBytes;
while ( end > ( ptr + sizeof(RIFFChunk) ) )
{
auto header = reinterpret_cast<const RIFFChunk*>( ptr );
if ( header->tag == tag )
return header;
ptrdiff_t offset = header->size + sizeof(RIFFChunk);
ptr += offset;
}
return nullptr;
}
//--------------------------------------------------------------------------------------
static HRESULT WaveFindFormatAndData( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize,
_Outptr_ const WAVEFORMATEX** pwfx, _Outptr_ const uint8_t** pdata, _Out_ uint32_t* dataSize,
_Out_ bool& dpds, _Out_ bool& seek )
{
if ( !wavData || !pwfx )
return E_POINTER;
dpds = seek = false;
if (wavDataSize < (sizeof(RIFFChunk)*2 + sizeof(uint32_t) + sizeof(WAVEFORMAT) ) )
{
return E_FAIL;
}
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk( wavData, wavDataSize, FOURCC_RIFF_TAG );
if ( !riffChunk || riffChunk->size < 4 )
{
return E_FAIL;
}
auto riffHeader = reinterpret_cast<const RIFFChunkHeader*>( riffChunk );
if ( riffHeader->riff != FOURCC_WAVE_FILE_TAG && riffHeader->riff != FOURCC_XWMA_FILE_TAG )
{
return E_FAIL;
}
// Locate 'fmt '
auto ptr = reinterpret_cast<const uint8_t*>( riffHeader ) + sizeof(RIFFChunkHeader);
if ( ( ptr + sizeof(RIFFChunk) ) > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
auto fmtChunk = FindChunk( ptr, riffHeader->size, FOURCC_FORMAT_TAG );
if ( !fmtChunk || fmtChunk->size < sizeof(PCMWAVEFORMAT) )
{
return E_FAIL;
}
ptr = reinterpret_cast<const uint8_t*>( fmtChunk ) + sizeof( RIFFChunk );
if ( ptr + fmtChunk->size > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
auto wf = reinterpret_cast<const WAVEFORMAT*>( ptr );
// Validate WAVEFORMAT (focused on chunk size and format tag, not other data that XAUDIO2 will validate)
switch( wf->wFormatTag )
{
case WAVE_FORMAT_PCM:
case WAVE_FORMAT_IEEE_FLOAT:
// Can be a PCMWAVEFORMAT (8 bytes) or WAVEFORMATEX (10 bytes)
// We validiated chunk as at least sizeof(PCMWAVEFORMAT) above
break;
default:
{
if ( fmtChunk->size < sizeof(WAVEFORMATEX) )
{
return E_FAIL;
}
auto wfx = reinterpret_cast<const WAVEFORMATEX*>( ptr );
if ( fmtChunk->size < ( sizeof(WAVEFORMATEX) + wfx->cbSize ) )
{
return E_FAIL;
}
switch( wfx->wFormatTag )
{
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
dpds = true;
break;
case 0x166 /*WAVE_FORMAT_XMA2*/: // XMA2 is supported by Xbox One
if ( ( fmtChunk->size < 52 /*sizeof(XMA2WAVEFORMATEX)*/ ) || ( wfx->cbSize < 34 /*( sizeof(XMA2WAVEFORMATEX) - sizeof(WAVEFORMATEX) )*/ ) )
{
return E_FAIL;
}
seek = true;
break;
case WAVE_FORMAT_ADPCM:
if ( ( fmtChunk->size < ( sizeof(WAVEFORMATEX) + 32 ) ) || ( wfx->cbSize < 32 /*MSADPCM_FORMAT_EXTRA_BYTES*/ ) )
{
return E_FAIL;
}
break;
case WAVE_FORMAT_EXTENSIBLE:
if ( ( fmtChunk->size < sizeof(WAVEFORMATEXTENSIBLE) ) || ( wfx->cbSize < ( sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) ) ) )
{
return E_FAIL;
}
else
{
static const GUID s_wfexBase = {0x00000000, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71};
auto wfex = reinterpret_cast<const WAVEFORMATEXTENSIBLE*>( ptr );
if ( memcmp( reinterpret_cast<const BYTE*>(&wfex->SubFormat) + sizeof(DWORD),
reinterpret_cast<const BYTE*>(&s_wfexBase) + sizeof(DWORD), sizeof(GUID) - sizeof(DWORD) ) != 0 )
{
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
switch( wfex->SubFormat.Data1 )
{
case WAVE_FORMAT_PCM:
case WAVE_FORMAT_IEEE_FLOAT:
break;
// MS-ADPCM and XMA2 are not supported as WAVEFORMATEXTENSIBLE
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
dpds = true;
break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
}
break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
}
}
// Locate 'data'
ptr = reinterpret_cast<const uint8_t*>( riffHeader ) + sizeof(RIFFChunkHeader);
if ( ( ptr + sizeof(RIFFChunk) ) > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
auto dataChunk = FindChunk( ptr, riffChunk->size, FOURCC_DATA_TAG );
if ( !dataChunk || !dataChunk->size )
{
return HRESULT_FROM_WIN32( ERROR_INVALID_DATA );
}
ptr = reinterpret_cast<const uint8_t*>( dataChunk ) + sizeof( RIFFChunk );
if ( ptr + dataChunk->size > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
*pwfx = reinterpret_cast<const WAVEFORMATEX*>( wf );
*pdata = ptr;
*dataSize = dataChunk->size;
return S_OK;
}
//--------------------------------------------------------------------------------------
static HRESULT WaveFindLoopInfo( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize,
_Out_ uint32_t* pLoopStart, _Out_ uint32_t* pLoopLength )
{
if ( !wavData || !pLoopStart || !pLoopLength )
return E_POINTER;
if (wavDataSize < ( sizeof(RIFFChunk) + sizeof(uint32_t) ) )
{
return E_FAIL;
}
*pLoopStart = 0;
*pLoopLength = 0;
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk( wavData, wavDataSize, FOURCC_RIFF_TAG );
if ( !riffChunk || riffChunk->size < 4 )
{
return E_FAIL;
}
auto riffHeader = reinterpret_cast<const RIFFChunkHeader*>( riffChunk );
if ( riffHeader->riff == FOURCC_XWMA_FILE_TAG )
{
// xWMA files do not contain loop information
return S_OK;
}
if ( riffHeader->riff != FOURCC_WAVE_FILE_TAG )
{
return E_FAIL;
}
// Locate 'wsmp' (DLS Chunk)
auto ptr = reinterpret_cast<const uint8_t*>( riffHeader ) + sizeof(RIFFChunkHeader);
if ( ( ptr + sizeof(RIFFChunk) ) > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
auto dlsChunk = FindChunk( ptr, riffChunk->size, FOURCC_DLS_SAMPLE );
if ( dlsChunk )
{
ptr = reinterpret_cast<const uint8_t*>( dlsChunk ) + sizeof( RIFFChunk );
if ( ptr + dlsChunk->size > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
if ( dlsChunk->size >= sizeof(RIFFDLSSample) )
{
auto dlsSample = reinterpret_cast<const RIFFDLSSample*>( ptr );
if ( dlsChunk->size >= ( dlsSample->size + dlsSample->loopCount * sizeof(DLSLoop) ) )
{
auto loops = reinterpret_cast<const DLSLoop*>( ptr + dlsSample->size );
for( uint32_t j = 0; j < dlsSample->loopCount; ++j )
{
if ( ( loops[j].loopType == DLSLoop::LOOP_TYPE_FORWARD || loops[j].loopType == DLSLoop::LOOP_TYPE_RELEASE ) )
{
// Return 'forward' loop
*pLoopStart = loops[j].loopStart;
*pLoopLength = loops[j].loopLength;
return S_OK;
}
}
}
}
}
// Locate 'smpl' (Sample Chunk)
auto midiChunk = FindChunk( ptr, riffChunk->size, FOURCC_MIDI_SAMPLE );
if ( midiChunk )
{
ptr = reinterpret_cast<const uint8_t*>( midiChunk ) + sizeof( RIFFChunk );
if ( ptr + midiChunk->size > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
if ( midiChunk->size >= sizeof(RIFFMIDISample) )
{
auto midiSample = reinterpret_cast<const RIFFMIDISample*>( ptr );
if ( midiChunk->size >= ( sizeof(RIFFMIDISample) + midiSample->loopCount * sizeof(MIDILoop) ) )
{
auto loops = reinterpret_cast<const MIDILoop*>( ptr + sizeof(RIFFMIDISample) );
for( uint32_t j = 0; j < midiSample->loopCount; ++j )
{
if ( loops[j].type == MIDILoop::LOOP_TYPE_FORWARD )
{
// Return 'forward' loop
*pLoopStart = loops[j].start;
*pLoopLength = loops[j].end + loops[j].start + 1;
return S_OK;
}
}
}
}
}
return S_OK;
}
//--------------------------------------------------------------------------------------
static HRESULT WaveFindTable( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _In_ uint32_t tag,
_Outptr_result_maybenull_ const uint32_t** pData, _Out_ uint32_t* dataCount )
{
if ( !wavData || !pData || !dataCount )
return E_POINTER;
if (wavDataSize < ( sizeof(RIFFChunk) + sizeof(uint32_t) ) )
{
return E_FAIL;
}
*pData = nullptr;
*dataCount = 0;
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk( wavData, wavDataSize, FOURCC_RIFF_TAG );
if ( !riffChunk || riffChunk->size < 4 )
{
return E_FAIL;
}
auto riffHeader = reinterpret_cast<const RIFFChunkHeader*>( riffChunk );
if ( riffHeader->riff != FOURCC_WAVE_FILE_TAG && riffHeader->riff != FOURCC_XWMA_FILE_TAG )
{
return E_FAIL;
}
// Locate tag
auto ptr = reinterpret_cast<const uint8_t*>( riffHeader ) + sizeof(RIFFChunkHeader);
if ( ( ptr + sizeof(RIFFChunk) ) > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
auto tableChunk = FindChunk( ptr, riffChunk->size, tag );
if ( tableChunk )
{
ptr = reinterpret_cast<const uint8_t*>( tableChunk ) + sizeof( RIFFChunk );
if ( ptr + tableChunk->size > wavEnd )
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
}
if ( ( tableChunk->size % sizeof(uint32_t) ) != 0 )
{
return E_FAIL;
}
*pData = reinterpret_cast<const uint32_t*>( ptr );
*dataCount = tableChunk->size / 4;
}
return S_OK;
}
//--------------------------------------------------------------------------------------
static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Out_ DWORD* bytesRead )
{
if ( !szFileName )
return E_INVALIDARG;
// open the file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile( safe_handle( CreateFile2( szFileName,
GENERIC_READ,
FILE_SHARE_READ,
OPEN_EXISTING,
nullptr ) ) );
#else
ScopedHandle hFile( safe_handle( CreateFileW( szFileName,
GENERIC_READ,
FILE_SHARE_READ,
nullptr,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
nullptr ) ) );
#endif
if ( !hFile )
{
return HRESULT_FROM_WIN32( GetLastError() );
}
// Get the file size
FILE_STANDARD_INFO fileInfo;
if ( !GetFileInformationByHandleEx( hFile.get(), FileStandardInfo, &fileInfo, sizeof(fileInfo) ) )
{
return HRESULT_FROM_WIN32( GetLastError() );
}
// File is too big for 32-bit allocation, so reject read
if (fileInfo.EndOfFile.HighPart > 0)
{
return E_FAIL;
}
// Need at least enough data to have a valid minimal WAV file
if (fileInfo.EndOfFile.LowPart < ( sizeof(RIFFChunk)*2 + sizeof(DWORD) + sizeof(WAVEFORMAT) ) )
{
return E_FAIL;
}
// create enough space for the file data
wavData.reset( new (std::nothrow) uint8_t[ fileInfo.EndOfFile.LowPart ] );
if (!wavData)
{
return E_OUTOFMEMORY;
}
// read the data in
if (!ReadFile( hFile.get(),
wavData.get(),
fileInfo.EndOfFile.LowPart,
bytesRead,
nullptr
))
{
return HRESULT_FROM_WIN32( GetLastError() );
}
return (*bytesRead < fileInfo.EndOfFile.LowPart) ? E_FAIL : S_OK;
}
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadWAVAudioInMemory( const uint8_t* wavData,
size_t wavDataSize,
const WAVEFORMATEX** wfx,
const uint8_t** startAudio,
uint32_t* audioBytes )
{
if ( !wavData || !wfx || !startAudio || !audioBytes )
return E_INVALIDARG;
*wfx = nullptr;
*startAudio = nullptr;
*audioBytes = 0;
// Need at least enough data to have a valid minimal WAV file
if (wavDataSize < (sizeof(RIFFChunk)*2 + sizeof(DWORD) + sizeof(WAVEFORMAT) ) )
{
return E_FAIL;
}
bool dpds, seek;
HRESULT hr = WaveFindFormatAndData( wavData, wavDataSize, wfx, startAudio, audioBytes, dpds, seek );
if ( FAILED(hr) )
return hr;
return (dpds || seek) ? E_FAIL : S_OK;
}
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadWAVAudioFromFile( const wchar_t* szFileName,
std::unique_ptr<uint8_t[]>& wavData,
const WAVEFORMATEX** wfx,
const uint8_t** startAudio,
uint32_t* audioBytes )
{
if ( !szFileName || !wfx || !startAudio || !audioBytes )
return E_INVALIDARG;
*wfx = nullptr;
*startAudio = nullptr;
*audioBytes = 0;
DWORD bytesRead = 0;
HRESULT hr = LoadAudioFromFile( szFileName, wavData, &bytesRead );
if ( FAILED(hr) )
{
return hr;
}
bool dpds, seek;
hr = WaveFindFormatAndData( wavData.get(), bytesRead, wfx, startAudio, audioBytes, dpds, seek );
if ( FAILED(hr) )
return hr;
return (dpds || seek) ? E_FAIL : S_OK;
}
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadWAVAudioInMemoryEx( const uint8_t* wavData, size_t wavDataSize, DirectX::WAVData& result )
{
if ( !wavData )
return E_INVALIDARG;
memset( &result, 0, sizeof(result) );
// Need at least enough data to have a valid minimal WAV file
if (wavDataSize < (sizeof(RIFFChunk)*2 + sizeof(DWORD) + sizeof(WAVEFORMAT) ) )
{
return E_FAIL;
}
bool dpds, seek;
HRESULT hr = WaveFindFormatAndData( wavData, wavDataSize, &result.wfx, &result.startAudio, &result.audioBytes, dpds, seek );
if ( FAILED(hr) )
return hr;
hr = WaveFindLoopInfo( wavData, wavDataSize, &result.loopStart, &result.loopLength );
if ( FAILED(hr) )
return hr;
if ( dpds )
{
hr = WaveFindTable( wavData, wavDataSize, FOURCC_XWMA_DPDS, &result.seek, &result.seekCount );
if ( FAILED(hr) )
return hr;
}
else if ( seek )
{
hr = WaveFindTable( wavData, wavDataSize, FOURCC_XMA_SEEK, &result.seek, &result.seekCount );
if ( FAILED(hr) )
return hr;
}
return S_OK;
}
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadWAVAudioFromFileEx( const wchar_t* szFileName, std::unique_ptr<uint8_t[]>& wavData, DirectX::WAVData& result )
{
if ( !szFileName )
return E_INVALIDARG;
memset( &result, 0, sizeof(result) );
DWORD bytesRead = 0;
HRESULT hr = LoadAudioFromFile( szFileName, wavData, &bytesRead );
if ( FAILED(hr) )
{
return hr;
}
bool dpds, seek;
hr = WaveFindFormatAndData( wavData.get(), bytesRead, &result.wfx, &result.startAudio, &result.audioBytes, dpds, seek );
if ( FAILED(hr) )
return hr;
hr = WaveFindLoopInfo( wavData.get(), bytesRead, &result.loopStart, &result.loopLength );
if ( FAILED(hr) )
return hr;
if ( dpds )
{
hr = WaveFindTable( wavData.get(), bytesRead, FOURCC_XWMA_DPDS, &result.seek, &result.seekCount );
if ( FAILED(hr) )
return hr;
}
else if ( seek )
{
hr = WaveFindTable( wavData.get(), bytesRead, FOURCC_XMA_SEEK, &result.seek, &result.seekCount );
if ( FAILED(hr) )
return hr;
}
return S_OK;
}

View File

@@ -0,0 +1,55 @@
//--------------------------------------------------------------------------------------
// File: WAVFileReader.h
//
// Functions for loading WAV audio files
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//-------------------------------------------------------------------------------------
#pragma once
#include <stdint.h>
#include <objbase.h>
#include <memory>
#include <mmreg.h>
namespace DirectX
{
HRESULT LoadWAVAudioInMemory( _In_reads_bytes_(wavDataSize) const uint8_t* wavData,
_In_ size_t wavDataSize,
_Outptr_ const WAVEFORMATEX** wfx,
_Outptr_ const uint8_t** startAudio,
_Out_ uint32_t* audioBytes );
HRESULT LoadWAVAudioFromFile( _In_z_ const wchar_t* szFileName,
_Inout_ std::unique_ptr<uint8_t[]>& wavData,
_Outptr_ const WAVEFORMATEX** wfx,
_Outptr_ const uint8_t** startAudio,
_Out_ uint32_t* audioBytes );
struct WAVData
{
const WAVEFORMATEX* wfx;
const uint8_t* startAudio;
uint32_t audioBytes;
uint32_t loopStart;
uint32_t loopLength;
const uint32_t* seek; // Note: XMA Seek data is Big-Endian
uint32_t seekCount;
};
HRESULT LoadWAVAudioInMemoryEx( _In_reads_bytes_(wavDataSize) const uint8_t* wavData,
_In_ size_t wavDataSize, _Out_ WAVData& result );
HRESULT LoadWAVAudioFromFileEx( _In_z_ const wchar_t* szFileName,
_Inout_ std::unique_ptr<uint8_t[]>& wavData,
_Out_ WAVData& result );
}

View File

@@ -0,0 +1,511 @@
//--------------------------------------------------------------------------------------
// File: WaveBank.cpp
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "Audio.h"
#include "WaveBankReader.h"
#include "SoundCommon.h"
#include "PlatformHelpers.h"
#include <list>
using namespace DirectX;
//======================================================================================
// WaveBank
//======================================================================================
// Internal object implementation class.
class WaveBank::Impl : public IVoiceNotify
{
public:
explicit Impl( _In_ AudioEngine* engine ) :
mEngine( engine ),
mOneShots( 0 ),
mPrepared( false ),
mStreaming( false )
{
assert( mEngine != 0 );
mEngine->RegisterNotify( this, false );
}
virtual ~Impl()
{
if ( !mInstances.empty() )
{
DebugTrace( "WARNING: Destroying WaveBank \"%hs\" with %Iu outstanding SoundEffectInstances\n", mReader.BankName(), mInstances.size() );
for( auto it = mInstances.begin(); it != mInstances.end(); ++it )
{
assert( *it != 0 );
(*it)->OnDestroyParent();
}
mInstances.clear();
}
if ( mOneShots > 0 )
{
DebugTrace( "WARNING: Destroying WaveBank \"%hs\" with %u outstanding one shot effects\n", mReader.BankName(), mOneShots );
}
if ( mEngine )
{
mEngine->UnregisterNotify( this, true, false );
mEngine = nullptr;
}
}
HRESULT Initialize( _In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName );
void Play( int index, float volume, float pitch, float pan );
// IVoiceNotify
virtual void __cdecl OnBufferEnd() override
{
InterlockedDecrement( &mOneShots );
}
virtual void __cdecl OnCriticalError() override
{
mOneShots = 0;
}
virtual void __cdecl OnReset() override
{
// No action required
}
virtual void __cdecl OnUpdate() override
{
// We do not register for update notification
assert(false);
}
virtual void __cdecl OnDestroyEngine() override
{
mEngine = nullptr;
mOneShots = 0;
}
virtual void __cdecl OnTrim() override
{
// No action required
}
virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const override
{
stats.playingOneShots += mOneShots;
if ( !mStreaming )
{
stats.audioBytes += mReader.BankAudioSize();
#if defined(_XBOX_ONE) && defined(_TITLE)
if ( mReader.HasXMA() )
stats.xmaAudioBytes += mReader.BankAudioSize();
#endif
}
}
AudioEngine* mEngine;
std::list<SoundEffectInstance*> mInstances;
WaveBankReader mReader;
uint32_t mOneShots;
bool mPrepared;
bool mStreaming;
};
_Use_decl_annotations_
HRESULT WaveBank::Impl::Initialize( AudioEngine* engine, const wchar_t* wbFileName )
{
if ( !engine || !wbFileName )
return E_INVALIDARG;
HRESULT hr = mReader.Open( wbFileName );
if ( FAILED(hr) )
return hr;
mStreaming = mReader.IsStreamingBank();
return S_OK;
}
void WaveBank::Impl::Play( int index, float volume, float pitch, float pan )
{
assert( volume >= -XAUDIO2_MAX_VOLUME_LEVEL && volume <= XAUDIO2_MAX_VOLUME_LEVEL );
assert( pitch >= -1.f && pitch <= 1.f );
assert( pan >= -1.f && pan <= 1.f );
if ( mStreaming )
{
DebugTrace( "ERROR: One-shots can only be created from an in-memory wave bank\n");
throw std::exception( "WaveBank::Play" );
}
if ( index < 0 || uint32_t(index) >= mReader.Count() )
{
DebugTrace( "WARNING: Index %d not found in wave bank with only %u entries, one-shot not triggered\n", index, mReader.Count() );
return;
}
if ( !mPrepared )
{
mReader.WaitOnPrepare();
mPrepared = true;
}
char wfxbuff[64];
auto wfx = reinterpret_cast<WAVEFORMATEX*>( wfxbuff );
HRESULT hr = mReader.GetFormat( index, wfx, 64 );
ThrowIfFailed( hr );
IXAudio2SourceVoice* voice = nullptr;
mEngine->AllocateVoice( wfx, SoundEffectInstance_Default, true, &voice );
if ( !voice )
return;
if ( volume != 1.f )
{
hr = voice->SetVolume( volume );
ThrowIfFailed( hr );
}
if ( pitch != 0.f )
{
float fr = XAudio2SemitonesToFrequencyRatio( pitch * 12.f );
hr = voice->SetFrequencyRatio( fr );
ThrowIfFailed( hr );
}
if ( pan != 0.f )
{
float matrix[16];
if ( ComputePan( pan, wfx->nChannels, matrix ) )
{
hr = voice->SetOutputMatrix( nullptr, wfx->nChannels, mEngine->GetOutputChannels(), matrix );
ThrowIfFailed( hr );
}
}
hr = voice->Start( 0 );
ThrowIfFailed( hr );
XAUDIO2_BUFFER buffer = {};
hr = mReader.GetWaveData( index, &buffer.pAudioData, buffer.AudioBytes );
ThrowIfFailed( hr );
WaveBankReader::Metadata metadata;
hr = mReader.GetMetadata( index, metadata );
ThrowIfFailed( hr );
buffer.Flags = XAUDIO2_END_OF_STREAM;
buffer.pContext = this;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
XAUDIO2_BUFFER_WMA wmaBuffer = {};
uint32_t tag;
hr = mReader.GetSeekTable( index, &wmaBuffer.pDecodedPacketCumulativeBytes, wmaBuffer.PacketCount, tag );
ThrowIfFailed( hr );
if ( tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3 )
{
hr = voice->SubmitSourceBuffer( &buffer, &wmaBuffer );
}
else
#endif
{
hr = voice->SubmitSourceBuffer( &buffer, nullptr );
}
if ( FAILED(hr) )
{
DebugTrace( "ERROR: WaveBank failed (%08X) when submitting buffer:\n", hr );
DebugTrace( "\tFormat Tag %u, %u channels, %u-bit, %u Hz, %u bytes\n", wfx->wFormatTag,
wfx->nChannels, wfx->wBitsPerSample, wfx->nSamplesPerSec, metadata.lengthBytes );
throw std::exception( "SubmitSourceBuffer" );
}
InterlockedIncrement( &mOneShots );
}
//--------------------------------------------------------------------------------------
// WaveBank
//--------------------------------------------------------------------------------------
// Public constructors.
_Use_decl_annotations_
WaveBank::WaveBank( AudioEngine* engine, const wchar_t* wbFileName )
: pImpl(new Impl(engine) )
{
HRESULT hr = pImpl->Initialize( engine, wbFileName );
if ( FAILED(hr) )
{
DebugTrace( "ERROR: WaveBank failed (%08X) to intialize from .xwb file \"%ls\"\n", hr, wbFileName );
throw std::exception( "WaveBank" );
}
DebugTrace( "INFO: WaveBank \"%hs\" with %u entries loaded from .xwb file \"%ls\"\n",
pImpl->mReader.BankName(), pImpl->mReader.Count(), wbFileName );
}
// Move constructor.
WaveBank::WaveBank(WaveBank&& moveFrom)
: pImpl(std::move(moveFrom.pImpl))
{
}
// Move assignment.
WaveBank& WaveBank::operator= (WaveBank&& moveFrom)
{
pImpl = std::move(moveFrom.pImpl);
return *this;
}
// Public destructor.
WaveBank::~WaveBank()
{
}
// Public methods.
void WaveBank::Play( int index )
{
pImpl->Play( index, 1.f, 0.f, 0.f );
}
void WaveBank::Play( int index, float volume, float pitch, float pan )
{
pImpl->Play( index, volume, pitch, pan );
}
void WaveBank::Play( _In_z_ const char* name )
{
int index = static_cast<int>( pImpl->mReader.Find( name ) );
if ( index == -1 )
{
DebugTrace( "WARNING: Name '%hs' not found in wave bank, one-shot not triggered\n", name );
return;
}
pImpl->Play( index, 1.f, 0.f, 0.f );
}
void WaveBank::Play( _In_z_ const char* name, float volume, float pitch, float pan )
{
int index = static_cast<int>( pImpl->mReader.Find( name ) );
if ( index == -1 )
{
DebugTrace( "WARNING: Name '%hs' not found in wave bank, one-shot not triggered\n", name );
return;
}
pImpl->Play( index, volume, pitch, pan );
}
std::unique_ptr<SoundEffectInstance> WaveBank::CreateInstance( int index, SOUND_EFFECT_INSTANCE_FLAGS flags )
{
auto& wb = pImpl->mReader;
if ( pImpl->mStreaming )
{
DebugTrace( "ERROR: SoundEffectInstances can only be created from an in-memory wave bank\n");
throw std::exception( "WaveBank::CreateInstance" );
}
if ( index < 0 || uint32_t(index) >= wb.Count() )
{
// We don't throw an exception here as titles often simply ignore missing assets rather than fail
return std::unique_ptr<SoundEffectInstance>();
}
if ( !pImpl->mPrepared )
{
wb.WaitOnPrepare();
pImpl->mPrepared = true;
}
auto effect = new SoundEffectInstance( pImpl->mEngine, this, index, flags );
assert( effect != 0 );
pImpl->mInstances.emplace_back( effect );
return std::unique_ptr<SoundEffectInstance>( effect );
}
std::unique_ptr<SoundEffectInstance> WaveBank::CreateInstance( _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags )
{
int index = static_cast<int>( pImpl->mReader.Find( name ) );
if ( index == -1 )
{
// We don't throw an exception here as titles often simply ignore missing assets rather than fail
return std::unique_ptr<SoundEffectInstance>();
}
return CreateInstance( index, flags );
}
void WaveBank::UnregisterInstance( _In_ SoundEffectInstance* instance )
{
auto it = std::find( pImpl->mInstances.begin(), pImpl->mInstances.end(), instance );
if ( it == pImpl->mInstances.end() )
return;
pImpl->mInstances.erase( it );
}
// Public accessors.
bool WaveBank::IsPrepared() const
{
if ( pImpl->mPrepared )
return true;
if ( !pImpl->mReader.IsPrepared() )
return false;
pImpl->mPrepared = true;
return true;
}
bool WaveBank::IsInUse() const
{
return ( pImpl->mOneShots > 0 ) || !pImpl->mInstances.empty();
}
bool WaveBank::IsStreamingBank() const
{
return pImpl->mReader.IsStreamingBank();
}
size_t WaveBank::GetSampleSizeInBytes( int index ) const
{
if ( index < 0 || uint32_t(index) >= pImpl->mReader.Count() )
return 0;
WaveBankReader::Metadata metadata;
HRESULT hr = pImpl->mReader.GetMetadata( index, metadata );
ThrowIfFailed( hr );
return metadata.lengthBytes;
}
size_t WaveBank::GetSampleDuration( int index ) const
{
if ( index < 0 || uint32_t(index) >= pImpl->mReader.Count() )
return 0;
WaveBankReader::Metadata metadata;
HRESULT hr = pImpl->mReader.GetMetadata( index, metadata );
ThrowIfFailed( hr );
return metadata.duration;
}
size_t WaveBank::GetSampleDurationMS( int index ) const
{
if ( index < 0 || uint32_t(index) >= pImpl->mReader.Count() )
return 0;
char buff[64];
auto wfx = reinterpret_cast<WAVEFORMATEX*>( buff );
HRESULT hr = pImpl->mReader.GetFormat( index, wfx, 64 );
ThrowIfFailed( hr );
WaveBankReader::Metadata metadata;
hr = pImpl->mReader.GetMetadata( index, metadata );
ThrowIfFailed( hr );
return static_cast<size_t>( ( uint64_t(metadata.duration) * 1000 ) / wfx->nSamplesPerSec );
}
_Use_decl_annotations_
const WAVEFORMATEX* WaveBank::GetFormat( int index, WAVEFORMATEX* wfx, size_t maxsize ) const
{
if ( index < 0 || uint32_t(index) >= pImpl->mReader.Count() )
return nullptr;
HRESULT hr = pImpl->mReader.GetFormat( index, wfx, maxsize );
ThrowIfFailed( hr );
return wfx;
}
_Use_decl_annotations_
int WaveBank::Find( const char* name ) const
{
return static_cast<int>( pImpl->mReader.Find( name ) );
}
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
_Use_decl_annotations_
bool WaveBank::FillSubmitBuffer( int index, XAUDIO2_BUFFER& buffer, XAUDIO2_BUFFER_WMA& wmaBuffer ) const
{
memset( &buffer, 0, sizeof(buffer) );
memset( &wmaBuffer, 0, sizeof(wmaBuffer) );
HRESULT hr = pImpl->mReader.GetWaveData( index, &buffer.pAudioData, buffer.AudioBytes );
ThrowIfFailed( hr );
WaveBankReader::Metadata metadata;
hr = pImpl->mReader.GetMetadata( index, metadata );
ThrowIfFailed( hr );
buffer.LoopBegin = metadata.loopStart;
buffer.LoopLength = metadata.loopLength;
uint32_t tag;
hr = pImpl->mReader.GetSeekTable( index, &wmaBuffer.pDecodedPacketCumulativeBytes, wmaBuffer.PacketCount, tag );
ThrowIfFailed( hr );
return ( tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3 );
}
#else
_Use_decl_annotations_
void WaveBank::FillSubmitBuffer( int index, XAUDIO2_BUFFER& buffer ) const
{
memset( &buffer, 0, sizeof(buffer) );
HRESULT hr = pImpl->mReader.GetWaveData( index, &buffer.pAudioData, buffer.AudioBytes );
ThrowIfFailed( hr );
WaveBankReader::Metadata metadata;
hr = pImpl->mReader.GetMetadata( index, metadata );
ThrowIfFailed( hr );
buffer.LoopBegin = metadata.loopStart;
buffer.LoopLength = metadata.loopLength;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
//--------------------------------------------------------------------------------------
// File: WaveBankReader.h
//
// Functions for loading audio data from Wave Banks
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//-------------------------------------------------------------------------------------
#pragma once
#include <stdint.h>
#include <objbase.h>
#include <memory>
#include <mmreg.h>
namespace DirectX
{
class WaveBankReader
{
public:
WaveBankReader();
#if !defined(_MSC_VER) || _MSC_VER >= 1900
WaveBankReader(WaveBankReader&&) = default;
WaveBankReader& operator= (WaveBankReader&&) = default;
#endif
WaveBankReader(WaveBankReader const&) = delete;
WaveBankReader& operator= (WaveBankReader const&) = delete;
~WaveBankReader();
HRESULT Open( _In_z_ const wchar_t* szFileName );
uint32_t Find( _In_z_ const char* name ) const;
bool IsPrepared();
void WaitOnPrepare();
bool HasNames() const;
bool IsStreamingBank() const;
#if defined(_XBOX_ONE) && defined(_TITLE)
bool HasXMA() const;
#endif
const char* BankName() const;
uint32_t Count() const;
uint32_t BankAudioSize() const;
HRESULT GetFormat( _In_ uint32_t index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* pFormat, _In_ size_t maxsize ) const;
HRESULT GetWaveData( _In_ uint32_t index, _Outptr_ const uint8_t** pData, _Out_ uint32_t& dataSize ) const;
HRESULT GetSeekTable( _In_ uint32_t index, _Out_ const uint32_t** pData, _Out_ uint32_t& dataCount, _Out_ uint32_t& tag ) const;
HANDLE GetAsyncHandle() const;
struct Metadata
{
uint32_t duration;
uint32_t loopStart;
uint32_t loopLength;
uint32_t offsetBytes;
uint32_t lengthBytes;
};
HRESULT GetMetadata( _In_ uint32_t index, _Out_ Metadata& metadata ) const;
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
};
}