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

Created by Mark Van Peteghem

This instrument plays audio files, and allows you to alter them. It plays both mono and stereo files (no need to specify this)
and takes the sample rate of the sample in account.

There are three play modes: play once, loop, and cycle. The first two should be obvious, the third means that the sample
will be used as the cycle that is repeated at audio rate, at the frequency given in p5 (pitch or frequency).

The first row of UI controls has the basic stuff: distortion of the table (done once to optimize, so not automatable), reversing,
selecting begin and end point to be played, begin and end speed up, stutter, optional attack and release, panning and volume adjustment.
Stutter length relates to the position in the original sample, so the actual stutter length may be shorter or longer due to the speedup settings.

The second row of UI controls has the more advanced stuff:
- Tune adjusts the pitch of the sample, either with pvscale or with delays (based on code by Victor Lazzarini).
  If the pvscale method is used, the preservation of formants can be selected.
  The amount of pitch adjustment can be selected with the knob in octaves (when &apos;Octaves&apos; is selected) or
  by specifying the wanted fequency in p5, if the pitch of the original sample is given in the text box (when &apos;Pitch in p5&apos; is selected).
  Note that the perceived pitch is also affected by the speedup knobs.
- Shift lets you use pvshift on the sample.
- Blur lets you use pvsblur on the sample.
- Smooth lets you use pvsmooth on the sample.
- Downsample lets you lower the sample frequency.
- Auto delay is an experimental feature that uses the sample itself to add a delay. This works best with samples
  that only have low frequencies, like kick drums.
- Chorus adds a chorus, optionally distributing the different voices to the left and right channel.
- The filter settings should be obvious.

If the play mode is cycle, the speedup, stutter and tune settings are ignored.

Some knobs have a text field under them. These can be used to alter the value of the knob, e.g. entering +p6
when the value of the knob is 1, the used value will be 1+p6.
</comment>
  <globalOrc>gi_sampler_sample1_&lt;INSTR_NAME&gt; = 0
gi_sampler_sample1_dist_&lt;INSTR_NAME&gt; = 0
gi_sampler_sample2_&lt;INSTR_NAME&gt; = 0
gi_sampler_sample2_dist_&lt;INSTR_NAME&gt; = 0
gi_sampler_sr_&lt;INSTR_NAME&gt; = 0
gi_sampler_nr_channels_&lt;INSTR_NAME&gt; = 0
gi_sampler_duration_&lt;INSTR_NAME&gt; = 0
gi_cosine ftgen	0, 0, 65536,	11,	1, 1
gi_Hamming ftgen 0, 0,   2^16,   20,   1,   1</globalOrc>
  <globalSco/>
  <instrumentText>iamp = ((p4 &gt; 0) ? 0dbfs*p4 : ampdbfs(p4))*ampdb(&lt;vol_adjust&gt;)


if gi_sampler_sample1_dist_&lt;INSTR_NAME&gt;==0 then
	gi_sampler_nr_channels_&lt;INSTR_NAME&gt; filenchnls &quot;&lt;file&gt;&quot;

	gi_sampler_sample1_&lt;INSTR_NAME&gt;, gi_sampler_duration_&lt;INSTR_NAME&gt;, gi_sampler_sr_&lt;INSTR_NAME&gt; mvpReadSampleFromFile &quot;&lt;file&gt;&quot;, 1
	gi_sampler_sample1_dist_&lt;INSTR_NAME&gt; mvpDistortWaveTable gi_sampler_sample1_&lt;INSTR_NAME&gt;, &lt;distort_type&gt;, &lt;distort_amount&gt;

	if (&lt;reverse&gt;==1) then
		itmp mvpReverseTable gi_sampler_sample1_dist_&lt;INSTR_NAME&gt;, gi_sampler_duration_&lt;INSTR_NAME&gt;*gi_sampler_sr_&lt;INSTR_NAME&gt;
	endif
	istutter_reset1 table 0, gi_sampler_sample1_&lt;INSTR_NAME&gt;

	if (gi_sampler_nr_channels_&lt;INSTR_NAME&gt; &gt; 1) then
		gi_sampler_sample2_&lt;INSTR_NAME&gt;, gi_sampler_duration_&lt;INSTR_NAME&gt;, gi_sampler_sr_&lt;INSTR_NAME&gt; mvpReadSampleFromFile &quot;&lt;file&gt;&quot;, 2
		gi_sampler_sample2_dist_&lt;INSTR_NAME&gt; mvpDistortWaveTable gi_sampler_sample2_&lt;INSTR_NAME&gt;, &lt;distort_type&gt;, &lt;distort_amount&gt;
		if (&lt;reverse&gt;==1) then
			itmp mvpReverseTable gi_sampler_sample2_dist_&lt;INSTR_NAME&gt;, gi_sampler_duration_&lt;INSTR_NAME&gt;*gi_sampler_sr_&lt;INSTR_NAME&gt;
		endif
		istutter_reset2 table 0, gi_sampler_sample2_&lt;INSTR_NAME&gt;
	endif
endif

ispeedup_start = &lt;speedup_start&gt;&lt;speedup_start_mod&gt;
ispeedup_end   = &lt;speedup_end&gt;&lt;speedup_end_mod&gt;
istart = i(&lt;start&gt;)
iend = (&lt;select_end&gt;==0) ? gi_sampler_duration_&lt;INSTR_NAME&gt; : i(&lt;end&gt;)
if (iend&gt;gi_sampler_duration_&lt;INSTR_NAME&gt;) then
	iend = gi_sampler_duration_&lt;INSTR_NAME&gt;
endif
isample_duration =  iend - istart

inr_samples = isample_duration*gi_sampler_sr_&lt;INSTR_NAME&gt;
isample_start = istart*gi_sampler_sr_&lt;INSTR_NAME&gt;
isample_end   = iend  *gi_sampler_sr_&lt;INSTR_NAME&gt;
istutter_len      = i(&lt;stutter_len&gt;)&lt;stutter_len_mod&gt;
istutter_samples  = istutter_len*gi_sampler_sr_&lt;INSTR_NAME&gt;+isample_start

iavg_speedup = (ispeedup_start+ispeedup_end)/2
iuse_stutter = (&lt;play_type&gt;!=3) ? &lt;stutter&gt; : 0
istutters = i(&lt;stutters&gt;)&lt;stutters_mod&gt;
ibasic_dur = (isample_duration+&lt;stutter&gt;*istutter_len*istutters)/iavg_speedup

if (&lt;play_type&gt;!=3) then
	if (&lt;play_type&gt;==1) then
		p3 = ibasic_dur
	endif

	aph, astutter_env mvpSamplePosition &lt;play_type&gt;, ispeedup_start, ispeedup_end, gi_sampler_sr_&lt;INSTR_NAME&gt;/sr, isample_start, isample_end, iuse_stutter, istutters, istutter_samples
	
	itune = &lt;tune&gt;
else
	ifreq getFrequency p5
	aph phasor ifreq
	aph = isample_start + aph*(isample_end - isample_start)
	itune = 0
endif

if (&lt;tune&gt;!=0 &amp;&amp; &lt;tune_method&gt;==2) then
	idummy = p5 ; not used, but seems necessary, otherwise the UDO mvpSampler can&apos;t use p5
endif

adeclick linseg 0, &lt;attack_len&gt;, 1, p3-&lt;attack_len&gt;-&lt;release_len&gt;, 1, &lt;release_len&gt;, 0

asig1 mvpSampler gi_sampler_sample1_dist_&lt;INSTR_NAME&gt;, aph, &lt;auto_delay&gt;*&lt;auto_delay_amount&gt;, itune, &lt;tune_tech&gt;, &lt;tune_method&gt;, &lt;tune_formant&gt;, &lt;tune_oct&gt;&lt;tune_oct_mod&gt;, &lt;sample_pitch&gt;, \
	&lt;shift&gt;, &lt;shift_freq&gt;&lt;shift_freq_mod&gt;, &lt;blur&gt;, &lt;blur_time&gt;, &lt;smooth&gt;, &lt;smooth_amp&gt;, &lt;smooth_freq&gt;, &lt;downsample_freq&gt;*&lt;downsample&gt;, &lt;add_attack&gt;+&lt;add_release&gt;, adeclick, \
	iuse_stutter, astutter_env, istutter_reset1, &lt;filter_type&gt;*&lt;use_filter&gt;, &lt;filter_freq&gt;, &lt;filter_qual&gt;

kleft, kright panner &lt;pan&gt;&lt;pan_mod&gt;
if (gi_sampler_nr_channels_&lt;INSTR_NAME&gt; == 1) then
	ichorus_stereoize = &lt;chorus_stereoize&gt;

	if (ichorus_stereoize==0) then
		asig1 mvpChorus asig1, &lt;chorus_voices&gt;, 0.1, &lt;chorus_depth&gt;, &lt;chorus_speed&gt;
		asig2 = asig1*kright
		asig1 = asig1*kleft
	else
		asig1, asig2 mvpStereoChorus asig1, &lt;chorus_voices&gt;, 0.1, &lt;chorus_depth&gt;, &lt;chorus_speed&gt;
		asig1 = asig1*kleft
		asig2 = asig2*kright
	endif
else
	asig2 mvpSampler gi_sampler_sample2_dist_&lt;INSTR_NAME&gt;, aph, &lt;auto_delay&gt;*&lt;auto_delay_amount&gt;, itune, &lt;tune_tech&gt;, &lt;tune_method&gt;, &lt;tune_formant&gt;, &lt;tune_oct&gt;&lt;tune_oct_mod&gt;, &lt;sample_pitch&gt;, \
		&lt;shift&gt;, &lt;shift_freq&gt;&lt;shift_freq_mod&gt;, &lt;blur&gt;, &lt;blur_time&gt;, &lt;smooth&gt;, &lt;smooth_amp&gt;, &lt;smooth_freq&gt;, &lt;downsample_freq&gt;*&lt;downsample&gt;, &lt;add_attack&gt;+&lt;add_release&gt;, adeclick, \
		 iuse_stutter, astutter_env, istutter_reset2, &lt;filter_type&gt;*&lt;use_filter&gt;, &lt;filter_freq&gt;, &lt;filter_qual&gt;

	; &lt;chorus_stereoize&gt; is not used in this case
	asig1 mvpChorus asig1, &lt;chorus_voices&gt;, 0.1, &lt;chorus_depth&gt;, &lt;chorus_speed&gt;
	asig2 mvpChorus asig2, &lt;chorus_voices&gt;, 0.1, &lt;chorus_depth&gt;, &lt;chorus_speed&gt;

	asig1 = asig1*kleft
	asig2 = asig2*kright
endif


asig1 = asig1*iamp
asig2 = asig2*iamp
blueMixerOut asig1, asig2
</instrumentText>
  <alwaysOnInstrumentText/>
  <graphicInterface editEnabled='false'>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>34</x>
      <y>18</y>
      <label>&lt;html&gt;&lt;font size=&quot;5&quot;&gt;File:&lt;/font&gt;&lt;/html&gt;</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBFileSelector'>
      <objectName>file</objectName>
      <x>79</x>
      <y>17</y>
      <fileName>K:\Samples\Berklee44v1\anklung_1.wav</fileName>
      <textFieldWidth>400</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>speedup_start</objectName>
      <x>366</x>
      <y>158</y>
      <automationAllowed>false</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>5.0</maximum>
      <value>1.0</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>405</x>
      <y>134</y>
      <label>Speedup</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>32</x>
      <y>134</y>
      <label>Distort</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>distort_amount</objectName>
      <x>94</x>
      <y>158</y>
      <automationAllowed>false</automationAllowed>
      <minimum>-1.0</minimum>
      <maximum>1.0</maximum>
      <value>0.28721344</value>
      <knobWidth>50</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBDropdown'>
      <objectName>distort_type</objectName>
      <x>85</x>
      <y>131</y>
      <automationAllowed>false</automationAllowed>
      <bsbDropdownItemList>
        <bsbDropdownItem uniqueId='57052350'>
          <name>None</name>
          <value>0</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052351'>
          <name>Atan</name>
          <value>1</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052352'>
          <name>Tan</name>
          <value>2</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052353'>
          <name>Sine</name>
          <value>3</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052354'>
          <name>Exp</name>
          <value>4</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052355'>
          <name>Clip</name>
          <value>5</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052356'>
          <name>Bitcrusher</name>
          <value>6</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052357'>
          <name>Square</name>
          <value>7</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='515458343'>
          <name>Cube</name>
          <value>8</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='939249687'>
          <name>Split</name>
          <value>9</value>
        </bsbDropdownItem>
      </bsbDropdownItemList>
      <selectedIndex>0</selectedIndex>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>reverse</objectName>
      <x>32</x>
      <y>95</y>
      <label>Reverse</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>downsample_freq</objectName>
      <x>556</x>
      <y>320</y>
      <automationAllowed>true</automationAllowed>
      <minimum>1000.0</minimum>
      <maximum>44100.0</maximum>
      <value>36482.61</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>downsample</objectName>
      <x>524</x>
      <y>287</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Downsample&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>auto_delay</objectName>
      <x>663</x>
      <y>287</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Auto delay&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>auto_delay_amount</objectName>
      <x>692</x>
      <y>320</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>10000.0</maximum>
      <value>6442.5293</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>tune</objectName>
      <x>18</x>
      <y>287</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Tune&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>tune_oct</objectName>
      <x>29</x>
      <y>352</y>
      <automationAllowed>true</automationAllowed>
      <minimum>-3.0</minimum>
      <maximum>3.0</maximum>
      <value>0.46687937</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>blur</objectName>
      <x>304</x>
      <y>287</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Blur&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>blur_time</objectName>
      <x>302</x>
      <y>320</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.51651406</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBDropdown'>
      <objectName>play_type</objectName>
      <x>366</x>
      <y>96</y>
      <automationAllowed>false</automationAllowed>
      <bsbDropdownItemList>
        <bsbDropdownItem uniqueId='438267762'>
          <name>Play once</name>
          <value>1</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='438267763'>
          <name>Loop</name>
          <value>2</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='-718385444'>
          <name>Cycle</name>
          <value>3</value>
        </bsbDropdownItem>
      </bsbDropdownItemList>
      <selectedIndex>0</selectedIndex>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>speedup_end</objectName>
      <x>433</x>
      <y>158</y>
      <automationAllowed>false</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>5.0</maximum>
      <value>1.0</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>pan</objectName>
      <x>871</x>
      <y>158</y>
      <automationAllowed>false</automationAllowed>
      <minimum>-1.0</minimum>
      <maximum>1.0</maximum>
      <value>0.0</value>
      <knobWidth>60</knobWidth>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>890</x>
      <y>134</y>
      <label>Pan</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>pan_mod</objectName>
      <x>871</x>
      <y>234</y>
      <value></value>
      <textFieldWidth>60</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>smooth</objectName>
      <x>375</x>
      <y>287</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Smooth&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>smooth_amp</objectName>
      <x>383</x>
      <y>320</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.9528363</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>smooth_freq</objectName>
      <x>453</x>
      <y>320</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.46328682</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>401</x>
      <y>398</y>
      <label>amp</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>468</x>
      <y>398</y>
      <label>freq</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBDropdown'>
      <objectName>tune_method</objectName>
      <x>18</x>
      <y>321</y>
      <automationAllowed>false</automationAllowed>
      <bsbDropdownItemList>
        <bsbDropdownItem uniqueId='1725919892'>
          <name>Octaves</name>
          <value>1</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='1725919893'>
          <name>Pitch in p5</name>
          <value>2</value>
        </bsbDropdownItem>
      </bsbDropdownItemList>
      <selectedIndex>0</selectedIndex>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>sample_pitch</objectName>
      <x>108</x>
      <y>393</y>
      <value>7.00</value>
      <textFieldWidth>70</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>107</x>
      <y>415</y>
      <label>sample pitch</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>add_attack</objectName>
      <x>708</x>
      <y>130</y>
      <label>atk</label>
      <selected>false</selected>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>attack_len</objectName>
      <x>700</x>
      <y>158</y>
      <automationAllowed>false</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.1</value>
      <knobWidth>60</knobWidth>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>add_release</objectName>
      <x>773</x>
      <y>130</y>
      <label>rel</label>
      <selected>false</selected>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>release_len</objectName>
      <x>773</x>
      <y>158</y>
      <automationAllowed>false</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.1</value>
      <knobWidth>60</knobWidth>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>start</objectName>
      <x>201</x>
      <y>158</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>5.0</maximum>
      <value>0.0</value>
      <knobWidth>60</knobWidth>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>end</objectName>
      <x>269</x>
      <y>158</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>5.0</maximum>
      <value>2.961832</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>218</x>
      <y>134</y>
      <label>start</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>select_end</objectName>
      <x>273</x>
      <y>130</y>
      <label>end</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBHSlider'>
      <objectName>chorus_voices</objectName>
      <x>864</x>
      <y>288</y>
      <automationAllowed>false</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>5.0</maximum>
      <resolution>1.0</resolution>
      <value>0.0</value>
      <sliderWidth>100</sliderWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>chorus_depth</objectName>
      <x>810</x>
      <y>345</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>0.1</maximum>
      <value>0.017289551</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>826</x>
      <y>324</y>
      <label>Depth</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>chorus_speed</objectName>
      <x>878</x>
      <y>345</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.08465153</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>888</x>
      <y>324</y>
      <label>Speed</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>chorus_stereoize</objectName>
      <x>953</x>
      <y>324</y>
      <label>stereoize</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>stutter_len</objectName>
      <x>523</x>
      <y>158</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.2962486</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>535</x>
      <y>135</y>
      <label>length</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>962</x>
      <y>126</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Volume adjust (db)&lt;/font&gt;&lt;/html&gt;</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>vol_adjust</objectName>
      <x>1006</x>
      <y>158</y>
      <automationAllowed>false</automationAllowed>
      <minimum>-40.0</minimum>
      <maximum>40.0</maximum>
      <value>0.0</value>
      <knobWidth>60</knobWidth>
      <randomizable>false</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>stutter</objectName>
      <x>534</x>
      <y>94</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Stutter&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBVSlider'>
      <objectName>stutters</objectName>
      <x>588</x>
      <y>143</y>
      <automationAllowed>true</automationAllowed>
      <minimum>1.0</minimum>
      <maximum>5.0</maximum>
      <resolution>1.0</resolution>
      <value>1.0</value>
      <sliderHeight>60</sliderHeight>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBDropdown'>
      <objectName>tune_tech</objectName>
      <x>107</x>
      <y>321</y>
      <automationAllowed>false</automationAllowed>
      <bsbDropdownItemList>
        <bsbDropdownItem uniqueId='-718385446'>
          <name>PVS</name>
          <value>1</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='-718385445'>
          <name>Delays</name>
          <value>2</value>
        </bsbDropdownItem>
      </bsbDropdownItemList>
      <selectedIndex>1</selectedIndex>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>shift</objectName>
      <x>205</x>
      <y>287</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Shift&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>shift_freq</objectName>
      <x>203</x>
      <y>320</y>
      <automationAllowed>true</automationAllowed>
      <minimum>-500.0</minimum>
      <maximum>500.0</maximum>
      <value>451.90448</value>
      <knobWidth>60</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBDropdown'>
      <objectName>tune_formant</objectName>
      <x>108</x>
      <y>352</y>
      <automationAllowed>false</automationAllowed>
      <bsbDropdownItemList>
        <bsbDropdownItem uniqueId='857849768'>
          <name>None</name>
          <value>0</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='857849769'>
          <name>Keep form 1</name>
          <value>1</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='857849770'>
          <name>Keep form 2</name>
          <value>2</value>
        </bsbDropdownItem>
      </bsbDropdownItemList>
      <selectedIndex>1</selectedIndex>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>speedup_start_mod</objectName>
      <x>366</x>
      <y>237</y>
      <value></value>
      <textFieldWidth>60</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>speedup_end_mod</objectName>
      <x>433</x>
      <y>237</y>
      <value></value>
      <textFieldWidth>60</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>stutter_len_mod</objectName>
      <x>523</x>
      <y>237</y>
      <value></value>
      <textFieldWidth>60</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>tune_oct_mod</objectName>
      <x>29</x>
      <y>431</y>
      <value></value>
      <textFieldWidth>60</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>shift_freq_mod</objectName>
      <x>204</x>
      <y>398</y>
      <value></value>
      <textFieldWidth>60</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>pan_mod6</objectName>
      <x>302</x>
      <y>398</y>
      <value></value>
      <textFieldWidth>60</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBTextField'>
      <objectName>stutters_mod</objectName>
      <x>588</x>
      <y>237</y>
      <value></value>
      <textFieldWidth>50</textFieldWidth>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>801</x>
      <y>291</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Chorus&lt;/font&gt;&lt;/html&gt;</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBDropdown'>
      <objectName>filter_type</objectName>
      <x>1132</x>
      <y>292</y>
      <automationAllowed>false</automationAllowed>
      <bsbDropdownItemList>
        <bsbDropdownItem uniqueId='57052740'>
          <name>Lowpass</name>
          <value>1</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052741'>
          <name>Highpass</name>
          <value>2</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052742'>
          <name>Bandpass</name>
          <value>3</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052743'>
          <name>Bandreject</name>
          <value>4</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052744'>
          <name>Rezzy lowpass</name>
          <value>5</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052745'>
          <name>Rezzy highpass</name>
          <value>6</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052746'>
          <name>Moogvcf</name>
          <value>7</value>
        </bsbDropdownItem>
        <bsbDropdownItem uniqueId='57052747'>
          <name>Moogladder</name>
          <value>8</value>
        </bsbDropdownItem>
      </bsbDropdownItemList>
      <selectedIndex>6</selectedIndex>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>filter_freq</objectName>
      <x>1068</x>
      <y>345</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>20000.0</maximum>
      <value>14301.696</value>
      <knobWidth>50</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>1081</x>
      <y>324</y>
      <label>Freq</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
      <objectName>filter_qual</objectName>
      <x>1127</x>
      <y>345</y>
      <automationAllowed>true</automationAllowed>
      <minimum>0.0</minimum>
      <maximum>1.0</maximum>
      <value>0.5409403</value>
      <knobWidth>50</knobWidth>
      <randomizable>true</randomizable>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel'>
      <objectName></objectName>
      <x>1134</x>
      <y>324</y>
      <label>Quality</label>
    </bsbObject>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
      <objectName>use_filter</objectName>
      <x>1049</x>
      <y>287</y>
      <label>&lt;html&gt;&lt;font size=&quot;+1&quot;&gt;Filter&lt;/font&gt;&lt;/html&gt;</label>
      <selected>false</selected>
      <randomizable>true</randomizable>
    </bsbObject>
  </graphicInterface>
  <bsbParameterList>
    <parameter uniqueId='-934014247' name='auto_delay_amount' label='' min='0.0' max='10000.0' resolution='-1.0' automationEnabled='false' value='6442.5293'>
      <line name='' version='2' max='10000.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='6442.5293'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014243' name='blur_time' label='' min='0.0' max='1.0' resolution='-1.0' automationEnabled='false' value='0.51651406'>
      <line name='' version='2' max='1.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.51651406'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014233' name='chorus_depth' label='' min='0.0' max='0.1' resolution='-1.0' automationEnabled='false' value='0.017289551'>
      <line name='' version='2' max='0.1' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.017289551'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014231' name='chorus_speed' label='' min='0.0' max='1.0' resolution='-1.0' automationEnabled='false' value='0.08465153'>
      <line name='' version='2' max='1.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.08465153'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014249' name='downsample_freq' label='' min='1000.0' max='44100.0' resolution='-1.0' automationEnabled='false' value='36482.61'>
      <line name='' version='2' max='44100.0' min='1000.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='36482.61'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014235' name='end' label='' min='0.0' max='5.0' resolution='-1.0' automationEnabled='false' value='2.961832'>
      <line name='' version='2' max='5.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='2.961832'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014223' name='filter_freq' label='' min='0.0' max='20000.0' resolution='-1.0' automationEnabled='false' value='14301.696'>
      <line name='' version='2' max='20000.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='14301.696'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014221' name='filter_qual' label='' min='0.0' max='1.0' resolution='-1.0' automationEnabled='false' value='0.5409403'>
      <line name='' version='2' max='1.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.5409403'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014225' name='shift_freq' label='' min='-500.0' max='500.0' resolution='-1.0' automationEnabled='false' value='451.90448'>
      <line name='' version='2' max='500.0' min='-500.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='451.90448'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014241' name='smooth_amp' label='' min='0.0' max='1.0' resolution='-1.0' automationEnabled='false' value='0.9528363'>
      <line name='' version='2' max='1.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.9528363'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014239' name='smooth_freq' label='' min='0.0' max='1.0' resolution='-1.0' automationEnabled='false' value='0.46328682'>
      <line name='' version='2' max='1.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.46328682'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014237' name='start' label='' min='0.0' max='5.0' resolution='-1.0' automationEnabled='false' value='0.0'>
      <line name='' version='2' max='5.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014229' name='stutter_len' label='' min='0.0' max='1.0' resolution='-1.0' automationEnabled='false' value='0.2962486'>
      <line name='' version='2' max='1.0' min='0.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.2962486'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014227' name='stutters' label='' min='1.0' max='5.0' resolution='1.0' automationEnabled='false' value='1.0'>
      <line name='' version='2' max='5.0' min='1.0' resolution='1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='1.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-934014245' name='tune_oct' label='' min='-3.0' max='3.0' resolution='-1.0' automationEnabled='false' value='0.46687937'>
      <line name='' version='2' max='3.0' min='-3.0' resolution='-1.0' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.46687937'/>
      </line>
    </parameter>
  </bsbParameterList>
  <presetGroup name='Presets'/>
  <opcodeList>
    <udo>
      <opcodeName>mvpReadSampleFromFile</opcodeName>
      <outTypes>iii</outTypes>
      <inTypes>Si</inTypes>
      <codeBody>Sname, ichannel xin

iname_len strlen Sname
Sext strsub Sname, iname_len-4
Sext strlower Sext
icmp strcmp Sext, &quot;.mp3&quot;

if (icmp!=0) then
	iduration filelen Sname
	isr filesr Sname
	inr_samples = iduration*isr
	itlen = 2^int(log(inr_samples)/log(2)+1) ; make table length power of 2 bigger than nr of samples
	itable ftgen 0, 0, itlen, 1, Sname, 0, 0, ichannel
else
	iduration = 1
	;iduration mp3len Sname
	;inr_samples = iduration*44100
	;itlen = 2^int(log(inr_samples)/log(2)+1) ; make table length power of 2 bigger than nr of samples
	print iduration
	itable ftgen 0, 0, 32768, 49, Sname, 0, ichannel
	print iduration+1
	itlen = ftlen(itable)
	print itlen
endif

xout itable, iduration, isr

</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>mvpDistortWaveTable</opcodeName>
      <outTypes>i</outTypes>
      <inTypes>iii</inTypes>
      <codeBody>iwave, idistortion_type, idistortion_amount xin
i_table_len = ftlen(iwave)

if (idistortion_type==1) then
	idistortion_amount = idistortion_amount * 20
	ipos = 0
	fill_loop_taninv:
		ival tab_i ipos, iwave
		ival = taninv(ival*idistortion_amount)
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_taninv
elseif (idistortion_type==2) then
	idistortion_amount = idistortion_amount * 10
	idistortion_factor = taninv(idistortion_amount)
	ipos = 0
	fill_loop_tan:
		ival tab_i ipos, iwave
		ival = tan(ival*idistortion_factor)/idistortion_amount
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_tan
elseif (idistortion_type==3) then
	idistortion_amount = idistortion_amount * 20
	ipos = 0
	fill_loop_sin:
		ival tab_i ipos, iwave
		ival = sin(ival*idistortion_amount)
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_sin
elseif (idistortion_type==4) then
	idistortion_amount = idistortion_amount * 5
	imin = exp(-idistortion_amount)
	imax = exp( idistortion_amount)
	isubtract = (imin+imax)/2
	iscale = (imax-imin)/2
	ipos = 0
	fill_loop_exp:
		ival tab_i ipos, iwave
		ival = (exp(ival*idistortion_amount)-isubtract)/iscale
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_exp
elseif (idistortion_type==5) then
	idistortion_amount = idistortion_amount * 20
	ipos = 0
	fill_loop_clip:
		ival tab_i ipos, iwave
		ival = ival*idistortion_amount
		if (ival&gt;1) then
			ival = 1
		elseif (ival&lt;-1) then
			ival = -1
		endif
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_clip
elseif (idistortion_type==6) then
	idistortion_amount = 2^(16-idistortion_amount*16)
	ipos = 0
	fill_loop_bit_crusher:
		ival tab_i ipos, iwave
		ival = round(ival*idistortion_amount)/idistortion_amount
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_bit_crusher
elseif (idistortion_type==7) then
	ipos = 0
	imin = 100
	imax = -100
	idry = 1-abs(idistortion_amount)
	fill_loop_square:
		ival tab_i ipos, iwave
		ival = idry*ival + idistortion_amount*ival*ival
		imin = (ival&lt;imin) ? ival : imin
		imax = (ival&gt;imax) ? ival : imax
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_square
	iavg = (imax+imin)/2
	iscale = 2/(imax-imin)
	ipos = 0
	fill_loop_square_normalize:
		ival tab_i ipos, iwave
		ival = (ival-iavg)*iscale
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_square_normalize
elseif (idistortion_type==8) then
	ipos = 0
	imin = 100
	imax = -100
	idry = 1-abs(idistortion_amount)
	fill_loop_cube:
		ival tab_i ipos, iwave
		ival = idry*ival + idistortion_amount*ival*ival*ival
		imin = (ival&lt;imin) ? ival : imin
		imax = (ival&gt;imax) ? ival : imax
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_cube
	iavg = (imax+imin)/2
	iscale = 2/(imax-imin)
	ipos = 0
	fill_loop_cube_normalize:
		ival tab_i ipos, iwave
		ival = (ival-iavg)*iscale
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_cube_normalize
elseif (idistortion_type==9) then
	; if idistortion_amount &gt;= 0, move positive samples up and negative samples down
	; opposite if idistortion_amount &lt; 0
	; scale so that 1 and -1 are not changed, so signals between -1 and 1 stay in that range
	ia = 1-idistortion_amount
	ipos = 0
	fill_loop_split:
		ival tab_i ipos, iwave
		ival = (ival&gt;=0) ? 1-ia*(1-ival) : -1-ia*(-1-ival)
		tabw_i ival, ipos, iwave
		loop_lt ipos, 1, i_table_len, fill_loop_split
