Thread Subject:
MATLAB Gui Volume Control?

Subject: MATLAB Gui Volume Control?

From: D Nguyen

Date: 29 Sep, 2009 16:45:19

Message: 1 of 10

Hello all,

I am trying to design a GUI interface with the option of adjusting the volume via a slider in the GUI figure. I have tried searching this up but can not find anything that will alter the settings of the system. This GUI will be running on a Windows XP system. I want to be able to slide the slider up and down, and it will either lower or increase the volume. Is this possible?

Subject: MATLAB Gui Volume Control?

From: Ashish Uthama

Date: 29 Sep, 2009 18:30:48

Message: 2 of 10

On Tue, 29 Sep 2009 12:45:19 -0400, D Nguyen <dnguyen1022@gmail.com> wrote:

> Hello all,
>
> I am trying to design a GUI interface with the option of adjusting the
> volume via a slider in the GUI figure. I have tried searching this up
> but can not find anything that will alter the settings of the system.
> This GUI will be running on a Windows XP system. I want to be able to
> slide the slider up and down, and it will either lower or increase the
> volume. Is this possible?

If its just something you want to control the volume of sound output from
MATLAB, have a look at the xpsound demo.

I couldnt find anything easily online to change the system volume. There
are quite a few 'freeware' packages which claim to provide command line
control, but I dont trust them/ have the inclination to check it out.
sndvol32.exe (native app) brings up the volume control, but I couldnt find
a volume change switch. If it had one, you could have used a SYSTEM call
to send in appropriate volume values.

If you find a way to control the volume using .NET assemblies, you could
check MATLAB .NET interface:

Please find more details online at:
     http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brpcay8-1.html#brtk59p-1
Or please paste this in the MATLAB command window:
     web([docroot,'/techdoc/matlab_external/brpcay8-1.html#brtk59p-1'])

Subject: MATLAB Gui Volume Control?

From: D Nguyen

Date: 1 Oct, 2009 16:50:21

Message: 3 of 10

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u0061mxsa5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 29 Sep 2009 12:45:19 -0400, D Nguyen <dnguyen1022@gmail.com> wrote:
>
> > Hello all,
> >
> > I am trying to design a GUI interface with the option of adjusting the
> > volume via a slider in the GUI figure. I have tried searching this up
> > but can not find anything that will alter the settings of the system.
> > This GUI will be running on a Windows XP system. I want to be able to
> > slide the slider up and down, and it will either lower or increase the
> > volume. Is this possible?
>
> If its just something you want to control the volume of sound output from
> MATLAB, have a look at the xpsound demo.
>
> I couldnt find anything easily online to change the system volume. There
> are quite a few 'freeware' packages which claim to provide command line
> control, but I dont trust them/ have the inclination to check it out.
> sndvol32.exe (native app) brings up the volume control, but I couldnt find
> a volume change switch. If it had one, you could have used a SYSTEM call
> to send in appropriate volume values.
>
> If you find a way to control the volume using .NET assemblies, you could
> check MATLAB .NET interface:
>
> Please find more details online at:
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brpcay8-1.html#brtk59p-1
> Or please paste this in the MATLAB command window:
> web([docroot,'/techdoc/matlab_external/brpcay8-1.html#brtk59p-1'])
>
>

Hm...problem is I don't know .NET and learning a whole new language may take me quite a long time as I don't have a lot of free time. Does anybody else have an alternative to this?

I am also looking at the xpsound demo. It appears it has the volume slider and does adjust the volume..however how do I see the code for this?

Subject: MATLAB Gui Volume Control?

From: arich82

Date: 1 Oct, 2009 17:17:04

Message: 4 of 10

"D Nguyen" <dnguyen1022@gmail.com> wrote in message <ha2mkd$ehg$1@fred.mathworks.com>...
> "Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u0061mxsa5ziv5@uthamaa.dhcp.mathworks.com>...
> > On Tue, 29 Sep 2009 12:45:19 -0400, D Nguyen <dnguyen1022@gmail.com> wrote:
> >
> > > Hello all,
> > >
> > > I am trying to design a GUI interface with the option of adjusting the
> > > volume via a slider in the GUI figure. I have tried searching this up
> > > but can not find anything that will alter the settings of the system.
> > > This GUI will be running on a Windows XP system. I want to be able to
> > > slide the slider up and down, and it will either lower or increase the
> > > volume. Is this possible?
> >
> > If its just something you want to control the volume of sound output from
> > MATLAB, have a look at the xpsound demo.
> >
> > I couldnt find anything easily online to change the system volume. There
> > are quite a few 'freeware' packages which claim to provide command line
> > control, but I dont trust them/ have the inclination to check it out.
> > sndvol32.exe (native app) brings up the volume control, but I couldnt find
> > a volume change switch. If it had one, you could have used a SYSTEM call
> > to send in appropriate volume values.
> >
> > If you find a way to control the volume using .NET assemblies, you could
> > check MATLAB .NET interface:
> >
> > Please find more details online at:
> > http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brpcay8-1.html#brtk59p-1
> > Or please paste this in the MATLAB command window:
> > web([docroot,'/techdoc/matlab_external/brpcay8-1.html#brtk59p-1'])
> >
> >
>
> Hm...problem is I don't know .NET and learning a whole new language may take me quite a long time as I don't have a lot of free time. Does anybody else have an alternative to this?
>
> I am also looking at the xpsound demo. It appears it has the volume slider and does adjust the volume..however how do I see the code for this?

