Exemplo n.º 1
0
        static public RiffForm Load(string path)
        {
            RiffForm riff = default(RiffForm);

            using (Stream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) riff = Load(fs);
            return(riff);
        }
Exemplo n.º 2
0
        public static RiffForm Load(Stream fs)
        {
            RiffForm riff = new RiffForm();
            ChunkCollection cks = riff.Cks = new ChunkCollection();
            using (BinaryReader bread = new BinaryReader(fs))
            {
                cks.ckMain = new CHUNK(bread);
                cks.SubChunks = new Dictionary<long,SUBCHUNK>();

                if (cks.ckMain.ckID=="RIFF")
                {
                    while (fs.Position < fs.Length)
                    {
                        SUBCHUNK CX = new SUBCHUNK(bread);
                        long tpos = fs.Position - Marshal.SizeOf(CX);

                        cks.SubChunks.Add(tpos,CX);

                        if (CX.ckID != null)
                            switch (CX.ckID)
                        {
                            case "fmt ":
                                cks.ckFmt = IOHelper.ReadChunk<WaveFormat>(tpos,fs,bread);
                                break;
                            case "fact":
                            case "INFO":
                                cks.ckFact = IOHelper.ReadChunk<ChunkFact>(tpos,fs,bread);
                                break;
                            case "inst":
                                cks.ckInst = IOHelper.ReadChunk<_inst>(tpos,fs,bread);
                                break;
                            case "smpl":
                                cks.ckSmpl = IOHelper.ReadChunk<_smp>(tpos,fs,bread);
                                List<_smpLoop> bob = new List<_smpLoop>();
                                for (int i=0; i<cks.ckSmpl.smpSampleLoops; i++) bob.Add(new _smpLoop(bread));
                                // clear the list.
                                cks.ckSmpLoop = bob.ToArray();
                                bob.Clear();
                                bob = null;
                                break;
                            case "data":
                            case "JUNK":
                            case "PAD ":
                                System.Diagnostics.Debug.Print("Skipping Chunk: '{0}'\n",CX.ckID);
                                break;
                            default:
                                System.Diagnostics.Debug.Print("Unknown Chunk: '{0}'\n",CX.ckID);
            //								Console.Beep();
                                break;
                        }
                        fs.Seek(tpos+CX.ckLength+Marshal.SizeOf(CX),SeekOrigin.Begin);
                    }
                }
                bread.Close();
            }
            fs.Close();
            riff.Cks = cks;
            return riff;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Returns the Index where reading begins for a wave-sample (<see cref="RiffForm" />) in memory.
 /// </summary>
 /// <param name="riff">Our ram/riff-wave.</param>
 /// <returns>Index where reading begins</returns>
 public static int FindSampleStart(RiffForm riff)
 {
     int start = -1;
     //			if (!MustReadFromDisk)
     {
         foreach (KeyValuePair<long,SUBCHUNK> ck in riff.Cks.SubChunks)
         {
             if (ck.Value.ckID=="data")
                 start = Convert.ToInt32(ck.Key)+8;
         }
     }
     return start;
 }
Exemplo n.º 4
0
 public override void Dispose()
 {
     DisposeStream();
     if (RawWaveData!=null)
     {
         Array.Clear(RawWaveData, 0, RawWaveData.Length);
         RawWaveData = null;
     }
     this.wformat = null;
     this.WaveForm = null;
 }
Exemplo n.º 5
0
        void InitializeMemory(string path)
        {
            this.WaveForm = RiffForm.Load(path);
            this.wformat = RiffUtil.ToNAudio(this.WaveForm.Cks.ckFmt);

            sampleData_ChunkLength	= this.WaveForm["data"].ckLength;
            SampleData_SampleCount	= SampleData_ChunkLength / WaveFormat.Channels;
            sampleData_DataStart	= RiffUtil.FindSampleStart(this.WaveForm);

            RawWaveData = new byte[sampleData_ChunkLength];
            using (waveFileInputStream = new FileStream(
                this.FilePath,FileMode.Open,FileAccess.Read,FileShare.ReadWrite))
            {
                waveFileInputStream.Seek(sampleData_DataStart, SeekOrigin.Begin);
                waveFileInputStream.Read(RawWaveData,/*sampleData_DataStart*/0,SampleData_ChunkLength);
            }
        }
Exemplo n.º 6
0
        static public RiffForm Load(Stream fs)
        {
            RiffForm        riff = new RiffForm();
            ChunkCollection cks  = riff.Cks = new ChunkCollection();

            using (BinaryReader bread = new BinaryReader(fs))
            {
                cks.ckMain    = new CHUNK(bread);
                cks.SubChunks = new Dictionary <long, SUBCHUNK>();

                if (cks.ckMain.ckID == "RIFF")
                {
                    while (fs.Position < fs.Length)
                    {
                        SUBCHUNK CX   = new SUBCHUNK(bread);
                        long     tpos = fs.Position - Marshal.SizeOf(CX);

                        cks.SubChunks.Add(tpos, CX);

                        if (CX.ckID != null)
                        {
                            switch (CX.ckID)
                            {
                            case "fmt ":
                                cks.ckFmt = IOHelper.ReadChunk <WaveFormat>(tpos, fs, bread);
                                break;

                            case "fact":
                            case "INFO":
                                cks.ckFact = IOHelper.ReadChunk <ChunkFact>(tpos, fs, bread);
                                break;

                            case "inst":
                                cks.ckInst = IOHelper.ReadChunk <_inst>(tpos, fs, bread);
                                break;

                            case "smpl":
                                cks.ckSmpl = IOHelper.ReadChunk <_smp>(tpos, fs, bread);
                                List <_smpLoop> bob = new List <_smpLoop>();
                                for (int i = 0; i < cks.ckSmpl.smpSampleLoops; i++)
                                {
                                    bob.Add(new _smpLoop(bread));
                                }
                                // clear the list.
                                cks.ckSmpLoop = bob.ToArray();
                                bob.Clear();
                                bob = null;
                                break;

                            case "data":
                            case "JUNK":
                            case "PAD ":
                                System.Diagnostics.Debug.Print("Skipping Chunk: '{0}'\n", CX.ckID);
                                break;

                            default:
                                System.Diagnostics.Debug.Print("Unknown Chunk: '{0}'\n", CX.ckID);
//								Console.Beep();
                                break;
                            }
                        }
                        fs.Seek(tpos + CX.ckLength + Marshal.SizeOf(CX), SeekOrigin.Begin);
                    }
                }
                bread.Close();
            }
            fs.Close();
            riff.Cks = cks;
            return(riff);
        }