Page 1 of 1

[HELP] Only adjust the volume of a sound

Posted: Thu May 09, 2013 4:44 pm
by PremierePRO

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Win
  #Text_
  #Btn_001
  #Btn_002
  #Btn_003
  #Btn_004
  #Btn_005
EndEnumeration

DataSection 
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001,#PB_Sound_Streaming)
CatchSound(2, ?s002,?End_s002-?s002,#PB_Sound_Streaming)
CatchSound(3, ?s003,?End_s003-?s003,#PB_Sound_Streaming)


If OpenWindow(#Win, 0, 0, 800, 25, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  ButtonGadget(#Btn_001, 0, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_002, 160, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_003, 320, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_004, 480, 0, 160, 25, "QUIT")
  ButtonGadget(#Btn_005, 640, 0, 160, 25, "STOP")
  
  Repeat 
    EventID = WaitWindowEvent()  
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Btn_001 : PlaySound(1)
          Case #Btn_002 : PlaySound(2)
          Case #Btn_003 : PlaySound(3)
          Case #Btn_004 : End
          Case #Btn_005 : StopSound(-1)
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Hello ...

I would like to adjust the volume of a sound code, without having to edit using software editing sounds ...

is it possible?

I Vistro that there is an option in the command PalaySound Volume, I tried to insert a -2, but the volume is always the same ...

Thank you.

Re: [HELP] Only adjust the volume of a sound

Posted: Thu May 09, 2013 4:59 pm
by Joris
I think you need this command :

Code: Select all

SoundVolume(#Sound, Volume [, Channel])

Re: [HELP] Only adjust the volume of a sound

Posted: Thu May 09, 2013 5:54 pm
by VB6_to_PBx

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Win
  #Text_
  #Btn_001
  #Btn_002
  #Btn_003
  #Btn_004
  #Btn_005
EndEnumeration

DataSection
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001,#PB_Sound_Streaming)
CatchSound(2, ?s002,?End_s002-?s002,#PB_Sound_Streaming)
CatchSound(3, ?s003,?End_s003-?s003,#PB_Sound_Streaming)


If OpenWindow(#Win, 0, 0, 960, 25, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  ButtonGadget(#Btn_001, 0, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_002, 160, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_003, 320, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_004, 480, 0, 160, 25, "QUIT")
  ButtonGadget(#Btn_005, 640, 0, 160, 25, "STOP")
  TrackBarGadget(1, 800, 0, 160, 25, 0, 100, #PB_TrackBar_Ticks)
  SetGadgetState(1, 100)
  SoundVolume(#PB_All,100)
  Repeat
    EventID = WaitWindowEvent() 
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1 : SoundVolume(#PB_All,GetGadgetState(1))
          Case #Btn_001 : PlaySound(1)
          Case #Btn_002 : PlaySound(2)
          Case #Btn_003 : PlaySound(3)
          Case #Btn_004 : End
          Case #Btn_005 : StopSound(-1)
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf


Re: [HELP] Only adjust the volume of a sound

Posted: Thu May 09, 2013 6:59 pm
by VB6_to_PBx
if you make "exact" multiple copies of the above Source Code , like 4 exact copies, ( 4 "<New>*X" TABS in IDE )
then Run each of them in turn , the Sound level will be half of what it is for 1 of those copies.

usually it will be the 1st TAB that now will have its Sound Volume suddenly around half the volume
of the other 3 exact code copies .

i noticed that effect a few months ago by accident playing around with
copies of similar code dealing with sound volume or OGG or WAV

could this be some kind of "Bug" in PureBasic Editor ??

Re: [HELP] Only adjust the volume of a sound

Posted: Fri May 10, 2013 12:46 am
by PremierePRO
VB6_to_PBx wrote:

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Win
  #Text_
  #Btn_001
  #Btn_002
  #Btn_003
  #Btn_004
  #Btn_005
EndEnumeration

DataSection
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001,#PB_Sound_Streaming)
CatchSound(2, ?s002,?End_s002-?s002,#PB_Sound_Streaming)
CatchSound(3, ?s003,?End_s003-?s003,#PB_Sound_Streaming)


If OpenWindow(#Win, 0, 0, 960, 25, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  ButtonGadget(#Btn_001, 0, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_002, 160, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_003, 320, 0, 160, 25, "DEMO")
  ButtonGadget(#Btn_004, 480, 0, 160, 25, "QUIT")
  ButtonGadget(#Btn_005, 640, 0, 160, 25, "STOP")
  TrackBarGadget(1, 800, 0, 160, 25, 0, 100, #PB_TrackBar_Ticks)
  SetGadgetState(1, 100)
  SoundVolume(#PB_All,100)
  Repeat
    EventID = WaitWindowEvent() 
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1 : SoundVolume(#PB_All,GetGadgetState(1))
          Case #Btn_001 : PlaySound(1)
          Case #Btn_002 : PlaySound(2)
          Case #Btn_003 : PlaySound(3)
          Case #Btn_004 : End
          Case #Btn_005 : StopSound(-1)
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf

Thank you, but I want to change the volume of just one and you do not all sound ...

Re: [HELP] Only adjust the volume of a sound

Posted: Fri May 10, 2013 8:02 am
by TI-994A
PremierePRO wrote:Thank you, but I want to change the volume of just one and you do not all sound ...
Hi PremierePRO. I've modified the code to individually control the volumes of the sounds, pause and resume their playback by toggling their buttons, and even display their status (paused or playing):

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Vol_001 = 1
  #Vol_002 = 2
  #Vol_003 = 3
  
  #Btn_001 = 4
  #Btn_002 = 5
  #Btn_003 = 6
  #Btn_004
  #Btn_005
  
  #Win
  #Text_
  #labelTimer
EndEnumeration

DataSection
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001)   ;,#PB_Sound_Streaming)
CatchSound(2, ?s002,?End_s002-?s002)   ;,#PB_Sound_Streaming)
CatchSound(3, ?s003,?End_s003-?s003)   ;,#PB_Sound_Streaming)

If OpenWindow(#Win, 0, 0, 800, 60, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  
  Dim buttonLabel.s(5)
  buttonLabel(1) = "DEMO 1"
  buttonLabel(2) = "DEMO 2"
  buttonLabel(3) = "DEMO 3"
  buttonLabel(4) = "QUIT"
  buttonLabel(5) = "STOP"
  ButtonGadget(#Btn_001, 0, 0, 160, 25, buttonLabel(1))
  ButtonGadget(#Btn_002, 160, 0, 160, 25, buttonLabel(2))
  ButtonGadget(#Btn_003, 320, 0, 160, 25, buttonLabel(3))
  ButtonGadget(#Btn_004, 480, 0, 160, 25, buttonLabel(4))
  ButtonGadget(#Btn_005, 640, 0, 160, 25, buttonLabel(5))
  AddWindowTimer(#Win, #labelTimer, 1000)
  
  Define.i tbGadget, xPos = 10, initialVolume = 30
  SoundVolume(#PB_All, initialVolume)
  For tbGadget = 1 To 3
    TrackBarGadget(tbGadget, xPos, 30, 140, 25, 0, 100, #PB_TrackBar_Ticks)
    SetGadgetState(tbGadget, initialVolume)
    xPos + 160
  Next tbGadget  
  
  Repeat
    EventID = WaitWindowEvent() 
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Vol_001, #Vol_002, #Vol_003
            volumeSelect = EventGadget()
            SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
          Case #Btn_001, #Btn_002, #Btn_003
            buttonSelect = EventGadget()
            Select SoundStatus(buttonSelect - 3)
              Case #PB_Sound_Stopped
                PlaySound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Paused
                ResumeSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Playing
                PauseSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Paused)")
            EndSelect    
          Case #Btn_004
            End
          Case #Btn_005
            StopSound(-1)
            For L = 1 To 5
              SetGadgetText(L + 3, buttonLabel(L))
            Next L
        EndSelect
        
      Case #PB_Event_Timer
        For L = 1 To 3
          If SoundStatus(L) = #PB_Sound_Stopped
            SetGadgetText(L + 3, buttonLabel(L))
          EndIf
        Next L

      Case #PB_Event_CloseWindow
        End
        
    EndSelect
  ForEver
EndIf
HOWEVER, there seems to be some issues with PureBasic's SoundStatus() and ResumeSound() functions:
1. If the sound is started with PlaySound() and ends on its own, SoundStatus() will flag it as #PB_Sound_Stopped; but if the sound ends after a PauseSound() and ResumeSound(), SoundStatus() does not return the #PB_Sound_Stopped flag.
2. PauseSound() and ResumeSound() works well with WAV files, but for some reason, OGG files do not resume properly.

In any case, hope it helps you in some way.

[EDIT:]
PureBasic's PauseSound() and ResumeSound() functions do not support #PB_Sound_Streaming; when the flags are commented out, as in the code above, they work perfectly well.

Re: [HELP] Only adjust the volume of a sound

Posted: Fri May 10, 2013 12:30 pm
by PremierePRO
TI-994A wrote:
PremierePRO wrote:Thank you, but I want to change the volume of just one and you do not all sound ...
Hi PremierePRO. I've modified the code to individually control the volumes of the sounds, pause and resume their playback by toggling their buttons, and even display their status (paused or playing):

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Vol_001 = 1
  #Vol_002 = 2
  #Vol_003 = 3
  
  #Btn_001 = 4
  #Btn_002 = 5
  #Btn_003 = 6
  #Btn_004
  #Btn_005
  
  #Win
  #Text_
  #labelTimer
EndEnumeration

DataSection
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001)   ;,#PB_Sound_Streaming)
CatchSound(2, ?s002,?End_s002-?s002)   ;,#PB_Sound_Streaming)
CatchSound(3, ?s003,?End_s003-?s003)   ;,#PB_Sound_Streaming)

If OpenWindow(#Win, 0, 0, 800, 60, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  
  Dim buttonLabel.s(5)
  buttonLabel(1) = "DEMO 1"
  buttonLabel(2) = "DEMO 2"
  buttonLabel(3) = "DEMO 3"
  buttonLabel(4) = "QUIT"
  buttonLabel(5) = "STOP"
  ButtonGadget(#Btn_001, 0, 0, 160, 25, buttonLabel(1))
  ButtonGadget(#Btn_002, 160, 0, 160, 25, buttonLabel(2))
  ButtonGadget(#Btn_003, 320, 0, 160, 25, buttonLabel(3))
  ButtonGadget(#Btn_004, 480, 0, 160, 25, buttonLabel(4))
  ButtonGadget(#Btn_005, 640, 0, 160, 25, buttonLabel(5))
  AddWindowTimer(#Win, #labelTimer, 1000)
  
  Define.i tbGadget, xPos = 10, initialVolume = 30
  SoundVolume(#PB_All, initialVolume)
  For tbGadget = 1 To 3
    TrackBarGadget(tbGadget, xPos, 30, 140, 25, 0, 100, #PB_TrackBar_Ticks)
    SetGadgetState(tbGadget, initialVolume)
    xPos + 160
  Next tbGadget  
  
  Repeat
    EventID = WaitWindowEvent() 
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Vol_001, #Vol_002, #Vol_003
            volumeSelect = EventGadget()
            SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
          Case #Btn_001, #Btn_002, #Btn_003
            buttonSelect = EventGadget()
            Select SoundStatus(buttonSelect - 3)
              Case #PB_Sound_Stopped
                PlaySound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Paused
                ResumeSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Playing
                PauseSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Paused)")
            EndSelect    
          Case #Btn_004
            End
          Case #Btn_005
            StopSound(-1)
            For L = 1 To 5
              SetGadgetText(L + 3, buttonLabel(L))
            Next L
        EndSelect
        
      Case #PB_Event_Timer
        For L = 1 To 3
          If SoundStatus(L) = #PB_Sound_Stopped
            SetGadgetText(L + 3, buttonLabel(L))
          EndIf
        Next L

      Case #PB_Event_CloseWindow
        End
        
    EndSelect
  ForEver
EndIf
HOWEVER, there seems to be some issues with PureBasic's SoundStatus() and ResumeSound() functions:
1. If the sound is started with PlaySound() and ends on its own, SoundStatus() will flag it as #PB_Sound_Stopped; but if the sound ends after a PauseSound() and ResumeSound(), SoundStatus() does not return the #PB_Sound_Stopped flag.
2. PauseSound() and ResumeSound() works well with WAV files, but for some reason, OGG files do not resume properly.

In any case, hope it helps you in some way.

[EDIT:]
PureBasic's PauseSound() and ResumeSound() functions do not support #PB_Sound_Streaming; when the flags are commented out, as in the code above, they work perfectly well.
Thanks ... you're legendary!

What if I want to have only one slider to control overall volume?

PS. Maybe you could help me create a digital VU-meter to be inserted in the code?

Re: [HELP] Only adjust the volume of a sound

Posted: Fri May 10, 2013 2:08 pm
by TI-994A
PremierePRO wrote:What if I want to have only one slider to control overall volume?

PS. Maybe you could help me create a digital VU-meter to be inserted in the code?

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Vol_001 = 1
  #Vol_002 = 2
  #Vol_003 = 3
  
  #Btn_001 = 4
  #Btn_002 = 5
  #Btn_003 = 6
  #Btn_004
  #Btn_005
  
  #Win
  #Text_
  #labelTimer
  #masterVolume
EndEnumeration

DataSection
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001)
CatchSound(2, ?s002,?End_s002-?s002)
CatchSound(3, ?s003,?End_s003-?s003)

If OpenWindow(#Win, 0, 0, 640, 90, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  
  Dim buttonLabel.s(5)
  buttonLabel(1) = "DEMO 1"
  buttonLabel(2) = "DEMO 2"
  buttonLabel(3) = "DEMO 3"
  buttonLabel(4) = "QUIT"
  buttonLabel(5) = "STOP"
  ButtonGadget(#Btn_001, 0, 0, 160, 25, buttonLabel(1))
  ButtonGadget(#Btn_002, 160, 0, 160, 25, buttonLabel(2))
  ButtonGadget(#Btn_003, 320, 0, 160, 25, buttonLabel(3))
  ButtonGadget(#Btn_004, 480, 45, 160, 45, buttonLabel(4))
  ButtonGadget(#Btn_005, 480, 0, 160, 45, buttonLabel(5))
  AddWindowTimer(#Win, #labelTimer, 1000)
  
  Define.i L, tbGadget, xPos = 10, initialVolume = 10, volumeSelect
  SoundVolume(#PB_All, initialVolume)
  For tbGadget = 1 To 3
    TrackBarGadget(tbGadget, xPos, 25, 140, 25, 0, 100)
    SetGadgetState(tbGadget, initialVolume)
    xPos + 160
  Next tbGadget  
  
  TrackBarGadget(#masterVolume, 10, 50, 460, 30, 0, 100, #PB_TrackBar_Ticks)
  SetGadgetState(#masterVolume, initialVolume)
  
  Repeat
    EventID = WaitWindowEvent() 
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #masterVolume
            SoundVolume(#PB_All, GetGadgetState(#masterVolume))
            For volumeSelect = 1 To 3
              SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
              SetGadgetState(volumeSelect, GetGadgetState(#masterVolume))
            Next volumeSelect
          Case #Vol_001, #Vol_002, #Vol_003
            volumeSelect = EventGadget()
            SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
          Case #Btn_001, #Btn_002, #Btn_003
            buttonSelect = EventGadget()
            Select SoundStatus(buttonSelect - 3)
              Case #PB_Sound_Stopped
                PlaySound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Paused
                ResumeSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Playing
                PauseSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Paused)")
            EndSelect    
          Case #Btn_004
            End
          Case #Btn_005
            StopSound(-1)
            For L = 1 To 5
              SetGadgetText(L + 3, buttonLabel(L))
            Next L
        EndSelect
        
      Case #PB_Event_Timer
        For L = 1 To 3
          If SoundStatus(L) = #PB_Sound_Stopped
            SetGadgetText(L + 3, buttonLabel(L))
          EndIf
        Next L

      Case #PB_Event_CloseWindow
        End
        
    EndSelect
  ForEver
EndIf
I've added a master volume control that will override all the volume controls, but the individual controls still work. A digital VU display may be tougher. :lol:

Re: [HELP] Only adjust the volume of a sound

Posted: Fri May 10, 2013 3:25 pm
by PremierePRO
TI-994A wrote:
PremierePRO wrote:What if I want to have only one slider to control overall volume?

PS. Maybe you could help me create a digital VU-meter to be inserted in the code?

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Vol_001 = 1
  #Vol_002 = 2
  #Vol_003 = 3
  
  #Btn_001 = 4
  #Btn_002 = 5
  #Btn_003 = 6
  #Btn_004
  #Btn_005
  
  #Win
  #Text_
  #labelTimer
  #masterVolume
EndEnumeration

DataSection
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001)
CatchSound(2, ?s002,?End_s002-?s002)
CatchSound(3, ?s003,?End_s003-?s003)

If OpenWindow(#Win, 0, 0, 640, 90, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  
  Dim buttonLabel.s(5)
  buttonLabel(1) = "DEMO 1"
  buttonLabel(2) = "DEMO 2"
  buttonLabel(3) = "DEMO 3"
  buttonLabel(4) = "QUIT"
  buttonLabel(5) = "STOP"
  ButtonGadget(#Btn_001, 0, 0, 160, 25, buttonLabel(1))
  ButtonGadget(#Btn_002, 160, 0, 160, 25, buttonLabel(2))
  ButtonGadget(#Btn_003, 320, 0, 160, 25, buttonLabel(3))
  ButtonGadget(#Btn_004, 480, 45, 160, 45, buttonLabel(4))
  ButtonGadget(#Btn_005, 480, 0, 160, 45, buttonLabel(5))
  AddWindowTimer(#Win, #labelTimer, 1000)
  
  Define.i L, tbGadget, xPos = 10, initialVolume = 10, volumeSelect
  SoundVolume(#PB_All, initialVolume)
  For tbGadget = 1 To 3
    TrackBarGadget(tbGadget, xPos, 25, 140, 25, 0, 100)
    SetGadgetState(tbGadget, initialVolume)
    xPos + 160
  Next tbGadget  
  
  TrackBarGadget(#masterVolume, 10, 50, 460, 30, 0, 100, #PB_TrackBar_Ticks)
  SetGadgetState(#masterVolume, initialVolume)
  
  Repeat
    EventID = WaitWindowEvent() 
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #masterVolume
            SoundVolume(#PB_All, GetGadgetState(#masterVolume))
            For volumeSelect = 1 To 3
              SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
              SetGadgetState(volumeSelect, GetGadgetState(#masterVolume))
            Next volumeSelect
          Case #Vol_001, #Vol_002, #Vol_003
            volumeSelect = EventGadget()
            SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
          Case #Btn_001, #Btn_002, #Btn_003
            buttonSelect = EventGadget()
            Select SoundStatus(buttonSelect - 3)
              Case #PB_Sound_Stopped
                PlaySound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Paused
                ResumeSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Playing
                PauseSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Paused)")
            EndSelect    
          Case #Btn_004
            End
          Case #Btn_005
            StopSound(-1)
            For L = 1 To 5
              SetGadgetText(L + 3, buttonLabel(L))
            Next L
        EndSelect
        
      Case #PB_Event_Timer
        For L = 1 To 3
          If SoundStatus(L) = #PB_Sound_Stopped
            SetGadgetText(L + 3, buttonLabel(L))
          EndIf
        Next L

      Case #PB_Event_CloseWindow
        End
        
    EndSelect
  ForEver
EndIf
I've added a master volume control that will override all the volume controls, but the individual controls still work. A digital VU display may be tougher. :lol:
Thank you ....

I have seen many examples of VU meter, but I can not place it in my code, as well as a password code for the software, but as always I can not insert it at the beginning of the code, it works by itself, but when I insert my from the error code after ...

Thanks anyway.

Re: [HELP] Only adjust the volume of a sound

Posted: Fri May 10, 2013 6:32 pm
by TI-994A
PremierePRO wrote:I have seen many examples of VU meter, but I can not place it in my code, as well as a password code for the software, but as always I can not insert it at the beginning of the code, it works by itself, but when I insert my from the error code after...
* the password for this example is texasinstruments:

Code: Select all

InitSound()
UseOGGSoundDecoder()

Enumeration
  #Vol_001 = 1
  #Vol_002 = 2
  #Vol_003 = 3
  #Btn_001 = 4
  #Btn_002 = 5
  #Btn_003 = 6
  #Btn_004
  #Btn_005
  #Win
  #Text_
  #labelTimer
  #masterVolume
EndEnumeration

DataSection
  IncludePath "E:\Music\"
  s001: IncludeBinary "your1.ogg":  End_s001:
  s002: IncludeBinary "your2.ogg": End_s002:
  s003: IncludeBinary "your3.ogg":  End_s003:
EndDataSection

CatchSound(1, ?s001,?End_s001-?s001)
CatchSound(2, ?s002,?End_s002-?s002)
CatchSound(3, ?s003,?End_s003-?s003)

If OpenWindow(#Win, 0, 0, 640, 90, "DEMO", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  
;##################
; PASSWORD ROUTINE START
;##################

  Define.i tryAgain, tries = 0, authorized = 0
  Define.s password, MD5Fpassword = "45aaf3660c8ae47332d334059041e15b"   ;replace with your encrypted password
  Repeat 
    password = InputRequester("", "Please enter your password:", "", #PB_InputRequester_Password)
    If MD5Fingerprint(@password, StringByteLength(password)) <> MD5Fpassword
      tries + 1
      If tries > 2
        MessageRequester ("Access Denied!", "Allowable tries exceeded. Program shutting down.")
        CloseWindow(#Win) : End
      EndIf
      tryAgain = MessageRequester ("Access Denied!", "You entered an invalid password." + 
                                    #CRLF$ + "Try again?", #PB_MessageRequester_YesNo)
      If tryAgain = #PB_MessageRequester_No
        CloseWindow(#Win) : End
      EndIf
    Else
      authorized = 1
    EndIf
  Until authorized = 1    

;####################
; PASSWORD ROUTINE END
;####################

  Dim buttonLabel.s(5)
  buttonLabel(1) = "DEMO 1"
  buttonLabel(2) = "DEMO 2"
  buttonLabel(3) = "DEMO 3"
  buttonLabel(4) = "QUIT"
  buttonLabel(5) = "STOP"
  ButtonGadget(#Btn_001, 0, 0, 160, 25, buttonLabel(1))
  ButtonGadget(#Btn_002, 160, 0, 160, 25, buttonLabel(2))
  ButtonGadget(#Btn_003, 320, 0, 160, 25, buttonLabel(3))
  ButtonGadget(#Btn_004, 480, 45, 160, 45, buttonLabel(4))
  ButtonGadget(#Btn_005, 480, 0, 160, 45, buttonLabel(5))
  AddWindowTimer(#Win, #labelTimer, 1000)
  
  Define.i L, tbGadget, xPos = 10, initialVolume = 10, volumeSelect
  SoundVolume(#PB_All, initialVolume)
  For tbGadget = 1 To 3
    TrackBarGadget(tbGadget, xPos, 25, 140, 25, 0, 100)
    SetGadgetState(tbGadget, initialVolume)
    xPos + 160
  Next tbGadget  
  
  TrackBarGadget(#masterVolume, 10, 50, 460, 30, 0, 100, #PB_TrackBar_Ticks)
  SetGadgetState(#masterVolume, initialVolume)
  
  Repeat
    EventID = WaitWindowEvent() 
    Select EventID
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #masterVolume
            SoundVolume(#PB_All, GetGadgetState(#masterVolume))
            For volumeSelect = 1 To 3
              SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
              SetGadgetState(volumeSelect, GetGadgetState(#masterVolume))
            Next volumeSelect
          Case #Vol_001, #Vol_002, #Vol_003
            volumeSelect = EventGadget()
            SoundVolume(volumeSelect, GetGadgetState(volumeSelect))
          Case #Btn_001, #Btn_002, #Btn_003
            buttonSelect = EventGadget()
            Select SoundStatus(buttonSelect - 3)
              Case #PB_Sound_Stopped
                PlaySound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Paused
                ResumeSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Playing)")
              Case #PB_Sound_Playing
                PauseSound(buttonSelect - 3)
                SetGadgetText(buttonSelect, buttonLabel(buttonSelect - 3) + " (Paused)")
            EndSelect    
          Case #Btn_004
            End
          Case #Btn_005
            StopSound(-1)
            For L = 1 To 5
              SetGadgetText(L + 3, buttonLabel(L))
            Next L
        EndSelect
      Case #PB_Event_Timer
        For L = 1 To 3
          If SoundStatus(L) = #PB_Sound_Stopped
            SetGadgetText(L + 3, buttonLabel(L))
          EndIf
        Next L
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
I've inserted a fairly simple password protection into your example, and it uses PureBasic's MD5Fingerprint encryption to obscure the hardcoded string. Please do bear in mind that it is a very simple implementation of program security, and anyone with a reverse debugger would be able to bypass the routine and run the program.

You can use this simple routine to create your own MD5Fingerprint passwords, and paste them into the code above:

Code: Select all

;MD5Fingerprint-encrypted password creator:

password.s = InputRequester("", "Please enter your desired password:", "")
password = MD5Fingerprint(@password, StringByteLength(password))
SetClipboardText(password)
MessageRequester ("MD5Fingerprinting", "Your encrypted password is: " + password + #CRLF$ +
      #CRLF$ + "It has also been copied to the clipboard for easy pasting into your code.")

; edit the main code: MD5Fpassword = "the newly generated password should be pasted here"
The implementation of a digital VU meter is a fairly complex process, and requires direct soundcard API calls, and would also not be a cross-platform solution. If you have any working examples, please do post them, and perhaps someone may be able to adapt it for your requirements.

Re: [HELP] Only adjust the volume of a sound

Posted: Fri May 10, 2013 10:17 pm
by davido
A vu meter was shared in this url: http://www.purebasic.fr/english/viewtop ... t=vu+meter

I hope you find it of interest.