oversampling
| Date | 2015-05-24 21:55 |
| From | Oeyvind Brandtsegg |
| Subject | oversampling |
Has anyone done oversampling (in RT) in Csound?, say, to do alias-free distortion etc.... Would it be possible with standard opcodes? ...writing to table or array, interpolating, processing (distortion), decimation, output. |
| Date | 2015-05-25 10:23 |
| From | Victor Lazzarini |
| Subject | Re: oversampling |
You can do it in an UDO (with local ksmps = 1) For instance, I do very simple 2x oversampling in the UDO version of the moogladder filter, by running the filter twice on each sample. But other approaches could be taken, I suppose, since Csound allows to process audio sample by sample, and you can write straight expressions to do it. I would expect that you might need some sort of buffering to upsample each sample input, process that data in maybe a loop, then downsample into each sample for output. best regards ======================== Dr Victor Lazzarini Dean of Arts, Celtic Studies and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 24 May 2015, at 21:55, Oeyvind Brandtsegg |
| Date | 2015-05-25 11:09 |
| From | Joel Ross |
| Subject | Re: oversampling |
I've been wondering for a while if the UDO mechanism couldn't support this itself. I imagine some kind of statement at the beginning and end of the UDO block could signal the sampling ratio and then it could instantiate appropriate interpolation and decimation filters for the sample rate and take care of any delay as a result of filtering. Then all of the code in the UDO could remain unchanged. I guess it depends on how the UDO works internally and on whether the block processing is amenable to that. Not being very familiar with csounds internals, I wouldn't know where to look but if anyone can point me in the right direction, I'd be interested in looking into this. Regards, Joel On 25 May 2015 at 10:23, Victor Lazzarini |
| Date | 2015-05-25 11:15 |
| From | Eduardo Moguillansky |
| Subject | Re: oversampling |
| Attachments | None None |
I have never tried it in csound, but use it regularly in supercollider, here is an example of 4x upsampling, using one-sample delays. UpSample { *ar{|sig| var upsampled, coeff, t0, t_1, t1, t2; coeff = [ [ -0.0703125, 0.8671875, 0.2265625, -0.0234375 ], [ -0.0625, 0.5625, 0.5625, -0.0625 ], [ -0.0234375, 0.2265625, 0.8671875, -0.0703125 ] ]; t2 = sig; t1 = Delay1.ar(t2); t0 = Delay1.ar(t1); t_1 = Delay1.ar(t0); upsampled = Array.fill(coeff.size, {|i| (coeff[i]*[t_1,t0,t1,t2]).sum}); upsampled = upsampled ++ t1; ^upsampled; } } This returns 4 audio-signals. You would then process all of them in parallel, and give the 4-streams to the downsampling part. var sig = SoundIn.ar(0); // sig is here 1-channel sig = UpSample.ar(sig); // now it is 4-channel sig = MyDistortion.ar(sig); // process the 4-channels in parallel sig = DownSample.ar(sig); // downsample to 1-channel In csound you need to be explicit about the different streams, but otherwise it would be straightforward to translate the code. cheers, Eduardo Moguillansky On Mon, May 25, 2015 at 11:23 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: You can do it in an UDO (with local ksmps = 1) |
| Date | 2015-05-25 11:16 |
| From | Victor Lazzarini |
| Subject | Re: oversampling |
That might be possible, but for now, it is still possible to do it "by hand". Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland > On 25 May 2015, at 11:09, Joel Ross |
| Date | 2015-05-25 15:46 |
| From | Steven Yi |
| Subject | Re: oversampling |
Hi Joel, I've thought about a generic way to do oversampling as well but wasn't quite sure about how to make the system generic enough for choosing/implementing how to upsample/downsample. As Victor mentioned, it's entirely possible to implement oversampling in ORC code. The nice thing would be if you could do something like: setksmps(1) setoversampling(4) For oversampling, because opcodes often take into account sr during init phase, one would have to update the system so that opcodes read sr from a "local sr", in the same way that ksmps is read from "local ksmps". I'd have to check, but it might be the case that it's already being read from local sr. Also, I think a macro is used for most opcodes reading sr such that one change to the macro would update all the opcodes. One a local sr is available, the other part would be the upsampling of inputs and downsampling of outputs. That would have to wrap the existing code to run instruments/UDO's. The code is in Engine/csound.c for instruments; check out kperf_nodebug() and kperf_debug(). For UDO's and subinstruments, check out Engine/insert.c at the useropcd1(), useropcd2(), and subinstr() functions. You'll see code related to ids and pds (or IDS or PDS), which are the init-time and perf-time chains of opcodes that get walked in a while-loop. That also brings up one other thing, which would be the need for local spin and spout. These are the places where audio in and audio out are read from/written to. We would need those to be local, so that the local buffer could be x times larger in size for the oversampling. I think that covers the things necessary. If you look into it and have further questions, please feel free to ask. As some of this gets into internal details, maybe further questions would be better on the developer mailing list. Cheers! steven On Mon, May 25, 2015 at 6:09 AM, Joel Ross |
| Date | 2015-05-25 20:29 |
| From | Oeyvind Brandtsegg |
| Subject | Re: oversampling |
Excellent, thanks for all the replies. 2015-05-25 16:46 GMT+02:00 Steven Yi |