Need some example code


#1

I’ve written a table based oscillator class. Yay me!
Right now it can do a saw and a sin using simple algos, but I would like to use a more versatile approach.

So, I am thinking of using the binary builder to source-ify single cycle wav files, and have the class load one of them into the table at creation. Brilliant, if I may say so. I suspect its simple.

'Cept I don’t know how exactly.

So, given this set up (roughly):

        int TableSize = 512;
        float * table  =   (float*)malloc(TableSize * sizeof(float));

        for(int i = 0; i < TableSize; i++){ 
            table[i] = [nab float from BB file here];
        }

How should I proceed?


#2

This is tougher than I thought. The wav reading thingummy does not have a method equivalent to what the image thingummy has.

Maybe the easiest way would be to save the wave cycle files as ‘raw’ 16/44100 with zero header and tail, and try and piece the floats together from that…

So, as an alternate question to the original one:

How does one make a float from two chars?

(Answer: You put one in the backseat and one in the fridge.) :smiley:


#3

And once again, a mere three hours after finding myself without a clue, I have worked my way to a solution!

float * raw = (float*)osc_tables::saw1_raw;

        for(int i = 0; i < 1024; i++){
            table[i] = raw[i];
        }

I didn’t realize I could save raw files with 32bit floats. No tricky casting required.


#4

Take a look at the MemoryInputStream class :wink:


#5

Oh oh oh!

Is there even a reason to copy the tables? What if I just copy the pointer. The binary builder data is already on the heap, right?


#6

Yes!

Check out This bad boy!


#7

Just out of interest… why not just generate the data dynamically when the plugin is initialised?

Not criticising… just wondering.


#8

[quote=“Pukeweed”]Oh oh oh!

Is there even a reason to copy the tables? What if I just copy the pointer. The binary builder data is already on the heap, right?[/quote]

probably no need - MemoryInputStream has an option to refer to static data.


#9

I want waveforms that do not lend themselves to algorithmical generation, and I want a lot of them.
The synth I posted above reads the table directly from the static array that binary builder files create, and you can swap them on the fly easily enough.
The 6 waveforms added roughly 12 Kb to the exe so there is really no need to save space.

Also, I just like the workflow of making waveforms in a sample editor, and the compile them into a synth, and then see the same waveform come out the other end. Its like the circle of life or something.


#10