Android Code Snippet Change Pitch of Wave File Playback using SoundPool

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
 

DonManfred

Expert
Licensed User
Longtime User
Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png


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

Danamo

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

codetag001.png

codetag002.png

codetag003.png


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

Oops, sorry, my bad!

B4X:
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
 
Top