Rockbox Technical Forums

Rockbox Development => Feature Ideas => Topic started by: delt on August 24, 2008, 11:26:39 PM

Title: Porting modplug...?
Post by: delt on August 24, 2008, 11:26:39 PM
I was wondering, how difficult would it be to port modplug to work as a plug-in on rockbox? The current .mod support is a bit buggy/incomplete, and i'd very much like to see support for .s3m, .xm, and .it files as well. I'm willing to help with development on this.

Modplug is the best open-source option in my opinion, other than the very mangled version of modplug we're currently using in schism tracker ;D
Title: Re: Porting modplug...?
Post by: Llorean on August 25, 2008, 12:24:36 AM
Modplug appears to include C++, it might be a considerable amount of work. And one of the greater concerns for these formats is how to properly buffer them for use in Rockbox playback.
Title: Re: Porting modplug...?
Post by: delt on August 25, 2008, 12:50:59 PM
DOH!! didn't think of that (c++) Yeah it does use classes, but not (much) the weird c++ syntax stuff like &variable in function headers, try {} fail {} etcetc.

But for buffering, isn't it the whole point of modplug to "convert" module files to pcm/wave data on the fly? and then send this data to an audio buffer?
Title: Re: Porting modplug...?
Post by: Llorean on August 25, 2008, 01:04:37 PM
The module files themselves need to be buffered (be in-RAM, as you can't constantly be spinning the disk). Because module files can in some situations be too long to fit in the buffer, and because they can contain loops, there is difficulty as to how to properly manage this aspect of them: You can't loop back to an area that's no longer buffered, but sometimes you can't keep the whole song in-buffer.

Basically, non-streaming files aren't what Rockbox was designed for, and there needs to be some work in general to handle them well. This applies to MIDI as well.
Title: Re: Porting modplug...?
Post by: delt on August 25, 2008, 08:52:13 PM
What about just keeping a copy of the module in memory, and rendering it to pcm one pattern at a time? ie. determine next pattern to play, render that while the current one is playing, and discard pcm buffers of previously played patterns, or cache them according to memory available, usage in orderlist, etc... ?

I would think rockbox's plugin architecture certainly offers enough flexibility for that. It can't be that much different from the music in a gameboy emulator.

Title: Re: Porting modplug...?
Post by: saratoga on August 25, 2008, 09:34:52 PM
What about just keeping a copy of the module in memory, and rendering it to pcm one pattern at a time? ie. determine next pattern to play, render that while the current one is playing, and discard pcm buffers of previously played patterns, or cache them according to memory available, usage in orderlist, etc... ?

I would think rockbox's plugin architecture certainly offers enough flexibility for that. It can't be that much different from the music in a gameboy emulator.



You can do that, but it means you can't use the buffering system, and so would have to write your own.
Title: Re: Porting modplug...?
Post by: Llorean on August 25, 2008, 10:04:51 PM
The playback system does essentially keep the original file in memory, decode to a PCM buffer, and then discard the PCM buffer as it's played.

As I think I said above, there's a significant problem when there's not enough RAM available to fit the original, compressed file. With streaming files you can dispose of played compressed data. Basically, someone needs to figure out a proper way to handle non-streaming data in the playback system.
Title: Re: Porting modplug...?
Post by: delt on August 26, 2008, 07:57:56 AM
I still say it can be done. I mean, if you can play doom and have a gameboy emulator on rockbox - both with low latency sound - it's certainly possible to make a plugin that plays s3m and xm files. At least within the limits of the hardware it's running on. It won't be a simple matter of copy/pasting code from modplug, but it most certainly can't be that hard to do.

I'm a bit busy with other stuff these days, but i look forward to become acquainted with rockbox's source code in the relatively near future.
Title: Re: Porting modplug...?
Post by: GodEater on August 26, 2008, 09:00:23 AM
Llorean didn't say it couldn't be done - he said it wouldn't be easy with the current design of the playback engine.

Doom and Rockboy don't use the playback engine.
Title: Re: Porting modplug...?
Post by: Captain Kewl on August 29, 2008, 08:00:18 PM
http://www.rockbox.org/tracker/8806 -- not Modplug, but it does play other mod formats (and renders .mod more completely).

Incidentally, I did do some preliminary work on a proper Mikmod codec about a month back, but pretty much ran into the same problems as the previous attempt: the 512k codec buffer makes it impossible to render anything more than some really simple .mod files.  I attempted to hijack the file buffer and use that for memory allocation, but then that broke, well, file buffering.
Title: Re: Porting modplug...?
Post by: pixelma on August 30, 2008, 07:03:07 AM
As far as I know, the current mod codec uses metadata-on-buffer to get rid of the codec buffer limitation, at least it plays my 2 mod files which are larger than that correctly (and I remember its first version which did not use this system and choked on the files when the "end of the buffer was reached). Maybe you can find some inspiration there?
Title: Re: Porting modplug...?
Post by: delt on August 31, 2008, 10:42:27 PM
Looks awesome. I'll try to round up all the compiler tools to build rockbox from source tomorrow.
Title: Re: Porting modplug...?
Post by: GodEater on September 01, 2008, 03:27:05 AM
We supply a script which does that already in svn, called rockboxdev.sh.

Or you could just download our VMWare image and use that, it has them all already installed.
Title: Re: Porting modplug...?
Post by: delt on September 01, 2008, 09:34:37 PM
Cool. But isn't vmware commercial? (i don't have it....)
Title: Re: Porting modplug...?
Post by: Llorean on September 01, 2008, 10:50:05 PM
It's free.
Title: Re: Porting modplug...?
Post by: GodEater on September 02, 2008, 02:57:41 AM
To clarify, both the "VMWare Player" application and "VMWare Server" application are available without any charge.

You can use either with our image - but we recommend "Player" unless you're planning on doing something more complicated with the image (since the Player can only "run" the image, it can't modify it).
Title: Re: Porting modplug...?
Post by: delt on September 06, 2008, 08:45:04 PM
http://www.rockbox.org/tracker/8806 -- not Modplug, but it does play other mod formats (and renders .mod more completely).

