Convert encoded audio file to text with signal values

Viewed 1057

I've been programming in c for the first time with audio files. I found this code which supposedly should read an audio file and then write a csv file containing several info in order to analyse the audio waves,that in case will be a simple voice: i'm interested in amplitude of the waves, in the timbre of the voice and its hight and extension.

           main () {   
           // Create a 20 ms audio buffer (assuming Fs = 44.1 kHz)
           int16_t buf[N] = {0}; // buffer
           int n;                // buffer index

          // Open WAV file with FFmpeg and read raw samples via the pipe.
          FILE *pipein;
          pipein = popen("ffmpeg -i whistle.wav -f s16le -ac 1 -", "r");
          fread(buf, 2, N, pipein);
          pclose(pipein);

          // Print the sample values in the buffer to a CSV file
          FILE *csvfile;
          csvfile = fopen("samples.csv", "w");
          for (n=0 ; n<N ; ++n) fprintf(csvfile, "%d\n", buf[n]);
          fclose(csvfile);

       }

Could someone explain me in detail how can I read an audio file so that I could extract from it the info I need? Referring to this code, could someone explain me the meaning of the pipe at line 8

pipein = popen("ffmpeg -i whistle.wav -f s16le -ac 1 -", "r");

p.s. I already know how to read the header of the audio file, which contains a lot of useful info, but I also want to analyse the entire audio file, sample by sample.

1 Answers
Related