[Top][All Lists]

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

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

From: Eric Blossom
Subject: Re: [Discuss-gnuradio] GNU Stereo audio --> wave file
Date: Sun, 6 Feb 2005 09:19:29 -0800
User-agent: Mutt/1.5.6i

On Sun, Feb 06, 2005 at 11:39:48AM -0500, Chuck Swiger wrote:
> 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:

You could also use a combination of gr.interleave and gr.float_to_short

Something like this:

          interleaver = gr.interleave (gr.sizeof_float)
          scale = gr.multiply_const_ff (32767)
          f2s = gr.float_to_short ()
          file_sink = gr.file_sink (gr.sizeof_short, "fm_stereo_out.sw")
          self.connect (tail[0], (interleaver, 0))
          self.connect (tail[1], (interleaver, 1))
          self.connect (interleaver, scale)
          self.connect (scale, f2s)
          self.connect (f2s, file_sink)

No external C code required.  You end up with a file of shorts with
interleaved left and right samples.

gr.interleave will interleave any number of input streams.  You
specify the size of the item in the constructor.  It also has a
brother called gr.deinterleave that's the inverse.


reply via email to

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