GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
wavfile_sink.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2008,2009,2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_GR_WAVFILE_SINK_H
12#define INCLUDED_GR_WAVFILE_SINK_H
13
14#include <gnuradio/blocks/api.h>
16#include <gnuradio/sync_block.h>
17
18namespace gr {
19namespace blocks {
20
21/*!
22 * \brief Write stream to a Microsoft PCM (.wav) file.
23 * \ingroup audio_blk
24 *
25 * \details
26 * Values must be floats within [-1;1].
27 * Check gr_make_wavfile_sink() for extra info.
28 */
29class BLOCKS_API wavfile_sink : virtual public sync_block
30{
31public:
32 // gr::blocks::wavfile_sink::sptr
33 typedef std::shared_ptr<wavfile_sink> sptr;
34
35 /*
36 * \param filename The .wav file to be opened
37 * \param n_channels Number of channels (2 = stereo or I/Q output)
38 * \param sample_rate Sample rate [S/s]
39 * \param format Output format (WAV, FLAC, Ogg, RF64)
40 * \param subformat Bits per sample
41 * \param append Append to existing file
42 */
43 static sptr make(const char* filename,
44 int n_channels,
45 unsigned int sample_rate,
46 wavfile_format_t format,
47 wavfile_subformat_t subformat,
48 bool append = false);
49
50 /*!
51 * \brief Opens a new file and writes a WAV header. Thread-safe.
52 */
53 virtual bool open(const char* filename) = 0;
54
55 /*!
56 * \brief Closes the currently active file and completes the WAV
57 * header. Thread-safe.
58 */
59 virtual void close() = 0;
60
61 /*!
62 * \brief Set the sample rate. This will not affect the WAV file
63 * currently opened. Any following open() calls will use this new
64 * sample rate.
65 */
66 virtual void set_sample_rate(unsigned int sample_rate) = 0;
67
68 /*!
69 * \brief Set bits per sample. This will not affect the WAV file
70 * currently opened (see set_sample_rate()). If the value is
71 * neither 8 nor 16, the call is ignored and the current value
72 * is kept.
73 */
74 virtual void set_bits_per_sample(int bits_per_sample) = 0;
75
76 /*!
77 * \brief Enable appending to an existing file instead of
78 * creating it. This will not affect the WAV file currently
79 * opened (see set_sample_rate()).
80 */
81 virtual void set_append(bool append) = 0;
82};
83
84} /* namespace blocks */
85} /* namespace gr */
86
87#endif /* INCLUDED_GR_WAVFILE_SINK_H */
Write stream to a Microsoft PCM (.wav) file.
Definition: wavfile_sink.h:30
virtual bool open(const char *filename)=0
Opens a new file and writes a WAV header. Thread-safe.
virtual void close()=0
Closes the currently active file and completes the WAV header. Thread-safe.
virtual void set_bits_per_sample(int bits_per_sample)=0
Set bits per sample. This will not affect the WAV file currently opened (see set_sample_rate())....
virtual void set_sample_rate(unsigned int sample_rate)=0
Set the sample rate. This will not affect the WAV file currently opened. Any following open() calls w...
std::shared_ptr< wavfile_sink > sptr
Definition: wavfile_sink.h:33
virtual void set_append(bool append)=0
Enable appending to an existing file instead of creating it. This will not affect the WAV file curren...
static sptr make(const char *filename, int n_channels, unsigned int sample_rate, wavfile_format_t format, wavfile_subformat_t subformat, bool append=false)
synchronous 1:1 input to output with history
Definition: sync_block.h:26
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
wavfile_subformat_t
Definition: wavfile.h:51
wavfile_format_t
Definition: wavfile.h:44
GR_RUNTIME_API const pmt::pmt_t sample_rate()
GNU Radio logging wrapper.
Definition: basic_block.h:29