mandel

mandel — Mandelbrot set

Description

Returns the number of iterations corresponding to a given point of complex plane by applying the Mandelbrot set formula.

Syntax

kiter, koutrig mandel  ktrig, kx, ky, kmaxIter

Performance

kiter - number of iterations

koutrig - output trigger signal

ktrig - input trigger signal

kx, ky - coordinates of a given point belonging to the complex plane

kmaxIter - maximum iterations allowed

mandel is an opcode that allows the use of the Mandelbrot set formula to generate an output that can be applied to any musical (or non-musical) parameter. It has two output arguments: kiter, that contains the iteration number of a given point, and koutrig, that generates a trigger 'bang' each time kiter changes. A new number of iterations is evaluated only when ktrig is set to a non-zero value. The coordinates of the complex plane are set in kx and ky, while kmaxIter contains the maximum number of iterations. Output values, which are integer numbers, can be mapped in any sorts of ways by the composer.

Examples

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

Example 571. Example of the mandel 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     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o mandel.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; By Stefano Cucchi 2021

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

instr 1     ; FM instrument

ksig oscil 1, 4                                 ; create a trigger signal
ktrig trigger ksig, 0, 2

kx linseg p8, p3, p9                            ; in the range -1 1
ky linseg p6, p3, p7                            ; in the range -1 1
kmaxIter linseg p4, p3*0.5, p5, p3*0.5, p4

kiter, koutrig mandel  ktrig, kx, ky, kmaxIter
printks2 "maximum iterations =  %d\n", kiter    ; show them

asig foscili 0.3, 1, 440, kiter, 10, 1          ; use number of iterations to modulate
outs asig, asig

endin

instr 2     ; grain instrument

ksig oscil 1, 100                               ; create a trigger signal
ktrig trigger ksig, 0, 2

kx linseg p8, p3, p9                            ; in the range -1 1
ky linseg p6, p3, p7                            ; in the range -1 1
kmaxIter linseg p4, p3*0.5, p5, p3*0.5, p4

kiter, koutrig mandel  ktrig, kx, ky, kmaxIter
printks2 "maximum iterations =  %d\n", kiter    ; show them

insnd   = 1 
ibasfrq = 44100 / ftlen(insnd)                  ; use original sample rate of insnd file 

kamp   = .8
kpitch = 1
kdens  = kiter
kaoff  line 0, p3, .1
kpoff  = 0
kgdur  =.002
imaxgdur =  .5 

asig  grain kamp, kpitch, kdens, kaoff, kpoff, kgdur, insnd, 1, imaxgdur, 0.0 
outs asig, asig

endin

</CsInstruments>
<CsScore>
f 1 0 4096 10 1 1 0 1   ; sinoid wave (instr 1)
f5  0 512  20 2         ; Hanning window (instr 2)

;           start   end     X1  X2  Y1  Y2 
i 1 0 10    110     2000    -1  1   -1  1

;           start   end     X1  X2  Y1  Y2    
i 2 11 10   120      1       0  1   -1  0     
e
</CsScore>
</CsoundSynthesizer>


Two musical examples featuring the mandel opcode: Mandel_Daughtrey.csd by Scott Daughtrey, and Mandel_Gogins.csd by Michael Gogins.

See Also

Models and Emulations

Credits

Written by Gabriel Maldonado.

New in Csound 5 (Previously available only on CsoundAV)