Android Question sound sugestion

Douglas Farias

Expert
Licensed User
Longtime User
Hi
Im making a drum app. And i have a a question.
What is the best way to play souns in the same times?
I m go make 5 - 10 buttons and add sound to this
How the best way to play sons fast ??click : sound . 2 clicks : 2 sounds fast ??

I tested wigh mediaplayer. audio library snd soundpool but give much delay i cNt press 3 simultaneos buttons for exemple.
 

Douglas Farias

Expert
Licensed User
Longtime User
Erel i m using this
this is my code but it is slow i cant press 3 buttons on same time, dont give a sound
and 2 buttons fast too, i downloaded the real drum from google play and works 3 4 buttons and same time
soundpoll is the best way to make a drum ? or have another
this is my project look this and tell me it is correct or i need make change pls thx

B4X:
#Region  Project Attributes
    #ApplicationLabel: Bateria
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: True
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bumbos,tarols,chipos As Int
    Dim sp As SoundPool
    Private chipo As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    sp.Initialize(50)
    bumbos = sp.Load(File.DirAssets, "bumbo.mp3")
    tarols = sp.Load(File.DirAssets, "tarol.mp3" )
    chipos = sp.Load(File.DirAssets, "chipo.mp3" )
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub bumbo_Click
    sp.Play(bumbos ,1,1,2,0,1 )
End Sub
Sub tarol_Click
    sp.Play(tarols ,1,1,2,0,1 )
End Sub
Sub chipo_Click
    sp.Play(chipos ,1,1,2,0,1 )
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You need to use the gesture library to capture multiple touches on the screen.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
how can i set gesture to my button?


B4X:
Sub bumbo_Click
    sp.Play(bumbos ,1,1,2,0,1 )
End Sub
Sub tarol_Click
    sp.Play(tarols ,1,1,2,0,1 )
End Sub
Sub chipo_Click
    sp.Play(chipos ,1,1,2,0,1 )
End Sub
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
hmm thx erel

this is correct?

i need know only one, later i make the others *-*

B4X:
#Region  Project Attributes
    #ApplicationLabel: Bateria
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: True
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bumbos,tarols,chipos As Int
    Dim sp As SoundPool
    Private chipo As Button
    Dim g As Gestures
    Private Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    sp.Initialize(50)
    bumbos = sp.Load(File.DirAssets, "bumbo.mp3")
    tarols = sp.Load(File.DirAssets, "tarol.mp3" )
    chipos = sp.Load(File.DirAssets, "chipo.mp3" )
    g.SetOnTouchListener(Panel1, "pnl_gesture")
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub bumbo_Click
    sp.Play(bumbos ,1,1,2,0,1 )
End Sub
Sub tarol_Click
    sp.Play(tarols ,1,1,2,0,1 )
End Sub
Sub chipo_Click
    sp.Play(chipos ,1,1,2,0,1 )
End Sub
Sub pnl_gesture (o As Object, ptrID As Int, action As Int, x As Float, y As Float) As Boolean
    sp.Play(bumbos ,1,1,2,0,1 )
End Sub
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
@Erel i make this and works
2 panel with a diferent song and works, i can press at same time and work

B4X:
#Region  Project Attributes
    #ApplicationLabel: Bateria
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: True
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bumbos,tarols,chipos As Int
    Dim sp As SoundPool
    Private chipo As Button
    Dim g As Gestures
    Dim Panel2 As Panel
Dim Panel3 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    Panel2.Initialize("Panel2")
    Panel2.Color = Colors.LightGray
    Panel2.Tag = "Panel2"
   
    Panel3.Initialize("Panel3")
    Panel3.Color = Colors.LightGray
    Panel3.Tag = "Panel3"
    'Panel3.Initialize("Panel3")
    g.SetOnTouchListener(Panel2, "Panel2_GesturesTouch")
        g.SetOnTouchListener(Panel3, "Panel3_GesturesTouch")
'    g.SetOnTouchListener(Panel3, "Panel3_GesturesTouch")
Activity.AddView(Panel2, 5%x, 5dip, 10%y, 310dip)
Activity.AddView(Panel3, 20%x, 5dip, 10%y, 310dip)
   
    sp.Initialize(50)
    bumbos = sp.Load(File.DirAssets, "bumbo.mp3")
    tarols = sp.Load(File.DirAssets, "tarol.mp3" )
    chipos = sp.Load(File.DirAssets, "chipo.mp3" )
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Panel2_GesturesTouch(o As Object, ptrID As Int, action As Int, x As Float, y As Float) As Boolean

            sp.Play(bumbos ,1,1,1,0,1 )

    'Return True ' need to return true otherwise we don't get any other events in the gesture

End Sub

Sub Panel3_GesturesTouch(o As Object, ptrID As Int, action As Int, x As Float, y As Float) As Boolean

            sp.Play(tarols ,1,1,2,0,1 )

    'Return True ' need to return true otherwise we don't get any other events in the gesture

End Sub


Sub bumbo_Click
    sp.Play(bumbos ,1,1,2,0,1 )
End Sub
Sub tarol_Click
    sp.Play(tarols ,1,1,2,0,1 )
End Sub
Sub chipo_Click
    sp.Play(chipos ,1,1,2,0,1 )
End Sub

but why dont work when i add the panel2 on design ?

only works with this
Activity.AddView(Panel2, 5%x, 5dip, 10%y, 310dip)

in design when i make a panel2 dont work
for me Activity.AddView(Panel2, 5%x, 5dip, 10%y, 310dip)
is hard to work because i need make a correct place for all instruments *-*
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
As this is something I have spent a lot of time working on, and at the risk of writing most of your app for you, here is an example that will manage the sounds and images (with a little extra work).

It makes use of Maps, Types and Rect's to make managing the sounds, touch area/Images on the screen and the sound types easier. It will handle one shot apps, like Drum Kits and Time - Touch dependent instruments like pianos etc (with more work on the layout).

It will currently handle 5 sounds at once, if you want more and your device will handle that many touches, increase the value in
B4X:
SP.Initialize(5)

If you have more touches than available notes (for a piano or similar), you may get an error or it may just not play the additional sounds, (I haven't tested that) if you do get an error, you'll need to manage the number of concurrent pointers in the Gest_Touch Sub.

If there is anything you don't understand, just ask.
 

Attachments

  • MTE.zip
    27.7 KB · Views: 520
Last edited:
Upvote 0
Top