id: pfb_arb_resampler_xxx
label: Polyphase Arbitrary Resampler
flags: [ python, cpp ]

parameters:
-   id: type
    label: Type
    dtype: enum
    options: [ccf, fff, ccc]
    option_labels: [Complex->Complex (Real Taps), Float->Float (Real Taps), Complex->Complex
            (Complex Taps)]
    option_attributes:
        input: [complex, float, complex]
        output: [complex, float, complex]
        taps: [real_vector, real_vector, complex_vector]
    hide: part
-   id: rrate
    label: Resampling Rate
    dtype: real
-   id: taps
    label: Taps
    dtype: ${ type.taps }
-   id: nfilts
    label: Number of Filters
    dtype: int
    default: '32'
-   id: atten
    label: Stop-band Attenuation
    dtype: real
    default: '100'
-   id: samp_delay
    label: Sample Delay
    dtype: int
    default: '0'
    hide: part

asserts:
-   ${ rrate > 0 }

inputs:
-   domain: stream
    dtype: ${ type.input }

outputs:
-   domain: stream
    dtype: ${ type.output }

templates:
    imports: |-
        from gnuradio.filter import pfb
        from gnuradio.filter import firdes
    make: |-
        pfb.arb_resampler_${type}(
            ${rrate},
            taps=${ taps if taps else 'None' },
            flt_size=${nfilts},
            atten=${atten})
        self.${id}.declare_sample_delay(${samp_delay})
    callbacks:
    - set_taps(${taps})
    - set_rate(${rrate})

cpp_templates:
    includes: ['#include <gnuradio/filter/pfb_arb_resampler_${type}.h>']
    declarations: 'gr::filter::pfb_arb_resampler_${type}::sptr ${id};'
    make: |-
        <% 
            taps = self.context.get('taps')
            try: taps
            except NameError: taps = None 
            taps = None if (len(taps) == 0) else taps
        %>
        % if taps == None or len(taps) == 0:
            <%
            # Leverage python module to generate values for taps
            from gnuradio import filter 
            %>
            % if type == 'fff':
              <% taps = filter.pfb.arb_resampler_fff.create_taps(float(self.context.get('rrate')), int(self.context.get('nfilts')), float(self.context.get('atten'))) %>
            % elif type == 'ccf':
              <% taps = filter.pfb.arb_resampler_ccf.create_taps(float(self.context.get('rrate')), int(self.context.get('nfilts')), float(self.context.get('atten'))) %>
            % elif type == 'ccc':
              <% taps = filter.pfb.arb_resampler_ccc.create_taps(float(self.context.get('rrate')), int(self.context.get('nfilts')), float(self.context.get('atten'))) %>
            % endif
        % endif

        % if str(type.taps) == "complex_vector":
        std::vector<gr_complex> taps = {${str(taps)[1:-1]}};
        % else:
        std::vector<float> taps = {${str(taps)[1:-1]}};
        % endif
        this->${id} = gr::filter::pfb_arb_resampler_${type}::make(
            ${rrate},
            taps,
            ${nfilts});
        this->${id}->declare_sample_delay(${samp_delay});
    link: ['gnuradio::gnuradio-filter']
    callbacks:
    - set_taps(taps)
    - set_rate(${rrate})

file_format: 1
