Using the Audio Expander Capelet - BelaPlatform/Bela GitHub Wiki

This material has been superseded. Visit learn.bela.io for the maintained version.

Using the Audio Expander Capelet

The Audio Expander Capelet is a hardware accessory for the Bela cape which converts the 16-bit analog inputs and outputs to extra audio channels. It provides lowpass filtering to reduce noise and aliasing, and DC blocking and level-shifting to allow audio signals to be sent and received from the analog I/Os.

Please read the entirety of this guide before using the Audio Expander in your project so you understand its capabilities and how to enable it on particular channels.

Hardware Setup

Installation

To install the audio expander, place it on top of the Bela cape. Ensure that all the pins fit into the sockets in the cape, especially the analog input and output sockets.

Make sure the audio expander is pushed down as far as it will go, so it makes a secure connection with the sockets underneath.

Audio Expander Outputs

The 3-pin connectors labelled OUT on the edge of the audio expander give you the extra audio outputs. These connectors contain low-pass filtered, level-shifted versions of the signals on each of the 8 analog output pins.

The 3-pin connectors use the same pinout as the audio input and output connectors on the Bela cape, so the same type of adapter cable can be used.

Unlike the Bela cape, the audio expander outputs are not designed to directly drive headphones. These should be considered line outputs only, and an external amp should be used for driving speakers and headphones.

Audio Expander Inputs

The 3-pin connectors labelled IN on the edge of the audio expander give you the extra audio inputs. Audio signals coming into these connectors will be low-pass filtered and level-shifted for use with the Bela analog inputs.

Important: to use the audio expander inputs, you must install wire jumpers between connectors J10 and J11 for the channels you want to use. The jumpers connect the output of the audio expander circuits to the Bela analog inputs. With the jumper installed, the audio expander is enabled, overriding the analog input; with the jumper removed, the analog input works normally and you can connect an analog signal directly to J10.

The audio expander inputs have a selectable gain: installing wire jumpers on J12 (labelled IN-GAIN) will increase the gain of selected channels by a factor of 20dB (x10).

Software

Two command-line options are provided for working with the audio expander and are also accessible through the IDE settings tab:

-Y or --audio-expander-inputs selects analog input channels to rescale and filter for use with the audio expander. Provide a list of channels (0 through 7) separated by commas. Example: -Y 0,1,2,3 would rescale analog inputs 0-3 for use with the audio expander. In this case, the analog input range is -1 to 1 rather than 0 to 1, and a highpass filter is added to remove the DC offset from the audio expander circuit.

-Z or --audio-expander-outputs selects analog output channels to rescale for use with the audio expander. Provide a list of channels (0 through 7) separated by commas. Example: -Z 4,5 would rescale analog outputs 4 and 5 for use with the audio expander. In this case, the analog output range is -1 to 1 rather than 0 to 1, and this will be rescaled internally to a single-ended signal suitable for the analog output.

The analog-as-audio channels are accessed from software the same way as the analog channels:

  • in C++, you'd use the analogRead()/analogWriteOnce() functions
  • in PureData, [adc~] and [dac~] 3 to 10 The only exception is Supercollider, where, when setting a channel count greater than 2, the analog-as-audio channels are accessed as audio channels instead of via the analogIn and analogOut uGens.

Under the hood

When you specify the --audio-expander- options, what happens has to do with scaling and level shifting:

Using analogWriteOnce(), the signal would normally be scaled between 0 and 1, not between -1 and 1 as with audioWrite(). To rescale an audio signal to this range, you should add 1 and multiply by 0.5. That said, the very top of the analog output range is sometimes clipped if the USB port powering the board has a voltage of less than 5V, so it is recommended to scale it down so the output never goes above 0.92. This is done for you in the background, but it is equivalent to using the following line without enabling the --audio-expander-outputs option:

analogWriteOnce(context, n, ch, (signal + 1.0) * 0.46);

where n is the frame number, ch is the channel, and signal is a bipolar signal in the range -1 to 1, then you would write this signal using analogWriteOnce as follows:

Similarly, the analog input is rescaled in the background so that the input range from 0 to 1 is scaled between -1 and 1, with an offset of about 0.4 from the audio expander filters. The signal is then filtered with a first-order high-pass to eliminate the DC offset.

Working with raw signals:

What the above options do may not be the perfect fit for your specific application. If you do not specify any of the --audio-expander- options, you can still access the audio expander the same way you usually access the analog inputs and outputs on Bela. When using C++, the analogRead() and analogWriteOnce() functions will work as usual (no rescaling or filtering in the background) and you can implement these functionalities yourself.

Similarly, when using libpd or Heavy, the analog inputs and outputs will show up on channels 3 through 10, scaled between 0 and 1, and will need to be manually rescaled and filtered.

Tech Specs

Audio input channels:

  • 2nd-order lowpass filters, f3 = 17.6kHz
  • Gain: 1.6 (default, no jumper set) or 16 (jumper set)
  • DC offset at Bela analog in: 1.8V
  • Max input range: +/- 1.12V (jumper not set) or +/- 112mV (jumper set)

Audio output channels:

  • 2nd-order lowpass filters, f3 = 17.8kHz
  • Gain: 1.0
  • Max output range: +/- 2.3V (assuming analogWriteOnce() range 0 to 0.92)

The filters are implemented with OPA4348 opamps.

Comparison to Bela audio input and output

The Audio Expander Capelet uses the Bela cape's DC-coupled ADC and DAC. These parts are of a different type to the sigma-delta codec used for the main Bela audio I/O. See here for a discussion of the different types of converter and their performance for audio. Also, there are some nonlinear effects on the DAC related to limited slew rate and differing settling time for different DAC codes, which add a bit of nonlinear distortion to the DAC outputs. (These issues do not affect the ADC.)