How can I make the function audioplayer global?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Magnus Woodgate
am 11 Mär. 2016
Kommentiert: Walter Roberson
am 12 Mär. 2016
So basically i'm making a wav player that will apply some FX to the file that is loaded into the gui. There are currently just the 2 buttons "Load Wav" and "Play".
"Load Wav" searches for a file of the users choice as follows:
[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
global x; %attempted to make the variables global so that the play callback can use the audioplayer function with (x, Fs)
global Fs;
[x,Fs] = audioread([PathName '/' FileName]);
handles.fileLoaded = 1;
guidata(hObject, handles);
Then in the "play" button is just:
player=audioplayer(x,Fs);
play(player);
The "Load Wav" button seems to store the data of the chosen file fine, however when the function for "playButton_Callback(hObject, eventdata, handles)" is used, it doesn't recognise the variables "x" or "Fs", even though they are stored as global variables.
Any help would be greatly appreciated, apologies if this is a simple question I'm relatively new to MatLab.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Mär. 2016
global variables need to be redeclared as global in every function they are to be used in.
2 Kommentare
Walter Roberson
am 12 Mär. 2016
You are letting your player object go out of scope, which is resulting in the player object being deleted.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!