% Cripple Pachebel’s Canon on Matlab
% Have fun

fs = 44100; % sample rate
dt = 1/fs;

T16 = 0.125;

t16 = [0:dt:T16];
[temp k] = size(t16);

t4 = linspace(0,4*T16,4*k);
t8 = linspace(0,2*T16,2*k);

[temp i] = size(t4);
[temp j] = size(t8);

% Modification functions
mod4 = sin(pi*t4/t4(end));
mod8 = sin(pi*t8/t8(end));
mod16 = sin(pi*t16/t16(end));

f0 = 2*146.8; % reference frequency

ScaleTable = [2/3 3/4 5/6 15/16 ...
1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...
2 9/4 5/2 8/3 3 10/3 15/4 4 ...
1/2 9/16 5/8];
% 1/4 notes
do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);
re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);
mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);

fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);
so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);
la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);
ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);
do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);
re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);
mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);
fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);
so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);
la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);
tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);
ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);
do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);
re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);
mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);
fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);
so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);
la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);
ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);
do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);
blkf = zeros(1,i);

% 1/8 notes
fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);
so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);
la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);
ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);
do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);
re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);
mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);
fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);
so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);
la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);
tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);
ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);
do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);
re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);
mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);
fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);
so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);
la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);
ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);
do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);
blke = zeros(1,j);

% 1/16 notes
fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);
so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);
la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);
ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);
do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);
re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);
mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);
fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);
so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);
la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);
tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);
ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);
do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);
re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);
mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);
fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);
so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);
la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);
ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);
do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);
blks = zeros(1,k);

% Blank Block
blkblock = [blkf blkf blkf blkf  blkf blkf blkf blkf...
blkf blkf blkf blkf  blkf blkf blkf blkf];

% Base Melody
cello = [do1f do1f so0f so0f  la0f la0f mi0f mi0f...
fa0f fa0f do0f do0f  fa0f fa0f so0f so0f];

