0
点赞
收藏
分享

微信扫一扫

Matlab实现电子钢琴

静悠 2022-03-11 阅读 64

1 简介

乐器仿真是跨软件工程和音乐理论双领域的交叉学科研究方向,长期以来,受到专业知识的限制,音乐专业人士不能采用软件工程及数学方法对乐器声学原理进行深入的剖析,而软件工程人员对音乐知识了解相对较少,因此涉及音乐的软件工程研究一直相对薄弱。实际上,在现代信号处理、模式识别的技术支撑下,可以揭示音乐背后的数学秘密,提高人类对音乐的理解。软件工程技术在音乐领域的应用,将给人类带来全新的听觉感受,符合国家近期提出的文化强国理念,在人文、科技领域都具有研究意义。本论文正是把软件工程和音乐理论相结合,以电子合成钢琴音色为目的,在剖析"十二平均律"、"钢琴弦振动方程"的数学基础上,对钢琴音色识别与电子合成方法进行了详尽的讨论和研究。

2 完整代码

function varargout = mypiano(varargin)
% MYPIANO MATLAB code for mypiano.fig
% MYPIANO, by itself, creates a new MYPIANO or raises the existing
% singleton*.
%
% H = MYPIANO returns the handle to a new MYPIANO or the handle to
% the existing singleton*.
%
% MYPIANO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYPIANO.M with the given input arguments.
%
% MYPIANO('Property','Value',...) creates a new MYPIANO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before mypiano_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to mypiano_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help mypiano
% Last Modified by GUIDE v2.5 20-Dec-2015 21:24:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mypiano_OpeningFcn, ...
'gui_OutputFcn', @mypiano_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before mypiano is made visible.
function mypiano_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to mypiano (see VARARGIN)
% Choose default command line output for mypiano
handles.output = hObject;
handles.SampleRate = 1/20000;
handles.Soundfcn = 0;
handles.TimeValue = 0.3488;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes mypiano wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = mypiano_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in C3.
function C3_Callback(hObject, eventdata, handles)
% hObject handle to C3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 130.81;
Press(handles,freq);
% --- Executes on button press in CSharp3.
function CSharp3_Callback(hObject, eventdata, handles)
% hObject handle to CSharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 138.59;
Press(handles,freq);
% --- Executes on button press in D3.
function D3_Callback(hObject, eventdata, handles)
% hObject handle to D3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 146.83;
Press(handles,freq);
% --- Executes on button press in E3.
function E3_Callback(hObject, eventdata, handles)
% hObject handle to E3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 164.81;
Press(handles,freq);
% --- Executes on button press in F3.
function F3_Callback(hObject, eventdata, handles)
% hObject handle to F3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 174.61;
Press(handles,freq);
% --- Executes on button press in B3.
function B3_Callback(hObject, eventdata, handles)
% hObject handle to B3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 246.94;
Press(handles,freq);
% --- Executes on button press in A3.
function A3_Callback(hObject, eventdata, handles)
% hObject handle to A3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 220;
Press(handles,freq);
% --- Executes on button press in G3.
function G3_Callback(hObject, eventdata, handles)
% hObject handle to G3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 196;
Press(handles,freq);
% --- Executes on button press in DSharp3.
function DSharp3_Callback(hObject, eventdata, handles)
% hObject handle to DSharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 155.56;
Press(handles,freq);
% --- Executes on button press in FSharp3.
function FSharp3_Callback(hObject, eventdata, handles)
% hObject handle to FSharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 185.00;
Press(handles,freq);
% --- Executes on button press in GSharp3.
function GSharp3_Callback(hObject, eventdata, handles)
% hObject handle to GSharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 207.65;
Press(handles,freq);
% --- Executes on button press in ASharp3.
function ASharp3_Callback(hObject, eventdata, handles)
% hObject handle to ASharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 233.08;
Press(handles,freq);
% --- Executes on button press in C4.
function C4_Callback(hObject, eventdata, handles)
% hObject handle to C4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 261.625;
Press(handles,freq);
% --- Executes on button press in CSharp4.
function CSharp4_Callback(hObject, eventdata, handles)
% hObject handle to CSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 277.18;
Press(handles,freq);
% --- Executes on button press in D4.
function D4_Callback(hObject, eventdata, handles)
% hObject handle to D4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 293.66;
Press(handles,freq);
% --- Executes on button press in E4.
function E4_Callback(hObject, eventdata, handles)
% hObject handle to E4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 329.63;
Press(handles,freq);
% --- Executes on button press in F4.
function F4_Callback(hObject, eventdata, handles)
% hObject handle to F4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 349.23;
Press(handles,freq);
% --- Executes on button press in B4.
function B4_Callback(hObject, eventdata, handles)
% hObject handle to B4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 493.88;
Press(handles,freq);
% --- Executes on button press in A4.
function A4_Callback(hObject, eventdata, handles)
% hObject handle to A4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 440;
Press(handles,freq);
% --- Executes on button press in G4.
function G4_Callback(hObject, eventdata, handles)
% hObject handle to G4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 392;
Press(handles,freq);
% --- Executes on button press in DSharp4.
function DSharp4_Callback(hObject, eventdata, handles)
% hObject handle to DSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 311.13;
Press(handles,freq);
% --- Executes on button press in FSharp4.
function FSharp4_Callback(hObject, eventdata, handles)
% hObject handle to FSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 369.99;
Press(handles,freq);
% --- Executes on button press in GSharp4.
function GSharp4_Callback(hObject, eventdata, handles)
% hObject handle to GSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 415.3;
Press(handles,freq);
% --- Executes on button press in ASharp4.
function ASharp4_Callback(hObject, eventdata, handles)
% hObject handle to ASharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 466.16;
Press(handles,freq);
function Press(handles,freq)
strFreq = num2str(freq);
set(handles.FrequencyValueTag, 'String', strFreq);
SampleRate = handles.SampleRate;
TimeValue = handles.TimeValue;
Samples = 0:SampleRate:TimeValue;
Soundfcn = sin(2*pi*freq*Samples);
sound(Soundfcn,1/SampleRate);
plot(handles.axes2,Samples,Soundfcn);

3 仿真结果

Matlab实现电子钢琴_ide

4 参考文献

[1]陈禄洪, 邵群英, 蔡伟强. 基于MATLAB数字电子琴的音乐喷泉控制系统设计[J].  2018.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

Matlab实现电子钢琴_d3_02


举报

相关推荐

0 条评论