/// <summary> /// Loads a SoundFont from a stream /// </summary> /// <param name="sfFile">stream</param> public SoundFont(Stream sfFile) { using (sfFile) // a bit ugly, done to get Win store to compile { RiffChunk riff = RiffChunk.GetTopLevelChunk(new BinaryReader(sfFile)); if (riff.ChunkID == "RIFF") { string formHeader = riff.ReadChunkID(); if (formHeader != "sfbk") { throw new InvalidDataException(String.Format("Not a SoundFont ({0})", formHeader)); } RiffChunk list = riff.GetNextSubChunk(); if (list.ChunkID == "LIST") { //RiffChunk r = list.GetNextSubChunk(); info = new InfoChunk(list); RiffChunk r = riff.GetNextSubChunk(); sampleData = new SampleDataChunk(r); r = riff.GetNextSubChunk(); presetsChunk = new PresetsChunk(r); } else { throw new InvalidDataException(String.Format("Not info list found ({0})", list.ChunkID)); } } else { throw new InvalidDataException("Not a RIFF file"); } } }
/// <summary> /// Loads a SoundFont from a file /// </summary> /// <param name="fileName">Filename of the SoundFont</param> public SoundFont(string fileName) { using (FileStream sfFile = new FileStream(fileName,FileMode.Open,FileAccess.Read)) { RiffChunk riff = RiffChunk.GetTopLevelChunk(new BinaryReader(sfFile)); if(riff.ChunkID == "RIFF") { string formHeader = riff.ReadChunkID(); if(formHeader != "sfbk") { throw new ApplicationException(String.Format("Not a SoundFont ({0})",formHeader)); } RiffChunk list = riff.GetNextSubChunk(); if(list.ChunkID == "LIST") { //RiffChunk r = list.GetNextSubChunk(); info = new InfoChunk(list); RiffChunk r = riff.GetNextSubChunk(); sampleData = new SampleDataChunk(r); r = riff.GetNextSubChunk(); presetsChunk = new PresetsChunk(r); } else { throw new ApplicationException(String.Format("Not info list found ({0})",list.ChunkID)); } } else { throw new ApplicationException("Not a RIFF file"); } } }
/// <summary> /// Loads a SoundFont from a stream /// </summary> /// <param name="sfFile">stream</param> public SoundFont(Stream sfFile) { using(sfFile) // a bit ugly, done to get Win store to compile { RiffChunk riff = RiffChunk.GetTopLevelChunk(new BinaryReader(sfFile)); if(riff.ChunkID == "RIFF") { string formHeader = riff.ReadChunkID(); if(formHeader != "sfbk") { throw new InvalidDataException(String.Format("Not a SoundFont ({0})",formHeader)); } RiffChunk list = riff.GetNextSubChunk(); if(list.ChunkID == "LIST") { //RiffChunk r = list.GetNextSubChunk(); info = new InfoChunk(list); RiffChunk r = riff.GetNextSubChunk(); sampleData = new SampleDataChunk(r); r = riff.GetNextSubChunk(); presetsChunk = new PresetsChunk(r); } else { throw new InvalidDataException(String.Format("Not info list found ({0})", list.ChunkID)); } } else { throw new InvalidDataException("Not a RIFF file"); } } }
/// <summary> /// Loads a SoundFont from a file /// </summary> /// <param name="fileName">Filename of the SoundFont</param> public SoundFont(string fileName) { using (FileStream sfFile = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { RiffChunk riff = RiffChunk.GetTopLevelChunk(new BinaryReader(sfFile)); if (riff.ChunkID == "RIFF") { string formHeader = riff.ReadChunkID(); if (formHeader != "sfbk") { throw new ApplicationException(String.Format("Not a SoundFont ({0})", formHeader)); } RiffChunk list = riff.GetNextSubChunk(); if (list.ChunkID == "LIST") { //RiffChunk r = list.GetNextSubChunk(); info = new InfoChunk(list); RiffChunk r = riff.GetNextSubChunk(); sampleData = new SampleDataChunk(r); r = riff.GetNextSubChunk(); presetsChunk = new PresetsChunk(r); } else { throw new ApplicationException(String.Format("Not info list found ({0})", list.ChunkID)); } } else { throw new ApplicationException("Not a RIFF file"); } } }