sbooth / SFBAudioEngine

A powerhouse of audio functionality for macOS and iOS
https://sbooth.github.io/SFBAudioEngine/
MIT License
552 stars 87 forks source link

How to play DSD in DoP mode? #185

Closed pzs7602 closed 3 years ago

pzs7602 commented 3 years ago

I play a dsd audio file (test.dff, DSD64 file) in DoP mode:

let player = AudioPlayer()
let url = Bundle.main.url(forResource: "test", withExtension: "dff")
let dsdDecoder = try DSDDecoder(url: url)
let decoder = try DoPDecoder(decoder: dsdDecoder)
try player.play(decoder)

but no sound heard from my Sony PHA-3 DAC, the DSD indicator of the DAC is not on.

BTW, I can play DSD audio file in PCM mode normally:

let decoder = try DSDPCMDecode(decoder: dsdDecoder)
try player.play(decoder)
sbooth commented 3 years ago

The code you have for DoP output looks correct.

Does the PHA-3 support DSD over PCM? I couldn't find any technical documentation on https://www.sony.com/electronics/headphone-amplifiers/pha-3/specifications

pzs7602 commented 3 years ago

Sony PHA-3 DAC supports DSD DoP mode, I can play DSD audio file in DoP mode normally by using Sony's Hi-Res Audio Player in Mac, the player's preference panel has DSD playing settings when PHA-3 is connected:

Screen Shot 2021-02-20 at 11 02 57

the demo application project SimplePlayer-macOS of SFBAudioEngine can play DSD in DoP mode with my Sony PHA-3 connected to Mac, but not normally for SimplePlayer-iOS project. Any one successfully plays DSD audio in DoP mode with (DoP capable)DAC/iPhone by using SimplePlayer-iOS project?

sbooth commented 3 years ago

Honestly I've never tried DoP on iOS and haven't heard of any attempts, successful or otherwise. I assume you'd need to make the session unmixable but I'm not sure if that would be sufficient. I assume this happens when testing on a device?

pzs7602 commented 3 years ago

I finally found the solution in DSD DoP mode playing: the AVAudioSession's sample rate should be set to sample_rate _of_the_DSD_Audio/16.0 before playing DSD audio in DoP mode. when playing DSD64, I add the following code before player.play:

let session:AVAudioSession = AVAudioSession.sharedInstance() // get audio session
try? session.setActive(false)
do{
    try session.setPreferredSampleRate(Double(dsd64SampleRate)/16.0) 
    try session.setActive(true)
}
catch let error as NSError{
    print("err=\(error.description)")
}

this works for my Sony PHA-3/iPhone 12 @sbooth may be the project can be updated for this(get the sample rate of the DSD audio file and then set the corresponding AVAudioSession sample rate before playing), so we can play DSD audio in DoP mode without these extra codes. thank sbooth for this great audio engine! BTW: DoP (DSD over PCM) packs 16 bits of 1 bit DSD data into each PCM 24 bit sample. The other 8 bits are used to identify the samples as PCM rather than DSD. 2.822 MHz/16 gives 172 KHz samples per second. So, a 1xDSD can be sent as 172 KHz DoP. To do 2xDSD as DoP your DAC needs to handle 352 KHz PCM.

sbooth commented 3 years ago

I'm glad you got this working, that is very cool!

I agree this should be documented somewhere to. Perhaps this topic is a candidate for the Wiki?

Please see https://github.com/sbooth/SFBAudioEngine/wiki/DSD-over-PCM-(DoP)-Playback