Re: microphone level meter?

From: Jamey Hicks <jamey.hicks_at_hp.com>
Date: Fri, 24 Jan 2003 08:52:03 -0500

Kristof Van Laerhoven wrote:

>Hi all,
>
>I'm trying to implement a simple program that measures the ambient noise
>level, using the ipaq's microphone. The readings I get from /dev/dsp
>don't really make sense, though, most of them are 0 and the few others
>seem random: what am I doing wrong? I experimented with different values
>for speed, channels, and sample format: help!:
>
>Source code:
>
>int sample = AFMT_U8;
>int channels = 2;
>int speed = 16000;
>int ret;
>unsigned char buf[1024];
>int dsp = open("/dev/dsp", O_RDONLY);
>if (dsp!=-1) {
> ioctl(dsp, SNDCTL_DSP_SPEED, &speed);
> ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels);
> ioctl(dsp, SNDCTL_DSP_SETFMT, &sample);
> ret = read(dsp, buf, sizeof(buf));
> for (int i=0; i<ret; i++)
> fifo.add(buf[i]);
> close(dsp);
>}
>printf("the noise volume is: %f", fifo.get_volume());
>
>
>
Only 16-bit audio format is supported by the hardware.

Jamey
Received on Fri Jan 24 2003 - 13:35:58 EST

This archive was generated by hypermail 2.2.0 : Mon Jul 25 2005 - 17:19:02 EDT