endif

xout iwave
</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>mvpReverseTable</opcodeName>
      <outTypes>i</outTypes>
      <inTypes>ii</inTypes>
      <codeBody>iwave, i_table_len xin

ipos = 0
reverse_loop:
	ival1 tab_i ipos, iwave
	ival2 tab_i i_table_len-ipos-1, iwave
	tabw_i ival2, ipos, iwave
	tabw_i ival1, i_table_len-ipos-1, iwave
	loop_lt ipos, 1, i_table_len/2, reverse_loop

xout iwave</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>getFrequency</opcodeName>
      <outTypes>i</outTypes>
      <inTypes>i</inTypes>
      <codeBody>ipch 	xin

iout	= (ipch &lt; 15 ? cpspch(ipch) : ipch)
	
	xout	iout
</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>PitchShifter</opcodeName>
      <outTypes>a</outTypes>
      <inTypes>aki</inTypes>
      <codeBody>setksmps 1 ; kr=sr
asig,kpitch,idel xin
kdelrate = (kpitch-1)/idel
avdel phasor -kdelrate ; 1 to 0
avdel2 phasor -kdelrate, 0.5 ; 1/2 buffer offset
afade tablei avdel, gi_Hamming, 1, 0, 1 ; crossfade windows
afade2 tablei avdel2,gi_Hamming, 1, 0, 1
adump delayr idel
atap1 deltapi avdel*idel ; variable delay taps
atap2 deltapi avdel2*idel
amix = atap1*afade + atap2*afade2 ; fade in/out the delay taps
delayw asig
xout amix
</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>mvpFilter</opcodeName>
      <outTypes>a</outTypes>
      <inTypes>aikki</inTypes>
      <codeBody>asig, itype, kfreq, kqual, ibalance xin

