Menu

Noise, when playing audio data

Mint3
2009-09-11
2012-10-29
  • Mint3

    Mint3 - 2009-09-11

    Hi, I am trying to capture and play audio using Directshow.
    I have captured the audio data using samplegrabber, but when I play the data it is giving only noise.

    Here is the format of audio data.

    m_Format = new WindowsMediaLib.Defs.WaveFormatEx();
    m_Format.wFormatTag = 1; // PCM
    m_Format.nChannels = 2; // Stereo
    m_Format.nSamplesPerSec = 44100;
    m_Format.wBitsPerSample = 8;
    m_Format.nBlockAlign = (short)(m_Format.nChannels * (m_Format.wBitsPerSample / 8));
    m_Format.nAvgBytesPerSec = m_Format.nSamplesPerSec * m_Format.nBlockAlign;
    m_Format.cbSize = 0;
    iRet = waveOut.Open(out m_pWave, 0, m_Format, IntPtr.Zero, IntPtr.Zero,WaveOpenFlags.None);
    m_Buff = new WBuf(m_pWave, m_Format.nSamplesPerSec * (int)Math.Ceiling(4.0) * m_Format.nBlockAlign);

    Here I am getting audio data and saving to saveAudio
    public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
    {
    // copying data to saveAudio
    Marshal.Copy(pBuffer, saveAudio, 0, BufferLen);
    //copying data to buffer
    m_Buff.CopyDataToBuffer(saveAudio);
    // writing data to play
    waveOut.Write(m_pWave, m_Buff.GetPtr(), BufferLen);
    return 0;
    }

    // Here is the code to copy audio data to buffer
    public void CopyDataToBuffer(byte[] arrary)
    {
    int iOffset = 0;
    IntPtr pBuff = m_Head.lpData;
    for(int i=0; i<arrary.Length; i++)
    {
    Marshal.WriteByte(pBuff, iOffset, arrary[i]);
    iOffset++;
    }
    }

    Please tell me the mistake, I am doing.

     
  • snarfle

    snarfle - 2009-09-12

    It looks like you are using a part DS and a part WM solution here. Is there
    some reason for that? Did you try the RecordWav sample from WM?

     
  • Mint3

    Mint3 - 2009-09-14

    Hi snarfle, thanks a lot for your reply.
    ya, I am using a part DS and a part WM. There is no reason for that.
    I had used samplegrabber to capture images using DS, so I tried DS and I saw
    generateLa example at windowsmedianet about audio, I tried merging both
    examples to get work.
    Actually I am a beginner in Directshow and trying to capture audio data at
    real time and send over network to play other side.
    I have done video part of capturing images and sending over network, and
    currently trying to do audio part.
    I am looking at RecordWav example, but it saves audio to a file instead of
    memory.

     

Log in to post a comment.