Skip to content

RowdyVoyeur/m8c-rpi4

 
 

Repository files navigation

M8C for Raspberry Pi 4 Model B

Introduction

The Dirtywave M8 Tracker is a portable sequencer and synthesizer, featuring 8 tracks of assignable instruments such as FM, waveform synthesis, virtual analog, sample playback, and MIDI output. It is powered by a Teensy micro-controller and inspired by the Gameboy tracker Little Sound DJ.

While Dirtywave makes new batches of units available on a regular basis, M8 is sometimes sold out due to the worldwide chip shortage and high demand of the unit. To fill this gap and and to allow users to freely test this wonderful tracker, Timothy Lamb was kind enough to make the M8 Headless available to everyone.

Note that this project is for educational and testing purposes only. If you like the M8 and you gel with the tracker workflow, please support Dirtywave by purchasing the actual unit. You can check its availability here. Meanwhile, you can also subscribe to Timothy Lamb's Patreon.

This is a fork of laamaa's fantastic cross platform M8 tracker headless client or M8C for short and includes some modifications based on rasprague's fork. The modifications are the following: Add two special button combinations for resetting the display and quitting the program before shutting down the Raspberry Pi; Add the option to disable the mouse cursor.

M8C is a client for Dirtywave M8 headless mode. The original application should be cross-platform ready and can be built in Linux, Windows, Mac OS and Android. However, this specific fork has been tested only on Raspberry Pi 4 Model B.

The main objective of this fork is to run M8C on a Raspberry Pi 4 with the best performance possible. Which means a stable setup with a good resolution and acceptable refresh rate, low audio latency and no sound artifacts such as random clicks and pops. After testing different approaches, I've settled for Blokas Patchbox OS and SDL2.

Below, you'll find the instructions to install Patchbox OS, configure the system, install M8C and a Patchbox module to automatically launch M8C on boot. In the end, M8C should start automatically on boot, connect your audio and MIDI devices and shutdown after quitting M8C.

If you have a Dirtywave M8 or if you're using M8 Headless, feel free to visit this website I created with a bunch of shortcuts, tips and tricks for the M8. Additionally, if you have a Roland MC-101, which is part of this project, you may also visit my other website with tips and tricks for this groovebox.

Acknowledgments

This project would not exist without Timothy Lamb's phenomenal invention, the Dirtywave M8 Tracker. Thank you for developing this fantastic product and for allowing the community to test and play it with the M8 Headless!

The M8C is also an essential part of this puzzle. Thank you very much laamaa for putting this together and rasprague for your great modifications!

And, finally, thank you to all the people at M8 Discord server for your support.

Disclaimer

While this project may give you access to some sort of a handheld M8 with relatively low audio latency and reasonable stability, this should be regarded as a temporary device for testing or learning purposes only.

From my experience, you may end up with audio latency (even if minor) and eventual random crashes (either from overheating or from Alsa instability). The user experience will feel crippled when compared with what you would get with the actual M8 and there is no customer support for this project.

The Teensy 4.1, while very robust, may get damaged when handled by inexperienced people (like me) and you may need to spend money buying more than one. Furthermore, you may need to put a lot of time onto this project and those hours have a cost. Which means that this project could be more expensive than buying the actual M8 unless you already have everything you need and you know very well what you are doing.

Please note that this project is not affiliated with Dirtywave and there is no guarantee or support from either the manufacturer or myself. You can build it at your own risk.


Project

Problem

Putting together a Raspberry Pi 4 with a screen, a Teensy board, a USB sound card, a game controller and, eventually, some sort of Power Bank or battery will always end up being a hot mess of cables.

This could be partially solved with a case such as a PiBoy or something similar or by 3D printing a custom case. However, this is a temporary device and I want to use most (if not all) of the parts in different audio projects. Thus, I opted to create something fun and easy to build and take apart.

Solution

