mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 12:03:04 +00:00
profile audio calls
This commit is contained in:
parent
7b491d49ae
commit
5a84e5fd61
2 changed files with 16 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace SanAndreasUnity.Audio
|
||||
{
|
||||
|
@ -40,9 +41,12 @@ namespace SanAndreasUnity.Audio
|
|||
/// <param name="closeStreamOnDispose">Close stream on dispose</param>
|
||||
public AudioStream(Stream stream, string audioClipName, bool closeStreamOnDispose)
|
||||
{
|
||||
Profiler.BeginSample("VorbisReader()");
|
||||
reader = new VorbisReader(stream, closeStreamOnDispose);
|
||||
Profiler.EndSample();
|
||||
audioClip = AudioClip.Create(audioClipName, (int)(reader.TotalSamples), reader.Channels, reader.SampleRate, true, (data) =>
|
||||
{
|
||||
Profiler.BeginSample("reader.ReadSamples()");
|
||||
if (data != null)
|
||||
{
|
||||
if (data.Length > 0)
|
||||
|
@ -50,9 +54,12 @@ namespace SanAndreasUnity.Audio
|
|||
reader.ReadSamples(data, 0, Mathf.Min(data.Length, Mathf.Max(0, (int)(reader.TotalSamples - reader.DecodedPosition))));
|
||||
}
|
||||
}
|
||||
Profiler.EndSample();
|
||||
}, (newPosition) =>
|
||||
{
|
||||
Profiler.BeginSample("set DecodedPosition");
|
||||
reader.DecodedPosition = newPosition;
|
||||
Profiler.EndSample();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ using UnityEngine;
|
|||
using GTAAudioSharp;
|
||||
using System.IO;
|
||||
using SanAndreasUnity.Audio;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace SanAndreasUnity.Behaviours.Audio
|
||||
{
|
||||
|
@ -73,6 +74,8 @@ namespace SanAndreasUnity.Behaviours.Audio
|
|||
|
||||
public static AudioClip CreateAudioClipFromStream (string streamFileName, int bankIndex)
|
||||
{
|
||||
Profiler.BeginSample("CreateAudioClipFromStream()");
|
||||
|
||||
AudioStream audio_stream = null;
|
||||
System.DateTime startTime = System.DateTime.Now;
|
||||
|
||||
|
@ -85,10 +88,14 @@ namespace SanAndreasUnity.Behaviours.Audio
|
|||
{
|
||||
try
|
||||
{
|
||||
Profiler.BeginSample("Open audio stream");
|
||||
Stream stream = s_gtaAudioFiles.OpenStreamsAudioStreamByName(streams_file_name, (uint)streams_bank_index);
|
||||
Profiler.EndSample();
|
||||
if (stream != null)
|
||||
{
|
||||
Profiler.BeginSample("AudioStream()");
|
||||
audio_stream = new AudioStream(stream, key, true);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
|
@ -106,6 +113,8 @@ namespace SanAndreasUnity.Behaviours.Audio
|
|||
return audio_stream.AudioClip;
|
||||
}
|
||||
|
||||
Profiler.EndSample();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue