一、粗略了解简谱
拍号:如图,“2”表示一个小节有2拍,“4”表示4分音符为一拍
终止线表示歌曲结束
注意:以下音符都按以四分音符为一拍计算拍数
四分音符:
唱一拍
二分音符:
某一个音右边有一个小横线,这个音唱两拍
全音符
某一个音右边有4个小横线,这个音唱四拍
八分音符
下面有一个横线的,这个音唱半拍
十六分音符
某个音下面有两个横线,这个音唱四分之一拍
附点音符
休止符
三连音
明示三连(bushi)
连音线
延音线连接的是相同的音符,功能和“” 一样。演唱圆滑线下面的音符时不能换气
反复记号
反复记号表示唱到反复记号处在唱一遍才结束
想这种的,演唱到第二个反复记号这里再回到第一个反复记号这儿,然后唱到第一个小房子这儿时跳到第二个小房子这儿。也就是说第一个小房子里面的是第一遍唱的,第二个小房子里面的是第二遍唱的。
二、把简谱转成代码
一、确定音阶对印频率
#define STOP 0
#define L_DO 262
#define L_RE 294
#define L_M 330
#define L_FA 349
#define L_SO 392
#define L_LA 440
#define L_SI 494
#define M_DO 523
#define M_RE 587
#define M_M 659
#define M_FA 698
#define M_SO 784
#define M_LA 880
#define M_SI 988
#define H_DO 1046
#define H_RE 1175
#define H_M 1318
#define H_FA 1397
#define H_SO 1568
#define H_LA 1760
#define H_SI 7967
2.乐谱处理
以最简单的歌曲为例:
uint16_t twinkle[] = {
M_DO,M_DO,M_SO,M_SO, M_LA,M_LA,M_SO,M_SO,
M_FA,M_FA,M_M, M_M, M_RE,M_RE,M_DO,M_DO,
M_SO,M_SO,M_FA,M_FA, M_M, M_M, M_RE,M_RE,
M_SO,M_SO,M_FA,M_FA, M_M, M_M, M_RE,M_RE,
M_DO,M_DO,M_SO,M_SO, M_LA,M_LA,M_SO,M_SO,
M_FA,M_FA,M_M ,M_M, M_RE,M_RE,M_DO,M_DO,
};
GUI_Audio au = {
.freqs = twinkle,
.length = sizeof(freqs)/sizeof(uint16_t),
.space = 250
};
如图:space表示一拍间隔,单位毫秒,音频数据存储在数组中。
来个难一点的
uint16_t freqs2[] = {
STOP,STOP, STOP,STOP, M_SO,M_SO,
M_LA,M_LA, M_SO,M_SO, H_DO,H_DO,
M_SI,M_SI, M_SI,M_SI, M_SO,M_SO,
M_LA,M_LA, M_SO,M_SO, H_RE,H_RE,
H_DO,H_DO, H_DO,H_DO, M_SO,M_SO,
H_SO,H_SO, H_M, H_M, H_DO,H_DO,
M_SI,M_SI, M_LA,M_LA, M_LA,M_LA,
STOP,STOP, STOP,STOP, H_FA,H_FA,
H_M, H_M, M_DO,H_DO, H_RE,H_RE,
H_DO,H_DO, H_DO,H_DO, M_SO,M_SO,
M_LA,M_LA, M_SO,M_SO, H_DO,H_DO,
M_SI,M_SI, M_SI,M_SI, M_SO,M_SO,
M_LA,M_LA, M_SO,M_SO, H_RE,H_RE,
H_DO,H_DO, H_DO,H_DO, M_SO,M_SO,
H_SO,H_SO, H_M, H_M, H_DO,H_DO,
M_SI,M_SI, M_LA,M_LA, M_LA,M_LA,
STOP,STOP, STOP,STOP, H_FA,H_FA,
H_M, H_M, M_DO,H_DO, H_RE,H_RE,
H_DO,H_DO, H_DO,H_DO, M_SO,M_SO,
H_RE,H_RE, H_RE,H_RE, H_FA,H_FA,
H_M, H_M, H_M, H_M, H_DO,H_DO,
H_RE,H_RE, H_M, H_M, H_FA,H_FA,
H_M, H_M, H_M, H_M, M_SO,M_SO,
H_RE,H_RE, H_RE,H_RE, H_FA,H_FA,
H_M, H_M, H_M, H_M, H_DO,H_DO,
H_RE,H_RE, H_DO,H_DO, M_SI,M_SI,
H_DO,H_DO, H_DO,H_DO, STOP,STOP,
};
GUI_Audio au2 = {
.freqs = freqs2,
.length = sizeof(freqs2)/sizeof(uint16_t),
.space = 250
};
参考: