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

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



推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文详细解析了Python中的os和sys模块,介绍了它们的功能、常用方法及其在实际编程中的应用。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • 使用GDI的一些AIP函数我们可以轻易的绘制出简 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • XNA 3.0 游戏编程:从 XML 文件加载数据
    本文介绍如何在 XNA 3.0 游戏项目中从 XML 文件加载数据。我们将探讨如何将 XML 数据序列化为二进制文件,并通过内容管道加载到游戏中。此外,还会涉及自定义类型读取器和写入器的实现。 ... [详细]
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
  • 本文详细介绍如何在VSCode中配置自定义代码片段,使其具备与IDEA相似的代码生成快捷键功能。通过具体的Java和HTML代码片段示例,展示配置步骤及效果。 ... [详细]
  • Mongoose 5.12.10 发布:MongoDB 异步对象模型工具的新特性与修复
    Mongoose 是一款专为异步环境设计的 MongoDB 对象模型工具,支持 Promise 和回调函数。最新版本 Mongoose 5.12.10 带来了多项修复和改进,包括查询选项中的默认值设置、嵌入式判别器填充、以及 TypeScript 定义文件的优化。 ... [详细]
  • Keras 实战:自编码器入门指南
    本文介绍了使用 Keras 框架实现自编码器的基本方法。自编码器是一种用于无监督学习的神经网络模型,主要功能包括数据降维、特征提取等。通过实际案例,我们将展示如何使用全连接层和卷积层来构建自编码器,并讨论不同维度对重建效果的影响。 ... [详细]
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社区 版权所有