IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 数据结构与算法 -> MATLAB创建音乐《光年之外》 -> 正文阅读

[数据结构与算法]MATLAB创建音乐《光年之外》

基于乐理和MATLAB自身sound函数,可以实现MATLAB演奏音乐,本文中以邓紫棋《光年之外》为例实现了该功能。

主函数代码为:

Fs = 44100;
y1=gen_wave2(3,0.5);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(2,0.25);
y5=gen_wave2(1,0.25);
y6=gen_wave2(1,0.25);
y7=gen_wave2(14,0.25);
y8=gen_wave2(14,0.25);
y9=gen_wave2(1,0.25);
y10=gen_wave2(1,0.25);
y11=gen_wave2(22,0.5);
y=[y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11];
%感受停在我发端的之间;
y1=gen_wave2(12,0.25);%12是5的低音;15是1的高音
y2=gen_wave2(12,0.25);
y3=gen_wave2(12,0.75);
y4=gen_wave2(3,0.75);
y5=gen_wave2(12,0.25);
y6=gen_wave2(12,0.25);
y7=gen_wave2(12,0.75);
y8=gen_wave2(2,0.5);
y9=gen_wave2(22,0.5);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9];
%如何瞬间冻结时间;
y1=gen_wave2(3,0.25);%12是5的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(2,0.25);
y5=gen_wave2(1,0.25);
y6=gen_wave2(1,0.25);
y7=gen_wave2(14,0.25);
y8=gen_wave2(14,0.25);
y9=gen_wave2(1,0.25);
y10=gen_wave2(1,0.5);
y11=gen_wave2(22,0.25);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11];
%记住望着我坚定的双眼
y1=gen_wave2(12,0.25);%12是5的低音;15是1的高音
y2=gen_wave2(12,0.25);
y3=gen_wave2(12,0.5);
y4=gen_wave2(3,0.75);
y5=gen_wave2(12,0.25);
y6=gen_wave2(12,0.25);
y7=gen_wave2(12,0.5);
y8=gen_wave2(2,0.5);
y9=gen_wave2(22,0.25);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9];
%也许已经没有明天
y1=gen_wave2(14,0.125);%8是1的低音;15是1的高音
y2=gen_wave2(14,0.125);
y3=gen_wave2(14,0.25);
y4=gen_wave2(1,0.125);
y5=gen_wave2(1,0.125);
y6=gen_wave2(1,0.25);
y7=gen_wave2(3,0.5);
y8=gen_wave2(22,0.5);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8];
%面对浩瀚的星海;
y1=gen_wave2(14,0.125);%8是1的低音;15是1的高音
y2=gen_wave2(14,0.125);
y3=gen_wave2(14,0.125);
y4=gen_wave2(14,0.25);
y5=gen_wave2(1,0.125);
y6=gen_wave2(1,0.125);
y7=gen_wave2(1,0.25);
y8=gen_wave2(3,0.25)
y9=gen_wave2(22,0.5);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9];
%我们微小得像尘埃;
y1=gen_wave2(1,0.125);%8是1的低音;15是1的高音
y2=gen_wave2(2,0.125);
y3=gen_wave2(3,0.25);
y4=gen_wave2(22,0.25);
y5=gen_wave2(1,0.25);
y6=gen_wave2(3,0.25);
y7=gen_wave2(22,0.25);
y8=gen_wave2(1,0.25)
y9=gen_wave2(2,0.25);
y10=gen_wave2(22,1);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10];
%漂浮在 一片无奈
y1=gen_wave2(14,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(1,0.25);
y3=gen_wave2(1,0.25);
y4=gen_wave2(2,0.25);
y5=gen_wave2(2,0.25);
y6=gen_wave2(3,0.25);
y7=gen_wave2(3,0.375);
y8=gen_wave2(5,0.125);
y9=gen_wave2(5,0.25);
y10=gen_wave2(6,0.25);
y11=gen_wave2(6,0.5);
y12=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12];
%缘分让我们相遇乱世以外
y1=gen_wave2(1,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(2,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(3,0.25);
y5=gen_wave2(3,0.25);
y6=gen_wave2(5,0.25);
y7=gen_wave2(5,0.375);
y8=gen_wave2(1,0.125);
y9=gen_wave2(3,0.25);
y10=gen_wave2(2,0.25);
y11=gen_wave2(2,0.5);
y12=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12];
%命运却要我们危难中相爱;
y1=gen_wave2(14,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(1,0.25);
y3=gen_wave2(1,0.25);
y4=gen_wave2(2,0.25);
y5=gen_wave2(2,0.25);
y6=gen_wave2(3,0.25);
y7=gen_wave2(3,0.375);
y8=gen_wave2(5,0.125);
y9=gen_wave2(5,0.25);
y10=gen_wave2(6,0.25);
y11=gen_wave2(6,0.5);
y12=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12];
%也许未来遥远在光年之外
y1=gen_wave2(1,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(2,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(3,0.25);
y5=gen_wave2(3,0.25);
y6=gen_wave2(5,0.25);
y7=gen_wave2(5,0.375);
y8=gen_wave2(1,0.125);
y9=gen_wave2(3,0.25);
y10=gen_wave2(2,0.25);
y11=gen_wave2(2,0.25);
%y12=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11];
%我愿守候未知里为你等待
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(13,0.25);
y13=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%我没想到为了你我能疯狂到
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(14,0.25);
y13=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%山崩海啸没有你根本不想逃
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);%此处6应该不准,仍写为1
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(13,0.25);
y13=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%我的大脑为了你已经疯狂到
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);%
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(14,0.25);
y13=gen_wave2(22,1.25);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%脉搏心跳没有你根本不重要
y1=gen_wave2(14,0.5);%8是1的低音;15是1的高音
y2=gen_wave2(13,0.25);
y3=gen_wave2(1,0.25);
y4=gen_wave2(14,0.5);%
y5=gen_wave2(12,0.5);
y6=gen_wave2(14,0.5);
y7=gen_wave2(22,0.5);
y8=gen_wave2(1,0.25);
y9=gen_wave2(14,0.25);
y10=gen_wave2(12,0.5);
y11=gen_wave2(9,0.5);
y12=gen_wave2(12,0.5);
y13=gen_wave2(10,0.25);
y14=gen_wave2(22,1);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14];
%也许航道以外是醒不来的梦;
y1=gen_wave2(1,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(14,0.5);
y3=gen_wave2(12,0.5);
y4=gen_wave2(2,0.25);%
y5=gen_wave2(22,0.5);
y6=gen_wave2(1,0.25);
y7=gen_wave2(1,0.5);
y8=gen_wave2(14,0.5);
y9=gen_wave2(14,0.5);
y10=gen_wave2(1,0.5);
y11=gen_wave2(2,0.25);
y12=gen_wave2(22,0.5);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12];
%乱世以外,是纯粹的相拥
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(13,0.25);
y13=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%我没想到为了你我能疯狂到
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(14,0.25);
y13=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%山崩海啸没有你根本不想逃
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);%此处6应该不准,仍写为1
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(13,0.25);
y13=gen_wave2(22,0.75);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%我的大脑为了你已经疯狂到
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);%
y5=gen_wave2(1,0.125);
y6=gen_wave2(5,0.125);
y7=gen_wave2(5,0.25);
y8=gen_wave2(5,0.25);
y9=gen_wave2(5,0.25);
y10=gen_wave2(1,0.375);
y11=gen_wave2(1,0.25);
y12=gen_wave2(14,0.25);
y13=gen_wave2(22,1.25);
y=[y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13];
%脉搏心跳没有你根本不重要
y1=gen_wave2(4,0.25);%8是1的低音;15是1的高音
y2=gen_wave2(3,0.25);
y3=gen_wave2(2,0.25);
y4=gen_wave2(1,0.25);%
y5=gen_wave2(22,0.125);
y=[y,y1,y2,y3,y4,y5];
%我没想到
sound(y,Fs);

