Learn Configuring Audio on the Raspberry Pi

Getting Started

Welcome to RNBO

Quickstart

RNBO Basics

Key Differences

Why We Made RNBO

Coding Resources

Fundamentals

Audio IO

Messages to rnbo~

Using Parameters

MIDI in RNBO

Messages and Ports

Polyphony and Voice Control

Audio Files in RNBO

Using Buffers

Using the FFT

Export Targets

Export Targets Overview

VST/AudioUnit
Max External Target
Raspberry Pi Target
The Web Export Target
The C++ Source Code Target

Code Export

Working with JavaScript
Working with C++

Special Topics

Sample Accurate Patching
Scala and Custom Tuning

RNBO and Max for Live

RNBO Raspberry Pi OSCQuery Runner

Metadata

Export Description

Raspberry Pi GPIO

Updating the RNBO Package

Configuring Audio on the Raspberry Pi

Steps to configure your audio device settings on the Raspberry Pi target for use with RNBO.

On the Raspberry Pi, the RNBO Runner uses JACK Audio Connection Kit to manage connections to all audio devices available to the Pi. The RNBO Runner exposes an OSC-based interface to JACK, which you can use to select your active soundcard, choose a sample rate, and restart JACK. You can use this OSC interface directly, or you can configure audio on your Pi by using the configuration options in the Pi export sidebar.

Audio Configuration Options

The easiest way to access the audio configuration is through the export sidebar. Open the export sidebar and navigate to the configuration page for your Raspberry Pi. You should see audio-related options under "Configuration".

rpi-configuration-options-final.png

Choosing an Audio Device

The Audio: Interface option can be used to choose your audio output device.

rpi-configure-devices.png

You may be wondering about the "Dummy" soundcard. The RNBO Rasperry Pi image defines the "Dummy" device for use with RNBO devices that do not produce audio. For example, if you had a RNBO device that synthesized MIDI events but which did not produce any sound, you could use that device with the "Dummy" sound card. If the "Dummy" sound card is the only one listed, then you may not have an audio device connected. Reconnect your device, then open the export menu again.

Changing the Sample Rate

The Audio: Sample Rate option lets you choose the sample rate of the active device on your Raspberry Pi. The menu should contain the options 22050, 44100, and 48000. If you would like to use a sampling rate that is not included in this menu, you'll have to use the OSC interface to set the sampling rate. See below for an example of how to do this. Consult the documentation for your hardware to find out which sample rates are supported.

Period Frames and Latency

The Audio: Period Frames option determines the block size of an audio callback. A frame is a single sample from each channel, so a block size of 256 frames has 256 samples of audio for each channel. Audio is processed on the device in blocks, so a larger frame size means more latency, but more efficient audio processing. The lowest size most devices can handle is 64. If you're hearing pops or audio dropouts, you can try increasing the block size with this option.

The Audio: Period Latency option sets the number of periods per playback callback. Similar to Period Frames, lower values mean less latency but require more intense computation. Values of 2 or 3 are typical. For more information on these configuration options see JACK Configuration.

Changes to Audio Configuration after Export

After export, you can still change audio configuration settings like sample rate, period frames, period rate, and audio interface. The easiest way to access these settings is from a browser using the Web Interface. Once you have the interface open, look under Settings -> Audio for configuration options. It's also possible to configure audio settings directly using OSC messages. The built-in RPi Configure Audio patch demonstrates this functionality, as does the Raspberry Pi OSCQuery example.

Using the OSC Interface

If you have advanced needs, for example you want to configure JACK programmatically, you can send OSC messages to your Raspberry Pi to change your JACK settings. You can also send an HTTP GET request to /rnbo/jack to get the current state of audio on your Raspberry Pi in JSON format.

const http = require("http");

const host = "c74rpi.local"; // replace with the hostname of your Raspberry Pi, or its IP address
const port = 5678; // HTTP interface is exposed on this port
const path = "/rnbo/jack";

const fetchJackStatus = async (host, port, path) => {
    const options = {
        protocol: "http:",
        host,
        port,
        path,
        family: 4
    };
    
    return new Promise((resolve, reject) => {
        http.get(options, function (res) {
            var json = '';
            res.on('data', function (chunk) {
                json += chunk;
            });
            res.on('end', function () {
                if (res.statusCode === 200) {
                    try {
                        resolve(json);
                    } catch (e) {
                        reject(e);
                    }
                } else {
                    reject('Status: ' + res.statusCode);
                }
            });
        }).on('error', reject);
    });
}

fetchJackStatus(host, port, path).then((res) => console.log(res));

This might return a result that looks something like this:

