summaryrefslogtreecommitdiff
path: root/src/lib/resampler.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-02-21 21:42:44 +0000
committerCarl Hetherington <cth@carlh.net>2017-04-19 23:04:32 +0100
commit89aa9d4ba69e471949f791cdafe4ae20cea554d2 (patch)
treea8260555268d392292775a2851d8780e5612091b /src/lib/resampler.cc
parent7db99ef207c68910ee96a3e806c9832e8f90b219 (diff)
Various fixes to push audio vaguely in the right direction.
Diffstat (limited to 'src/lib/resampler.cc')
-rw-r--r--src/lib/resampler.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc
index 01d71c79b..d08e7bc38 100644
--- a/src/lib/resampler.cc
+++ b/src/lib/resampler.cc
@@ -67,9 +67,19 @@ Resampler::set_fast ()
}
}
-shared_ptr<const AudioBuffers>
-Resampler::run (shared_ptr<const AudioBuffers> in)
+pair<shared_ptr<const AudioBuffers>, Frame>
+Resampler::run (shared_ptr<const AudioBuffers> in, Frame frame)
{
+ if (!_next_in || !_next_out || _next_in.get() != frame) {
+ /* Either there was a discontinuity in the input or this is the first input;
+ reset _next_out.
+ */
+ _next_out = lrintf (frame * _out_rate / _in_rate);
+ }
+
+ /* Expected next input frame */
+ _next_in = frame + in->frames ();
+
int in_frames = in->frames ();
int in_offset = 0;
int out_offset = 0;
@@ -142,7 +152,12 @@ Resampler::run (shared_ptr<const AudioBuffers> in)
delete[] data.data_out;
}
- return resampled;
+ Frame out_frame = _next_out.get ();
+
+ /* Expected next output frame */
+ _next_out = _next_out.get() + resampled->frames();
+
+ return make_pair (resampled, out_frame);
}
shared_ptr<const AudioBuffers>