if (kfreq&gt;sr/2) then
	kfreq = sr/2
endif

if (itype==1) then
	afilt tone asig, kfreq
	;afilt butterlp asig, kfreq
elseif (itype==2) then
	afilt atone asig, kfreq
elseif (itype==3) then
	afilt reson asig, kfreq, kfreq/(kqual*20), 2
elseif (itype==4) then
	afilt areson asig, kfreq, kfreq/(kqual*20), 2
elseif (itype==5) then
	afilt rezzy asig, kfreq, kqual*100, 0
elseif (itype==6) then
	afilt rezzy asig, kfreq, kqual*100, 1
elseif (itype==7) then
	afilt moogvcf asig, kfreq, kqual
elseif (itype==8) then
	afilt moogladder asig, kfreq, kqual
endif

if (ibalance!=0) then
	afilt balance afilt, asig
endif

xout afilt
</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>mvpSampler</opcodeName>
      <outTypes>a</outTypes>
      <inTypes>iakiiiikiikikikkkiaiaiikk</inTypes>
      <codeBody>itable, aph, kauto_delay, itune, itune_tech, itune_method, itune_form, ktune_oct, isample_pitch, ishift, kshift_freq, iblur, kblur_time, ismooth, ksmooth_amp, ksmooth_freq, \
