<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform; Audio out Audio in No messages-odac -d
; -iadc -d ;;;RT audio I/O; For Non-realtime ouput leave only the line below:; -o biquad.wav -W ;;; for file output any platform</CsOptions><CsInstruments>; Initialize the global variables.sr=44100kr=4410ksmps=10nchnls=2; Instrument #1.instr1; Get the values from the score.dur:i=p3amp:i=p4cps:i=cpspch(p5)fco:k=p6rez:k=p7; Calculate the biquadratic filter's coefficients fcon:k=2*3.14159265*fco/sralpha:k=1-2*rez*cos(fcon)*cos(fcon)+rez*rez*cos(2*fcon)beta:k=rez*rez*sin(2*fcon)-2*rez*cos(fcon)*sin(fcon)gama:k=1+cos(fcon)m1:k=alpha*gama+beta*sin(fcon)m2:k=alpha*gama-beta*sin(fcon)den:k=sqrt(m1*m1+m2*m2)b0:k=1.5*(alpha*alpha+beta*beta)/denb1:k=b0b2:k=0a0:k=1a1:k=-2*rez*cos(fcon)a2:k=rez*rez; Generate an input signal.xn:a=vco(1,cps,1); Filter the input signal.yn:a=biquad(xn,b0,b1,b2,a0,a1,a2)yn*=amp/2outs(yn,yn)endin</CsInstruments><CsScore>; Table #1, a sine wave.f1016384101; Sta Dur Amp Pitch Fco Rezi10.01.0200006.001000.8i11.01.0200006.032000.95e</CsScore></CsoundSynthesizer>
Here is an example of the biquad opcode. It uses the file biquad.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform; Audio out Audio in No messages-odac -iadc -d ;;;RT audio I/O; For Non-realtime ouput leave only the line below:; -o biquad.wav -W ;;; for file output any platform</CsOptions><CsInstruments>; Initialize the global variables.sr=44100kr=4410ksmps=10nchnls=2; Instrument #1.instr1; Get the values from the score.idur=p3iamp=p4icps=cpspch(p5)kfco=p6krez=p7; Calculate the biquadratic filter's coefficients kfcon=2*3.14159265*kfco/srkalpha=1-2*krez*cos(kfcon)*cos(kfcon)+krez*krez*cos(2*kfcon)kbeta=krez*krez*sin(2*kfcon)-2*krez*cos(kfcon)*sin(kfcon)kgama=1+cos(kfcon)km1=kalpha*kgama+kbeta*sin(kfcon)km2=kalpha*kgama-kbeta*sin(kfcon)kden=sqrt(km1*km1+km2*km2)kb0=1.5*(kalpha*kalpha+kbeta*kbeta)/kdenkb1=kb0kb2=0ka0=1ka1=-2*krez*cos(kfcon)ka2=krez*krez; Generate an input signal.axnvco1,icps,1; Filter the input signal.aynbiquadaxn,kb0,kb1,kb2,ka0,ka1,ka2outsayn*iamp/2,ayn*iamp/2endin</CsInstruments><CsScore>; Table #1, a sine wave.f1016384101; Sta Dur Amp Pitch Fco Rezi10.01.0200006.001000.8i11.01.0200006.032000.95e</CsScore></CsoundSynthesizer>
Here is another example of the biquad opcode used for modal synthesis. It uses the file biquad-2-modern.csd. See the Modal Frequency Ratios appendix for other frequency ratios.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform; Audio out Audio in-odac
; -iadc ;;;RT audio I/O; For Non-realtime ouput leave only the line below:; -o biquad-2.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100kr=4410ksmps=10nchnls=2/* modal synthesis using biquad filters as oscillators Example by Scott Lindroth 2007 */instr1denom:i=sr*0.5ipulseSpd=p4cps:i=p5ipan=p6amp:i=p7modes:i=p8pulse:a=mpulse(amp,0)cps=cpspch(cps); filter gainamp1:i=600amp2:i=1000amp3:i=1000amp4:i=1000amp5:i=1000amp6:i=1000; resonancerpole1:i=0.99999rpole2:i=rpole1rpole3:i=rpole1rpole4:i=rpole1rpole5:i=rpole1rpole6:i=rpole1; modal frequenciesifmodes==1thenf1:i=cps*1;pot lidf2:i=cps*6.27f3:i=cps*3.2f4:i=cps*9.92f5:i=cps*14.15f6:i=cps*6.23else; ;modes != 1f1=cps*1;uniform wood barf2=cps*2.572f3=cps*4.644f4=cps*6.984f5=cps*9.723f6=cps*12.0endif; convert frequency to radian frequencytheta1:i=(f1/denom)*$M_PItheta2:i=(f2/denom)*$M_PItheta3:i=(f3/denom)*$M_PItheta4:i=(f4/denom)*$M_PItheta5:i=(f5/denom)*$M_PItheta6:i=(f6/denom)*$M_PI; calculate coefficientsb11:i=-2*rpole1*cos(theta1)b21:i=rpole1*rpole1b12:i=-2*rpole2*cos(theta2)b22:i=rpole2*rpole2b13:i=-2*rpole3*cos(theta3)b23:i=rpole3*rpole3b14:i=-2*rpole4*cos(theta4)b24:i=rpole4*rpole4b15:i=-2*rpole5*cos(theta5)b25:i=rpole5*rpole5b16:i=-2*rpole6*cos(theta6)b26:i=rpole6*rpole6;printk(1, b11);printk(1, b21); also try setting the -1 coeff. to 0, but be sure to scale down the amplitude!sin1:a=biquad(pulse*amp1,1,0,-1,1,b11,b21)sin2:a=biquad(pulse*amp2,1,0,-1,1,b12,b22)sin3:a=biquad(pulse*amp3,1,0,-1,1,b13,b23)sin4:a=biquad(pulse*amp4,1,0,-1,1,b14,b24)sin5:a=biquad(pulse*amp5,1,0,-1,1,b15,b25)sin6:a=biquad(pulse*amp6,1,0,-1,1,b16,b26)afin=(sin1+sin2+sin3+sin4+sin5+sin6)outs(afin*sqrt(ipan),afin*sqrt(1-ipan))endin</CsInstruments><CsScore>;ins st dur pulseSpd pch pan amp modesi101207.08900.72i1...7.091..i1...7.0910.5..i101208.03900.72i101208.0410.72i101208.0410.50.72i19..7.0890.2i1...7.091..i1...7.0910.5..i191208.01900.72i191208.0210.72i191208.0210.50.72e</CsScore></CsoundSynthesizer>
Here is another example of the biquad opcode used for modal synthesis. It uses the file biquad-2.csd. See the Modal Frequency Ratios appendix for other frequency ratios.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform; Audio out Audio in-odac -iadc ;;;RT audio I/O; For Non-realtime ouput leave only the line below:; -o biquad-2.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100kr=4410ksmps=10nchnls=2/* modal synthesis using biquad filters as oscillators Example by Scott Lindroth 2007 */instr1ipi=3.1415926idenom=sr*0.5ipulseSpd=p4icps=p5ipan=p6iamp=p7iModes=p8apulsempulseiamp,0icps=cpspch(icps); filter gainiamp1=600iamp2=1000iamp3=1000iamp4=1000iamp5=1000iamp6=1000; resonanceirpole1=0.99999irpole2=irpole1irpole3=irpole1irpole4=irpole1irpole5=irpole1irpole6=irpole1; modal frequenciesif(iModes==1)gotomodes1if(iModes==2)gotomodes2modes1:if1=icps*1;pot lidif2=icps*6.27if3=icps*3.2if4=icps*9.92if5=icps*14.15if6=icps*6.23gotonextPartmodes2:if1=icps*1;uniform wood barif2=icps*2.572if3=icps*4.644if4=icps*6.984if5=icps*9.723if6=icps*12.0gotonextPartnextPart:; convert frequency to radian frequencyitheta1=(if1/idenom)*ipiitheta2=(if2/idenom)*ipiitheta3=(if3/idenom)*ipiitheta4=(if4/idenom)*ipiitheta5=(if5/idenom)*ipiitheta6=(if6/idenom)*ipi; calculate coefficientsib11=-2*irpole1*cos(itheta1)ib21=irpole1*irpole1ib12=-2*irpole2*cos(itheta2)ib22=irpole2*irpole2ib13=-2*irpole3*cos(itheta3)ib23=irpole3*irpole3ib14=-2*irpole4*cos(itheta4)ib24=irpole4*irpole4ib15=-2*irpole5*cos(itheta5)ib25=irpole5*irpole5ib16=-2*irpole6*cos(itheta6)ib26=irpole6*irpole6;printk 1, ib 11;printk 1, ib 21; also try setting the -1 coeff. to 0, but be sure to scale down the amplitude!asin1biquadapulse*iamp1,1,0,-1,1,ib11,ib21asin2biquadapulse*iamp2,1,0,-1,1,ib12,ib22asin3biquadapulse*iamp3,1,0,-1,1,ib13,ib23asin4biquadapulse*iamp4,1,0,-1,1,ib14,ib24asin5biquadapulse*iamp5,1,0,-1,1,ib15,ib25asin6biquadapulse*iamp6,1,0,-1,1,ib16,ib26afin=(asin1+asin2+asin3+asin4+asin5+asin6)outsafin*sqrt(p6),afin*sqrt(1-p6)endin</CsInstruments><CsScore>;ins st dur pulseSpd pch pan amp Modesi101207.08900.72i1...7.091..i1...7.0910.5..i101208.03900.72i101208.0410.72i101208.0410.50.72i19..7.0890.2i1...7.091..i1...7.0910.5..i191208.01900.72i191208.0210.72i191208.0210.50.72e</CsScore></CsoundSynthesizer>