locked
Encoding a .WAV file header RRS feed

  • Question

  • How do you encode a wave file? I have data, but without the header it doesn't play.

    I've seen this method:

    sound.Stream.BeginWrite(buffer , 0 , Num  , async,  sent);

    however, I'm confused over what the 3rd and 4th Arguments are for, and how to tell it where to put the file. I'm using as input the XNA framework for the microphone, but I can't find anything over encoding it!

    Thursday, June 21, 2012 9:00 PM

Answers

  • That sample writes to a MemoryStream.  Try using a FileStream, instead.

    System.IO.FileStream (.NET Framework 4)

    Change the using statement that uses the type MemoryStream.

    All of the XxxxWriter classes can use any of the XxxxStream classes.


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, June 23, 2012 1:53 PM
    Moderator
  • Hi ProgrammingInCSharp12453,

      I think you could combine Filestream and BinaryWriter for filling the binary stream into file storage. Those code look like as follows:

     
    FileStream writeStream ;
      writeStream = new FileStream("c:\\testBinary.dat", FileMode.Create);
      BinaryWriter writeBinay = new BinaryWriter(writeStream); 

      The detailed information about its explanations you could read the following material:

      How to use C# BinaryWriter Class  

      The structure of Wav file header you could read the following standard soundfile format:

      WAVE PCM soundfile format

      Certainly, you can read Rudedog2's reply about Beep Beep,and it announces the code about reading the wav file head.

      Hope it helps you.

      Sincerely,

      Jason Wang


    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 25, 2012 2:41 AM
    Moderator

All replies

  • Check out this thread from a grandmaster of Input/Output.

    Beep Beep

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/


    Thursday, June 21, 2012 10:31 PM
    Moderator
  • What are they doing with the Binary Writer? Is there any other way to encode it?
    Friday, June 22, 2012 12:29 AM
  • Writing to the MemoryStream with the BinaryWriter. That's what he's doing there, and playing/loading the MemoryStream into the SoundPlayer constructor to play the sound with it's methods.

    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum

    Friday, June 22, 2012 2:15 AM
  • So once the data is in the Binary Writer, it writes to file with the following code snippet:

     BW.Write(Hdr[I]);

    Binary writer then must have a way to A: Set where to write it to, as it is in stream, and B, How do you get the data from stream to file?

    Friday, June 22, 2012 4:16 AM
  • That sample writes to a MemoryStream.  Try using a FileStream, instead.

    System.IO.FileStream (.NET Framework 4)

    Change the using statement that uses the type MemoryStream.

    All of the XxxxWriter classes can use any of the XxxxStream classes.


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, June 23, 2012 1:53 PM
    Moderator
  • How do you encode a wave file? I have data, but without the header it doesn't play.

    I've seen this method:

    sound.Stream.BeginWrite(buffer , 0 , Num  , async,  sent);

    however, I'm confused over what the 3rd and 4th Arguments are for, and how to tell it where to put the file. I'm using as input the XNA framework for the microphone, but I can't find anything over encoding it!

    I'm not familiar with that method.  What is its' type?

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, June 23, 2012 1:55 PM
    Moderator
  • Hi ProgrammingInCSharp12453,

      I think you could combine Filestream and BinaryWriter for filling the binary stream into file storage. Those code look like as follows:

     
    FileStream writeStream ;
      writeStream = new FileStream("c:\\testBinary.dat", FileMode.Create);
      BinaryWriter writeBinay = new BinaryWriter(writeStream); 

      The detailed information about its explanations you could read the following material:

      How to use C# BinaryWriter Class  

      The structure of Wav file header you could read the following standard soundfile format:

      WAVE PCM soundfile format

      Certainly, you can read Rudedog2's reply about Beep Beep,and it announces the code about reading the wav file head.

      Hope it helps you.

      Sincerely,

      Jason Wang


    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 25, 2012 2:41 AM
    Moderator
  • I'm pretty sure its for sending data in sync for writing then reading and so on...

    Monday, June 25, 2012 3:24 AM