Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:58:59+00:00 2026-06-09T23:58:59+00:00

I’m doing audio sampling with waveInProc callback. The problem is that when I’m trying

  • 0

I’m doing audio sampling with waveInProc callback. The problem is that when I’m trying to stop sampling and close the audio device I get no msg in the callback – tried waveInStop, waveInClose, waveInReset.

Pls advice.
10xs,
Nahum

HWAVEIN  hWaveIn
waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInStart(hWaveIn);

waveInStop(hWaveIn); //OR
waveInClose(hWaveIn); //OR
waveInReset(hWaveIn); //OR

UPDATE: Here is the code:

Starting:

waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInPrepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInAddBuffer(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInStart(hWaveIn);

 void CALLBACK waveInProc(  HWAVEIN hwi, UINT uMsg, DWORD dwInstance, 
                            DWORD dwParam1,   DWORD       dwParam2    )
  {

     if (uMsg == WIM_OPEN)
     {
     return;
     }
     if (uMsg == WIM_DATA)
     {
     //process data
     waveInAddBuffer(hWaveIn,(PWAVEHDR)dwParam1,sizeof(WAVEHDR));
     return;
     }
     if (uMsg == WIM_CLOSE) //NOT GETTING THIS MSG

     {
      printf("*****************got WIM_CLOSE\n");
     }
 }

So how to stop sampling and close the audio device?


Here is the code:
Starting:

waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInPrepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInAddBuffer(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInStart(hWaveIn);

 void CALLBACK waveInProc(  HWAVEIN hwi, UINT uMsg, DWORD dwInstance, 
                            DWORD dwParam1,   DWORD       dwParam2    )
  {

     if (uMsg == WIM_OPEN)
     {
     return;
     }
     if (uMsg == WIM_DATA)
     {
     //process data
     waveInAddBuffer(hWaveIn,(PWAVEHDR)dwParam1,sizeof(WAVEHDR));
     return;
     }
     if (uMsg == WIM_CLOSE) //NOT GETTING THIS MSG

     {
      printf("*****************got WIM_CLOSE\n");
     }
 }

So how to stop sampling and close the audio device?

10xs,
Nahum

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:59:00+00:00Added an answer on June 9, 2026 at 11:59 pm

    Are you checking your waveInOpen result?

    Because it works as expected:

    hWaveIn 0x005B7768, nMessage 0x03BE, nInstance 0, nParameter1 0, nParameter2 0
    nWaveInOpenResult 0, hWaveIn 0x005B7768
    hWaveIn 0x005B7768, nMessage 0x03BF (WIM_CLOSE), nInstance 0, nParameter1 0, nParameter2 0
    

    Code:

    #include "stdafx.h"
    #include <mmsystem.h>
    
    #pragma comment(lib, "winmm.lib")
    
    VOID CALLBACK waveInProc(HWAVEIN hWaveIn, UINT nMessage, DWORD_PTR nInstance, DWORD_PTR nParameter1, DWORD_PTR nParameter2)
    {
        _tprintf(_T("hWaveIn 0x%p, nMessage 0x%04X, nInstance %d, nParameter1 %d, nParameter2 %d\n"), hWaveIn, nMessage, nInstance, nParameter1, nParameter2);
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        WAVEFORMATEX Format = { WAVE_FORMAT_PCM, 1, 8000, 16000, 2, 16, 0 };
        HWAVEIN hWaveIn = NULL;
        const MMRESULT nWaveInOpenResult = waveInOpen(&hWaveIn, WAVE_MAPPER, &Format, (DWORD_PTR) &waveInProc, 0, CALLBACK_FUNCTION);
        _tprintf(_T("nWaveInOpenResult %d, hWaveIn 0x%p\n"), nWaveInOpenResult, hWaveIn);
        waveInStart(hWaveIn);
        waveInStop(hWaveIn);
        waveInClose(hWaveIn);
        return 0;
    }
    

    While processing data in real code make sure to take this into consideration: within the callback function:

    Applications should not call any system-defined functions from inside
    a callback function, except for EnterCriticalSection,
    LeaveCriticalSection, midiOutLongMsg, midiOutShortMsg,
    OutputDebugString, PostMessage, PostThreadMessage, SetEvent,
    timeGetSystemTime, timeGetTime, timeKillEvent, and timeSetEvent.
    Calling other wave functions will cause deadlock.

    To re-add buffer, you need to indicate such as need by signalling to another thread, using PostMessage or SetEvent, so that your code outside of the callback could receive this indication and re-add the empty buffer from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.