Wolfram 语言

计算音频

Shepard 音:音频错觉

创建一个音频错觉.

In[1]:=
Click for copyable input
range = 12; duration = 10; lfoFreq = .05; basePitch = 30; numOsc = 8; midiToFreq[m_] := 2^((m - 69)/12)*440.

创建坡道控制振荡器的频率和振幅.

In[2]:=
Click for copyable input
phasors = Table[AudioGenerator[{"Sawtooth", lfoFreq, 2. Pi/numOsc (i - 1.)}, duration, SampleRate -> 500]/2. + .5, {i, numOsc}]; AudioPlot[phasors, PlotLayout -> "Overlaid", PlotRange -> All]
Out[2]=

创建控制振荡器的频率. 频率间隔仅为 1 倍频程并以指数方式增加,从而使得音高为线性增加.

In[3]:=
Click for copyable input
freqs = Table[ midiToFreq[(phasors[[i]])*12*numOsc + basePitch], {i, numOsc}]; AudioPlot[freqs, PlotLayout -> "Overlaid", PlotRange -> All]
Out[3]=

创建控制振荡器的振幅. 当频率减至最小值时振幅为 0.

In[4]:=
Click for copyable input
amps = Cos[#*Pi - Pi/2.] & /@ phasors; AudioPlot[amps, PlotLayout -> "Overlaid", PlotRange -> All]
Out[4]=

显示振荡器频率和振幅间的关系.

In[5]:=
Click for copyable input
AudioPlot[AudioNormalize /@ {freqs[[2]], amps[[2]]}, PlotRange -> All]
Out[5]=

使用创建的频率和振幅合成一个振荡器库.

In[6]:=
Click for copyable input
res = Mean[ Table[amps[[i]] AudioGenerator[{"Sin", freqs[[i]]}], {i, numOsc}]]
Out[6]=
In[7]:=
Click for copyable input
Spectrogram[res, 8192, 4096, HannWindow, PlotRange -> {All, {0, 10000}}, ImageSize -> Medium]
Out[7]=

相关范例

de en es fr ja ko pt-br ru