B4A Library Equalizer library

Here's my first attempt at a library that's suitable to share. It's for the Equalizer available in API 9 and later (Gingerbread 2.3).

If it's used on a device which does not have API 9 or later, it will not fail at initialization and you can check the IsInitialized method to see if it's available and use it if it is.

It is my first attempt, let me know if you get any problems with it and I'll try to sort them out.

Steve



I've added an example program which works fine on the emulator, my Cyanogen mod powered devices are not so happy. Probably to do with the Cyanogen mod release, I'll try to update them.

V1.01 ensures reinitialization is done after app is paused.
V1.10 allows attaching to a specific Mediaplayer or AudioTrack using the audioSessionID. You can get this using reflection on Mediaplayer. See Post:#15
 

Attachments

  • EqGui3.zip
    8 KB · Views: 893
  • EQlib.zip
    5.5 KB · Views: 937
Last edited:

Gigatron

Member
Licensed User
Longtime User
Thank you very much.

It's working on my Xperia10i, when it's play mp3.
I would like make xm,mod s3m player libs for b4a but i realy not understand rules of build libs with eclipse.

Thank a lot again ,and thanks to all making libs for B4A
I forgot... I HATE JAVA !

Later
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Hi Gigatron,

No problem, I've just spent a couple of months writing a Java app for the Pc, and now understand enough to find most of what I need, but before that it would have been difficult.

Steve
 

stevel05

Expert
Licensed User
Longtime User
I've just updated the demo app, Cyanogen doesn't like the GetProperties call, so the demo saves the settings without it.
 

stevel05

Expert
Licensed User
Longtime User
Just to make it a little more functional, the demo app will now leave the equalizer active when it's in the background until you turn it off, or close the app (or Android force closes it!).
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
A simpler with a few more comments.
 

Attachments

  • EqGui2.zip
    7 KB · Views: 599

Gigatron

Member
Licensed User
Longtime User
A simpler with a few more comments.

Thank you very much Stevel05

I have tryed quickly and it's working on Xperia10i 2.3.3

Here are what i added to your code, to test if eqlib affect Mediaplayer of B4A.




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

   Dim EQ As EQlib
   Dim MP As MediaPlayer    ' (1)

End Sub


Sub Activity_Create(FirstTime As Boolean)

   'Just layout stuff
   Activity.LoadLayout("EQ.bal")
   'size the background to full screen
   EQPnlBG.SetLayout(0,0,100%x,100%y)
   'Center the EQ panel
   EQPnl.Left=(Activity.Width-EQPnl.Width)/2
   EQPnl.Top=(Activity.Height-EQPnl.Height)/2
   
   MP.Initialize2("MP")                              ' (2)
   MP.Load(File.DirAssets,"monday.mp3")      '(3)
   MP.play                                              '(4)
   
End Sub


Thanks again
 

stevel05

Expert
Licensed User
Longtime User
Great, I'm glad you got it working.


It should work when the Media player is being used by any app, if you only want to use it for a specific app, just make sure you disable it and release the resource when you close the app, so that other apps can gain control of it.

Steve
 

BLOKKER

Member
Licensed User
Longtime User
Relation between GetBandLevel and SetBandLevel

Hi Steve, Nice lib!

Function GetBandLevel returns me a different value that has been set using method SetBandLevel. In your sample I see a save to file of preset values and a recall from file of the set but not the retrieval of the current equalizer settings (directly from the audio chip) and set the seekbar values by using GetBandLevel.

Could you explain what the relation is between these two functions and how to retrieve level settings from the audio chip?

Thanks,
Marcel
 

stevel05

Expert
Licensed User
Longtime User
Hi Marcel,

The eqlibrary is a thin wrapper for the Android Equalizer library full documentation is here.

The preset system uses only predefined presets, to get the current equalizer settings use getProperties, which returns an Equalizer Settings object, which you can send back to the equalizer using setProperties(settings).

It was a while ago now, but when I tested the library it was returning the correct values from getbandlevel, did you check the value you set was within the getBandLevelRange() limits?

If you still get the same issue you can post your project and I'll take a look if you like.

Steve
 

BLOKKER

Member
Licensed User
Longtime User
Thanks Steve. I noticed that GetBandLevelRange is returning an array containing a minimum and maximum range. The minimum range is negative signed and therefore I had to change the seekbar calculations and the following code is working.

