PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/patches/LivingstonGuitar (mikey's conflicted copy 2010-09-09)

http://silencio.googlecode.com/
#! | 180 lines | 180 code | 0 blank | 0 comment | 0 complexity | 05d4106e80b405f429ee898be91bf810 MD5 | raw file
  1. instr LivingstonGuitar
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ; The model takes pluck position, and pickup position (in % of string length), and generates
  4. ; a pluck excitation signal, representing the string displacement. The pluck consists
  5. ; of a forward and backward traveling displacement wave, which are recirculated thru two
  6. ; separate delay lines, to simulate the one dimensional string waveguide, with
  7. ; fixed ends.
  8. ;
  9. ; Losses due to internal friction of the string, and with air, as well as
  10. ; losses due to the mechanical impedance of the string terminations are simulated by
  11. ; low pass filtering the signal inside the feedback loops.
  12. ; Delay line outputs at the bridge termination are summed and fed into an IIR filter
  13. ; modeled to simulate the lowest two vibrational modes (resonances) of the guitar body.
  14. ; The theory implies that force due to string displacement, which is equivalent to
  15. ; displacement velocity times bridge mechanical impedance, is the input to the guitar
  16. ; body resonator model. Here we have modified the transfer fuction representing the bridge
  17. ; mech impedance, to become the string displacement to bridge input force transfer function.
  18. ; The output of the resulting filter represents the displacement of the guitar's top plate,
  19. ; and sound hole, since thier respective displacement with be propotional to input force.
  20. ; (based on a simplified model, viewing the top plate as a force driven spring).
  21. ;
  22. ; The effects of pluck hardness, and contact with frets during pluck release,
  23. ; have been modeled by injecting noise into the initial pluck, proportional to initial
  24. ; string displacement.
  25. ;
  26. ; Note on pluck shape: Starting with a triangular displacment, I found a decent sounding
  27. ; initial pluck shape after some trial and error. This pluck shape, which is a linear
  28. ; ramp, with steep fall off, doesn't necessarily agree with the pluck string models I've
  29. ; studied. I found that initial pluck shape significantly affects the realism of the
  30. ; sound output, but I the treatment of this topic in musical acoustics literature seems
  31. ; rather limited as far as I've encountered.
  32. ;
  33. ; Original pfields
  34. ; p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13
  35. ; in st dur amp pch plklen fbfac pkupPos pluckPos brightness vibf vibd vibdel
  36. ; i01.2 0.5 0.75 5000 7.11 .85 0.9975 .0 .25 1 0 0 0
  37. pset 0, 0, 3600, 0, 0, 0, 0, 0, 0, 0, 0
  38. iHz,kHz,iamplitude,idB NoteOn p4, p5, 2.0
  39. p3, adamping Damping 0.003, p3,.03
  40. isafety init 0.001
  41. ip4 init iamplitude
  42. ip6 init 0.85
  43. ip7 init 0.9975
  44. ip8 init 0
  45. ip9 init 0.25
  46. ip10 init 1.0
  47. ip11 init 0.001
  48. ip12 init 0.0
  49. ip13 init 0.0
  50. afwav init 0
  51. abkwav init 0
  52. abkdout init 0
  53. afwdout init 0
  54. iEstr init 1.0 / cpspch(6.04)
  55. ifqc init iHz ; cpspch(p5)
  56. ; note:delay time=2x length of string (time to traverse it)
  57. idlt init 1.0 / ifqc
  58. print iHz, ifqc, idlt
  59. ipluck = 0.5 * idlt * ip6 * ifqc / cpspch(8.02)
  60. ifbfac = ip7 ; feedback factor
  61. ; (exponentialy scaled) additive noise to add hi freq content
  62. ibrightness = ip10 * exp(ip6 * log(2)) / 2
  63. ivibRate = ip11
  64. ivibDepth pow 2, ip12 / 12
  65. ; vibrato depth, +,- ivibDepth semitones
  66. ivibDepth = idlt - 1.0 / (ivibDepth * ifqc)
  67. ; vibrato start delay (secs)
  68. ivibStDly = ip13
  69. ; termination impedance model
  70. ; cutoff freq of LPF due to mech. impedance at the nut (2kHz-10kHz)
  71. if0 = 10000
  72. ; damping parameter of nut impedance
  73. iA0 = ip7
  74. ialpha = cos(2 * 3.14159265 * if0 * 1 / sr)
  75. ; FIR LPF model of nut impedance, H(z)=a0+a1z^-1+a0z^-2
  76. ia0 = 0.3 * iA0 / (2 * (1 - ialpha))
  77. ia1 = iA0 - 2 * ia0
  78. ; NOTE each filter pass adds a sampling period delay,so subtract 1/sr from tap time to compensate
  79. ; determine (in crude fashion) which string is being played
  80. ; icurStr = (ifqc > cpspch(6.04) ? 2 : 1)
  81. ; icurStr = (ifqc > cpspch(6.09) ? 3 : icurStr)
  82. ; icurStr = (ifqc > cpspch(7.02) ? 4 : icurStr)
  83. ; icurStr = (ifqc > cpspch(7.07) ? 5 : icurStr)
  84. ; icurStr = (ifqc > cpspch(7.11) ? 6 : icurStr)
  85. ipupos = ip8 * idlt / 2 ; pick up position (in % of low E string length)
  86. ippos = ip9 * idlt / 2 ; pluck position (in % of low E string length)
  87. isegF = 1 / sr
  88. isegF2 = ipluck
  89. iplkdelF = (ipluck / 2 > ippos ? 0 : ippos - ipluck / 2)
  90. isegB = 1 / sr
  91. isegB2 = ipluck
  92. iplkdelB = (ipluck / 2 > idlt / 2 - ippos ? 0 : idlt / 2 - ippos - ipluck / 2)
  93. ; EXCITATION SIGNAL GENERATION
  94. ; the two excitation signals are fed into the fwd delay represent the 1st and 2nd
  95. ; reflections off of the left boundary, and two accelerations fed into the bkwd delay
  96. ; represent the the 1st and 2nd reflections off of the right boundary.
  97. ; Likewise for the backward traveling acceleration waves, only they encouter the
  98. ; terminationsin the opposite order.
  99. ipw = 1
  100. ipamp = ip4 * ipluck ; 4 / ipluck
  101. aenvstrf linseg 0, isegF, -ipamp / 2, isegF2, 0
  102. adel1 delayr idlt > 0 ? idlt : idlt
  103. ; initial forward traveling wave (pluck to bridge)
  104. aenvstrf1 deltapi iplkdelF
  105. ; first forward traveling reflection (nut to bridge)
  106. aenvstrf2 deltapi iplkdelB + idlt / 2
  107. delayw aenvstrf
  108. ; inject noise for attack time string fret contact, and pre pluck vibrations against pick
  109. anoiz rand ibrightness
  110. aenvstrf1 = aenvstrf1 + anoiz*aenvstrf1
  111. aenvstrf2 = aenvstrf2 + anoiz*aenvstrf2
  112. ; filter to account for losses along loop path
  113. aenvstrf2 filter2 aenvstrf2, 3, 0, ia0, ia1, ia0
  114. ; combine into one signal (flip refl wave's phase)
  115. aenvstrf = aenvstrf1 - aenvstrf2
  116. ; initial backward excitation wave
  117. aenvstrb linseg 0, isegB, - ipamp / 2, isegB2, 0
  118. adel2 delayr idlt > 0 ? idlt : 0.1
  119. ; initial bdwd traveling wave (pluck to nut)
  120. aenvstrb1 deltapi iplkdelB
  121. ; first forward traveling reflection (nut to bridge)
  122. aenvstrb2 deltapi idlt / 2 + iplkdelF
  123. delayw aenvstrb
  124. ; initial bdwd traveling wave (pluck to nut)
  125. ; aenvstrb1 delay aenvstrb, iplkdelB
  126. ; first bkwd traveling reflection (bridge to nut)
  127. ; aenvstrb2 delay aenvstrb, idlt/2+iplkdelF
  128. ; inject noise
  129. aenvstrb1 = aenvstrb1 + anoiz*aenvstrb1
  130. aenvstrb2 = aenvstrb2 + anoiz*aenvstrb2
  131. ; filter to account for losses along loop path
  132. aenvstrb2 filter2 aenvstrb2, 3, 0, ia0, ia1, ia0
  133. ; combine into one signal (flip refl wave's phase)
  134. aenvstrb = aenvstrb1 - aenvstrb2
  135. ; low pass to band limit initial accel signals to be < 1/2 the sampling freq
  136. ainputf tone aenvstrf, sr * 0.9 / 2
  137. ainputb tone aenvstrb, sr * 0.9 / 2
  138. ; additional lowpass filtering for pluck shaping\
  139. ; Note, it would be more efficient to combine stages into a single filter
  140. ainputf tone ainputf, sr * 0.9 / 2
  141. ainputb tone ainputb, sr * 0.9 / 2
  142. ; Vibrato generator
  143. icosine ftgenonce 0, 0, 65537, 11, 1.0
  144. avib poscil ivibDepth, ivibRate, icosine
  145. avibdl delayr (ivibStDly * 1.1) > 0 ? ivibStDly * 1.1 : 0.1
  146. avibrato deltapi ivibStDly
  147. delayw avib
  148. ; Dual Delay line,
  149. ; NOTE: delay length longer than needed by a bit so that the output at t=idlt will be interpolated properly
  150. ;forward traveling wave delay line
  151. afd delayr ((idlt + ivibDepth) * 1.1) > 0 ? (idlt + ivibDepth) * 1.1 : 0.1
  152. ; output tap point for fwd traveling wave
  153. afwav deltapi ipupos
  154. ; output at end of fwd delay (left string boundary)
  155. afwdout deltapi idlt - 1 / sr + avibrato
  156. ; lpf/attn due to reflection impedance
  157. afwdout filter2 afwdout, 3, 0, ia0, ia1, ia0
  158. delayw ainputf + afwdout * ifbfac * ifbfac
  159. ; backward trav wave delay line
  160. abkwd delayr ((idlt + ivibDepth) * 1.1) > 0 ? (idlt + ivibDepth) * 1.1 : 0.1
  161. ; output tap point for bkwd traveling wave
  162. abkwav deltapi idlt / 2 - ipupos
  163. ; output at the left boundary
  164. ; abkterm deltapi idlt/2
  165. ; output at end of bkwd delay (right string boundary)
  166. abkdout deltapi idlt - 1 / sr + avibrato
  167. abkdout filter2 abkdout, 3, 0, ia0, ia1, ia0
  168. delayw ainputb + abkdout * ifbfac * ifbfac
  169. ; resonant body filter model, from Cuzzucoli and Lombardo
  170. ; IIR filter derived via bilinear transform method
  171. ; the theoretical resonances resulting from circuit model should be:
  172. ; resonance due to the air volume + soundhole = 110Hz (strongest)
  173. ; resonance due to the top plate = 220Hz
  174. ; resonance due to the inclusion of the back plate = 400Hz (weakest)
  175. aresbod filter2 (afwdout + abkdout), 5, 4, 0.000000000005398681501844749, .00000000000001421085471520200, -.00000000001076383426834582, -00000000000001110223024625157, .000000000005392353230604385, -3.990098622573566, 5.974971737738533, -3.979630684599723, .9947612723736902
  176. asig = (1500 * (afwav + abkwav + aresbod * .000000000000000000003)) * adamping
  177. aleft, aright Pan p7, asig
  178. outleta "leftout", aleft
  179. outleta "rightout", aright
  180. endin