Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. About wavein API

About wavein API

Scheduled Pinned Locked Moved C / C++ / MFC
jsonhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    minihotto
    wrote on last edited by
    #1

    Hello I have a program using waveIn API. This is part of my code. Originally, my program has a deadlock while running waveInReset. I google it and it is said putting the wavein function in the callback function is forbidden. So I delete the code which I put waveinstop in the callback function. It can run waveInReset and waveInunprepareheader successfully. But it halt at waveInClose. I can't find information about waveInClose halt. Can anybody solve this problem?Thx, Jane. while(1){ if(isopen==1){ if(waveInOpen(&hWavin,WAVE_MAPPER, &wfx,(DWORD_PTR)WaveInProc ,0, CALLBACK_FUNCTION) == MMSYSERR_NOERROR) { isopen=1; for(int i=0;i<4;i++) { mmrr = waveInPrepareHeader(hWavin, headersend + i, sizeof(WAVEHDR)); mmrr = waveInAddBuffer(hWavin, headersend + i, sizeof(WAVEHDR)); } mmrr = waveInStart(hWavin); } } if(isclose==1) { if(hWavin) { mmrr=waveInReset(hWavin); for(int i=0;i<4;i++) { mmrr=waveInUnprepareHeader(hWavin,headersend+i, sizeof(WAVEHDR)); } for(int i=0;i<4;i++) { mmrr=waveInReset(hWavin); } mmrr=waveInClose(hWavin); sclose=0; } } } static void CALLBACK WaveInProc(HWAVEIN hw, UINT uMsg,DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD dwParam2) { WAVEHDR* curhdrin = (WAVEHDR*)dwParam1; if(uMsg != WIM_DATA) return; if(isclose==1){ Sleep(1000); return; } ///other code//// waveInAddBuffer(hw, curhdrin, sizeof(WAVEHDR)); }

    M 1 Reply Last reply
    0
    • M minihotto

      Hello I have a program using waveIn API. This is part of my code. Originally, my program has a deadlock while running waveInReset. I google it and it is said putting the wavein function in the callback function is forbidden. So I delete the code which I put waveinstop in the callback function. It can run waveInReset and waveInunprepareheader successfully. But it halt at waveInClose. I can't find information about waveInClose halt. Can anybody solve this problem?Thx, Jane. while(1){ if(isopen==1){ if(waveInOpen(&hWavin,WAVE_MAPPER, &wfx,(DWORD_PTR)WaveInProc ,0, CALLBACK_FUNCTION) == MMSYSERR_NOERROR) { isopen=1; for(int i=0;i<4;i++) { mmrr = waveInPrepareHeader(hWavin, headersend + i, sizeof(WAVEHDR)); mmrr = waveInAddBuffer(hWavin, headersend + i, sizeof(WAVEHDR)); } mmrr = waveInStart(hWavin); } } if(isclose==1) { if(hWavin) { mmrr=waveInReset(hWavin); for(int i=0;i<4;i++) { mmrr=waveInUnprepareHeader(hWavin,headersend+i, sizeof(WAVEHDR)); } for(int i=0;i<4;i++) { mmrr=waveInReset(hWavin); } mmrr=waveInClose(hWavin); sclose=0; } } } static void CALLBACK WaveInProc(HWAVEIN hw, UINT uMsg,DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD dwParam2) { WAVEHDR* curhdrin = (WAVEHDR*)dwParam1; if(uMsg != WIM_DATA) return; if(isclose==1){ Sleep(1000); return; } ///other code//// waveInAddBuffer(hw, curhdrin, sizeof(WAVEHDR)); }

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      How does isclose ever get set to 1? Why is there no waveInStop() call anywhere? Why do you use the Sleep() call in the waveInProc? That's really going to mess things up if isclose==1. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      M 1 Reply Last reply
      0
      • M Mark Salsbery

        How does isclose ever get set to 1? Why is there no waveInStop() call anywhere? Why do you use the Sleep() call in the waveInProc? That's really going to mess things up if isclose==1. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        M Offline
        M Offline
        minihotto
        wrote on last edited by
        #3

        Thx for ur reply. I have a button that would let user click to stop recording. That would make isclose = 1; Originally, I use waveInStop but I waveInStop only stop recording. waveInReset would stop recording and set the position to 0. I see some information in the Internet that says use waveInUnPrepareHeader before using waveInReset. Originally, I don't use Sleep() function,but it has same problem. I write it in a new small program as follow. It halts at waveInReset. If I delete waveInReset, waveInUnPrepareHeader and waveInClose falses and returns 33. #include "stdafx.h" #include #include #include #include #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "Winmm.lib") using namespace System; using namespace std; static void CALLBACK WaveInProc(HWAVEIN, UINT, DWORD , DWORD , DWORD ); static const int SNDNBUF = 2; static const int SNDSIZEBUF = 320; HWAVEOUT hWavout; MMRESULT mmrr; WAVEHDR headersend[SNDNBUF]; char hdrDatasend[SNDSIZEBUF*SNDNBUF]; HWAVEIN hWavin; int _tmain(int argc, _TCHAR* argv[]) { WAVEFORMATEX wfx; wfx.nSamplesPerSec = 8000; wfx.nChannels = 1; wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.wBitsPerSample = 16; wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8); wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; memset(headersend, 0,sizeof(WAVEHDR)*SNDNBUF); for(int i=0;i<sndnbuf;i++){ headersend[i].lpData = hdrDatasend + i*SNDSIZEBUF; headersend[i].dwBufferLength = SNDSIZEBUF;} memset(hdrDatasend,0,SNDSIZEBUF*SNDNBUF); if(waveInOpen(&hWavin,WAVE_MAPPER, &wfx,(DWORD_PTR)WaveInProc ,0, CALLBACK_FUNCTION) == MMSYSERR_NOERROR){ for(int i=0;i{ mmrr = waveInPrepareHeader(hWavin, headersend + i, sizeof(WAVEHDR)); mmrr = waveInAddBuffer(hWavin, headersend + i, sizeof(WAVEHDR));} mmrr = waveInStart(hWavin); } int i; cin >> i; mmrr=waveInStop(hWavin); mmrr=waveInReset(hWavin); Sleep(500); for(int i=0;i<sndnbuf;i++){ if ((headersend+i)->dwFlags & WHDR_PREPARED){ mmrr=waveInUnprepareHeader(hWavin,headersend+i, sizeof(WAVEHDR));} Sleep(500); mmrr=waveInClose(hWavin); cin >> i; return 0; } static void CALLBACK WaveInProc(HWAVEIN hw, UINT uMsg,DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD dwParam2) { WAVEHDR* curhdrin = (WAVEHDR*)dwParam1; if(uMsg != WIM_DATA)return; waveInAddBuffer(hw, curhdrin, sizeof

        M 1 Reply Last reply
        0
        • M minihotto

          Thx for ur reply. I have a button that would let user click to stop recording. That would make isclose = 1; Originally, I use waveInStop but I waveInStop only stop recording. waveInReset would stop recording and set the position to 0. I see some information in the Internet that says use waveInUnPrepareHeader before using waveInReset. Originally, I don't use Sleep() function,but it has same problem. I write it in a new small program as follow. It halts at waveInReset. If I delete waveInReset, waveInUnPrepareHeader and waveInClose falses and returns 33. #include "stdafx.h" #include #include #include #include #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "Winmm.lib") using namespace System; using namespace std; static void CALLBACK WaveInProc(HWAVEIN, UINT, DWORD , DWORD , DWORD ); static const int SNDNBUF = 2; static const int SNDSIZEBUF = 320; HWAVEOUT hWavout; MMRESULT mmrr; WAVEHDR headersend[SNDNBUF]; char hdrDatasend[SNDSIZEBUF*SNDNBUF]; HWAVEIN hWavin; int _tmain(int argc, _TCHAR* argv[]) { WAVEFORMATEX wfx; wfx.nSamplesPerSec = 8000; wfx.nChannels = 1; wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.wBitsPerSample = 16; wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8); wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; memset(headersend, 0,sizeof(WAVEHDR)*SNDNBUF); for(int i=0;i<sndnbuf;i++){ headersend[i].lpData = hdrDatasend + i*SNDSIZEBUF; headersend[i].dwBufferLength = SNDSIZEBUF;} memset(hdrDatasend,0,SNDSIZEBUF*SNDNBUF); if(waveInOpen(&hWavin,WAVE_MAPPER, &wfx,(DWORD_PTR)WaveInProc ,0, CALLBACK_FUNCTION) == MMSYSERR_NOERROR){ for(int i=0;i{ mmrr = waveInPrepareHeader(hWavin, headersend + i, sizeof(WAVEHDR)); mmrr = waveInAddBuffer(hWavin, headersend + i, sizeof(WAVEHDR));} mmrr = waveInStart(hWavin); } int i; cin >> i; mmrr=waveInStop(hWavin); mmrr=waveInReset(hWavin); Sleep(500); for(int i=0;i<sndnbuf;i++){ if ((headersend+i)->dwFlags & WHDR_PREPARED){ mmrr=waveInUnprepareHeader(hWavin,headersend+i, sizeof(WAVEHDR));} Sleep(500); mmrr=waveInClose(hWavin); cin >> i; return 0; } static void CALLBACK WaveInProc(HWAVEIN hw, UINT uMsg,DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD dwParam2) { WAVEHDR* curhdrin = (WAVEHDR*)dwParam1; if(uMsg != WIM_DATA)return; waveInAddBuffer(hw, curhdrin, sizeof

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          The order should be: waveInStop waveInReset waveInUnprepareHeader (for all buffers) And get rid of the Sleep() calls. There is absolutely NO reason for them. When you prepare the headers, you must initialize dwFlags (Use 0 for input buffers) as well as lpData and dwBufferLength. Also, IMO, "headersend + i" is confusing to read. I'd use "&headersend[i]". Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups