summaryrefslogtreecommitdiff
path: root/gr-blocks/lib/wavfile_sink_impl.cc
diff options
context:
space:
mode:
authorRon Economos <w6rz@comcast.net>2020-09-23 21:13:12 -0700
committermormj <34754695+mormj@users.noreply.github.com>2020-09-25 06:19:11 -0400
commit8f3d61984ecd9ecc97789a174a54c7f0505bddb4 (patch)
tree994b9372e582a1f8f7e7ef91ccab524e3e0672b5 /gr-blocks/lib/wavfile_sink_impl.cc
parent1247d48d5416e0f62147f26907bd6c6f76fc2a31 (diff)
gr-blocks: Fix wavfile sink and source block performance issues.
Calling libsndfile sf_read/write_float() for every sample created too much overhead. sf_read/write_float() is now called every 1024 samples for the wavfile source block and every 8192 samples for the wavfile sink block.
Diffstat (limited to 'gr-blocks/lib/wavfile_sink_impl.cc')
-rw-r--r--gr-blocks/lib/wavfile_sink_impl.cc28
1 files changed, 15 insertions, 13 deletions
diff --git a/gr-blocks/lib/wavfile_sink_impl.cc b/gr-blocks/lib/wavfile_sink_impl.cc
index 38325856bb..5e3362d92d 100644
--- a/gr-blocks/lib/wavfile_sink_impl.cc
+++ b/gr-blocks/lib/wavfile_sink_impl.cc
@@ -49,8 +49,9 @@ wavfile_sink_impl::wavfile_sink_impl(const char* filename,
{
int bits_per_sample;
- if (n_channels > 24) {
- throw std::runtime_error("Number of channels greater than 24 not supported.");
+ if (n_channels > s_max_channels) {
+ throw std::runtime_error("Number of channels greater than " +
+ std::to_string(s_max_channels) + " not supported.");
}
d_h.sample_rate = sample_rate;
@@ -86,6 +87,9 @@ wavfile_sink_impl::wavfile_sink_impl(const char* filename,
set_bits_per_sample_unlocked(bits_per_sample);
d_h.bytes_per_sample = d_bytes_per_sample_new;
+ set_max_noutput_items(s_items_size);
+ d_buffer.resize(s_items_size * d_h.nchans);
+
if (!open(filename)) {
throw std::runtime_error("Can't open WAV file.");
}
@@ -243,7 +247,6 @@ int wavfile_sink_impl::work(int noutput_items,
int n_in_chans = input_items.size();
int nwritten;
int errnum;
- float sample[24];
gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this block
do_update(); // update: d_fp is read
@@ -257,21 +260,20 @@ int wavfile_sink_impl::work(int noutput_items,
// Write zeros to channels which are in the WAV file
// but don't have any inputs here
if (chan < n_in_chans) {
- sample[chan] = in[chan][nwritten];
+ d_buffer[chan + (nwritten * nchans)] = in[chan][nwritten];
} else {
- sample[chan] = 0;
+ d_buffer[chan + (nwritten * nchans)] = 0;
}
}
+ }
- sf_write_float(d_fp, &sample[0], nchans);
+ sf_write_float(d_fp, &d_buffer[0], nchans * nwritten);
- errnum = sf_error(d_fp);
- if (errnum) {
- GR_LOG_ERROR(d_logger,
- boost::format("sf_error: %s") % sf_error_number(errnum));
- close();
- throw std::runtime_error("File I/O error.");
- }
+ errnum = sf_error(d_fp);
+ if (errnum) {
+ GR_LOG_ERROR(d_logger, boost::format("sf_error: %s") % sf_error_number(errnum));
+ close();
+ throw std::runtime_error("File I/O error.");
}
return nwritten;