MATLAB Answers

0

Change from wavplay to audioplayer

Hassan Bosha さんによって質問されました 2019 年 2 月 24 日
最新アクティビティ Walter Roberson
さんによって コメントされました 2019 年 2 月 26 日
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() ?

  0 件のコメント

サインイン to comment.

タグ

1 件の回答

Walter Roberson
回答者: Walter Roberson
2019 年 2 月 24 日
編集済み: Walter Roberson
2019 年 2 月 25 日
 採用された回答

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?

  7 件のコメント

Walter Roberson
2019 年 2 月 25 日
The analyzer is not noticing that you are playing different sounds each time.
Any one audioplayer object is for playing one sound, possibly positioning to different parts of it (though that is not simple.) To play a different sound you need a different audioplayer object. Creation and deletion of those objects is a bit slow. The only way to get streaming would be to have the objects prepared in advance and have the stopfcn of one start the playing of another.
If you want streaming audio then you should give up compatibility with wavplay(), which never supported streaming audio. You should instead switch to the tools available through the Audio System Toolbox: those tools permit you to queue samples to be played while playing is going on.
Hassan Bosha 2019 年 2 月 26 日
will that possible to be done through my code ?
if it's can u show some code examples ?
Walter Roberson
2019 年 2 月 26 日

サインイン to comment.



Translated by