-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on NAudio and NVorbis
- Loading branch information
1 parent
e3256b7
commit 37d0a5f
Showing
9 changed files
with
11 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters