Android Question Assistance Needed for Creating a BASS Library Wrapper in B4A

hub73

Active Member
Licensed User
Longtime User
Hi Everyone !


B4X:
MyB4AProject/
├── Files/
├── Objects/
├── libs/
│   ├── armeabi/
│   │   ├── libbass.so
│   │   ├── libbass_fx.so
│   ├── armeabi-v7a/
│   │   ├── libbass.so
│   │   ├── libbass_fx.so
│   ├── arm64-v8a/
│   │   ├── libbass.so
│   │   ├── libbass_fx.so
├── Main.b4a
├── ...
and

B4X:
Sub Process_Globals
    Private LibBass As BASS
    Private FX As BASS_FX
    Private recordingHandle As Int
End Sub

Sub Globals
    ' Déclarez les composants UI ici si nécessaire
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        ' Charger les fichiers .so
        If File.Exists(File.DirInternal, "libbass.so") = False Then
            File.Copy(File.DirAssets, "libbass.so", File.DirInternal, "libbass.so")
        End If
        If File.Exists(File.DirInternal, "libbass_fx.so") = False Then
            File.Copy(File.DirAssets, "libbass_fx.so", File.DirInternal, "libbass_fx.so")
        End If
        System.LoadLibrary("bass")
        System.LoadLibrary("bass_fx")
    End If

    ' Initialiser BASS
    LibBass.BASS_Init(-1, 44100, 0)
    recordingHandle = LibBass.BASS_RecordStart(44100, 1, BASS_STREAM_AUTOFREE, "RecordingCallback", Null)
End Sub

Sub RecordingCallback(Buffer() As Byte, Length As Int, User As Object)
    ' Traitement de l'audio ici
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    LibBass.BASS_Free()
End Sub

I am currently working on a project in B4A and I need to integrate the BASS audio library. I have the necessary .so files (libbass.so and libbass_fx.so) for different architectures, but I am encountering issues with creating the wrapper libraries required to use BASS functions in B4A.

Here are the specific points where I need assistance:

  1. Wrapper Creation: I need guidance on creating .jar and .xml files to wrap the BASS library for use in B4A. If anyone has experience with this or has existing wrappers, your input would be greatly appreciated.
  2. Integration Steps: Detailed steps on how to properly include and reference the BASS libraries in a B4A project. I am particularly interested in understanding the correct folder structure and any necessary configuration settings.
  3. Loading the Libraries: Best practices for loading the .so files at runtime and ensuring they are correctly initialized within the B4A environment.
If anyone has sample projects, documentation, or can provide code snippets that demonstrate how to achieve this, it would be immensely helpful. Additionally, if there are any common pitfalls or issues I should be aware of, please let me know.

Thank you in advance for your assistance!
 

aeric

Expert
Licensed User
Longtime User
Try check this thread:
 
Upvote 0

hub73

Active Member
Licensed User
Longtime User
Thank you. I tried creating an Android application using Android Studio and ChatGPT, but despite hours of research, I couldn't get a functional application. Maybe someone else has tried to do the same and succeeded. For the next step with B4A, I need to create a JAR file with an XML description, I believe. I'm switching to B4A because I find Android programming complicated, and this experience has only reinforced that belief. Thank you all for your help!
 
Upvote 0

hub73

Active Member
Licensed User
Longtime User
Hi ! Could you help me to use SimpleLibrayCompiler ? I've the following error

B4X:
Starting step: Compiling Java code.
C:\Users\pc\Desktop\SimpleLibraryCompiler\BassLibrary\src\com\un4seen\bass\BassWrapper.java:10: error: class BASSWrapper is public, should be declared in a file named BASSWrapper.java
public class BASSWrapper {
       ^
1 error
only showing the first 1 errors, of 3 total; use -Xmaxerrs if you would like to see more

javac 14.0.1

Error.

Here my zip archive with SimpleLibrayCompiler and Bass :

https://lesfloralies.info/telech/BassB4A.zip

Many thanks !
 
Upvote 0

hub73

Active Member
Licensed User
Longtime User
I don't know what to do about this message. I'm trying to create a library to then use with b4a containing the Bass functions. And java isn't what I'm best at. can you guide me on this? Thank you so much.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

hub73

Active Member
Licensed User
Longtime User
'BASSWrapper.java' : This is case sensitive also for the filename !
Now i've this :

B4X:
Starting step: Compiling Java code.
javac 14.0.1

Completed successfully.
Starting step: Creating jar file.
Completed successfully.
Starting step: Creating XML file.
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javadoc/Doclet
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
    at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:514)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:422)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:416)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:415)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at jdk.javadoc/jdk.javadoc.internal.tool.Start.loadDocletClass(Start.java:758)
    at jdk.javadoc/jdk.javadoc.internal.tool.Start.preprocess(Start.java:727)
    at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:374)
    at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:342)
    at jdk.javadoc/jdk.javadoc.internal.tool.Main.execute(Main.java:63)
    at jdk.javadoc/jdk.javadoc.internal.tool.Main.main(Main.java:52)
Caused by: java.lang.ClassNotFoundException: com.sun.javadoc.Doclet
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 16 more

Error.
 
Upvote 0

hub73

Active Member
Licensed User
Longtime User
i'm searching a way to set javac to javac 1.8 !
I found it was in the B4A editor. The library is generated with the XML file!
 
Last edited:
Upvote 0

hub73

Active Member
Licensed User
Longtime User
I've this library for B4A :


and this program :

My code:
Sub Process_Globals
    Private bass As BASSWrapper
End Sub

Sub Globals
    ' Déclarez les variables nécessaires ici
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        bass.Initialize
        ' Initialisation de BASS avec entrée microphone
        If bass.BASS_RecordInit(-1) = False Then
            Log("BASS_RecordInit error: " & bass.BASS_ErrorGetCode)
            Return
        End If

        ' Crée un stream pour le microphone
        Dim micStream As Int = bass.BASS_RecordStart(44100, 2, 0, Null, 0)
        If micStream = 0 Then
            Log("BASS_RecordStart error: " & bass.BASS_ErrorGetCode)
            Return
        End If

        ' Initialisation de l'encodeur pour Icecast
        Dim encoder As Int = bass.BASS_Encode_Start(micStream, "lame -r -b 128 -", BASSWrapper.BASS_ENCODE_NOHEAD, Null, 0)
        If encoder = 0 Then
            Log("BASS_Encode_Start error: " & bass.BASS_ErrorGetCode)
            Return
        End If

        ' Configuration pour caster vers Icecast
        If bass.BASS_Encode_CastInit(encoder, "http://lesfloralies.ovh:8000/flooralies.mp3", _
                                     "source:MotDePasse", _
                                     "audio/mpeg", _
                                     "Radio Les Floralies", _
                                     "http://lesfloralies.ovh:8000/flooralies.mp3", _
                                     "La webradio chaurienne", _
                                     "autre", _
                                     Null, 128, 44100, 2, 0) = 0 Then
            Log("BASS_Encode_CastInit error: " & bass.BASS_ErrorGetCode)
            Return
        End If

        Log("Streaming to Icecast started successfully!")
    End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

But i've error here : Private bass As BASSWrapper (unknow type).

I've checked BASSWrapper as external library.

Many thanks for your help !
 
Upvote 0

hub73

Active Member
Licensed User
Longtime User
Thanks DonManfred. Sorry, I experimented a bit to try to resolve my problem and I moved on to other avenues as I progressed. I'm going to research it a little more!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top