用到的函数代码为:

function y = gen_wave2( tone, rythm )

??? %Fs = 8192;
??? Fs = 44100;
?? %freqs = [ 262, 294,330, 349, 392, 440, 494, 131, 147, 165, 175, 196, 220, 247, 523,587,659,698,784,880,988,0,3520];
?? freqs=[262, 294,330, 349, 392, 440, 494, 131,147,165,175,196,220,247,523, 587, 659, 698, 783, 880, 988,0,3520]
??? x = linspace(0, 2 * pi * rythm, floor(Fs * rythm));

?? y = sin(freqs(tone) * x) .*(1- x/(rythm * 2 *pi));
?? ?
end

  数据结构与算法 最新文章
【力扣106】 从中序与后续遍历序列构造二叉
leetcode 322 零钱兑换
哈希的应用:海量数据处理
动态规划|最短Hamilton路径
华为机试_HJ41 称砝码【中等】【menset】【
【C与数据结构】——寒假提高每日练习Day1
基础算法——堆排序
2023王道数据结构线性表--单链表课后习题部
LeetCode 之 反转链表的一部分
【题解】lintcode必刷50题<有效的括号序列
上一篇文章      下一篇文章      查看所有文章
加:2022-04-01 23:38:43  更:2022-04-01 23:41:32 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 9:28:29-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码