Exemple #1
0
 private static void ConvertAiffToWav(string aiffFile, string wavFile)
 {
     using (AiffFileReader reader = new AiffFileReader(aiffFile))
     {
         using (WaveFileWriter writer = new WaveFileWriter(wavFile, reader.WaveFormat))
         {
             byte[] buffer    = new byte[4096];
             int    bytesRead = 0;
             do
             {
                 bytesRead = reader.Read(buffer, 0, buffer.Length);
                 writer.Write(buffer, 0, bytesRead);
             } while (bytesRead > 0);
         }
     }
 }
Exemple #2
0
        private void printAudioWave()
        {
            BinaryReader binRead    = null;
            uint         dataSize   = 0;
            int          numSamples = 0;

            Point[]      points         = new Point[pictureBox.Width];
            int          coefForWidth   = 0;
            int          coeffForHeight = 0;
            Pen          penCountur     = new Pen(Color.Black, 2);
            SolidBrush   drawBrush      = new SolidBrush(Color.Black);
            StringFormat drawFormat     = new StringFormat();
            Graphics     graphicMain    = pictureBox.CreateGraphics();

            switch (currentAudioFormat)
            {
            case "wav":
                Cursor.Current = Cursors.WaitCursor;
                fileStreamInput.Read(new byte[4], 0, 4);
                binRead   = new BinaryReader(fileStreamInput);
                dataSize  = (uint)(fileStreamInput.Length / 4);
                audioData = new Int16[dataSize];
                fileStreamInput.Seek(40, System.IO.SeekOrigin.Begin);
                numSamples = (int)(dataSize / 1);
                for (int i = 0; i < numSamples; i++)
                {
                    audioData[i] = binRead.ReadInt16();
                }
                coefForWidth   = (int)(audioData.Length / (pictureBox.Width));
                coeffForHeight = (int)(65536 / (pictureBox.Height - 40));
                for (int i = 0; i < pictureBox.Width; i++)
                {
                    points[i] = new Point(i, (int)((audioData[i * coefForWidth] / coeffForHeight) + (pictureBox.Height / 2)));
                }
                graphicMain.Clear(Color.White);
                graphicMain.DrawLines(penCountur, points);
                Cursor.Current = Cursors.Default;
                break;

            case "aiff":
                Cursor.Current = Cursors.WaitCursor;
                string tempFileName = Path.Combine(Environment.CurrentDirectory, "temp.wav");
                using (AiffFileReader reader = new AiffFileReader(inputAudioFile))
                {
                    using (WaveFileWriter writer = new WaveFileWriter(tempFileName, reader.WaveFormat))
                    {
                        byte[] buffer    = new byte[4096];
                        int    bytesRead = 0;
                        do
                        {
                            bytesRead = reader.Read(buffer, 0, buffer.Length);
                            writer.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);
                    }
                }
                FileStream tempFileStreamInput = new FileStream(tempFileName, FileMode.Open, FileAccess.Read);
                tempFileStreamInput.Read(new byte[4], 0, 4);
                binRead   = new BinaryReader(tempFileStreamInput);
                dataSize  = (uint)(tempFileStreamInput.Length / 4);
                audioData = new Int16[dataSize];
                tempFileStreamInput.Seek(40, System.IO.SeekOrigin.Begin);
                numSamples = (int)(dataSize / 1);
                for (int i = 0; i < numSamples; i++)
                {
                    audioData[i] = binRead.ReadInt16();
                }
                tempFileStreamInput.Close();
                File.Delete(tempFileName);
                coefForWidth   = (int)(audioData.Length / (pictureBox.Width));
                coeffForHeight = (int)(65536 / (pictureBox.Height - 40));
                for (int i = 0; i < pictureBox.Width; i++)
                {
                    points[i] = new Point(i, (int)((audioData[i * coefForWidth] / coeffForHeight) + (pictureBox.Height / 2)));
                }
                graphicMain.Clear(Color.White);
                graphicMain.DrawLines(penCountur, points);
                Cursor.Current = Cursors.Default;
                break;

            default:
                break;
            }
        }
Exemple #3
0
 public override int Read(byte[] buffer, int offset, int count)
 {
     return(m_reader.Read(buffer, offset, count));
 }