Link of Previous Post:
Matlab Questions about Audioplayer GUI
I am trying to make a volume slider in Matlab...
So currently what I have in mind from what I have searched is using handles variable to get the slider's value. After that, I am planning to have the variable multiply the (x,fs) in the audioplayer.
My current code for the beginning of the handle is like this...
handles.a = [] ; %I don't know what to put for this >.<
handles.output = hObject;
handles.myPlayer=[];
guidata(hObject, handles);
My code for the volume slider is like this:
function slider1_Callback(hObject, eventdata, handles)
handles.a = get(handles.slider1,'Value');
guidata(hObject,handles);
And my code for the audioplayer will be something like this(not sure if it will work if I do it this way):
FullPath='C:\Users\Y400\Documents\MATLAB\test1';
[x,Fs]=wavread(FullPath);
handles.myPlayer = audioplayer(handles.a*x,Fs);
play(handles.myPlayer);`
guidata(hObject, handles)`
So when I tried "Playing" the audio after this, I get the following error:
Undefined function or variable 'a'.
Will appreciate it if anyone can guide me on this? >.<
EDIT
I manage to solve(?) the error: Undefined Function or Variable 'a'.
My current error now is I am getting this error:
Error using * Inner matrix dimensions must agree.
Above code is edited to have the following error as well...
The " * " comes from when I try to multiply handles.a with x
Let's now see how we can do to increase/decrease the volume without restarting the sample play :
In the slider1_Callback :
function slider1_Callback(hObject,handles,eventdata)
%Pause audioplayer
pause(handles.myPlayer);
%Know how far the user has got in the sample
NewStart=get(handles.myPlayer,'CurrentSample')+1;
%stop current player
stop(handles.myPlayer);
%Reload your sample
[x,Fs]=wavread(FullPath);
%Create a new sample by cutting x and keeping only the lines from NewStart
%to the end
x=x(NewStart:end,:);
%Get the value of the slider
Volume=get(handles.slider1,'value');
%Set new audioplayer
handles.myPlayer=audioplayer(x*Volume,Fs);
%Play
play(handles.myPlayer);
% save handles structure
guidata(hObject,handles);
How long is your audio sample? If it's too long, it might take some time to load and interrupt play. To reduce loading times, you might consider saving the data (for example in one of your button's 'userdata' property).