Home How do I read an audio file into an array in C#
Reply: 0

How do I read an audio file into an array in C#

user1188 Published in March 23, 2018, 2:34 pm

I am trying to read a WAV file into a buffer array in c# but am having some problems. I am using a file stream to manage the audio file. Here is what I have...

FileStream WAVFile = new FileStream(@"test.wav", FileMode.Open);

        //Buffer for the wave file...
        BinaryReader WAVreader = new BinaryReader(WAVFile);

        //Read information from the header.
        chunkID = WAVreader.ReadInt32();
        chunkSize = WAVreader.ReadInt32();
        RiffFormat = WAVreader.ReadInt32();


        channels = WAVreader.ReadInt16();
        samplerate = WAVreader.ReadInt32();
        byteRate = WAVreader.ReadInt32();
        blockAllign = WAVreader.ReadInt16();
        bitsPerSample = WAVreader.ReadInt16();

        dataID = WAVreader.ReadInt32();
        dataSize = WAVreader.ReadInt32();

The above is reading data from the WAV file header. Then I have this:

musicalData = WAVreader.ReadBytes(dataSize);

...to read the actual sample data but this is only 26 bytes for 60 seconds of audio. Is this correct?

How would I go about converting the byte[] array to double[]?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.520863 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO