Solved

low-level audio callback function crash

Posted on 1997-07-02
3
1,596 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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