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
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Wavetables
13 posts
• Page 1 of 2 • 1, 2
Wavetables
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?
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?
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Wavetables
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.
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: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Wavetables
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?
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.
- 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.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Wavetables
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: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Wavetables
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)
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Wavetables
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.
thanks... well, the Slovak word is Jarmok (from the german Jahrmarkt) and I was too lazy to search for English equivalent.
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 1455 times
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Wavetables
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
And yes, I can build the oscillator.
I know we are tough guys and all, still, the word Jarmok is somehow cute
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Wavetables
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 1443 times
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Wavetables
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: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Wavetables
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.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
13 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 43 guests