//tanh(x) = x/(1+x²/(3+x²/(5+x²/(... //Define the needed Gain network. 5 => int depth; //How big the resulting network will be. Gain input; Gain output; Gain squared; squared.op(3); //Set operation to multiply Gain square_dummy => squared; input => square_dummy; input => squared; Step odd_numbers[depth]; Gain sum[depth]; Gain divider[depth]; make_tanh(); //Connect everything to get Gauss's continued fraction for the hyperbolic tangent. //Test it: SinOsc s => input; output => dac; 0.0 => float x; while(x < 5.0){ //at depth = 5 the ouput follows tanh quite closely up to amplitudes 5.0, then it starts to drop. Increase deth if you need more than that. x => s.gain; x + 0.01 => x; 10::ms => now; } //---Functions--- fun void make_tanh(){ for(0 => int i; i < depth; i++){ divider[i].op(4); }//Set operation to divide; input => divider[0]; for(0 => int i; i < depth - 1; i++){ 2*i+1 => odd_numbers[i].next; squared => divider[i+1] => sum[i]; odd_numbers[i] => sum[i] => divider[i]; } depth*2-1 => odd_numbers[depth-1].next; squared => sum[depth-1]; odd_numbers[depth-1] => sum[depth-1] => divider[depth -1]; divider[0] => output; }