I started thinking about different solutions, but Lego immediately became the obvious choice. I would be lying if I said that no Lego parts were hurt in this project. Afterall, it's not easy to hold the boards without screws.

Pictures

Picture of headless M8 Tracker running in Raspberry Pi 4 Model B with 1 GB of RAM:

Another picture of the setup with headphones for scale:

And, lastly, a picture showing the different gear that can be connected:

Videos

Here's a quick demo video of this project (click on the image to watch the video):

Alt text

And here's a video showing the unit's innards and how the Lego buttons work (click on the image to watch the video):

Alt text


Requirements

  • A working Raspberry Pi 4 Model B. I'm using a discontinued 1GB model, so any RPi4 will do.

  • A Raspberry Pi Screen such as a Waveshare or equivalent. I'm using a cheap 3.5" LCD with HDMI.

  • A TeenTeensy 4.1 Board with the latest M8 Headless Firmware installed.

  • A USB Cable with 5-Pin Micro-B Plug to connect the Teensy to the Raspberry Pi. Must be a power and data cable, otherwise the Pi will not find the Teensy.

  • A USB audio interface. I got a really cheap USB sound card with a HS-100B chip. It's great because it handles 48K or 44.1KHz sampling rates and small buffer sizes. The only downside is the mono ADC, which means that I have stereo output, but only mono input.

  • A USB Game Controller. I'm using a Geeekpi set of controllers, but I wanted something really cheap so I could remorselessly take it apart.

  • A power adapter for the Raspberry Pi, a power bank or something similar if you want a portable device. I'm using something like this and a LiPo battery because my power bank wasn't cutting it.

  • Some additional USB cables, preferably with ferrite core to filter out undesirable noise.

  • An ethernet cable because we will disconnect Wi-Fi to save battery and, hopefully, improve performance.

  • Lastly, if you want to put together something similar to what I've done, then you'll need lots of Lego. Preferably Lego Technics to keep everything cool and well ventilated.


Installation

Install and Configure Patchbox OS

  1. Download and install balenaEtcher.

  2. Download and unzip Patchbox OS.

  3. Insert the SD card to your computer's SD card reader and launch balenaEtcher.

  4. Click Flash from File and select the file you want to upload (e.g. 2022-05-17-Patchbox.img).

  5. Click Select Target, choose your SD card and click Flash.

  6. After flashing, safely remove the SD card, insert it into your Raspberry Pi and power it on.

  7. Connect your computer to the same Network as Raspberry Pi, open a Terminal window and paste the following after boot is complete (default password: blokaslabs):

ssh-keygen -R patchbox.local
ssh patch@patchbox.local
  1. Follow the Setup Wizard instructions:
  • If prompted, start by updating Patchbox OS;

  • Then, for security reasons, change the default password;

  • Follow these instructions to configure the audio settings;

  • Choose the boot environment Console Autologin;

  • When prompted, disable Wi-Fi;

  • Select None: Default Patchbox OS Environment to disable modules.

  1. Once the setup if finished, open the config.txt file to edit the display settings, disable Bluetooth and WiFi and improve boot time:
sudo nano /boot/config.txt
  1. You may need to adjust the display settings to achieve a suitable resolution for M8C (more information here, here and here). In my case, I had to edit the following lines in under the HDMI settings:
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=2
hdmi_cvt=480p 60 6 0 0 0
  1. If you have black borders around your display or if you cannot see the whole display, you may need to adjust overscan. In my case, I need to add the following so the left side of the display doesn’t go under the screen cover/protection:
overscan_left=16
  1. Disable the on-board or internal (Broadcom) sound card, just add the following under # Enable audio (loads snd_bcm2835) (source):
dtparam=audio=off
  1. Disable HDMI audio, under # Enable DRM VC4 V3D driver (source):
dtoverlay=vc4-kms-v3d,noaudio
  1. Add the following under the first [all] (source). To enable these options back, just comment each line. Note that you’ll need an ethernet cable from here on:
