Author Topic: DSD DoP in Linux  (Read 274 times)

pzs7602

  • Posts: 80
DSD DoP in Linux
« on: 18 Oct '22 - 03:45 »
Does any one can normally play dsf/dff in DoP mode in Linux(Ubuntu)? I try to play dsf in DoP mode in Ubuntu, but I only hear a noisy background with a low level music sound from DAC(Sony PHA-3) output, my DAC's DSD indicator light is off.
My environment:
Ubuntu 22.04, dotnet 6.0.400, Bass.NET 2.4.17.0 with Bass linux native libs,
My code snippet:
Code: [Select]
            bool code = Bass.BASS_Init(-1, 176400, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            if (code != true)
            {
                Console.WriteLine("Error returned from BASS_INIT");
            }
            else
            {
                Console.WriteLine("BASS_INIT OK");
            }
            stream = BassDsd.BASS_DSD_StreamCreateFile("test.dsf", 0, 0, BASSFlag.BASS_DSD_DOP | BASSFlag.BASS_SAMPLE_FLOAT,0);
            if (stream == 0)
            {
                BASSError err = Bass.BASS_ErrorGetCode();
                Console.WriteLine("create file error code={0}",err);
               
            }

            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);
            }
           
            bool result = Bass.BASS_ChannelPlay(stream, false);

176400 in BASS_Init is the sample frequency of the test.dsf.
Any advice is appreciated.

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: DSD DoP in Linux
« Reply #1 on: 18 Oct '22 - 13:20 »
The "Default" output on Linux is usually via PulseAudio/PipeWire, and I'm not sure if that'll be bit-perfect, which it needs to be for the DSD data to reach the DAC intact. You could try using the real device directly instead via the BASS_Init "device" parameter, and set the "freq" parameter to match the DoP stream's rate. Also make sure you don't apply any DSP/FX, including volume adjustment. If it still doesn't work, you could also try using the BASS_DSD_DOP_AA flag in the BASS_DSD_StreamCreateFile call.

pzs7602

  • Posts: 80
Re: DSD DoP in Linux
« Reply #2 on: 19 Oct '22 - 08:44 »
Thanks for the reply.
Using the real device directly via the BASS_Init "device" parameter, and set the "freq" parameter to match the DoP stream's rate make the DoP mode functional in Linux.
I can get available audio output device names from BASS_GetDeviceInfo and let user choose the DAC from the list, but BASS_GetDeviceInfo seems return a bunch of devices which are hard for user to choose from, such as:(in my environment)

Code: [Select]
n=0 No sound
n=1 Default
n=2 HDA Intel PCH: CX20632 Analog
n=3 HDA Intel PCH: HDMI 0
n=4 HDA Intel PCH: HDMI 1
n=5 HDA Intel PCH: HDMI 2
n=6 HDA Intel PCH: HDMI 3
n=7 HDA Intel PCH: HDMI 4
n=8 HDA Intel PCH: HDMI 5
n=9 HDA Intel PCH: HDMI 6
n=10 PHA-3: USB Audio
n=11 2.1 Surround output to Front and Subwoofer speakers
n=12 4.0 Surround output to Front and Rear speakers
n=13 4.1 Surround output to Front, Rear and Subwoofer speakers
n=14 5.0 Surround output to Front, Center and Rear speakers
n=15 5.1 Surround output to Front, Center, Rear and Subwoofer speakers
n=16 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
n=17 Rate Converter Plugin Using Samplerate Library
n=18 Rate Converter Plugin Using Speex Resampler
n=19 JACK Audio Connection Kit
n=20 Open Sound System
n=21 PulseAudio Sound Server
n=22 Plugin for channel upmix (4,6,8)
n=23 Plugin for channel downmix (stereo) with a simple spacialization

Is it possible to filter out some system-used devices or automatically detect connected DAC device(such as PHA-3 in the list)?
« Last Edit: 19 Oct '22 - 09:40 by pzs7602 »

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: DSD DoP in Linux
« Reply #3 on: 19 Oct '22 - 16:39 »
Good to hear that using the real device directly got things working properly.

Regarding filtering the device list, you could also check the BASS_DEVICEINFO "driver" value. It will start with "hw:" for a real device.

pzs7602

  • Posts: 80
Re: DSD DoP in Linux
« Reply #4 on: 20 Oct '22 - 02:48 »
This Method for DSD DoP playing in Linux is not working in macOS(12.6), any suggestion?

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: DSD DoP in Linux
« Reply #5 on: 20 Oct '22 - 16:25 »
Try adding the BASS_DEVICE_FREQ flag to your BASS_Init call, as BASS will otherwise leave the device's existing rate on macOS. You can confirm whether the new rate was successfully applied with BASS_GetInfo. Also make sure the device's volume is set to 100%.

pzs7602

  • Posts: 80
Re: DSD DoP in Linux
« Reply #6 on: 21 Oct '22 - 07:07 »
Thanks! This works for both macOS and Linux now.
« Last Edit: 21 Oct '22 - 14:41 by pzs7602 »