Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

Wavetables

DSP related issues, mathematics, processing and techniques

Wavetables

Postby tulamide » Sat Sep 12, 2015 12:20 pm

I want to understand the basics, so that I could replicate it in code.

We have one cycle of a sine wave, rendered with 512 sample points. The built-in prim now generates a "bandlimited wavetable" out of that waveform. I heard that bandlimiting is needed to minimize aliasing.

But how is that performed?
How many different waveforms are needed to be generated from the original source?
To what frequency does the original source refer to?
How are they generated?
To what bands are they limited?
How does one limit to bands?
Who defined what bands are to be used?
Can wavetables be generated in runtime, while they are used (so that one could realize morphing sounds, for example)?
How is evaluated what waveform from the table is to be used?
If you feel like gifting: https://paypal.me/tulamide
tulamide
 
Posts: 2196
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Wavetables

Postby KG_is_back » Sat Sep 12, 2015 1:22 pm

It works like this:

Suppose you have 512samples long wavetable. That means it contains 128 possible frequencies (including DC which is zero frequency). Remember, PCM wave files/streams are not "connect the dots" type of wave, but rather "build from harmonics lower than nyquist" wave.

To create a bandlimited wavetable you need to do following:
1. Create 128copies if the wave.
2. Leave first wave as it is, remove topmost harmonic from the second, two topmost harmonics from the third... Leave only base harmonic and DC in the next-to-last wave and leave only DC in the last one.
NOTE: the flowstone wavetable prim has the waves in reversed order.

How to pick the right table:
The point of the band limited table is, to pick the wavetable that will have all harmonics below nyquist frequency.
the formula is: table_index= min(127, max(0, 2/freq)) //freq is the normalized frequency
The min/max term is there because for frequencies below nyquist/128 all harmonics of the original wavetable are below nyquist so you use that one and for all frequencies above nyquist you use the one that has only DC, because all other harmonics would alias.

The whole point of bandlimited wavetables is to have them pre-computed. Computing them at samplerate is pointless. The typical alternative approach is to use oversampled non-bandlimited oscillator and then downsample it, which removes all harmonics above nyquist.
KG_is_back
 
Posts: 1201
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Wavetables

Postby tulamide » Sat Sep 12, 2015 5:37 pm

Assume to do something like this in Ruby. I have a float array as input, named @input_array. Would this be a correct building of the wavetable?
Code: Select all
def init
   @table = []
end

def to_table source, index
   waveform = source.clone
   waveform[(511 - index)..511] = 0
   @table << waveform
end

def event i, v
   0..127.each do |ix|
      to_table @input_array, ix
   end
end


I ask, because some things were unclear. If there are 512 sample points and I do 128 copies then

1) It would result in 129 waveforms in the table
2) The last converted waveform would have 512 - 128 = 384 sample points and 128 points at dc

Also, I understand the pre-compute thing. But how is real morphing with wavetables then realized? There are some synths that have this feature.
If you feel like gifting: https://paypal.me/tulamide
tulamide
 
Posts: 2196
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Wavetables

Postby KG_is_back » Sat Sep 12, 2015 8:56 pm

tulamide wrote:I ask, because some things were unclear. If there are 512 sample points and I do 128 copies then

1) It would result in 129 waveforms in the table
2) The last converted waveform would have 512 - 128 = 384 sample points and 128 points at dc


sorry for the confusion. No, the resulting wavetable will have 128 waves. Total amount of samples will be 512*128 (ir in general (N*N)/2, where N is the single wave size )
Each waveform will still have 512 samples. First will contain only DC, seconf will contain DC and fundamental (= it will be a sine wave)... and the last one will have all harmonics (=will be identical to source). To do that you need to use Fourier transform. I have to go to the Trnava Jahrmakt now, I will make an example later this evening when I come back ;-)

tulamide wrote:Also, I understand the pre-compute thing. But how is real morphing with wavetables then realized? There are some synths that have this feature.


