Skip to content

Commit

Permalink
Remove dependency on NAudio and NVorbis
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathWeasel1337 committed Nov 9, 2020
1 parent e3256b7 commit 37d0a5f
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 119 deletions.
14 changes: 1 addition & 13 deletions src/AI_BGMLoader/AI_BGMLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@
<HintPath>..\..\packages\MonoMod.Utils.20.11.5.1\lib\net40\MonoMod.Utils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NAudio, Version=1.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Core_BGMLoader\lib\NAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NVorbis, Version=0.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Core_BGMLoader\lib\NVorbis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -134,9 +124,7 @@
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" AI
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NAudio.dll" AI
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NVorbis.dll" AI</PostBuildEvent>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" AI</PostBuildEvent>
</PropertyGroup>
<Import Project="..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets" Condition="Exists('..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
68 changes: 5 additions & 63 deletions src/Core_BGMLoader/Core.BGMLoader.AudioLoader.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,20 @@
using NAudio.Wave;
using NVorbis;
using UnityEngine;
using UnityEngine;

namespace BGMLoader
{
public static class AudioLoader
{
/// <summary>
/// Requires MediaFoundation to be installed (non N edition of windows)
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public static AudioClip LoadGeneric(string filename)
public static AudioClip LoadAudioClip(string path)
{
using (MediaFoundationReader reader = new MediaFoundationReader(filename))
using (WWW www = new WWW(BepInEx.Utility.ConvertToWWWFormat(path)))
{
int sampleCount = (int)(reader.WaveFormat.Channels * reader.Length / reader.WaveFormat.BlockAlign);
AudioClip clip = www.GetAudioClip();

var audioData = new float[sampleCount];

reader.ToSampleProvider().Read(audioData, 0, sampleCount);

return LoadInternal(filename, audioData, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate);
}
}

public static AudioClip LoadWave(string filename)
{
using (WaveFileReader reader = new WaveFileReader(filename))
{
int sampleCount = (int)(reader.SampleCount * reader.WaveFormat.Channels);

var audioData = new float[sampleCount];

reader.ToSampleProvider().Read(audioData, 0, sampleCount);

return LoadInternal(filename, audioData, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate);
}
}

public static AudioClip LoadVorbis(string filename)
{
using (VorbisReader reader = new VorbisReader(filename))
{
int sampleCount = (int)reader.TotalSamples * reader.Channels;

var audioData = new float[sampleCount];

reader.ReadSamples(audioData, 0, sampleCount);

return LoadInternal(filename, audioData, reader.Channels, reader.SampleRate);
}
}

public static AudioClip LoadAudioClip(string path, AudioType type)
{
using (WWW loadGachi = new WWW(BepInEx.Utility.ConvertToWWWFormat(path)))
{
AudioClip clip = loadGachi.GetAudioClipCompressed(false, type);

//force single threaded loading instead of using a coroutine
//Wait for the clip to be loaded before returning it
while (clip.loadState != AudioDataLoadState.Loaded) { }

return clip;
}
}

private static AudioClip LoadInternal(string name, float[] data, int channels, int sampleRate)
{
var clip = AudioClip.Create(name, data.Length / channels, channels, sampleRate, false);

clip.SetData(data, 0);

return clip;
}
}
}
4 changes: 2 additions & 2 deletions src/Core_BGMLoader/Core.BGMLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void LoadIntroClips(IAssetLoadingContext context)

var path = files[Random.Range(0, files.Length - 1)];

context.Asset = AudioLoader.LoadAudioClip(path, AudioType.WAV);
context.Asset = AudioLoader.LoadAudioClip(path);
context.Complete();
}
}
Expand All @@ -63,7 +63,7 @@ public void LoadBGM(IAssetLoadingContext context)
{
Logger.LogDebug($"Loading BGM track \"{(BGM)bgmTrack}\" from {path}");

context.Asset = AudioLoader.LoadVorbis(path);
context.Asset = AudioLoader.LoadAudioClip(path);
context.Complete();
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/Core_BGMLoader/Core_BGMLoader.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@
<Compile Include="$(MSBuildThisFileDirectory)Core.BGMLoader.AudioLoader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Core.BGMLoader.cs" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)lib\NAudio.dll" />
<None Include="$(MSBuildThisFileDirectory)lib\NVorbis.dll" />
</ItemGroup>
</Project>
Binary file removed src/Core_BGMLoader/lib/NAudio.dll
Binary file not shown.
Binary file removed src/Core_BGMLoader/lib/NVorbis.dll
Binary file not shown.
12 changes: 1 addition & 11 deletions src/EC_BGMLoader/EC_BGMLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@
<HintPath>..\..\packages\MonoMod.Utils.20.11.5.1\lib\net40\MonoMod.Utils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NAudio">
<HintPath>..\Core_BGMLoader\lib\NAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NVorbis">
<HintPath>..\Core_BGMLoader\lib\NVorbis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -128,9 +120,7 @@
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" EC
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NAudio.dll" EC
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NVorbis.dll" EC</PostBuildEvent>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" EC</PostBuildEvent>
</PropertyGroup>
<Import Project="..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets" Condition="Exists('..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
14 changes: 1 addition & 13 deletions src/HS2_BGMLoader/HS2_BGMLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@
<HintPath>..\..\packages\MonoMod.Utils.20.11.5.1\lib\net40\MonoMod.Utils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NAudio, Version=1.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Core_BGMLoader\lib\NAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NVorbis, Version=0.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Core_BGMLoader\lib\NVorbis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -133,9 +123,7 @@
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" HS2
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NAudio.dll" HS2
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NVorbis.dll" HS2</PostBuildEvent>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" HS2</PostBuildEvent>
</PropertyGroup>
<Import Project="..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets" Condition="Exists('..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
14 changes: 1 addition & 13 deletions src/KK_BGMLoader/KK_BGMLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@
<HintPath>..\..\packages\MonoMod.Utils.20.11.5.1\lib\net35\MonoMod.Utils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NAudio, Version=1.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Core_BGMLoader\lib\NAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NVorbis, Version=0.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Core_BGMLoader\lib\NVorbis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -114,9 +104,7 @@
<Import Project="..\Core_BGMLoader\Core_BGMLoader.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" KK
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NAudio.dll" KK
IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetDir)NVorbis.dll" KK</PostBuildEvent>
<PostBuildEvent>IF EXIST "$(SolutionDir)PostBuild.bat" CALL "$(SolutionDir)PostBuild.bat" "$(TargetPath)" KK</PostBuildEvent>
</PropertyGroup>
<Import Project="..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets" Condition="Exists('..\..\packages\BepInEx.Core.5.4.0\build\BepInEx.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down

0 comments on commit 37d0a5f

Please sign in to comment.