Click here to Skip to main content
15,921,643 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralTooltips for combo Pin
balajeedurai28-Oct-04 22:21
balajeedurai28-Oct-04 22:21 
GeneralRe: Tooltips for combo Pin
hou_12628-Oct-04 22:38
hou_12628-Oct-04 22:38 
Generalinstall Pin
hou_12628-Oct-04 22:03
hou_12628-Oct-04 22:03 
GeneralRe: install Pin
Arsalan Malik28-Oct-04 23:13
Arsalan Malik28-Oct-04 23:13 
GeneralRe: install Pin
ThatsAlok29-Oct-04 0:03
ThatsAlok29-Oct-04 0:03 
GeneralBrowser Control performance Issue Pin
nabil_shams28-Oct-04 21:47
nabil_shams28-Oct-04 21:47 
GeneralRe: Browser Control performance Issue Pin
Sujan Christo29-Oct-04 1:10
Sujan Christo29-Oct-04 1:10 
Generalaudio - waveInPrepareHeader() problem Pin
normanS28-Oct-04 21:46
normanS28-Oct-04 21:46 
I am writing a "C" application (not C++, not MFC) running on Win98SE which captures audio from line-in into a wrap-around ring of 40mSec buffers. When the user stops capture, the last audio which was captured is combined with PAL video frames (25Hz) from a frame grabber into an AVI file.

The capture works fine with a small numbers of buffers (125 buffers for 5 seconds), but when I try 1 minute (1500 buffers), the program gets to about buffer 300 during the waveInPrepareHeader() stage, which then returns an error value of 7 (MMSYSERR_NOMEM, explained in the mmsystem.h file as "memory allocation error".) About this time, Win98 becomes unstable! Once, Windows gave the error "System is dangerously low on resources . . .".

I ran resource meter, and when MMSYSERR_NOMEM is reported by my program, resource meter reports 92% system resources, 92% user resources, 95% GDI resources. System monitor reports 550 Meg of free physical memory.

Does anyone know what waveInPrepareHeader() is actually doing, what the system is running out of, and how I can fix it?

I can work around the problem by grabbing the audio in half-second chunks instead, but that complicates the code.

The test program runs fine on Windows XP, so I could also try to migrate to XP, but I want to understand what is happening!

Any ideas?

Here is a console application which demonstrates the problem (on my PC, it fails at header 301 or so)

// AudioTest.c : console application.<br />
<br />
#include "stdafx.h"<br />
#include <windows.h><br />
#include <vfw.h><br />
#include <mmsystem.h><br />
<br />
#define DEF_BlocksPerSecond 25<br />
#define DEF_NumAudioBlocks 1500<br />
// grabbing at 25Hz to match PAL video frames, 1500 frames = 60 seconds<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
   unsigned int uiNumWaveInDevices;<br />
   unsigned int uiCounter;<br />
   unsigned int uiReturn;<br />
   char szTempString[100];<br />
   WAVEINCAPS WaveInCaps;<br />
   BOOL bSoundModeValid;<br />
   HWAVEIN hWaveInDevice;<br />
   WAVEFORMATEX WaveFormat;<br />
   unsigned int uiAudioBufferNumBytes;<br />
<br />
   WAVEHDR WaveHeaders[DEF_NumAudioBlocks];<br />
<br />
   // going to capture at 11.025Hz, Mono, 16 bps<br />
   uiAudioBufferNumBytes = 11025 * 2 / DEF_BlocksPerSecond;<br />
<br />
   uiNumWaveInDevices = waveInGetNumDevs();<br />
<br />
   for (uiCounter=0; uiCounter < uiNumWaveInDevices; uiCounter++)<br />
   {<br />
      // Check device can do mono, 11.025kHz, 16 bit/sample<br />
      waveInGetDevCaps(uiCounter, &WaveInCaps, sizeof(WaveInCaps));<br />
      bSoundModeValid = WaveInCaps.dwFormats & WAVE_FORMAT_1M16;<br />
      if (bSoundModeValid)<br />
         break; // Stop with first suitable device<br />
   }<br />
<br />
   if (!bSoundModeValid)<br />
      return(1); // First possible error exit<br />
<br />
   // Hard-code the wave format - mono, 16bit, 11.025kHz<br />
   WaveFormat.wFormatTag = WAVE_FORMAT_PCM;<br />
   WaveFormat.nChannels = 1; // Mono<br />
   WaveFormat.nSamplesPerSec = 11025; // 11.025 kHz<br />
   WaveFormat.nBlockAlign = 2; // 2 bytes per sample<br />
   WaveFormat.wBitsPerSample = 16; // 16 bits per sample<br />
   WaveFormat.nAvgBytesPerSec = 11025 * 2; // obvious<br />
   WaveFormat.cbSize = 0; // no additional data<br />
