How do I write my own linear interpolation function for removing frequency and volume slider artifacts?

Hey everyone! I’m currently studying computer science and I’m enrolled in a numeric analysis class, and my peers and I got plenty of freedom to do a final assignment involving one of the numeric methods taught in the lectures.

I started studying JUCE’s tutorials and figuring out the basics of DSP, and I eventually found out that interpolation is used in removing the artifacting that you get when move sliders over non-continuous intervals to alter parameters, so I thought I could use it in my project. As it stands, I spent the better part of this month desperately attempting to code my own interpolation function for a simple sine generator - and failed miserably. The results are always something in the lines of incredibly garbled audio, infinitely growing frequency values and whatnot.

I have a sine wave generator, where the user controls the frequency of each wave and the volume in db, cobbled together from a tutorial that didn’t illustrate how to smoothly interpolate values between slider changes. I added an interpolate button that toggles my attempts at smoothing out the value transitions.

It’s from the basic Audio Application template, standard MainComponent.cpp and MainComponent.cpp files.

I have four possible options here:
(1) Fix my crappy interpolation attempt - I can’t for the life of me figure out what exactly to use as input for the function.
(2) Understand the SmoothedValue or the LinearSmoothedValue JUCE class - I lifted the former from the kvraudio forums ( in hopes of finding something that worked so that I could create my own solution based on it, but I couldn’t find out how to get it to work. Same goes for the LinearSmoothedValue. Couldn’t get it to work.
(3) Attempt spline interpolating, but I’m really more clueless about that than I already am with simple interpolation.
(4) Give up and cry really hard in a corner somewhere.

I added plenty of commentary in my code to possibly guide to the root of my problems. Right now I am currently very desperate and I have pretty much given up hope of ever removing the artifacting, and I would greatly appreciate any help given. (the main issues are around line 156.)
Codeshare for non-download option:
MainComponent.cpp (12.1 KB)
Main.cpp (3.9 KB)

start here for learning how to use LinearSmoothedValue:

…and you can also use a low pass filter to smooth parameter changes , here’s the class I use, interchangeable with LinearSmoothedValue

I’ve looked over those files extensively, and unfortunately, I couldn’t think of a way to use them in my code. I would like not to rewrite everything from the ground up. Do I call LinearSmoothedValue for every sample I get? How exactly do I instantiate it in the getNextAudioBlock() function and compute the actual smoothed values?

I appreciate the swift answers, but I’m limited to linear/spline interpolation as the project is intended as an experiment to showcase numeric method applications :frowning:

what is a inputVolume?

what is a dsp::Gain ?

and what is dsp::Gain::process()?

where is the LinearSmoothedValue?

How is that LinearSmoothedValue used so linear interpolation is applied to a sample buffer?
First the ramp duration property is set for the LSV:

then the samples are processed:

specifically, here, for mono audio channels:


Hey, thanks again for taking the time to help. I just had another look at those and tried my hand at it again - there is one parameter that I still didn’t figure out.

I implemented it this way:

  1. A LinearSmoothedValue freqSmooth object as a member variable
  2. In the prepareToPlay() function, I call its setValue() method and set it to frequency (the current frequency, that is) and call reset(sampleRate).
  3. In the slider, I call setValue(targetFrequency) whenever it is dragged to a value targetFrequency.
  4. In the getNextAudioBlock(), for the monoBuffer, each new frequency value for the current sample is updated with frequency = freqSmooth.getNextValue()

But what is that rampDurationInSeconds? I tried setting my time variable as it, but I’m still getting the exact same artifacting - even though I am getting the values from the LinearSmoothedValue. The frequency changes appear smooth when printed in the terminal but the output is still garbled.

Updated codeshare link: