// Process a RIFF list element (list sub elements)
        public static void ProcessList(RiffParser rp, int FourCC, int length)
        {
            string type = RiffParser.FromFourCC(FourCC);

            Console.WriteLine("Found list element of type \"" + type + "\" and length " + length.ToString());

            // Define the processing delegates
            RiffParser.ProcessChunkElement pc = new RiffParser.ProcessChunkElement(ProcessChunk);
            RiffParser.ProcessListElement  pl = new RiffParser.ProcessListElement(ProcessList);

            // Read all the elements in the current list
            try {
                while (length > 0)
                {
                    // Prefix each line with the type of the current list
                    Console.Write(type + " (" + length.ToString() + "): ");
                    // Get the next element (if there is one)
                    if (false == rp.ReadElement(ref length, pc, pl))
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem: " + ex.ToString());
            }
        }
        // Parse a RIFF file
        static void Main(string[] args)
        {
            // Create a parser instance
            RiffParser rp = new RiffParser();

            try
            {
                string filename = @"C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Graphics\videos\BLUR24.avi";
                //string filename = @"C:\WINNT\Media\Chimes.wav"
                if (0 != args.Length)
                {
                    filename = args[0];
                }

                // Specify a file to open
                rp.OpenFile(filename);

                // If we got here - the file is valid. Output information about the file
                Console.WriteLine("File " + rp.ShortName + " is a \"" + RiffParser.FromFourCC(rp.FileRIFF)
                                  + "\" with a specific type of \"" + RiffParser.FromFourCC(rp.FileType) + "\"");

                // Store the size to loop on the elements
                int size = rp.DataSize;

                // Define the processing delegates
                RiffParser.ProcessChunkElement pc = new RiffParser.ProcessChunkElement(ProcessChunk);
                RiffParser.ProcessListElement  pl = new RiffParser.ProcessListElement(ProcessList);

                // Read all top level elements and chunks
                while (size > 0)
                {
                    // Prefix the line with the current top level type
                    Console.Write(RiffParser.FromFourCC(rp.FileType) + " (" + size.ToString() + "): ");
                    // Get the next element (if there is one)
                    if (false == rp.ReadElement(ref size, pc, pl))
                    {
                        break;
                    }
                }
                // Close the stream
                rp.CloseFile();
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("-----------------");
                Console.WriteLine("Problem: " + ex.ToString());
            }
            Console.WriteLine("\n\rDone. Press 'Enter' to exit.");
            Console.ReadLine();
        }
        public void ProcessMainWAVE()
        {
            Clear();
            int length = Parser.DataSize;

            RiffParser.ProcessChunkElement pdc = ProcessWaveChunk;
            RiffParser.ProcessListElement  pal = ProcessList;

            while (length > 0)
            {
                if (false == Parser.ReadElement(ref length, pdc, pal))
                {
                    break;
                }
            }
        }
示例#4
0
        public void ProcessMainAVI()
        {
            Clear();
            int length = Parser.DataSize;

            RiffParser.ProcessChunkElement pdc = new RiffParser.ProcessChunkElement(ProcessAVIChunk);
            RiffParser.ProcessListElement  pal = new RiffParser.ProcessListElement(ProcessAVIList);

            while (length > 0)
            {
                if (false == Parser.ReadElement(ref length, pdc, pal))
                {
                    break;
                }
            }
        }
示例#5
0
        public async void CheckFile()
        {
            StorageFolder storageFolder = KnownFolders.MusicLibrary;
            var           checkFile     = await storageFolder.TryGetItemAsync(this.Recorder.FileName);

            if (checkFile == null)
            {
                this.Info.Text = "Wav not recorded ...";
            }
            else
            {
                StorageFile storageFile = await storageFolder.GetFileAsync(this.Recorder.FileName);

                var parser = new RiffParser();

                // read file
                await Windows.System.Threading.ThreadPool.RunAsync(
                    async (workItem) =>
                {
                    IRandomAccessStream stream = await storageFile.OpenAsync(FileAccessMode.Read);
                    Stream sstream             = stream.AsStream();
                    parser.OpenFile(sstream);
                    // Define the processing delegates
                    RiffParser.ProcessChunkElement pc = ProcessChunk;

                    // Read all top level elements and chunks
                    int size = parser.DataSize;
                    while (size > 0)
                    {
                        // Prefix the line with the current top level type
                        var info = (RiffParser.FromFourCC(parser.FileType) + " (" + size.ToString() + "): ");
                        // Get the next element (if there is one)
                        if (false == parser.ReadElement(ref size, pc, null))
                        {
                            break;
                        }
                    }

                    // Close the stream
                    parser.CloseFile();
                });
            }
        }
示例#6
0
        /// <summary>
        /// Handle List elements found in the AVI file. Ignores unknown lists and recursively looks
        /// at the content of known lists.
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="fourCc"></param>
        /// <param name="length"></param>
        private void ProcessAviList(RiffParser rp, int fourCc, int length)
        {
            RiffParser.ProcessChunkElement pac = ProcessAviChunk;
            RiffParser.ProcessListElement  pal = ProcessAviList;

            // Is this the header?
            if (AviRiffData.AviHeaderList == fourCc || AviRiffData.AviStreamList == fourCc || AviRiffData.InfoList == fourCc)
            {
                while (length > 0)
                {
                    if (false == rp.ReadElement(ref length, pac, pal))
                    {
                        break;
                    }
                }
            }
            else
            {
                rp.SkipData(length); // Unknown lists - ignore
            }
        }
        /// <summary>
        /// Handle List elements found in the AVI file. Ignores unknown lists and recursively looks
        /// at the content of known lists.
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="FourCC"></param>
        /// <param name="length"></param>
        private void ProcessAVIList(RiffParser rp, int FourCC, int length)
        {
            RiffParser.ProcessChunkElement pac = ProcessAVIChunk;
            RiffParser.ProcessListElement  pal = ProcessAVIList;

            // Is this the header?
            if ((AviRiffData.ckidAVIHeaderList == FourCC) ||
                (AviRiffData.ckidAVIStreamList == FourCC) ||
                (AviRiffData.ckidINFOList == FourCC))
            {
                while (length > 0)
                {
                    if (false == rp.ReadElement(ref length, pac, pal))
                    {
                        break;
                    }
                }
            }
            else
            {
                // Unknown lists - ignore
                rp.SkipData(length);
            }
        }
        public void ProcessMainWAVE()
        {
            Clear();
            int length = Parser.DataSize;

            RiffParser.ProcessChunkElement pdc = new RiffParser.ProcessChunkElement(ProcessWaveChunk);
            RiffParser.ProcessListElement pal = new RiffParser.ProcessListElement(ProcessList);

            while (length > 0)
            {
                if (false == Parser.ReadElement(ref length, pdc, pal)) break;
            }
        }
        /// <summary>
        /// Handle List elements found in the AVI file. Ignores unknown lists and recursively looks
        /// at the content of known lists.
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="FourCC"></param>
        /// <param name="length"></param>
        private void ProcessAVIList(RiffParser rp, int FourCC, int length)
        {
            RiffParser.ProcessChunkElement pac = new RiffParser.ProcessChunkElement(ProcessAVIChunk);
            RiffParser.ProcessListElement pal = new RiffParser.ProcessListElement(ProcessAVIList);

            // Is this the header?
            if ((AviRiffData.ckidAVIHeaderList == FourCC)
                || (AviRiffData.ckidAVIStreamList == FourCC)
                || (AviRiffData.ckidINFOList == FourCC))
            {
                while (length > 0)
                {
                    if (false == rp.ReadElement(ref length, pac, pal)) break;
                }
            }
            else
            {
                // Unknown lists - ignore
                rp.SkipData(length);
            }
        }