Proper use of P/Invoke WaveIn and Wave classes? RRS feed

  • Question


    Hello all, I would like to begin by saying that I have little/no experience when it comes to programming hardware, so please bear with me :)

    I managed to re-create the P/Invoke classes WaveIn, Wave, and Memory. My goal is to record the raw data from the mic (i.e. the "ambient noise" that the device is near). What is the proper way to implement these classes in order extract this data? I would like them saved into an array so that I can do whatever I want with them (such as take the variance, RMS, fft, etc.). The rest of the code is a cake-walk for me, I just need to get the raw input from the mic.

    Someone earlier had directed me to: http://msdn.microsoft.com/en-us/magazine/cc163341.aspx I understand the premise of what this guy is doing, but I do not understand this little bit:


    byte[] data = new byte[dwBytesRecorded];
    Marshal.Copy(lpData, data, 0, data.Length);


    Where does he declare dwBytesRecorded? How does he already have bytes recorded?

    By the way, I created by P/Invoke classes based on this website: http://www.pudn.com/downloads71/sourcecode/comm/windows_mobile/detail255733.html

    I realize the website is not in English, but if you scroll down it has a list of files and C# code that I used.

    Any help would be greatly appreciated!

    Monday, April 26, 2010 4:11 AM


  • Hi nizar.g,

    Please take a look at WaveInStart API document as below:

    Buffers are returned to the application when full or when the waveInReset function is called (the dwBytesRecorded member in the header will contain the length of data). If there are no buffers in the queue, the data is thrown away without notifying the application, and input continues.

    For more information:



    Best regards,
    Guang-Ming Bian - MSFT

    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Wednesday, April 28, 2010 8:16 AM