public static AudioClip CreateAudioClipFromSfx(string sfxFileName, int bankIndex, int audioIndex, SfxBankAudioData?sfxBankAudioData) { if (null == s_gtaAudioFiles || bankIndex < 0 || audioIndex < 0) { return(null); } AudioClip ret = null; string clipName = sfxFileName + "." + bankIndex + "." + audioIndex; try { using (GTAAudioStream audio_stream = s_gtaAudioFiles.OpenSFXAudioStreamByName(sfxFileName, (uint)bankIndex, (uint)audioIndex)) { if (audio_stream != null) { // this audio stream holds all sounds from this bank int freq = sfxBankAudioData.HasValue ? Mathf.RoundToInt(KbsToFreq(sfxBankAudioData.Value.bitrateKbs)) : audio_stream.SampleRate; int offsetInBytes = sfxBankAudioData.HasValue ? sfxBankAudioData.Value.offsetInBytes : 0; int sizeInBytes = sfxBankAudioData.HasValue ? sfxBankAudioData.Value.sizeInBytes : (int)audio_stream.Length; ret = CreateAudioClipFromSfx(clipName, audio_stream, offsetInBytes, sizeInBytes, freq); } } } catch (System.Exception e) { Debug.LogError(e); } return(ret); }
public static AudioClip CreateAudioClipFromSfx(string sfxFileName, int bankIndex, int audioIndex) { if (null == s_gtaAudioFiles || bankIndex < 0 || audioIndex < 0) { return(null); } AudioClip ret = null; string clipName = sfxFileName + "." + bankIndex + "." + audioIndex; try { using (GTAAudioStream audio_stream = s_gtaAudioFiles.OpenSFXAudioStreamByName(sfxFileName, (uint)bankIndex, (uint)audioIndex)) { if (audio_stream != null) { ret = CreateAudioClipFromSfx(clipName, audio_stream); } } } catch (System.Exception e) { Debug.LogError(e); } return(ret); }