Solved

waveform audio API question

Posted on 1998-11-19
7
1,087 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 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

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…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…

732 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