{
  "FULL_PATH": "/rnbo/jack",
  "CONTENTS": {
    "info": {
      "FULL_PATH": "/rnbo/jack/info",
      "CONTENTS": {
        "alsa_cards": {
          "FULL_PATH": "/rnbo/jack/info/alsa_cards",
          "CONTENTS": {
            "hw:0": {
              "FULL_PATH": "/rnbo/jack/info/alsa_cards/hw:0",
              "TYPE": "s",
              "VALUE": "Dummy - Dummy\nDummy 1",
              "ACCESS": 1,
              "CLIPMODE": "none"
            },
            "hw:1": {
              "FULL_PATH": "/rnbo/jack/info/alsa_cards/hw:1",
              "TYPE": "s",
              "VALUE": "bcm2835_headphonbcm2835 Headphones - bcm2835 Headphones\nbcm2835 Headphones",
              "ACCESS": 1,
              "CLIPMODE": "none"
            },
            "hw:2": {
              "FULL_PATH": "/rnbo/jack/info/alsa_cards/hw:2",
              "TYPE": "s",
              "VALUE": "USB-Audio - USB AUDIO  CODEC\nBurrBrown from Texas Instruments USB AUDIO  CODEC at usb-3f980000.usb-1.2, full",
              "ACCESS": 1,
              "CLIPMODE": "none"
            },
            "hw:CODEC": {
              "FULL_PATH": "/rnbo/jack/info/alsa_cards/hw:CODEC",
              "TYPE": "s",
              "VALUE": "USB-Audio - USB AUDIO  CODEC\nBurrBrown from Texas Instruments USB AUDIO  CODEC at usb-3f980000.usb-1.2, full",
              "ACCESS": 1,
              "CLIPMODE": "none"
            },
            "hw:Dummy": {
              "FULL_PATH": "/rnbo/jack/info/alsa_cards/hw:Dummy",
              "TYPE": "s",
              "VALUE": "Dummy - Dummy\nDummy 1",
              "ACCESS": 1,
              "CLIPMODE": "none"
            },
            "hw:Headphones": {
              "FULL_PATH": "/rnbo/jack/info/alsa_cards/hw:Headphones",
              "TYPE": "s",
              "VALUE": "bcm2835_headphonbcm2835 Headphones - bcm2835 Headphones\nbcm2835 Headphones",
              "ACCESS": 1,
              "CLIPMODE": "none"
            }
          }
        }
      }
    },
    "config": {
      "FULL_PATH": "/rnbo/jack/config",
      "DESCRIPTION": "Jack configuration parameters",
      "CONTENTS": {
        "card": {
          "FULL_PATH": "/rnbo/jack/config/card",
          "TYPE": "s",
          "VALUE": "hw:2",
          "RANGE": [
            {
              "VALS": [
                "hw:0",
                "hw:1",
                "hw:2",
                "hw:CODEC",
                "hw:Dummy",
                "hw:Headphones"
              ]
            }
          ],
          "ACCESS": 3,
          "CLIPMODE": "both",
          "DESCRIPTION": "ALSA device name"
        },
        "num_periods": {
          "FULL_PATH": "/rnbo/jack/config/num_periods",
          "TYPE": "i",
          "VALUE": 2,
          "RANGE": [
            {
              "VALS": [
                1,
                2,
                3,
                4
              ]
            }
          ],
          "ACCESS": 3,
          "CLIPMODE": "both",
          "DESCRIPTION": "Number of periods of playback latency"
        },
        "period_frames": {
          "FULL_PATH": "/rnbo/jack/config/period_frames",
          "TYPE": "i",
          "VALUE": 256,
          "RANGE": [
            {
              "VALS": [
                32,
                64,
                128,
                256,
                512,
                1024
              ]
            }
          ],
          "ACCESS": 3,
          "CLIPMODE": "both",
          "DESCRIPTION": "Frames per period"
        },
        "sample_rate": {
          "FULL_PATH": "/rnbo/jack/config/sample_rate",
          "TYPE": "f",
          "VALUE": 48000,
          "RANGE": [
            {
              "MIN": 22050
            }
          ],
          "ACCESS": 3,
          "CLIPMODE": "both",
          "DESCRIPTION": "Sample rate"
        }
      }
    },
    "active": {
      "FULL_PATH": "/rnbo/jack/active",
      "TYPE": "F",
      "VALUE": null,
      "ACCESS": 3,
      "CLIPMODE": "none"
    }
  }
}

Given this configuration, if you wanted JACK to use hw:0, the "Dummy" soundcard, you could send it an OSC message like the following (this uses the sendosc command line tool):

sendosc c74rpi.local 1234 /rnbo/jack/config/card s hw:0

Similarly, you could set the sample rate with a message like this:

sendosc c74rpi.local 1234 /rnbo/jack/config/sample_rate i 96000