热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【游戏】音乐时钟Matlab设计

1简介本文结合数字信号处理课程和Matlab程序设计课程的相关知识,给出了基于Matlab的音乐播放器的总体设计方案,介绍了播放器主要模块的功能,设计与实现方法.我们将该设


1 简介


本文结合"数字信号处理"课程和"Matlab程序设计"课程的相关知识,给出了基于Matlab的音乐播放器的总体设计方案,介绍了播放器主要模块的功能,设计与实现方法.我们将该设计作为电子信息类专业数字信号处理课程设计项目,有助于激发学生的学习兴趣,提高其综合设计和应用创新能力.


2 部分代码

function varargout = untitled(varargin)

% UNTITLED M-file for untitled.fig

%      UNTITLED, by itself, creates a new UNTITLED or raises the existing

%      singleton*.

%

%      H = UNTITLED returns the handle to a new UNTITLED or the handle to

%      the existing singleton*.

%

%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local

%      function named CALLBACK in UNTITLED.M with the given input arguments.

%

%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the

%      existing singleton*.  Starting from the left, property value pairs ar

%      applied to the GUI before untitled_OpeningFcn gets called.  An

%      unrecognized property name or invalid value makes property application

%      stop.  All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 02-Jun-2021 00:03:55

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

                   'gui_Singleton',  gui_Singleton, ...

                   'gui_OpeningFcn', @untitled_OpeningFcn, ...

                   'gui_OutputFcn',  @untitled_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 untitled is made visible.

function untitled_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 untitled (see VARARGIN)

if ~isempty(timerfindall), stop(timerfindall);  delete(timerfindall);end

ed until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');

end

set(hObject,'Value',handles.clockSaveData(2));

handles.popupmenu2=hObject;

guidata(hObject,handles);

function edit_musicFile_Callback(hObject, eventdata, handles)

