Cabbage Logo
Back to Cabbage Site

Question about oversampling and possible workarounds found

Hi, let me introduce myself since I’m new to this forum, my name is Alejo Ponce. I have been using Csound since last year and at the end of last year I started using Cabbage, I liked the program a lot since it seemed quite friendly and I was able to quickly start making some vst instruments knowing something about Csound previously.

The biggest drawback I’ve found in Csound is the lack of an oversampling implementation to avoid aliasing. Although I have been able to create custom bandlimiting tables with Vco2init and Vco2ft, I still believe that the aliasing that processes such as FM, Ring modulation, effects, etc. can produce. could be inconvenient. I know that the issue has been discussed in these forum before and that 2 .csd files with possible solutions were shared. With none of those 2 I had any luck. However I have found some possible workarounds that involve the use of external software. I’m going to start talking about these solutions because I think that maybe it could help other people and also it would be a good way to understand the question that I would like to ask about the oversampling .csd uploaded by Rory.

What I have done is this: I have created a simple instrument the is same as the initial instrument but with the only difference that instead of having a Vco2 Saw oscillator it uses an oscili opcode that reads an non-limited table therefore it produces aliasing. As I said before I know that this can be fixed with band-limited waveforms but I did this for testing oversampling solutions.

The workaraounds that I have found are:

  1. Reaper : in the latest version it has a feature that can apply oversampling to VST instruments and plugins. I have tried loading the test instrument that creates aliasing in Reaper and when applying oversampling the aliasing disappears at all. It seems to be the best and easier workaround (for the people who use Reaper).

  2. Metaplugin -DDMF: this is a plugin wrapper that loads other Vst instruments inside, it has an oversampling option. I tested with this instrument and it does the same that Reaper, turned oversample on and the aliasing was totally gone. It is not as easy than the option in Reaper (which is just pushing a button) but it is not difficult at all and it works.

  3. Ableton: I discovered that offline render at higher samplerates that the project (96000, 192000, etc. if the original sample rate is 44100 or 48000,) forces the plugins to run at higher sr and the result is that the aliasing is gone in the rendered audio file without being foreced to change the audio hardware sr. This seems to be something unique from Ableton because I tested the same in Cubase and Studio One and the alliasing was still in the audio files. It seems that with other daws the plugins work at the original sample rate and then are converted.

4)Puredata: A Cabbage/Csound vst colud be used inside puredata with the vstplugin~ object and PD has a simple way to oversample with the block~ object. There is an example at help—browser—audio examples—J07. oversampling. I`ve used the test instrument in combination with that patch and the aliasing was gone.

Although these solutions are useful, I think they are not ideal since they all involve the use of some external complement, and it would be very cool if there was a solution from within Cabbage/Csound.

In the search of that solutions I have tested the test instrument with the patch “oversampling_Rory_august_2020.csd” I’ve tried to do something simple and just connect the test waveform with aliasing to see if oversampling would fix it like happened with the alternatives mentioned above and it didn’t work for me. I’ve just tried to remove the code related to the transfer function and connect the aliased saw waveform to the oversampling and see if it fixes it, probably I’m doing something wrong and wanted to ask @rorywalsh f it’s possible to take a look at it and tell me what is wrong with the code. The only difference I hear is that the oversampled version sounds quieter. I attach the simple instrument with which I have done the tests and the modified oversampling patch.

With the patch from @Oeyvind, I did not have luck in making it work also.

I apologize if this post has been a bit long, but I really think that since Cabbage is such a nice and usefullsoftware it would be good to find a solution to this and if it is not possible I hope that at least the workarounds could help someone, thank you very much in advance.

Test instrument.csd (631 Bytes)
oversampling_Rory_august_2020 (mod).csd (1.9 KB)
oversampling_Rory_august_2020.csd (1.7 KB)

Hi @Alejo, welcome to the forum. I think most Csound users can share your frustration with the lack of any simple oversampling methods. Thanks for listing the workarounds, I wasn’t aware that Reaper can do this. It’s a nice feature.

With regards to the posts on this list, I think they both take a similar approach, i.e, upsample by stuffing zeros into the signal, low-pass, process audio, low-pass and output. At least I’m pretty sure that the angle taken (it’s a while since I wrote that).

I just tried Oeyvind’s example, and it seems to work fine. He does a few more things in his, which makes it a more complete implementation. For one, he does some interpolation, and his low pass filters seems to be a better implementation also. Let me see if I can hobble together a Cabbage version.

Here’s a rather crude hack of Oeyvinds version. I removed the processing he was doing and added an oscillator that is bound to alias due to the number of harmonics. You can enable/disable the oversampling. This a real hack, but might be enough for you to build a generic solution. I guess the most important thing is that once aliasing happens, you can’t get rid of it. That’s why the signal processing/generation has to take place on the upsampled signal. Anyway, here’s a Cabbage OeyverSampler example :slight_smile:

filter_coefs.inc (3.5 KB) oeyverSampler.csd (2.5 KB)

Many thanks to @Oeyvind for sharing this. I find that it works very well.

@rorywalsh oh what a great name :joy:
Thanks for making the demo of it in this context. It makes a very good example, especially when you play notes up in the high register (C6 -C7 octave).
Thanks also to @Alejo for showing all of these recent conveniences, I had not updated my Reaper in a while, so I did not know it had this oversampling functionality. Not surprised that they made it, as Reaper is the best :wink: My guess is that they do something similar, letting the plugin run at a higher sample rate and then wrap it in an upsample + plugin + downsample process.
I do agree that the implementation I made can be hard to understand at first glance (and hence that @Alejo did not manage to make it do what it was supposed to do initially). The cumbersome element is that the audio process to be oversampled has to be inserted right in the middle (line 59 in @rorywalsh’s example).
I heard rumors that Csound7 will have more convenient oversampling processes, so this will only get better with time :wink:

It couldn’t have been called anything else. The example does work really well, but like you say, having to embed the audio into the middle of the processing chain is awkward. Your original example handled this by overriding various UDOs. That’s probably a better approach, and offers more flexibility.

With regards to Csound7, I do recall discussing oversampling at one point, but I’m don’t recall what was decided. It might have been one of those generic ‘Csound 7 will make this easier’ answers :rofl:

Thanks @rorywalsh for creating this adaptation of the oversampling process and thanks @Oeyvind for the original code, you made it!!
I have tested it and I can confirm that it works well, this modified version will help me to better understand the previous version and see what I was doing wrong but anyway it is working in the way it is now. It would be great if Csound 7 incorporated an easy way to do oversampling but until that day comes at least I think this code does the oversampling trick just fine.
The question I have now is the following, the sr=original of the first @Oeyvind code was 48000 and from what I see in the file “filter_coefs.inc.” file the filter coefficients have been calculated for sr=48000. To apply the oversampling in another sr like 44100 I assume that the filter coefficients would have to be changed if I am not mistaken and it can be done with the link that appears in the file filter_coefs.inc “http://t-filter.engineerjs.com /”
In case of using another sample rate, would it be necessary to change something else beside from the filter coefficients?