Microphone volume

Post Reply
Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Microphone volume

Post by Derrik » Mon Aug 25, 2014 12:53 pm

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!");
}

sverx
Posts: 94
Joined: Wed Aug 12, 2009 2:56 pm
Location: github.com/sverx
Contact:

Re: Microphone volume

Post by sverx » Tue Aug 26, 2014 12:22 pm

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:

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Microphone volume

Post by Derrik » Fri Sep 19, 2014 5:08 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests