classdef app2 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
startButton matlab.ui.control.Button
stopButton matlab.ui.control.Button
speedDropDownLabel matlab.ui.control.Label
speedDropDown matlab.ui.control.DropDown
volumeSliderLabel matlab.ui.control.Label
volumeSlider matlab.ui.control.Slider
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
fs = 44100;
Freq;
music;
signal;
CS;
fun;
fun1; % Description
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
[app.fun1,app.fs] = audioread('123.mp3',[661500 2646000]);
app.signal = app.fun1;
end
% Value changed function: volumeSlider
function volumeSliderValueChanged(app, event)
value = app.volumeSlider.Value;
end
% Button pushed function: startButton
function startButtonPushed(app, event)
switch app.speedDropDown.Value
case '0.5'
app.Freq = 0.5 * app.fs ;
case '1'
app.Freq = app.fs ;
case '1.25'
app.Freq = 1.25 * app.fs ;
case '1.5'
app.Freq = 1.5 * app.fs ;
end
value = app.volumeSlider.Value;
app.CS = value * app.signal;
app.music = audioplayer(app.CS,app.Freq);
play(app.music,app.Freq);
time = (1:length(app.signal))/app.Freq;
plot(app.UIAxes, time, app.signal);
end
% Button pushed function: stopButton
function stopButtonPushed(app, event)
stop(app.music);
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create startButton
app.startButton = uibutton(app.UIFigure, 'push');
app.startButton.ButtonPushedFcn = createCallbackFcn(app, @startButtonPushed, true);
app.startButton.Position = [84 127 100 22];
app.startButton.Text = 'start';
% Create stopButton
app.stopButton = uibutton(app.UIFigure, 'push');
app.stopButton.ButtonPushedFcn = createCallbackFcn(app, @stopButtonPushed, true);
app.stopButton.Position = [240 127 100 22];
app.stopButton.Text = 'stop';
% Create speedDropDownLabel
app.speedDropDownLabel = uilabel(app.UIFigure);
app.speedDropDownLabel.HorizontalAlignment = 'right';
app.speedDropDownLabel.Position = [394 340 39 15];
app.speedDropDownLabel.Text = 'speed';
% Create speedDropDown
app.speedDropDown = uidropdown(app.UIFigure);
app.speedDropDown.Items = {'0.5', '1', '1.25', '1.5'};
app.speedDropDown.Position = [448 336 100 22];
app.speedDropDown.Value = '0.5';
% Create volumeSliderLabel
app.volumeSliderLabel = uilabel(app.UIFigure);
app.volumeSliderLabel.HorizontalAlignment = 'right';
app.volumeSliderLabel.Position = [394 271 45 15];
app.volumeSliderLabel.Text = 'volume';
% Create volumeSlider
app.volumeSlider = uislider(app.UIFigure);
app.volumeSlider.Limits = [0 10];
app.volumeSlider.MajorTicks = [];
app.volumeSlider.MajorTickLabels = {};
app.volumeSlider.ValueChangedFcn = createCallbackFcn(app, @volumeSliderValueChanged, true);
app.volumeSlider.MinorTicks = [];
app.volumeSlider.Position = [460 277 150 3];
app.volumeSlider.Value = 1;
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [40 226 300 185];
end
end
methods (Access = public)
% Construct app
function app = app2
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end