//fmtChunk ReadFormatHeader() - 2004 July 28
        //Again, not much to say.
        public fmtChunk ReadFormatHeader()
        {
            format = new fmtChunk();

            format.sChunkID         = "fmt ";
            format.dwChunkSize      = reader.ReadUInt32();
            format.wFormatTag       = reader.ReadUInt16();
            format.wChannels        = reader.ReadUInt16();
            format.dwSamplesPerSec  = reader.ReadUInt32();
            format.dwAvgBytesPerSec = reader.ReadUInt32();
            format.wBlockAlign      = reader.ReadUInt16();
            format.dwBitsPerSample  = reader.ReadUInt32();
            return(format);
        }
Ejemplo n.º 2
0
        //fmtChunk ReadFormatHeader() - 2004 July 28
        //Again, not much to say.
        public fmtChunk ReadFormatHeader()
        {
            format = new fmtChunk();

            format.sChunkID = "fmt ";

            int pos = 0;

            format.dwChunkSize = reader.ReadUInt32();


            format.wFormatTag = reader.ReadUInt16();
            pos += 2;

            format.wChannels = reader.ReadUInt16();
            pos += 2;

            format.dwSamplesPerSec = reader.ReadUInt32();
            pos += 4;

            format.dwAvgBytesPerSec = reader.ReadUInt32();
            pos += 4;

            format.wBlockAlign = reader.ReadUInt16();
            pos += 2;

            if (pos + 4 <= format.dwChunkSize)
            {
                format.dwBitsPerSample = reader.ReadUInt32();
                pos += 4;
            }
            else
            {
                format.dwBitsPerSample = 8 * format.dwAvgBytesPerSec / format.dwSamplesPerSec;
            }

            while (pos < format.dwChunkSize)
            {
                reader.ReadByte();
                pos++;
            }

            return(format);
        }
Ejemplo n.º 3
0
        public WaveFile(string filename)
        {
            reader            = new WaveFileReader(filename);
            maindata          = reader.ReadMainFileHeader();
            maindata.FileName = filename;
            long   chunkSize = 0;
            string chunkName = null;

            while (chunkName != "data" && reader.GetPosition() < (long)maindata.dwFileLength && reader.GetPosition() + chunkSize < maindata.dwFileLength)
            {
                chunkName = reader.GetChunkName();
                switch (chunkName)
                {
                case "fmt ":

                    format    = reader.ReadFormatHeader();
                    chunkSize = format.dwChunkSize;
                    break;

                case "fact":

                    fact      = reader.ReadFactHeader();
                    chunkSize = fact.dwChunkSize;
                    break;

                case "data":

                    data      = reader.ReadDataHeader();
                    chunkSize = data.dwChunkSize;
                    break;

                default:
                    //This provides the required skipping of unsupported chunks.
                    // reader.AdvanceToNext();

                    chunkSize = 0;
                    break;
                }
            }
        }