echolevel
Posts: 9
Joined: Sun Aug 05, 2012 10:38 pm

Amiga MOD playback on RasPi with Java

Sun Aug 05, 2012 11:29 pm

Hi there, just thought I'd document what I've been working on since the RasPi came through the letterbox on Friday. If anyone has questions or suggestions, I'm all ears! Oh, and although I can cobble together some easyish stuff, bear in mind that I'm not a programmer; just an enthusiastic amateur. I'm happy to be corrected where I've gone wrong!

I'm not going to bore everyone with a history of the demoscene, the Commodore Amiga and Protracker/FastTracker/ScreamTracker module formats as I'm sure this'll only get clicked on by people who know what the subject heading means :)

Long story short: I made a very flexible, very lightweight, highly interactive MOD/XM/S3M replayer library for Processing some years ago. The idea was that people could put module-format soundtracks in Processing sketches while keeping the sketches very small for web viewing - most MOD music is well under 500kb, often around 20kb. Not many people used it, but I'd mostly done it for my own amusement. I used that library to create a dual-deck module DJing app called Chipdisco, an old version of which you can try in the browser complete with multiple MIDI input devices, multiple soundcard support and a baffling user interface here (drag and drop a file from the playlist to a deck to start playback).

Processing is dropping applet support and, frankly, running this in the browser in this day and age is problematic - Apple's Java implementations seem to get worse every year and they've already broken bits of javasound. So I decided to overhaul Chipdisco last week, throw out a load of bloat and turn it back into an app to be run locally without any of the security/signing problems.

The more I optimised it, the more I realised that playing back these archaic formats should be quite possible on a machine like RasPi - after all, the Amiga 500 was only rocking 7mhz and a bit of DMA hardware. Ordered a RasPi from Farnell, arrived a few days later, and after some false starts (and a lot of helpful posts on this forum about the Java situation) I got openJDK installed and got Chipdisco to at least *run*, if not play anything. Writing a tiny test Java app using my PortaMod library got me successful playback of a 4-channel MOD, but with epic stuttering. I realised that was mostly due to Processing's draw() loop, which uses quite a lot of juice and can't be disabled. Well, it can, but you can't run Processing apps headless. So I had to strip all the Processing-reliant stuff out and recreate it in pure Java - bit of a nightmare as I'm a horribly bad programmer, but there's a lot of help out there and I've become quite experienced at Googling it ;)

Once I'd got that app together and transferred it over, the errors I was getting were javasound SourceDataLine errors mentioning PulseAudio. Got past that by just installing PulseAudio (a whopping 100mb on my tiny SD card), but I think it's a failure on the JVM's part to simply detect whether or not PulseAudio is there and, if not, to just use ALSA instead. Sledgehammer/walnut - I hope that ceases to be a problem when a solid, fast, Oracle JVM comes along for RasPi. From the chat on this forum and elsewhere, there seems to be a lot of interest in getting Java to run tolerably on RasPi and, as I use Processing quite a bit for teaching and for interactive digital art, I'd love to see it easily available to beginners on the platform. Anyway, openJDK is slow for now but EVEN SO, I got listenable playback!

Playing from the commandline is fine; when the Rasbpian GUI is running, moving the mouse will cause stutters while the poor thing tries to keep up with its redraws. Booting to shell is better, and I'm sure better audio driver implementations, better FPU, better JVMs and various other improvements will eventually mean I can play complex 32-channel FastTracker XMs without stuttering (gotta be optimistic!)

My final experiments have been with receiving USB MIDI with Java. It seems to work quite well, but I've read that having the USB ports enabled draws quite a bit of CPU, even when they're idle...so it might be better to do this over the GPIO in future - someone's designed a breakout board that I might try to build.

Put it all together and, ultimately, I want to have RasPi as a headless, mouseless, keyboardless, portable, dual-deck MOD DJ box into which I can plug my MIDI controller and rock some (very nerdy) parties! Reet - sorry for the huge essay, and I'll update this thread when (and if) I make progress.

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Amiga MOD playback on RasPi with Java

Sun Sep 02, 2012 7:21 pm