% So-FUCKING-Long Melody
violin = [mi2f mi2f re2f re2f  do2f do2f ti1f ti1f...
la1f la1f so1f so1f  la1f la1f ti1f ti1f ...%
do2f do2f ti1f ti1f  la1f la1f so1f so1f...
fa1f fa1f mi1f mi1f  fa1f fa1f re1f re1f ...%
do1f mi1f so1f fa1f  mi1f do1f mi1f re1f...
do1f la0f do1f so1f  fa1f la1f so1f fa1f...%
mi1f do1f re1f ti1f  do2f mi2f so2f so1f...
la1f fa1f so1f mi1f  do1f do2f blkf blke ti1e ...%
do2e ti1e do2e do1e  ti0e so1e re1e mi1e...
do1e do2e ti1e la1e  ti1e mi2e so2e la2e...
fa2e mi2e re2e fa2e  mi2e re2e do2e ti1e...
la1e so1e fa1e mi1e  re1e fa1e mi1e re1e... %%
do1e re1e mi1e fa1e  so1e re1e so1e fa1e...
mi1e la1e so1e fa1e  so1e fa1e mi1e re1e...
do1e la0e la1e ti1e  do2e ti1e la1e so1e...
fa1e mi1e re1e la1e  so1e la1e so1e fa1e...%
mi1f mi2e blke re2f re2f  blkf do1f mi2f mi2f...
la2f la2f so2f so2f  la2f la2f ti2f ti2f...%
do3e blke do2e blke ti1f ti1f  blkf la1f do2f do2f...
do2f do2f do2f do2f  do2f fa2f re2f so2f...%
so2e mi2s fa2s so2e mi2s fa2s so2s so1s la1s ti1s ...
do2s re2s mi2s fa2s mi2e do2s re2s...
mi2e mi1s fa1s so1s la1s so1s fa1s so1s mi1s fa1s so1s...
fa1e la1s so1s fa1e mi1s re1s mi1s re1s do1s re1s mi1s fa1s so1s la1s...
fa2e la1s so1s la1e ti1s do2s so1s la1s ti1s do2s re2s mi2s fa2s so2s...%
mi2e do2s re2s mi2e re2s do2s re2s ti1s do2s re2s mi2s re2s do2s ti1s...
do2e la1s ti1s do2e do1s re1s mi1s fa1s mi1s re1s mi1s do2s ti1s do2s...
la1e do2s ti1s la1e so1s fa1s so1s fa1s mi1s fa1s so1s la1s ti1s do2s...
la2e do2s ti1s do2e ti1s la1s ti1s do2s re2s do2s ti1s do1s la1s ti1s...%%
do2e blke blkf ti1e blke blkf la1e blke blkf do2e blke blkf...
do1e blke blkf do1e blke blkf do1e blke blkf do1e blke blkf...%
blkf so1e blke blkf so1e blke blkf mi1e blke blkf so1e blke...
blkf fa1e blke blkf mi1e blke blkf fa1e blke blkf re2e blke...%
mi2e mi1e fa1e mi1e re1e re2e mi2e re2e do2e mi1e do1e do2e ti1e so0e fa0e so0e...
la0e la1e so1e la1e so1e so0e fa0e so0e do1e la1e so1e la1e ti1e ti0e la0e ti0e...%
do1e do2e re2e do2e ti1e ti0e do1e ti0e la0e la1e so1e la1e ti1e ti0e mi1e re1e...
do1e do2e re2e fa2e mi2e mi1e so1e mi2e do2e fa2e mi2e fa2e re2e so1e fa1e so1e...%
mi1e so1e so1e so1e so1e so1e so1e so1e mi1e mi1e mi1e mi1e mi1e mi1e so1e so1e...
fa1e fa1e fa1e do2e do2e do2e do2e do2e do2e do2e la1e la1e so1e so1e re2e ti1e...%%
so1e mi2e mi2e mi2e re2e re2e re2e re2e do2e do2e do2e do2e so2e so2e so2e so2e...
la2e la2e la2e la2e so2e so2e so2e so2e la2e la2e la2e la2e ti2e ti1e ti1e ti1e...%
do2e do1s re1s mi1e do1e ti0e ti1s do2s re2e ti1e la1e la0s ti0s do1e la0e ti0e so1s fa1s mi1e re1e...
do1e mi1s re1s do1e fa1e mi1e do1s re1s mi1e so1e fa1e la1s so1s fa1e mi1e re1e so1s fa1s mi1e re1e...%
mi1e do2s ti1s do2e mi1e so1e so1s la1s ti1e so1e mi1e do2s re2s mi2e do2e mi2e mi2s re2s do2e ti1e...
la1e la1s so1s la1e ti1e do2e mi2s re2s do2e mi2e fa2e do2s ti1s la1e la1e so1e re1e so1e so1e...%
so1f so1f so1f so1f  do1f do1f do1f so1f...
fa1f fa1f so1f so1f  fa1f do1f do1f do1e ti0e...%
do1f do2f ti1f ti1f  la1f la1f so1f so1f...
do1f do1e re1e mi1f mi1f  do2f do2f ti1f ti1f...%%
do2f];

% cello
c1 = [cello cello cello cello cello...
cello cello cello cello cello...
cello cello cello cello cello...
cello cello cello cello cello...
cello cello cello blkf];
% violin1
v1 = [blkblock violin blkblock blkblock];
% violin2
v2 = [blkblock blkblock violin blkblock];
% violin3
v3 = [blkblock blkblock blkblock violin];

% Get dirty
s = c1+v1+v2+v3;
s = s/max(s);

sound(s,fs);

