Program stopped responding

I finished my program so I went to test it on other computer. And it stopped working as soon as I started it. The problem was that I put "Sleep" function inside between WaveInStart and WaveInStop to allow the program to record 6.5 seconds of audio and then stop.

When I removed Sleep function everything worked fine. So, is there any other way to automatically stop recording after some time? With Sleep it works fine on my computer but it doesn't on the other.
I have now tried even with this code instead Sleep(), but the same thing. Could it be something else? Why it won't work on my laptop but it works on a computer that I compiled the code on?

MMRESULT wavStrt = waveInStart(wih);
time_t ft;
time(&ft);
int tdif=0;

while (tdif <= 7){
time_t st;
time(&st);
tdif = difftime(st, ft);
}
if (tdif > 6){
MMRESULT wavStop = waveInStop(wih);


MMRESULT unprep = waveInUnprepareHeader(wih, &header, sizeof(WAVEHDR));
if (unprep == MMSYSERR_NOERROR)


waveInClose(wih);
}
This usually happens when your application is trying to link to something at run time that isn't there. Try installing the appropriate C-Run Time library for the compiler you are using on the laptop.
Can you please tell me what RunTime Library should I install? Here are all #includes that I'm using.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <iostream>
#include <math.h> 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <windows.h>
#include <fstream>
#include <vector>
#include <Mmreg.h>
#include <Mmsystem.h>
#include <time.h>
#include <cstdio>
#pragma comment(lib, "winmm.lib") 
#pragma comment(lib, "user32.lib")  
It would depend on the compiler that you are using. If for example you are using the version of cl for MS Visual Studio 2012, then you want to install the MSCRT 2012 version.
I'm using Visual Studio Community 2013 and I have tried installing this http://www.microsoft.com/en-us/download/details.aspx?id=30679 but the same thing. In the end I will have to install Visual Studio on my laptop also.
Read what I wrote again. Then try this one: http://www.microsoft.com/en-us/download/details.aspx?id=40784
I did. It's the same thing. The program opens but stops when it has to record some audio data. This part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MMRESULT wavStrt = waveInStart(wih);
	time_t ft;
	time(&ft);
	int tdif=0;
	
	while (tdif <= 7){
		time_t st;
		time(&st);
		tdif = difftime(st, ft);
	}
	if (tdif > 6){
	
		MMRESULT wavStop = waveInStop(wih);


		MMRESULT unprep = waveInUnprepareHeader(wih, &header, sizeof(WAVEHDR));
		if (unprep == MMSYSERR_NOERROR)


			waveInClose(wih);
	}


When I remove that part that waits 6 seconds, everything works. But it then doesn't record any data because it starts and stops at the same time.
Last edited on
Can we see more code? I have one or two ideas but they're guess work at this point.
I figured it out. It was my own stupidity. I told my timer to wait for "t" miliseconds. And "t" was calculated from signal coming in to my microphone. I did not setup microphone correctly so no sound was coming into a program and no data was extracted from it. So then my timer went crazy and crashed. :) Now I set it up so "t" was pre-set and updated later if a signal appears.
All is well that ends well.
Topic archived. No new replies allowed.