pianoroll

一、对音符的pianoroll

midi = pm.PrettyMIDI(midi_file)
note_instrument = midi.instruments[0]
onset_instrument = on_midi.instruments[0]
offset_instrument = off_midi.instruments[0]
for note, onset_note, offset_note in zip(note_instrument.notes, onset_instrument.notes, offset_instrument.notes):
	note_length = offset_note.end - offset_note.start  #end-start=音符时值
    onset_note.end = onset_note.start + min(note_length, unit_time)
    offset_note.end += unit_time
    offset_note.start = offset_note.end - min(note_length, unit_time)
pianoroll = note_instrument.get_piano_roll(fs=frame_per_second)  
#frame_per_second = 8,unit_time = 1/8 = 0.125s(16分音符
onset_roll = onset_instrument.get_piano_roll(fs=frame_per_second)
offset_roll = offset_instrument.get_piano_roll(fs=frame_per_second)
print(pianoroll[60:80,10:20])
print(pianoroll.shape) #(128, 326)

用pretty_midi读取的(note,onset_note,offset_note)
三种一模一样的音符

1 Note(start=1.500000, end=1.625000, pitch=67, velocity=115) Note(start=1.500000, end=1.625000, pitch=67, velocity=115) Note(start=1.500000, end=1.625000, pitch=67, velocity=115)
2 Note(start=1.750000, end=1.875000, pitch=72, velocity=118) Note(start=1.750000, end=1.875000, pitch=72, velocity=118) Note(start=1.750000, end=1.875000, pitch=72, velocity=118)
3 Note(start=1.875000, end=2.000000, pitch=74, velocity=112) Note(start=1.875000, end=2.000000, pitch=74, velocity=112) Note(start=1.875000, end=2.000000, pitch=74, velocity=112)
4 Note(start=2.000000, end=2.125000, pitch=76, velocity=112) Note(start=2.000000, end=2.125000, pitch=76, velocity=112) Note(start=2.000000, end=2.125000, pitch=76, velocity=112)
5 Note(start=2.250000, end=2.500000, pitch=72, velocity=112) Note(start=2.250000, end=2.500000, pitch=72, velocity=112) Note(start=2.250000, end=2.500000, pitch=72, velocity=112)
6 Note(start=2.500000, end=2.750000, pitch=69, velocity=118) Note(start=2.500000, end=2.750000, pitch=69, velocity=118) Note(start=2.500000, end=2.750000, pitch=69, velocity=118)

因为pitch range选择的是人声的歌唱范围,48-95(c3-b5)
所以做了4个八度的移调

取出pianoroll[60:80,10:20],如下图所示
怎么阅读note的pianoroll呢?
1、矩阵的行意义为128种音高范围,因为我们的音高是48-96,所以只在这个范围内有值。
2、矩阵的列意义为时间步,往右走时间步增加,因为每秒是8帧,所以假如Note(start=1.500000, end=1.625000, pitch=67, velocity=115),即它在1.5*8=12帧,所以可以看到在坐标(67,12)的位置有值115
在这里插入图片描述
偏移处理后
在这里插入图片描述

所以40.758 = 326
39.875
8 = 319
40.875*8 = 327
pianoroll.shape = (128,326)
onset_roll.shape = (128,319)
offset_roll.shape = (128,327)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值