;Written by Iain McCurdy, ;Modified for QuteCsound by René, March 2011 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817 ; RATTLES AND RUBBERS DOESN'T SEEM TO WORK AT PRESENT IN CSOUND ;Notes on modifications from original csd: ; Add tables for exp slider ; Init instrument added ; Info panel: ; prepiano ; --------------------------------------------------------------------------------------------------------------------------- ; The prepiano opcode implements a physical model of a Cagian prepared piano. The user has control of the base frequency of ; a string (or group of strings), the number of strings beneath the hammer, the amount of detuning between a group of ; strings, the stiffness of the strings, the time for a note to decay by 30 dB, the amount of high frequency damping that ; occurs during a note's decay, the mass of the hammer, the frequency of the hammer's natural vibrations, the location ; along the string's length at which the hammer strikes and the velocity of the hammer as it moves to strike the string. ; The user can choose the method of restraint applied to the string independently for its left and right extremities. ; Choosing 'clamped' reflects the normal method of binding a piano string, 'pivoting' reflects the method used to bind a ; note on a marimba and 'free' means that the string extremity is not bound at all. ; To imbue the sound with some movement the author has imagined the sound being received by a pick-up that moves to ; and from along the length of the string. 'Scanning Spread' controls the amplitude of this movement and 'Scanning ; Frequency' controls the frequency of this movement. The methods of Cagian piano preparation that are implemented ; in this opcode are the addition of hard objects that vibrate in sympathy with the string but are not firmly attached to ; it rattles and soft objects that damp the string (rubbers). For rattles the user is able to define its position along the ; string, the mass/density ratio between rattle and string, its frequency and its length. ; For rubbers the user can define position, mass/density ratio, frequency and loss. ; By using function tables for the definition of rubbers and rattles it is possible to have any amount of them applied to ; the same string. Unfortunately the rattles and rubbers part of the Csound implementation of this physical model do not ; appear to work so I have only supplied user control for one rattle and one rubber (which don't work anyway). ; As with many physical models we have the opportunity to specify conditions that would not be possible in the real ; world, for this reason it is easily to produce mathematical procedures that quickly 'blow up' and produce extremely loud ; and distorted sounds. Approach parameter changes with caution and protect your ears and speakers. ;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0 sr = 44100 ;SAMPLE RATE ksmps = 100 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) ;DEFINE FUNCTION TABLES FOR RATTLES AND RUBBERS ; COUNT | POSITION | MASS DENSITY RATIO OF RATTLE/STRING | FREQUENCY OF RATTLE | VERTICAL LENGTH OF THE RATTLE/ RUBBER LOSS girattles ftgen 0, 0, 8, -2, 1, .6, .1, 100, 10 girubbers ftgen 0, 0, 8, -2, 1, .7, .1, 500, .1 ;TABLE FOR EXP SLIDER giExp1 ftgen 0, 0, 129, -25, 0, 20.0, 128, 10000.0 giExp2 ftgen 0, 0, 129, -25, 0, 20.0, 128, 20000.0 instr 100 ;GUI ktrig metro 10 if (ktrig == 1) then gkrattle1 invalue "Rattle" gkposRat1 invalue "posRat" gkMDRRat1 invalue "MDRRat" gkFrqRat1 invalue "FrqRat" gkLenRat1 invalue "LenRat" gkrubber1 invalue "Rubber" gkposRub1 invalue "posRub" gkMDRRub1 invalue "MDRRub" gkFrqRub1 invalue "FrqRub" gkLosRub1 invalue "LosRub" kfreqS invalue "StrFreq" gkfreqS tablei kfreqS, giExp1, 1 outvalue "StrFreq_Value", gkfreqS gkD invalue "Detuning" gkK invalue "Stiffness" gkT30 invalue "30DT" gkB invalue "HFLoss" gkmass invalue "HammerMass" kfreqH invalue "HammerFreq" gkfreqH tablei kfreqH, giExp2, 1 outvalue "HammerFreq_Value", gkfreqH gkinit invalue "HammerInitPos" gkpos invalue "HammerPosStr" gkvel invalue "StringVel" gksfreq invalue "ScanFreq" gksspread invalue "ScanFreqSpread" gkOutGain invalue "OutGain" gkNS invalue "NumbStr" gkbcL invalue "bcL" gkbcR invalue "bcR" endif endin instr 1 ;(ALWAYS ON - SEE SCORE) PLAYS FILE AND SENSES FADER MOVEMENT AND RESTARTS INSTR 2 FOR I-RATE CONTROLLERS ;;;THE FOLLOWING LINES OF CODE UPDATE THE FUNCTION TABLE CONTENTS FOR RATTLES AND RUBBERS - UNFORTUNATELY THIS FEATURE DOESN'T SEEM TO WORK AT PRESENT IN CSOUND #define VAR #gkrattle1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+2, 0, .001, $VAR #define VAR #gkposRat1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+3, 0, .001, $VAR #define VAR #gkMDRRat1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+4, 0, .001, $VAR #define VAR #gkFrqRat1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+5, 0, .001, $VAR #define VAR #gkLenRat1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+6, 0, .001, $VAR #define VAR #gkrubber1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+7, 0, .001, $VAR #define VAR #gkposRub1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+8, 0, .001, $VAR #define VAR #gkMDRRub1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+9, 0, .001, $VAR #define VAR #gkFrqRub1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+10, 0, .001, $VAR #define VAR #gkLosRub1# ktrigger$VAR changed $VAR schedkwhen ktrigger$VAR, 0, 0, p1+11, 0, .001, $VAR ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ktrigger changed gkfreqS, gkD, gkK, gkT30, gkB, gkmass, gkfreqH, gkinit, gkpos, gkvel, gksfreq, gksspread, gkNS, gkrattle1, gkposRat1, gkMDRRat1, gkFrqRat1, gkLenRat1, gkrubber1, gkposRub1, gkMDRRub1, gkFrqRub1, gkLosRub1 ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO) ; TRIGGER | IMINTIM | IMAXNUM | IINSNUM | IWHEN | IDUR (-1 MEANS A NOTE OF INFINITE DURATION) schedkwhen ktrigger, 0, 0, 2, 0, -1 ;RESTART INSTRUMENT 2 WITH A SUSTAINED (HELD) NOTE WHENEVER kSwitch=1 endin instr 2 ;SOUND PRODUCING INSTRUMENT ;OUTPUTS OPCODE BASE-FREQ | NUM_OF_STRINGS | DETUNING | STIFFNESS | 30 DB DECAY TIME | HIGH_FREQUENCY_LOSS | LEFT_BOUNDARY_CONDITION | RIGHT_BOUNDARY_CONDITION | HAMMER_MASS | HAMMER_FREQUENCY | HAMMER_INITIAL_POSITION | POSITION_ALONG_STRING | HAMMER_VELOCITY | SCANNING_FREQ | SCANNING_FREQ_SPREAD | RATTLES_FUNCTION_TABLE | RUBBERS_FUNCTION_TABLE al, ar prepiano i(gkfreqS), i(gkNS), i(gkD), i(gkK), i(gkT30), i(gkB), gkbcL+1, gkbcR+1, i(gkmass), i(gkfreqH), i(gkinit), i(gkpos), i(gkvel), i(gksfreq), i(gksspread), girattles, girubbers outs al * gkOutGain, ar * gkOutGain endin instr 3,4,5,6,7 ;UPDATE RATTLES FUNCTION TABLE tableiw p4, p1-3, girattles endin instr 8,9,10,11,12 ;UPDATE RUBBERS FUNCTION TABLE tableiw p4, p1-8, girubbers endin instr 200 ;INIT outvalue "StrFreq" , 0.26 outvalue "NumbStr" , 3 outvalue "Detuning" , 0 outvalue "Stiffness" , 1 outvalue "30DT" , 3 outvalue "HFLoss" , .002 outvalue "bcL" , 2 outvalue "bcR" , 2 outvalue "HammerMass" , 1 outvalue "HammerFreq" , 0.8 outvalue "HammerInitPos" , -.01 outvalue "HammerPosStr" , .09 outvalue "StringVel" , 50 outvalue "ScanFreq" , 0 outvalue "ScanFreqSpread" , .1 outvalue "OutGain" , .5 outvalue "Rattle" , 1 outvalue "posRat" , .6 outvalue "MDRRat" , .1 outvalue "FrqRat" , 100 outvalue "LenRat" , .1 outvalue "Rubber" , 1 outvalue "posRub" , .7 outvalue "MDRRub" , .1 outvalue "FrqRub" , 500 outvalue "LosRub" , .1 endin ;INSTR | START | DURATION i 1 0 3600 i 100 0 3600 ;GUI i 200 0 0.1 ;INIT 72 179 400 200 true 241 226 185 2 2 1023 607 {aa607456-d368-4d59-8497-d16d608404c3} true 0 0 center Liberation Sans 18 3 0 0 0 147 154 255 border 5 2 8 77 220 30 {640b50b7-7200-4f81-8394-89d9843ae939} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 StrFreq 8 57 500 27 {5585fa6f-0f63-4ac3-bf1b-809c2b1d9134} true 0 0 0.00000000 1.00000000 0.25999999 lin continuous -1.00000000 false StrFreq_Value 448 77 60 30 {b731b52e-e14a-476a-a583-f3b2bd885539} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 14 120 30 {e40c02c1-81d8-4459-938d-9e77ae8e081e} true 0 0 event 1.00000000 Note On / Off / i 2 0 -1 true false 518 418 500 100 {a21b6db2-5090-4663-b2de-b6685e7f2d95} true 0 0 center Liberation Sans 18 3 0 0 0 255 255 255 border 10 2 8 167 220 30 {126e87c3-8382-48d7-9f69-d7ffccf30307} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Stiffness 8 147 500 27 {436e054c-3a03-4bcb-95be-d3d4182eb85c} true 0 0 -100.00000000 100.00000000 1.00000000 lin continuous -1.00000000 false Stiffness 448 167 60 30 {e0681007-f414-48ae-84d9-0fbba93c58c9} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 122 220 30 {a87b27cc-bc96-4b29-9677-682e316d9b4d} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Detuning 8 102 500 27 {86b4ad35-b12a-4ab9-b344-09172118e0b5} true 0 0 0.00000000 5000.00000000 0.00000000 lin continuous -1.00000000 false Detuning 448 122 60 30 {92311d9a-da30-4af3-84f6-0c49a990db9a} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 212 220 30 {8dfbef14-56ca-4b84-b240-6d04bb2c1ae1} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 30DT 8 192 500 27 {690f907d-2cd9-47de-a7dc-327507391fb9} true 0 0 0.10000000 30.00000000 3.00000000 lin continuous -1.00000000 false 30DT 448 212 60 30 {3e957d6d-7cfe-478b-8a7a-8533fe10751f} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 257 220 30 {d586223e-5a9a-4e2d-86c8-7b43d306bd5c} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 HFLoss 8 237 500 27 {a118f008-d3cd-4b4b-8382-0b95756b7f05} true 0 0 0.00010000 1.00000000 0.00200000 lin continuous -1.00000000 false HFLoss 448 257 60 30 {c03464a4-fd79-4a65-aa5a-598495964bfa} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 302 220 30 {fdfdf2ac-ef3f-4331-a400-59d9a5daa767} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 HammerMass 8 282 500 27 {d17a0978-b780-493c-9a30-3dc8d5883146} true 0 0 0.00010000 10.00000000 1.00000000 lin continuous -1.00000000 false HammerMass 448 302 60 30 {5dcc1d22-735c-4bea-b699-077117f98c5a} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 392 220 30 {71e6a282-2ab6-46f6-a0ed-b85f1c7e15b5} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 HammerInitPos 8 372 500 27 {88eb1332-f82d-41d1-81e6-708c546d9d32} true 0 0 -1.00000000 1.00000000 -0.01000000 lin continuous -1.00000000 false HammerInitPos 448 392 60 30 {49e9d58a-f523-4036-8232-4e5bf01a6e7b} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 347 220 30 {87f26ca4-2db8-4185-8c84-4e1ce3d54704} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 HammerFreq 8 327 500 27 {42134457-b4cf-4163-889a-6e8bdbf7a18d} true 0 0 0.00000000 1.00000000 0.80000001 lin continuous -1.00000000 false HammerFreq_Value 448 347 60 30 {a369d53f-a407-4760-a01c-da504cd12a24} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 437 220 30 {02e28cb2-13c2-4711-bcc7-ab0064b94720} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 HammerPosStr 8 417 500 27 {63b8e4cc-0721-4001-854a-cd1a1702a526} true 0 0 0.00400000 0.99600000 0.09000000 lin continuous -1.00000000 false HammerPosStr 448 437 60 30 {f4e74c63-a005-4dc3-a458-670b14fcd5a7} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 482 220 30 {11774312-f30e-47e2-82ad-91aacc0655e0} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 StringVel 8 462 500 27 {c0712931-0b9f-41e0-89f6-423c7168d3d8} true 0 0 0.00000000 100.00000000 50.00000000 lin continuous -1.00000000 false StringVel 448 482 60 30 {350c87da-03d7-4b73-a0e4-a070f47db9e5} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 527 220 30 {ce3fc0e6-e898-401a-b231-b0630597b627} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 ScanFreq 8 507 500 27 {170052ec-d982-474d-a790-941d150a418b} true 0 0 0.00000000 100.00000000 0.00000000 lin continuous -1.00000000 false ScanFreq 448 527 60 30 {4692ad47-e4f8-44b8-a8b9-3092572406c9} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 517 572 220 30 {bfea4810-1819-47d0-9e54-c621b9457a65} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 OutGain 517 552 500 27 {1219981f-96c7-4c4e-b323-5618efbc38b1} true 0 0 0.00000000 1.00000000 0.50000000 lin continuous -1.00000000 false OutGain 957 572 60 30 {f8220f0d-67a3-4996-8fd3-df2d68dbd348} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 8 572 220 30 {59341b34-9c0e-4350-9a12-720655f5e414} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 ScanFreqSpread 8 552 500 27 {c85f37ac-5428-491d-bfa1-3ab2a861ecc9} true 0 0 0.00000000 1.00000000 0.10000000 lin continuous -1.00000000 false ScanFreqSpread 448 572 60 30 {0471d44f-9ed3-4663-a728-362d11727168} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 518 115 500 100 {3f0f6653-bb33-47c7-8d04-8e91d69f9e45} true 0 0 left Liberation Sans 18 3 0 0 0 255 255 255 border 10 2 613 164 80 50 {d1b644c3-0c6c-4d73-827d-0e89b7ca09b5} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 713 164 80 50 {4f6ecb39-332e-4821-85a5-a019a092ff94} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 posRat 613 136 80 30 {5e98811a-ff43-4250-a418-c4a414d1c396} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 0.00010000 0 1 false 0.6 MDRRat 713 136 80 30 {898bdcc6-e952-49f2-9b51-9b58e406639d} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 0.00010000 0 1 false 0.1 813 164 80 50 {29f045a1-7728-4b6a-9ff6-de076ef00be6} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 FrqRat 813 136 80 30 {55c018d2-2a51-4ee6-a4a1-5a01cf61188a} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 1.00000000 0 1000 false 100 913 164 80 50 {dec8c13d-881c-48df-a101-fd8fe40eed7e} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 LenRat 913 136 80 30 {52ba9f86-1994-497b-89b6-777a49c7a995} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 0.00100000 0 1 false 0.1 518 337 500 68 {48beae5a-470d-4a21-89d7-b610b999079d} true 0 0 left Liberation Sans 18 3 0 0 0 255 255 255 border 10 2 671 358 40 30 {ed09a043-e2d8-4158-bc76-b3378f199768} true 0 0 right Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 858 358 40 30 {6a0c7846-df6c-4af2-9619-665491d0e5ad} true 0 0 right Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 bcL 712 358 100 30 {d9ae99ca-c298-4362-8e65-77791e8352ea} true 0 0 Clamped 0 Pivoting 1 Free 2 2 false bcR 899 358 100 30 {918a69f2-09e7-42e7-97fd-e2b550f11677} true 0 0 Clamped 0 Pivoting 1 Free 2 2 false 590 60 120 30 {a3ad4fa4-3aa7-4dc9-a785-579406e79709} true 0 0 right Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 NumbStr 713 56 50 30 {ddb7a386-dde5-446d-b3a6-b61bdd1f2533} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 2 50 false 3 Rattle 545 151 16 16 {77710ef6-e1b6-4dee-baa2-c7aa4c401729} true 0 0 value 1.00000000 / true false 514 166 80 30 {60ad5f87-337d-4fe2-a7c0-86e1af01dc14} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 518 225 500 100 {aadf418c-5f4b-40f1-bbb1-a310a2946c15} true 0 0 left Liberation Sans 18 3 0 0 0 255 255 255 border 10 2 613 274 80 50 {d5d999c9-634c-4357-8d95-1a11e33b079e} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 713 274 80 50 {9d7246c4-496d-454a-b28f-8ab7f035157e} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 posRub 613 246 80 30 {f98230c1-1b5c-413b-bdc0-e5d404d1ea60} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 0.00010000 0 1 false 0.7 MDRRub 713 246 80 30 {9dd539c6-ce85-4d65-8552-e1b51e4bc74d} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 0.00010000 0 1 false 0.1 813 274 80 50 {fa4a4597-7015-4c11-9e6b-65a3fae5f4a7} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 FrqRub 813 246 80 30 {3a933db9-04fa-4bb0-9d23-3de214efd82e} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 1.00000000 0 1000 false 500 913 274 80 50 {4684fd72-91e0-467e-98ab-16b3aba3b37d} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 LosRub 913 246 80 30 {42076dc7-1734-42c5-a31e-f3d2bc40d00b} true 0 0 right Liberation Sans 12 0 0 0 255 255 255 0.00100000 0 1 false 0.1 Rubber 545 261 16 16 {42cced17-179c-4511-bd64-b8defb66530f} true 0 0 value 1.00000000 / true false 514 276 80 30 {bbaec2dc-9e4a-43bd-b67e-3230e57047bf} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1