Author Topic: BassEnc_Flac.BASS_Encode_FLAC_StartFile return 0 but error code is BASS_OK  (Read 422 times)

pzs7602

  • Posts: 80
I'm using BASS_StreamCreateFile and BassEnc_Flac.BASS_Encode_FLAC_StartFile to convert audio from mp3 to flac, the BASS_Encode_FLAC_StartFile call return 0 but error code is 0(BASS_OK), my code:

Code: [Select]
            bool code = Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, win: IntPtr.Zero);
            if (code != true)
            {
                Console.WriteLine("Error returned from BASS_INIT");
            }
            else
            {
                Console.WriteLine("BASS_INIT OK");
            }

            string AudioFile = "encoded.flac";
            stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE); // create decoding channel for 1st track on 1st drive
            if (stream == 0)
            {
                var err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("BASS_CD_StreamCreate error: {0}", err);
            }

            var c = BassEnc_Flac.BASS_Encode_FLAC_StartFile(stream, "-0 --bps=768", BASSEncode.BASS_ENCODE_FP_AUTO, AudioFile);
            if (c == 0)
            {
                var err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("BASS_Encode_FLAC_StartFile error: {0}", err);
            }

why the error code is BASS_OK ?
My running environment:

Bass.Net 2.4.17
macOS 13.0
Apple silicon CPU
dotnet 6.0

I've try above code in Linux and it runs OK.


Ian @ un4seen

  • Administrator
  • Posts: 24801
That's strange. I had a look at the BASS_Encode_FLAC_StartFile source, but couldn't see any way for it to fail with a 0 error code. Please check that you're using the latest BASSenc and BASSenc_FLAC versions with BASS_Encode_GetVersion and BASS_Encode_FLAC_GetVersion, and if not then try upgrading and see if you still get the problem. If it does still happen, to narrow it down, does it still happen if you set options=null in the call?

pzs7602

  • Posts: 80
Get Bass version and set option in BassEnc_Flac.BASS_Encode_FLAC_StartFile to null, the same error:
Code: [Select]
            int Bass_ver = Bass.BASS_GetVersion();
            int BassEnc_Flac_Ver = BassEnc_Flac.BASS_Encode_FLAC_GetVersion();
            int BassEnc_Ver = BassEnc.BASS_Encode_GetVersion();
            bool code = Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, win: IntPtr.Zero);
            Console.WriteLine("Bass Version={0:X}",Bass_ver);
            Console.WriteLine("BassEnc Version={0:X}",BassEnc_Ver);
            Console.WriteLine("BassEnc_Flac_Ver Version={0:X}",BassEnc_Flac_Ver);
           
            if (code != true)
            {
                Console.WriteLine("Error returned from BASS_INIT");
            }
            else
            {
                Console.WriteLine("BASS_INIT OK");
            }

            string AudioFile = "encoded.flac";
            stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE); // create decoding channel for 1st track on 1st drive
            if (stream == 0)
            {
                var err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("BASS_StreamCreate error: {0}", err);
            }
            else
            {
                Console.WriteLine("stream={0}", stream);
            }
            var c = BassEnc_Flac.BASS_Encode_FLAC_StartFile(stream, null, BASSEncode.BASS_ENCODE_FP_AUTO, AudioFile);
            if (c == 0)
            {
                var err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("BASS_Encode_FLAC_StartFile error: {0}", err);
            }


Console output:
Bass Version=2041007
BassEnc Version=2041001
BassEnc_Flac_Ver Version=2040400
BASS_INIT OK
stream=-2147483647
BASS_Encode_FLAC_StartFile error: BASS_OK

My running environment:

Bass.Net 2.4.17
macOS 13.0
Apple silicon CPU
dotnet 6.0

Ian @ un4seen

  • Administrator
  • Posts: 24801
Is the problem only happening on macOS? Please try building and running the "convert-addons" example from the BASSenc package in Xcode and see if its FLAC encoding option (-e5) is affected too. Note you will need to have all of the BASSenc_FLAC/MP3/OGG/OPUS add-ons for that.

pzs7602

  • Posts: 80
convert-addons -e5 demo.mp3 can output normal bass.flac, so the problem is in my project. I re-download all the newest bass libs needed by my project and the problem disappeared but still don't know the reason. Thank Ian for help!