<?xml version='1.0' encoding='US-ASCII'?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>

<rfc ipr="trust200902" category="std" updates="7845" submissionType="IETF"
     xml:lang="en" number="8486" consensus="yes">
  <front>
    <title abbrev="Opus Ambisonics">Ambisonics in an Ogg Opus Container</title>
    <author initials="J." surname="Skoglund" fullname="Jan Skoglund">
      <organization>Google LLC</organization>
      <address>
        <postal>
          <street>345 Spear Street</street>
          <city>San Francisco</city>
          <region>CA</region>
          <code>94105</code>
          <country>United States of America</country>
        </postal>
        <email>jks@google.com</email>
      </address>
    </author>


    <author initials="M.G." surname="Graczyk" fullname="Michael Graczyk">
      <organization></organization>
      <address>
        <email>michael@mgraczyk.com</email>
      </address>
    </author>
    <date month="October" year="2018"/>
    <area>RAI</area>
    <workgroup>codec</workgroup>


<keyword>spatial audio, lossy compression</keyword>


    <abstract>
      <t>This document defines an extension to the Opus audio codec to
      encapsulate coded Ambisonics using the Ogg format. It also contains updates to RFC 7845 to reflect necessary changes in the description of channel mapping families.</t>
    </abstract>
  </front>
  <middle>
    <section anchor="intro" title="Introduction" toc="default">
      <t>Ambisonics is a representation format for three-dimensional
      sound fields that can be used for surround sound and immersive
      virtual-reality playback.  See <xref target="fellgett75"
      pageno="false" format="default"/> and <xref target="daniel04"
      pageno="false" format="default"/> for technical details on the
      Ambisonics format.  For the purposes of the this document,
      Ambisonics can be considered a multichannel audio stream.  A
      separate stereo stream can be used alongside the Ambisonics in a
      head-tracked virtual reality experience to provide so-called
      non-diegetic audio -- that is, audio that should remain
      unchanged by rotation of the listener's head, such as narration
      or stereo music.  Ogg is a general-purpose container, supporting
      audio, video, and other media.  It can be used to encapsulate
      audio streams coded using the Opus codec.  See <xref
      target="RFC6716" pageno="false" format="default"/> and <xref
      target="RFC7845" pageno="false" format="default"/> for technical
      details on the Opus codec and its encapsulation in the Ogg
      container, respectively.  </t>

      <t>This document extends the Ogg Opus format by defining two new
      channel mapping families for encoding Ambisonics. The Ogg Opus
      format is extended indirectly by adding items with values 2 and
      3 to the "Opus Channel Mapping Families" IANA registry.  When 2 or
      3 are used as the Channel Mapping Family Number in an Ogg
      stream, the semantic meaning of the channels in the multichannel
      Opus stream is one of the Ambisonics layouts defined in this
      document. This mapping can also be used in other contexts that
      make use of the channel mappings defined by the "Opus Channel
      Mapping Families" registry. Furthermore, mapping families 240
      through 254 (inclusively) are reserved for experimental use.</t>
    </section>
    <section anchor="terminology" title="Terminology" toc="default">
        <t>
    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
    NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED",
    "MAY", and "OPTIONAL" in this document are to be interpreted as
    described in BCP&nbsp;14 <xref target="RFC2119"/> <xref target="RFC8174"/> 
    when, and only when, they appear in all capitals, as shown here.
        </t>

    </section>
    <section anchor="ogg_extension" title="Ambisonics with Ogg Opus" toc="default">
      <t>Ambisonics can be encapsulated in the Ogg format by encoding
      with the Opus codec and setting the channel mapping family value
      to 2 or 3 in the Ogg identification (ID) header. A demuxer
      implementation encountering channel mapping family 2 or 3 MUST
      interpret the Opus stream as containing Ambisonics with the
      format described in Sections <xref target="channel_mapping_2"
      pageno="false" format="counter"/> or <xref
      target="channel_mapping_3" pageno="false" format="counter"/>,
      respectively.  </t>
      <section anchor="channel_mapping_2" title="Channel Mapping Family 2" toc="default">
        <t>This channel mapping uses the same channel mapping table
        format used by channel mapping family 1. The output channels
        are Ambisonic components ordered in Ambisonic Channel Number
        (ACN) order (which is defined in <xref target="ACN" pageno="false"
        format="default"/>) followed by two optional channels of
        non-diegetic stereo indexed (left, right). The terms "order"
        and "degree" are defined according to <xref target="ambix"
        pageno="false" format="default"/>. </t>
        <figure anchor="ACN" title="Ambisonic Channel Number (ACN)" align="center" suppress-title="false" alt="" width="" height="">
          <artwork align="center" xml:space="preserve" name="" type="" alt="" width="" height="">
