目录:
直接上学习链接:https://mp.weixin.qq.com/s/32KI7H\_ASYNOwH-P7FjbRA
https://harmonyos.51cto.com/posts/1511
综合以上2个链接和这个图来改的新年好,(这个图对我帮助很大,我不懂音乐,按照这图改的频率)大家想改其他音乐,建议首先看看开头的2个链接的文章!
感觉还是不太完美。下面吧源码共享出来。大家可以完善完善。。
钢琴上88按键的频率如下表所示:
然后对应到代码中:
`<span class="colour" style="color:rgb(215, 58, 73)">float</span> pitch_names_frequency[] = {
<span class="colour" style="color:rgb(106, 115, 125)">//0--A0</span><span class="hljs-number" style="box-sizing: inherit;">27.50</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A0\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">29.14</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#0\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">30.87</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B0\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//3--C1</span><span class="hljs-number" style="box-sizing: inherit;">32.70</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">34.65</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C#1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">36.71</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">38.89</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D#1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">41.20</span><span class="colour" style="color:rgb(106, 115, 125)">/\*E1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">43.65</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">46.25</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F#1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">49.00</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">51.91</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G#1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">55.00</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">58.27</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#1\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">61.74</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B1\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//15--C2</span>
<span class="hljs-number" style="box-sizing: inherit;">65.41</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">69.30</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C#2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">73.42</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">77.78</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D#2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">82.41</span><span class="colour" style="color:rgb(106, 115, 125)">/\*E2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">87.31</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">92.5</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F#2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">98.00</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">103.8</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G#2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">110.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">116.5</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#2\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">123.5</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B2\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//27--C3</span>
<span class="hljs-number" style="box-sizing: inherit;">130.8</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">138.6</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C#3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">146.8</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">155.6</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D#3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">164.8</span><span class="colour" style="color:rgb(106, 115, 125)">/\*E3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">174.6</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">185.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F#3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">196.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">207.6</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G#3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">220.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">233.1</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#3\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">246.9</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B3\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//39--C4</span>
<span class="hljs-number" style="box-sizing: inherit;">261.6</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">277.2</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C#4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">293.7</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">311.1</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D#4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">329.6</span><span class="colour" style="color:rgb(106, 115, 125)">/\*E4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">349.2</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">370.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F#4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">392.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">415.3</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G#4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">440.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">466.2</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#4\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">493.9</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B4\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//51--C5</span>
<span class="hljs-number" style="box-sizing: inherit;">523.2</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">554.4</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C#5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">587.3</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D5\*/</span>, <span class="hljs-number" style="box-sizing: inherit;">622.2</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D#5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">659.3</span><span class="colour" style="color:rgb(106, 115, 125)">/\*E5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">698.5</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">740.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F#5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">784.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">830.6</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G#5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">880.0</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">932.3</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#5\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">987.8</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B5\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//63--C6</span>
<span class="hljs-number" style="box-sizing: inherit;">1046</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1109</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C#6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1175</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1245</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D#6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1319</span><span class="colour" style="color:rgb(106, 115, 125)">/\*E6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1397</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1480</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F#6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1568</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1661</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G#6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1760</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1865</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#6\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">1976</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B6\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//75--C7</span>
<span class="hljs-number" style="box-sizing: inherit;">2093</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">2217</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C#7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">2349</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">2489</span><span class="colour" style="color:rgb(106, 115, 125)">/\*D#7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">2637</span><span class="colour" style="color:rgb(106, 115, 125)">/\*E7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">2794</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">2960</span><span class="colour" style="color:rgb(106, 115, 125)">/\*F#7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">3136</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">3322</span><span class="colour" style="color:rgb(106, 115, 125)">/\*G#7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">3520</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">3729</span><span class="colour" style="color:rgb(106, 115, 125)">/\*A#7\*/</span>,<span class="hljs-number" style="box-sizing: inherit;">3951</span><span class="colour" style="color:rgb(106, 115, 125)">/\*B7\*/</span>,
<span class="colour" style="color:rgb(106, 115, 125)">//87</span>
<span class="hljs-number" style="box-sizing: inherit;">4186</span><span class="colour" style="color:rgb(106, 115, 125)">/\*C8\*/</span>
};`
接着找出每个音的频率
`<span class="colour" style="color:rgb(106, 115, 125)">#<span class="hljs-meta-keyword" style="box-sizing: inherit;">define</span> L\_B 51</span><span class="colour" style="color:rgb(106, 115, 125)">#<span class="hljs-meta-keyword" style="box-sizing: inherit;">define</span> N\_B 63</span><span class="colour" style="color:rgb(106, 115, 125)">#<span class="hljs-meta-keyword" style="box-sizing: inherit;">define</span> H\_B 75</span><span class="colour" style="color:rgb(215, 58, 73)">unsigned</span> <span class="colour" style="color:rgb(215, 58, 73)">char</span> ai_ruo_liu_li[] = {
N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">7</span>, N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>,
N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">9</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">9</span>, N_B+<span class="hljs-number" style="box-sizing: inherit;">5</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">2</span>,
N_B+<span class="hljs-number" style="box-sizing: inherit;">2</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">5</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">5</span>, N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">2</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>,
N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>, N_B+<span class="hljs-number" style="box-sizing: inherit;">4</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">2</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>, L_B+<span class="hljs-number" style="box-sizing: inherit;">11</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">2</span>,N_B+<span class="hljs-number" style="box-sizing: inherit;">0</span>,
};
`
然后根据简谱确定时长:
`<span class="colour" style="color:rgb(3, 47, 98)">unsigned</span> <span class="colour" style="color:rgb(3, 47, 98)">char</span> <span class="colour" style="color:rgb(3, 47, 98)">music[]={</span>
<span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,4,4,</span> <span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,4,4,</span>
<span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,4,4,</span> <span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,8,</span>
<span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,4,4,</span> <span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,4,4,</span>
<span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,4,4,</span> <span class="hljs-number" style="box-sizing: inherit;">2</span><span class="colour" style="color:rgb(3, 47, 98)">,2,8,</span>
<span class="colour" style="color:rgb(3, 47, 98)">};</span>`
第一句最后一个5.的音,换了好几个频率。总感觉不太对劲
我写的还是不太对,多有不足。请大家指正!
视频稍后传到极客Show
祝鸿蒙越来越好!祝正在学习的我们,学习进步!
视频链接:https://harmonyos.51cto.com/show/2355
作者: zzb16888
想了解更多内容,请访问: 51CTO和华为官方战略合作共建的鸿蒙技术社区https://harmonyos.51cto.com/