Morphing is usually done by mixing 2 or more wavetables... However, if you want to do triangle<->saw morphing (or similar shape changes) you need to do the oversampled nonbandlimited osc that I mentioned before...
KG_is_back
 
Posts: 1201
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Wavetables

Postby tulamide » Sat Sep 12, 2015 9:54 pm

KG_is_back wrote:To do that you need to use Fourier transform. I have to go to the Trnava Jahrmakt now, I will make an example later this evening when I come back ;-)

An example would be awesome! Thank you in advance!

And have fun now! (is it really called Jahrmarkt or did you just use that german word so that I understand it)
If you feel like gifting: https://paypal.me/tulamide
tulamide
 
Posts: 2196
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Wavetables

Postby KG_is_back » Sun Sep 13, 2015 1:02 am

OK, here is the wavetable generator. It is pretty much identical with the stock prim. Input must be 2^N long.
I don't have the wavetable oscillator finished, but I'm pretty sure you can work that one out.

tulamide wrote:And have fun now! (is it really called Jahrmarkt or did you just use that german word so that I understand it)

thanks... well, the Slovak word is Jarmok (from the german Jahrmarkt) and I was too lazy to search for English equivalent.
Attachments
wavetablebuilder.fsm
(3.2 KiB) Downloaded 639 times
KG_is_back
 
Posts: 1201
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Wavetables

Postby tulamide » Sun Sep 13, 2015 2:21 am

Awesome, KG, thank you for taking the time! Finally there's code I can read and understand, whereas wikipedia and audio engeneering sites are more interested in strange formulas with even more strange signs.

And yes, I can build the oscillator.

I know we are tough guys and all, still, the word Jarmok is somehow cute :mrgreen:
If you feel like gifting: https://paypal.me/tulamide
tulamide
 
Posts: 2196
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Wavetables

Postby MyCo » Sun Sep 13, 2015 6:26 pm

KG_is_back wrote:Suppose you have 512samples long wavetable. That means it contains 128 possible frequencies (including DC which is zero frequency).


No idea how you come to 128 "possible frequencies"... in fact, for a 512 samples long wavetable, there are 256 harmonics + DC. Just count yourself: how many frequencies can be represented in a 2 samples long wave ;)

There are 2 possible ways for calculating a wavetable:
Easy Way: just sum up sine waves of different phases and amplitudes, start with a simple sine, and in the next wave add another sine of twice the frequency... just loop...
Difficult Way: use FFT on a reference waveform, then loop through the waves and do iFFT with magnitudes of the higher bins cleared. So the first wave uses original magnitude of the first bin for iFFT (all other bins = 0), the next wave uses the first 2 magnitudes,...

I've attached a "simple" schematic that demonstrates how the wavetables in FS are internally constructed.
Attachments
Wavetable-Insights (MyCo).fsm
(123.23 KiB) Downloaded 604 times
User avatar
MyCo
 
Posts: 759
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Wavetables

Postby KG_is_back » Sun Sep 13, 2015 9:32 pm

ops... you are indeed correct... my explanation was a bit off, my example is correct though... sometimes hands are ahead of the brain...
KG_is_back
 
Posts: 1201
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Wavetables

Postby tulamide » Mon Sep 14, 2015 9:25 am

MyCo wrote:Easy Way: just sum up sine waves of different phases and amplitudes, start with a simple sine, and in the next wave add another sine of twice the frequency... just loop...

Say I want the user to have influence. I can imagine 256 faders, each one controlling the "amplitude" of the appropriate Harmonic. But what would be an just as easy way, building upon given 256 faders, to let them control the phase for each "harmonic" as well? Do you have any idea?

@KG your code works well, it is looping anyway, it doesn't make a difference if looping 128 or 256 times.
If you feel like gifting: https://paypal.me/tulamide
tulamide
 
Posts: 2196
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Next

Return to DSP

Who is online

Users browsing this forum: No registered users and 7 guests