Author Topic: App corrupted when playing DSD in DoP mode in Windows 11  (Read 217 times)

pzs7602

  • Posts: 80
I'm using Bass.Net lib to play a dsf file in DoP mode in Windows 11, my app can play the file normally from the begining, but after 1 minutes or so, the sound starts dithering and the app corrupted. Please help me to find the solution. My env:
Bass.Net 2.4.17
Bass libs 2.4.17
BASSWASAPI 2.4.3.1
dotnet 6.0.400
windows 11

My code snippet:
Code: [Select]
        public void OnPlayClickCommand()
        {
            bool code = Bass.BASS_Init(-1, 176400, BASSInit.BASS_DEVICE_DEFAULT | BASSInit.BASS_DEVICE_FREQ , IntPtr.Zero);
            if (code != true)
            {
                Console.WriteLine("Error returned from BASS_INIT");
            }
            else
            {
                Console.WriteLine("BASS_INIT OK");
            }

            int freq = 0;
            stream = BassDsd.BASS_DSD_StreamCreateFile("test.dsf", 0, 0, BASSFlag.BASS_DSD_DOP | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, 0);
            if (stream == 0)
            {
                BASSError err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("create file error code={0}",err);
               
            }
            BASS_CHANNELINFO ci;
            ci = Bass.BASS_ChannelGetInfo(stream);
           
            BASS_CHANNELINFO info = new BASS_CHANNELINFO();
            bool ret = Bass.BASS_ChannelGetInfo(stream, info);
            if (ret == false)
            {
                BASSError err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("channel getinfo  error code={0}",err);
            }

           
            WASAPIPROC _wasapiProc = new WASAPIPROC(WasapiProc);
            code = BassWasapi.BASS_WASAPI_Init(-1, ci.freq, ci.chans, BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE, 0.4f, 0, _wasapiProc, IntPtr.Zero);
            if (code != true)
            {
                BASSError err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("Error returned from BASS_WASAPI_Init:{0}",err);
            }
            else
            {
                Console.WriteLine("BASS_WASAPI_Init OK");
            }
           
            code = BassWasapi.BASS_WASAPI_Start();
            if (code != true)
            {
                BASSError err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("Error returned from BASS_WASAPI_Start:{0}",err);
            }
            else
            {
                Console.WriteLine("BASS_WASAPI_Start OK");
            }

        }

        private int WasapiProc(IntPtr buffer, int length, IntPtr user)
        {
            // stream is defined in class as:  public int stream;
            int r = Bass.BASS_ChannelGetData(stream, buffer, length);
            // error occur
            if (r == -1)
            {
                r = 0;
//                BASSError err = Bass.BASS_ErrorGetCode();
//                Console.WriteLine("Error returned from BASS_ChannelGetData:{0}",err);

            }
            return r;
        }

Thanks in advance.
« Last Edit: 25 Oct '22 - 04:56 by pzs7602 »

Ian @ un4seen

  • Administrator
  • Posts: 24792
When you say the "app corrupted", do you mean the app is crashing or just the sound is corrupted? If the latter, is the sound still recognisable or is it just noise? Is the same "test.dsf" file playing 100% fine in other software? Does the file sound OK if you convert it to PCM, ie. without the BASS_DSD_DOP flag? If your device has an ASIO driver, you could also try playing the file with the DSDTEST.EXE example from the BASSASIO package (C\BIN folder) for comparison. Note that example supports both raw DSD and DSD-over-PCM, depending on what the ASIO driver supports.

The problem is probably unrelated, but as you're using BASSWASAPI rather than BASS for output, you can/should use the "No Sound" device (0) in your BASS_Init call.

pzs7602

  • Posts: 80
My app can play dsf in DoP mode normally(music sounds good and my DAC's DSD indicattor light is on) when starting to play, after 1 minutes or so, the sound stopped and the app crashed.
The test.dsf sounds OK when play it without DoP option(and not using WASAPI):
stream=BassDsd.BASS_DSD_StreamCreateFile("test.dsf", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT,0);
So, the problem has nothing to do witth test.dsf itself, I change to other dsf file, same error.
may be my incorrect usage of WASAPI methods ?
Is there other way to play DSD in DoP mode without using WASAPI in windows?(like in macOS/Linux use BASS only, I've try, but fail.) 

Ian @ un4seen

  • Administrator
  • Posts: 24792
My app can play dsf in DoP mode normally(music sounds good and my DAC's DSD indicattor light is on) when starting to play, after 1 minutes or so, the sound stopped and the app crashed.
The test.dsf sounds OK when play it without DoP option(and not using WASAPI):
stream=BassDsd.BASS_DSD_StreamCreateFile("test.dsf", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT,0);
So, the problem has nothing to do witth test.dsf itself, I change to other dsf file, same error.
may be my incorrect usage of WASAPI methods ?

Perhaps your WASAPIPROC delegate (_wasapiProc) is being garbage-collected? I believe you need to keep a reference to the delegate to prevent that happening, ie. it shouldn't be a local variable. Please see the "Callbacks and Delegates" section of the "Interoperating with Unmanaged Code" page in the BASS.Net documentation for details.

Is there other way to play DSD in DoP mode without using WASAPI in windows?(like in macOS/Linux use BASS only, I've try, but fail.)

ASIO can also be used instead of exclusive-mode WASAPI. It isn't generally possible to play DoP data via normal shared output without the data getting modified/corrupted, eg. by resampling or other processing. But you could try setting the appropriate format and disabling audio enhancements and setting the level to 100% in the Sound control panel.

pzs7602

  • Posts: 80
define the delegate as the class member(not the local variable) makes DoP playing normal. thanks!