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

Live Playback of waveinstream

Oct 9, 2009 at 5:52 PM

I want to play back the captured audio as close to live as possible

the wavinstream capture is easy... i assume i would put the buffer into a memory stream...???? or do i put the data into a wavebuffer?
then i need to created a class that is derrived from wavestream, and get the data from the memory stream
in the Read method

but im not having much luck, anychance some example code of the derrived wavestream?
perticually the overridden Read method

Im just going in circles now...

thanks
mitch

Oct 9, 2009 at 8:39 PM

ok, lets switch to the newer naudio...

 

wavin...
i dont know what to do with the data that shows up in data arrived, where do i stick it :)
i need like a buffer, that can hold say 1 second, of 44.1k 16bit x 2chanel audio?

Oct 10, 2009 at 5:36 AM

 

ok, i got it all working :)

 

now how do it control the wavein mixerline ;)

 

Oct 15, 2009 at 1:23 PM

would it be possible for u to post your derived wavestream

thanks

Oct 15, 2009 at 4:04 PM
Edited Oct 15, 2009 at 4:05 PM
Sure,





mainOutputStream = new WaveOutStream();

its called... line in the capture
// wavein data from capture
  private void waveIn_DataAvailable(object sender, WaveInEventArgs e)
  {
   mainOutputStream.SetStream(e.Buffer, e.BytesRecorded);
  }

-----------------------------------
using System.IO

public class WaveOutStream : WaveStream
{
  MemoryStream SourceStream;
  private bool Streaming;

  public WaveOutStream()
  {
    SourceStream = new MemoryStream();
  }

  public void SetStream(byte[] buffer, int bufferLength)
  {
    if (Streaming == true)
    {
      SourceStream.Position = 0;
      SourceStream.Write(buffer, 0, bufferLength);
    }
  }

  public void Stop()
  {
    Streaming = false;
    SourceStream.Position = 0;
    SourceStream.SetLength(0);
  }

  public void Start()
  {
    Streaming = true;
  }

  public override int Read(byte[] buffer, int offset, int count)
  {
    if (SourceStream.Length == 0)
    {
      buffer[0] = 0;
      return 1;
    }
    else
    {
      SourceStream.Position = 0;
      int bytesRead = SourceStream.Read(buffer, offset, count);

      return bytesRead;
    }
  }

  public override WaveFormat WaveFormat
  {
    get { return new WaveFormat(44100, 16, 2); }
  }

  public override long Length
  {
    get { return SourceStream.Length; }
  }

  public override long Position
  {
    get
    {
      throw new NotImplementedException();
    }
    set
    {
      throw new NotImplementedException();
    }
  }
}