Author Topic: microphone crackles  (Read 348 times)

hub73

  • Posts: 74
microphone crackles
« on: 29 Aug '22 - 19:47 »
Bass works well in my purebasic project. But when I speak on the microphone I hear crackling. I tried with several computers and micro and it's the same thing. It doesn't seem to come from the VSTs, everything seems to be set to be below 0 db. What should I check? The problem seems to occur at any volume level. Only when I speak into the microphone i hear crackles. I also record the sound. It works well... the crackling is also recorded! It's a shame, my program is almost finished. In any case, thank you for this extraordinary library. Note i use an mixer as output.

Code: [Select]
gParametres\Channel_ligne = BASS_RecordStart(44100, 1, #Null, #Null, 0)
 BASS_Mixer_StreamAddChannel(gParametres\Mixer, gParametres\Channel_ligne, #BASS_MIXER_NORAMPIN | #BASS_STREAM_AUTOFREE)

The mp3 files illustrate the problem when I lightly tap the microphone
https://www.lesfloralies.info/telech/20220829_test.mp3
« Last Edit: 29 Aug '22 - 21:54 by hub73 »

Ian @ un4seen

  • Administrator
  • Posts: 24730
Re: microphone crackles
« Reply #1 on: 30 Aug '22 - 17:20 »
Try adding the BASS_MIXER_LIMIT flag to the recording's BASS_Mixer_StreamAddChannel call, to limit mixing to the amount available from the recording.

hub73

  • Posts: 74
Re: microphone crackles
« Reply #2 on: 30 Aug '22 - 18:12 »
gParametres\Channel_ligne record the microphone input.

Code: [Select]
gParametres\Channel_ligne = BASS_RecordStart(44100, 1, #Null, #Null, 0)
 BASS_Mixer_StreamAddChannel(gParametres\Mixer, gParametres\Channel_ligne, #BASS_MIXER_NORAMPIN | #BASS_STREAM_AUTOFREE | #BASS_MIXER_LIMIT)
like this ?
(not fix the problem).

hub73

  • Posts: 74
Re: microphone crackles
« Reply #3 on: 30 Aug '22 - 20:51 »
maybe something to do with 'buffers' ? (via  BASS_SetConfig) ???

Could you tell me what could be causing this problem?
« Last Edit: 31 Aug '22 - 04:27 by hub73 »

Ian @ un4seen

  • Administrator
  • Posts: 24730
Re: microphone crackles
« Reply #4 on: 31 Aug '22 - 13:32 »
To narrow down where the problem is, please try setting an encoder directly on the recording ("Channel_ligne") and see if the problem is present in the written file. Also show how the mixer is created, ie. the BASS_Mixer_StreamCreate call.

hub73

  • Posts: 74
Re: microphone crackles
« Reply #5 on: 31 Aug '22 - 15:01 »
Quote
To narrow down where the problem is, please try setting an encoder directly on the recording ("Channel_ligne") and see if the problem is present in the written file.
Code: [Select]
NomFichier = gParametres\CheminDossierEnregAudio + "test.ogg"
Options = StringToANSI("--bitrate 192") 
 gParametres\Channel_ligne = BASS_RecordStart(44100, 1, #Null , #Null, 0)
 gParametres\Encoder_enregistrement_entree = BASS_Encode_Ogg_StartFile(gParametres\Channel_ligne, @options, #BASS_UNICODE, @NomFichier); // setup the encoder
 
 BASS_Mixer_StreamAddChannel(gParametres\Mixer, gParametres\Channel_ligne, #BASS_MIXER_NORAMPIN | #BASS_STREAM_AUTOFREE | #BASS_MIXER_LIMIT )
No problem inside the test.ogg file

Quote
Also show how the mixer is created, ie. the BASS_Mixer_StreamCreate call.
Code: [Select]
gParametres\Mixer = BASS_Mixer_StreamCreate(44100, 2, #BASS_MIXER_NONSTOP)
BASS_ChannelSetAttribute(gParametres\Mixer, #BASS_ATTRIB_BUFFER, 0) ; disable playback buffering

Note : Problem persist if i desactivate all VST.
 

Ian @ un4seen

  • Administrator
  • Posts: 24730
Re: microphone crackles
« Reply #6 on: 31 Aug '22 - 15:31 »
OK, so the problem doesn't appear to be in the recording then. Are there any other sources in the mixer, and if so, does removing them prevent the problem? Or does removing the BASS_MIXER_NONSTOP flag from the BASS_Mixer_StreamCreate call prevent it? Please also confirm what BASSmix version you're using with BASS_Mixer_GetVersion.

hub73

  • Posts: 74
Re: microphone crackles
« Reply #7 on: 31 Aug '22 - 17:59 »
i use latest version of BASS and BASSMIX
if i remove #BASS_MIXER_NONSTOP problem persist.

i use too sounds on the gParametres\Mixer

Code: [Select]

Procedure Son_Charger_Son (CheminFichier$, *Son.BASS_struct)
 
  Protected filename.s
 
  filename.s = CheminFichier$
  *Son\Fichier$ = CheminFichier$
 
  *Son\channel = BASS_StreamCreateFile (0, @filename, 0, 0, #BASS_UNICODE)
 
EndProcedure 

Procedure Son_Jouer_Son(*Son.BASS_struct, Volume.i, bBoucler.l)
 
  Protected Vol.f
 
  BASS_ChannelPlay(*Son\channel, bBoucler.l)
 
  Vol = Volume / 100.0
 
  ;BASS_ChannelSetAttribute(*Son\Channel, #BASS_ATTRIB_VOL, vol) 
   
EndProcedure

Son_charger_son (Chemin$ + Cartouches(IdSlot)\Fichier$, @Cartouches(IdSlot)\Sonlu)
Cartouches(IdSlot)\Stream = BASS_StreamCreateFile(0, stringtoansi(Chemin$ + Cartouches(IdSlot)\Fichier$), 0, 0, #BASS_SAMPLE_FLOAT|#BASS_STREAM_DECODE)

...

Son_jouer_son (@Cartouches(IdSlot)\Sonlu, v, 0)
BASS_Mixer_StreamAddChannel(gParametres\Mixer, Cartouches(IdSlot)\Stream, #Null)
but not used for the test. And no crackle with the sounds only with gParametres\Channel_ligne

hub73

  • Posts: 74
Re: microphone crackles
« Reply #8 on: 31 Aug '22 - 20:43 »
I also tested from another computer with another microphone and another external card. It's the same problem.

To sum up.

- Microphone/Input -> Vst (gate, compressor, eq, spectrum display)-> Mixer
- Sounds -> Mixer.

Finally :
Mixer -> Vst (Compressor, Limiter) -> File Recording, IceCast, Headphone listening.

I also tried to remove the crackle with a vst equalizer eq (located microphone/Input>Mixer) but no positive result!)
It's not a buffer or volume problem? (yet no saturation, I'm well below 0 db)

In any case, thank you Ian for the help provided.
I feel a little lonely using purebasic and Bass ;-) We are going to try to do a live broadcast with the web radio in two days with our software at an association fair... I was surprised by these crackles!
« Last Edit: 31 Aug '22 - 20:50 by hub73 »

Chris

  • Posts: 2092
Re: microphone crackles
« Reply #9 on: 1 Sep '22 - 10:32 »
Have you check the CPU Usage ?
Are the Harddisk's) on both Machines SSD`s ?

Ian @ un4seen

  • Administrator
  • Posts: 24730
Re: microphone crackles
« Reply #10 on: 1 Sep '22 - 12:14 »
To sum up.

- Microphone/Input -> Vst (gate, compressor, eq, spectrum display)-> Mixer
- Sounds -> Mixer.

Finally :
Mixer -> Vst (Compressor, Limiter) -> File Recording, IceCast, Headphone listening.

What happens if you remove all other sounds and VST, so just this:

  Microphone/Input -> Mixer -> File Recording

Do you still hear the problem in the written file then?

hub73

  • Posts: 74
Re: microphone crackles
« Reply #11 on: 1 Sep '22 - 15:22 »
Quote
Have you check the CPU Usage ?
Are the Harddisk's) on both Machines SSD`s ?
CPU usage is correct (under 10%)
Both are SSD harddisk
« Last Edit: 1 Sep '22 - 15:37 by hub73 »

hub73

  • Posts: 74
Re: microphone crackles
« Reply #12 on: 1 Sep '22 - 15:34 »
Quote
What happens if you remove all other sounds and VST, so just this:

  Microphone/Input -> Mixer -> File Recording

Do you still hear the problem in the written file then?.
Crackles inside the recording file

Ian @ un4seen

  • Administrator
  • Posts: 24730
Re: microphone crackles
« Reply #13 on: 1 Sep '22 - 16:39 »
OK. Please show the exact calls/parameters that you used in doing that.

hub73

  • Posts: 74
Re: microphone crackles
« Reply #14 on: 1 Sep '22 - 16:42 »
I am creating a new purebasic program which contains microphone recording only

hub73

  • Posts: 74
Re: microphone crackles
« Reply #15 on: 1 Sep '22 - 17:58 »
 (Microphone/Input -> Mixer -> File Recording)
No Crackle with this basic microphone -> Mixer -> File.  But latency ??? when I speak

https://www.lesfloralies.info/telech/test.zip

https://www.lesfloralies.info/telech/test.txt
« Last Edit: 1 Sep '22 - 18:20 by hub73 »

Ian @ un4seen

  • Administrator
  • Posts: 24730
Re: microphone crackles
« Reply #16 on: 2 Sep '22 - 13:11 »
How much latency is there, and is it more than before? If it is more than before, what are you doing differently now? Make sure you start the mixer (BASS_ChannelPlay) before (or straight after) the recording, otherwise there may be a build-up of data in the recording buffer, resulting in extra latency.

I see you have disabled playback buffering on the mixer via BASS_ATTRIB_BUFFER. When doing that, you should also enable asynchronous encoding via the BASS_ENCODE_QUEUE flag to avoid delaying the mixer processing. Any delay could result in a small break/gap in the playback (it won't be in the written file).

hub73

  • Posts: 74
Re: microphone crackles
« Reply #17 on: 2 Sep '22 - 20:47 »
Quote
How much latency is there, and is it more than before? If it is more than before, what are you doing differently now? Make sure you start the mixer (BASS_ChannelPlay) before (or straight after) the recording, otherwise there may be a build-up of data in the recording buffer, resulting in extra latency.
Thanks latency corrected now.

Quote
you should also enable asynchronous encoding via the BASS_ENCODE_QUEUE flag
Could you tell me what's bass functions to add BASS_ENCODE_QUEUE ? Encoders ?
« Last Edit: 2 Sep '22 - 20:59 by hub73 »

hub73

  • Posts: 74
Re: microphone crackles
« Reply #18 on: 3 Sep '22 - 04:56 »
- I found the origin of the crackles: the procedure that calculates the db: Diffuser_calculer_db_entree() using BASS_ChannelGetLevelEx !
This procedure produce a 'crackle' !
As the procedure is placed in a part of the main loop which is called every 60 milliseconds, full of crackles!
- Note i use also a similar procedure with the mixer db mesure, no crackle produced !

Code: [Select]
Procedure.i uMax(val1.i, val2.i)
 
  EnableASM
 
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      MOV eax,[p.v_val1]
      CMP eax, [p.v_val2]
      CMOVNA eax,[p.v_val2]
   CompilerElse
      MOV rax,[p.v_val1]
      CMP rax, [p.v_val2]
      CMOVNA rax, [p.v_val2]
   CompilerEndIf
   
   DisableASM
   
   ProcedureReturn
   
 EndProcedure

Procedure.i Son_LinToDB(Volume, Base = 100)

  Protected Retour.i
 
  If (Volume <= 0)
    Retour = -50 ; To prevent overflow
  Else
    Retour = Round(Log10(Abs(Volume) / uMax(Base, 1)) * 20, #PB_Round_Nearest)
  EndIf
 
  ProcedureReturn Retour
 
 EndProcedure

Procedure Diffuser_calculer_db_entree()
 
  Dim FLevel.f(2)
 
  BASS_ChannelGetLevelEx(gParametres\Channel_ligne, @Flevel(), 0.05, #BASS_LEVEL_STEREO);  // Stereo
 
  gParametres\Mesure_db_gauche_entree = Son_LinToDB(Round(Flevel(0) * 100, #PB_Round_Nearest), 55)
  gParametres\Mesure_db_droite_entree = Son_LinToDB(Round(Flevel(1) * 100, #PB_Round_Nearest), 55) 
 
EndProcedure


hub73

  • Posts: 74
Re: microphone crackles
« Reply #19 on: 3 Sep '22 - 20:38 »
We are back from the association forum of our city. The software with the patch worked fine. (we disabled the input db meter). Bass is truly a fantastic code library.

Ian @ un4seen

  • Administrator
  • Posts: 24730
Re: microphone crackles
« Reply #20 on: 5 Sep '22 - 16:31 »
Great to hear that you got things working OK in time!

Regarding the recording level meter problem, that will be because BASS_ChannelGetLevelEx is taking data from the recording (to calculate the level) and the mixer then doesn't see that data, ie. the mixer is skipping data from the recording. Adding the BASS_LEVEL_NOREMOVE flag to the BASS_ChannelGetLevelEx call should fix the problem. Another solution is to use BASS_Mixer_ChannelGetLevelEx instead (note you will also need to add BASS_MIXER_CHAN_BUFFER to the BASS_Mixer_StreamAddChannel call).

Regarding the BASS_ENCODE_QUEUE flag, you would use that in the BASS_Encode_OGG_StartFile call (or any other encoder start call).