def validate_speaker_mapping(channels, candidate_speaker_mapping)
      if candidate_speaker_mapping.is_a?(Array) && candidate_speaker_mapping.length == channels
        speaker_mapping_without_invalid_speakers = UnvalidatedFormat::SPEAKER_POSITIONS & candidate_speaker_mapping
        if speaker_mapping_without_invalid_speakers.length < channels
          speaker_mapping_without_invalid_speakers += [:undefined] * (channels - speaker_mapping_without_invalid_speakers.length)
        end

        if speaker_mapping_without_invalid_speakers == candidate_speaker_mapping
          return
        end
      end

      raise InvalidFormatError,
            "Invalid speaker_mapping: `#{candidate_speaker_mapping.inspect}`. Should be an array the same size as the number of channels, containing either :undefined or these known speakers: #{UnvalidatedFormat::SPEAKER_POSITIONS.inspect}. Each defined speaker must come before any of the ones after it in the master list, and all :undefined speakers must come after the last defined speaker."
    end
def validate_speaker_mapping(channels, candidate_speaker_mapping)
      if candidate_speaker_mapping.is_a?(Array) && candidate_speaker_mapping.length == channels
        speaker_mapping_without_invalid_speakers = UnvalidatedFormat::SPEAKER_POSITIONS & candidate_speaker_mapping
        if speaker_mapping_without_invalid_speakers.length < channels
          speaker_mapping_without_invalid_speakers += [:undefined] * (channels - speaker_mapping_without_invalid_speakers.length)
        end

        if speaker_mapping_without_invalid_speakers == candidate_speaker_mapping
          return
        end
      end

      raise InvalidFormatError,
            "Invalid speaker_mapping: `#{candidate_speaker_mapping.inspect}`. Should be an array the same size as the number of channels, containing either :undefined or these known speakers: #{UnvalidatedFormat::SPEAKER_POSITIONS.inspect}. Each defined speaker must come before any of the ones after it in the master list, and all :undefined speakers must come after the last defined speaker."
    end
Internal