默认采样率
这个波的震动并没有声音,因为他太短了,所以听不到
1hz,次声波,我们人耳听不到,所以要想办法增加周期
音乐里边有标准音高
440
Fs=8192;
>> x=linspace(0,2*pi,Fs);
>> y=sin(x);
>> plot(x,y);
>> sound(y,Fs);
>> y=sin(440*x);
>> plot(x,y);
>> sound(y,Fs);
>> sound(y,Fs);
>>
这个有声音,哈哈哈,激动。
——————————————————————
声音的采样率不会对声音产生影响
所以唯一对声音产生影响的是它的频率
——————————————————————————————————————————————————————————————————————————
十二平均律
一个八度,那几个do re mi fa so la si 过一遍就是一个八度
这七个音都可以发出来
Fs=8192;
>> x=linspace(0,2*pi,Fs);
>> y1=sin(440*x);
>> y2=sin(500*x);
>> freqs=[523,587,659,698,783,880,988];
>> y1=sin(freqs(1)*x);
>> y2=sin(freqs(2)*x);
>> y3=sin(freqs(3)*x);
>>
>> y4=sin(freqs(4)*x);
>> y5=sin(freqs(5)*x);
>> y6=sin(freqs(6)*x);
>> y7=sin(freqs(7)*x);
>> y=[y1,y2,y3,y4,y5,y6,y7];
>> sound(y,Fs)
一闪一闪亮晶晶
Fs=8192;
x=linspace(0,2*pi,Fs);
freqs=[523,587,659,698,783,880,988];
y1=sin(freqs(1)*x) .* (1-x/(2*pi));
y2=sin(freqs(1)*x) .* (1-x/(2*pi));
y3=sin(freqs(5)*x) .* (1-x/(2*pi));
y4=sin(freqs(5)*x) .* (1-x/(2*pi));
y5=sin(freqs(6)*x) .* (1-x/(2*pi));
y6=sin(freqs(6)*x) .* (1-x/(2*pi));
y7=sin(freqs(5)*x) .* (1-x/(2*pi));
y8=sin(freqs(5)*x);
y=[y1,y2,y3,y4,y5,y6,y7,y8];
%plot(y)
sound(y,Fs);
本次终极版
调用函数
Fs=8192;
y1=gen_wave(1,0.5);
y2=gen_wave(1,0.5);
y3=gen_wave(5,0.5);
y4=gen_wave(5,0.5);
y5=gen_wave(6,0.5);
y6=gen_wave(6,0.5);
y7=gen_wave(5,1);
y=[y1,y2,y3,y4,y5,y6,y7];
y1=gen_wave(4,0.5);
y2=gen_wave(4,0.5);
y3=gen_wave(3,0.5);
y4=gen_wave(3,0.5);
y5=gen_wave(2,0.5);
y6=gen_wave(2,0.5);
y7=gen_wave(1,1);
y=[y,y1,y2,y3,y4,y5,y6,y7];
%plot(y)
sound(y,Fs);
被调用函数
function y=gen_wave(tone,rythm)
Fs=8192;
freqs=[523,587,659,698,783,880,988];
x=linspace(0,2*pi*rythm,floor(Fs*rythm));
y=sin(freqs(tone)*x).*(1-x/(rythm*2*pi));
end
看下图形
声音效果
littlestar音乐