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

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



推荐阅读
  • 本文探讨了如何在游戏启动画面中移除广告,特别是在游戏数据加载期间(大约5-6秒)广告会短暂显示的问题。通过调整XML布局和代码逻辑,可以实现广告的延迟加载或完全移除。 ... [详细]
  • 如何从BAM文件绘制ATAC-seq插入片段长度分布图?
    在ATAC-seq数据处理中,插入片段长度的分布图是一个重要的质量控制指标,它能反映出核小体的周期性排列。本文将详细介绍如何从BAM文件中提取并绘制这些数据。 ... [详细]
  • 理解浏览器历史记录(2)hashchange、pushState
    阅读目录1.hashchange2.pushState本文也是一篇基础文章。继上文之后,本打算去研究pushState,偶然在一些信息中发现了锚点变 ... [详细]
  • 在Qt框架中,信号与槽机制是一种独特的组件间通信方式。本文探讨了这一机制相较于传统的C风格回调函数所具有的优势,并分析了其潜在的不足之处。 ... [详细]
  • Flutter 核心技术与混合开发模式深入解析
    本文深入探讨了 Flutter 的核心技术,特别是其混合开发模式,包括统一管理模式和三端分离模式,以及混合栈原理。通过对比不同模式的优缺点,帮助开发者选择最适合项目的混合开发策略。 ... [详细]
  • RTThread线程间通信
    线程中通信在裸机编程中,经常会使用全局变量进行功能间的通信,如某些功能可能由于一些操作而改变全局变量的值,另一个功能对此全局变量进行读取& ... [详细]
  • 前言:由于Android系统本身决定了其自身的单线程模型结构。在日常的开发过程中,我们又不能把所有的工作都交给主线程去处理(会造成UI卡顿现象)。因此,适当的创建子线程去处理一些耗 ... [详细]
  • 关于进程的复习:#管道#数据的共享Managerdictlist#进程池#cpu个数1#retmap(func,iterable)#异步自带close和join#所有 ... [详细]
  • importjava.io.*;importjava.util.*;publicclass五子棋游戏{staticintm1;staticintn1;staticfinalintS ... [详细]
  • 本题要求计算一组正整数的最小公倍数(LCM)。输入包括多组测试数据,每组数据首先给出一个正整数n,随后是n个正整数。 ... [详细]
  • 在开发iOS应用时,面对不同状态(如数据加载成功、无数据、未登录、网络异常等)的界面管理,如何实现既高效又美观的用户体验?本文探讨了几种最佳实践方法。 ... [详细]
  • 本文详细介绍了 Java 中 org.w3c.dom.Node 类的 isEqualNode() 方法的功能、参数及返回值,并通过多个实际代码示例来展示其具体应用。此方法用于检测两个节点是否相等,而不仅仅是判断它们是否为同一个对象。 ... [详细]
  • 本文介绍了如何在GTK+2中实现透明背景下的小部件叠加绘制,类似于GTK3中的GtkOverlay功能。 ... [详细]
  • Spring Boot + RabbitMQ 消息确认机制详解
    本文详细介绍如何在 Spring Boot 项目中使用 RabbitMQ 的消息确认机制,包括消息发送确认和消息接收确认,帮助开发者解决在实际操作中可能遇到的问题。 ... [详细]
  • 我自己做了一个网站图片的抓取,感觉速度有点慢抓取4000张图片可能得用15分钟左右的时间,我百度看用线程可以加快抓取,然后创建了5个线程抓取,但是5个线程是同步执行同样的操作一个图片就 ... [详细]
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社区 版权所有