MATLAB: Change from wavplay to audioplayer

audioplayer

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 stop file_name C;
stop=1;
equalizer_play();
function equalizer_play()
global stop file_name C;
[x,Fs]= audioread(file_name);
[a,b]=coef();
l_bucata=2*Fs;
Nb=round(length(x)/l_bucata);
y=0;
for i=1:floor(Nb)
bucata=x((i-1)*l_bucata+1:i*l_bucata);
for k=1:5
y=y+filter(10^(C(k)/20)*b{k},a{k},bucata);
if(stop==0)
break;
end
end
wavplay(y,Fs,'async');
y=0;
if(stop==0)
break;
end
end
i want to change this code to fit audioplayer() ?

Best Answer

p = audioplayer(y, Fs);
playblocking(p);
Note that using playblocking() is not exactly the same as what you have now. Your current code loops back around and starts playing the new y for the next i while the first wavplay is still playing, and leaves up to floor(Nb) sounds playing simultaneously when the function returns. It is possible to emulate that behaviour, but is it really what you want?