[SOLVED] Putting in an if makes sound play volume lower?

if (timeWantedtoTurn == 0)
{ float volume = 1.0f;
float pitch = -1.0f;
float pan = 0.0f;
trunk1.Play(volume, pitch, pan);
}

if i play it in an if sound volume is lower. if do not use if statement it’s volume is higher.

Makine a if(true) statement OR a if if (timeWantedtoTurn >= 0) makes play volume higher one.

I would like to help, but I do not fully understand what problem you have…

Can you post the 2 different sections of code that play different volumes, so I can compare them?

Not a problem for me but just weird .
This is the all function

public void TurnTrunk(GameTime gameTime)

    {
        float volume = 1.0f;
        float pitch = -1.0f;
        float pan = 0.0f;
        //trunk1.Play(volume, pitch, pan);//This plays higher volume
        if (timeWantedtoTurn == 0)
        {                 
            trunk1.Play(volume, pitch, pan);//This plays lover volume
        }
        if (timeWantedtoTurn == 0)
        {
            
            timeWantedtoTurn = gameTime.TotalGameTime.TotalSeconds;
        }
           
        double delta = gameTime.TotalGameTime.TotalSeconds - timeWantedtoTurn;
        // System.Console.Out.WriteLine(gameTime.TotalGameTime.Milliseconds - timeWanted);
        if (delta > TimeSpan.FromSeconds(1).TotalSeconds&& !tta.flag)
        {
            Texture2D temp = trunks[activeTrunk].texture;
            activeTrunk = (activeTrunk + 1) % 4;
            while (trunks[activeTrunk] == null)
            {
                activeTrunk = (activeTrunk + 1) % 4;
            }
            moveActiveTrunk();
            //Vector2 tempPosition=new Vector2(trunks[activeTrunk].position)
            tta.LoadContent(temp, trunks[activeTrunk].texture, screen, trunks[activeTrunk].position);
            tta.flag = true;
            timeWantedtoTurn = 0;
        }
    }

hmm… You seem to declare the same variables twice, within the same scope…?

I would have thought that code would give you some warning or error, and I dont know why that should give you those problems… But maybe try and change the variable names the for the second part to volume_2 pitch_2 pan_2 and see if that helps…

Sorry it is just copy/paste error. Fixing it.

Have you used breakpoints and checked the values of volume and the others are the same in both scenarios?

Oh sorry, I was waiting for a new post :blush:

So, I’m thinking you might have double or more instances playing simultaneously?

I have had stuff like that going on… So for certain sounds/situations, I will use a simple frame-counter to make sure the sound is only played at certain minimum intervals…

something like :
int counter = 0;
Update()
{
counter++;
if (counter >10)
{
counter = 0;
playSound();
}
}

-the same sound played twice right after each other will sound like one louder sound.

This is probably whats happening, good call :slight_smile:

@Xentios you could test this by still using the if statement but have it evaluate to true every frame, should sound the same as if it was outside the if.