#!/bin/env /usr/bin/python
#
# Copyright 2004 Free Software Foundation, Inc.
# 
# This file is part of GNU Radio
# 
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# 

from gnuradio import gr

def graph ():
    sampling_freq = 8000000
    ampl = 1.

    fg = gr.flow_graph ()

    src0 = gr.file_source (gr.sizeof_gr_complex,"/mnt/linux4/atsc_data_8m_complex")
    src1 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0)
    src2 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0)
    src3 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0)
    src4 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0)

    interlv = gr.interleave(gr.sizeof_gr_complex)

    lp_coeffs = gr.firdes.low_pass ( 5, 40e6, 4e6, .5e6, gr.firdes.WIN_HAMMING )
    lp = gr.fir_filter_ccf ( 1, lp_coeffs )

    duc_coeffs = gr.firdes.low_pass ( 1, 40e6, 9e6, 1e6, gr.firdes.WIN_HAMMING )
    duc = gr.freq_xlating_fir_filter_ccf ( 2, duc_coeffs, 5.75e6, 40e6 )

    c2f = gr.complex_to_float()
    f2s = gr.float_to_short()
    file = gr.file_sink(gr.sizeof_short,"/tmp/atsc_pipe")

    fg.connect( src0, (interlv, 0) )
    fg.connect( src1, (interlv, 1) )
    fg.connect( src2, (interlv, 2) )
    fg.connect( src3, (interlv, 3) )
    fg.connect( src4, (interlv, 4) )
    fg.connect( interlv, lp, duc, c2f, f2s, file )

    fg.start()
    raw_input('Press Enter to quit: ')
    fg.stop ()

if __name__ == '__main__':
    graph ()
