PageRenderTime 24ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/patches/LivingstonGuitar

http://silencio.googlecode.com/
#! | 179 lines | 179 code | 0 blank | 0 comment | 0 complexity | 2362b7973c4bf21f08a8133fc78da0a3 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, 13
  39. p3, adamping Damping 0.003, p3,.03
  40. ip4 init iamplitude
  41. ip6 init 0.85
  42. ip7 init 0.9975
  43. ip8 init 0
  44. ip9 init 0.25
  45. ip10 init 1.0
  46. ip11 init 0.001
  47. ip12 init 0.0
  48. ip13 init 0.0
  49. afwav init 0
  50. abkwav init 0
  51. abkdout init 0
  52. afwdout init 0
  53. iEstr init 1.0 / cpspch(6.04)
  54. ifqc init iHz ; cpspch(p5)
  55. ; note:delay time=2x length of string (time to traverse it)
  56. idlt init 1.0 / ifqc
  57. print iHz, ifqc, idlt
  58. ipluck = 0.5 * idlt * ip6 * ifqc / cpspch(8.02)
  59. ifbfac = ip7 ; feedback factor
  60. ; (exponentialy scaled) additive noise to add hi freq content
  61. ibrightness = ip10 * exp(ip6 * log(2)) / 2
  62. ivibRate = ip11
  63. ivibDepth pow 2, ip12 / 12
  64. ; vibrato depth, +,- ivibDepth semitones
  65. ivibDepth = idlt - 1.0 / (ivibDepth * ifqc)
  66. ; vibrato start delay (secs)
  67. ivibStDly = ip13
  68. ; termination impedance model
  69. ; cutoff freq of LPF due to mech. impedance at the nut (2kHz-10kHz)
  70. if0 = 10000
  71. ; damping parameter of nut impedance
  72. iA0 = ip7
  73. ialpha = cos(2 * 3.14159265 * if0 * 1 / sr)
  74. ; FIR LPF model of nut impedance, H(z)=a0+a1z^-1+a0z^-2
  75. ia0 = 0.3 * iA0 / (2 * (1 - ialpha))
  76. ia1 = iA0 - 2 * ia0
  77. ; NOTE each filter pass adds a sampling period delay,so subtract 1/sr from tap time to compensate
  78. ; determine (in crude fashion) which string is being played
  79. ; icurStr = (ifqc > cpspch(6.04) ? 2 : 1)
  80. ; icurStr = (ifqc > cpspch(6.09) ? 3 : icurStr)
  81. ; icurStr = (ifqc > cpspch(7.02) ? 4 : icurStr)
  82. ; icurStr = (ifqc > cpspch(7.07) ? 5 : icurStr)
  83. ; icurStr = (ifqc > cpspch(7.11) ? 6 : icurStr)
  84. ipupos = ip8 * idlt / 2 ; pick up position (in % of low E string length)
  85. ippos = ip9 * idlt / 2 ; pluck position (in % of low E string length)
  86. isegF = 1 / sr
  87. isegF2 = ipluck
  88. iplkdelF = (ipluck / 2 > ippos ? 0 : ippos - ipluck / 2)
  89. isegB = 1 / sr
  90. isegB2 = ipluck
  91. iplkdelB = (ipluck / 2 > idlt / 2 - ippos ? 0 : idlt / 2 - ippos - ipluck / 2)
  92. ; EXCITATION SIGNAL GENERATION
  93. ; the two excitation signals are fed into the fwd delay represent the 1st and 2nd
  94. ; reflections off of the left boundary, and two accelerations fed into the bkwd delay
  95. ; represent the the 1st and 2nd reflections off of the right boundary.
  96. ; Likewise for the backward traveling acceleration waves, only they encouter the
  97. ; terminationsin the opposite order.
  98. ipw = 1
  99. ipamp = ip4 * ipluck ; 4 / ipluck
  100. aenvstrf linseg 0, isegF, -ipamp / 2, isegF2, 0
  101. adel1 delayr (idlt > 0) ? idlt : 0.01
  102. ; initial forward traveling wave (pluck to bridge)
  103. aenvstrf1 deltapi iplkdelF
  104. ; first forward traveling reflection (nut to bridge)
  105. aenvstrf2 deltapi iplkdelB + idlt / 2
  106. delayw aenvstrf
  107. ; inject noise for attack time string fret contact, and pre pluck vibrations against pick
  108. anoiz rand ibrightness
  109. aenvstrf1 = aenvstrf1 + anoiz*aenvstrf1
  110. aenvstrf2 = aenvstrf2 + anoiz*aenvstrf2
  111. ; filter to account for losses along loop path
  112. aenvstrf2 filter2 aenvstrf2, 3, 0, ia0, ia1, ia0
  113. ; combine into one signal (flip refl wave's phase)
  114. aenvstrf = aenvstrf1 - aenvstrf2
  115. ; initial backward excitation wave
  116. aenvstrb linseg 0, isegB, - ipamp / 2, isegB2, 0
  117. adel2 delayr (idlt > 0) ? idlt : 0.01
  118. ; initial bdwd traveling wave (pluck to nut)
  119. aenvstrb1 deltapi iplkdelB
  120. ; first forward traveling reflection (nut to bridge)
  121. aenvstrb2 deltapi idlt / 2 + iplkdelF
  122. delayw aenvstrb
  123. ; initial bdwd traveling wave (pluck to nut)
  124. ; aenvstrb1 delay aenvstrb, iplkdelB
  125. ; first bkwd traveling reflection (bridge to nut)
  126. ; aenvstrb2 delay aenvstrb, idlt/2+iplkdelF
  127. ; inject noise
  128. aenvstrb1 = aenvstrb1 + anoiz*aenvstrb1
  129. aenvstrb2 = aenvstrb2 + anoiz*aenvstrb2
  130. ; filter to account for losses along loop path
  131. aenvstrb2 filter2 aenvstrb2, 3, 0, ia0, ia1, ia0
  132. ; combine into one signal (flip refl wave's phase)
  133. aenvstrb = aenvstrb1 - aenvstrb2
  134. ; low pass to band limit initial accel signals to be < 1/2 the sampling freq
  135. ainputf tone aenvstrf, sr * 0.9 / 2
  136. ainputb tone aenvstrb, sr * 0.9 / 2
  137. ; additional lowpass filtering for pluck shaping\
  138. ; Note, it would be more efficient to combine stages into a single filter
  139. ainputf tone ainputf, sr * 0.9 / 2
  140. ainputb tone ainputb, sr * 0.9 / 2
  141. ; Vibrato generator
  142. icosine ftgenonce 0, 0, 65537, 11, 1.0
  143. avib poscil ivibDepth, ivibRate, icosine
  144. avibdl delayr (((ivibStDly * 1.1)) > 0.0) ? (ivibStDly * 1.1) : 0.01
  145. avibrato deltapi ivibStDly
  146. delayw avib
  147. ; Dual Delay line,
  148. ; NOTE: delay length longer than needed by a bit so that the output at t=idlt will be interpolated properly
  149. ;forward traveling wave delay line
  150. afd delayr (((idlt + ivibDepth) * 1.1) > 0.0) ? ((idlt + ivibDepth) * 1.1) : 0.01
  151. ; output tap point for fwd traveling wave
  152. afwav deltapi ipupos
  153. ; output at end of fwd delay (left string boundary)
  154. afwdout deltapi idlt - 1 / sr + avibrato
  155. ; lpf/attn due to reflection impedance
  156. afwdout filter2 afwdout, 3, 0, ia0, ia1, ia0
  157. delayw ainputf + afwdout * ifbfac * ifbfac
  158. ; backward trav wave delay line
  159. abkwd delayr (((idlt + ivibDepth) * 1.1) > 0) ? ((idlt + ivibDepth) * 1.1) : 0.01
  160. ; output tap point for bkwd traveling wave
  161. abkwav deltapi idlt / 2 - ipupos
  162. ; output at the left boundary
  163. ; abkterm deltapi idlt/2
  164. ; output at end of bkwd delay (right string boundary)
  165. abkdout deltapi idlt - 1 / sr + avibrato
  166. abkdout filter2 abkdout, 3, 0, ia0, ia1, ia0
  167. delayw ainputb + abkdout * ifbfac * ifbfac
  168. ; resonant body filter model, from Cuzzucoli and Lombardo
  169. ; IIR filter derived via bilinear transform method
  170. ; the theoretical resonances resulting from circuit model should be:
  171. ; resonance due to the air volume + soundhole = 110Hz (strongest)
  172. ; resonance due to the top plate = 220Hz
  173. ; resonance due to the inclusion of the back plate = 400Hz (weakest)
  174. aresbod filter2 (afwdout + abkdout), 5, 4, 0.000000000005398681501844749, .00000000000001421085471520200, -.00000000001076383426834582, -00000000000001110223024625157, .000000000005392353230604385, -3.990098622573566, 5.974971737738533, -3.979630684599723, .9947612723736902
  175. asig = (1500 * (afwav + abkwav + aresbod * .000000000000000000003)) * adamping
  176. aleft, aright Pan p7, asig
  177. outleta "leftout", aleft
  178. outleta "rightout", aright
  179. endin