diff --git a/Assets/Scripts/Audio/AudioStream.cs b/Assets/Scripts/Audio/AudioStream.cs index 18fde874..db04db58 100644 --- a/Assets/Scripts/Audio/AudioStream.cs +++ b/Assets/Scripts/Audio/AudioStream.cs @@ -2,6 +2,7 @@ using System; using System.IO; using UnityEngine; +using UnityEngine.Profiling; namespace SanAndreasUnity.Audio { @@ -40,9 +41,12 @@ namespace SanAndreasUnity.Audio /// Close stream on dispose 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(); }); } diff --git a/Assets/Scripts/Behaviours/Audio/AudioManager.cs b/Assets/Scripts/Behaviours/Audio/AudioManager.cs index 79f20a71..ccc7522d 100644 --- a/Assets/Scripts/Behaviours/Audio/AudioManager.cs +++ b/Assets/Scripts/Behaviours/Audio/AudioManager.cs @@ -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; }