blob: 2d1a76845ab219bdf4ceda77a6b7fcb18f638318 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/* -*- c++ -*- */
/*
* Copyright 2008,2009,2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#ifndef INCLUDED_GR_WAVFILE_SINK_IMPL_H
#define INCLUDED_GR_WAVFILE_SINK_IMPL_H
#include <gnuradio/blocks/wavfile_sink.h>
namespace gr {
namespace blocks {
class wavfile_sink_impl : public wavfile_sink
{
private:
unsigned d_sample_rate;
const int d_nchans;
unsigned d_sample_count;
int d_bytes_per_sample;
int d_bytes_per_sample_new;
int d_max_sample_val;
int d_min_sample_val;
int d_normalize_shift;
int d_normalize_fac;
FILE* d_fp;
FILE* d_new_fp;
bool d_updated;
boost::mutex d_mutex;
/*!
* \brief Convert a sample value within [-1;+1] to a corresponding
* short integer value
*/
short convert_to_short(float sample);
/*!
* \brief If any file changes have occurred, update now. This is called
* internally by work() and thus doesn't usually need to be called by
* hand.
*/
void do_update();
/*!
* \brief Writes information to the WAV header which is not available
* a-priori (chunk size etc.) and closes the file. Not thread-safe and
* assumes d_fp is a valid file pointer, should thus only be called by
* other methods.
*/
void close_wav();
protected:
bool stop();
public:
wavfile_sink_impl(const char* filename,
int n_channels,
unsigned int sample_rate,
int bits_per_sample);
~wavfile_sink_impl();
bool open(const char* filename);
void close();
void set_sample_rate(unsigned int sample_rate);
void set_bits_per_sample(int bits_per_sample);
int bits_per_sample();
unsigned int sample_rate();
int work(int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items);
};
} /* namespace blocks */
} /* namespace gr */
#endif /* INCLUDED_GR_WAVFILE_SINK_IMPL_H */
|