[Tutorial] Installing Munt (MT-32 emulation) on RPi 3
-
This is a tutorial on setting up Munt (Roland MT-32 and CM-32L synthesizer modules emulator) on RetroPie 4.2 on Raspberry Pi 3 (Model B). This article should be applicable to other hardware as well (with proper compiler flags). Tutorial is based on these two articles:
- https://www.vogons.org/viewtopic.php?f=29&t=46899
- http://www.marshalltradecorp.com/coDe/old-game-info/linux-roland-mt32-munt-and-dosbox.html
Munt is generally working on Raspberry Pi 3, but sometimes sound jams a bit.
Here are the installation steps:
- Install necessary packages (some other packages might be needed as well):
sudo apt-get install build-essential cmake portaudio19-dev qtmobility-dev libx11-dev libxt-dev libxpm-dev
- Download Munt 2.2.0:
wget https://github.com/munt/munt/archive/munt_2_2_0.tar.gz
- Extract Munt and prepare build dir:
tar -xzf munt_2_2_0.tar.gz
mkdir munt-build
cd munt-build
- Set compiler flags (this is specific for Raspberry Pi 3, compiler flags for other systems are listed at the end of this post):
export CCFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
- Build Munt:
cmake -DCMAKE_BUILD_TYPE=Release -Dmunt_WITH_MT32EMU_QT:BOOL=OFF ../munt-munt_2_2_0
make -j 4
- Install Munt:
sudo make install
- Build Munt ALSA MIDI driver:
cd ../munt-munt_2_2_0/mt32emu_alsadrv
make
- Install Munt ALSA MIDI driver:
sudo make install
- Verify that Install Munt ALSA MIDI driver is installed:
ls -la /usr/local/bin/mt32d
- Place MT-32/CM-32L ROM files (MT32_CONTROL.ROM and MT32_PCM.ROM for MT-32 emulation, or CM32L_CONTROL.ROM and CM32L_PCM.ROM for CM-32L emulation) in folder /usr/share/mt32-rom-data
- Configure Munt to start automatically - add line
/usr/local/bin/mt32d -i 12&
to file /etc/rc.local (above last line containingexit 0
). The parameter-i 12
is audio output buffer size, a bigger number might be needed if audio is shuttering (output buffer underruns occur), a smaller number might be used to decrease sound output latency/lag (important for CM-32L sound effects). - To decrease jamming of the sound these ondemand CPU governor tweaks can be added to /etc/rc.local (above or below mt32d command line):
echo -n 100 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
echo -n 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
- As alternative to previous step CPU governor can be set to performance - this will make Raspberry Pi more hot however might decrease jamming more:
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
- After configuring autostart and CPU governor reboot Raspberry Pi
- After reboot check that Munt has created MIDI output port by command
aconnect -o
(output should contain client 128: 'MT-32' [type=user]). - Configure DOSBox to output MIDI to Munt - in file /home/pi/.dosbox/dosbox-SVN.conf adjust the line
midiconfig=
to bemidiconfig=128:0
- Run a DOS game and test MT-32/CM-32L emulation.
Compiler flags for various boards/systems/hardware (taken/adapted from RetroPie-Setup). There are exactly two commands for each system (long command-lines get visually wrapped here).
- Raspberry Pi 4:
export CCFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
- Raspberry Pi 3:
export CCFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
- Alternative Raspberry Pi 3 compiler flags (probably less optimal, mentioned in initial versions of this article):
export CCFLAGS="-Ofast -mcpu=cortex-a53"
export CXXFLAGS="-Ofast -mcpu=cortex-a53"
- Raspberry Pi 2:
export CCFLAGS="-Ofast -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
- Alternative Raspberry Pi 2 compiler flags (probably less optimal) are described here.
- Raspberry Pi 1/Zero (not sure whether Munt will be usable on these boards):
export CCFLAGS="-Ofast -mfpu=vfp -march=armv6j -mfloat-abi=hard"
export CXXFLAGS="-Ofast -mfpu=vfp -march=armv6j -mfloat-abi=hard"
- ODROID-C2:
export CCFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -ftree-vectorize -funsafe-math-optimizations"
- ODROID-C1:
export CCFLAGS="-Ofast -mcpu=cortex-a5 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -mcpu=cortex-a5 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
- ODROID-XU:
export CCFLAGS="-Ofast -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations -DGL_GLEXT_PROTOTYPES"
export CXXFLAGS="-Ofast -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations -DGL_GLEXT_PROTOTYPES"
- Freescale i.MX6 Quad/DualLite:
export CCFLAGS="-Ofast -march=armv7-a -mfpu=neon -mtune=cortex-a9 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -march=armv7-a -mfpu=neon -mtune=cortex-a9 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
- x86/other/unknown:
export CCFLAGS="-Ofast -march=native -ftree-vectorize -funsafe-math-optimizations"
export CXXFLAGS="-Ofast -march=native -ftree-vectorize -funsafe-math-optimizations"
-
@david87 This is awesome. How's the performance on a stock Pi 3?
-
After much arguing with names, I've discovered the docs on the above web site link aren't quite correct for Linux. ROM names need to be uppercase:
MT32_CONTROL.ROM MT32_PCM.ROM CM32L_CONTROL.ROM CM32L_PCM.ROM
-
I read the title as tmnt there are no ninja turtles here ....:( I am off to bed
-
@sduensin Regarding performance of Munt on Raspberry Pi 3 - the sound sometimes jams a bit (timing between notes/sounds seems a bit off). The average CPU usage of Munt (shown by top) is around 40% (of a single core). I guess both Munt and Dosbox should be single threaded (or at least all the heavy processing should be done in a single thread), so Raspberry Pi 3 with its 4 core CPU should be able to run both apps in parallel (without affecting each other).
I assume that jamming of the sound might be caused by very short and time critical CPU usage spikes of Munt (some heavy processing done by Munt that doesn't happen all the time, but when it happens it must complete in a very short amount of time to prevent sound from being crippled).
Anyway with the described CPU governor tweaks Munt works IMHO quite well.And thanks for mentioning ROM file names - I have updated OP!
-
@david87 said in [Tutorial] Installing Munt (MT-32 emulation) on RPi 3:
Munt works IMHO quite well.
Heck yeah it does! Played a few titles in DOSBox on the Pi after getting it to work. Just amazing. This needs to be in the official RetroPie distro!
-
I have updated compiler flags (and added a list of flags that should work on other systems). With updated compiler flags sound seems to jam a bit less on Raspberry Pi 3.
-
Hey, David.
Just a quick update on compiler flags.
First, on ARM platforms, march and mtune are overridden by the flags set in -mcpu. Setting -mcpu=cortex-a53 will also select appropriate tune and arch flags.
Second, -Ofast also enables -ftree-vectorize (auto vectorizing) and -ffast-math (which contains -funsafe-math-optimizations).
Last, -mfpu and -mfloat are not supported options for GCC targeting ARMv8 (64 bit), so please be conscious of what ABI is being utilized by the underlying operating system.
Cheers and thanks for helping spread the word about accessible retro sound.
-
Just had a go at this on my pi 3b+ running retropie 4.41... no dice :(
It doesnt seem to show mt32 when i run the test to check munt has created the midi output port - when i run command: aconnect -o I get the following:
pi@retropie:~ $ aconnect -o client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 128: 'TiMidity' [type=user,pid=577] 0 'TiMidity port 0 ' 1 'TiMidity port 1 ' 2 'TiMidity port 2 ' 3 'TiMidity port 3 '
no sign of mt32 :( any ideas? The installation process all seemed to go through fine, no probs.
If anyone has any helpful advice I'd be very grateful! Thanks -
@nighthurdles Try opening another console session (e.g. another SSH session) and run
/usr/local/bin/mt32d
there.- If this command will output error message and return to console, you will have a clue what needs to be fixed.
- If this command will display some messages and continue to run. Please go back to first console session and run
aconnect -o
again.
2.1. If new MIDI port 'MT-32' will be displayed you have issue with starting Munt automatically (step 11. in OP).
2.2. If no new MIDI port will be shown, try stopping TiMidity while running Munt.
-
So, I hit a snag at the point where I have to put the MT32 roms in the mt32-rom-data directory; the directory doesn't exist, and trying to create the directory manually gives me that the permission to create the directory is denied. Similarly, I don't have permission to edit rc.local.
Any ideas?
-
@3DMaster You must create the directory /usr/share/mt32-rom-data (and place files there) and edit /etc/rc.local as root.
If you don't know how, you can try using Midnight Commander for these actions.
To install Midnight Commander run:sudo apt-get install mc
To run Midnight Commander as root run:sudo mc
-
Considering to build a Munt-Pi (3B+). But I have some questions first:
- Can I use the 3B compiler flags for the 3B+
- Can I route the audio output via a Hifiberry or USB audio device? If so, how?
- Can I input another audio source via a USB audio device (e.g. Sharp X68000 native audio), and mix it with the audio generated with Munt (from X68000 Midi) and have it both routed to the USB audio output?
Thanks in advance!
-
@seren said in [Tutorial] Installing Munt (MT-32 emulation) on RPi 3:
- Can I use the 3B compiler flags for the 3B+
Most likely they will do. - Can I route the audio output via a Hifiberry or USB audio device? If so, how?
You can either add-d name
parameter when starting mt32d (step 11. in OP) to specify ALSA PCM output device. Or you can comment outdtparam=audio=on
in /boot/config.txt to disable Raspberry Pi built-in sound card.
- Can I use the 3B compiler flags for the 3B+
-
I would like to try the Qt version on my Raspberry Pi 3B+. Can you explain how to build that (including installing Qt itself, etc.) ? I ran into issues , something with: fatal error: QtWidgets/QAction: No such file or directory
#include <QtWidgets/QAction>@David87 said in [Tutorial] Installing Munt (MT-32 emulation) on RPi 3:
- Can I route the audio output via a Hifiberry or USB audio device? If so, how?
You can either add-d name
parameter when starting mt32d (step 11. in OP) to specify ALSA PCM output device. Or you can comment outdtparam=audio=on
in /boot/config.txt to disable Raspberry Pi built-in sound card.
I have it running (mt32d) with a HifiBerry DAC+ADC. I made sure the latest kernel was installed with Hifiberry support with sudo rpi-update and indeed commented out dtparam=audio=on and put in dtoverlay=hifiberry-dacplusadc in /boot/config.txt. Use the correct name for your hifiberry device: https://www.hifiberry.com/build/documentation/configuring-linux-3-18-x/
- Can I route the audio output via a Hifiberry or USB audio device? If so, how?
-
@seren Unfortunately I cannot help with Qt things.
And the default audio output device for you is successfully set to HiFiBerry, correct? -
i am very interested to pimp up my DosBox by using this great tutorial.
Just two questions in advance:
- is this tutorial still up to date concering retropie 4.4.(.15) ?
- is munt_2_2_0 still the latest available version of this Emulator?
Thx a lot for Support!
-
Is this better than using the munt implementation already built into scummVM or does the retropie version not have munt built in?
-
@Barcrest AFAIR its meant for usage in DosBOX - not ScummVM.
-
- You can test this tutorial on RetroPie 4.4. And please post here any issues observed if you do so! Most likely everything will work.
- Latest Munt version is 2.3.0 - the 2nd step will be
wget https://github.com/munt/munt/archive/munt_2_3_0.tar.gz
and first command of 3rd step will betar -xzf munt_2_3_0.tar.gz
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.