Csound Csound-dev Csound-tekno Search About

Re: distortion

Date1998-03-16 09:19
From=cw4t7abs
SubjectRe: distortion
>Ola everyone

engl!sch plz.

            o
>Is there a way to simulate distortion using csound? My knowledge on the
>innings of distortion are very limited, but I believe it comes from boosting
>a signals level until it clips.

preffrd m th d 4 d!stort!ng akk.+.m.!kc. m9nd konta!nrz.

         e

http://www.dwfearn.com/tvst1.htm

This inspired me to try and simulate it in Csound. Unfortunately it isn't
too great. Does anyone have any examples of simulated distortion?

; Orchestra begins here.

sr=44100
kr=4410
ksmps=10
nchnls=1

gasig init 0

; Pluck
instr 2

iamp =  p4*4
ifqc =  cpspch(p5)
kamp linseg 0, .002, p4, p3-.004, p4, .002, 0

asin1 pluck kamp, ifqc, ifqc, p6, p7
gasig = gasig + asin1

endin

; Tube Amp
instr 10

asig    init 0
kamp    linseg 0, .002, 1, p3-.004, 1, .002, 0
igaini =        p4
igainf =        p5
iduty = p6
islope =        p7

aold    =       asig
asig    =       igaini*gasig/40000 ; Distortion effect using waveshaping.
aclip tablei asig,5,1,.5        ; A lazy "S" curve, use table 6 for
increased
aclip = igainf*aclip*10000 ; distortion.

; Tube Amplifiers show a shifted duty cycle which I try to emulate with ; a
delay line. The slope bit is just something goofy I thought I would add.
atemp delayr .1
adel1 deltapi (1-iduty*asig)/3000 + (1+islope*(asig-aold))/3000
delayw aclip

out adel1*kamp

gasig = 0

endin


; Score starts here

; Sine Wave
f1 0 8192 10 1
; Triangle Wave
f2 0 8192 7 -1 4096 1 4096 -1

; Distortion Tables
;---------------------------------------------------------------------- ;
Heavy Distortion
;f5 0 8192 8 -.8 336 -.76 3000 -.7 1520 .7 3000 .76 336 .8 ; Slight Distortion
;f5 0 8192 8 -.8 336 -.78 800 -.7 5920 .7 800 .78 336 .8 ; Tube Distortion
; Light
;f5 0 8192 7 -.8 834 -.79 834 -.77 834 -.64 834 -.48 1520 .47 2000 .48 1336 .48
; Heavy
f5 0 8192 7 -.8 934 -.79 934 -.77 934 -.64 1034 -.48 520 .47 2300 .48 1536 .48

; Tube Amp
; Sta Dur PreGain PostGain DutyOffset SlopeShift i10 0 1.5 2    1       1
0

; Pluck
; Sta Dur Amp Fqc Func Meth
i2 0.0 1.6 4000 7.00 0  1
i2 0.2 1.4 3000 7.05 .  .
i2 0.4 1.2 2600 8.00 .  .
i2 0.6 1.0 3000 8.05 .  .
i2 0.8 0.8 4000 7.00 0  1
i2 1.0 0.6 3000 7.05 .  .
i2 1.2 0.4 2600 8.00 .  .
i2 1.4 0.2 3000 8.05 .  .


| | | \ |       /       Hans P. Mikelson
| __    | __/ | \ | hljmm@discover-net.net
|__ |__ |__ |__ \_ |__ http://discover-net.net/~hljmm/







;---------------------------------------------------------------------------
; A Multi-Effects System
;---------------------------------------------------------------------------
; 1. Simple Sine Wave
; 2. Pluck
; 3. Mono Sampler
; 4. Noise
; 10. Compressor
; 11. Tube Amp Distortion
; 15. Wah-Wah: This one sucks but the talk-box makes a pretty good Wah-Wah.
; 16. Talk-Box
; 20. Vibrato
; 21. Tremelo
; 22. Pitch Shifter
; 23. Panner
; 30. Stereo Flanger
; 31. Cross Feedback Flanger
; 35. Chorus
; 40. Delay
; 45. Reverb

;---------------------------------------------------------------------------
; Waveforms
;---------------------------------------------------------------------------
; Sine Wave
f1 0 8192 10 1
; Triangle Wave
f2 0 8192 7 -1 4096 1 4096 -1
; Sample
;f3 0 0 1 "harp.wav" 0 4 0
; Triangle Wave
f4 0 8192 7 0 4096 1 4096 0