dtoverlay=disable-bt
dtoverlay=disable-wifi
  1. Exit with ctrl + x, save and reboot the Raspberry Pi with sudo reboot.

  2. To improve boot time, go to raspi-config and disable Wait for Network on Boot, under System Options and Network at Boot:

sudo raspi-config
  1. Still in raspi-config, go to Localisation Options, then Locale, and select en_US.UTF-8 only using the spacebar. Exit raspi-config and reboot.

  2. Login again and finish setting the locale:

sudo update-locale LC_ALL="en_US.UTF-8"
sudo update-locale LANGUAGE="en_US"
sudo reboot
  1. Login again and check that your Raspberry Pi OS locale is properly set by typing the command locale and making sure it returns the following:
locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
  1. If you're not using Pisound, disable pisound-ctl, pisound-btn. If you're not using TouchOSC2MIDI, disable touchosc2midi. You can also opt-out of statistics program, which are not necessary. All of this can be done with the following commands. More information here.
sudo systemctl disable pisound-ctl
sudo systemctl disable pisound-btn
sudo systemctl disable touchosc2midi
sudo systemctl disable wifi-hotspot.service
sudo systemctl disable --now blokas-telemetry.target
  1. Check if PulseAudio is running by typing pactl list in terminal. If PulseAudio is not necessary for your project, you can save some resources by permanently disabling it:
systemctl --user stop pulseaudio.socket
systemctl --user stop pulseaudio.service
systemctl --user disable pulseaudio.socket
systemctl --user disable pulseaudio.service
systemctl --user mask pulseaudio.socket
systemctl --user mask pulseaudio.service

Prepare to Install M8C

  1. Login again, update, install required packages and install SLD2 (source):
sudo apt update && sudo apt install -y git gcc make libsdl2-2.0-0 libsdl2-dev
sudo reboot
  1. Install other package needed to compile and install M8C:
sudo apt install -y autotools-dev autoconf libtool
  1. Download the source code for libserialport:
cd
git clone https://github.com/sigrokproject/libserialport.git
  1. After cloning, compile and install:
cd libserialport
./autogen.sh
./configure
make
sudo make install
  1. A couple more steps:
sudo ln -s /usr/local/lib/libserialport.so.0.1.0 /usr/lib/libserialport.so.0.1.0
sudo ln -s /usr/local/lib/libserialport.so.0 /usr/lib/libserialport.so.0
  1. And finally, run to finalise the packages installation and to ensure the library is found when building M8C:
sudo ldconfig

Install and Configure M8C

  1. At this stage, you can reboot before installing M8C:
cd
git clone https://github.com/RowdyVoyeur/m8c-rpi4.git
  1. Followed by the commands below, once it’s cloned:
cd m8c-rpi4
make
sudo make install
  1. Lastly, make shell scripts executable by everyone:
sudo chmod a+x m8c*.sh
  1. To generate the config files in .local/share/m8c you need to run M8C once. Connect the Teensy 4.1 with the installed M8 Headless Firmware to the Raspberry Pi 4 using a USB data cable. Wait 10 seconds to ensure it is properly connected and run the following commands (use Ctrl+C or close the Terminal window to quit M8C):
