Android Question Simulate car engine sound

Mostez

Well-Known Member
Licensed User
Longtime User
my application is a wi-fi toy car controller, I just want to add sound effect to simulate car engine sound on phone, I have an integer representing the speed , it changes according to press time on speed pedal button. I want to make something like:

B4X: Copy
Sub SimulateCarEngineSound(Speed as int)
'car engine roares high or low according to value of 'Speed'
End Sub

TIA
 
here is what I've done, the result is acceptable though it suffers 'silent gaps' while switching wav files
B4X: Copy
If SoundOn Then
        Dim fileName As String
        Select True
            Case Speed = 0
                fileName = "idle.wav"
            Case Speed > 0 And Speed <= maxSpeed * .33
                fileName = "offlow.wav"
            Case Speed > maxSpeed * .33 And Speed <= maxSpeed * .66
                fileName = "onlow.wav"
            Case Speed > maxSpeed * .66 And maxSpeed <= maxSpeed
                fileName = "onhigh.wav"
        End Select

        If fileName = LastSoundFile Then Return
        LastSoundFile = fileName
        If MP.IsPlaying Then MP.Pause
        MP.Load(File.DirAssets, fileName)
        MP.SetVolume(1,1)
        MP.Looping = True
        MP.Play
        
    End If
 
Upvote 0
You could also try soundpool, which allows looping and setting the rate will change the pitch (if I remember correctly).
 
Upvote 1
Back
Top