using System.IO; /// /// GTA audio sharp namespace /// namespace GTAAudioSharp { /// /// GTA audio SFX file class /// public class GTAAudioSFXFile : AGTAAudioFile { /// /// Constructor /// /// Name /// File stream /// Bank data internal GTAAudioSFXFile(string name, FileStream fileStream, GTAAudioBankData[] bankData) : base(name, fileStream, bankData) { // ... } /// /// Open audio stream /// /// Bank index /// Audio index /// GTA audio stream public override Stream Open(uint bankIndex, uint audioIndex) { GTAAudioStream ret = null; if (FileStream != null) { if (bankIndex < NumBanks) { GTAAudioBankData bank_data = BankData[bankIndex]; if (audioIndex < bank_data.NumAudioClips) { GTAAudioAudioClipData audio_clip_data = bank_data.AudioClipData[audioIndex]; uint offset = bank_data.Offset + audio_clip_data.SoundBufferOffset + 0x12C4; if (FileStream.Length >= (offset + audio_clip_data.Length)) { byte[] data = new byte[audio_clip_data.Length]; FileStream.Seek(offset, SeekOrigin.Begin); if (FileStream.Read(data, 0, data.Length) == data.Length) { ret = new GTAAudioStream(this, audio_clip_data.SampleRate, audio_clip_data.LoopOffset, audio_clip_data.SoundHeadroom, data); ret.Seek(0L, SeekOrigin.Begin); } } } } } return ret; } } }