; Distortion Tables
; Heavy Distortion
;f5 0 8192 8 -.8 336 -.76 3000 -.7 1520 .7 3000 .76 336 .8 ; Slight Distortion
;f5 0 8192 8 -.8 336 -.78 800 -.7 5920 .7 800 .78 336 .8 ; Tube Distortion
;f5 0 8192 7 -.8 834 -.79 834 -.77 834 -.64 834 -.48 1520 .47 2000 .48 1336 .48
f5 0 8192 7 -.8 934 -.79 934 -.77 934 -.64 1034 -.48 520 .47 2300 .48 1536 .48

; Wah-Wah
f7 0 1024 -7 100 512 10000 512 100

; Pitch Shift Window Shape (1/2 sine)
f8 0 16384 9 .5 1 0

; Formants
; Ahh/Oooh
f10 0 1024 -7 722 256 722 256 266 256 266 256 722 f11 0 1024 -7 1216 256
1216 256 1292 256 1292 256 1216 f12 0 1024 -7 2433 256 2433 256 2281 256
2281 256 2433 f13 0 1024 -7 3193 256 3193 256 3421 256 3421 256 3193

; Sample
; Sta Dur Amp   Fqc Table Begin End(n-1) OutCh
;i3 0 21.6 10000 440 3  0       474670 1

; Sine Wave
;i1 0 1 10000 1000
;i1 1 1 10000 500

; Pitch Shifter This has not been tested. ; Sta Dur Fqc Wave WinFun OutCh
;i19 0 1.6 2 3  8       1

; Noise
; Sta Dur Amp
;i4 0 4 5000

; Wah-Wah
; Sta Dur Frqc Table InChL InChR OutChL OutChR ;i15 0 1.6 2     7       2
2       3       3

; Vibrato
; Sta Dur Amp Fqc Table MaxDelay InChL InChR OutChL OutChR ;i20 0 2.5 1 5 1
3       1       1       2       2

; Tremelo
; Sta Dur Amp Fqc Table InChL InChR OutChL OutChR ;i21 0 2.5 .5 5 1     1
1       2       2

;---------------------------------------------------------------------------
; Plain Pluck
;---------------------------------------------------------------------------
; Sta Dur Amp Fqc Func Meth OutCh
i2 0.0 1.6 4000 7.00 0  1 1
i2 0.2 1.4 3000 7.05 .  . .
i2 0.4 1.2 2600 8.00 .  . .
i2 0.6 1.0 3000 8.05 .  . .
i2 0.8 0.8 4000 7.00 .  . .
i2 1.0 0.6 3000 7.05 .  . .
i2 1.2 0.4 2600 8.00 .  . .
i2 1.4 0.2 3000 8.05 .  . .

; Mixer
; Sta Dur Ch1 Gain Pan Ch2 Gain Pan Ch3 Gain Pan Ch4 Gain Pan i100 0 2 1 4
1 1 4   0 3 2   1 4     2 0

;---------------------------------------------------------------------------
; Pluck with Heavy Distortion
;---------------------------------------------------------------------------
i2 2.0 1.6 4000 7.00 0     1 1
i2 2.2 1.4 3000 7.05 .  . .
i2 2.4 1.2 2600 8.00 .  . .
i2 2.6 1.0 3000 8.05 .  . .
i2 2.8 0.8 4000 7.00 .  . .
i2 3.0 0.6 3000 7.05 .  . .
i2 3.2 0.4 2600 8.00 .  . .
i2 3.4 0.2 3000 8.05 .  . .

; Tube Amp
; Sta Dur PreGain PostGain DutyOffset SlopeShift InCh OutCh i11 2 1.6 2 1
1       1       1       2

; Mixer
; Sta Dur Ch1 Gain Pan Ch2 Gain Pan Ch3 Gain Pan Ch4 Gain Pan i100 2 2 2 1
1 2 1   0 3 2   1 4     2 0

;---------------------------------------------------------------------------
; Pluck with Distortion & Flanging
;---------------------------------------------------------------------------
i2 4.0 1.6 4000 7.00 0     1 1
i2 4.2 1.4 3000 7.05 .  . .
i2 4.4 1.2 2600 8.00 .  . .
i2 4.6 1.0 3000 8.05 .  . .
i2 4.8 0.8 4000 7.00 .  . .
i2 5.0 0.6 3000 7.05 .  . .
i2 5.2 0.4 2600 8.00 .  . .
i2 5.4 0.2 3000 8.05 .  . .

; Tube Amp
; Sta Dur PreGain PostGain DutyOffset SlopeShift InCh OutCh i11 4 1.6 2 1
1       1       1       2

; Flanger
; Sta Dur Rate Depth Wave Feedbk Mix DelayOff InCh OutChL OutChR
;       (1-40)
i30 4 1.61 .5   20      1       .8      1 10    2       3       4

