【音乐播放】基于matlab GUI 动感音乐播放【含Matlab源码 778期】

2021/4/15 1:25:09

本文主要是介绍【音乐播放】基于matlab GUI 动感音乐播放【含Matlab源码 778期】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、简介

基于matlab GUI 动感音乐播放:
1 自由选择本地音乐;
2 播放音乐的同时还有行走人的动画;
3 人的速度和姿态都可调整;
4 还可输入文本;

二、源代码

function varargout = hdm_player(varargin)
% HDM_PLAYER MATLAB code for hdm_player.fig
%      HDM_PLAYER, by itself, creates a new HDM_PLAYER or raises the existing
%      singleton*.
%
%      H = HDM_PLAYER returns the handle to a new HDM_PLAYER or the handle to
%      the existing singleton*.
%
%      HDM_PLAYER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in HDM_PLAYER.M with the given input arguments.
%
%      HDM_PLAYER('Property','Value',...) creates a new HDM_PLAYER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before hdm_player_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to hdm_player_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 hdm_player

% Last Modified by GUIDE v2.5 08-Jun-2013 07:56:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @hdm_player_OpeningFcn, ...
                   'gui_OutputFcn',  @hdm_player_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 hdm_player is made visible.
function hdm_player_OpeningFcn(hObject, eventdata, handles, varargin)
global T_obj which_channel T_start x;
which_channel = 1;
T_start = 0; 
x = 0;
% 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 hdm_player (see VARARGIN)
T_obj=timer('TimerFcn',{@plotupdate, handles}, 'Period', 0.1, 'ExecutionMode', 'FixedRate');
% Choose default command line output for hdm_player
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes hdm_player wait for user response (see UIRESUME)
% uiwait(handles.figure1);
set(gcf, 'color','w')

% --- Outputs from this function are returned to the command line.
function varargout = hdm_player_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 loadbutton.
function loadbutton_Callback(hObject, eventdata, handles)
global  wavfile Fs;
% hObject    handle to loadbutton (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('*.wav', '选择播放文件');
[wavfile Fs] = wavread([pathname filename]);
%sound(wavfile,Fs);


% --- Executes on button press in playbutton.
function playbutton_Callback(hObject, eventdata, handles)
global p   wavfile Fs T_obj T_start x;
% hObject    handle to playbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
   
x = wavfile(:, 1);
    
p = audioplayer(x, Fs);
 
play(p);
if T_start == 0
    start(T_obj);
    T_start = 1;
end



% --- Executes on button press in pausebutton.
function pausebutton_Callback(hObject, eventdata, handles)
global p T_obj;
% hObject    handle to pausebutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pause(p);


% --- Executes on button press in continued.
function continued_Callback(hObject, eventdata, handles)
global p;
% hObject    handle to continued (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
resume(p);

    

% --- Executes on button press in stopbutton.
function stopbutton_Callback(hObject, eventdata, handles)
global p T_obj T_stop;
% hObject    handle to stopbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
stop(p);
stop(T_obj);
delete(T_obj);
T_stop = 1;


 



 


 


 

% --- Executes during object deletion, before destroying properties.
function figure1_DeleteFcn(hObject, eventdata, handles)
global T_obj T_stop p;
stop(p);
if T_stop == 0
    stop(T_obj);
    delete(T_obj);
end
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
shg
set(gcf,'doublebuf','on','color','w','name','Walker','numbertitle','off')
set(gca,'pos',get(gca,'pos')+[0 .07 0 0])

% The body is represented by 15 points in three space, i.e. a vector of
% length 45.  The data consists of F, five vectors describing the average
% female and M, five vectors describing the average male.  Four linked
% segments, indexed by L, are the head, torso, arms, and legs.

% Initial view

load walkers
X = reshape((F(:,1)+M(:,1))/2,15,3);
L = {[1 5],[5 12],[2 3 4 5 6 7 8],[9 10 11 12 13 14 15]};
for k = 1:4
   p(k) = line(X(L{k},1),X(L{k},2),X(L{k},3),'marker','o', ...
      'markersize',10,'linestyle','-','erasemode','background');
end

三、运行结果

在这里插入图片描述

四、备注

完整代码或者代写添加QQ 1564658423



这篇关于【音乐播放】基于matlab GUI 动感音乐播放【含Matlab源码 778期】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程