Hi,
I'd like to use a slider for the control of the volume.
I tried this :
y_temp=y;
disp(get(hObject,'Value'));
if(get(hObject,'Value')==0)
y_temp=0;
else
y_temp=(get(hObject,'Value')/10)*y;
end
pl=audioplayer(y_temp,f);
resume(pl);
But it doesn't work because when I change the volume, the music starts at the beginning.
Is there a way to control the volume without retarting the music ?
Thank you

답변 (2개)

Walter Roberson
Walter Roberson 2014년 3월 25일

0 개 추천

Get the audioplayer CurrentSample property. use the audioplayer stop() method to stop playing. Scale the samples for the entire rest of the sound after CurrentSample. audioplayer() that new data.
As you go remember that CurrentSample will be relative to what was queued, so you need to keep track of how far into the original sound you had gotten in order to be able to scale and continue properly.
audioplayer() does not offer any method to flush the queue and queue new samples, or to change the data that is currently queued. If you want to do add more samples to the queue on the fly, you need to work with the Data Acquisition Toolbox.
Note MS Windows systems you may be able to use ActiveX to adjust the volume controls.

댓글 수: 6

Thibault
Thibault 2014년 3월 25일
Thank you, I understand ! :) But one more question : how can I scale the samples for the entire rest of the sound after CurrentSample ?
Thank you
Honglei Chen
Honglei Chen 2014년 3월 25일
You could set up a variable, say k, and at the beginning, it's 1. Then you always pass in k*x instead of x into the audio player. You want to be able to control volume in real time any way.
Thibault
Thibault 2014년 3월 25일
Yes, but if I don't want to start at the beginning each time I change the volume. I have to get the audioplayer CurrentSample property, then I stop audio player, then I want to resume my music but after CurrentSample.
Honglei Chen
Honglei Chen 2014년 3월 25일
which syntax are you using? If you are using audioplayer with an input argument, then you just need to scale the input samples, no need to touch audioplayer
Thibault
Thibault 2014년 3월 25일
Thank you, I succeed :) But how can I get : get(pl,'TotalSamples') in seconds ? Thanks
Walter Roberson
Walter Roberson 2014년 3월 25일
get() the SampleRate property and divide TotalSamples by that.

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

JIANGYU HUANG
JIANGYU HUANG 2016년 4월 14일

0 개 추천

i meet the same problem now so do you know how to solve this. can you teach me??

카테고리

태그

질문:

2014년 3월 25일

답변:

2016년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by