; Mixer
; Sta Dur Ch1 Gain Pan Ch2 Gain Pan Ch3 Gain Pan Ch4 Gain Pan i100 4 2 3 .5
1 4 .5 0 3 0        1 4 0   0

;---------------------------------------------------------------------------
; Distortion & Chorus
;---------------------------------------------------------------------------
i2 6.0 1.6 4000 7.00 0     1 1
i2 6.2 1.4 3000 7.05 .  . .
i2 6.4 1.2 2600 8.00 .  . .
i2 6.6 1.0 3000 8.05 .  . .
i2 6.8 0.8 4000 7.00 .  . .
i2 7.0 0.6 3000 7.05 .  . .
i2 7.2 0.4 2600 8.00 .  . .
i2 7.4 0.2 3000 8.05 .  . .

; Tube Amp
; Sta Dur PreGain PostGain DutyOffset SlopeShift InCh OutCh i11 6 1.6 2 1
1       1       1       2

; Chorus
; Sta Dur Rate Depth Wave Mix DelayOff InCh OutChL OutChR ;     (.1-2)
i35 6 1.61 1    1       1       1 30    2       3       4

; Mixer
; Sta Dur Ch1 Gain Pan Ch2 Gain Pan Ch3 Gain Pan Ch4 Gain Pan i100 6 2 3 1
1 4 1   0 3 0   1 4 0   0

;---------------------------------------------------------------------------
; Distortion & Talk-Box
;---------------------------------------------------------------------------
i2 8.0 1.6 4000 7.07 0     1 1
i2 8.4 1.2 3000 7.00 .  . .
i2 8.8 .8 2600 9.05 .   . .
i2 9.2 .4 3000 9.00 .   . .

; Tube Amp
; Sta Dur PreGain PostGain DutyOffset SlopeShift InCh OutCh i11 8 1.6 2 1
1       1       1       2

; Talk Box
; Sta Dur InCh OutCh
i16 8 1.6 2     3

; Mixer
; Sta Dur Ch1 Gain Pan Ch2 Gain Pan Ch3 Gain Pan Ch4 Gain Pan i100 8 2 3 1
1 3 1   0 3 0   1 4 0   0

;---------------------------------------------------------------------------
; Digital Delay with Moderate Distortion
;---------------------------------------------------------------------------
i2 10.0 1.6 4000 7.07 0      1 1
i2 10.4 1.2 3000 7.00 . . .
i2 10.8 .8 2600 9.05 .  . .
i2 11.2 .4 3000 9.00 .  . .

; Tube Distortion
f5 10 8192 7 -.8 834 -.79 834 -.77 834 -.64 834 -.48 1520 .47 2000 .48 1336 .48

; Tube Amp
; Sta Dur PreGain PostGain DutyOffset SlopeShift InCh OutCh i11 10 1.6 2
1       .2      0       1       2

; Delay
; Sta Dur Time Feedbk InChL InChR OutChL OutChR i40 10 3 .2 .5  2       2
3       3

; Mixer
; Sta Dur Ch1 Gain Pan Ch2 Gain Pan Ch3 Gain Pan Ch4 Gain Pan i100 10 3 2 1
1 2 1   0 3 1   1 3 1   0

;---------------------------------------------------------------------------
; Compression & Auto Pan
;---------------------------------------------------------------------------
i2 13.0 1.6 4000 7.07 0    1 1
i2 13.4 1.2 3000 7.00 . . .
i2 13.8 .8 2600 9.05 .  . .
i2 14.2 .4 3000 9.00 .  . .

; Compression Curve
f6 13 1025 7 1 256 1 256 .1 256 .1 257 .1

; Compressor
; Sta Dur RespFrqc Table PreGain PostGain InCh OutCh i10 13 1.6 100     6
1       20      1       2

; Tube Distortion
f5 13 8192 7 -.8 834 -.79 834 -.77 834 -.64 834 -.48 1520 .47 2000 .48 1336 .48

; Tube Amp
; Sta Dur PreGain PostGain DutyOffset SlopeShift InCh OutCh i11 13 1.6 2
1       .2      0       2       3

; Panner
; Sta Dur Amp Fqc Table InCh OutChL OutChR i23 13 1.6 1 5 1     3       4
5

; Reverb
; Sta Dur gain %orig inputdur atk InCh1 InCh2 OutChL OutChR i45 13 3 1 .5
1.61  .2 4    5       6       7

; Mixer
; Sta Dur Ch1 Gain Pan Ch2 Gain Pan Ch3 Gain Pan Ch4 Gain Pan i100 13 3 4 1
1 5 1   0 6 1   1 7 1   0


| | | \ |       /       Hans P. Mikelson
| __    | __/ | \ | hljmm@discover-net.net
|__ |__ |__ |__ \_ |__ http://discover-net.net/~hljmm/