alsa and sox questions
Ari Moisio
armoi at sci.fi
Sat Mar 30 00:26:40 EST 2002
Hi!
I use followinc c code to check record level. It will take two optinal
parameters: positive integer is time in seconds and negative interger is
warning level in decibels when program will send bell character to
terminal in addition to normal output.
Output is rms level and peak leven.
--
Mr. Ari Moisio, Niittykatu 7, 41160 Tikkakoski, +358-40-5055239
ari.moisio at iki.fi http://www.iki.fi/arimo PGP-keyID: 0x3FAF0F05
// Record level 'meter'
// Results: rms / peak in db.
// Compile gcc -lm vumeter.c -o vumeter
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <math.h>
int signo = 0;
void handler(int sno)
{
signo = sno;
}
int main(int argc, char **argv)
{
int t_val, max, secs = 5, retval = 0, c_rms = 0, warn = -1, tmp;
long s_cnt = 0, s_sum = 0;
float level = 0.0, rms=0.0, max_level=99.9, s_rms=0.0;
FILE *dsp_fd;
signal(SIGINT, handler);
for (tmp = 1; tmp < argc; tmp++)
{
t_val = atoi(argv[tmp]);
if (t_val > 0) secs = t_val;
if (t_val < 0) warn = -t_val;
}
// endfor
dsp_fd = fopen("/dev/dsp","r");
max = 0;
s_sum = 0;
for (; secs > 0 && signo == 0; secs -= 1)
{
max = 0;
s_sum = 0;
s_cnt = 0;
for (s_cnt = 1; s_cnt <= 8000; s_cnt++)
{
t_val = fgetc(dsp_fd) - 0x80;
if (t_val < 0) t_val = -t_val;
if (t_val > 127) t_val = 127;
if (t_val > max) max = t_val;
s_sum += t_val * t_val;
}
// endfor
if (signo ==0)
{
level = (log10(127.0 / max)) * 20;
rms = (log10(127.0 / sqrt(s_sum / s_cnt)) * 20);
if (level < warn) printf("\a");
printf("%4.1f / %4.1f\n", -rms, -level);
if (level < max_level) max_level = level;
s_rms += rms;
c_rms++;
}
// endif signo eq 0
}
// endfor secs
fclose(dsp_fd);
printf("============\n%4.1f / %4.1f\n", -s_rms / c_rms, -max_level);
retval = floor(max_level);
return retval;
}
More information about the Speakup
mailing list