1 #ifndef __SDR_WAVFILE_HH__
2 #define __SDR_WAVFILE_HH__
11 template <
class Scalar>
18 :
Sink<Scalar>(),
_file(filename.c_str(),
std::ios_base::out|
std::ios_base::binary),
21 if (!
_file.is_open()) {
23 err <<
"Can not open wav file for output: " << filename;
27 for (
size_t i=0; i<44; i++) {
_file.write(
"\x00", 1); }
30 switch (Config::typeId<Scalar>()) {
53 err <<
"WAV format only allows (real) integer typed data.";
60 if (
_file.is_open()) {
70 if (Config::typeId<Scalar>() != src_cfg.
type()) {
72 err <<
"Can not configure WavSink: Invalid buffer type " << src_cfg.
type()
73 <<
", expected " << Config::typeId<Scalar>();
82 if (!
_file.is_open()) {
return; }
87 _file.write(
"RIFF", 4);
89 _file.write(
"WAVE", 4);
91 _file.write(
"fmt ", 4);
92 val4 = 16;
_file.write((
char *)&val4, 4);
93 val2 = 1;
_file.write((
char *)&val2, 2);
97 _file.write((
char *)&val4, 4);
99 _file.write((
char *)&val2, 2);
102 _file.write(
"data", 4);
109 if (!
_file.is_open()) {
return; }
139 WavSource(
const std::string &filename,
size_t buffer_size=1024);
146 void open(
const std::string &filename);
176 #endif // __SDR_WAVFILE_HH__
double _sample_rate
The sample rate.
Definition: wavfile.hh:169
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
Base class of all buffers, represents an untyped array of bytes.
Definition: buffer.hh:32
WavSource(size_t buffer_size=1024)
Constructor, buffer_size specified the output buffer size.
Definition: wavfile.cc:9
Stores the received buffers into a WAV file.
Definition: wavfile.hh:12
Real signed 16b ints.
Definition: node.hh:44
Typed sink.
Definition: node.hh:192
Complex (aka I/Q) type of unsigned 16b ints.
Definition: node.hh:49
Definition: autocast.hh:8
size_t _frames_left
The number of frames left to be read.
Definition: wavfile.hh:171
WavSink(const std::string &filename)
Constructor, filename specifies the file name, the WAV data is stored into.
Definition: wavfile.hh:17
Real signed 8b ints.
Definition: node.hh:42
Definition: operators.hh:9
A simple imput source that reads from a wav file.
Definition: wavfile.hh:133
uint16_t _bitsPerSample
The number of bits per sample (depends on the template type).
Definition: wavfile.hh:119
bool hasSampleRate() const
If true, the configuration has a sample rate.
Definition: node.hh:75
Generic source class.
Definition: node.hh:213
Real unsigned 8b ints.
Definition: node.hh:41
std::fstream _file
The file output stream.
Definition: wavfile.hh:117
void close()
Completes the WAV header and closes the file.
Definition: wavfile.hh:81
size_t size() const
Returns the number of elements of type T in this buffer.
Definition: buffer.hh:166
bool hasType() const
If true, the configuration has a type.
Definition: node.hh:69
Config::Type _type
The type of the data in the WAV file.
Definition: wavfile.hh:167
char * data() const
Returns the pointer to the data of the buffer view.
Definition: buffer.hh:69
Real unsigned 16b ints.
Definition: node.hh:43
size_t _buffer_size
The current buffer size.
Definition: wavfile.hh:162
uint32_t _sampleRate
The sample rate.
Definition: wavfile.hh:123
void open(const std::string &filename)
Open a new file.
Definition: wavfile.cc:33
virtual void process(const Buffer< Scalar > &buffer, bool allow_overwrite)
Writes some data into the WAV file.
Definition: wavfile.hh:108
Type type() const
Returns the type.
Definition: node.hh:71
uint32_t _frameCount
The total number of frame counts.
Definition: wavfile.hh:121
virtual void config(const Config &src_cfg)
Configures the sink.
Definition: wavfile.hh:66
void close()
Close the current file.
Definition: wavfile.cc:188
void next()
Read the next data.
Definition: wavfile.cc:199
The configuration error class.
Definition: exception.hh:24
virtual ~WavSink()
Destructor, closes the file if not done yet.
Definition: wavfile.hh:59
Type
The type IDs.
Definition: node.hh:39
RawBuffer _buffer
The output buffer.
Definition: wavfile.hh:160
uint16_t _numChanels
The number of chanels.
Definition: wavfile.hh:125
bool isOpen() const
Returns true if the file is open.
Definition: wavfile.cc:28
Complex (aka I/Q) type of signed 8b ints.
Definition: node.hh:48
Complex (aka I/Q) type of signed 16b ints.
Definition: node.hh:50
Complex (aka I/Q) type of unsigned 8b ints.
Definition: node.hh:47
std::fstream _file
The input file stream.
Definition: wavfile.hh:158
bool isReal() const
Returns true, if the input is real (stereo files are handled as I/Q signals).
Definition: wavfile.cc:194
size_t _frame_count
The number of available frames.
Definition: wavfile.hh:165
double sampleRate() const
Returns the sample rate.
Definition: node.hh:77
virtual ~WavSource()
Destructor.
Definition: wavfile.cc:23