kdownsample, iuse_declick, adeclick, iuse_stutter_env, astutter_env, istutter_reset, ifilter_type, kfilter_freq, kfilter_qual xin

asig tablei aph, itable

if (kauto_delay!=0) then
	asig tablei aph+(1+asig)*kauto_delay, itable
endif

if (iuse_stutter_env!=0) then
	asig = asig*astutter_env+istutter_reset*(1-astutter_env)
endif

if (itune!=0 &amp;&amp; itune_tech==2) then
	if (itune_method==1) then
		kratio = 2^ktune_oct
	else
		isample_freq getFrequency isample_pitch
		ifreq getFrequency p5
		kratio = ifreq/isample_freq
	endif
	asig PitchShifter asig, kratio, 0.01
endif

itune_pvs = (itune==1 &amp;&amp; itune_tech==1) ? 1 : 0

if (itune_pvs!=0 || ishift!=0 || iblur!=0 || ismooth!=0) then
	fsig pvsanal asig, 1024,256,2048,0

	if (itune!=0) then
		if (itune_method==1) then
			kratio = 2^ktune_oct
		else
			isample_freq getFrequency isample_pitch
			ifreq getFrequency p5
			kratio = ifreq/isample_freq
		endif
		fsig1 pvscale fsig, kratio, itune_form
		fsig2 pvscale fsig, kratio*2, itune_form
		asig1  pvsynth   fsig1
		asig2  pvsynth   fsig2
		fsig pvsanal asig1+asig2, 1024,256,2048,0
	endif
	if (ishift!=0) then
		fsigo  pvshift	fsig, kshift_freq, 100, 0, 1
		fsig = fsigo
	endif
	if (iblur!=0) then
		fsigo  pvsblur	fsig, kblur_time, 1
		fsig = fsigo
	endif
	if (ismooth!=0) then
		fsigo  pvsmooth	fsig, ksmooth_amp, ksmooth_freq
		fsig = fsigo
	endif

	asig  pvsynth   fsig
