Audio guidance.

This is a discussion on Audio guidance. within the Windows Programming forums, part of the Platform Specific Boards category; I have spent the morning playing with the audio API, but so far haven't been able to confirm a proper ...

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,669

    Audio guidance.

    I have spent the morning playing with the audio API, but so far haven't been able to confirm a proper setup. If anyone has experience in this field, I would appreciate a little guidance. Here are the steps I am following:

    1) Initialize a WAVEFORMATEX structure to zero and set the sample rate, bits per second, channels, block alignment, average bytes per second, and set the format to WAVE_FORMAT_PCM.

    where:

    sr = 8000;
    bps = 8;
    c = 1;
    ba = bps * c;
    abps = ba * sr;
    f = WAVE_FORMAT_PCM;

    2) Initialize a WAVEHDR structure to zero and set the buffer length to a size compatible with the value of abps from above, pass it a buffer of that size, and set the flags to WHDR_BEGINLOOP|WHDR_ENDLOOP.

    3) Format the header.

    4) Open.
    [ waveInOpen(&hwavein, WAVE_MAPPED, &wavefmtx, hwnd, 0, CALLBACK_WINDOW|WAVE_MAPPER); ]

    5) Start.

    6) Stop.

    7) Unformat the header.

    8) Free the buffer.

    In the Window procedure, I am monitoring for the MM_WIM_OPEN, MM_WIM_CLOSE, and MM_WIM_DATA messages, and that is the problem. I am not recieving them as of yet, which leads me to believe I am doing something wrong. Any advice would be highly appreciated...



    ITSA
    Socket Library!

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Lets see what I can remember...

    First in your WAVEFORMATEX struct..

    I believe your nBlockAlign is wrong. Well you multiply correctly but you need to divide out by 8.

    nBlockAlign = (nChannels * wBitsPerSample) / 8;

    You also want to use waveOutOpen( ) prototyped as follows:

    Code:
    MMRESULT waveOutOpen( LPHWAVEOUT hWaveOut, UINT nDeviceID, LPWAVEFORMATEX pWaveFormatEx, DWORD dwCallback, DWORD dwCallbackInstance, DWORD dwOpen );
    Make sure the return code is MMSYSERR_NOERROR. The main value we are interested in is the hWaveOut value. This is a handle to our wave-output device obviously.

    Second parameter should be the symbolic constant WAVE_MAPPER to indicate you want the default system wave output device.

    Third parameter is your struct you already initialized.

    Fourth parameter is a callback. This describes how we want to be notified of certain events. Use the handle to some window casted to a DWORD.

    Fifth parameter is the actual callback data. Just set this to 0 we will ignore it. We will use our windows procedure to get messages.

    Sixth parameter should be another constant CALLBACK_WINDOW to request messages.

    Once you successfully open the device it will send a message MM_WOM_OPEN. This is a good thing


    Now we can prepare our "wave header struct".
    Looking back over what you wrote I think you probably have this part down. I think you were just incorrectly calling waveInOpen instead of the waveOutOpen. A reasonable mistake. Let me know if you need the rest of the stuff I was going to type. Hopefully this will get you going!

    --MrWizard
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,669
    Hey, thanks Wiz, I can see now why my calculation was wrong...need to convert bits to bytes and all...

    I actually mean to open the mic but honestly don't know where to go from there, just needed the AOK of a system message to keep me going! OK so I will try outputing before inputting first. Eventually my goal is to analyze microphone data. I will let y'all know how it goes....

    Thanks again,

    -Sebastian

    P.S. Merry Cristmas all. Have a safe and happy holiday.



    ITSA
    Socket Library!

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    I once made an application for analyzing audio received by a standard soundcard using the Win32 Audio API. The following is the procedure I used to open a wave device:

    1. Check if there is a wave-device available using: waveInGetNumDevs(). The result should be larger than zero.

    2. Check if the available wave-device is capable for recording purposes, using: waveInGetDevCaps(). The result should be MMSYSERR_NOERROR.

    3. Create a recording thread, put it in suspended mode first.

    4. Define the wave format.

    5. Open the wave device using: waveInOpen().

    6. Initialise recording process. Which consist of preparing the headers, adding the buffers and starting the process using waveInStart().

    The real starting of the recording begins when resuming the created recording thread.

    And for stopping the recording, the thread is put to suspended again and waveInStop() and then waveInReset() are called to finish communication with the soundcard.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    There is a good section on FFT's and frequency analysis here and code for a simple windows app here
    Last edited by Stoned_Coder; 12-22-2002 at 06:38 AM.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Another great site with good tutorials:

    http://www.digitalfilter.com/

    Since you're working with Windows, especially the Visual C++ Class may be interesting.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,669
    Thank you all for the intelligent replies. It's interesting you posted that reliable software link, Stoner. That was actually part of the inspiration for this project. I am basically going to try to implement some sort of voice recognition system, and I will plot the signals while I study them, probably using the FFT algorithm. Shiro, thanks for the tips you gave too. This should prove to be an interesting project!

    Merry Christmas!

    -Sebastian



    ITSA
    Socket Library!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Audio Programming
    By dwalters in forum Tech Board
    Replies: 0
    Last Post: 02-07-2008, 03:20 PM
  2. front audio panel
    By crvenkapa in forum Tech Board
    Replies: 1
    Last Post: 12-09-2007, 12:00 PM
  3. Audio Drivers
    By Tonto in forum Tech Board
    Replies: 8
    Last Post: 08-30-2006, 09:07 PM
  4. audio programming (from scratch)
    By simpleid in forum C Programming
    Replies: 6
    Last Post: 07-26-2006, 09:32 AM
  5. Port Audio
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 12-07-2005, 10:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21