Playing 3 different audio samples using 3 different buttons on GUI?

3 visualizaciones (últimos 30 días)
Tanmayee Pathre
Tanmayee Pathre el 14 de Feb. de 2022
Comentada: David Hill el 14 de Feb. de 2022
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?

Respuestas (1)

David Hill
David Hill el 14 de Feb. de 2022
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 comentarios
Tanmayee Pathre
Tanmayee Pathre el 14 de Feb. de 2022
Hello. Thanks for the answer. But it doesnt work. I get the following error message.
Undefined function or variable 'sig_conv_WB'.
Error in Start (line 2)
player1conv = audioplayer(sig_conv_WB,fs);
David Hill
David Hill el 14 de Feb. de 2022
Yep, need to pass your signals to the function
function Start(sig_conv_WB,sig_conv_HybIR_125,sig_conv_HybIR_250)

Iniciar sesión para comentar.

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by