ACN = n * (n + 1) + m,
for order n and degree m.
</artwork>
        </figure>
        <t>For the Ambisonic channels, the ACN component corresponds to
	channel index as k = ACN. The reverse correspondence can also be
	computed for an Ambisonic channel with index k.  </t>
        <figure anchor="inverseACN" title="Ambisonic Degree and Order   from ACN" align="center" suppress-title="false" alt="" width="" height="">
          <artwork align="center" xml:space="preserve" name="" type="" alt="" width="" height="">
order   n = floor(sqrt(k)),
degree  m = k - n * (n + 1).
</artwork>
        </figure>
  <t> Note that channel mapping family 2 allows for so-called mixed-order
  Ambisonic representation, in which only a subset of the full Ambisonic order
  number of channels is encoded. By specifying the full number in the channel
  count field, the inactive ACNs can then be indicated in the channel mapping
  field using the index 255.</t>
        <t>Ambisonic channels are normalized with Schmidt Semi-Normalization (SN3D).  The interpretation of the Ambisonics signal as well as detailed definitions of ACN channel ordering and SN3D normalization are described in <xref target="ambix" pageno="false" format="default"/>, Section 2.1.  </t>
      </section>
      <section anchor="channel_mapping_3" title="Channel Mapping Family 3" toc="default">
        <t>In this mapping, C output channels (the channel count) are
	generated at the decoder by multiplying K = N + M decoded channels with
	a designated demixing matrix, D, having C rows and K columns (C and K
	do not have to be equal). Here, N denotes the number of streams
	encoded, and M is the number of these encoded streams that are coupled to produce two
	channels.  As for channel mapping family 2, this mapping family also
	allows for the encoding and decoding of full-order Ambisonics and
	mixed-order Ambisonics, as well as non-diegetic stereo
	channels. Furthermore, it has the added flexibility of mixing
	channels.  Let X denote a column vector containing K decoded channels
	X1, X2, ..., XK (from N streams), and let S denote a column vector
	containing C output streams S1, S2, ..., SC. Then, S = D X, as shown in
	<xref target="demixing"  />.</t>
        <figure anchor="demixing" title="Demixing in Channel Mapping Family 3" align="center" suppress-title="false" alt="" width="" height="">
          <artwork align="center" xml:space="preserve" name="" type="" alt="" width="" height="">
/     \   /                   \ /     \
| S1  |   | D11  D12  ... D1K | | X1  |
| S2  |   | D21  D22  ... D2K | | X2  |
| ... | = | ...  ...  ... ... | | ... |
| SC  |   | DC1  DC2  ... DCK | | XK  |
\     /   \                   / \     /
</artwork>
        </figure>
        <t>The matrix MUST be provided in the channel mapping table part of
	the identification header; see Section 5.1.1 of <xref target="RFC7845"
	pageno="false" format="default"/>. The matrix replaces the need for a
	channel mapping field; for channel mapping family 3, the mapping table
	has the following layout: </t>
        <figure anchor="channel_mapping" title="Channel Mapping Table for  Channel Mapping Family 3" align="center" suppress-title="false" alt="" width="" height="">
          <artwork align="center" xml:space="preserve" name="" type="" alt="" width="" height="">

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                                                +-+-+-+-+-+-+-+-+
                                                | Stream Count  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Coupled Count | Demixing Matrix                               :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

