next SuperCollider: Procesador de efectos genérico
up Ejemplos en SuperCollider
previous SuperCollider: Compresión
  Índice General   Índice de Materias


SuperCollider: Reverberación


(
        // Reverberación

        var w;
        var caption1,caption2,caption3,captionfbSlider,captionddSlider;
        var in1Box,in2Box,in3Box,in4Box,captionSource;
        var applyBox;
        var captiongainSlider,gainSlider,gainNum;
        var captionreverbSlider,reverbSlider,reverbNum;
        var captionpredelaySlider,predelaySlider,predelayNum;
        var captionbwSlider,bwSlider,bwNum;
        var captiondecaySlider,decaySlider,decayNum;
        var captiondampingSlider,dampingSlider,dampingNum;
        var captionindiff1Slider,indiff1Slider,indiff1Num;
        var captionindiff2Slider,indiff2Slider,indiff2Num;
        var captiondecdiff1Slider,decdiff1Slider,decdiff1Num;
        var captiondecdiff2Slider,decdiff2Slider,decdiff2Num;
        var captionrate1Slider,rate1Slider,rate1Num;
        var captionrate2Slider,rate2Slider,rate2Num;
        var captionexcursionSlider,excursionSlider,excursionNum;
        var captiondecaytimeSlider,decaytimeSlider,decaytimeNum;

        
        var
view1,view2,view3,view4,captionview1,captionview2,captionview3,captionview4;
        var view5,view6,captionview5,captionview6;

        
        var diff1_coef_label,diff1_coef_box;
        var diff2_coef_label,diff2_coef_box;
        var diff3_coef_label,diff3_coef_box;
        var diff4_coef_label,diff4_coef_box;
        var decdiff1_coef_label,decdiff1_coef_box;
        var decdiff2_coef_label,decdiff2_coef_box;
        var decdiff3_coef_label,decdiff3_coef_box;
        var decdiff4_coef_label,decdiff4_coef_box;


        var filename, sound, signal;
        var fore_color;
        
        var attack_coef;
        var release_coef;
        
        var xoff1,xoff2,xoff3;
        var ftoW;
        
        // convert dB to amplitude
        
        var a_to_db;
        var dBtoA,dB_to_A;
        
        var convert_delay,convert_sample,revtime;
        var show_value_in_box;  
        
        dBtoA = { arg decibels;
                r = 0.5011872336;
                r*10**(decibels/20.0);};
                
     // 96 decibels scale
        dB_to_A = { arg decibels;
             r = 0.008229747050;        
                r*10**(decibels/20.0);};
                
        // 96 decibels scale
        a_to_db = { arg amp;
            r = 0.008229747050;
            20*log(amp/r);};
                        
        // Hertz to radian frequency
        ftoW = { arg hertz;
                2pi*(hertz/Synth.sampleRate);};
        
        
        
        // Convert samples to delay time
        revtime = {arg coef, delay;
                (-6.907755279*delay)/log(coef);};
                
        // Convert samples to 44.1 sampling rate
        convert_sample = {arg samples;
                (samples*(44100/29761)).ceil;}; 
        
        // Convert delays to 44.1 sampling rate
        convert_delay = {arg delay;
                delay/29761;};

        
        // Show any signal value on a number box                
        show_value_in_box = {arg input, box, period;
                Sequencer.kr({ var val;
                        val = input.poll;
                        box.value = val;
                        val
                }, Impulse.kr(period));};
        
        
        
        // GUI Window
        w = GUIWindow.new("Reverberator >>> Rodrigo F. Cadiz", Rect.newBy(200,
70, 850, 650));
        w.backColor = Color.new(99,130,160);
        
        
        // Offsets
        xoff1 = 10;
        xoff2 = 250;
        xoff3 = 550;
        
        // Colors
        fore_color = Color.new(255,255,0);
        
        // Various labels
        caption1 = StringView.new( w, Rect.newBy(xoff1, 10, 228, 20), "Advanced
Audio Signal Processing");
        caption1.labelColor = fore_color;
        caption2 = StringView.new( w, Rect.newBy(xoff1, 30, 328, 20),
"Assignment 4: Reverberator");
        caption2.labelColor = fore_color;
        caption3 = StringView.new( w, Rect.newBy(xoff1, 50, 128, 20), "Rodrigo
F. Cadiz");
        caption3.labelColor = fore_color;
        
        
        // Input Gain
        captiongainSlider = StringView.new( w, Rect.newBy(xoff2, 10, 235, 20),
"Dry gain [dB] "); 
     gainSlider = SliderView.new( w, Rect.newBy( xoff2, 30, 230, 20 ),
"Mix", -11, -60 , 6 , 1, 'linear');
     gainNum = NumericalView.new( w, Rect.newBy( xoff2+235, 30, 50, 20 ), 
"NumericalView", -11, -60, 6, 1, 'linear');
     gainNum.backColor = fore_color;
     gainSlider.action = { gainNum.value = gainSlider.value};
     
     
     // Reverb gain
        captionreverbSlider = StringView.new( w, Rect.newBy(xoff2, 60, 235, 20), 
"Reverb gain [dB]"); 
     reverbSlider = SliderView.new( w, Rect.newBy( xoff2, 80, 230, 20 ),
"Mix", 0, -60, 6 , 1, 'linear');
     reverbNum = NumericalView.new( w, Rect.newBy( xoff2+235, 80, 50, 20
), "NumericalView", 0, -60, 6, 1, 'linear');
     reverbNum.backColor = fore_color;
     reverbSlider.action = { reverbNum.value = reverbSlider.value};
     
          
     // Predelay
        captionpredelaySlider = StringView.new( w, Rect.newBy(xoff2, 110, 235,
20), "Predelay [s]"); 
     predelaySlider = SliderView.new( w, Rect.newBy( xoff2, 130, 230, 20
), "Mix", 0.0231, 0.0, 0.2 , 0.0001, 'linear');
     predelayNum = NumericalView.new( w, Rect.newBy( xoff2+235, 130, 50,
20 ), "NumericalView", 0.0231, 0.0, 0.2, 0.0001, 'linear');
     predelayNum.backColor = fore_color;
     predelaySlider.action = { predelayNum.value = predelaySlider.value};
     
     
     // Bandwidth
        captionbwSlider = StringView.new( w, Rect.newBy(xoff2, 160, 235, 20),
"Bandwidth "); 
     bwSlider = SliderView.new( w, Rect.newBy( xoff2, 180, 230, 20 ),
"Mix", 0.7995, 0.00001 , 0.99999 , 0.00001, 'linear');
     bwNum = NumericalView.new( w, Rect.newBy( xoff2+235, 180, 50, 20 ),
"NumericalView", 0.7995, 0.000001, 0.99999, 0.00001, 'linear');
     bwNum.backColor = fore_color;
     bwSlider.action = { bwNum.value = bwSlider.value};
        
        // Decay
        captiondecaySlider = StringView.new( w, Rect.newBy(xoff2, 210, 235, 20), 
"Decay factor"); 
     decaySlider = SliderView.new( w, Rect.newBy( xoff2, 230, 230, 20 ),
"Mix", 0.75, 0.0 , 1.0 , 0.0001, 'linear');
     decayNum = NumericalView.new( w, Rect.newBy( xoff2+235, 230, 50, 20
), "NumericalView", 0.75, 0.0, 1.0, 0.0001, 'linear');
     decayNum.backColor = fore_color;
     decaySlider.action = { decayNum.value = decaySlider.value};
                
        // Damping
        captiondampingSlider = StringView.new( w, Rect.newBy(xoff2, 260, 235,
20), "Damping "); 
     dampingSlider = SliderView.new( w, Rect.newBy( xoff2, 280, 230, 20
), "Mix", 0.3, 0.0 , 1.0 , 0.000001, 'linear');
     dampingNum = NumericalView.new( w, Rect.newBy( xoff2+235, 280, 50,
20 ), "NumericalView", 0.3, 0.0 ,1.0, 0.000001, 'linear');
     dampingNum.backColor = fore_color;
     dampingSlider.action = { dampingNum.value = dampingSlider.value};
                
        // Input diff 1
        captionindiff1Slider = StringView.new( w, Rect.newBy(xoff3, 10, 235,
20), "Input diff 1 "); 
     indiff1Slider = SliderView.new( w, Rect.newBy( xoff3, 30, 230, 20 ), 
"Mix", 0.945, 0.0 , 1.0 , 0.0001, 'linear');
     indiff1Num = NumericalView.new( w, Rect.newBy( xoff3+235, 30, 50, 20 
), "NumericalView", 0.945, 0.0, 1.0, 0.0001, 'linear');
     indiff1Num.backColor = fore_color;
     indiff1Slider.action = { indiff1Num.value = indiff1Slider.value};
     
        // Input diff 2
        captionindiff2Slider = StringView.new( w, Rect.newBy(xoff3, 60, 235,
20), "Input diff 2 "); 
     indiff2Slider = SliderView.new( w, Rect.newBy( xoff3, 80, 230, 20 ), 
"Mix", 0.915, 0.0 , 1.0 , 0.0001, 'linear');
     indiff2Num = NumericalView.new( w, Rect.newBy( xoff3+235, 80, 50, 20 
), "NumericalView", 0.915, 0.0, 1.0, 0.0001, 'linear');
     indiff2Num.backColor = fore_color;
     indiff2Slider.action = { indiff2Num.value = indiff2Slider.value};
          
        // Decay diff 1
        captiondecdiff1Slider = StringView.new( w, Rect.newBy(xoff3, 110, 235,
20), "Decay diff 1 "); 
     decdiff1Slider = SliderView.new( w, Rect.newBy( xoff3, 130, 230, 20
), "Mix", 0.965, 0.0 , 1.0 , 0.0001, 'linear');
     decdiff1Num = NumericalView.new( w, Rect.newBy( xoff3+235, 130, 50,
20 ), "NumericalView", 0.965, 0.0 , 1.0 , 0.0001, 'linear');
     decdiff1Num.backColor = fore_color;
     decdiff1Slider.action = { decdiff1Num.value = decdiff1Slider.value};
     
        // Decay diff 2
        captiondecdiff2Slider = StringView.new( w, Rect.newBy(xoff3, 160, 235,
20), "Decay diff 2 "); 
     decdiff2Slider = SliderView.new( w, Rect.newBy( xoff3, 180, 230, 20
), "Mix", 0.815, 0.25 , 0.85 , 0.0001, 'linear');
     decdiff2Num = NumericalView.new( w, Rect.newBy( xoff3+235, 180, 50,
20 ), "NumericalView", 0.815, 0.25 , 0.85 , 0.0001, 'linear');
     decdiff2Num.backColor = fore_color;
     decdiff2Slider.action = { decdiff2Num.value = decdiff2Slider.value};
     
     // Rate 1
        captionrate1Slider = StringView.new( w, Rect.newBy(xoff3, 210, 235, 20), 
"Osc. Rate 1 [Hz] "); 
     rate1Slider = SliderView.new( w, Rect.newBy( xoff3, 230, 230, 20 ),
"Mix", 0.032, 0.0 , 0.3 , 0.001, 'linear');
     rate1Num = NumericalView.new( w, Rect.newBy( xoff3+235, 230, 50, 20
), "NumericalView", 0.032, 0.0 ,0.3, 0.001, 'linear');
     rate1Num.backColor = fore_color;
     rate1Slider.action = { rate1Num.value = rate1Slider.value};
                
        // Rate 2
        captionrate1Slider = StringView.new( w, Rect.newBy(xoff3, 260, 235, 20), 
"Osc. Rate 2 [Hz]"); 
     rate2Slider = SliderView.new( w, Rect.newBy( xoff3, 280, 230, 20 ),
"Mix", 0.106, 0.0 , 0.3 , 0.001, 'linear');
     rate2Num = NumericalView.new( w, Rect.newBy( xoff3+235, 280, 50, 20
), "NumericalView", 0.106, 0.0 ,0.3, 0.001, 'linear');
     rate2Num.backColor = fore_color;
     rate2Slider.action = { rate2Num.value = rate2Slider.value};

        // Excursion
        captionexcursionSlider = StringView.new( w, Rect.newBy(xoff3, 310, 235,
20), "Excursion "); 
     excursionSlider = SliderView.new( w, Rect.newBy( xoff3, 330, 230, 20 
), "Mix", 11, 0, 16 , 1, 'linear');
     excursionNum = NumericalView.new( w, Rect.newBy( xoff3+235, 330, 50, 
20 ), "NumericalView", 11, 0 ,16, 1, 'linear');
     excursionNum.backColor = fore_color;
     excursionSlider.action = { excursionNum.value = excursionSlider.value};
                
                
        // Decay time
        captiondecaytimeSlider = StringView.new( w, Rect.newBy(xoff2, 310, 235,
20), "Decay time [s] "); 
     decaytimeSlider = SliderView.new( w, Rect.newBy( xoff2, 330, 230, 20 
), "Mix", 2.0, 0.01, 4.0 , 0.001, 'linear');
     decaytimeNum = NumericalView.new( w, Rect.newBy( xoff2+235, 330, 50, 
20 ), "NumericalView", 2.0, 0.01 ,4.0, 0.001, 'linear');
     decaytimeNum.backColor = fore_color;
     decaytimeSlider.action = { decaytimeNum.value = decaytimeSlider.value};    
        
        // Number boxes for variables

        diff1_coef_label = StringView.new( w, Rect.newBy(xoff1, 200, 150, 20),
"Input diff 1 [s]"); 
        diff1_coef_box = NumericalView.new( w, Rect.newBy( xoff1+160,200,50,20
), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');
        
        diff2_coef_label = StringView.new( w, Rect.newBy(xoff1, 220, 150, 20),
"Input diff 2 [s]"); 
        diff2_coef_box = NumericalView.new( w, Rect.newBy( xoff1+160,220,50,20
), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');    
        
        diff3_coef_label = StringView.new( w, Rect.newBy(xoff1, 240, 150, 20),
"Input diff 3 [s]"); 
        diff3_coef_box = NumericalView.new( w, Rect.newBy( xoff1+160,240,50,20
), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');
        
        diff4_coef_label = StringView.new( w, Rect.newBy(xoff1, 260, 150, 20),
"Input diff 4 [s]"); 
        diff4_coef_box = NumericalView.new( w, Rect.newBy( xoff1+160,260,50,20
), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');    
        
        decdiff1_coef_label = StringView.new( w, Rect.newBy(xoff1, 280, 150,
20), "Decay diff 1 [s]"); 
        decdiff1_coef_box = NumericalView.new( w, Rect.newBy(
xoff1+160,280,50,20 ), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');
        
        decdiff2_coef_label = StringView.new( w, Rect.newBy(xoff1, 300, 150,
20), "Decay diff 2 [s]"); 
        decdiff2_coef_box = NumericalView.new( w, Rect.newBy(
xoff1+160,300,50,20 ), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');        
        
        decdiff3_coef_label = StringView.new( w, Rect.newBy(xoff1, 320, 150,
20), "Decay diff 3 [s]"); 
        decdiff3_coef_box = NumericalView.new( w, Rect.newBy(
xoff1+160,320,50,20 ), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');
        
        decdiff4_coef_label = StringView.new( w, Rect.newBy(xoff1, 340, 150,
20), "Decay diff 4 [s]"); 
        decdiff4_coef_box = NumericalView.new( w, Rect.newBy(
xoff1+160,340,50,20 ), "amp", 0.0, 0.0, 10.0, 0.0001, 'linear');        
        
                
        // Apply compressor
     applyBox = CheckBoxView.new( w, Rect.newBy( xoff1, 77, 230, 20 ),
"Apply reverberation ", 1, 0, 1, 0, 'linear');
        
     // Select source
     captionSource = StringView.new( w, Rect.newBy(xoff1, 100, 235, 20),
"Select source"); 
     captionSource.labelColor = fore_color;     
     in1Box = CheckBoxView.new( w, Rect.newBy( xoff1, 120, 230, 20 ),
"Sound file ", 1, 0, 1, 0, 'linear');
     in2Box = CheckBoxView.new( w, Rect.newBy( xoff1, 140, 230, 20 ),
"Sinusoid", 0, 0, 1, 0, 'linear');
     in3Box = CheckBoxView.new( w, Rect.newBy( xoff1, 160, 230, 20 ),
"BrownNoise ", 0, 0, 1, 0, 'linear');
     in4Box = CheckBoxView.new( w, Rect.newBy( xoff1, 180, 230, 20 ),
"Impulses ", 0, 0, 1, 0, 'linear');


        // Scopes

        captionview1 = StringView.new( w, Rect.newBy(xoff1, 370, 235, 20),
"Original signal"); 
        view1 = ScopeView.new( w, Rect.newBy(xoff1, 395, 200, 100), 4410, -1, 1);

        captionview2 = StringView.new( w, Rect.newBy(xoff1, 500, 235, 20),
"Signal after BW filter"); 
        view2 = ScopeView.new( w, Rect.newBy(xoff1, 525, 200, 100), 4410, -1, 1);

        captionview3 = StringView.new( w, Rect.newBy(xoff2, 370, 235, 20),
"Signal after diffusors"); 
        view3 = ScopeView.new( w, Rect.newBy(xoff2, 395, 200, 100), 4410, -1, 1);

        //captionview4 = StringView.new( w, Rect.newBy(xoff2, 500, 235, 20),
"Compressed signal"); 
        //view4 = ScopeView.new( w, Rect.newBy(xoff2, 525, 200, 100), 4410, -1, 1);
        
        captionview5 = StringView.new( w, Rect.newBy(xoff3, 370, 235, 20), "Left 
channel output"); 
        view5 = ScopeView.new( w, Rect.newBy(xoff3, 395, 200, 100), 4410, -1, 1);

        captionview6 = StringView.new( w, Rect.newBy(xoff3, 500, 235, 20),
"Right channel output"); 
        view6 = ScopeView.new( w, Rect.newBy(xoff3, 525, 200, 100), 4410, -1, 1);
        
        filename = ":Sounds:redobles.aiff";
        sound = SoundFile.new;
        if (sound.read(filename), {
        
                Synth.play({
                        var signal;   // for audiofile stream
                        var input,input1,input2,input3,input4;    // for effects processor
                
                        var diff1,diff2,diff3,diff4;
                var decdiff1,decdiff2,decdiff3,decdiff4;                
                        var in2,in3,in4,in5,in6,in7,in8;
                        var outL,outL2,outL3,outL4,outL5,outL6,outL7,outL1;
                        var outR,outR2,outR3,outR4,outR5,outR6,outR7,outR1;
                        var outL8=0;
                        var outR8=0;
                        var osc1,osc2,osc3,osc4;
                        var buffer_left,buffer_right,delL,delR;

                
                        signal = sound.data.at(0);
                        
                        // Different sources
                        input1 = PlayBuf.ar(signal, sound.sampleRate, 1, 0, 0, signal.size-2); 
                        input2 = SinOsc.ar(200, 0.1);
                        input3 = BrownNoise.ar(0.1);
                        input4 = Impulse.ar(100,0.2);
                        
                        // Source mix
                        input = Mix.ar([input1 * in1Box.kr,
                                        input2 * in2Box.kr,
                                        input3 * in3Box.kr,
                                        input4 * in4Box.kr]);
                                        
                        
                
                        // Amplification factor
                        in2 = 1.0*input;
                        
                        // Predelay
                        in3 = DelayN.ar(in2,1.0,predelaySlider.kr);
                        
                        // First filter for bandwidth
                        in4 = OnePole.ar(in3,(1.0-bwSlider.kr));
                
                        
                        diff1 = revtime.value(indiff1Slider.kr,convert_delay.value(142));
                        diff2 = revtime.value(indiff1Slider.kr,convert_delay.value(107));
                        diff3 = revtime.value(indiff2Slider.kr,convert_delay.value(379));
                        diff4 = revtime.value(indiff2Slider.kr,convert_delay.value(277));
                        
                
                        // First diffusion filter
                        in5 = AllpassN.ar(in4,1.0,convert_delay.value(142),diff1);
                
                        // Second diffusion filter
                        in6 = AllpassN.ar(in5,1.0,convert_delay.value(107),diff2);
                        
                        // Third diffusion filter
                        in7 = AllpassN.ar(in6,1.0,convert_delay.value(379),diff3);
                        
                        // Fourth diffusion filter
                        in8 = AllpassN.ar(in7,1.0,convert_delay.value(277),diff4);
                
                
                        buffer_left = Signal.new(Synth.sampleRate*0.3);
                        buffer_right = Signal.new(Synth.sampleRate*0.3);                
                 
                        delL = TapN.ar(buffer_left,convert_delay.value(3720));
                        delR = TapN.ar(buffer_right,convert_delay.value(3163)); 
                        
                        decdiff1 =
revtime.value(decdiff1Slider.kr,convert_delay.value(672+excursionSlider.kr));
                        decdiff2 =
revtime.value(decdiff1Slider.kr,convert_delay.value(908+excursionSlider.kr));
                        decdiff3 = revtime.value(decdiff2Slider.kr,convert_delay.value(1800));
                        decdiff4 = revtime.value(decdiff2Slider.kr,convert_delay.value(2656));  
                        
                        outL2 =
AllpassN.ar(delL,1.0,convert_delay.value(672+excursionSlider.kr),decdiff1.neg);
                        outR2 =
AllpassN.ar(delR,1.0,convert_delay.value(908+excursionSlider.kr),decdiff2.neg);
                 
                        osc1 = SinOsc.kr(rate1Slider.kr,0.0,convert_delay.value(4453)*0.5);
                        osc2 = SinOsc.kr(rate2Slider.kr,0.0,convert_delay.value(4217)*0.5);
                        
                        outL3 = DelayN.ar(outL2,1.0,(convert_delay.value(4453)+osc1));
                        outR3 = DelayN.ar(outR2,1.0,(convert_delay.value(4217)+osc2));
                        
                        outL4 = OnePole.ar(outL3,dampingSlider.kr);
                        outR4 = OnePole.ar(outR3,dampingSlider.kr);
                        
                        outL5 = decaySlider.kr*outL4;
                        outR5 = decaySlider.kr*outR4;            
                   
                        outL6 =
decaySlider.kr*AllpassN.ar(outL5,1.0,convert_delay.value(1800),decdiff3);
                        outR6 =
decaySlider.kr*AllpassN.ar(outR5,1.0,convert_delay.value(2656),decdiff4);
                        
                        outL1 = dBtoA.value(reverbSlider.kr)*applyBox.kr*(in8 + outR6);
                        outR1 = dBtoA.value(reverbSlider.kr)*applyBox.kr*(in8 + outL6);
                                                
                        DelayWr.ar(buffer_left,outL1);
                        DelayWr.ar(buffer_right,outR1);
                        
                        
                        show_value_in_box.value(diff1,diff1_coef_box,7);
                        show_value_in_box.value(diff2,diff2_coef_box,7);
                        show_value_in_box.value(diff3,diff3_coef_box,7);
                        show_value_in_box.value(diff4,diff4_coef_box,7);
                                
                        show_value_in_box.value(decdiff1,decdiff1_coef_box,7);
                        show_value_in_box.value(decdiff2,decdiff2_coef_box,7);
                        show_value_in_box.value(decdiff3,decdiff3_coef_box,7);
                        show_value_in_box.value(decdiff4,decdiff4_coef_box,7);
        
                        
                        
                        Scope.ar(view1,input);
                        Scope.ar(view2,in4);
                        Scope.ar(view3,in8);
        
                        Scope.ar(view5,outL1);
                        Scope.ar(view6,outR1);
                        
                        [Mix.ar([dBtoA.value(gainSlider.kr)*input,outL1]),
                         Mix.ar([dBtoA.value(gainSlider.kr)*input,outR1])];
                        
                
                        });
                
                                
        },{ (filename ++ " not found.\n").post });
        
        w.close;



)


next SuperCollider: Procesador de efectos genérico
up Ejemplos en SuperCollider
previous SuperCollider: Compresión
  Índice General   Índice de Materias

Copyright © 2008-06-05
Rodrigo F. Cádiz   - Centro de Investigación en Tecnologías de Audio, Instituto de Música, Pontificia Universidad Católica de Chile