Playing 3 different audio samples using 3 different buttons on GUI?
古いコメントを表示
I have 3 different convolved signals which I would like to play out using 3 different buttons using callbacks using UI control. I have following code for creating the GUI and playing out the signals. When I press the first button, pushbutton1_Callback needs to play sound 1 and print "is working". In the commnad window, "is working" is printed but I get the following error message:
Undefined function or variable 'player1'.
Error in playaudio/playaudio/pushbutton1_Callback (line 95)
play(player1);
player1 = audioplayer(sig_conv_WB,fs);
player2 = audioplayer(sig_conv_HybIR_125,fs);
player3 = audioplayer(sig_conv_HybIR_250,fs);
this.wavebased = uicontrol(hfig,'style','push',...
'position',[sl*0.35 sh*0.85 sl*0.3 sh*0.1],... %[sl*0.2 (sh/2)+(sh*0.2) sl*0.6 sh*0.1]
'string','Wave Based','fontsize',16,...
'callback',@pushbutton1_Callback);
this.hybrid125 = uicontrol(hfig,'style','push',...
'position',[sl*0.35 sh*0.70 sl*0.3 sh*0.1 ],... %[sl*0.2 (sh/2)+(sh*0.2) sl*0.6 sh*0.1]
'string','Hybrid 125','fontsize',16,...
'callback',@pushbutton2_Callback);
this.hybrid250 = uicontrol(hfig,'style','push',...
'position',[sl*0.35 sh*0.55 sl*0.3 sh*0.1 ],... %[sl*0.2 (sh/2)+(sh*0.2) sl*0.6 sh*0.1]
'string','Hybrid 250','fontsize',16,...
'callback',@pushbutton3_Callback);
function pushbutton1_Callback(this, ~, ~)
disp('is working')
play(player1);
end
function pushbutton2_Callback(this, ~, ~)
play(player2);
end
function pushbutton3_Callback(this, ~, ~)
play(player3);
end
Can someone help me solve this?
回答 (1 件)
David Hill
2022 年 2 月 14 日
You need to pass player1, player2, and player3 to your functions. One way is to make the functions part of an overall function.
function Start()
player1 = audioplayer(sig_conv_WB,fs);
player2 = audioplayer(sig_conv_HybIR_125,fs);
player3 = audioplayer(sig_conv_HybIR_250,fs);
hfig=figure;
sl=500;sh=300;
this.wavebased = uicontrol(hfig,'style','push',...
'position',[sl*0.35 sh*0.85 sl*0.3 sh*0.1],... %[sl*0.2 (sh/2)+(sh*0.2) sl*0.6 sh*0.1]
'string','Wave Based','fontsize',16,...
'callback',@pushbutton1_Callback);
this.hybrid125 = uicontrol(hfig,'style','push',...
'position',[sl*0.35 sh*0.70 sl*0.3 sh*0.1 ],... %[sl*0.2 (sh/2)+(sh*0.2) sl*0.6 sh*0.1]
'string','Hybrid 125','fontsize',16,...
'callback',@pushbutton2_Callback);
this.hybrid250 = uicontrol(hfig,'style','push',...
'position',[sl*0.35 sh*0.55 sl*0.3 sh*0.1 ],... %[sl*0.2 (sh/2)+(sh*0.2) sl*0.6 sh*0.1]
'string','Hybrid 250','fontsize',16,...
'callback',@pushbutton3_Callback);
function pushbutton1_Callback(this, ~, ~)
display(player1);
end
function pushbutton2_Callback(this, ~, ~)
display(player2);
end
function pushbutton3_Callback(this, ~, ~)
display(player3);
end
end
2 件のコメント
Tanmayee Pathre
2022 年 2 月 14 日
David Hill
2022 年 2 月 14 日
Yep, need to pass your signals to the function
function Start(sig_conv_WB,sig_conv_HybIR_125,sig_conv_HybIR_250)
カテゴリ
ヘルプ センター および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!