Fixed surround sound support on Apple TV
authorSam Lantinga
Mon, 24 Feb 2020 10:25:57 -0800
changeset 13549dfe181848aba
parent 13548 96382c849dec
child 13550 058a6b076676
Fixed surround sound support on Apple TV
src/audio/coreaudio/SDL_coreaudio.m
     1.1 --- a/src/audio/coreaudio/SDL_coreaudio.m	Sun Feb 23 23:07:15 2020 +0100
     1.2 +++ b/src/audio/coreaudio/SDL_coreaudio.m	Mon Feb 24 10:25:57 2020 -0800
     1.3 @@ -710,6 +710,41 @@
     1.4      /* Calculate the final parameters for this audio specification */
     1.5      SDL_CalculateAudioSpec(&this->spec);
     1.6  
     1.7 +    /* Set the channel layout for the audio queue */
     1.8 +    AudioChannelLayout layout;
     1.9 +    SDL_zero(layout);
    1.10 +    switch (this->spec.channels) {
    1.11 +    case 1:
    1.12 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
    1.13 +        break;
    1.14 +    case 2:
    1.15 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
    1.16 +        break;
    1.17 +    case 3:
    1.18 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_4;
    1.19 +        break;
    1.20 +    case 4:
    1.21 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_Quadraphonic;
    1.22 +        break;
    1.23 +    case 5:
    1.24 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_5_0_A;
    1.25 +        break;
    1.26 +    case 6:
    1.27 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_5_1_A;
    1.28 +        break;
    1.29 +    case 7:
    1.30 +        /* FIXME: Need to move channel[4] (BC) to channel[6] */
    1.31 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_6_1_A;
    1.32 +        break;
    1.33 +    case 8:
    1.34 +        layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_7_1_A;
    1.35 +        break;
    1.36 +    }
    1.37 +    if (layout.mChannelLayoutTag != 0) {
    1.38 +        result = AudioQueueSetProperty(this->hidden->audioQueue, kAudioQueueProperty_ChannelLayout, &layout, sizeof(layout));
    1.39 +        CHECK_RESULT("AudioQueueSetProperty(kAudioQueueProperty_ChannelLayout)");
    1.40 +    }
    1.41 +
    1.42      /* Allocate a sample buffer */
    1.43      this->hidden->bufferSize = this->spec.size;
    1.44      this->hidden->bufferOffset = iscapture ? 0 : this->hidden->bufferSize;
    1.45 @@ -820,6 +855,13 @@
    1.46          AVAudioSession* session = [AVAudioSession sharedInstance];
    1.47          [session setPreferredSampleRate:this->spec.freq error:nil];
    1.48          this->spec.freq = (int)session.sampleRate;
    1.49 +        if (iscapture) {
    1.50 +            [session setPreferredInputNumberOfChannels:this->spec.channels error:nil];
    1.51 +            this->spec.channels = session.preferredInputNumberOfChannels;
    1.52 +        } else {
    1.53 +            [session setPreferredOutputNumberOfChannels:this->spec.channels error:nil];
    1.54 +            this->spec.channels = session.preferredOutputNumberOfChannels;
    1.55 +        }
    1.56      }
    1.57  #endif
    1.58  
    1.59 @@ -864,7 +906,7 @@
    1.60          return SDL_SetError("Unsupported audio format");
    1.61      }
    1.62  
    1.63 -    strdesc->mBytesPerFrame = strdesc->mBitsPerChannel * strdesc->mChannelsPerFrame / 8;
    1.64 +    strdesc->mBytesPerFrame = strdesc->mChannelsPerFrame * strdesc->mBitsPerChannel / 8;
    1.65      strdesc->mBytesPerPacket = strdesc->mBytesPerFrame * strdesc->mFramesPerPacket;
    1.66  
    1.67  #if MACOSX_COREAUDIO