Page 1 of 1

Microphone volume

Posted: Mon Aug 25, 2014 12:53 pm
by Derrik
How do I get the volume of the microphone? I found only examples for how to record.

I am looking for a simple way of doing:

Code: Select all

if(getMicVol() > 127) {
printf("Blowing!");
}

Re: Microphone volume

Posted: Tue Aug 26, 2014 12:22 pm
by sverx
You have to record to a buffer and check the values there. If MAX-MIN> some threshold I bet you could assume someone is blowing into the mic. Surely there are better ways :roll:

Re: Microphone volume

Posted: Fri Sep 19, 2014 5:08 pm
by Derrik
I tried recording a buffer and getting the volume, but I couldn't get it to work.

I am using this example:

devkitPro\examples\nds\audio\micrecord\

In the micHandler function I add this to the end:

Code: Select all

static u8 oldsmp = 0;
	register s8 smp_s = (*(char *)data) ^ 0x80;
	register u8 smp = ((smp_s < 0) ? (-smp_s) : smp_s) << 1;
	//return oldsmp = (oldsmp + smp) >> 1;
	int vol = oldsmp = (oldsmp + smp) >> 1;
	//printf("Vol: %d\n", oldsmp = (oldsmp + smp) >> 1);
	
	if(vol > 200) printf("....\n");
	else if(vol > 150) printf("...\n");
	else if(vol > 100) printf("..\n");
	else if(vol > 50) printf(".\n");
	else printf(".\n");
I based the code from the PAlib function, however it doesn't seem to give accurate results so I think it is incorrect.