Android Code Snippet Change Pitch of Wave File Playback using SoundPool

Discussion in 'Code Snippets' started by Danamo, Dec 29, 2017.

  1. Danamo

    Danamo Member Licensed User

    Sub Process_Globals
    'Requires Audio library
    Private Pool As SoundPool
    End Sub

    Sub PlayRecording
    Dim ret As Int 'Used in call to Pool.Play. ret = 0 if error occurs
    Dim PoolID As Int 'Identifies the Pool number when a sound file is loaded
    Dim SourceDir As String = File.DirInternal 'or the Directory where your file is located
    Dim SourceFileName As String = "yourfilename.wav" 'The file you wish to use
    Dim VolumeLeft As Double = 1 ' = Value between 0 and 1 for Left Channel
    Dim VolumeRight As Double = 1 ' = Value between 0 and 1 for Right Channel
    Dim Pitch As Double = 1 '= Value between 0 and 2: <1 is low pitch, 1 is normal, 2 is highest pitch
    Dim Priority As Int = 1 'SoundPool Documentation says this value is irrelevant, is for future use
    Dim Loop As Int = 0 'Number of times to repeat the sound, -1 to repeat indefinitely

    'Load the sound
    PoolID = Pool.Load(SourceDir,SourceFileName) 'Loads the file and gets it's number in the pool.

    Sleep(100) 'Some delay required between pool loading and playback - I'm unsure why or how much?

    'Play the sound
    ret = Pool.Play(PoolID,VolumeLeft,VolumeRight,Priority,Loop,Pitch)
    End Sub
     
  2. DonManfred

    DonManfred Expert Licensed User

    Please use [CODE]code here...[/CODE] tags when posting code.

    [​IMG]
    [​IMG]
    [​IMG]

    PD: You got this told a few times in the past!
     
  3. Danamo

    Danamo Member Licensed User

    Oops, sorry, my bad!

    Code:
    Sub Globals
        
    'Requires Audio library
        Private Pool As SoundPool
    End Sub

    Sub PlayRecording
        
    Dim ret As Int 'Used in call to Pool.Play. ret = 0 if error occurs
        Dim PoolID As Int 'Identifies the Pool number when a sound file is loaded
        Dim SourceDir As String = File.DirInternal 'or the Directory where your file is located
        Dim SourceFileName As String = "yourfilename.wav" 'The file you wish to use
        Dim VolumeLeft As Double = 1 ' = Value between 0 and 1 for Left Channel
        Dim VolumeRight As Double = 1 ' = Value between 0 and 1 for Right Channel
        Dim Pitch As Double = 1 '= Value between 0 and 2: <1 is low pitch, 1 is normal, 2 is highest pitch
        Dim Priority As Int = 1 'SoundPool Documentation says this value is irrelevant, is for future use
        Dim Loop As Int = 0 'Number of times to repeat the sound, -1 to repeat indefinitely

        
    'Load the sound
        PoolID = Pool.Load(SourceDir,SourceFileName) 'Loads the file and gets it's number in the pool.

        Sleep(
    100'Some delay required between pool loading and playback - I'm unsure why or how much?

        
    'Play the sound
        ret = Pool.Play(PoolID,VolumeLeft,VolumeRight,Priority,Loop,Pitch)
    End Sub
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice