mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 12:03:04 +00:00
wip
This commit is contained in:
parent
5a84e5fd61
commit
01d80f7bad
2 changed files with 55 additions and 1 deletions
|
@ -63,6 +63,50 @@ namespace SanAndreasUnity.Audio
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct AudioClipCreationData
|
||||||
|
{
|
||||||
|
public int Channels, SampleRate, TotalSamples;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AudioClipCreationData ReadStreamIntoBuffer(
|
||||||
|
Stream stream,
|
||||||
|
bool closeStreamOnDispose,
|
||||||
|
Func<int, float[]> funcGetBuffer)
|
||||||
|
{
|
||||||
|
var reader = new VorbisReader(stream, closeStreamOnDispose);
|
||||||
|
|
||||||
|
var audioClipCreationData = new AudioClipCreationData
|
||||||
|
{
|
||||||
|
Channels = reader.Channels,
|
||||||
|
SampleRate = reader.SampleRate,
|
||||||
|
TotalSamples = (int) reader.TotalSamples,
|
||||||
|
};
|
||||||
|
|
||||||
|
var buffer = funcGetBuffer(audioClipCreationData.Channels * audioClipCreationData.TotalSamples);
|
||||||
|
|
||||||
|
// read entire stream
|
||||||
|
reader.ReadSamples(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
|
return audioClipCreationData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AudioClip CreateAudioClip(
|
||||||
|
string audioClipName,
|
||||||
|
AudioClipCreationData audioClipCreationData,
|
||||||
|
float[] audioData)
|
||||||
|
{
|
||||||
|
var clip = AudioClip.Create(
|
||||||
|
audioClipName,
|
||||||
|
audioClipCreationData.TotalSamples,
|
||||||
|
audioClipCreationData.Channels,
|
||||||
|
audioClipCreationData.SampleRate,
|
||||||
|
false);
|
||||||
|
|
||||||
|
clip.SetData(audioData, 0);
|
||||||
|
|
||||||
|
return clip;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose
|
/// Dispose
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -72,7 +72,17 @@ namespace SanAndreasUnity.Behaviours.Audio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static AudioClip CreateAudioClipFromStream (string streamFileName, int bankIndex)
|
public static void CreateAudioClipFromStreamAsync(
|
||||||
|
string streamFileName,
|
||||||
|
int bankIndex,
|
||||||
|
System.Action<AudioClip> onFinish)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CreateAudioClipFromStreamInBackgroundThread(
|
||||||
|
string streamFileName,
|
||||||
|
int bankIndex)
|
||||||
{
|
{
|
||||||
Profiler.BeginSample("CreateAudioClipFromStream()");
|
Profiler.BeginSample("CreateAudioClipFromStream()");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue