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());
Cheers,
Kristof.
Received on Fri Jan 24 2003 - 13:15:02 EST
This archive was generated by hypermail 2.2.0 : Mon Jul 25 2005 - 17:19:02 EDT