?
Solved

waveform audio API question

Posted on 1998-11-19
7
Medium Priority
?
1,092 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 450 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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 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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

764 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