discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] GNU Stereo audio --> wave file


From: Chuck Swiger
Subject: [Discuss-gnuradio] GNU Stereo audio --> wave file
Date: Sun, 06 Feb 2005 11:39:48 -0500

Gang - Here's how to export two audio channels and get stereo wav, mp3, etc.

Sound card audio ranges from -1 to 1 so we scale by 32768 (-32767 to 32768)
then combine two float streams to one complex stream and save to a file:

----------------------------------------------------------------------
        scale1 = gr.multiply_const_ff(32767)
        scale2 = gr.multiply_const_ff(32767)
        combine = gr.float_to_complex ()
        file_sink = gr.file_sink (gr.sizeof_gr_complex, "fm_stereo_out")

#leave tail connect to audio_sink to listen and record at the same time

        self.connect (tail[0], scale1)
        self.connect (tail[1], scale2)
        self.connect (scale1,(combine,0))
        self.connect (scale2,(combine,1))
        self.connect (combine,file_sink)
--------------------------------------------------------------------------

The secret sauce is the following which will convert the complex 2 channel float
format to "signed word" (two channel short) format that sox understands:

--------------------------------------------------------------------------
/* convert double 4-byte float (complex) data to
   double 2-byte short numbers for 2 channel stereo */

#include <stdio.h>

FILE *input_file, *output_file;
int i,int_j,int_k;
float j,k;

int main(int argc, char *argv[]) {

if ( argc < 4 ) {
   printf("\nUsage: raw2num <input file> <output file> <number of samples>\n");
   printf("Exampel: ./raw2num fm_out_complex fm_out.sw 1920000\n");
   exit(1);
   }

input_file = fopen(argv[1],"r");
output_file = fopen(argv[2],"w");

for (i=0;i<atoi(argv[3]);i++) {
    fread(&j,4,1,input_file);
    fread(&k,4,1,input_file);
    int_j = (int) j;
    int_k = (int) k;
    fwrite(&int_j,2,1,output_file);
    fwrite(&int_k,2,1,output_file);
    }

fclose(input_file);
fclose(output_file);
}

------------------------------------------------------------------------------------------------------

Not ready for prime time but works. Then run the output file thru sox:

$ sox -r 32000 -c 2 fm_stereo_out.sw fm_stereo_out.wav

then you can load it into Cooledit/Audacity, convert to mp3, etc.
sample here: http://webpages.charter.net/cswiger/fm_stereo.html

--Chuck


reply via email to

[Prev in Thread] Current Thread [Next in Thread]