您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783
  1. # clm-ins.rb -- CLM instruments translated to Snd/Ruby
  2. # Translator: Michael Scholz <mi-scholz@users.sourceforge.net>
  3. # Created: 03/09/16 01:27:09
  4. # Changed: 14/11/28 02:16:54
  5. # Instruments work with
  6. # with_sound (CLM (sample2file gens) and Snd)
  7. # with_dac (dac output, except at least for fullmix)
  8. #
  9. # Tested with Snd 15.x and Ruby 2.x.x
  10. # pluck reson
  11. # vox cellon
  12. # fofins jl_reverb
  13. # fm_trumpet gran_synth
  14. # pqw_vox touch_tone
  15. # stereo_flute spectra
  16. # fm_bell two_tab
  17. # fm_insect lbj_piano
  18. # fm_drum resflt
  19. # gong scratch
  20. # attract pins
  21. # pqw zc
  22. # tubebell zn
  23. # wurley za
  24. # rhodey clm_expsrc exp_snd
  25. # hammondoid expfil
  26. # metal graph_eq
  27. # drone anoi
  28. # canter fullmix
  29. # nrev grani
  30. #
  31. # class Ssb_fm < Musgen
  32. # initialize(freq)
  33. # inspect
  34. # to_s
  35. # run_func(val1, val2)
  36. # ssb_fm(modsig)
  37. # bes_fm(start, dur, freq, amp, ratio, index)
  38. #
  39. # make_ssb_fm(freq)
  40. # ssb_fm?(obj)
  41. # ssb_fm(gen, modsig)
  42. #
  43. # class Fm2 < Musgen
  44. # initialize(f1, f2, f3, f4, p1, p2, p3, p4)
  45. # inspect
  46. # to_s
  47. # run_func(val1, val2)
  48. # fm2(index)
  49. #
  50. # make_fm2(f1, f2, f3, f4, p1, p2, p3, p4)
  51. # fm2?(obj)
  52. # fm2(gen, index)
  53. # comments from clm-ins.scm
  54. $now = 0.0
  55. require "ws"
  56. require "spectr"
  57. require "env"
  58. include Math
  59. with_silence do
  60. require "matrix"
  61. end
  62. def normalize_partials(partials)
  63. sum = 0.0
  64. parts = partials.dup
  65. len = parts.length
  66. 1.step(len - 1, 2) do |i|
  67. sum += parts[i].abs
  68. end
  69. 1.step(len - 1, 2) do |i|
  70. parts[i] /= sum
  71. end
  72. parts
  73. end unless defined? normalize_partials
  74. # violin is defined as an example in ws.rb
  75. def violin_test(start = 0.0, dur = 1.0)
  76. violin(start, dur, 440, 0.5)
  77. $now = start + dur + 0.2
  78. end
  79. require "v"
  80. # fm_violin is defined in v.rb
  81. def fm_violin_test(start = 0.0, dur = 1.0)
  82. fm_violin(start, dur, 440, 0.5)
  83. $now = start + dur + 0.2
  84. end
  85. # PLUCK
  86. #
  87. # The Karplus-Strong algorithm as extended by David Jaffe and Julius
  88. # Smith -- see Jaffe and Smith, "Extensions of the Karplus-Strong
  89. # Plucked-String Algorithm" CMJ vol 7 no 2 Summer 1983, reprinted in
  90. # "The Music Machine". translated from CLM's pluck.ins
  91. add_help(:pluck,
  92. "pluck(start, dur, freq, amp, weighting, lossfact) \
  93. Implements the Jaffe-Smith plucked string physical model.
  94. WEIGHTING is the ratio of the once-delayed to the twice-delayed samples. \
  95. It defaults to 0.5=shortest decay.
  96. Anything other than 0.5 = longer decay. \
  97. Must be between 0 and less than 1.0.
  98. LOSSFACT can be used to shorten decays. \
  99. Most useful values are between 0.8 and 1.0. pluck(0, 1, 330, 0.3, 0.95, 0.95)")
  100. def pluck(start, dur, freq, amp, weighting = 0.5, lossfact = 0.9)
  101. get_optimum_c = lambda do |s, o, p|
  102. pa = (1.0 / o) * atan2(s * sin(o), (1.0 - s) + s * cos(o))
  103. tmp_int = (p - pa).floor
  104. pc = p - pa - tmp_int
  105. until pc >= 0.1
  106. tmp_int -= 1
  107. pc += 1.0
  108. end
  109. [tmp_int, (sin(o) - sin(o * pc)) / sin(o + o * pc)]
  110. end
  111. tune_it = lambda do |f, s1|
  112. p = @srate / f
  113. s = s1.zero? ? 0.5 : s1
  114. o = hz2radians(f)
  115. t1, c1 = get_optimum_c.call(s, o, p)
  116. t2, c2 = get_optimum_c.call(1.0 - s, o, p)
  117. if s != 0.5 and c1.abs < c2.abs
  118. [1.0 - s, c1, t1]
  119. else
  120. [s, c2, t2]
  121. end
  122. end
  123. wt0, c, dlen = tune_it.call(freq, weighting)
  124. lf = lossfact.zero? ? 1.0 : [1.0, lossfact].min
  125. wt = wt0.zero? ? 0.5 : [1.0, wt0].min
  126. tab = make_vct(dlen)
  127. # get initial waveform in "tab" -- here we can introduce 0's to
  128. # simulate different pick positions, and so on -- see the CMJ
  129. # article for numerous extensions. The normal case is to load it
  130. # with white noise (between -1 and 1).
  131. allp = make_one_zero(lf * (1.0 - wt), lf * wt)
  132. feedb = make_one_zero(c, 1.0) # or feedb = make_one_zero(1.0, c)
  133. dlen.times do |i|
  134. tab[i] = 1.0 - random(2.0)
  135. end
  136. run_instrument(start, dur) do
  137. val = tab.clm_cycle
  138. tab[tab.clm_cycle_index] = (1.0 - c) * one_zero(feedb, one_zero(allp, val))
  139. amp * val
  140. end
  141. end
  142. def pluck_test(start = 0.0, dur = 1.0)
  143. pluck(start, dur, 330, 0.3, 0.95, 0.95)
  144. $now = start + dur + 0.2
  145. end
  146. # formant center frequencies for a male speaker (vox and pqw_vox)
  147. Formants = {
  148. :I => [390, 1990, 2550], :E => [530, 1840, 2480], :AE => [660, 1720, 2410],
  149. :UH => [520, 1190, 2390], :A => [730, 1090, 2440], :OW => [570, 840, 2410],
  150. :U => [440, 1020, 2240], :OO => [300, 870, 2240], :ER => [490, 1350, 1690],
  151. :W => [300, 610, 2200], :LL => [380, 880, 2575], :R => [420, 1300, 1600],
  152. :Y => [300, 2200, 3065], :EE => [260, 3500, 3800], :LH => [280, 1450, 1600],
  153. :L => [300, 1300, 3000], :I2 => [350, 2300, 3340], :B => [200, 800, 1750],
  154. :D => [300, 1700, 2600], :G => [250, 1350, 2000], :M => [280, 900, 2200],
  155. :N => [280, 1700, 2600], :NG => [280, 2300, 2750], :P => [300, 800, 1750],
  156. :T => [200, 1700, 2600], :K => [350, 1350, 2000], :F => [175, 900, 4400],
  157. :TH => [200, 1400, 2200], :S => [200, 1300, 2500], :SH => [200, 1800, 2000],
  158. :V => [175, 1100, 2400], :THE => [200, 1600, 2200], :Z => [200, 1300, 2500],
  159. :ZH => [175, 1800, 2000], :ZZ => [900, 2400, 3800], :VV => [565, 1045, 2400]}
  160. # MLBVOI
  161. #
  162. # translation from MUS10 of Marc LeBrun's waveshaping voice instrument
  163. # (using FM here) this version translated (and simplified slightly)
  164. # from CLM's mlbvoi.ins
  165. def vox(start, dur, freq, amp, ampfun, freqfun, freqscl, voxfun, index, vibscl)
  166. f1 = []
  167. f2 = []
  168. f3 = []
  169. (voxfun.length - 1).step(1, -2) do |i|
  170. phon = Formants[voxfun[i]]
  171. x = voxfun[i - 1]
  172. f1.unshift(phon[0])
  173. f1.unshift(x)
  174. f2.unshift(phon[1])
  175. f2.unshift(x)
  176. f3.unshift(phon[2])
  177. f3.unshift(x)
  178. end
  179. car_os = make_oscil(:frequency, 0)
  180. of0 = make_oscil(:frequency, 0)
  181. of1 = make_oscil(:frequency, 0)
  182. of2 = make_oscil(:frequency, 0)
  183. of3 = make_oscil(:frequency, 0)
  184. of4 = make_oscil(:frequency, 0)
  185. of5 = make_oscil(:frequency, 0)
  186. ampf = make_env(:envelope, ampfun, :scaler, amp, :duration, dur)
  187. frmf1 = make_env(:envelope, f1, :duration, dur)
  188. frmf2 = make_env(:envelope, f2, :duration, dur)
  189. frmf3 = make_env(:envelope, f3, :duration, dur)
  190. freqf = make_env(:envelope, freqfun, :duration, dur, :scaler, freqscl * freq, :offset, freq)
  191. per_vib = make_triangle_wave(:frequency, 6, :amplitude, freq * vibscl)
  192. ran_vib = make_rand_interp(:frequency, 20, :amplitude, freq * 0.01)
  193. run_instrument(start, dur) do
  194. frq = env(freqf) + triangle_wave(per_vib) + rand_interp(ran_vib)
  195. car = index * oscil(car_os, hz2radians(frq))
  196. frm = env(frmf1)
  197. frm0 = frm / frq.to_f
  198. frm_int = frm0.floor
  199. if frm_int.even?
  200. frq0 = hz2radians(frm_int * frq)
  201. frq1 = hz2radians((frm_int + 1) * frq)
  202. amp1 = frm0 - frm_int
  203. amp0 = 1.0 - amp1
  204. else
  205. frq1 = hz2radians(frm_int * frq)
  206. frq0 = hz2radians((frm_int + 1) * frq)
  207. amp0 = frm0 - frm_int
  208. amp1 = 1.0 - amp0
  209. end
  210. frm = env(frmf2)
  211. frm0 = frm / frq.to_f
  212. frm_int = frm0.floor
  213. if frm_int.even?
  214. frq2 = hz2radians(frm_int * frq)
  215. frq3 = hz2radians((frm_int + 1) * frq)
  216. amp3 = frm0 - frm_int
  217. amp2 = 1.0 - amp3
  218. else
  219. frq3 = hz2radians(frm_int * frq)
  220. frq2 = hz2radians((frm_int + 1) * frq)
  221. amp2 = frm0 - frm_int
  222. amp3 = 1.0 - amp2
  223. end
  224. frm = env(frmf3)
  225. frm0 = frm / frq.to_f
  226. frm_int = frm0.floor
  227. if frm_int.even?
  228. frq4 = hz2radians(frm_int * frq)
  229. frq5 = hz2radians((frm_int + 1) * frq)
  230. amp5 = frm0 - frm_int
  231. amp4 = 1.0 - amp5
  232. else
  233. frq5 = hz2radians(frm_int * frq)
  234. frq4 = hz2radians((frm_int + 1) * frq)
  235. amp4 = frm0 - frm_int
  236. amp5 = 1.0 - amp4
  237. end
  238. env(ampf) * (0.8 * (amp0 * oscil(of0, frq0 + 0.2 * car) +
  239. amp1 * oscil(of1, frq1 + 0.2 * car)) +
  240. 0.15 * (amp2 * oscil(of2, frq2 + 0.5 * car) +
  241. amp3 * oscil(of3, frq3 + 0.5 * car)) +
  242. 0.05 * (amp4 * oscil(of4, frq4 + car) +
  243. amp5 * oscil(of5, frq5 + car)))
  244. end
  245. end
  246. def vox_test(start = 0.0, dur = 1.0)
  247. amp_env = [0, 0, 25, 1, 75, 1, 100, 0]
  248. frq_env = [0, 0, 5, 0.5, 10, 0, 100, 1]
  249. examp1 = [0, :E, 25, :AE, 35, :ER, 65, :ER, 75, :I, 100, :UH]
  250. examp2 = [0, :I, 5, :OW, 10, :I, 50, :AE, 100, :OO]
  251. $now = start
  252. vox($now, dur, 170, 0.4, amp_env, frq_env, 0.1, examp1, 0.05, 0.1)
  253. $now += dur + 0.2
  254. vox($now, dur, 300, 0.4, amp_env, frq_env, 0.1, examp2, 0.02, 0.1)
  255. $now += dur + 0.2
  256. vox($now, 5, 600, 0.4, amp_env, frq_env, 0.1, examp2, 0.01, 0.1)
  257. $now += 5.0 + 0.2
  258. end
  259. # FOF example
  260. add_help(:fofins,
  261. "fofins(beg, dur, frq, amp, vib, f0, a0, f1, a1, \
  262. f2, a2, ae=[0, 0, 25, 1, 75, 1, 100, 0]) \
  263. Produces FOF synthesis: \
  264. fofins(0, 1, 270, 0.2, 0.001, 730, 0.6, 1090, 0.3, 2440, 0.1)")
  265. def fofins(start, dur, frq, amp, vib, f0, a0, f1, a1, f2, a2,
  266. ae = [0, 0, 25, 1, 75, 1, 100,0])
  267. ampf = make_env(:envelope, ae, :scaler, amp, :duration, dur)
  268. frq0 = hz2radians(f0)
  269. frq1 = hz2radians(f1)
  270. frq2 = hz2radians(f2)
  271. foflen = @srate == 22050.0 ? 100 : 200
  272. vibr = make_oscil(:frequency, 6)
  273. win_freq = TWO_PI / foflen
  274. wt0 = make_wave_train(:size, foflen, :frequency, frq)
  275. foftab = mus_data(wt0)
  276. foflen.times do |i|
  277. foftab[i] = (a0 * sin(i * frq0) + a1 * sin(i * frq1) +
  278. a2 * sin(i * frq2)) * 0.5 * (1.0 - cos(i * win_freq))
  279. end
  280. run_instrument(start, dur) do
  281. env(ampf) * wave_train(wt0, vib * oscil(vibr))
  282. end
  283. end
  284. def fofins_test(start = 0.0, dur = 1.0)
  285. fofins(start, dur, 270, 0.2, 0.001, 730, 0.6, 1090, 0.3, 2440, 0.1)
  286. $now = start + dur + 0.2
  287. end
  288. # FM TRUMPET
  289. #
  290. # Dexter Morrill's FM-trumpet: from CMJ feb 77 p51
  291. def fm_trumpet(start, dur, *args)
  292. frq1, frq2, amp1, amp2, ampatt1, ampdec1, ampatt2, ampdec2 = nil
  293. modfrq1, modind11, modind12, modfrq2, modind21, modind22 = nil
  294. rvibamp, rvibfrq, vibamp, vibfrq, vibatt, vibdec = nil
  295. frqskw, frqatt, ampenv1, ampenv2 = nil
  296. indenv1, indenv2, degree, distance, reverb_amount = nil
  297. optkey(args, binding,
  298. [:frq1, 250.0],
  299. [:frq2, 1500.0],
  300. [:amp1, 0.5],
  301. [:amp2, 0.1],
  302. [:ampatt1, 0.03],
  303. [:ampdec1, 0.35],
  304. [:ampatt2, 0.03],
  305. [:ampdec2, 0.3],
  306. [:modfrq1, 250.0],
  307. [:modind11, 0.0],
  308. [:modind12, 2.66],
  309. [:modfrq2, 250.0],
  310. [:modind21, 0.0],
  311. [:modind22, 1.8],
  312. [:rvibamp, 0.007],
  313. [:rvibfrq, 125.0],
  314. [:vibamp, 0.007],
  315. [:vibfrq, 7.0],
  316. [:vibatt, 0.6],
  317. [:vibdec, 0.2],
  318. [:frqskw, 0.03],
  319. [:frqatt, 0.06],
  320. [:ampenv1, [0, 0, 25, 1, 75, 0.9, 100, 0]],
  321. [:ampenv2, [0, 0, 25, 1, 75, 0.9, 100, 0]],
  322. [:indenv1, [0, 0, 25, 1, 75, 0.9, 100, 0]],
  323. [:indenv2, [0, 0, 25, 1, 75, 0.9, 100, 0]],
  324. [:degree, 0.0],
  325. [:distance, 1.0],
  326. [:reverb_amount, 0.005])
  327. dur = dur.to_f
  328. per_vib_f = make_env(:envelope,
  329. stretch_envelope([0, 1, 25, 0.1, 75, 0, 100, 0],
  330. 25,
  331. [100 * (vibatt / dur), 45].min,
  332. 75,
  333. [100 * (1.0 - vibdec / dur), 55].max),
  334. :scaler, vibamp, :duration, dur)
  335. ran_vib = make_rand_interp(:frequency, rvibfrq, :amplitude, rvibamp)
  336. per_vib = make_oscil(:frequency, vibfrq)
  337. dec_01 = [75, 100 * (1.0 - 0.01 / dur)].max
  338. frq_f = make_env(:envelope,
  339. stretch_envelope([0, 0, 25, 1, 75, 1, 100, 0],
  340. 25,
  341. [25, 100 * (frqatt / dur)].min,
  342. 75,
  343. dec_01),
  344. :scaler, frqskw, :duration, dur)
  345. ampattpt1 = [25, 100 * (ampatt1 / dur)].min
  346. ampdecpt1 = [75, 100 * (1.0 - ampdec1 / dur)].max
  347. ampattpt2 = [25, 100 * (ampatt2 / dur)].min
  348. ampdecpt2 = [75, 100 * (1.0 - ampdec2 / dur)].max
  349. mod1_f = make_env(:envelope,
  350. stretch_envelope(indenv1, 25, ampattpt1, 75, dec_01),
  351. :scaler, modfrq1 * (modind12 - modind11), :duration, dur)
  352. mod1 = make_oscil(:frequency, 0.0)
  353. car1 = make_oscil(:frequency, 0.0)
  354. # set frequency to zero here because it is handled multiplicatively below
  355. car1_f = make_env(:envelope,
  356. stretch_envelope(ampenv1, 25, ampattpt1, 75, ampdecpt1),
  357. :scaler, amp1, :duration, dur)
  358. mod2_f = make_env(:envelope,
  359. stretch_envelope(indenv2, 25, ampattpt2, 75, dec_01),
  360. :scaler, modfrq2 * (modind22 - modind21), :duration, dur)
  361. mod2 = make_oscil(:frequency, 0.0)
  362. car2 = make_oscil(:frequency, 0.0)
  363. car2_f = make_env(:envelope,
  364. stretch_envelope(ampenv2, 25, ampattpt2, 75, ampdecpt2),
  365. :scaler, amp2, :duration, dur)
  366. run_instrument(start, dur,
  367. :degree, degree,
  368. :distance, distance,
  369. :reverb_amount, reverb_amount) do
  370. frq_change = hz2radians((1.0 +
  371. rand_interp(ran_vib)) *
  372. (1.0 + env(per_vib_f) *
  373. oscil(per_vib)) *
  374. (1.0 + env(frq_f)))
  375. env(car1_f) *
  376. oscil(car1, frq_change *
  377. (frq1 + env(mod1_f) * oscil(mod1, modfrq1 * frq_change))) +
  378. env(car2_f) *
  379. oscil(car2, frq_change *
  380. (frq2 + env(mod2_f) * oscil(mod2, modfrq2 * frq_change)))
  381. end
  382. end
  383. def fm_trumpet_test(start = 0.0, dur = 1.0)
  384. fm_trumpet(start, dur)
  385. $now = start + dur + 0.2
  386. end
  387. # PQWVOX
  388. #
  389. # translation of CLM pqwvox.ins (itself translated from MUS10 of MLB's
  390. # waveshaping voice instrument (using phase quadrature waveshaping))
  391. add_help(:pqw_vox,
  392. "pqw_vox(start, dur, freq, spacing_freq, \
  393. amp, ampfun, freqfun, freqscl, phonemes, formant_amps, formant_shapes) \
  394. Produces vocal sounds using phase quadrature waveshaping.")
  395. def pqw_vox(start, dur, freq, spacing_freq, amp, ampfun, freqfun, freqscl,
  396. phonemes, formant_amps, formant_shapes)
  397. vox_fun = lambda do |phons, which, newenv|
  398. # make an envelope from which entry of phoneme data referred to by phons
  399. if phons.empty?
  400. newenv
  401. else
  402. vox_fun.call(phons[2..-1],
  403. which, newenv + [phons[0], Formants[phons[1]][which]])
  404. end
  405. end
  406. car_sin = make_oscil(:frequency, 0.0)
  407. car_cos = make_oscil(:frequency, 0.0, :initial_phase, HALF_PI)
  408. frq_ratio = spacing_freq / freq.to_f
  409. fs = formant_amps.length
  410. sin_evens = Array.new(fs)
  411. cos_evens = Array.new(fs)
  412. sin_odds = Array.new(fs)
  413. cos_odds = Array.new(fs)
  414. amps = Array.new(fs)
  415. frmfs = Array.new(fs)
  416. sin_coeffs = Array.new(fs)
  417. cos_coeffs = Array.new(fs)
  418. ampf = make_env(:envelope, ampfun, :scaler, amp, :duration, dur)
  419. freqf = make_env(:envelope, freqfun, :scaler, freqscl * freq,
  420. :duration, dur, :offset, freq)
  421. per_vib = make_triangle_wave(:frequency, 6.0, :amplitude, freq * 0.1)
  422. ran_vib = make_rand_interp(:frequency, 20.0, :amplitude, freq * 0.05)
  423. fs.times do |i|
  424. sin_evens[i] = make_oscil(:frequency, 0.0)
  425. sin_odds[i] = make_oscil(:frequency, 0.0)
  426. cos_evens[i] = make_oscil(:frequency, 0.0, :initial_phase, HALF_PI)
  427. cos_odds[i] = make_oscil(:frequency, 0.0, :initial_phase, HALF_PI)
  428. amps[i] = formant_amps[i]
  429. shape = normalize_partials(formant_shapes[i])
  430. cos_coeffs[i] = partials2polynomial(shape, 1)
  431. sin_coeffs[i] = partials2polynomial(shape, 0)
  432. frmfs[i] = make_env(:envelope, vox_fun.call(phonemes, i, []),
  433. :duration, dur)
  434. end
  435. run_instrument(start, dur) do
  436. frq = env(freqf) + triangle_wave(per_vib) + rand_interp(ran_vib)
  437. frqscl = hz2radians(frq * frq_ratio)
  438. carsin = oscil(car_sin, frqscl)
  439. carcos = oscil(car_cos, frqscl)
  440. sum = 0.0
  441. fs.times do |j|
  442. frm = env(frmfs[j])
  443. frm0 = frm / frq
  444. frm_int = frm0.floor
  445. if frm_int.even?
  446. even_freq = hz2radians(frm_int * frq)
  447. odd_freq = hz2radians((frm_int + 1.0) * frq)
  448. odd_amp = frm0 - frm_int
  449. even_amp = 1.0 - odd_amp
  450. else
  451. odd_freq = hz2radians(frm_int * frq)
  452. even_freq = hz2radians((frm_int + 1.0) * frq)
  453. even_amp = frm0 - frm_int
  454. odd_amp = 1.0 - even_amp
  455. end
  456. fax = polynomial(cos_coeffs[j], carcos)
  457. yfax = carsin * polynomial(sin_coeffs[j], carcos)
  458. sum = sum + amps[j] *
  459. (even_amp * (yfax * oscil(sin_evens[j], even_freq) -
  460. fax * oscil(cos_evens[j], even_freq)) +
  461. odd_amp * (yfax * oscil(sin_odds[j], odd_freq) -
  462. fax * oscil(cos_odds[j], odd_freq)))
  463. end
  464. env(ampf) * sum
  465. end
  466. end
  467. def pqw_vox_test(start = 0.0, dur = 1.0)
  468. ampfun = [0, 0, 50, 1, 100, 0]
  469. freqfun = [0, 0, 100, 0]
  470. freqramp = [0, 0, 100, 1]
  471. sh1 = [[1, 1, 2, 0.5],
  472. [1, 0.5, 2, 0.5, 3, 1],
  473. [1, 1, 4, 0.5]]
  474. sh2 = [[1, 1, 2, 0.5],
  475. [1, 1, 2, 0.5, 3, 0.2, 4, 0.1],
  476. [1, 1, 3, 0.1, 4, 0.5]]
  477. sh3 = [[1, 1, 2, 0.5],
  478. [1, 1, 4, 0.1],
  479. [1, 1, 2, 0.1, 4, 0.05]]
  480. sh4 = [[1, 1, 2, 0.5, 3, 0.1, 4, 0.01],
  481. [1, 1, 4, 0.1],
  482. [1, 1, 2, 0.1, 4, 0.05]]
  483. $now = start
  484. pqw_vox($now, dur, 300, 300, 0.5, ampfun, freqfun, 0.0,
  485. [0, :L, 100, :L], [0.33, 0.33, 0.33], sh1)
  486. $now += dur + 0.2
  487. pqw_vox($now, dur, 200, 200, 0.1, ampfun, freqramp, 0.1,
  488. [0, :UH, 100, :ER], [0.8, 0.15, 0.05], sh2)
  489. $now += dur + 0.2
  490. pqw_vox($now, dur, 100, 314, 0.1, ampfun, freqramp, 0.1,
  491. [0, :UH, 100, :ER], [0.8, 0.15, 0.05], sh2)
  492. $now += dur + 0.2
  493. pqw_vox($now, dur, 200, 314, 0.1, ampfun, freqramp, 0.01,
  494. [0, :UH, 100, :ER], [0.8, 0.15, 0.05], sh3)
  495. $now += dur + 0.2
  496. pqw_vox($now, dur, 100, 414, 0.2, ampfun, freqramp, 0.01,
  497. [0, :OW, 50, :E, 100, :ER], [0.8, 0.15, 0.05], sh4)
  498. $now += dur + 0.2
  499. end
  500. # STEREO-FLUTE
  501. # slightly simplified [MS]
  502. add_help(:stereo_flute,
  503. "stereo_flute(start, dur, freq, flow, *key_args)
  504. :flow_envelope = [0, 1, 100, 1]
  505. :decay = 0.01
  506. :noise = 0.0356
  507. :embouchure_size = 0.5
  508. :fbk_scl1 = 0.5
  509. :fbk_scl2 = 0.55
  510. :out_scl = 1.0
  511. :a0 = 0.7
  512. :b1 = -0.3
  513. :vib_rate = 5
  514. :vib_amount = 0.03
  515. :ran_rate = 5
  516. :ran_amount = 0.03
  517. is a physical model of a flute: \
  518. stereo_flute(0, 1, 440, 0.55, :flow_envelope, [0, 0, 1, 1, 2, 1, 3, 0])")
  519. def stereo_flute(start, dur, freq, flow, *args)
  520. flow_envelope, decay, noise, embouchure_size = nil
  521. fbk_scl1, fbk_scl2, out_scl = nil
  522. a0, b1, vib_rate, vib_amount, ran_rate, ran_amount = nil
  523. optkey(args, binding,
  524. [:flow_envelope, [0, 1, 100, 1]],
  525. [:decay, 0.01], # additional time for instrument to decay
  526. [:noise, 0.0356],
  527. [:embouchure_size, 0.5],
  528. [:fbk_scl1, 0.5], # these two are crucial for good results
  529. [:fbk_scl2, 0.55],
  530. [:out_scl, 1.0],
  531. [:a0, 0.7], # filter coefficients
  532. [:b1, -0.3],
  533. [:vib_rate, 5],
  534. [:vib_amount, 0.03],
  535. [:ran_rate, 5],
  536. [:ran_amount, 0.03])
  537. flowf = make_env(:envelope, flow_envelope, :scaler, flow,
  538. :length, seconds2samples(dur - decay))
  539. periodic_vib = make_oscil(:frequency, vib_rate)
  540. ran_vib = make_rand_interp(:frequency, ran_rate)
  541. breath = make_rand(:frequency, @srate / 2.0, :amplitude, 1)
  542. period_samples = (@srate / freq).floor
  543. embouchure_samples = (embouchure_size * period_samples).floor
  544. embouchure = make_delay(embouchure_samples, :initial_element, 0.0)
  545. bore = make_delay(period_samples)
  546. reflection_lp_filter = make_one_pole(a0, b1)
  547. out_sig = current_diff = previous_out_sig = previous_dc_blocked_a = 0.0
  548. run_instrument(start, dur) do
  549. delay_sig = delay(bore, out_sig)
  550. emb_sig = delay(embouchure, current_diff)
  551. current_flow = vib_amount * oscil(periodic_vib) +
  552. ran_amount * rand_interp(ran_vib) + env(flowf)
  553. current_diff = (current_flow + noise * current_flow * rand(breath)) +
  554. fbk_scl1 * delay_sig
  555. current_exitation = emb_sig - emb_sig * emb_sig * emb_sig
  556. out_sig = one_pole(reflection_lp_filter,
  557. current_exitation + fbk_scl2 * delay_sig)
  558. # NB the DC blocker is not in the cicuit. It is applied to the
  559. # out_sig but the result is not fed back into the system.
  560. dc_blocked_a = (out_sig - previous_out_sig) + 0.995 * previous_dc_blocked_a
  561. previous_out_sig = out_sig
  562. previous_dc_blocked_a = dc_blocked_a
  563. out_scl * dc_blocked_a
  564. end
  565. end
  566. def flute_test(start = 0.0, dur = 1.0)
  567. stereo_flute(start, dur, 440, 0.55, :flow_envelope, [0, 0, 1, 1, 2, 1, 3, 0])
  568. $now = start + dur + 0.2
  569. end
  570. # FM-BELL
  571. add_help(:fm_bell,
  572. "fm_bell(startime, dur, frequency, amplitude, \
  573. amp-env=[...], index_env=[...], index=1.0) \
  574. Mixes in one fm bell note." )
  575. def fm_bell(start, dur, freq, amp,
  576. amp_env = [0, 0, 0.1, 1, 10, 0.6, 25, 0.3,
  577. 50, 0.15, 90, 0.1, 100, 0],
  578. index_env = [0, 1, 2, 1.1, 25, 0.75, 75, 0.5, 100, 0.2],
  579. index = 1.0)
  580. fm_ind1 = hz2radians(32.0 * freq)
  581. fm_ind2 = hz2radians(4.0 * (8.0 - freq / 50.0))
  582. fm_ind3 = fm_ind2 * 0.705 * (1.4 - freq / 250.0)
  583. fm_ind4 = hz2radians(32.0 * (20.0 - freq / 20.0))
  584. mod1 = make_oscil(:frequency, freq * 2.0)
  585. mod2 = make_oscil(:frequency, freq * 1.41)
  586. mod3 = make_oscil(:frequency, freq * 2.82)
  587. mod4 = make_oscil(:frequency, freq * 2.4)
  588. car1 = make_oscil(:frequency, freq)
  589. car2 = make_oscil(:frequency, freq)
  590. car3 = make_oscil(:frequency, freq * 2.4)
  591. indf = make_env(:envelope, index_env, :scaler, index, :duration, dur)
  592. ampf = make_env(:envelope, amp_env, :scaler, amp, :duration, dur)
  593. run_instrument(start, dur) do
  594. fmenv = env(indf)
  595. env(ampf) *
  596. (oscil(car1, fmenv * fm_ind1 * oscil(mod1)) +
  597. 0.15 *
  598. oscil(car2, fmenv * (fm_ind2 * oscil(mod2) + fm_ind3 * oscil(mod3))) +
  599. 0.15 *
  600. oscil(car3, fmenv * fm_ind4 * oscil(mod4)))
  601. end
  602. end
  603. def fm_bell_test(start = 0.0, dur = 1.0)
  604. fm_bell(start, dur, 440, 0.5)
  605. $now = start + dur + 0.2
  606. end
  607. # FM-INSECT
  608. def fm_insect(start, dur, freq, amp, amp_env,
  609. mod_freq, mod_skew, mod_freq_env, mod_index, mod_index_env,
  610. fm_index, fm_ratio, *args)
  611. degree, distance, reverb_amount = nil
  612. optkey(args, binding,
  613. [:degree, 0.0],
  614. [:distance, 1.0],
  615. [:reverb_amount, 0.005])
  616. carrier = make_oscil(:frequency, freq)
  617. fm1_osc = make_oscil(:frequency, mod_freq)
  618. fm2_osc = make_oscil(:frequency, fm_ratio * freq)
  619. ampf = make_env(:envelope, amp_env, :scaler, amp, :duration, dur)
  620. indf = make_env(:envelope, mod_index_env,
  621. :scaler, hz2radians(mod_index),
  622. :duration, dur)
  623. modfrqf = make_env(:envelope, mod_freq_env,
  624. :scaler, hz2radians(mod_skew),
  625. :duration, dur)
  626. fm2_amp = hz2radians(fm_index * fm_ratio * freq)
  627. run_instrument(start, dur,
  628. :degree, degree,
  629. :distance, distance,
  630. :reverb_amount, reverb_amount) do
  631. garble_in = env(indf) * oscil(fm1_osc, env(modfrqf))
  632. garble_out = fm2_amp * oscil(fm2_osc, garble_in)
  633. env(ampf) * oscil(carrier, garble_out + garble_in)
  634. end
  635. end
  636. def fm_insect_test(start = 0.0, dur = 1.0)
  637. locust = [0, 0, 40, 1, 95, 1, 100, 0.5]
  638. bug_hi = [0, 1, 25, 0.7, 75, 0.78, 100, 1]
  639. amp = [0, 0, 25, 1, 75, 0.7, 100, 0]
  640. $now = start
  641. fm_insect($now + 0.000, 1.699, 4142.627, 0.015, amp, 60, -16.707,
  642. locust, 500.866, bug_hi, 0.346, 0.5)
  643. fm_insect($now + 0.195, 0.233, 4126.284, 0.030, amp, 60, -12.142,
  644. locust, 649.490, bug_hi, 0.407, 0.5)
  645. fm_insect($now + 0.217, 2.057, 3930.258, 0.045, amp, 60, -3.011,
  646. locust, 562.087, bug_hi, 0.591, 0.5)
  647. fm_insect($now + 2.100, 1.500, 900.627, 0.060, amp, 40, -16.707,
  648. locust, 300.866, bug_hi, 0.346, 0.5)
  649. fm_insect($now + 3.000, 1.500, 900.627, 0.060, amp, 40, -16.707,
  650. locust, 300.866, bug_hi, 0.046, 0.5)
  651. fm_insect($now + 3.450, 1.500, 900.627, 0.090, amp, 40, -16.707,
  652. locust, 300.866, bug_hi, 0.006, 0.5)
  653. fm_insect($now + 3.950, 1.500, 900.627, 0.120, amp, 40, -10.707,
  654. locust, 300.866, bug_hi, 0.346, 0.5)
  655. fm_insect($now + 4.300, 1.500, 900.627, 0.090, amp, 40, -20.707,
  656. locust, 300.866, bug_hi, 0.246, 0.5)
  657. $now += 6.0
  658. end
  659. # FM-DRUM
  660. #
  661. # Jan Mattox's fm drum:
  662. def fm_drum(start, dur, freq, amp, index, high = false,
  663. degree = 0.0, distance = 1.0, rev_amount = 0.01)
  664. casrat = high ? 8.525 : 3.515
  665. fmrat = high ? 3.414 : 1.414
  666. glsf = make_env(:envelope, [0, 0, 25, 0, 75, 1, 100, 1],
  667. :scaler, high ? hz2radians(66) : 0.0, :duration, dur)
  668. ampfun = [0, 0, 3, 0.05, 5, 0.2, 7, 0.8, 8, 0.95,
  669. 10, 1.0, 12, 0.95, 20, 0.3, 30, 0.1, 100, 0]
  670. atdrpt = 100 * (high ? 0.01 : 0.015) / dur
  671. ampf = make_env(:envelope,
  672. stretch_envelope(ampfun, 10, atdrpt, 15,
  673. [atdrpt + 1,
  674. 100 - 100 * ((dur - 0.2) / dur)].max),
  675. :scaler, amp, :duration, dur)
  676. indxfun = [0, 0, 5, 0.014, 10, 0.033, 15, 0.061, 20, 0.099,
  677. 25, 0.153, 30, 0.228, 35, 0.332, 40, 0.477,
  678. 45, 0.681, 50, 0.964, 55, 0.681, 60, 0.478, 65, 0.332,
  679. 70, 0.228, 75, 0.153, 80, 0.099, 85, 0.061,
  680. 90, 0.033, 95, 0.0141, 100, 0]
  681. indxpt = 100 - 100 * ((dur - 0.1) / dur)
  682. divindxf = stretch_envelope(indxfun, 50, atdrpt, 65, indxpt)
  683. indxf = make_env(:envelope, divindxf, :duration, dur,
  684. :scaler, [hz2radians(index * fmrat * freq), PI].min)
  685. mindxf = make_env(:envelope, divindxf, :duration, dur,
  686. :scaler, [hz2radians(index * casrat * freq), PI].min)
  687. devf = make_env(:envelope,
  688. stretch_envelope(ampfun, 10, atdrpt, 90,
  689. [atdrpt + 1,
  690. 100 - 100 * ((dur - 0.05) / dur)].max),
  691. :scaler, [hz2radians(7000), PI].min, :duration, dur)
  692. rn = make_rand(:frequency, 7000, :amplitude, 1)
  693. carrier = make_oscil(:frequency, freq)
  694. fmosc = make_oscil(:frequency, freq * fmrat)
  695. cascade = make_oscil(:frequency, freq * casrat)
  696. run_instrument(start, dur,
  697. :degree, degree,
  698. :distance, distance,
  699. :reverb_amount, rev_amount) do
  700. gls = env(glsf)
  701. env(ampf) *
  702. oscil(carrier,
  703. gls +
  704. env(indxf) *
  705. oscil(fmosc,
  706. gls * fmrat +
  707. env(mindxf) * oscil(cascade,
  708. gls * casrat +
  709. env(devf) * rand(rn))))
  710. end
  711. end
  712. def fm_drum_test(start = 0.0, dur = 1.0)
  713. $now = start
  714. fm_drum($now, dur, 55, 0.3, 5, false)
  715. $now += dur + 0.2
  716. fm_drum($now, dur, 66, 0.3, 4, true)
  717. $now += dur + 0.2
  718. end
  719. # FM-GONG
  720. #
  721. # Paul Weineke's gong.
  722. def gong(start, dur, freq, amp, *args)
  723. degree, distance, reverb_amount = nil
  724. optkey(args, binding,
  725. [:degree, 0.0],
  726. [:distance, 1.0],
  727. [:reverb_amount, 0.005])
  728. mfq1 = freq * 1.16
  729. mfq2 = freq * 3.14
  730. mfq3 = freq * 1.005
  731. indx01 = hz2radians(0.01 * mfq1)
  732. indx11 = hz2radians(0.30 * mfq1)
  733. indx02 = hz2radians(0.01 * mfq2)
  734. indx12 = hz2radians(0.38 * mfq2)
  735. indx03 = hz2radians(0.01 * mfq3)
  736. indx13 = hz2radians(0.50 * mfq3)
  737. atpt = 5
  738. atdur = 100 * (0.002 / dur)
  739. expf = [0, 0, 3, 1, 15, 0.5, 27, 0.25, 50, 0.1, 100, 0]
  740. rise = [0, 0, 15, 0.3, 30, 1.0, 75, 0.5, 100, 0]
  741. fmup = [0, 0, 75, 1.0, 98, 1.0, 100, 0]
  742. fmdwn = [0, 0, 2, 1.0, 100, 0]
  743. ampfun = make_env(:envelope, stretch_envelope(expf, atpt, atdur),
  744. :scaler, amp, :duration, dur)
  745. indxfun1 = make_env(:envelope, fmup, :scaler, indx11 - indx01,
  746. :duration, dur, :offset, indx01)
  747. indxfun2 = make_env(:envelope, fmdwn, :scaler, indx12 - indx02,
  748. :duration, dur, :offset, indx02)
  749. indxfun3 = make_env(:envelope, rise, :scaler, indx13 - indx03,
  750. :duration, dur, :offset, indx03)
  751. carrier = make_oscil(:frequency, freq)
  752. mod1 = make_oscil(:frequency, mfq1)
  753. mod2 = make_oscil(:frequency, mfq2)
  754. mod3 = make_oscil(:frequency, mfq3)
  755. run_instrument(start, dur,
  756. :degree, degree,
  757. :distance, distance,
  758. :reverb_amount, reverb_amount) do
  759. env(ampfun) *
  760. oscil(carrier,
  761. env(indxfun1) * oscil(mod1) +
  762. env(indxfun2) * oscil(mod2) +
  763. env(indxfun3) * oscil(mod3))
  764. end
  765. end
  766. def gong_test(start = 0.0, dur = 1.0)
  767. gong(start, dur, 261.61, 0.6)
  768. $now = start + dur + 0.2
  769. end
  770. # ATTRACT
  771. #
  772. # by James McCartney, from CMJ vol 21 no 3 p 6
  773. def attract(start, dur, amp, c)
  774. a = b = 0.2
  775. dt = 0.04
  776. scale = (0.5 * amp) / c
  777. x = -1.0
  778. y = z = 0.0
  779. run_instrument(start, dur) do
  780. x1 = x - dt * (y + z)
  781. y = y + dt * (x + a * y)
  782. z = z + dt * ((b + x * z) - c * z)
  783. x = x1
  784. scale * x
  785. end
  786. end
  787. def attract_test(start = 0.0, dur = 1.0)
  788. attract(start, dur, 0.5, 2.0)
  789. $now = start + dur + 0.2
  790. end
  791. # PQW
  792. #
  793. # phase-quadrature waveshaping used to create asymmetric (i.e. single
  794. # side-band) spectra. The basic idea here is a variant of sin x sin y
  795. # - cos x cos y = cos (x + y)
  796. def pqw(start, dur, spacing_freq, carrier_freq,
  797. amp, ampfun, indexfun, partials, *args)
  798. degree, distance, reverb_amount = nil
  799. optkey(args, binding,
  800. [:degree, 0.0],
  801. [:distance, 1.0],
  802. [:reverb_amount, 0.005])
  803. normalized_partials = normalize_partials(partials)
  804. spacing_cos = make_oscil(:frequency, spacing_freq, :initial_phase, HALF_PI)
  805. spacing_sin = make_oscil(:frequency, spacing_freq)
  806. carrier_cos = make_oscil(:frequency, carrier_freq, :initial_phase, HALF_PI)
  807. carrier_sin = make_oscil(:frequency, carrier_freq)
  808. sin_coeffs = partials2polynomial(normalized_partials, 0)
  809. cos_coeffs = partials2polynomial(normalized_partials, 1)
  810. amp_env = make_env(:envelope, ampfun, :scaler, amp, :duration, dur)
  811. ind_env = make_env(:envelope, indexfun, :duration, dur)
  812. r = carrier_freq / spacing_freq.to_f
  813. tr = make_triangle_wave(:frequency, 5,
  814. :amplitude, hz2radians(0.005 * spacing_freq))
  815. rn = make_rand_interp(:frequency, 12,
  816. :amplitude, hz2radians(0.005 * spacing_freq))
  817. run_instrument(start, dur,
  818. :degree, degree,
  819. :distance, distance,
  820. :reverb_amount, reverb_amount) do
  821. vib = triangle_wave(tr) + rand_interp(rn)
  822. ax = [1.0, env(ind_env)].min * oscil(spacing_cos, vib)
  823. fax = polynomial(cos_coeffs, ax)
  824. yfax = oscil(spacing_sin, vib) * polynomial(sin_coeffs, ax)
  825. env(amp_env) *
  826. (oscil(carrier_sin, vib * r) * yfax -
  827. oscil(carrier_cos, vib * r) * fax)
  828. end
  829. end
  830. def pqw_test(start = 0.0, dur = 1.0)
  831. pqw(start, dur, 200, 1000, 0.2,
  832. [0, 0, 25, 1, 100, 0], [0, 1, 100, 0], [2, 0.1, 3, 0.3, 6, 0.5])
  833. $now = start + dur + 0.2
  834. # to see the asymmetric spectrum most clearly, set the index function
  835. # above to [0, 1, 100, 1]
  836. end
  837. # taken from Perry Cook's stkv1.tar.Z (Synthesis Toolkit), but I was
  838. # in a bit of a hurry and may not have made slavishly accurate
  839. # translations. Please let me (bil@ccrma.stanford.edu) know of any
  840. # serious (non-envelope) errors.
  841. #
  842. # from Perry Cook's TubeBell.cpp
  843. def tubebell(start, dur, freq, amp, base = 32.0)
  844. osc0 = make_oscil(freq * 0.995)
  845. osc1 = make_oscil(freq * 0.995 * 1.414)
  846. osc2 = make_oscil(freq * 1.005)
  847. osc3 = make_oscil(freq * 1.414)
  848. ampenv1 = make_env(:envelope, [0, 0, 0.005, 1, dur, 0],
  849. :base, base, :duration, dur)
  850. ampenv2 = make_env(:envelope, [0, 0, 0.001, 1, dur, 0],
  851. :base, 2 * base, :duration, dur)
  852. ampmod = make_oscil(:frequency, 2.0)
  853. g0 = 0.5 * amp * 0.707
  854. g1 = 0.203
  855. g2 = 0.5 * amp
  856. g3 = 0.144
  857. run_instrument(start, dur) do
  858. (0.007 *
  859. oscil(ampmod) + 0.993) *
  860. (g0 * env(ampenv1) * oscil(osc0, g1 * oscil(osc1)) +
  861. g2 * env(ampenv2) * oscil(osc2, g3 * oscil(osc3)))
  862. end
  863. end
  864. def tubebell_test(start = 0.0, dur = 1.0)
  865. tubebell(start, dur, 440, 0.2, 32)
  866. $now = start + dur + 0.2
  867. end
  868. # from Perry Cook's Wurley.cpp
  869. def wurley(start, dur, freq, amp)
  870. osc0 = make_oscil(freq)
  871. osc1 = make_oscil(freq * 4.0)
  872. osc2 = make_oscil(510.0)
  873. osc3 = make_oscil(510.0)
  874. ampmod = make_oscil(:frequency, 8.0)
  875. g0 = 0.5 * amp
  876. g1 = 0.307
  877. g2 = 0.5 * amp * 0.307
  878. g3 = 0.117
  879. dur = [dur, 0.3].max
  880. ampenv = make_env(:envelope, [0, 0, 1, 1, 9, 1, 10, 0], :duration, dur)
  881. indenv = make_env(:envelope, [0, 0, 0.001, 1, 0.15, 0, dur, 0],
  882. :duration, dur)
  883. resenv = make_env(:envelope, [0, 0, 0.001, 1, 0.25, 0, dur, 0],
  884. :duration, dur)
  885. run_instrument(start, dur) do
  886. env(ampenv) *
  887. (1.0 + 0.007 * oscil(ampmod)) *
  888. (g0 * oscil(osc0, g1 * oscil(osc1)) +
  889. env(resenv) * g2 * oscil(osc2, g3 * env(indenv) * oscil(osc3)))
  890. end
  891. end
  892. def wurley_test(start = 0.0, dur = 1.0)
  893. wurley(start, dur, 440, 0.2)
  894. $now = start + dur + 0.2
  895. end
  896. # from Perry Cook's Rhodey.cpp
  897. def rhodey(start, dur, freq, amp, base = 0.5)
  898. osc0 = make_oscil(freq)
  899. osc1 = make_oscil(freq * 0.5)
  900. osc2 = make_oscil(freq)
  901. osc3 = make_oscil(freq * 15.0)
  902. dur = [dur, 0.3].max
  903. ampenv1 = make_env(:envelope, [0, 0, 0.005, 1, dur, 0],
  904. :base, base, :duration, dur)
  905. ampenv2 = make_env(:envelope, [0, 0, 0.001, 1, dur, 0],
  906. :base, base * 1.5, :duration, dur)
  907. ampenv3 = make_env(:envelope, [0, 0, 0.001, 1, 0.25, 0, dur, 0],
  908. :base, base * 4, :duration, dur)
  909. g0 = 0.5 * amp
  910. g1 = 0.535
  911. g2 = 0.5 * amp
  912. g3 = 0.109
  913. run_instrument(start, dur) do
  914. g0 * env(ampenv1) * oscil(osc0, g1 * oscil(osc1)) +
  915. g2 * env(ampenv2) * oscil(osc2, env(ampenv3) * g3 * oscil(osc3))
  916. end
  917. end
  918. def rhodey_test(start = 0.0, dur = 1.0)
  919. rhodey(start, dur, 440, 0.2, 0.5)
  920. $now = start + dur + 0.2
  921. end
  922. # from Perry Cook's BeeThree.cpp
  923. def hammondoid(start, dur, freq, amp)
  924. osc0 = make_oscil(freq * 0.999)
  925. osc1 = make_oscil(freq * 1.997)
  926. osc2 = make_oscil(freq * 3.006)
  927. osc3 = make_oscil(freq * 6.009)
  928. dur = [dur, 0.1].max
  929. ampenv1 = make_env(:envelope, [0, 0, 0.005, 1, dur - 0.008, 1, dur, 0],
  930. :duration, dur)
  931. ampenv2 = make_env(:envelope, [0, 0, 0.005, 1, dur, 0], :duration, dur)
  932. g0 = 0.25 * 0.75 * amp
  933. g1 = 0.25 * 0.75 * amp
  934. g2 = 0.5 * amp
  935. g3 = 0.5 * 0.75 * amp
  936. run_instrument(start, dur) do
  937. env(ampenv1) *
  938. (g0 * oscil(osc0) +
  939. g1 * oscil(osc1) +
  940. g2 * oscil(osc2)) +
  941. env(ampenv2) * g3 * oscil(osc3)
  942. end
  943. end
  944. def hammondoid_test(start = 0.0, dur = 1.0)
  945. hammondoid(start, dur, 440, 0.2)
  946. $now = start + dur + 0.2
  947. end
  948. # from Perry Cook's HeavyMtl.cpp
  949. def metal(start, dur, freq, amp)
  950. osc0 = make_oscil(freq)
  951. osc1 = make_oscil(freq * 4.0 * 0.999)
  952. osc2 = make_oscil(freq * 3.0 * 1.001)
  953. osc3 = make_oscil(freq * 0.5 * 1.002)
  954. dur = [dur, 0.1].max
  955. ampenv0 = make_env(:envelope, [0, 0, 0.001, 1, dur - 0.002, 1, dur, 0],
  956. :duration, dur)
  957. ampenv1 = make_env(:envelope, [0, 0, 0.001, 1, dur - 0.011, 1, dur, 0],
  958. :duration, dur)
  959. ampenv2 = make_env(:envelope, [0, 0, 0.01, 1, dur - 0.015, 1, dur, 0],
  960. :duration, dur)
  961. ampenv3 = make_env(:envelope, [0, 0, 0.03, 1, dur - 0.04, 1, dur, 0],
  962. :duration, dur)
  963. g0 = 0.615 * amp
  964. g1 = 0.202
  965. g2 = 0.574
  966. g3 = 0.116
  967. run_instrument(start, dur) do
  968. g0 *
  969. env(ampenv0) *
  970. oscil(osc0,
  971. g1 * env(ampenv1) * oscil(osc1, g2 * env(ampenv2) * oscil(osc2)) +
  972. g3 * env(ampenv3) * oscil(osc3))
  973. end
  974. end
  975. def metal_test(start = 0.0, dur = 1.0)
  976. metal(start, dur, 440, 0.2)
  977. $now = start + dur + 0.2
  978. end
  979. # DRONE
  980. def drone(start, dur, freq, amp, ampfun, synth,
  981. ampat, ampdc, amtrev, deg, dis, rvibamt, rvibfreq)
  982. waveform = partials2wave(synth)
  983. amp *= 0.25
  984. s = make_table_lookup(:frequency, freq, :wave, waveform)
  985. amp_env = make_env(:envelope,
  986. stretch_envelope(ampfun, 25, 100 * (ampat / dur.to_f), 75,
  987. 100 - 100 * (ampdc / dur.to_f)),
  988. :scaler, amp, :duration, dur)
  989. ran_vib = make_rand(:frequency, rvibfreq,
  990. :amplitude, hz2radians(rvibamt * freq))
  991. run_instrument(start, dur,
  992. :distance, dis,
  993. :degree, deg,
  994. :reverb_amount, amtrev) do
  995. env(amp_env) * table_lookup(s, rand(ran_vib).abs)
  996. end
  997. end
  998. # CANTER
  999. def canter(start, dur, pitch, amp, deg, dis, pcrev,
  1000. ampfun, ranfun, skewfun, skewpc,
  1001. ranpc, ranfreq, indexfun, atdr, dcdr,
  1002. ampfun1, indfun1, fmtfun1,
  1003. ampfun2, indfun2, fmtfun2,
  1004. ampfun3, indfun3, fmtfun3,
  1005. ampfun4, indfun4, fmtfun4)
  1006. amp *= 0.25
  1007. dur = dur.to_f
  1008. pitch = pitch.to_f
  1009. rangetop = 910.0
  1010. rangebot = 400.0
  1011. k = (100 * (log(pitch / rangebot) / log(rangetop / rangebot))).floor
  1012. mfq = pitch
  1013. atpt = 100 * (atdr / dur)
  1014. dcpt = 100 - 100 * (dcdr / dur)
  1015. lfmt1 = envelope_interp(k, fmtfun1)
  1016. harm1 = (0.5 + lfmt1 / pitch).floor
  1017. dev11 = hz2radians(envelope_interp(k, indfun1) * mfq)
  1018. dev01 = dev11 * 0.5
  1019. lamp1 = envelope_interp(k, ampfun1) * amp * (1 - (harm1 - lfmt1 / pitch).abs)
  1020. lfmt2 = envelope_interp(k, fmtfun2)
  1021. harm2 = (0.5 + lfmt2 / pitch).floor
  1022. dev12 = hz2radians(envelope_interp(k, indfun2) * mfq)
  1023. dev02 = dev12 * 0.5
  1024. lamp2 = envelope_interp(k, ampfun2) * amp * (1 - (harm2 - lfmt2 / pitch).abs)
  1025. lfmt3 = envelope_interp(k, fmtfun3)
  1026. harm3 = (0.5 + lfmt3 / pitch).floor
  1027. dev13 = hz2radians(envelope_interp(k, indfun3) * mfq)
  1028. dev03 = dev13 * 0.5
  1029. lamp3 = envelope_interp(k, ampfun3) * amp * (1 - (harm3 - lfmt3 / pitch).abs)
  1030. lfmt4 = envelope_interp(k, fmtfun4)
  1031. harm4 = (0.5 + lfmt4 / pitch).floor
  1032. dev14 = hz2radians(envelope_interp(k, indfun4) * mfq)
  1033. dev04 = dev14 * 0.5
  1034. lamp4 = envelope_interp(k, ampfun4) * amp * (1 - (harm4 - lfmt4 / pitch).abs)
  1035. tampfun = make_env(:envelope, stretch_envelope(ampfun, 25, atpt, 75, dcpt),
  1036. :duration, dur)
  1037. tskwfun = make_env(:envelope, stretch_envelope(skewfun, 25, atpt, 75, dcpt),
  1038. :scaler, hz2radians(pitch * skewpc.to_f), :duration, dur)
  1039. tranfun = make_env(:envelope, stretch_envelope(ranfun, 25, atpt, 75, dcpt),
  1040. :duration, dur)
  1041. tidxfun = make_env(:envelope, stretch_envelope(indexfun, 25, atpt, 75, dcpt),
  1042. :duration, dur)
  1043. modgen = make_oscil(:frequency, pitch)
  1044. gen1 = make_oscil(:frequency, pitch * harm1)
  1045. gen2 = make_oscil(:frequency, pitch * harm2)
  1046. gen3 = make_oscil(:frequency, pitch * harm3)
  1047. gen4 = make_oscil(:frequency, pitch * harm4)
  1048. ranvib = make_rand(:frequency, ranfreq, :amplitude, hz2radians(ranpc * pitch))
  1049. run_instrument(start, dur,
  1050. :degree, deg,
  1051. :distance, dis,
  1052. :reverb_amount, pcrev) do
  1053. frqval = env(tskwfun) + env(tranfun) * rand(ranvib)
  1054. modval = oscil(modgen, frqval)
  1055. ampval = env(tampfun)
  1056. indval = env(tidxfun)
  1057. lamp1 *
  1058. ampval *
  1059. oscil(gen1, ((dev01 + indval * dev11) * modval + frqval) * harm1) +
  1060. lamp2 *
  1061. ampval *
  1062. oscil(gen2, ((dev02 + indval * dev12) * modval + frqval) * harm2) +
  1063. lamp3 *
  1064. ampval *
  1065. oscil(gen3, ((dev03 + indval * dev13) * modval + frqval) * harm3) +
  1066. lamp4 *
  1067. ampval *
  1068. oscil(gen4, ((dev04 + indval * dev14) * modval + frqval) * harm4)
  1069. end
  1070. end
  1071. # NREV (the most popular Samson box reverb)
  1072. #
  1073. # reverb_factor controls the length of the decay -- it should not
  1074. # exceed (/ 1.0 .823)
  1075. # lp_coeff controls the strength of the low pass filter inserted
  1076. # in the feedback loop
  1077. # volume can be used to boost the reverb output
  1078. def nrev(*args)
  1079. reverb_factor, lp_coeff, volume = nil
  1080. optkey(args, binding,
  1081. [:reverb_factor, 1.09],
  1082. [:lp_coeff, 0.7],
  1083. [:volume, 1.0])
  1084. next_prime = lambda do |val|
  1085. if val.prime?
  1086. val
  1087. else
  1088. next_prime.call(val + 2)
  1089. end
  1090. end
  1091. srscale = @srate / 25641
  1092. dly_len = [1433, 1601, 1867, 2053, 2251, 2399,
  1093. 347, 113, 37, 59, 53, 43, 37, 29, 19]
  1094. dly_len.map! do |x|
  1095. val = (x * srscale).round
  1096. val += 1 if val.even?
  1097. next_prime.call(val)
  1098. end
  1099. comb1 = make_comb(0.822 * reverb_factor, dly_len[0])
  1100. comb2 = make_comb(0.802 * reverb_factor, dly_len[1])
  1101. comb3 = make_comb(0.773 * reverb_factor, dly_len[2])
  1102. comb4 = make_comb(0.753 * reverb_factor, dly_len[3])
  1103. comb5 = make_comb(0.753 * reverb_factor, dly_len[4])
  1104. comb6 = make_comb(0.733 * reverb_factor, dly_len[5])
  1105. low = make_one_pole(lp_coeff, lp_coeff - 1.0)
  1106. chan2 = (@channels > 1)
  1107. chan4 = (@channels == 4)
  1108. allpass1 = make_all_pass(-0.7, 0.7, dly_len[6])
  1109. allpass2 = make_all_pass(-0.7, 0.7, dly_len[7])
  1110. allpass3 = make_all_pass(-0.7, 0.7, dly_len[8])
  1111. allpass4 = make_all_pass(-0.7, 0.7, dly_len[9]) # 10 for quad
  1112. allpass5 = make_all_pass(-0.7, 0.7, dly_len[11])
  1113. allpass6 = (chan2 ? make_all_pass(-0.7, 0.7, dly_len[12]) : nil)
  1114. allpass7 = (chan4 ? make_all_pass(-0.7, 0.7, dly_len[13]) : nil)
  1115. allpass8 = (chan4 ? make_all_pass(-0.7, 0.7, dly_len[14]) : nil)
  1116. out_frample = Vct.new(@channels, 0.0)
  1117. run_reverb() do |val, i|
  1118. rev = volume * val
  1119. outrev = all_pass(allpass4,
  1120. one_pole(low,
  1121. all_pass(allpass3,
  1122. all_pass(allpass2,
  1123. all_pass(allpass1,
  1124. comb(comb1, rev) +
  1125. comb(comb2, rev) +
  1126. comb(comb3, rev) +
  1127. comb(comb4, rev) +
  1128. comb(comb5, rev) +
  1129. comb(comb6, rev))))))
  1130. out_frample[0] = all_pass(allpass5, outrev)
  1131. if chan2
  1132. out_frample[1] = all_pass(allpass6, outrev)
  1133. end
  1134. if chan4
  1135. out_frample[2] = all_pass(allpass7, outrev)
  1136. out_frample[3] = all_pass(allpass8, outrev)
  1137. end
  1138. out_frample
  1139. end
  1140. end
  1141. def drone_canter_test(start = 0.0, dur = 1.0)
  1142. fmt1 = [0, 1200, 100, 1000]
  1143. fmt2 = [0, 2250, 100, 1800]
  1144. fmt3 = [0, 4500, 100, 4500]
  1145. fmt4 = [0, 6750, 100, 8100]
  1146. amp1 = [0, 0.67, 100, 0.7]
  1147. amp2 = [0, 0.95, 100, 0.95]
  1148. amp3 = [0, 0.28, 100, 0.33]
  1149. amp4 = [0, 0.14, 100, 0.15]
  1150. ind1 = [0, 0.75, 100, 0.65]
  1151. ind2 = [0, 0.75, 100, 0.75]
  1152. ind3 = [0, 1, 100, 1]
  1153. ind4 = [0, 1, 100, 1]
  1154. skwf = [0, 0, 100, 0]
  1155. ampf = [0, 0, 25, 1, 75, 1, 100, 0]
  1156. ranf = [0, 0.5, 100, 0.5]
  1157. index = [0, 1, 100, 1]
  1158. solid = [0, 0, 5, 1, 95, 1, 100, 0]
  1159. bassdr2 = [0.5, 0.06, 1, 0.62, 1.5, 0.07, 2, 0.6, 2.5, 0.08, 3, 0.56,
  1160. 4, 0.24, 5, 0.98, 6, 0.53, 7, 0.16, 8, 0.33, 9, 0.62, 10, 0.12,
  1161. 12, 0.14, 14, 0.86, 16, 0.12, 23, 0.14, 24, 0.17]
  1162. tenordr = [0.3, 0.04, 1, 0.81, 2, 0.27, 3, 0.2, 4, 0.21, 5, 0.18,
  1163. 6, 0.35, 7, 0.03, 8, 0.07, 9, 0.02, 10, 0.025, 11, 0.035]
  1164. $now = start
  1165. drone($now, 4, 115, 0.125, solid, bassdr2, 0.1, 0.5, 0.03, 45, 1, 0.01, 10)
  1166. drone($now, 4, 229, 0.125, solid, tenordr, 0.1, 0.5, 0.03, 45, 1, 0.01, 11)
  1167. drone($now, 4, 229.5, 0.125, solid, tenordr, 0.1, 0.5, 0.03, 45, 1, 0.01, 9)
  1168. canter($now, 2.100, 918.000, 0.175, 45.0, 1, 0.05,
  1169. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1170. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1171. canter($now + 2.100, 0.300, 688.500, 0.175, 45.0, 1, 0.05,
  1172. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1173. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1174. canter($now + 2.400, 0.040, 826.200, 0.175, 45.0, 1, 0.05,
  1175. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1176. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1177. canter($now + 2.440, 0.560, 459.000, 0.175, 45.0, 1, 0.05,
  1178. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1179. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1180. canter($now + 3.000, 0.040, 408.000, 0.175, 45.0, 1, 0.05,
  1181. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1182. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1183. canter($now + 3.040, 0.040, 619.650, 0.175, 45.0, 1, 0.05,
  1184. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1185. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1186. canter($now + 3.080, 0.040, 408.000, 0.175, 45.0, 1, 0.05,
  1187. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1188. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1189. canter($now + 3.120, 0.040, 688.500, 0.175, 45.0, 1, 0.05,
  1190. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1191. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1192. canter($now + 3.160, 0.290, 459.000, 0.175, 45.0, 1, 0.05,
  1193. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1194. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1195. canter($now + 3.450, 0.150, 516.375, 0.175, 45.0, 1, 0.05,
  1196. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1197. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1198. canter($now + 3.600, 0.040, 826.200, 0.175, 45.0, 1, 0.05,
  1199. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1200. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1201. canter($now + 3.640, 0.040, 573.750, 0.175, 45.0, 1, 0.05,
  1202. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1203. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1204. canter($now + 3.680, 0.040, 619.650, 0.175, 45.0, 1, 0.05,
  1205. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1206. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1207. canter($now + 3.720, 0.180, 573.750, 0.175, 45.0, 1, 0.05,
  1208. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1209. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1210. canter($now + 3.900, 0.040, 688.500, 0.175, 45.0, 1, 0.05,
  1211. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1212. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1213. canter($now + 3.940, 0.260, 459.000, 0.175, 45.0, 1, 0.05,
  1214. ampf, ranf, skwf, 0.050, 0.01, 10, index, 0.005, 0.005,
  1215. amp1, ind1, fmt1, amp2, ind2, fmt2, amp3, ind3, fmt3, amp4, ind4, fmt4)
  1216. $now += 4.4
  1217. end
  1218. # RESON
  1219. def reson(start, dur, pitch, amp, numformants,
  1220. indxfun, skewfun, pcskew, skewat, skewdc,
  1221. vibfreq, vibpc, ranvibfreq, ranvibpc,
  1222. degree, distance, rev_amount, data)
  1223. # data is a list of lists of form
  1224. # [ampf, resonfrq, resonamp, ampat, ampdc, dev0, dev1, indxat, indxdc]
  1225. dur = dur.to_f
  1226. pitch = pitch.to_f
  1227. modulator = make_oscil(:frequency, pitch)
  1228. carriers = Array.new(numformants)
  1229. ampfs = Array.new(numformants)
  1230. indfs = Array.new(numformants)
  1231. c_rats = Array.new(numformants)
  1232. frqf = make_env(:envelope,
  1233. stretch_envelope(skewfun, 25, 100 * (skewat / dur), 75,
  1234. 100 - (100 * (skewdc / dur))),
  1235. :scaler, hz2radians(pcskew * pitch), :duration, dur)
  1236. pervib = make_triangle_wave(:frequency, vibfreq,
  1237. :amplitude, hz2radians(vibpc * pitch))
  1238. ranvib = make_rand_interp(:frequency, ranvibfreq,
  1239. :amplitude, hz2radians(ranvibpc * pitch))
  1240. totalamp = 0.0
  1241. numformants.times do |i|
  1242. totalamp += data[i][2]
  1243. end
  1244. numformants.times do |i|
  1245. frmdat = data[i]
  1246. ampf = frmdat[0]
  1247. freq = frmdat[1]
  1248. rfamp = frmdat[2]
  1249. ampat = 100 * (frmdat[3] / dur)
  1250. ampdc = 100 - 100 * (frmdat[4] / dur)
  1251. dev0 = hz2radians(frmdat[5] * freq)
  1252. dev1 = hz2radians(frmdat[6] * freq)
  1253. indxat = 100 * (frmdat[7] / dur)
  1254. indxdc = 100 - 100 * (frmdat[8] / dur)
  1255. harm = (freq / pitch).round
  1256. rsamp = 1.0 - (harm - freq / pitch).abs
  1257. cfq = pitch * harm
  1258. ampat = 25 if ampat.zero?
  1259. ampdc = 75 if ampdc.zero?
  1260. indxat = 25 if indxat.zero?
  1261. indxdc = 75 if indxdc.zero?
  1262. indfs[i] = make_env(:envelope,
  1263. stretch_envelope(indxfun, 25, indxat, 75, indxdc),
  1264. :scaler, dev1 - dev0,
  1265. :offset, dev0,
  1266. :duration, dur)
  1267. ampfs[i] = make_env(:envelope,
  1268. stretch_envelope(ampf, 25, ampat, 75, ampdc),
  1269. :scaler, rsamp * amp * (rfamp / totalamp),
  1270. :duration, dur)
  1271. c_rats[i] = harm
  1272. carriers[i] = make_oscil(:frequency, cfq)
  1273. end
  1274. run_instrument(start, dur,
  1275. :degree, degree,
  1276. :distance, distance,
  1277. :reverb_amount, rev_amount) do
  1278. vib = triangle_wave(pervib) + rand_interp(ranvib) + env(frqf)
  1279. modsig = oscil(modulator, vib)
  1280. outsum = 0.0
  1281. numformants.times do |j|
  1282. outsum += env(ampfs[j]) *
  1283. oscil(carriers[j],
  1284. vib * c_rats[j] +
  1285. env(indfs[j]) * modsig)
  1286. end
  1287. outsum
  1288. end
  1289. end
  1290. def reson_test(start = 0.0, dur = 1.0)
  1291. data = [[[0, 0, 100, 1], 1200, 0.5, 0.1, 0.1, 0, 1.0, 0.1, 0.1],
  1292. [[0, 1, 100, 0], 2400, 0.5, 0.1, 0.1, 0, 1.0, 0.1, 0.1]]
  1293. reson(start, dur, 440, 0.5, 2, [0, 0, 100, 1], [0, 0, 100, 1],
  1294. 0.1, 0.1, 0.1, 5, 0.01, 5, 0.01, 0, 1.0, 0.01, data)
  1295. $now = start + dur + 0.2
  1296. end
  1297. # STK's feedback-fm instrument named CelloN in Sambox-land
  1298. def cellon(start, dur, pitch0, amp, ampfun, betafun,
  1299. beta0, beta1, betaat, betadc, ampat, ampdc, dis, pcrev, deg, pitch1,
  1300. glissfun = [0, 0, 100, 0], glissat = 0.0, glissdc = 0.0,
  1301. pvibfreq = 0.0, pvibpc = 0.0,
  1302. pvibfun = [0, 1, 100, 1], pvibat = 0.0, pvibdc = 0.0,
  1303. rvibfreq = 0.0, rvibpc = 0.0, rvibfun = [0, 1, 100, 1])
  1304. pit1 = pitch1.zero? ? pitch0 : pitch1
  1305. car = make_oscil(:frequency, pitch0)
  1306. low = make_one_zero(0.5, -0.5)
  1307. fmosc = make_oscil(:frequency, pitch0)
  1308. fm = 0.0
  1309. dur = dur.to_f
  1310. pitch0 = pitch0.to_f
  1311. pvib = make_triangle_wave(:frequency, pvibfreq, :amplitude, 1.0)
  1312. rvib = make_rand_interp(:frequency, rvibfreq, :amplitude, 1.0)
  1313. ampap = (ampat > 0.0 ? (100 * (ampat / dur)) : 25)
  1314. ampdp = (ampdc > 0.0 ? (100 * (1.0 - ampdc / dur)) : 75)
  1315. glsap = (glissat > 0.0 ? (100 * (glissat / dur)) : 25)
  1316. glsdp = (glissdc > 0.0 ? (100 * (1.0 - glissdc / dur)) : 75)
  1317. betap = (betaat > 0.0 ? (100 * (betaat / dur)) : 25)
  1318. betdp = (betadc > 0.0 ? (100 * (1.0 - betadc / dur)) : 75)
  1319. pvbap = (pvibat > 0.0 ? (100 * (pvibat / dur)) : 25)
  1320. pvbdp = (pvibdc > 0.0 ? (100 * (1.0 - pvibdc / dur)) : 75)
  1321. pvibenv = make_env(:envelope,
  1322. stretch_envelope(pvibfun, 25, pvbap, 75, pvbdp),
  1323. :scaler, hz2radians(pvibpc * pitch0),
  1324. :duration, dur)
  1325. rvibenv = make_env(:envelope, stretch_envelope(rvibfun),
  1326. :duration, dur,
  1327. :scaler, hz2radians(rvibpc * pitch0))
  1328. glisenv = make_env(:envelope,
  1329. stretch_envelope(glissfun, 25, glsap, 75, glsdp),
  1330. :scaler, hz2radians(pit1 - pitch0),
  1331. :duration, dur)
  1332. amplenv = make_env(:envelope, stretch_envelope(ampfun, 25, ampap, 75, ampdp),
  1333. :scaler, amp,
  1334. :duration, dur)
  1335. betaenv = make_env(:envelope, stretch_envelope(betafun, 25, betap, 75, betdp),
  1336. :scaler, beta1 - beta0,
  1337. :offset, beta0,
  1338. :duration, dur)
  1339. run_instrument(start, dur,
  1340. :degree, deg,
  1341. :distance, dis,
  1342. :reverb_amount, pcrev) do
  1343. vib = env(pvibenv) * triangle_wave(pvib) +
  1344. env(rvibenv) * rand_interp(rvib) +
  1345. env(glisenv)
  1346. fm = one_zero(low, env(betaenv) * oscil(fmosc, fm + vib))
  1347. env(amplenv) * oscil(car, fm + vib)
  1348. end
  1349. end
  1350. def cellon_test(start = 0.0, dur = 1.0)
  1351. cellon(start, dur, 220, 0.5,
  1352. [0, 0, 25, 1, 75, 1, 100, 0], # ampfun
  1353. [0, 0, 25, 1, 75, 1, 100, 0], # betafun
  1354. 0.75, 1.0, 0, 0, 0, 0, 1, 0, 0, 220,
  1355. [0, 0, 25, 1, 75, 1, 100, 0], # glissfun
  1356. 0, 0, 0, 0,
  1357. [0, 0, 100, 0], # pvibfun
  1358. 0, 0, 0, 0,
  1359. [0, 0, 100, 0]) # rvibfun
  1360. $now = start + dur + 0.2
  1361. end
  1362. # JL-REVERB
  1363. def jl_reverb(*args)
  1364. allpass1 = make_all_pass(-0.7, 0.7, 2111)
  1365. allpass2 = make_all_pass(-0.7, 0.7, 673)
  1366. allpass3 = make_all_pass(-0.7, 0.7, 223)
  1367. comb1 = make_comb(0.742, 9601)
  1368. comb2 = make_comb(0.733, 10007)
  1369. comb3 = make_comb(0.715, 10799)
  1370. comb4 = make_comb(0.697, 11597)
  1371. outdel1 = make_delay((0.013 * @srate).round)
  1372. outdel2 = (@channels > 1 ? make_delay((0.011 * @srate).round) : false)
  1373. out_frample = Vct.new(@channels, 0.0)
  1374. run_reverb() do |ho, i|
  1375. allpass_sum = all_pass(allpass3, all_pass(allpass2, all_pass(allpass1, ho)))
  1376. comb_sum = (comb(comb1, allpass_sum) + comb(comb2, allpass_sum) +
  1377. comb(comb3, allpass_sum) + comb(comb4, allpass_sum))
  1378. out_frample[0] = delay(outdel1, comb_sum)
  1379. if outdel2
  1380. out_frample[1] = delay(outdel2, comb_sum)
  1381. end
  1382. out_frample
  1383. end
  1384. end
  1385. # GRAN-SYNTH
  1386. def gran_synth(start, dur, freq, grain_dur, interval, amp)
  1387. grain_env = make_env(:envelope, [0, 0, 25, 1, 75, 1, 100, 0],
  1388. :duration, grain_dur)
  1389. carrier = make_oscil(:frequency, freq)
  1390. grain_size = ([grain_dur, interval].max * @srate).ceil
  1391. grains = make_wave_train(:size, grain_size, :frequency, 1.0 / interval)
  1392. grain = mus_data(grains)
  1393. grain_size.times do |i|
  1394. grain[i] = env(grain_env) * oscil(carrier)
  1395. end
  1396. run_instrument(start, dur) do
  1397. amp * wave_train(grains)
  1398. end
  1399. end
  1400. def gran_synth_test(start = 0.0, dur = 1.0)
  1401. gran_synth(start, dur, 100, 0.0189, 0.02, 0.4)
  1402. $now = start + dur + 0.2
  1403. end
  1404. # TOUCH-TONE
  1405. def touch_tone(start, number)
  1406. touch_tab_1 = [0, 697, 697, 697, 770, 770, 770, 852, 852, 852, 941, 941, 941]
  1407. touch_tab_2 = [0, 1209, 1336, 1477, 1209, 1336,
  1408. 1477, 1209, 1336, 1477, 1209, 1336, 1477]
  1409. number.length.times do |i|
  1410. k = number[i]
  1411. ii = if k.kind_of?(Numeric)
  1412. k.zero? ? 11 : k
  1413. else
  1414. k == ?* ? 10 : 12
  1415. end
  1416. frq1 = make_oscil(:frequency, touch_tab_1[ii])
  1417. frq2 = make_oscil(:frequency, touch_tab_2[ii])
  1418. run_instrument(start + i * 0.3, 0.2) do
  1419. 0.25 * (oscil(frq1) + oscil(frq2))
  1420. end
  1421. end
  1422. end
  1423. def touch_tone_test(start = 0.0, dur = 1.0)
  1424. touch_tone(start, [4, 8, 3, 4, 6, 2, 1])
  1425. $now = start + dur * 7 + 0.2 # 7 digits
  1426. end
  1427. # SPECTRA
  1428. def spectra(start, dur, freq, amp,
  1429. partials = [1, 1, 2, 0.5],
  1430. amp_envelope = [0, 0, 50, 1, 100, 0],
  1431. vibrato_amplitude = 0.005,
  1432. vibrato_speed = 5.0,
  1433. degree = 0.0,
  1434. distance = 1.0,
  1435. rev_amount = 0.005)
  1436. waveform = partials2wave(partials)
  1437. frq = hz2radians(freq)
  1438. s = make_table_lookup(:frequency, freq, :wave, waveform)
  1439. amp_env = make_env(:envelope, amp_envelope, :scaler, amp, :duration, dur)
  1440. per_vib = make_triangle_wave(:frequency, vibrato_speed,
  1441. :amplitude, vibrato_amplitude * frq)
  1442. ran_vib = make_rand_interp(:frequency, vibrato_speed + 1.0,
  1443. :amplitude, vibrato_amplitude * frq)
  1444. run_instrument(start, dur,
  1445. :degree, degree,
  1446. :distance, distance,
  1447. :reverb_amount, rev_amount) do
  1448. env(amp_env) *
  1449. table_lookup(s, triangle_wave(per_vib) + rand_interp(ran_vib))
  1450. end
  1451. end
  1452. def spectra_test(start = 0.0, dur = 1.0)
  1453. spectra(start, dur, 440.0, 0.8, P_a4,
  1454. [0, 0, 1, 1, 5, 0.9, 12, 0.5, 25, 0.25, 100, 0])
  1455. $now = start + dur + 0.2
  1456. end
  1457. # TWO-TAB
  1458. #
  1459. # interpolate between two waveforms (this could be extended to
  1460. # implement all the various wavetable-based synthesis techniques).
  1461. def two_tab(start, dur, freq, amp,
  1462. partial_1 = [1.0, 1.0, 2.0, 0.5],
  1463. partial_2 = [1.0, 0.0, 3.0, 1.0],
  1464. amp_envelope = [0, 0, 50, 1, 100, 0],
  1465. interp_func = [0, 1, 100, 0],
  1466. vibrato_amplitude = 0.005,
  1467. vibrato_speed = 5.0,
  1468. degree = 0.0,
  1469. distance = 1.0,
  1470. rev_amount = 0.005)
  1471. waveform_1 = partials2wave(partial_1)
  1472. waveform_2 = partials2wave(partial_2)
  1473. frq = hz2radians(freq)
  1474. s_1 = make_table_lookup(:frequency, freq, :wave, waveform_1)
  1475. s_2 = make_table_lookup(:frequency, freq, :wave, waveform_2)
  1476. amp_env = make_env(:envelope, amp_envelope, :scaler, amp, :duration, dur)
  1477. interp_env = make_env(:envelope, interp_func, :duration, dur)
  1478. per_vib = make_triangle_wave(:frequency, vibrato_speed,
  1479. :amplitude, vibrato_amplitude * frq)
  1480. ran_vib = make_rand_interp(:frequency, vibrato_speed + 1.0,
  1481. :amplitude, vibrato_amplitude * frq)
  1482. run_instrument(start, dur,
  1483. :degree, degree,
  1484. :distance, distance,
  1485. :reverb_amount, rev_amount) do
  1486. vib = triangle_wave(per_vib) + rand_interp(ran_vib)
  1487. intrp = env(interp_env)
  1488. env(amp_env) *
  1489. (intrp * table_lookup(s_1, vib) +
  1490. (1.0 - intrp) * table_lookup(s_2, vib))
  1491. end
  1492. end
  1493. def two_tab_test(start = 0.0, dur = 1.0)
  1494. two_tab(start, dur, 440, 0.5)
  1495. $now = start + dur + 0.2
  1496. end
  1497. # LBJ-PIANO
  1498. $clm_piano_attack_duration = 0.04
  1499. $clm_piano_release_duration = 0.2
  1500. $clm_db_drop_per_second = -10.0
  1501. Piano_Spectra = [[1.97, 0.0326, 2.99, 0.0086, 3.95, 0.0163, 4.97,
  1502. 0.0178, 5.98, 0.0177, 6.95, 0.0315, 8.02, 0.0001, 8.94, 0.0076,
  1503. 9.96, 0.0134, 10.99, 0.0284, 11.98, 0.0229, 13.02, 0.0229, 13.89,
  1504. 0.0010, 15.06, 0.0090, 16.00, 0.0003, 17.08, 0.0078, 18.16, 0.0064,
  1505. 19.18, 0.0129, 20.21, 0.0085, 21.27, 0.0225, 22.32, 0.0061, 23.41,
  1506. 0.0102, 24.48, 0.0005, 25.56, 0.0016, 26.64, 0.0018, 27.70, 0.0113,
  1507. 28.80, 0.0111, 29.91, 0.0158, 31.06, 0.0093, 32.17, 0.0017, 33.32,
  1508. 0.0002, 34.42, 0.0018, 35.59, 0.0027, 36.74, 0.0055, 37.90, 0.0037,
  1509. 39.06, 0.0064, 40.25, 0.0033, 41.47, 0.0014, 42.53, 0.0004, 43.89,
  1510. 0.0010, 45.12, 0.0039, 46.33, 0.0039, 47.64, 0.0009, 48.88, 0.0016,
  1511. 50.13, 0.0006, 51.37, 0.0010, 52.70, 0.0002, 54.00, 0.0004, 55.30,
  1512. 0.0008, 56.60, 0.0025, 57.96, 0.0010, 59.30, 0.0012, 60.67, 0.0011,
  1513. 61.99, 0.0003, 62.86, 0.0001, 64.36, 0.0005, 64.86, 0.0001, 66.26,
  1514. 0.0004, 67.70, 0.0006, 68.94, 0.0002, 70.10, 0.0001, 70.58, 0.0002,
  1515. 72.01, 0.0007, 73.53, 0.0006, 75.00, 0.0002, 77.03, 0.0005, 78.00,
  1516. 0.0002, 79.57, 0.0006, 81.16, 0.0005, 82.70, 0.0005, 84.22, 0.0003,
  1517. 85.41, 0.0002, 87.46, 0.0001, 90.30, 0.0001, 94.02, 0.0001, 95.26,
  1518. 0.0002, 109.39, 0.0003],
  1519. [1.98, 0.0194, 2.99, 0.0210, 3.97, 0.0276, 4.96, 0.0297, 5.96, 0.0158,
  1520. 6.99, 0.0207, 8.01, 0.0009, 9.00, 0.0101, 10.00, 0.0297, 11.01,
  1521. 0.0289, 12.02, 0.0211, 13.04, 0.0127, 14.07, 0.0061, 15.08, 0.0174,
  1522. 16.13, 0.0009, 17.12, 0.0093, 18.16, 0.0117, 19.21, 0.0122, 20.29,
  1523. 0.0108, 21.30, 0.0077, 22.38, 0.0132, 23.46, 0.0073, 24.14, 0.0002,
  1524. 25.58, 0.0026, 26.69, 0.0035, 27.77, 0.0053, 28.88, 0.0024, 30.08,
  1525. 0.0027, 31.13, 0.0075, 32.24, 0.0027, 33.36, 0.0004, 34.42, 0.0004,
  1526. 35.64, 0.0019, 36.78, 0.0037, 38.10, 0.0009, 39.11, 0.0027, 40.32,
  1527. 0.0010, 41.51, 0.0013, 42.66, 0.0019, 43.87, 0.0007, 45.13, 0.0017,
  1528. 46.35, 0.0019, 47.65, 0.0021, 48.89, 0.0014, 50.18, 0.0023, 51.42,
  1529. 0.0015, 52.73, 0.0002, 54.00, 0.0005, 55.34, 0.0006, 56.60, 0.0010,
  1530. 57.96, 0.0016, 58.86, 0.0005, 59.30, 0.0004, 60.75, 0.0005, 62.22,
  1531. 0.0003, 63.55, 0.0005, 64.82, 0.0003, 66.24, 0.0003, 67.63, 0.0011,
  1532. 69.09, 0.0007, 70.52, 0.0004, 72.00, 0.0005, 73.50, 0.0008, 74.95,
  1533. 0.0003, 77.13, 0.0013, 78.02, 0.0002, 79.48, 0.0004, 82.59, 0.0004,
  1534. 84.10, 0.0003],
  1535. [2.00, 0.0313, 2.99, 0.0109, 4.00, 0.0215, 5.00, 0.0242, 5.98, 0.0355,
  1536. 7.01, 0.0132, 8.01, 0.0009, 9.01, 0.0071, 10.00, 0.0258, 11.03,
  1537. 0.0221, 12.02, 0.0056, 13.06, 0.0196, 14.05, 0.0160, 15.11, 0.0107,
  1538. 16.11, 0.0003, 17.14, 0.0111, 18.21, 0.0085, 19.23, 0.0010, 20.28,
  1539. 0.0048, 21.31, 0.0128, 22.36, 0.0051, 23.41, 0.0041, 24.05, 0.0006,
  1540. 25.54, 0.0019, 26.62, 0.0028, 27.72, 0.0034, 28.82, 0.0062, 29.89,
  1541. 0.0039, 30.98, 0.0058, 32.08, 0.0011, 33.21, 0.0002, 34.37, 0.0008,
  1542. 35.46, 0.0018, 36.62, 0.0036, 37.77, 0.0018, 38.92, 0.0042, 40.07,
  1543. 0.0037, 41.23, 0.0011, 42.67, 0.0003, 43.65, 0.0018, 44.68, 0.0025,
  1544. 45.99, 0.0044, 47.21, 0.0051, 48.40, 0.0044, 49.67, 0.0005, 50.88,
  1545. 0.0019, 52.15, 0.0003, 53.42, 0.0008, 54.69, 0.0010, 55.98, 0.0005,
  1546. 57.26, 0.0013, 58.53, 0.0027, 59.83, 0.0011, 61.21, 0.0027, 62.54,
  1547. 0.0003, 63.78, 0.0003, 65.20, 0.0001, 66.60, 0.0006, 67.98, 0.0008,
  1548. 69.37, 0.0019, 70.73, 0.0007, 72.14, 0.0004, 73.62, 0.0002, 74.40,
  1549. 0.0003, 76.52, 0.0006, 77.97, 0.0002, 79.49, 0.0004, 80.77, 0.0003,
  1550. 81.00, 0.0001, 82.47, 0.0005, 83.97, 0.0001, 87.27, 0.0002],
  1551. [2.00, 0.0257, 2.99, 0.0142, 3.97, 0.0202, 4.95, 0.0148, 5.95, 0.0420,
  1552. 6.95, 0.0037, 7.94, 0.0004, 8.94, 0.0172, 9.95, 0.0191, 10.96, 0.0115,
  1553. 11.97, 0.0059, 12.98, 0.0140, 14.00, 0.0178, 15.03, 0.0121, 16.09,
  1554. 0.0002, 17.07, 0.0066, 18.08, 0.0033, 19.15, 0.0022, 20.18, 0.0057,
  1555. 21.22, 0.0077, 22.29, 0.0037, 23.33, 0.0066, 24.97, 0.0002, 25.49,
  1556. 0.0019, 26.55, 0.0042, 27.61, 0.0043, 28.73, 0.0038, 29.81, 0.0084,
  1557. 30.91, 0.0040, 32.03, 0.0025, 33.14, 0.0005, 34.26, 0.0003, 35.38,
  1558. 0.0019, 36.56, 0.0037, 37.68, 0.0049, 38.86, 0.0036, 40.11, 0.0011,
  1559. 41.28, 0.0008, 42.50, 0.0004, 43.60, 0.0002, 44.74, 0.0022, 45.99,
  1560. 0.0050, 47.20, 0.0009, 48.40, 0.0036, 49.68, 0.0004, 50.92, 0.0009,
  1561. 52.17, 0.0005, 53.46, 0.0007, 54.76, 0.0006, 56.06, 0.0005, 57.34,
  1562. 0.0011, 58.67, 0.0005, 59.95, 0.0015, 61.37, 0.0008, 62.72, 0.0004,
  1563. 65.42, 0.0009, 66.96, 0.0003, 68.18, 0.0003, 69.78, 0.0003, 71.21,
  1564. 0.0004, 72.45, 0.0002, 74.22, 0.0003, 75.44, 0.0001, 76.53, 0.0003,
  1565. 78.31, 0.0004, 79.83, 0.0003, 80.16, 0.0001, 81.33, 0.0003, 82.44,
  1566. 0.0001, 83.17, 0.0002, 84.81, 0.0003, 85.97, 0.0003, 89.08, 0.0001,
  1567. 90.70, 0.0002, 92.30, 0.0002, 95.59, 0.0002, 97.22, 0.0003, 98.86,
  1568. 0.0001, 108.37, 0.0001, 125.54, 0.0001],
  1569. [1.99, 0.0650, 3.03, 0.0040, 4.03, 0.0059, 5.02, 0.0090, 5.97, 0.0227,
  1570. 6.98, 0.0050, 8.04, 0.0020, 9.00, 0.0082, 9.96, 0.0078, 11.01, 0.0056,
  1571. 12.01, 0.0095, 13.02, 0.0050, 14.04, 0.0093, 15.08, 0.0064, 16.14,
  1572. 0.0017, 17.06, 0.0020, 18.10, 0.0025, 19.14, 0.0023, 20.18, 0.0015,
  1573. 21.24, 0.0032, 22.29, 0.0029, 23.32, 0.0014, 24.37, 0.0005, 25.43,
  1574. 0.0030, 26.50, 0.0022, 27.60, 0.0027, 28.64, 0.0024, 29.76, 0.0035,
  1575. 30.81, 0.0136, 31.96, 0.0025, 33.02, 0.0003, 34.13, 0.0005, 35.25,
  1576. 0.0007, 36.40, 0.0014, 37.51, 0.0020, 38.64, 0.0012, 39.80, 0.0019,
  1577. 40.97, 0.0004, 42.09, 0.0003, 43.24, 0.0003, 44.48, 0.0002, 45.65,
  1578. 0.0024, 46.86, 0.0005, 48.07, 0.0013, 49.27, 0.0008, 50.49, 0.0006,
  1579. 52.95, 0.0001, 54.23, 0.0005, 55.45, 0.0004, 56.73, 0.0001, 58.03,
  1580. 0.0003, 59.29, 0.0002, 60.59, 0.0003, 62.04, 0.0002, 65.89, 0.0002,
  1581. 67.23, 0.0002, 68.61, 0.0002, 69.97, 0.0004, 71.36, 0.0005, 85.42,
  1582. 0.0001],
  1583. [1.98, 0.0256, 2.96, 0.0158, 3.95, 0.0310, 4.94, 0.0411, 5.95, 0.0238,
  1584. 6.94, 0.0152, 7.93, 0.0011, 8.95, 0.0185, 9.92, 0.0166, 10.93, 0.0306,
  1585. 11.94, 0.0258, 12.96, 0.0202, 13.97, 0.0403, 14.95, 0.0228, 15.93,
  1586. 0.0005, 17.01, 0.0072, 18.02, 0.0034, 19.06, 0.0028, 20.08, 0.0124,
  1587. 21.13, 0.0137, 22.16, 0.0102, 23.19, 0.0058, 23.90, 0.0013, 25.30,
  1588. 0.0039, 26.36, 0.0039, 27.41, 0.0025, 28.47, 0.0071, 29.64, 0.0031,
  1589. 30.60, 0.0027, 31.71, 0.0021, 32.84, 0.0003, 33.82, 0.0002, 35.07,
  1590. 0.0019, 36.09, 0.0054, 37.20, 0.0038, 38.33, 0.0024, 39.47, 0.0055,
  1591. 40.55, 0.0016, 41.77, 0.0006, 42.95, 0.0002, 43.27, 0.0018, 44.03,
  1592. 0.0006, 45.25, 0.0019, 46.36, 0.0033, 47.50, 0.0024, 48.87, 0.0012,
  1593. 50.03, 0.0016, 51.09, 0.0004, 53.52, 0.0017, 54.74, 0.0012, 56.17,
  1594. 0.0003, 57.40, 0.0011, 58.42, 0.0020, 59.70, 0.0007, 61.29, 0.0008,
  1595. 62.56, 0.0003, 63.48, 0.0002, 64.83, 0.0002, 66.12, 0.0012, 67.46,
  1596. 0.0017, 68.81, 0.0003, 69.13, 0.0003, 70.53, 0.0002, 71.84, 0.0001,
  1597. 73.28, 0.0002, 75.52, 0.0010, 76.96, 0.0005, 77.93, 0.0003, 78.32,
  1598. 0.0003, 79.73, 0.0003, 81.69, 0.0002, 82.52, 0.0001, 84.01, 0.0001,
  1599. 84.61, 0.0002, 86.88, 0.0001, 88.36, 0.0002, 89.85, 0.0002, 91.35,
  1600. 0.0003, 92.86, 0.0002, 93.40, 0.0001, 105.28, 0.0002, 106.22, 0.0002,
  1601. 107.45, 0.0001, 108.70, 0.0003, 122.08, 0.0002],
  1602. [1.97, 0.0264, 2.97, 0.0211, 3.98, 0.0234, 4.98, 0.0307, 5.96, 0.0085,
  1603. 6.94, 0.0140, 7.93, 0.0005, 8.96, 0.0112, 9.96, 0.0209, 10.98, 0.0194,
  1604. 11.98, 0.0154, 12.99, 0.0274, 13.99, 0.0127, 15.01, 0.0101, 15.99,
  1605. 0.0002, 17.04, 0.0011, 18.08, 0.0032, 19.14, 0.0028, 20.12, 0.0054,
  1606. 21.20, 0.0053, 22.13, 0.0028, 23.22, 0.0030, 24.32, 0.0006, 25.24,
  1607. 0.0004, 26.43, 0.0028, 27.53, 0.0048, 28.52, 0.0039, 29.54, 0.0047,
  1608. 30.73, 0.0044, 31.82, 0.0007, 32.94, 0.0008, 34.04, 0.0012, 35.13,
  1609. 0.0018, 36.29, 0.0007, 37.35, 0.0075, 38.51, 0.0045, 39.66, 0.0014,
  1610. 40.90, 0.0004, 41.90, 0.0002, 43.08, 0.0002, 44.24, 0.0017, 45.36,
  1611. 0.0013, 46.68, 0.0020, 47.79, 0.0015, 48.98, 0.0010, 50.21, 0.0012,
  1612. 51.34, 0.0001, 53.82, 0.0003, 55.09, 0.0004, 56.23, 0.0005, 57.53,
  1613. 0.0004, 58.79, 0.0005, 59.30, 0.0002, 60.03, 0.0002, 61.40, 0.0003,
  1614. 62.84, 0.0001, 66.64, 0.0001, 67.97, 0.0001, 69.33, 0.0001, 70.68,
  1615. 0.0001, 73.57, 0.0002, 75.76, 0.0002, 76.45, 0.0001, 79.27, 0.0001,
  1616. 80.44, 0.0002, 81.87, 0.0002],
  1617. [2.00, 0.0311, 2.99, 0.0086, 3.99, 0.0266, 4.97, 0.0123, 5.98, 0.0235,
  1618. 6.97, 0.0161, 7.97, 0.0008, 8.96, 0.0088, 9.96, 0.0621, 10.99, 0.0080,
  1619. 11.99, 0.0034, 12.99, 0.0300, 14.03, 0.0228, 15.04, 0.0105, 16.03,
  1620. 0.0004, 17.06, 0.0036, 18.09, 0.0094, 18.95, 0.0009, 20.17, 0.0071,
  1621. 21.21, 0.0161, 22.25, 0.0106, 23.28, 0.0104, 24.33, 0.0008, 25.38,
  1622. 0.0030, 26.46, 0.0035, 27.50, 0.0026, 28.59, 0.0028, 29.66, 0.0128,
  1623. 30.75, 0.0139, 31.81, 0.0038, 32.93, 0.0006, 34.04, 0.0004, 35.16,
  1624. 0.0005, 36.25, 0.0023, 37.35, 0.0012, 38.46, 0.0021, 39.59, 0.0035,
  1625. 40.71, 0.0006, 41.86, 0.0007, 42.42, 0.0001, 43.46, 0.0003, 44.17,
  1626. 0.0032, 45.29, 0.0013, 46.57, 0.0004, 47.72, 0.0011, 48.79, 0.0005,
  1627. 50.11, 0.0005, 51.29, 0.0003, 52.47, 0.0002, 53.68, 0.0004, 55.02,
  1628. 0.0005, 56.18, 0.0003, 57.41, 0.0003, 58.75, 0.0007, 59.33, 0.0009,
  1629. 60.00, 0.0004, 61.34, 0.0001, 64.97, 0.0003, 65.20, 0.0002, 66.48,
  1630. 0.0002, 67.83, 0.0002, 68.90, 0.0003, 70.25, 0.0003, 71.59, 0.0002,
  1631. 73.68, 0.0001, 75.92, 0.0001, 77.08, 0.0002, 78.45, 0.0002, 81.56,
  1632. 0.0002, 82.99, 0.0001, 88.39, 0.0001],
  1633. [0.97, 0.0059, 1.98, 0.0212, 2.99, 0.0153, 3.99, 0.0227, 4.96, 0.0215,
  1634. 5.97, 0.0153, 6.98, 0.0085, 7.98, 0.0007, 8.97, 0.0179, 9.98, 0.0512,
  1635. 10.98, 0.0322, 12.00, 0.0098, 13.02, 0.0186, 14.00, 0.0099, 15.05,
  1636. 0.0109, 15.88, 0.0011, 17.07, 0.0076, 18.11, 0.0071, 19.12, 0.0045,
  1637. 20.16, 0.0038, 21.23, 0.0213, 22.27, 0.0332, 23.34, 0.0082, 24.34,
  1638. 0.0014, 25.42, 0.0024, 26.47, 0.0012, 27.54, 0.0014, 28.60, 0.0024,
  1639. 29.72, 0.0026, 30.10, 0.0008, 31.91, 0.0021, 32.13, 0.0011, 33.02,
  1640. 0.0007, 34.09, 0.0014, 35.17, 0.0007, 36.27, 0.0024, 37.39, 0.0029,
  1641. 38.58, 0.0014, 39.65, 0.0017, 40.95, 0.0012, 41.97, 0.0004, 42.43,
  1642. 0.0002, 43.49, 0.0001, 44.31, 0.0012, 45.42, 0.0031, 46.62, 0.0017,
  1643. 47.82, 0.0013, 49.14, 0.0013, 50.18, 0.0010, 51.54, 0.0003, 53.90,
  1644. 0.0006, 55.06, 0.0010, 56.31, 0.0003, 57.63, 0.0001, 59.02, 0.0003,
  1645. 60.09, 0.0004, 60.35, 0.0004, 61.62, 0.0009, 63.97, 0.0001, 65.19,
  1646. 0.0001, 65.54, 0.0002, 66.92, 0.0002, 67.94, 0.0002, 69.17, 0.0003,
  1647. 69.60, 0.0004, 70.88, 0.0002, 72.24, 0.0002, 76.12, 0.0001, 78.94,
  1648. 0.0001, 81.75, 0.0001, 82.06, 0.0001, 83.53, 0.0001, 90.29, 0.0002,
  1649. 91.75, 0.0001, 92.09, 0.0002, 93.28, 0.0001, 97.07, 0.0001],
  1650. [1.98, 0.0159, 2.98, 0.1008, 3.98, 0.0365, 4.98, 0.0133, 5.97, 0.0101,
  1651. 6.97, 0.0115, 7.97, 0.0007, 8.99, 0.0349, 10.01, 0.0342, 11.01,
  1652. 0.0236, 12.00, 0.0041, 13.02, 0.0114, 14.05, 0.0137, 15.06, 0.0100,
  1653. 16.05, 0.0007, 17.04, 0.0009, 18.12, 0.0077, 19.15, 0.0023, 20.12,
  1654. 0.0017, 21.24, 0.0113, 22.26, 0.0126, 23.30, 0.0093, 24.36, 0.0007,
  1655. 25.43, 0.0007, 26.47, 0.0009, 27.55, 0.0013, 28.59, 0.0025, 29.61,
  1656. 0.0010, 30.77, 0.0021, 31.86, 0.0023, 32.96, 0.0003, 34.03, 0.0007,
  1657. 35.06, 0.0005, 36.20, 0.0006, 37.34, 0.0006, 38.36, 0.0009, 39.60,
  1658. 0.0016, 40.69, 0.0005, 41.77, 0.0002, 42.92, 0.0002, 44.02, 0.0003,
  1659. 45.24, 0.0006, 46.33, 0.0004, 47.50, 0.0007, 48.71, 0.0007, 49.87,
  1660. 0.0002, 51.27, 0.0002, 53.42, 0.0003, 55.88, 0.0003, 57.10, 0.0004,
  1661. 58.34, 0.0002, 59.86, 0.0003, 61.13, 0.0003, 67.18, 0.0001, 68.50,
  1662. 0.0001, 71.17, 0.0001, 83.91, 0.0001, 90.55, 0.0001],
  1663. [0.98, 0.0099, 2.00, 0.0181, 2.99, 0.0353, 3.98, 0.0285, 4.97, 0.0514,
  1664. 5.96, 0.0402, 6.96, 0.0015, 7.98, 0.0012, 8.98, 0.0175, 9.98, 0.0264,
  1665. 10.98, 0.0392, 11.98, 0.0236, 13.00, 0.0153, 14.04, 0.0049, 15.00,
  1666. 0.0089, 16.01, 0.0001, 17.03, 0.0106, 18.03, 0.0028, 19.05, 0.0024,
  1667. 20.08, 0.0040, 21.11, 0.0103, 22.12, 0.0104, 23.20, 0.0017, 24.19,
  1668. 0.0008, 25.20, 0.0007, 26.24, 0.0011, 27.36, 0.0009, 27.97, 0.0030,
  1669. 29.40, 0.0044, 30.37, 0.0019, 31.59, 0.0017, 32.65, 0.0008, 33.59,
  1670. 0.0005, 34.79, 0.0009, 35.75, 0.0027, 36.88, 0.0035, 37.93, 0.0039,
  1671. 39.00, 0.0031, 40.08, 0.0025, 41.16, 0.0010, 43.25, 0.0004, 44.52,
  1672. 0.0012, 45.62, 0.0023, 45.85, 0.0012, 47.00, 0.0006, 47.87, 0.0008,
  1673. 48.99, 0.0003, 50.48, 0.0003, 51.62, 0.0001, 52.43, 0.0001, 53.56,
  1674. 0.0002, 54.76, 0.0002, 56.04, 0.0002, 56.68, 0.0006, 57.10, 0.0003,
  1675. 58.28, 0.0005, 59.47, 0.0003, 59.96, 0.0002, 60.67, 0.0001, 63.08,
  1676. 0.0002, 64.29, 0.0002, 66.72, 0.0001, 67.97, 0.0001, 68.65, 0.0001,
  1677. 70.43, 0.0001, 79.38, 0.0001, 80.39, 0.0001, 82.39, 0.0001],
  1678. [1.00, 0.0765, 1.99, 0.0151, 2.99, 0.0500, 3.99, 0.0197, 5.00, 0.0260,
  1679. 6.00, 0.0145, 6.98, 0.0128, 7.97, 0.0004, 8.98, 0.0158, 9.99, 0.0265,
  1680. 11.02, 0.0290, 12.02, 0.0053, 13.03, 0.0242, 14.03, 0.0103, 15.06,
  1681. 0.0054, 16.04, 0.0006, 17.08, 0.0008, 18.10, 0.0058, 19.16, 0.0011,
  1682. 20.16, 0.0055, 21.18, 0.0040, 22.20, 0.0019, 23.22, 0.0014, 24.05,
  1683. 0.0005, 25.31, 0.0019, 26.38, 0.0018, 27.44, 0.0022, 28.45, 0.0024,
  1684. 29.57, 0.0073, 30.58, 0.0032, 31.66, 0.0071, 32.73, 0.0015, 33.85,
  1685. 0.0005, 34.96, 0.0003, 36.00, 0.0020, 37.11, 0.0018, 38.18, 0.0055,
  1686. 39.23, 0.0006, 40.33, 0.0004, 41.52, 0.0003, 43.41, 0.0028, 45.05,
  1687. 0.0003, 45.99, 0.0002, 47.07, 0.0003, 48.52, 0.0002, 49.48, 0.0003,
  1688. 50.63, 0.0003, 51.81, 0.0002, 54.05, 0.0002, 55.24, 0.0001, 56.62,
  1689. 0.0001, 57.81, 0.0004, 59.16, 0.0013, 60.23, 0.0003, 66.44, 0.0001,
  1690. 68.99, 0.0004, 75.49, 0.0001, 87.56, 0.0004],
  1691. [0.98, 0.0629, 1.99, 0.0232, 2.98, 0.0217, 4.00, 0.0396, 4.98, 0.0171,
  1692. 5.97, 0.0098, 6.99, 0.0167, 7.99, 0.0003, 8.98, 0.0192, 9.98, 0.0266,
  1693. 10.99, 0.0256, 12.01, 0.0061, 13.02, 0.0135, 14.02, 0.0062, 15.05,
  1694. 0.0158, 16.06, 0.0018, 17.08, 0.0101, 18.09, 0.0053, 19.11, 0.0074,
  1695. 20.13, 0.0020, 21.17, 0.0052, 22.22, 0.0077, 23.24, 0.0035, 24.00,
  1696. 0.0009, 25.32, 0.0016, 26.40, 0.0022, 27.43, 0.0005, 28.55, 0.0026,
  1697. 29.60, 0.0026, 30.65, 0.0010, 31.67, 0.0019, 32.77, 0.0008, 33.81,
  1698. 0.0003, 34.91, 0.0003, 36.01, 0.0005, 37.11, 0.0010, 38.20, 0.0014,
  1699. 39.29, 0.0039, 40.43, 0.0012, 41.50, 0.0006, 43.38, 0.0017, 43.75,
  1700. 0.0002, 44.94, 0.0005, 46.13, 0.0002, 47.11, 0.0003, 48.28, 0.0005,
  1701. 48.42, 0.0005, 49.44, 0.0003, 50.76, 0.0004, 51.93, 0.0002, 54.15,
  1702. 0.0003, 55.31, 0.0005, 55.50, 0.0003, 56.98, 0.0003, 57.90, 0.0004,
  1703. 60.33, 0.0002, 61.39, 0.0001, 61.59, 0.0001, 65.09, 0.0002, 66.34,
  1704. 0.0001, 68.85, 0.0001, 70.42, 0.0002, 71.72, 0.0001, 73.05, 0.0003,
  1705. 79.65, 0.0001, 85.28, 0.0002, 93.52, 0.0001],
  1706. [1.02, 0.0185, 1.99, 0.0525, 2.98, 0.0613, 3.99, 0.0415, 4.98, 0.0109,
  1707. 5.97, 0.0248, 6.99, 0.0102, 7.98, 0.0005, 8.98, 0.0124, 9.99, 0.0103,
  1708. 10.99, 0.0124, 12.00, 0.0016, 13.01, 0.0029, 14.03, 0.0211, 15.04,
  1709. 0.0128, 16.07, 0.0021, 17.09, 0.0009, 18.09, 0.0043, 19.14, 0.0022,
  1710. 20.13, 0.0016, 21.20, 0.0045, 22.21, 0.0088, 23.26, 0.0046, 24.29,
  1711. 0.0013, 25.35, 0.0009, 26.39, 0.0028, 27.49, 0.0009, 28.51, 0.0006,
  1712. 29.58, 0.0012, 30.70, 0.0010, 31.74, 0.0019, 32.75, 0.0002, 33.85,
  1713. 0.0001, 34.95, 0.0005, 36.02, 0.0003, 37.16, 0.0009, 38.25, 0.0018,
  1714. 39.35, 0.0008, 40.54, 0.0004, 41.61, 0.0002, 43.40, 0.0004, 43.74,
  1715. 0.0003, 45.05, 0.0001, 46.11, 0.0003, 47.40, 0.0002, 48.36, 0.0004,
  1716. 49.55, 0.0004, 50.72, 0.0002, 52.00, 0.0001, 55.58, 0.0002, 57.02,
  1717. 0.0001, 57.98, 0.0002, 59.13, 0.0003, 61.56, 0.0001, 66.56, 0.0001,
  1718. 87.65, 0.0002],
  1719. [1.00, 0.0473, 1.99, 0.0506, 2.99, 0.0982, 3.99, 0.0654, 5.00, 0.0196,
  1720. 5.99, 0.0094, 6.99, 0.0118, 7.93, 0.0001, 8.99, 0.0057, 10.01, 0.0285,
  1721. 11.01, 0.0142, 12.03, 0.0032, 13.03, 0.0056, 14.06, 0.0064, 15.06,
  1722. 0.0059, 16.11, 0.0005, 17.09, 0.0033, 18.14, 0.0027, 19.15, 0.0014,
  1723. 20.17, 0.0010, 21.21, 0.0059, 22.26, 0.0043, 23.31, 0.0031, 24.31,
  1724. 0.0018, 25.33, 0.0009, 26.41, 0.0005, 27.47, 0.0015, 28.53, 0.0015,
  1725. 29.58, 0.0041, 30.65, 0.0025, 31.73, 0.0011, 32.83, 0.0010, 34.98,
  1726. 0.0003, 36.07, 0.0009, 37.23, 0.0001, 38.26, 0.0020, 39.41, 0.0014,
  1727. 40.53, 0.0005, 41.40, 0.0003, 42.80, 0.0002, 43.48, 0.0028, 43.93,
  1728. 0.0001, 45.03, 0.0003, 46.18, 0.0007, 47.41, 0.0001, 48.57, 0.0002,
  1729. 49.67, 0.0001, 50.83, 0.0002, 54.39, 0.0001, 55.58, 0.0002, 57.97,
  1730. 0.0005, 58.11, 0.0002, 59.21, 0.0001, 60.42, 0.0002, 61.66, 0.0001],
  1731. [1.00, 0.0503, 2.00, 0.0963, 2.99, 0.1304, 3.99, 0.0218, 4.98, 0.0041,
  1732. 5.98, 0.0292, 6.98, 0.0482, 7.99, 0.0005, 8.99, 0.0280, 10.00, 0.0237,
  1733. 11.00, 0.0152, 12.02, 0.0036, 12.95, 0.0022, 14.06, 0.0111, 15.07,
  1734. 0.0196, 16.08, 0.0016, 17.11, 0.0044, 18.13, 0.0073, 19.17, 0.0055,
  1735. 20.19, 0.0028, 21.20, 0.0012, 22.27, 0.0068, 23.30, 0.0036, 24.35,
  1736. 0.0012, 25.35, 0.0002, 26.46, 0.0005, 27.47, 0.0005, 28.59, 0.0009,
  1737. 29.65, 0.0021, 30.70, 0.0020, 31.78, 0.0012, 32.89, 0.0010, 35.06,
  1738. 0.0005, 36.16, 0.0008, 37.27, 0.0010, 38.36, 0.0010, 39.47, 0.0014,
  1739. 40.58, 0.0004, 41.43, 0.0007, 41.82, 0.0003, 43.48, 0.0008, 44.53,
  1740. 0.0001, 45.25, 0.0003, 46.43, 0.0002, 47.46, 0.0002, 48.76, 0.0005,
  1741. 49.95, 0.0004, 50.96, 0.0002, 51.12, 0.0002, 52.33, 0.0001, 54.75,
  1742. 0.0001, 55.75, 0.0002, 56.90, 0.0002, 58.17, 0.0002, 59.40, 0.0004,
  1743. 60.62, 0.0002, 65.65, 0.0001, 66.91, 0.0002, 69.91, 0.0001, 71.25,
  1744. 0.0002],
  1745. [1.00, 0.1243, 1.98, 0.1611, 3.00, 0.0698, 3.98, 0.0390, 5.00, 0.0138,
  1746. 5.99, 0.0154, 7.01, 0.0287, 8.01, 0.0014, 9.01, 0.0049, 10.00, 0.0144,
  1747. 11.01, 0.0055, 12.05, 0.0052, 13.01, 0.0011, 14.05, 0.0118, 15.07,
  1748. 0.0154, 16.12, 0.0028, 17.14, 0.0061, 18.25, 0.0007, 19.22, 0.0020,
  1749. 20.24, 0.0011, 21.27, 0.0029, 22.30, 0.0046, 23.34, 0.0049, 24.35,
  1750. 0.0004, 25.45, 0.0003, 26.47, 0.0007, 27.59, 0.0008, 28.16, 0.0009,
  1751. 29.12, 0.0002, 29.81, 0.0006, 30.81, 0.0009, 31.95, 0.0004, 33.00,
  1752. 0.0011, 34.12, 0.0005, 35.18, 0.0003, 36.30, 0.0008, 37.38, 0.0003,
  1753. 38.55, 0.0003, 39.64, 0.0006, 40.77, 0.0007, 41.52, 0.0006, 41.89,
  1754. 0.0006, 43.04, 0.0011, 43.60, 0.0009, 44.31, 0.0002, 45.68, 0.0002,
  1755. 46.56, 0.0003, 47.60, 0.0001, 48.83, 0.0006, 50.01, 0.0003, 51.27,
  1756. 0.0003, 56.04, 0.0005, 57.21, 0.0003, 58.56, 0.0004, 59.83, 0.0003,
  1757. 61.05, 0.0001, 62.20, 0.0001, 67.37, 0.0002, 76.53, 0.0001],
  1758. [0.99, 0.0222, 1.99, 0.0678, 2.99, 0.0683, 4.00, 0.0191, 5.00, 0.0119,
  1759. 6.01, 0.0232, 6.98, 0.0336, 7.99, 0.0082, 9.01, 0.0201, 10.01, 0.0189,
  1760. 11.01, 0.0041, 12.01, 0.0053, 13.05, 0.0154, 14.04, 0.0159, 15.06,
  1761. 0.0092, 16.11, 0.0038, 17.12, 0.0014, 18.15, 0.0091, 19.16, 0.0006,
  1762. 20.30, 0.0012, 21.25, 0.0061, 22.28, 0.0099, 23.34, 0.0028, 24.38,
  1763. 0.0012, 25.43, 0.0016, 26.49, 0.0048, 27.55, 0.0025, 28.62, 0.0015,
  1764. 29.71, 0.0032, 30.78, 0.0077, 31.88, 0.0011, 32.97, 0.0007, 34.08,
  1765. 0.0006, 35.16, 0.0008, 36.28, 0.0004, 37.41, 0.0006, 38.54, 0.0005,
  1766. 39.62, 0.0002, 40.80, 0.0003, 41.93, 0.0001, 43.06, 0.0002, 44.21,
  1767. 0.0003, 45.38, 0.0002, 46.54, 0.0007, 47.78, 0.0003, 48.95, 0.0004,
  1768. 50.10, 0.0003, 51.37, 0.0002, 53.79, 0.0003, 56.20, 0.0001, 58.71,
  1769. 0.0002, 66.47, 0.0003],
  1770. [1.01, 0.0241, 1.99, 0.1011, 2.98, 0.0938, 3.98, 0.0081, 4.99, 0.0062,
  1771. 5.99, 0.0291, 6.99, 0.0676, 7.59, 0.0004, 8.98, 0.0127, 9.99, 0.0112,
  1772. 10.99, 0.0142, 12.00, 0.0029, 13.02, 0.0071, 14.02, 0.0184, 15.03,
  1773. 0.0064, 16.07, 0.0010, 17.09, 0.0011, 18.11, 0.0010, 19.15, 0.0060,
  1774. 20.19, 0.0019, 21.24, 0.0025, 22.29, 0.0013, 23.31, 0.0050, 25.41,
  1775. 0.0030, 26.50, 0.0018, 27.53, 0.0006, 28.63, 0.0012, 29.66, 0.0013,
  1776. 30.77, 0.0020, 31.84, 0.0006, 34.04, 0.0001, 35.14, 0.0001, 36.32,
  1777. 0.0004, 37.41, 0.0007, 38.53, 0.0007, 39.67, 0.0009, 40.85, 0.0003,
  1778. 45.49, 0.0002, 46.65, 0.0001, 47.81, 0.0004, 49.01, 0.0002, 53.91,
  1779. 0.0002, 55.14, 0.0002, 57.69, 0.0002],
  1780. [1.00, 0.0326, 2.00, 0.1066, 2.99, 0.1015, 4.00, 0.0210, 4.97, 0.0170,
  1781. 5.99, 0.0813, 6.98, 0.0820, 7.96, 0.0011, 8.99, 0.0248, 10.03, 0.0107,
  1782. 11.01, 0.0126, 12.01, 0.0027, 13.01, 0.0233, 14.04, 0.0151, 15.05,
  1783. 0.0071, 16.04, 0.0002, 17.10, 0.0061, 18.12, 0.0059, 19.15, 0.0087,
  1784. 20.23, 0.0005, 21.25, 0.0040, 22.30, 0.0032, 23.35, 0.0004, 24.40,
  1785. 0.0001, 25.45, 0.0030, 26.54, 0.0022, 27.60, 0.0003, 28.70, 0.0009,
  1786. 29.80, 0.0029, 30.85, 0.0006, 31.97, 0.0006, 34.19, 0.0004, 35.30,
  1787. 0.0003, 36.43, 0.0007, 37.56, 0.0005, 38.68, 0.0019, 39.88, 0.0013,
  1788. 41.00, 0.0003, 43.35, 0.0003, 44.51, 0.0002, 45.68, 0.0006, 46.93,
  1789. 0.0010, 48.11, 0.0006, 49.29, 0.0003, 55.58, 0.0002],
  1790. [0.98, 0.0113, 1.99, 0.0967, 3.00, 0.0719, 3.98, 0.0345, 4.98, 0.0121,
  1791. 6.00, 0.0621, 7.00, 0.0137, 7.98, 0.0006, 9.01, 0.0314, 10.01, 0.0171,
  1792. 11.02, 0.0060, 12.03, 0.0024, 13.05, 0.0077, 14.07, 0.0040, 15.12,
  1793. 0.0032, 16.13, 0.0004, 17.15, 0.0011, 18.20, 0.0028, 19.18, 0.0003,
  1794. 20.26, 0.0003, 21.31, 0.0025, 22.35, 0.0021, 23.39, 0.0005, 25.55,
  1795. 0.0002, 26.62, 0.0014, 27.70, 0.0003, 28.78, 0.0005, 29.90, 0.0030,
  1796. 31.01, 0.0011, 32.12, 0.0005, 34.31, 0.0001, 35.50, 0.0002, 36.62,
  1797. 0.0002, 37.76, 0.0005, 38.85, 0.0002, 40.09, 0.0004, 43.60, 0.0001,
  1798. 44.73, 0.0002, 46.02, 0.0002, 47.25, 0.0004, 48.44, 0.0004],
  1799. [0.99, 0.0156, 1.98, 0.0846, 2.98, 0.0178, 3.98, 0.0367, 4.98, 0.0448,
  1800. 5.98, 0.0113, 6.99, 0.0189, 8.00, 0.0011, 9.01, 0.0247, 10.02, 0.0089,
  1801. 11.01, 0.0184, 12.03, 0.0105, 13.00, 0.0039, 14.07, 0.0116, 15.09,
  1802. 0.0078, 16.13, 0.0008, 17.14, 0.0064, 18.19, 0.0029, 19.22, 0.0028,
  1803. 20.25, 0.0017, 21.32, 0.0043, 22.37, 0.0055, 23.42, 0.0034, 24.48,
  1804. 0.0004, 25.54, 0.0002, 26.61, 0.0017, 27.70, 0.0011, 28.80, 0.0002,
  1805. 29.89, 0.0019, 30.97, 0.0028, 32.09, 0.0007, 34.30, 0.0002, 35.44,
  1806. 0.0003, 36.55, 0.0001, 37.69, 0.0004, 38.93, 0.0002, 40.05, 0.0005,
  1807. 41.20, 0.0005, 42.37, 0.0002, 43.54, 0.0003, 44.73, 0.0001, 45.95,
  1808. 0.0002, 47.16, 0.0001, 48.43, 0.0005, 49.65, 0.0004, 55.90, 0.0002,
  1809. 59.81, 0.0004],
  1810. [1.01, 0.0280, 2.00, 0.0708, 2.99, 0.0182, 3.99, 0.0248, 4.98, 0.0245,
  1811. 5.98, 0.0279, 6.98, 0.0437, 7.99, 0.0065, 8.99, 0.0299, 10.00, 0.0073,
  1812. 10.99, 0.0011, 12.03, 0.0122, 13.03, 0.0028, 14.08, 0.0044, 15.11,
  1813. 0.0097, 16.15, 0.0010, 17.17, 0.0025, 18.19, 0.0017, 19.24, 0.0008,
  1814. 20.28, 0.0040, 21.32, 0.0024, 22.38, 0.0008, 23.46, 0.0032, 24.52,
  1815. 0.0010, 25.59, 0.0008, 26.68, 0.0009, 27.76, 0.0012, 28.88, 0.0003,
  1816. 29.95, 0.0005, 31.05, 0.0017, 32.14, 0.0002, 33.29, 0.0003, 37.88,
  1817. 0.0002, 39.03, 0.0002, 40.19, 0.0004, 41.37, 0.0003, 43.74, 0.0002,
  1818. 46.20, 0.0001, 48.68, 0.0001, 49.93, 0.0001, 51.19, 0.0002],
  1819. [1.00, 0.0225, 1.99, 0.0921, 2.98, 0.0933, 3.99, 0.0365, 4.99, 0.0100,
  1820. 5.98, 0.0213, 6.98, 0.0049, 7.98, 0.0041, 8.98, 0.0090, 9.99, 0.0068,
  1821. 11.01, 0.0040, 12.03, 0.0086, 13.02, 0.0015, 14.04, 0.0071, 15.09,
  1822. 0.0082, 16.14, 0.0011, 17.15, 0.0014, 18.18, 0.0010, 19.26, 0.0013,
  1823. 20.26, 0.0005, 21.33, 0.0006, 22.36, 0.0011, 23.46, 0.0016, 24.52,
  1824. 0.0004, 25.59, 0.0002, 26.70, 0.0006, 27.78, 0.0007, 28.87, 0.0002,
  1825. 30.03, 0.0008, 31.14, 0.0010, 32.24, 0.0006, 33.37, 0.0002, 35.67,
  1826. 0.0003, 37.99, 0.0004, 39.17, 0.0004, 40.35, 0.0005, 41.53, 0.0001,
  1827. 46.42, 0.0001],
  1828. [1.00, 0.0465, 1.99, 0.0976, 2.98, 0.0678, 4.00, 0.0727, 4.99, 0.0305,
  1829. 5.98, 0.0210, 6.98, 0.0227, 8.00, 0.0085, 9.01, 0.0183, 10.02, 0.0258,
  1830. 11.05, 0.0003, 12.06, 0.0061, 13.05, 0.0021, 14.10, 0.0089, 15.12,
  1831. 0.0077, 16.16, 0.0016, 17.21, 0.0061, 18.23, 0.0011, 19.29, 0.0031,
  1832. 20.36, 0.0031, 21.41, 0.0007, 22.48, 0.0013, 23.55, 0.0020, 24.64,
  1833. 0.0004, 25.74, 0.0005, 26.81, 0.0006, 27.95, 0.0006, 29.03, 0.0001,
  1834. 30.22, 0.0010, 31.30, 0.0004, 32.48, 0.0001, 33.60, 0.0002, 38.30,
  1835. 0.0003],
  1836. [1.00, 0.0674, 1.99, 0.0841, 2.98, 0.0920, 3.99, 0.0328, 4.99, 0.0368,
  1837. 5.98, 0.0206, 6.99, 0.0246, 8.01, 0.0048, 9.01, 0.0218, 10.03, 0.0155,
  1838. 11.05, 0.0048, 12.06, 0.0077, 13.00, 0.0020, 14.10, 0.0083, 15.15,
  1839. 0.0084, 16.18, 0.0015, 17.22, 0.0039, 18.27, 0.0032, 19.34, 0.0026,
  1840. 20.40, 0.0012, 21.47, 0.0009, 22.54, 0.0008, 23.62, 0.0016, 24.71,
  1841. 0.0005, 25.82, 0.0004, 26.91, 0.0002, 28.03, 0.0008, 29.17, 0.0002,
  1842. 30.32, 0.0028, 31.45, 0.0004, 32.61, 0.0005, 33.77, 0.0001, 36.14,
  1843. 0.0003, 37.32, 0.0002, 38.54, 0.0005, 39.75, 0.0002, 42.23, 0.0002,
  1844. 48.65, 0.0001],
  1845. [1.01, 0.0423, 1.99, 0.0240, 2.98, 0.0517, 4.00, 0.0493, 5.00, 0.0324,
  1846. 6.00, 0.0094, 6.99, 0.0449, 7.99, 0.0050, 9.00, 0.0197, 10.03, 0.0132,
  1847. 11.03, 0.0009, 12.07, 0.0017, 13.08, 0.0023, 14.12, 0.0094, 15.16,
  1848. 0.0071, 16.21, 0.0020, 17.25, 0.0005, 18.30, 0.0027, 19.04, 0.0004,
  1849. 20.43, 0.0022, 21.51, 0.0002, 22.59, 0.0006, 23.72, 0.0018, 24.80,
  1850. 0.0002, 25.88, 0.0002, 27.03, 0.0002, 28.09, 0.0006, 29.31, 0.0002,
  1851. 30.46, 0.0004, 31.61, 0.0007, 32.78, 0.0005, 33.95, 0.0001, 36.34,
  1852. 0.0002, 37.56, 0.0001, 38.80, 0.0001, 40.02, 0.0001, 44.14, 0.0001],
  1853. [1.00, 0.0669, 1.99, 0.0909, 2.99, 0.0410, 3.98, 0.0292, 4.98, 0.0259,
  1854. 5.98, 0.0148, 6.98, 0.0319, 7.99, 0.0076, 9.01, 0.0056, 10.02, 0.0206,
  1855. 11.04, 0.0032, 12.05, 0.0085, 13.08, 0.0040, 14.12, 0.0037, 15.16,
  1856. 0.0030, 16.20, 0.0013, 17.24, 0.0021, 18.30, 0.0010, 19.36, 0.0015,
  1857. 20.44, 0.0013, 21.50, 0.0009, 22.60, 0.0015, 23.69, 0.0014, 24.80,
  1858. 0.0006, 25.87, 0.0002, 27.02, 0.0006, 28.12, 0.0002, 29.28, 0.0003,
  1859. 30.43, 0.0002, 31.59, 0.0007, 32.79, 0.0001, 35.14, 0.0001, 37.57,
  1860. 0.0001, 40.03, 0.0002, 41.28, 0.0004, 44.10, 0.0001],
  1861. [0.99, 0.0421, 1.99, 0.1541, 2.98, 0.0596, 3.98, 0.0309, 4.98, 0.0301,
  1862. 5.99, 0.0103, 7.00, 0.0240, 8.01, 0.0073, 9.01, 0.0222, 10.04, 0.0140,
  1863. 11.05, 0.0033, 12.08, 0.0045, 13.13, 0.0009, 14.13, 0.0015, 15.21,
  1864. 0.0026, 16.24, 0.0003, 17.30, 0.0004, 18.35, 0.0010, 19.39, 0.0003,
  1865. 20.50, 0.0015, 21.57, 0.0003, 22.68, 0.0011, 23.80, 0.0005, 24.90,
  1866. 0.0008, 26.02, 0.0002, 27.16, 0.0001, 28.30, 0.0006, 29.48, 0.0002,
  1867. 31.81, 0.0005, 33.00, 0.0003, 34.21, 0.0001, 37.89, 0.0001],
  1868. [0.99, 0.0389, 2.00, 0.2095, 3.00, 0.0835, 3.99, 0.0289, 5.00, 0.0578,
  1869. 5.99, 0.0363, 7.01, 0.0387, 8.01, 0.0056, 9.04, 0.0173, 10.05, 0.0175,
  1870. 11.08, 0.0053, 12.10, 0.0056, 13.15, 0.0064, 14.19, 0.0036, 15.22,
  1871. 0.0019, 16.29, 0.0010, 17.36, 0.0017, 18.43, 0.0018, 19.51, 0.0004,
  1872. 20.60, 0.0011, 21.70, 0.0003, 22.82, 0.0003, 23.95, 0.0001, 25.05,
  1873. 0.0004, 26.17, 0.0001, 28.50, 0.0003, 29.68, 0.0001, 32.07, 0.0003,
  1874. 33.28, 0.0004, 34.52, 0.0001],
  1875. [1.00, 0.1238, 1.99, 0.2270, 3.00, 0.0102, 3.99, 0.0181, 4.98, 0.0415,
  1876. 6.00, 0.0165, 7.01, 0.0314, 8.02, 0.0148, 9.04, 0.0203, 10.05, 0.0088,
  1877. 11.07, 0.0062, 12.11, 0.0070, 13.14, 0.0054, 14.19, 0.0028, 15.24,
  1878. 0.0044, 16.30, 0.0029, 17.38, 0.0009, 18.45, 0.0026, 19.56, 0.0003,
  1879. 20.65, 0.0025, 21.74, 0.0014, 22.87, 0.0013, 23.99, 0.0007, 25.15,
  1880. 0.0002, 27.46, 0.0004, 28.39, 0.0006, 28.65, 0.0004, 29.85, 0.0001,
  1881. 31.05, 0.0002, 32.27, 0.0003, 33.52, 0.0002, 34.76, 0.0003],
  1882. [1.00, 0.1054, 2.00, 0.2598, 2.99, 0.0369, 3.98, 0.0523, 4.99, 0.0020,
  1883. 5.99, 0.0051, 7.00, 0.0268, 8.01, 0.0027, 9.04, 0.0029, 10.05, 0.0081,
  1884. 11.08, 0.0047, 12.12, 0.0051, 13.16, 0.0091, 14.19, 0.0015, 15.27,
  1885. 0.0030, 16.34, 0.0017, 17.42, 0.0006, 18.51, 0.0003, 19.61, 0.0007,
  1886. 20.72, 0.0003, 21.84, 0.0001, 22.99, 0.0010, 24.13, 0.0001, 28.44,
  1887. 0.0001, 30.09, 0.0001],
  1888. [0.99, 0.0919, 2.00, 0.0418, 2.99, 0.0498, 3.99, 0.0135, 4.99, 0.0026,
  1889. 6.00, 0.0155, 7.01, 0.0340, 8.02, 0.0033, 9.04, 0.0218, 10.08, 0.0084,
  1890. 11.11, 0.0057, 12.15, 0.0051, 13.21, 0.0043, 14.25, 0.0015, 15.31,
  1891. 0.0023, 16.40, 0.0008, 17.48, 0.0004, 18.59, 0.0016, 19.71, 0.0010,
  1892. 20.84, 0.0018, 21.98, 0.0002, 23.11, 0.0013, 24.26, 0.0003, 26.67,
  1893. 0.0002, 29.12, 0.0002, 30.37, 0.0002, 31.62, 0.0003, 32.92, 0.0001],
  1894. [0.99, 0.1174, 1.99, 0.1126, 2.99, 0.0370, 3.99, 0.0159, 5.01, 0.0472,
  1895. 6.01, 0.0091, 7.03, 0.0211, 8.05, 0.0015, 9.07, 0.0098, 10.11, 0.0038,
  1896. 11.15, 0.0042, 12.20, 0.0018, 13.24, 0.0041, 14.32, 0.0033, 15.41,
  1897. 0.0052, 16.49, 0.0001, 17.61, 0.0004, 18.71, 0.0004, 19.84, 0.0004,
  1898. 20.99, 0.0002, 22.14, 0.0006, 23.31, 0.0006, 24.50, 0.0004, 25.70,
  1899. 0.0002, 28.09, 0.0002, 28.66, 0.0002, 32.00, 0.0001],
  1900. [1.00, 0.1085, 2.00, 0.1400, 2.99, 0.0173, 3.99, 0.0229, 5.00, 0.0272,
  1901. 6.02, 0.0077, 7.03, 0.0069, 8.04, 0.0017, 9.08, 0.0045, 10.10, 0.0030,
  1902. 11.15, 0.0040, 12.20, 0.0007, 13.25, 0.0019, 14.32, 0.0008, 15.42,
  1903. 0.0024, 16.50, 0.0002, 17.59, 0.0005, 18.71, 0.0003, 19.83, 0.0002,
  1904. 20.98, 0.0005, 23.29, 0.0008],
  1905. [1.00, 0.0985, 2.00, 0.1440, 2.99, 0.0364, 3.99, 0.0425, 5.00, 0.0190,
  1906. 6.01, 0.0089, 7.03, 0.0278, 8.04, 0.0006, 9.07, 0.0083, 10.10, 0.0021,
  1907. 11.14, 0.0050, 12.18, 0.0005, 13.26, 0.0036, 14.33, 0.0005, 15.41,
  1908. 0.0026, 17.62, 0.0004, 18.75, 0.0004, 19.89, 0.0003, 21.04, 0.0012,
  1909. 22.21, 0.0002, 23.38, 0.0004, 27.04, 0.0001],
  1910. [0.99, 0.1273, 2.00, 0.1311, 2.99, 0.0120, 4.00, 0.0099, 5.00, 0.0235,
  1911. 6.02, 0.0068, 7.03, 0.0162, 8.06, 0.0009, 9.08, 0.0083, 10.12, 0.0014,
  1912. 11.17, 0.0050, 12.24, 0.0010, 13.29, 0.0013, 14.39, 0.0022, 15.48,
  1913. 0.0011, 16.59, 0.0002, 17.70, 0.0003, 18.84, 0.0010, 20.00, 0.0003,
  1914. 21.17, 0.0003, 23.56, 0.0004, 28.79, 0.0003],
  1915. [1.00, 0.1018, 2.00, 0.1486, 3.00, 0.0165, 4.00, 0.0186, 5.01, 0.0194,
  1916. 6.02, 0.0045, 7.04, 0.0083, 8.06, 0.0012, 9.10, 0.0066, 10.15, 0.0009,
  1917. 11.19, 0.0008, 12.26, 0.0011, 13.34, 0.0028, 14.45, 0.0006, 15.53,
  1918. 0.0009, 16.66, 0.0002, 17.79, 0.0006, 18.94, 0.0005, 20.11, 0.0003,
  1919. 21.29, 0.0005, 22.49, 0.0003, 23.73, 0.0005, 26.22, 0.0001, 27.52,
  1920. 0.0001, 28.88, 0.0002],
  1921. [1.00, 0.1889, 1.99, 0.1822, 3.00, 0.0363, 4.00, 0.0047, 5.01, 0.0202,
  1922. 6.03, 0.0053, 7.05, 0.0114, 8.01, 0.0002, 9.13, 0.0048, 10.17, 0.0010,
  1923. 11.23, 0.0033, 12.30, 0.0010, 13.38, 0.0006, 14.50, 0.0002, 15.62,
  1924. 0.0010, 20.27, 0.0001, 21.47, 0.0001],
  1925. [1.00, 0.0522, 1.99, 0.0763, 2.99, 0.0404, 4.00, 0.0139, 5.01, 0.0185,
  1926. 6.01, 0.0021, 7.06, 0.0045, 8.09, 0.0002, 9.11, 0.0003, 10.17, 0.0006,
  1927. 11.25, 0.0004, 12.32, 0.0005, 13.40, 0.0003, 14.53, 0.0003, 15.65,
  1928. 0.0007, 16.80, 0.0001, 17.95, 0.0002, 19.14, 0.0006, 20.34, 0.0002,
  1929. 21.56, 0.0003],
  1930. [0.99, 0.1821, 1.99, 0.0773, 3.00, 0.0125, 4.01, 0.0065, 5.01, 0.0202,
  1931. 6.03, 0.0071, 7.05, 0.0090, 8.08, 0.0006, 9.13, 0.0008, 10.18, 0.0013,
  1932. 11.25, 0.0010, 12.33, 0.0012, 13.42, 0.0006, 14.54, 0.0005, 15.65,
  1933. 0.0004, 17.97, 0.0002, 19.15, 0.0001],
  1934. [1.00, 0.1868, 2.00, 0.0951, 3.00, 0.0147, 4.01, 0.0134, 5.02, 0.0184,
  1935. 6.04, 0.0132, 7.06, 0.0011, 8.11, 0.0008, 9.15, 0.0010, 10.22, 0.0012,
  1936. 11.30, 0.0011, 12.40, 0.0003, 13.11, 0.0004, 13.49, 0.0002, 14.62,
  1937. 0.0003, 15.77, 0.0001],
  1938. [1.00, 0.1933, 2.00, 0.0714, 3.00, 0.0373, 4.00, 0.0108, 5.02, 0.0094,
  1939. 6.02, 0.0010, 7.07, 0.0022, 8.11, 0.0002, 9.16, 0.0065, 10.23, 0.0015,
  1940. 11.31, 0.0023, 12.40, 0.0003, 13.53, 0.0014, 14.66, 0.0002, 15.81,
  1941. 0.0011, 18.20, 0.0002, 19.41, 0.0001],
  1942. [0.99, 0.2113, 1.99, 0.0877, 3.00, 0.0492, 4.01, 0.0094, 5.02, 0.0144,
  1943. 6.04, 0.0103, 7.07, 0.0117, 8.12, 0.0006, 9.19, 0.0019, 10.25, 0.0007,
  1944. 11.35, 0.0017, 12.45, 0.0010, 13.58, 0.0003, 14.74, 0.0003, 15.91,
  1945. 0.0003, 19.57, 0.0002],
  1946. [0.99, 0.2455, 1.99, 0.0161, 3.00, 0.0215, 4.01, 0.0036, 5.03, 0.0049,
  1947. 6.04, 0.0012, 7.09, 0.0036, 8.14, 0.0011, 9.21, 0.0009, 10.30, 0.0001,
  1948. 11.40, 0.0012, 12.50, 0.0001, 13.66, 0.0005, 14.84, 0.0001],
  1949. [1.00, 0.1132, 2.00, 0.0252, 3.00, 0.0292, 4.01, 0.0136, 5.03, 0.0045,
  1950. 6.06, 0.0022, 7.11, 0.0101, 8.17, 0.0004, 9.23, 0.0010, 10.33, 0.0012,
  1951. 11.44, 0.0013, 12.58, 0.0011, 13.75, 0.0002, 14.93, 0.0005, 16.14, 0.0002],
  1952. [1.00, 0.1655, 2.00, 0.0445, 3.00, 0.0120, 4.00, 0.0038, 5.02, 0.0015,
  1953. 6.07, 0.0038, 7.11, 0.0003, 8.19, 0.0002, 9.25, 0.0010, 10.36, 0.0011,
  1954. 11.48, 0.0005, 12.63, 0.0002, 13.79, 0.0003, 16.24, 0.0002],
  1955. [0.99, 0.3637, 1.99, 0.0259, 3.01, 0.0038, 4.01, 0.0057, 5.03, 0.0040,
  1956. 6.07, 0.0067, 7.12, 0.0014, 8.19, 0.0004, 9.27, 0.0003, 10.38, 0.0002,
  1957. 12.67, 0.0001],
  1958. [1.00, 0.1193, 2.00, 0.0230, 3.00, 0.0104, 4.01, 0.0084, 5.04, 0.0047,
  1959. 6.08, 0.0035, 7.13, 0.0041, 8.20, 0.0002, 9.29, 0.0005, 10.40, 0.0005,
  1960. 11.53, 0.0003, 12.70, 0.0002, 13.91, 0.0002],
  1961. [1.00, 0.0752, 2.00, 0.0497, 3.00, 0.0074, 4.02, 0.0076, 5.05, 0.0053,
  1962. 6.09, 0.0043, 7.15, 0.0024, 8.22, 0.0001, 9.32, 0.0006, 10.45, 0.0002,
  1963. 11.58, 0.0001, 12.78, 0.0001, 15.22, 0.0001],
  1964. [1.00, 0.2388, 2.00, 0.0629, 3.01, 0.0159, 4.04, 0.0063, 5.07, 0.0051,
  1965. 6.12, 0.0045, 7.19, 0.0026, 8.29, 0.0015, 9.43, 0.0001, 11.75, 0.0002],
  1966. [1.00, 0.1919, 2.01, 0.0116, 3.01, 0.0031, 4.03, 0.0090, 5.07, 0.0061,
  1967. 6.13, 0.0036, 7.19, 0.0013, 8.30, 0.0016, 9.13, 0.0001, 10.59, 0.0002,
  1968. 11.78, 0.0002],
  1969. [1.00, 0.1296, 2.00, 0.0135, 3.01, 0.0041, 4.04, 0.0045, 5.09, 0.0028,
  1970. 6.14, 0.0046, 7.23, 0.0007, 8.32, 0.0007, 9.50, 0.0001],
  1971. [1.00, 0.0692, 2.00, 0.0209, 3.02, 0.0025, 4.05, 0.0030, 5.09, 0.0047,
  1972. 6.17, 0.0022, 7.25, 0.0015, 8.36, 0.0015, 9.53, 0.0010, 10.69, 0.0001,
  1973. 13.40, 0.0001],
  1974. [1.00, 0.1715, 2.00, 0.0142, 3.01, 0.0024, 4.03, 0.0015, 5.07, 0.0017,
  1975. 6.13, 0.0018, 7.22, 0.0009, 8.33, 0.0014, 9.51, 0.0007, 10.69, 0.0002],
  1976. [1.00, 0.1555, 2.01, 0.0148, 3.02, 0.0007, 4.06, 0.0006, 5.10, 0.0005,
  1977. 6.16, 0.0008, 7.26, 0.0009, 8.39, 0.0008, 9.58, 0.0002],
  1978. [1.00, 0.1357, 2.00, 0.0116, 3.02, 0.0026, 4.04, 0.0009, 5.09, 0.0004,
  1979. 6.17, 0.0005, 7.27, 0.0002, 8.40, 0.0001],
  1980. [1.00, 0.2185, 2.01, 0.0087, 3.03, 0.0018, 4.06, 0.0025, 5.11, 0.0020,
  1981. 6.20, 0.0012, 7.32, 0.0005, 8.46, 0.0001, 9.66, 0.0003],
  1982. [1.00, 0.2735, 2.00, 0.0038, 3.02, 0.0008, 4.06, 0.0012, 5.12, 0.0008,
  1983. 6.22, 0.0011, 7.35, 0.0003, 8.50, 0.0002],
  1984. [1.00, 0.1441, 1.99, 0.0062, 3.01, 0.0023, 4.05, 0.0011, 5.11, 0.0012,
  1985. 6.20, 0.0003, 7.33, 0.0004, 8.50, 0.0001],
  1986. [1.00, 0.0726, 2.01, 0.0293, 3.03, 0.0022, 5.14, 0.0005, 6.26, 0.0011,
  1987. 7.41, 0.0002, 8.63, 0.0002],
  1988. [1.00, 0.0516, 2.00, 0.0104, 3.02, 0.0029, 5.15, 0.0002, 6.27, 0.0001],
  1989. [1.00, 0.0329, 2.00, 0.0033, 3.03, 0.0013, 4.10, 0.0005, 5.19,
  1990. 0.0004, 6.32, 0.0002],
  1991. [1.00, 0.0179, 1.99, 0.0012, 3.04, 0.0005, 4.10, 0.0017, 5.20, 0.0005,
  1992. 6.35, 0.0001],
  1993. [1.00, 0.0334, 2.01, 0.0033, 3.04, 0.0011, 4.13, 0.0003, 5.22, 0.0003],
  1994. [0.99, 0.0161, 2.01, 0.0100, 3.04, 0.0020, 4.13, 0.0003],
  1995. [1.00, 0.0475, 1.99, 0.0045, 3.03, 0.0035, 4.12, 0.0011],
  1996. [1.00, 0.0593, 2.00, 0.0014, 4.17, 0.0002],
  1997. [1.00, 0.0249, 2.01, 0.0016],
  1998. [1.00, 0.0242, 2.00, 0.0038, 4.19, 0.0002],
  1999. [1.00, 0.0170, 2.02, 0.0030],
  2000. [1.00, 0.0381, 2.00, 0.0017, 3.09, 0.0002],
  2001. [1.00, 0.0141, 2.03, 0.0005, 3.11, 0.0003, 4.26, 0.0001],
  2002. [1.00, 0.0122, 2.03, 0.0024],
  2003. [1.00, 0.0107, 2.07, 0.0007, 3.12, 0.0004],
  2004. [1.00, 0.0250, 2.02, 0.0026, 3.15, 0.0002],
  2005. [1.01, 0.0092],
  2006. [1.01, 0.0102, 2.09, 0.0005],
  2007. [1.00, 0.0080, 2.00, 0.0005, 3.19, 0.0001],
  2008. [1.01, 0.0298, 2.01, 0.0005]]
  2009. def lbj_piano(start, dur, freq, amp, *args)
  2010. pfreq, degree, distance, reverb_amount = nil
  2011. optkey(args, binding,
  2012. [:pfreq, freq],
  2013. [:degree, 45.0],
  2014. [:distance, 1.0],
  2015. [:reverb_amount, 0.0])
  2016. get_piano_partials = lambda do |frq|
  2017. Piano_Spectra[(12 * (log(frq / 32.703) / log(2))).round]
  2018. end
  2019. make_piano_ampfun = lambda do |dr|
  2020. release_amp = db2linear($clm_db_drop_per_second * dr)
  2021. attack_time = $clm_piano_attack_duration * 100.0 / dr
  2022. [0, 0, attack_time / 4, 1.0, attack_time, 1.0, 100, release_amp]
  2023. end
  2024. # This thing sounds pretty good down low, below middle c or so.
  2025. # Unfortunately, there are some tens of partials down there and
  2026. # we're using exponential envelopes. You're going to wait for a
  2027. # long long time just to hear a single low note. The high notes
  2028. # sound pretty rotten--they just don't sparkle; I have a feeling
  2029. # that this is due to the low amplitude of the original data, and
  2030. # the lack of mechanical noise.
  2031. #
  2032. # The only thing you can do to alter the sound of a piano note is to
  2033. # set the pfreq parameter. Pfreq is used to look up the partials.
  2034. # By default, it's set to the requested frequency. Setting it to a
  2035. # neighboring freq is useful when you're repeating notes. Note that
  2036. # there's no nyquist detection; a high freq with a low pfreq, will
  2037. # give you fold over (hmmm...maybe I can get those high notes to
  2038. # sparkle after all).
  2039. partials = normalize_partials(get_piano_partials.call(pfreq))
  2040. newdur = dur + $clm_piano_attack_duration + $clm_piano_release_duration
  2041. env1dur = newdur - $clm_piano_release_duration
  2042. env1samples = (env1dur * @srate).floor
  2043. siz = (partials.length / 2).floor
  2044. oscils = Array.new(siz)
  2045. alist = make_vct(siz)
  2046. ampfun1 = make_piano_ampfun.call(env1dur)
  2047. ampenv1 = make_env(:envelope, ampfun1, :scaler, amp,
  2048. :duration, env1dur, :base, 10000.0)
  2049. releaseamp = ampfun1.last
  2050. ampenv2 = make_env(:envelope, [0, 1, 100, 0], :scaler, amp * releaseamp,
  2051. :duration, env1dur, :base, 1.0)
  2052. sktr = j = 0
  2053. 0.step(partials.length - 1, 2) do |i|
  2054. alist[j] = partials[i + 1]
  2055. oscils[j] = make_oscil(:frequency, partials[i] * freq)
  2056. j += 1
  2057. end
  2058. run_instrument(start, newdur,
  2059. :degree, degree,
  2060. :distance, distance,
  2061. :reverb_amount, reverb_amount) do
  2062. sktr += 1
  2063. let(0.0) do |sum|
  2064. oscils.each_with_index do |osc, i|
  2065. sum = sum + oscil(osc) * alist[i]
  2066. end
  2067. sum * env(((sktr > env1samples) ? ampenv2 : ampenv1))
  2068. end
  2069. end
  2070. end
  2071. def lbj_piano_test(start = 0.0, dur = 1.0)
  2072. lbj_piano(start, dur, 440.0, 0.5)
  2073. $now = start + dur + 0.24 + 0.2
  2074. end
  2075. # RESFLT
  2076. def resflt(start, dur, driver,
  2077. ranfreq, noiamp, noifun, cosamp, cosfreq1, cosfreq0, cosnum,
  2078. ampcosfun, freqcosfun,
  2079. frq1, r1, g1, frq2, r2, g2, frq3, r3, g3, *args)
  2080. degree, distance, reverb_amount = nil
  2081. optkey(args, binding,
  2082. [:degree, 0.0],
  2083. [:distance, 1.0],
  2084. [:reverb_amount, 0.005])
  2085. # driver=0 -- use sum of cosines to drive the filter,
  2086. # driver=1 -- use white noise
  2087. # if noise used, ranfreq=frequency of random number generator,
  2088. # noiamp=amplitude thereof,
  2089. # noifun=amplitude envelope on white noise
  2090. # if sum-of-cosines (i.e. a band-limited pulse train),
  2091. # cosamp=amplitude of pulse train,
  2092. # cosfreq1=top frequency (given freqcosfun)
  2093. # (i.e. pulse frequency)
  2094. # cosfreq0=bottom frequency,
  2095. # cosnum=number of cosines in the pulse,
  2096. # ampcosfun=amplitude envelope on pulse train
  2097. # freqcosfun=frequency envelope on pulse train
  2098. # There are then 3 resonators, centered at frq1, frq2, frq3,
  2099. # with pole-radius r1, r2, and r3 respectively, and
  2100. # with gains of g1, g2, and g3.
  2101. f1 = make_two_pole(frq1, r1)
  2102. f2 = make_two_pole(frq2, r2)
  2103. f3 = make_two_pole(frq3, r3)
  2104. with_noise = (driver == 1)
  2105. frqf = if with_noise
  2106. nil
  2107. else
  2108. make_env(:envelope, freqcosfun, :duration, dur,
  2109. :scaler, hz2radians(cosfreq1 - cosfreq0))
  2110. end
  2111. ampf = if with_noise
  2112. make_env(:envelope, noifun, :scaler, noiamp, :duration, dur)
  2113. else
  2114. make_env(:envelope, ampcosfun, :scaler, cosamp, :duration, dur)
  2115. end
  2116. rn = if with_noise
  2117. make_rand(:frequency, ranfreq)
  2118. else
  2119. nil
  2120. end
  2121. cn = if with_noise
  2122. nil
  2123. else
  2124. make_sum_of_cosines(:frequency, cosfreq0, :cosines, cosnum)
  2125. end
  2126. if with_noise
  2127. run_instrument(start, dur,
  2128. :distance, distance,
  2129. :degree, degree,
  2130. :reverb_amount, reverb_amount) do
  2131. input1 = env(ampf) * rand(rn)
  2132. two_pole(f1, input1 * g1) +
  2133. two_pole(f2, input1 * g2) +
  2134. two_pole(f3, input1 * g3)
  2135. end
  2136. else
  2137. run_instrument(start, dur,
  2138. :distance, distance,
  2139. :degree, degree,
  2140. :reverb_amount, reverb_amount) do
  2141. input1 = env(ampf) * sum_of_cosines(cn, env(frqf))
  2142. two_pole(f1, input1 * g1) +
  2143. two_pole(f2, input1 * g2) +
  2144. two_pole(f3, input1 * g3)
  2145. end
  2146. end
  2147. end
  2148. def resflt_test(start = 0.0, dur = 1.0)
  2149. $now = start
  2150. resflt($now, dur, 0, 0, 0, nil,
  2151. 0.1, 200, 230, 10, [0, 0, 50, 1, 100, 0], [0, 0, 100, 1],
  2152. 500, 0.995, 0.1, 1000, 0.995, 0.1, 2000, 0.995, 0.1)
  2153. $now += dur + 0.2
  2154. resflt($now, dur, 1, 10000, 0.01, [0, 0, 50, 1, 100, 0],
  2155. 0, 0, 0, 0, nil, nil,
  2156. 500, 0.995, 0.1, 1000, 0.995, 0.1, 2000, 0.995, 0.1)
  2157. $now += dur + 0.2
  2158. end
  2159. # SCRATCH
  2160. def scratch(start, file, src_ratio, turntable)
  2161. assert_type(File.exist?(file), file, 1, "an existing file")
  2162. f = make_file2sample(file)
  2163. turn_i = 1
  2164. turns = turntable.length
  2165. cur_sample = seconds2samples(turntable[0])
  2166. turn_sample = seconds2samples(turntable[turn_i])
  2167. rd = make_src(:srate, src_ratio)
  2168. forwards = (src_ratio > 0.0)
  2169. set_mus_increment(rd, -src_ratio) if forwards and turn_sample < cur_sample
  2170. turning = 0
  2171. last_val = last_val2 = 0.0
  2172. run_instrument(start, ws_duration(file)) do
  2173. break if turn_i >= turns
  2174. val = src(rd, 0.0, lambda do |dir|
  2175. inval = file2sample(f, cur_sample)
  2176. cur_sample += dir
  2177. inval
  2178. end)
  2179. if turning.zero?
  2180. # we past turn point going forwards
  2181. if forwards and cur_sample >= turn_sample
  2182. turning = 1
  2183. # we past turn point going backwards
  2184. elsif (not forwards) and cur_sample <= turn_sample
  2185. turning = -1
  2186. end
  2187. else
  2188. # wait for an inflection...
  2189. if (last_val2 <= last_val and last_val >= val) or
  2190. (last_val2 >= last_val and last_val <= val)
  2191. turn_i += 1
  2192. if turn_i < turns
  2193. turn_sample = seconds2samples(turntable[turn_i])
  2194. forwards = (not forwards)
  2195. set_mus_increment(rd, -mus_increment(rd))
  2196. end
  2197. turning = 0
  2198. end
  2199. end
  2200. last_val2, last_val = last_val, val
  2201. val
  2202. end
  2203. mus_close(f)
  2204. end
  2205. def scratch_test(start = 0.0, dur = 1.0)
  2206. scratch(start, "fyow.snd", [dur, 1.5].min, [0.0, 0.5, 0.25, 1.0])
  2207. $now = start + mus_sound_duration("fyow.snd") + 0.2
  2208. end
  2209. # PINS
  2210. #
  2211. # spectral modeling (SMS)
  2212. def pins(start, dur, file, amp, *args)
  2213. assert_type(File.exist?(file), file, 2, "an existing file")
  2214. transposition, time_scaler, fftsize, highest_bin, max_peaks, attack = nil
  2215. optkey(args, binding,
  2216. [:transposition, 1.0], # this can be used to transpose the sound
  2217. [:time_scaler, 1.0], # this can make things happen faster
  2218. # (< 1.0)/slower (> 1.0) in the output
  2219. [:fftsize, 256], # should be a power of 2
  2220. # at 22050 srate, this is ok for
  2221. # sounds above 300Hz or so, below that
  2222. # you need 512 or 1024, at 44100,
  2223. # probably best to double these sizes
  2224. # -- it takes some searching
  2225. # sometimes.
  2226. [:highest_bin, 128], # how high in fft data should we search for pks
  2227. [:max_peaks, 16], # how many spectral peaks to track at the max
  2228. :attack) # whether to use original attack via time domain
  2229. # splice do the sliding fft shuffle,
  2230. # translate to polar coordinates, find
  2231. # spectral peaks, match with current,
  2232. # do some interesting transformation,
  2233. # resynthesize using oscils All the
  2234. # envelopes are created on the fly.
  2235. # max-peaks is how many of these peaks
  2236. # we are willing to track at any given
  2237. # time.
  2238. fil = make_file2sample(file)
  2239. file_duration = ws_duration(file)
  2240. fdr = make_vct(fftsize)
  2241. fdi = make_vct(fftsize)
  2242. window = make_fft_window(Blackman2_window, fftsize)
  2243. fftamps = make_vct(fftsize)
  2244. max_oscils = 2 * max_peaks
  2245. current_peak_freqs = make_vct(max_oscils)
  2246. last_peak_freqs = make_vct(max_oscils)
  2247. current_peak_amps = make_vct(max_oscils)
  2248. last_peak_amps = make_vct(max_oscils)
  2249. peak_amps = make_vct(max_peaks)
  2250. peak_freqs = make_vct(max_peaks)
  2251. resynth_oscils = make_array(max_oscils) do
  2252. make_oscil(:frequency, 0)
  2253. end
  2254. # run-time generated amplitude and frequency envelopes
  2255. amps = make_vct(max_oscils)
  2256. rates = make_vct(max_oscils)
  2257. freqs = make_vct(max_oscils)
  2258. sweeps = make_vct(max_oscils)
  2259. lowest_magnitude = 0.001
  2260. hop = (fftsize / 4).floor
  2261. outhop = (time_scaler * hop).floor
  2262. ifreq = 1.0 / outhop
  2263. ihifreq = hz2radians(ifreq)
  2264. # integrate Blackman-Harris window = .42323*window
  2265. fftscale = 1.0 / (fftsize * 0.42323)
  2266. # width and shift by fftsize
  2267. fft_mag = @srate / fftsize
  2268. furthest_away_accepted = 0.1
  2269. filptr = 0
  2270. cur_oscils = max_oscils
  2271. ramped = (attack or 0)
  2272. splice_attack = attack.kind_of?(Numeric)
  2273. attack_size = (attack or 1)
  2274. ramp_ind = 0
  2275. ramped_attack = make_vct(attack_size)
  2276. if (dur / time_scaler) > file_duration
  2277. error("%s is %1.3f seconds long, \
  2278. but we'll need %1.3f seconds of data for this note",
  2279. file, file_duration, dur / time_scaler)
  2280. end
  2281. trigger = outhop
  2282. vct_scale!(window, fftscale)
  2283. run_instrument(start, dur) do
  2284. if splice_attack
  2285. ramp = 1.0 / attack_size
  2286. # my experience in translating SMS, and rumor via Greg Sandell
  2287. # leads me to believe that there is in fact no way to model some
  2288. # attacks successfully in this manner, so this block simply
  2289. # splices the original attack on to the rest of the note.
  2290. # "attack" is the number of samples to include bodily.
  2291. out_val = amp * file2sample(fil, filptr)
  2292. filptr += 1
  2293. if filptr > attack_size
  2294. mult = 1.0
  2295. attack_size.times do |j|
  2296. ramped_attack[j] = mult * file2sample(fil, filptr + j)
  2297. mult -= ramp
  2298. end
  2299. splice_attack = false
  2300. end
  2301. # if out_val
  2302. out_val
  2303. else
  2304. if trigger >= outhop
  2305. peaks = 0
  2306. # get next block of data and apply window to it
  2307. trigger = 0
  2308. fftsize.times do |j|
  2309. fdr[j] = window[j] * file2sample(fil, filptr)
  2310. filptr += 1
  2311. end
  2312. vct_fill!(fdi, 0.0)
  2313. filptr -= fftsize - hop
  2314. # get the fft
  2315. mus_fft(fdr, fdi, fftsize, 1)
  2316. # change to polar coordinates (ignoring phases)
  2317. highest_bin.times do |j|
  2318. # no need to paw through the upper half
  2319. # (so (<= highest-bin (floor fft-size 2)))
  2320. x = fdr[j]
  2321. y = fdi[j]
  2322. fftamps[j] = 2.0 * sqrt(x * x + y * y)
  2323. end
  2324. max_oscils.times do |j|
  2325. last_peak_freqs[j] = current_peak_freqs[j]
  2326. last_peak_amps[j] = current_peak_amps[j]
  2327. current_peak_amps[j] = 0.0
  2328. end
  2329. vct_fill!(peak_amps, 0.0)
  2330. ra = fftamps[0]
  2331. la = ca = 0.0
  2332. # search for current peaks following Xavier Serra's recommendations in
  2333. # "A System for Sound Analysis/Transformation/Synthesis
  2334. # Based on a Deterministic Plus Stochastic Decomposition"
  2335. highest_bin.times do |j|
  2336. la, ca, ra = ca, ra, fftamps[j]
  2337. if ca > lowest_magnitude and ca > ra and ca > la
  2338. # found a local maximum above the current threshold
  2339. # (its bin number is j-1)
  2340. logla = log10(la)
  2341. logca = log10(ca)
  2342. logra = log10(ra)
  2343. offset = (0.5 * (logla - logra)) / (logla + -2 * logca + logra)
  2344. amp_1 = 10.0 ** (logca - (0.25 * (logla - logra) * offset))
  2345. freq = fft_mag * (j + offset - 1)
  2346. if peaks == max_peaks
  2347. # gotta either flush this peak,
  2348. # or find current lowest and flush him
  2349. minp = 0
  2350. minpeak = peak_amps[0]
  2351. 1.upto(max_peaks - 1) do |k|
  2352. if peak_amps[k] < minpeak
  2353. minp = k
  2354. minpeak = peak_amps[k]
  2355. end
  2356. end
  2357. if amp_1 > minpeak
  2358. peak_freqs[minp] = freq
  2359. peak_amps[minp] = amp_1
  2360. end
  2361. else
  2362. peak_freqs[peaks] = freq
  2363. peak_amps[peaks] = amp_1
  2364. peaks += 1
  2365. end
  2366. end
  2367. end
  2368. # now we have the current peaks -- match them to the previous
  2369. # set and do something interesting with the result the end
  2370. # results are reflected in the updated values in the rates and
  2371. # sweeps arrays. search for fits between last and current,
  2372. # set rates/sweeps for those found try to go by largest amp
  2373. # first
  2374. peaks.times do |j|
  2375. maxp = 0
  2376. maxpk = peak_amps[0]
  2377. 1.upto(max_peaks - 1) do |k|
  2378. if peak_amps[k] > maxpk
  2379. maxp = k
  2380. maxpk = peak_amps[k]
  2381. end
  2382. end
  2383. # now maxp points to next largest unmatched peak
  2384. if maxpk > 0.0
  2385. closestp = -1
  2386. closestamp = 10.0
  2387. current_freq = peak_freqs[maxp]
  2388. icf = 1.0 / current_freq
  2389. max_peaks.times do |k|
  2390. if last_peak_amps[k] > 0.0
  2391. closeness = icf * (last_peak_freqs[k] - current_freq).abs
  2392. if closeness < closestamp
  2393. closestamp = closeness
  2394. closestp = k
  2395. end
  2396. end
  2397. end
  2398. if closestamp < furthest_away_accepted
  2399. # peak_amp is transferred to appropriate current_amp and zeroed,
  2400. current_peak_amps[closestp] = peak_amps[maxp]
  2401. peak_amps[maxp] = 0.0
  2402. current_peak_freqs[closestp] = current_freq
  2403. end
  2404. end
  2405. end
  2406. max_peaks.times do |j|
  2407. if peak_amps[j] > 0.0
  2408. # find a place for a new oscil and start it up
  2409. new_place = -1
  2410. max_oscils.times do |k|
  2411. if last_peak_amps[k].zero? and current_peak_amps[k].zero?
  2412. new_place = k
  2413. break
  2414. end
  2415. end
  2416. current_peak_amps[new_place] = peak_amps[j]
  2417. peak_amps[j] = 0.0
  2418. current_peak_freqs[new_place] = peak_freqs[j]
  2419. last_peak_freqs[new_place] = peak_freqs[j]
  2420. set_mus_frequency(resynth_oscils[new_place],
  2421. transposition * peak_freqs[j])
  2422. end
  2423. end
  2424. cur_oscils = 0
  2425. max_oscils.times do |j|
  2426. rates[j] = ifreq * (current_peak_amps[j] - last_peak_amps[j])
  2427. if current_peak_amps[j].nonzero? or last_peak_amps[j].nonzero?
  2428. cur_oscils = j
  2429. end
  2430. sweeps[j] = ihifreq * transposition *
  2431. (current_peak_freqs[j] - last_peak_freqs[j])
  2432. end
  2433. cur_oscils += 1
  2434. end
  2435. # run oscils, update envelopes
  2436. trigger += 1
  2437. if ramped.zero?
  2438. sum = 0.0
  2439. else
  2440. sum = ramped_attack[ramp_ind]
  2441. ramp_ind += 1
  2442. ramped = 0 if ramp_ind == ramped
  2443. end
  2444. cur_oscils.times do |j|
  2445. if amps[j].nonzero? or rates[j].nonzero?
  2446. sum = sum + amps[j] * oscil(resynth_oscils[j], freqs[j])
  2447. amps[j] += rates[j]
  2448. freqs[j] += sweeps[j]
  2449. end
  2450. end
  2451. # else out_val
  2452. amp * sum
  2453. end
  2454. end
  2455. mus_close(fil)
  2456. end
  2457. def pins_test(start = 0.0, dur = 1.0)
  2458. pins(start, dur, "fyow.snd", 1, :time_scaler, 2)
  2459. $now = start + dur + 0.2
  2460. end
  2461. # ZC
  2462. def zc(start, dur, freq, amp, length1, length2, feedback)
  2463. s = make_pulse_train(:frequency, freq)
  2464. d0 = make_comb(:size, length1,
  2465. :max_size, [length1, length2].max + 1,
  2466. :scaler, feedback)
  2467. zenv = make_env(:envelope, [0, 0, 1, 1],
  2468. :scaler, length2 - length1,
  2469. :duration, dur)
  2470. run_instrument(start, dur) do
  2471. comb(d0, amp * pulse_train(s), env(zenv))
  2472. end
  2473. end
  2474. def zc_test(start = 0.0, dur = 1.0)
  2475. $now = start
  2476. zc($now, dur, 100, 0.4, 20, 100, 0.95)
  2477. $now += dur + 0.2
  2478. zc($now, dur, 100, 0.4, 100, 20, 0.95)
  2479. $now += dur + 0.2
  2480. end
  2481. # ZN
  2482. #
  2483. # notches are spaced at srate/len, feedforward sets depth thereof so
  2484. # sweep of len from 20 to 100 sweeps the notches down from 1000 Hz to
  2485. # ca 200 Hz so we hear our downward glissando beneath the pulses.
  2486. def zn(start, dur, freq, amp, length1, length2, feedforward)
  2487. s = make_pulse_train(:frequency, freq)
  2488. d0 = make_notch(:size, length1,
  2489. :max_size, [length1, length2].max + 1,
  2490. :scaler, feedforward)
  2491. zenv = make_env(:envelope, [0, 0, 1, 1],
  2492. :scaler, length2 - length1,
  2493. :duration, dur)
  2494. run_instrument(start, dur) do
  2495. notch(d0, amp * pulse_train(s), env(zenv))
  2496. end
  2497. end
  2498. def zn_test(start = 0.0, dur = 1.0)
  2499. $now = start
  2500. zn($now, dur, 100, 0.5, 20, 100, 0.95)
  2501. $now += dur + 0.2
  2502. zn($now, dur, 100, 0.5, 100, 20, 0.95)
  2503. $now += dur + 0.2
  2504. end
  2505. # ZA
  2506. def za(start, dur, freq, amp, length1, length2, feedback, feedforward)
  2507. s = make_pulse_train(:frequency, freq)
  2508. d0 = make_all_pass(:feedback, feedback,
  2509. :feedforward, feedforward,
  2510. :size, length1,
  2511. :max_size, [length1, length2].max + 1)
  2512. zenv = make_env(:envelope, [0, 0, 1, 1],
  2513. :scaler, length2 - length1,
  2514. :duration, dur)
  2515. run_instrument(start, dur) do
  2516. all_pass(d0, amp * pulse_train(s), env(zenv))
  2517. end
  2518. end
  2519. def za_test(start = 0.0, dur = 1.0)
  2520. $now = start
  2521. za($now, dur, 100, 0.3, 20, 100, 0.95, 0.95)
  2522. $now += dur + 0.2
  2523. za($now, dur, 100, 0.3, 100, 20, 0.95, 0.95)
  2524. $now += dur + 0.2
  2525. end
  2526. # CLM-EXPSRC
  2527. def clm_expsrc(start, dur, in_file, exp_ratio, src_ratio, amp,
  2528. rev = false, start_in_file = 0)
  2529. assert_type(File.exist?(in_file), in_file, 0, "an existing file")
  2530. stf = (start_in_file * srate(in_file)).floor
  2531. fda = make_readin(in_file, :channel, 0, :start, stf)
  2532. exa = make_granulate(lambda do |dir|
  2533. readin(fda)
  2534. end, :expansion, exp_ratio)
  2535. srca = make_src(lambda do |dir|
  2536. granulate(exa)
  2537. end, :srate, src_ratio)
  2538. two_chans = (channels(in_file) == 2) and (channels(@ws_output) == 2)
  2539. revit = @reverb and rev
  2540. beg = seconds2samples(start)
  2541. fin = seconds2samples(dur) + beg
  2542. # to satisfy with_sound-option :info and :notehook
  2543. with_sound_info(get_func_name, start, dur)
  2544. if two_chans
  2545. fdb = make_readin(in_file, :channel, 1, :srate, stf)
  2546. exb = make_granulate(lambda do |dir|
  2547. readin(fdb)
  2548. end, :expansion, exp_ratio)
  2549. srcb = make_src(lambda do |dir|
  2550. granulate(exb)
  2551. end, :srate, src_ratio)
  2552. if revit
  2553. rev_amp = rev * 0.5
  2554. (beg..fin).each do |i|
  2555. vala = src(srca) * amp
  2556. valb = src(srcb) * amp
  2557. outa(i, vala, @ws_output)
  2558. outb(i, valb, @ws_output)
  2559. outa(i, (vala + valb) * rev_amp, @reverb)
  2560. end
  2561. else # !revit
  2562. (beg..fin).each do |i|
  2563. outa(i, src(srca) * amp, @ws_output)
  2564. outb(i, src(srcb) * amp, @ws_output)
  2565. end
  2566. end # revit
  2567. else # !two_chans
  2568. if revit
  2569. rev_amp = rev
  2570. (beg..fin).each do |i|
  2571. vala = src(srca) * amp
  2572. outa(i, vala, @ws_output)
  2573. outa(i, vala * rev_amp, @ws_reverb)
  2574. end
  2575. else # !revit
  2576. (beg..fin).each do |i|
  2577. outa(i, src(srca) * amp, @ws_output)
  2578. end
  2579. end # revit
  2580. end # two_chans
  2581. end
  2582. def clm_expsrc_test(start = 0.0, dur = 1.0)
  2583. clm_expsrc(start, dur, "oboe.snd", 2.0, 1.0, 1.0, 0.05)
  2584. $now = start + dur + 0.2
  2585. end
  2586. # EXP-SND
  2587. #
  2588. # granulate with envelopes on the expansion amount, segment envelope
  2589. # shape, segment length, hop length, and input file resampling rate
  2590. def exp_snd(file, start, dur, amp,
  2591. exp_amt = 1.0, ramp = 0.4, seglen = 0.15,
  2592. sr = 1.0, hop = 0.05, ampenv = nil)
  2593. assert_type(File.exist?(file), file, 0, "an existing file")
  2594. f0 = make_ws_reader(file, :start, 0)
  2595. expenv = make_env(:envelope,
  2596. (exp_amt.kind_of?(Array) ?
  2597. exp_amt : [0, exp_amt, 1, exp_amt]),
  2598. :duration, dur)
  2599. lenenv = make_env(:envelope,
  2600. (seglen.kind_of?(Array) ?
  2601. seglen : [0, seglen, 1, seglen]),
  2602. :duration, dur)
  2603. max_seg_len, initial_seg_len = if seglen
  2604. if seglen.kind_of?(Array)
  2605. [max_envelope(seglen), seglen[1]]
  2606. else
  2607. [seglen, seglen]
  2608. end
  2609. else
  2610. [0.15, 0.15]
  2611. end
  2612. scaler_amp = ((max_seg_len > 0.15) ? ((0.6 * 0.15) / max_seg_len) : 0.6)
  2613. srenv = make_env(:envelope, (sr.kind_of?(Array) ? sr : [0, sr, 1, sr]),
  2614. :duration, dur)
  2615. rampdata = (ramp.kind_of?(Array) ? ramp : [0, ramp, 1, ramp])
  2616. rampenv = make_env(:envelope, rampdata, :duration, dur)
  2617. initial_ramp_time = if ramp
  2618. if ramp.kind_of?(Array)
  2619. ramp[1]
  2620. else
  2621. ramp
  2622. end
  2623. else
  2624. 0.4
  2625. end
  2626. hopenv = make_env(:envelope, (hop.kind_of?(Array) ? hop : [0, hop, 1, hop]),
  2627. :duration, dur)
  2628. max_out_hop, initial_out_hop = if hop
  2629. if hop.kind_of?(Array)
  2630. [max_envelope(hop), hop[1]]
  2631. else
  2632. [hop, hop]
  2633. end
  2634. else
  2635. [0.05, 0.05]
  2636. end
  2637. min_exp_amt, initial_exp_amt = if exp_amt
  2638. if exp_amt.kind_of?(Array)
  2639. [min_envelope(exp_amt), exp_amt[1]]
  2640. else
  2641. [exp_amt, exp_amt]
  2642. end
  2643. else
  2644. [1.0, 1.0]
  2645. end
  2646. max_in_hop = max_out_hop / min_exp_amt.to_f
  2647. max_len = (@srate * ([max_out_hop, max_in_hop].max + max_seg_len)).ceil
  2648. ampe = make_env(:envelope, (ampenv or [0, 0, 0.5, 1, 1, 0]),
  2649. :scaler, amp,
  2650. :duration, dur)
  2651. ex_a = make_granulate(:input, lambda do |dir| ws_readin(f0) end,
  2652. :expansion, initial_exp_amt,
  2653. :max_size, max_len,
  2654. :ramp, initial_ramp_time,
  2655. :hop, initial_out_hop,
  2656. :length, initial_seg_len,
  2657. :scaler, scaler_amp)
  2658. ex_samp = next_samp = 0.0
  2659. vol = env(ampe)
  2660. val_a0 = vol * granulate(ex_a)
  2661. val_a1 = vol * granulate(ex_a)
  2662. if min_envelope(rampdata) <= 0.0 or max_envelope(rampdata) >= 0.5
  2663. error("ramp argument to expand must always be between 0.0 and 0.5: %1.3f",
  2664. ramp)
  2665. else
  2666. run_instrument(start, dur) do
  2667. expa = env(expenv) # current expansion amount
  2668. segl = env(lenenv) # current segment length
  2669. resa = env(srenv) # current resampling increment
  2670. rmpl = env(rampenv) # current ramp length (0 to 0.5)
  2671. hp = env(hopenv) # current hop size
  2672. # now we set the granulate generator internal state to reflect all
  2673. # these envelopes
  2674. sl = (segl * @srate).floor
  2675. rl = (rmpl * sl).floor
  2676. vol = env(ampe)
  2677. set_mus_length(ex_a, sl)
  2678. set_mus_ramp(ex_a, rl)
  2679. set_mus_frequency(ex_a, hp)
  2680. set_mus_increment(ex_a, expa)
  2681. next_samp += resa
  2682. if next_samp > (ex_samp + 1)
  2683. (next_samp - ex_samp).floor.times do
  2684. val_a0, val_a1 = val_a1, vol * granulate(ex_a)
  2685. ex_samp += 1
  2686. end
  2687. end
  2688. if next_samp == ex_samp
  2689. val_a0
  2690. else
  2691. val_a0 + (next_samp - ex_samp) * (val_a1 - val_a0)
  2692. end
  2693. end
  2694. close_ws_reader(f0)
  2695. end
  2696. end
  2697. def exp_snd_test(start = 0.0, dur = 1.0)
  2698. $now = start
  2699. exp_snd("fyow.snd", $now, dur, 1, [0, 1, 1, 3], 0.4, 0.15,
  2700. [0, 2, 1, 0.5], 0.05)
  2701. $now += dur + 0.2
  2702. exp_snd("oboe.snd", $now, dur, 1, [0, 1, 1, 3], 0.4, 0.15,
  2703. [0, 2, 1, 0.5], 0.2)
  2704. $now += dur + 0.2
  2705. end
  2706. # EXPFIL
  2707. Grn = Struct.new("Grn",
  2708. :rampval, :rampinc,
  2709. :loc, :segctr, :whichseg, :ramplen, :steadylen, :trigger)
  2710. def expfil(start, dur, hopsecs, rampsecs, steadysecs, file1, file2)
  2711. assert_type(File.exist?(file1), file1, 5, "an existing file")
  2712. assert_type(File.exist?(file2), file2, 6, "an existing file")
  2713. fil1 = make_file2sample(file1)
  2714. fil2 = make_file2sample(file2)
  2715. hop = seconds2samples(hopsecs)
  2716. ramplen = seconds2samples(rampsecs)
  2717. steadylen = seconds2samples(steadysecs)
  2718. grn1 = Grn.new(0.0, 1.0 / ramplen, 0, 0, 0, ramplen, steadylen, 0)
  2719. grn2 = Grn.new(0.0, 1.0 / ramplen, 0, 0, 0, ramplen, steadylen, 0)
  2720. beg = seconds2samples(start)
  2721. out1 = beg
  2722. out2 = hop + beg
  2723. run_instrument(start, dur) do |i|
  2724. val = 0.0
  2725. if i == out1
  2726. inval = ina(grn1.loc, fil1)
  2727. grn1.loc += 1
  2728. if grn1.whichseg.zero? # ramp-up
  2729. inval *= grn1.rampval
  2730. grn1.rampval += grn1.rampinc
  2731. grn1.segctr += 1
  2732. if grn1.segctr == grn1.ramplen
  2733. grn1.segctr = 0
  2734. grn1.whichseg += 1
  2735. end
  2736. else
  2737. if grn1.whichseg == 1 # steady-state
  2738. grn1.segctr += 1
  2739. if grn1.segctr == grn1.steadylen
  2740. grn1.segctr = 0
  2741. grn1.whichseg += 1
  2742. end
  2743. else # ramp-down
  2744. inval *= grn1.rampval
  2745. grn1.segctr += 1
  2746. grn1.rampval -= grn1.rampinc
  2747. if grn1.segctr == grn1.ramplen
  2748. grn1.segctr = 0
  2749. grn1.trigger = 1
  2750. grn1.whichseg = 0
  2751. grn1.rampval = 0.0
  2752. end
  2753. end
  2754. end
  2755. val += inval
  2756. out1 += 1
  2757. if grn1.trigger == 1
  2758. grn1.trigger = 0
  2759. out1 += hop
  2760. end
  2761. end
  2762. if i == out2
  2763. inval = ina(grn2.loc, fil2)
  2764. grn2.loc += 1
  2765. if grn2.whichseg.zero? # ramp-up
  2766. inval *= grn2.rampval
  2767. grn2.rampval += grn2.rampinc
  2768. grn2.segctr += 1
  2769. if grn2.segctr == grn2.ramplen
  2770. grn2.segctr = 0
  2771. grn2.whichseg += 1
  2772. end
  2773. else
  2774. if grn2.whichseg == 1 # steady-state
  2775. grn2.segctr += 1
  2776. if grn2.segctr == grn2.steadylen
  2777. grn2.segctr = 0
  2778. grn2.whichseg += 1
  2779. end
  2780. else # ramp-down
  2781. inval *= grn2.rampval
  2782. grn2.segctr += 1
  2783. grn2.rampval -= grn2.rampinc
  2784. if grn2.segctr == grn2.ramplen
  2785. grn2.segctr = 0
  2786. grn2.trigger = 1
  2787. grn2.whichseg = 0
  2788. grn2.rampval = 0.0
  2789. end
  2790. end
  2791. end
  2792. val += inval
  2793. out2 += 1
  2794. if grn2.trigger == 1
  2795. grn2.trigger = 0
  2796. out2 += hop
  2797. end
  2798. end
  2799. val
  2800. end
  2801. end
  2802. def expfil_test(start = 0.0, dur = 1.0)
  2803. expfil(start, dur, 0.2, 0.01, 0.1, "oboe.snd", "fyow.snd")
  2804. $now = start + dur + 0.2
  2805. end
  2806. # GRAPH-EQ
  2807. #
  2808. =begin
  2809. From: Marco Trevisani <marco@ccrma.Stanford.EDU>
  2810. This should work like a Graphic Equalizer....
  2811. Very easy to use. Just some note:
  2812. "amp" & "amp-env" apply an enveloppe to the final result of the
  2813. filtering.
  2814. "dur" as ""standard"" in my instruments, when dur = 0 it will take the length
  2815. of the sndfile input, otherwise the duration in seconds.
  2816. "gain-freq-list" is a list of gains and frequencies to
  2817. filter --in this order gain and frequencies--. There is no limit to
  2818. the size of the list. Gain can be a number or an
  2819. envelope. Unfortunatelly in this version they cant alternate, one
  2820. should chose, all envelopes or all numbers i.e.:
  2821. case 1 -> '( .1 440.0 .3 1500.0 .2 330.0 ...etc) or
  2822. case 2 -> '((0 .1 1 .5) 440.0 (0 1 1 .01) 1500 (0 .3 1 .5) 330.0 ...etc)
  2823. '( .1 440.0 (0 1 1 .01) 1500 ..etc) <<< again, this is not allowed ..
  2824. "offset-gain" This apply to all the gains if case 1. It adds or
  2825. subtracts an offset to all the gains in the list. This number can be positive
  2826. or negative. In case the result is a negative number --let's say offset =
  2827. -.4 and, like in case 1, the first gain is .1, the result would be
  2828. -.3 -- the instrument will pass a gain equal to 0.
  2829. "filt-gain-scale" & "filt-gain-base" will apply to the elements of the
  2830. envelopes if we are in case 2, gains are envelopes.
  2831. "stats" if #t --default-- prints the number of seconds processed, if
  2832. nil doesnt print anything, which will speed up a bit the process.
  2833. =end
  2834. #
  2835. def graph_eq(file, start, dur, *args)
  2836. assert_type(File.exist?(file), file, 0, "an existing file")
  2837. or_beg, amplitude, amp_env, amp_base, offset_gain = nil
  2838. gain_freq_list, filt_gain_scale, filt_gain_base, a1 = nil
  2839. optkey(args, binding,
  2840. [:or_beg, 0],
  2841. [:amplitude, 1],
  2842. [:amp_env, [0, 1, 0.8, 1, 1, 0]],
  2843. [:amp_base, 1],
  2844. [:offset_gain, 0],
  2845. [:gain_freq_list, [[0, 1, 1, 0], 440, [0, 0, 1, 1], 660]],
  2846. [:filt_gain_scale, 1],
  2847. [:filt_gain_base, 1],
  2848. [:a1, 0.99])
  2849. durata = (dur.zero? ? ws_duration(file) : dur)
  2850. len = seconds2samples(durata)
  2851. or_start = (or_beg * ws_srate(file)).round
  2852. rd_a = make_ws_reader(file, :start, or_start)
  2853. half_list = gain_freq_list.length / 2
  2854. ampenv = make_env(:envelope, amp_env,
  2855. :scaler, amplitude,
  2856. :duration, durata,
  2857. :base, amp_base)
  2858. gain_list = []
  2859. 0.step(gain_freq_list.length - 1, 2) do |i|
  2860. gain_list << gain_freq_list[i]
  2861. end
  2862. freq_list = []
  2863. 1.step(gain_freq_list.length - 1, 2) do |i|
  2864. freq_list << gain_freq_list[i]
  2865. end
  2866. if_list_in_gain = gain_list[0].kind_of?(Array)
  2867. env_size = (if_list_in_gain ? Array.new(freq_list.length) : nil)
  2868. frm_size = Array.new(freq_list.length)
  2869. gains = Vct.new(len, 1.0)
  2870. half_list.times do |i|
  2871. gval = gain_list[i]
  2872. fval = freq_list[i]
  2873. if gval.kind_of?(Array)
  2874. env_size[i] = make_env(:envelope, gval,
  2875. :scaler, filt_gain_scale,
  2876. :duration, durata,
  2877. :base, filt_gain_base)
  2878. frm_size[i] = make_formant(fval, a1)
  2879. else
  2880. gains[i] = (offset_gain + gval < 0) ? 0 : (offset_gain + gain)
  2881. frm_size[i] = make_formant(fval, a1)
  2882. end
  2883. end
  2884. run_instrument(start, durata) do
  2885. outval = 0.0
  2886. inval = ws_readin(rd_a)
  2887. half_list.times do |j|
  2888. if if_list_in_gain
  2889. gains[j] = env(env_size[j]) * (1.0 - a1)
  2890. end
  2891. outval = outval + gains[j] * formant(frm_size[j], inval)
  2892. end
  2893. env(ampenv) * outval
  2894. end
  2895. close_ws_reader(rd_a)
  2896. end
  2897. def graph_eq_test(start = 0.0, dur = 1.0)
  2898. graph_eq("oboe.snd", start, dur, :amplitude, 50.0)
  2899. $now = start + dur + 0.2
  2900. end
  2901. # ANOI
  2902. #
  2903. # a kind of noise reduction -- on-going average spectrum is squelched
  2904. # to some extent obviously aimed at intermittent signal in background
  2905. # noise
  2906. # this is based on Perry Cook's Scrubber.m
  2907. def anoi(infile, start, dur, fftsize = 128, amp_scaler = 1.0, r = TWO_PI)
  2908. assert_type(File.exist?(infile), infile, 0, "an existing file")
  2909. freq_inc = (fftsize / 2).floor
  2910. fdi = make_vct(fftsize)
  2911. fdr = make_vct(fftsize)
  2912. spectr = make_vct(freq_inc, 1.0)
  2913. scales = make_vct(freq_inc, 1.0)
  2914. diffs = make_vct(freq_inc)
  2915. win = make_fft_window(Blackman2_window, fftsize)
  2916. k = 0
  2917. amp = 0.0
  2918. incr = amp_scaler * 4.0 / @srate
  2919. file = make_file2sample(infile)
  2920. radius = 1.0 - r / fftsize.to_f
  2921. bin = @srate / fftsize
  2922. fs = make_array(freq_inc) do |i|
  2923. make_formant(i * bin, radius)
  2924. end
  2925. samp = 0
  2926. run_instrument(start, dur) do
  2927. inval = file2sample(file, samp)
  2928. samp += 1
  2929. fdr[k] = inval
  2930. k += 1
  2931. amp += incr if amp < amp_scaler
  2932. if k >= fftsize
  2933. k = 0
  2934. spectrum(fdr, fdi, win, 1)
  2935. freq_inc.times do |j|
  2936. spectr[j] = 0.9 * spectr[j] + 0.1 * fdr[j]
  2937. if spectr[j] >= fdr[j]
  2938. diffs[j] = scales[j] / -fftsize
  2939. else
  2940. diffs[j] = ((fdr[j] - spectr[j]) / fdr[j] - scales[j]) / fftsize
  2941. end
  2942. end
  2943. end
  2944. outval = 0.0
  2945. 1.upto(freq_inc - 1) do |j|
  2946. cur_scale = scales[j]
  2947. outval = outval + cur_scale * formant(fs[j], inval)
  2948. scales[j] += diffs[j]
  2949. end
  2950. amp * outval
  2951. end
  2952. end
  2953. def anoi_test(start = 0.0, dur = 1.0)
  2954. anoi("fyow.snd", start, dur, 128, 2.0)
  2955. $now = start + dur + 0.2
  2956. end
  2957. =begin
  2958. Date: Fri, 25 Sep 1998 09:56:41 +0300
  2959. From: Matti Koskinen <mjkoskin@sci.fi>
  2960. To: linux-audio-dev@ginette.musique.umontreal.ca
  2961. Subject: [linux-audio-dev] Announce: alpha version of denoising
  2962. [...]
  2963. I wrote a simple denoiser called anoi after it's parent
  2964. clm-instrument anoi.ins.
  2965. anoi tries to remove white noise like tape hiss from wav-
  2966. files. Removing of noise succeeds ok, but depending of the
  2967. original sound, some distortion can be audible.
  2968. If someone is interested, http://www.sci.fi/~mjkoskin
  2969. contains tarred and gzipped file.
  2970. Now only monophonic wav-files can be denoised, but adding
  2971. others isn't too difficult.
  2972. -matti
  2973. mjkoskin@sci.fi
  2974. =end
  2975. # FULLMIX
  2976. #
  2977. # ;; "matrix" can be a simple amplitude or a list of lists each inner
  2978. # ;; list represents one input channel's amps into one output channel
  2979. # ;; each element of the list can be a number, a list (turned into an
  2980. # ;; env) or an env
  2981. # ;;
  2982. # ;; "srate" can be a negative number (read in reverse), or an envelope.
  2983. def fullmix(in_file,
  2984. start = 0.0,
  2985. outdur = false,
  2986. inbeg = 0.0,
  2987. matrix = false,
  2988. srate = false,
  2989. reverb_amount = false)
  2990. unless File.exist?(in_file)
  2991. Snd.raise(:no_such_file, in_file, "no such file")
  2992. end
  2993. unless start
  2994. start = 0.0
  2995. end
  2996. unless inbeg
  2997. inbeg = 0.0
  2998. end
  2999. if number?(outdur)
  3000. dur = outdur
  3001. else
  3002. sr = number?(srate) ? srate.abs : 1.0
  3003. dur = (mus_sound_duration(in_file) - inbeg) / sr
  3004. end
  3005. in_chans = channels(in_file)
  3006. reversed = ((number?(srate) and srate.negative?) or
  3007. (array?(srate) and srate.cadr.negative?))
  3008. inloc = (Float(inbeg) * mus_sound_srate(in_file)).round
  3009. ochans = [in_chans, @channels].max
  3010. if @ws_reverb and number?(reverb_amount) and reverb_amount.positive?
  3011. rev_mx = Vct.new(in_chans * in_chans, reverb_amount)
  3012. else
  3013. rev_mx = false
  3014. end
  3015. dir = (reversed ? -1 : 1)
  3016. if (not srate) or (number?(srate) and srate == 1.0)
  3017. file = make_file2frample(in_file)
  3018. else
  3019. file = make_array(in_chans) do |i|
  3020. make_readin(in_file, i, inloc, :direction, dir)
  3021. end
  3022. end
  3023. envs = false
  3024. if array?(srate)
  3025. srcenv = make_env(srate, :duration, dur, :scaler, Float(dir))
  3026. else
  3027. srcenv = false
  3028. end
  3029. case matrix
  3030. when Array
  3031. mx = Vct.new(ochans * ochans, 0.0)
  3032. matrix.each_with_index do |inlist, inp|
  3033. break if inp >= in_chans
  3034. inlist.each_with_index do |outn, outp|
  3035. break if outp >= @channels
  3036. case outn
  3037. when Numeric
  3038. # mx[inp][outp] = outn
  3039. mx[inp * ochans + outp] = outn
  3040. when Array, Mus
  3041. unless envs
  3042. envs = Array.new(in_chans * @channels, false)
  3043. end
  3044. if env?(outn)
  3045. envs[inp * @channels + outp] = outn
  3046. else
  3047. envs[inp * @channels + outp] = make_env(outn, :duration, dur)
  3048. end
  3049. else
  3050. Snd.warning("unknown element in matrix: %p", outn)
  3051. end
  3052. end
  3053. end
  3054. when Numeric
  3055. # ; matrix is a number in this case (a global scaler)
  3056. mx = Vct.new(ochans * ochans, matrix)
  3057. else
  3058. mx = Vct.new(ochans * ochans, 1.0)
  3059. end
  3060. # to satisfy with_sound-option :info and :notehook
  3061. with_sound_info(get_func_name, start, dur)
  3062. beg = seconds2samples(start)
  3063. samps = seconds2samples(dur)
  3064. if (not array?(file))
  3065. mxe = envs
  3066. if envs
  3067. mxe = Array.new(in_chans) do |i|
  3068. Array.new(@channels) do |j|
  3069. envs[i * @channels + j]
  3070. end
  3071. end
  3072. end
  3073. if sound?(@ws_output)
  3074. output = file_name(@ws_output)
  3075. if sound?(@ws_reverb)
  3076. revout = file_name(@ws_reverb)
  3077. end
  3078. else
  3079. output = @ws_output
  3080. revout = @ws_reverb
  3081. end
  3082. mus_file_mix(output, file, beg, samps, inloc, mx, mxe)
  3083. if rev_mx
  3084. mus_file_mix(revout, file, beg, samps, inloc, rev_mx)
  3085. end
  3086. else
  3087. if sound?(@ws_output)
  3088. Snd.raise(:wrong_type_arg, "don't use :to_snd true")
  3089. end
  3090. sr = (number?(srate) ? srate.abs : 0.0)
  3091. srcs = Array.new(in_chans) do |i|
  3092. make_src(:input, file[i], :srate, sr)
  3093. end
  3094. mus_file_mix_with_envs(file, beg, samps, mx, rev_mx, envs, srcs, srcenv,
  3095. @ws_output, @ws_reverb)
  3096. end
  3097. end
  3098. def fullmix_test(start = 0.0, dur = 1.0)
  3099. $now = start
  3100. fullmix("pistol.snd", $now, dur)
  3101. $now += dur + 0.2
  3102. fullmix("oboe.snd", $now, dur, 0,
  3103. [[0.1, make_env([0, 0, 1, 1], :duration, dur, :scaler, 0.5)]])
  3104. $now += dur + 0.2
  3105. end
  3106. # Original header:
  3107. # ;;; grani: a granular synthesis instrument
  3108. # ;;; by Fernando Lopez-Lezcano
  3109. # ;;; http://ccrma.stanford.edu/~nando/clm/grani/
  3110. # ;;;
  3111. # ;;; Original grani.ins instrument written for the 220a Course by
  3112. # ;;; Fernando Lopez-Lezcano & Juan Pampin, November 6 1996
  3113. # ;;;
  3114. # ;;; Mar 21 1997: working with hop and grain-dur envelopes
  3115. # ;;; Mar 22 1997: working with src envelope (grain wise) & src spread
  3116. # ;;; Jan 26 1998: started work on new version
  3117. # ;;; Nov 7 1998: input soundfile duration calculation wrong
  3118. # ;;; Nov 10 1998: bug in in-samples (thanks to Kristopher D. Giesing for this one)
  3119. # ;;; Dec 20 1998: added standard locsig code
  3120. # ;;; Feb 19 1999: added "nil" as default value of where to avoid warning (by bill)
  3121. # ;;; Jan 10 2000: added input-channel to select which channel of the input file
  3122. # ;;; to process.
  3123. # ;;; added grain-start-in-seconds to be able to specify input file
  3124. # ;;; locations in seconds for the grain-start envelope
  3125. # ;;; May 06 2002: fixed array passing of where-bins in clisp (reported by Charles
  3126. # ;;; Nichols and jennifer l doering
  3127. # ;;; Mar 27 2003: added option for sending grains to all channels (requested by
  3128. # ;;; Oded Ben-Tal)
  3129. # ;;; calculate a random spread around a center of 0
  3130. def random_spread(spread)
  3131. spread.nonzero? ? (random(spread) - spread / 2.0) : 0.0
  3132. end
  3133. # ;;; create a constant envelope if argument is a number
  3134. def envelope_or_number(val)
  3135. assert_type((number?(val) or array?(val) or vct?(val)),
  3136. val, 0, "a number, an array or a vct")
  3137. case val
  3138. when Numeric
  3139. [0, Float(val), 1, Float(val)]
  3140. when Vct
  3141. val.to_a
  3142. when Array
  3143. val
  3144. end
  3145. end
  3146. # ;;; create a vct from an envelope
  3147. def make_gr_env(env, length = 512)
  3148. length_1 = (length - 1).to_f
  3149. make_vct!(length) do |i|
  3150. envelope_interp(i / length_1, env)
  3151. end
  3152. end
  3153. # ;;; Grain envelopes
  3154. def raised_cosine(*args)
  3155. duty_cycle, length = nil
  3156. optkey(args, binding,
  3157. [:duty_cycle, 100],
  3158. [:length, 128])
  3159. active = length * duty_cycle.to_f * 0.01
  3160. incr = PI / (active - 1.0)
  3161. start = (length - active) / 2.0
  3162. fin = (length + active) / 2.0
  3163. s = -1
  3164. make_vct!(length) do |i|
  3165. sine = if i >= start and i < fin
  3166. s += 1
  3167. sin(s * incr)
  3168. else
  3169. 0.0
  3170. end
  3171. sine * sine
  3172. end
  3173. end
  3174. # ;;;=============================================================================
  3175. # ;;; Granular synthesis instrument
  3176. # ;;;=============================================================================
  3177. #
  3178. # ;;; input-channel:
  3179. # ;;; from which channel in the input file are samples read
  3180. # ;;; amp-envelope:
  3181. # ;;; amplitude envelope for the note
  3182. # ;;; grain-envelope:
  3183. # ;;; grain-envelope-end:
  3184. # ;;; envelopes for each individual grain. The envelope applied in the result
  3185. # ;;; of interpolating both envelopes. The interpolation is controlled by
  3186. # ;;; grain-envelope-trasition. If "grain-envelope-end" is nil interpolation
  3187. # ;;; is turned off and only grain-envelope is applied to the grains.
  3188. # ;;; grain-envelope-trasition:
  3189. # ;;; an enveloper that controls the interpolation between the two grain envelopes
  3190. # ;;; 0 -> selects "grain-envelope"
  3191. # ;;; 1 -> selects "grain-envelope-end"
  3192. # ;;; grain-envelope-array-size
  3193. # ;;; size of the array passed to make-table-lookup
  3194. # ;;; grain-duration:
  3195. # ;;; envelope that controls grain duration in seconds
  3196. # ;;; srate-linear:
  3197. # ;;; t -> sample rate envelope is linear
  3198. # ;;; nil -> sample rate envelope is exponential
  3199. # ;;; srate:
  3200. # ;;; envelope that controls sample rate conversion. The envelope is an
  3201. # ;;; exponential envelope, the base and error bound of the conversion
  3202. # ;;; are controlled by "srate-base" and "srate-error".
  3203. # ;;; srate-spread:
  3204. # ;;; random spread of sample rate conversion around "srate"
  3205. # ;;; srate-base:
  3206. # ;;; base for the exponential conversion
  3207. # ;;; for example: base = (expt 2 (/ 12)) creates a semitone envelope
  3208. # ;;; srate-error:
  3209. # ;;; error bound for the exponential conversion.
  3210. # ;;; grain-start:
  3211. # ;;; envelope that determines the starting point of the current grain in
  3212. # ;;; the input file. "y"->0 starts the grain at the beginning of the input
  3213. # ;;; file. "y"->1 starts the grain at the end of the input file.
  3214. # ;;; grain-start-spread:
  3215. # ;;; random spread around the value of "grain-start"
  3216. # ;;; grain-start-in-seconds:
  3217. # ;;; nil -> grain-start y envelope expressed in percent of the duration of the input file
  3218. # ;;; t -> grain-start y envelope expressed in seconds
  3219. # ;;; grain-density:
  3220. # ;;; envelope that controls the number of grains per second generated in the output file
  3221. # ;;; grain-density-spread:
  3222. Grani_to_locsig = 0
  3223. Grani_to_grain_duration = 1
  3224. Grani_to_grain_start = 2
  3225. Grani_to_grain_sample_rate = 3
  3226. Grani_to_grain_random = 4
  3227. Grani_to_grain_allchans = 5
  3228. def grani(start, dur, amp, file, *args)
  3229. assert_type(File.exist?(file), file, 3, "an existing file")
  3230. input_channel = nil
  3231. grains, amp_envelope, grain_envelope, grain_envelope_end = nil
  3232. grain_envelope_transition, grain_envelope_array_size, grain_duration = nil
  3233. grain_duration_spread, grain_duration_limit, srate, srate_spread = nil
  3234. srate_linear, srate_base, srate_error, grain_start, grain_start_spread = nil
  3235. grain_start_in_seconds, grain_density, grain_density_spread = nil
  3236. reverb_amount, reverse, where_to, where_bins, grain_distance = nil
  3237. grain_distance_spread, grain_degree, grain_degree_spread = nil
  3238. optkey(args, binding,
  3239. [:input_channel, 0],
  3240. [:grains, 0],
  3241. [:amp_envelope, [0, 0, 0.3, 1, 0.7, 1, 1, 0]],
  3242. [:grain_envelope, [0, 0, 0.3, 1, 0.7, 1, 1, 0]],
  3243. [:grain_envelope_end, false],
  3244. [:grain_envelope_transition, [0, 0, 1, 1]],
  3245. [:grain_envelope_array_size, 512],
  3246. [:grain_duration, 0.1],
  3247. [:grain_duration_spread, 0.0],
  3248. [:grain_duration_limit, 0.002],
  3249. [:srate, 0.0],
  3250. [:srate_spread, 0.0],
  3251. [:srate_linear, false],
  3252. [:srate_base, 2.0 ** (1.0 / 12)],
  3253. [:srate_error, 0.01],
  3254. [:grain_start, [0, 0, 1, 1]],
  3255. [:grain_start_spread, 0.0],
  3256. [:grain_start_in_seconds, false],
  3257. [:grain_density, 10.0],
  3258. [:grain_density_spread, 0.0],
  3259. [:reverb_amount, 0.01],
  3260. [:reverse, false],
  3261. [:where_to, 0],
  3262. [:where_bins, []],
  3263. [:grain_distance, 1.0],
  3264. [:grain_distance_spread, 0.0],
  3265. [:grain_degree, 45.0],
  3266. [:grain_degree_spread, 0.0])
  3267. beg, fin = times2samples(start, dur)
  3268. in_file_channels = ws_channels(file)
  3269. in_file_sr = ws_srate(file)
  3270. in_file_dur = ws_duration(file)
  3271. rd = make_ws_reader(file,
  3272. :channel, [input_channel, in_file_channels - 1].min,
  3273. :vct?, true)
  3274. in_file_reader = make_src(:input, lambda do |dir| ws_readin(rd) end,
  3275. :srate, 1.0)
  3276. set_mus_increment(in_file_reader, -1) if reverse
  3277. last_in_sample = (in_file_dur * in_file_sr).round
  3278. srate_ratio = in_file_sr / mus_srate()
  3279. sr_env = make_env(:envelope, if srate_linear
  3280. envelope_or_number(srate)
  3281. else
  3282. exp_envelope(envelope_or_number(srate),
  3283. :base, srate_base,
  3284. :error, srate_error)
  3285. end,
  3286. :scaler, srate_ratio,
  3287. :duration, dur)
  3288. sr_spread_env = make_env(:envelope, envelope_or_number(srate_spread),
  3289. :duration, dur)
  3290. amp_env = make_env(:envelope, amp_envelope, :scaler, amp, :duration, dur)
  3291. gr_dur = make_env(:envelope, envelope_or_number(grain_duration),
  3292. :duration, dur)
  3293. gr_dur_spread = make_env(:envelope, envelope_or_number(grain_duration_spread),
  3294. :duration, dur)
  3295. gr_start_scaler = (grain_start_in_seconds ? 1.0 : in_file_dur)
  3296. gr_start = make_env(:envelope, envelope_or_number(grain_start),
  3297. :duration, dur)
  3298. gr_start_spread = make_env(:envelope, envelope_or_number(grain_start_spread),
  3299. :duration, dur)
  3300. gr_dens_env = make_env(:envelope, envelope_or_number(grain_density),
  3301. :duration, dur)
  3302. gr_dens_spread_env = make_env(:envelope,
  3303. envelope_or_number(grain_density_spread),
  3304. :duration, dur)
  3305. if vct?(grain_envelope)
  3306. ge = grain_envelope
  3307. else
  3308. ge = make_gr_env(grain_envelope, grain_envelope_array_size)
  3309. end
  3310. gr_env = make_table_lookup(:frequency, 1.0, :initial_phase, 0, :wave, ge)
  3311. if grain_envelope_end
  3312. if vct?(grain_envelope_end)
  3313. ge = grain_envelope_end
  3314. else
  3315. ge = make_gr_env(grain_envelope_end, grain_envelope_array_size)
  3316. end
  3317. else
  3318. ge = make_vct(512)
  3319. end
  3320. gr_env_end = make_table_lookup(:frequency, 1.0, :initial_phase, 0, :wave, ge)
  3321. gr_int_env = make_env(:envelope,
  3322. envelope_or_number(grain_envelope_transition),
  3323. :duration, dur)
  3324. gr_dist = make_env(:envelope, envelope_or_number(grain_distance),
  3325. :duration, dur)
  3326. gr_dist_spread = make_env(:envelope,
  3327. envelope_or_number(grain_distance_spread),
  3328. :duration, dur)
  3329. gr_degree = make_env(:envelope, envelope_or_number(grain_degree),
  3330. :duration, dur)
  3331. gr_degree_spread = make_env(:envelope,
  3332. envelope_or_number(grain_degree_spread),
  3333. :duration, dur)
  3334. gr_start_sample = beg
  3335. gr_samples = 0
  3336. gr_offset = 1
  3337. gr_dens = 0.0
  3338. gr_dens_spread = 0.0
  3339. grain_counter = 0
  3340. samples = 0
  3341. first_grain = true
  3342. case grain_duration
  3343. when Numeric
  3344. dur += grain_duration
  3345. when Array
  3346. dur += grain_duration.last
  3347. end
  3348. run_instrument(start, dur, :degree, 45.0) do
  3349. if gr_offset < gr_samples
  3350. gr_offset += 1
  3351. (if grain_envelope_end
  3352. gr_where = env(gr_int_env)
  3353. (1 - gr_where) * table_lookup(gr_env) +
  3354. gr_where * table_lookup(gr_env_end)
  3355. else
  3356. table_lookup(gr_env)
  3357. end) * env(amp_env) * src(in_file_reader)
  3358. else
  3359. if first_grain
  3360. first_grain = false
  3361. gr_start_sample = beg
  3362. else
  3363. gr_start_sample += seconds2samples(1.0 / (gr_dens + gr_dens_spread))
  3364. if (gr_start_sample > fin) or
  3365. (grains.nonzero? and (grain_counter >= grains))
  3366. break
  3367. end
  3368. end
  3369. gr_offset = 0
  3370. gr_from_beg = gr_start_sample - beg
  3371. set_mus_location(amp_env, gr_from_beg)
  3372. set_mus_location(gr_dur, gr_from_beg)
  3373. set_mus_location(gr_dur_spread, gr_from_beg)
  3374. set_mus_location(sr_env, gr_from_beg)
  3375. set_mus_location(sr_spread_env, gr_from_beg)
  3376. set_mus_location(gr_start, gr_from_beg)
  3377. set_mus_location(gr_start_spread, gr_from_beg)
  3378. set_mus_location(gr_dens_env, gr_from_beg)
  3379. set_mus_location(gr_dens_spread_env, gr_from_beg)
  3380. in_start_value = env(gr_start) * gr_start_scaler +
  3381. random_spread(env(gr_start_spread) * gr_start_scaler)
  3382. in_start = (in_start_value * in_file_sr).round
  3383. gr_duration = [grain_duration_limit,
  3384. env(gr_dur) + random_spread(env(gr_dur_spread))].max
  3385. gr_samples = seconds2samples(gr_duration)
  3386. gr_srate = if srate_linear
  3387. env(sr_env) + random_spread(env(sr_spread_env))
  3388. else
  3389. env(sr_env) * srate_base ** random_spread(env(sr_spread_env))
  3390. end
  3391. set_mus_increment(in_file_reader, gr_srate)
  3392. in_samples = (gr_samples / (1.0 / srate_ratio)).round
  3393. set_mus_phase(gr_env, 0.0)
  3394. set_mus_phase(gr_env_end, 0.0)
  3395. set_mus_frequency(gr_env, 1.0 / gr_duration)
  3396. set_mus_frequency(gr_env_end, 1.0 / gr_duration)
  3397. gr_dens = env(gr_dens_env)
  3398. gr_dens_spread = random_spread(env(gr_dens_spread_env))
  3399. samples += gr_samples
  3400. grain_counter += 1
  3401. where = case where_to
  3402. when Grani_to_grain_duration
  3403. gr_duration
  3404. when Grani_to_grain_start
  3405. in_start_value
  3406. when Grani_to_grain_sample_rate
  3407. gr_srate
  3408. when Grani_to_grain_random
  3409. random(1.0)
  3410. else
  3411. Grani_to_locsig
  3412. end
  3413. if where.nonzero? and where_bins.length > 0
  3414. (where_bins.length - 1).times do |chn|
  3415. locsig_set!(@locsig, chn,
  3416. (where.between?(where_bins[chn], where_bins[chn + 1]) ?
  3417. 1.0 :
  3418. 0.0))
  3419. end
  3420. else
  3421. if where_to == Grani_to_grain_allchans
  3422. @channels.times do |chn|
  3423. locsig_set!(@locsig, chn, 1.0)
  3424. end
  3425. else
  3426. set_mus_location(gr_dist, gr_from_beg)
  3427. set_mus_location(gr_dist_spread, gr_from_beg)
  3428. set_mus_location(gr_degree, gr_from_beg)
  3429. set_mus_location(gr_degree_spread, gr_from_beg)
  3430. deg = env(gr_degree) + random_spread(env(gr_degree_spread))
  3431. dist = env(gr_dist) + random_spread(env(gr_dist_spread))
  3432. dist_scl = 1.0 / [dist, 1.0].max
  3433. if sample2file?(@ws_reverb)
  3434. locsig_reverb_set!(@locsig, 0,
  3435. reverb_amount * (1.0 / sqrt([dist, 1.0].max)))
  3436. end
  3437. if @channels == 1
  3438. locsig_set!(@locsig, 0, dist_scl)
  3439. else
  3440. if @channels == 2
  3441. frac = [90.0, [0.0, deg].max].min / 90.0
  3442. locsig_set!(@locsig, 0, dist_scl * (1.0 - frac))
  3443. locsig_set!(@locsig, 1, dist_scl * frac)
  3444. else
  3445. if @channels > 2
  3446. locsig_set!(@locsig, 0, if deg.between?(0, 90)
  3447. dist_scl * ((90.0 - deg) / 90.0)
  3448. else
  3449. if deg.between?(270, 360)
  3450. dist_scl * ((deg - 270.0) / 90.0)
  3451. else
  3452. 0.0
  3453. end
  3454. end)
  3455. locsig_set!(@locsig, 1, if deg.between?(90, 180)
  3456. dist_scl * (180.0 - deg) / 90.0
  3457. else
  3458. if deg.between?(0, 90)
  3459. dist_scl * (deg / 90.0)
  3460. else
  3461. 0.0
  3462. end
  3463. end)
  3464. locsig_set!(@locsig, 2, if deg.between?(180, 270)
  3465. dist_scl * (270.0 - deg) / 90.0
  3466. else
  3467. if deg.between?(90, 180)
  3468. dist_scl * (deg - 90.0) / 90.0
  3469. else
  3470. 0.0
  3471. end
  3472. end)
  3473. if @channels > 3
  3474. locsig_set!(@locsig, 3, if deg.between?(270, 360)
  3475. dist_scl * (360.0 - deg) / 90.0
  3476. else
  3477. if deg.between?(180, 270)
  3478. dist_scl * (deg - 180.0) / 90.0
  3479. else
  3480. 0.0
  3481. end
  3482. end)
  3483. end
  3484. end
  3485. end
  3486. end
  3487. end
  3488. end
  3489. in_start = if (in_start + in_samples) > last_in_sample
  3490. last_in_sample - in_samples
  3491. else
  3492. [in_start, 0].max
  3493. end
  3494. set_ws_location(rd, in_start)
  3495. 0.0
  3496. end
  3497. end
  3498. close_ws_reader(rd)
  3499. end
  3500. def grani_test(start = 0.0, dur = 1.0)
  3501. grani(start, dur, 5.0, "oboe.snd", :grain_envelope, raised_cosine())
  3502. $now = start + dur + 0.2
  3503. end
  3504. # BES-FM
  3505. def bes_fm(start, dur, freq, amp, ratio, index)
  3506. car_ph = mod_ph = 0.0
  3507. car_incr = hz2radians(freq)
  3508. mod_incr = ratio.to_f * car_incr
  3509. ampenv = make_env(:envelope, [0, 0, 25, 1, 75, 1, 100, 0],
  3510. :scaler, amp,
  3511. :duration, dur)
  3512. run_instrument(start, dur) do
  3513. out_val = env(ampenv) * bes_j1(car_ph)
  3514. car_ph = car_ph + car_incr + index.to_f * bes_j1(mod_ph)
  3515. mod_ph += mod_incr
  3516. out_val
  3517. end
  3518. end
  3519. def bes_fm_test(start = 0.0, dur = 1.0)
  3520. bes_fm(start, dur, 440, 10, 1, 4)
  3521. $now = start + dur + 0.2
  3522. end
  3523. # SSB_FM
  3524. class Ssb_fm < Musgen
  3525. def initialize(freq)
  3526. super()
  3527. @frequency = freq
  3528. @osc1 = make_oscil(freq, 0)
  3529. @osc2 = make_oscil(freq, HALF_PI)
  3530. @osc3 = make_oscil(0, 0)
  3531. @osc4 = make_oscil(0, HALF_PI)
  3532. @hilbert = make_hilbert_transform(40)
  3533. @delay = make_delay(40)
  3534. end
  3535. def inspect
  3536. format("%s.new(%s)", self.class, @frequency)
  3537. end
  3538. def to_s
  3539. format("#<%s freq: %s>", self.class, @frequency)
  3540. end
  3541. def run_func(val1 = 0.0, val2 = 0.0)
  3542. ssb_fm(val1)
  3543. end
  3544. def ssb_fm(modsig)
  3545. am0 = oscil(@osc1)
  3546. am1 = oscil(@osc2)
  3547. car0 = oscil(@osc3, hilbert_transform(@hilbert, modsig))
  3548. car1 = oscil(@osc4, delay(@delay, modsig))
  3549. am0 * car0 + am1 * car1
  3550. end
  3551. end
  3552. def make_ssb_fm(freq = 440.0)
  3553. Ssb_fm.new(freq)
  3554. end
  3555. def ssb_fm?(obj)
  3556. obj.kind_of?(Ssb_fm)
  3557. end
  3558. def ssb_fm(gen, modsig = 0.0)
  3559. gen.ssb_fm(modsig)
  3560. end
  3561. # FM2
  3562. class Fm2 < Musgen
  3563. def initialize(f1, f2, f3, f4, p1, p2, p3, p4)
  3564. super()
  3565. @osc1 = make_oscil(f1, p1)
  3566. @osc2 = make_oscil(f2, p2)
  3567. @osc3 = make_oscil(f3, p3)
  3568. @osc4 = make_oscil(f4, p4)
  3569. end
  3570. def inspect
  3571. format("%s.new(%s, %s, %s, %s, %s, %s, %s, %s)",
  3572. self.class, @f1, @f2, @f3, @f4, @p1, @p2, @p3, @p4)
  3573. end
  3574. def to_s
  3575. format("#<%s %1.3f, %1.3f, %1.3f, %1.3f, %1.3f, %1.3f, %1.3f, %1.3f>",
  3576. self.class, @f1, @f2, @f3, @f4, @p1, @p2, @p3, @p4)
  3577. end
  3578. def run_func(val1 = 0.0, val2 = 0.0)
  3579. fm2(val1)
  3580. end
  3581. def fm2(index)
  3582. (oscil(@osc1, index * oscil(@osc2)) +
  3583. oscil(@osc3, index * oscil(@osc4))) * 0.25
  3584. end
  3585. end
  3586. # make_fm2(1000, 100, 1000, 100, 0, 0, HALF_PI, HALF_PI)
  3587. # make_fm2(1000, 100, 1000, 100, 0, 0, 0, HALF_PI)
  3588. def make_fm2(f1, f2, f3, f4, p1, p2, p3, p4)
  3589. Fm2.new(f1, f2, f3, f4, p1, p2, p3, p4)
  3590. end
  3591. def fm2?(obj)
  3592. obj.kind_of?(Fm2)
  3593. end
  3594. def fm2(gen, index = 0.0)
  3595. gen.fm2(index)
  3596. end
  3597. def clm_ins_test(start = 0.0, dur = 1.0)
  3598. $now = start
  3599. violin_test($now, dur)
  3600. fm_violin_test($now, dur)
  3601. pluck_test($now, dur)
  3602. vox_test($now, dur)
  3603. fofins_test($now, dur)
  3604. fm_trumpet_test($now, dur)
  3605. pqw_vox_test($now, dur)
  3606. flute_test($now, dur)
  3607. fm_bell_test($now, dur)
  3608. fm_insect_test($now, dur)
  3609. fm_drum_test($now, dur)
  3610. gong_test($now, dur)
  3611. attract_test($now, dur)
  3612. pqw_test($now, dur)
  3613. tubebell_test($now, dur)
  3614. wurley_test($now, dur)
  3615. rhodey_test($now, dur)
  3616. hammondoid_test($now, dur)
  3617. metal_test($now, dur)
  3618. drone_canter_test($now, dur)
  3619. reson_test($now, dur)
  3620. cellon_test($now, dur)
  3621. gran_synth_test($now, dur)
  3622. touch_tone_test($now, dur)
  3623. spectra_test($now, dur)
  3624. two_tab_test($now, dur)
  3625. lbj_piano_test($now, dur)
  3626. resflt_test($now, dur)
  3627. scratch_test($now, dur)
  3628. pins_test($now, dur)
  3629. zc_test($now, dur)
  3630. zn_test($now, dur)
  3631. za_test($now, dur)
  3632. clm_expsrc_test($now, dur)
  3633. exp_snd_test($now, dur)
  3634. expfil_test($now, dur)
  3635. graph_eq_test($now, dur)
  3636. anoi_test($now, dur)
  3637. fullmix_test($now, dur)
  3638. grani_test($now, dur)
  3639. bes_fm_test($now, dur)
  3640. end
  3641. # clm-ins.rb ends here