public static void InitFromLoader() { s_gtaAudioFiles = GTAAudio.OpenRead(Path.Combine(Utilities.Config.GamePath, "audio")); if (Instance.playStartupSound) { s_startupAudioSource = PlayStream("Beats", 1); if (s_startupAudioSource != null) { s_startupAudioSource.time = Instance.startupSoundTimeOffset; } } }
public static void InitFromLoader() { s_gtaAudioFiles = GTAAudio.OpenRead(Path.Combine(Utilities.Config.GamePath, "audio")); s_sfxGENRL137Timings = LoadSfxBankTimings(Resources.Load <TextAsset>("Data/SFX_GENRL_137").text); if (Instance.playStartupSound) { s_startupAudioSource = PlayStream("Beats", 1); if (s_startupAudioSource != null) { s_startupAudioSource.time = Instance.startupSoundTimeOffset; } } // s_sfxGENRLClip = CreateAudioClipFromSfx ("GENRL", 136, 0); }
/// <summary> /// Main entry point /// </summary> /// <param name="args">Command line arguments</param> static void Main(string[] args) { try { string path = null; if (args.Length > 0) { path = args[0]; } else { Console.Write("Please specify a path to dump the audio files from (press return to exit): "); path = Console.ReadLine(); } if (path != null) { if (path.Trim().Length > 0) { string sfx_directory = Path.Combine(Environment.CurrentDirectory, "sfx"); byte[] buffer = new byte[4096]; if (!(Directory.Exists(sfx_directory))) { Directory.CreateDirectory(sfx_directory); } using (GTAAudioFiles gta_audio_files = GTAAudio.OpenRead(path)) { if (gta_audio_files != null) { GTAAudioSFXFile[] sfx_audio_files = gta_audio_files.SFXAudioFiles; foreach (GTAAudioSFXFile sfx_audio_file in sfx_audio_files) { if (sfx_audio_file != null) { string sfx_sfx_directory = Path.Combine(sfx_directory, sfx_audio_file.Name); try { if (!(Directory.Exists(sfx_sfx_directory))) { Directory.CreateDirectory(sfx_sfx_directory); } for (int i = 0, j; i < sfx_audio_file.NumBanks; i++) { try { GTAAudioBankData bank_data = sfx_audio_file.GetBankData((uint)i); string sfx_bank_directory = Path.Combine(sfx_sfx_directory, i.ToString()); if (!(Directory.Exists(sfx_bank_directory))) { Directory.CreateDirectory(sfx_bank_directory); } for (j = 0; j < bank_data.NumAudioClips; j++) { using (Stream audio_stream = sfx_audio_file.Open((uint)i, (uint)j)) { if (audio_stream is GTAAudioStream) { GTAAudioStream gta_audio_stream = (GTAAudioStream)audio_stream; string audio_file_path = Path.Combine(sfx_bank_directory, sfx_audio_file.Name + "." + i + "." + j + ".wav"); if (File.Exists(audio_file_path)) { File.Delete(audio_file_path); } using (FileStream file_stream = File.Open(audio_file_path, FileMode.Create)) { using (BinaryWriter writer = new BinaryWriter(file_stream)) { int len; long audio_stream_length = audio_stream.Length; writer.Write(Encoding.ASCII.GetBytes("RIFF")); writer.Write(0); writer.Write(Encoding.ASCII.GetBytes("WAVEfmt ")); writer.Write(16); writer.Write((short)1); writer.Write((short)1); writer.Write((int)(gta_audio_stream.SampleRate)); writer.Write(gta_audio_stream.SampleRate * 2); writer.Write((short)2); writer.Write((short)16); writer.Write(Encoding.ASCII.GetBytes("data")); writer.Write((int)audio_stream_length); while ((len = Math.Min((int)(audio_stream_length - audio_stream.Position), buffer.Length)) > 0) { if (audio_stream.Read(buffer, 0, len) == len) { file_stream.Write(buffer, 0, len); } else { break; } } file_stream.Seek(4L, SeekOrigin.Begin); writer.Write((int)(file_stream.Length - 8)); } } } } } } catch (Exception e) { Console.Error.WriteLine(e); } } } catch (Exception e) { Console.Error.WriteLine(e); } } } } else { Console.Error.WriteLine("Can't open audio directory \"" + path + "\"."); Environment.ExitCode = 3; } } } else { Environment.ExitCode = 2; } } else { Environment.ExitCode = 1; } } catch (Exception e) { Console.Error.WriteLine(e); Environment.ExitCode = -1; } }
/// <summary> /// Main entry point /// </summary> /// <param name="args">Command line arguments</param> static void Main(string[] args) { try { string path = null; if (args.Length > 0) { path = args[0]; } else { Console.Write("Please specify a path to dump the audio files from (press return to exit): "); path = Console.ReadLine(); } if (path != null) { if (path.Trim().Length > 0) { string streams_directory = Path.Combine(Environment.CurrentDirectory, "streams"); byte[] buffer = new byte[4096]; if (!(Directory.Exists(streams_directory))) { Directory.CreateDirectory(streams_directory); } using (GTAAudioFiles gta_audio_files = GTAAudio.OpenRead(path)) { if (gta_audio_files != null) { GTAAudioStreamsFile[] streams_audio_files = gta_audio_files.StreamsAudioFiles; foreach (GTAAudioStreamsFile streams_audio_file in streams_audio_files) { if (streams_audio_file != null) { string streams_streams_directory = Path.Combine(streams_directory, streams_audio_file.Name); try { if (!(Directory.Exists(streams_streams_directory))) { Directory.CreateDirectory(streams_streams_directory); } for (int i = 0; i < streams_audio_file.NumBanks; i++) { try { using (Stream audio_stream = streams_audio_file.Open((uint)i)) { if (audio_stream != null) { string audio_file_path = Path.Combine(streams_streams_directory, streams_audio_file.Name + "." + i + ".ogg"); if (File.Exists(audio_file_path)) { File.Delete(audio_file_path); } using (FileStream file_stream = File.Open(audio_file_path, FileMode.Create)) { int len; long audio_stream_length = audio_stream.Length; while ((len = Math.Min((int)(audio_stream_length - audio_stream.Position), buffer.Length)) > 0) { if (audio_stream.Read(buffer, 0, len) == len) { file_stream.Write(buffer, 0, len); } else { break; } } } } } } catch (Exception e) { Console.Error.WriteLine(e); } } } catch (Exception e) { Console.Error.WriteLine(e); } } } } else { Console.Error.WriteLine("Can't open audio directory \"" + path + "\"."); Environment.ExitCode = 3; } } } else { Environment.ExitCode = 2; } } else { Environment.ExitCode = 1; } } catch (Exception e) { Console.Error.WriteLine(e); Environment.ExitCode = -1; } }
public void ReadFileTest() { using (GTAAudioFiles files = GTAAudio.OpenRead(Config.AudioFilesDir)) { Assert.IsNotNull(files, "Files can't be opened. Please configure \"" + configPath + "\"."); GTAAudioSFXFile[] sfx_audio_files = files.SFXAudioFiles; Assert.IsTrue(sfx_audio_files.Length == validSFXFiles.Length, "Missing SFX file entries. " + files.SFXAudioFiles.Length + " files found, not " + validSFXFiles.Length); for (int i = 0, j, k; i < sfx_audio_files.Length; i++) { GTAAudioSFXFile sfx_audio_file = sfx_audio_files[i]; if (sfx_audio_file != null) { Assert.IsTrue(sfx_audio_file.Name == validSFXFiles[i], "SFX file \"" + sfx_audio_file.Name + "\" is not \"" + validSFXFiles[i] + "\" at index " + i); Debug.WriteLine(sfx_audio_file.Name + ":"); Debug.WriteLine("\tNumber of banks: " + sfx_audio_file.NumBanks); for (j = 0; j < sfx_audio_file.NumBanks; j++) { GTAAudioBankData bank_data = sfx_audio_file.GetBankData((uint)j); Debug.WriteLine("\t\t" + sfx_audio_file.Name + " bank " + j + ":"); Debug.WriteLine("\t\t\tLength: " + bank_data.Length); Debug.WriteLine("\t\t\tOffset: " + bank_data.Offset); Debug.WriteLine("\t\t\tNumber of audio clips: " + bank_data.NumAudioClips); for (k = 0; k < bank_data.NumAudioClips; k++) { GTAAudioAudioClipData audio_clip_data = bank_data.GetAudioClipData((uint)k); Debug.WriteLine("\t\t\t" + sfx_audio_file.Name + " bank " + j + " audio " + k + ":"); Debug.WriteLine("\t\t\t\tSample rate: " + audio_clip_data.SampleRate); Debug.WriteLine("\t\t\t\tSound buffer offset: " + audio_clip_data.SoundBufferOffset); Debug.WriteLine("\t\t\t\tLoop offset: " + audio_clip_data.LoopOffset); Debug.WriteLine("\t\t\t\tSound headroom: " + audio_clip_data.SoundHeadroom); Debug.WriteLine("\t\t\t\tLength: " + audio_clip_data.Length); } } } } GTAAudioStreamsFile[] streams_audio_files = files.StreamsAudioFiles; Assert.IsTrue(streams_audio_files.Length == validStreamsFiles.Length, "Missing streams file entries. " + files.SFXAudioFiles.Length + " files found, not " + validSFXFiles.Length); for (int i = 0, j; i < streams_audio_files.Length; i++) { GTAAudioStreamsFile streams_audio_file = streams_audio_files[i]; if (streams_audio_file != null) { Assert.IsTrue(streams_audio_file.Name == validStreamsFiles[i], "Streams file \"" + streams_audio_file.Name + "\" is not \"" + validStreamsFiles[i] + "\" at index " + i); Debug.WriteLine(streams_audio_file.Name + ":"); Debug.WriteLine("\tNumber of banks: " + streams_audio_file.NumBanks); for (j = 0; j < streams_audio_file.NumBanks; j++) { GTAAudioBankData bank_data = streams_audio_file.GetBankData((uint)j); Debug.WriteLine("\t\t" + streams_audio_file.Name + " bank " + j + ":"); Debug.WriteLine("\t\t\tLength: " + bank_data.Length); Debug.WriteLine("\t\t\tOffset: " + bank_data.Offset); } for (j = 0; j < streams_audio_file.NumBeats; j++) { GTAAudioBeatData beat_data = streams_audio_file.GetBeatData((uint)j); Debug.WriteLine("\t\t\t" + streams_audio_file.Name + " beat " + j + ":"); Debug.WriteLine("\t\t\t\tControl: " + beat_data.Control); Debug.WriteLine("\t\t\t\tTiming: " + beat_data.Timing); } } } } }