B4X:
' Note: initializations left out this sample...
' Set the maximum level of the sliders (skb prefixed)
' by recalling from the DAC into short array shBandLevelRange 

shBandLevelRange = clsEQ.GetBandLevelRange

skbEQ1.Max = shBandLevelRange(1)-shBandLevelRange(0)
skbEQ2.Max = shBandLevelRange(1)-shBandLevelRange(0)
skbEQ3.Max = shBandLevelRange(1)-shBandLevelRange(0)
skbEQ4.Max = shBandLevelRange(1)-shBandLevelRange(0)
skbEQ5.Max = shBandLevelRange(1)-shBandLevelRange(0)

' Recall the settings from the DAC and store it in 
' shBandLevelRange (short array) and set the 
' sliders (skb prefixed)

shBandLevelRange = clsEQ.GetBandLevelRange
   
shLevel1 = clsEQ.GetBandLevel(0)-shBandLevelRange(0)
shLevel2 = clsEQ.GetBandLevel(1)-shBandLevelRange(0)
shLevel3 = clsEQ.GetBandLevel(2)-shBandLevelRange(0)
shLevel4 = clsEQ.GetBandLevel(3)-shBandLevelRange(0)
shLevel5 = clsEQ.GetBandLevel(4)-shBandLevelRange(0)
   
skbEQ1.Value = shLevel1
skbEQ2.Value = shLevel2
skbEQ3.Value = shLevel3
skbEQ4.Value = shLevel4
skbEQ5.Value = shLevel5

The reason I wanted to recall the INITIAL setting from the DAC is to prevent the adjustment of the EQ levels every time the app is first time started. The use of GetBandLevelRange is not fully illustrated in your sample so I hope others will understand the function a bit more (especially the negative signed minimal value that is returned by the function).

Also, the link to the Android SDK proved to be very useful.

Cheers!
Marcel
 

stevel05

Expert
Licensed User
Longtime User
Hi Marcel,

Great, I'm glad you got it working. More examples are always good, thanks.

Steve
 

VicH

New Member
Licensed User
Longtime User
Get the audio levels

Using your library, by the way is great, exist a way to get the level of the sound, this in order to do a graphic equilazer, thanks in advance.
 

stevel05

Expert
Licensed User
Longtime User
Hi VicH,

I'm not quite sure what you are asking. Do you want the values set within the equalizer in which case you can use getbandlevel or getproperties as in the example, or the amplitude values in the sound file itself?

Steve
 

stevel05

Expert
Licensed User
Longtime User
New Version 1.10

V1.10 allows attaching to a specific Mediaplayer or AudioTrack using the audioSessionID.

You can get this using reflection on Mediaplayer:

B4X:
    Dim R As Reflector
    R.Target=MP
    R.Target=R.GetField("mp")
    Dim AudioSessionID As Int = R.RunMethod("getAudioSessionId")

Or by using the GetAudioSessionID method on AudioTrack.

Added
B4X:
initialize2(Priority,AudioSessionID)
to avoid breaking existing code.

Example app has also been updated to demonstrate, you need to provide your own audio file where the compilation fails and remove the 'XX' as it makes the file too large to include one.

Files are attached to the first post in this thread.
 
Last edited:

MrDezibel

Member
Licensed User
Longtime User
Is there a way to get the AudioSessionID from the Mediaplayer/Audiotrack a Videoview is using ?

I am writing a Videoplayer using a Videoview and I can't find a way to attach the Equalizer to it or control the Volume...

Thx
 

stevel05

Expert
Licensed User
Longtime User
I haven't tried it but you should be able to get it with this code:

B4X:
Dim JO as JavaObject = myVideoView
SessionID = JO.Runmethod("getAudioSessionId",Null)
 

MrDezibel

Member
Licensed User
Longtime User
hmmm...i get
java.lang.RuntimeException: Method: getAudioSessionId not found in: android.widget.VideoView

Using
Dim R As Reflector
R.Target=mpv
R.Target=R.GetField("mpv")
Dim AudioSessionID AsInt = R.RunMethod("getAudioSessionId")

I get
java.lang.NoSuchFieldException: mpv
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Try the attached project, it works for me.
 

Attachments

  • VideoView.zip
    5.9 KB · Views: 370
Top