根据乐谱合成钢琴音乐
1 钢琴音乐合成原理和方法
决定乐器音色的主要因素为谐波特征,因此,在获得了音符基频之后合成钢琴音乐需要按照钢琴的谐波特征进行。本次实验首先分析钢琴部分音符的频域包络和时域包络,得到其频域谐频与基频的关系以及时域声音强度衰减的特征规律,让后根据此特征并结合已知的音乐基频合成钢琴音乐。
分别分析钢琴Do ReMi Fa四个音的频谱,即对四个实录音符做fft在求模,得到的下面四幅图:
分别计算各个音符2~15次谐频与基频的比例关系,取平均值,得到的平均比例关系为钢琴音符频域包络特征。最终得到的1~15谐波与基频的比例关系如下:
[1,0.340,0.102,0.085,0.070,0.065,0.028,0.085,0.011,0.030,0.010,0.014,0.012,0.013,0.004]
关于乐谱与基频的关系可以参考百度文库中的一个表格:http://wenku.baidu.com/link?url=Comd7xeOv_4fFKFTyirgfMYWd_-xh26-DNc7KLliNLVMTtObrkZOf2IFp31hY8p95T0TGBXsx-_iYilwvXT81j0ODifO4Ki9tiidO4rPvPy
在分析钢琴音符的时域包络,即衰减特征,可以得到其包络如下图:
得到了钢琴音色的频域和时域特征之后根据2.8中时频分析得到的各个时间段的音符基频和持续时间就可以合成模拟的钢琴音乐。在合成每个音时的主要方法,是先根据谐波与基频的比例特征生成15个正弦波并累加,然后根据每个音的持续时间对其在时域进行衰减。
2实验结果
本实验模拟的钢琴频域和时域特征如下图所示:
最后合成的钢琴音乐波形如下图所示:
通过输出的音乐文件pianomusic.wav可以听到合成音乐的效果。必须要承认,该合成效果与真正的钢琴声音又差别,误差主要是由谐波数量以及比例关系的精度造成的。另外,该钢琴音乐与给定的吉他音乐在旋律上也有差别,主要是音符提取精度不足造成的。
3代码(python)
# TO DO: reform it into piano
#-----------------------------------------
def gen_sin(amp, f, fs, tau):
nT = np.linspace(0,tau, round(tau/(1.0/fs)))
signal =np.array([amp*np.cos(2*np.pi*f*t) for t in nT])
return signal
#model the harmonic feature in frequency domain
Amp=[1,0.340,0.102,0.085,0.070,0.065,0.028,0.085,0.011,0.030,0.010,0.014,0.012,0.013,0.004]
numharmonic=len(Amp)
pianomusic=[0 for x in range(0,len(wave_data[0]))]
startpoint=0
#model the piano note attenuation feature in the time domain
attenuation=[0 for x in range(0, 8000)]
#the attack stage
for i in range(0,200):
attenuation[i]=i*0.005
#the attenuate stage
for i in range(200,800):
attenuation[i]=1-(i-200)*0.001
#the maintain stage
for i in range(800,4000):
attenuation[i]=0.4-(i-800)*0.000078
for i in range(4000,8000):
attenuation[i]=0.15-(i-4000)*0.0000078
#compose each note in each time quantum
#nomalizedbasicfreq=[261.63,261.63,261.63,261.63,293.665,293.665,293.665,293.665,329.628,329.628,329.628,329.628,349.228,349.228,349.228,349.228,391.995,391.995,391.995,391.995,440,440,440,440,493.883,493.883,493.883,493.883,523.251,523.251,523.251,523.251,587.33,587.33,587.33,587.33,659.255,659.255,659.255,659.255]
#notestime=[4,4,4,4,4,4,4,4,4,4]
for w in range(0,len(notestime)):
pianonote = [0 for x in range(0, windowsize*notestime[w])] #get the length according to the time of the note
for i in range(0, numharmonic): #get the note by add each harmonic by the amplitude comparatively with the basic frequency
pianonote = pianonote + gen_sin(ampli[startpoint] /50* Amp[i], nomalizedbasicfreq[startpoint] * (i + 1), 8000, 0.125*notestime[w])
#attenuate the note with the time domain feature
for k in range(0,windowsize*notestime[w]):
pianomusic[startpoint*windowsize+k]=pianonote[k]*attenuation[k]
startpoint=startpoint+notestime[w] #record the start point of the next note
startpoint=0
for w in range(0,len(notestime1)):
pianonote = [0 for x in range(0, windowsize*notestime1[w])] #get the length according to the time of the note
for i in range(0, numharmonic): #get the note by add each harmonic by the amplitude comparatively with the basic frequency
pianonote = pianonote + gen_sin(ampli1[startpoint] /50 * Amp[i], basicfreq1[startpoint] * (i + 1), 8000, 0.125*notestime1[w])
#attenuate the note with the time domain feature
for k in range(0,windowsize*notestime1[w]):
pianomusic[startpoint*windowsize+k]=pianomusic[startpoint*windowsize+k]+pianonote[k]*attenuation[k]
startpoint=startpoint+notestime1[w] #record the start point of the next note
startpoint=0
for w in range(0,len(notestime2)):
pianonote = [0 for x in range(0, windowsize*notestime2[w])] #get the length according to the time of the note
for i in range(0, numharmonic): #get the note by add each harmonic by the amplitude comparatively with the basic frequency
pianonote = pianonote + gen_sin(ampli2[startpoint] /100 * Amp[i], basicfreq2[startpoint] * (i + 1), 8000, 0.125*notestime2[w])
#attenuate the note with the time domain feature
#for k in range(0,windowsize*notestime2[w]):
# pianomusic[startpoint*windowsize+k]=pianomusic[startpoint*windowsize+k]+pianonote[k]*attenuation[k]
startpoint=startpoint+notestime2[w] #record the start point of the next note
for i in range(0,len(wave_data[0])):
wave_data[0][i]=pianomusic[i]
#get a wave file
f = wave.open(r"pianomusic.wav", "wb")
#get the channel, sampling width and sampling frequency information
#see details in 2.9 of my report
f.setnchannels(1)
f.setsampwidth(2)
f.setframerate(8000)
f.writeframes(wave_data[0].tostring()) #put the data into the wave file
f.close()
print("STEP 9: please see in figure and listen the pianomusic.wav file")
plt.figure()
plt.subplot(211)
plt.plot(Amp)
plt.title(r'frequency domain harmonic feature')
plt.subplot(212)
plt.plot(attenuation)
plt.title(r'time domain attenuation feature')
plt.figure()
plt.plot(pianomusic)
plt.title(r'STEP 9:reform it into piano')
plt.show()
根据乐谱合成钢琴音乐相关推荐
- 膨胀卷积神经网络_用膨胀的卷积神经网络生成钢琴音乐
膨胀卷积神经网络 介绍 (Introduction) Fully convolutional neural networks consisting of dilated 1D convolutions ...
- 计算机弹钢琴的音乐音符,钢琴音乐谱曲基础知识
钢琴音乐谱曲基础知识 在音乐艺术中,钢琴具有其它乐器不可取代的地位.从1709年,第一台钢琴的出现经过了约三百年的历程,在这期间,钢琴发生了许多变化,其音色亮丽.动人,擅长演奏各种风格的音乐,其演奏风 ...
- grasps元素_从玛祖卡舞曲肖邦钢琴音乐中民族元素的运用.pdf
从玛祖卡舞曲肖邦钢琴音乐中民族元素的运用 THE ADOPTION0F TRADITIONAL POLANDFOLKMUSIC INPIANO COMPOSITIONOF CHOPIN'SMAZURK ...
- 计算机乐谱弱点,钢琴老师眼中的谱子VS学生眼中的谱子
眼看乐谱,少看键盘和手 看谱的过程是眼脑手耳并用.协调的过程.在眼睛看到乐谱,通过大脑的思考,把信息传递给手指,手指在键盘上弹出声音这个过程中,需要学生注意力高度集中,需要学生根据准确的音程指距感.和 ...
- 生僻字用计算机怎么弹歌曲,抖音生僻字简谱:计算器数字乐谱计算器弹奏音乐总结...
抖音生僻字这首歌最近真的超火,据悉,这首歌里面一共包含了70多个生僻字呢,而用计算器到底是怎么弹的呢,下面是小编收集的关于抖音生僻字的计算器数字乐谱,和如何使用计算器弹奏音乐的总结,想要试的可以来看下 ...
- 计算机合成的音乐后缀,计算机音乐课程――《声音制作与合成基础》
计算机音乐课程――<声音制作与合成基础> 中国音乐学院作曲系 多媒体音乐中心 程伊兵 稿源:中音网 摘要:本文试从声音制作与合成在计算机音乐教学中的学科位置.课程内容以及教学重点等方面,勾 ...
- 计算机exo乐谱,History钢琴简谱-数字双手-EXO
History钢琴简谱歌词 作曲:Troelsen,Thomas/Remee Mikkel Sigvardt Jackman/Yoo,Young Jin 演唱:EXO (中文) Listen 感觉 ...
- Using LSTM network generate MIDI files 用LSTM神经网络合成MIDI音乐
问题1:无法导入mido模块 import mido 解决方法:cmd中输入 pip install mido 然后重启电脑. 问题2:使用如下代码将list写入文件中时,报错. import mid ...
- 【Win 10 应用开发】MIDI 音乐合成——音符消息篇
在上一篇中,老周介绍了一些乐理知识,有了那些常识后,进行 MIDI 编程就简单得多了.尽管微软已经把 API 封装好,用起来也很简单,但是,如果你没有相应的音乐知识基础,你是无法进行 MIDI 编程的 ...
最新文章
- boost::statechart模块实现延迟错误的测试程序
- ITK:计算图像的蒙版区域的直方图
- hbase命令行在create table时为啥有MIN_VERSIONS而没有MAX_VERSIONS
- 受欢迎的五个开源可视化工具——你的选择是?
- mysql+误操作怎么恢复_MySQL 误操作后如何快速恢复数据
- spring boot连接数据库
- Lock的tryLock()方法
- 带你读论文丨基于视觉匹配的自适应文本识别
- 多人在线答题游戏 小程序 (规划设计方案)
- android studio for android learning (八)开机启动界面splashActivity
- iTunes恢复系统显示正在等待iPhone解决步骤
- Arduino DY-SV17F自动语音播报
- 中科大计算机招非全日制,中国科学技术大学工商管理(非全日制)招生简章
- 生成的分子图像是否可以识别为SMILES,然后再将识别后的SMILES转换为图像?
- 金山毒霸--血淋淋的教训
- 在美国读博士的那七年
- LabVIEW字符串中显示多种字体
- 【SSA三维路径规划】基于matlab麻雀算法无人机三维航迹规划【含Matlab源码 301期】
- php 赠送礼品功能开发,类似礼物说送礼提醒的功能该怎么做?
- 平行因子-三维荧光-PARAFAC-drEEM 0.6