Results 1 to 7 of 7

Math Help - Help with my MATLAB DJ program?

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    9

    Help with my MATLAB DJ program?

    I am making a MATLAB DJ program in which I can load in a song, have it display on a listbox, stop, pause, and play it, as well as determine it's BPM. I am trying to use audioplayer for my push buttons (stop, play, etc.) but for some reason, it is not working properly. I used GUIDE to make my GUI, but I will show my m.file

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

    % Last Modified by GUIDE v2.5 29-Apr-2010 20:22:36

    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name', mfilename, ...
    'gui_Singleton', gui_Singleton, ...
    'gui_OpeningFcn', @MatlabMedia_OpeningFcn, ...
    'gui_OutputFcn', @MatlabMedia_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 MatlabMedia is made visible.
    function MatlabMedia_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 MatlabMedia (see VARARGIN)
    axis off
    % Choose default command line output for MatlabMedia
    handles.output = hObject;

    % Update handles structure
    guidata(hObject, handles);

    % UIWAIT makes MatlabMedia wait for user response (see UIRESUME)
    % uiwait(handles.figure1);
    global p
    p=audioplayer();

    % --- Outputs from this function are returned to the command line.
    function varargout = MatlabMedia_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 stop.
    function stop_Callback(hObject, eventdata, handles)
    % hObject handle to stop (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    clear playsnd

    % --- Executes on button press in play.
    function play_Callback(hObject, eventdata, handles)
    % hObject handle to play (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    global p
    [y f]=wavread(get(handles.list,'String'));
    p=audioplayer(y,f);
    play(y)

    %wavplay(y,f,'async')

    % --- Executes on button press in pause.
    function pause_Callback(hObject, eventdata, handles)
    % hObject handle to pause (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    global p
    [y f]=wavread(get(handles.list,'String'));
    p=audioplayer(y);
    pause(y)


    % --- Executes on button press in load.
    function load_Callback(hObject, eventdata, handles)
    % hObject handle to load (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    global p
    [file path] = uigetfile('*.wav*','Select your song')
    song=[path file];
    %p=audioplayer(file);
    %y=wavread(song);
    %song = fullfile(y,file);
    set(handles.list,'String',song);




    Whenever I try to run my program, I get these errors

    ??? Error using ==> audioplayer.audioplayer at 44
    Not enough input arguments.

    Error in ==> MatlabMedia>MatlabMedia_OpeningFcn at 64
    p=audioplayer();

    Error in ==> gui_mainfcn at 221
    feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure),
    varargin{:});

    Error in ==> MatlabMedia at 42
    gui_mainfcn(gui_State, varargin{:});

    I could play the wav files using wavplay, but then i cannot use stop and pause features that audioplayer has...
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    I am unfamiliar with the audioplayer function but it looks like it requires at least 2 inputs. You seem to call it with no inputs at one stage?

    Create object for playing audio - MATLAB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2010
    Posts
    9
    I was trying to set a global variable at the beginning an was told that was how to go about it.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    Code:
    global p
    should be all you need although I haven't run your code as it wont work without your fig file.

    Generally I try to avoid global variables.
    Here is a short tutorial I started trying to put together on making GUI's with matlab. You can place variables inside the handle structure to avoid using globals. It might be something you want to consider, although using globals will work too of course).

    http://www.mathhelpforum.com/math-he...-tutorial.html


    Elbarto
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Feb 2010
    Posts
    9
    Thanks for the responses. I went to my TA's recitation and he helped me out. I can now load a wav file in, play, pause, and stop it.

    I was wondering if anyone has ideas on how to simultaneously play songs?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Newbie
    Joined
    Nov 2009
    Posts
    3
    Quote Originally Posted by nottheface View Post
    Thanks for the responses. I went to my TA's recitation and he helped me out. I can now load a wav file in, play, pause, and stop it.

    I was wondering if anyone has ideas on how to simultaneously play songs?

    Just interested: How did you end up stopping it while playing?
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Feb 2010
    Posts
    9
    made a stop button

    Called the global p variable at the start of the call back
    typed in stop(p)
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Writing a program in MATLAB
    Posted in the Math Software Forum
    Replies: 1
    Last Post: September 13th 2011, 05:08 AM
  2. How to program this in matlab or python: matrices
    Posted in the Math Software Forum
    Replies: 0
    Last Post: April 19th 2011, 08:02 AM
  3. Matlab Date Sorting Program, need help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 28th 2010, 12:51 AM
  4. Converting an R-program to MATLAB
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 17th 2009, 06:54 AM
  5. MATLAB program creation help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: November 7th 2009, 06:53 PM

Search Tags


/mathhelpforum @mathhelpforum