;Written by Iain McCurdy, 2010 ;Modified for QuteCsound by René, January 2011, updated Feb 2011 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817 ;Notes on modifications from original csd: ; Add tables for exp slider ; Add Browser for audio files and use of FilePlay2 udo, now accept mono or stereo wav files ; Removed "Instructions and Info Panel" for the gui to fit in a 1200x800 screen ; ; compress ; ----------------------------------------------------------------------------------------------------------------------------- ; 'compress' is an opcode for dynamic processing of an audio signal. The signal used by the detector does not have to be ; the same as the signal to which dynamics processing is applied thus enabling the effect 'ducking' heard commonly in ; radio where the DJ cutting in with an announcement causes a dynamic dip in the music sound-bed. ; 'compress' incorporates a noise gate, the threshold of which is controlled with the 'Noise Gate Threshold' slider. ; The 'Attack Time' and 'Release Time' sliders control the attack and release times of both the noise gate and the compressor. ; 'Ratio' controls the amount of compression or expansion that will be applied. ; Values greater than 1 will apply higher degrees of compression, values less than 1 will dynamically ; expand the signal increasingly, a ratio of 1 will leave the signal unaltered. ; 'Look Ahead Time' defines how far ahead the detector scans in order to pre-empt dynamic changes. What actually happens is ; that the signal to which dynamics processing is applied is delayed with respect to the detection signal but the result is the same. ; In this implementation the user can independently select the audio signal from which dynamics will be detected and the ; signal to which dynamics processing will be applied. ; The 'Detect Sig. Gain' slider allows the user to mix the detected signal into the output along with the compressed signal. ; A number of presets are provided to demonstrate some basic applications of this opcode. ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0 --env:SSDIR+=../../SourceMaterials sr = 44100 ;SAMPLE RATE ksmps = 16 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) ;TABLES FOR EXP SLIDER giExp1 ftgen 0, 0, 129, -25, 0, 0.001, 128, 1.0 giExp2 ftgen 0, 0, 129, -25, 0, 0.001, 128, 2.0 giExp100 ftgen 0, 0, 129, -25, 0, 0.125, 128, 100.0 opcode FilePlay2, aa, Skoo ; Credit to Joachim Heintz ;gives stereo output regardless your soundfile is mono or stereo Sfil, kspeed, iskip, iloop xin ichn filenchnls Sfil if ichn == 1 then aL diskin2 Sfil, kspeed, iskip, iloop aR = aL else aL, aR diskin2 Sfil, kspeed, iskip, iloop endif xout aL, aR endop instr 10 ;GUI ktrig metro 10 if (ktrig == 1) then gkInGain invalue "Live_Gain" gkDetGain invalue "Detect_Gain" gkthresh invalue "Gate_Threshold" gkloknee invalue "Low_Knee" gkhiknee invalue "High_Knee" kratio invalue "Ratio" gkratio tablei kratio, giExp100, 1 outvalue "Ratio_Value", gkratio katt invalue "Attack" gkatt tablei katt, giExp1, 1 outvalue "Attack_Value", gkatt krel invalue "Release" gkrel tablei krel, giExp1, 1 outvalue "Release_Value", gkrel gklook invalue "Look_Ahead" kgain invalue "Gain" gkgain tablei kgain, giExp2, 1 outvalue "Gain_Value", gkgain gkinput invalue "Input" gkdetect invalue "Detect" endif endin instr 1 Sfile1_new strcpy "" ;INIT TO EMPTY STRING Sfile1 invalue "_Browse1" Sfile1_old strcpyk Sfile1_new Sfile1_new strcpyk Sfile1 kfile1 strcmpk Sfile1_new, Sfile1_old if kfile1 != 0 then ;IF A BANG HAD BEEN GENERATED IN THE LINE ABOVE reinit NEW_FILE1 ;REINITIALIZE FROM LABEL 'NEW_FILE1' endif Sfile2_new strcpy "" ;INIT TO EMPTY STRING Sfile2 invalue "_Browse2" Sfile2_old strcpyk Sfile2_new Sfile2_new strcpyk Sfile2 kfile2 strcmpk Sfile2_new, Sfile2_old if kfile2 != 0 then ;IF A BANG HAD BEEN GENERATED IN THE LINE ABOVE reinit NEW_FILE2 ;REINITIALIZE FROM LABEL 'NEW_FILE2' endif if gkinput=0 then aasigL, aasigR ins aasigL = aasigL*gkInGain aasigR = aasigR*gkInGain else NEW_FILE1: aasigL, aasigR FilePlay2 Sfile1, 1, 0, 1 rireturn endif if gkdetect=0 then acsigL, acsigR ins acsigL = acsigL*gkInGain acsigR = acsigR*gkInGain else NEW_FILE2: acsigL, acsigR FilePlay2 Sfile2, 1, 0, 1 rireturn endif ktrig changed gklook if ktrig=1 then reinit UPDATE endif UPDATE: ;ar compress aasig, acsig, kthresh, kloknee, khiknee, kratio, katt, krel, ilook aCompL compress aasigL, acsigL, gkthresh, gkloknee, gkhiknee, gkratio, gkatt, gkrel, i(gklook) aCompR compress aasigR, acsigR, gkthresh, gkloknee, gkhiknee, gkratio, gkatt, gkrel, i(gklook) rireturn outs (aCompL*gkgain)+(acsigL*gkDetGain), (aCompR*gkgain)+(acsigR*gkDetGain) endin instr 2 ;PRESETS outvalue "_SetPresetIndex", p4 endin ;INSTR | START | DURATION i 10 0 3600 ;GUI 326 411 1039 351 true 241 226 185 2 2 1037 348 {aa607456-d368-4d59-8497-d16d608404c3} true 0 0 center Liberation Sans 18 3 0 0 0 147 154 255 border 5 2 8 8 100 30 {24979132-c53f-4414-ac6b-6b4f503ecfe8} true 0 0 event 1.00000000 On / Off / i1 0 -1 true false 6 42 506 98 {cdc434d0-b9e7-4f6f-aa90-800ec76dced6} true 0 0 left Liberation Sans 16 3 0 0 0 255 255 255 border 3 1 _Browse1 10 103 170 30 {b9431a61-61f7-432b-bf6f-c47ddc7f9050} true 0 0 value 1.00000000 SynthPad.wav Browse Audio File / false false _Browse1 181 104 326 28 {68b5f90b-b78e-4581-b434-232db5f4c40f} true 0 0 left Liberation Sans 10 3 0 0 0 229 229 229 nobackground Input 331 61 120 30 {be1f1edc-082e-4433-a418-1e81baf4e305} true 0 0 Live Input 0 Audio File 1 1 false 8 78 120 30 {2c897206-0dbc-47b5-ba68-915d83839ab6} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Live_Gain 8 61 300 27 {304e78d8-b320-453a-b28f-86b0ca872b86} true 0 0 0.00000000 1.00000000 0.50000000 lin continuous -1.00000000 false Live_Gain 248 78 60 30 {94c7e961-7981-4d21-942f-80bcc647daf5} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 6 142 506 98 {f264412d-1014-4e65-bc0b-e8dabda1779d} true 0 0 left Liberation Sans 16 3 0 0 0 255 255 255 border 3 1 _Browse2 10 203 170 30 {fd6d018b-1bcd-43b4-88e9-f240b379d7d0} true 0 0 value 1.00000000 808loop.wav Browse Audio File / false false _Browse2 181 204 326 28 {8616b387-3762-43e0-9492-10006eb9c01f} true 0 0 left Liberation Sans 10 3 0 0 0 229 229 229 nobackground Detect 331 161 120 30 {78d0d7ed-0b48-41de-bec3-8b85723c1dd6} true 0 0 Live Input 0 Audio File 1 1 false 8 178 120 30 {5df5ef4b-3db4-4c45-a343-9a1a05ec99fb} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Detect_Gain 8 161 300 27 {59bb85ee-6e9a-4e00-9fd1-ace42baf2654} true 0 0 0.00000000 1.00000000 0.00000000 lin continuous -1.00000000 false Detect_Gain 248 178 60 30 {2c621be3-47b0-4dfd-9037-ef64aa6676df} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 513 42 520 302 {326530f7-646b-4eec-923b-c87806f17ed9} true 0 0 516 78 180 30 {640b50b7-7200-4f81-8394-89d9843ae939} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Gate_Threshold 516 61 500 27 {5585fa6f-0f63-4ac3-bf1b-809c2b1d9134} true 0 0 0.00000000 120.00000000 0.00000000 lin continuous -1.00000000 false Gate_Threshold 956 78 60 30 {b731b52e-e14a-476a-a583-f3b2bd885539} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 6 242 506 102 {557603bf-8a2a-4845-9090-466ac15ef873} true 0 0 left Liberation Sans 16 3 0 0 0 255 255 255 border 3 1 516 113 180 30 {989564b0-b237-4c22-9d10-b76b7c7e4e4c} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Low_Knee 516 96 500 27 {84cd664e-fb67-4dd4-aac3-adbcf2c81fe6} true 0 0 0.00000000 100.00000000 48.00000000 lin continuous -1.00000000 false Low_Knee 956 113 60 30 {ba8682a6-056f-4432-946b-4e3ee82c47a1} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 516 147 180 30 {76044785-79c4-4202-b7ce-07aee4868219} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 High_Knee 516 130 500 27 {0f952e77-ff9b-4621-b1af-23252bb9c2a6} true 0 0 0.00000000 100.00000000 60.00000000 lin continuous -1.00000000 false High_Knee 956 147 60 30 {7b92c0ca-2fe8-4b4f-9ed0-f618c1b3cb5c} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 516 182 180 30 {ca41878c-b561-486b-9cf9-d0da6b48448b} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Ratio 516 165 500 27 {2800fb88-347a-402c-88ed-fc97af6a36be} true 0 0 0.00000000 1.00000000 0.55199999 lin continuous -1.00000000 false Ratio_Value 956 182 60 30 {5d1ba94c-536a-4178-be6c-c0d9d2f75e3d} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 516 217 180 30 {cdd71125-b224-471a-9c41-9c05d8d28d0c} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Attack 516 200 500 27 {7a83bb1f-f25d-47e0-bf2d-9c5c86e0756b} true 0 0 0.00000000 1.00000000 0.22200000 lin continuous -1.00000000 false Attack_Value 956 217 60 30 {7f8d2709-bf8c-46ab-83f0-36fc620b0d56} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 516 252 180 30 {9519d46e-b6e4-422e-8653-ae5db12b1c04} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Release 516 235 500 27 {0f9b569d-7f5b-4540-a415-6fd6762f6fe9} true 0 0 0.00000000 1.00000000 0.66600001 lin continuous -1.00000000 false Release_Value 956 252 60 30 {df4e20a1-b9a6-46ca-bb02-911779f6b4b5} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 516 286 180 30 {1089c148-0c3a-497a-a8d5-a62e3d62ff54} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Look_Ahead 516 269 500 27 {cb90b71f-234b-4c3e-875b-ce04075ae3ee} true 0 0 0.00000000 1.00000000 0.10000000 lin continuous -1.00000000 false Look_Ahead 956 286 60 30 {54d08872-94cf-49c9-b64f-605fddc65867} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 516 321 180 30 {8c81bb50-0c7b-4902-9178-d05f83831ade} true 0 0 left Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Gain 516 304 500 27 {6ef7cd84-2fc3-4cb0-b69d-4d037f7406af} true 0 0 0.00000000 1.00000000 0.96399999 lin continuous -1.00000000 false Gain_Value 956 321 60 30 {9481489d-99dd-43af-8282-21a31584dd71} true 0 0 right Liberation Sans 9 3 0 0 0 255 255 255 noborder 1 1 47 280 100 30 {fd55c818-d471-4651-9897-987cd1ad2797} true 0 0 event 1.00000000 Compressor / i2 0 0 0 false false button1 156 280 100 30 {7cab7fde-7c56-4940-bef7-cb79e979fbc4} true 0 0 event 1.00000000 Expander / i2 0 0 1 false false 264 280 100 30 {0c604f4c-26b3-4cf9-84a2-7d962e5b21b6} true 0 0 event 1.00000000 Noise Gate / i2 0 0 2 false false button1 373 280 100 30 {56984bf7-2754-4d29-a8c2-5f1f99ab744a} true 0 0 event 1.00000000 Ducker / i2 0 0 3 false false 0.00000000 0 SynthPad.wav SynthPad.wav 1.00000000 0.50000000 0.50000000 0.500 808loop.wav 808loop.wav 1.00000000 0.00000000 0.00000000 0.000 0.00000000 0.00000000 0.000 48.00000000 48.00000000 48.000 60.00000000 60.00000000 60.000 0.55199999 5.00668192 5.007 0.22200000 0.00463611 0.005 0.66600001 0.09956787 0.100 0.10000000 0.10000000 0.100 0.96399999 1.52186573 1.522 0 1 0 0 0.00000000 0 SynthPad.wav SynthPad.wav 1.00000000 0.50000000 0.50000000 0.500 808loop.wav 808loop.wav 1.00000000 0.00000000 0.00000000 0.000 0.00000000 0.00000000 0.000 0.00000000 0.00000000 0.000 6.00000000 6.00000000 6.000 0.24800000 0.65612835 0.656 0.00100000 0.00100710 0.001 0.00100000 0.00100710 0.001 0.10000000 0.10000000 0.100 0.30399999 0.01008263 0.010 0 0 0 1 0.00000000 0 SynthPad.wav SynthPad.wav 1.00000000 0.50000000 0.50000000 0.500 808loop.wav 808loop.wav 1.00000000 0.00000000 0.00000000 0.000 80.00000000 80.00000000 80.000 48.00000000 48.00000000 48.000 60.00000000 60.00000000 60.000 0.31200001 1.00625920 1.006 0.22600000 0.00476477 0.005 0.66399997 0.09817593 0.098 0.10000000 0.10000000 0.100 0.95200002 1.38890934 1.389 0 0 0 1 0.00000000 0 SynthPad.wav SynthPad.wav 1.00000000 1.00000000 1.00000000 1.000 808loop.wav 808loop.wav 1.00000000 0.13000000 0.13000000 0.130 0.00000000 0.00000000 0.000 48.00000000 48.00000000 48.000 60.00000000 60.00000000 60.000 0.55199999 5.00668192 5.007 0.23000000 0.00489955 0.005 0.66600001 0.09956787 0.100 0.10000000 0.10000000 0.100 0.95800000 1.45400441 1.454 0 1 0 0