From d9f20223b582e010b262b9f8aa68087f5f6feec2 Mon Sep 17 00:00:00 2001 From: nwolek Date: Sat, 2 Jan 2016 15:13:37 -0500 Subject: [PATCH] first draft of the SampleBundle.at() function. issue #70 --- include/core/JamomaSample.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/core/JamomaSample.h b/include/core/JamomaSample.h index 483f4aa..f01f36a 100644 --- a/include/core/JamomaSample.h +++ b/include/core/JamomaSample.h @@ -111,6 +111,25 @@ namespace Jamoma { { return const_cast(this)->mChannels[index]; } + + + /** Interpolate a value between known Samples. + */ + Sample at(size_t channel, double interpolatedFrameIndex) { + Sample output = 0.0; + Jamoma::Interpolator::Linear my_interp; + + int frameIndexBefore = (int)interpolatedFrameIndex; + double delta = interpolatedFrameIndex - frameIndexBefore; + int frameIndexAfter = frameIndexBefore + 1; + + Sample sampleAtIndexBefore = mChannels[channel][frameIndexBefore]; + Sample sampleAtIndexAfter = mChannels[channel][frameIndexAfter]; + + output = my_interp(sampleAtIndexBefore,sampleAtIndexAfter,delta); + + return output; + } /** Change the channel count of the bundle.