Solved

waveform audio API question

Posted on 1998-11-19
7
1,081 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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