필터 지우기
필터 지우기

How can I make the function audioplayer global?

조회 수: 1 (최근 30일)
Magnus Woodgate
Magnus Woodgate 2016년 3월 11일
댓글: Walter Roberson 2016년 3월 12일
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.

채택된 답변

Walter Roberson
Walter Roberson 2016년 3월 12일
global variables need to be redeclared as global in every function they are to be used in.
  댓글 수: 2
Magnus Woodgate
Magnus Woodgate 2016년 3월 12일
Hi I tried this in:
global x;
global Fs;
player = audioplayer(x,Fs);
play(player);
But the audio still wouldn't play. However for some reason, using the "playblocking" feature it would play the chosen sample but obviously this means I cannot pause/resume/stop the audio but instead have to wait for it to complete.
Is there any way I can use the "play" feature still whilst using the global variables created from using the "audioread" data?
Thanks.
Walter Roberson
Walter Roberson 2016년 3월 12일
You are letting your player object go out of scope, which is resulting in the player object being deleted.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by