Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
MATLAB-Tool for Bandlimited Wavetables
September 8, 2015 - 12:14 am
Member Since: September 7, 2015
Forum Posts: 45
sp_UserOfflineSmall Offline

Hey Guys,
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!?)
Cheers Frodson

edit: here's the .m file:
is there any way to attach files in the forum?

W Pirkle
September 8, 2015 - 12:38 am
Member Since: January 29, 2017
Forum Posts: 444
sp_UserOfflineSmall Offline

Hi Frodson

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.

September 16, 2015 - 12:35 am
Member Since: September 7, 2015
Forum Posts: 45
sp_UserOfflineSmall Offline

Hi Will,
here's a simple mono oscillator plugin with four waveforms, featuring:

- Fatsaw
- a composition of 3 parabolas
- sectionwise Noise/Saw
- 16 stages of Sample&Hold


I wonder why it tourned out so big (15Mb)?
Greetings, Frodson

W Pirkle
September 16, 2015 - 10:02 pm
Member Since: January 29, 2017
Forum Posts: 444
sp_UserOfflineSmall Offline

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.

- Will

Forum Timezone: America/New_York

Most Users Ever Online: 152

Currently Online:
5 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 48

Derek: 46

Frodson: 45

Peter: 43

TheSmile: 43

clau_ste: 39

JimmyM: 33

Gwen: 32

EZB: 24

lppier: 23

Member Stats:

Guest Posters: 1

Members: 617

Moderators: 1

Admins: 4

Forum Stats:

Groups: 12

Forums: 38

Topics: 651

Posts: 2558

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