cd m8c-rpi4
./m8c.sh
  1. Type the following to find if config.ini has been successfully generated (if config.ini isn't listed in this folder, repeat the step above):
cd .local/share/m8c
ls
  1. Edit the config.ini file, so the [graphics] and [gamepad] sections look like this. Don't forget to change fullscreen and disable_cursor to true.
sudo nano config.ini
  1. Then, type the following to point the M8C to the gamecontrollerdb.txt, so it finds the game controller mapping:
cd ~/.local/share/m8c
ln -s ~/m8c-rpi4/gamecontrollerdb.txt .

Game Controller Configuration

  1. On startup, M8C tries to load a SDL game controller database named gamecontrollerdb.txt from the same directory as the config file. Therefore, you need to check whether gamecontrollerdb.txt is inside .local/share/m8c/.

  2. Assuming the gamecontrollerdb.txt is in the right place, then you need to ensure that your specific game controller mapping is listed in this file. Just go to ~/m8c-rpi4, edit gamecontrollerdb.txt and do one of the following:

  • Copy the full updated database from here and paste it onto gamecontrollerdb.txt. If your game controller is listed, then M8C should automagically recognize it;

  • If this does not work, then download SDL2 Gamepad Tool and follow the instructions to get your game controller mapping. Once you have the mapping, paste it under the #Custom line of gamecontrollerdb.txt.

  1. You may also need to edit the [gamepad] section of the config.ini file found in .local/share/m8c to match the configuration of your game controller. You can find more information about the required values here. If you are using the same game controller as me, then the [gamepad] section should remain like this.

Audio Configuration

  1. You may need to customise this script to your needs, as described here. If you have audio related problems, you may need to reconfigure the audio settings in Patchbox OS Setup Wizard, as listed here.

  2. Adjust the audio levels by opening Terminal and typing alsamixer. Then, use the arrows to adjust the output and input levels of your audio card. Exit alsamixer using Escape and save your adjustments by typing sudo alsactl store. Find more information here.


MIDI Configuration

  1. amidiauto is a background process of Patchbox OS, which takes care of setting up the MIDI routings automatically. Since we will use this Patchbox module, all MIDI configurations should be done here.

  2. In this file you can see that MC-101 and M8 can both send and receive MIDI from each other, nanoKONTROL can send MIDI to M8 and other hardware and software is not allowed to automatically connect ports. This setup works exclusively with this Patchbox module. So, if you switch modules, these settings won't have any effect.

  3. You can configure the amidiauto.conf to suit your own needs. If you're using the Patchbox module, then you should edit this file by following these instructions.

  4. Alternatively, you can make these settings permanent for your system by editing the Patchbox OS amidiauto.conf. To create a amidiauto.conf that makes the MIDI settings permanent to your system (instead of using the Patchbox module), you should follow the steps below:

  • Visit this page to understand how things work.

  • List all the connected MIDI devices to find their names with the following command:

aconnect -l
  • Create your own version of this file or edit the Patchbox OS amidiauto.conf with the following command:
sudo nano /etc/amidiauto.conf

Optional: You can install these MIDI tools to control parameters of M8C and Patchbox OS with an external MIDI device, including switching audio routings on the fly, adjusting some Alsamixer volume levels and several other things.


Install Patchbox Module

  1. To automatically start M8C on system boot without configuring systemd or crontab, you need to install the m8c-rpi4-module with the following command:
patchbox module install https://github.com/RowdyVoyeur/m8c-rpi4-module

45. Activate the module by running the command below or, alternatively, type patchbox in Terminal, go to modules menu and select m8c-rpi4-module:

patchbox module activate m8c-rpi4-module
  1. The module should start between 5 and 10 seconds after activation. If it does not start, confirm that M8C is installed at home/patch/m8c-rpi4 and the script is executable by everyone.

Final Checks

  1. The M8C script, together with the m8c-rpi4-module should now be able to autostart the M8C on system boot, display the M8 graphics on the screen, connect the audio ports so you can hear what you're playing and sample any instruments, connect the MIDI devices with amidiauto and shutdown the Raspberry Pi upon quitting the M8C with the button combination.

  2. You should be able to use the following button combinations:

  • Quit M8C and automatically shutdown Raspberry Pi: [SELECT] + [OPTION] + [DOWN]

  • Reset display in case of graphic glitches: [SELECT] + [OPTION] + [UP]

  1. If the M8C starts on boot, you can see and hear the M8 audio and record onto it, sync your connected MIDI devices and shutdown with the button combination, then you're good to go.

  2. Well done! Grab a cup of coffee, read the M8 User Manual and start saving for the actual thing ;)

Languages

  • C 98.0%
  • Other 2.0%