热门标签 | 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代码问题可私信交流。

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



推荐阅读
  • 深入解析 Android IPC 中的 Messenger 机制
    本文详细介绍了 Android 中基于消息传递的进程间通信(IPC)机制——Messenger。通过实例和源码分析,帮助开发者更好地理解和使用这一高效的通信工具。 ... [详细]
  • 在 Android 开发中,通过 Intent 启动 Activity 或 Service 时,可以使用 putExtra 方法传递数据。接收方可以通过 getIntent().getExtras() 获取这些数据。本文将介绍如何使用 RoboGuice 框架简化这一过程,特别是 @InjectExtra 注解的使用。 ... [详细]
  • 深入解析SpringMVC核心组件:DispatcherServlet的工作原理
    本文详细探讨了SpringMVC的核心组件——DispatcherServlet的运作机制,旨在帮助有一定Java和Spring基础的开发人员理解HTTP请求是如何被映射到Controller并执行的。文章将解答以下问题:1. HTTP请求如何映射到Controller;2. Controller是如何被执行的。 ... [详细]
  • 深入解析Spring启动过程
    本文详细介绍了Spring框架的启动流程,帮助开发者理解其内部机制。通过具体示例和代码片段,解释了Bean定义、工厂类、读取器以及条件评估等关键概念,使读者能够更全面地掌握Spring的初始化过程。 ... [详细]
  • 本文介绍了如何在 C# 和 XNA 框架中实现一个自定义的 3x3 矩阵类(MMatrix33),旨在深入理解矩阵运算及其应用场景。该类参考了 AS3 Starling 和其他相关资源,以确保算法的准确性和高效性。 ... [详细]
  • 并发编程 12—— 任务取消与关闭 之 shutdownNow 的局限性
    Java并发编程实践目录并发编程01——ThreadLocal并发编程02——ConcurrentHashMap并发编程03——阻塞队列和生产者-消费者模式并发编程04——闭锁Co ... [详细]
  • 探讨ChatGPT在法律和版权方面的潜在风险及影响,分析其作为内容创造工具的合法性和合规性。 ... [详细]
  • 深入理解Vue.js:从入门到精通
    本文详细介绍了Vue.js的基础知识、安装方法、核心概念及实战案例,帮助开发者全面掌握这一流行的前端框架。 ... [详细]
  • 本文详细探讨了Android Activity中View的绘制流程和动画机制,包括Activity的生命周期、View的测量、布局和绘制过程以及动画对View的影响。通过实验验证,澄清了一些常见的误解,并提供了代码示例和执行结果。 ... [详细]
  • Redux入门指南
    本文介绍Redux的基本概念和工作原理,帮助初学者理解如何使用Redux管理应用程序的状态。Redux是一个用于JavaScript应用的状态管理库,特别适用于React项目。 ... [详细]
  • 云函数与数据库API实现增删查改的对比
    本文将深入探讨使用云函数和数据库API实现数据操作(增删查改)的不同方法,通过详细的代码示例帮助读者更好地理解和掌握这些技术。文章不仅提供代码实现,还解释了每种方法的特点和适用场景。 ... [详细]
  • 本文介绍如何从字符串中移除大写、小写、特殊、数字和非数字字符,并提供了多种编程语言的实现示例。 ... [详细]
  • Linux环境下C语言实现定时向文件写入当前时间
    本文介绍如何在Linux系统中使用C语言编程,实现在每秒钟向指定文件中写入当前时间戳。通过此示例,读者可以了解基本的文件操作、时间处理以及循环控制。 ... [详细]
  • 探讨 HDU 1536 题目,即 S-Nim 游戏的博弈策略。通过 SG 函数分析游戏胜负的关键,并介绍如何编程实现解决方案。 ... [详细]
  • CSS高级技巧:动态高亮当前页面导航
    本文介绍了如何使用CSS实现网站导航栏中当前页面的高亮显示,提升用户体验。通过为每个页面的body元素添加特定ID,并结合导航项的类名,可以轻松实现这一功能。 ... [详细]
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社区 版权所有