I wrote a neat little MATLAB-script, which does the following:
- you give it an explicit function you want to use as an wavetable-osc (or rather a cycle of it.)
- MATLAB does fourrier-analysis of said function and finds the coefficients for the sums of sin and cos functions in 'createWavetables()' (synthbook)
- it then outputs these coefficients in a .txt file in an array in C++ syntax.
All you have to do then is to copy said array to your C++ code and modify the createWavetables() function so it uses these coefficients.
In its original version it looks something like this:
for(int i = 0; i < WT_LENGTH; i++) // LOOP THROUGH THE TABLE
for(int g = 1; g<=nHarms; g++) // LOOP THOUGH OVERTONES
pSawTable[i] += pow((float)-1,(float)(g+1))*(1/n*sigma*sin(2*pi*i*n/WT_LENGTH));
Where you have to change the accumulation for this:
pCustomTable[i] += customTableOdd[g]*sin(2*pi*double(i)*double(g)/WT_LENGTH) + customTableEven[g]*cos(2*pi*double(i)*double(g)/WT_LENGTH);
where customTableOdd and customTableEven are the coefficient arrays for the sine and cosine functions.
Note that you need sine as well as cosine functions to recreate waveforms which are neither centrosymmetrically nor axissymmetrically.
And there you have it: An oscillator wich gives you the best approximation of your waveform without any aliasing!
You need MATLAB however. (I don't know whether or not this is used by the community!?)
edit: here's the .m file:
is there any way to attach files in the forum?
Cool, thanks for letting us know about your MATLAB tool! And, yes all of my students are MATLAB-competent so maybe I can get some of them to use this for a project this semester.
Could you give an example of the tool being used?
All the best,
PS: no, can't attach files right now; we did have a SimplePress plugin for a better text editor, but it had too many problems with not letting people reply, so I removed it -- might go back and reinvestigate this now.
here's a simple mono oscillator plugin with four waveforms, featuring:
- a composition of 3 parabolas
- sectionwise Noise/Saw
- 16 stages of Sample&Hold
I wonder why it tourned out so big (15Mb)?
Thanks for the sample DLL, Frodson.
The reason the file is 15MB is because it is linked to a library (.lib) file that allows the DLL to run as RAFX and VST2 and VST3 plugins at the same time. Without that library, the plugin would be very small (a few KB). The name of the lib is Sock2VST3 and you can find a bunch of different versions of it in your project folder.
Most Users Ever Online: 152
Currently Browsing this Page:
Guest Posters: 1
Newest Members:TheJonDoe, DoubleLiines.com, jmf11, dan, Luke Bilodeau, Carlos_1, ant, marclingk, TheCammen, Hubbert
Moderators: W Pirkle: 444
Administrators: Tom: 74, JD Young: 80, Will Pirkle: 0, W Pirkle: 444