Exemplo n.º 1
0
        public void WriteWav(WavFile wavFile)
        {
            FileStream   fsr  = new FileStream(wavFile.path, FileMode.Open, FileAccess.Read);
            BinaryReader r    = new BinaryReader(fsr);
            string       path = wavFile.path;

            path = path.Insert(path.Length - 4, "(+)");
            FileStream fsw = null;

            try
            {
                fsw = new FileStream(path, FileMode.CreateNew);
            }
            catch (IOException)
            {
                fsw = new FileStream(path, FileMode.Truncate);
            }
            BinaryWriter w = new BinaryWriter(fsw);
            int          pos = 0, len = (int)r.BaseStream.Length; short temp;

            while (pos < len)
            {
                temp = (short)r.ReadInt16();
                //Working with the temp
                w.Write(temp);
                pos += 2;
            }
            r.Close(); w.Close();
            fsr.Close(); fsw.Close();
        }
Exemplo n.º 2
0
        // Returns left and right double arrays. 'right' will be null if sound is mono.
        public void openWav(WavFile wavFile)
        {
            //path
            FileStream   fsr = new FileStream(wavFile.path, FileMode.Open, FileAccess.Read);
            BinaryReader r   = new BinaryReader(fsr);

            try
            {
                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;

                int n = (int)(wavFile.dwFileLength / wavFile.wChannels * 8 / wavFile.wBitsPerSample);
                wavFile.AudioDataArray = new byte[dwFileLength - 44];

                for (int i = 0; i < dwFileLength - 44; i++)
                {
                    wavFile.AudioDataArray [i] = r.ReadByte();
                    //wavFile.AudioDataArray[i] = sample / 32768f;
                }
            }
            finally
            {
                r.Close();
                fsr.Close();
            }
        }
Exemplo n.º 3
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (openFileDialogWav.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            // получаем выбранный файл
            OurWav      = new WavFile();
            OurWav.path = openFileDialogWav.FileName;
            // читаем файл в строку
            OurWav.openWav(OurWav);
            MessageBox.Show("Файл открыт");
            for (int i = 0; i < OurWav.AudioDataArray.Length; i += 1600)
            {
                OurWav.AudioDataArray.Skip(i);
                FFTandDraw(OurWav.AudioDataArray, 1600);
                //Thread.Sleep(1000);
            }
            //     Transform.FourierForward(OurWav.AudioDataArray, FourierOptions.Matlab);
            // for (int i = 0; i < OurWav.AudioDataArray.Length/1024; i++)

            //         CreateGraph(zedGraphControl1, OurWav.AudioDataArray);
        }