Recording too much data

Hi everyone,

I’m currently trying to record data from a microphone, access the raw data of the recorded sound, and then hand it over to a homemade karaoke library that should use it.

But I’ve come across a few issues trying to get data from the microphone.
There’s something a bit odd with my code : it seems the microphone records data faster than it should.

I have an instance of a class that updates each frame. In its update, it displays both the time that passed since the last update, and the amount of data available in the sound I did a sound->recordStart(…) on. And my problem is that I have more data available than what should be available, given the time since last update and the sound frequency.

The setup for the recording sound is the exact same as in the “record” example, and here’s my code displaying obviously incorrect values :

in the .h :

class myClass 
{

private :
	void initialization();
	void update(float deltaTime);
	
	FMOD::System* system;
	FMOD_RESULT result;
	const unsigned int driverId;
	unsigned int lastRecordPos;	
}

in the .cpp :

//Called every frame
// delta Time is the time the last frame took to complete
void myClass::update(float deltaTime) {

result = system->update();
ERRCHECK(result);

/**
*	Here I print deltaTime, which is given by Unreal Engine and is always equal to 0.008334s
*	I'm creating a sound for recording as in the "record" example, with a frequency of 16 000 hz.
*	This means the maximum number of values that should become available in the recording sound each frame is :
*	0.0008334 * 16 000 = 133 values
*/
//I'm on unreal engine, but how I print is equivalent to the following
printf("deltaTime : %f", deltaTime);												//returns 0.008334 ...
printf("max number of data values stacked this frame : %f", deltaTime * 16000);		//returns 133.33 ...

unsigned int recordPos = 0;
result = system->getRecordPosition(driverId, &recordPos);	//driverID is a valid driver ID that has been determined in initialization
ERRCHECK(result);
	
if (recordPos != lastRecordPos)
{
	unsigned int recordDelta = (recordPos >= lastRecordPos) ? (recordPos - lastRecordPos) : (recordPos + soundLength - lastRecordPos);
	lastRecordPos = recordPos;
	
	/**
	*	Here I print the value of recordDelta, when the value returned by getRecordPosition() changes, which means every other frame or so.
	*	So, I should obtain a value that is inferior to the maximum amount of data the sound can record in two frames :
	*	I should have : recordDelta <= number of frames since last time I got here * max number of values the microphone can record in one frame
	*				so:	recordDelta <= 2 * 133 = 266
	*	But each time it prints, I got recordDelta = 313, even when it took 3 frames instead of 2 frames to enter the if statement 
	*/
	//I'm on unreal engine, but how I print is equivalent to the following
	printf("recordDelta: %u", recordDelta);											//returns 313 each time it prints something, no matter how long it took to get here
}
}

I understand why I can sometimes get less values than what have actually been recorded, because of system->getRecordPosition() updating by chunks.
But I thought that system->getRecordPosition() can’t return a value beyond the actual record position.
If so, I can’t explain why I get more values than I should.
Is there anything I misunderstood that would legitimate this discrepancy ?
Like something with the setup of the exinfo used to create the sound in the example?

Thanks for your help !

It sounds like you are just seeing the chunking nature of the record update. It might take a an uneven number of your frames compare with the record chunk size. So sometimes you see an increment in 2 frames, sometimes 3 etc.

If you add up all the record deltas as a running total and compare that with time elapsed do you see a significant drift? Also, ensure that you reference time is correct.

Looks like the deltaTime sent by Unreal Engine isn’t that precise.
Problem solved, thanks.