Csound Csound-dev Csound-tekno Search About

Subharmonic synthesis, again (again?)

Date1999-06-25 07:12
FromPaul Winkler
SubjectSubharmonic synthesis, again (again?)
Hi folks,

I hope this isn't a repeat. (I didn't see it on this end; maybe because
I was accidentally sending messages with my old (defunct + unsubscribed)
return address?)

Recently someone asked about subharmonic synthesis, and several replies
mentioned the analog "flip-flop" circuit such as is found in guitar
"octave" pedals. I have an orc/sco that does this reasonably well and I
thought it might be of interest. I would have sent this sooner, but I
just moved and only set up the linux box (with all my csound stuff on
it) yesterday...

It behaves somewhat like the above-mentioned guitar stomp boxes: it
tracks the pitch of monophonic sound sources pretty well, but more
complex inputs yield strange results.

This orc was the first time I felt like I really had a handle on using
csound's if/goto flow control.  It takes a while for us young'uns to get
the hang of this archaic syntax where things are sort of falling
downstairs in a controlled fashion ... it works, it's just a weird way
to think!

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;copyright 1998 Paul M. Winkler, zarmzarm@hotmail.com
;****++++
;**** Last modified: Fri Jun 18 00:52:34 1999
;****----
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


	sr	=	44100
	kr	=	44100
	ksmps	=	1
	nchnls	=	2


instr 1
        ; subharmonic synthesis
        ; version one -- downsampling
        ; Low ksmps (1 or 2) gives best-sounding results.
istraightgain = ampdb(p4)                       ; used as gains,
idown1gain = ampdb(p5)                          ; not amplitudes.
idown2gain =  ampdb(p6)                         ; e.g. if arg is
                                                ; 6, the gain is 2.
                                                ; If arg. is -6, 
                                                ;  gain is 0.5.
; first generate some sound
kcount init 0
ktest init 0
kamp expseg .001, 0.5, 1, p3 -1, 1, 0.5, .0001 
kpitch linseg 0.9, p3, 1.3
a1 diskin "beats+loops/longroove.aiff", kpitch
;  afilt1 tonex a1, 400, 4     ;  heavy pre-filtering.
afilt1 resonx a1, 150, 200, 2, 1 ; this could use some tweaking
k1 downsamp afilt1

    ; Now process channel 1.
            ; This works by counting upward zero crossings in the 
            ;   waveform.
            ;  The count is used to set the output to either 1 or -1
            ; so we get a square waves at half (and a quarter) of
            ; the input frequency.
kdetect trigger k1, 0, 0 ; notice only upward zero-crossings
if kdetect == 0 goto next1
kcount = kcount + 1
ktest = kcount % 4
next1:
if ktest != 1 goto next2
    adown1 = 1
    adown2 = 1
    goto output
next2:
    if ktest != 2 goto next3
    adown1 = -1
    adown2 = 1
    goto output
next3:
    if ktest !=3 goto next4
    adown1 = 1
    adown2 = -1
    goto output
next4:
    adown1 = -1
    adown2 = -1
output:
  ; Choose your filter...
;  adown1 tone adown1, kfreq * .04     ; takes out some high end, but
               ; still synth-sounding... looks like a triangle wave.
;  adown1 rezzy adown1, 40, 30      ; pretty smooth but asymmetrical.
;  adown1 tonex adown1, 40, 7         ; distorts with some inputs.
adown1 resonx adown1, 35, 60, 4       ; Very nice, near-sine output.
adown2 resonx adown2, 30, 50, 4
; adown1 butterbp adown1, 30, 10      ; output looks like a triangle
wave!
adown1 dcblock adown1
adown2 dcblock adown2
adown1 balance adown1, afilt1   ; Restore dynamics.
adown2 balance adown2, afilt1   ; It's important to use filtered signal!
a1 = a1 * istraightgain
outs a1 + (adown1 * idown1gain),  a1 + (adown2 * idown2gain)
endin

;;;;;;;;; end of orc

;;;;;;;;;; start sco

f1 0 32768 10 1                          ; sine
;                       gains:  
;1      at      dur     straight down1  down2

i1      0       3.88   -12     -1     -10
i1      +       3.88   -95     4       4       




-------------------   paul winkler   --------------------
slinkP arts: music, sound, illustration, web design, etc.

zarmzarm@hotmail.com    http://members.tripod.com/~slinkP
=========================================================