<effect>
  <name>BrickLimit</name>
  <enabled>true</enabled>
  <numIns>2</numIns>
  <numOuts>2</numOuts>
  <code>if (&lt;BrickLimitON&gt; == 1) then
    kthresh	=		&lt;treshold&gt; 		
    ksmooth	=		&lt;smooth&gt;                                        ; this is needed as an i-time variable so will have to be cast as an i variable and a reinitialisation forced
    kthresh	=		ampdbfs(kthresh)                                ; convert threshold to an amplitude value
    if changed(ksmooth)==1 then                                                    ; if Smoothing slider is moved...
        reinit REINIT                                                                 ; ... force a reinitialisation
    endif
    REINIT:                                                                        ; reinitialise from here
    krmsL		rms		ain1, 1/i(ksmooth)                              ; scan both channels
    krmsR		rms		ain2, 1/i(ksmooth)                              ; ...
    rireturn                                                                       ; return to performance pass from reinitialisation pass (if applicable)
    krms		max		krmsL,krmsR                                     ; but only used the highest rms

    kdelay		=   &lt;delay&gt;				
    if kdelay&gt;0 then                                                               ; if Delay value is anything above zero ...
        ain1d	vdelay	ain1, kdelay*1000, 200                                          ; delay audio signals before limiting
        ain2d	vdelay	ain2, kdelay*1000, 200
    endif

    if krms&gt;kthresh then					; if current RMS is above threshold; i.e. limiting required
        kfctr		=	kthresh/krms			; derive less than &apos;1&apos; factor required to attenuate audio signal to limiting value
        afctr		interp	kfctr				; smooth changes (and interpolate from k to a)
        aout1		=	ain1d * afctr			; apply scaling factor
        aout2		=	ain2d * afctr
    else
        aout1 	=	ain1d				; pass audio signals unchanged
        aout2	=	ain2d				; ...
    endif

    kgain		=	&lt;gain&gt;				; make up gain control
    kgain		=	ampdb(kgain)			; derive gain value as an amplitude factor
    aout1		*=	kgain				; make up gain
    aout2		*=	kgain
else
    aout1    =   ain1
    aout2    =   ain2
endif

</code>
  <comments>
DESCRIPTION:

BrickLimit is a simple &apos;brick-wall&apos; limiter, developped in Cabbage by Iain McCurdy (2016). A small delay is used; this acts as a look-ahead feature.
This is an implementation as a blue effect, and some values are slightly adapted for use within blue.
   

CONTROLLERS:

ON/OFF          -       bypass
Threshold       -	dB threshold below above which signals will be aggressively limited
Smoothing	-	response of the amplitude follower. Higher values result in a slower, but possibly smoother, response
Delay		-	delay applied to the input sound before it is limited (the tracked signal is always undelayed)
			This can be useful for compensating for a limiter than is not responding fast enough to sudden dynamic transients 
Gain		-	Make up gain. Useful for compensating for gain loss.

---

version 1.02, July 2020
- added BSB information comments

version 1.01, May 2020
- added comments on controllers