I just compiled rockbox with this patch and it works quite well! (is it normal if .mod files are still played by the firmware itself and not the mikmod plugin?) Anyway this rocks, thanks very much for this.

btw, what are those "ohloh" things with "kudos/commits" in some people's signature? (i just noticed the number on GodEater's increased from 8 to 9)
Title: Re: Porting modplug...?
Post by: Captain Kewl on September 07, 2008, 12:26:00 AM
You can use "Open With..." in the context menu to open the file with Mikmod.  On the iPod, just hold down the select button for a few seconds to bring up the menu; I don't know about other audio players.
Title: Re: Porting modplug...?
Post by: delt on September 07, 2008, 01:22:57 AM
Yep, that works, thanks =) actually figured it out after posting my previous comment. Now how would i modify the rockbox firmware so it doesn't try to load .mod files itself?

Incidentally, how do you generate your patches against the rockbox source? What would i need to name the unmodified and (mik)modified ;D source tree directories before running diff?
Title: Re: Porting modplug...?
Post by: bascule on September 07, 2008, 03:16:36 PM
btw, what are those "ohloh" things with "kudos/commits" in some people's signature? (i just noticed the number on GodEater's increased from 8 to 9)
Just click the link, that will get you started...
Title: Re: Porting modplug...?
Post by: delt on September 08, 2008, 11:57:18 PM
BTW i just fixed a small but annoying bug that made instrument and sample lists scroll upside down on ipod.


Just changed apps/plugins/mikmod/mikmod.c lines 64 and 65 from:

Code: [Select]
#define BTN_UP           BUTTON_SCROLL_FWD
#define BTN_DOWN         BUTTON_SCROLL_BACK

to:

Code: [Select]
#define BTN_DOWN         BUTTON_SCROLL_FWD
#define BTN_UP           BUTTON_SCROLL_BACK

/* edit */

Never mind, that screws up the volume control now. Best fix is to swap lines 584-589 with lines 604-609.
Title: Re: Porting modplug...?
Post by: Strife89 on September 09, 2008, 10:29:20 AM
I've applied the patch and I'm loving it. I had 43 MB of free space on my micro SD card before. A quick visit to www.modarchive.org filled it up completely. :o ;D
Title: Re: Porting modplug...?
Post by: XqWyZ on January 15, 2009, 10:37:57 AM
what about bassmod as a src?
Title: Re: Porting modplug...?
Post by: Chronon on January 15, 2009, 12:51:58 PM
Cool. But isn't vmware commercial? (i don't have it....)


Also, VirtualBox now supports VMWare disk images.

what about bassmod as a src?

What is your suggestion, exactly?