Solved

low-level audio callback function crash

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

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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