presetinterp

Abstract

Interpolates between presets placed in a 2D plane

Description

Given a set of points in 2D, this opcodes determines the weight of each point in relation to a cursor. Imagine a set of presets. A preset contains a set of parameters, for example, the formant frequencies, amplitudes and bandwidths of the a given vowel. Each preset is associated with a point in the plane. This opcode returns an array of weights, one for each point, indicating how much each preset should contribute to the result. These weights can be used together with other array opcodes (particularly with weightedsum) to interpolate the actual parameters.

Syntax

kweights[]  presetinterp kx, ky, kpoints[], iclamp=0
kweights[]  presetinterp kx, ky, ipoints[], iclamp=0

Arguments

  • kx: the x coordinate of the cursor
  • ky: the y coordinate of the cursor
  • kpoints[]: a 1D array with the coordinates and weights representing the points. Each point is represented by 3 numbers: x, y, weight (the size of the array should be 3x the number of points defined). The weight is normally a number between 0-1 which can be used to scale the presence of a particular preset. It is often needed for points placed at the center of the 2D plane
  • iclamp: if given, a value in the range (0, 1]. Presets which would get an associated weight less than iclamp * averageWeight (where averageWeight is 1/numberOfPoints) are clamped to 0 and their weight is redistributed (kweights always sums up to 1)

Output

  • kweights: an array with the same size as the number of presets given, representing the weight for each point in the same order the points were defined. The weights in this array always sum up to 1.0.

See Also

Examples

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 64
nchnls = 4
0dbfs = 1

giformantFreqs[] fillarray 800, 1150, 2900, 3900, 4950, \  ; A
                           350, 2000, 2800, 3600, 4950, \  ; E
                           270, 2140, 2950, 3900, 4950, \  ; I
                           450, 800, 2830, 3800, 4950,  \  ; O
                           325, 700, 2700, 3800, 4950      ; U



giformantDbs[] fillarray   0, -6, -32, -20, -50, \
                           0, -20, -15, -40, -56, \
                           0, -12, -26, -26, -44, \
                           0, -11, -22, -22, -50, \
                           0, -16, -35, -40, -60

giformantBws[] fillarray   80, 90, 120, 130, 140, \
                           60, 100, 120, 150, 200, \
                           60, 90, 100, 120, 120, \
                           40, 80, 100, 120, 120, \
                           50, 60, 170, 180, 200


giformantAmps[] maparray giformantDbs, "ampdb"

reshapearray giformantFreqs, 5, 5
reshapearray giformantAmps, 5, 5
reshapearray giformantBws, 5, 5

instr 10
  kmidi = p4
  kamp = p5
  kx = p6
  ky = p7
  kmidi = lag:k(kmidi, 0.3)

  kvibfreq linseg 0, 0.3, 0, 2.5, 4.5
  ivibsemi = 0.1
  kvib oscil ivibsemi/2, kvibfreq
  kvib -= ivibsemi / 2
  kpitch = kmidi + kvib
  kfreq = lag(mtof(kpitch), 0.2)

  ; asource = mpulse:a(kamp*10, 1/kfreq)
  asource vco2 kamp, kfreq
  asource = butterlp:a(asource, 4000)

  ;                   x    y    weight
  kcoords[] fillarray 0,   0,   1,      \    ; A
                      0.5, 0.5, 0.4,    \    ; E
                      1,   0,   1,      \    ; I
                      0,   1,   1,      \    ; O
                      1,   1,   1            ; U
  kweights[] init 5
  kformantFreqs[] init 5
  kformantBws[] init 5
  kformantAmps[] init 5

  if changed:k(kx, ky) == 1 then
    kweights presetinterpw kx, ky, kcoords, 0.25
    printarray kweights
    kformantFreqs weightedsum giformantFreqs, kweights
    kformantBws   weightedsum giformantBws, kweights
    kformantAmps  weightedsum giformantAmps, kweights

  endif
  kformantFreqs poly 5, "lag", kformantFreqs, 0.1
  kformantAmps poly 5, "lag", kformantAmps, 0.1

  aformants[] poly 5, "resonx", asource, kformantFreqs, kformantBws, 2, 2
  ; aformants[] poly 5, "butterbp", asource, kformantFreqs, kformantBws
  aformants *= kformantAmps
  asum sumarray aformants
  asum *= a(kamp)
  asum *= linsegr(0, 0.1, 1, 0.1, 0)
  ; asum *= 0.1
  ; dispfft asum, 0.05, 4096
  dispfft asource, 0.05, 4096
  outch 1, asum, 3, asource
endin

instr 20
  ip1 = p4
  kt = timeinsts()
  kmidi bpf kt, 0, 60, 10, 60, 18, 36
  kamp = 0.1
  kradius linseg 0.5, 10, 0.5, 10, 0.1
  kfreq = 1/10
  kx = oscil:k(kradius, kfreq)+0.5
  ky = oscil:k(kradius, kfreq, -1, 3.1415/4)+0.5
  pwrite ip1, 4, kmidi, 5, kamp, 6, kx, 7, ky
  if metro(30) == 1 then
    outvalue "x", kx
    outvalue "y", ky
    outvalue "note", mton(round(kmidi*2)/2)
  endif
endin

idur = 20
schedule 10.01, 0, idur, 48, 0.5, 0, 1, 0
schedule 20, 0, idur, 10.01