<br />
   hWaveInDevice = NULL;<br />
   <br />
   uiReturn = waveInOpen(&hWaveInDevice,uiCounter-1,&WaveFormat,0,0,CALLBACK_NULL);<br />
   if (uiReturn != MMSYSERR_NOERROR)<br />
   {<br />
      MessageBox(0, "Error opening wave in device", "WaveInOpen Error",<br />
            MB_OK);<br />
      return (2); // Second possible error exit<br />
   }<br />
<br />
   // Create the buffers<br />
   for(uiCounter = 0; uiCounter<DEF_NumAudioBlocks; uiCounter++)<br />
   {<br />
      // Allocate storage space for wave data<br />
      WaveHeaders[uiCounter].lpData = <br />
            GlobalLock(GlobalAlloc(GMEM_FIXED, uiAudioBufferNumBytes));<br />
      if (WaveHeaders[uiCounter].lpData == NULL)<br />
      {<br />
         MessageBox(0, "Error allocating wave data", "Wave Data Error",<br />
               MB_OK);<br />
         return (3); // 3rd error - rely on Windows to un-allocate on exit<br />
      }<br />
<br />
      WaveHeaders[uiCounter].dwBufferLength = uiAudioBufferNumBytes;<br />
      WaveHeaders[uiCounter].dwBytesRecorded = 0;<br />
      WaveHeaders[uiCounter].dwUser = 0;<br />
      WaveHeaders[uiCounter].dwFlags = 0;<br />
      WaveHeaders[uiCounter].dwLoops = 0;<br />
      uiReturn = waveInPrepareHeader(hWaveInDevice, &(WaveHeaders[uiCounter]),<br />
               sizeof(WAVEHDR));<br />
      if (uiReturn != MMSYSERR_NOERROR )<br />
      {<br />
         sprintf(szTempString, "Error %d preparing header %d.",<br />
               uiReturn, uiCounter);<br />
         MessageBox(0, szTempString, "Wave Data Error", MB_OK);<br />
         return(4);<br />
      }<br />
   }<br />
<br />
   MessageBox(0, "Allocated and prepared all buffers - cleaning up!",<br />
         "All successful!", MB_OK);<br />
   // Problem not repeated - clean up & exit!!!<br />
   // OK, I don't clean up - hopefully Windows does!!!<br />
<br />
   return 0;<br />
}

GeneralRe: audio - waveInPrepareHeader() problem Pin
Blake Miller29-Oct-04 4:54
Blake Miller29-Oct-04 4:54 
GeneralRe: audio - waveInPrepareHeader() problem Pin
Anonymous29-Oct-04 19:06
Anonymous29-Oct-04 19:06 
GeneralRe: audio - waveInPrepareHeader() problem Pin
Blake Miller1-Nov-04 4:09
Blake Miller1-Nov-04 4:09 
GeneralReply to Oliv Pin
normanS31-Oct-04 20:51
normanS31-Oct-04 20:51 
GeneralAbout "SHChangeNotifyRegister" Pin
Na_Su28-Oct-04 21:37
Na_Su28-Oct-04 21:37 
GeneralRe: About &quot;SHChangeNotifyRegister&quot; Pin
Blake Miller29-Oct-04 5:02
Blake Miller29-Oct-04 5:02 
QuestionHow to add a response file to the project dependencies? Pin
AlxZ28-Oct-04 20:47
AlxZ28-Oct-04 20:47 
GeneralWindows Media Format SDK IWMSyncReader Problem Pin
ytod28-Oct-04 15:54
ytod28-Oct-04 15:54 
GeneralRe: Windows Media Format SDK IWMSyncReader Problem Pin
aasikRaja7-Oct-12 23:20
aasikRaja7-Oct-12 23:20 
GeneralCPreviewWnd Pin
BaldwinMartin28-Oct-04 11:20
BaldwinMartin28-Oct-04 11:20 
GeneralAccessing to keyb controller from C++ Pin
ninjanear28-Oct-04 10:59
professionalninjanear28-Oct-04 10:59 
GeneralAdding a button to a Tab Control Pin
RobJones28-Oct-04 10:42
RobJones28-Oct-04 10:42 
Generalabout device instance enumeration Pin
momer28-Oct-04 9:21
momer28-Oct-04 9:21 
GeneralRe: about device instance enumeration Pin
Ryan Binns28-Oct-04 18:21
Ryan Binns28-Oct-04 18:21 
GeneralApplication Help for an MFC application Pin
digwizfox28-Oct-04 8:24
digwizfox28-Oct-04 8:24 
GeneralRe: Application Help for an MFC application Pin
pubududilena28-Oct-04 17:37
pubududilena28-Oct-04 17:37 
Generaldialog based mfc app Pin
sv4228-Oct-04 7:48
sv4228-Oct-04 7:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.