Exemple #1
0
        public static void Write(string Path, WavFile wavFile)
        {
            FileStream   fsr = new FileStream(Path, FileMode.Create, FileAccess.Write);
            BinaryWriter r   = new BinaryWriter(fsr);

            r.Write(wavFile.sGroupID);
            r.Write(wavFile.dwFileLength);
            r.Write(wavFile.sRiffType);
            r.Write(wavFile.sFChunkID);
            r.Write(wavFile.dwFChunkSize);
            r.Write(wavFile.wFormatTag);
            r.Write(wavFile.wChannels);
            r.Write(wavFile.dwSamplesPerSec);
            r.Write(wavFile.dwAvgBytesPerSec);
            r.Write(wavFile.wBlockAlign);
            r.Write(wavFile.wBitsPerSample);
            r.Write(wavFile.sDChunkID);
            r.Write(wavFile.dwDChunkSize * 2);


            int n = (int)(wavFile.dwDChunkSize / wavFile.wBitsPerSample * 8);

            for (int i = 0; i < n; i++)
            {
                Int16 tmp = 0;
                tmp = wavFile.DataList[i];
                r.Write(tmp);
            }

            r.Close();
            fsr.Close();
        }
Exemple #2
0
        public static WavFile Read(string Path)
        {
            var wavFile = new WavFile();

            wavFile.path = Path;//@"C:\Rammstein - Kokain.wav";
            FileStream   fsr = new FileStream(wavFile.path, FileMode.Open, FileAccess.Read);
            BinaryReader r   = new BinaryReader(fsr);

            wavFile.sGroupID         = r.ReadChars(4);
            wavFile.dwFileLength     = r.ReadUInt32();
            wavFile.sRiffType        = r.ReadChars(4);
            wavFile.sFChunkID        = r.ReadChars(4);
            wavFile.dwFChunkSize     = r.ReadUInt32();
            wavFile.wFormatTag       = r.ReadUInt16();
            wavFile.wChannels        = r.ReadUInt16();
            wavFile.dwSamplesPerSec  = r.ReadUInt32();
            wavFile.dwAvgBytesPerSec = r.ReadUInt32();
            wavFile.wBlockAlign      = r.ReadUInt16();
            wavFile.wBitsPerSample   = r.ReadUInt16();
            wavFile.sDChunkID        = r.ReadChars(4);
            wavFile.dwDChunkSize     = r.ReadUInt32();
            wavFile.dataStartPos     = (byte)r.BaseStream.Position;

            //

            r.BaseStream.Position += wavFile.dwDChunkSize;

            wavFile.sDChunkID    = r.ReadChars(4);
            wavFile.dwDChunkSize = r.ReadUInt32();
            int n = (int)(wavFile.dwDChunkSize / wavFile.wBitsPerSample * 8);

            for (int i = 0; i < n; i++)
            {
                Int16 tmp = 0;
                tmp = r.ReadInt16();
                wavFile.DataList.Add(tmp);
            }

            //wavFile.sDChunkID = r.ReadChars(4);
            //wavFile.dwDChunkSize = r.ReadUInt32();

            r.Close();
            fsr.Close();

            return(wavFile);
        }