public SampleDataChunk(RiffChunk chunk) { string header = chunk.ReadChunkID(); if (header != "sdta") { throw new ApplicationException(String.Format("Not a sample data chunk ({0})", header)); } sampleData = chunk.GetData(); }
public SampleDataChunk(RiffChunk chunk) { string header = chunk.ReadChunkID(); if (header != "sdta") { throw new ApplicationException(String.Format("Not a sample data chunk ({0})", header)); } sampleData = chunk.GetData(); }
/// <summary> /// creates a new riffchunk from current position checking that we're not /// at the end of this chunk first /// </summary> /// <returns>the new chunk</returns> public RiffChunk GetNextSubChunk() { if (riffFile.BaseStream.Position + 8 < dataOffset + chunkSize) { var chunk = new RiffChunk(riffFile); chunk.ReadChunk(); return(chunk); } //Console.WriteLine("DEBUG Failed to GetNextSubChunk because Position is {0}, dataOffset{1}, chunkSize {2}",riffFile.BaseStream.Position,dataOffset,chunkSize); return(null); }
internal PresetsChunk(RiffChunk chunk) { string header = chunk.ReadChunkID(); if (header != "pdta") { throw new ApplicationException(String.Format("Not a presets data chunk ({0})", header)); } RiffChunk c; while ((c = chunk.GetNextSubChunk()) != null) { switch (c.ChunkID) { case "PHDR": case "phdr": c.GetDataAsStructureArray(presetHeaders); break; case "PBAG": case "pbag": c.GetDataAsStructureArray(presetZones); break; case "PMOD": case "pmod": c.GetDataAsStructureArray(presetZoneModulators); break; case "PGEN": case "pgen": c.GetDataAsStructureArray(presetZoneGenerators); break; case "INST": case "inst": c.GetDataAsStructureArray(instruments); break; case "IBAG": case "ibag": c.GetDataAsStructureArray(instrumentZones); break; case "IMOD": case "imod": c.GetDataAsStructureArray(instrumentZoneModulators); break; case "IGEN": case "igen": c.GetDataAsStructureArray(instrumentZoneGenerators); break; case "SHDR": case "shdr": c.GetDataAsStructureArray(sampleHeaders); break; default: throw new ApplicationException(String.Format("Unknown chunk type {0}", c.ChunkID)); } } // now link things up instrumentZoneGenerators.Load(sampleHeaders.SampleHeaders); instrumentZones.Load(instrumentZoneModulators.Modulators, instrumentZoneGenerators.Generators); instruments.LoadZones(instrumentZones.Zones); presetZoneGenerators.Load(instruments.Instruments); presetZones.Load(presetZoneModulators.Modulators, presetZoneGenerators.Generators); presetHeaders.LoadZones(presetZones.Zones); sampleHeaders.RemoveEOS(); }
/// <summary> /// creates a new riffchunk from current position checking that we're not /// at the end of this chunk first /// </summary> /// <returns>the new chunk</returns> public RiffChunk GetNextSubChunk() { if (riffFile.BaseStream.Position + 8 < dataOffset + chunkSize) { var chunk = new RiffChunk(riffFile); chunk.ReadChunk(); return chunk; } //Console.WriteLine("DEBUG Failed to GetNextSubChunk because Position is {0}, dataOffset{1}, chunkSize {2}",riffFile.BaseStream.Position,dataOffset,chunkSize); return null; }
public static RiffChunk GetTopLevelChunk(BinaryReader file) { var r = new RiffChunk(file); r.ReadChunk(); return r; }
internal PresetsChunk(RiffChunk chunk) { string header = chunk.ReadChunkID(); if (header != "pdta") { throw new ApplicationException(String.Format("Not a presets data chunk ({0})", header)); } RiffChunk c; while ((c = chunk.GetNextSubChunk()) != null) { switch (c.ChunkID) { case "PHDR": case "phdr": c.GetDataAsStructureArray(presetHeaders); break; case "PBAG": case "pbag": c.GetDataAsStructureArray(presetZones); break; case "PMOD": case "pmod": c.GetDataAsStructureArray(presetZoneModulators); break; case "PGEN": case "pgen": c.GetDataAsStructureArray(presetZoneGenerators); break; case "INST": case "inst": c.GetDataAsStructureArray(instruments); break; case "IBAG": case "ibag": c.GetDataAsStructureArray(instrumentZones); break; case "IMOD": case "imod": c.GetDataAsStructureArray(instrumentZoneModulators); break; case "IGEN": case "igen": c.GetDataAsStructureArray(instrumentZoneGenerators); break; case "SHDR": case "shdr": c.GetDataAsStructureArray(sampleHeaders); break; default: throw new ApplicationException(String.Format("Unknown chunk type {0}", c.ChunkID)); } } // now link things up instrumentZoneGenerators.Load(sampleHeaders.SampleHeaders); instrumentZones.Load(instrumentZoneModulators.Modulators, instrumentZoneGenerators.Generators); instruments.LoadZones(instrumentZones.Zones); presetZoneGenerators.Load(instruments.Instruments); presetZones.Load(presetZoneModulators.Modulators, presetZoneGenerators.Generators); presetHeaders.LoadZones(presetZones.Zones); sampleHeaders.RemoveEOS(); }
internal InfoChunk(RiffChunk chunk) { bool ifilPresent = false; bool isngPresent = false; bool INAMPresent = false; if (chunk.ReadChunkID() != "INFO") { throw new ApplicationException("Not an INFO chunk"); } //this.chunk = chunk; RiffChunk c; while ((c = chunk.GetNextSubChunk()) != null) { switch (c.ChunkID) { case "ifil": ifilPresent = true; verSoundFont = (SFVersion) c.GetDataAsStructure(new SFVersionBuilder()); break; case "isng": isngPresent = true; WaveTableSoundEngine = c.GetDataAsString(); break; case "INAM": INAMPresent = true; BankName = c.GetDataAsString(); break; case "irom": DataROM = c.GetDataAsString(); break; case "iver": ROMVersion = (SFVersion) c.GetDataAsStructure(new SFVersionBuilder()); break; case "ICRD": CreationDate = c.GetDataAsString(); break; case "IENG": Author = c.GetDataAsString(); break; case "IPRD": TargetProduct = c.GetDataAsString(); break; case "ICOP": Copyright = c.GetDataAsString(); break; case "ICMT": Comments = c.GetDataAsString(); break; case "ISFT": Tools = c.GetDataAsString(); break; default: throw new ApplicationException(String.Format("Unknown chunk type {0}", c.ChunkID)); } } if (!ifilPresent) { throw new ApplicationException("Missing SoundFont version information"); } if (!isngPresent) { throw new ApplicationException("Missing wavetable sound engine information"); } if (!INAMPresent) { throw new ApplicationException("Missing SoundFont name information"); } }
internal InfoChunk(RiffChunk chunk) { bool ifilPresent = false; bool isngPresent = false; bool INAMPresent = false; if (chunk.ReadChunkID() != "INFO") { throw new ApplicationException("Not an INFO chunk"); } //this.chunk = chunk; RiffChunk c; while ((c = chunk.GetNextSubChunk()) != null) { switch (c.ChunkID) { case "ifil": ifilPresent = true; verSoundFont = (SFVersion)c.GetDataAsStructure(new SFVersionBuilder()); break; case "isng": isngPresent = true; WaveTableSoundEngine = c.GetDataAsString(); break; case "INAM": INAMPresent = true; BankName = c.GetDataAsString(); break; case "irom": DataROM = c.GetDataAsString(); break; case "iver": ROMVersion = (SFVersion)c.GetDataAsStructure(new SFVersionBuilder()); break; case "ICRD": CreationDate = c.GetDataAsString(); break; case "IENG": Author = c.GetDataAsString(); break; case "IPRD": TargetProduct = c.GetDataAsString(); break; case "ICOP": Copyright = c.GetDataAsString(); break; case "ICMT": Comments = c.GetDataAsString(); break; case "ISFT": Tools = c.GetDataAsString(); break; default: throw new ApplicationException(String.Format("Unknown chunk type {0}", c.ChunkID)); } } if (!ifilPresent) { throw new ApplicationException("Missing SoundFont version information"); } if (!isngPresent) { throw new ApplicationException("Missing wavetable sound engine information"); } if (!INAMPresent) { throw new ApplicationException("Missing SoundFont name information"); } }