</artwork>
        </figure>
        <t>The fields in the channel mapping table have the following
        meaning: <list style="numbers" counter="8"><t>Stream Count "N"
        (8 bits, unsigned): <vspace blankLines="1"/> This is the total
        number of streams encoded in each Ogg packet.  <vspace
        blankLines="1"/> </t><t>Coupled Stream Count "M" (8 bits,
        unsigned): <vspace blankLines="1"/> This is the number of the
        N streams whose decoders are to be configured to produce two
        channels (stereo).  <vspace blankLines="1"/> </t><t>Demixing
        Matrix (16*K*C bits, signed): <vspace blankLines="1"/> The
        coefficients of the demixing matrix stored in column-major
        order as 16-bit, signed, two's complement fixed-point values
        with 15 fractional bits (Q15), little endian. If needed, the
        output gain field can be used for a normalization scale. For
        mixed-order Ambisonic representations, the silent ACN channels
        are indicated by all zeros in the corresponding rows of the
        mixing matrix. This also allows for mixed order with
        non-diegetic stereo as the number of columns implies the
        presence of non-diegetic channels.</t></list> </t>
        <t>Note that <xref target="RFC7845" pageno="false"
        format="default"/> specifies that the identification header
        cannot exceed one "page", which is 65,025 octets. This limits
        the Ambisonic order, which then MUST be lower than 12, if full
        order is utilized and the number of coded streams is the same
        as the Ambisonic order plus the two non-diegetic channels.
        The total output channel number, C, MUST be set in the third
        field of the identification header.  </t>
      </section>
   <section anchor="allowed_numbers_channels" title="Allowed Numbers of Channels" toc="default">
        <t>For both channel mapping families 2 and 3, the allowed
        numbers of channels are (1 + n)^2 + 2j for n = 0, 1, ..., 14
        and j = 0 or 1, where n denotes the (highest) Ambisonic order
        and j denotes whether or not there is a separate non-diegetic
        stereo stream.  This corresponds to periphonic Ambisonics from
        zeroth to fourteenth order plus potentially two channels of
        non-diegetic stereo.  Explicitly, the allowed number of
        channels are 1, 3, 4, 6, 9, 11, 16, 18, 25, 27, 36, 38, 49,
        51, 64, 66, 81, 83, 100, 102, 121, 123, 144, 146, 169, 171,
        196, 198, 225, and 227.  Note again that if full Ambisonic
        order is used and the number of coded streams is the same as
        the Ambisonic order plus the two non-diegetic channels, the
        order must then be lower than 12, due to the identification
        header length limit.</t>
   </section>

    </section>
    <section anchor="downmixing" title="Downmixing" toc="default">


             <t> The downmixing matrices in this section are only
             examples known to give acceptable results for stereo
             downmixing from Ambisonics, but other mixing strategies
             will be allowed, e.g., to emphasize a certain
             panning.</t>
             <t> An Ogg Opus player MAY use the matrix in <xref
	     target="stereo_downmix_matrix_1" /> to implement downmixing from
	     multichannel files using channel mapping families 2 and 3 when
	     there is no non-diegetic stereo. The first and second Ambisonic
	     channels are known as "W" and "Y", respectively. The omitted
	     coefficients in the matrix in the figure have the value 0.0. </t>
        <figure anchor="stereo_downmix_matrix_1" title="Stereo Downmixing Matrix for Channel Mapping Families 2 and 3 - Only Ambisonic Channels" align="center" suppress-title="false" alt="" width="" height="">
          <artwork align="center" xml:space="preserve" name="" type="" alt="" width="" height="">
/   \   /                  \ /     \
| L |   | 0.5  0.5 0.0 ... | |  W  |
| R | = | 0.5 -0.5 0.0 ... | |  Y  |
\   /   \                  / | ... |
                             \     /
</artwork>
        </figure>
        <t>The first Ambisonic channel (W) is a mono audio stream that
        represents the average audio signal over all directions. Since
        W is not directional, Ogg Opus players MAY use W directly for
        mono playback.  </t>
        <t>If a non-diegetic stereo track is present, the player MAY
        use the matrix in <xref target="stereo_downmix_matrix_2" />
        for downmixing.  Ls and Rs denote the two non-diegetic stereo
        channels.  </t>
        <figure anchor="stereo_downmix_matrix_2" title="Stereo Downmixing Matrix for Channel Mapping Families 2 and 3 -   Ambisonic Channels Plus a Non-Diegetic Stereo Stream" align="center" suppress-title="false" alt="" width="" height="">
          <artwork align="center" xml:space="preserve" name="" type="" alt="" width="" height="">
/   \   /                            \  /     \
| L |   | 0.25  0.25 0.0 ... 0.5 0.0 |  |  W  |
| R | = | 0.25 -0.25 0.0 ... 0.0 0.5 |  |  Y  |
\   /   \                            /  | ... |
                                        |  Ls |
                                        |  Rs |
                                        \     /
