|
发表于 2013-12-12 17:57:55
|
显示全部楼层
附 录
用MATLAB仿真
[Y,FS,BITS]=wavread(‘wei’);
SIZ=wavread(‘wei’,’size’);
Time=1:SIZ(1);
Plot(time,Y);%画图波形图
Sound(Y,FS,BITS);%声音输出
n=SIZ(1);
X=Y;
for i=10001:n
Y(i)=X(i)+0.3*X(i-10000);%0.3即为衰减比例,10000即为延时长度
if Y(i)>1
Y(i)=1;
else
if Y(i)<-1
Y(i)=-1;
end
end
end
length(Y)
time=1:SIZ(1);
plot(time,Y);
sound(Y,FS,BITS);%声音输出
[Y,FS,BITS]=wavread(‘wei’);
SIZ=wavread(‘wei’,’size’);
Time=1:SIZ(1);
Plot(time,Y);%声音输出
n=SIZ(1);
X=Y;
for i=22051:n
Y(i)=Y(i)+0.7*X(i-22050);%0.7即为衰减比例,22050即为延时长度
if Y(i)>1
Y(i)=1;
else
if Y(i)<-1
Y(i)=-1;
End
End
End
Time=1:SIZ(1);
Plot(time,Y);
Sound(Y,FS,BITS);%声音输出
C语言 实现延时效果
#define delay_time 5000
#define BUFFER_SIZE delay_time+1
Int flag=1;
Int input,output;
Int n;
Int write_position=BUFFER_SIZE-1;
Int read_position=0;
Void main ()
{
for (n=0;n<BUFFER_SIZE;n++)
buffer[n]=0;
while(1)
{
Input=*(unsigned int*)0x021;
Output= buffer[read_position];
Output+=(input*22932)>>15;
Buffer[write_position]-=(output*9830)>>15;
*(unsigned int*)0x0023 =output;
/*calculate read position*/
Read_position++;
If (read_position>(BUFFER_SIZE-1))
Read_position=0;
/*calculate write position*/
Write_position++;
If(write_position>(BUFFER_SIZE-1))
Write_position=0;
}
}
C语言实现合唱效果
#define BUFFER_SIZE 8000
Int buffer[BUFFER_SIZE];
Int write_position=BUFFER_SIZE-1;
Int read_position;
Int ya1,output;
Int a;
Int depth=30;
Int delay=100;
Int rate=12;
Int pace , n;
Int step=1;
Int finaldelay;
Int input;
Void main()
{
Finaldelay=delay;
Pace=16000/(rate*depth);
While (1)
{
Input=*(volatile unsigned int*)0x021;
If (n==pace)
{n=0;
Finaldelay+=step;}
Else
n++;
if(finaldelay>=(depth+delay))
step=-1;
if(finaldelay<=(delay))
step=1;
read_position=(write_position-finaldelay+BUFFER_SIZE-1)%(BUFFER_SIZE-1);
ya1=buffer[read_position];
buffer[write_position]=input;
output=(ya1*29730)>>15;
output+=input;
if(output<=-32768){output=-32768;}
else
{if (output>=32767){output=32767;}}
*(volatile unsigned int*)0x0023=output;
Write_position++;
If(write_position>=BUFFER_SIZE-1)
{write_position=0;}
}
}
C语言实现混响效果
#define combdelay1 500
#define combdelay2 700
#define combdelay3 1020
#define combdelay4 1400
#define alldelay9 2600
#define alldelay10 1640
Int input ,sum;
Int y1,y2,y3,y4,y9,y10;
Int input;
Int buffer1[comdelay1];
Int buffer2[comdelay2];
Int buffer3[comdelay3];
Int buffer4[comdelay4];
Int buffer9[alldelay9];
Int buffer10[alldelay10];
Int write_position1=combdelay1-1;
Int write_position2=combdelay2-1;
Int write_position3=combdelay3-1;
Int write_position4=combdelay4-1;
Int write_position9=alldelay9-1;
Int write_position10=alldelay10-1;
Int read_position1=0;
Int read_position2=0;
Int read_position3=0;
Int read_position4=0;
Int read_position9=0;
Int read_position10=0;
Void main()
{
While(1)
{
Input=*(volatile unsigned int*)0x0021;
Y1=(buffer[read_position1]*22938)>>15;
Y1+=(buffer1[write_position1]*9830)>>15;
Buffer1[write_position1]=input;
Y2=(buffer2[read_position2]*21299)>>15;
Y2+=(buffer2[read_position2]*13107)>>15;
Buffer2[write_position2]=intput;
Y3=(buffer3[read_position3]*20316)>>15;
Y2+=(buffer3[read_position3]*24314)>>15;
Buffer3[write_position3]=intput;
Y4=(buffer4[read_position4]*19661)>>15;
Y4+=(buffer4[read_position4]*24019)>>15;
Buffer4[write_position4]=intput;
Sum=y1+y2+y3+y4;
If(sum<=-32768){sum=-32768;}
Else
{if(sum>=32767){sum=32767;}}
Y9=buffer9[read_position9];
Y9-=(sum*22938)>>15;
Buffer9[write_position9]=sum;
Buffer9[write_position9]+=(y9*22983)>>15;
Y10=buffer10[read_position10];
Y10-=(y9*22983)>>15;
Buffer10[write_position10]=y9;
Buffer10[write_position10]+=(y10*22938)>>15;
If(y9<=-32768) {y9=-32768;}
Else
{if(y9>=32767){y9=32767;}}
*(volatile unsigned int*)0x0023=y10;
Read_position1++;
If(read_position1>(combdelay1-1))
{read_position1=0;}
Read_position2++;
If(read_position2>(combdelay2-1))
{read_position2=0;}
Read_position3++;
If(read_position3>(combdelay3-1))
{read_position3=0;}
Read_position4++;
If(read_position4>(combdelay4-1))
{read_position4=0;}
Read_position9++;
If(read_position9>(alldelay9-1))
{read_position9=0;}
Read_position10++;
If(read_position10>(alldelay10-1))
{read_position10=0;}
Write_position1++;
If(write_posotion1>combdelay1-1))
Write_position1=0;
Write_position2++;
If(write_posotion2>combdelay2-1))
Write_position2=0;
Write_position3++;
If(write_posotion3>combdelay3-1))
Write_position3=0;
Write_position4++;
If(write_posotion4>combdelay4-1))
Write_position4=0;
Write_position9++;
If(write_posotion9>alldelay9-1))
Write_position9=0;
Write_position10++;
If(write_posotion10>alldelay10-1))
Write_position10=0;
} |
|