Type:
>> open xpsound;

Depending on your needs, you could just link your slider to a multiplier s.t. 0<A<1 and scale your amplitude when you playback.

Compare:

A = 0.1;
load handel;
sound(y, Fs);
sound(A*y, Fs);

Subject: MATLAB Gui Volume Control?

From: D Nguyen

Date: 7 Oct, 2009 17:01:04

Message: 5 of 10

"arich82 " <|a|r|i|c|8|2|@hotmail.com> wrote in message <ha2o6g$som$1@fred.mathworks.com>...
> "D Nguyen" <dnguyen1022@gmail.com> wrote in message <ha2mkd$ehg$1@fred.mathworks.com>...
> > "Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u0061mxsa5ziv5@uthamaa.dhcp.mathworks.com>...
> > > On Tue, 29 Sep 2009 12:45:19 -0400, D Nguyen <dnguyen1022@gmail.com> wrote:
> > >
> > > > Hello all,
> > > >
> > > > I am trying to design a GUI interface with the option of adjusting the
> > > > volume via a slider in the GUI figure. I have tried searching this up
> > > > but can not find anything that will alter the settings of the system.
> > > > This GUI will be running on a Windows XP system. I want to be able to
> > > > slide the slider up and down, and it will either lower or increase the
> > > > volume. Is this possible?
> > >
> > > If its just something you want to control the volume of sound output from
> > > MATLAB, have a look at the xpsound demo.
> > >
> > > I couldnt find anything easily online to change the system volume. There
> > > are quite a few 'freeware' packages which claim to provide command line
> > > control, but I dont trust them/ have the inclination to check it out.
> > > sndvol32.exe (native app) brings up the volume control, but I couldnt find
> > > a volume change switch. If it had one, you could have used a SYSTEM call
> > > to send in appropriate volume values.
> > >
> > > If you find a way to control the volume using .NET assemblies, you could
> > > check MATLAB .NET interface:
> > >
> > > Please find more details online at:
> > > http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brpcay8-1.html#brtk59p-1
> > > Or please paste this in the MATLAB command window:
> > > web([docroot,'/techdoc/matlab_external/brpcay8-1.html#brtk59p-1'])
> > >
> > >
> >
> > Hm...problem is I don't know .NET and learning a whole new language may take me quite a long time as I don't have a lot of free time. Does anybody else have an alternative to this?
> >
> > I am also looking at the xpsound demo. It appears it has the volume slider and does adjust the volume..however how do I see the code for this?
>
> Type:
> >> open xpsound;
>
> Depending on your needs, you could just link your slider to a multiplier s.t. 0<A<1 and scale your amplitude when you playback.
>
> Compare:
>
> A = 0.1;
> load handel;
> sound(y, Fs);
> sound(A*y, Fs);

So A is the amplitude which basically can increase or decrease my volume right?
What does load handel do? And what about the sound(A*y, FS)? I know y is the vector and FS is the frequency. However what is y a vector of?

Subject: MATLAB Gui Volume Control?

From: arich82

Date: 7 Oct, 2009 19:18:01

Message: 6 of 10

> So A is the amplitude which basically can increase or decrease my volume right?
> What does load handel do? And what about the sound(A*y, FS)? I know y is the vector and FS is the frequency. However what is y a vector of?

Try it and find out!

Check 'help sound'.

'handel' is some built-in data for demos; it's a short clip of Handel's Hallelujah Chorus. It automatically loads the vector 'y' with a time trace of the amplitude, and the scalar 'Fs' denoting the frequency at which the data was recorded. I just used it as dummy data since I don't have your data.

'sound(A*y, FS)' should be obvious if you read the help. 'A*y' is simply rescaling the amplitude in y by factor A, and SOUND causes Matlab to play the vector over your computer speakers.

Put your amplitude data from an amplitude vs. time trace into vector y and try it.

Subject: MATLAB Gui Volume Control?

From: D Nguyen

Date: 14 Oct, 2009 16:51:03

Message: 7 of 10

"arich82 " <|a|r|i|c|8|2|@hotmail.com> wrote in message <haiph9$9ua$1@fred.mathworks.com>...
> > So A is the amplitude which basically can increase or decrease my volume right?
> > What does load handel do? And what about the sound(A*y, FS)? I know y is the vector and FS is the frequency. However what is y a vector of?
>
> Try it and find out!
>
> Check 'help sound'.
>
> 'handel' is some built-in data for demos; it's a short clip of Handel's Hallelujah Chorus. It automatically loads the vector 'y' with a time trace of the amplitude, and the scalar 'Fs' denoting the frequency at which the data was recorded. I just used it as dummy data since I don't have your data.
>
> 'sound(A*y, FS)' should be obvious if you read the help. 'A*y' is simply rescaling the amplitude in y by factor A, and SOUND causes Matlab to play the vector over your computer speakers.
>
> Put your amplitude data from an amplitude vs. time trace into vector y and try it.