% hObject    handle to edit_musicFile (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_musicFile as text

%        str2double(get(hObject,'String')) returns contents of edit_musicFile as a double

handles.musicSaveData=get(hObject,'String');

musicSaveData=handles.musicSaveData;

save('musicSaveData.txt','-ascii','musicSaveData');

guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.

function edit_musicFile_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit_musicFile (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');

end

set(hObject,'String',handles.musicSaveData); 

handles.edit_musicFile=hObject;

guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.

function pushbutton1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to pushbutton1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

handles.pushbutton1=hObject;

guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.

function radiobutton1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to radiobutton1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

handles.radiobutton1=hObject;

guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.

function radiobutton2_CreateFcn(hObject, eventdata, handles)

% hObject    handle to radiobutton2 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

handles.radiobutton2=hObject;

guidata(hObject,handles);

% --- Executes when selected object is changed in uipanel4.

function uipanel4_SelectionChangeFcn(hObject, eventdata, handles)

% hObject    handle to the selected object in uipanel4 

% eventdata  structure with the following fields (see UIBUTTONGROUP)

% EventName: string 'SelectionChanged' (read only)

% OldValue: handle of the previously selected object or empty if none was selected

% NewValue: handle of the currently selected object

% handles    structure with handles and user data (see GUIDATA)

clockSaveData=handles.clockSaveData;

if isequal(get(hObject,'Tag'),get(gethandles.radiobutton1,'Tag'))

    clockSavaData(3)=1-get(hObject,'Value');

else

    clockSaveData(3)=get(hObject,'Value');

end

save('clockSaveData.txt','-ascii','clockSaveData');

% --- Executes during object creation, after setting all properties.

function figure1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to figure1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

set(hObject,'name','音乐闹钟');

if exist('clockSaveData.txt','file')

    clockSaveData=load('clockSaveData.txt');

    if numel(clockSaveData)~=3

        clockSaveData=[13,1,0];

        save('clockSaveData.txt','-ascii','clockSaveData')

    end

else

    clockSaveData=[13,1,0];

    save('clockSaveData.txt','-ascii','clockSaveData')

end

if exist('musicSaveData.txt','file')

    musicSaveData=char(load('musicSaveData.txt'));    

else

    musicSaveData='设定音乐文件';

    save('musicSaveData.txt','-ascii','musicSaveData')

end

handles.clockSaveData=clockSaveData;

handles.musicSaveData=musicSaveData;

handles.figure1=hObject;

guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.

function uipanel3_CreateFcn(hObject, eventdata, handles)

% hObject    handle to uipanel3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

handles.uipanel3=hObject;

guidata(hObject,handles);

function start_timer(handles)

    cOntents=cellstr(get(handles.popupmenu1,'String'));

    hour=contents{get(handles.popupmenu1,'Value')};

    hour=str2double(hour);

    cOntents=cellstr(get(handles.popupmenu2,'String'));

    minute=contents{get(handles.popupmenu2,'Value')};

    minute=str2double(minute);

    startTime=datevec(now);%时间矢量为【年,月,日,时,分,秒】

    if hour>startTime(4)

        startTime(4:6)=[hour,minute,0];

    elseif hour==startTime(4)

        if minute>startTime(5)

            startTime(5:6)=[minute,0];

        else

            startTime(3:6)=[startTime(3)+1,hour,minute,0];

        end

    else

         startTime(3:6)=[startTime(3)+1,hour,minute,0];

    end

stop(handles.timer);

startat(handles.timer,startTime);

function start_timer_solid_hour(handles)

    startTime=datevec(now);

    startTime(4:6)=[startTime(4)+1,0,0];

    stop(handles.timer);

    startat(handles.timer,startTime);

function timer_action(timerObj,evendata,handles)

if (get(handles.radiobutton1,'Value')==1 && get(handles.checkbox1,'Value')==1)

% --- Executes on button press in checkbox1.

function checkbox1_Callback(hObject, eventdata, handles)

handles.checkbox1=hObject;

guidata(hObject,handles);

if (get(handles.checkbox1,'Value')==1)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    start_timer_solid_hour(handles);

else

    start_timer(handles);

end

    

% --- Executes during object creation, after setting all properties.

function checkbox1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to checkbox1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

handles.checkbox1=hObject;

guidata(hObject,handles);

% --- Executes on button press in pushbutton3.

function pushbutton3_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

[filename,pathname]=uigetfile(...

    {'*.jpg;*.bmp;*.tif','可选择';},'选择背景图片','MultiSelect','off');

%handles.musicSaveData=fullfile(pathname,filename);

selected_figure=fullfile(pathname,filename);

ha=axes('units','normalized','position',[0 0 1 1]); 

uistack(ha,'down') 

II=imread(selected_figure); 

image(II) 

colormap gray 

set(ha,'handlevisibility','off','visible','off'); 

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@

%set(handles.edit_musicFile,'String',handles.musicSaveData);

%musicSaveData=handles.musicSaveData;

%save('musicSaveData.txt','-ascii','musicSaveData');

handles.pushbutton3=hObject;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.

function pushbutton3_CreateFcn(hObject, eventdata, handles)

% hObject    handle to pushbutton3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

handles.pushbutton3=hObject;

guidata(hObject,handles);


3 仿真结果


4 参考文献

[1]韩萍, 周航, 金昌旺. 基于Matlab的音乐播放器设计[J]. 电气电子教学学报, 2012, 34(4):4.


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

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



推荐阅读
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 本文介绍了在go语言中利用(*interface{})(nil)传递参数类型的原理及应用。通过分析Martini框架中的injector类型的声明,解释了values映射表的作用以及parent Injector的含义。同时,讨论了该技术在实际开发中的应用场景。 ... [详细]
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • 本文讨论了如何在codeigniter中识别来自angularjs的请求,并提供了两种方法的代码示例。作者尝试了$this->input->is_ajax_request()和自定义函数is_ajax(),但都没有成功。最后,作者展示了一个ajax请求的示例代码。 ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有