B4A Library Audio library v0.9

Edit: V0.91 is available with support for SoundPool.
SoundPool allows you to load many short sounds and then play those files with low latency. A short example is also attached.
The first version of the Audio library is available. This is a beta version and it includes support for JetPlayer.

See this link for more information about JetPlayer: SONiVOX JETCreator User Manual | Android Developers

A short example which plays the JET file that is included in the Android SDK is available here: http://www.b4x.com/android/files/AudioExample.zip

Installation instructions:
Unzip the attach file and copy both files to the Additional Libraries path or the internal libraries path: C:\Program Files\Anywhere Software\Basic4android\Libraries.
 

Attachments

  • Audio.zip
    6.9 KB · Views: 1,009
  • SoundPoolExample.zip
    52.6 KB · Views: 1,567

James Moxham

Member
Licensed User
Longtime User
This is very good. Compiled and playing some sounds while I type this.

A few questions:
1) I had to change one line to
B4X:
      JP.LoadFile("/sdcard", "level1.jet")
and manually copy the file to the sd card. Is there a way of including "level1.jet" as part of the compilation process and sending it over at the same time? Or is it indeed better to put these large files on an sd card to save filling up the memory of the Android?

2) My display is blank. But touching various parts of the display plays different sounds. I gather the graphics parts of programs are separate. Maybe I didn't install that bit?

3) Is it possible to edit an instrument from within code? Specifically, to create an array of 16 bit integer data as in the raw data used in a .wav file, and then to play this as an instrument without saving the data to disk? I'm thinking of playing 2400 baud data files. Also, I'm thinking of doing some direct digital synthesis by adding sine waves and it would be cool to play the sounds and then tweak the harmonic weights. Or is the jet player more a midi player than a synth? I think you said there was another audio device on the way soon.

It sure is great to be able to play sounds this easily. This really will add to any games one might want to write! Thanks Erel.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You can include your file (assuming it is not more than a few mb) in the Files tab in the right pane. Then you can access it an in my code: JP.LoadFile(File.DirAssets, "level1.jet")
2. There is no display for this demo.
I used the Activity_Click event to change the segment:
B4X:
Sub Activity_Click
    JP.ClearQueue
    JP.QueueSegment(1, 0, 0, Rnd(-12, 13), mute, SegmentId)
    SegmentId = SegmentId + 1
    JP.Play
End Sub
3) This is not supported by JetPlayer.
 

Cor

Active Member
Licensed User
Longtime User
Where can I download the SONiVOX JET Creator?

See only python download on the android info site
 

James Moxham

Member
Licensed User
Longtime User
Interesting reading. I agree it would not be good to include code that has bugs otherwise Basic4Android would get blamed for those bugs.
 

Highwinder

Active Member
Licensed User
Longtime User
SoundPool Limitations

Erel,

What is the maximum length (time? size?) that a sound file can be that SoundPool will play?

Thanks
 

Rusty

Well-Known Member
Licensed User
Longtime User
Does this allow one to play a sound track and during its play, to be able to insert or play another track and then resume.
Example:
Sound track one, speaking: "Hello, my name is "
Sound track two, speaking: "Rusty. "
Sound track one (continuing or sound track three): "What is your name?"
Thanks,
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Erel,
How can one load three (for example) sound tracks, play the first and then immediately play the second and then immediately play the third, without any latency?
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Sorry Erel.
I thought I was continuing exactly the same question.
Regards,
Rusty
 

Fusseldieb

Active Member
Licensed User
Longtime User
I have put the "Rate" to 0.05 on Erels example with "bounce.wav"... It sound like a horror movie xD
Btw, "Rate" goes from "0" to "2", but I have tested with "10", "40", "50", etc. and it plays just fine. I'm using Android 5.0, but is there any compatibilty issue when I use eg. "30" with older devices?
 
Top