classdef app1 < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure      matlab.ui.Figure
        human         matlab.ui.control.StateButton
        style         matlab.ui.control.DropDown
        resound       matlab.ui.control.DropDown
        Label_11      matlab.ui.control.Label
        Label_10      matlab.ui.control.Label
        TabGroup      matlab.ui.container.TabGroup
        Tab           matlab.ui.container.Tab
        UIAxes1       matlab.ui.control.UIAxes
        UIAxes2       matlab.ui.control.UIAxes
        Tab_2         matlab.ui.container.Tab
        UIAxes3       matlab.ui.control.UIAxes
        Tab_3         matlab.ui.container.Tab
        UIAxes5       matlab.ui.control.UIAxes
        UIAxes4       matlab.ui.control.UIAxes
        music_volume  matlab.ui.control.Slider
        Label_9       matlab.ui.control.Label
        total_time    matlab.ui.control.Label
        Label_7       matlab.ui.control.Label
        current_time  matlab.ui.control.Label
        stop_music    matlab.ui.control.StateButton
        next          matlab.ui.control.StateButton
        last          matlab.ui.control.StateButton
        play_music    matlab.ui.control.Button
        version       matlab.ui.control.Label
        play_speed    matlab.ui.control.DropDown
        Label_4       matlab.ui.control.Label
        process       matlab.ui.control.Slider
        Label_2       matlab.ui.control.Label
        Label         matlab.ui.control.Label
        Panel         matlab.ui.container.Panel
        MusicList     matlab.ui.control.ListBox
        del           matlab.ui.control.Button
        add           matlab.ui.control.Button
    end


    properties (Access = private)
        fs;%采样率，即每秒播放点数
        speed = 1;%播放速度
        sample;%帧率
        pathlist = {};%歌曲地址数组,和MusicList并列使用
        N = 0;%总歌曲数目
        audiodata;%音频数据
        total;%总帧数
        current;%当前帧
        player;%播放器
        my_timer;%定时器，用于刷新各种实时显示的数据
    end
    
    methods (Access = private)
        
        function set_total_time(app)
            if isempty(app.player) == 0
                total_minutes = floor((app.player.TotalSamples/app.player.SampleRate)/60);
                total_seconds = floor(app.player.TotalSamples/app.player.SampleRate - total_minutes*60);
                min = timeformat(app,total_minutes);
                sec = timeformat(app,total_seconds);
                app.total_time.Text = [min,':',sec];
            end
        end
        
    
        
        function update_process1(app,hObject,eventdata)%这两个没用上的参数很关键，删了就无法更新
            %更新实时变化
            %更新时间的条件是播放器不为空
            if ~isempty(app.player)
                %如果正在播放
                if strcmpi(get(app.player,'running'),'on')
                    %更新当前时间和总时间
                    set_total_time(app);
                    app.sample = app.player.SampleRate/app.speed;
                    current_minutes = floor((app.player.CurrentSample/app.sample)/60);
                    current_seconds = floor(app.player.CurrentSample/app.sample - current_minutes*60);
                    min = timeformat(app,current_minutes);
                    sec = timeformat(app,current_seconds);
                    app.current_time.Text = [min,':',sec];
                    %更新图像
                    %时域
                    Fs = app.player.SampleRate;
                    n = 0:1:app.player.TotalSamples-1;
                    %时间太短的就看1s
                    if app.player.TotalSamples < Fs*40
                        if app.player.CurrentSample+Fs*1<= app.player.TotalSamples
                            n1 = app.player.CurrentSample:1:app.player.CurrentSample+Fs*1;
                        else
                            n1 = app.player.CurrentSample:1:app.player.TotalSamples;
                        end
                    else%长的看10s
                        if app.player.CurrentSample+Fs*10<= app.player.TotalSamples
                            n1 = app.player.CurrentSample:1:app.player.CurrentSample+Fs*10;
                        else
                            n1 = app.player.CurrentSample:1:app.player.TotalSamples;
                        end
                    end
                    y = app.audiodata(:,1);
                    y1 = app.audiodata(n1,1);
                    plot(app.UIAxes1,n/Fs,y,'-k',n1/Fs,y1,'-r');%采用了在一个图上画多个图的方法
                    %hold(app.UIAxes1,"on");%hold on 画多个图会因为图太多而卡顿而且内存不足
                    plot(app.UIAxes4,n/Fs,y,'-k');
                    plot(app.UIAxes2,n1/Fs,y1,'-r');
                    %频域
                    Y = fft(y);Y = abs(Y);
                    L = floor(app.player.TotalSamples/2)+1;
                    Yh = Y(1:L);
                    h = Yh/Fs;
                    fz = Fs/app.player.TotalSamples;
                    k = 0:L-1;
                    f = fz*k;
                    plot(app.UIAxes3,f,h);
                    %包络
                    if app.player.TotalSamples/app.player.SampleRate <= 30
                       Fs = floor(Fs/100);
                    else
                       Fs = floor(Fs);
                    end
                    yleft = y(:,1);%取单声道
                    N1 = floor(length(yleft)/Fs);%为了方便分割先记下可完整分割为每段Fs的份数
                    yleft = yleft(1:N1*Fs);%截取可整除长度的yleft
                    N0 = length(yleft);%记下新的yleft的总点数
                    y1 = reshape(yleft,Fs,[]);%新yleft分组,每组Fs个
                    y1 = max(y1);%每组取最大值
                    x1 = linspace(0,N0-1,length(y1));
                    x2 = 0:1:N0-1;%点数还原
                    y2 = interp1(x1,y1,x2,'spline');%平滑曲线估算插值
                    plot(app.UIAxes5,x2,y2,'-k');%作图

                    %更新进度条
                    app.process.Value = app.player.CurrentSample/app.player.TotalSamples;
                    if app.player.CurrentSample == 1
                        stop(app.player);
                        app.play_music.Text = '▶';
                        app.speed = 1;
                        app.play_speed.Value = 'x1';
                    end
                      
                %没有正在播放时,列表为空就归零
                else
                    if isempty(app.MusicList.Items)
                        app.total_time.Text = ['00',':','00'];
                        app.current_time.Text = ['00',':','00'];
                        app.process.Value = 0;
                        app.play_music.Text = '▶';
                    end
                end
                
            end
            
            %如果播放器是空的，但列表选中了歌曲，除了总时间外刷新
            if isempty(app.player)&&~isempty(app.MusicList.Value)
                app.current_time.Text = ['00',':','00'];
                app.process.Value = 0;
                app.play_music.Text = '▶'; 
            end
            %播放器是空的列表也没选中，就全部刷新归零
            if isempty(app.player)&&isempty(app.MusicList.Value)
                app.total_time.Text = ['00',':','00'];
                app.current_time.Text = ['00',':','00'];
                app.process.Value = 0;
                app.play_music.Text = '▶';
            end
        end
        
        
        function str = timeformat(app,num)
            %方便显示时间格式的函数
            if num < 10
                str = ['0',num2str(num)];
            else
                str = num2str(num);
            end
        end
        

    end


    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            app.my_timer = timer("ExecutionMode","fixedSpacing","Period",0.1,"TimerFcn",@app.update_process1);
            start(app.my_timer);
        end

        % Button pushed function: add
        function addPushed(app, event)
            %播放器非空时暂停音乐，并改变图标
            if ~isempty(app.player)
                pause(app.player);
                app.play_music.Text = '▶';
            end
            %查找文件
            [filename,app.pathlist{app.N+1}] = uigetfile({'*.mp3;*.mp4;*.wav','音频文件'},'multiselect','off');
            %判断是否选中了文件
            if filename ~= 0    
                %元胞数组计数
                dims = size(app.MusicList.Items);
                n = dims(2);
                %添加到列表
                if ismember(filename,app.MusicList.Items)
                    errordlg('已经导入过同名歌曲！');
                else
                    app.MusicList.Items{n+1} = filename;
                    %更新总数，方便后面使用
                    app.N = app.N + 1;
                end
            end
        end

        % Button pushed function: del
        function delButtonPushed(app, event)
            %播放器非空时暂停音乐，并改变图标
            if ~isempty(app.player)
                pause(app.player);
                app.play_music.Text = '▶';
            end
            %查找选定元素的索引
            if isempty(app.MusicList.Items)
                errordlg('没有更多歌曲可删了！');
            else 
                %选中了某个元素的情况
                if isempty(app.MusicList.Value) == 0  
                    n = 1;
                    while isequal(app.MusicList.Items{n},app.MusicList.Value) == 0
                        n = n + 1;
                    end
                    %删除该元素，注意删除用（索引），这样删除的是元素
                    app.MusicList.Items(n) = [];
                    app.pathlist(n) = [];
                    %总数刷新，方便后面使用
                    app.N = app.N - 1;
                %没有选中元素的情况
                else
                    errordlg('您还没有选择要删除的歌曲！');
                end          
            end   
        end

        % Value changed function: last
        function lastValueChanged(app, event)
            n = 1;
            while isequal(app.MusicList.Items{n},app.MusicList.Value) == 0
                n = n + 1;
            end
            %如果存在上一曲      
            if (n-1) >= 1
                %先刷新下进度条和时间以及符号
                if ~isempty(app.player)
                    stop(app.player);
                    app.play_music.Text = '▶';
                    app.process.Value = 0;
                    app.total_time.Text = ['00',':','00'];
                    app.current_time.Text = ['00',':','00'];
                end
                %把选定歌曲修改
                app.MusicList.Value = app.MusicList.Items{n-1};
                %执行选定曲目修改回调
                MusicListValueChanged(app, event);
                %记得把按钮弹起来
                app.last.Value = false;
                %为了便捷，自动按下播放按钮
                play_musicButtonPushed(app, event);
            else
                %报警前也把按钮弹起来
                app.last.Value = false;
                errordlg('没有更多了！');
            end
        end

        % Button pushed function: play_music
        function play_musicButtonPushed(app, event)
            %首先判断按下按钮时是否选中了某歌曲
            if isempty(app.MusicList.Value) == 0
                %如果播放器中没有音乐就读入数据，并设置时间
                if isempty(app.player) == 1
                    %先找到歌曲索引，MusicList和pathlist一样
                    n = 1;
                    while isequal(app.MusicList.Items{n},app.MusicList.Value) == 0
                        n = n + 1;
                    end
                    fullpath = [app.pathlist{n},app.MusicList.Value];
                    [app.audiodata,app.fs] = audioread(fullpath);
                    app.player = audioplayer(app.audiodata,app.fs); 
                    set_total_time(app);
                end
                %按下播放按钮，图标变化
                if app.play_music.Text == '▶'
                    %判断是播放还是继续
                    if app.player.CurrentSample == 1
                        play(app.player);
                    elseif app.player.CurrentSample ~= 1
                        resume(app.player);
                    end
                    app.play_music.Text = '| |';
                else
                    pause(app.player);
                    app.play_music.Text = '▶';
                end
            %未选中歌曲时给出警告
            else
                errordlg('未选择要播放或暂停的歌曲！');
            end          
        end

        % Value changed function: play_speed
        function play_speedValueChanged(app, event)
            value = app.play_speed.Value;
            %先判断是否有正在播放的音乐，有就改变播放速度,但是要注意不是累乘，所以要先还原再乘
            if isempty(app.player) ~= 1
                app.player.SampleRate = (app.player.SampleRate)/(app.speed);
                app.speed = str2num(strip(value,'left','x'));
                app.player.SampleRate = (app.player.SampleRate)*(app.speed);
            else
                errordlg('当前无正在播放的音乐！');
            end
        end

        % Value changed function: stop_music
        function stop_musicValueChanged(app, event)
            %如果播放器非空，则按下结束停止歌曲，并且保证播放图样正确,将进度和时间归0
            if isempty(app.player) ~= 1
                stop(app.player);
                app.play_music.Text = '▶';
                app.stop_music.Value = false;
                app.process.Value = 0;
                app.current_time.Text = '00:00';
            end
        end

        % Value changed function: MusicList
        function MusicListValueChanged(app, event)
            %切换歌曲时有歌曲在播放器中，就停止音乐,清空播放器，重新读入选中的数据，更新进度条和时间
            if ~isempty(app.player)
                stop(app.player);
                clear app.player;
                n = 1;
                while ~isequal(app.MusicList.Items{n},app.MusicList.Value)
                    n = n + 1;
                end
                fullpath = [app.pathlist{n},app.MusicList.Value];
                [app.audiodata,app.fs] = audioread(fullpath);
                app.player = audioplayer(app.audiodata,app.fs);
                set_total_time(app);
                @update_process1;  
            end
        end

        % Value changed function: next
        function nextValueChanged(app, event)
            n = 1;
            while ~isequal(app.MusicList.Items{n},app.MusicList.Value)
                n = n + 1;
            end
            %如果存在下一曲
            if (n+1) <= app.N
                %先刷新下进度条和时间以及符号
                if ~isempty(app.player)
                    stop(app.player);
                    app.play_music.Text = '▶';
                    app.process.Value = 0;
                    app.total_time.Text = ['00',':','00'];
                    app.current_time.Text = ['00',':','00'];
                end
                %把选定歌曲修改
                app.MusicList.Value = app.MusicList.Items{n+1};
                %执行选定曲目修改回调
                MusicListValueChanged(app, event);
                %记得把按钮弹起来
                app.next.Value = false;
                %为了便捷，自动按下播放按钮
                play_musicButtonPushed(app, event);
            else
                %报警前也把按钮弹起来
                app.next.Value = false;
                errordlg('没有更多了！');
            end
            
        end

        % Value changed function: music_volume
        function music_volumeValueChanged(app, event)
            %如果播放器非空就可以调节音量
            if ~isempty(app.player)
                changedValue = event.Value;
                currentSample = get(app.player,'currentSample');
                yC=app.audiodata*changedValue/30;
                app.player=audioplayer(yC,app.fs);
                play(app.player,currentSample);
            else
                errordlg('当前无正在播放的音乐！');
            end
        end

        % Value changing function: music_volume
        function music_volumeValueChanging(app, event)
            if isempty(app.player) == 0
                pause(app.player);
            end
        end

        % Close request function: UIFigure
        function UIFigureCloseRequest(app, event)
            stop(app.my_timer);
            delete(app);
        end

        % Value changed function: process
        function processValueChanged(app, event)
            value = app.process.Value;
            %播放器非空时，从对应处开始播放即可
            if ~isempty(app.player)
                pause(app.player);
                C = get(app.player,'TotalSamples');
                play(app.player,round(value*C)); 
                app.play_music.Text = '| |';
            else
                app.process.Value = 0;
                errordlg('当前无正在播放的音乐！'); 
            end
        end

        % Value changed function: resound
        function resoundValueChanged(app, event)
            if ~isempty(app.player)
                pause(app.player);
                Current = app.player.currentSample;
                app.play_music.Text = '▶';
                value = app.resound.Value;
                
                n = 1;%先把player还原默认值再操作
                while ~isequal(app.MusicList.Items{n},app.MusicList.Value)
                    n = n + 1;
                end
                fullpath = [app.pathlist{n},app.MusicList.Value];
                [app.audiodata,app.fs] = audioread(fullpath);
                app.player = audioplayer(app.audiodata,app.fs);
                
                num=str2double(value);
                I=app.audiodata;
                z=[zeros(num,2);I];
                y=[I;zeros(num,2)];%补num?
                app.audiodata=y+z;%将原始信号与延迟信号相加，产生混响信号?
                app.player = audioplayer(app.audiodata,app.fs);
                play(app.player,Current);
                app.play_music.Text = '| |';
            else
                errordlg("当前无正在播放的音乐！");
                app.resound.Value = "0";
            end            
        end

        % Value changed function: human
        function humanValueChanged(app, event)
            value = app.human.Value;
            if value == true
                if ~isempty(app.player)
                    pause(app.player);
                    Current = app.player.currentSample;
                    app.play_music.Text = '▶';
                    SoundLeft=app.audiodata(:,1);
                    SoundRight=app.audiodata(:,2);
                     
                    NewLeft=SoundLeft-SoundRight;
                    NewRight=SoundLeft-SoundRight;
                    
                    Sound(:,1)=NewLeft;
                    Sound(:,2)=NewRight;
                    
                    BP=fir1(300,[500,2000]/(app.fs/2));     % 考虑300阶
                    CutDown=filter(BP,1,Sound);     %Pass BPF
                    Sound_Final=Sound-0.6*abs(CutDown);
                    
                    app.player = audioplayer(Sound_Final,app.fs);
                    play(app.player,Current);
                    app.play_music.Text = '| |';
                else
                    errordlg("当前无正在播放的歌曲！");
                end
            end
            if value == false
                if ~isempty(app.player)
                    pause(app.player);
                    app.play_music.Text = '▶';
                    Current = app.player.currentSample;
                    n = 1;
                    while ~isequal(app.MusicList.Items{n},app.MusicList.Value)
                        n = n + 1;
                    end
                    fullpath = [app.pathlist{n},app.MusicList.Value];
                    [app.audiodata,app.fs] = audioread(fullpath);
                    app.player = audioplayer(app.audiodata,app.fs);
                    play(app.player,Current);
                    app.play_music.Text = '| |';
                else
                    errordlg("当前无正在播放的歌曲！");
                end
            end
        end

        % Value changed function: style
        function styleValueChanged(app, event)
            value = app.style.Value;
            pause(app.player);
            app.play_music.Text = '▶';
            Current = app.player.currentSample;
            n = 1;
            while ~isequal(app.MusicList.Items{n},app.MusicList.Value)
                  n = n + 1;
            end
            fullpath = [app.pathlist{n},app.MusicList.Value];
            [app.audiodata,app.fs] = audioread(fullpath);
            f = [0 0.0016 0.0028 0.0057 0.0113 0.0227 0.0454 0.0907 0.1814 0.3628 0.7256 1];
            m = zeros(1,12);
            switch value
                case 'normal'
                    
                case 'Jazz_t_domain'
                    [M,Wn]=buttord(2*pi*200,2*pi*100,1,15,'s');
                    [Z,P,K]=buttap(M);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2hp(Bap,Aap,Wn);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*2000,2*pi*3000,1,5,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,6000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*3000,2*pi*4000,1,4,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,6000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*4000,2*pi*5000,1,3,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,6000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*1500,2*pi*2500,1,5,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,6000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata = filter(bz,az,app.audiodata); % 进行滤波
                case 'Rock_t_domain'
                    [M,Wn]=cheb1ord(2*pi*125,2*pi*700,1,15,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*500,2*pi*1000,1,12,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1500);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*1000,2*pi*1500,1,3,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                case 'Dance_t_domain'
                    [M,Wn]=cheb1ord(2*pi*100,2*pi*400,0.0001,0.00010001,'s');
                    [Z,P,K]=cheb1ap(M,0.0001);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bp(Bap,Aap,Wn,400);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*40,2*pi*80,0.0001,0.000100002,'s');
                    [Z,P,K]=cheb1ap(M,0.0001);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bp(Bap,Aap,Wn,400);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*20,2*pi*60,0.0001,0.000100001,'s');
                    [Z,P,K]=cheb1ap(M,0.0001);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bp(Bap,Aap,Wn,400);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*250,2*pi*700,1,5,'s');
                    [Z,P,K]=cheb1ap(M,1);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*500,2*pi*1000,2,5,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1000);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*700,2*pi*1200,2,15,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1200);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*1000,2*pi*1500,2,19,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1200);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*1200,2*pi*1700,2,19,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1200);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*1600,2*pi*2100,2,19,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1200);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*2000,2*pi*2500,2,19,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1200);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                    [M,Wn]=cheb1ord(2*pi*2200,2*pi*2700,2,19,'s');
                    [Z,P,K]=cheb1ap(M,2);
                    [Bap,Aap]=zp2tf(Z,P,K);
                    [b,a]=lp2bs(Bap,Aap,Wn,1200);
                    [bz,az]=bilinear(b,a,app.fs);
                    app.audiodata=filter(bz,az,app.audiodata); % 进行滤波
                case "Jazz_f_domain"
                    m = [0 1.995 1.995 1.259 1.585 0.631 0.794 1 1.259 1.585 2.512 0];
                    b = fir2(100,f,m);
                    app.audiodata = filter(b,1,app.audiodata);
                case "Rock_f_domain"
                    m = [0 2.512 1.995 1.995 1.259 1 0.794 1 1.259 1.585 2.512 0];
                    b = fir2(100,f,m);
                    app.audiodata = filter(b,1,app.audiodata);
                case "Metal_f_domain"
                    m = [0 0.501 3.162 2.512 0.631 0.501 0.631 1.585 1.995 1.259 2.512 0];
                    b = fir2(100,f,m);
                    app.audiodata = filter(b,1,app.audiodata);
                case "Bass_f_domain"
                    m = [0 3.981 3.162 6.310 1.585 1 1 1 1 1 1 0];
                    b = fir2(100,f,m);
                    app.audiodata = filter(b,1,app.audiodata);
            end
            app.player = audioplayer(app.audiodata,app.fs);
            play(app.player,Current);
            app.play_music.Text = '| |';
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 750 608];
            app.UIFigure.Name = '音乐播放器';
            app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);

            % Create Panel
            app.Panel = uipanel(app.UIFigure);
            app.Panel.TitlePosition = 'centertop';
            app.Panel.Title = '歌曲列表';
            app.Panel.BackgroundColor = [0.9412 0.9412 0.9412];
            app.Panel.FontName = '等线';
            app.Panel.FontWeight = 'bold';
            app.Panel.FontSize = 16;
            app.Panel.Position = [22 14 188 542];

            % Create add
            app.add = uibutton(app.Panel, 'push');
            app.add.ButtonPushedFcn = createCallbackFcn(app, @addPushed, true);
            app.add.FontName = '等线';
            app.add.FontSize = 14;
            app.add.Position = [12 8 73 27];
            app.add.Text = '导入';

            % Create del
            app.del = uibutton(app.Panel, 'push');
            app.del.ButtonPushedFcn = createCallbackFcn(app, @delButtonPushed, true);
            app.del.FontName = '等线';
            app.del.FontSize = 14;
            app.del.Position = [103 8 73 27];
            app.del.Text = '删除';

            % Create MusicList
            app.MusicList = uilistbox(app.Panel);
            app.MusicList.Items = {};
            app.MusicList.ValueChangedFcn = createCallbackFcn(app, @MusicListValueChanged, true);
            app.MusicList.FontSize = 14;
            app.MusicList.Position = [12 50 164 459];
            app.MusicList.Value = {};

            % Create Label
            app.Label = uilabel(app.UIFigure);
            app.Label.VerticalAlignment = 'top';
            app.Label.FontName = '等线';
            app.Label.FontSize = 18;
            app.Label.FontWeight = 'bold';
            app.Label.Position = [320 571 95 23];
            app.Label.Text = '音乐播放器';

            % Create Label_2
            app.Label_2 = uilabel(app.UIFigure);
            app.Label_2.HorizontalAlignment = 'right';
            app.Label_2.VerticalAlignment = 'top';
            app.Label_2.FontName = '等线';
            app.Label_2.FontSize = 14;
            app.Label_2.FontWeight = 'bold';
            app.Label_2.Position = [225 168 63 22];
            app.Label_2.Text = '音乐进度';

            % Create process
            app.process = uislider(app.UIFigure);
            app.process.Limits = [0 1];
            app.process.MajorTicks = [];
            app.process.MajorTickLabels = {};
            app.process.ValueChangedFcn = createCallbackFcn(app, @processValueChanged, true);
            app.process.MinorTicks = [];
            app.process.FontName = '等线';
            app.process.Position = [301 181 323 3];

            % Create Label_4
            app.Label_4 = uilabel(app.UIFigure);
            app.Label_4.HorizontalAlignment = 'right';
            app.Label_4.VerticalAlignment = 'top';
            app.Label_4.FontName = '等线';
            app.Label_4.FontSize = 16;
            app.Label_4.FontWeight = 'bold';
            app.Label_4.Position = [228 67 69 22];
            app.Label_4.Text = '播放速度';

            % Create play_speed
            app.play_speed = uidropdown(app.UIFigure);
            app.play_speed.Items = {'x0.5', 'x0.75', 'x1', 'x1.25', 'x1.5', 'x2'};
            app.play_speed.ValueChangedFcn = createCallbackFcn(app, @play_speedValueChanged, true);
            app.play_speed.FontWeight = 'bold';
            app.play_speed.Position = [304 66 116 28];
            app.play_speed.Value = 'x1';

            % Create version
            app.version = uilabel(app.UIFigure);
            app.version.VerticalAlignment = 'top';
            app.version.FontName = 'Corbel';
            app.version.Position = [416 564 48 22];
            app.version.Text = 'version3';

            % Create play_music
            app.play_music = uibutton(app.UIFigure, 'push');
            app.play_music.ButtonPushedFcn = createCallbackFcn(app, @play_musicButtonPushed, true);
            app.play_music.FontSize = 26;
            app.play_music.FontWeight = 'bold';
            app.play_music.Position = [463 112 74 56];
            app.play_music.Text = '▶';

            % Create last
            app.last = uibutton(app.UIFigure, 'state');
            app.last.ValueChangedFcn = createCallbackFcn(app, @lastValueChanged, true);
            app.last.Text = '上一曲';
            app.last.FontName = '等线';
            app.last.FontSize = 16;
            app.last.FontWeight = 'bold';
            app.last.Position = [332 125 89 32];

            % Create next
            app.next = uibutton(app.UIFigure, 'state');
            app.next.ValueChangedFcn = createCallbackFcn(app, @nextValueChanged, true);
            app.next.Text = '下一曲';
            app.next.FontName = '等线';
            app.next.FontSize = 16;
            app.next.FontWeight = 'bold';
            app.next.Position = [578 124 87 32];

            % Create stop_music
            app.stop_music = uibutton(app.UIFigure, 'state');
            app.stop_music.ValueChangedFcn = createCallbackFcn(app, @stop_musicValueChanged, true);
            app.stop_music.Text = '结束';
            app.stop_music.FontName = '等线';
            app.stop_music.FontSize = 16;
            app.stop_music.FontWeight = 'bold';
            app.stop_music.Position = [454 64 93 32];

            % Create current_time
            app.current_time = uilabel(app.UIFigure);
            app.current_time.FontSize = 14;
            app.current_time.FontWeight = 'bold';
            app.current_time.Position = [642 170 41 22];
            app.current_time.Text = '00:00';

            % Create Label_7
            app.Label_7 = uilabel(app.UIFigure);
            app.Label_7.FontSize = 14;
            app.Label_7.FontWeight = 'bold';
            app.Label_7.Position = [685 170 10 22];
            app.Label_7.Text = '/';

            % Create total_time
            app.total_time = uilabel(app.UIFigure);
            app.total_time.FontSize = 14;
            app.total_time.FontWeight = 'bold';
            app.total_time.Position = [697 170 41 22];
            app.total_time.Text = '00:00';

            % Create Label_9
            app.Label_9 = uilabel(app.UIFigure);
            app.Label_9.HorizontalAlignment = 'right';
            app.Label_9.VerticalAlignment = 'top';
            app.Label_9.FontName = '等线';
            app.Label_9.FontSize = 16;
            app.Label_9.FontWeight = 'bold';
            app.Label_9.Position = [576 66 37 22];
            app.Label_9.Text = '音量';

            % Create music_volume
            app.music_volume = uislider(app.UIFigure);
            app.music_volume.MajorTicks = [];
            app.music_volume.MajorTickLabels = {};
            app.music_volume.ValueChangedFcn = createCallbackFcn(app, @music_volumeValueChanged, true);
            app.music_volume.ValueChangingFcn = createCallbackFcn(app, @music_volumeValueChanging, true);
            app.music_volume.MinorTicks = [];
            app.music_volume.FontName = '等线';
            app.music_volume.Position = [622 79 107 3];
            app.music_volume.Value = 30;

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Position = [227 208 505 348];

            % Create Tab
            app.Tab = uitab(app.TabGroup);
            app.Tab.Title = '时域波形';

            % Create UIAxes2
            app.UIAxes2 = uiaxes(app.Tab);
            xlabel(app.UIAxes2, 't/s')
            ylabel(app.UIAxes2, 'Y')
            app.UIAxes2.PlotBoxAspectRatio = [4.3953488372093 1 1];
            app.UIAxes2.FontName = '等线';
            app.UIAxes2.FontWeight = 'bold';
            app.UIAxes2.XLim = [-Inf Inf];
            app.UIAxes2.YLim = [-Inf Inf];
            app.UIAxes2.YTickLabel = {'0'; '0.5'; '1'};
            app.UIAxes2.XGrid = 'on';
            app.UIAxes2.YGrid = 'on';
            app.UIAxes2.TitleFontWeight = 'bold';
            app.UIAxes2.Box = 'on';
            app.UIAxes2.Position = [2 8 501 155];

            % Create UIAxes1
            app.UIAxes1 = uiaxes(app.Tab);
            xlabel(app.UIAxes1, 't/s')
            ylabel(app.UIAxes1, 'Y')
            app.UIAxes1.PlotBoxAspectRatio = [4.3953488372093 1 1];
            app.UIAxes1.FontName = '等线';
            app.UIAxes1.FontWeight = 'bold';
            app.UIAxes1.XLim = [-Inf Inf];
            app.UIAxes1.YLim = [-Inf Inf];
            app.UIAxes1.YTickLabel = {'0'; '0.5'; '1'};
            app.UIAxes1.XGrid = 'on';
            app.UIAxes1.YGrid = 'on';
            app.UIAxes1.TitleFontWeight = 'bold';
            app.UIAxes1.Box = 'on';
            app.UIAxes1.Position = [2 160 501 155];

            % Create Tab_2
            app.Tab_2 = uitab(app.TabGroup);
            app.Tab_2.Title = '频域波形';

            % Create UIAxes3
            app.UIAxes3 = uiaxes(app.Tab_2);
            xlabel(app.UIAxes3, 'X')
            ylabel(app.UIAxes3, 'Y')
            app.UIAxes3.PlotBoxAspectRatio = [1.77429467084639 1 1];
            app.UIAxes3.FontName = '等线';
            app.UIAxes3.FontWeight = 'bold';
            app.UIAxes3.XLim = [-Inf Inf];
            app.UIAxes3.YLim = [-Inf Inf];
            app.UIAxes3.XGrid = 'on';
            app.UIAxes3.YGrid = 'on';
            app.UIAxes3.TitleFontWeight = 'bold';
            app.UIAxes3.Box = 'on';
            app.UIAxes3.Position = [2 8 500 307];

            % Create Tab_3
            app.Tab_3 = uitab(app.TabGroup);
            app.Tab_3.Title = '包络形状';

            % Create UIAxes4
            app.UIAxes4 = uiaxes(app.Tab_3);
            xlabel(app.UIAxes4, 't/s')
            ylabel(app.UIAxes4, 'Y')
            app.UIAxes4.FontName = '等线';
            app.UIAxes4.FontWeight = 'bold';
            app.UIAxes4.XLim = [-Inf Inf];
            app.UIAxes4.YLim = [-Inf Inf];
            app.UIAxes4.YTickLabel = {'0'; '0.5'; '1'};
            app.UIAxes4.XGrid = 'on';
            app.UIAxes4.YGrid = 'on';
            app.UIAxes4.TitleFontWeight = 'bold';
            app.UIAxes4.Box = 'on';
            app.UIAxes4.Position = [2 160 501 155];

            % Create UIAxes5
            app.UIAxes5 = uiaxes(app.Tab_3);
            xlabel(app.UIAxes5, 't/s')
            ylabel(app.UIAxes5, 'Y')
            app.UIAxes5.FontName = '等线';
            app.UIAxes5.FontWeight = 'bold';
            app.UIAxes5.XLim = [-Inf Inf];
            app.UIAxes5.YLim = [-Inf Inf];
            app.UIAxes5.YTickLabel = {'0'; '0.5'; '1'};
            app.UIAxes5.XGrid = 'on';
            app.UIAxes5.YGrid = 'on';
            app.UIAxes5.TitleFontWeight = 'bold';
            app.UIAxes5.Box = 'on';
            app.UIAxes5.Position = [2 8 501 155];

            % Create Label_10
            app.Label_10 = uilabel(app.UIFigure);
            app.Label_10.FontName = '等线';
            app.Label_10.FontSize = 16;
            app.Label_10.FontWeight = 'bold';
            app.Label_10.Position = [232 23 69 22];
            app.Label_10.Text = '音乐风格';

            % Create Label_11
            app.Label_11 = uilabel(app.UIFigure);
            app.Label_11.FontName = '等线';
            app.Label_11.FontSize = 16;
            app.Label_11.FontWeight = 'bold';
            app.Label_11.Position = [581 20 37 22];
            app.Label_11.Text = '回响';

            % Create resound
            app.resound = uidropdown(app.UIFigure);
            app.resound.Items = {'0', '1000', '2000', '4000', '6000', '8000'};
            app.resound.ValueChangedFcn = createCallbackFcn(app, @resoundValueChanged, true);
            app.resound.FontWeight = 'bold';
            app.resound.Position = [621 17 110 28];
            app.resound.Value = '0';

            % Create style
            app.style = uidropdown(app.UIFigure);
            app.style.Items = {'Normal', 'Jazz_t_domain', 'Rock_t_domain', 'Dance_t_domain', 'Jazz_f_domain', 'Rock_f_domain', 'Metal_f_domain', 'Bass_f_domain'};
            app.style.ValueChangedFcn = createCallbackFcn(app, @styleValueChanged, true);
            app.style.FontWeight = 'bold';
            app.style.Position = [304 20 117 28];
            app.style.Value = 'Normal';

            % Create human
            app.human = uibutton(app.UIFigure, 'state');
            app.human.ValueChangedFcn = createCallbackFcn(app, @humanValueChanged, true);
            app.human.Text = '人声消除';
            app.human.FontName = '等线';
            app.human.FontSize = 16;
            app.human.FontWeight = 'bold';
            app.human.Position = [454 17 93 32];

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = app1

            % Create UIFigure and 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