endif

if (ifilter_type!=0) then
	asig mvpFilter asig, ifilter_type, kfilter_freq, kfilter_qual, 0
endif

if (kdownsample!=0) then
	agate mpulse 1, 1/kdownsample
	asig samphold asig, agate
endif

asig dcblock asig

if (iuse_declick!=0) then
	asig = asig*adeclick
endif

xout asig
</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>panner</opcodeName>
      <outTypes>kk</outTypes>
      <inTypes>k</inTypes>
      <codeBody>; sin/cos taper, constant power.
kPanpos xin
kPanpos = kPanpos/2

kPanpos	= kPanpos * 3.14159265359 * .5
kLeft     	= sqrt(2) / 2 * (cos(kPanpos) - sin(kPanpos)) 
kRight    	= sqrt(2) / 2 * (cos(kPanpos) + sin(kPanpos))
xout kLeft,kRight</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>mvpChorus</opcodeName>
      <outTypes>a</outTypes>
      <inTypes>aiikk</inTypes>
      <codeBody>asig, inr_voices, imax_depth, kdepth, kspeed xin

ach = asig

if (inr_voices!=0) then
	atemp           delayr          imax_depth*2

	alfo            oscili          kdepth, kspeed, gi_cosine
	adel            deltapi         alfo+kdepth
	ach             = ach + adel

	if (inr_voices&gt;1) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 1/inr_voices
		adel            deltapi         alfo+kdepth
		ach             = ach + adel
	endif

	if (inr_voices&gt;2) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 2/inr_voices
		adel            deltapi         alfo+kdepth
		ach             = ach + adel
	endif

	if (inr_voices&gt;3) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 3/inr_voices
		adel            deltapi         alfo+kdepth
		ach             = ach + adel
	endif

	if (inr_voices&gt;4) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 4/inr_voices
		adel            deltapi         alfo+kdepth
		ach             = ach + adel
	endif

	delayw          asig
endif

xout ach
</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>mvpStereoChorus</opcodeName>
      <outTypes>aa</outTypes>
      <inTypes>aiikk</inTypes>
      <codeBody>asig, inr_voices, imax_depth, kdepth, kspeed xin

if (inr_voices%2==0) then
	ach1 = asig
	ach2 = asig
else
	ach1 = asig
	ach2 = 0
endif

if (inr_voices!=0) then
	atemp           delayr          imax_depth*2

	alfo            oscili          kdepth, kspeed, gi_cosine
	adel            deltapi         alfo+kdepth
	ach2            = ach2 + adel
	print 2

	if (inr_voices&gt;1) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 1/inr_voices
		adel            deltapi         alfo+kdepth
		ach1            = ach1 + adel
		print 1
	endif

	if (inr_voices&gt;2) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 2/inr_voices
		adel            deltapi         alfo+kdepth
		ach2            = ach2 + adel
		print 2
	endif

	if (inr_voices&gt;3) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 3/inr_voices
		adel            deltapi         alfo+kdepth
		ach1            = ach1 + adel
	endif

	if (inr_voices&gt;4) then
		alfo            oscili          kdepth, kspeed, gi_cosine, 4/inr_voices
		adel            deltapi         alfo+kdepth
		ach2            = ach2 + adel
	endif

	delayw          asig
endif

xout ach1, ach2
</codeBody>
      <comments></comments>
    </udo>
    <udo>
      <opcodeName>mvpSamplePosition</opcodeName>
      <outTypes>aa</outTypes>
      <inTypes>iiiiiiiii</inTypes>
      <codeBody>setksmps 1              ; need sr=kr
iplay_type, ispeedup_start, ispeedup_end, isr, isample_start, isample_end, iuse_stutter, istutters, istutter_samples xin

kspeedup linseg ispeedup_start, p3, ispeedup_end
kstep = kspeedup*isr

aph init isample_start

aph = aph+kstep  
kph downsamp aph

kstutter_count init istutters
astutter_env init 1
istutter_dec = istutter_samples/5

if (iuse_stutter==1) then
	if (kph&gt;istutter_samples &amp;&amp; kstutter_count&gt;0) then
		aph = isample_start
		astutter_env = 1
		kstutter_count = kstutter_count-1
	elseif (istutter_samples-kph&lt;istutter_dec &amp;&amp; kstutter_count&gt;0) then
		astutter_env = (istutter_samples-kph)/istutter_dec
	else
		astutter_env = 1
	endif
endif

if (iplay_type==2) then
	if (kph&gt;isample_end) then
		aph = isample_start
		kstutter_count = istutters
	endif
endif

xout aph, astutter_env
</codeBody>
      <comments>UDO to update aph at sr speed</comments>
    </udo>
  </opcodeList>
</instrument>