<instrument type='blue.orchestra.BlueSynthBuilder' editEnabled='true'>
  <name>Lorenz7</name>
  <comment>==============================================================================================================
==============================================================================================================


	LORENZ TIME SERIES
	Ignasi ?lvarez Garriga 1998
	rev. 2005


==============================================================================================================
        NOTE: this instrument&apos;s sound is heavilly influenced by the project&apos;s krate (ksmps). Should be set to
        1, but feel free to experiment.
==============================================================================================================
	Uncomment the score i statements or use the score events on i/o !!
==============================================================================================================

		
		The original Lorenz system of equations is:

			Dx=A*(x-y)
			Dy=B*x-y-z*x
			Dz=x*y-C*z

		To build an audio instrument with it, we will use the Heun&apos;s integration method.
		
		A, B and C parameters will have realtime control using Csound i/o features.

		The Dt, or integration step, will have realtime control too.

		Due to sensibility to initial conditions, dense periodic points, and mixing properties,
		the Lorenz system reacts differently to N iterations with M size Dt, than to n*N iterations
		at size Dt/n (non-linearity). That is why we may need the &quot;zoom&quot; trick in adittion to variable length
		Dt steps. For convenience, the zoom parameter runs as an init P-parameter on .sco, as the loop algorithm,
		with its &apos;if&apos; operator, would otherwise not accept it. I am listening to any suggestions in this point ...

		As enough processing power is available, we are supposed to be able to run more than one instance
		of this instrument using score statements: for the case in wich we run it simultaneously, the
		p7, p8, and p9 score parameters will allow to introduce a &quot;chorus&quot; effect naturally derivating
		from sensibility to initial conditions property of the system.

		
		SCORE PARAMETERS

		p4 = zoom (time we run the integration loop for each audio sample / las veces que corremos el bucle de
				integraci?n para cada muestra de audio )
		p5=pan L ; Simple stereo image weighting / Sencillo balanceado de la im?gen est?reo
		p6=pan R
		p7 = diferential to kbparamA
		p8 = diferential to KbparamB
		p9 = diferential to KnparamC

		____________________________________________________________________________________________________


		El sistema de ecuaciones de Lorenz original es:

			Dx=A*(x-y)
			Dy=B*x-y-z*x
			Dz=x*y-C*z

		Para construir un instrumento de audio con ellas, utilizaremos la integraci?n por el m?todo de Heun.
		
		Los par?metros A, B y C tendr?n control a tiempo real utilizando las prestaciones de i/o de Csound.

		Tambi?n tendr? control a tiempo real el paso de integraci?n Dt.

		Debido sus propiedades de sensibilidad a las condiciones iniciales, densidad de puntos peri?dicos y mezcolanza,
		el sistema de Lorenz reacciona de modo distinto a N iteraciones con paso Dt de tama?o M, que a N*2 iteraciones
		con tama?o de paso Dt/2 (no-linealidad). Por esa raz?n se necesita el truco de &quot;zoom&quot; adem?s de la longitud
		variable en los pasos de Dt. Por conveniencia, el par?metro zoom es un P-par?metro incial en .sco, ya que el
		algoritmo del bucle, con su operador &apos;if&apos;, no lo aceptar?a de otro modo. Agradecer? sugerencias sobre este punto...

		A medida que dispongamos de suficiente capacidad de proceso, se supone que podremos ejecutar m?s de una
		instancia de este instrumento mediante las entradas en el score: para el caso en que se ejecuten simult?nneamente,
		los par?metros p7, p8 y p9 del score permiten introducir un efecto de &quot;chorus&quot; natural derivado de la propiedad
		de sensibilidad a las condiciones iniciales del sistema.


		PAR?METROS DE SCORE

		p4 = zoom ( numero de veces que corremos el bucle de integraci?n para cada muestra de audio )
		p5=pan L ; Sencillo balanceado de la im?gen est?reo
		p6=pan R
		p7 = diferential to kbparamA
		p8 = diferential to KbparamB
		p9 = diferential to KnparamC

		
		
==============================================================================================================
==============================================================================================================

</comment>
  <globalOrc>gitbdeclip_&lt;INSTR_ID&gt;	ftgen	0, 0, 16384, 7, 0, 16, 1, 16352, 1, 16, 0
</globalOrc>
  <globalSco/>
  <instrumentText>idur	=	abs(p3)
izoom	=	p4
iamp	=	p5
ipanL	=	sqrt(p6)
ipanR	=	sqrt(1-p6)
iparamA	=	p7
iparamB	=	p8
iparamC	=	p9

ka = &lt;paramA&gt;
kb = &lt;paramB&gt;
kc = &lt;paramC&gt;
kdt = &lt;dt&gt;
kdt2 = &lt;dt&gt;/2
kgainmaster = &lt;gain&gt;
kgainx = &lt;gainX&gt;
kgainy = &lt;gainY&gt;
kgainz = &lt;gainZ&gt;

ka = ka + iparamA
kb = kb + iparamB
kc = kc + iparamC

ky init 1
kz init 1
kx init 1

kxo init 0
kyo init 0
kzo init 0

kynew init 0
kxnew init 0
kznew init 0

kynewo init 0
kxnewo init 0
kznewo init 0

kcont init 0


loop:

