1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <ctype.h>
6 
7 /* plugin for lame v3.50. WILL NOT WORK for 3.13 */
8 
9 #define OUTPUT_BUF_LENGTH 4096
10 #define OFFSET_LENGTH 16
11 
12 #define PRINTOUT_INTERVAL       0.5
13 
14 int
lame_read_stat(double * current)15 lame_read_stat (double *current)
16 {
17 	char temp[OUTPUT_BUF_LENGTH];
18 	char string[100];
19 	char *string1;
20 	int bytes_read;
21 	/* Grab new ouput from 'lame'  */
22 	bytes_read = read (0, (void *) temp, sizeof (temp));
23         if (bytes_read > OFFSET_LENGTH) {
24                 sscanf (&temp[OFFSET_LENGTH], "%s%%)|", string);
25                 *current = atof(string) / 100.0;
26                 return (0);
27         }
28 	return (-1);
29 }
30 
31 int
main(int argc,char ** argv)32 main (int argc, char **argv)
33 {
34 	double current = 0.0;
35 
36 	while (1) {
37 		if (lame_read_stat (&current) == 0)
38 			/* print message in form [P 0.xxxxx]\n */
39 			printf ("[P %f]\n", current);
40 		usleep (PRINTOUT_INTERVAL * 1000000);
41 	}
42 }
43