Solved

low-level audio callback function crash

Posted on 1997-07-02
3
1,652 Views
Last Modified: 2013-12-03
I'm using Visual C++ 5.0 to write a simple console application that makes use of the low-level audio routines to continuously record waveform audio for analysis, and have run into a problem.



The audio object that I've written does the following:



1) fills a WAVEFORMATEX structure with the appropriate values.

2) calls waveInOpen with the structure, specifying a waveInProc callback function.

3) GlobalAllocs storage for two WAVEHDR structures and two 4K audio interrupt buffers and sets the data and size fields appropriately.

4) calls waveInPrepare and waveInAdd for the WAVEHDR structs.

5) calls waveInStart to start recording.



The problem is that after step 2) and before waveInStart is called, the program crashes with an



    "Unhandled exception in Audio.exe : 0xc0000005: Access violation".



The stack is way overflowed, registers are trashed and register EBP contains the HWAVEIN handle that was used in waveInOpen.



I suspect that its crashing in the waveInProc callback function, but this happens even if the function does absolutely nothing!
0
Comment
Question by:danlau
[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 Comments
 
LVL 3

Expert Comment

by:byang
ID: 1399917
Put your code here.

By the way, since you only have 2 4K buffers, why bother with dynamic memory allocation, just declare 2 global or static arrays.
0
 

Accepted Solution

by:
kbg earned 70 total points
ID: 1399918
I don's understand youer error.
MFC Debuger is very useful tool.
I estimated message looping or youer waveInProc don's define static callback function.
 
 refer to this code               --- Good luck ----

// wavein.h
class CWaveInAudio : public CWaveformAudio
{
public :
  CWaveInAudio() ;
  ~CWaveInAudio() ;

protected :
  // return
  UINT m_uiDeviceID ;

  HWAVEIN m_hWaveIn ;
  WAVEINCAPS m_WaveInCaps ;

  static CWaveInAudio* m_pThis ;
  static void CALLBACK waveInProc
  (
    HWAVEIN hwi, UINT uMsg,      DWORD dwInstance,      
    DWORD dwParam1,      DWORD dwParam2      
  ) ;

      .
      .
      .
}



// WaveIn.cpp
void CALLBACK CWaveInAudio::waveInProc
(
  HWAVEIN hwi,
  UINT uMsg,
  DWORD dwInstance,      
  DWORD dwParam1,      DWORD dwParam2
)
{
  switch( uMsg )
  {
  // Sent when the device is closed
  // using the waveInClose function.
  case WIM_CLOSE :
) ;

    break ;

  // Sent when the device driver is finished with
  // a data block sent using the waveInAddBuffer function.
  case WIM_DATA :
   
    m_pThis->StopRecording() ;
    m_pThis->ReleaseRecording() ;
    m_pThis->CloseDevice() ;
    break ;

  // Sent when the device is opened
  // using the waveInOpen function.
  case WIM_OPEN :
    m_pThis->PrepareRecording() ;
    m_pThis->AddBufferToDevice() ;
    m_pThis->BeginRecording() ;

    break ;

  default :
    Message( _T("WaveIN Callback function, Unknowen Message") ) ;
    break ;
  }
}



///////////
void CWaveInAudio::AddBufferToDevice()
{
  if( m_hWaveIn == 0 )
  {
    Message( _T(" m_hWaveIn don's Init") ) ;
    return ;
  }

  m_mmRet = waveInAddBuffer
    (
      m_hWaveIn,
      &m_WaveHdr,
      sizeof(WAVEHDR)
    ) ;
}


// VC++ halp
The waveInAddBuffer function sends an input buffer to the given waveform-audio input device. When the buffer is filled, the application is notified.

MMRESULT waveInAddBuffer(


HWAVEIN hwi,



LPWAVEHDR pwh,



UINT cbwh



);



Parameters

hwi

Handle of the waveform-audio input device.

pwh

Address of a WAVEHDR structure that identifies the buffer.

cbwh

Size, in bytes, of the WAVEHDR structure.

Return Values

Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following:


MMSYSERR_INVALHANDLE



Specified device handle is invalid.

MMSYSERR_NODRIVER



No device driver is present.

MMSYSERR_NOMEM



Unable to allocate or lock memory.

WAVERR_UNPREPARED



The buffer pointed to by the pwh parameter hasn’t been prepared.



Remarks

When the buffer is filled, the WHDR_DONE bit is set in the dwFlags member of the WAVEHDR structure.

The buffer must be prepared with the waveInPrepareHeader function before it is passed to this function.

0
 

Expert Comment

by:liquidnet
ID: 24213381
i don't see any solution here except msdn code
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

696 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