[Csnd] Tuning issues with the various pluck opcodes
Date | 2022-08-25 18:35 |
From | Aaron Krister Johnson |
Subject | [Csnd] Tuning issues with the various pluck opcodes |
HI all - The various opcodes in Csound are really a great way to get a nice organic natural-sounding string instrument, however, I have noticed that, at least when coupled with MIDI via `cpstmid`, playing certain octaves introduces an out-of-tune beating. I understand this can be an artifact of integer sample-length delay lines, but I also though all these implementations were supposedly fine-tuned to have fractional-delay length interpolation, and/or allpass filters and/or lagrangian interpolation so that tuning remains exact and solid. Am I mistaken in that assumption? Can one fix these opcodes, if so, after the fact, with some kind of external allpass filtering?(I will verify that the tuning isn't at least partially because the output of cpstmid is inaccurate later today) |
Date | 2022-08-25 18:45 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
I think pluck is well in tune. It doesn't use a tuning filter but interpolation. As far as I can remember, it tunes ok.
I guess a simple test is to use a sine wave oscillator at the same time to check for beats.
Prof. Victor Lazzarini
Maynooth University
Ireland
On 25 Aug 2022, at 18:36, Aaron Krister Johnson <akjmicro@gmail.com> wrote:
|
Date | 2022-08-25 18:54 |
From | Aaron Krister Johnson |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
Right, good suggestion Victor; will try later. And yes, I do remember on other occasions feeling like the only one that gave me decent tuning was `pluck`. So, I wonder if there's some peculiarity with my particular patch on Bela. Briefly, I have `pluck` going through `tone`, then `hilbert` for width and `reverbsc` gives room ambience.On Thu, Aug 25, 2022 at 10:45 AM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2022-08-25 18:58 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
I have an instrument that tunes well and does not need ksmps=1. I can post it here when I get to a computer.
Prof. Victor Lazzarini
Maynooth University
Ireland
On 25 Aug 2022, at 18:55, Aaron Krister Johnson <akjmicro@gmail.com> wrote:
|
Date | 2022-08-25 21:53 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
Here's the instrument, it can be run with ksmps .> 1. I realised an interpolated tap can tune just as
well as the allpass filter (although it's not flat but OK in my opinion), and you can bend the pitch without any
artefacts (which is a problem with the allpass).
instr 1
iamp = p4 // amp
ifo = p5 // fund
idec = p6 // dec (dB/sec)
ipos = p7 // pluck pos
ipk = (1-p8)/2 // pickup pos (0=bridge)
idel = 1/ifo - 1/(2*sr)
iG = pow(10, -idec/(20*ifo))
iA = cos($M_PI*ifo/sr)
ig = iG / iA
kcnt timeinsts
if kcnt < idel then
ip = 0.5*ipos
aexc linseg 0,idel*ip,iamp,idel*(0.5-ip),
0,idel*(0.5+ip),-iamp,(1-ip),0
else
aexc = 0
endif
adp delayr 1/20
aks deltap3 idel
apk1 deltap3 ipk*idel
apk2 deltap3 (1-ipk)*idel
delayw aexc + ig*(aks + delay1(aks))*0.5
out (apk1+apk2)*0.5
endin
|
Date | 2022-08-26 16:49 |
From | Aaron Krister Johnson |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
Victor, Thanks for the help.
In any event, I appreciate the code share! Thanks again. Always open to hearing about other suggested tweaks to explore. On Bela, I'm also messing about with raw C++ generated from Faust, but that is bringing its own set of platform/template problems, since Faust can seem a bit promising yet chaotic in that regard. Cheers, On Thu, Aug 25, 2022 at 1:54 PM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2022-08-26 18:22 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
There are two things I can say 1) you can try to replace the excitation with a noise generator, which will make it brighter 2) the aliasing may be to do with the triangle excitation, the cos() code would not influence aliasing, all it does is control decay by calculating a gain scaling factor. Maybe the older code had an LP somewhere in the triangle excitation. The other code used an allpass to tune and it’s possible that this code has less highs because the tuning is not guaranteed to be allpass. A solution I think to have the older code without the ksmps = 1 is to use the “biquad” opcode and implement the allpass without having to do 1-sample feedback in the code. I’ll see if I can try that. ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 26 Aug 2022, at 16:49, Aaron Krister Johnson |
Date | 2022-08-26 18:40 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
Attachments | test.aif test1.aif |
I just run the code here with
i1 0 5 0.9 900 12 0.1 0 and i1 0 5 0.9 900 12 0.1 0.2 but I could not detect any aliasing. See the files attached. ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 26 Aug 2022, at 16:49, Aaron Krister Johnson <akjmicro@GMAIL.COM> wrote: > > Victor, > > Thanks for the help. > > I formatted the code and ran it. I was impressed that it was well-tuned, for my initial explorations. There are two things, however for my use case: > > • The overall color was "duller"; I would need the "harpsichord-like ping" with lots of high partials, and would want to filter myself with another opcode as need be (like `tone` or `biquad`). > This might be pluck-position related, but I wasn't able, in the small time I tried, to get it much brighter, alas. Years ago, though, I hacked at your instrument that was essentially an UDO > where `ksmps = 1`, and used that as the basis for a good generalized karplus instrument that _did_ have good brightness. I don't remember what I did, but I do remember that that > instrument also had more a nylon-string/electric-piano sound, too. You had used it to demo "Catharine of Aragon" by Rick Wakeman, remember? In any event, I'd need to study this > new iteration further to grok what could be done to brighten it up. > • This instrument started aliasing somewhere between 512 hz and 1024 hz -- really badly so...I suspect it has to do with the subtle maths to transform pitch to delay line length involving $M_PI > and such, but not sure. > > In any event, I appreciate the code share! Thanks again. Always open to hearing about other suggested tweaks to explore. On Bela, I'm also messing about with raw C++ generated from Faust, > but that is bringing its own set of platform/template problems, since Faust can seem a bit promising yet chaotic in that regard. > > Cheers, > > > Aaron Krister Johnson > Music, etc.: > http://www.untwelve.org > https://www.youtube.com/channel/UC_utjGYbSizWE0dNyr0Vdmg > https://soundcloud.com/aaron-krister-johnson > https://soundcloud.com/filtercreed > https://aaronkristerjohnson.bandcamp.com/ > Code: > https://github.com/akjmicro > > > On Thu, Aug 25, 2022 at 1:54 PM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote: > Here's the instrument, it can be run with ksmps .> 1. I realised an interpolated tap can tune just as > well as the allpass filter (although it's not flat but OK in my opinion), and you can bend the pitch without any > artefacts (which is a problem with the allpass). > > instr 1 > iamp = p4 // amp > ifo = p5 // fund > idec = p6 // dec (dB/sec) > ipos = p7 // pluck pos > ipk = (1-p8)/2 // pickup pos (0=bridge) > idel = 1/ifo - 1/(2*sr) > iG = pow(10, -idec/(20*ifo)) > iA = cos($M_PI*ifo/sr) > ig = iG / iA > kcnt timeinsts > if kcnt < idel then > ip = 0.5*ipos > aexc linseg 0,idel*ip,iamp,idel*(0.5-ip), > 0,idel*(0.5+ip),-iamp,(1-ip),0 > else > aexc = 0 > endif > > adp delayr 1/20 > aks deltap3 idel > apk1 deltap3 ipk*idel > apk2 deltap3 (1-ipk)*idel > delayw aexc + ig*(aks + delay1(aks))*0.5 > out (apk1+apk2)*0.5 > endin > > > > >> On 25 Aug 2022, at 18:58, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote: >> >> I have an instrument that tunes well and does not need ksmps=1. I can post it here when I get to a computer. >> >> Prof. Victor Lazzarini >> Maynooth University >> Ireland >> >>> On 25 Aug 2022, at 18:55, Aaron Krister Johnson <akjmicro@gmail.com> wrote: >>> >>> >>> Right, good suggestion Victor; will try later. >>> >>> And yes, I do remember on other occasions feeling like the only one that gave me decent tuning was `pluck`. So, I wonder if there's some peculiarity with my particular patch on Bela. Briefly, I have `pluck` going through `tone`, then `hilbert` for width and `reverbsc` gives room ambience. >>> >>> But, what about the other plucky-opcodes? Are they supposed to be solid in tuning? If not, if we like the sound of them, or the configurability of them, are there workarounds to the tuning? >>> >>> I remember running some UDO-like code of yours that did work better, and was solidly tuned (I hacked it a bit and used it on a piece of mine called "For Juhani")...however, the gotcha there was it also only worked where `ksmps = 1`... >>> >>> Aaron Krister Johnson >>> Music, etc.: >>> http://www.untwelve.org >>> https://www.youtube.com/channel/UC_utjGYbSizWE0dNyr0Vdmg >>> https://soundcloud.com/aaron-krister-johnson >>> https://soundcloud.com/filtercreed >>> https://aaronkristerjohnson.bandcamp.com/ >>> Code: >>> https://github.com/akjmicro >>> >>> >>> On Thu, Aug 25, 2022 at 10:45 AM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote: >>> I think pluck is well in tune. It doesn't use a tuning filter but interpolation. As far as I can remember, it tunes ok. >>> >>> I guess a simple test is to use a sine wave oscillator at the same time to check for beats. >>> >>> Prof. Victor Lazzarini >>> Maynooth University >>> Ireland >>> >>>> On 25 Aug 2022, at 18:36, Aaron Krister Johnson <akjmicro@gmail.com> wrote: >>>> >>>> >>>> WARNING This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe. >>>> HI all - >>>> >>>> The various opcodes in Csound are really a great way to get a nice organic natural-sounding string instrument, however, I have noticed that, at least when coupled with MIDI via `cpstmid`, playing certain octaves introduces an out-of-tune beating. I understand this can be an artifact of integer sample-length delay lines, but I also though all these implementations were supposedly fine-tuned to have fractional-delay length interpolation, and/or allpass filters and/or lagrangian interpolation so that tuning remains exact and solid. Am I mistaken in that assumption? Can one fix these opcodes, if so, after the fact, with some kind of external allpass filtering? >>>> >>>> (I will verify that the tuning isn't at least partially because the output of cpstmid is inaccurate later today) >>>> >>>> What am I doing wrong? I so want to be able to use Csound for a certain project, but am pulling my hair out over these tuning issues, which kind of block me on musical utility. >>>> >>>> While I mention this, the source code for searching out all things plucky seems....all over the place. `pluck` itself doesn't live in `pluck.c` for example, but in one of the main `ugens*.c` files. There are other weird things I've noticed that make it hard to look at the source and figure things out. >>>> >>>> Thanks, >>>> >>>> Aaron Krister Johnson >>>> Music, etc.: >>>> http://www.untwelve.org >>>> https://www.youtube.com/channel/UC_utjGYbSizWE0dNyr0Vdmg >>>> https://soundcloud.com/aaron-krister-johnson >>>> https://soundcloud.com/filtercreed >>>> https://aaronkristerjohnson.bandcamp.com/ >>>> Code: >>>> https://github.com/akjmicro >>>> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here >>> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here >>> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here >> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here > > Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here > Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2022-08-26 19:24 |
From | ST Music |
Subject | Re: [Csnd] Tuning issues with the various pluck opcodes |
Attachments | Screenshot_20220826-125651.png |
While not Csound related, Caustic 3 has a decent implementation of the KS model. Every control on the synth is also easily automated with great control in both pattern and song modes as well as via midi. Caustic has full midi support as well as the ability to import midi files. It is suprisingly free for the desktop versions (mobile versions require an extremely cheap key). It is apparantly functional on Linux as well although I don't know if that includes midi support, though there is a forum for such questions. The full sdk is available on github but I don't know if that includes the KSsynth. On Thu, Aug 25, 2022, 1:36 PM Aaron Krister Johnson, <akjmicro@gmail.com> wrote:
|
Date | 2022-08-26 21:10 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Tuning issues with the various pluck opcodes |
I had a look and modified the old code with an allpass to use filter2 and avoid having to set ksmps=1, and the code below does that, being equivalent to the one with ksmps=1 but more efficient. To my ears it doesn’t sound that much different from the one with interpolation. instr 1 /* now we combine the modern waveguide model with the ideas developed with the KS model */ ipi = -4*taninv(-1) iamp = p4 ifun = p5 idec = 12 ipkpos = 0.5 /*0.5 = bridge*/ ipos = 0.01 idts = sr/ifun /* total delay time (samples) */ idtt = int(sr/ifun) /* truncated delay time */ idel = idts/sr /* delay time (secs) */ ifac init 1 /* decay shortening factor (fdb gain) */ is init 0.5 /* loss filter coefficient */ igf pow 10, -idec/(20*ifun) /* gain required for a certain decay */ ig = cos(ipi*ifun/sr) /* unitary gain with s=0.5 */ if igf > ig igoto stretch /* if decay needs lengthening */ ifac = igf/ig /* if decay needs shortening */ goto continue stretch: /* this is the LP coefficient calculation to provide the required decay stretch */ icosfun = cos(2*ipi*ifun/sr) ia = 2 - 2*icosfun ib = 2*icosfun - 2 ic = 1 - igf*igf id = sqrt(ib*ib - 4*ia*ic) is1 = (-ib + id)/(ia*2) is2 = (-ib - id)/(ia*2) is = (is1 < is2 ? is1 : is2) continue: idtt = ((idtt+is) > (idts) ? idtt - 1: idtt) ifd = (idts - (idtt + is)) /* fractional delay */ icoef = (1-ifd)/(1+ifd) /* allpass coefficient */ kcount line 0, p3, p3 /* time counter */ if kcount > idel kgoto wguide /* this is the string initial state, based on a ideal triangle shape filtered by a gentle lowpass */ awvr linseg 0, ipos*idel/2, -iamp, (1-ipos)*idel, iamp, ipos*idel/2,0,1,0 aexcr = (awvr+delay1(awvr))*0.5 wguide: adump delayr 1 adel deltapn idtt aflt = (adel*(1-is) + delay1(adel)*is)*ifac alps filter2 aflt,1,1,icoef,1,icoef ipkpr = (1-ipkpos)*idtt ipkpl = ipkpos*idtt apkupr deltapn ipkpr /* right-going wave pickup */ apkupl deltapn ipkpl /* left-going wave pickup */ delayw aflt+aexcr aout dcblock (apkupr+apkupl)*0.25 out aout endin ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 26 Aug 2022, at 16:49, Aaron Krister Johnson |