0 Replies
      Latest reply on Jun 2, 2019 10:16 AM by tempostudios
      tempostudios Level 1 Level 1 (0 points)

        I'm making an iOS audio playback app using AVFoundation. I'm trying to create the simplest possible implementation of playing a 5.1 Surround Sound audio file via AirPlay to an Apple TV 4K.

         

        The problem: my 5.1 file is downmixed to stereo. My audioSession.maximumOutputNumberOfChannels always returns 2, even if I connect to Apple TV 4K via Airplay and the Apple TV settings have Dolby Digital 5.1 set to on.

         

        I've tested my 5.1 audio file (6 ch,  48000 Hz, 'ec-3' encoded with the official Dolby Digital Encoder utility here: http://dolbyencodingutility.com/) with optical audio in to my Sonos 5.1 system and the channel mappings work correctly.

         

        Code here:

         

        let audioSession = AVAudioSession.sharedInstance()
              
                do {
                    try audioSession.setCategory(AVAudioSession.Category.playback)
                  
                }
                catch {
                    print("Couldn't set category")
                }
              
                do {
                    try audioSession.setActive(true)
                }
                catch {
                    print("Couldn't init audio session")
                }
        
                print(audioSession.currentRoute.outputs.count)
        
                do {
                    try audioSession.setPreferredOutputNumberOfChannels(6)
                }
                catch {
                    print("Couldn't set six channels")
                    print(audioSession.maximumOutputNumberOfChannels)
                    print(audioSession.outputNumberOfChannels)    
                }
        
                //play audio
                let path = Bundle.main.path(forResource: "art.scnassets/Woodwind_6Short_Dolby", ofType: "mp4")!
                let url = URL(fileURLWithPath: path)
              
                do {
                    audioPlayer = try AVAudioPlayer(contentsOf: url)
                    print(audioPlayer.format)
                }
                catch{
                    print(error)
                }
                audioPlayer.play()