private static void WriteSounds(IList <KeyValuePair <string, GMSound> > _data, Stream _s, IFF _iff) { Random rnd = new Random(); int NumSounds = _data.Count; Console.WriteLine("Making Audio Files ISO9660 Compatible"); for (int i = 0; i < NumSounds; i++) { if (!(_data[i].ToString() == "[, ]")) { GMSound Sound = _data[i].Value; byte[] AudioName = new byte[0x5]; rnd.NextBytes(AudioName); string OriginalName = Sound.OrigName; string Extension = Path.GetExtension(Sound.OrigName); Sound.OrigName = Path.ChangeExtension(BitConverter.ToString(AudioName).Replace("-", ""), Extension); Console.WriteLine("Renaming: " + OriginalName + "->" + Sound.OrigName); } } WriteDataKVP(_data, _s, _iff, delegate(KeyValuePair <string, GMSound> _kvp, Stream __s, IFF __iff, long __index) { __s.PatchOffset(__index); __iff.AddString(__s, _kvp.Key); GMSound value = _kvp.Value; string[] source = value.OrigName.Split('\\', '/', ':'); string text = Path.GetFileName(source.Last()); bool flag = true; while (flag) { flag = false; foreach (Wave ms_Wave in ms_Waves) { if (ms_Wave.FileName == text) { text = string.Format("{0}{1}{2}", Path.GetFileNameWithoutExtension(text), "_a", Path.GetExtension(text)); flag = true; } } } if (value.Data != null) { ms_Waves.Add(new Wave(_iff, value.Data, text)); } __s.WriteInteger(value.Kind); __iff.AddString(__s, value.Extension); __iff.AddString(__s, text); __s.WriteInteger(value.Effects); __s.WriteSingle((float)value.Volume); __s.WriteSingle((float)value.Pan); __s.WriteBoolean(value.Preload); __s.WriteInteger(ms_Waves.Count - 1); }); }
public void Sound_Load(Stream _s) { int num = _s.ReadInteger(); int num2 = _s.ReadInteger(); for (int i = 0; i < num2; i++) { Stream s = _s; if (num == 800) { s = _s.ReadStreamC(); } bool flag = s.ReadBoolean(); KeyValuePair <string, GMSound> item = default(KeyValuePair <string, GMSound>); if (flag) { string key = s.ReadString(); GMSound value = new GMSound(this, s); item = new KeyValuePair <string, GMSound>(key, value); } Sounds.Add(item); } }
private static void WriteSounds(IList <KeyValuePair <string, GMSound> > _data, Stream _s, IFF _iff) { WriteDataKVP(_data, _s, _iff, delegate(KeyValuePair <string, GMSound> _kvp, Stream __s, IFF __iff, long __index) { __s.PatchOffset(__index); __iff.AddString(__s, _kvp.Key); GMSound value = _kvp.Value; string[] source = value.OrigName.Split('\\', '/', ':'); string text = Path.GetFileName(source.Last()); bool flag = true; while (flag) { flag = false; foreach (Wave ms_Wave in ms_Waves) { if (ms_Wave.FileName == text) { text = string.Format("{0}{1}{2}", Path.GetFileNameWithoutExtension(text), "_a", Path.GetExtension(text)); flag = true; } } } if (value.Data != null) { ms_Waves.Add(new Wave(_iff, value.Data, text)); } __s.WriteInteger(value.Kind); __iff.AddString(__s, value.Extension); __iff.AddString(__s, text); __s.WriteInteger(value.Effects); __s.WriteSingle((float)value.Volume); __s.WriteSingle((float)value.Pan); __s.WriteBoolean(value.Preload); __s.WriteInteger(ms_Waves.Count - 1); }); }
private static void WriteWaveforms(GMAssets _data, Stream _s, IFF _iff) { WriteDataList(ms_Waves, _s, _iff, delegate(Wave _wave, Stream __s, IFF __iff, long __index) { int num = 4; int num2 = num - 1; while ((__s.Position & num2) != 0) { __s.WriteByte(0); } __s.PatchOffset(__index); __s.WriteInteger(_wave.RawWavFile.Length); __s.Write(_wave.RawWavFile, 0, _wave.RawWavFile.Length); if (Program.WriteWaves && _wave.FileName.ToLower().EndsWith("wav")) { File.WriteAllBytes(Path.Combine(Program.OutputDir, Path.GetFileName(_wave.FileName)), _wave.RawWavFile); } }); Console.WriteLine("SILICA PATCH!"); int NumSounds = _data.Sounds.Count; for (int i = 0; i < NumSounds; i++) { // Console.WriteLine("Reading Sound: " + i.ToString()); if (_data.Sounds[i].ToString() == "[, ]") { continue; } KeyValuePair <string, GMSound> SoundPair = _data.Sounds[i]; GMSound Sound = SoundPair.Value; String OriginalName = Sound.OrigName; Console.WriteLine("Writing: " + OriginalName); String AudioFile = Path.Combine(Program.OutputDir, OriginalName); Console.WriteLine("Converting " + OriginalName + " To .WAV"); if (Path.GetExtension(OriginalName).ToLower() == ".mid" || Path.GetExtension(OriginalName).ToLower() == ".midi") { // File.WriteAllBytes(AudioFile, Sound.Data); MessageBox.Show("MIDI NOT SUPPORTED!\nPlease convert " + OriginalName + " to an MP3 File!", "MIDI", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (Path.GetExtension(OriginalName).ToLower() == ".mp3" || Path.GetExtension(OriginalName).ToLower() == ".wav") { if (Path.GetExtension(OriginalName).ToLower() == ".mp3") { MemoryStream Mp3Stream = new MemoryStream(Sound.Data); Mp3FileReader mp3 = new Mp3FileReader(Mp3Stream); WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3); WaveFileWriter.CreateWaveFile(Path.ChangeExtension(AudioFile, "wav"), pcm); pcm.Close(); mp3.Close(); pcm.Dispose(); mp3.Dispose(); //Convert to AT3 Process At3Tool = new Process(); At3Tool.StartInfo.FileName = Path.Combine(Application.StartupPath, "at3tool.exe"); At3Tool.StartInfo.CreateNoWindow = true; At3Tool.StartInfo.UseShellExecute = false; At3Tool.StartInfo.RedirectStandardOutput = true; At3Tool.StartInfo.RedirectStandardError = true; At3Tool.StartInfo.Arguments = "-e \"" + Path.ChangeExtension(AudioFile, "wav") + "\" \"" + Path.ChangeExtension(AudioFile, "at3") + "\""; Console.WriteLine(At3Tool.StartInfo.FileName + " " + At3Tool.StartInfo.Arguments); At3Tool.Start(); At3Tool.WaitForExit(); if (At3Tool.ExitCode != 0) { Console.WriteLine(At3Tool.StandardOutput.ReadToEnd() + At3Tool.StandardError.ReadToEnd()); return; } At3Tool.Dispose(); File.Delete(Path.ChangeExtension(AudioFile, "wav")); } /*else if(Path.GetExtension(OriginalName) == ".wav") * { * MemoryStream WavStream = new MemoryStream(Sound.Data); * WaveFileReader WavReader = new WaveFileReader(WavStream); * WaveFormat WavFormat = new WaveFormat(44100, 16, 2); * WaveFormatConversionStream conversionStream = new WaveFormatConversionStream(WavFormat, WavReader); * WaveFileWriter.CreateWaveFile(AudioFile, conversionStream); * * WavStream.Close(); * WavStream.Dispose(); * WavReader.Close(); * WavReader.Dispose(); * conversionStream.Close(); * conversionStream.Dispose(); * }*/ } } Console.WriteLine("Done"); }
private static void WriteWaveforms(GMAssets _data, Stream _s, IFF _iff) { IFFSaver.WriteDataList <Wave>(IFFSaver.ms_Waves, _s, _iff, delegate(Wave _wave, Stream __s, IFF __iff, long __index) { int num = 4; int num2 = num - 1; while ((__s.Position & (long)num2) != 0L) { __s.WriteByte(0); } __s.PatchOffset(__index); __s.WriteInteger(_wave.RawWavFile.Length); __s.Write(_wave.RawWavFile, 0, _wave.RawWavFile.Length); if (Program.WriteWaves && _wave.FileName.ToLower().EndsWith("wav")) { File.WriteAllBytes(Path.Combine(Program.OutputDir, Path.GetFileName(_wave.FileName)), _wave.RawWavFile); } }); Console.WriteLine("Converting to at3.."); int NumSounds = _data.Sounds.Count; for (int i = 0; i < NumSounds; i++) { if (!(_data.Sounds[i].ToString() == "[, ]")) { GMSound Sound = _data.Sounds[i].Value; string OriginalName = Sound.OrigName; string Extension = Path.GetExtension(Sound.OrigName); string AudioFile = Path.Combine(Program.OutputDir, OriginalName); if (Extension.ToLower() == ".mid" || Extension.ToLower() == ".midi") { Console.WriteLine("Converting " + OriginalName + " To .WAV"); File.WriteAllBytes(AudioFile, Sound.Data); Process FluidSynth = new Process(); FluidSynth.StartInfo.FileName = Path.Combine(Application.StartupPath, "fluidsynth.exe"); FluidSynth.StartInfo.WorkingDirectory = Application.StartupPath; FluidSynth.StartInfo.CreateNoWindow = true; FluidSynth.StartInfo.UseShellExecute = false; FluidSynth.StartInfo.RedirectStandardOutput = true; FluidSynth.StartInfo.RedirectStandardError = true; //Change "gm.sf2" to whatever soundfont you want. FluidSynth.StartInfo.Arguments = "-F \"" + Path.ChangeExtension(AudioFile, "wav") + "\" \"gm.sf2\" \"" + AudioFile + "\""; Console.WriteLine(FluidSynth.StartInfo.FileName + " " + FluidSynth.StartInfo.Arguments); FluidSynth.Start(); FluidSynth.WaitForExit(); if (FluidSynth.ExitCode != 0) { Console.WriteLine(FluidSynth.StandardOutput.ReadToEnd() + FluidSynth.StandardError.ReadToEnd()); return; } FluidSynth.Dispose(); } else if (Path.GetExtension(OriginalName).ToLower() == ".mp3") { Console.WriteLine("Converting " + OriginalName + " To .WAV"); MemoryStream Mp3Stream = new MemoryStream(Sound.Data); Mp3FileReader mp3 = new Mp3FileReader(Mp3Stream); WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3); WaveFileWriter.CreateWaveFile(Path.ChangeExtension(AudioFile, "wav"), pcm); pcm.Close(); mp3.Close(); pcm.Dispose(); mp3.Dispose(); } else { continue; } String OutputPath = Path.Combine(Program.OutputDir, "_iso_temp", "PSP_GAME", "USRDIR", Path.ChangeExtension(OriginalName, "at3")); Console.WriteLine("Output: " + OutputPath); Process At3Tool = new Process(); At3Tool.StartInfo.FileName = Path.Combine(Application.StartupPath, "at3tool.exe"); At3Tool.StartInfo.WorkingDirectory = Application.StartupPath; At3Tool.StartInfo.CreateNoWindow = true; At3Tool.StartInfo.UseShellExecute = false; At3Tool.StartInfo.RedirectStandardOutput = true; At3Tool.StartInfo.RedirectStandardError = true; At3Tool.StartInfo.Arguments = "-e \"" + Path.ChangeExtension(AudioFile, "wav") + "\" \"" + OutputPath + "\""; Console.WriteLine(At3Tool.StartInfo.FileName + " " + At3Tool.StartInfo.Arguments); At3Tool.Start(); At3Tool.WaitForExit(); if (At3Tool.ExitCode != 0) { Console.WriteLine(At3Tool.StandardOutput.ReadToEnd() + At3Tool.StandardError.ReadToEnd()); return; } At3Tool.Dispose(); if (File.Exists(AudioFile)) { File.Delete(AudioFile); } File.Delete(Path.ChangeExtension(AudioFile, "wav")); } } Console.WriteLine("Done"); }