</artwork>
        </figure>
     
    </section>
  
<section anchor="updates" title="Updates to RFC 7845" toc="default">  
  <section anchor="updates_format" title="Format of the Channel Mapping Table" toc="default">
      <t>The language in Section 5.1.1 of <xref target="RFC7845" pageno="false" format="default"/> (copied below) implies that the channel
      mapping table, when present, has a fixed format for all channel mapping families: <list><t>
<!--Begin DNE text -->
      The order and meaning of these channels are defined by a channel
      mapping, which consists of the 'channel mapping family' octet and,
      for channel mapping families other than family 0, a 'channel
      mapping table', as illustrated in Figure 3.
<!--End DNE text -->
</t></list>
   This document updates <xref target="RFC7845" pageno="false"
   format="default"/> to clarify that the format of the channel mapping table
   may depend on the channel mapping family:
   <list><t>
 
      The order and meaning of these channels are defined by a channel
      mapping, which consists of the 'channel mapping family' octet and
      for channel mapping families other than family 0, a 'channel
      mapping table'.
</t><t>
      The format of the channel mapping table depends on the channel
      mapping family.  Unless the channel mapping family requires a
      custom format for its channel mapping table, the RECOMMENDED
      channel mapping table format for new mapping families is
      illustrated in Figure 3.
</t></list>
   The change above is not meant to change how families 1 and 255
   currently work.  To ensure that, the first paragraph of
   Section 5.1.1.2 is changed from:
   <list><t>
     <!--Begin DNE text -->
      Allowed numbers of channels: 1...8.  Vorbis channel order (see
      below).
     <!--END DNE text -->
</t></list>
   to:
   <list><t>
      Allowed numbers of channels: 1...8, with the mapping specified
      according to Figure 3.  Vorbis channel order (see below).
</t></list>
   Similarly, the first paragraph of Section 5.1.1.3 is changed from:
   <list><t>
     <!--Begin DNE text -->
     Allowed numbers of channels: 1...255.  No defined channel meaning.
     <!--END DNE text -->
</t></list>
   to:
   <list><t>
      Allowed numbers of channels: 1...255, with the mapping specified
      according to Figure 3.  No defined channel meaning.
</t></list>
</t> </section>

 <section anchor="unknown_mapping" title="Unknown Mapping Families" toc="default">
      <t>The treatment of unknown mapping families is changed slightly.
   Section 5.1.1.4 of <xref target="RFC7845" pageno="false" format="default"/> states:
   <list><t>
         <!--Begin DNE text -->
      The remaining channel mapping families (2...254) are reserved.  A
      demuxer implementation encountering a reserved 'channel mapping
      family' value SHOULD act as though the value is 255.
          <!--END DNE text -->
</t></list>
   This is changed to:
 <list><t>
      The remaining channel mapping families (2...254) are reserved.  A
      demuxer implementation encountering a 'channel mapping family'
      value that it does not recognize SHOULD NOT attempt to decode the
      packets and SHOULD NOT use any information except for the first 19
      octets of the ID header packet (Figure 2) and the comment header
      (Figure 10).
</t></list>
</t> </section>
    </section>

 <section anchor="experimental_mapping" title="Experimental Mapping Families" toc="default">
   <t>To make development of new mapping families easier while reducing the
   risk of creating compatibility issues with non-final versions of
   mapping families, mapping families 240 through 254 (inclusively) are
   now reserved for experiments and implementations of in-development
   families. Note that these mapping-family experiments are not restricted
   to Ambisonics.
   Implementers SHOULD attempt to use experimental family
   numbers that have not recently been used and SHOULD advertise what
   experimental numbers they use (e.g., for Internet-Drafts).
</t> <t>
   The Ambisonics mapping experiments that led to this document used
   experimental family 254 for family 2 and experimental family 253 for
   family 3. </t>
    </section>
   
    <section anchor="security" title="Security Considerations" toc="default">


      <t>Implementations of the Ogg container need to take appropriate security considerations into account, as outlined in Section 8 of <xref target="RFC7845" pageno="false" format="default"/>.  The extension defined in this document requires that semantic meaning be assigned to more channels than the existing Ogg format requires.  Since more allocations will be required to encode and decode these semantically meaningful channels, care should be taken in any new allocation paths.  Implementations MUST NOT overrun their allocated memory nor read from uninitialized memory when managing the Ambisonic channel mapping.  </t>
    </section>
    <section anchor="iana" title="IANA Considerations" toc="default">
      <t>This document updates the IANA registry "Opus Channel
      Mapping Families" to add 17 new assignments.  </t>


