Author Topic: Problem of recording sound from microphone if the audio outputs are turned off  (Read 271 times)

lamborgine

  • Posts: 5
I need to record audio from a microphone, but if all audio outputs are disabled on windows, an MP3 BASS_ERROR_FILEOPEN error occurs. In the code, an error occurs after the execution of the BASS_Encode_Start function, it returns 0, which throws an exception.

Code: [Select]
RecStream: = BASS_Encode_Start (Stream, PChar ('lame.exe --abr 56 -mm - rec.mp3'), BASS_ENCODE_AUTOFREE or BASS_ENCODE_FP_32BIT or BassUnicode, nil, nil)
How can this be fixed?

Ian @ un4seen

  • Administrator
  • Posts: 23743
If I understand correctly, you have no output devices enabled in Windows but you do have a recording device (microphone) enabled? Output devices shouldn't have any bearing on encoding from a recording device, so it's strange if that is what you're seeing. Are your BASS_RecordInit and BASS_RecordStart calls (before the BASS_Encode_Start call) definitely successful, ie. returning true? Does the problem still happen if you write a WAV file instead?

Code: [Select]
RecStream: = BASS_Encode_Start (Stream, PChar ('rec.wav'), BASS_ENCODE_AUTOFREE or BASS_ENCODE_PCM or BassUnicode, nil, nil)

lamborgine

  • Posts: 5
Microphone in windows is detected. BASS_RecordInit and BASS_RecordStart return true. I tried to write wav, the file is not created and there are no errors. I took an example of sound recording from the site, it works with the audio outputs turned off. So the problem is somewhere in my code. I will look for. Thanks.

lamborgine

  • Posts: 5
I figured out, the problem was that if you do not use the BASS_ENCODE_PCM flag when there are no audio outputs, then BASS_Encode_Start will return 0. Is this the correct behavior? Can you do something about this?

Chris

  • Posts: 1957
I don`t think so.
for Bass_encode is a realoutput not needed.
maybe something with the lame binary is not ok.
You can try also to test that with bassenc_mp3 .


Ian @ un4seen

  • Administrator
  • Posts: 23743
I figured out, the problem was that if you do not use the BASS_ENCODE_PCM flag when there are no audio outputs, then BASS_Encode_Start will return 0. Is this the correct behavior? Can you do something about this?

That sounds like the LAME.EXE file probably can't be found. You could try providing its full path in your BASS_Encode_Start call, or use BASS_Encode_MP3_StartFile instead (from the BASSenc_MP3 add-on).

lamborgine

  • Posts: 5
What we managed to find out: If all audio outputs are turned off, then the BASS_Init (-1, 44100, 0, handle, nil) function does not work, and without it BASS_Encode_Start does not encode in mp3. Can I somehow immediately save to mp3 without BASS_Init, or do I have to save it to wav and convert it separately to mp3?

ps Saving recording to wav without BASS_Init works correctly.

Ian @ un4seen

  • Administrator
  • Posts: 23743
BASS_Encode_Start shouldn't require BASS_Init to be called if you're only encoding recording channels (from BASS_RecordStart). So it's strange if that's what you're seeing. What is the error code in that case? Call BASS_ErrorGetCode straight after the failed BASS_Encode_Start call to check.

If you happen to also want to transcode files without playing anything then you can use the "No Sound" device (device=0) in the BASS_Init call to avoid any soundcard requirement.

Chris

  • Posts: 1957
Hi,
 I thing something like this makes more sense.

Code: [Select]
If not Bass_Init(-1, 44100, 0, handle, nil) then
   // all outputs are disabled or no Real Soundcard on the machine
  if not Bass_Init(0, 44100, 0, handle, nil) then
   // if this will fail just check the error
      ShowMessage('ErrorCode : '+(Bass_ErrorGetCode).ToString);
// Remember for pur encoding is no real Soundcard needed.

lamborgine

  • Posts: 5
Thanks to all!

Code: [Select]
If not Bass_Init (-1, 44100, 0, handle, nil) then
   if not Bass_Init (0, 44100, 0, handle, nil) then
     ...

This solution did the trick!

ps BASS_Encode_Start did not throw an error, but returned handle = 0

Chris

  • Posts: 1957
Hi just place an Bass_ErrorGetCode after the call.

Code: [Select]
RecStream: = BASS_Encode_Start (Stream,.........
if (RecStream = 0) and (Bass_ErrorGetCode <> 0) then
  ShowMessage('ErrorCode : '+(Bass_ErrorGetCode).ToString);

by the way , the Stream is a Hrecord?
so possible way post more of your code to find what is going wrong.
and place just after every call a Bass_ErrrorGetCode to enclose the Error.

Remember if you are working with the No Soundcard Flag (Bass_Init(0....) then
the creation of the"Stream" handle must have the Flag
Bass_Stream_Decode
« Last Edit: 7 Jun '21 - 13:23 by Chris »