Encoding Ambisonics in SC

The Virtual Source

The following example encodes a single monophonic audio signal to an Ambisonics source with two parameters:

  • Azimuth: the horizontal angle of incidence.

  • Elevation: the vertical angle of incidence.

Both angles are expressed in rad and range from \(-\pi\) to \(\pi\). Figure 1 shows a virtual sound source with these two parameters.

/images/spatial/single-source.png

Figure 1: Virtual sound source with two angles (azimuth and elevation).


Setup

First steps include booting the server and defining the Ambisonics order:

(
// increase the number of SC output channels
s.options.numInputBusChannels = 2;
s.options.numOutputBusChannels = 16;
s.boot;

~order     = 1;
~nHOA      = (pow(~order+1,2)).asInteger;



// show SC meter
s.meter;
)

The Ambisonics Bus

// create the Ambisonics mix bus
~ambi_BUS  = Bus.audio(s,~nHOA);

The audio rate ~ambi_BUS sums all encoded Ambisonics signals. The bus size depends on the Ambisonics order M, following the formula \(N = (M+1)^2\). For simplicity, this example uses first order.


The channels of this bus correspond to the spherical harmonics. In the SC-HOA tools, Ambisonics channels are ordered according to the ACN convention and normalized with the N3D standard (Grond, 2017). The channels in the bus thus hold the three main axes in the following order:

Ambisonics channel ordering in the SC-HOA tools (ACN).

Spherical Harmonic Index

Channel

Description

1

W

omnidirectional

2

X

left-right

3

Z

top-bottom

4

Y

front-rear


Angles in SC Ambisonics

Both SC-HOA and ATK use the same angle convention for control:

  • azimuth = 0 with elevation=0 is a signal straight ahead

  • azimuth =-pi/2 is hard left

  • azimuth = pi/2 is hard right

  • azimuth = pi is in the back.

  • elevation = pi/2 is on the top

  • elevation = -pi/2 is on the bottom

Encoding with SC-HOA

The SC-HOA library includes different encoder options. This example uses the HOASphericalHarmonics class. This simple encoder can set the angles of incidence (azimuth, elevation) in spherical coordinates.

This example uses a sawtooth signal as mono input and calculates the four Ambisonics channels.

(
~encoder_A = {arg azim=0, elev=0;
      Out.ar(~ambi_BUS,HOASphericalHarmonics.coefN3D(~order,azim,elev)*Saw.ar(140));
      }.play;
)

The Ambisonics bus can be monitored and the angles of the source can be set, manually:

~ambi_BUS.scope;

// set parameters
~encoder_A.set(\azim,0)
~encoder_A.set(\elev,0)
/images/spatial/sc_ambi_scope.png

Figure 2: Ambisonics signal in scope with angles = 0,0.


Encoding with ATK

Hit ``ctrl + .`` (or ``Cmd + .``) to free the previous encoder.

Encoding with ATK works in a single synth like the SC-HOA approach. The HoaEncodeDirection UGen takes the input signal, the angles, a distance value (not for attenuation), and the order:

// with near-field effect (NFE)
(
~encoder_B = {arg azim=0, elev=0;
  Out.ar(~ambi_BUS ,HoaEncodeDirection.ar(Saw.ar(140),azim,elev, 1, ~order))
}.play;
)

The encoded signal is written to the Ambisonics bus.


Exercises


References

2017

  • Florian Grond and Pierre Lecomte. Higher order ambisonics for supercollider. In Linux audio conference 2017 proceedings. 2017.
    [details] [BibTeX▼]