id: blocks_wavfile_sink
label: Wav File Sink
flags: [ python, cpp ]

parameters:
-   id: file
    label: File
    dtype: file_save
-   id: nchan
    label: N Channels
    dtype: int
    default: '1'
    hide: part
-   id: samp_rate
    label: Sample Rate
    dtype: int
    default: samp_rate
-   id: format
    label: Output Format
    dtype: enum
    options: [FORMAT_WAV, FORMAT_FLAC, FORMAT_OGG, FORMAT_RF64]
    option_labels: [WAV, FLAC, Ogg, 64-bit WAV]
    default: FORMAT_WAV
    option_attributes:
        hide_wav: [none, all, all, all]
        hide_flac: [all, none, all, all]
        hide_ogg: [all, all, none, all]
        hide_rf64: [all, all, all, none]
        hide_append: [none, all, all, none]
        val: [blocks.FORMAT_WAV, blocks.FORMAT_FLAC, blocks.FORMAT_OGG, blocks.FORMAT_RF64]
-   id: bits_per_sample1
    label: Bits per Sample
    dtype: enum
    options: [FORMAT_PCM_16, FORMAT_PCM_24, FORMAT_PCM_32, FORMAT_PCM_U8, FORMAT_FLOAT, FORMAT_DOUBLE]
    option_labels: [16-bit, 24-bit, 32-bit, unsigned 8-bit, float, double]
    default: FORMAT_PCM_16
    option_attributes:
        val: [blocks.FORMAT_PCM_16, blocks.FORMAT_PCM_24, blocks.FORMAT_PCM_32, blocks.FORMAT_PCM_U8, blocks.FORMAT_FLOAT, blocks.FORMAT_DOUBLE]
    hide: ${ format.hide_wav }
-   id: bits_per_sample2
    label: Bits per Sample
    dtype: enum
    options: [FORMAT_PCM_S8, FORMAT_PCM_16, FORMAT_PCM_24]
    option_labels: [signed 8-bit, 16-bit, 24-bit]
    default: FORMAT_PCM_16
    option_attributes:
        val: [blocks.FORMAT_PCM_S8, blocks.FORMAT_PCM_16, blocks.FORMAT_PCM_24]
    hide: ${ format.hide_flac }
-   id: bits_per_sample3
    label: Codec
    dtype: enum
    options: [FORMAT_VORBIS, FORMAT_OPUS]
    option_labels: [Vorbis, Opus]
    default: FORMAT_VORBIS
    option_attributes:
        val: [blocks.FORMAT_VORBIS, blocks.FORMAT_OPUS]
    hide: ${ format.hide_ogg }
-   id: bits_per_sample4
    label: Bits per Sample
    dtype: enum
    options: [FORMAT_PCM_16, FORMAT_PCM_24, FORMAT_PCM_32, FORMAT_PCM_U8, FORMAT_FLOAT, FORMAT_DOUBLE]
    option_labels: [16-bit, 24-bit, 32-bit, unsigned 8-bit, float, double]
    default: FORMAT_PCM_16
    option_attributes:
        val: [blocks.FORMAT_PCM_16, blocks.FORMAT_PCM_24, blocks.FORMAT_PCM_32, blocks.FORMAT_PCM_U8, blocks.FORMAT_FLOAT, blocks.FORMAT_DOUBLE]
    hide: ${ format.hide_rf64 }
-   id: append
    label: Append to existing file
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: ${ format.hide_append }

inputs:
-   domain: stream
    dtype: float
    multiplicity: ${ nchan }

asserts:
- ${ 1 <= nchan }

templates:
    imports: from gnuradio import blocks
    make: |-
        blocks.wavfile_sink(
            ${file},
            ${nchan},
            ${samp_rate},
            ${format.val},
            % if str(format) == 'FORMAT_WAV':
            ${bits_per_sample1.val},
            % elif str(format) == 'FORMAT_FLAC':
            ${bits_per_sample2.val},
            % elif str(format) == 'FORMAT_OGG':
            ${bits_per_sample3.val},
            % elif str(format) == 'FORMAT_RF64':
            ${bits_per_sample4.val},
            % endif
            % if str(format) == 'FORMAT_WAV':
            ${append}
            % elif str(format) == 'FORMAT_FLAC':
            ${False}
            % elif str(format) == 'FORMAT_OGG':
            ${False},
            % elif str(format) == 'FORMAT_RF64':
            ${append}
            % endif
            )

    callbacks:
    - open(${file})

cpp_templates:
    includes: ['#include <gnuradio/blocks/wavfile_sink.h>']
    declarations: 'blocks::wavfile_sink::sptr ${id};'
    make: |-
        this->${id} = blocks::wavfile_sink::make(
            ${file},
            ${nchan},
            ${samp_rate},
            ${format.val},
            % if str(format) == 'FORMAT_WAV':
            ${bits_per_sample1.val},
            % elif str(format) == 'FORMAT_FLAC':
            ${bits_per_sample2.val},
            % elif str(format) == 'FORMAT_OGG':
            ${bits_per_sample3.val},
            % elif str(format) == 'FORMAT_RF64':
            ${bits_per_sample4.val},
            % endif
            % if str(format) == 'FORMAT_WAV':
            ${append}
            % elif str(format) == 'FORMAT_FLAC':
            ${False}
            % elif str(format) == 'FORMAT_OGG':
            ${False},
            % elif str(format) == 'FORMAT_RF64':
            ${append}
            % endif
            );

    callbacks:
    ## TODO Handle std::string type when const char* argument is needed
    - this->${id}->open(${file})

file_format: 1
