This project has moved. For the latest updates, please go here.

How to extract raw data from Byte Buffer and transform it into object

Apr 26, 2013 at 11:11 AM
Hey all! I am currently participating in a project that involves Message Brokers, and one of the projects that use such is Simultaneous Audio and Video Streaming. In order for my audio data to be transferred and processed to the Messaging System, in which I am using ActiveMQ, It must be transformed to an object. The point in my code that performs this is here:

private void button2_Click(object sender, EventArgs e)
{
    stream = new NAudio.Wave.WaveIn();
    stream.DeviceNumber = 0;
    stream.WaveFormat = new NAudio.Wave.WaveFormat(44100, 1);
    stream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(anyue);
    stream.StartRecording();
}

private void anyue(object sender, NAudio.Wave.WaveInEventArgs e)
{     
    e.buffer // How to extract raw audio data here?
}
My question is, how do you extract raw data from the buffer and transform it into an object? Thanks! Sample codes will be greatly helpful! I owe you a lot!
Apr 27, 2013 at 5:06 AM
Edited Apr 27, 2013 at 5:06 AM
Try the WaveIn event handler DataAvailable like this:
stream.DataAvailable += WaveIn_DataAvailable;

 private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
// use WaveInEventArgs to access the buffer
// maybe use a MemoryStream
}