next SuperCollider: Compresión
up Ejemplos en SuperCollider
previous SuperCollider: Patrones
  Índice General   Índice de Materias


SuperCollider: Filtros bi-cuadráticos


(
        // Filtros biquad
        
        var w;
        var caption1,caption2,caption3,captionfbSlider,captionddSlider;
        var lpfBox,hpfBox,bpfBox,notchBox,peakingEQBox,lowShelfBox,highShelfBox;
        var in1Box,in2Box,in3Box,captionSource;
        var captiongainSlider,gainSlider,gainNum;
        var captionfilterSlider,filterSlider,filterNum;
        var captionshelfSlider,shelfSlider,shelfNum;
        var captionQSlider,qSlider,qNum;
        var captionOmegaSlider,omegaSlider,omegaNum;

        var filename, sound, signal;
        var fore_color;
        
        var xoff1,xoff2;
        var ftoW;
        
        // convert dB to amplitude
        var dBtoA;
        dBtoA = { arg decibels;
                r = 0.5011872336;
                r*10**(decibels/20.0);};
                        
        
        ftoW = { arg hertz;
                2pi*(hertz/Synth.sampleRate);};
        
        
        // GUI Window
        w = GUIWindow.new("First order biquad filters >>> Rodrigo F. Cadiz",
Rect.newBy(500, 70, 650, 400));
        w.backColor = Color.new(99,130,160);
        
        
        // Offsets
        xoff1 = 10;
        xoff2 = 350;
        
        // 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 2: Second order biquad filters");
        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),
