Matlab GUI中的音量滑块 [英] Volume Slider in Matlab GUI

查看:401
本文介绍了Matlab GUI中的音量滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上一篇文章的链接:
关于Audioplayer GUI的Matlab问题

Link of Previous Post:
Matlab Questions about Audioplayer GUI

我正在尝试在Matlab中制作音量滑块...
因此,目前我从搜索中想到的是使用handles变量来获取滑块的值.之后,我打算让变量在音频播放器中乘以(x,fs).
我当前的句柄开头代码是这样的...

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)`

因此,当我尝试在此之后播放"音频时,出现以下错误:
未定义的函数或变量"a".

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? >.<

编辑

我设法解决(?)错误:未定义的函数或变量'a'.

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...

当我尝试将handles.a与x相乘时,"*"来自

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 :

在slider1_Callback中:

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);

您的音频样本多长时间?如果时间太长,可能会花费一些时间来加载和中断播放.为了减少加载时间,您可以考虑保存数据(例如,在按钮的"userdata"属性之一中).

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).

这篇关于Matlab GUI中的音量滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