tester wrote:Hey KG, while I'm stuck right now for a while with other non-FS related stuff - could you take some time to create wave read module, that uses large accurate numbers (and has phase offset setting and resync node like stock oscillators)?
*
A few thoughts of further things to check (for me), but it might be useful for others too.
I'm not sure yet (did not tested it), but my guess is, that it will be better to use larger waveshape files (2000 samples or more, to have very low basic frequency at ratio 1:1) for upscaling with ratio into audible ranges. Instead of starting with small shapes (= high freqs) and scaling them down. [But since such explorer would be for both - shapes and loops, then I guess it would be good to have on board the version that does not have the 6.5 min limit]
I'm not sure if for upscaling interpolation is needed, but if so, then my guess would be that b-spline interpolator should give clearest results (it does when playing with downscaling).
But basically - my guess is, that some sort of lowpass filter should be added around the SR/2 border, to avoid introducing artifacts when getting higher pitches (also not tested).
The best solution to the wave table oscillators is the one that already in FS. When you input an wave shape to a wave table prim, the prim creates a set of tables. The first table is identical with the inputted shape and each next has one top harmonic removed (using Furrier transform). The next to last one is a single sine wave (the fundamental frequency) and the last one is complete silence (or only a DC). Within the wavetable osc firt thing the prim does is, it decides (based on the input frequency) which table to use so it does not produce any content above Nyquist (which would result in aliasing).
So when scaling up, you indeed need to lowpass by SR/2 to prevent aliasing (in the stock wavetable prims this is precomputed within the tables as explained above).
When scaling down no such lowpassing is needed.
In both cases though you need good interpolation. Imagine you have a wave table [0,1,0,-1]. If you look at it carefully and analyze it with a FFT you will see that it basically contains only one sine wave (a first harmonic = 2*fundamental frequency). If would would input this into a wave table osc then at frequency 0.25 it would indeed produce a sine wave [0,1,0,-1,0,1,0,-1,0,...], but with linear interpolation on lower frequencies it would produce a triangle wave (which is obviously not a wave with single harmonic) - you need better interpolation to "smooth" it to a sine wave when playing on lower frequencies (which in fact means you are upsampling the wave table). If you would use bigger wave table that would also contain only one sine, the result would be much better even with linear interpolation (the output at lower frequencies would indeed be close to a sine wave), but still some distortion would be present.
The very same thing happens when playing at higher frequencies, but it is harder to imagine since frequencies above 0.25*samplerate do not translate into samples so intuitively.
With perfect interpolation (which in fact exists and is called sync interpolation) the size of the wave table only affects one thing - the number of harmonics the wave table has. The math is really simple: no. of harmonics = no. of samples /2. That is what Fourier series (and Fourier transform) is all about. THe smallest wave table of a sine is [1,-1]. With perfect interpolation it would give you a perfect sine wave at any frequency - and a sine table of any size would too.
With nonperfect interpolation (like the linear interpolation is) you need to cheat a little - bigger wave table = more samples = smaller gaps to interpolate = smaller errors. Now obviously, with linear interpolation wavetable [1,-1] would produce a triangle wave and with each increase in wave table size, the result would be closer and closer to a sine.
So to make long story short, all your concerns and assumptions are correct.
To the topic of a custom wave table read - there is one
here. Based on the rest of your post I assume you mean a wave table oscillator.