ref: 20eb9fd95233af43dfc4a683bc1afbb3dde879fb
parent: 8a2d297dc0fbd0233e35eb994c6f5f4e686107e6
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Mon Apr 19 11:18:18 EDT 2021
add instructions for usb audio routing
--- /dev/null
+++ b/AUDIOGUIDE.md
@@ -1,0 +1,116 @@
+# Audio setup for M8 headless and Raspberry Pi
+
+It is possible to route the M8 USB audio to another audio interface in Linux without a DAW, using JACK Audio Connection kit and a few other command line tools.
+
+Please note that this is not an optimal solution for getting audio from the headless M8, but as far as I know the easiest way to use the USB audio feature on Linux. The best parameters for running the applications can vary a lot depending on your configuration, and however you do it, there will be some latency.
+
+It is possible to use the integrated audio of the Pi for this, but it has quite a poor quality and likely will have sound popping issues while running this.
+
+These instructions were written for Raspberry PI OS desktop using a Raspberry Pi 3 B+, but should work for other Debian/Ubuntu flavors as well.
+
+Open Terminal and run the commands below to setup the system.
+
+## First time setup
+
+### Install JACK Audio Connection Kit
+
+The jackd2 package will provide the basic tools that make the audio patching possible.
+
+```
+sudo apt install jackd2
+```
+
+### Add your user to the audio group
+
+This is required to get real time priority for the JACK process.
+
+```
+sudo usermod -a -G audio $USER
+```
+
+You need to log out completely or reboot for this change to take effect.
+
+### Find your audio interface ALSA device id
+
+Use the ```aplay -l``` command to list the audio devices present in the system.
+
+```
+pi@raspberrypi:~ $ aplay -l
+**** List of PLAYBACK Hardware Devices ****
+card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
+ Subdevices: 8/8
+ Subdevice #0: subdevice #0
+ Subdevice #1: subdevice #1
+ Subdevice #2: subdevice #2
+ Subdevice #3: subdevice #3
+ Subdevice #4: subdevice #4
+ Subdevice #5: subdevice #5
+ Subdevice #6: subdevice #6
+ Subdevice #7: subdevice #7
+card 1: M8 [M8], device 0: USB Audio [USB Audio]
+ Subdevices: 1/1
+ Subdevice #0: subdevice #0
+card 2: vc4hdmi [vc4-hdmi], device 0: MAI PCM vc4-hdmi-hifi-0 [MAI PCM vc4-hdmi-hifi-0]
+ Subdevices: 1/1
+ Subdevice #0: subdevice #0
+card 3: v10 [AudioQuest DragonFly Red v1.0], device 0: USB Audio [USB Audio]
+ Subdevices: 1/1
+ Subdevice #0: subdevice #0
+
+```
+
+Take note of the card number you wish to use. In my case, I want to use card 3: v10.
+
+After these steps have been taken care of, we can try to route some audio.
+
+## Stop pulseaudio backend
+
+## Start JACK server and route audio
+```
+jackd -d alsa -d hw:M8 -r44100 -p512 &
+```
+
+This will start the JACK server using ALSA backend driver (-d alsa), open the M8 USB audio interface (-d hw:M8) with the sample rate of 44100hz (-r44100) and buffer period size of 512 frames (-p512). The program will run in background (the & character in the end specifies this).
+If you don't see your terminal prompt, just press enter and it should appear.
+
+Next, we will create a virtual port for routing audio to another interface. We need to specify the audio interface id where we want to output audio here.
+
+```alsa_out -j m8out -d hw:<AUDIO INTERFACE NUMBER> -r 44100 &```
+
+example:
+
+```alsa_out -j m8out -d hw:3 -r 44100 &```
+
+This creates a JACK client called "m8out" (-j m8out) that performs output to ALSA audio hardware interface number 3 (-d hw:3) with a samplerate of 44100 (-r 44100). The ampersand at the end runs the program in the background.
+
+If you wish to use the Pi integrated sound board, check the number of the "bcm2835 Headphones" device. Usually it is 0.
+
+After the virtual port has been created, we need to connect it to the M8 USB Audio capture device.
+
+```
+jack_connect system:capture_1 m8out:playback_1
+jack_connect system:capture_2 m8out:playback_2
+```
+
+This will connect the audio ports. You should be able to hear sounds from the M8 now.
+
+If you wish to shut down the applications, you can do that by sending a interrupt signal to the processes.
+
+```killall -s SIGINT jackd alsa_out```
+
+
+## TL;DR
+Run these in Terminal:
+
+```
+sudo apt install jackd2
+sudo usermod -a -G audio $USER
+sudo reboot
+
+```
+```
+jackd -d alsa -d hw:M8 -r44100 -p512 &
+alsa_out -j m8out -d hw:0 -r 44100 &
+jack_connect system:capture_1 m8out:playback_1
+jack_connect system:capture_2 m8out:playback_2
+```
\ No newline at end of file
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
m8c is a Linux client for Dirtywave M8 tracker's headless mode. It is intended for use with lower end systems like RPi zero.
-Please note that routing the headless M8 USB audio isn't in the scope of this program -- if this is needed, it can be achieved with tools like jackd, alsa\_in and alsa\_out for example.
+Please note that routing the headless M8 USB audio isn't in the scope of this program -- if this is needed, it can be achieved with tools like jackd, alsa\_in and alsa\_out for example. Check out the guide in file AUDIOGUIDE.md for some instructions on routing the audio.
Many thanks to turbolent for the great Golang-based g0m8 application, which I used as reference on how the M8 serial protocol works.
@@ -18,13 +18,12 @@
### Install required packages
->
```
sudo apt update && sudo apt install -y git gcc make libsdl2-dev libsdl2-ttf-dev
```
### Download source code
->
+
```
mkdir code && cd code
git clone https://github.com/laamaa/m8c.git
@@ -31,7 +30,7 @@
```
### Build the program
->
+
```
cd m8c
make && sudo make install
@@ -40,7 +39,7 @@
### Find out the correct device name
Connect the Teensy to your computer and look up the device name:
->
+
```
sudo dmesg | grep ttyACM
```
--
⑨