Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MATLAB Gui Volume Control?

Subject: MATLAB Gui Volume Control?

From: D Nguyen

Date: 29 Sep, 2009 16:45:19

Message: 1 of 6

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: arich82

Date: 7 Oct, 2009 19:18:01

Message: 2 of 6

> 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: 3 of 6

"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: 4 of 6

> 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: 5 of 6

"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: 6 of 6

> 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

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.

Contact us