From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from netsonic.fi ([194.29.192.20] helo=nalle.netsonic.fi ident=root) by speech.braille.uwo.ca with esmtp (Exim 3.34 #1 (Debian)) id 16rBNy-0002tk-00 for ; Sat, 30 Mar 2002 00:26:42 -0500 Received: from thp.local (qmailr@wanda69.adsl.netsonic.fi [81.17.192.69]) by nalle.netsonic.fi (8.10.1/8.10.1) with SMTP id g2U5Qjg10224 for ; Sat, 30 Mar 2002 07:26:46 +0200 Received: (qmail 13033 invoked from network); 30 Mar 2002 05:26:44 -0000 Received: from nkl.local (qmailr@192.168.2.4) by gw.local with SMTP; 30 Mar 2002 05:26:44 -0000 Received: (qmail 28761 invoked by uid 1013); 30 Mar 2002 05:26:41 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 30 Mar 2002 05:26:41 -0000 Date: Sat, 30 Mar 2002 07:26:40 +0200 (EET) From: Ari Moisio X-X-Sender: armoi@nkl.local To: Speakup mailing list Subject: Re: alsa and sox questions In-Reply-To: <20020330085344.C19619@joana.gotss.net> Message-ID: X-PGP-KeyID: 0x3FAF0F05 X-PGP-Key-fingerprint: 8A 91 96 E2 98 64 D0 4D 57 5E 3E EE 72 E9 DD D2 MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) Sender: speakup-admin@braille.uwo.ca Errors-To: speakup-admin@braille.uwo.ca X-BeenThere: speakup@braille.uwo.ca X-Mailman-Version: 2.0.8 Precedence: bulk Reply-To: speakup@braille.uwo.ca X-Reply-To: armoi@sci.fi List-Help: List-Post: List-Subscribe: , List-Id: Speakup is a screen review system for Linux. List-Unsubscribe: , List-Archive: 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@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 #include #include #include 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; }