"Input gain [dB] "); 
     gainSlider = SliderView.new( w, Rect.newBy( xoff2, 30, 230, 20 ),
"Mix", 0, -30 , 6 , 1, 'linear');
     gainNum = NumericalView.new( w, Rect.newBy( xoff2+235, 30, 50, 20 ), 
"NumericalView", 0, -30, 6, 1, 'linear');
     gainNum.backColor = fore_color;
     gainSlider.action = { gainNum.value = gainSlider.value};
     
     
     // Filter Gain
        captionfilterSlider = StringView.new( w, Rect.newBy(xoff2, 60, 235, 20), 
"Filter gain [dB] "); 
     filterSlider = SliderView.new( w, Rect.newBy( xoff2, 80, 230, 20 ),
"Mix", 0, -0.02 , 0.02 , 0.0001, 'linear');
     filterNum = NumericalView.new( w, Rect.newBy( xoff2+235, 80, 50, 20
), "NumericalView", 0, -0.02, 0.02, 0.0001, 'linear');
     filterNum.backColor = fore_color;
     filterSlider.action = { filterNum.value = filterSlider.value};
     
     
     // Shelf slope
        captionshelfSlider = StringView.new( w, Rect.newBy(xoff2, 110, 235, 20), 
"Shelf slope "); 
     shelfSlider = SliderView.new( w, Rect.newBy( xoff2, 130, 230, 20 ),
"Mix", 1, 0.001 , 2 , 0.001, 'exponential');
     shelfNum = NumericalView.new( w, Rect.newBy( xoff2+235, 130, 50, 20
), "NumericalView", 1, 0.001, 2, 0.001, 'exponential');
     shelfNum.backColor = fore_color;
     shelfSlider.action = { shelfNum.value = shelfSlider.value};
        
        // Omega
        captionOmegaSlider = StringView.new( w, Rect.newBy(xoff2, 160, 235, 20), 
"Cutoff frequency [Hz] "); 
     omegaSlider = SliderView.new( w, Rect.newBy( xoff2, 180, 230, 20 ),
"Mix", 400, 100 , 15000 , 10, 'exponential');
     omegaNum = NumericalView.new( w, Rect.newBy( xoff2+235, 180, 50, 20
), "NumericalView", 400, 100, 15000, 10, 'exponential');
     omegaNum.backColor = fore_color;
     omegaSlider.action = { omegaNum.value = omegaSlider.value};
                
        // Q
        captionQSlider = StringView.new( w, Rect.newBy(xoff2, 210, 235, 20), "Q "); 
     qSlider = SliderView.new( w, Rect.newBy( xoff2, 230, 230, 20 ),
"Mix", 0.5, 0.01 , 10.0 , 0.01, 'exponential');
     qNum = NumericalView.new( w, Rect.newBy( xoff2+235, 230, 50, 20 ),
"NumericalView", 0.5, 0.01 ,10.0, 0.01, 'exponential');
     qNum.backColor = fore_color;
     qSlider.action = { qNum.value = qSlider.value};
                
        lpfBox = CheckBoxView.new( w, Rect.newBy( xoff1, 90, 230, 20 ), "Low
pass ", 1, 0, 1, 0, 'linear');
        hpfBox = CheckBoxView.new( w, Rect.newBy( xoff1, 110, 230, 20 ), "High
pass ", 0, 0, 1, 0, 'linear');
        bpfBox = CheckBoxView.new( w, Rect.newBy( xoff1, 130, 230, 20 ), "Band
pass ", 0, 0, 1, 0, 'linear');
        notchBox = CheckBoxView.new( w, Rect.newBy( xoff1, 150, 230, 20 ),
"Notch  ", 0, 0, 1, 0, 'linear');
        peakingEQBox = CheckBoxView.new( w, Rect.newBy( xoff1, 170, 230, 20 ),
"PeakingEQ ", 0, 0, 1, 0, 'linear');
        lowShelfBox = CheckBoxView.new( w, Rect.newBy( xoff1, 190, 230, 20 ),
"Low Shelf ", 0, 0, 1, 0, 'linear');
        highShelfBox = CheckBoxView.new( w, Rect.newBy( xoff1, 210, 230, 20 ),
"High Shelf ", 0, 0, 1, 0, 'linear');
        
        lpfBox.action = {
             lpfBox.value = 1.0;
                hpfBox.value = 0.0;
                bpfBox.value = 0.0;
                notchBox.value = 0.0;
                peakingEQBox.value = 0.0;
                lowShelfBox.value = 0.0;
                highShelfBox.value = 0.0;};     
                
        hpfBox.action = {
             lpfBox.value = 0.0;
                hpfBox.value = 1.0;
                bpfBox.value = 0.0;
                notchBox.value = 0.0;
                peakingEQBox.value = 0.0;
                lowShelfBox.value = 0.0;
                highShelfBox.value = 0.0;};                     
        
        bpfBox.action = {
             lpfBox.value = 0.0;
                hpfBox.value = 0.0;
                bpfBox.value = 1.0;
                notchBox.value = 0.0;
                peakingEQBox.value = 0.0;
                lowShelfBox.value = 0.0;
                highShelfBox.value = 0.0;};     
                
        notchBox.action = {
             lpfBox.value = 0.0;
                hpfBox.value = 0.0;
                bpfBox.value = 0.0;
                notchBox.value = 1.0;
                peakingEQBox.value = 0.0;
                lowShelfBox.value = 0.0;
                highShelfBox.value = 0.0;};     
        
        peakingEQBox.action = {
             lpfBox.value = 0.0;
                hpfBox.value = 0.0;
                bpfBox.value = 0.0;
                notchBox.value = 0.0;
                peakingEQBox.value = 1.0;
                lowShelfBox.value = 0.0;
                highShelfBox.value = 0.0;};
        
        lowShelfBox.action = {
             lpfBox.value = 0.0;
                hpfBox.value = 0.0;
                bpfBox.value = 0.0;
                notchBox.value = 0.0;
                peakingEQBox.value = 0.0;
                lowShelfBox.value = 1.0;
                highShelfBox.value = 0.0;};
        
        highShelfBox.action = {
             lpfBox.value = 0.0;
                hpfBox.value = 0.0;
                bpfBox.value = 0.0;
                notchBox.value = 0.0;
                peakingEQBox.value = 0.0;
                lowShelfBox.value = 0.0;
                highShelfBox.value = 1.0;};
        
     // Select source
      captionSource = StringView.new( w, Rect.newBy(xoff2, 250, 235, 20), 
"Select source"); 
      captionSource.labelColor = fore_color;    
        in1Box = CheckBoxView.new( w, Rect.newBy( xoff2, 270, 230, 20 ), "Sound
file ", 1, 0, 1, 0, 'linear');
        in2Box = CheckBoxView.new( w, Rect.newBy( xoff2, 290, 230, 20 ),
"LFSaw", 0, 0, 1, 0, 'linear');
        in3Box = CheckBoxView.new( w, Rect.newBy( xoff2, 310, 230, 20 ),
"BrownNoise ", 0, 0, 1, 0, 'linear');



        
        filename = ":Sounds:redobles.aiff";
        sound = SoundFile.new;
        if (sound.read(filename), {
        
                Synth.dualScope({
                        var signal;   // for audiofile stream
                        var input,input1,input2,input3;    // for effects processor
                        var
lpf_sig,hpf_sig,bpf_sig,notch_sig,peakingEQ_sig,lowShelf_sig,highShelf_sig;
                        
                        
                        signal = sound.data.at(0);
                        
                        // Different sources
                        input1 = PlayBuf.ar(signal, sound.sampleRate, 1, 0, 0,
signal.size-2)*dBtoA.value(gainSlider.kr); 
                        input2 = LFSaw.ar(200, 0.1)*dBtoA.value(gainSlider.kr);
                        input3 = BrownNoise.ar(0.1)*dBtoA.value(gainSlider.kr);
                        
                        // Source mix
                        input = Mix.ar([input1 * in1Box.kr,
                                        input2 * in2Box.kr,
                                        input3 * in3Box.kr]);
                                        
                        
                        
                        // LPF
                        
                        lpf_sig = Pause.ar({
                                var alpha,sn,cs;
                                var a0,a1,a2,b0,b1,b2;
                                sn = sin(ftoW.value(omegaSlider.kr));
                                cs = cos(ftoW.value(omegaSlider.kr));
                                alpha = sn/(2*qSlider.kr);
                                
                                
                                b0 = 1 + alpha;
                                b1 = (-2*cs)/b0;
                                b2 = (1 - alpha)/b0;
                                a0 = (1 - cs)/(2*b0);
                                a1 = (1 - cs)/b0;
                                a2 = (1 - cs)/(2*b0);
                                
                                SOS.ar(input, a0, a1, a2, b1.neg, b2.neg);} , lpfBox.kr(0));
                        
                        
                        
                                
                        // HPF
                        
                        hpf_sig = Pause.ar({
                                var alpha,sn,cs;
                                var a0,a1,a2,b0,b1,b2;
                                sn = sin(ftoW.value(omegaSlider.kr));
                                cs = cos(ftoW.value(omegaSlider.kr));
                                alpha = sn/(2*qSlider.kr);
                                
                                
                                b0 = 1 + alpha;
                                b1 = (-2*cs)/b0;
                                b2 = (1 - alpha)/b0;
                                a0 = (1 + cs)/(2*b0);
                                a1 = (1 + cs).neg/b0;
                                a2 = (1 + cs)/(2*b0);
                                
                                SOS.ar(input, a0, a1, a2, b1.neg, b2.neg);} , hpfBox.kr(0));
                                
                                
                        // BPF
                        
                        bpf_sig = Pause.ar({
                                var alpha,sn,cs;
                                var a0,a1,a2,b0,b1,b2;
                                sn = sin(ftoW.value(omegaSlider.kr));
                                cs = cos(ftoW.value(omegaSlider.kr));
                                alpha = sn/(2*qSlider.kr);
                                
                                
                                b0 = 1 + alpha;
                                b1 = (-2*cs)/b0;
                                b2 = (1 - alpha)/b0;
                                a0 = alpha/b0;
                                a1 = 0;
                                a2 = alpha.neg/b0;
                                
                                SOS.ar(input, a0, a1, a2, b1.neg, b2.neg);} , bpfBox.kr(0));    
                        
                        
                        // NOTCH
                        
                        notch_sig = Pause.ar({
                                var alpha,sn,cs;
                                var a0,a1,a2,b0,b1,b2;
                                sn = sin(ftoW.value(omegaSlider.kr));
                                cs = cos(ftoW.value(omegaSlider.kr));
                                alpha = sn/(2*qSlider.kr);
                                
                                
                                b0 = 1 + alpha;
                                b1 = (-2*cs)/b0;
                                b2 = (1 - alpha)/b0;
                                a0 = 1/b0;
                                a1 = (-2*cs)/b0;
                                a2 = 1/b0;
                                
                                SOS.ar(input, a0, a1, a2, b1.neg, b2.neg);} , notchBox.kr(0));  
                        
                        // PEAKINGEQ
                        
                        peakingEQ_sig = Pause.ar({
                                var alpha,sn,cs,a;
                                var a0,a1,a2,b0,b1,b2;  
                                sn = sin(ftoW.value(omegaSlider.kr));
                                cs = cos(ftoW.value(omegaSlider.kr));
                                alpha = sn/(2*qSlider.kr);
                                a = 10**(filterSlider.kr/40.0);
                                
                                b0 = 1 + alpha/a;
                                b1 = (-2*cs)/b0;
                                b2 = (1 - alpha/a)/b0;
                                a0 = (1 + alpha*a)/b0;
                                a1 = (-2*cs)/b0;
                                a2 = (1 - alpha*a)/b0;
                                
                                SOS.ar(input, a0, a1, a2, b1.neg, b2.neg);} , peakingEQBox.kr(0));      
                                        
                
                        // LOWSHELF
                        
                        lowShelf_sig = Pause.ar({
                                var alpha,beta,sn,cs,a;
                                var a0,a1,a2,b0,b1,b2;  
                                sn = sin(ftoW.value(omegaSlider.kr));
                                cs = cos(ftoW.value(omegaSlider.kr));
                                alpha = sn/(2*qSlider.kr);
                                a = 10**(filterSlider.kr/40.0);
                                beta = sqrt((a**2 + 1)/shelfSlider.kr - (a - 1)**2);
                                
                                b0 =        (a + 1) + (a - 1)*cs + beta*sn;
                                b1 =   (-2*((a - 1) + (a + 1)*cs ))/b0;
                                b2 =       ((a + 1) + (a - 1)*cs - beta*sn)/b0;
                                a0 =     a*((a + 1) - (a - 1)*cs + beta*sn)/b0;
                                a1 =  (2*a*((a - 1) - (a + 1)*cs ))/b0;
                                a2 =     a*((a + 1) - (a - 1)*cs - beta*sn)/b0;
                                
                                SOS.ar(input, a0, a1, a2, b1.neg, b2.neg);} , lowShelfBox.kr(0));               
                        
                        
                        // HIGHSHELF
                        
                        highShelf_sig = Pause.ar({
                                var alpha,beta,sn,cs,a;
                                var a0,a1,a2,b0,b1,b2;  
                                sn = sin(ftoW.value(omegaSlider.kr));
                                cs = cos(ftoW.value(omegaSlider.kr));
                                alpha = sn/(2*qSlider.kr);
                                a = 10**(filterSlider.kr/40.0);
                                beta = sqrt((a**2 + 1)/shelfSlider.kr - (a - 1)**2);
                                
                                b0 =        (a + 1) - (a - 1)*cs + beta*sn;
                                b1 =    (2*((a - 1) - (a + 1)*cs ))/b0;
                                b2 =       ((a + 1) - (a - 1)*cs - beta*sn)/b0;
                                a0 =     a*((a + 1) + (a - 1)*cs + beta*sn)/b0;
                                a1 = (-2*a*((a - 1) + (a + 1)*cs ))/b0;
                                a2 =     a*((a + 1) + (a - 1)*cs - beta*sn)/b0;
                                
                                SOS.ar(input, a0, a1, a2, b1.neg, b2.neg);} , highShelfBox.kr(0));              
                        
                        
                        Mix.ar([lpf_sig,hpf_sig,bpf_sig,notch_sig,peakingEQ_sig,lowShelf_sig,highShelf_sig]);
                        
                
                        },0.1);
                
                                
        },{ (filename ++ " not found.\n").post });
        
        w.close;



)


next SuperCollider: Compresión
up Ejemplos en SuperCollider
previous SuperCollider: Patrones
  Í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