Sei sulla pagina 1di 12

//allpass

float *pwrap(int, float *, float *);


ab.c

// defined in dspl

float allpass(int D, float *w, float **p, float a, float x)


{
float y, s0, sD;
sD = *pwrap(D,w,*p+D);
s0 = x + a * sD;
y = -a * s0 + sD;
**p = s0;
*p = pwrap(D,w,--*p);
return y;
}
//allpass_tr
float *pwrap(int, float *, float *);
ab.c

// defined in dspl

float allpass_tr(int D, float *w, float **p, float a, float x)


{
float y, sD;
sD = *pwrap(D,w,*p+D);
y = sD - a*x;
**p = x + a*y;
*p = pwrap(D,w,--*p);
return y;
}

// allpass.c - allpass reverb with circular delay line - canonical realization


//
// from the I2SP book: http://www.ece.rutgers.edu/~orfanidi/intro2sp/
//
// 332:348 DSP Lab - Spring 2011 - S. J. Orfanidis
// --------------------------------------------------------------------------------#include "dsplab.h"

// DSK initialization declarations and function pro

totypes
// #include <math.h>, if necessary, or <stdio.h>, or <stdlib.h>
# define D 2500
short xL, xR, yL, yR;
// left and right input and output samples from/to
codec
// gain to demonstrate watch windows and GEL files (see templ
ate.gel)
float a=0.99;
float w[D+1];
float *p;
float allpass(int,float*,float**,float,float);
// --------------------------------------------------------------------------------// here, add more global variable declarations, #define's, #include's, etc.
// --------------------------------------------------------------------------------void main()
// main program executed first
{
int n;
for(n=0; n <= D; n++)
w[n]=0;
p=w;
initialize();

sampling_rate(8);
96 kHz
audio_source(LINE);
while(1);

// initialize DSK board and codec, define interrupts

// possible sampling rates: 8, 16, 24, 32, 44, 48,


// LINE or MIC for line or microphone input
// keep waiting for interrupt, then jump to isr()

}
interrupt void isr()
{
float x, y;
read_inputs(&xL, &xR); // read inputs from codec
x = (float) xL; // process left channel only
y = allpass(D,w,&p,a,x); // to be linked with main()
yL = yR = (short) y;
write_outputs(yL,yR); // write outputs to codec
return;
}

///Lowpass1
#include "dsplab.h"
// DSK initialization declarations and function pro
totypes
// #include <math.h>, if necessary, or <stdio.h>, or <stdlib.h>
short xL, xR, yL, yR,v0, v1=0;
from/to codec
float b0=0.495, b1=0.495;
s and GEL files (see template.gel)

// left and right input and output samples


// gain to demonstrate watch window

#define D 100
float a=0;
int on=1;
float w[D+1];
float *p;

// --------------------------------------------------------------------------------// here, add more global variable declarations, #define's, #include's, etc.
// --------------------------------------------------------------------------------void main()
// main program executed first
{
int n;
for(n=0; n <= D; n++)
w[n]=0;
p=w;
initialize();

sampling_rate(44.1);
8, 96 kHz
audio_source(LINE);
while(1);

// initialize DSK board and codec, define interrupts

// possible sampling rates: 8, 16, 24, 32, 44, 4


// LINE or MIC for line or microphone input
// keep waiting for interrupt, then jump to isr()

}
interrupt void isr()
routine
{
float x, y, sD, u;

// sample processing algorithm - interrupt service

read_inputs(&xL, &xR);

// read inputs from codec

if (on) {
x = (float) xL;

// process left channel only

sD = *pwrap(D,w,p+D);
v0 = a*v1 + sD;

// feedback filter G(z) = (b0 + b1*z^-1)/(1-a*

u = b0*v0 + b1*v1;
v1 = v0;

// feedback filter's output


// update feedback filter's delay

y = x+u;

// closed-loop output

z^-1)

*p = y;
p = pwrap(D,w,--p);
yL = yR = (short) y;
}
else
{yL=xL; yR=xR;}
write_outputs(yL,yR);

// write outputs to codec

return;
}

//Plain1

#include "dsplab.h"
// DSK initialization declarations and function pro
totypes
// #include <math.h>, if necessary, or <stdio.h>, or <stdlib.h>
short xL, xR, yL, yR;
codec
float g=1;
(see template.gel)
int D= 5000;
float a=0.25;
short fs;
float w[5001];

// left and right input and output samples from/to


// gain to demonstrate watch windows and GEL files

float *p;

