Author Topic: Using BASS in an Android App to Stream Microphone Audio to Icecast Server  (Read 698 times)

hub73

  • Posts: 104
Hello!

Do you think it's possible to code an Android app with BASS to send the smartphone microphone sound to an Icecast server? What would be an interesting, cheap, and easy development language for this? I used PureBasic to code our webradio system, and BASS is fabulous! However, with Android, I have no idea how to start the project and include the BASS library.

I am particularly interested in using B4A (Basic4Android) for this project. Has anyone experimented with B4A and BASS? If so, could you provide some guidance or examples on how to integrate BASS into this development environment? This could be very useful for streaming the smartphone microphone for our webradio live broadcasts.

Many thanks for your ideas and suggestions!

Best regards,
« Last Edit: 9 Jun '24 - 08:20 by hub73 »

Ian @ un4seen

  • Administrator
  • Posts: 25866
Yes, that should be possible. I'm unfamiliar with Basic4Android, so I'm afraid I can't advise on that, but you would basically just need to call BASS_RecordInit, BASS_RecordStart, BASS_Encode_OGG_Start (in BASSenc_OGG add-on), BASS_Encode_CastInit (in BASSenc add-on). Please see the documentation for details on those functions. If you're more familiar with another platform then perhaps you could get things working on that first, and then port it. The BASS calls will be much the same everywhere.

hub73

  • Posts: 104
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!

MB_SOFT

  • Posts: 491
i use bass with B4A without big problems. You can create the JAR file using the "SimpleLibraryConverter" of B4A.

The only problem is that BASS callbacks are not working straight away after the conversion.

But you can plug the recorder channel and the encoder to a bass mixer so i think you can avoid the use of bass callbacks.

so you need to convert BASS BASSMIX and BASSENC and also BASSenc_MP3 or BASSenc_OPUS depending the codec you want to stream

Ian @ un4seen

  • Administrator
  • Posts: 25866
If you're having trouble with RECORDPROC callbacks and don't need them to do anything special (just "return true") then there is actually a new option for that in the latest BASS build that you could try.

   www.un4seen.com/stuff/bass-android.zip

The new option is currently called RECORDPROC_EMPTY (may change before release) and is defined as -1, like this:

Code: [Select]
#define RECORDPROC_EMPTY (RECORDPROC*)-1

handle = BASS_RecordStart(freq, chans, flags, RECORDPROC_EMPTY, NULL);

hub73

  • Posts: 104
MB_SOFT could you post a link to the 'SimpleLibraryConverter' for B4A. Many thanks !


MB_SOFT

  • Posts: 491
If you're having trouble with RECORDPROC callbacks and don't need them to do anything special (just "return true") then there is actually a new option for that in the latest BASS build that you could try.

useful ... thanks

hub73

  • Posts: 104
@MB_SOFT :

I am trying to use the software SLC to create a library for B4A, but I cannot generate the .jar file. I have included the organization of my files and the .java code in the attached zip file. Thank you for your help!

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

MB_SOFT

  • Posts: 491
try adding

package com.un4seen.bass;
import java.lang.*;
import java.nio.ByteBuffer;
import android.content.res.AssetManager;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.AbsObjectWrapper;

@SuppressWarnings({"all"})
@ShortName("BASS")
@Permissions(values={"android.permission.INTERNET","android.permission.MODIFY_AUDIO_SETTINGS"})
/*@Permissions(values={"android.permission.INTERNET","android.permission.MODIFY_AUDIO_SETTINGS","android.permission.RECORD_AUDIO","android.permission.READ_EXTERNAL_STORAGE","android.permission.WRITE_EXTERNAL_STORAGE"})*/
@Version(2.4f)

public class BASS .........

hub73

  • Posts: 104

With SLC : I've this library for B4A  :

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

and this program :

Code: [Select]
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).

Sure something is wrong !

I've checked BASSWrapper as external library.


Many thanks for your help !

MB_SOFT

  • Posts: 491
Dim LibBass As BASS
if LibBass.BASS_Init(-1,44100,0)
 ....

hub73

  • Posts: 104
Quote
Dim LibBass As BASS
if LibBass.BASS_Init(-1,44100,0)

It does not work. It's the same error. Could you check if you see anything strange in my library for B4A?

hub73

  • Posts: 104
I'm almost there...

hub73

  • Posts: 104
@MB_SOFT : Could you share your SLC BASS folder structure and code ?

MB_SOFT

  • Posts: 491
here it is

hub73

  • Posts: 104
Many thanks. Could you also provide your SLC zipped Bass folder ?
I'm trying to figure out what's wrong with mine.

MB_SOFT

  • Posts: 491
attached

hub73

  • Posts: 104
This helps me a lot. I'm trying to compare with what I did and for the moment I don't see what's wrong with my SLC version which seems similar to me.
Can you include the use of the BASS FX and BASSenc add-on? To use 'BASS_Encode_Start' and 'BASS_Encode_CastInit'. Thank you so much !

MB_SOFT

  • Posts: 491
i don't use BASS_FX and the BASS_Enc i made is slightly modified. Why don't you generate it with Simple Libray Converter?


hub73

  • Posts: 104
In fact this is my problem. Insert the  adds on to the SLC library folder and generate the b4a library.  Something is wrong but i dont know where is the problem ! I'm not a java coder !