Solved

waveform audio API question

Posted on 1998-11-19
7
1,083 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

861 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now