Solved

low-level audio callback function crash

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dir function fails on mapped drives 28 154
Problem to packaging 1 125
SSIS 2010 Convert to SSIS 2013 On Different Box 3 63
Trouble installing msi file with msiexe.exe 2 47
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…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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