Page 1 of 1

Oversample your Oscillators with R_OpenLib

Posted: Thu Jan 12, 2023 11:05 pm
by ChR_is
I updated R_OpenLib today with separate Upsampling and Downsamping classes that you can use, for instance, to oversample your own oscillator implementations.

Here's a tutorial on how to create an oversampled oscillator:
https://youtu.be/Lm0zI0a2Qus

Get R_OpenLib here:
https://github.com/NeverKnewTheName/R_OpenLib

Re: Oversample your Oscillators with R_OpenLib

Posted: Fri Jan 20, 2023 11:39 am
by poetix
If I'm not mistaken, this:

Code: Select all

    public double process( double value, R_IOversampledProcessor processor )
    {
        double[] os = new double[m_osFactor];
        os[0] = value; // first value is valid, others are zero-stuffed

        //////// OVERSAMPLING
        for( int i = 0; i < m_osFactor; ++i )
        {
            os[i] = m_upSampler.process( os[i] );
            os[i] = processor.process( m_osFactor * os[i] );
            os[i] = m_downSampler.process( os[i] );
        }
        //////// OVERSAMPLING

        return os[0];
    }


could be rewritten as this:

Code: Select all

    public double process(double value, R_IOversampledProcessor processor) {
    	// Upsample, process and downsample the value itself, getting the result
        double result = m_downSampler.process(
                processor.process(factor * m_upSampler.process(value)));

	// Feed processed zeroes into the up/down filters so everything is in the right state for the next impulse
        for (int i = 1; i < factor; i++) {
            m_downSampler.process(
                    processor.apply(factor * m_upSampler.process(0)));
        }
        
        return result;
    }
I think there's no need to allocate an empty array and write values into it that you're just going to throw away anyway?

Re: Oversample your Oscillators with R_OpenLib

Posted: Fri Jan 20, 2023 4:19 pm
by poetix
(It works great, by the way - using it on a waveshaper and it appreciably cleans up some of the high-frequency fuzz and whizz)

Re: Oversample your Oscillators with R_OpenLib

Posted: Mon Jan 23, 2023 6:48 pm
by ChR_is
You are correct. in fact i did that optimization already, but haven't pushed the update yet.
the allocation is unnecessary and can be optimized exactly the way you have pointed out. thanks!

update is now live in R_OpenLib. i also added a utility class with some helpful, optimized functions i tend to use often.