Cameron1470 / audio-programming-project

First shot at getting wavetable synthesis from a file working
0 stars 0 forks source link

Lagrange Lookup Table #7

Open mhamilt opened 3 years ago

mhamilt commented 3 years ago

If you are making your own class for a lagrange lookup table,

https://github.com/Cameron1470/audio-programming-project/blob/master/Source/LagrangeTable.h

definitely split this up.

First step is to figure out what it can do

.h

class LagrangeTable
{
public:
    LagrangeTable(int _lagrangeOrder, int _numberOfInterpolationPoints);

    /// function for setting up lagrange table using the private variables Q and lagrangeOrder
    void setLagrangeTable();

    /// function for getting values from the lagrange table matrix
    float getTableValue();

private:

    /// order of Lagrange interpolation
    int lagrangeOrder;

    /// number of values between alpha = -1/2 and 1/2
    int Q;

    /// Matrix for storing Lagrange table
    //juce::dsp::Matrix<float> lagrangeTableMatrix{ size_t(Q), size_t(lagrangeOrder) };
};

We know for setting the table it will have to involve something like

for (int q = 0; q < resolution; ++q) // loop for every value of alpha
{
    for (int j = 0; j < order; ++j) // loop for sub polynomial
    {
        for (int m = 0; m < order; ++m) //loop for each point in subpoly
        {
            if (m != j)
            {
                if (q == 0)
                {

                }

            }
        }
    }
}

Sure you can probably make this nicer, but start of verbose and chip it down

mhamilt commented 3 years ago

I would also start with a double float pointer, that way you can essentially access an array like a matrix

float** lookup;

lookup = new float*[order]; // create an array of float pointers

for (int i = 0; i < order; ++i)
{
    lookup[i] = new float[resolution]; // for each pointer create a float array
}

you can now store data in lookup with the syntax lookup[x][y]

Cameron1470 commented 3 years ago

I would also start with a double float pointer, that way you can essentially access an array like a matrix

float** lookup;

interpLookTable = new float*[order]; // create an array of float pointers

for (int i = 0; i < order; ++i)
{
    interpLookTable[i] = new float[resolution]; // for each pointer create a float array
}

you can now store data in lookup with the syntax lookup[x][y]

Hi Matthew, I'm having another shot at this but could you clarify something for me. In the example you've written is lookup == interpLookTable (ie. just a typo)? also in the suggested syntax would x = order and y = resolution or the other way around?

mhamilt commented 3 years ago

Yes, lookup == interpLookTable and x and y are essentially interchangeable, but x == order and y == resolution would be a sensible approach. Naming convention is your call. I originally tackled lagrange in c, so wrapping in a class wasn't an option. If you wrap everything in a class you can avoid being tautological and give your variables some more sensible names. interpLookTable is pretty ugly all things considered.

mhamilt commented 3 years ago

Edited the original snippet to actually be consistent.

Cameron1470 commented 3 years ago

okay, I think I understand what's going on. Thanks for clarifying! I was still having some real trouble with this Lagrange interpolation today, however I did just try the cubic spline method from the delay class you pointed out a while back and it was infinitely easier to implement so I think I'll just stick with that! This will probably still come in handy later on though

mhamilt commented 3 years ago

I think Cubic Spline is the way to go. Lagrange is only really helpful when missing massive chunks of data e.g.

Lagrange Example use case

still wouldn't hurt to give it a go, I'm sure you could program a nice way to switch between the two so you can easily A / B against a spectrogram.