From the original SynthMaker forum (2004–2014), with its members’ names and dates.
Andrew J ·
Hi all,
As hinted elsewhere on the forum, I've been working on a toolkit for oversampling - and now it's ready! So take a look at the wiki tutorial (which is inside the DSP section of the tutorials). You'll find a schematic containing the ASM-optimised filters towards the bottom of the page, there's also an example schematic to play with.
Thanks to sambean for originally providing the code for the polyphase IIR filter, and to aliasant for user testing and feedback.
Please post any comments/issues here.
Regards,
Andrew J
aliasant ·
Simply amazing work. Im stunned! Speechless.
Out of words. Knocked to the floor.
😀
sunsynth ·
I second that and i am the 2nd on the floor 😉
SUNsynth
exonerate ·
Thanks andrew 🙂
Have to study this some more, but I think your tutorial and example will help me to get my head around oversampling at last!
It seems that in your example schematic the triangular and power oversampling requires a gain boost by the oversampling factor to be at the same volume level as the polyphase. I guess thats to do with the quality of the filters and the roll off?
Cheers 😀
Exo
kirkagur ·
I must say that I am "on the ceiling" like all the others!
very useful stuff a lot to learn!
thx!!!!!!!!!!
TomC ·
Andrew J wrote: Hi all,
As hinted elsewhere on the forum, I've been working on a toolkit for oversampling - and now it's ready! So take a look at the wiki tutorial (which is inside the DSP section of the tutorials). You'll find a schematic containing the ASM-optimised filters towards the bottom of the page, there's also an example schematic to play with.
Thanks to sambean for originally providing the code for the polyphase IIR filter, and to aliasant for user testing and feedback.
Please post any comments/issues here.
Regards,
Andrew J
Great
I've already created my own Triangular/Linear up and downsampler primitives, but that polyphase thingy sounds quite interesting. But I think it's more than just upsampling, I'll have a closer look next weekend.
Tom
MyCo ·
Hi Andrew!
This is exactly what I described in the other thread, which you are refering to. But your explanation is totaly missleading, and I don't think there are many people outside that realy understand how simple it is. The way you describe it is just to difficult. The basic idea is just: calculate an imaginary sample between 2 real samples, the easiest way is a moving average filter which is the most simple lowpass filter. Then process the real-stream and the imaginary-stream you describe it as "oversampling process" and at the end you just mix the to streams together with another lowpass filter (the moving average filter could do this too).
My english is too bad, to explain it in "Fachchinesisch" (technical mumbo-jumbo [???]) 😈
And for me, it is still a fake oversampling, because it isn't processed at higher sample rate. The right term for this in my opinion is "double processing" 😉
Andrew J ·
MyCo wrote: Hi Andrew!
This is exactly what I described in the other thread, which you are refering to. But your explanation is totaly missleading, and I don't think there are many people outside that realy understand how simple it is. The way you describe it is just to difficult. The basic idea is just: calculate an imaginary sample between 2 real samples, the easiest way is a moving average filter which is the most simple lowpass filter. Then process the real-stream and the imaginary-stream you describe it as "oversampling process" and at the end you just mix the to streams together with another lowpass filter (the moving average filter could do this too).
My english is too bad, to explain it in "Fachchinesisch" (technical mumbo-jumbo [???]) 😈
And for me, it is still a fake oversampling, because it isn't processed at higher sample rate. The right term for this in my opinion is "double processing" 😉
Hi Maik,
I don't understand why you say the explanation is totally misleading? The explanation is simplified in some regards, but I don't think it's actually misleading. The use of a low pass filter as an interpolator is well documented in literature, as are the use of polyphase IIR filters as decimators.
The triangular window filter I provide is quite similar to the moving average filter you mention. While I'd agree that a moving average filter is the easiest way, the performance of this and other simple convolution filters is somewhat limited.
As for "double processing" at the original sample rate, it's not fake. It's all a matter of timing. With "true" oversampling at 2X the original rate, you simply process one sample and produce the ouput, and then the process the next and produce the next output. When doing this in SM, we are going to be returning to the original sample rate anyway - so we don't need to wait for an in-between sample period (of a higher S.R.). We can simply shuffle our sample/state values and process the next sample immediately after the first one. If coded correctly, the result (after returning to the original sample rate) is mathematically equivalent to what you call "true" oversampling.
The only thing I'm not completely comfortable with in this toolkit is the cascading technique for higher rates of oversampling. While cascading techniques have been proven elsewhere, I have not worked all the way through the maths of my example. I have simply performed experiments (as per the overdrive example) and concluded that the technique does actually seem to work!
In the end, the real test is whether or not people find that it removes audible aliasing artifacts.
Regards,
Andrew
PS - I really appreciate any critical review (I don't always get it in my job as a professional engineer!)
MyCo ·
In "true" oversampling, you can generate waveforms with let's say FS/2 which have 4 samples so you can see what it is:
sine: 0 1 0 -1
saw: -1 -0.3 0.4 1
ramp: 1 0.4 -0.3 -1
pulse: -1 -1 1 1
in "fake" oversampling FS/2 is a pulse (-1 1) and it depends on the filter how it looks like oversampled. But you can NEVER generate different waveforms at this frequency.
And this is not what you are looking for, if you need oversampling...
Andrew J ·
exonerate wrote: It seems that in your example schematic the triangular and power oversampling requires a gain boost by the oversampling factor to be at the same volume level as the polyphase. I guess thats to do with the quality of the filters and the roll off?
Exactly - gain is preserved if you stay within the pass band. You can try a pre or post EQ to compensate for the roll-off.
Andrew J ·
MyCo wrote: In "true" oversampling, you can generate waveforms with let's say FS/2 which have 4 samples so you can see what it is:
sine: 0 1 0 -1
saw: -1 -0.3 0.4 1
ramp: 1 0.4 -0.3 -1
pulse: -1 -1 1 1
in "fake" oversampling FS/2 is a pulse (-1 1) and it depends on the filter how it looks like oversampled. But you can NEVER generate different waveforms at this frequency.
And this is not what you are looking for, if you need oversampling...
OK - so you're talking specifically about constructing an oscillator here? If so, you don't need to upsample anything - you'd simply generate the in-between samples immediately after the first ones and output them to the decimating filter. The decimating filter is coded so that it considers all the samples correctly and effectively processes them as if it were at the higher sampling rate.
I've never coded an oscillator before, but it'd be fun to have a go and see if I can show you exactly what I mean. Any preferences as to which waveform you'd like me to attempt?
-Andrew
bootsy ·
great stuff - thanks for sharing and thanks especially for the detailed comments in the ASM 🙂
watch out for denormals when using the polyphase filter.
aliasant ·
bootsy wrote: great stuff - thanks for sharing and thanks especially for the detailed comments in the ASM 🙂
watch out for denormals when using the polyphase filter.
I just noticed that too. Simple fix by adding a low noise to the signal. My noise is at -160dB If I go lower it seems to stop working.
TomC ·
MyCo wrote: And for me, it is still a fake oversampling, because it isn't processed at higher sample rate. The right term for this in my opinion is "double processing" 😉
Nope it's perfectly normal oversampling. When you double your sample rate you're processing twice as much samples per second, when you do it like Andrew and I do you process 2 samples at the same time, which happen to be twice as much samples per second as well.
When you use the same upsampling algorithm the result even does null.
Tom
bootsy ·
Andrew,
I just took an ordinary RBJ peak filter and oversampled it with vour polyphase OS. I saw that the EQ curves still get warped near nyquist frequency in the same way as without OS. I thought the warping should be gone with proper OS. Any ideas?
peace,
bootsy
Andrew J ·
bootsy wrote: Andrew,
I just took an ordinary RBJ peak filter and oversampled it with vour polyphase OS. I saw that the EQ curves still get warped near nyquist frequency in the same way as without OS. I thought the warping should be gone with proper OS. Any ideas?
peace,
bootsy
Bootsy,
Recursive filters are state dependent - they need to operate on past samples. So if you just take two ordinary RBJ filters and process the two sample streams independently, then they're skipping alternate samples. You need to recode it so that you can feed the outputs of each filter to the other one (as well as still taking the inputs!). For an example of this, look at the original code version of the triangular convolution filter.
The other thing you need to watch out for is that when you operate at a different sampling rate, the interpretation of a 0..1 frequency cutoff is also going to be different.
-Andrew
bootsy ·
Andrew J wrote:
bootsy wrote: Andrew,
I just took an ordinary RBJ peak filter and oversampled it with vour polyphase OS. I saw that the EQ curves still get warped near nyquist frequency in the same way as without OS. I thought the warping should be gone with proper OS. Any ideas?
peace,
bootsy
Bootsy,
Recursive filters are state dependent - they need to operate on past samples. So if you just take two ordinary RBJ filters and process the two sample streams independently, then they're skipping alternate samples. You need to recode it so that you can feed the outputs of each filter to the other one (as well as still taking the inputs!). For an example of this, look at the original code version of the triangular convolution filter.
I see, makes sense of course.
The other thing you need to watch out for is that when you operate at a different sampling rate, the interpretation of a 0..1 frequency cutoff is also going to be different.
-Andrew
I've managed that one already. Thanks for the help!
Bootsy
Andrew J ·
Maik,
Seeing as I'm a total noob with oscillators, I've had to go and have a bit of a play, a bit of a think, and do a bit of research. I can now see why you don't think this approach is much good for oscillators - but I think it's for different reasons than what you were trying to explain.
I have been able to build a naive sawtooth oscillator (which is non-band limited) and extend the code to produce 2X and 4X samples for each 1X sample period. If I feed this into the polyphase IIR decimating filter I do get a sawtooth output. However, the filter introduces a nasty ringing on the -1 to -1 step transition. If I use one of the simple convolution filters, I don't have the ringing problem - but I get a really nasty aliasing problem because the naive method extends the signal bandwidth even higher at 2X and 4X and these filters aren't good enough to reject it.
So, obviously we 'd be better off using a band limited oscillator in the first place - and if you do that with a BLIT or minBLEP, there may be little or no advantage in using the approach taken with this toolkit.
Having said all that, it's interesting to note that the output of a 2x oversampled naive oscillator is starting to look like the output of a BLIT oscillator anyway.
BLIT sawtooth
The other difference being that it looks like optimised BLIT code would be less CPU intensive!
-Andrew
aliasant ·
I like the "naive" sawtooth.
Looks nice 😉
Tom7777 ·
Nice work, the 2X oversampled naive sawtooth looks nice, im a bit confused as to how to use them in a poly signal however on oscs etc, does anyone have a quick example for a saw like that?
Edit - Also can one use them as a stereo effect etc, i notice there mono but packed and unpacked in the overdrive example for stereo would you just double both sides up as normal?
Andrew J ·
Tom7777 wrote: Edit - Also can one use them as a stereo effect etc, i notice there mono but packed and unpacked in the overdrive example for stereo would you just double both sides up as normal?
Yep - you can unpack the overdrive (or whatever effect you're working on) - and put packs before and after the filters instead. Obviously, you want to use packs wisely to ensure most efficient use of the most processor intensive modules.
Andrew J ·
Tom7777 wrote: Nice work, the 2X oversampled naive sawtooth looks nice, im a bit confused as to how to use them in a poly signal however on oscs etc, does anyone have a quick example for a saw like that?
Try this for a start...
Tom7777 ·
Thanks, i hope im not being annoying but as im no coder is there anyway to make it a module i can put after any osc i want, the saw is coded as is the other bit it seems, could you use this with the default oscs etc?
Also is this right for a stereo overdrive effect?
aliasant ·
Yes Tom7777
That looks about right.
sunsynth ·
If 2X Polyphase IIR is enough...
...this should work (untested):
Tom7777 ·
Thanks 🙂
Large ·
That's cool, but I've been trying the last few days to get it to work on my digital AND wavetable oscillators in a basic Midi-keyboard-triggered-synth-type schematic and it does nothing to remove aliases. Perhaps I'm setting it up wrong, but then again, how do you set it up?
I'd prefer if it would process the entire output of a schematic, without turning everything mono. Preferably using the 2x and 4x Polyphase IIR (my favorties 🙂 )
Can you post an example of it doing this?
Disco_Steve ·
I may have simply missed it in your wiki/forum posts, but what delay offset do I need to add so that I can make the output 'linear' phase?
I'm guessing for the power version its 1 sample
and for the triangle its 2
but how many is it for the polyphase? also when I combine them to give me say ,8X oversampling, how much delay do I need then, I'm getting very confused?
Andrew J ·
Disco_Steve wrote: I may have simply missed it in your wiki/forum posts, but what delay offset do I need to add so that I can make the output 'linear' phase?
I'm guessing for the power version its 1 sample
and for the triangle its 2
but how many is it for the polyphase? also when I combine them to give me say ,8X oversampling, how much delay do I need then, I'm getting very confused?
Whether the output is linear phase or not is dependent on the group delay of each filter (i.e. the phase response), you can't just make it linear phase with a delay offset.
If you're talking about time aligning the output with respect to the input, then this can only be done accurately for all frequencies if the filters are linear phase. The polyphase IIR is definitely not linear phase as only FIR filters can be linear phase. Same goes for the power series filter. The triangular filter is a symmetrical FIR, so it should be linear phase. By experimentation, a one sample delay per 2X stage seems to give time alignment.
-Andrew
Andrew J ·
Large wrote: That's cool, but I've been trying the last few days to get it to work on my digital AND wavetable oscillators in a basic Midi-keyboard-triggered-synth-type schematic and it does nothing to remove aliases. Perhaps I'm setting it up wrong, but then again, how do you set it up?
I'd prefer if it would process the entire output of a schematic, without turning everything mono. Preferably using the 2x and 4x Polyphase IIR (my favorties 🙂 )
Can you post an example of it doing this?
Sorry I missed this one Large.
It's really important to get rid of the aliases as early as possible, otherwise they can keep forming products with each other throughout your schematic (this happens any time you multiply signals together). If these products fall across the wanted audio band, you can't filter them out at the end of the chain without affecting the wanted audio.
-Andrew
Disco_Steve ·
Thank you most help full,
time alignment was the word I should have used on my last post, I'm using your up samplers in a limiter I have made, however the phase error in the iir seems to stop everything from working the way that a planed, and overshoots are still occurring , I could use them but it would require a rewrite.
however I am using your triangle up sampler with great effect as its linear phase.
thank you again for your excellent Oversampling Toolkit, steve
Thorsten ·
I'm, trying to use the fantastic 🙂 os. toolkit with some cascaded biquads, but I'm in deep water here.
Am I doing it right? It seems so, but I could have missed something... I thought the frequency range of the filter would change for instance, seemingly it hasn't.
Andrew J ·
Thorsten - just take your cascaded biquad and put it between the pack and unpack components without fiddling with it at all. The cutoff will work out OK.
What you've done is introduce some more recursion on each stage of the biquad, which is effectively adding a gentle low-pass. That's why the upper band looks cleaner (not because of oversampling).
-Andrew
bootsy ·
But it's a recursive filter here too ...
Thorsten ·
Thanks, Andrew. I think I'll keep it though, I like the sound it gives the schematic I'm using it in 🙂
bootsy ·
Howdy,
I've attached an example on how to use straight forward SSE packageing on the 4x Polyphase Upsampler when using two channels (stereo). This saves a lot cpu in this case.
Could be done for the cheaper filters as well but the savings are not that significant due to the pack/unpack overhead.
And don't forget to denormalise the Polyphase filter with your preferred method.
peace,
bootsy
sunsynth ·
Hi bootsy,
thank's 4 your source... great work - will test it soon!
SUNsynth
infuzion ·
Thanks booty!
I've noticed with the CPU Cycle Analyser v1.5, this only takes about 2 cycles?? Something must be weird...
aliasant ·
infuzion wrote: Thanks booty!
I've noticed with the CPU Cycle Analyser v1.5, this only takes about 2 cycles?? Something must be weird...
Strange. I just checked and it used about 530 cycles here.
bootsy ·
infuzion wrote: Thanks booty!
I've noticed with the CPU Cycle Analyser v1.5, this only takes about 2 cycles?? Something must be weird...
now thats what I call optimization 😉
infuzion ·
aliasant wrote:
infuzion wrote: Thanks booty!
I've noticed with the CPU Cycle Analyser v1.5, this only takes about 2 cycles?? Something must be weird...
Strange. I just checked and it used about 530 cycles here.
You are correct; I mistakenly used the MonoToPoly which threw things off.
Large ·
Hello, does this Oversampling Toolkit not work with Digital Oscillators?
Also, if there was a POLY / ASM method of Oversampling, that would bring down the CPU even more 🙂
I really can't stand that it has to be in MONO all the time.
Something to look into!
Can you fix the attachment so it works with Digital Oscillators?
Andrew J ·
Large,
The OSC you're using produces aliasing inside the wanted audio band before you pass even it to the filters. You can't get rid of that without getting rid of the wanted signal too!
You need to use an OSC that calculates multiple samples for each 1X sample or use a bandlimited OSC that avoids the aliases in the first place (e.g. BLIT or minBLEP).
For an example of a 2X SAW, see this post and OSC_example_v1.6b.osm. This example also shows that you can use the filters with a POLY signal (you just have to avoid using Pack/Unpack).
-Andrew
Large ·
The 2X Saw is okay but at higher pitches it has a low hum sound.
Also I think the pitch is off by a note or two.
It needs Phase and Hard-Sync as well. Oh well.
overhishead ·
Is this topic finished here, or has oversampling moved to a more current thread?
MegaHurtz ·
Its there.
overhishead ·
i stupidly forgot to re-read the title of the thread... Its not about oversampling, its about the toolkit. im sure i meant to ask if there was a discussion on oversampling somewhere else on the thread.
dasdeck ·
hi there!
i see that the polyphase upsampler reduces volume by 50% (the half variable).
wouldn't this change the sound for volume dependent dsp ?
i'd just change it to alter volume after downsampling.
its not good to reduce volume by half for my purpose 😉.
cheers!
and thanks for this toolkit! 🙂
jm
edit: i'm not fully grasping the math going on, so i woudl like to know if the division by two is nessesary.
Andrew J ·
The halving is to make sure the energy is balanced from end to end. You're correct in pointing out that it can be a problem for volume dependent dsp - in that case it's better to do the halving in the downsamplers rather than the upsamplers. I probably should have done that from the start!
dasdeck ·
cool, yeah...would make sense to be able to a-b stuff and such..
peace!
jm
Andrew J ·
Have now added a new version of the toolkit to the wiki which corrects this issue.
aliasant ·
Andrew J wrote: Have now added a new version of the toolkit to the wiki which corrects this issue.
Nice Andrew! 🙂
Andrew J ·
Only took me two years 😊
aliasant ·
Andrew J wrote: Only took me two years 😊
Lol. I do think I did that change myself ( or similar, havnt looked at yours yet) and should be just as ashamed for not posting it here 😊 But then again. I havnt been using these oversampling things cause I could never really find the place for them. Used other ways to get the sound I wanted. I guess I should dig into this someday.
attic ·
Thanks Andrew. The wiki info is very easy to understand and I enjoyed learning about this. 🙂
Dell ·
Hi.
Possibly you can explain something that you have not addressed.
If one should insert an up-sampling module between two processor modules, will it follow the same topology as hardware devices (44100 <-pre-up-sampling, 88200 post-up-sampling) or will just convert everything within the chain to 88200?
How does it determine the up sample rate?
Is it based on the audio file?
If yes, would a 96 kHz file automatically be 192 kHz based on your up-sampling design scheme?
Cheers!
Andrew J ·
Dell, this works on an audio stream at the current sample rate of the project. Each stage has a factor of 2 effect on the sampling rate.
When you upsample by a factor of 2, the project sample rate doesn't change. The effective rate is achieved by creating 2 samples from 1 and processing both of them at each step of the project sample rate.
If this doesn't help explain things, then describe what you would like to achieve and I'll try and explain within that context.
Dell ·
Cheers Andrew J!
It appears the concept follows the same method as a dual-core processor oppose a single core. 🙂
tor ·
Think I will use this. Credit will follow.
Thanks Andrew! 😀
dasdeck ·
hi!
may the polyphase IIR from the toolkit create less images/ catch more aliases if the frequency is lowered a bit?
it seems to be above audible range (@ nyquist?). maybe lowering it to 20k + x would increase its anti aliasing capabilitys?
some high quality plugins i use seem to beusing oversampling filters at about 20 k.
if there may be benefit from it, can you please point me to a way to lower the frequency of the polypahse iir? or hint me to a different implementation? i'll try to find out whether the oversampler Christian Budde uses is open source, and if so i'll port and post it here.
cheers!
jm
edit:
if i use 2xoversampling to unripple high frequency warping, can i skip downsampling an just use the first sample? i assume this is the case, as no additional content is created?
edit2:
i just discovered that the chbyshev filter is very steep. any experience oppinions on using it for downsampling? how would i use it for upsampling? i tried to use a RBJ for upsampling, but i seem to have approached it wrong (thought RBJs seems like a little wrong for oversampling anyways 😊 ).
edit3:
ok the chebyshev thing seems to be a brainfart. i forgot that the filter will unripple when used as a downsampler (or at least thats how i would discribe it)
edit4: 😀 ok...seems liek the budde one is not better as the stuff I come up with, and the one form the toolkit is superior in terms of steepness.
Andrew J ·
Hi dasdeck,
The polyphase IIR filter in the toolkit is a half band filter - i.e. it stops at the nyquist frequency. This is quite a nice filter in theory, but in practise I think it's let down because we can only use single precision floating point in SM code. You could improve rejection of aliases by lowering the stop band, but I don't have the coefficients for that with this filter.
If you are truly not creating any information above the nyquist frequency, then yes you can downsample by just omitting unwanted samples.
Chebyshev can suffer from ripple in the pass band. To get good enough performance you'll need up to maybe about 300 taps in your FIR.
-Andrew
dasdeck ·
Andrew J wrote: Hi dasdeck,
The polyphase IIR filter in the toolkit is a half band filter - i.e. it stops at the nyquist frequency. This is quite a nice filter in theory, but in practise I think it's let down because we can only use single precision floating point in SM code. You could improve rejection of aliases by lowering the stop band, but I don't have the coefficients for that with this filter.
If you are truly not creating any information above the nyquist frequency, then yes you can downsample by just omitting unwanted samples.
Chebyshev can suffer from ripple in the pass band. To get good enough performance you'll need up to maybe about 300 taps in your FIR.
-Andrew
thanks.
i suppose i don't create any information above the nyquist frequency with a standart RBJ filter ?
i saw the chebyshev ripple, but one can bring it down pretty much, i could not hear it conciously (when set to around 20k that is), but one can feel how the signal change. anyways, i think i'll stick with the polyphase then. how did you come up with the coefficients in the version form the toolkit in the first place?
jm
Andrew J ·
The coefficients were from sambean's original code, and if I recall correctly it looked to me like he got them from a paper by Laurent de Soras.
With regards to the RBJ and creating information above fs/2, you might get a bit, but it may not be audible. Perhaps try it and see!
mikedaniel01 ·
how would i go about oversampling the osc's that come standard in synthmaker with the oversampling toolkit i know nothing about oversampling so descriptiveness would help
dasdeck ·
i would expect it to work like this:
download
the selector switches normal and oversampled version. (true => oversampled)
this may be wrong thought.
cheers!
jm
tor ·
This chematic is wrong in the oscilator part. The phase change is not the way to do this. Though I am not the right person to answer this but I think you have have to either upsample just one oscillator. Or write your own osillator that output oversampled sound within two paralell streams. I think maybe there are some others here on the forum working or worked with the same goal. I just do not remember who or in what thread. Try some searing in here.
Good luck to you 🙂
dasdeck ·
mhhh....are you shure? from what i can see this is waht the oscilator would put out when driven at double the sample rate...whatever....i have a question to the all knowong DSP gods 😀...why does a clipper/saturator let peaks through when oversampled? is it me implementing it wrong? i already use the updated toolkit. judging by the sound the oversampling does what it is supposed to do, it removes some harsh artifacts. is it maybe because of the reconstruction in the downsampler? similar to what happens when encoding clipped material to mp3s and decoding them will make then "unclipped" again ? i try to think it through myself again, but input is welcome of course 😀!
cheers!
jm
Andrew J ·
dasdeck's approach should work as long as the second oscillator is set up so it calculates the value exactly mid way in between any two consecutive outputs from the first oscillator. The phase adjustment is a clever way to do this, but the multiplication factor needs to be 0.25 rather than 0.5. Also, it doesn't make a lot of sense to try this with the sin oscillator as it isn't trying to generate much above fs/2. Change out to triangle oscillators and you can see that the oversampling does indeed attenuate the aliases.
With regards to the question about the clipper letting peaks through, I'd like to see a schematic before I comment.
tor ·
ok... sorry 🙂
mikedaniel01 ·
Thx for the help. 🙂
mikedaniel01 ·
In regards to the oversampled oscillator the half module comes from the freq knob in the schematic so if i was to connect it directly from the pitch to freq module on the freq connector that would work right? I'm just making sure i'm connecting it right.
Andrew J ·
Should be fine, go ahead and give it a go. The only niggle I can think of is that if you want to feed this with poly then the half module needs to be implemented in stream maths.
Large ·
Andrew,
Can you adjust this code so it is oversampled?
This is a fully functional digital oscillator, but aliases like crazy:
tmp = tmp - (lastsync==0) & (sync!=0) & (tmp+phtemp);
a = tmp+phtemp;
a = a - (a>1.0)&2.0;
a = a + (a<-1.0)&2.0;
out = 0-a;
lastsync=sync;
}
I need to be able to do FM, and Hard-Sync with these oscillators, without any aliasing.
Please note: I don't have SM 2.0, so please post code only. Thanks.
Andrew J ·
Large - the easiest thing is to use the technique dasdeck demonstrated above, it should work fine with the code you posted (mind you, I haven't tested it with FM or hard-sync).
The oversampled waveform is the paler one which shows the ringing you'd expect of a band-limited signal.
You can oversample at 4x by using phase multipliers of 0.25, 0.5 & 0.75 and cascading the downsampling filters.
aliasant ·
Andrew J wrote: Large - the easiest thing is to use the technique dasdeck demonstrated above, it should work fine with the code you posted (mind you, I haven't tested it with FM or hard-sync).
The oversampled waveform is the paler one which shows the ringing you'd expect of a band-limited signal.
You can oversample at 4x by using phase multipliers of 0.25, 0.5 & 0.75 and cascading the downsampling filters.
Tested and works but I also tried the other Downsampling filters you made; Triangular and Power.
personally I prefer the Triangular downsampling for 2 reasons.
First it doesnt sound that different from polyphase.
Second is that it uses a fraction of the Polyphases cycles.
On my system the Polyphase uses 108cycles and the Triangular uses only 5cycles.
If using three of them cascaded the difference is huge.
Im probably missing something here so go on Andrew 🙂 Hit me with the facts. 😈 😊
Large ·
Andrew J wrote: You can oversample at 4x by using phase multipliers of 0.25, 0.5 & 0.75 and cascading the downsampling filters.
2X does nothing at all. 😠
4X did barely anything.
So I tried 8X.
Did I set this up correctly Andrew?
Dozius ·
This isn't correct. The intermediary sample is not going to always land at 1/4 phase. If you look at the waveform on a spectrum analyzer you can see that there is some weird cancellation going on, but it's not oversampling.
To do this correctly you should be calculating the correct intermediary sample. You can do it with this code.
tmp2 = tmp2 - (lastsync==0) & (sync!=0) & (tmp2+phtemp);
a = tmp2 + phtemp;
a = a - (a>1.0)&2.0;
a = a + (a<-1.0)&2.0;
out2 = 0-a;
}
I haven't tested with FM, but since this is properly oversampling then it should work as expected. The sync might not work as expected, but you would just have to rearrange when things are being calculated to fix it I think.
edit: here's some proof, the green is not oversampled and the red is 2x. I've zoomed in so you can see the aliasing more clearly.
aliasant ·
It does work if you set it up correctly.
I made a testbed for you guys.
Theres both the Polyphase and the Triangular and you can listen to the original, 2xOS or 4xOS.
Dozius ·
I totally missed the multiply on the phase input. This does indeed work correctly.
edit: so does my code, it might be more efficient to have it in one code block anyways but then you would need different code for each over sample factor. Oh well, more than one way to skin a cat I suppose.
Large ·
Dozius wrote: This isn't correct. The intermediary sample is not going to always land at 1/4 phase. If you look at the waveform on a spectrum analyzer you can see that there is some weird cancellation going on, but it's not oversampling.
To do this correctly you should be calculating the correct intermediary sample. You can do it with this code.
I haven't tested with FM, but since this is properly oversampling then it should work as expected. The sync might not work as expected, but you would just have to rearrange when things are being calculated to fix it I think.
Yep. This is oversampled 🙂
With no mess.
It works with FM. I couldn't test hard-sync because I don't know how you would set that up.
But it needs more oversampling. About 8X or 16X would be needed for a releasable synth.
What do I copy and paste into the code? Or what do I change? Perhaps put some comments around the parts that are doing the oversampling?
MyCo posted a bunch of digital oscillators in code. How would I convert codes to your oversampled code?
Should I just post MyCo codes here?
infuzion ·
Large wrote: But it needs more oversampling. About 8X or 16X would be needed for a releasable synth.
Why so much?
Dozius ·
Large wrote: What do I copy and paste into the code?
I wouldn't worry about changing code and just use the original method proposed as it can easily be applied to any existing code. As I stated above I completely missed the multiply on the phase input, which is why I thought it was incorrect but it actually works fine.
The way I've done it you might squeeze a bit more performance by having everything in one code block (ie: more optimization opportunities) but then the code becomes much more application specific. Probably best to save that for the final stages of a synth/effect design.
Large ·
Dozius wrote:
Large wrote: What do I copy and paste into the code?
I wouldn't worry about changing code and just use the original method proposed as it can easily be applied to any existing code. As I stated above I completely missed the multiply on the phase input, which is why I thought it was incorrect but it actually works fine.
The way I've done it you might squeeze a bit more performance by having everything in one code block (ie: more optimization opportunities) but then the code becomes much more application specific. Probably best to save that for the final stages of a synth/effect design.
What I'm asking is, how do you get from 2X to 16X oversampling in one code block?
tmp11 = tmp11 - (lastsync==0) & (sync!=0) & (tmp11+phtemp);
a = tmp11 + phtemp;
a = a - (a>1.0)&2.0;
a = a + (a<-1.0)&2.0;
out11 = 0-a;
}
Dozius ·
You're multiplying by values greater than 1 which means you're no longer calculating the 'in between' samples but instead calculating future samples. This won't work out correctly.
1/(oversample factor) to find the correct interval. For 16x it's 0.0625
Large ·
Dozius, there must be something I'm doing wrong.
This 16X code sounds nowhere near as clean as Sytrus at 16X.
1.) Can you check the code for errors?
2.) What about Hard-Sync? Have you tested /implemented that into the code?
tmp16 = tmp16 - (lastsync==0) & (sync!=0) & (tmp16+phtemp);
a = tmp16 + phtemp;
a = a - (a>1.0)&2.0;
a = a + (a<-1.0)&2.0;
out16 = 0-a;
}
Andrew J ·
aliasant wrote: Tested and works but I also tried the other Downsampling filters you made; Triangular and Power.
personally I prefer the Triangular downsampling for 2 reasons.
First it doesnt sound that different from polyphase.
Second is that it uses a fraction of the Polyphases cycles.
On my system the Polyphase uses 108cycles and the Triangular uses only 5cycles.
If using three of them cascaded the difference is huge.
Im probably missing something here so go on Andrew 🙂 Hit me with the facts. 😈 😊
The triangular starts rolling off a lot earlier than the polyphase, so you'll lose the top end. Whether or not you think that sounds good depends on your source and your taste. If it sounds good, then it is good!
As a compromise, try using the polyphase for the last downsampler and triangular for all the rest. If you need to upsample, then use the polyphase as the first upsampler.
Andrew J ·
Large - does it sound OK to you before you try to put it all into one code block?
aliasant ·
Andrew J wrote:
aliasant wrote: Tested and works but I also tried the other Downsampling filters you made; Triangular and Power.
personally I prefer the Triangular downsampling for 2 reasons.
First it doesnt sound that different from polyphase.
Second is that it uses a fraction of the Polyphases cycles.
On my system the Polyphase uses 108cycles and the Triangular uses only 5cycles.
If using three of them cascaded the difference is huge.
Im probably missing something here so go on Andrew 🙂 Hit me with the facts. 😈 😊
The triangular starts rolling off a lot earlier than the polyphase, so you'll lose the top end. Whether or not you think that sounds good depends on your source and your taste. If it sounds good, then it is good!
As a compromise, try using the polyphase for the last downsampler and triangular for all the rest. If you need to upsample, then use the polyphase as the first upsampler.
Interesting tip Andrew!
Thank you. I will try that.
I cant hear higher then 13kHz so that might be why I dont think the difference is worth the cycles.
Large ·
Andrew J wrote: Large - does it sound OK to you before you try to put it all into one code block?
No, not at all.
Only the low notes (C1, C2, C3) sound fine.
And when you use them for FM, they REALLY alias badly.
Same with the stock oscillators though.
At least these digital ones let you alter the code, offering hope 🙂
Dozius, did I do the code correctly?
adamszabo ·
I am trying to understand this oversampling thing as well. How do I use these? I am trying to look at the examples but I cant get my head around them at all. Can I oversample any kind of signal flow? How would I oversample a simple stock ramp waveform? I tried connecting it in different ways but nothing happened.
Cyforce ·
The bigger question than "can i oversample anything" would be(in my mind) what would make the most sense to oversample, so where to place, which moduls etc.
From the logical view i think, the best start point for os is before the signal goes into the first "sound-changing" moduls, which would be in a normal design the filter.
Osc-oversampling, i can`t imagine, that it makes sense, also where to place there the os, specially on a digi osc, adding it before - brings nothing, adding it behind - oversamples "only" the finished output of the osc.
So for good osc sound the waveform must be right, sometimes micro changes can do there a lot for the charisma and frequency-spectrum. There is in my eyes still the best way to use wavetable-osc, you can build the waveforms how you need them and through the right matching interpolation the frequency spectrum is also different(from interpolation to interpolation) also useful for trimming the hole to the targeted sound-layout.
MichaelBenjamin ·
to my knowledge oversampling helps whenever you:
a) create a waveform with possible partials above nyquist (anything with an abrupt value change like saw/square)
b) do processing that introduces new harmonics (all kinds of waveshaping)
c) want to to something essential above 1/2 nyquist (filter curves, fast attacks, high frequency whatever)
Large ·
Still waiting for a reply from the great Dozius. Did I do it right, in my latest CODE post?
The latest saw wave code that I posted sounds "better" at high freqs, BUT, when I apply FM synthesis with TWO saw waves,
it sounds terrible, because of aliasing.
So this is where the problem lies: when two OSCs interact during:
1.) FM synthesis (phase modulation).
2.) Hard-Sync.
3.) Waveshaping the OSC.
4.) Amplitude modulation (AM).
I even tried reducing the samplerate to 11025 HZ, performing the FM synthesis, then moving the HZ back to 44,100.
I failed. But I believe this technique could work, if done properly. Please, someone else try this technique.
adamszabo ·
So how does this work in practice? I have put a ramp there, but its still aliasing like hell... it doesnt do anything
Large ·
I can't open SM 2.0 OSMs unless they are from FL Studio. That is why I can only use code for now.
Are you trying to alter the code of the ramp, or use the "toolkits" to oversample?
--------------------------------------------
I would really like to get to the bottom of this.
I followed the "toolkit", with about 16 cascading modules. It BARELY had an effect. See the picture I posted earlier.
Surely someone knows how to code oversampled oscillators, waveshapers, distortion amps, and the like.
I've seen them in FL Studio. I want them in Synthmaker, so I can make a SYNTH. Please...
aliasant ·
Large wrote: I can't open SM 2.0 OSMs unless they are from FL Studio. That is why I can only use code for now.
Are you trying to alter the code of the ramp, or use the "toolkits" to oversample?
--------------------------------------------
I would really like to get to the bottom of this.
I followed the "toolkit", with about 16 cascading modules. It BARELY had an effect. See the picture I posted earlier.
Surely someone knows how to code oversampled oscillators, waveshapers, distortion amps, and the like.
I've seen them in FL Studio. I want them in Synthmaker, so I can make a SYNTH. Please...
Maybe you should start updating to v2.0 so that you can test the osm's we upload here?
Update:[old link]
This one works but you havnt tested it since you dont have the latest version: [old link]
trogluddite ·
OT: Yes, it's just one of those things with SM (and DSP in general), having the schematic does make things much easier to explain (and to understand). It's just not feasable to create a comprehensive guide to these techniques in words alone.
It's one of the reasons I upgraded - I figures that there'd be things here that I'd miss out on if I didn't upgrade.
adamszabo wrote: ... it doesnt do anything
It's not the easiest comcept to understand, but Andrew J's Wiki article (see first post) is well worth reading and digesting. Some very technical stuff admittedly, but youl'll struggle to find a more concise and clear article anywhere else on this subject.
The part that is wrong in your schematic is that you still have only one ramp modules. If you are oversampling 2* from 44100 samples per sec, then SM now has to process 88200 samples every second. So somehow, twice as much work has to be done.
You'll see from some of the other schematics that there are extra osclllators connected in parallel to take up the slack. That's why the upsample/downsampler modules have the extra ins and outs - so that you can arrange this "parallel processing".
For many things, just doubling up on the modules doesn't wotk though, because an effect might need access to every sample, and not just half of them - in which case specially written code needs to be used.
rl ·
@adamszabo: there is a little mistake in your schematic. You're upsampling the frequency which doesn't make much sense.
As a starting point: this little piece of code exactly reproduces the behavior of the Ramp module (without consideration of the sync input):
streamin f;
streamout o;
//accumulated phase
float p;
p = p+0.5*f;
p = p - (p>1)&p;
o = p;
(the Ramp module is a bit weird when used as an oscillator, since it is in the [0..1] range, thus having DC offset. A real osc would be in the [-1..1] range. Here's a real (mathematically exact) saw:
streamin f;
streamout o;
float p;
p = p+f;
p = p - (p>1)&2;
o = p;
ok, now an "upsampled" saw code to be used with the downsampling polyphase filter would be:
streamin f;
// alternating output samples
streamout o1;
streamout o2;
float p;
// two calculations at half the frequency:
p = p+0.5*f;
p = p - (p>1)&2;
o1 = p;
p = p+0.5*f;
p = p - (p>1)&2;
o2 = p;
now connect f to the frequency input and o1 and o2 to the both inputs of an "2x downsampling polyphase filter " and you have a "less-aliasing" oscillator.
adamszabo ·
Ah thank you now I understand. So basically I need to calculate everything twice.
Dozius ·
Large wrote: Did I do it right, in my latest CODE post?
As far as I can see it's correct. If there are problems, it's in the downsampling.
Large ·
"now connect f to the frequency input and o1 and o2 to the both inputs of an "2x downsampling polyphase filter " and you have a "less-aliasing" oscillator."
I just tried this. While a single oscillator sounds better, FM synthesis between TWO oscillators sounds worse than without the oversampling. 😠
This is not a valid solution.
Large ·
Dozius wrote:
Large wrote: Did I do it right, in my latest CODE post?
As far as I can see it's correct. If there are problems, it's in the downsampling.
Again, single oscillators sound better, yet "detuned" in your case.
But FM synthesis between TWO oscillators results in a horrible result.
What is this about the "downsampling"? Is this in the code?
Can you test FM synthesis with my 16X code and see where the problem lies?
BTW here is an FM synthesis OSM for everyone to try to fix the aliasing 🙂
rl ·
Large wrote: This is not a valid solution.
I did my post to help adamszabo with his schematic, not to solve FM issues.
BTW: your schematic does phase modulation not frequency modulation.
Re aliasing: What do you expect the result of a phase modulation of two non-bandlimited signals will be?
Cyforce ·
rl wrote: @adamszabo: there is a little mistake in your schematic. You're upsampling the frequency which doesn't make much sense.
As a starting point: this little peace of code exactly reproduces the behavior of the Ramp module (without consideration of the sync input):
streamin f;
streamout o;
//accumulated phase
float p;
p = p+0.5*f;
p = p - (p>1)&p;
o = p;
(the Ramp module is a bit weird when used as an oscillator, since it is in the [0..1] range, thus having DC offset. A real osc would be in the [-1..1] range. Here's a real (mathematically exact) saw:
streamin f;
streamout o;
float p;
p = p+f;
p = p - (p>1)&2;
o = p;
ok, now an "upsampled" saw code to be used with the downsampling polyphase filter would be:
streamin f;
// alternating output samples
streamout o1;
streamout o2;
float p;
// two calculations at half the frequency:
p = p+0.5*f;
p = p - (p>1)&2;
o1 = p;
p = p+0.5*f;
p = p - (p>1)&2;
o2 = p;
now connect f to the frequency input and o1 and o2 to the both inputs of an "2x downsampling polyphase filter " and you have a "less-aliasing" oscillator.
Very good explained, thanks for this 🙂
The "less-aliasing" - is the amount of "better sound" there big enough, for needing more than 2x cpu usage(because double code + downsampler modul)?
Large ·
rl wrote:
Large wrote: This is not a valid solution.
Your schematic does phase modulation not frequency modulation(FM).
Re aliasing: What do you expect the result of a phase modulation of two non-bandlimited signals will be?
I already mentioned that I was doing "PM". "FM" is just what most people call it these days.
That's the whole point of this. OF COURSE we can have non-aliasing saw waves...BY THEMSELVES.
Just use the standard saw wave that come with SM.
The point HERE is, what if someone wants to build an "FM" synthesizer? Whether you use standard saw waves, or digital ones,
they both ALIAS, and this need to be addressed.
Same with Hard-Sync. Same with waveshaping.
Not everyone here just wants to make simple subtractive synths. They are a dime a dozen.
We need MALC in here, I believe he is the only one qualified to solve this problem.
TheAudiophileDutchman ·
Large wrote: We need MALC in here, I believe he is the only one qualified to solve this problem.
JORGE or STEPHAN or some 'genius' would be just fine too! 😇
Large ·
Yes, we need their help too.
Gol, of FL Studio, solved this in 2005, with his release of Sytrus. Anything needing oversampling, he added it. Just press a button, and choose 2X, 4X, 8X, 16X, 32X, etc.
All, without a huge CPU hit.
Waveshaper, PM synthesis, etc.
It is now 2011, and SM STILL has no solution for oversampling. *shakes head*...
SM developers, please come forth!!!
infuzion ·
Large wrote: The point HERE is, what if someone wants to build an "FM" synthesizer? Whether you use standard saw waves, or digital ones,
they both ALIAS, and this need to be addressed.
Same with Hard-Sync. Same with waveshaping.
Not everyone here just wants to make simple subtractive synths. They are a dime a dozen.
We need MALC in here, I believe he is the only one qualified to solve this problem.
I don't think Malc reads anything but email, bug forum, & suggestion forums much anymore, in that order. So it's best to x-post in suggestions.
trogluddite ·
Pretty sure Malc has his hands full keeping two large software platforms up to date (SM and now also FlowStone).
He has created an open ended platform for synth designers to realise their creations; but working out how to use those tools to realise our synth and effect ideas is down to us end users. You wouldn't expect the guy that makes shovels to come around and dig your holes for you.
SM is an open ended development environment, whereas your example of Sytrus is a closed "all-in-one-box" system - so they are different in nature. I doubt that oversampling can be a 'tick the box' option for something like SM, because the implementation is so dependent upon what you're trying to use it for.
I can't pretend that I have anything like the knowledge to understand all of this, but it seems to me that simply un-aliasing oscillators is not the panacea that you think. For example...
Upsample your oscillators by 2*, sample rate is now effectively 88200 Hz - but doing FM with two such oscillators could still generate harmonics sufficiently above 44100 Hz (the new Nyquist freq) to create aliases that would appear in the downsampled signal.
It seems logical to me that the oversampling technique must be applied to the system as a whole, rather than tacking it onto each sub-module in a piecemeal fashion. That's where the Sytrus guy had an advantage - because he had complete control over every aspect of the code.
I really do wish you every success with this - I too am a little 'Yawn' about the glut of subtractive synths - but it appears that there is no substitute for a complete understanding of the implications of oversampling at every level of your design. I don't think that doing it in SM will be easier or harder than on any other platform; just that without the full understanding of oversampling, the implementation will be impossible whatever development tools you have at your disposal.
rl ·
Large, Synthmaker is a very capable tool to create proper modulation algorithms. Read some books, google for bandlimited synthesis, etc. Here is a good lecture on the topic: http://www.music.mcgill.ca/~gary/307/we ... mited.html. Don't blame others. Bring your own fairy dust. If you start with a non-bandlimited waveform and add some modulation, you also add frequency to the spectra, thus even more aliasing.
Large ·
Nice speech, RL, *golf hand clap*.
But I am looking to build a synth, not take a course on DSP.
Hence, the name "Synthmaker".
Oversampled Oscillators (ready for any type of synthesis), among other BASIC modules (Convolution, anyone?) should come STANDARD with a program dubbed "Synthmaker". I believe I read "SynthEdit" has them already. So why not "Synthmaker"?
BTW RL, you can use non-bandlimited OSCs in Sytrus, and STILL oversample them, with very little aliasing and a very little CPU hit.
----------------------------------------------
This discussion should continue, until someone with strong DSP skills can lend a hand in solving this issue. Again, we are not looking to simply oversample ONE waveform, but the interaction of:
1.) Two or more oscillators: FM(PM), Hard-Sync, AM(Ring Modulation AKA Amplitude Modulation).
2.) Oscillators through Waveshapers / Distortion / Clippers.
3.) Any event that cause freqs to go beyond Nyquist.
Dozius ·
Large wrote: But I am looking to build a synth, not take a course on DSP.
Large wrote: This discussion should continue, until someone with strong DSP skills
Sounds to me like some DSP background is required to be a 'synthmaker'.
Anyways, the oscillator is being calculated at an 'oversampled' rate so the problem is in the downsampling. Cascading half band filters will lead to artifacts. What you need is an anti-aliasing filter designed for the amount of downsampling you intend to do.
Large ·
How do you suppose gol added oversampling to Sytrus and his Waveshaper?
By the method you mentioned?
Andrew J ·
Dozius wrote: Anyways, the oscillator is being calculated at an 'oversampled' rate so the problem is in the downsampling. Cascading half band filters will lead to artifacts. What you need is an anti-aliasing filter designed for the amount of downsampling you intend to do.
The IIR filters used here are designed to do this. If they don't achieve the required outcome then perhaps it's because SM is restricted to single precision floating point in code. Indeed, having just implemented these filters in C++ I can say that double precision makes a big difference.
treacherousumbrella ·
Large wrote: Nice speech, RL, *golf hand clap*.
But I am looking to build a synth, not take a course on DSP.
You want to build a synth yet you do not wish to learn any of the skills to do so? You want everyone else to do the hard work for you?
Large wrote: Oversampled Oscillators (ready for any type of synthesis), among other BASIC modules (Convolution, anyone?) should come STANDARD with a program dubbed "Synthmaker". I believe I read "SynthEdit" has them already. So why not "Synthmaker"?
Why not switch to SE then if it solves all your issues? There are many features missing from SM, but I am sure a lot of these will be added as the program develops over time. You can't expect everything right now.
Large wrote: BTW RL, you can use non-bandlimited OSCs in Sytrus, and STILL oversample them, with very little aliasing and a very little CPU hit.
As you have been told before, FM on a non band limited oscillator will likely add frequencies above the new Nyquist f which will fold back into the audible spectrum.
Large wrote: This discussion should continue, until someone with strong DSP skills can lend a hand in solving this issue. Again, we are not looking to simply oversample ONE waveform, but the interaction of:
1.) Two or more oscillators: FM(PM), Hard-Sync, AM(Ring Modulation AKA Amplitude Modulation).
2.) Oscillators through Waveshapers / Distortion / Clippers.
3.) Any event that cause freqs to go beyond Nyquist.
Reads: "The discussion should continue until someone has done all the hard work for me, whithout me having to learn anything" People come here and give their free time to help others. They do not have to do this. They do not get paid for it.And they should not be badgered by people like you who are to lazy to learn anything for themselves. You have a powerful tool at your disposal in SM, if you just took some time to learn how to use it.
Dozius ·
Andrew J wrote: If they don't achieve the required outcome then perhaps it's because SM is restricted to single precision floating point in code.
This could play a part in it, but I'm sure the accumulating ripple from cascading a lot of them plays a part too. It would be better to have one filter that is set to the proper bandwidth and downsample once.
I haven't had a chance to look at the polyphase IIR source code yet, but I was seeing significant degradation even at 4x so maybe there is something else going on here that isn't plainly apparent.
Large ·
treacherousumbrella:
1.) I know how to use SM.
2.) Synthedit is way too hard on my eyes, plus I put in too many years in SM to switch. But I used it as an example.
3.) I will happily pay the first person (anyone watching this topic) to provide me with code and instructions for oversampling the scenerios I listed above. [[Although I shouldn't have to resort to this; this is a VERY basic feature that should've been included in SM in 2005. If you're gonna include oscillators, you should include a way to oversample them. Shame on Malc the the other devs... Tisk Tisk. Shame.]]
infuzion ·
Andrew J wrote:
Dozius wrote: Anyways, the oscillator is being calculated at an 'oversampled' rate so the problem is in the downsampling. Cascading half band filters will lead to artifacts. What you need is an anti-aliasing filter designed for the amount of downsampling you intend to do.
The IIR filters used here are designed to do this. If they don't achieve the required outcome then perhaps it's because SM is restricted to single precision floating point in code. Indeed, having just implemented these filters in C++ I can say that double precision makes a big difference.
Another request for SSE3 please?
+ SSE2=64bit audio, SSE3=faster FFT... please
Large, you've run into the wall many of us here on the SM forum hit years ago. Since SM had neither a C++ SDK nor lockable modules, SM lacks many of the modules/primitives we would like. So please, you need to either:
1) Try to make the modules yourself
2) Move to SE
3) Learn C++
4) Quit the idea of alias-free FM in SM
5) Post in the Suggestion forum.
Tzarls ·
Andrew J wrote:
Dozius wrote: Anyways, the oscillator is being calculated at an 'oversampled' rate so the problem is in the downsampling. Cascading half band filters will lead to artifacts. What you need is an anti-aliasing filter designed for the amount of downsampling you intend to do.
The IIR filters used here are designed to do this. If they don't achieve the required outcome then perhaps it's because SM is restricted to single precision floating point in code. Indeed, having just implemented these filters in C++ I can say that double precision makes a big difference.
Do these filters behave better (performance - wise) in C++ than in SM? I mean, the polyphase filter is very CPU hungry in SM, the difference with the other 2 filters is huge. Is it the same in C++?
BTW, I was thinking that maybe using a triangular filter with some pre-emphasis to compensate for the high freq roll-off would be better than using the polyphase, if only to save some CPU?
aliasant ·
Tzarls wrote: Do these filters behave better (performance - wise) in C++ than in SM? I mean, the polyphase filter is very CPU hungry in SM, the difference with the other 2 filters is huge. Is it the same in C++?
Very interesting question.
Tzarls wrote: BTW, I was thinking that maybe using a triangular filter with some pre-emphasis to compensate for the high freq roll-off would be better than using the polyphase, if only to save some CPU?
Absolutely. That should work much better and faster.
Andrew J ·
Tzarls wrote: Do these filters behave better (performance - wise) in C++ than in SM? I mean, the polyphase filter is very CPU hungry in SM, the difference with the other 2 filters is huge. Is it the same in C++?
Quality comes at a price 🙂
I'll have to get back to you on the performance differences as I've actually implemented a higher spec filter in C++, and with double precision. Might not be able to do this for a while though, am insanely busy with other stuff at the moment...
infuzion ·
Tzarls wrote: Do these filters behave better (performance - wise) in C++ than in SM? I mean, the polyphase filter is very CPU hungry in SM, the difference with the other 2 filters is huge. Is it the same in C++?
If you want really fast performance in C++ or any language, you'll have to program directly into ASM, which SM allows you to... but only a subset of ASM. There are several super-fast FFT algorithms & higher quality (eg needs less oversampling) 64bit floats that use SSE3 & SSE4, which SM does not permit.
Andrew J ·
infuzion wrote:
Tzarls wrote: Do these filters behave better (performance - wise) in C++ than in SM? I mean, the polyphase filter is very CPU hungry in SM, the difference with the other 2 filters is huge. Is it the same in C++?
If you want really fast performance in C++ or any language, you'll have to program directly into ASM, which SM allows you to... but only a subset of ASM. There are several super-fast FFT algorithms & higher quality (eg needs less oversampling) 64bit floats that use SSE3 & SSE4, which SM does not permit.
The optimised libraries I'm using have SSE optimised code with ASM in places, however ASM isn't required universally as compilers can do a pretty good job anyway. The other advantage in C++ is that you can process in blocks as opposed to sample by sample in SM. I'd speculate that the sample-by-sample approach in SM introduces some overhead that you can certainly avoid in C++.
Tzarls ·
Doest it make sense to use oversampling when working at sample rates higher than 44.1? I was thinking of a scheme where a 4x os would be applied if working t 44.1 or 48KHz, 2x os when at 88.2 or 96KHZ, and no oversampling when working at higher sample rates. Would that be ok, generally speaking, or am I better applying the same ratio of os regardless of the sr used?
aliasant ·
Tzarls wrote: Doest it make sense to use oversampling when working at sample rates higher than 44.1? I was thinking of a scheme where a 4x os would be applied if working t 44.1 or 48KHz, 2x os when at 88.2 or 96KHZ, and no oversampling when working at higher sample rates. Would that be ok, generally speaking, or am I better applying the same ratio of os regardless of the sr used?
That sounds like a good approach but you could also leave that desiscion to the user?
Tzarls ·
Yes, but then me, as a user, would also like to know! 🙂
Large ·
There's never going to be proper oversampling in SM so lets move on to Synth Edit.
Gol figured it out in 2005, with Sytrus and all his other plugins. SIX YEARS AGO.
And in 2011, Malc STILL hasn't provided us a solution. This is supposed to be "synth-maker", not "oversampling-maker".
C'mon, MALC!!! Keep up with the times!
Tzarls ·
Actually, when I leave SM it´s not for SE or anything like that. These days I´m trying to use C++, but SM is still very useful as a prototyping and( fast ) learning tool. Heck, I might even upgrade to 2.0 if they ever release a streambool2tick primitive. OTOH, I think we can have proper oversampling in SM, but implementing a whole oversampled synth requires a new approach, since the existing modules and/or primitives might not work directly when in an oversampled environment.
But none of this answers my question. Does it make sense to use oversampling when working at sampling rates of, say, 192KHz? I´ll try to find some time one of these days to find the answer by myself by performing some tests. In the meantime, if anybody knows the answer, feel free to post it. 🙂
MichaelBenjamin ·
generally i would say yes - it makes sense, especially for synthesis, waveshaping, distortion, overtones, FM and all other cases where you generate higher frequency content. the samplestuffing method with the toolkit also helps with modules that introduce higher frequencies, despite it being somewhat less effective than "real" oversampling (might need doubles as andrew said). but as a raw estimate: 2x oversamling in sm + 2x oversampling in clock rate would result in 4x oversampling overall.
Andrew J ·
Tzarls wrote: Does it make sense to use oversampling when working at sampling rates of, say, 192KHz?
It depends on the bandwidth expansion of your process, the highest audio frequency you want to protect, and how much aliasing you can tolerate. I've used a technique like you suggest for some things, but for others you might want to use plenty of oversampling even at high sample rates. This can all be figured out mathematically, but I reckon the best place to start is to just listen!
To make sure you know what to listen to, train your ears while visually analysing a signal you control. Try generating a simple sine wave and passing it through the Chebyshev polynomial code I posted recently. If you generate a 4th or 5th order harmonic and sweep through a wide range of frequencies you will easily see and hear the aliasing. Your ears are the most amazing analysers you can find, all you need to do is to learn to trust them.
BTW, another thing you can do is offer your users choice. You can give them an auto oversample option based on sample rate, as well as let them select low or high quality oversampling that are fixed irrespective of sampling rate.
oddson ·
Andrew J wrote:
Tzarls wrote: Does it make sense to use oversampling when working at sampling rates of, say, 192KHz?
It depends on the bandwidth expansion of your process...
With that much band-width head-room can't you just use filters?
I understand that you can't always do that after you've generated huge side-bands by modulating with a signal that has very high frequencies in it... but if you filter before modulating? 😕
MichaelBenjamin ·
oddson wrote:
Andrew J wrote:
Tzarls wrote: Does it make sense to use oversampling when working at sampling rates of, say, 192KHz?
It depends on the bandwidth expansion of your process...
With that much band-width head-room can't you just use filters?
I understand that you can't always do that after you've generated huge side-bands by modulating with a signal that has very high frequencies in it... but if you filter before modulating? 😕
i think thats what oversampling is about - giving headroom for lowpass filtering. besides the overstuffing modules from andrew are also filters. you probably could aswell use a moog filter, but then you want to cut as exactly as possible at half samplerate, and i think the moog filter or any other "normal" one is not very well suited for this.
Andrew J ·
MichaelBenjamin wrote:
oddson wrote:
Andrew J wrote: It depends on the bandwidth expansion of your process...
With that much band-width head-room can't you just use filters?
I understand that you can't always do that after you've generated huge side-bands by modulating with a signal that has very high frequencies in it... but if you filter before modulating? 😕
i think thats what oversampling is about - giving headroom for lowpass filtering. besides the overstuffing modules from andrew are also filters. you probably could aswell use a moog filter, but then you want to cut as exactly as possible at half samplerate, and i think the moog filter or any other "normal" one is not very well suited for this.
That's right MB.
Leif, what you're saying is right in some circumstances but not all. As I said it, all depends on how much bandwidth expansion your process has and how much aliasing you can tolerate. One of the reasons people use higher sample rates is that they want a higher audio bandwidth. Rupert Neve claims that frequencies as high as ~60kHz can affect your perception of audio quality - even though you can't hear them directly. This would indicate to me that there may be a sonic advantage to make sure that aliases aren't appearing even when operating at 192kHz. In other words, don't use the upper inaudible bands as a dumping ground for digital crap! So for processes like guitar amp simulation, using oversampling can make a lot of sense even at high sample rates. In fact, a developer of one of the older commercial guitar amp modelling algorithms has mentioned using between 4x & 16x oversampling even at 192 kHz.
BTW and as an aside: for really high levels of oversampling you'd probably want to have the polyphase IIR as first step followed by cheaper ones for later stages. For the downsampling, an FIR can become worthwhile as you only need to calculate 1 out of every 2^n output samples (where n is the number of stages).
markholtuk ·
First of all, thank you for this Andrew. It's really useful, but you don't need me to tell you that.
Second, this is my first post, so, hello everyone. I've had SM for quite a long time, but have only really had time to dabble a bit here and there. I'm hoping to do more than dabble a bit in the near future and I'm trying to get to grips with the system.
I've been working on a VST effect recently that turned out to have a denormal problem. I looked every where in my own modules that I'd coded. Nothing. It turned out it was an upsampling module in the oversampling kit. Anyway, thought I'd let you know. I stuck a denormal module between the input and the 2x upsampling polyphase IIR module and that's now fixed. I haven't checked the other upsampling modules.
Anyway, I'm not wishing to appear to be criticising, I mostly wanted to say thanks and hello.
Cheers,
Mark
Andrew J ·
Welcome to SM Mark 🙂
Thanks for reminding us that denormals need to be managed here, as they do for any IIR filters. I hope you didn't lose too much time tracking it down!
infuzion ·
markholtuk wrote: Second, this is my first post, so, hello everyone.
Hi Mark! Ever shopped at Vinyl Junkies?
markholtuk ·
Andrew J wrote: Welcome to SM Mark 🙂
Thanks for reminding us that denormals need to be managed here, as they do for any IIR filters. I hope you didn't lose too much time tracking it down!
Not too long and it was a useful exercise in itself. Thanks again!
markholtuk ·
infuzion wrote:
markholtuk wrote: Second, this is my first post, so, hello everyone.
Hi Mark! Ever shopped at Vinyl Junkies?
I haven't. My record/CD days are behind me unfortunately. The Soho shop has closed down afaik.
mayo ·
First of all, Happy Christmas to all of you! 🙂
markholtuk wrote: I stuck a denormal module between the input and the 2x upsampling polyphase IIR module and that's now fixed.
This combination will create some kind of bug. You can reproduce it by placing a denormal remover before 2x upsampling polyphase IIR module as you mentioned and the scheme will look like:
Spectrum analyzer shows white noise generated by denormal module, that's OK:
BUT, always after 10mins (regardless if some signal is going through or you just keep it as it is) it changes dramatically and hangs on this static 'buzz' wave:
Any ideas why this is happening and what should be wrong?
nmakinen ·
I have read the whole topic and the wiki page about oversampling, but there was no solution for this problem (at least I couldn't find any):
I'm working on a brickwall limiter and I've been trying to achieve up to 8x oversampling. The polyphase OS gives the best sound, but the problem is that it will mess up the volume so that the limiter won't be brickwall anymore. The triangular OS seems to preserve the volume quite well, but it will sound pretty low-passed (as pointed out earlier on this topic), especially when it's 8x.
I wouldn't like to make any compromises, and would really appreciate some help. Thanks! 🙂
- nmakinen
aliasant ·
nmakinen wrote: I have read the whole topic and the wiki page about oversampling, but there was no solution for this problem (at least I couldn't find any):
I'm working on a brickwall limiter and I've been trying to achieve up to 8x oversampling. The polyphase OS gives the best sound, but the problem is that it will mess up the volume so that the limiter won't be brickwall anymore. The triangular OS seems to preserve the volume quite well, but it will sound pretty low-passed (as pointed out earlier on this topic), especially when it's 8x.
I wouldn't like to make any compromises, and would really appreciate some help. Thanks! 🙂
- nmakinen
I have been down that same road with the same problems.
Andrew tried to help but we both failed. Cant remember details but it has something to do with the way SM works and the lack of double precision.
Maybe Andrew had success but I didnt. At least not in the oversampling part.
Andrew J ·
Not much success from me, it's a thorny problem. Some important notes:
- Performing upsampling reveals higher levels than were in the original signal.
- Imagine a signal which has the following consecutive values: 0.5, 1.0, 1.0, 0.5
- Upsampling this at 2X will interpolate a value between each pair of original samples
- If you visualize an interpolated line between these points it's obvious that the middle
value will be >1.0
- This is actually how inter-sample clipping is identified in meters such as the X-ISM meter
from SSL
- Performing downsampling can also reveal higher levels than were in the original signal
- I'm not sure this is a good explanation, but downsampling removes higher frequencies,
so...
- When higher frequencies are removed you lose definition on sharp edges and you end up
with jaggies
- So if you downsample a signal that was at 1.0 for a few samples, you can end up with
values either side of 1.0
- Clipping on a per-sample basis adds lots of harmonics and aliasing (which is why we're
interested in oversampling)
- Using an envelope reduces the need for oversampling
- The longer the time an envelope operates over, the more it looks like a fade and the less
harmonics are created
Hope that helps
nmakinen ·
Thanks for the info. I have already tried to get rid of harmonics with smooth envelope, but so far I've only managed to ruin the sound along with that (it adds pumping to the sound as far as I have tried it).
Guess I'll just try to make it work somehow. After all I think that limiters are allowed to add a tiny bit of soft saturation to the sound (at least when pushed hard) because otherwise they loose the edge of the sound trying to be too smooth. It's just a matter of damping the ugliest aliases somehow at the same time..
Panoply ·
On the issues of hard sync and fm.
I've had a few thoughts, and it seems to me that oversampling oscs using the gate pin is not the way to go.
The basic problem is that the gate pin is one sample on and one sample off, which obviously induces aliasing, and no matter how good the routine, it's always gonna be fighting a loosing battle, aliases (no matter the rate) will be generated, and they'll be big ones. On the other hand, I've been wondering whether oversampling a rapid phase offset wouldn't make a lot more sense. This would do something far more akin to what hard sync in an analog synth actually is.
As for fm ... Not at all convinced oversampling is the way to go here at all. Strikes me an additive Osc would acheive very similar results, without ever actually producing an aliasing tone, again, boxing smarter not harder!
Don't ask me to do either though, I've got near with the sync thing - near enough to be pretty sure it could work, but I don't understand how to generate additive oscs and can't help on the fm front.
I save oversampling for filters - typically self resonating ones, that sometimes display aliasing ( or more visible aliasing) at high q settings - ideal for that.
Wrote something here? To have a post removed or your name hidden, write to [email protected].