</CsInstruments>
<CsScore>

</CsScore>
</CsoundSynthesizer>











































<bsbPanel>
 <label>Widgets</label>
 <objectName/>
 <x>0</x>
 <y>0</y>
 <width>833</width>
 <height>631</height>
 <visible>true</visible>
 <uuid/>
 <bgcolor mode="background">
  <r>40</r>
  <g>40</g>
  <b>40</b>
 </bgcolor>
 <bsbObject version="2" type="BSBGraph">
  <objectName>graph1</objectName>
  <x>5</x>
  <y>9</y>
  <width>828</width>
  <height>313</height>
  <uuid>{a386abff-a2e9-4fd5-a2a1-044b268f027e}</uuid>
  <visible>true</visible>
  <midichan>0</midichan>
  <midicc>-3</midicc>
  <description/>
  <value>0</value>
  <objectName2/>
  <zoomx>4.00000000</zoomx>
  <zoomy>1.00000000</zoomy>
  <dispx>1.00000000</dispx>
  <dispy>1.00000000</dispy>
  <modex>lin</modex>
  <modey>lin</modey>
  <showSelector>false</showSelector>
  <showGrid>true</showGrid>
  <showTableInfo>true</showTableInfo>
  <showScrollbars>false</showScrollbars>
  <enableTables>false</enableTables>
  <enableDisplays>true</enableDisplays>
  <all>true</all>
 </bsbObject>
 <bsbObject version="2" type="BSBController">
  <objectName>x</objectName>
  <x>171</x>
  <y>332</y>
  <width>300</width>
  <height>300</height>
  <uuid>{f50d2326-9e70-41bf-a9d2-ea39b20ad45b}</uuid>
  <visible>true</visible>
  <midichan>0</midichan>
  <midicc>0</midicc>
  <description/>
  <objectName2>y</objectName2>
  <xMin>0.00000000</xMin>
  <xMax>1.00000000</xMax>
  <yMin>0.00000000</yMin>
  <yMax>1.00000000</yMax>
  <xValue>0.99604966</xValue>
  <yValue>0.54824522</yValue>
  <type>point</type>
  <pointsize>20</pointsize>
  <fadeSpeed>0.00000000</fadeSpeed>
  <mouseControl act="press">jump</mouseControl>
  <bordermode>border</bordermode>
  <borderColor>#007800</borderColor>
  <color>
   <r>0</r>
   <g>234</g>
   <b>0</b>
  </color>
  <randomizable mode="both" group="0">false</randomizable>
  <bgcolor>
   <r>0</r>
   <g>80</g>
   <b>0</b>
  </bgcolor>
  <bgcolormode>true</bgcolormode>
 </bsbObject>
 <bsbObject version="2" type="BSBDisplay">
  <objectName>note</objectName>
  <x>96</x>
  <y>332</y>
  <width>64</width>
  <height>36</height>
  <uuid>{ede113aa-8dda-4374-ab74-995b45a818df}</uuid>
  <visible>true</visible>
  <midichan>0</midichan>
  <midicc>-3</midicc>
  <description/>
  <label>4C</label>
  <alignment>left</alignment>
  <valignment>center</valignment>
  <font>Liberation Sans</font>
  <fontsize>16</fontsize>
  <precision>3</precision>
  <color>
   <r>255</r>
   <g>255</g>
   <b>255</b>
  </color>
  <bgcolor mode="background">
   <r>24</r>
   <g>24</g>
   <b>24</b>
  </bgcolor>
  <bordermode>false</bordermode>
  <borderradius>5</borderradius>
  <borderwidth>0</borderwidth>
 </bsbObject>
 <bsbObject version="2" type="BSBLabel">
  <objectName/>
  <x>50</x>
  <y>336</y>
  <width>43</width>
  <height>26</height>
  <uuid>{1b1e8fcb-efcc-4236-a315-e07e13fafec0}</uuid>
  <visible>true</visible>
  <midichan>0</midichan>
  <midicc>-3</midicc>
  <description/>
  <label>Pitch</label>
  <alignment>right</alignment>
  <valignment>center</valignment>
  <font>Liberation Sans</font>
  <fontsize>12</fontsize>
  <precision>3</precision>
  <color>
   <r>239</r>
   <g>239</g>
   <b>239</b>
  </color>
  <bgcolor mode="nobackground">
   <r>255</r>
   <g>255</g>
   <b>255</b>
  </bgcolor>
  <bordermode>false</bordermode>
  <borderradius>1</borderradius>
  <borderwidth>0</borderwidth>
 </bsbObject>
 <bsbObject version="2" type="BSBScope">
  <objectName/>
  <x>483</x>
  <y>332</y>
  <width>350</width>
  <height>150</height>
  <uuid>{735224e3-fc71-454b-9aee-f857e8ea1b89}</uuid>
  <visible>true</visible>
  <midichan>0</midichan>
  <midicc>-3</midicc>
  <description/>
  <value>3.00000000</value>
  <type>scope</type>
  <zoomx>8.00000000</zoomx>
  <zoomy>2.00000000</zoomy>
  <dispx>1.00000000</dispx>
  <dispy>1.00000000</dispy>
  <mode>0.00000000</mode>
  <triggermode>TriggerUp</triggermode>
 </bsbObject>
</bsbPanel>
<bsbPresets>
</bsbPresets>