distort1

distort1 — Modified hyperbolic tangent distortion.

Description

Implementation of modified hyperbolic tangent distortion. distort1 can be used to generate wave shaping distortion based on a modification of the tanh function.


         exp(asig * (shape1 + pregain)) - exp(asig * (shape2 - pregain))
  aout = ---------------------------------------------------------------
         exp(asig * pregain)            + exp(-asig * pregain)
      

Syntax

ares distort1 asig, kpregain, kpostgain, kshape1, kshape2[, imode]

Initialization

imode (Csound version 5.00 and later only; optional, defaults to 0) -- scales kpregain, kpostgain, kshape1, and kshape2 for use with audio signals in the range -32768 to 32768 (imode=0), -0dbfs to 0dbfs (imode=1), or disables scaling of kpregain and kpostgain and scales kshape1 by kpregain and kshape2 by -kpregain (imode=2).

Performance

asig -- is the input signal.

kpregain -- determines the amount of gain applied to the signal before waveshaping. A value of 1 gives slight distortion.

kpostgain -- determines the amount of gain applied to the signal after waveshaping.

kshape1 -- determines the shape of the positive part of the curve. A value of 0 gives a flat clip, small positive values give sloped shaping.

kshape2 -- determines the shape of the negative part of the curve.

Examples

Here is an example of the distort1 opcode. It uses the file distort1.csd.

Example 242. Example of the distort1 opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o distort1.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


gadist init 0
  
instr 1
  iamp = p4
  ifqc = cpspch(p5)
  asig pluck iamp, ifqc, ifqc, 0, 1
  gadist = gadist + asig
endin
  
instr 50
  kpre init p4
  kpost init p5
  kshap1 init p6
  kshap2 init p7
  aout distort1 gadist, kpre, kpost, kshap1, kshap2, 1

  outs aout, aout

  gadist = 0
endin


</CsInstruments>
<CsScore>

;   Sta  Dur  Amp    Pitch
i1  0.0  3.0  0.5  6.00
i1  0.5  2.5  0.5  7.00
i1  1.0  2.0  0.5  7.07
i1  1.5  1.5  0.5  8.00
  
;   Sta  Dur  PreGain PostGain Shape1 Shape2
i50 0    4      2       .5       0      0
e

</CsScore>
</CsoundSynthesizer>


See also

Special Effects

Waveshaping

Credits

Author: Hans Mikelson
December 1998

New in Csound version 3.50