summaryrefslogtreecommitdiff
path: root/src/lib/resampler.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-11 12:57:53 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-11 12:57:53 +0100
commit49deab5be257f3a11f5b053224f4a3218fad8da3 (patch)
treeedb4593b33d2a062614cdfaba9cc96d4aab8c1ed /src/lib/resampler.cc
parentcb2d996875db099ce456c18e9751f5dfe3d9056d (diff)
Untested flushing of resamplers.
Diffstat (limited to 'src/lib/resampler.cc')
-rw-r--r--src/lib/resampler.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc
index 1235b9038..ebb507cb1 100644
--- a/src/lib/resampler.cc
+++ b/src/lib/resampler.cc
@@ -59,3 +59,31 @@ Resampler::run (shared_ptr<const AudioBuffers> in)
resampled->set_frames (resampled_frames);
return resampled;
}
+
+shared_ptr<const AudioBuffers>
+Resampler::flush ()
+{
+ shared_ptr<AudioBuffers> out (new AudioBuffers (_channels, 0));
+ int out_offset = 0;
+ int64_t const pass_size = 256;
+ shared_ptr<AudioBuffers> pass (new AudioBuffers (_channels, 256));
+
+ while (1) {
+ int const frames = swr_convert (_swr_context, (uint8_t **) pass->data(), pass_size, 0, 0);
+
+ if (frames < 0) {
+ throw EncodeError (_("could not run sample-rate converter"));
+ }
+
+ if (frames == 0) {
+ break;
+ }
+
+ out->ensure_size (out_offset + frames);
+ out->copy_from (pass.get(), frames, 0, out_offset);
+ out_offset += frames;
+ out->set_frames (out_offset);
+ }
+
+ return out;
+}