;sistema d&apos;equacions

kxnew=ka*(ky-kx)
kynew=kb*kx-ky-kz*kx
kznew=kx*ky-kc*kz

kxo=kx
kyo=ky
kzo=kz

kxnewo=kxnew
kynewo=kynew
kznewo=kznew

kx=kxo+kxnewo*kdt
ky=kyo+kynewo*kdt
kz=kzo+kznewo*kdt

;sistema d&apos;equacions

kxnew=ka*(ky-kx)
kynew=kb*kx-ky-kz*kx
kznew=kx*ky-kc*kz

kx=kxo+kdt2*(kxnew+kxnewo)
ky=kyo+kdt2*(kynew+kynewo)
kz=kzo+kdt2*(kznew+kznewo)

kcont=kcont+1

if kcont!=izoom kgoto loop
kcont=0

araw = kgainmaster*(kx*kgainx+ky*kgainy+kz*kgainz)

; declip
aclip	oscil	iamp, 1/idur, gitbdeclip_&lt;INSTR_ID&gt;
asig	dcblock	araw * aclip

; Optionally output to a Display object:

;outvalue &quot;kdisplay&quot;, 0.5+kx/25
;outvalue &quot;kdisplax&quot;, 0.5-ky/25


blueMixerOut asig*ipanL,asig*ipanR
</instrumentText>
  <graphicInterface editEnabled='false'>
    <uniqueNameManager nameIndex='3' defaultPrefix='bsbObj'/>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>paramA</objectName>
      <x>26</x>
      <y>16</y>
      <automationAllowed>true</automationAllowed>
      <minimum>1.0</minimum>
      <maximum>10.0</maximum>
      <value>8.1415</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>33</x>
      <y>94</y>
      <label>Param A</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>paramB</objectName>
      <x>99</x>
      <y>17</y>
      <automationAllowed>true</automationAllowed>
      <minimum>14.0</minimum>
      <maximum>28.0</maximum>
      <value>26.6504</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>106</x>
      <y>95</y>
      <label>Param B</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>paramC</objectName>
      <x>171</x>
      <y>16</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.8165</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>178</x>
      <y>94</y>
      <label>Param C</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>dt</objectName>
      <x>305</x>
      <y>24</y>
      <automationAllowed>true</automationAllowed>
      <minimum>2.0E-4</minimum>
      <maximum>0.05</maximum>
      <value>0.028063</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>328</x>
      <y>102</y>
      <label>dT</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>gain</objectName>
      <x>303</x>
      <y>136</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>5000.0</maximum>
      <value>888.5</value>
      <knobWidth>60</knobWidth>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>305</x>
      <y>215</y>
      <label>Master Gain</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>gainX</objectName>
      <x>30</x>
      <y>143</y>
      <automationAllowed>true</automationAllowed>
      <minimum>-1.0</minimum>
      <maximum>1.0</maximum>
      <value>-0.5148</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>42</x>
      <y>223</y>
      <label>Gain X</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>gainY</objectName>
      <x>102</x>
      <y>143</y>
      <automationAllowed>true</automationAllowed>
      <minimum>-1.0</minimum>
      <maximum>1.0</maximum>
      <value>0.4756</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>114</x>
      <y>223</y>
      <label>Gain Y</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>gainZ</objectName>
      <x>172</x>
      <y>144</y>
      <automationAllowed>true</automationAllowed>
      <minimum>-1.0</minimum>
      <maximum>1.0</maximum>
      <value>0.9028</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>184</x>
      <y>224</y>
      <label>Gain Z</label>
    </bsbObject>
  </graphicInterface>
  <bsbParameterList>
    <parameter uniqueId='-1365000996' name='dt' label='' min='2.0E-4' max='0.05' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='0.05' min='2.0E-4' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='0.028063'/>
      </line>
    </parameter>
    <parameter uniqueId='-1365000994' name='gain' label='' min='0.0' max='5000.0' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='5000.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='888.5'/>
      </line>
    </parameter>
    <parameter uniqueId='-1365000992' name='gainX' label='' min='-1.0' max='1.0' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='1.0' min='-1.0' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='-0.5148'/>
      </line>
    </parameter>
    <parameter uniqueId='-1365000990' name='gainY' label='' min='-1.0' max='1.0' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='1.0' min='-1.0' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='0.4756'/>
      </line>
    </parameter>
    <parameter uniqueId='-1365000988' name='gainZ' label='' min='-1.0' max='1.0' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='1.0' min='-1.0' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='0.9028'/>
      </line>
    </parameter>
    <parameter uniqueId='-1365001002' name='paramA' label='' min='1.0' max='10.0' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='10.0' min='1.0' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='8.1415'/>
      </line>
    </parameter>
    <parameter uniqueId='-1365001000' name='paramB' label='' min='14.0' max='28.0' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='28.0' min='14.0' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='26.6504'/>
      </line>
    </parameter>
    <parameter uniqueId='-1365000998' name='paramC' label='' min='0.0' max='1.0' resolution='-1.0' automationEnabled='false'>
      <line name='' version='2' max='1.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false'>
        <linePoint x='0.0' y='0.8165'/>
      </line>
    </parameter>
  </bsbParameterList>
  <presetGroup name='Presets'/>
  <opcodeList/>
</instrument>