Sndio

From Void Linux Wiki
Jump to: navigation, search

Medic template.svgThis article or section needs expansion.

Reason: An explanation of how to use sndio for network sound and controlling MIDI devices is needed. (Discuss)

sndio is a small audio and MIDI framework part of the OpenBSD project. It provides an optional sound server (sndiod) and a documented application programming interface to access either the server or the audio and MIDI hardware in a uniform way.

It is an alternative to the well known PulseAudio and jack sound servers.

Some prominent features of sndio include:

  • Performs re-sampling and format conversions.
  • Allows concurrent access to an audio device.
  • Split an audio device into sub-devices.
  • Allows one program to record what other programs play.
  • Control the volume of individual programs.
  • Route audio and MIDI data through a network and between programs.

Installation

# xbps-install -S sndio

To start the sound server sndiod:

# ln -s /etc/sv/sndiod /var/service

It is recommended to have all ALSA outputs at 0dB and control the volume through sndiod instead.

Controlling volume

sndiod controls application volume using MIDI messages, to do this without a MIDI device, aucatctl can be used.

aucatctl sends MIDI volume controller messages to adjust the volume of audio programs using the sndiod server for output.

Installation

# xbps-install -S aucatctl

Example

List available volume controls and their values:

$ aucatctl

Set master volume to maximum:

$ aucatctl master=127

Mute mpv and set sox to 100:

$ aucatctl mpv0=0 sox0=100

Extra utilities

sndio also provides two extra utilities, aucat and midicat.

aucat

The aucat utility can play, record, mix, and process audio files on the fly. Similar to that of aplay and arecord from ALSA. See aucat(1) for usage.

midicat

The midicat utility receives MIDI data from a given input MIDI port and/or sends it to a given output MIDI port. See midicat(1) for usage.

Using Firefox with Sndio[1]

By default Firefox will try to output to ALSA instead of sndio. To configure Firefox to use sndio navigate to about:config and set media.cubeb.backend to sndio. If it does not exist right click and do New -> String then enter media.cubeb.backend as the preference name and sndio as the value. After restarting, Firefox will now output to sndio.

Currently three additional preferences need to be set to allow Firefox to properly work with sndio. security.sandbox.content.read_path_whitelist and security.sandbox.content.write_path_whitelist both need to be set to /home/<username>/.sndio/cookie or /home/<username>/.aucat_cookie for sndio versions prior to 1.5.0. And media.cubeb.sandbox must be set to false since Firefox 60.

sndio via ALSA

Some programs are not designed to output sound directly to sndio but it's possible to use an ALSA plugin to fix this. This will allow programs without an sndio backend to output their audio through sndio.

Install alsa-sndio and edit /$HOME/.asoundrc with these contents:

pcm.!default {
	type sndio
}

See alsa-sndio for more information about the configuration options.

Old Method[2]

Warning: This has not been thoroughly tested, it is possible you may encounter sound issues, quality loss, sync issues, etc. You have been warned!

To get programs that only support outputting to ALSA to use sndio, create /$HOME/.asoundrc with these contents:

pcm.sndio {
    type asym
    playback.pcm "sndio-play"
    hint {
        show on description "OpenBSD sndio"
    }
}

pcm.sndio-play {
    type plug
    slave {
        pcm "sndio-raw"
        rate 48000
        format s16_le
        channels 2
    }
}

pcm.sndio-raw {
    type file
    slave.pcm null
    format raw
    file "| aucat -f snd/0 -i -"
}

pcm.default sndio

This will create a signed 16 bit stereo ALSA output at 48000Hz.

Known issues

Some programs play sound at maximum volume

Either the program is not configured to use sndio as its output or it does not support sndio. The program will play at maximum volume as it will connect to the master ALSA output, which should be configured to 0dB.

To prevent programs from playing at maximum volume when they don't natively support sndio, follow the instructions at Sndio#sndio_via_ALSA.

References

External links