Exemple #1
0
		/// <summary>
		/// Loads a SoundFont from a file
		/// </summary>
		/// <param name="fileName">Filename of the SoundFont</param>
		public SoundFont(string fileName)
		{
			using (var 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");
				}
			}
		}
Exemple #2
0
        /// <summary>
        /// Loads a SoundFont from a file
        /// </summary>
        /// <param name="fileName">Filename of the SoundFont</param>
        public SoundFont(string fileName)
        {
            using (var 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");
                }
            }
        }