0 Replies
      Latest reply on Jul 18, 2019 5:17 AM by Deepa Pai
      Deepa Pai Level 1 Level 1 (0 points)

        As per the documentation, we can use AudioChannelDescription.mCoordinates to set speaker position. Following is my code snippet:

         

            OSStatus status = noErr;

          

            AudioObjectPropertyAddress propertyAddress;

            propertyAddress.mSelector = kAudioDevicePropertyPreferredChannelLayout;

            propertyAddress.mScope = kAudioDevicePropertyScopeOutput;

            propertyAddress.mElement = kAudioObjectPropertyElementMaster;

          

            if(AudioObjectHasProperty(self.mID, &propertyAddress)){

                UInt32 propSize = 0;

                AudioObjectGetPropertyDataSize(self.mID, &propertyAddress, 0, NULL, &propSize);

              

                AudioChannelLayout* layout = (AudioChannelLayout*)malloc(propSize);

                AudioChannelLabel labels[2] = {kAudioChannelLabel_Right, kAudioChannelLabel_Left};

              

                layout->mNumberChannelDescriptions = 2;

                layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;

                layout->mChannelBitmap = 0;

              

                for (UInt32 i = 0; i < layout->mNumberChannelDescriptions; i++) {

                    layout->mChannelDescriptions[i].mChannelLabel = labels[i];

                    layout->mChannelDescriptions[i].mChannelFlags = kAudioChannelFlags_SphericalCoordinates|kAudioChannelFlags_Meters;

                    layout->mChannelDescriptions[i].mCoordinates[kAudioChannelCoordinates_Distance] = sender.doubleValue;

                    layout->mChannelDescriptions[i].mCoordinates[kAudioChannelCoordinates_Azimuth] = (i == 0) ? 90 : -90;

                    layout->mChannelDescriptions[i].mCoordinates[kAudioChannelCoordinates_Elevation] = 0;

                }

              

                status = AudioObjectSetPropertyData(self.mID, &propertyAddress, 0, NULL, propSize, layout);

                if(status != noErr){

                    NSLog(@"setPosition cannot set");

                }

            }

         

        The API doesn't throw any error. But, there is no change is listening experience. Even if I set right speaker at distance 'x' (far), it doesn't give experience of listening from far speaker.

         

        What might be wrong here? Did I understand speaker positioning concept wrong?

         

        Thanks.

        Deepa