Solved

waveform audio API question

Posted on 1998-11-19
7
1,084 Views
Last Modified: 2013-12-03
I am trying to do a simple audio loopback program that will read in audio from the mic and send it out to the speaker immediately.

Here is my problem:

In the callback function for input audio (waveInProc) I get the wave header structure copy the data to a queue and try to send the buffer back to the device using waveInAddbuffer. However when I do this the application locks up. While stepping through the code when I get to the waveInAddBuffer call the function never returns. What makes this even more weird is that the code I have written works fine under Windows98, but when I try to run it under WinNT 4.0 it will lock up.

Anyone have any ideas why this is happening?

Here is my waveInProc function:

void CALLBACK waveInProc(HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
      LPWAVEHDR      lpHeader;
      char            *lpTempBuf;

      switch(uMsg)
      {
      case WIM_DATA:
            lpHeader = (LPWAVEHDR) dwParam1;
            PlayAudio(lpHeader->lpData,
                          lpHeader->dwBytesRecorded);

            lpTempBuf = lpHeader->lpData;

            waveInUnprepareHeader(hwi,
                                      lpHeader,
                                      sizeof(WAVEHDR));

            lpHeader->dwBufferLength =
                                 NUMBER_OF_BYTES_PER_BLOCK;
            lpHeader->lpData = lpTempBuf;
            lpHeader->dwFlags = 0;

              waveInPrepareHeader(hwi,
                                    lpHeader,
                                    sizeof(WAVEHDR));

            waveInAddBuffer(hwi,
                                lpHeader,
                                sizeof(WAVEHDR));

            break;

      case WIM_OPEN:
            printf("WIM_OPEN\n");
            break;

      case WIM_CLOSE:
            printf("WIM_CLOSE\n");
            break;
      }

}
0
Comment
Question by:cjl036
  • 3
  • 3
7 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 150 total points
ID: 1416202
You should add buffers from outside of waveInProc. You can check samples from win32 sdk for how to do this.
Try do not use callback function at all. You may use event or check the flag 'buffer is done' in WAVEHDR.

From SDK:

Applications should not call any system-defined functions from inside a callback function, except for EnterCriticalSection, LeaveCriticalSection, midiOutLongMsg, midiOutShortMsg, OutputDebugString, PostMessage, PostThreadMessage, SetEvent, timeGetSystemTime, timeGetTime, timeKillEvent, and timeSetEvent. Calling other wave functions will cause deadlock.

0
 

Author Comment

by:cjl036
ID: 1416203
But why will this work under Win98 and not under WinNT?
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1416204
Different implementation, may be. I'm not sure, but may be MS something changed in 98. I have not get latest SDK. Try to run this on 95.

But if you want to run your app on 95 and NT, then follow my answer.
If MS says 'do not do this', then, i think its better to do as they said.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 15

Expert Comment

by:NickRepin
ID: 1416205
I've check www.MS.com and found no change in SDK docs (http://premium.microsoft.com/isapi/devonly/prodinfo/msdnprod/msdnlib.idc?theURL=/msdn/library/sdkdoc/multimed/mmfunc_7j8j.htm).

May be, the same program works on your PC, but hungs on different one under 98.
0
 

Expert Comment

by:gbeau
ID: 1416206
BTW, if you happen to be using a Creative soundcard (SB16, AWE32, AWE64) and find that your audio sound quality is low, it's not because of your code.  Turns out that Creative cards use two DMA channels, one 8 bit, the other 16 bit, thus making it impossible to do full duplex 16 bit audio.  Be warned!
0
 

Author Comment

by:cjl036
ID: 1416207
But why will this work under Win98 and not under WinNT?
0
 

Author Comment

by:cjl036
ID: 1416208
Nick,

Thank you. I missed that part in the remarks section of the documentation where it said that calling other wave functions will cause deadlock.

Nuch appreciated.

Joe
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question