We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,939 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

sound control

hi i have a sound control on my website, i need to put a condition to check, when the xcoordinate is increasing, the sound volume increase and if xcoordinate is decreasing, sound volume decrease. I'm having trouble to set this condition, i dont know how to put this. Can you help me?

2
Contributors
9
Replies
1 Week
Discussion Span
7 Months Ago
Last Updated
10
Views
techyworld
Junior Poster
198 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

If you are talking about using pure JavaScript to control audio level, I doublt it can because the language is not a audio player...

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

I am using Ocanvas library and Buzz library. using ocanvas, i can capture the x coordinate, and with buzz i can increase the sound. i just need a condition if (x increasing) increase volume and vice versa

techyworld
Junior Poster
198 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

If you could obtain the value, then you may need a local variable and store the current captured value. Whenever the value is changed, compared the new value with the current value and deal with it. Then, update the current value to the changed value. If you still do not understand, please provide the script where you obtain the value and where the value changing event occur.

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17
 var soundcontrol;
            window.onload=function()
            {
                drawcanvas();
                draw();
                soundcontrol = new mysound();
                soundcontrol.playmenusound();
                volume();

            } 

            function drawcanvas()
            {//code to draw canvas}

            function draw()
            {
                //codes to draw line
                //codes to draw ellipse on line 
                //append both line and ellipse on canvas

                //the following are codes to drag the ellipse back and forward along the line   
                ellipse.dragAndDrop({
                    move: function ()
                    {
                        //capture the x coordinate an validate motion

                        curX= canvas.mouse.x;

                        if(curX<0)
                        {
                            this.moveTo(0,10);
                        }//lower bound
                        else if(curX>50)
                        {
                            this.moveTo(50,10);
                        }//upper bound
                        else
                        {
                            this.moveTo(canvas.mouse.x,10);

                        } },    

                    end: function () 
                    {
                        if(curX<32)
                        {
                            this.moveTo(0,10);

                        }
                        else if(curX>200)
                        {
                            this.moveTo(50,10);

                        }
                        else
                        {
                            this.moveTo(curX,10);
                            //I think i should place the condition here. but how? 

                        }}});}}

        function mysound()
        {
            this.sound="";
            this.playmenusound=function()
            {
                sound= new buzz.sound("mysong.mp3");
                sound.play();   
            }   
        }

I am using ocanvas and buzz library(for sound). So to increase/decrease the sound , ijust need to use this .increaseVolume() and .decreaseVolume(). canvas.mouse.x = capturing the x position of th emouse pointer. So where should i place the condition and how? I'm confused.

techyworld
Junior Poster
198 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

It's going to be inside }} at line 41. Also, you need to have a currentVolume declared somewhere outside to be used as global for the function. A question I would ask is that can you specify the value of increase/decrease volume? If so, assume the value range from 0 as 0% and 50 as 100% of volume. The percentage of the volume would be computed as VOLUMN_PERCENTAGE = curX*2;. In order to do so, you need to update certain things...

var currentVolume = 50;  // default is max?
...
curX= canvas.mouse.x;

if(curX<0)
{
    this.moveTo(0,10);
    curX = 0;
}//lower bound
else if(curX>50)
{
    this.moveTo(50,10);
    curX = 50;
}//upper bound
else
{
    this.moveTo(canvas.mouse.x,10);

}
// if there is no way to set a step value, then below is what it is...
if (curX>currentVolume) { increaseVolume(); }
else if (curX<currentVolume) { decreaseVolume(); }
// otherwise, you could compute the value...
// my assumption is that there is a setVolume(VALUE) function
// setVolume(curX*2);
currentVolume = curX;
},    
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

yes i can use .setVolume()

techyworld
Junior Poster
198 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I did not understand the following
// otherwise, you could compute the value...
// my assumption is that there is a setVolume(VALUE) function
// setVolume(curX*2);
currentVolume = curX;

techyworld
Junior Poster
198 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

It means that if you don't use the if-else statement, you could simply use setVolume() to the value the curX is selected instead. However, the currentVolume must still be set to curX after the move() function is called.

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

ok thanks

techyworld
Junior Poster
198 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.3228 seconds using 2.67MB