12-29-2010 02:07 PM
Hi all,
I have a program that is using the WinMM library to sample the wave-in in a buffer, for 0.015s every 0.030s.
The program works OK, but every now and then I get an error saying:
"A non-debuggable thread is trying to suspend execution at address 7C90120E.
Do you want to suspend execution?"
You can choose whether or not to suspend, and in either case the error will come again.
Sometimes it runs without a problem for about 30s, sometimes I get the error every second, so at very unregular intervals.
I tried to do the sampling in a seperate thread but it doesn't make any difference (conceirning the error)
I'm using LABWindows/CVI 9.0 at WindowsXP Professional 2002 sp3, using Windows SDK 7.1.
Does anyone know what could be the problem?
Regards, Dirk
Solved! Go to Solution.
12-29-2010 03:32 PM
I have not seen that error before but would probably need some of your code in order take a look. The suspen execution flag makes it sound like there is an error or memory issue and is trying to stop but can't (like a non-fatal run time engine would do). Not sure if those small time frames would have anything to do with it.
12-29-2010 03:45 PM
In the main program I initialize the Format:
pFormat.wFormatTag=WAVE_FORMAT_PCM; // simple, uncompressed format
pFormat.nChannels=1; // 1=mono, 2=stereo
pFormat.nSamplesPerSec=sampleRate; // 44100
pFormat.nAvgBytesPerSec=sampleRate*2; // = nSamplesPerSec * n.Channels * wBitsPerSample/8
pFormat.nBlockAlign=2; // = n.Channels * wBitsPerSample/8
pFormat.wBitsPerSample=16; // 16 for high quality, 8 for telephone-grade
pFormat.cbSize=0;
result = waveInOpen(&hWaveIn, WAVE_MAPPER,&pFormat,
0L, 0L, WAVE_FORMAT_DIRECT);
Then every 0.030s or so, getsound() is called at a TIMER_TICK_EVENT
getsound() is:
void getsound(void)
{
WAVEHDR WaveInHdr;
// Set up and prepare header for input
WaveInHdr.lpData = (LPSTR)waveIn;
WaveInHdr.dwBufferLength = NUMPTS*2;
WaveInHdr.dwBytesRecorded=0;
WaveInHdr.dwUser = 0L;
WaveInHdr.dwFlags = 0L;
WaveInHdr.dwLoops = 0L;
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WaveInHdr));
// Insert a wave input buffer
result = waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WaveInHdr));
if (result)
{
Fmt (ErrorMessage, "%s","Failed to read block from device");
MessagePopup ("Audio Error", ErrorMessage);
}
// Commence sampling input
result = waveInStart(hWaveIn);
if (result)
{
Fmt (ErrorMessage, "%s","Failed to start recording");
MessagePopup ("Audio Error", ErrorMessage);
}
// Wait until finished recording
do {} while (waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WaveInHdr))==WAVERR_STILLPLAYING);
}
Hope this helps!
12-29-2010 03:50 PM
I've tried Samples as long as 0.150 sec (ten times as large)
but the error still occurs
12-29-2010 04:03 PM
This is not a great answer, but I would be interested how long the do {} while function runs. That statement always seems to jump out at me. If you can, add a before and after time measure and maybe track how long it is running and print it out. Also, perhaps add a dummy statement within teh do while.
For example.
int before = time();
int i = 0;
do {
i++;
}
while ....
printf(time()-before);
printf(i);
Log/Print results how you wish since I left it as psuedocode.
Then maybe average 100 samples or as many as you can before it errors. I know this is not a solution, but this may help us steer in the correct direction. I know the do forever thing kind of jumps out at me since there isn't a timeout established.
12-29-2010 04:48 PM
Ah, excellent idea,
I made it output the times between the while repetitions as wel as total time to fill a buffer, some curious findings:
- most buffers take about 0.022s (instead of 0.015)
- some take only 0.012s (to fill a 0.015 buffer!!)
- nothing peculair happens before it goes into error...
I attached a report file of the timings...
12-29-2010 04:58 PM
Hmm well although informative, I'm not sure where the issue lies. May have to wait until a CVI expert chimes in. If it is run in release mode, does it error out or hang? This would lean more toward a build option issue.
12-29-2010 04:59 PM - edited 12-29-2010 05:00 PM
release or debug all the same...
(btw heres the code generating previous text-file: )
result = waveInStart(hWaveIn); total_old=total_new; if (result) { Fmt (ErrorMessage, "%s","Failed to start recording"); MessagePopup ("Audio Error", ErrorMessage); } // Wait until finished recording do { debug_time_old=debug_time_new; debug_time_new=Timer(); debug_i++; fprintf(f,"%d %f \n",debug_i,debug_time_new-debug_time_old); Delay(0.001); } while (waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WaveInHdr))==WAVERR_STILLPLAYING); total_new=Timer(); fprintf(f,"\ntotal time: %f\n\nnext buffer:\n",total_new-total_old); }
12-29-2010 05:05 PM
Hmm for gits and shiggles, try this:
debug_start = Timer(); fprintf(f,"start = %f",debug_start)); do { ProcessSystemEvents(); } while (waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WaveInHdr))==WAVERR_STILLPLAYING); total_new=Timer(); fprintf(f,"\ntotal time: %f\n\nnext buffer:\n",total_new-debug_start);
I tend to sprinkle ProcessSystemEvents throughout the code and would probably add it before and after the while loop as well. This will most likely slow the execution down, but nonetheless, possibly catch an error outside of this thread.
12-29-2010 05:13 PM
This shouldn't (and didn't) do any better, as the sound is recorded in a seperate thread..
(although if i run it in the main loop it still gives these errors)
attached the timing.txt after adding PrecessSystemEvents()