no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | wiki:raspberrypi [2017/05/18 22:59] – [Running JACK] - more specifics to help newbies colinsullivan | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Raspberry Pi and realtime, low-latency audio ====== | ||
+ | The Raspberry Pi can be set up to handle realtime, low-latency audio but it requires quite some tweaking. Hence this Wiki article in which some common bottlenecks as well as some possible optimizations will be described. Last but not least this article will explain how to get JACK aka jackd running on your RPi. | ||
+ | |||
+ | ===== Powering the RPi ===== | ||
+ | |||
+ | If you use the micro-USB power input to power the RPi you might encounter sudden reboots when plugging in or unplugging USB devices. If you want to be sure your RPi doesn' | ||
+ | |||
+ | ===== Overclocking ===== | ||
+ | |||
+ | With the '' | ||
+ | |||
+ | More info on overclocking: | ||
+ | |||
+ | ==== CPU frequency scaling ==== | ||
+ | |||
+ | From the aforementioned link: | ||
+ | >//" | ||
+ | |||
+ | So when overclocking your RPi for audio usage you should set the governor to '' | ||
+ | echo -n performance \ | ||
+ | | sudo tee / | ||
+ | | ||
+ | RPi2: | ||
+ | for cpu in / | ||
+ | | sudo tee $cpu/ | ||
+ | |||
+ | Another option is to disable CPU frequency scaling by disabling it in the kernel. You can do this when modifying the kernel config (with for example '' | ||
+ | |||
+ | ===== Disabling unneeded services ===== | ||
+ | |||
+ | By default the RPi runs quite some services that are not really needed or even get in the way when setting up a real-time, low-latency environment. One way to disable such services from running and chewing up precious CPU cycles is to write a little script, an example can be found here: https:// | ||
+ | |||
+ | Breaking down the script: | ||
+ | |||
+ | ''# | ||
+ | \\ | ||
+ | ## Stop the ntp service\\ | ||
+ | sudo service ntp stop\\ | ||
+ | \\ | ||
+ | ## Stop the triggerhappy service\\ | ||
+ | sudo service triggerhappy stop\\ | ||
+ | \\ | ||
+ | ## Stop the dbus service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi\\ | ||
+ | sudo service dbus stop\\ | ||
+ | \\ | ||
+ | ## Stop the console-kit-daemon service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi\\ | ||
+ | sudo killall console-kit-daemon\\ | ||
+ | \\ | ||
+ | ## Stop the polkitd service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi\\ | ||
+ | sudo killall polkitd\\ | ||
+ | \\ | ||
+ | ## Only needed when Jack2 is compiled with D-Bus support (Jack2 in the AutoStatic RPi audio repo is compiled without D-Bus support)\\ | ||
+ | #export DBUS_SESSION_BUS_ADDRESS=unix: | ||
+ | \\ | ||
+ | ## Remount /dev/shm to prevent memory allocation errors\\ | ||
+ | sudo mount -o remount, | ||
+ | \\ | ||
+ | ## Kill the usespace gnome virtual filesystem daemon. | ||
+ | killall gvfsd\\ | ||
+ | \\ | ||
+ | ## Kill the userspace D-Bus daemon. | ||
+ | killall dbus-daemon\\ | ||
+ | \\ | ||
+ | ## Kill the userspace dbus-launch daemon. | ||
+ | killall dbus-launch\\ | ||
+ | \\ | ||
+ | ## Uncomment if you'd like to disable the network adapter completely\\ | ||
+ | #echo -n " | ||
+ | ## In case the above line doesn' | ||
+ | #echo -n " | ||
+ | \\ | ||
+ | ## Set the CPU scaling governor to performance\\ | ||
+ | echo -n performance | sudo tee / | ||
+ | \\ | ||
+ | ## And finally start JACK\\ | ||
+ | jackd -P70 -p16 -t2000 -d alsa -dhw:UA25 -p 128 -n 3 -r 44100 -s &\\ | ||
+ | \\ | ||
+ | exit | ||
+ | '' | ||
+ | |||
+ | Also, as long as you don't need networking, adding these also frees up some resources: | ||
+ | |||
+ | '' | ||
+ | sudo service ifplugd stop\\ | ||
+ | sudo killall ifplugd\\ | ||
+ | sudo service networking stop\\ | ||
+ | '' | ||
+ | ===== Running a headless RPi ===== | ||
+ | |||
+ | You can get a significant performance gain by not using a desktop environment on the RPi. That's nice and all but how do I control the RPi then and what if the software I'd like to use has a GUI? Enter X-forwarding over SSH. X-forwarding over SSH allows you to run software from the RPi within the desktop environment of the machine you're SSH' | ||
+ | ssh -X pi@ip.address.of.rpi | ||
+ | | ||
+ | This will give you shell access to the RPi. Now you can start GUI software by invoking them from the command line, like '' | ||
+ | |||
+ | Using this method also works around the issue of non-working mice and keyboards when using the '' | ||
+ | ===== On-board audio ===== | ||
+ | |||
+ | The on-board chipset of the RPi has quite some limitations unfortunately. It only does playback and because of it's design it is not really suited for real-time, low-latency audio processing. It does work with JACK now that it has MMAP support but don't expect it to run without glitches at lower latencies. | ||
+ | |||
+ | Other drawbacks of the analog audio output: | ||
+ | * it can produce clicks and pops due to the design of the RPi | ||
+ | * apparently the on-board audio is 11 bits only | ||
+ | |||
+ | More info:\\ | ||
+ | http:// | ||
+ | http:// | ||
+ | |||
+ | ===== GPIO (On-board) audio ===== | ||
+ | |||
+ | Various sound card hats and addons are available for high quality audio. These sound cards use the GPIO I2S (and I2C) pins on the GPIO header. Some sound cards have inputs as well as outputs. Sound cards range from 2 channels (in/out) to 8 channels out and 6 channels in. | ||
+ | |||
+ | A short list of GPIO sound cards can be found on eLinux :\\ | ||
+ | http:// | ||
+ | ===== On-board MIDI ===== | ||
+ | |||
+ | The on board PL011 based UART may be used as a MIDI interface. A kernel module (snd-serial-pl011) may be found here: | ||
+ | https:// | ||
+ | |||
+ | Usage is similar to the snd-serial-u16550 module found in the mainline kernel, please refer to the documentation for that module. Also within the repository is a patch for jack2 for MIDI only usage with the ALSA driver. | ||
+ | ===== USB audio ===== | ||
+ | |||
+ | To work around having only audio out an external USB audio interface can be an option as a lot of USB audio interfaces have both audio inputs and outputs that can be used simultaneously. You can also use JACK directly with an USB audio interface. To get a working set-up you will first need to work around some of the limitations of the USB implementation of the RPi. | ||
+ | |||
+ | ==== Supported USB devices ==== | ||
+ | |||
+ | === USB1.1 === | ||
+ | |||
+ | Any class compliant USB1.1 audio interface will work with the RPi. You can determine if a device is class compliant if the specifications of the interface state that no drivers are needed when using Mac or Windows. If unsure several listings of supported interfaces are available: | ||
+ | * http:// | ||
+ | * http:// | ||
+ | * http:// | ||
+ | |||
+ | === USB2 === | ||
+ | |||
+ | There are USB2.0 interfaces that are supported by the Linux audio driver stack (ALSA). Those interfaces should also work with the RPi. An example is the M-Audio Fast Track Ultra 8R, it has been reported that this interface works with the RPi. If your USB2 interface doesn' | ||
+ | http:// | ||
+ | Hopefully the fiq_split patch will make it into the main kernels available for the RPi in due time. | ||
+ | ==== Force USB1.1 mode ==== | ||
+ | |||
+ | The RPi has a USB2.0 controller that apparently can cause issues with USB1.1 audio interfaces. The solution is to force the controller to use USB1.1 mode. You can do this by adding the following kernel parameter to your ''/ | ||
+ | dwc_otg.speed=1 | ||
+ | |||
+ | ==== Ethernet controller ==== | ||
+ | |||
+ | While you're at it you might also want to disable the turbo mode for the ethernet controller of the RPi by adding: | ||
+ | smsc95xx.turbo_mode=N | ||
+ | |||
+ | >//" | ||
+ | |||
+ | You could also disable the ethernet connection altogether to make sure you can use the full bandwidth of the USB controller: | ||
+ | echo -n " | ||
+ | |||
+ | ==== USB1.1 and more than two inputs ==== | ||
+ | |||
+ | If your USB1.1 interface has more than two inputs and fails to work properly with JACK try forcing using only two inputs with the '' | ||
+ | |||
+ | ===== Setting the default soundcard ===== | ||
+ | |||
+ | The order in which soundcards are indexed is determinded by the content of ''/ | ||
+ | options snd-usb-audio index=-2 | ||
+ | |||
+ | And either comment it: | ||
+ | #options snd-usb-audio index=-2 | ||
+ | |||
+ | Or assign an index of 0: | ||
+ | options snd-usb-audio index=0 | ||
+ | |||
+ | Another option is to comment or remove the kernel module for the onboard soundcard (snd-bcm2835) from ''/ | ||
+ | |||
+ | ===== Audio software repository ===== | ||
+ | |||
+ | There' | ||
+ | |||
+ | ==== Adding the repository ==== | ||
+ | |||
+ | wget -O - http:// | ||
+ | sudo wget -O / | ||
+ | sudo apt-get update | ||
+ | |||
+ | ===== Using JACK ===== | ||
+ | |||
+ | JACK (JACK Audio Connection Kit), often referred to as jackd, is a | ||
+ | >//" | ||
+ | \\ | ||
+ | JACK was designed from the ground up for professional audio work, and its design focuses on two key areas: synchronous execution of all clients, and low latency operation."// | ||
+ | |||
+ | ==== Patching JACK ==== | ||
+ | |||
+ | You will need a patched JACK1 for the RPi otherwise you will encounter the infamous "Bus error" when starting JACK. This is because JACK uses packed structs and the RPi doesn' | ||
+ | |||
+ | There' | ||
+ | |||
+ | Patches for both JACK1 and JACK2 can be found here: https:// | ||
+ | The patches apply cleanly to Jack1 0.121.3 git commit 75e3e20b and Jack2 1.9.8 git commit 007cdc37 but since the patches are relatively simple they can be easily adapted for other JACK versions. | ||
+ | |||
+ | ==== Packages ==== | ||
+ | |||
+ | There are also packages available that contain patched versions of Jack1 and Jack2. You can find them in the aforementioned [[wiki: | ||
+ | |||
+ | After having added the repository you can install either Jack1 or Jack2 with '' | ||
+ | |||
+ | === Jack1 === | ||
+ | |||
+ | sudo apt-get --no-install-recommends install jackd1 | ||
+ | |||
+ | === Jack2 === | ||
+ | |||
+ | sudo apt-get --no-install-recommends install jackd2 | ||
+ | |||
+ | ==== Running JACK ==== | ||
+ | |||
+ | If you've set '' | ||
+ | sudo mount -o remount, | ||
+ | |||
+ | So JACK will not complain that it cannot allocate memory. Also set the CPU governor to performance so the CPU frequency does not scale: | ||
+ | echo -n performance \ | ||
+ | | sudo tee / | ||
+ | |||
+ | When using Jack2 you might want to disable dbus dependent code in JACK components if you want to run Jack2 on a headless RPi (so without X). You can do this by building without the '' | ||
+ | export DBUS_SESSION_BUS_ADDRESS=unix: | ||
+ | |||
+ | And then add the following lines to ''/ | ||
+ | <policy user=" | ||
+ | <allow own=" | ||
+ | <allow own=" | ||
+ | </ | ||
+ | |||
+ | === Using an external USB audio interface === | ||
+ | |||
+ | Now you should be able to fire up jackd, the actual daemon of the JACK package. Capture or playback only should be no problem but full-duplex can be troublesome, | ||
+ | jackd -P70 -p16 -t2000 -dalsa -dhw:UA25 -p128 -n3 -r44100 -s & | ||
+ | |||
+ | Which translates to: run JACK with a realtime priority of 70 ('' | ||
+ | |||
+ | === Using the on-board audio === | ||
+ | |||
+ | Work has been done on [[http:// | ||
+ | |||
+ | ===== Real-time kernel ===== | ||
+ | |||
+ | It is possible to use a real-time kernel on the RPi. You will need to compile it yourself after having patched the [[https:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | {{tag> |