Solved

low-level audio callback function crash

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save copy of document in Word 4 88
dialer.exe 4 64
What the difference between blend and Visual Studio 3 177
Why is "packages element is not declared"? 2 332
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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