[Csnd] Purpose of Tanh Function in Moogladder Source Code
Date | 2017-09-06 18:41 |
From | Emmett Palaima |
Subject | [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Hi, as part of my research on filter design I have been studying the source code for the moogladder opcode (moogladder_process, fast_tanh, TanH, lines 30-153) and was wondering what purpose passing part of the feedback loop through a tanh function is serving.
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
The signal is scaled down by thermal before being passed through the tanh (and scaled back afterwards by tune), which means that on a 0dbfs = 1 scale the tanh optimization given will always return the result return x * sign (the original value). I even tested this by implementing the code myself and putting a print statement inside the fast_tanh function, which was never called. What then is the purpose of including tanh? Is the opcode meant to function on another amplitude scale, and if so how does it account for users defining different amplitude scales? Thanks, Emmett |
Date | 2017-09-06 18:45 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
I'd guess the accounting for different 0dbfs values probably is the reason for it. Have you tested different amplitudes through your example? Originally csound was based on 16bit int amplitudes On 6 Sep 2017 6:41 p.m., "Emmett Palaima" <epalaima@berklee.edu> wrote:
|
Date | 2017-09-06 19:12 |
From | Emmett Palaima |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
That would make sense if the transfer function was built for a different amplitude scale. The max value of 32,767 time 0.000025 would be 0.819175, which at least makes a little bit of use of the transfer function. The coefficient THERMAL is commented as transistor thermal voltage, which suggests that tanh is used to approximate the behavior of an analog transistor. On Wed, Sep 6, 2017 at 1:45 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
|
Date | 2017-09-06 19:34 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
I haven't looked at the code. What's the 0.000025 from? Transistor huh? That's interesting, I suppose if you're dealing with positive and negative values higher than 1, a tanh function will produce something similar to transistor ons and offs with a rise and fall time. That's a pretty clever idea! On 6 Sep 2017 7:12 p.m., "Emmett Palaima" <epalaima@berklee.edu> wrote:
|
Date | 2017-09-06 19:49 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Tanh() is the non-linear waveshaper used to clip the signal in the filter. If you look in the manual, you will see the reference from where the design comes from. I wrote the original code, but John implemented the optimisations so if the question is related
to that, he should be able to answer them.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-06 20:36 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Ah right, tanh is used as a distortion function then. That makes sense On 6 Sep 2017 7:49 p.m., "Victor Lazzarini" <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2017-09-06 21:20 |
From | Emmett Palaima |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Since you wrote the code, perhaps you can clarify: what sort of amplitude range is the transfer function designed to work with? I was thinking it was supposed to work as a waveshaper / transfer function to simulate the clipping of analog transistors. The reason for my question stemmed from the fact that in a system where 0dbfs = 1 the transfer function does nothing. Thanks for your replies. On Wed, Sep 6, 2017 at 2:49 PM, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2017-09-06 21:37 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
The tanh() is supposed to simulate the clipping of the transistors. Can't recall the details, and I don't have the computer here,
but I'd say it works on a normalised range
-1 to 1. The code just follows the recipe in the paper, so you should read that reference.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-06 21:44 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Non-Linear Digital Implementation of the Moog Ladder Filter
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-06 21:57 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
and here is the first implementation using Csound code. The range of amplitudes for tanh() does not seem to be a consideration. Thinking about it, it never appeared to
matter; I guess if you are replacing tanh()
with table lookup or other optimised
code etc then it is probably important to find out.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-06 22:19 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Surely the amplitude range does realistically matter unless it's normalised first. If you're using a 16bit int range, you'll almost always be harshly clipping On 6 Sep 2017 9:57 p.m., "Victor Lazzarini" <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2017-09-06 22:47 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
You can check the paper, it makes no
mention as to what signal levels are
expected at the input, only that the
filter becomes linear for very small
input values (of course).
Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-06 23:22 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Fair enough. I guess the non linear effect is part of the deal anyway On 6 Sep 2017 10:47 p.m., "Victor Lazzarini" <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2017-09-08 06:43 |
From | Emmett Palaima |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
To be more precise, I am not asking what the amplitude level the filter expects, but rather, what system for describing amplitude the filter expects. As Peter has suggested this code may have been written to work with a system where 0dbfs = 32,767, since in a system where 0dbfs = 1.0 the transfer function will never do anything (since the maximum value passed into it is 0.000025 in that system, which is well below the threshold at which the tanh optimization is called). @Victor: That is what I was trying to ask you to clarify, but I now realize my wording was unclear. On Wed, Sep 6, 2017 at 6:22 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
|
Date | 2017-09-08 09:16 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Well, I did not consider the input ranges, just implemented the filter straight out of the paper (with calls to tanh(), no optimisation). ======================== Prof. 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 8 Sep 2017, at 06:43, Emmett Palaima |
Date | 2017-09-08 11:12 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Where in the source is moogladder? On 8 Sep 2017 9:16 a.m., "Victor Lazzarini" <Victor.Lazzarini@mu.ie> wrote: Well, I did not consider the input ranges, just implemented the filter straight out of the paper (with calls to tanh(), no optimisation). |
Date | 2017-09-08 11:34 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Opcodes/newfils.c ======================== Prof. 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 8 Sep 2017, at 11:12, Peter Burgess |
Date | 2017-09-08 20:37 |
From | Emmett Palaima |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Tried implementing the code on a 0dbfs = 1 scale without the THERMAL coefficient included in any of the calculations (can do this by setting THERMAL = 1). Definitely makes a difference in the sound, there is some nice harmonic distortion added to the system which was not there previously. Especially noticeable at higher resonance values, causing the resonance to sound much more "analog" (for lack of a better term). That brings up an interesting question with Csound opcodes. Does Csound make any adjustments to how things are processed based on the definition of 0dbfs? If not any sort of transfer function / distortion type opcode would work much differently for different 0dbfs values (which might be a good thing, since it adds the possibility for creative use). Thanks all for your responses. Has been very interesting to figure this stuff out. On Fri, Sep 8, 2017 at 6:34 AM, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote: Opcodes/newfils.c |
Date | 2017-09-08 20:39 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Depending on the opcode, it does.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-08 20:43 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
It might be possible to set thermal to
depend the 0dbfs value.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-08 21:20 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Or making a new moogladder with an optional threshold parameter might also be good. If none is given, 0dbfs is used. What dyou say emmett? On 8 Sep 2017 8:43 p.m., "Victor Lazzarini" <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2017-09-08 21:22 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
I've never really used moog ladder, I don't think I was ever satisfied with the sound. I wonder now if this was because I wasn't getting any tanh distortion? On 8 Sep 2017 9:20 p.m., "Peter Burgess" <pete.soundtechnician@gmail.com> wrote:
|
Date | 2017-09-08 21:33 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
Moogladder has been very popular and lots of people have used it.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-08 21:33 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
No, I don't think this should be a user parameter.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-09-08 21:53 |
From | Peter Burgess |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
I'm not doubting that, but I've never used anything but 0dbfs = 1. So I'd never have got any nice crunch out of it On 8 Sep 2017 9:34 p.m., "Victor Lazzarini" <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2017-09-08 23:58 |
From | Emmett Palaima |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
I actually like the original sound of moogladder as well. The reason I was studying it is because it's my go-to whenever I need a resonant lowpass filter in something that I'm making. If this were a feature that got added in I think it would be as a moogladder2 or something, but the original version is still great in my opinion. On Fri, Sep 8, 2017 at 4:53 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
|
Date | 2017-09-18 22:42 |
From | Roger Kelly |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
The moogladder sounds the MOST like my Voyager's Filters. Really love it. It can eat a lot of CPU on a Raspberry Pi. Any thoughts on any optimizations. On Fri, Sep 8, 2017 at 4:58 PM, Emmett Palaima <epalaima@berklee.edu> wrote:
|
Date | 2017-09-18 23:03 |
From | Anton Kholomiov |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
There is an optimized version of moogladder2 where tanh is substituted with slight variation, https://csound.github.io/docs/manual/moogladder2.html 2017-09-19 0:42 GMT+03:00 Roger Kelly <loraxman+csound@gmail.com>:
|
Date | 2017-09-19 06:06 |
From | Emmett Palaima |
Subject | Re: [Csnd] Purpose of Tanh Function in Moogladder Source Code |
One could probably create a further optimization of moogladder2 by cutting out THERMAL and TanH entirely, since, as I discovered, the TanH function doesn't actually do anything to the signal when 0dfs = 1. This would save several conditional statements and multiplies, as well as a divide in the coefficient calculation. Might add up to a noticeable decrease in load given the oversampling. |