Ok so I was able to figure it out. Thank you! However there is a problem...everytime I move the slider the music plays even if a music file is already playing. Is there a way to determine if a music file is already playing?

I tried creating a play button where I check to see if the button is toggled. If not I set soundLev(variable I'm multiplying y by to adjust sound) to 0. I thought possibly maybe the functions within the gui would be running concurrently to each other but apparently not. The toggler button is a separate function within the same .m file. How do I do it so that the slider function reads in the value from the toggled button?

Subject: MATLAB Gui Volume Control?

From: arich82

Date: 15 Oct, 2009 03:04:02

Message: 8 of 10

> Ok so I was able to figure it out. Thank you! However there is a problem...everytime I move the slider the music plays even if a music file is already playing. Is there a way to determine if a music file is already playing?

> I tried creating a play button where I check to see if the button is toggled. If not I set soundLev(variable I'm multiplying y by to adjust sound) to 0. I thought possibly maybe the functions within the gui would be running concurrently to each other but apparently not. The toggler button is a separate function within the same .m file. How do I do it so that the slider function reads in the value from the toggled button?

Think about what the function did: it scaled the entire vector by A, then sent it to the 'sound' function. Even if the callback knew A was updated, the data has already been scaled and sent. As written, the best it could do is send another vector to sound.

Some of the other GUI experts might have a better answer, but my guess is that this method won't be very amenable to interactively changing the volume during playback since it scales the entire sound vector.

Furthermore, I'm thinking the 'sound' command should be in the 'play button' callback, not in the slider. When 'play' is pressed, it should set it so the button is no longer selectable, read in the value of the slider, scale the sound vector, play the vector, then set itself to be selectable again. The only thing the slider should do is set the value of A, to be queried by 'play'.

You could also grey out the slider during the 'play' callback to let the user know that the volume won't be adjusted until the next execution, but this doesn't get around the fact that you don't have interactive volume control (it just lowers the user's expectation of such).

If you're good at Java, you can check the undocumentedmatlab.com blog to see if you can access the system volume (perhaps through the systray?) using Java, which could possibly give you interactive control.

Hopefully someone else might have more answers for you. Good luck.


--

Subject: MATLAB Gui Volume Control?

From: D Nguyen

Date: 15 Oct, 2009 04:28:02

Message: 9 of 10

"arich82 " <|a|r|i|c|8|2|@hotmail.com> wrote in message <hb63f2$c8f$1@fred.mathworks.com>...
> > Ok so I was able to figure it out. Thank you! However there is a problem...everytime I move the slider the music plays even if a music file is already playing. Is there a way to determine if a music file is already playing?
>
> > I tried creating a play button where I check to see if the button is toggled. If not I set soundLev(variable I'm multiplying y by to adjust sound) to 0. I thought possibly maybe the functions within the gui would be running concurrently to each other but apparently not. The toggler button is a separate function within the same .m file. How do I do it so that the slider function reads in the value from the toggled button?
>
> Think about what the function did: it scaled the entire vector by A, then sent it to the 'sound' function. Even if the callback knew A was updated, the data has already been scaled and sent. As written, the best it could do is send another vector to sound.
>
> Some of the other GUI experts might have a better answer, but my guess is that this method won't be very amenable to interactively changing the volume during playback since it scales the entire sound vector.
>
> Furthermore, I'm thinking the 'sound' command should be in the 'play button' callback, not in the slider. When 'play' is pressed, it should set it so the button is no longer selectable, read in the value of the slider, scale the sound vector, play the vector, then set itself to be selectable again. The only thing the slider should do is set the value of A, to be queried by 'play'.
>
> You could also grey out the slider during the 'play' callback to let the user know that the volume won't be adjusted until the next execution, but this doesn't get around the fact that you don't have interactive volume control (it just lowers the user's expectation of such).
>
> If you're good at Java, you can check the undocumentedmatlab.com blog to see if you can access the system volume (perhaps through the systray?) using Java, which could possibly give you interactive control.
>
> Hopefully someone else might have more answers for you. Good luck.
>
>
> --

hm..I see does anybody have a possible solution to this without the use of java?

Subject: MATLAB Gui Volume Control?

From: Yair Altman

Date: 15 Oct, 2009 16:17:19

Message: 10 of 10

> If you're good at Java, you can check the undocumentedmatlab.com blog to see if you can access the system volume (perhaps through the systray?) using Java, which could possibly give you interactive control.


Of course: http://undocumentedmatlab.com/blog/updating-speaker-sound-volume/

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
java Yair Altman 15 Oct, 2009 12:19:07
volume control D Nguyen 29 Sep, 2009 12:49:03
gui D Nguyen 29 Sep, 2009 12:49:03
rssFeed for this Thread

Contact us