Neat project, it would be lovely to thinker with your source-code if you decide to publish it.

For low latency audio in Java applications I suggest you to switch from the default blocking i/o and push driven Java Sound framework into a pull and event driven framework like jjack in order to archive low latency audio playback. http://jjack.berlios.de/

Karl Helgason held an excellent session on the current state of Low latency in
Java Sound & Gervill at Fosdem 2011
http://java.net/projects/gervill/downlo ... slides.pdf
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

echolevel
Posts: 9
Joined: Sun Aug 05, 2012 10:38 pm

Re: Amiga MOD playback on RasPi with Java

Sun Sep 02, 2012 8:48 pm

Wow, I had no idea about this; I shall investigate. Thanks!

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Amiga MOD playback on RasPi with Java

Fri Sep 21, 2012 10:41 am

I have to say your YouTube clip of this Java Chipdisco MOD playback is nice!
http://www.youtube.com/watch?v=P6UtcsNFA4s - Chipdisco test on Raspberry Pi - Music
http://www.youtube.com/watch?v=l-M65hjryYc&feature=plcp - Chipdisco on Raspberry Pi - Amiga MOD playback in Java - Talk

Is the "Raspberry Pi optimized console version" included on the Chipdisco webpage?
http://echolevel.co.uk/chipdisco/
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Amiga MOD playback on RasPi with Java

Fri Sep 21, 2012 1:47 pm

echolevel wrote:Once I'd got that app together and transferred it over, the errors I was getting were javasound SourceDataLine errors mentioning PulseAudio. Got past that by just installing PulseAudio (a whopping 100mb on my tiny SD card), but I think it's a failure on the JVM's part to simply detect whether or not PulseAudio is there and, if not, to just use ALSA instead. Sledgehammer/walnut
This is a Linux distribution issue, if the distribution compile icedtea/openjdk with pulseaudio enabled as default then they should also install pulseaudio. You can configure OpenJDK to use ALSA instead of PulseAudio by editing
/etc/java-6-openjdk/sound.properties
or
/etc/java-7-openjdk/sound.properties
and use the following settings for ALSA playback:

javax.sound.sampled.Clip=com.sun.media.sound.DirectAudioDeviceProvider
javax.sound.sampled.Port=com.sun.media.sound.PortMixerProvider
javax.sound.sampled.SourceDataLine=com.sun.media.sound.DirectAudioDeviceProvider
javax.sound.sampled.TargetDataLine=com.sun.media.sound.DirectAudioDeviceProvider
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

echolevel
Posts: 9
Joined: Sun Aug 05, 2012 10:38 pm

Re: Amiga MOD playback on RasPi with Java

Fri Sep 21, 2012 3:11 pm

xranby - thanks! In all my desperate, late-night attempts to figure this out, I never investigated /etc/java-[x]-openjdk/sound.properties, so that's a great tip. I haven't uploaded the test build anywhere yet and I've tried out a range of different things since then (mostly involving headless keyboard control and MIDI), but I'll tidy it up a bit and make it available as soon as I get time. I'm also looking at JJack as an alternative to Javasound's blocking technique, in the hope of reducing latency, but I think that might be hampered by a lack of ARM versions of the native binaries... I've only had a brief glance at the docs so far though, so we'll see.

And thanks for the heads-up about that weird bug in the (auto-generated) run script in the Linux version of Chipdisco - I've fixed it for the release, but I'll delve into Eclipse and my ant build to try and stop it happening again :)

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Amiga MOD playback on RasPi with Java

Sun Sep 23, 2012 3:47 am

We will have to compile the native "c" parts of jjack for ARM on the Pi and check.
.. or maybe i/you do not have to! :) I found this alternative jjack implementation that is using JNA thus it would work on the Pi by using the Debian/Rasbian built JNA packages.
http://code.google.com/p/java-audio-utils/

I found out about this in a response to Karl's latency talk while browsing the Gervill mailinglist.
http://java.net/projects/gervill/lists/ ... /message/0

Hot sounding stuff!
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

Return to “Graphics, sound and multimedia”