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

  • attest.zip
    305.8 KB · Views: 1,691
  • AudioTrack1.3.zip
    7.8 KB · Views: 1,844
  • swt1-3.zip
    8.5 KB · Views: 1,481
  • attest2.zip
    298.4 KB · Views: 503
Last edited:

stevel05

Expert
Licensed User
Longtime User
You need to specify the stream type so its:

B4X:
at.SetPlaybackRate(at.GetNativeOutputSampleRate(at.Stream_Music)*2)

Steve
 

vb1992

Well-Known Member
Licensed User
Longtime User
This is what worked with a vocal wave

'
' Slow motion voice

at.SetPlaybackRate(at.GetNativeOutputSampleRate(at.Stream_Music)/3)

'
' Normal
at.SetPlaybackRate(at.GetNativeOutputSampleRate(at.Stream_Music)/2)

'
' Sped up
at.SetPlaybackRate(at.GetNativeOutputSampleRate(at.Stream_Music)*1.05)

'
'
' Super Chip Munks
at.SetPlaybackRate(at.GetNativeOutputSampleRate(at.Stream_Music)*2)
 

stevel05

Expert
Licensed User
Longtime User
Cool, I've just noticed that at.Ch_Conf_Mono returns the wrong value, it should be 4, I'm trying to get another demo done, I'll amend the library when it's finished.
 

joseluis

Active Member
Licensed User
Longtime User
Ha! You did it! And sooner than expected! :) Good. I'll have time to play with it in a couple of weeks.
 

stevel05

Expert
Licensed User
Longtime User
Yes, it was so similar (work wise) to Audiorecord, it didn't take too long.
 

Gigatron

Member
Licensed User
Longtime User
:sign0188: Thank you very much Steve

Hope this library will help my work to port XMP,xm,s3m,mod player (amiga module player) to B4A.
 

stevel05

Expert
Licensed User
Longtime User
If you can find the decoder routines (to PCM) it shouldn't be too bad. I'm experimenting with creating and playing sine waves at the minute. Getting the raw data to play isn't difficult.
 

stevel05

Expert
Licensed User
Longtime User
OK, I'll post something once I'm happy with how it's working.
 

stevel05

Expert
Licensed User
Longtime User
Just added swt.zip to the first post. A quick and dirty sine wave generator as an example.
 

stevel05

Expert
Licensed User
Longtime User
Updated swt to version 1.1, a few more refinements, can change sample rate and sample size, plus fixed some logic.
 

stevel05

Expert
Licensed User
Longtime User
Update swt to 1.2 - 8khz plays closer to correct tuning.
 

vb1992

Well-Known Member
Licensed User
Longtime User
There was no .IsInitialized in your library
I commented it out

.. this worked with your example in the swt.zip


B4X:
   'If at.IsInitialized Then ' has been initialized once already
   Try
      at.Release
   Catch
   End Try


What's at.State_Initialized?
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Ah sorry I forgot to update the library will do it now.
 

stevel05

Expert
Licensed User
Longtime User
Updated Library to 1.2 required for swt1-2.zip
 

susu

Well-Known Member
Licensed User
Longtime User
One silly question: Does it support mp3 files? :D
 
Top