I have tried to pipe the output of arecord using c:
int main(int argc,char *argv[])
{
FILE* file = popen("arecord -r 8000 --format S32_LE -D plughw:0,0 -d 4", "r");
long buffer[100];
FILE *fp;
fp=fopen("./record.dat", "w+");
int i;
for (i=0; i<40000; i++){
fscanf(file, "%ld", &buffer[i%100]);
fprintf(fp,"%d\t%ld\n", i , buffer[i%100] ) ;
}
pclose(file);
fclose(fp) ;
FILE *p = popen(GNUPLOT,"w");
fprintf(p,"plot 'record.dat' lt rgb 'red' title 'yeag' \n");
fclose(p);
return 0;
}
I have chosen "long" because of the "signed 32 bit" specification in the arecord command. However, gnuplot is showing me nonsense. Also the program finishes after milliseconds although I want to record for 4 seconds. What am I doing wrong?
it seems like fscanf() is for text not for binary. Thanks to Pablo. A corrected version looks like:
which returns a beautiful plot: waves