// --------------------------------------------------------------------------------// here, add more global variable declarations, #define's, #include's, etc.
// --------------------------------------------------------------------------------void main()
// main program executed first
{
int n;
for(n=0; n <= D; n++)
w[n]=0;
p=w;
initialize();

sampling_rate(8);
96 kHz
audio_source(LINE);
while(1);

// initialize DSK board and codec, define interrupts

// possible sampling rates: 8, 16, 24, 32, 44, 48,


// LINE or MIC for line or microphone input
// keep waiting for interrupt, then jump to isr()

interrupt void isr()


routine
{
float sD, x, y;

// sample processing algorithm - interrupt service


// D-th state, input & output

read_inputs(&xL, &xR);

// read inputs from codec

x = (float) xL;

// process left channel only

sD = *pwrap(D,w,p+D);
y = x + a*sD;
*p = y;
p = pwrap(D,w,--p);

//
//
//
//

extract states relative to p


output sample
delay-line input
backshift pointer

yL = yR = (short) y;
write_outputs(yL,yR);
return;
}

// write outputs to codec

///---6.4

// schroeder.c - Schroeder's reverb using circular buffers


//
// 332:348 DSP Lab - Spring 2011 - S. J. Orfanidis
//
// --------------------------------------------------------------------------------#include "dsplab.h"

// init parameters and function prototypes

short xL, xR, yL, yR;

// input and output samples from/to codec

short fs = 44;

// sampling rate in kHz

#define
#define
#define
#define
#define
#define

D1
D2
D3
D4
D5
D6

1759*2
1949*2
2113*2
2293*2
307*2
313*2

#define a 0.5
float b1=1, b2=0.9, b3=0.8, b4=0.7;
float a1=a, a2=a, a3=a, a4=a, a5=a, a6=a;
float
float
float
float
float
float

w1[D1+1],
w2[D2+1],
w3[D3+1],
w4[D4+1],
w5[D5+1],
w6[D6+1],

*p1;
*p2;
*p3;
*p4;
*p5;
*p6;

float plain(int, float *, float **, float, float);


project
float allpass(int, float *, float **, float, float);

// must be added to

// --------------------------------------------------------------------------------void main()
{
int n;
for (n=0;
for (n=0;
for (n=0;
for (n=0;
for (n=0;
for (n=0;

n<=D1;
n<=D2;
n<=D3;
n<=D4;
n<=D5;
n<=D6;

n++)
n++)
n++)
n++)
n++)
n++)

w1[n]
w2[n]
w3[n]
w4[n]
w5[n]
w6[n]

=
=
=
=
=
=

0;
0;
0;
0;
0;
0;

p1 = w1; p2 = w2; p3 = w3; p4 = w4; p5 = w5; p6 = w6;


initialize();
s

// initialize DSK board and codec, define interrupt

sampling_rate(fs);
96 kHz
audio_source(MIC);
while(1);

// possible sampling rates: 8, 16, 24, 32, 44, 48,


// LINE or MIC for line or microphone input
// keep waiting for interrupt, then jump to isr()

}
// --------------------------------------------------------------------------------interrupt void isr()
// sample processing algorithm - interrupt service
routine
{
float x, x1, x2, x3, x4, x5, x6, y;
read_inputs(&xL, &xR);

// read inputs from codec

x = (float) (xL>>1);

// process left channel only

x1 = plain(D1, w1, &p1, a1, x);


x2 = plain(D2, w2, &p2, a2, x);
x3 = plain(D3, w3, &p3, a3, x);
x4 = plain(D4, w4, &p4, a4, x);
x5 = b1*x1 + b2*x2 + b3*x3 + b4*x4;
x6 = allpass(D5, w5, &p5, a5, x5);
y = allpass(D6, w6, &p6, a6, x6);

// your code goes here


yL = yR = (short) y;
write_outputs(yL,yR);

// write outputs to codec

return;
}
// ---------------------------------------------------------------------------------

//------6.5
//Plain1

#include "dsplab.h"
// DSK initialization declarations and function pro
totypes
// #include <math.h>, if necessary, or <stdio.h>, or <stdlib.h>

short xL, xR, yL, yR;


codec
float g=1;
(see template.gel)

// left and right input and output samples from/to


// gain to demonstrate watch windows and GEL files

float aL=0.2, aR=0.2, bL=0.8, bR=0.8, cL=0.5, cR=0.5, dL=0.5,dR=0.5;


#define L 3000
#define R 3000
#define a 0.25
short fs;
float wL[3001],wR[3001];
float *pL,*pR;

// --------------------------------------------------------------------------------// here, add more global variable declarations, #define's, #include's, etc.
// --------------------------------------------------------------------------------void main()
// main program executed first
{
int n;
for(n=0; n <= L; n++)
wL[n]=0;
pL=wL;
for(n=0; n <= R; n++)
wR[n]=0;
pR=wR;
initialize();

sampling_rate(8);
96 kHz
audio_source(LINE);
while(1);

// initialize DSK board and codec, define interrupts

// possible sampling rates: 8, 16, 24, 32, 44, 48,


// LINE or MIC for line or microphone input
// keep waiting for interrupt, then jump to isr()

interrupt void isr() // sample processing algorithm - interrupt service routine


{
float sL, sR;
read_inputs(&xL, &xR); // read inputs from codec
sL = *pwrap(L,wL,pL+L);
sR = *pwrap(R,wR,pR+R);
yL = cL*xL + sL;
yR = cR*xR + sR;
*pL = bL*xL + aL*sL + dR*sR;

*pR = bR*xR + aR*sR + dL*sL;


pL = pwrap(L,wL,--pL);
pR = pwrap(R,wR,--pR);
write_outputs(yL,yR); // write outputs to codec
return;
}

//-----6.6
//revdel
#include "dsplab.h"
// DSK initialization declarations and function pro
totypes
// #include <math.h>, if necessary, or <stdio.h>, or <stdlib.h>
short xL, xR, yL, yR;
codec
float g=1;
(see template.gel)

// left and right input and output samples from/to


// gain to demonstrate watch windows and GEL files

#define D 6000
#define a 0.5
float b=.5;
float c=1;
short fs;
float w[6001];
float *p;

// --------------------------------------------------------------------------------// here, add more global variable declarations, #define's, #include's, etc.
// --------------------------------------------------------------------------------void main()
// main program executed first
{
int n;
for(n=0; n <= D; n++)
w[n]=0;
p=w;
initialize();

// initialize DSK board and codec, define interrupts

sampling_rate(8);
96 kHz
audio_source(MIC);
while(1);

// possible sampling rates: 8, 16, 24, 32, 44, 48,


// LINE or MIC for line or microphone input
// keep waiting for interrupt, then jump to isr()

interrupt void isr()


routine
{
float sD, x, y;

// sample processing algorithm - interrupt service


// D-th state, input & output

read_inputs(&xL, &xR);

// read inputs from codec

x = (float) xL;

// process left channel only

sD = *pwrap(D,w,p+D);
y = c*x + sD;
*p = b*x + a*sD;
p = pwrap(D,w,--p);

// extract states relative to p


// output sample
// delay-line input
// backshift pointer

yL = yR = (short) y;
write_outputs(yL,yR);

// write outputs to codec

return;
}

//------6.7
//multidel
#include "dsplab.h"
// DSK initialization declarations and function pro
totypes
// #include <math.h>, if necessary, or <stdio.h>, or <stdlib.h>
short xL, xR, yL, yR;
codec
#define D1 5000
#define D2 2000
float a1=0.5;
float a2=0.4;
float b0=1;
float b1=0;
float b2=0;
float *p1, *p2;
float w1[D1+1];
float w2[D2+1];
short fs;

// left and right input and output samples from/to

// -----------------------------------------------------------------------------

----// here, add more global variable declarations, #define's, #include's, etc.
// --------------------------------------------------------------------------------void main()
{
int n;
initialize();
s

// main program executed first


// initialize DSK board and codec, define interrupt

sampling_rate(8);
// possible sampling rates: 8, 16, 24, 32, 44, 48,
96 kHz
audio_source(LINE);
// LINE or MIC for line or microphone input
for(n=0;n<=D1;n++){
w1[n]=0;
}
for(n=0;n<=D2;n++){
w2[n]=0;
}
p1=w1;
p2=w2;
while(1);

// keep waiting for interrupt, then jump to isr()

}
// ---------------------------------------------------------------------------------

interrupt void isr()


routine
{
float x, s1, s2, y;

// sample processing algorithm - interrupt service

read_inputs(&xL, &xR);

// read inputs from codec

x = (float) xL;

// process left channel only

s1 = *pwrap(D1, w1, p1+D1);


s2 = *pwrap(D2, w2, p2+D2);
y = b0*x + b1*s1 + b2*s2;
*p2 = s1 + a2*s2;
p2 = pwrap(D2, w2, --p2);
*p1 = x + a1*s1;
p1 = pwrap(D1, w1, --p1);
yL = yR = (short) y;
write_outputs(yL,yR);
return;
}

// write outputs to codec

Potrebbero piacerti anche