<?rfc compact="no"?>
<texttable title="" suppress-title="false" align="center" style="full">

  
        <ttcol align="left">Value</ttcol>
        <ttcol align="left">Description</ttcol>
        <ttcol align="left">Reference</ttcol>
        <c>0</c>
        <c>Mono, L/R stereo </c><c> 
        Section 5.1.1.1 of <xref target="RFC7845" pageno="false" format="default"/>, <xref target="updates" pageno="false" format="default"/> of this document</c>
        <c>1</c>
        <c>1-8 channel surround </c><c>Section 5.1.1.2 of <xref target="RFC7845" pageno="false" format="default"/>, <xref target="updates" pageno="false" format="default"/> of this document</c>
        <c>2</c>
        <c>Ambisonics as individual channels</c> <c> <xref target="channel_mapping_2" pageno="false" format="default"/> of this document</c>
        <c>3</c>
        <c>Ambisonics with demixing matrix</c><c> <xref target="channel_mapping_3" pageno="false" format="default"/> of this document</c>
        <c>240-254</c> 
        <c>Experimental use </c><c> <xref target="experimental_mapping" pageno="false" format="default"/> of this document</c> 
        <c>255</c>
        <c>Discrete channels </c><c> 
        Section 5.1.1.3 of <xref target="RFC7845" pageno="false" format="default"/>, <xref target="updates" pageno="false" format="default"/> of this document</c>
    
      </texttable>
<?rfc compact="yes"?>
    </section>

  </middle>
  <back>
    <references title="Normative References">

<?rfc include="reference.RFC.2119" ?>

<?rfc include="reference.RFC.6716" ?>

<?rfc include="reference.RFC.7845" ?>

<?rfc include='reference.RFC.8174.xml'?>

  <reference anchor="ambix"
	     target="http://iem.kug.ac.at/fileadmin/media/iem/projects/2011/ambisonics11_nachbar_zotter_sontacchi_deleflie.pdf"
	     quote-title="true">
<front>
<title>AMBIX - A SUGGESTED AMBISONICS FORMAT</title>
<author initials="C." surname="Nachbar" fullname="Christian Nachbar"/>
<author initials="F." surname="Zotter" fullname="Franz Zotter"/>
<author initials="E." surname="Deleflie" fullname="Etienne Deleflie"/>
<author initials="A." surname="Sontacchi" fullname="Alois Sontacchi"/>
<date month="June" year="2011"/>
</front>
<seriesInfo name="Ambisonics" value="Symposium"  />
</reference>

</references>

    <references title="Informative References">

 
      <reference anchor="fellgett75" target="http://www.michaelgerzonphotos.org.uk/articles/Ambisonics%201.pdf" quote-title="true">
        <front>
          <title>Ambisonics. Part one: General system description</title>
          <author initials="P." surname="Fellgett" fullname="Peter Fellgett"/>
          <date month="August" year="1975"/>
        </front>
  <seriesInfo name="Studio Sound" value="vol. 17, no. 8, pp. 20-22" />

      </reference>

      <reference anchor="daniel04" target="https://www.researchgate.net/publication/277841868_Further_Study_of_Sound_Field_Coding_with_Higher_Order_Ambisonics">
        <front>
          <title>Further Study of Sound Field Coding with Higher Order Ambisonics</title>
          <author initials="J." surname="Daniel" fullname="Jerome Daniel"/>
          <author initials="S." surname="Moreau" fullname="Sebastien Moreau"/>
          <date month="May" year="2004"/>
        </front>
	<seriesInfo name="Audio Engineering Society" value="Convention Paper" />
      </reference>


    </references>

    <section anchor="Acknowledgments" title="Acknowledgments" toc="default" numbered="no">
      <t>Thanks to Timothy Terriberry, Jean-Marc Valin, Mark Harris, Marcin Gorzel, and Andrew Allen for their guidance and valuable contributions to this document.  </t>
    </section>
  </back>
</rfc>