matlab演奏《卡农》的更多相关文章

  1. [HNOI2011]卡农

    题目描述 众所周知卡农是一种复调音乐的写作技法,小余在听卡农音乐时灵感大发,发明了一种新的音乐谱写规则.他将声音分成 n 个音阶,并将音乐分成若干个片段.音乐的每个片段都是由 1 到 n 个音阶构成的 ...

  2. [HNOI2011]卡农 题解

    题目描述 众所周知卡农是一种复调音乐的写作技法,小余在听卡农音乐时灵感大发,发明了一种新的音乐谱写规则.他将声音分成 n 个音阶,并将音乐分成若干个片段.音乐的每个片段都是由 1 到 n 个音阶构成的 ...

  3. [HNOI2011]卡农 (数论计数,DP)

    题面 原题面 众所周知卡农是一种复调音乐的写作技法,小余在听卡农音乐时灵感大发,发明了一种新的音乐谱写规则. 他将声音分成 n n n 个音阶,并将音乐分成若干个片段.音乐的每个片段都是由 1 1 1 ...

  4. [BZOJ2339][HNOI2011]卡农

    [BZOJ2339][HNOI2011]卡农 试题描述 输入 见"试题描述" 输出 见"试题描述" 输入示例 见"试题描述" 输出示例 见& ...

  5. bzoj2339[HNOI2011]卡农 dp+容斥

    2339: [HNOI2011]卡农 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 842  Solved: 510[Submit][Status][ ...

  6. BZOJ2339[HNOI2011]卡农——递推+组合数

    题目链接: [HNOI2011]卡农 题目要求从$S=\{1,2,3……n\}$中选出$m$个子集满足以下三个条件: 1.不能选空集 2.不能选相同的两个子集 3.每种元素出现次数必须为偶数次 我们考 ...

  7. BZOJ 2339 【HNOI2011】 卡农

    题目链接:卡农 听说这道题是经典题? 首先明确一下题意(我在这里纠结了好久):有\(n\)个数,要求你选出\(m\)个不同的子集,使得每个数都出现了偶数次.无先后顺序. 这道题就是一道数学题.显然我们 ...

  8. 【BZOJ2339】卡农(递推,容斥)

    [BZOJ2339]卡农(递推,容斥) 题面 BZOJ 题解 先简化一下题意: 在\([1,2^n-1]\)中选择不重复的\(m\)个数,使得他们异或和为\(0\)的方案数. 我们设\(f[i]\)表 ...

  9. P3214 [HNOI2011]卡农

    题目 P3214 [HNOI2011]卡农 在被一题容斥\(dp\)完虐之后,打算做一做集合容斥这类的题了 第一次深感HNOI的毒瘤(题做得太少了!!) 做法 求\([1,n]\)组成的集合中选\(m ...

  10. 【BZOJ2339】[HNOI2011]卡农 组合数+容斥

    [BZOJ2339][HNOI2011]卡农 题解:虽然集合具有无序性,但是为了方便,我们先考虑有序的情况,最后将答案除以m!即可. 考虑DP.如果我们已经知道了前m-1个集合,那么第m个集合已经是确 ...

随机推荐

  1. C-union的使用

    union有两个作用: 1,节约空间,如果一个struct存在两个互斥的变量,则可以把这个struct变成union 2,将同一个内存作为多种解释 代码: #include <iostream& ...

  2. Portlet和servlet的区别

    相同之处 l 都是java技术开发的web组件 l 都是由特定的容器在管理 l 都可以动态产生各种内容 l 生命周期都是由容器管理 l 和客户端的交互通过request/response机制 不同之处 ...

  3. hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏

    problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...

  4. 【转】Centos系统文件与用户权限分配详解ftp,nginx,php

    linux系统中权限是非常完善的一个功能了,我们如果设置不正确文件就无法使用了,像我们以一般情况需要把文件权限设置为777或644了,对于用户权 限就更加了,像素ftp,nginx,php这些我们都可 ...

  5. 【转】Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  6. 关于Mapper、Reducer的个人总结(转)

    Mapper的处理过程: 1.1. InputFormat 产生 InputSplit,并且调用RecordReader将这些逻辑单元(InputSplit)转化为map task的输入.其中Inpu ...

  7. 解决win7资源监视器不能开启

    刚开始时是这样,点击开始监控,无效 需要开始服务即可解决

  8. 极客DIY:如何构建一台属于自己的基站

    写在前面(原文作者) 上周我去特拉维夫(Tel Aviv)探望我的朋友结果有了一些收获,一块崭新的BladeRF(x40),即一个支持USB3.0的SDR平台,这就意味着可以同时发送和接收信息了.而H ...

  9. 极客DIY:廉价电视棒玩转GNSS-SDR,实现GPS实时定位

    0×00 前言 GNSS是Global Navigation Satellite System的缩写.中文称作:全球卫星导航系统.全球导航卫星系统. GNSS泛指所有的卫星导航系统,包括全球的.区域的 ...

  10. <xliff:g>标签

    摘要: 这是Android4.3Mms源码中的strings.xml的一段代码: <!--Settings item desciption for integer auto-delete sms ...