Page 1 of 1

Bass library, VST and IceCast

Posted: Fri Feb 25, 2022 12:20 am
by hub73
Hello !

My project is a french webradio : Radio Les Floralies.

i'm trying to use Bass library, include stereotool vst too. And next broadcast to my icecast server inside my purebasic program.

But it's difficult to understand what's wrong today inside my code.

You can see my post inside the BASS forum at un4seem website : 'Purebasic, Icecast and Bass'
(https://www.un4seen.com/forum/?topic=19 ... #msg137734)

we're here :

My program correctly play sounds as a playliste on the device 'dispositif' (i can hear the sound on my headphones) . It open the vst, and seems to connect to the icecast server without error... but i've no final sound.

Code: Select all

Procedure Son_envoyer_vers_serveur()
 
  Protected HENCODE_encoder
  Protected NomServeur.s
  Protected MotDePasse.s
  Protected Nom.s
  Protected Url.s
  Protected Genre.s 
  Protected Description.s
  Protected Header.s
  Protected Commande.s
 
  Protected NomVst.s
    Protected Retour

  Protected channel
 
  Protected FDSP
 
  NomServeur = "146.59.233.129:8000/floralies.ogg" ; address:port/mount" (Icecast).
  NomServeur = "http://lesfloralies.ovh:8000/floralies.ogg" ; address:port/mount" (Icecast).
  MotDePasse = "*****"
  Nom = "Radio Les Floralies 2"
  Url = "http://www.lesfloralies.info"
  Genre = "other"
  Description = "Webradio à Castelnaudary France"
  Header = ""
 
  Protected Dispositif
 
  Dispositif = gParametres\Dispositif_sonore

  Retour = BASS_RecordInit(Dispositif)
  If Retour = 0
   MessageRequester ("Erreur","RecordInit : " + BASS_ErrorGetCode())
  EndIf
 
  Retour = BASS_RecordSetDevice(Dispositif)
  If Retour = 0
   MessageRequester ("Erreur","RecordSetDevice : " + BASS_ErrorGetCode())
  EndIf
 
  Channel = BASS_RecordStart (0, 2, #BASS_RECORD_PAUSE|#BASS_SAMPLE_FLOAT,#Null, #Null)
  If Channel = 0
    MessageRequester ("Erreur","RecordStart : " + BASS_ErrorGetCode())
  EndIf 
 
  NomVst = "C:\Users\user\Documents\radio_programmation_purebasic_broadcast\vst_stereo_tool_64.dll"
 
  FDSP  = BASS_VST_ChannelSetDSP(Channel, @NomVst, #BASS_Unicode, 0);
  ; panel should To be  a second form Or in the Mainform remember the Sterotool Editor is Not small
   OpenWindow_vst(0,0)
  BASS_VST_EmbedEditor(FDSP, WindowID(Window_vst)) 
 
  Commande = StringToUTF("oggenc -M %d -m %d -r -R 44100 -")
 
  HENCODE_encoder = BASS_Encode_Start(channel, @Commande, #BASS_ENCODE_NOHEAD, #Null, 0); // setup the encoder
 
  If HENCODE_encoder = 0
    MessageRequester ("Erreur","Erreur de l'encodeur OGG Bass : " + BASS_ErrorGetCode())
  Else
    Ajouter_au_log ("Encodeur OGG Bass fonctionne.", #LOG_DEMARRAGE)
EndIf

  Retour = BASS_Encode_CastInit(HENCODE_encoder, NomServeur, MotDePasse, #BASS_ENCODE_TYPE_OGG, Nom, Url , Genre, Description, Header, 192, 1) ; débute le cast
 
  If Retour = 1
    Ajouter_au_log ("Connecté au serveur IceCast.", #LOG_DEMARRAGE)
  Else 
    Select BASS_ErrorGetCode()
      Case #BASS_ERROR_BUSY
        MessageRequester ("Erreur","Le serveur IceCast est déja occupé !")
       Default
         MessageRequester ("Erreur","Connection serveur IceCast Erreur : " + BASS_ErrorGetCode())
    EndSelect
  EndIf
 
  BASS_ChannelPlay(Channel, 0)
 
EndProcedure
So Is there a BASS - Purebasic guru here ? Someone who managed to use the bass library with purebasic to stream to an icecast server ?

Many thanks !

Re: Bass library, VST and IceCast

Posted: Fri Feb 25, 2022 9:18 am
by ozzie
I use BASS extensively, but have never used icecast, etc. However, looking at this line:

Code: Select all

Retour = BASS_Encode_CastInit(HENCODE_encoder, NomServeur, MotDePasse, #BASS_ENCODE_TYPE_OGG, Nom, Url , Genre, Description, Header, 192, 1)
I'm wondering if 'NomServeur' should '@NomServeur', and similarly with the other string pointer parameters.

Also, fields like Retour and HENCODE_encoder should be declared as longs, eg 'Protected HENCODE_encoder.l', especially when compiling for 64-bit. In the BASS files these are declared as DWORD, which is 32 bits.

Hope this is of some help.

Re: Bass library, VST and IceCast

Posted: Fri Feb 25, 2022 9:43 am
by hub73
all ideas are good for me ! i'll test that. Do you mean that i must modify to long inside the pbi files too ? Thanks Mike.

Re: Bass library, VST and IceCast

Posted: Fri Feb 25, 2022 9:53 am
by hub73
i've this into the pbi : Prototype.l BASS_Encode_CastInit(handle.l, server.p-utf8, pass.p-utf8, content.p-utf8, name.p-utf8, url.p-utf8, genre.p-utf8, desc.p-utf8, headers.p-utf8, bitrate.l, pub.l)

with @MonServeur, i've 'incorrect parameter, string is expected

Re: Bass library, VST and IceCast

Posted: Fri Feb 25, 2022 11:55 pm
by hub73
Could you help me with the pbi :
Prototype.l BASS_Encode_CastInit(handle.l, server.p-utf8, pass.p-utf8, content.p-utf8, name.p-utf8, url.p-utf8, genre.p-utf8, desc.p-utf8, headers.p-utf8, bitrate.l, pub.l)
from here :
http://www.un4seen.com/doc/#bassenc/BAS ... tInit.html

to convert this to an purebasic 'prototype'

Difficult to understand what's the good format : ANSI, ASCII, Unicode, UTF8 and also the difference between BASS variables declaration and Purebasic :P

Many thanks!

Re: Bass library, VST and IceCast

Posted: Sat Feb 26, 2022 12:34 am
by ozzie
I've sent you a PM.

Re: Bass library, VST and IceCast

Posted: Mon Feb 28, 2022 1:32 am
by hub73
it works. Thanks to all the coders for their great help !

Code: Select all


Procedure.s StringToANSI(s.s)

	#AutoLength=-1
	Protected buffer.s
	buffer=Space(StringByteLength(s,#PB_Ascii))
	PokeS(@buffer,s,#AutoLength,#PB_Ascii)

	ProcedureReturn buffer

EndProcedure
Procedure Son_desactiver_vst()
  
  BASS_VST_ChannelRemoveDSP(gParametres\Channel_cast, gParametres\FDSP)
  CloseWindow (WindowID(Window_vst))
  
EndProcedure  

Procedure Son_activer_vst()
  
  Protected NomVst.s
  
  NomVst = "C:\Users\user\Documents\radio_programmation_purebasic_broadcast\vst_stereo_tool_64.dll"
  gParametres\FDSP  = BASS_VST_ChannelSetDSP(gParametres\Channel_cast, @NomVst, #BASS_Unicode, 0);
  ;; panel should To be  a second form Or in the Mainform remember the Sterotool Editor is Not small
   OpenWindow_vst(0,0)
  BASS_VST_EmbedEditor(gParametres\FDSP, WindowID(Window_vst))  
  ;BASS_VST_SetScope(FDSP, 0)  
  
EndProcedure

Procedure.l RecordingCallBack(Channel.l, *buffer, length.f, user.f)
  
  Protected Result.l
  
  Result = BASS_Encode_IsActive(Channel); //  <> 0 continue recording if encoder is live
  
  ;BASS_ChannelGetData(Channel.l, *buffer, length.f)
  BASS_Encode_Write(Channel.l,*buffer,length.f)
  
  ProcedureReturn Result
  
EndProcedure

Procedure Son_fermer_cast()
  
  BASS_Encode_Stop (gParametres\Channel_cast)
  
EndProcedure


Procedure EncoderNotify(Enchandle.l, status.l, user.f)
  
  If status < $10000
    Ajouter_au_log ("Encodeur, Serveur déconnectés", #LOG_ERREUR)
    Son_fermer_cast()
    Son_envoyer_vers_serveur()
  EndIf
  
EndProcedure


Procedure Son_envoyer_vers_serveur()
  
  Protected HENCODE_encoder.l
  Protected NomServeur.s 
  Protected MotDePasse.s
  Protected Nom.s
  Protected Url.s
  Protected Genre.s  
  Protected Description.s
  Protected Header.s
  Protected Commande.s
  
  Protected Retour
  
  NomServeur = StringToANSI("146.59.233.129:8000/floralies.ogg") ; address:port/mount" (Icecast).
  MotDePasse = StringToANSI("source:******")
  Nom = StringToANSI("Radio Les Floralies 2")
  Url = StringToANSI("http://lesfloralies.ovh:8000/floralies.ogg")
  Genre = StringToANSI("other")
  Description = StringToANSI ("Webradio à Castelnaudary France")
  Header = StringToANSI("")
  
  Retour = BASS_RecordInit(gParametres\Dispositif_sonore)
  If Retour = 0
   MessageRequester ("Erreur","RecordInit : " + BASS_ErrorGetCode()) 
  EndIf
  
  Retour = BASS_RecordSetDevice(gParametres\Dispositif_sonore)
  If Retour = 0
   MessageRequester ("Erreur","RecordSetDevice : " + BASS_ErrorGetCode()) 
  EndIf
  
  gParametres\Channel_cast = BASS_RecordStart (48000, 2, #BASS_RECORD_PAUSE | #BASS_SAMPLE_FLOAT, @RecordingCallback(), #Null);)
  
  If gParametres\Channel_cast = 0
    MessageRequester ("Erreur","RecordStart : " + BASS_ErrorGetCode()) 
  EndIf  
  
  Son_activer_vst()
  
  Protected Options.s
  Options = StringToANSI("--bitrate 192")
  
  HENCODE_encoder = BASS_Encode_Ogg_Start(gParametres\Channel_cast, @options, #BASS_UNICODE | #BASS_ENCODE_AUTOFREE, #Null, #Null); // setup the encoder
 
  If HENCODE_encoder = 0
    MessageRequester ("Erreur","Erreur de l'encodeur OGG Bass : " + BASS_ErrorGetCode())
  Else
    Ajouter_au_log ("Encodeur OGG Bass fonctionne. ("+ Str(HENCODE_encoder) + ")", #LOG_DEMARRAGE)
  EndIf
  
  Protected Content.s
  
  Content = StringToANSI (#BASS_ENCODE_TYPE_OGG)
  
  Retour = BASS_Encode_CastInit(HENCODE_encoder, @NomServeur, @MotDePasse, @content, @Nom, @Url , @Genre, @Description, @Header, 0, 0) ; débute le cast
  
  If Retour = 1
    Ajouter_au_log ("Connecté au serveur IceCast. (" + Str(Retour) + ")", #LOG_DEMARRAGE)
  Else  
    Select BASS_ErrorGetCode() 
      Case #BASS_ERROR_BUSY
        MessageRequester ("Erreur","Le serveur IceCast est déja occupé !")
       Default 
         MessageRequester ("Erreur","Connection serveur IceCast Erreur : " + BASS_ErrorGetCode())
    EndSelect
  EndIf
  
  BASS_ChannelPlay(gParametres\Channel_cast, 0)
  
  BASS_Encode_SetNotify(HENCODE_encoder, @EncoderNotify(), 0)
  
EndProcedure