private static void AddInfo(Config config, DLS dls) { var info = new ListChunk("INFO"); dls.Add(info); info.Add(new InfoSubChunk("INAM", config.Name)); //info.Add(new InfoSubChunk("ICOP", config.Creator)); info.Add(new InfoSubChunk("IENG", "Kermalis")); info.Add(new InfoSubChunk("ISFT", Util.Utils.ProgramName)); }
private static Dictionary <int, (WaveSampleChunk, int)> AddSamples(Config config, DLS dls) { ListChunk waves = dls.WavePool; var sampleDict = new Dictionary <int, (WaveSampleChunk, int)>((int)config.SampleTableSize); for (int i = 0; i < config.SampleTableSize; i++) { int ofs = config.Reader.ReadInt32(config.SampleTableOffset + (i * 4)); if (ofs == 0) { continue; // Skip null samples } ofs += config.SampleTableOffset; SampleHeader sh = config.Reader.ReadObject <SampleHeader>(ofs); // Create format chunk var fmt = new FormatChunk(WaveFormat.PCM); fmt.WaveInfo.Channels = 1; fmt.WaveInfo.SamplesPerSec = (uint)(sh.SampleRate >> 10); fmt.WaveInfo.AvgBytesPerSec = fmt.WaveInfo.SamplesPerSec; fmt.WaveInfo.BlockAlign = 1; fmt.FormatInfo.BitsPerSample = 8; // Create wave sample chunk and add loop if there is one var wsmp = new WaveSampleChunk { UnityNote = 60, Options = WaveSampleOptions.NoTruncation | WaveSampleOptions.NoCompression }; if (sh.DoesLoop == 0x40000000) { wsmp.Loop = new WaveSampleLoop { LoopStart = (uint)sh.LoopOffset, LoopLength = (uint)(sh.Length - sh.LoopOffset), LoopType = LoopType.Forward }; } // Get PCM sample byte[] pcm = new byte[sh.Length]; Array.Copy(config.ROM, ofs + 0x10, pcm, 0, sh.Length); // Add int dlsIndex = waves.Count; waves.Add(new ListChunk("wave") { fmt, wsmp, new DataChunk(pcm), new ListChunk("INFO") { new InfoSubChunk("INAM", $"Sample {i}") } }); sampleDict.Add(i, (wsmp, dlsIndex)); } return(sampleDict); }