public SoundChunkController(NSFController nsfcontroller, SoundChunk soundchunk) : base(nsfcontroller, soundchunk) { this.soundchunk = soundchunk; Node.Text = "Sound Chunk"; Node.ImageKey = "soundchunk"; Node.SelectedImageKey = "soundchunk"; }
private void Menu_Add_SoundChunk() { SoundChunk chunk = new SoundChunk(); nsf.Chunks.Add(chunk); SoundChunkController controller = new SoundChunkController(this, chunk); AddNode(controller); }
internal void UpdateSize() { if (InfoChunk == null || SoundChunk == null || HydraChunk == null) { return; } _size = 4 + InfoChunk.UpdateSize() + 8 + SoundChunk.UpdateSize() + 8 + HydraChunk.UpdateSize() + 8; }
public void Save(string path) { using (var writer = new EndianBinaryWriter(File.Open(path, FileMode.Create))) { AddTerminals(); writer.Write("RIFF", 4); writer.Write(_size); writer.Write("sfbk", 4); InfoChunk.Write(writer); SoundChunk.Write(writer); HydraChunk.Write(writer); } }
private void FixSoundReference_PitchRange(int originalIndex, int count, IWriter buffer) { for (int i = 0; i < count; i++) { var pRange = _container.FindSoundPitchRange(originalIndex + i); int newIndex; if (!_soundPitchRanges.TryGetValue(pRange, out newIndex)) { newIndex = _soundResources.PitchRanges.Count; SoundPitchRange newPRange = new SoundPitchRange(); newPRange.Name = InjectSoundStringID(pRange.Name); newPRange.Parameter = pRange.Parameter; newPRange.HasEncodedData = pRange.HasEncodedData; newPRange.RequiredPermutationCount = pRange.RequiredPermutationCount; var permutations = new List <SoundPermutation>(); foreach (var perm in pRange.Permutations) { SoundPermutation newPerm = new SoundPermutation(); newPerm.Name = InjectSoundStringID(perm.Name); newPerm.EncodedSkipFraction = perm.EncodedSkipFraction; newPerm.EncodedGain = perm.EncodedGain; newPerm.EncodedPermutationInfoIndex = perm.EncodedPermutationInfoIndex; newPerm.SampleSize = perm.SampleSize; newPerm.FSBInfo = perm.FSBInfo; var chunks = new List <SoundChunk>(); foreach (var chunk in perm.Chunks) { SoundChunk src = chunk.Source; src.FModBankSuffix = InjectSoundStringID(chunk.FModBankSuffix); chunks.Add(src); } if (perm.Languages != null) { var languages = new List <SoundPermutationLanguage>(); foreach (var lang in perm.Languages) { var newPL = new SoundPermutationLanguage(); newPL.LanguageIndex = lang.LanguageIndex; newPL.SampleSize = lang.SampleSize; if (lang.Chunks != null && lang.Chunks.Count > 0) { var lChunks = new List <SoundChunk>(); foreach (var chunk in lang.Chunks) { SoundChunk src = chunk.Source; src.FModBankSuffix = InjectSoundStringID(chunk.FModBankSuffix); lChunks.Add(src); } newPL.Chunks = lChunks.ToArray(); } } newPerm.Languages = languages.ToArray(); } if (perm.LayerMarkers != null) { newPerm.LayerMarkers = perm.LayerMarkers.ToArray(); } newPerm.Chunks = chunks.ToArray(); permutations.Add(newPerm); } newPRange.Permutations = permutations.ToArray(); _soundResources.PitchRanges.Add(newPRange); _soundPitchRanges[pRange] = newIndex; } if (i == 0) { var test = _soundLayout.GetFieldOffset("first pitch range index"); buffer.SeekTo(test); buffer.WriteInt16((short)newIndex); } } }
private static ExtractedSoundPitchRange ReadSoundPitchRange(IReader reader, byte version) { if (version > 1) { throw new InvalidOperationException("Unrecognized \"snpr\" block version"); } int originalIndex = reader.ReadInt32(); string name = reader.ReadAscii(); SoundPitchRangeParameter param = null; if (reader.ReadByte() == 1) { param = new SoundPitchRangeParameter(); param.NaturalPitch = reader.ReadInt32(); param.BendMin = reader.ReadInt32(); param.BendMax = reader.ReadInt32(); param.MaxGainPitchMin = reader.ReadInt32(); param.MaxGainPitchMax = reader.ReadInt32(); param.PlaybackPitchMin = reader.ReadInt32(); param.PlaybackPitchMax = reader.ReadInt32(); if (reader.ReadByte() == 1) { SoundPitchRangeDistance dist = new SoundPitchRangeDistance(); dist.DontPlayDistance = reader.ReadFloat(); dist.AttackDistance = reader.ReadFloat(); dist.MinDistance = reader.ReadFloat(); dist.MaxDistance = reader.ReadFloat(); param.Distance = dist; } } bool hasdata = (reader.ReadByte() == 1); int reqcount = reader.ReadInt32(); System.Collections.Generic.List <ExtractedSoundPermutation> perms = new System.Collections.Generic.List <ExtractedSoundPermutation>(); int permcount = reader.ReadInt32(); for (int p = 0; p < permcount; p++) { ExtractedSoundPermutation perm = new ExtractedSoundPermutation(); perm.Name = reader.ReadAscii(); perm.EncodedSkipFraction = reader.ReadInt32(); perm.SampleSize = reader.ReadInt32(); perm.EncodedGain = reader.ReadInt32(); perm.EncodedPermutationInfoIndex = reader.ReadInt32(); perm.FSBInfo = reader.ReadInt32(); int chunkcount = reader.ReadInt32(); perm.Chunks = new System.Collections.Generic.List <ExtractedSoundChunk>(); for (int c = 0; c < chunkcount; c++) { SoundChunk chunk = new SoundChunk(); chunk.FileOffset = reader.ReadInt32(); chunk.EncodedSizeAndFlags = reader.ReadInt32(); chunk.CacheIndex = reader.ReadInt32(); chunk.XMA2BufferStart = reader.ReadInt32(); chunk.XMA2BufferEnd = reader.ReadInt32(); chunk.Unknown = reader.ReadInt32(); chunk.Unknown1 = reader.ReadInt32(); string bankSuffix = null; if (version >= 1) { bankSuffix = reader.ReadAscii(); } perm.Chunks.Add(new ExtractedSoundChunk(chunk, bankSuffix)); } int langcount = reader.ReadInt32(); perm.Languages = new System.Collections.Generic.List <ExtractedSoundLanguagePermutation>(); for (int l = 0; l < langcount; l++) { ExtractedSoundLanguagePermutation lang = new ExtractedSoundLanguagePermutation(); lang.LanguageIndex = reader.ReadInt32(); lang.SampleSize = reader.ReadInt32(); int lchunkcount = reader.ReadInt32(); lang.Chunks = new System.Collections.Generic.List <ExtractedSoundChunk>(); for (int c = 0; c < lchunkcount; c++) { SoundChunk chunk = new SoundChunk(); chunk.FileOffset = reader.ReadInt32(); chunk.EncodedSizeAndFlags = reader.ReadInt32(); chunk.CacheIndex = reader.ReadInt32(); chunk.XMA2BufferStart = reader.ReadInt32(); chunk.XMA2BufferEnd = reader.ReadInt32(); chunk.Unknown = reader.ReadInt32(); chunk.Unknown1 = reader.ReadInt32(); string bankSuffix = null; if (version >= 1) { bankSuffix = reader.ReadAscii(); } lang.Chunks.Add(new ExtractedSoundChunk(chunk, bankSuffix)); } perm.Languages.Add(lang); } int markercount = reader.ReadInt32(); perm.LayerMarkers = new System.Collections.Generic.List <int>(); for (int m = 0; m < markercount; m++) { perm.LayerMarkers.Add(reader.ReadInt32()); } perms.Add(perm); } return(new ExtractedSoundPitchRange(originalIndex, name, param, hasdata, reqcount, perms)); }
public ExtractedSoundChunk(SoundChunk src) { Source = src; }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) { return; } Bundle b = sb.bundles[n]; listBox2.Items.Clear(); sounds = new List <SoundWaveAssetEntry>(); for (int i = 0; i < b.ebx.Count; i++) { Bundle.ebxtype ebx = b.ebx[i]; try { string x = Encoding.UTF8.GetString(Tools.ExtractEbx(new MemoryStream(Tools.GetDataBySHA1(ebx.SHA1, cat)))); XmlDocument xml = new XmlDocument(); xml.LoadXml("<xml>" + x + "</xml>"); XmlNodeList list = xml.GetElementsByTagName("SoundWaveAsset"); foreach (XmlNode node in list) { SoundWaveAssetEntry sound = new SoundWaveAssetEntry(); sound.chunks = new List <SoundChunk>(); sound.segments = new List <SoundSegment>(); sound.Index = i; if (node.Name == "SoundWaveAsset") { foreach (XmlNode node2 in node.ChildNodes) { switch (node2.Name) { case "SoundDataAsset": foreach (XmlNode node3 in node2.ChildNodes) { switch (node3.Name) { case "Asset": foreach (XmlNode node4 in node3.ChildNodes) { switch (node4.Name) { case "Name": sound.name = node4.InnerText; break; } } break; case "Chunks": XmlNode members = node3.ChildNodes[0]; if (members == null) { continue; } foreach (XmlNode node4 in members) { switch (node4.Name) { case "SoundDataChunk": SoundChunk chunk = new SoundChunk(); XmlNode nId = node4.ChildNodes[0]; chunk.id = Tools.StringToByteArray(nId.InnerText); foreach (CATFile.ChunkType c in cat.chunks) { if (Tools.ByteArrayCompare(c.id, chunk.id)) { chunk.sha1 = c.sha1; } } sound.chunks.Add(chunk); break; } } break; } } break; case "Segments": foreach (XmlNode node3 in node2.ChildNodes) { switch (node3.Name) { case "member": XmlNode swvseg = node3.ChildNodes[0]; if (swvseg != null && swvseg.Name == "SoundWaveVariationSegment") { SoundSegment seg = new SoundSegment(); XmlNode offset = swvseg.ChildNodes[0]; seg.offset = Convert.ToInt32(offset.InnerText, 16); sound.segments.Add(seg); } break; } } break; } } } sounds.Add(sound); } } catch (Exception) { } } foreach (SoundWaveAssetEntry sound in sounds) { listBox2.Items.Add(sound.name); } }
public ExtractedSoundChunk(SoundChunk src, string bankSuffix) { Source = src; FModBankSuffix = bankSuffix == null ? "" : bankSuffix; }
private SoundWaveAssetEntry GetSoundData(byte[] data, SQLiteConnection con) { string x = Encoding.UTF8.GetString(Tools.ExtractEbx(new MemoryStream(data))); XmlDocument xml = new XmlDocument(); xml.LoadXml("<xml>" + x + "</xml>"); XmlNodeList list = xml.GetElementsByTagName("SoundWaveAsset"); XmlNode node = list[0]; SoundWaveAssetEntry sound = new SoundWaveAssetEntry(); sound.chunks = new List <SoundChunk>(); sound.segments = new List <SoundSegment>(); if (node.Name == "SoundWaveAsset") { foreach (XmlNode node2 in node.ChildNodes) { switch (node2.Name) { case "SoundDataAsset": foreach (XmlNode node3 in node2.ChildNodes) { switch (node3.Name) { case "Asset": foreach (XmlNode node4 in node3.ChildNodes) { switch (node4.Name) { case "Name": sound.name = node4.InnerText; break; } } break; case "Chunks": XmlNode members = node3.ChildNodes[0]; if (members == null) { continue; } foreach (XmlNode node4 in members) { switch (node4.Name) { case "SoundDataChunk": SoundChunk chunk = new SoundChunk(); XmlNode nId = node4.ChildNodes[0]; chunk.id = Tools.StringToByteArray(nId.InnerText); SQLiteDataReader reader = Database.getReader("SELECT sha1 FROM chunkids WHERE id='" + nId.InnerText + "'", con); if (reader.Read()) { chunk.sha1 = reader.GetString(0); } sound.chunks.Add(chunk); break; } } break; } } break; case "Segments": foreach (XmlNode node3 in node2.ChildNodes) { switch (node3.Name) { case "member": XmlNode swvseg = node3.ChildNodes[0]; if (swvseg != null && swvseg.Name == "SoundWaveVariationSegment") { SoundSegment seg = new SoundSegment(); XmlNode offset = swvseg.ChildNodes[0]; seg.offset = Convert.ToInt32(offset.InnerText, 16); sound.segments.Add(seg); } break; } } break; } } } return(sound); }