B4A Library AudioTrack

This is a wrapper library for the AudioTrack Object, simlar to the AudioRecord object, it's more complex to use than the MediaPlayer but has some functionality that is useful for audio processing.

I haven't had time to test this one thoroughly, I thought you may like to play with it as well. Let me know if you find anything that doesn't work.

The attachment is quite big as it has an example wav file that is loaded via a random access file and played via Audiotrack, just to give an idea.

Edit: V1.01 fixed a typo and Separate file for libs only
17/1/12 Added swt.zip, quick and dirty sine wave generator as an example.
Added swt1-1.zip a few more refinements.
Added swt1-2.zip better tuning
Updated lib files to 1.2 - needed for swt1-2
13/2/12 Added and reformatted Constants - audiotrack1.3
19/3/12 Updated SWT to reach 19khz and added input fields (touch the display labels)

15/1/21
  • Added attest2
  • Updated example with a Stream Static and looping example.
  • Replaced threading with Wait For and Sleep in the streaming example. For heavy usage, it may still be necessary to use threading, so I'll leave the original example here as well.
 

Attachments

Last edited:
No Raw audio only I'm afraid. Compression/formatting would need to be written as with the WAV header.
 
Thank you Stevel. I want to make a player that can slow down or speed up audio files. Do you have any idea?
 
Have a look at vb1992's post earlier in this thread. I'm not sure if it will work on the fly though.

To get it to keep the same pitch you will need to resample the file, there are lot's of references on the internet but I haven't come across an Android library yet.

Andrew and Klaus's fft library will help, not that I'd know how to apply it unfortunately.


Sent from my Hero using Tapatalk
 
Last edited:
I just don't get it I guess.

After loading the samples provided, I immediately get an error showing in the IDE with the statement: Dim Play As Thread

Play shows as red, as does Thread, like I'm missing a library or something.

What do I need to do here? Sorry for the new_b question.
 
Answer in post #25 :D
 
i have downloaded swt1-3.zip but it can not run when i click play button as showing an error

Compiling code. Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 121
Play.Start("PlaySound",Array As Object(DurSB.Value))
Word: )
.

pls advise where it is problem
 
Compile error in attest.zip

I downloaded the attest.zip and display error when compile:
Code:
Compiling code.                         Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 56
Play.Start("Playing",Null)
Word: )
Any suggestion?
 
@junaidahmed and Sally3599

For B4A V2, the threading library has changed which requires a change in the play.start method, see here.

Fot this ecample you can just add null as the first parameter, so

Play.Start("Playing",Null)

becomes

Play.Start(Null,"Playing",Null)

I will incorporate this in the examples shortly.
 
Capturing Audio w/o recording

Is it possible to capture audio without it recording? I want to capture microphone audio and analyze it. One application is a real random number generator. I am trying to be kind to the device because these things have a finite number of write operations and if this object can capture audio into a buffer and allow the program to analyze it in real time then that would be wonderful.
 
There is an java lib for android need to convert to b4a at

BASS for Android

this has change speed without changing pitch

grCor

Have a look at vb1992's post earlier in this thread. I'm not sure if it will work on the fly though.

To get it to keep the same pitch you will need to resample the file, there are lot's of references on the internet but I haven't come across an Android library yet.

Andrew and Klaus's fft library will help, not that I'd know how to apply it unfortunately.


Sent from my Hero using Tapatalk
 
Hi Cor, yes I've seen this, unfortunately it's not simple. It requires use of the NDK for at least 1 library (soundtouch). I have played with the soundtouch library on it's own and have had it working but with not very pleasing results.

I very quickly get out of my knowledge comfort zone when working with C and the NDK, but I am keeping a eye on the android environment forums to see if anyone has cracked it that are willing to share.
 
@Stevel05
Thank you for sharing your audiotrack and audiorecord libraries. :) I am currently playing with the demo programs and have two questions:

1. How can i loop a part of a wav file? There is a setlooppoints method in audiotrack, but i don't know how to use it.

2. How can i resample a wave file? i would like to change the play rate and eliminate the pitch-shift-effect.
 
I think that to use looping you need to initialize the audiotrack as MODE_STATIC, there's not much info on the internet about it though so I'm afraid it'll be a bit of trial and error, I've not tried it.

to change the playbackrate, have a look here. If you mean that you want to keep the same frequency, then you'll have to find an algorithm or library to do it. i've been looking at soundtouch, but without success. Not that I've given up totally, just may take a while.

Steve
 
Last edited:
Hi Steve,

SetLoopPoints works fine with MODE_STATIC.

:sign0060:

Thanks again for these great libraries.
 
Back
Top