version 1.0, April 2020
- initial version by Menno Knevel. Original code largely developped in Cabbage by Iain McCurdy (2016)
</comments>
  <opcodeList/>
  <graphicInterface editEnabled='false'>
    <gridSettings>
      <width>5</width>
      <height>5</height>
      <gridStyle>DOT</gridStyle>
      <snapGridEnabled>true</snapGridEnabled>
    </gridSettings>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
      <objectName></objectName>
      <x>0</x>
      <y>0</y>
      <groupName>Group</groupName>
      <backgroundColor>0x00000033</backgroundColor>
      <borderColor>0x000000ff</borderColor>
      <labelTextColor>0xffffffff</labelTextColor>
      <titleEnabled>true</titleEnabled>
      <width>20</width>
      <height>20</height>
      <bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
        <objectName></objectName>
        <x>10</x>
        <y>10</y>
        <groupName>ReverbSC</groupName>
        <backgroundColor>0x4d8080ff</backgroundColor>
        <borderColor>0x000000ff</borderColor>
        <labelTextColor>0xffffffff</labelTextColor>
        <titleEnabled>false</titleEnabled>
        <width>170</width>
        <height>30</height>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel' version='2'>
          <objectName></objectName>
          <x>130</x>
          <y>80</y>
          <label>gain</label>
          <font>
            <name>System Regular</name>
            <size>12.0</size>
          </font>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBVSlider' version='2'>
          <objectName>treshold</objectName>
          <x>10</x>
          <y>10</y>
          <comment>dB threshold below above which signals will be aggressively limited</comment>
          <automationAllowed>true</automationAllowed>
          <minimum>-60.0</minimum>
          <maximum>1.0</maximum>
          <bdresolution>1</bdresolution>
          <value>-21.0</value>
          <sliderHeight>60</sliderHeight>
          <randomizable>true</randomizable>
          <valueDisplayEnabled>true</valueDisplayEnabled>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBVSlider' version='2'>
          <objectName>gain</objectName>
          <x>160</x>
          <y>10</y>
          <comment>Make up gain. Useful for compensating for gain loss.</comment>
          <automationAllowed>true</automationAllowed>
          <minimum>-48.0</minimum>
          <maximum>48.0</maximum>
          <bdresolution>1</bdresolution>
          <value>0.0</value>
          <sliderHeight>60</sliderHeight>
          <randomizable>true</randomizable>
          <valueDisplayEnabled>true</valueDisplayEnabled>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel' version='2'>
          <objectName></objectName>
          <x>60</x>
          <y>80</y>
          <label>treshold</label>
          <font>
            <name>System Regular</name>
            <size>12.0</size>
          </font>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
          <objectName>smooth</objectName>
          <x>60</x>
          <y>10</y>
          <comment>response of the amplitude follower. Higher values result in a slower, but possibly smoother, response</comment>
          <automationAllowed>true</automationAllowed>
          <minimum>0.0</minimum>
          <maximum>1.0</maximum>
          <value>0.65</value>
          <knobWidth>45</knobWidth>
          <randomizable>true</randomizable>
          <valueDisplayEnabled>false</valueDisplayEnabled>
          <label>smooth</label>
          <labelEnabled>true</labelEnabled>
          <font>
            <name>System Regular</name>
            <size>12.0</size>
          </font>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
          <objectName>delay</objectName>
          <x>110</x>
          <y>10</y>
          <comment>delay applied to the input sound before it is limited (the tracked signal is always undelayed). This can be useful for compensating for a limiter than is not responding fast enough to sudden dynamic transients </comment>
          <automationAllowed>true</automationAllowed>
          <minimum>0.0</minimum>
          <maximum>0.2</maximum>
          <value>0.132</value>
          <knobWidth>45</knobWidth>
          <randomizable>true</randomizable>
          <valueDisplayEnabled>false</valueDisplayEnabled>
          <label> delay</label>
          <labelEnabled>true</labelEnabled>
          <font>
            <name>System Regular</name>
            <size>12.0</size>
          </font>
        </bsbObject>
      </bsbObject>
      <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
        <objectName>BrickLimitON</objectName>
        <x>0</x>
        <y>0</y>
        <comment>bypass</comment>
        <automationAllowed>true</automationAllowed>
        <label/>
        <selected>true</selected>
        <randomizable>true</randomizable>
      </bsbObject>
    </bsbObject>
  </graphicInterface>
  <parameterList>
    <parameter uniqueId='-885254976' name='BrickLimitON' label='' min='0.0' max='1.0' bdresolution='1' automationEnabled='false' value='1.0'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='1.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-885254966' name='delay' label='' min='0.0' max='0.2' bdresolution='-1' automationEnabled='false' value='0.132'>
      <line name='' version='2' max='0.2' min='0.0' bdresolution='-1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.132'/>
      </line>
    </parameter>
    <parameter uniqueId='-885254964' name='smooth' label='' min='0.0' max='1.0' bdresolution='-1' automationEnabled='false' value='0.65'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='-1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.65'/>
      </line>
    </parameter>
    <parameter uniqueId='-885254962' name='treshold' label='' min='-60.0' max='1.0' bdresolution='1' automationEnabled='false' value='-21.0'>
      <line name='' version='2' max='1.0' min='-60.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='-21.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-885254960' name='gain' label='' min='-48.0' max='48.0' bdresolution='1' automationEnabled='false' value='0.0'>
      <line name='' version='2' max='48.0' min='-48.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.0'/>
      </line>
    </parameter>
  </parameterList>
</effect>