Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[ac617d]: plugins / ripperX_plugin-lame.c Maximize Restore History

Download this file

ripperX_plugin-lame.c    42 lines (34 with data), 826 Bytes

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