You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clm-ins.scm 119KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
  1. ;;; CLM instruments translated to Snd/Scheme
  2. (provide 'snd-clm-ins.scm)
  3. (if (provided? 'snd)
  4. (require snd-ws.scm)
  5. (require sndlib-ws.scm))
  6. (require snd-env.scm snd-dsp.scm snd-fullmix.scm snd-expandn.scm)
  7. ;;; -------- pluck
  8. ;;;
  9. ;;; The Karplus-Strong algorithm as extended by David Jaffe and Julius Smith -- see
  10. ;;; Jaffe and Smith, "Extensions of the Karplus-Strong Plucked-String Algorithm"
  11. ;;; CMJ vol 7 no 2 Summer 1983, reprinted in "The Music Machine".
  12. ;;; translated from CLM's pluck.ins
  13. (definstrument (pluck start dur freq amp (weighting .5) (lossfact .9))
  14. "(pluck start dur freq amp weighting lossfact) implements the Jaffe-Smith plucked string physical model.
  15. 'weighting' is the ratio of the once-delayed to the twice-delayed samples. It defaults to .5=shortest decay.
  16. Anything other than .5 = longer decay. Must be between 0 and less than 1.0.
  17. 'lossfact' can be used to shorten decays. Most useful values are between .8 and 1.0. (with-sound () (pluck 0 1 330 .3 .7 .995))"
  18. (define (tuneIt f s1)
  19. (define (getOptimumC S o p)
  20. (let* ((pa (* (/ 1.0 o) (atan (* S (sin o)) (- (+ 1.0 (* S (cos o))) S))))
  21. (tmpInt (floor (- p pa)))
  22. (pc (- p pa tmpInt)))
  23. (if (< pc .1)
  24. (do ()
  25. ((>= pc .1))
  26. (set! tmpInt (- tmpInt 1))
  27. (set! pc (+ pc 1.0))))
  28. (list tmpInt (/ (- (sin o) (sin (* o pc))) (sin (+ o (* o pc)))))))
  29. (let ((p (/ *clm-srate* f)) ;period as float
  30. (s (if (= s1 0.0) 0.5 s1))
  31. (o (hz->radians f)))
  32. (let ((vals (getOptimumC s o p))
  33. (vals1 (getOptimumC (- 1.0 s) o p)))
  34. (if (and (not (= s 1/2))
  35. (< (abs (cadr vals)) (abs (cadr vals1))))
  36. (list (- 1.0 s) (cadr vals) (car vals))
  37. (list s (cadr vals1) (car vals1))))))
  38. (let ((vals (tuneIt freq weighting)))
  39. (let ((wt0 (car vals))
  40. (c (cadr vals))
  41. (dlen (caddr vals))
  42. (beg (seconds->samples start))
  43. (end (seconds->samples (+ start dur)))
  44. (lf (if (= lossfact 0.0) 1.0 (min 1.0 lossfact))))
  45. (let ((wt (if (= wt0 0.0) 0.5 (min 1.0 wt0)))
  46. (tab (make-float-vector dlen)))
  47. ;; get initial waveform in "tab" -- here we can introduce 0's to simulate different pick
  48. ;; positions, and so on -- see the CMJ article for numerous extensions. The normal case
  49. ;; is to load it with white noise (between -1 and 1).
  50. (let ((allp (make-one-zero (* lf (- 1.0 wt)) (* lf wt)))
  51. (feedb (make-one-zero c 1.0)) ;or (feedb (make-one-zero 1.0 c))
  52. (c1 (- 1.0 c)))
  53. (do ((i 0 (+ i 1)))
  54. ((= i dlen))
  55. (float-vector-set! tab i (mus-random 1.0)))
  56. (do ((i beg (+ i 1))
  57. (ctr 0 (modulo (+ ctr 1) dlen)))
  58. ((= i end))
  59. (outa i (* amp (float-vector-set! tab ctr (* c1 (one-zero feedb (one-zero allp (float-vector-ref tab ctr)))))))))))))
  60. #|
  61. (let ((val (float-vector-ref tab ctr))) ;current output value
  62. (float-vector-set! tab ctr (* c1 (one-zero feedb (one-zero allp val))))
  63. (outa i (* amp val)))))))))
  64. |#
  65. ;;; -------- mlbvoi
  66. ;;;
  67. ;;; translation from MUS10 of Marc LeBrun's waveshaping voice instrument (using FM here)
  68. ;;; this version translated (and simplified slightly) from CLM's mlbvoi.ins
  69. (definstrument (vox beg dur freq amp ampfun freqfun freqscl phonemes formant-amps formant-indices (vibscl .1) (deg 0) (pcrev 0))
  70. (define (vox-fun phons which)
  71. (let ((formants
  72. '((I 390 1990 2550) (E 530 1840 2480) (AE 660 1720 2410)
  73. (UH 520 1190 2390) (A 730 1090 2440) (OW 570 840 2410)
  74. (U 440 1020 2240) (OO 300 870 2240) (ER 490 1350 1690)
  75. (W 300 610 2200) (LL 380 880 2575) (R 420 1300 1600)
  76. (Y 300 2200 3065) (EE 260 3500 3800) (LH 280 1450 1600)
  77. (L 300 1300 3000) (I2 350 2300 3340) (B 200 800 1750)
  78. (D 300 1700 2600) (G 250 1350 2000) (M 280 900 2200)
  79. (N 280 1700 2600) (NG 280 2300 2750) (P 300 800 1750)
  80. (T 200 1700 2600) (K 350 1350 2000) (F 175 900 4400)
  81. (TH 200 1400 2200) (S 200 1300 2500) (SH 200 1800 2000)
  82. (V 175 1100 2400) (THE 200 1600 2200)(Z 200 1300 2500)
  83. (ZH 175 1800 2000) (ZZ 900 2400 3800) (VV 565 1045 2400))))
  84. ;;formant center frequencies for a male speaker
  85. (define (find-phoneme phoneme forms)
  86. (if (eq? phoneme (caar forms))
  87. (cdar forms)
  88. (find-phoneme phoneme (cdr forms))))
  89. (let ((f1 ())
  90. (len (length phons)))
  91. (do ((i 0 (+ i 2)))
  92. ((>= i len))
  93. (set! f1 (cons ((find-phoneme (phons (+ i 1)) formants) which) (cons (phons i) f1))))
  94. (reverse f1))))
  95. (let ((start (seconds->samples beg))
  96. (end (seconds->samples (+ beg dur)))
  97. (car-os (make-oscil 0))
  98. (fs (length formant-amps))
  99. (per-vib (make-triangle-wave :frequency 6 :amplitude (hz->radians (* freq vibscl))))
  100. (ran-vib (make-rand-interp :frequency 20 :amplitude (hz->radians (* freq .5 vibscl))))
  101. (freqf (make-env freqfun :duration dur :scaler (hz->radians (* freqscl freq)) :offset (hz->radians freq))))
  102. (if (and (= fs 3)
  103. (= (channels *output*) 1))
  104. ;; optimize the common case
  105. (let ((a0 (make-env ampfun :scaler (* amp (formant-amps 0)) :duration dur))
  106. (a1 (make-env ampfun :scaler (* amp (formant-amps 1)) :duration dur))
  107. (a2 (make-env ampfun :scaler (* amp (formant-amps 2)) :duration dur))
  108. (o0 (make-oscil 0.0))
  109. (o1 (make-oscil 0.0))
  110. (o2 (make-oscil 0.0))
  111. (e0 (make-oscil 0.0))
  112. (e1 (make-oscil 0.0))
  113. (e2 (make-oscil 0.0))
  114. (ind0 (formant-indices 0))
  115. (ind1 (formant-indices 1))
  116. (ind2 (formant-indices 2))
  117. (f0 (make-env (vox-fun phonemes 0) :scaler (hz->radians 1.0) :duration dur))
  118. (f1 (make-env (vox-fun phonemes 1) :scaler (hz->radians 1.0) :duration dur))
  119. (f2 (make-env (vox-fun phonemes 2) :scaler (hz->radians 1.0) :duration dur)))
  120. (do ((i start (+ i 1)))
  121. ((= i end))
  122. (let* ((frq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
  123. (carg (oscil car-os frq))
  124. (frm0 (/ (env f0) frq))
  125. (frm1 (/ (env f1) frq))
  126. (frm2 (/ (env f2) frq)))
  127. (outa i (+
  128. (* (env a0)
  129. (+ (* (even-weight frm0) (oscil e0 (+ (* ind0 carg) (even-multiple frm0 frq))))
  130. (* (odd-weight frm0) (oscil o0 (+ (* ind0 carg) (odd-multiple frm0 frq))))))
  131. (* (env a1)
  132. (+ (* (even-weight frm1) (oscil e1 (+ (* ind1 carg) (even-multiple frm1 frq))))
  133. (* (odd-weight frm1) (oscil o1 (+ (* ind1 carg) (odd-multiple frm1 frq))))))
  134. (* (env a2)
  135. (+ (* (even-weight frm2) (oscil e2 (+ (* ind2 carg) (even-multiple frm2 frq))))
  136. (* (odd-weight frm2) (oscil o2 (+ (* ind2 carg) (odd-multiple frm2 frq)))))))))))
  137. (let ((evens (make-vector fs))
  138. (odds (make-vector fs))
  139. (ampfs (make-vector fs))
  140. (indices (make-float-vector fs))
  141. (frmfs (make-vector fs))
  142. (carrier 0.0)
  143. (frm-int 0)
  144. (rfrq 0.0)
  145. (frm0 0.0)
  146. (frac 0.0)
  147. (fracf 0.0)
  148. (loc (make-locsig deg 1.0 pcrev)))
  149. (do ((i 0 (+ i 1)))
  150. ((= i fs))
  151. (set! (evens i) (make-oscil 0))
  152. (set! (odds i) (make-oscil 0))
  153. (set! (ampfs i) (make-env ampfun :scaler (* amp (formant-amps i)) :duration dur))
  154. (set! (indices i) (formant-indices i))
  155. (set! (frmfs i) (make-env (vox-fun phonemes i) :scaler (hz->radians 1.0) :duration dur)))
  156. (if (= fs 3)
  157. (let ((frmfs0 (frmfs 0)) (frmfs1 (frmfs 1)) (frmfs2 (frmfs 2))
  158. (index0 (indices 0)) (index1 (indices 1)) (index2 (indices 2))
  159. (ampfs0 (ampfs 0)) (ampfs1 (ampfs 1)) (ampfs2 (ampfs 2))
  160. (evens0 (evens 0)) (evens1 (evens 1)) (evens2 (evens 2))
  161. (odds0 (odds 0)) (odds1 (odds 1)) (odds2 (odds 2)))
  162. (do ((i start (+ i 1)))
  163. ((= i end))
  164. (set! rfrq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
  165. (set! carrier (oscil car-os rfrq))
  166. (set! frm0 (/ (env frmfs0) rfrq))
  167. (set! frm-int (floor frm0))
  168. (set! frac (- frm0 frm-int))
  169. (set! fracf (+ (* index0 carrier) (* frm-int rfrq)))
  170. (locsig loc i
  171. (* (env ampfs0)
  172. (if (even? frm-int)
  173. (+ (* (- 1.0 frac) (oscil evens0 fracf)) (* frac (oscil odds0 (+ fracf rfrq))))
  174. (+ (* frac (oscil evens0 (+ fracf rfrq))) (* (- 1.0 frac) (oscil odds0 fracf))))))
  175. (set! frm0 (/ (env frmfs1) rfrq))
  176. (set! frm-int (floor frm0))
  177. (set! frac (- frm0 frm-int))
  178. (set! fracf (+ (* index1 carrier) (* frm-int rfrq)))
  179. (locsig loc i
  180. (* (env ampfs1)
  181. (if (even? frm-int)
  182. (+ (* (- 1.0 frac) (oscil evens1 fracf)) (* frac (oscil odds1 (+ fracf rfrq))))
  183. (+ (* frac (oscil evens1 (+ fracf rfrq))) (* (- 1.0 frac) (oscil odds1 fracf))))))
  184. (set! frm0 (/ (env frmfs2) rfrq))
  185. (set! frm-int (floor frm0))
  186. (set! frac (- frm0 frm-int))
  187. (set! fracf (+ (* index2 carrier) (* frm-int rfrq)))
  188. (locsig loc i
  189. (* (env ampfs2)
  190. (if (even? frm-int)
  191. (+ (* (- 1.0 frac) (oscil evens2 fracf)) (* frac (oscil odds2 (+ fracf rfrq))))
  192. (+ (* frac (oscil evens2 (+ fracf rfrq))) (* (- 1.0 frac) (oscil odds2 fracf))))))))
  193. (do ((i start (+ i 1)))
  194. ((= i end))
  195. (set! rfrq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
  196. (set! carrier (oscil car-os rfrq)) ; better name: modulator or perhaps perceived-carrier?
  197. (do ((k 0 (+ k 1)))
  198. ((= k fs))
  199. (set! frm0 (/ (env (vector-ref frmfs k)) rfrq))
  200. (set! frm-int (floor frm0))
  201. (set! frac (- frm0 frm-int))
  202. (set! fracf (+ (* (float-vector-ref indices k) carrier) (* frm-int rfrq)))
  203. (locsig loc i
  204. (* (env (vector-ref ampfs k))
  205. (if (even? frm-int)
  206. (+ (* (- 1.0 frac) (oscil (vector-ref evens k) fracf))
  207. (* frac (oscil (vector-ref odds k) (+ fracf rfrq))))
  208. (+ (* frac (oscil (vector-ref evens k) (+ fracf rfrq)))
  209. (* (- 1.0 frac) (oscil (vector-ref odds k) fracf)))))))))))))
  210. ;;; (with-sound (:statistics #t) (vox 0 2 170 .4 '(0 0 25 1 75 1 100 0) '(0 0 5 .5 10 0 100 1) .1 '(0 E 25 AE 35 ER 65 ER 75 I 100 UH) '(.8 .15 .05) '(.005 .0125 .025) .05 .1))
  211. ;;; (with-sound () (vox 0 2 300 .4 '(0 0 25 1 75 1 100 0) '(0 0 5 .5 10 0 100 1) .1 '(0 I 5 OW 10 I 50 AE 100 OO) '(.8 .15 .05) '(.05 .0125 .025) .02 .1))
  212. ;;; (with-sound () (vox 0 5 600 .4 '(0 0 25 1 75 1 100 0) '(0 0 5 .5 10 0 100 1) .1 '(0 I 5 OW 10 I 50 AE 100 OO) '(.8 .16 .04) '(.01 .01 .1) .01 .1))
  213. ;;; -------- PQWVOX
  214. ;;; translation of CLM pqwvox.ins (itself translated from MUS10 of MLB's waveshaping voice instrument (using phase quadrature waveshaping))
  215. (definstrument (pqw-vox beg dur freq spacing-freq amp ampfun freqfun freqscl phonemes formant-amps formant-shapes)
  216. "(pqw-vox beg dur freq spacing-freq amp ampfun freqfun freqscl phonemes formant-amps formant-shapes) produces
  217. vocal sounds using phase quadrature waveshaping"
  218. (letrec ((vox-fun
  219. (let ((formants '((I 390 1990 2550) (E 530 1840 2480) (AE 660 1720 2410)
  220. (UH 520 1190 2390) (A 730 1090 2440) (OW 570 840 2410)
  221. (U 440 1020 2240) (OO 300 870 2240) (ER 490 1350 1690)
  222. (W 300 610 2200) (LL 380 880 2575) (R 420 1300 1600)
  223. (Y 300 2200 3065) (EE 260 3500 3800) (LH 280 1450 1600)
  224. (L 300 1300 3000) (I2 350 2300 3340) (B 200 800 1750)
  225. (D 300 1700 2600) (G 250 1350 2000) (M 280 900 2200)
  226. (N 280 1700 2600) (NG 280 2300 2750) (P 300 800 1750)
  227. (T 200 1700 2600) (K 350 1350 2000) (F 175 900 4400)
  228. (TH 200 1400 2200) (S 200 1300 2500) (SH 200 1800 2000)
  229. (V 175 1100 2400) (THE 200 1600 2200)(Z 200 1300 2500)
  230. (ZH 175 1800 2000) (ZZ 900 2400 3800) (VV 565 1045 2400))))
  231. ;; formant center frequencies for a male speaker
  232. (lambda (phons which newenv)
  233. ;; make an envelope from which-th entry of phoneme data referred to by phons
  234. (if (null? phons)
  235. newenv
  236. (vox-fun (cddr phons) which
  237. (append newenv
  238. (list (car phons)
  239. ((let find-phoneme ((phoneme (cadr phons))
  240. (form formants))
  241. (if (eq? (caar form) phoneme)
  242. (cdar form)
  243. (find-phoneme phoneme (cdr form))))
  244. which)))))))))
  245. (let ((start (seconds->samples beg))
  246. (end (seconds->samples (+ beg dur)))
  247. (car-sin (make-oscil 0))
  248. (car-cos (make-oscil 0 :initial-phase (/ pi 2.0)))
  249. (frq-ratio (/ spacing-freq freq))
  250. (fs (length formant-amps))
  251. (freqf (make-env freqfun :duration dur :scaler (* freqscl freq) :offset freq))
  252. (per-vib (make-triangle-wave :frequency 6.0 :amplitude (* freq .1)))
  253. (ran-vib (make-rand-interp :frequency 20.0 :amplitude (* freq .05))))
  254. (let ((sin-evens (make-vector fs))
  255. (cos-evens (make-vector fs))
  256. (sin-odds (make-vector fs))
  257. (cos-odds (make-vector fs))
  258. (ampfs (make-vector fs))
  259. (frmfs (make-vector fs))
  260. (sin-coeffs (make-vector fs))
  261. (cos-coeffs (make-vector fs))
  262. (frq 0.0) (rfrq 0.0) (carcos 0.0) (carsin 0.0)
  263. (frac 0.0) (fracf 0.0) (frm0 0.0) (frm-int 0) (fax 0.0) (yfax 0.0))
  264. (do ((i 0 (+ i 1)))
  265. ((= i fs))
  266. (let ((shape (normalize-partials (formant-shapes i))))
  267. (set! (sin-evens i) (make-oscil 0))
  268. (set! (sin-odds i) (make-oscil 0))
  269. (set! (cos-evens i) (make-oscil 0 :initial-phase (/ pi 2.0)))
  270. (set! (cos-odds i) (make-oscil 0 :initial-phase (/ pi 2.0)))
  271. (set! (ampfs i) (make-env ampfun :scaler (* amp (formant-amps i)) :duration dur))
  272. (set! (cos-coeffs i) (partials->polynomial shape mus-chebyshev-first-kind))
  273. (set! (sin-coeffs i) (partials->polynomial shape mus-chebyshev-second-kind))
  274. (set! (frmfs i) (make-env (vox-fun phonemes i ()) :duration dur))))
  275. (if (= fs 3) ; unroll the inner loop in the most common case
  276. (let ((frmfs0 (frmfs 0)) (frmfs1 (frmfs 1)) (frmfs2 (frmfs 2))
  277. (ampfs0 (ampfs 0)) (ampfs1 (ampfs 1)) (ampfs2 (ampfs 2))
  278. (sin-evens0 (sin-evens 0)) (sin-evens1 (sin-evens 1)) (sin-evens2 (sin-evens 2))
  279. (sin-odds0 (sin-odds 0)) (sin-odds1 (sin-odds 1)) (sin-odds2 (sin-odds 2))
  280. (cos-evens0 (cos-evens 0)) (cos-evens1 (cos-evens 1)) (cos-evens2 (cos-evens 2))
  281. (cos-odds0 (cos-odds 0)) (cos-odds1 (cos-odds 1)) (cos-odds2 (cos-odds 2))
  282. (cos-coeffs0 (cos-coeffs 0)) (cos-coeffs1 (cos-coeffs 1)) (cos-coeffs2 (cos-coeffs 2))
  283. (sin-coeffs0 (sin-coeffs 0)) (sin-coeffs1 (sin-coeffs 1)) (sin-coeffs2 (sin-coeffs 2)))
  284. (do ((i start (+ i 1)))
  285. ((= i end))
  286. (set! frq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
  287. (set! rfrq (hz->radians frq))
  288. (set! carsin (oscil car-sin (* rfrq frq-ratio)))
  289. (set! carcos (oscil car-cos (* rfrq frq-ratio)))
  290. (set! frm0 (/ (env frmfs0) frq))
  291. (set! frm-int (floor frm0))
  292. (set! frac (- frm0 frm-int))
  293. (set! fracf (* frm-int rfrq))
  294. (set! fax (polynomial cos-coeffs0 carcos))
  295. (set! yfax (* carsin (polynomial sin-coeffs0 carcos)))
  296. (outa i
  297. (* (env ampfs0)
  298. (if (even? frm-int)
  299. (+ (* (- 1.0 frac) (- (* yfax (oscil sin-evens0 fracf)) (* fax (oscil cos-evens0 fracf))))
  300. (* frac (- (* yfax (oscil sin-odds0 (+ fracf rfrq))) (* fax (oscil cos-odds0 (+ fracf rfrq))))))
  301. (+ (* frac (- (* yfax (oscil sin-evens0 (+ fracf rfrq))) (* fax (oscil cos-evens0 (+ fracf rfrq)))))
  302. (* (- 1.0 frac) (- (* yfax (oscil sin-odds0 fracf)) (* fax (oscil cos-odds0 fracf))))))))
  303. (set! frm0 (/ (env frmfs1) frq))
  304. (set! frm-int (floor frm0))
  305. (set! frac (- frm0 frm-int))
  306. (set! fracf (* frm-int rfrq))
  307. (set! fax (polynomial cos-coeffs1 carcos))
  308. (set! yfax (* carsin (polynomial sin-coeffs1 carcos)))
  309. (outa i
  310. (* (env ampfs1)
  311. (if (even? frm-int)
  312. (+ (* (- 1.0 frac) (- (* yfax (oscil sin-evens1 fracf)) (* fax (oscil cos-evens1 fracf))))
  313. (* frac (- (* yfax (oscil sin-odds1 (+ fracf rfrq))) (* fax (oscil cos-odds1 (+ fracf rfrq))))))
  314. (+ (* frac (- (* yfax (oscil sin-evens1 (+ fracf rfrq))) (* fax (oscil cos-evens1 (+ fracf rfrq)))))
  315. (* (- 1.0 frac) (- (* yfax (oscil sin-odds1 fracf)) (* fax (oscil cos-odds1 fracf))))))))
  316. (set! frm0 (/ (env frmfs2) frq))
  317. (set! frm-int (floor frm0))
  318. (set! frac (- frm0 frm-int))
  319. (set! fracf (* frm-int rfrq))
  320. (set! fax (polynomial cos-coeffs2 carcos))
  321. (set! yfax (* carsin (polynomial sin-coeffs2 carcos)))
  322. (outa i
  323. (* (env ampfs2)
  324. (if (even? frm-int)
  325. (+ (* (- 1.0 frac) (- (* yfax (oscil sin-evens2 fracf)) (* fax (oscil cos-evens2 fracf))))
  326. (* frac (- (* yfax (oscil sin-odds2 (+ fracf rfrq))) (* fax (oscil cos-odds2 (+ fracf rfrq))))))
  327. (+ (* frac (- (* yfax (oscil sin-evens2 (+ fracf rfrq))) (* fax (oscil cos-evens2 (+ fracf rfrq)))))
  328. (* (- 1.0 frac) (- (* yfax (oscil sin-odds2 fracf)) (* fax (oscil cos-odds2 fracf))))))))))
  329. (do ((i start (+ i 1)))
  330. ((= i end))
  331. (set! frq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
  332. (set! rfrq (hz->radians frq))
  333. (set! carsin (oscil car-sin (* rfrq frq-ratio)))
  334. (set! carcos (oscil car-cos (* rfrq frq-ratio)))
  335. (do ((k 0 (+ k 1)))
  336. ((= k fs))
  337. (set! frm0 (/ (env (vector-ref frmfs k)) frq))
  338. (set! frm-int (floor frm0))
  339. (set! frac (- frm0 frm-int))
  340. (set! fracf (* frm-int rfrq))
  341. (set! fax (polynomial (vector-ref cos-coeffs k) carcos))
  342. (set! yfax (* carsin (polynomial (vector-ref sin-coeffs k) carcos)))
  343. (outa i (* (env (vector-ref ampfs k))
  344. (if (even? frm-int)
  345. (+ (* (- 1.0 frac) (- (* yfax (oscil (vector-ref sin-evens k) fracf))
  346. (* fax (oscil (vector-ref cos-evens k) fracf))))
  347. (* frac (- (* yfax (oscil (vector-ref sin-odds k) (+ fracf rfrq)))
  348. (* fax (oscil (vector-ref cos-odds k) (+ fracf rfrq))))))
  349. (+ (* frac (- (* yfax (oscil (vector-ref sin-evens k) (+ fracf rfrq)))
  350. (* fax (oscil (vector-ref cos-evens k) (+ fracf rfrq)))))
  351. (* (- 1.0 frac) (- (* yfax (oscil (vector-ref sin-odds k) fracf))
  352. (* fax (oscil (vector-ref cos-odds k) fracf)))))))))))))))
  353. ;;; (with-sound (:statistics #t) (pqw-vox 0 1 300 300 .1 '(0 0 50 1 100 0) '(0 0 100 0) 0 '(0 L 100 L) '(.33 .33 .33) '((1 1 2 .5) (1 .5 2 .5 3 1) (1 1 4 .5))))
  354. ;;; (a test to see if the cancellation is working -- sounds like a mosquito)
  355. ;;; (with-sound () (pqw-vox 0 2 200 200 .1 '(0 0 50 1 100 0) '(0 0 100 1) .1 '(0 UH 100 ER) '(.8 .15 .05) '((1 1 2 .5) (1 1 2 .5 3 .2 4 .1) (1 1 3 .1 4 .5))))
  356. ;;; (with-sound () (pqw-vox 0 2 100 314 .1 '(0 0 50 1 100 0) '(0 0 100 1) .1 '(0 UH 100 ER) '(.8 .15 .05) '((1 1 2 .5) (1 1 2 .5 3 .2 4 .1) (1 1 3 .1 4 .5))))
  357. ;;; (with-sound () (pqw-vox 0 2 200 314 .1 '(0 0 50 1 100 0) '(0 0 100 1) .01 '(0 UH 100 ER) '(.8 .15 .05) '((1 1 2 .5) (1 1 4 .1) (1 1 2 .1 4 .05))))
  358. ;;; (with-sound () (pqw-vox 0 2 100 414 .2 '(0 0 50 1 100 0) '(0 0 100 1) .01 '(0 OW 50 E 100 ER) '(.8 .15 .05) '((1 1 2 .5 3 .1 4 .01) (1 1 4 .1) (1 1 2 .1 4 .05))))
  359. ;;; -------- FOF
  360. (definstrument (fofins beg dur frq amp vib f0 a0 f1 a1 f2 a2 (ae '(0 0 25 1 75 1 100 0)) ve)
  361. "(fofins beg dur frq amp vib f0 a0 f1 a1 f2 a2 (ampenv '(0 0 25 1 75 1 100 0)) vibenv) produces FOF
  362. synthesis: (fofins 0 1 270 .2 .001 730 .6 1090 .3 2440 .1)"
  363. (let ((foflen (if (= *clm-srate* 22050) 100 200)))
  364. (let ((start (seconds->samples beg))
  365. (end (seconds->samples (+ beg dur)))
  366. (ampf (make-env ae :scaler amp :duration dur))
  367. (vibf (make-env (or ve '(0 1 100 1)) :scaler vib :duration dur))
  368. (frq0 (hz->radians f0))
  369. (frq1 (hz->radians f1))
  370. (frq2 (hz->radians f2))
  371. (vibr (make-oscil 6))
  372. (win-freq (/ (* 2.0 pi) foflen))
  373. (wt0 (make-wave-train :size foflen :frequency frq)))
  374. (let ((foftab (mus-data wt0)))
  375. (do ((i 0 (+ i 1)))
  376. ((= i foflen))
  377. (float-vector-set! foftab i (* (+ (* a0 (sin (* i frq0)))
  378. (* a1 (sin (* i frq1)))
  379. (* a2 (sin (* i frq2))))
  380. .5 (- 1.0 (cos (* i win-freq)))))))
  381. (do ((i start (+ i 1)))
  382. ((= i end))
  383. (outa i (* (env ampf)
  384. (wave-train wt0 (* (env vibf)
  385. (oscil vibr)))))))))
  386. ;;; FM TRUMPET ---------------------------------------------------
  387. ;;; Dexter Morrill's FM-trumpet:
  388. ;;; from CMJ feb 77 p51
  389. (definstrument (fm-trumpet startime dur
  390. (frq1 250.0)
  391. (frq2 1500.0)
  392. (amp1 0.5)
  393. (amp2 0.1)
  394. (ampatt1 0.03)
  395. (ampdec1 0.35)
  396. (ampatt2 0.03)
  397. (ampdec2 0.3)
  398. (modfrq1 250.0)
  399. (modind11 0.0)
  400. (modind12 2.66)
  401. (modfrq2 250.0)
  402. (modind21 0.0)
  403. (modind22 1.8)
  404. (rvibamp 0.007)
  405. (rvibfrq 125.0)
  406. (vibamp 0.007)
  407. (vibfrq 7.0)
  408. (vibatt 0.6)
  409. (vibdec 0.2)
  410. (frqskw 0.03)
  411. (frqatt 0.06)
  412. (ampenv1 '(0 0 25 1 75 .9 100 0))
  413. (ampenv2 '(0 0 25 1 75 .9 100 0))
  414. (indenv1 '(0 0 25 1 75 .9 100 0))
  415. (indenv2 '(0 0 25 1 75 .9 100 0))
  416. (degree 0.0)
  417. (distance 1.0)
  418. (reverb-amount 0.005))
  419. (let ((dec-01 (max 75 (* 100 (- 1.0 (/ .01 dur))))))
  420. (let ((beg (seconds->samples startime))
  421. (end (seconds->samples (+ startime dur)))
  422. (loc (make-locsig degree distance reverb-amount))
  423. (per-vib-f (let ((vibe (stretch-envelope '(0 1 25 .1 75 0 100 0)
  424. 25 (min (* 100 (/ vibatt dur)) 45)
  425. 75 (max (* 100 (- 1.0 (/ vibdec dur))) 55))))
  426. (make-env vibe :scaler vibamp :duration dur)))
  427. (ran-vib (make-rand-interp :frequency rvibfrq :amplitude rvibamp))
  428. (per-vib (make-oscil vibfrq))
  429. (frq-f (let ((frqe (stretch-envelope '(0 0 25 1 75 1 100 0)
  430. 25 (min 25 (* 100 (/ frqatt dur)))
  431. 75 dec-01)))
  432. (make-env frqe :scaler frqskw :offset 1.0 :duration dur)))
  433. (ampattpt1 (min 25 (* 100 (/ ampatt1 dur))))
  434. (ampdecpt1 (max 75 (* 100 (- 1.0 (/ ampdec1 dur)))))
  435. (ampattpt2 (min 25 (* 100 (/ ampatt2 dur))))
  436. (ampdecpt2 (max 75 (* 100 (- 1.0 (/ ampdec2 dur))))))
  437. (let ((mod1-f (make-env (stretch-envelope indenv1 25 ampattpt1 75 dec-01)
  438. :scaler (* modfrq1 (- modind12 modind11)) :duration dur))
  439. (mod1 (make-oscil 0.0))
  440. (car1 (make-oscil 0.0))
  441. ;; set frequency to zero here because it is handled multiplicatively below
  442. (car1-f (make-env (stretch-envelope ampenv1 25 ampattpt1 75 ampdecpt1)
  443. :scaler amp1 :duration dur))
  444. (mod2-f (make-env (stretch-envelope indenv2 25 ampattpt2 75 dec-01)
  445. :scaler (* modfrq2 (- modind22 modind21)) :duration dur))
  446. (mod2 (make-oscil 0.0))
  447. (car2 (make-oscil 0.0))
  448. (car2-f (make-env (stretch-envelope ampenv2 25 ampattpt2 75 ampdecpt2)
  449. :scaler amp2 :duration dur)))
  450. (do ((i beg (+ i 1)))
  451. ((= i end))
  452. (let ((frq-change (hz->radians (* (+ 1.0 (rand-interp ran-vib))
  453. (+ 1.0 (* (env per-vib-f) (oscil per-vib)))
  454. (env frq-f)))))
  455. (locsig loc i (+ (* (env car1-f)
  456. (oscil car1 (* frq-change
  457. (+ frq1 (* (env mod1-f)
  458. (oscil mod1 (* modfrq1 frq-change)))))))
  459. (* (env car2-f)
  460. (oscil car2 (* frq-change
  461. (+ frq2 (* (env mod2-f)
  462. (oscil mod2 (* modfrq2 frq-change)))))))))))))))
  463. ;;; -------- STEREO-FLUTE
  464. (definstrument (stereo-flute start dur freq flow
  465. (flow-envelope '(0 1 100 1))
  466. (decay 0.01) ; additional time for instrument to decay
  467. (noise 0.0356)
  468. (embouchure-size 0.5)
  469. (fbk-scl1 0.5) ; these two are crucial for good results
  470. (fbk-scl2 0.55)
  471. (offset-pos 0.764264) ; from 0.0 to 1.0 along the bore
  472. (out-scl 1.0)
  473. (a0 0.7) (b1 -0.3) ; filter coefficients
  474. (vib-rate 5) (vib-amount 0.03)
  475. (ran-rate 5) (ran-amount 0.03))
  476. "(stereo-flute dur freq flow
  477. (flow-envelope '(0 1 100 1)) (decay 0.01)
  478. (noise 0.0356) (embouchure-size 0.5) (fbk-scl1 0.5)
  479. (fbk-scl2 0.55) (offset-pos 0.764264) (out-scl 1.0)
  480. (a0 0.7) (b1 -0.3) (vib-rate 5) (vib-amount 0.03)
  481. (ran-rate 5) (ran-amount 0.03))
  482. is a physical model of a flute:
  483. (stereo-flute 0 1 440 .55 :flow-envelope '(0 0 1 1 2 1 3 0))"
  484. (let ((period-samples (floor (/ *clm-srate* freq))))
  485. (let ((embouchure-samples (floor (* embouchure-size period-samples))))
  486. (let ((current-excitation 0.0)
  487. (current-difference 0.0)
  488. (current-flow 0.0)
  489. (out-sig 0.0)
  490. (tap-sig 0.0)
  491. (previous-out-sig 0.0)
  492. (previous-tap-sig 0.0)
  493. (dc-blocked-a 0.0)
  494. (dc-blocked-b 0.0)
  495. (previous-dc-blocked-a 0.0)
  496. (previous-dc-blocked-b 0.0)
  497. (delay-sig 0.0)
  498. (emb-sig 0.0)
  499. (beg (seconds->samples start))
  500. (end (seconds->samples (+ start dur)))
  501. (flowf (make-env flow-envelope
  502. :scaler flow
  503. :duration (- dur decay)))
  504. (periodic-vibrato (make-oscil vib-rate))
  505. (random-vibrato (make-rand-interp :frequency ran-rate :amplitude ran-amount))
  506. (breath (make-rand :frequency (/ *clm-srate* 2) :amplitude noise))
  507. (embouchure (make-delay embouchure-samples :initial-element 0.0))
  508. (bore (make-delay period-samples))
  509. (offset (floor (* period-samples offset-pos)))
  510. (reflection-lowpass-filter (make-one-pole a0 b1)))
  511. (do ((i beg (+ i 1)))
  512. ((= i end))
  513. (set! delay-sig (delay bore out-sig))
  514. (set! emb-sig (delay embouchure current-difference))
  515. (set! current-flow (+ (* vib-amount (oscil periodic-vibrato))
  516. (rand-interp random-vibrato)
  517. (env flowf)))
  518. (set! current-difference
  519. (+ current-flow
  520. (* current-flow (rand breath))
  521. (* fbk-scl1 delay-sig)))
  522. (set! current-excitation (- emb-sig (* emb-sig emb-sig emb-sig)))
  523. (set! out-sig (one-pole reflection-lowpass-filter
  524. (+ current-excitation (* fbk-scl2 delay-sig))))
  525. (set! tap-sig (tap bore offset))
  526. ;; NB the DC blocker is not in the cicuit. It is applied to the out-sig
  527. ;; but the result is not fed back into the system.
  528. (set! dc-blocked-a (- (+ out-sig (* 0.995 previous-dc-blocked-a)) previous-out-sig))
  529. (set! dc-blocked-b (- (+ tap-sig (* 0.995 previous-dc-blocked-b)) previous-tap-sig))
  530. (outa i (* out-scl dc-blocked-a))
  531. (outb i (* out-scl dc-blocked-b))
  532. (set! previous-out-sig out-sig)
  533. (set! previous-dc-blocked-a dc-blocked-a)
  534. (set! previous-tap-sig tap-sig)
  535. (set! previous-dc-blocked-b dc-blocked-b))))))
  536. ;;; -------- FM-BELL
  537. (definstrument (fm-bell startime dur frequency amplitude amp-env index-env index)
  538. "(fm-bell startime dur frequency amplitude amp-env index-env index) mixes in one fm bell note"
  539. (let ((fmInd2 (hz->radians (* 4.0 (- 8.0 (/ frequency 50.0))))))
  540. (let ((beg (seconds->samples startime))
  541. ;(len (seconds->samples dur))
  542. (end (seconds->samples (+ startime dur)))
  543. (fmInd1 (hz->radians (* 32.0 frequency)))
  544. (fmInd3 (* fmInd2 0.705 (- 1.4 (/ frequency 250.0))))
  545. (fmInd4 (hz->radians (* 32.0 (- 20 (/ frequency 20)))))
  546. (mod1 (make-oscil (* frequency 2)))
  547. (mod2 (make-oscil (* frequency 1.41)))
  548. (mod3 (make-oscil (* frequency 2.82)))
  549. (mod4 (make-oscil (* frequency 2.4)))
  550. (car1 (make-oscil frequency))
  551. (car2 (make-oscil frequency))
  552. (car3 (make-oscil (* frequency 2.4)))
  553. (indf (make-env (or index-env
  554. '(0 1 2 1.1 25 .75 75 .5 100 .2))
  555. (or index 1.0) dur))
  556. (ampf (make-env (or amp-env
  557. '(0 0 .1 1 10 .6 25 .3 50 .15 90 .1 100 0))
  558. amplitude dur)))
  559. (do ((i beg (+ i 1)))
  560. ((= i end))
  561. (let ((fmenv (env indf)))
  562. (outa i (* (env ampf)
  563. (+ (oscil car1 (* fmenv fmInd1 (oscil mod1)))
  564. (* .15 (oscil car2 (* fmenv
  565. (+ (* fmInd2 (oscil mod2))
  566. (* fmInd3
  567. (oscil mod3))))))
  568. (* .15 (oscil car3 (* fmenv
  569. fmInd4
  570. (oscil mod4))))))))))))
  571. ;(define fbell '(0 1 2 1.1000 25 .7500 75 .5000 100 .2000 ))
  572. ;(define abell '(0 0 .1000 1 10 .6000 25 .3000 50 .1500 90 .1000 100 0 ))
  573. ;(fm-bell 0.0 1.0 220.0 .5 abell fbell 1.0)
  574. ;;; -------- FM_INSECT
  575. (definstrument (fm-insect startime dur frequency amplitude amp-env
  576. mod-freq mod-skew mod-freq-env mod-index mod-index-env
  577. fm-index fm-ratio
  578. (degree 0.0)
  579. (distance 1.0)
  580. (reverb-amount 0.005))
  581. (let ((beg (seconds->samples startime))
  582. (end (seconds->samples (+ startime dur)))
  583. (loc (make-locsig degree distance reverb-amount))
  584. (carrier (make-oscil frequency))
  585. (fm1-osc (make-oscil mod-freq))
  586. (fm2-osc (make-oscil (* fm-ratio frequency)))
  587. (ampf (make-env amp-env :scaler amplitude :duration dur))
  588. (indf (make-env mod-index-env :scaler (hz->radians mod-index) :duration dur))
  589. (modfrqf (make-env mod-freq-env :scaler (hz->radians mod-skew) :duration dur))
  590. (fm2-amp (hz->radians (* fm-index fm-ratio frequency))))
  591. (do ((i beg (+ i 1)))
  592. ((= i end))
  593. (let ((garble-in (* (env indf)
  594. (oscil fm1-osc (env modfrqf)))))
  595. (locsig loc i (* (env ampf)
  596. (oscil carrier (+ (* fm2-amp (oscil fm2-osc garble-in))
  597. garble-in))))))))
  598. #|
  599. (with-sound (:srate 22050)
  600. (let ((locust '(0 0 40 1 95 1 100 .5))
  601. (bug_hi '(0 1 25 .7 75 .78 100 1))
  602. (amp '(0 0 25 1 75 .7 100 0)))
  603. (fm-insect 0 1.699 4142.627 .015 amp 60 -16.707 locust 500.866 bug_hi .346 .500)
  604. (fm-insect 0.195 .233 4126.284 .030 amp 60 -12.142 locust 649.490 bug_hi .407 .500)
  605. (fm-insect 0.217 2.057 3930.258 .045 amp 60 -3.011 locust 562.087 bug_hi .591 .500)
  606. (fm-insect 2.100 1.500 900.627 .06 amp 40 -16.707 locust 300.866 bug_hi .346 .500)
  607. (fm-insect 3.000 1.500 900.627 .06 amp 40 -16.707 locust 300.866 bug_hi .046 .500)
  608. (fm-insect 3.450 1.500 900.627 .09 amp 40 -16.707 locust 300.866 bug_hi .006 .500)
  609. (fm-insect 3.950 1.500 900.627 .12 amp 40 -10.707 locust 300.866 bug_hi .346 .500)
  610. (fm-insect 4.300 1.500 900.627 .09 amp 40 -20.707 locust 300.866 bug_hi .246 .500)))
  611. |#
  612. ;;; -------- FM-DRUM
  613. ;;; Jan Mattox's fm drum:
  614. (definstrument (fm-drum start-time duration frequency amplitude index
  615. high (degree 0.0) (distance 1.0) (reverb-amount 0.01))
  616. (let (;; many of the following variables were originally passed as arguments
  617. (casrat (if high 8.525 3.515))
  618. (fmrat (if high 3.414 1.414))
  619. (glsfun '(0 0 25 0 75 1 100 1))
  620. (indxfun '(0 0 5 .014 10 .033 15 .061 20 .099
  621. 25 .153 30 .228 35 .332 40 .477
  622. 45 .681 50 .964 55 .681 60 .478 65 .332
  623. 70 .228 75 .153 80 .099 85 .061
  624. 90 .033 95 .0141 100 0))
  625. (indxpt (- 100 (* 100 (/ (- duration .1) duration))))
  626. (ampfun '(0 0 3 .05 5 .2 7 .8 8 .95 10 1.0 12 .95 20 .3 30 .1 100 0))
  627. (atdrpt (* 100 (/ (if high .01 .015) duration))))
  628. (let ((divindxf (stretch-envelope indxfun 50 atdrpt 65 indxpt)))
  629. (let ((beg (seconds->samples start-time))
  630. (end (seconds->samples (+ start-time duration)))
  631. (glsf (make-env glsfun :scaler (if high (hz->radians 66) 0.0) :duration duration))
  632. (ampf (let ((ampe (stretch-envelope ampfun
  633. 10 atdrpt
  634. 15 (max (+ atdrpt 1)
  635. (- 100 (* 100 (/ (- duration .2) duration)))))))
  636. (make-env ampe :scaler amplitude :duration duration)))
  637. (indxf (make-env divindxf :scaler (min (hz->radians (* index fmrat frequency)) pi) :duration duration))
  638. (mindxf (make-env divindxf :scaler (min (hz->radians (* index casrat frequency)) pi) :duration duration))
  639. (devf (let ((deve (stretch-envelope ampfun
  640. 10 atdrpt
  641. 90 (max (+ atdrpt 1)
  642. (- 100 (* 100 (/ (- duration .05) duration)))))))
  643. (make-env deve :scaler (min pi (hz->radians 7000)) :duration duration)))
  644. (loc (make-locsig degree distance reverb-amount))
  645. (rn (make-rand :frequency 7000 :amplitude 1.0))
  646. (carrier (make-oscil frequency))
  647. (fmosc (make-oscil (* frequency fmrat)))
  648. (cascade (make-oscil (* frequency casrat))))
  649. (do ((i beg (+ i 1)))
  650. ((= i end))
  651. (let ((gls (env glsf)))
  652. (locsig loc i (* (env ampf)
  653. (oscil carrier
  654. (+ gls
  655. (* (env indxf)
  656. (oscil fmosc
  657. (+ (* gls fmrat)
  658. (* (env mindxf)
  659. (oscil cascade
  660. (+ (* gls casrat)
  661. (* (env devf) (rand rn))))))))))))))))))
  662. #|
  663. (with-sound ()
  664. (fm-drum 0 1.5 55 .3 5 #f)
  665. (fm-drum 2 1.5 66 .3 4 #t))
  666. |#
  667. ;;; -------- FM-GONG
  668. ;;; Paul Weineke's gong.
  669. (definstrument (gong start-time duration frequency amplitude
  670. (degree 0.0) (distance 1.0) (reverb-amount 0.005))
  671. (let ((mfq1 (* frequency 1.16))
  672. (mfq2 (* frequency 3.14))
  673. (mfq3 (* frequency 1.005)))
  674. (let ((indx01 (hz->radians (* .01 mfq1)))
  675. (indx11 (hz->radians (* .30 mfq1)))
  676. (indx02 (hz->radians (* .01 mfq2)))
  677. (indx12 (hz->radians (* .38 mfq2)))
  678. (indx03 (hz->radians (* .01 mfq3)))
  679. (indx13 (hz->radians (* .50 mfq3)))
  680. (atpt 5)
  681. (atdur (* 100 (/ .002 duration)))
  682. (expf '(0 0 3 1 15 .5 27 .25 50 .1 100 0))
  683. (rise '(0 0 15 .3 30 1.0 75 .5 100 0))
  684. (fmup '(0 0 75 1.0 98 1.0 100 0))
  685. (fmdwn '(0 0 2 1.0 100 0)))
  686. (let ((ampfun (make-env (stretch-envelope expf atpt atdur)
  687. :scaler amplitude :duration duration))
  688. (indxfun1 (make-env fmup :duration duration
  689. :scaler (- indx11 indx01) :offset indx01))
  690. (indxfun2 (make-env fmdwn :duration duration
  691. :scaler (- indx12 indx02) :offset indx02))
  692. (indxfun3 (make-env rise :duration duration
  693. :scaler (- indx13 indx03) :offset indx03))
  694. (loc (make-locsig degree distance reverb-amount))
  695. (carrier (make-oscil frequency))
  696. (mod1 (make-oscil mfq1))
  697. (mod2 (make-oscil mfq2))
  698. (mod3 (make-oscil mfq3))
  699. (beg (seconds->samples start-time))
  700. (end (seconds->samples (+ start-time duration))))
  701. (do ((i beg (+ i 1)))
  702. ((= i end))
  703. (locsig loc i (* (env ampfun)
  704. (oscil carrier (+ (* (env indxfun1) (oscil mod1))
  705. (* (env indxfun2) (oscil mod2))
  706. (* (env indxfun3) (oscil mod3)))))))))))
  707. ;;; (with-sound () (gong 0 3 261.61 .6))
  708. (definstrument (attract beg dur amp c-1) ;c from 1 to 10 or so
  709. ;; by James McCartney, from CMJ vol 21 no 3 p 6
  710. (let ((st (seconds->samples beg))
  711. (nd (seconds->samples (+ beg dur)))
  712. (c c-1) (a .2) (b .2) (dt .04)
  713. (scale (/ (* .5 amp) c-1))
  714. (x -1.0) (y 0.0) (z 0.0))
  715. (do ((i st (+ i 1)))
  716. ((= i nd))
  717. (let ((x1 (- x (* dt (+ y z)))))
  718. (set! y (+ y (* dt (+ x (* a y)))))
  719. (set! z (+ z (* dt (- (+ b (* x z)) (* c z)))))
  720. (set! x x1)
  721. (outa i (* scale x))))))
  722. ;;; -------- PQW
  723. (definstrument (pqw start dur spacing-freq carrier-freq amplitude ampfun indexfun partials
  724. (degree 0.0)
  725. (distance 1.0)
  726. (reverb-amount 0.005))
  727. ;; phase-quadrature waveshaping used to create asymmetric (i.e. single side-band) spectra.
  728. ;; The basic idea here is a variant of sin x sin y - cos x cos y = cos (x + y)
  729. (define (clip-env e)
  730. (do ((x e (cddr x)))
  731. ((null? x) e)
  732. (if (> (cadr x) 1.0)
  733. (list-set! x 1 1.0))))
  734. (let ((normalized-partials (normalize-partials partials))
  735. (spacing-cos (make-oscil spacing-freq :initial-phase (/ pi 2.0)))
  736. (spacing-sin (make-oscil spacing-freq))
  737. (carrier-cos (make-oscil carrier-freq :initial-phase (/ pi 2.0)))
  738. (carrier-sin (make-oscil carrier-freq)))
  739. (let ((sin-coeffs (partials->polynomial normalized-partials mus-chebyshev-second-kind))
  740. (cos-coeffs (partials->polynomial normalized-partials mus-chebyshev-first-kind))
  741. (amp-env (make-env ampfun :scaler amplitude :duration dur))
  742. (ind-env (make-env (clip-env indexfun) :duration dur))
  743. (loc (make-locsig degree distance reverb-amount))
  744. (r (/ carrier-freq spacing-freq))
  745. (tr (make-triangle-wave :frequency 5 :amplitude (hz->radians (* .005 spacing-freq))))
  746. (rn (make-rand-interp :frequency 12 :amplitude (hz->radians (* .005 spacing-freq))))
  747. (beg (seconds->samples start))
  748. (end (seconds->samples (+ start dur))))
  749. (do ((i beg (+ i 1)))
  750. ((= i end))
  751. (let* ((vib (+ (triangle-wave tr) (rand-interp rn)))
  752. (ax (* (env ind-env) (oscil spacing-cos vib))))
  753. (locsig loc i (* (env amp-env)
  754. (- (* (oscil carrier-sin (* vib r))
  755. (oscil spacing-sin vib)
  756. (polynomial sin-coeffs ax))
  757. (* (oscil carrier-cos (* vib r))
  758. (polynomial cos-coeffs ax))))))))))
  759. ;; (with-sound () (pqw 0 .5 200 1000 .2 '(0 0 25 1 100 0) '(0 1 100 0) '(2 .1 3 .3 6 .5)))
  760. ;; to see the asymmetric spectrum most clearly, set the index function above to '(0 1 100 1)
  761. ;;; taken from Perry Cook's stkv1.tar.Z (Synthesis Toolkit), but I was
  762. ;;; in a bit of a hurry and may not have made slavishly accurate translations.
  763. ;;; Please let me know of any errors.
  764. (definstrument (tubebell beg dur freq amp (base 32.0))
  765. ;; from Perry Cook's TubeBell.cpp
  766. (let ((osc0 (make-oscil (* freq 0.995)))
  767. (osc1 (make-oscil (* freq 1.414 0.995)))
  768. (osc2 (make-oscil (* freq 1.005)))
  769. (osc3 (make-oscil (* freq 1.414)))
  770. (ampenv1 (make-env (list 0 0 .005 1 dur 0) :base base :duration dur :scaler (* amp .5 .707)))
  771. (ampenv2 (make-env (list 0 0 .001 1 dur 0) :base (* 2 base) :duration dur :scaler (* .5 amp)))
  772. (ampmod (make-oscil 2.0))
  773. (st (seconds->samples beg))
  774. (nd (seconds->samples (+ beg dur))))
  775. (do ((i st (+ i 1)))
  776. ((= i nd))
  777. (outa i (* (+ (* .007 (oscil ampmod)) .993)
  778. (+ (* (env ampenv1) (oscil osc0 (* .203 (oscil osc1))))
  779. (* (env ampenv2) (oscil osc2 (* .144 (oscil osc3))))))))))
  780. (definstrument (wurley beg dur freq amp)
  781. ;; from Perry Cook's Wurley.cpp
  782. (let ((osc0 (make-oscil freq))
  783. (osc1 (make-oscil (* freq 4.0)))
  784. (osc2 (make-oscil 510.0))
  785. (osc3 (make-oscil 510.0))
  786. (ampmod (make-oscil 8.0))
  787. (g0 (* .5 amp))
  788. (ampenv (make-env '(0 0 1 1 9 1 10 0) :duration dur))
  789. (indenv (make-env (list 0 0 .001 1 .15 0 (max dur .16) 0) :duration dur :scaler .117))
  790. (resenv (make-env (list 0 0 .001 1 .25 0 (max dur .26) 0) :duration dur :scaler (* .5 .307 amp)))
  791. (st (seconds->samples beg))
  792. (nd (seconds->samples (+ beg dur))))
  793. (do ((i st (+ i 1)))
  794. ((= i nd))
  795. (outa i (* (env ampenv)
  796. (+ 1.0 (* .007 (oscil ampmod)))
  797. (+ (* g0 (oscil osc0 (* .307 (oscil osc1))))
  798. (* (env resenv) (oscil osc2 (* (env indenv) (oscil osc3))))))))))
  799. (definstrument (rhodey beg dur freq amp (base .5))
  800. ;; from Perry Cook's Rhodey.cpp
  801. (let ((osc0 (make-oscil freq))
  802. (osc1 (make-oscil (* freq 0.5)))
  803. (osc2 (make-oscil freq))
  804. (osc3 (make-oscil (* freq 15.0)))
  805. (ampenv1 (make-env (list 0 0 .005 1 dur 0) :base base :duration dur :scaler (* amp .5)))
  806. (ampenv2 (make-env (list 0 0 .001 1 dur 0) :base (* base 1.5) :duration dur :scaler (* amp .5)))
  807. (ampenv3 (make-env (list 0 0 .001 1 .25 0 (max dur .26) 0) :base (* base 4) :duration dur :scaler .109))
  808. (st (seconds->samples beg))
  809. (nd (seconds->samples (+ beg dur))))
  810. (do ((i st (+ i 1)))
  811. ((= i nd))
  812. (outa i (+ (* (env ampenv1) (oscil osc0 (* .535 (oscil osc1))))
  813. (* (env ampenv2) (oscil osc2 (* (env ampenv3) (oscil osc3)))))))))
  814. (definstrument (hammondoid beg dur freq amp)
  815. ;; from Perry Cook's BeeThree.cpp
  816. (let ((osc0 (make-oscil (* freq 0.999)))
  817. (osc1 (make-oscil (* freq 1.997)))
  818. (osc2 (make-oscil (* freq 3.006)))
  819. (osc3 (make-oscil (* freq 6.009)))
  820. (ampenv1 (make-env (list 0 0 .005 1 (- dur .008) 1 dur 0) :duration dur))
  821. (ampenv2 (make-env (list 0 0 .005 1 dur 0) :duration dur :scaler (* .5 .75 amp)))
  822. (g0 (* .25 .75 amp))
  823. (g1 (* .25 .75 amp))
  824. (g2 (* .5 amp))
  825. (st (seconds->samples beg))
  826. (nd (seconds->samples (+ beg dur))))
  827. (do ((i st (+ i 1)))
  828. ((= i nd))
  829. (outa i (+ (* (env ampenv1)
  830. (+ (* g0 (oscil osc0))
  831. (* g1 (oscil osc1))
  832. (* g2 (oscil osc2))))
  833. (* (env ampenv2) (oscil osc3)))))))
  834. (definstrument (metal beg dur freq amp)
  835. ;; from Perry Cook's HeavyMtl.cpp
  836. (let ((osc0 (make-oscil freq))
  837. (osc1 (make-oscil (* freq 4.0 0.999)))
  838. (osc2 (make-oscil (* freq 3.0 1.001)))
  839. (osc3 (make-oscil (* freq 0.50 1.002)))
  840. (ampenv0 (make-env (list 0 0 .001 1 (- dur .002) 1 dur 0) :duration dur :scaler (* amp .615)))
  841. (ampenv1 (make-env (list 0 0 .001 1 (- dur .011) 1 dur 0) :duration dur :scaler .202))
  842. (ampenv2 (make-env (list 0 0 .01 1 (- dur .015) 1 dur 0) :duration dur :scaler .574))
  843. (ampenv3 (make-env (list 0 0 .03 1 (- dur .040) 1 dur 0) :duration dur :scaler .116))
  844. (st (seconds->samples beg))
  845. (nd (seconds->samples (+ beg dur))))
  846. (do ((i st (+ i 1)))
  847. ((= i nd))
  848. (outa i (* (env ampenv0)
  849. (oscil osc0
  850. (+ (* (env ampenv1) (oscil osc1 (* (env ampenv2) (oscil osc2))))
  851. (* (env ampenv3) (oscil osc3)))))))))
  852. (definstrument (drone startime dur frequency amp ampfun synth ampat ampdc amtrev deg dis rvibamt rvibfreq)
  853. (let ((beg (seconds->samples startime))
  854. (end (seconds->samples (+ startime dur)))
  855. (waveform (partials->wave synth))
  856. (amplitude (* amp .25))
  857. (freq (hz->radians frequency)))
  858. (let ((s (make-table-lookup :frequency frequency :wave waveform))
  859. (amp-env (let ((ampe (stretch-envelope ampfun 25 (* 100 (/ ampat dur)) 75 (- 100 (* 100 (/ ampdc dur))))))
  860. (make-env ampe :scaler amplitude :duration dur)))
  861. (ran-vib (make-rand :frequency rvibfreq :amplitude (* rvibamt freq)))
  862. (loc (make-locsig deg dis amtrev)))
  863. (do ((i beg (+ i 1)))
  864. ((= i end))
  865. (locsig loc i (* (env amp-env) (table-lookup s (rand ran-vib))))))))
  866. (definstrument (canter beg dur pitch amp-1 deg dis pcrev ampfun ranfun skewfun
  867. skewpc ranpc ranfreq indexfun atdr dcdr
  868. ampfun1 indfun1 fmtfun1
  869. ampfun2 indfun2 fmtfun2
  870. ampfun3 indfun3 fmtfun3
  871. ampfun4 indfun4 fmtfun4)
  872. (let ((amp (* amp-1 .25)) ;pvc's amplitudes in bag.clm are very high (overflows)
  873. (rangetop 910.0)
  874. (rangebot 400.0))
  875. (let ((k (floor (* 100 (log (/ pitch rangebot) (/ rangetop rangebot)))))
  876. (atpt (* 100 (/ atdr dur)))
  877. (dcpt (- 100 (* 100 (/ dcdr dur)))))
  878. (let ((lfmt1 (envelope-interp k fmtfun1))
  879. (lfmt2 (envelope-interp k fmtfun2))
  880. (lfmt3 (envelope-interp k fmtfun3))
  881. (lfmt4 (envelope-interp k fmtfun4))
  882. (dev11 (hz->radians (* (envelope-interp k indfun1) pitch)))
  883. (dev12 (hz->radians (* (envelope-interp k indfun2) pitch)))
  884. (dev13 (hz->radians (* (envelope-interp k indfun3) pitch)))
  885. (dev14 (hz->radians (* (envelope-interp k indfun4) pitch))))
  886. (let ((start (seconds->samples beg))
  887. (end (seconds->samples (+ beg dur)))
  888. (dev01 (* dev11 .5))
  889. (dev02 (* dev12 .5))
  890. (dev03 (* dev13 .5))
  891. (dev04 (* dev14 .5))
  892. (harm1 (floor (+ .5 (/ lfmt1 pitch))))
  893. (harm2 (floor (+ .5 (/ lfmt2 pitch))))
  894. (harm3 (floor (+ .5 (/ lfmt3 pitch))))
  895. (harm4 (floor (+ .5 (/ lfmt4 pitch)))))
  896. (let ((lamp1 (* (envelope-interp k ampfun1) amp (- 1 (abs (- harm1 (/ lfmt1 pitch))))))
  897. (lamp2 (* (envelope-interp k ampfun2) amp (- 1 (abs (- harm2 (/ lfmt2 pitch))))))
  898. (lamp3 (* (envelope-interp k ampfun3) amp (- 1 (abs (- harm3 (/ lfmt3 pitch))))))
  899. (lamp4 (* (envelope-interp k ampfun4) amp (- 1 (abs (- harm4 (/ lfmt4 pitch))))))
  900. (tidx-stretched (stretch-envelope indexfun 25 atpt 75 dcpt)))
  901. (let ((tampfun (make-env (stretch-envelope ampfun 25 atpt 75 dcpt) :duration dur))
  902. (tskwfun (make-env (stretch-envelope skewfun 25 atpt 75 dcpt) :scaler (hz->radians (* pitch skewpc)) :duration dur))
  903. (tranfun (make-env (stretch-envelope ranfun 25 atpt 75 dcpt) :duration dur))
  904. (d1env (make-env tidx-stretched :offset dev01 :scaler dev11 :duration dur))
  905. (d2env (make-env tidx-stretched :offset dev02 :scaler dev12 :duration dur))
  906. (d3env (make-env tidx-stretched :offset dev03 :scaler dev13 :duration dur))
  907. (d4env (make-env tidx-stretched :offset dev04 :scaler dev14 :duration dur))
  908. (modgen (make-oscil pitch))
  909. (ranvib (make-rand :frequency ranfreq :amplitude (hz->radians (* ranpc pitch))))
  910. (loc (make-locsig deg dis pcrev))
  911. (gen1 (make-oscil (* pitch harm1)))
  912. (gen2 (make-oscil (* pitch harm2)))
  913. (gen3 (make-oscil (* pitch harm3)))
  914. (gen4 (make-oscil (* pitch harm4))))
  915. (do ((i start (+ i 1)))
  916. ((= i end))
  917. (let* ((frqval (+ (env tskwfun) (* (env tranfun) (rand ranvib))))
  918. (modval (oscil modgen frqval)))
  919. (locsig loc i (* (env tampfun)
  920. (+ (* lamp1 (oscil gen1 (* (+ (* (env d1env) modval) frqval) harm1)))
  921. (* lamp2 (oscil gen2 (* (+ (* (env d2env) modval) frqval) harm2)))
  922. (* lamp3 (oscil gen3 (* (+ (* (env d3env) modval) frqval) harm3)))
  923. (* lamp4 (oscil gen4 (* (+ (* (env d4env) modval) frqval) harm4)))))))))))))))
  924. ;;; NREV (the most popular Samson box reverb)
  925. (definstrument (nrev (reverb-factor 1.09) (lp-coeff 0.7) (volume 1.0))
  926. ;; reverb-factor controls the length of the decay -- it should not exceed (/ 1.0 .823)
  927. ;; lp-coeff controls the strength of the low pass filter inserted in the feedback loop
  928. ;; output-scale can be used to boost the reverb output
  929. (define (next-prime val)
  930. (if (or (= val 2)
  931. (and (odd? val)
  932. (do ((i 3 (+ i 2))
  933. (lim (sqrt val)))
  934. ((or (= 0 (modulo val i)) (> i lim)) (> i lim)))))
  935. val
  936. (next-prime (+ val 2))))
  937. (let ((srscale (/ *clm-srate* 25641))
  938. (dly-len (list 1433 1601 1867 2053 2251 2399 347 113 37 59 53 43 37 29 19))
  939. (chan2 (> (channels *output*) 1))
  940. (chan4 (= (channels *output*) 4)))
  941. (do ((i 0 (+ i 1)))
  942. ((= i 15))
  943. (let ((val (floor (* srscale (dly-len i)))))
  944. (if (even? val) (set! val (+ val 1)))
  945. (set! (dly-len i) (next-prime val))))
  946. (let ((len (+ (floor *clm-srate*) (framples *reverb*)))
  947. (comb1 (make-comb (* .822 reverb-factor) (dly-len 0)))
  948. (comb2 (make-comb (* .802 reverb-factor) (dly-len 1)))
  949. (comb3 (make-comb (* .773 reverb-factor) (dly-len 2)))
  950. (comb4 (make-comb (* .753 reverb-factor) (dly-len 3)))
  951. (comb5 (make-comb (* .753 reverb-factor) (dly-len 4)))
  952. (comb6 (make-comb (* .733 reverb-factor) (dly-len 5)))
  953. (low (make-one-pole lp-coeff (- lp-coeff 1.0)))
  954. (allpass1 (make-all-pass -0.700 0.700 (dly-len 6)))
  955. (allpass2 (make-all-pass -0.700 0.700 (dly-len 7)))
  956. (allpass3 (make-all-pass -0.700 0.700 (dly-len 8)))
  957. (allpass4 (make-all-pass -0.700 0.700 (dly-len 9))) ; 10 for quad
  958. (allpass5 (make-all-pass -0.700 0.700 (dly-len 11)))
  959. (allpass6 (and chan2 (make-all-pass -0.700 0.700 (dly-len 12))))
  960. (allpass7 (and chan4 (make-all-pass -0.700 0.700 (dly-len 13))))
  961. (allpass8 (and chan4 (make-all-pass -0.700 0.700 (dly-len 14)))))
  962. (let ((filts (if (not chan2)
  963. (vector allpass5)
  964. (if (not chan4)
  965. (vector allpass5 allpass6)
  966. (vector allpass5 allpass6 allpass7 allpass8))))
  967. (combs (make-comb-bank (vector comb1 comb2 comb3 comb4 comb5 comb6)))
  968. (allpasses (make-all-pass-bank (vector allpass1 allpass2 allpass3))))
  969. (do ((i 0 (+ i 1)))
  970. ((= i len))
  971. (out-bank filts i
  972. (all-pass allpass4
  973. (one-pole low
  974. (all-pass-bank allpasses
  975. (comb-bank combs (* volume (ina i *reverb*))))))))))))
  976. (definstrument (reson startime dur pitch amp numformants indxfun skewfun pcskew skewat skewdc
  977. vibfreq vibpc ranvibfreq ranvibpc degree distance reverb-amount data)
  978. ;; data is a list of lists of form '(ampf resonfrq resonamp ampat ampdc dev0 dev1 indxat indxdc)
  979. (let ((beg (seconds->samples startime))
  980. (end (seconds->samples (+ startime dur)))
  981. (carriers (make-vector numformants))
  982. (modulator (make-oscil pitch))
  983. (ampfs (make-vector numformants))
  984. (indfs (make-vector numformants))
  985. (c-rats (make-vector numformants))
  986. (totalamp 0.0)
  987. (loc (make-locsig degree distance reverb-amount))
  988. (pervib (make-triangle-wave :frequency vibfreq
  989. :amplitude (hz->radians (* vibpc pitch))))
  990. (ranvib (make-rand-interp :frequency ranvibfreq
  991. :amplitude (hz->radians (* ranvibpc pitch))))
  992. (frqf (let ((frqe (stretch-envelope skewfun
  993. 25 (* 100 (/ skewat dur))
  994. 75 (- 100 (* 100 (/ skewdc dur))))))
  995. (make-env frqe :scaler (hz->radians (* pcskew pitch)) :duration dur))))
  996. ;; initialize the "formant" generators
  997. (do ((i 0 (+ i 1)))
  998. ((= i numformants))
  999. (set! totalamp (+ totalamp ((data i) 2))))
  1000. (do ((i 0 (+ i 1)))
  1001. ((= i numformants))
  1002. (let* ((frmdat (data i))
  1003. (freq (cadr frmdat))
  1004. (harm (round (/ freq pitch))))
  1005. (let ((rfamp (frmdat 2))
  1006. (ampat (* 100 (/ (frmdat 3) dur)))
  1007. (ampdc (- 100 (* 100 (/ (frmdat 4) dur))))
  1008. (dev0 (hz->radians (* (frmdat 5) freq)))
  1009. (dev1 (hz->radians (* (frmdat 6) freq)))
  1010. (indxat (* 100 (/ (frmdat 7) dur)))
  1011. (indxdc (- 100 (* 100 (/ (frmdat 8) dur))))
  1012. (ampf (car frmdat))
  1013. (rsamp (- 1.0 (abs (- harm (/ freq pitch)))))
  1014. (cfq (* pitch harm)))
  1015. (if (zero? ampat) (set! ampat 25))
  1016. (if (zero? ampdc) (set! ampdc 75))
  1017. (if (zero? indxat) (set! indxat 25))
  1018. (if (zero? indxdc) (set! indxdc 75))
  1019. (set! (indfs i) (make-env (stretch-envelope indxfun 25 indxat 75 indxdc) :duration dur
  1020. :scaler (- dev1 dev0) :offset dev0))
  1021. (set! (ampfs i) (make-env (stretch-envelope ampf 25 ampat 75 ampdc) :duration dur
  1022. :scaler (/ (* rsamp amp rfamp) totalamp)))
  1023. (set! (c-rats i) harm)
  1024. (set! (carriers i) (make-oscil cfq)))))
  1025. (if (= numformants 2)
  1026. (let ((e1 (ampfs 0))
  1027. (e2 (ampfs 1))
  1028. (c1 (carriers 0))
  1029. (c2 (carriers 1))
  1030. (i1 (indfs 0))
  1031. (i2 (indfs 1))
  1032. (r1 (c-rats 0))
  1033. (r2 (c-rats 1)))
  1034. (do ((i beg (+ i 1)))
  1035. ((= i end))
  1036. (let* ((vib (+ (env frqf) (triangle-wave pervib) (rand-interp ranvib)))
  1037. (modsig (oscil modulator vib)))
  1038. (locsig loc i (+ (* (env e1)
  1039. (oscil c1 (+ (* vib r1)
  1040. (* (env i1) modsig))))
  1041. (* (env e2)
  1042. (oscil c2 (+ (* vib r2)
  1043. (* (env i2) modsig)))))))))
  1044. (do ((i beg (+ i 1)))
  1045. ((= i end))
  1046. (let* ((outsum 0.0)
  1047. (vib (+ (env frqf) (triangle-wave pervib) (rand-interp ranvib)))
  1048. (modsig (oscil modulator vib)))
  1049. (do ((k 0 (+ k 1)))
  1050. ((= k numformants))
  1051. (set! outsum (+ outsum
  1052. (* (env (ampfs k))
  1053. (oscil (carriers k)
  1054. (+ (* vib (c-rats k))
  1055. (* (env (indfs k)) modsig)))))))
  1056. (locsig loc i outsum))))))
  1057. ;; (with-sound (:statistics #t) (reson 0 1.0 440 .1 2 '(0 0 100 1) '(0 0 100 1) .1 .1 .1 5 .01 5 .01 0 1.0 0.01 '(((0 0 100 1) 1200 .5 .1 .1 0 1.0 .1 .1) ((0 1 100 0) 2400 .5 .1 .1 0 1.0 .1 .1))))
  1058. ;;; STK's feedback-fm instrument named CelloN in Sambox-land
  1059. (definstrument (cellon beg dur pitch0 amp ampfun betafun
  1060. beta0 beta1 betaat betadc ampat ampdc dis pcrev deg
  1061. pitch1 glissfun glissat glissdc
  1062. pvibfreq pvibpc pvibfun pvibat pvibdc
  1063. rvibfreq rvibpc rvibfun)
  1064. (let ((st (seconds->samples beg))
  1065. (nd (seconds->samples (+ beg dur)))
  1066. (pit1 (if (zero? pitch1) pitch0 pitch1))
  1067. (loc (make-locsig deg dis pcrev))
  1068. (carrier (make-oscil pitch0))
  1069. (low (make-one-zero .5 -.5))
  1070. (fm 0.0)
  1071. (fmosc (make-oscil pitch0))
  1072. (pvib (make-triangle-wave :frequency pvibfreq :amplitude 1.0))
  1073. (rvib (make-rand-interp :frequency rvibfreq :amplitude 1.0))
  1074. (ampap (if (> ampat 0.0) (* 100 (/ ampat dur)) 25))
  1075. (ampdp (if (> ampdc 0.0) (* 100 (- 1.0 (/ ampdc dur))) 75))
  1076. (glsap (if (> glissat 0.0) (* 100 (/ glissat dur)) 25))
  1077. (glsdp (if (> glissdc 0.0) (* 100 (- 1.0 (/ glissdc dur))) 75))
  1078. (betap (if (> betaat 0.0) (* 100 (/ betaat dur)) 25))
  1079. (betdp (if (> betadc 0.0) (* 100 (- 1.0 (/ betadc dur))) 75))
  1080. (pvbap (if (> pvibat 0.0) (* 100 (/ pvibat dur)) 25))
  1081. (pvbdp (if (> pvibdc 0.0) (* 100 (- 1.0 (/ pvibdc dur))) 75)))
  1082. (let ((pvibenv (make-env (stretch-envelope (or pvibfun '(0 1 100 1)) 25 pvbap 75 pvbdp) :duration dur
  1083. :scaler (hz->radians (* pvibpc pitch0))))
  1084. (rvibenv (make-env (or rvibfun '(0 1 100 1)) :duration dur
  1085. :scaler (hz->radians (* rvibpc pitch0))))
  1086. (glisenv (make-env (stretch-envelope (or glissfun '(0 0 100 0)) 25 glsap 75 glsdp) :duration dur
  1087. :scaler (hz->radians (- pit1 pitch0))))
  1088. (amplenv (make-env (stretch-envelope ampfun 25 ampap 75 ampdp) :scaler amp :duration dur))
  1089. (betaenv (make-env (stretch-envelope betafun 25 betap 75 betdp) :duration dur
  1090. :scaler (- beta1 beta0) :offset beta0)))
  1091. (if (and (= pitch0 pitch1)
  1092. (or (zero? pvibfreq)
  1093. (zero? pvibpc))
  1094. (or (zero? rvibfreq)
  1095. (zero? rvibpc)))
  1096. (do ((i st (+ i 1)))
  1097. ((= i nd))
  1098. (set! fm (one-zero low (* (env betaenv) (oscil fmosc fm))))
  1099. (locsig loc i (* (env amplenv) (oscil carrier fm))))
  1100. (do ((i st (+ i 1)))
  1101. ((= i nd))
  1102. (let ((vib (+ (* (env pvibenv) (triangle-wave pvib))
  1103. (* (env rvibenv) (rand-interp rvib))
  1104. (env glisenv))))
  1105. (set! fm (one-zero low (* (env betaenv) (oscil fmosc (+ fm vib)))))
  1106. (locsig loc i (* (env amplenv)
  1107. (oscil carrier (+ fm vib))))))))))
  1108. (definstrument (jl-reverb (decay 3.0) (volume 1.0))
  1109. (let ((allpass1 (make-all-pass -0.700 0.700 2111))
  1110. (allpass2 (make-all-pass -0.700 0.700 673))
  1111. (allpass3 (make-all-pass -0.700 0.700 223))
  1112. (comb1 (make-comb 0.742 9601))
  1113. (comb2 (make-comb 0.733 10007))
  1114. (comb3 (make-comb 0.715 10799))
  1115. (comb4 (make-comb 0.697 11597))
  1116. (outdel1 (make-delay (seconds->samples .013)))
  1117. (outdel2 (make-delay (seconds->samples .011)))
  1118. (len (floor (+ (* decay *clm-srate*) (length *reverb*)))))
  1119. (let ((filts (vector outdel1 outdel2))
  1120. (combs (make-comb-bank (vector comb1 comb2 comb3 comb4)))
  1121. (allpasses (make-all-pass-bank (vector allpass1 allpass2 allpass3))))
  1122. (do ((i 0 (+ i 1)))
  1123. ((= i len))
  1124. (out-bank filts i (* volume (comb-bank combs (all-pass-bank allpasses (ina i *reverb*)))))))))
  1125. (definstrument (gran-synth start-time duration audio-freq grain-dur grain-interval amp)
  1126. (let ((grain-size (ceiling (* (max grain-dur grain-interval) *clm-srate*))))
  1127. (let ((beg (seconds->samples start-time))
  1128. (end (seconds->samples (+ start-time duration)))
  1129. (grain-env (make-env '(0 0 25 1 75 1 100 0) :duration grain-dur))
  1130. (carrier (make-oscil audio-freq))
  1131. (grains (make-wave-train :size grain-size :frequency (/ 1.0 grain-interval))))
  1132. (let ((grain (mus-data grains)))
  1133. (do ((i 0 (+ i 1)))
  1134. ((= i grain-size))
  1135. (set! (grain i) (* (env grain-env) (oscil carrier)))))
  1136. (do ((i beg (+ i 1)))
  1137. ((= i end))
  1138. (outa i (* amp (wave-train grains)))))))
  1139. ;;; (with-sound () (gran-synth 0 2 100 .0189 .02 .4))
  1140. (definstrument (touch-tone start telephone-number)
  1141. (let ((touch-tab-1 '(0 697 697 697 770 770 770 852 852 852 941 941 941))
  1142. (touch-tab-2 '(0 1209 1336 1477 1209 1336 1477 1209 1336 1477 1209 1336 1477)))
  1143. (do ((i 0 (+ i 1)))
  1144. ((= i (length telephone-number)))
  1145. (let ((k (telephone-number i))
  1146. (beg (seconds->samples (+ start (* i .4)))))
  1147. (let ((end (+ beg (seconds->samples .3)))
  1148. (i (if (number? k)
  1149. (if (not (= 0 k)) k 11)
  1150. (if (eq? k '*) 10 12))))
  1151. (let ((frq1 (make-oscil (touch-tab-1 i)))
  1152. (frq2 (make-oscil (touch-tab-2 i))))
  1153. (do ((j beg (+ j 1)))
  1154. ((= j end))
  1155. (outa j (* 0.1 (+ (oscil frq1)
  1156. (oscil frq2)))))))))))
  1157. ;;; (with-sound () (touch-tone 0.0 '(7 2 3 4 9 7 1)))
  1158. ;;; I think the dial tone is 350 + 440
  1159. ;;; http://www.hackfaq.org/telephony/telephone-tone-frequencies.shtml
  1160. (definstrument (spectra start-time duration frequency amplitude
  1161. (partials '(1 1 2 0.5))
  1162. (amp-envelope '(0 0 50 1 100 0))
  1163. (vibrato-amplitude 0.005)
  1164. (vibrato-speed 5.0)
  1165. (degree 0.0)
  1166. (distance 1.0)
  1167. (reverb-amount 0.005))
  1168. (let ((beg (seconds->samples start-time))
  1169. (end (seconds->samples (+ start-time duration)))
  1170. (waveform (partials->wave partials))
  1171. (freq (hz->radians frequency)))
  1172. (let ((s (make-table-lookup :frequency frequency :wave waveform))
  1173. (amp-env (make-env amp-envelope :scaler amplitude :duration duration))
  1174. (per-vib (make-triangle-wave :frequency vibrato-speed
  1175. :amplitude (* vibrato-amplitude freq)))
  1176. (loc (make-locsig degree distance reverb-amount))
  1177. (ran-vib (make-rand-interp :frequency (+ vibrato-speed 1.0)
  1178. :amplitude (* vibrato-amplitude freq))))
  1179. (do ((i beg (+ i 1)))
  1180. ((= i end))
  1181. (locsig loc i (* (env amp-env)
  1182. (table-lookup s (+ (triangle-wave per-vib)
  1183. (rand-interp ran-vib)))))))))
  1184. #|
  1185. (with-sound (:play #t)
  1186. (spectra 0 1 440.0 .1 '(1.0 .4 2.0 .2 3.0 .2 4.0 .1 6.0 .1)
  1187. '(0.0 0.0 1.0 1.0 5.0 0.9 12.0 0.5 25.0 0.25 100.0 0.0)))
  1188. |#
  1189. ;;; interpolate between two waveforms (this could be extended to implement all the various
  1190. ;;; wavetable-based synthesis techniques).
  1191. (definstrument (two-tab start-time duration frequency amplitude
  1192. (partial-1 '(1.0 1.0 2.0 0.5))
  1193. (partial-2 '(1.0 0.0 3.0 1.0))
  1194. (amp-envelope '(0 0 50 1 100 0))
  1195. (interp-func '(0 1 100 0))
  1196. (vibrato-amplitude 0.005)
  1197. (vibrato-speed 5.0)
  1198. (degree 0.0)
  1199. (distance 1.0)
  1200. (reverb-amount 0.005))
  1201. (let ((beg (seconds->samples start-time))
  1202. (end (seconds->samples (+ start-time duration)))
  1203. (waveform-1 (partials->wave partial-1))
  1204. (waveform-2 (partials->wave partial-2))
  1205. (freq (hz->radians frequency)))
  1206. (let ((s-1 (make-table-lookup :frequency frequency :wave waveform-1))
  1207. (s-2 (make-table-lookup :frequency frequency :wave waveform-2))
  1208. (amp-env (make-env amp-envelope :scaler amplitude :duration duration))
  1209. (interp-env (make-env interp-func :duration duration))
  1210. (interp-env-1 (make-env interp-func :duration duration :offset 1.0 :scaler -1.0))
  1211. (loc (make-locsig degree distance reverb-amount))
  1212. (per-vib (make-triangle-wave :frequency vibrato-speed
  1213. :amplitude (* vibrato-amplitude freq)))
  1214. (ran-vib (make-rand-interp :frequency (+ vibrato-speed 1.0)
  1215. :amplitude (* vibrato-amplitude freq))))
  1216. (do ((i beg (+ i 1)))
  1217. ((= i end))
  1218. (let ((vib (+ (triangle-wave per-vib) (rand-interp ran-vib))))
  1219. (locsig loc i (* (env amp-env)
  1220. (+ (* (env interp-env) (table-lookup s-1 vib))
  1221. (* (env interp-env-1) (table-lookup s-2 vib))))))))))
  1222. (definstrument (lbj-piano begin-time duration frequency amplitude pfreq
  1223. (degree 45) (reverb-amount 0) (distance 1))
  1224. (define (get-piano-partials freq)
  1225. (let ((piano-spectra #((1.97 .0326 2.99 .0086 3.95 .0163 4.97 .0178 5.98 .0177 6.95 .0315 8.02 .0001
  1226. 8.94 .0076 9.96 .0134 10.99 .0284 11.98 .0229 13.02 .0229 13.89 .0010 15.06 .0090 16.00 .0003
  1227. 17.08 .0078 18.16 .0064 19.18 .0129 20.21 .0085 21.27 .0225 22.32 .0061 23.41 .0102 24.48 .0005
  1228. 25.56 .0016 26.64 .0018 27.70 .0113 28.80 .0111 29.91 .0158 31.06 .0093 32.17 .0017 33.32 .0002
  1229. 34.42 .0018 35.59 .0027 36.74 .0055 37.90 .0037 39.06 .0064 40.25 .0033 41.47 .0014 42.53 .0004
  1230. 43.89 .0010 45.12 .0039 46.33 .0039 47.64 .0009 48.88 .0016 50.13 .0006 51.37 .0010 52.70 .0002
  1231. 54.00 .0004 55.30 .0008 56.60 .0025 57.96 .0010 59.30 .0012 60.67 .0011 61.99 .0003 62.86 .0001
  1232. 64.36 .0005 64.86 .0001 66.26 .0004 67.70 .0006 68.94 .0002 70.10 .0001 70.58 .0002 72.01 .0007
  1233. 73.53 .0006 75.00 .0002 77.03 .0005 78.00 .0002 79.57 .0006 81.16 .0005 82.70 .0005 84.22 .0003
  1234. 85.41 .0002 87.46 .0001 90.30 .0001 94.02 .0001 95.26 .0002 109.39 .0003)
  1235. (1.98 .0194 2.99 .0210 3.97 .0276 4.96 .0297 5.96 .0158 6.99 .0207 8.01 .0009
  1236. 9.00 .0101 10.00 .0297 11.01 .0289 12.02 .0211 13.04 .0127 14.07 .0061 15.08 .0174 16.13 .0009
  1237. 17.12 .0093 18.16 .0117 19.21 .0122 20.29 .0108 21.30 .0077 22.38 .0132 23.46 .0073 24.14 .0002
  1238. 25.58 .0026 26.69 .0035 27.77 .0053 28.88 .0024 30.08 .0027 31.13 .0075 32.24 .0027 33.36 .0004
  1239. 34.42 .0004 35.64 .0019 36.78 .0037 38.10 .0009 39.11 .0027 40.32 .0010 41.51 .0013 42.66 .0019
  1240. 43.87 .0007 45.13 .0017 46.35 .0019 47.65 .0021 48.89 .0014 50.18 .0023 51.42 .0015 52.73 .0002
  1241. 54.00 .0005 55.34 .0006 56.60 .0010 57.96 .0016 58.86 .0005 59.30 .0004 60.75 .0005 62.22 .0003
  1242. 63.55 .0005 64.82 .0003 66.24 .0003 67.63 .0011 69.09 .0007 70.52 .0004 72.00 .0005 73.50 .0008
  1243. 74.95 .0003 77.13 .0013 78.02 .0002 79.48 .0004 82.59 .0004 84.10 .0003)
  1244. (2.00 .0313 2.99 .0109 4.00 .0215 5.00 .0242 5.98 .0355 7.01 .0132 8.01 .0009
  1245. 9.01 .0071 10.00 .0258 11.03 .0221 12.02 .0056 13.06 .0196 14.05 .0160 15.11 .0107 16.11 .0003
  1246. 17.14 .0111 18.21 .0085 19.23 .0010 20.28 .0048 21.31 .0128 22.36 .0051 23.41 .0041 24.05 .0006
  1247. 25.54 .0019 26.62 .0028 27.72 .0034 28.82 .0062 29.89 .0039 30.98 .0058 32.08 .0011 33.21 .0002
  1248. 34.37 .0008 35.46 .0018 36.62 .0036 37.77 .0018 38.92 .0042 40.07 .0037 41.23 .0011 42.67 .0003
  1249. 43.65 .0018 44.68 .0025 45.99 .0044 47.21 .0051 48.40 .0044 49.67 .0005 50.88 .0019 52.15 .0003
  1250. 53.42 .0008 54.69 .0010 55.98 .0005 57.26 .0013 58.53 .0027 59.83 .0011 61.21 .0027 62.54 .0003
  1251. 63.78 .0003 65.20 .0001 66.60 .0006 67.98 .0008 69.37 .0019 70.73 .0007 72.14 .0004 73.62 .0002
  1252. 74.40 .0003 76.52 .0006 77.97 .0002 79.49 .0004 80.77 .0003 81.00 .0001 82.47 .0005 83.97 .0001
  1253. 87.27 .0002)
  1254. (2.00 .0257 2.99 .0142 3.97 .0202 4.95 .0148 5.95 .0420 6.95 .0037 7.94 .0004
  1255. 8.94 .0172 9.95 .0191 10.96 .0115 11.97 .0059 12.98 .0140 14.00 .0178 15.03 .0121 16.09 .0002
  1256. 17.07 .0066 18.08 .0033 19.15 .0022 20.18 .0057 21.22 .0077 22.29 .0037 23.33 .0066 24.97 .0002
  1257. 25.49 .0019 26.55 .0042 27.61 .0043 28.73 .0038 29.81 .0084 30.91 .0040 32.03 .0025 33.14 .0005
  1258. 34.26 .0003 35.38 .0019 36.56 .0037 37.68 .0049 38.86 .0036 40.11 .0011 41.28 .0008 42.50 .0004
  1259. 43.60 .0002 44.74 .0022 45.99 .0050 47.20 .0009 48.40 .0036 49.68 .0004 50.92 .0009 52.17 .0005
  1260. 53.46 .0007 54.76 .0006 56.06 .0005 57.34 .0011 58.67 .0005 59.95 .0015 61.37 .0008 62.72 .0004
  1261. 65.42 .0009 66.96 .0003 68.18 .0003 69.78 .0003 71.21 .0004 72.45 .0002 74.22 .0003 75.44 .0001
  1262. 76.53 .0003 78.31 .0004 79.83 .0003 80.16 .0001 81.33 .0003 82.44 .0001 83.17 .0002 84.81 .0003
  1263. 85.97 .0003 89.08 .0001 90.70 .0002 92.30 .0002 95.59 .0002 97.22 .0003 98.86 .0001 108.37 .0001
  1264. 125.54 .0001)
  1265. (1.99 .0650 3.03 .0040 4.03 .0059 5.02 .0090 5.97 .0227 6.98 .0050 8.04 .0020
  1266. 9.00 .0082 9.96 .0078 11.01 .0056 12.01 .0095 13.02 .0050 14.04 .0093 15.08 .0064 16.14 .0017
  1267. 17.06 .0020 18.10 .0025 19.14 .0023 20.18 .0015 21.24 .0032 22.29 .0029 23.32 .0014 24.37 .0005
  1268. 25.43 .0030 26.50 .0022 27.60 .0027 28.64 .0024 29.76 .0035 30.81 .0136 31.96 .0025 33.02 .0003
  1269. 34.13 .0005 35.25 .0007 36.40 .0014 37.51 .0020 38.64 .0012 39.80 .0019 40.97 .0004 42.09 .0003
  1270. 43.24 .0003 44.48 .0002 45.65 .0024 46.86 .0005 48.07 .0013 49.27 .0008 50.49 .0006 52.95 .0001
  1271. 54.23 .0005 55.45 .0004 56.73 .0001 58.03 .0003 59.29 .0002 60.59 .0003 62.04 .0002 65.89 .0002
  1272. 67.23 .0002 68.61 .0002 69.97 .0004 71.36 .0005 85.42 .0001)
  1273. (1.98 .0256 2.96 .0158 3.95 .0310 4.94 .0411 5.95 .0238 6.94 .0152 7.93 .0011
  1274. 8.95 .0185 9.92 .0166 10.93 .0306 11.94 .0258 12.96 .0202 13.97 .0403 14.95 .0228 15.93 .0005
  1275. 17.01 .0072 18.02 .0034 19.06 .0028 20.08 .0124 21.13 .0137 22.16 .0102 23.19 .0058 23.90 .0013
  1276. 25.30 .0039 26.36 .0039 27.41 .0025 28.47 .0071 29.64 .0031 30.60 .0027 31.71 .0021 32.84 .0003
  1277. 33.82 .0002 35.07 .0019 36.09 .0054 37.20 .0038 38.33 .0024 39.47 .0055 40.55 .0016 41.77 .0006
  1278. 42.95 .0002 43.27 .0018 44.03 .0006 45.25 .0019 46.36 .0033 47.50 .0024 48.87 .0012 50.03 .0016
  1279. 51.09 .0004 53.52 .0017 54.74 .0012 56.17 .0003 57.40 .0011 58.42 .0020 59.70 .0007 61.29 .0008
  1280. 62.56 .0003 63.48 .0002 64.83 .0002 66.12 .0012 67.46 .0017 68.81 .0003 69.13 .0003 70.53 .0002
  1281. 71.84 .0001 73.28 .0002 75.52 .0010 76.96 .0005 77.93 .0003 78.32 .0003 79.73 .0003 81.69 .0002
  1282. 82.52 .0001 84.01 .0001 84.61 .0002 86.88 .0001 88.36 .0002 89.85 .0002 91.35 .0003 92.86 .0002
  1283. 93.40 .0001 105.28 .0002 106.22 .0002 107.45 .0001 108.70 .0003 122.08 .0002)
  1284. (1.97 .0264 2.97 .0211 3.98 .0234 4.98 .0307 5.96 .0085 6.94 .0140 7.93 .0005
  1285. 8.96 .0112 9.96 .0209 10.98 .0194 11.98 .0154 12.99 .0274 13.99 .0127 15.01 .0101 15.99 .0002
  1286. 17.04 .0011 18.08 .0032 19.14 .0028 20.12 .0054 21.20 .0053 22.13 .0028 23.22 .0030 24.32 .0006
  1287. 25.24 .0004 26.43 .0028 27.53 .0048 28.52 .0039 29.54 .0047 30.73 .0044 31.82 .0007 32.94 .0008
  1288. 34.04 .0012 35.13 .0018 36.29 .0007 37.35 .0075 38.51 .0045 39.66 .0014 40.90 .0004 41.90 .0002
  1289. 43.08 .0002 44.24 .0017 45.36 .0013 46.68 .0020 47.79 .0015 48.98 .0010 50.21 .0012 51.34 .0001
  1290. 53.82 .0003 55.09 .0004 56.23 .0005 57.53 .0004 58.79 .0005 59.30 .0002 60.03 .0002 61.40 .0003
  1291. 62.84 .0001 66.64 .0001 67.97 .0001 69.33 .0001 70.68 .0001 73.57 .0002 75.76 .0002 76.45 .0001
  1292. 79.27 .0001 80.44 .0002 81.87 .0002)
  1293. (2.00 .0311 2.99 .0086 3.99 .0266 4.97 .0123 5.98 .0235 6.97 .0161 7.97 .0008
  1294. 8.96 .0088 9.96 .0621 10.99 .0080 11.99 .0034 12.99 .0300 14.03 .0228 15.04 .0105 16.03 .0004
  1295. 17.06 .0036 18.09 .0094 18.95 .0009 20.17 .0071 21.21 .0161 22.25 .0106 23.28 .0104 24.33 .0008
  1296. 25.38 .0030 26.46 .0035 27.50 .0026 28.59 .0028 29.66 .0128 30.75 .0139 31.81 .0038 32.93 .0006
  1297. 34.04 .0004 35.16 .0005 36.25 .0023 37.35 .0012 38.46 .0021 39.59 .0035 40.71 .0006 41.86 .0007
  1298. 42.42 .0001 43.46 .0003 44.17 .0032 45.29 .0013 46.57 .0004 47.72 .0011 48.79 .0005 50.11 .0005
  1299. 51.29 .0003 52.47 .0002 53.68 .0004 55.02 .0005 56.18 .0003 57.41 .0003 58.75 .0007 59.33 .0009
  1300. 60.00 .0004 61.34 .0001 64.97 .0003 65.20 .0002 66.48 .0002 67.83 .0002 68.90 .0003 70.25 .0003
  1301. 71.59 .0002 73.68 .0001 75.92 .0001 77.08 .0002 78.45 .0002 81.56 .0002 82.99 .0001 88.39 .0001)
  1302. ( .97 .0059 1.98 .0212 2.99 .0153 3.99 .0227 4.96 .0215 5.97 .0153 6.98 .0085
  1303. 7.98 .0007 8.97 .0179 9.98 .0512 10.98 .0322 12.00 .0098 13.02 .0186 14.00 .0099 15.05 .0109
  1304. 15.88 .0011 17.07 .0076 18.11 .0071 19.12 .0045 20.16 .0038 21.23 .0213 22.27 .0332 23.34 .0082
  1305. 24.34 .0014 25.42 .0024 26.47 .0012 27.54 .0014 28.60 .0024 29.72 .0026 30.10 .0008 31.91 .0021
  1306. 32.13 .0011 33.02 .0007 34.09 .0014 35.17 .0007 36.27 .0024 37.39 .0029 38.58 .0014 39.65 .0017
  1307. 40.95 .0012 41.97 .0004 42.43 .0002 43.49 .0001 44.31 .0012 45.42 .0031 46.62 .0017 47.82 .0013
  1308. 49.14 .0013 50.18 .0010 51.54 .0003 53.90 .0006 55.06 .0010 56.31 .0003 57.63 .0001 59.02 .0003
  1309. 60.09 .0004 60.35 .0004 61.62 .0009 63.97 .0001 65.19 .0001 65.54 .0002 66.92 .0002 67.94 .0002
  1310. 69.17 .0003 69.60 .0004 70.88 .0002 72.24 .0002 76.12 .0001 78.94 .0001 81.75 .0001 82.06 .0001
  1311. 83.53 .0001 90.29 .0002 91.75 .0001 92.09 .0002 93.28 .0001 97.07 .0001)
  1312. (1.98 .0159 2.98 .1008 3.98 .0365 4.98 .0133 5.97 .0101 6.97 .0115 7.97 .0007
  1313. 8.99 .0349 10.01 .0342 11.01 .0236 12.00 .0041 13.02 .0114 14.05 .0137 15.06 .0100 16.05 .0007
  1314. 17.04 .0009 18.12 .0077 19.15 .0023 20.12 .0017 21.24 .0113 22.26 .0126 23.30 .0093 24.36 .0007
  1315. 25.43 .0007 26.47 .0009 27.55 .0013 28.59 .0025 29.61 .0010 30.77 .0021 31.86 .0023 32.96 .0003
  1316. 34.03 .0007 35.06 .0005 36.20 .0006 37.34 .0006 38.36 .0009 39.60 .0016 40.69 .0005 41.77 .0002
  1317. 42.92 .0002 44.02 .0003 45.24 .0006 46.33 .0004 47.50 .0007 48.71 .0007 49.87 .0002 51.27 .0002
  1318. 53.42 .0003 55.88 .0003 57.10 .0004 58.34 .0002 59.86 .0003 61.13 .0003 67.18 .0001 68.50 .0001
  1319. 71.17 .0001 83.91 .0001 90.55 .0001)
  1320. ( .98 .0099 2.00 .0181 2.99 .0353 3.98 .0285 4.97 .0514 5.96 .0402 6.96 .0015
  1321. 7.98 .0012 8.98 .0175 9.98 .0264 10.98 .0392 11.98 .0236 13.00 .0153 14.04 .0049 15.00 .0089
  1322. 16.01 .0001 17.03 .0106 18.03 .0028 19.05 .0024 20.08 .0040 21.11 .0103 22.12 .0104 23.20 .0017
  1323. 24.19 .0008 25.20 .0007 26.24 .0011 27.36 .0009 27.97 .0030 29.40 .0044 30.37 .0019 31.59 .0017
  1324. 32.65 .0008 33.59 .0005 34.79 .0009 35.75 .0027 36.88 .0035 37.93 .0039 39.00 .0031 40.08 .0025
  1325. 41.16 .0010 43.25 .0004 44.52 .0012 45.62 .0023 45.85 .0012 47.00 .0006 47.87 .0008 48.99 .0003
  1326. 50.48 .0003 51.62 .0001 52.43 .0001 53.56 .0002 54.76 .0002 56.04 .0002 56.68 .0006 57.10 .0003
  1327. 58.28 .0005 59.47 .0003 59.96 .0002 60.67 .0001 63.08 .0002 64.29 .0002 66.72 .0001 67.97 .0001
  1328. 68.65 .0001 70.43 .0001 79.38 .0001 80.39 .0001 82.39 .0001)
  1329. (1.00 .0765 1.99 .0151 2.99 .0500 3.99 .0197 5.00 .0260 6.00 .0145 6.98 .0128
  1330. 7.97 .0004 8.98 .0158 9.99 .0265 11.02 .0290 12.02 .0053 13.03 .0242 14.03 .0103 15.06 .0054
  1331. 16.04 .0006 17.08 .0008 18.10 .0058 19.16 .0011 20.16 .0055 21.18 .0040 22.20 .0019 23.22 .0014
  1332. 24.05 .0005 25.31 .0019 26.38 .0018 27.44 .0022 28.45 .0024 29.57 .0073 30.58 .0032 31.66 .0071
  1333. 32.73 .0015 33.85 .0005 34.96 .0003 36.00 .0020 37.11 .0018 38.18 .0055 39.23 .0006 40.33 .0004
  1334. 41.52 .0003 43.41 .0028 45.05 .0003 45.99 .0002 47.07 .0003 48.52 .0002 49.48 .0003 50.63 .0003
  1335. 51.81 .0002 54.05 .0002 55.24 .0001 56.62 .0001 57.81 .0004 59.16 .0013 60.23 .0003 66.44 .0001
  1336. 68.99 .0004 75.49 .0001 87.56 .0004)
  1337. ( .98 .0629 1.99 .0232 2.98 .0217 4.00 .0396 4.98 .0171 5.97 .0098 6.99 .0167
  1338. 7.99 .0003 8.98 .0192 9.98 .0266 10.99 .0256 12.01 .0061 13.02 .0135 14.02 .0062 15.05 .0158
  1339. 16.06 .0018 17.08 .0101 18.09 .0053 19.11 .0074 20.13 .0020 21.17 .0052 22.22 .0077 23.24 .0035
  1340. 24.00 .0009 25.32 .0016 26.40 .0022 27.43 .0005 28.55 .0026 29.60 .0026 30.65 .0010 31.67 .0019
  1341. 32.77 .0008 33.81 .0003 34.91 .0003 36.01 .0005 37.11 .0010 38.20 .0014 39.29 .0039 40.43 .0012
  1342. 41.50 .0006 43.38 .0017 43.75 .0002 44.94 .0005 46.13 .0002 47.11 .0003 48.28 .0005 48.42 .0005
  1343. 49.44 .0003 50.76 .0004 51.93 .0002 54.15 .0003 55.31 .0005 55.50 .0003 56.98 .0003 57.90 .0004
  1344. 60.33 .0002 61.39 .0001 61.59 .0001 65.09 .0002 66.34 .0001 68.85 .0001 70.42 .0002 71.72 .0001
  1345. 73.05 .0003 79.65 .0001 85.28 .0002 93.52 .0001)
  1346. (1.02 .0185 1.99 .0525 2.98 .0613 3.99 .0415 4.98 .0109 5.97 .0248 6.99 .0102
  1347. 7.98 .0005 8.98 .0124 9.99 .0103 10.99 .0124 12.00 .0016 13.01 .0029 14.03 .0211 15.04 .0128
  1348. 16.07 .0021 17.09 .0009 18.09 .0043 19.14 .0022 20.13 .0016 21.20 .0045 22.21 .0088 23.26 .0046
  1349. 24.29 .0013 25.35 .0009 26.39 .0028 27.49 .0009 28.51 .0006 29.58 .0012 30.70 .0010 31.74 .0019
  1350. 32.75 .0002 33.85 .0001 34.95 .0005 36.02 .0003 37.16 .0009 38.25 .0018 39.35 .0008 40.54 .0004
  1351. 41.61 .0002 43.40 .0004 43.74 .0003 45.05 .0001 46.11 .0003 47.40 .0002 48.36 .0004 49.55 .0004
  1352. 50.72 .0002 52.00 .0001 55.58 .0002 57.02 .0001 57.98 .0002 59.13 .0003 61.56 .0001 66.56 .0001
  1353. 87.65 .0002)
  1354. (1.00 .0473 1.99 .0506 2.99 .0982 3.99 .0654 5.00 .0196 5.99 .0094 6.99 .0118
  1355. 7.93 .0001 8.99 .0057 10.01 .0285 11.01 .0142 12.03 .0032 13.03 .0056 14.06 .0064 15.06 .0059
  1356. 16.11 .0005 17.09 .0033 18.14 .0027 19.15 .0014 20.17 .0010 21.21 .0059 22.26 .0043 23.31 .0031
  1357. 24.31 .0018 25.33 .0009 26.41 .0005 27.47 .0015 28.53 .0015 29.58 .0041 30.65 .0025 31.73 .0011
  1358. 32.83 .0010 34.98 .0003 36.07 .0009 37.23 .0001 38.26 .0020 39.41 .0014 40.53 .0005 41.40 .0003
  1359. 42.80 .0002 43.48 .0028 43.93 .0001 45.03 .0003 46.18 .0007 47.41 .0001 48.57 .0002 49.67 .0001
  1360. 50.83 .0002 54.39 .0001 55.58 .0002 57.97 .0005 58.11 .0002 59.21 .0001 60.42 .0002 61.66 .0001)
  1361. (1.00 .0503 2.00 .0963 2.99 .1304 3.99 .0218 4.98 .0041 5.98 .0292 6.98 .0482
  1362. 7.99 .0005 8.99 .0280 10.00 .0237 11.00 .0152 12.02 .0036 12.95 .0022 14.06 .0111 15.07 .0196
  1363. 16.08 .0016 17.11 .0044 18.13 .0073 19.17 .0055 20.19 .0028 21.20 .0012 22.27 .0068 23.30 .0036
  1364. 24.35 .0012 25.35 .0002 26.46 .0005 27.47 .0005 28.59 .0009 29.65 .0021 30.70 .0020 31.78 .0012
  1365. 32.89 .0010 35.06 .0005 36.16 .0008 37.27 .0010 38.36 .0010 39.47 .0014 40.58 .0004 41.43 .0007
  1366. 41.82 .0003 43.48 .0008 44.53 .0001 45.25 .0003 46.43 .0002 47.46 .0002 48.76 .0005 49.95 .0004
  1367. 50.96 .0002 51.12 .0002 52.33 .0001 54.75 .0001 55.75 .0002 56.90 .0002 58.17 .0002 59.40 .0004
  1368. 60.62 .0002 65.65 .0001 66.91 .0002 69.91 .0001 71.25 .0002)
  1369. (1.00 .1243 1.98 .1611 3.00 .0698 3.98 .0390 5.00 .0138 5.99 .0154 7.01 .0287
  1370. 8.01 .0014 9.01 .0049 10.00 .0144 11.01 .0055 12.05 .0052 13.01 .0011 14.05 .0118 15.07 .0154
  1371. 16.12 .0028 17.14 .0061 18.25 .0007 19.22 .0020 20.24 .0011 21.27 .0029 22.30 .0046 23.34 .0049
  1372. 24.35 .0004 25.45 .0003 26.47 .0007 27.59 .0008 28.16 .0009 29.12 .0002 29.81 .0006 30.81 .0009
  1373. 31.95 .0004 33.00 .0011 34.12 .0005 35.18 .0003 36.30 .0008 37.38 .0003 38.55 .0003 39.64 .0006
  1374. 40.77 .0007 41.52 .0006 41.89 .0006 43.04 .0011 43.60 .0009 44.31 .0002 45.68 .0002 46.56 .0003
  1375. 47.60 .0001 48.83 .0006 50.01 .0003 51.27 .0003 56.04 .0005 57.21 .0003 58.56 .0004 59.83 .0003
  1376. 61.05 .0001 62.20 .0001 67.37 .0002 76.53 .0001)
  1377. ( .99 .0222 1.99 .0678 2.99 .0683 4.00 .0191 5.00 .0119 6.01 .0232 6.98 .0336
  1378. 7.99 .0082 9.01 .0201 10.01 .0189 11.01 .0041 12.01 .0053 13.05 .0154 14.04 .0159 15.06 .0092
  1379. 16.11 .0038 17.12 .0014 18.15 .0091 19.16 .0006 20.30 .0012 21.25 .0061 22.28 .0099 23.34 .0028
  1380. 24.38 .0012 25.43 .0016 26.49 .0048 27.55 .0025 28.62 .0015 29.71 .0032 30.78 .0077 31.88 .0011
  1381. 32.97 .0007 34.08 .0006 35.16 .0008 36.28 .0004 37.41 .0006 38.54 .0005 39.62 .0002 40.80 .0003
  1382. 41.93 .0001 43.06 .0002 44.21 .0003 45.38 .0002 46.54 .0007 47.78 .0003 48.95 .0004 50.10 .0003
  1383. 51.37 .0002 53.79 .0003 56.20 .0001 58.71 .0002 66.47 .0003)
  1384. (1.01 .0241 1.99 .1011 2.98 .0938 3.98 .0081 4.99 .0062 5.99 .0291 6.99 .0676
  1385. 7.59 .0004 8.98 .0127 9.99 .0112 10.99 .0142 12.00 .0029 13.02 .0071 14.02 .0184 15.03 .0064
  1386. 16.07 .0010 17.09 .0011 18.11 .0010 19.15 .0060 20.19 .0019 21.24 .0025 22.29 .0013 23.31 .0050
  1387. 25.41 .0030 26.50 .0018 27.53 .0006 28.63 .0012 29.66 .0013 30.77 .0020 31.84 .0006 34.04 .0001
  1388. 35.14 .0001 36.32 .0004 37.41 .0007 38.53 .0007 39.67 .0009 40.85 .0003 45.49 .0002 46.65 .0001
  1389. 47.81 .0004 49.01 .0002 53.91 .0002 55.14 .0002 57.69 .0002)
  1390. (1.00 .0326 2.00 .1066 2.99 .1015 4.00 .0210 4.97 .0170 5.99 .0813 6.98 .0820
  1391. 7.96 .0011 8.99 .0248 10.03 .0107 11.01 .0126 12.01 .0027 13.01 .0233 14.04 .0151 15.05 .0071
  1392. 16.04 .0002 17.10 .0061 18.12 .0059 19.15 .0087 20.23 .0005 21.25 .0040 22.30 .0032 23.35 .0004
  1393. 24.40 .0001 25.45 .0030 26.54 .0022 27.60 .0003 28.70 .0009 29.80 .0029 30.85 .0006 31.97 .0006
  1394. 34.19 .0004 35.30 .0003 36.43 .0007 37.56 .0005 38.68 .0019 39.88 .0013 41.00 .0003 43.35 .0003
  1395. 44.51 .0002 45.68 .0006 46.93 .0010 48.11 .0006 49.29 .0003 55.58 .0002)
  1396. ( .98 .0113 1.99 .0967 3.00 .0719 3.98 .0345 4.98 .0121 6.00 .0621 7.00 .0137
  1397. 7.98 .0006 9.01 .0314 10.01 .0171 11.02 .0060 12.03 .0024 13.05 .0077 14.07 .0040 15.12 .0032
  1398. 16.13 .0004 17.15 .0011 18.20 .0028 19.18 .0003 20.26 .0003 21.31 .0025 22.35 .0021 23.39 .0005
  1399. 25.55 .0002 26.62 .0014 27.70 .0003 28.78 .0005 29.90 .0030 31.01 .0011 32.12 .0005 34.31 .0001
  1400. 35.50 .0002 36.62 .0002 37.76 .0005 38.85 .0002 40.09 .0004 43.60 .0001 44.73 .0002 46.02 .0002
  1401. 47.25 .0004 48.44 .0004)
  1402. ( .99 .0156 1.98 .0846 2.98 .0178 3.98 .0367 4.98 .0448 5.98 .0113 6.99 .0189
  1403. 8.00 .0011 9.01 .0247 10.02 .0089 11.01 .0184 12.03 .0105 13.00 .0039 14.07 .0116 15.09 .0078
  1404. 16.13 .0008 17.14 .0064 18.19 .0029 19.22 .0028 20.25 .0017 21.32 .0043 22.37 .0055 23.42 .0034
  1405. 24.48 .0004 25.54 .0002 26.61 .0017 27.70 .0011 28.80 .0002 29.89 .0019 30.97 .0028 32.09 .0007
  1406. 34.30 .0002 35.44 .0003 36.55 .0001 37.69 .0004 38.93 .0002 40.05 .0005 41.20 .0005 42.37 .0002
  1407. 43.54 .0003 44.73 .0001 45.95 .0002 47.16 .0001 48.43 .0005 49.65 .0004 55.90 .0002 59.81 .0004)
  1408. (1.01 .0280 2.00 .0708 2.99 .0182 3.99 .0248 4.98 .0245 5.98 .0279 6.98 .0437
  1409. 7.99 .0065 8.99 .0299 10.00 .0073 10.99 .0011 12.03 .0122 13.03 .0028 14.08 .0044 15.11 .0097
  1410. 16.15 .0010 17.17 .0025 18.19 .0017 19.24 .0008 20.28 .0040 21.32 .0024 22.38 .0008 23.46 .0032
  1411. 24.52 .0010 25.59 .0008 26.68 .0009 27.76 .0012 28.88 .0003 29.95 .0005 31.05 .0017 32.14 .0002
  1412. 33.29 .0003 37.88 .0002 39.03 .0002 40.19 .0004 41.37 .0003 43.74 .0002 46.20 .0001 48.68 .0001
  1413. 49.93 .0001 51.19 .0002)
  1414. (1.00 .0225 1.99 .0921 2.98 .0933 3.99 .0365 4.99 .0100 5.98 .0213 6.98 .0049
  1415. 7.98 .0041 8.98 .0090 9.99 .0068 11.01 .0040 12.03 .0086 13.02 .0015 14.04 .0071 15.09 .0082
  1416. 16.14 .0011 17.15 .0014 18.18 .0010 19.26 .0013 20.26 .0005 21.33 .0006 22.36 .0011 23.46 .0016
  1417. 24.52 .0004 25.59 .0002 26.70 .0006 27.78 .0007 28.87 .0002 30.03 .0008 31.14 .0010 32.24 .0006
  1418. 33.37 .0002 35.67 .0003 37.99 .0004 39.17 .0004 40.35 .0005 41.53 .0001 46.42 .0001)
  1419. (1.00 .0465 1.99 .0976 2.98 .0678 4.00 .0727 4.99 .0305 5.98 .0210 6.98 .0227
  1420. 8.00 .0085 9.01 .0183 10.02 .0258 11.05 .0003 12.06 .0061 13.05 .0021 14.10 .0089 15.12 .0077
  1421. 16.16 .0016 17.21 .0061 18.23 .0011 19.29 .0031 20.36 .0031 21.41 .0007 22.48 .0013 23.55 .0020
  1422. 24.64 .0004 25.74 .0005 26.81 .0006 27.95 .0006 29.03 .0001 30.22 .0010 31.30 .0004 32.48 .0001
  1423. 33.60 .0002 38.30 .0003)
  1424. (1.00 .0674 1.99 .0841 2.98 .0920 3.99 .0328 4.99 .0368 5.98 .0206 6.99 .0246
  1425. 8.01 .0048 9.01 .0218 10.03 .0155 11.05 .0048 12.06 .0077 13.00 .0020 14.10 .0083 15.15 .0084
  1426. 16.18 .0015 17.22 .0039 18.27 .0032 19.34 .0026 20.40 .0012 21.47 .0009 22.54 .0008 23.62 .0016
  1427. 24.71 .0005 25.82 .0004 26.91 .0002 28.03 .0008 29.17 .0002 30.32 .0028 31.45 .0004 32.61 .0005
  1428. 33.77 .0001 36.14 .0003 37.32 .0002 38.54 .0005 39.75 .0002 42.23 .0002 48.65 .0001)
  1429. (1.01 .0423 1.99 .0240 2.98 .0517 4.00 .0493 5.00 .0324 6.00 .0094 6.99 .0449
  1430. 7.99 .0050 9.00 .0197 10.03 .0132 11.03 .0009 12.07 .0017 13.08 .0023 14.12 .0094 15.16 .0071
  1431. 16.21 .0020 17.25 .0005 18.30 .0027 19.04 .0004 20.43 .0022 21.51 .0002 22.59 .0006 23.72 .0018
  1432. 24.80 .0002 25.88 .0002 27.03 .0002 28.09 .0006 29.31 .0002 30.46 .0004 31.61 .0007 32.78 .0005
  1433. 33.95 .0001 36.34 .0002 37.56 .0001 38.80 .0001 40.02 .0001 44.14 .0001)
  1434. (1.00 .0669 1.99 .0909 2.99 .0410 3.98 .0292 4.98 .0259 5.98 .0148 6.98 .0319
  1435. 7.99 .0076 9.01 .0056 10.02 .0206 11.04 .0032 12.05 .0085 13.08 .0040 14.12 .0037 15.16 .0030
  1436. 16.20 .0013 17.24 .0021 18.30 .0010 19.36 .0015 20.44 .0013 21.50 .0009 22.60 .0015 23.69 .0014
  1437. 24.80 .0006 25.87 .0002 27.02 .0006 28.12 .0002 29.28 .0003 30.43 .0002 31.59 .0007 32.79 .0001
  1438. 35.14 .0001 37.57 .0001 40.03 .0002 41.28 .0004 44.10 .0001)
  1439. ( .99 .0421 1.99 .1541 2.98 .0596 3.98 .0309 4.98 .0301 5.99 .0103 7.00 .0240
  1440. 8.01 .0073 9.01 .0222 10.04 .0140 11.05 .0033 12.08 .0045 13.13 .0009 14.13 .0015 15.21 .0026
  1441. 16.24 .0003 17.30 .0004 18.35 .0010 19.39 .0003 20.50 .0015 21.57 .0003 22.68 .0011 23.80 .0005
  1442. 24.90 .0008 26.02 .0002 27.16 .0001 28.30 .0006 29.48 .0002 31.81 .0005 33.00 .0003 34.21 .0001
  1443. 37.89 .0001)
  1444. ( .99 .0389 2.00 .2095 3.00 .0835 3.99 .0289 5.00 .0578 5.99 .0363 7.01 .0387
  1445. 8.01 .0056 9.04 .0173 10.05 .0175 11.08 .0053 12.10 .0056 13.15 .0064 14.19 .0036 15.22 .0019
  1446. 16.29 .0010 17.36 .0017 18.43 .0018 19.51 .0004 20.60 .0011 21.70 .0003 22.82 .0003 23.95 .0001
  1447. 25.05 .0004 26.17 .0001 28.50 .0003 29.68 .0001 32.07 .0003 33.28 .0004 34.52 .0001)
  1448. (1.00 .1238 1.99 .2270 3.00 .0102 3.99 .0181 4.98 .0415 6.00 .0165 7.01 .0314
  1449. 8.02 .0148 9.04 .0203 10.05 .0088 11.07 .0062 12.11 .0070 13.14 .0054 14.19 .0028 15.24 .0044
  1450. 16.30 .0029 17.38 .0009 18.45 .0026 19.56 .0003 20.65 .0025 21.74 .0014 22.87 .0013 23.99 .0007
  1451. 25.15 .0002 27.46 .0004 28.39 .0006 28.65 .0004 29.85 .0001 31.05 .0002 32.27 .0003 33.52 .0002
  1452. 34.76 .0003)
  1453. (1.00 .1054 2.00 .2598 2.99 .0369 3.98 .0523 4.99 .0020 5.99 .0051 7.00 .0268
  1454. 8.01 .0027 9.04 .0029 10.05 .0081 11.08 .0047 12.12 .0051 13.16 .0091 14.19 .0015 15.27 .0030
  1455. 16.34 .0017 17.42 .0006 18.51 .0003 19.61 .0007 20.72 .0003 21.84 .0001 22.99 .0010 24.13 .0001
  1456. 28.44 .0001 30.09 .0001)
  1457. ( .99 .0919 2.00 .0418 2.99 .0498 3.99 .0135 4.99 .0026 6.00 .0155 7.01 .0340
  1458. 8.02 .0033 9.04 .0218 10.08 .0084 11.11 .0057 12.15 .0051 13.21 .0043 14.25 .0015 15.31 .0023
  1459. 16.40 .0008 17.48 .0004 18.59 .0016 19.71 .0010 20.84 .0018 21.98 .0002 23.11 .0013 24.26 .0003
  1460. 26.67 .0002 29.12 .0002 30.37 .0002 31.62 .0003 32.92 .0001)
  1461. ( .99 .1174 1.99 .1126 2.99 .0370 3.99 .0159 5.01 .0472 6.01 .0091 7.03 .0211
  1462. 8.05 .0015 9.07 .0098 10.11 .0038 11.15 .0042 12.20 .0018 13.24 .0041 14.32 .0033 15.41 .0052
  1463. 16.49 .0001 17.61 .0004 18.71 .0004 19.84 .0004 20.99 .0002 22.14 .0006 23.31 .0006 24.50 .0004
  1464. 25.70 .0002 28.09 .0002 28.66 .0002 32.00 .0001)
  1465. (1.00 .1085 2.00 .1400 2.99 .0173 3.99 .0229 5.00 .0272 6.02 .0077 7.03 .0069
  1466. 8.04 .0017 9.08 .0045 10.10 .0030 11.15 .0040 12.20 .0007 13.25 .0019 14.32 .0008 15.42 .0024
  1467. 16.50 .0002 17.59 .0005 18.71 .0003 19.83 .0002 20.98 .0005 23.29 .0008)
  1468. (1.00 .0985 2.00 .1440 2.99 .0364 3.99 .0425 5.00 .0190 6.01 .0089 7.03 .0278
  1469. 8.04 .0006 9.07 .0083 10.10 .0021 11.14 .0050 12.18 .0005 13.26 .0036 14.33 .0005 15.41 .0026
  1470. 17.62 .0004 18.75 .0004 19.89 .0003 21.04 .0012 22.21 .0002 23.38 .0004 27.04 .0001)
  1471. ( .99 .1273 2.00 .1311 2.99 .0120 4.00 .0099 5.00 .0235 6.02 .0068 7.03 .0162
  1472. 8.06 .0009 9.08 .0083 10.12 .0014 11.17 .0050 12.24 .0010 13.29 .0013 14.39 .0022 15.48 .0011
  1473. 16.59 .0002 17.70 .0003 18.84 .0010 20.00 .0003 21.17 .0003 23.56 .0004 28.79 .0003)
  1474. (1.00 .1018 2.00 .1486 3.00 .0165 4.00 .0186 5.01 .0194 6.02 .0045 7.04 .0083
  1475. 8.06 .0012 9.10 .0066 10.15 .0009 11.19 .0008 12.26 .0011 13.34 .0028 14.45 .0006 15.53 .0009
  1476. 16.66 .0002 17.79 .0006 18.94 .0005 20.11 .0003 21.29 .0005 22.49 .0003 23.73 .0005 26.22 .0001
  1477. 27.52 .0001 28.88 .0002)
  1478. (1.00 .1889 1.99 .1822 3.00 .0363 4.00 .0047 5.01 .0202 6.03 .0053 7.05 .0114
  1479. 8.01 .0002 9.13 .0048 10.17 .0010 11.23 .0033 12.30 .0010 13.38 .0006 14.50 .0002 15.62 .0010
  1480. 20.27 .0001 21.47 .0001)
  1481. (1.00 .0522 1.99 .0763 2.99 .0404 4.00 .0139 5.01 .0185 6.01 .0021 7.06 .0045
  1482. 8.09 .0002 9.11 .0003 10.17 .0006 11.25 .0004 12.32 .0005 13.40 .0003 14.53 .0003 15.65 .0007
  1483. 16.80 .0001 17.95 .0002 19.14 .0006 20.34 .0002 21.56 .0003)
  1484. ( .99 .1821 1.99 .0773 3.00 .0125 4.01 .0065 5.01 .0202 6.03 .0071 7.05 .0090
  1485. 8.08 .0006 9.13 .0008 10.18 .0013 11.25 .0010 12.33 .0012 13.42 .0006 14.54 .0005 15.65 .0004
  1486. 17.97 .0002 19.15 .0001)
  1487. (1.00 .1868 2.00 .0951 3.00 .0147 4.01 .0134 5.02 .0184 6.04 .0132 7.06 .0011
  1488. 8.11 .0008 9.15 .0010 10.22 .0012 11.30 .0011 12.40 .0003 13.11 .0004 13.49 .0002 14.62 .0003
  1489. 15.77 .0001)
  1490. (1.00 .1933 2.00 .0714 3.00 .0373 4.00 .0108 5.02 .0094 6.02 .0010 7.07 .0022
  1491. 8.11 .0002 9.16 .0065 10.23 .0015 11.31 .0023 12.40 .0003 13.53 .0014 14.66 .0002 15.81 .0011
  1492. 18.20 .0002 19.41 .0001)
  1493. ( .99 .2113 1.99 .0877 3.00 .0492 4.01 .0094 5.02 .0144 6.04 .0103 7.07 .0117
  1494. 8.12 .0006 9.19 .0019 10.25 .0007 11.35 .0017 12.45 .0010 13.58 .0003 14.74 .0003 15.91 .0003
  1495. 19.57 .0002)
  1496. ( .99 .2455 1.99 .0161 3.00 .0215 4.01 .0036 5.03 .0049 6.04 .0012 7.09 .0036
  1497. 8.14 .0011 9.21 .0009 10.30 .0001 11.40 .0012 12.50 .0001 13.66 .0005 14.84 .0001)
  1498. (1.00 .1132 2.00 .0252 3.00 .0292 4.01 .0136 5.03 .0045 6.06 .0022 7.11 .0101
  1499. 8.17 .0004 9.23 .0010 10.33 .0012 11.44 .0013 12.58 .0011 13.75 .0002 14.93 .0005 16.14 .0002)
  1500. (1.00 .1655 2.00 .0445 3.00 .0120 4.00 .0038 5.02 .0015 6.07 .0038 7.11 .0003
  1501. 8.19 .0002 9.25 .0010 10.36 .0011 11.48 .0005 12.63 .0002 13.79 .0003 16.24 .0002)
  1502. ( .99 .3637 1.99 .0259 3.01 .0038 4.01 .0057 5.03 .0040 6.07 .0067 7.12 .0014
  1503. 8.19 .0004 9.27 .0003 10.38 .0002 12.67 .0001)
  1504. (1.00 .1193 2.00 .0230 3.00 .0104 4.01 .0084 5.04 .0047 6.08 .0035 7.13 .0041
  1505. 8.20 .0002 9.29 .0005 10.40 .0005 11.53 .0003 12.70 .0002 13.91 .0002)
  1506. (1.00 .0752 2.00 .0497 3.00 .0074 4.02 .0076 5.05 .0053 6.09 .0043 7.15 .0024
  1507. 8.22 .0001 9.32 .0006 10.45 .0002 11.58 .0001 12.78 .0001 15.22 .0001)
  1508. (1.00 .2388 2.00 .0629 3.01 .0159 4.04 .0063 5.07 .0051 6.12 .0045 7.19 .0026
  1509. 8.29 .0015 9.43 .0001 11.75 .0002)
  1510. (1.00 .1919 2.01 .0116 3.01 .0031 4.03 .0090 5.07 .0061 6.13 .0036 7.19 .0013
  1511. 8.30 .0016 9.13 .0001 10.59 .0002 11.78 .0002)
  1512. (1.00 .1296 2.00 .0135 3.01 .0041 4.04 .0045 5.09 .0028 6.14 .0046 7.23 .0007
  1513. 8.32 .0007 9.50 .0001)
  1514. (1.00 .0692 2.00 .0209 3.02 .0025 4.05 .0030 5.09 .0047 6.17 .0022 7.25 .0015
  1515. 8.36 .0015 9.53 .0010 10.69 .0001 13.40 .0001)
  1516. (1.00 .1715 2.00 .0142 3.01 .0024 4.03 .0015 5.07 .0017 6.13 .0018 7.22 .0009
  1517. 8.33 .0014 9.51 .0007 10.69 .0002)
  1518. (1.00 .1555 2.01 .0148 3.02 .0007 4.06 .0006 5.10 .0005 6.16 .0008 7.26 .0009
  1519. 8.39 .0008 9.58 .0002)
  1520. (1.00 .1357 2.00 .0116 3.02 .0026 4.04 .0009 5.09 .0004 6.17 .0005 7.27 .0002
  1521. 8.40 .0001)
  1522. (1.00 .2185 2.01 .0087 3.03 .0018 4.06 .0025 5.11 .0020 6.20 .0012 7.32 .0005
  1523. 8.46 .0001 9.66 .0003)
  1524. (1.00 .2735 2.00 .0038 3.02 .0008 4.06 .0012 5.12 .0008 6.22 .0011 7.35 .0003
  1525. 8.50 .0002)
  1526. (1.00 .1441 1.99 .0062 3.01 .0023 4.05 .0011 5.11 .0012 6.20 .0003 7.33 .0004
  1527. 8.50 .0001)
  1528. (1.00 .0726 2.01 .0293 3.03 .0022 5.14 .0005 6.26 .0011 7.41 .0002 8.63 .0002)
  1529. (1.00 .0516 2.00 .0104 3.02 .0029 5.15 .0002 6.27 .0001)
  1530. (1.00 .0329 2.00 .0033 3.03 .0013 4.10 .0005 5.19 .0004 6.32 .0002)
  1531. (1.00 .0179 1.99 .0012 3.04 .0005 4.10 .0017 5.20 .0005 6.35 .0001)
  1532. (1.00 .0334 2.01 .0033 3.04 .0011 4.13 .0003 5.22 .0003)
  1533. ( .99 .0161 2.01 .0100 3.04 .0020 4.13 .0003)
  1534. (1.00 .0475 1.99 .0045 3.03 .0035 4.12 .0011)
  1535. (1.00 .0593 2.00 .0014 4.17 .0002)
  1536. (1.00 .0249 2.01 .0016)
  1537. (1.00 .0242 2.00 .0038 4.19 .0002)
  1538. (1.00 .0170 2.02 .0030)
  1539. (1.00 .0381 2.00 .0017 3.09 .0002)
  1540. (1.00 .0141 2.03 .0005 3.11 .0003 4.26 .0001)
  1541. (1.00 .0122 2.03 .0024)
  1542. (1.00 .0107 2.07 .0007 3.12 .0004)
  1543. (1.00 .0250 2.02 .0026 3.15 .0002)
  1544. (1.01 .0092)
  1545. (1.01 .0102 2.09 .0005)
  1546. (1.00 .0080 2.00 .0005 3.19 .0001)
  1547. (1.01 .0298 2.01 .0005)))
  1548. (pitch (round (* 12 (log (/ freq 32.703) 2)))))
  1549. (piano-spectra pitch)))
  1550. (let ((*piano-attack-duration* .04)
  1551. (*piano-release-duration* .2))
  1552. (define (make-piano-ampfun dur)
  1553. (let ((*db-drop-per-second* -10.0))
  1554. (let ((releaseAmp (db->linear (* *db-drop-per-second* dur)))
  1555. (attackTime (/ (* *piano-attack-duration* 100) dur)))
  1556. (list 0 0 (/ attackTime 4) 1.0 attackTime 1.0 100 releaseAmp))))
  1557. ;; This thing sounds pretty good down low, below middle c or so.
  1558. ;; The high notes sound pretty rotten--they just don't
  1559. ;; sparkle; I have a feeling that this is due to the low amplitude of the
  1560. ;; original data, and the lack of mechanical noise.
  1561. ;;
  1562. ;; The only thing you can do to alter the sound of a piano note is to set the
  1563. ;; pfreq parameter. Pfreq is used to look up the partials. By default, it's
  1564. ;; set to the requested frequency. Setting it to a neighboring freq is useful
  1565. ;; when you're repeating notes. Note that there's no nyquist detection;
  1566. ;; a high freq with a low pfreq, will give you fold over (hmmm...maybe
  1567. ;; I can get those high notes to sparkle after all).
  1568. (if (not (number? pfreq))
  1569. (set! pfreq frequency))
  1570. (let ((partials (normalize-partials (get-piano-partials pfreq)))
  1571. (beg (seconds->samples begin-time))
  1572. (newdur (+ duration *piano-attack-duration* *piano-release-duration*)))
  1573. (let ((end (+ beg (seconds->samples newdur)))
  1574. (env1dur (- newdur *piano-release-duration*))
  1575. (siz (floor (/ (length partials) 2))))
  1576. (let ((env1samples (+ beg (seconds->samples env1dur)))
  1577. (freqs (make-float-vector siz))
  1578. (phases (make-float-vector siz))
  1579. (alist (make-float-vector siz))
  1580. (locs (make-locsig degree distance reverb-amount))
  1581. (ampfun1 (make-piano-ampfun env1dur)))
  1582. (let ((ampenv1 (make-env ampfun1
  1583. :scaler amplitude
  1584. :duration env1dur
  1585. :base 10000.0))
  1586. (ampenv2 (make-env '(0 1 100 0)
  1587. :scaler (* amplitude (ampfun1 (- (length ampfun1) 1)))
  1588. :duration env1dur
  1589. :base 1.0)))
  1590. (do ((i 0 (+ i 2))
  1591. (j 0 (+ j 1)))
  1592. ((= i (length partials)))
  1593. (set! (alist j) (partials (+ i 1)))
  1594. (set! (freqs j) (hz->radians (* (partials i) frequency))))
  1595. (let ((obank (make-oscil-bank freqs phases alist #t)))
  1596. (do ((i beg (+ i 1)))
  1597. ((= i env1samples))
  1598. (locsig locs i (* (env ampenv1) (oscil-bank obank))))
  1599. (do ((i env1samples (+ i 1)))
  1600. ((= i end))
  1601. (locsig locs i (* (env ampenv2) (oscil-bank obank)))))))))))
  1602. ;;; (with-sound () (lbj-piano 0 3 440.0 .2))
  1603. (definstrument (resflt start dur driver
  1604. ranfreq noiamp noifun cosamp cosfreq1 cosfreq0 cosnum
  1605. ampcosfun freqcosfun
  1606. frq1 r1 g1 frq2 r2 g2 frq3 r3 g3
  1607. (degree 0.0)
  1608. (distance 1.0)
  1609. (reverb-amount 0.005))
  1610. ;; driver=0 -- use sum of cosines to drive the filter,
  1611. ;; driver=1 -- use white noise
  1612. ;; if noise used, ranfreq=frequency of random number generator,
  1613. ;; noiamp=amplitude thereof,
  1614. ;; noifun=amplitude envelope on white noise
  1615. ;; if ncos (i.e. a band-limited pulse train),
  1616. ;; cosamp=amplitude of pulse train,
  1617. ;; cosfreq1=top frequency (given freqcosfun) (i.e. pulse frequency)
  1618. ;; cosfreq0=bottom frequency,
  1619. ;; cosnum=number of cosines in the pulse,
  1620. ;; ampcosfun=amplitude envelope on pulse train
  1621. ;; freqcosfun=frequency envelope on pulse train
  1622. ;; There are then 3 resonators, centered at frq1, frq2, frq3,
  1623. ;; with pole-radius r1, r2, and r3 respectively, and
  1624. ;; with gains of g1, g2, and g3.
  1625. (let ((with-noise (= driver 1)))
  1626. (let ((beg (seconds->samples start))
  1627. (end (seconds->samples (+ start dur)))
  1628. (f1 (make-two-pole :radius r1 :frequency frq1))
  1629. (f2 (make-two-pole :radius r2 :frequency frq2))
  1630. (f3 (make-two-pole :radius r3 :frequency frq3))
  1631. (loc (make-locsig degree distance reverb-amount))
  1632. (frqf (and (not with-noise)
  1633. (make-env freqcosfun :duration dur
  1634. :scaler (hz->radians (- cosfreq1 cosfreq0)))))
  1635. (ampf (make-env (if with-noise
  1636. (values noifun :scaler noiamp)
  1637. (values ampcosfun :scaler cosamp))
  1638. :duration dur))
  1639. (rn (and with-noise
  1640. (make-rand :frequency ranfreq)))
  1641. (cn (and (not with-noise)
  1642. (make-ncos cosfreq0 cosnum))))
  1643. (set! (mus-xcoeff f1 0) g1)
  1644. (set! (mus-xcoeff f2 0) g2)
  1645. (set! (mus-xcoeff f3 0) g3)
  1646. (if with-noise
  1647. (do ((i beg (+ i 1)))
  1648. ((= i end))
  1649. (let ((input1 (* (env ampf) (rand rn))))
  1650. (locsig loc i (+ (two-pole f1 input1)
  1651. (two-pole f2 input1)
  1652. (two-pole f3 input1)))))
  1653. (do ((i beg (+ i 1)))
  1654. ((= i end))
  1655. (let ((input1 (* (env ampf) (ncos cn (env frqf)))))
  1656. (locsig loc i (+ (two-pole f1 input1)
  1657. (two-pole f2 input1)
  1658. (two-pole f3 input1)))))))))
  1659. ; (with-sound () (resflt 0 1.0 0 0 0 #f .1 200 230 10 '(0 0 50 1 100 0) '(0 0 100 1) 500 .995 .1 1000 .995 .1 2000 .995 .1))
  1660. ; (with-sound () (resflt 0 1.0 1 10000 .01 '(0 0 50 1 100 0) 0 0 0 0 #f #f 500 .995 .1 1000 .995 .1 2000 .995 .1))
  1661. (definstrument (scratch start file src-ratio turnaroundlist)
  1662. (let ((f (make-file->sample file))
  1663. (beg (seconds->samples start))
  1664. (turntable (apply vector turnaroundlist))
  1665. (turn-i 1)
  1666. (turns (length turnaroundlist)))
  1667. (let ((cur-sample (seconds->samples (turntable 0)))
  1668. (turn-sample (seconds->samples (turntable 1))))
  1669. (let ((func (lambda (dir)
  1670. (let ((inval (file->sample f cur-sample)))
  1671. (set! cur-sample (+ cur-sample dir))
  1672. inval)))
  1673. (turning 0)
  1674. (last-val 0.0)
  1675. (last-val2 0.0)
  1676. (rd (make-src :srate src-ratio))
  1677. (forwards (> src-ratio 0.0)))
  1678. (if (and forwards (< turn-sample cur-sample))
  1679. (set! (mus-increment rd) (- src-ratio)))
  1680. (do ((i beg (+ i 1)))
  1681. ((>= turn-i turns))
  1682. (let ((val (src rd 0.0 func)))
  1683. (if (= turning 0)
  1684. (if (and forwards (>= cur-sample turn-sample)) ;; we passed turn point going forwards
  1685. (set! turning 1)
  1686. (if (and (not forwards) (<= cur-sample turn-sample)) ;; we passed turn point going backwards
  1687. (set! turning -1)))
  1688. ;; wait for an inflection...
  1689. (if (or (and (<= last-val2 last-val) (>= last-val val))
  1690. (and (>= last-val2 last-val) (<= last-val val)))
  1691. (begin
  1692. (set! turn-i (+ turn-i 1))
  1693. (if (< turn-i turns)
  1694. (begin
  1695. (set! turn-sample (seconds->samples (turntable turn-i)))
  1696. (set! forwards (not forwards))
  1697. (set! (mus-increment rd) (- (mus-increment rd)))))
  1698. (set! turning 0))))
  1699. (set! last-val2 last-val)
  1700. (set! last-val val)
  1701. (outa i val)))))))
  1702. ;;; (with-sound () (scratch 0.0 "now.snd" 1.5 '(0.0 .5 .25 1.0)))
  1703. ;;; spectral modeling (SMS)
  1704. (definstrument (pins beg dur file amp
  1705. (transposition 1.0) ; this can be used to transpose the sound
  1706. (time-scaler 1.0) ; this can make things happen faster (< 1.0)/slower (> 1.0) in the output
  1707. (fftsize 256) ; should be a power of 2
  1708. ;; at 22050 srate, this is ok for sounds above 300Hz or so, below that you need 512 or 1024,
  1709. ;; at 44100, probably best to double these sizes -- it takes some searching sometimes.
  1710. (highest-bin 128) ; how high in fft data should we search for peaks
  1711. (max-peaks 16) ; how many spectral peaks to track at the maximum
  1712. attack) ; whether to use original attack via time domain splice
  1713. ;; do the sliding fft shuffle, translate to polar coordinates, find spectral peaks,
  1714. ;; match with current, do some interesting transformation, resynthesize using oscils
  1715. ;; All the envelopes are created on the fly. max-peaks is how many of these peaks
  1716. ;; we are willing to track at any given time.
  1717. (let ((max-peaks-1 max-peaks)
  1718. (fftsize-1 fftsize)
  1719. (highest-bin-1 highest-bin)
  1720. (start (seconds->samples beg))
  1721. (attack-size (or attack 1)))
  1722. (let* ((hop (floor (/ fftsize-1 4)))
  1723. (outhop (floor (* time-scaler hop))))
  1724. (let ((ifreq (/ 1.0 outhop))
  1725. (max-oscils (* 2 max-peaks-1)))
  1726. (let ((end (+ start (seconds->samples dur)))
  1727. (fil (make-readin file))
  1728. (fdr (make-float-vector fftsize-1))
  1729. (fdi (make-float-vector fftsize-1))
  1730. (window (make-fft-window blackman2-window fftsize-1))
  1731. (current-peak-freqs (make-float-vector max-oscils))
  1732. (last-peak-freqs (make-float-vector max-oscils))
  1733. (current-peak-amps (make-float-vector max-oscils))
  1734. (last-peak-amps (make-float-vector max-oscils))
  1735. (peak-amps (make-float-vector max-peaks-1))
  1736. (peak-freqs (make-float-vector max-peaks-1))
  1737. (amps (make-float-vector max-oscils)) ;run-time generated amplitude and frequency envelopes
  1738. (rates (make-float-vector max-oscils))
  1739. (freqs (make-float-vector max-oscils))
  1740. (sweeps (make-float-vector max-oscils))
  1741. ;; (lowest-magnitude .001)
  1742. (ihifreq (hz->radians ifreq))
  1743. (fftscale (/ 1.0 fftsize-1 .42323)) ;integrate Blackman-Harris window = .42323*window width and shift by fftsize-1
  1744. (fft-mag (/ *clm-srate* fftsize-1))
  1745. (furthest-away-accepted .1)
  1746. (filptr 0)
  1747. (filend 0)
  1748. (cur-oscils max-oscils)
  1749. (splice-attack (number? attack))
  1750. (ramped-attack (make-float-vector attack-size)))
  1751. (let ((obank (make-oscil-bank freqs (make-float-vector max-oscils) amps)))
  1752. (set! filend (mus-length fil))
  1753. (float-vector-scale! window fftscale)
  1754. (when splice-attack
  1755. (let ((cur-end (+ start attack-size)))
  1756. ;; my experience in translating SMS, and rumor via Greg Sandell leads me to believe that
  1757. ;; there is in fact no way to model some attacks successfully in this manner, so this block
  1758. ;; simply splices the original attack on to the rest of the note. "attack" is the number
  1759. ;; of samples to include bodily.
  1760. (do ((i start (+ i 1)))
  1761. ((= i cur-end))
  1762. (outa i (* amp (readin fil))))
  1763. (set! filptr attack_size)
  1764. (let ((mult (make-env '(0 1.0 1.0 0.0) :length attack-size)))
  1765. (do ((k 0 (+ k 1)))
  1766. ((= k attack-size))
  1767. (float-vector-set! ramped-attack k (* (env mult) (readin fil)))))
  1768. (set! start cur-end)))
  1769. (when (< start end)
  1770. (do ((i start (+ i outhop)))
  1771. ((>= i end))
  1772. (when (<= filptr filend)
  1773. ;; get next block of data and apply window to it
  1774. (set! (mus-location fil) filptr)
  1775. (do ((k 0 (+ k 1)))
  1776. ((= k fftsize-1))
  1777. (float-vector-set! fdr k (readin fil)))
  1778. (float-vector-multiply! fdr window)
  1779. (set! filptr (+ filptr hop))
  1780. (fill! fdi 0.0)
  1781. ;; get the fft
  1782. (mus-fft fdr fdi fftsize-1 1)
  1783. ;; change to polar coordinates (ignoring phases)
  1784. (rectangular->magnitudes fdr fdi)
  1785. (float-vector-scale! fdr 2.0)
  1786. (float-vector-subseq current-peak-freqs 0 max-oscils last-peak-freqs)
  1787. (float-vector-subseq current-peak-amps 0 max-oscils last-peak-amps)
  1788. (fill! current-peak-amps 0.0)
  1789. (fill! peak-amps 0.0)
  1790. (let ((peaks 0))
  1791. (let ((ra (fdr 0))
  1792. (la 0.0)
  1793. (ca 0.0))
  1794. ;; search for current peaks following Xavier Serra's recommendations in
  1795. ;; "A System for Sound Analysis/Transformation/Synthesis
  1796. ;; Based on a Deterministic Plus Stochastic Decomposition"
  1797. (do ((k 0 (+ k 1)))
  1798. ((= k highest-bin-1))
  1799. (set! la ca)
  1800. (set! ca ra)
  1801. (set! ra (fdr k))
  1802. (when (and (> ca .001) ; lowest-magnitude
  1803. (> ca ra)
  1804. (> ca la)
  1805. (not (zero? ra))
  1806. (not (zero? la)))
  1807. ;; found a local maximum above the current threshold (its bin number is k-1)
  1808. (let ((logla (log la 10.0))
  1809. (logca (log ca 10.0))
  1810. (logra (log ra 10.0)))
  1811. (let ((offset (/ (* .5 (- logla logra)) (+ logla (* -2 logca) logra)))) ; isn't logca always 0?
  1812. (let ((amp (expt 10.0 (- logca (* .25 (- logla logra) offset))))
  1813. (freq (* fft-mag (+ k offset -1))))
  1814. ;; (if (not (real? amp)) (format *stderr* "~A ~A ~A -> ~A ~A~%" la ca ra offset amp))
  1815. (if (= peaks max-peaks-1)
  1816. ;; gotta either flush this peak, or find current lowest and flush him
  1817. (let ((minp 0)
  1818. (minpeak (peak-amps 0)))
  1819. (do ((j 1 (+ j 1)))
  1820. ((= j max-peaks-1))
  1821. (if (< (peak-amps j) minpeak)
  1822. (begin
  1823. (set! minp j)
  1824. (set! minpeak (peak-amps j)))))
  1825. (if (> amp minpeak)
  1826. (begin
  1827. (set! (peak-freqs minp) freq)
  1828. (set! (peak-amps minp) amp))))
  1829. (begin
  1830. (set! (peak-freqs peaks) freq)
  1831. (set! (peak-amps peaks) amp)
  1832. (set! peaks (+ peaks 1))))))))))
  1833. ;; now we have the current peaks -- match them to the previous set and do something interesting with the result
  1834. ;; the end results are reflected in the updated values in the rates and sweeps arrays.
  1835. ;; search for fits between last and current, set rates/sweeps for those found
  1836. ;; try to go by largest amp first
  1837. (do ((k 0 (+ k 1)))
  1838. ((= k peaks))
  1839. (let ((pl (float-vector-peak-and-location peak-amps)))
  1840. (let ((maxpk (car pl))
  1841. (maxp (cadr pl)))
  1842. ;; now maxp points to next largest unmatched peak
  1843. (if (> maxpk 0.0)
  1844. (let ((closestp -1)
  1845. (closestamp 10.0)
  1846. (current-freq (peak-freqs maxp)))
  1847. (let ((icf (/ 1.0 current-freq)))
  1848. (do ((j 0 (+ j 1)))
  1849. ((= j max-peaks-1))
  1850. (if (> (last-peak-amps j) 0.0)
  1851. (let ((closeness (* icf (abs (- (last-peak-freqs j) current-freq)))))
  1852. (if (< closeness closestamp)
  1853. (begin
  1854. (set! closestamp closeness)
  1855. (set! closestp j))))))
  1856. (if (< closestamp furthest-away-accepted)
  1857. (begin
  1858. ;; peak-amp is transferred to appropriate current-amp and zeroed,
  1859. (set! (current-peak-amps closestp) (peak-amps maxp))
  1860. (set! (peak-amps maxp) 0.0)
  1861. (set! (current-peak-freqs closestp) current-freq))))))))))
  1862. (do ((k 0 (+ k 1)))
  1863. ((= k max-peaks-1))
  1864. (if (> (peak-amps k) 0.0)
  1865. ;; find a place for a new oscil and start it up
  1866. (let ((new-place -1))
  1867. (do ((j 0 (+ j 1)))
  1868. ((or (not (= new-place -1))
  1869. (= j max-oscils)))
  1870. (if (= (last-peak-amps j) 0.0 (current-peak-amps j))
  1871. (set! new-place j)))
  1872. (set! (current-peak-amps new-place) (peak-amps k))
  1873. (set! (peak-amps k) 0.0)
  1874. (set! (current-peak-freqs new-place) (peak-freqs k))
  1875. (set! (last-peak-freqs new-place) (peak-freqs k))
  1876. (set! (freqs new-place) (hz->radians (* transposition (peak-freqs k)))))))
  1877. (set! cur-oscils 0)
  1878. (do ((k 0 (+ k 1)))
  1879. ((= k max-oscils))
  1880. (set! (rates k) (* amp ifreq (- (current-peak-amps k) (last-peak-amps k))))
  1881. (if (not (and (= (current-peak-amps k) 0.0)
  1882. (= (last-peak-amps k) 0.0)))
  1883. (set! cur-oscils k))
  1884. (set! (sweeps k) (* ihifreq transposition (- (current-peak-freqs k) (last-peak-freqs k)))))
  1885. (set! cur-oscils (+ cur-oscils 1))
  1886. (set! (mus-length obank) cur-oscils)
  1887. (let ((stop (min end (+ i outhop))))
  1888. (do ((k i (+ k 1)))
  1889. ((= k stop))
  1890. ;; run oscils, update envelopes
  1891. (outa k (oscil-bank obank))
  1892. (float-vector-add! amps rates)
  1893. (float-vector-add! freqs sweeps))))))))))))
  1894. ;; (with-sound (:statistics #t) (pins 0 2 "oboe.snd" 1.0 :max-peaks 8))
  1895. (definstrument (zc time dur freq amp length1 length2 feedback)
  1896. (let ((beg (seconds->samples time))
  1897. (end (seconds->samples (+ time dur)))
  1898. (s (make-pulse-train freq amp))
  1899. (d0 (make-comb :size length1 :max-size (+ 1 (max length1 length2)) :scaler feedback))
  1900. (zenv (make-env '(0 0 1 1) :scaler (- length2 length1) :duration dur)))
  1901. (do ((i beg (+ i 1)))
  1902. ((= i end))
  1903. (outa i (comb d0 (pulse-train s) (env zenv))))))
  1904. ;; (with-sound () (zc 0 3 100 .1 20 100 .95) (zc 3.5 3 100 .1 100 20 .95))
  1905. (definstrument (zn time dur freq amp length1 length2 feedforward)
  1906. ;; notches are spaced at srate/len, feedforward sets depth thereof
  1907. ;; so sweep of len from 20 to 100 sweeps the notches down from 1000 Hz to ca 200 Hz
  1908. ;; so we hear our downward glissando beneath the pulses.
  1909. (let ((beg (seconds->samples time))
  1910. (end (seconds->samples (+ time dur)))
  1911. (s (make-pulse-train freq amp))
  1912. (d0 (make-notch :size length1 :max-size (+ 1 (max length1 length2)) :scaler feedforward))
  1913. (zenv (make-env '(0 0 1 1) :scaler (- length2 length1) :duration dur)))
  1914. (do ((i beg (+ i 1)))
  1915. ((= i end))
  1916. (outa i (notch d0 (pulse-train s) (env zenv))))))
  1917. ;;(with-sound () (zn 0 1 100 .1 20 100 .995) (zn 1.5 1 100 .1 100 20 .995))
  1918. (definstrument (za time dur freq amp length1 length2 feedback feedforward)
  1919. (let ((beg (seconds->samples time))
  1920. (end (seconds->samples (+ time dur)))
  1921. (s (make-pulse-train freq amp))
  1922. (d0 (make-all-pass feedback feedforward :size length1 :max-size (+ 1 (max length1 length2))))
  1923. (zenv (make-env '(0 0 1 1) :scaler (- length2 length1) :duration dur)))
  1924. (do ((i beg (+ i 1)))
  1925. ((= i end))
  1926. (outa i (all-pass d0 (pulse-train s) (env zenv))))))
  1927. ;;(with-sound () (za 0 1 100 .1 20 100 .95 .95) (za 1.5 1 100 .1 100 20 .95 .95))
  1928. (define* (clm-expsrc beg dur input-file exp-ratio src-ratio amp rev start-in-file)
  1929. (let ((stf (floor (* (or start-in-file 0) (srate input-file))))
  1930. (two-chans (= (channels input-file) 2 (channels *output*)))
  1931. (revit (and *reverb* rev)))
  1932. (let ((st (seconds->samples beg))
  1933. (exA (make-granulate (make-readin input-file :channel 0 :start stf) :expansion exp-ratio))
  1934. (exB (and two-chans (make-granulate (make-readin input-file :channel 1 :start stf) :expansion exp-ratio))))
  1935. (let ((srcA (make-src :srate src-ratio
  1936. :input (lambda (dir) (granulate exA))))
  1937. (srcB (and two-chans (make-src :srate src-ratio
  1938. :input (lambda (dir) (granulate exB)))))
  1939. (rev-amp (if revit (if two-chans (* rev .5) rev) 0.0))
  1940. (nd (seconds->samples (+ beg dur))))
  1941. (if revit
  1942. (let ((valA 0.0)
  1943. (valB 0.0))
  1944. (if two-chans
  1945. (do ((i st (+ i 1)))
  1946. ((= i nd))
  1947. (set! valA (* amp (src srcA)))
  1948. (set! valB (* amp (src srcB)))
  1949. (outa i valA)
  1950. (outb i valB)
  1951. (outa i (* rev-amp (+ valA valB)) *reverb*))
  1952. (do ((i st (+ i 1)))
  1953. ((= i nd))
  1954. (set! valA (* amp (src srcA)))
  1955. (outa i valA)
  1956. (outa i (* rev-amp valA) *reverb*))))
  1957. (if two-chans
  1958. (do ((i st (+ i 1)))
  1959. ((= i nd))
  1960. (outa i (* amp (src srcA)))
  1961. (outb i (* amp (src srcB))))
  1962. (do ((i st (+ i 1)))
  1963. ((= i nd))
  1964. (outa i (* amp (src srcA))))))))))
  1965. ;;; (with-sound () (clm-expsrc 0 2.5 "oboe.snd" 2.0 1.0 1.0))
  1966. (definstrument (exp-snd file beg dur amp (exp-amt 1.0) (ramp .4) (seglen .15) (sr 1.0) (hop .05) ampenv)
  1967. ;; granulate with envelopes on the expansion amount, segment envelope shape,
  1968. ;; segment length, hop length, and input file resampling rate
  1969. (let ((max-seg-len (if seglen (if (pair? seglen) (max-envelope seglen) seglen) .15))
  1970. (initial-seg-len (if seglen (if (pair? seglen) (cadr seglen) seglen) .15))
  1971. (rampdata (if (pair? ramp) ramp (list 0 ramp 1 ramp)))
  1972. (max-out-hop (if hop (if (pair? hop) (max-envelope hop) hop) .05))
  1973. (initial-out-hop (if hop (if (pair? hop) (cadr hop) hop) .05))
  1974. (min-exp-amt (if exp-amt (if (pair? exp-amt) (min-envelope exp-amt) exp-amt) 1.0))
  1975. (initial-exp-amt (if exp-amt (if (pair? exp-amt) (cadr exp-amt) exp-amt) 1.0)))
  1976. (if (or (<= (min-envelope rampdata) 0.0)
  1977. (>= (max-envelope rampdata) 0.5))
  1978. (format #t "ramp argument to exp-snd must always be between 0.0 and 0.5: ~A" ramp)
  1979. (let ((st (seconds->samples beg))
  1980. (nd (seconds->samples (+ beg dur)))
  1981. (f0 (make-readin file 0))
  1982. (expenv (make-env (if (pair? exp-amt)
  1983. exp-amt
  1984. (list 0 exp-amt 1 exp-amt))
  1985. :duration dur))
  1986. (lenenv (make-env (if (pair? seglen)
  1987. seglen
  1988. (list 0 seglen 1 seglen))
  1989. :scaler *clm-srate* :duration dur))
  1990. (scaler-amp (if (> max-seg-len .15) (/ (* 0.6 .15) max-seg-len) 0.6))
  1991. (srenv (make-env (if (pair? sr)
  1992. sr
  1993. (list 0 sr 1 sr))
  1994. :duration dur))
  1995. (rampenv (make-env rampdata :duration dur))
  1996. (initial-ramp-time (if ramp (if (pair? ramp) (cadr ramp) ramp) .4))
  1997. (max-in-hop (/ max-out-hop min-exp-amt)))
  1998. (let ((max-len (seconds->samples (+ (max max-out-hop max-in-hop) max-seg-len)))
  1999. (hopenv (make-env (if (pair? hop)
  2000. hop
  2001. (list 0 hop 1 hop))
  2002. :duration dur))
  2003. (ampe (make-env (or ampenv '(0 0 .5 1 1 0)) :scaler amp :duration dur)))
  2004. (let ((exA (make-granulate :expansion initial-exp-amt
  2005. :input f0
  2006. :max-size max-len
  2007. :ramp initial-ramp-time
  2008. :hop initial-out-hop
  2009. :length initial-seg-len
  2010. :scaler scaler-amp))
  2011. (vol (env ampe)))
  2012. (do ((valA0 (* vol (granulate exA)))
  2013. (valA1 (* vol (granulate exA)))
  2014. (ex-samp 0.0)
  2015. (next-samp 0.0)
  2016. (i st (+ i 1)))
  2017. ((= i nd))
  2018. (let ((sl (env lenenv))) ;current segment length
  2019. ;; now we set the granulate generator internal state to reflect all these envelopes
  2020. (set! vol (env ampe))
  2021. (set! (mus-length exA) (round sl))
  2022. (set! (mus-ramp exA) (floor (* sl (env rampenv))))) ;current ramp length (0 to .5)
  2023. (set! (mus-frequency exA) (env hopenv)) ;current hop size
  2024. (set! (mus-increment exA) (env expenv)) ;current expansion amount
  2025. (set! next-samp (+ next-samp (env srenv))) ;current resampling increment
  2026. (if (> next-samp (+ 1 ex-samp))
  2027. (let ((samps (floor (- next-samp ex-samp))))
  2028. (if (> samps 2)
  2029. (do ((k 0 (+ k 1)))
  2030. ((= k (- samps 2)))
  2031. (granulate exA)))
  2032. (set! valA0 (if (>= samps 2)
  2033. (* vol (granulate exA))
  2034. (set! valA0 valA1)))
  2035. (set! valA1 (* vol (granulate exA)))
  2036. (set! ex-samp (+ ex-samp samps))))
  2037. (outa i (if (= next-samp ex-samp)
  2038. valA0
  2039. (+ valA0 (* (- next-samp ex-samp) (- valA1 valA0))))))))))))
  2040. ;;; (with-sound (:statistics #t) (exp-snd "fyow.snd" 0 3 1 '(0 1 1 3) 0.4 .15 '(0 2 1 .5) 0.05))
  2041. ;;; (with-sound () (exp-snd "oboe.snd" 0 3 1 '(0 1 1 3) 0.4 .15 '(0 2 1 .5) 0.2))
  2042. (defgenerator grn
  2043. (rampval 0.0)
  2044. (rampinc 0.0)
  2045. (loc 0)
  2046. (segctr 0)
  2047. (whichseg 0)
  2048. (ramplen 0)
  2049. (steadylen 0)
  2050. (trigger 0)
  2051. file)
  2052. (definstrument (expfil start duration hopsecs rampsecs steadysecs file1 file2)
  2053. (let ((fil1 (make-file->sample file1))
  2054. (fil2 (make-file->sample file2))
  2055. (hop (seconds->samples hopsecs))
  2056. (rampdur (seconds->samples rampsecs))
  2057. (steadydur (seconds->samples steadysecs))
  2058. (beg (seconds->samples start))
  2059. (end (seconds->samples (+ start duration))))
  2060. (let ((grn1 (make-grn :rampval 0.0 :rampinc (/ 1.0 rampdur) :loc 0 :segctr 0 :whichseg 0 :ramplen rampdur :steadylen steadydur :trigger 0 :file fil1))
  2061. (grn2 (make-grn :rampval 0.0 :rampinc (/ 1.0 rampdur) :loc 0 :segctr 0 :whichseg 0 :ramplen rampdur :steadylen steadydur :trigger 0 :file fil2))
  2062. (out1 beg)
  2063. (out2 (+ hop beg)))
  2064. (do ((i beg (+ i 1))
  2065. (val 0.0 0.0))
  2066. ((= i end))
  2067. (when (= i out1)
  2068. (set! val (with-let grn1
  2069. (let ((inval (ina loc file)))
  2070. (set! loc (+ loc 1))
  2071. (if (= whichseg 0) ;ramp-up
  2072. (begin
  2073. (set! inval (* inval rampval))
  2074. (set! rampval (+ rampval rampinc))
  2075. (set! segctr (+ segctr 1))
  2076. (if (= segctr ramplen)
  2077. (begin
  2078. (set! segctr 0)
  2079. (set! whichseg (+ whichseg 1)))))
  2080. (if (= whichseg 1) ;steady-state
  2081. (begin
  2082. (set! segctr (+ segctr 1))
  2083. (if (= segctr steadylen)
  2084. (begin
  2085. (set! segctr 0)
  2086. (set! whichseg (+ whichseg 1)))))
  2087. (begin ;ramp-down
  2088. (set! inval (* inval rampval))
  2089. (set! segctr (+ segctr 1))
  2090. (set! rampval (- rampval rampinc))
  2091. (if (= segctr ramplen)
  2092. (begin
  2093. (set! segctr 0)
  2094. (set! trigger 1)
  2095. (set! whichseg 0)
  2096. (set! rampval 0.0))))))
  2097. inval)))
  2098. (set! out1 (+ out1 1))
  2099. (if (= (grn1 'trigger) 1)
  2100. (begin
  2101. (set! (grn1 'trigger) 0)
  2102. (set! out1 (+ out1 hop)))))
  2103. (when (= i out2)
  2104. (set! val (+ val (with-let grn2
  2105. (let ((inval (ina loc file)))
  2106. (set! loc (+ loc 1))
  2107. (if (= whichseg 0) ;ramp-up
  2108. (begin
  2109. (set! inval (* inval rampval))
  2110. (set! rampval (+ rampval rampinc))
  2111. (set! segctr (+ segctr 1))
  2112. (if (= segctr ramplen)
  2113. (begin
  2114. (set! segctr 0)
  2115. (set! whichseg (+ whichseg 1)))))
  2116. (if (= whichseg 1) ;steady-state
  2117. (begin
  2118. (set! segctr (+ segctr 1))
  2119. (if (= segctr steadylen)
  2120. (begin
  2121. (set! segctr 0)
  2122. (set! whichseg (+ whichseg 1)))))
  2123. (begin ;ramp-down
  2124. (set! inval (* inval rampval))
  2125. (set! segctr (+ segctr 1))
  2126. (set! rampval (- rampval rampinc))
  2127. (if (= segctr ramplen)
  2128. (begin
  2129. (set! segctr 0)
  2130. (set! trigger 1)
  2131. (set! whichseg 0)
  2132. (set! rampval 0.0))))))
  2133. inval))))
  2134. (set! out2 (+ out2 1))
  2135. (if (= (grn2 'trigger) 1)
  2136. (begin
  2137. (set! (grn2 'trigger) 0)
  2138. (set! out2 (+ out2 hop)))))
  2139. (outa i val)))))
  2140. ;;; (with-sound () (expfil 0 2 .2 .01 .1 "oboe.snd" "fyow.snd"))
  2141. #|
  2142. From: Marco Trevisani <marco@ccrma.Stanford.EDU>
  2143. This should work like a Graphic Equalizer....
  2144. Very easy to use. Just some note:
  2145. "amp" & "amp-env" apply an enveloppe to the final result of the
  2146. filtering.
  2147. "dur" as ""standard"" in my instruments, when dur = 0 it will take the length of the
  2148. sndfile input, otherwise the duration in seconds.
  2149. "gain-freq-list" is a list of gains and frequencies to
  2150. filter --in this order gain and frequencies--. There is no limit to
  2151. the size of the list. Gain can be a number or an
  2152. envelope. Unfortunatelly in this version they can't alternate, one
  2153. should chose, all envelopes or all numbers i.e.:
  2154. case 1 -> '( .1 440.0 .3 1500.0 .2 330.0 ...etc) or
  2155. case 2 -> '((0 .1 1 .5) 440.0 (0 1 1 .01) 1500 (0 .3 1 .5) 330.0 ...etc)
  2156. '( .1 440.0 (0 1 1 .01) 1500 ..etc) <<< again, this is not allowed ..
  2157. "offset-gain" This apply to all the gains if case 1. It adds or
  2158. subtracts an offset to all the gains in the list. This number can be positive or
  2159. negative. In case the result is a negative number --let's say offset =
  2160. -.4 and, like in case 1, the first gain is .1, the result would be
  2161. -.3 -- the instrument will pass a gain equal to 0.
  2162. "filt-gain-scale" & "filt-gain-base" will apply to the elements of the
  2163. envelopes if we are in case 2, gains are envelopes.
  2164. "stats" if #t --default-- prints the number of seconds processed, if
  2165. nil doesnt print anything, which will speed up a bit the process.
  2166. |#
  2167. (definstrument (graphEq file (beg 0) (dur 0) (or-beg 0) (amp 1) (amp-env '(0 1 .8 1 1 0)) (amp-base 1)
  2168. (offset-gain 0)
  2169. (gain-freq-list '(.8 440 .2 660))
  2170. (filt-gain-scale 1)
  2171. (filt-gain-base 1)
  2172. (a1 .99))
  2173. (let ((st (seconds->samples beg))
  2174. (durata (if (= 0 dur) (mus-sound-duration file) dur))
  2175. (or-start (round (* or-beg (srate file))))
  2176. (gain-list (let ((lst ())
  2177. (len (length gain-freq-list)))
  2178. (do ((i (- len 2) (- i 2)))
  2179. ((< i 0))
  2180. (set! lst (cons (gain-freq-list i) lst)))
  2181. lst))
  2182. (freq-list (let ((lst ())
  2183. (len (length gain-freq-list)))
  2184. (do ((i (- len 1) (- i 2)))
  2185. ((<= i 0))
  2186. (set! lst (cons (gain-freq-list i) lst)))
  2187. lst)))
  2188. (let ((nd (+ st (seconds->samples durata)))
  2189. (RdA (make-readin :file file :start or-start))
  2190. (half-list (/ (length gain-freq-list) 2))
  2191. (ampenv (make-env amp-env :scaler amp :duration durata :base amp-base))
  2192. (env-size (and (pair? (car gain-list))
  2193. (make-vector (length freq-list))))
  2194. (if-list-in-gain (pair? (car gain-list)))
  2195. (frm-size (make-vector (length freq-list)))
  2196. (gains (make-float-vector (length freq-list) 1.0))
  2197. (filt-scl (* filt-gain-scale (- 1.0 a1))))
  2198. (do ((k 0 (+ k 1)))
  2199. ((= k half-list))
  2200. (let ((gval (gain-list k))
  2201. (fval (freq-list k)))
  2202. (if (pair? gval)
  2203. (begin
  2204. (set! (env-size k) (make-env gval
  2205. :scaler filt-scl
  2206. :duration durata :base filt-gain-base))
  2207. (set! (frm-size k) (make-formant fval a1)))
  2208. (begin
  2209. (set! (frm-size k) (make-formant fval a1))
  2210. (set! (gains k) (max 0 (+ offset-gain gval)))))))
  2211. (set! frm-size (make-formant-bank frm-size gains))
  2212. (if if-list-in-gain
  2213. (do ((i st (+ i 1)))
  2214. ((= i nd))
  2215. (do ((k 0 (+ k 1)))
  2216. ((= k half-list))
  2217. (float-vector-set! gains k (env (vector-ref env-size k))))
  2218. (outa i (* (env ampenv) (formant-bank frm-size (readin RdA)))))
  2219. (do ((i st (+ i 1)))
  2220. ((= i nd))
  2221. (outa i (* (env ampenv) (formant-bank frm-size (readin RdA)))))))))
  2222. (definstrument (anoi infile start dur (fftsize 128) (amp-scaler 1.0) rr)
  2223. ;; a kind of noise reduction -- on-going average spectrum is squelched to some extent
  2224. ;; obviously aimed at intermittent signal in background noise
  2225. ;; this is based on Perry Cook's Scrubber.m
  2226. (let ((r (or rr (* 2.0 pi)))
  2227. (freq-inc (floor (/ fftsize 2)))
  2228. (fdi (make-float-vector fftsize))
  2229. (fdr (make-float-vector fftsize)))
  2230. (let ((spectr (make-vector freq-inc 1.0))
  2231. (scales (make-float-vector freq-inc 1.0))
  2232. (diffs (make-float-vector freq-inc))
  2233. (win (make-fft-window blackman2-window fftsize))
  2234. (incr (/ (* amp-scaler 4) *clm-srate*))
  2235. (beg (seconds->samples start))
  2236. (end (seconds->samples (+ start dur)))
  2237. (file (make-file->sample infile))
  2238. (fs (make-vector freq-inc)))
  2239. (let ((bin (/ *clm-srate* fftsize))
  2240. (radius (- 1.0 (/ r fftsize))))
  2241. (do ((ctr 0 (+ ctr 1)))
  2242. ((= ctr freq-inc))
  2243. (set! (fs ctr) (make-formant (* ctr bin) radius))))
  2244. (set! fs (make-formant-bank fs scales))
  2245. (set! (scales 0) 0.0)
  2246. (do ((k 0)
  2247. (amp 0.0)
  2248. (samp 0)
  2249. (fdrc 0.0)
  2250. (i beg (+ i 1)))
  2251. ((= i end))
  2252. (let ((inval (file->sample file samp)))
  2253. (set! samp (+ samp 1))
  2254. (set! (fdr k) inval)
  2255. (set! k (+ k 1))
  2256. (if (< amp amp-scaler) (set! amp (+ amp incr)))
  2257. (if (>= k fftsize)
  2258. (begin
  2259. (set! k 0)
  2260. (spectrum fdr fdi win 1)
  2261. (do ((ctr 0 (+ ctr 1)))
  2262. ((= ctr freq-inc))
  2263. (set! fdrc (fdr ctr))
  2264. (set! (spectr ctr) (+ (* .9 (spectr ctr)) (* .1 fdrc)))
  2265. (set! (diffs ctr) (if (>= (spectr ctr) fdrc)
  2266. (/ (scales ctr) (- fftsize))
  2267. (/ (- (/ (- fdrc (spectr ctr)) fdrc)
  2268. (scales ctr))
  2269. fftsize))))))
  2270. (outa i (* amp (formant-bank fs inval)))
  2271. (float-vector-add! scales diffs))))))
  2272. #|
  2273. Date: Fri, 25 Sep 1998 09:56:41 +0300
  2274. From: Matti Koskinen <mjkoskin@sci.fi>
  2275. To: linux-audio-dev@ginette.musique.umontreal.ca
  2276. Subject: [linux-audio-dev] Announce: alpha version of denoising
  2277. [...]
  2278. I wrote a simple denoiser called anoi after it's parent
  2279. clm-instrument anoi.ins.
  2280. anoi tries to remove white noise like tape hiss from wav-
  2281. files. Removing of noise succeeds ok, but depending of the
  2282. original sound, some distortion can be audible.
  2283. If someone is interested, http://www.sci.fi/~mjkoskin
  2284. contains tarred and gzipped file.
  2285. Now only monophonic wav-files can be denoised, but adding
  2286. others isn't too difficult.
  2287. -matti
  2288. mjkoskin@sci.fi
  2289. |#
  2290. ;;; bes-fm -- can also use bes-j0 here as in earlier versions
  2291. (define bes-fm
  2292. (let ((documentation "(bes-fm beg dur freq amp ratio index) produces J1(J1) imitating FM"))
  2293. (lambda (beg dur freq amp ratio index)
  2294. (let ((car-incr (hz->radians freq)))
  2295. (let ((st (seconds->samples beg))
  2296. (nd (seconds->samples (+ beg dur)))
  2297. (car-ph 0.0)
  2298. (mod-ph 0.0)
  2299. (mod-incr (* ratio car-incr))
  2300. (ampenv (make-env '(0 0 25 1 75 1 100 0) :scaler amp :duration dur)))
  2301. (do ((i st (+ i 1)))
  2302. ((= i nd))
  2303. (outa i (* (env ampenv) (bes-j1 car-ph)))
  2304. (set! car-ph (+ car-ph car-incr (* index (bes-j1 mod-ph))))
  2305. (set! mod-ph (+ mod-ph mod-incr))))))))
  2306. ;;; (with-sound (:statistics #t) (bes-fm 0 1 440 10.0 1.0 4.0))
  2307. ;;; ssb-fm
  2308. ;;; this might be better named "quasi-ssb-fm" -- cancellations are not perfect
  2309. (defgenerator sbfm
  2310. (am0 #f) (am1 #f)
  2311. (car0 #f) (car1 #f)
  2312. (mod0 #f) (mod1 #f)
  2313. modsig)
  2314. (define make-ssb-fm
  2315. (let ((documentation "(make-ssb-fm freq) makes an ssb-fm generator"))
  2316. (lambda (freq)
  2317. (make-sbfm :am0 (make-oscil freq 0)
  2318. :am1 (make-oscil freq (* 0.5 pi))
  2319. :car0 (make-oscil 0 0)
  2320. :car1 (make-oscil 0 (* 0.5 pi))
  2321. :mod0 (make-hilbert-transform 40)
  2322. :mod1 (make-delay 40)))))
  2323. (define ssb-fm
  2324. (let ((documentation "(ssb-fm gen modsig) runs an ssb-fm generator"))
  2325. (lambda (gen modsig)
  2326. (let-set! gen 'modsig modsig)
  2327. (with-let gen
  2328. (+ (* (oscil am0)
  2329. (oscil car0 (hilbert-transform mod0 modsig)))
  2330. (* (oscil am1)
  2331. (oscil car1 (delay mod1 modsig))))))))
  2332. ;;; if all we want are asymmetric fm-generated spectra, we can just add 2 fm oscil pairs:
  2333. (define make-fm2
  2334. (let ((documentation "(make-fm2 f1 f2 f3 f4 p1 p2 p3 p4) makes two FM paired oscils"))
  2335. (lambda (f1 f2 f3 f4 p1 p2 p3 p4)
  2336. ;; (make-fm2 1000 100 1000 100 0 0 (* 0.5 pi) (* 0.5 pi))
  2337. ;; (make-fm2 1000 100 1000 100 0 0 0 (* 0.5 pi))
  2338. (list (make-oscil f1 p1)
  2339. (make-oscil f2 p2)
  2340. (make-oscil f3 p3)
  2341. (make-oscil f4 p4)))))
  2342. (define fm2
  2343. (let ((documentation "(fm2 gen index) runs an fm2 generator"))
  2344. (lambda (gen index)
  2345. (* .25 (+ (oscil (gen 0) (* index (oscil (gen 1))))
  2346. (oscil (gen 2) (* index (oscil (gen 3)))))))))
  2347. ;;; rms gain balance
  2348. ;;; This is a translation of the rmsgain code provided by Fabio Furlanete.
  2349. (defgenerator rmsg
  2350. (c1 0.0)
  2351. (c2 0.0)
  2352. (q 0.0)
  2353. (r 0.0)
  2354. (avg 0.0)
  2355. (avgc 0)
  2356. sig rmsval)
  2357. (define make-rmsgain
  2358. (let ((documentation "(make-rmsgain (hp 10.0)) makes an RMS gain generator"))
  2359. (lambda* ((hp 10.0))
  2360. (let ((c2 (let ((b (- 2.0 (cos (* hp (/ (* 2.0 pi) *clm-srate*))))))
  2361. (- b (sqrt (- (* b b) 1.0))))))
  2362. (make-rmsg :c1 (- 1.0 c2) :c2 c2)))))
  2363. (define rms
  2364. (let ((documentation "(rms gen sig) runs an RMS gain generator"))
  2365. (lambda (gen sig)
  2366. (let-set! gen 'sig sig)
  2367. (with-let gen
  2368. (set! q (+ (* c1 sig sig) (* c2 q)))
  2369. (sqrt q)))))
  2370. (define gain
  2371. (let ((documentation "(gain gen sig rmsval) returns the current RMS gain"))
  2372. (lambda (gen sig rmsval)
  2373. (let-set! gen 'sig sig)
  2374. (let-set! gen 'rmsval rmsval)
  2375. (with-let gen
  2376. (set! r (+ (* c1 sig sig) (* c2 r)))
  2377. (let ((this-gain (if (zero? r)
  2378. rmsval
  2379. (/ rmsval (sqrt r)))))
  2380. (set! avg (+ avg this-gain))
  2381. (set! avgc (+ avgc 1))
  2382. (* sig this-gain))))))
  2383. (define balance
  2384. (let ((documentation "(balance gen signal compare) scales a signal based on a RMS gain"))
  2385. (lambda (gen signal compare)
  2386. (gain gen signal (rms gen compare)))))
  2387. (define gain-avg
  2388. (let ((documentation "(gain-avg gen) is part of the RMS gain stuff"))
  2389. (lambda (gen)
  2390. (/ (gen 'avg) (gen 'avgc)))))
  2391. (define balance-avg
  2392. (let ((documentation "(balance-avg gen) is part of the RM gain stuff"))
  2393. (lambda (gen)
  2394. (gen 'avg))))
  2395. (definstrument (cnvrev file impulse (rev-amt .1))
  2396. (let ((filter-len (mus-sound-framples impulse)))
  2397. (let ((file-len (mus-sound-framples file))
  2398. (filter-chan0 (make-float-vector filter-len))
  2399. (filter-chan1 (and (= (mus-channels *output*) 2)
  2400. (> (mus-sound-chans impulse) 1)
  2401. (make-float-vector filter-len))))
  2402. (file->array impulse 0 0 filter-len filter-chan0)
  2403. (if (float-vector? filter-chan1)
  2404. (file->array impulse 1 0 filter-len filter-chan1)
  2405. (set! filter-chan1 filter-chan0))
  2406. (let ((fd (make-readin file))
  2407. (fd1 (and (= (mus-channels *output*) 2)
  2408. (> (mus-sound-chans file) 1)
  2409. (make-readin file :channel 1))))
  2410. (let ((ff0 (make-convolve :input fd :filter filter-chan0))
  2411. (ff1 (and (= (mus-channels *output*) 2)
  2412. (> (mus-sound-chans file) 1)
  2413. (make-convolve :input fd1 :filter filter-chan1)))
  2414. (end (+ file-len filter-len)))
  2415. (if ff1
  2416. (do ((i 0 (+ i 1)))
  2417. ((= i end))
  2418. (outa i (* rev-amt (convolve ff0)))
  2419. (outb i (* rev-amt (convolve ff1))))
  2420. (do ((i 0 (+ i 1)))
  2421. ((= i end))
  2422. (outa i (* rev-amt (convolve ff0))))))))))
  2423. #|
  2424. (with-sound (:statistics #t :scaled-to .5 :srate 44100 :channels 1)
  2425. (cnvrev "oboe.snd" "fyow.snd"))
  2426. |#