Csound Csound-dev Csound-tekno Search About

[Csnd] Hans Mikelson distortion, slope based delay

Date2012-05-24 14:31
FromOeyvind Brandtsegg
Subject[Csnd] Hans Mikelson distortion, slope based delay
Hi list,

I'm working on a lesson on distortion effects, where I'd like to include the delay based distortion effect introduced (afaik) by Hans Mikelson here:
http://www.csounds.com/mikelson/index.html#multifx
I think this was written in 1999 or so ? (Hans if you're here, please comment)

What I want to ask is to get confirmation that my changes to the code has not significantly altered the processing result.
I've tried to make the code cleaner, adapt it to a 0dbfs=1 standard, and also secure that the delay time never goes below zero (regardless of the values used for duty and slope).

Mikelson's distortion includes both soft clipping and the slope based delay stage, I've also tried to isolate the slope based delay stage.
The essential line of code is:

(Mikelson version)
    aout    deltapi (2-iduty*asign)/1500 + islope*(asign-aold)/300
(My version)
    a2         deltap3 ((1-a1)*iduty) + ((a1-an) * islope) + (0.5*iduty) + islope + 0.001

Now, this is taken out of context, and not directly comparable, as the Mikelson version also uses a clipping stage.
I have phase differences in the output between the two different version of the code, but the spectrum looks and sounds (in all significant detail) equal (clipping stage omitted).
Hans, if you're here, perhaps you can comment?
And anyone else too of course, all suggestions and objections welcome.

Code for the complete instruments pasted below

Oeyvind

***
;---------------------------------------------------------------------------
; Distortion 2 (Mikelson)
;---------------------------------------------------------------------------
         instr   8

igaini   =       p4          ; Pre gain
igainf   =       p5          ; Post gain
iduty    =       p6          ; Duty cycle offset
islope   =       p7          ; Slope offset
izin     =       p8          ; Input channel
izout    =       p9          ; Output channel
asign    init    0           ; Delayed signal

kamp     linseg  0, .002, 1, p3-.004, 1, .002, 0   ; Declick

asig     zar     izin                  ; Read input channel
aold     =       asign                 ; Save the last signal
asign    =       igaini*asig/20000     ; Normalize the signal
aclip    =       (8*asign-4)/(1+exp(30*asign-15))/(1+exp(1-asign))+.8
aclip    =       igainf*aclip*30000    ; Re-amplify the signal

atemp    delayr  .1                    ; Amplitude and slope based delay
aout     deltapi (2-iduty*asign)/1500 + islope*(asign-aold)/300
         delayw  aclip

         zaw     aout, izout           ; Write to output channel

         endin


;***************************************************
; slope based delay distortion (Brandtsegg, after Mikelson)
;***************************************************
    instr    8

    islope        = p5        ; amount of slope influence on delay time
    iduty        = p6        ; amount of duty influence on delay time

    a1        = (read from chn or generate audio signal)

; distortion

    an1        delay1    a1    ; delay audio by 1 sample
    aslope        = a1 - an1    ; find difference between samples (= slope of the waveform)

    ; delay time offset to avoid delay time less than zero
    ioffset        = (0.5*iduty) + islope + 0.001

    ; delay line processing
    atemp        delayr  1     
    a2             deltap3 ((1-a1)*iduty) + (aslope * islope) + ioffset
            delayw      a1

; audio out
    out        a2
    endin
;***************************************************