Beispiel #1
0
        /// <summary>
        /// Open SFX audio stream by index
        /// </summary>
        /// <param name="sfxIndex">SFX index</param>
        /// <param name="bankIndex">Bank Index</param>
        /// <param name="audioClipIndex">Audio clip index</param>
        /// <returns>GTA audio stream</returns>
        public GTAAudioStream OpenSFXAudioStreamByID(uint sfxIndex, uint bankIndex, uint audioClipIndex)
        {
            GTAAudioStream ret = null;

            if (sfxIndex < sfxAudioFiles.Length)
            {
                GTAAudioSFXFile sfx_file = sfxAudioFiles[sfxIndex];
                if (sfx_file != null)
                {
                    Stream stream = sfx_file.Open(bankIndex, audioClipIndex);
                    if (stream != null)
                    {
                        if (stream is GTAAudioStream)
                        {
                            ret = (GTAAudioStream)stream;
                        }
                        else
                        {
                            stream.Dispose();
                        }
                    }
                }
            }
            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// Open audio stream
        /// </summary>
        /// <param name="bankIndex">Bank index</param>
        /// <param name="audioIndex">Audio index</param>
        /// <returns>GTA audio stream</returns>
        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);
        }
Beispiel #3
0
        /// <summary>
        /// Open SFX audio stream by script event index
        /// </summary>
        /// <param name="eventIndex"></param>
        /// <returns>GTA audio stream if successful, otherwise "null"</returns>
        public GTAAudioStream OpenSFXAudioStreamByScriptEventIndex(uint eventIndex)
        {
            GTAAudioStream ret = null;

            if (eventIndex >= 2000U)
            {
                ret = OpenSFXAudioStreamByName("SCRIPT", (eventIndex - 2000U) / 200U, (eventIndex - 2000) % 200);
            }
            return(ret);
        }
Beispiel #4
0
        /// <summary>
        /// Open SFX audio stream by name
        /// </summary>
        /// <param name="sfxName">SFX name</param>
        /// <param name="bankIndex">Bank index</param>
        /// <param name="audioClipIndex">Audio clip index</param>
        /// <returns>GTA audio stream if successful, otherwise "null"</returns>
        public GTAAudioStream OpenSFXAudioStreamByName(string sfxName, uint bankIndex, uint audioClipIndex)
        {
            GTAAudioStream ret = null;

            if (sfxName != null)
            {
                string key = sfxName.Trim().ToLower();
                if (sfxFilesLookup.ContainsKey(key))
                {
                    ret = OpenSFXAudioStreamByID(sfxFilesLookup[key], bankIndex, audioClipIndex);
                }
            }
            return(ret);
        }