[SOLVED] How to play a mod sound file in java!

Hi,

First to refresh everyone’s memory, here’s a quick description of a mod file form wikipedia.

source: http://en.wikipedia.org/wiki/Module_file

So picking the highlights above a mod file basically 4 streams of notes, each note representing 1 of the 15 instruments.

My question is how can these files be converted into sound in modern day computers?? (I know they can, JavaModPlayer2 is a good mod player). I’m assuming that the original notes in the mod files were directly fed to the 15 hardware instruments that resides in the Amiga.

Wouldn’t this undoubtedly make mod files sound different on practically every computer depending on how the 15 Amiga instruments are emulated?

How do modern mod players play mod files? Do they decode into another format first, like mp3? Or do they directly feed the information to the sound hardware - how do they do that? Does Java provide an API for this?

Would it be possible to ship “software” versions of the 15 Amiga instruments and use them while reading the mod file and to ultimately play the music unanimously on all computers?

I am quite clouded by how sound works in general, so any and all insights are welcome!

I was considering making my own mod player in java for fun since the mod format is fairly straightforward and tangible.

Thanks,
jon

What I’m looking for are ideas/links/books where to start. Things like what did you personally read (recommended books?) and need to learn before coding your own audio player/synth/decoder.

It’s immensely more helpful than deciphering google.
:slight_smile:

The mod-format is not like general midi, but also contains the audio-clips to use for an instrument. So “everything” you have to do, is feed the right audio-clip to a “mixer” at the right time.

The tricky part is, that these clips have to be played back in different sample-rates, depending on the tune of the note you need to play. Like if the audio-clip is a A-4, sampled with 16kHz, you need to play it back with 32Khz to get A-5, 64kHz for A-6 and a whopping 128kHz for A-7.

Since consumer hardware does not support these sample-rates, they have to be emulated by the mixer using resampling (e.g. leaving out every second sample in the clip to convert a 16kHz clip to a 8kHz clip, effectively tuning it up by one octave).

I’ve never done anything sound related with java, so I don’t know the available mixer options, but I am sure, others here can help out with this.

I should check out JavaModPlayer2–hadn’t heard of it before. (If it already exists, what is your goal in creating another Java Mod player?)

Overall, this sounds very interesting to me as a project. I may be able to help or collaborate, if you are interested in doing so. I’ve been wanting to turn what I’ve been learning with audio into something that would be appealing and practical for Java game programmers wanting to add music to their games.

But I have never seen the mod format, and don’t recall what the old Amigas sounded like. From what you say, it sounds kind of like a simplified version of midi?

What I have done in Java:

  • a real time mixer
  • varispeed playback for PCM data
  • wave table synthesis
  • real time FM synthesis

So, if I could hear the 16 source waves from the Amiga, it could very well be possible to recreate those sounds via FM or WaveTables, and use the mixer I wrote (or something similar) for playback. This would mean the “mod” sound unit would be written using native Java and should sound “the same” for all computers.

If the sounds being used must be samples (can’t be synthesized), one would presumably load them as resources into memory (from .wav or ogg/vorbis or flac or mp3) as PCM data. Once in memory, it is fairly straightforward to use linear interpolation to step through the audio data and create different pitches. The only aspect I haven’t direct experience with is dealing with aliasing if you push the frequency so high that overtones in the data surpass the sample rate’s limit. I’ve read about what to do for that situation, but haven’t actually tried programming a working example yet.

Please let me know if you want to discuss further! I’ll also be happy to answer questions when I can, if you decide to do this on your own.

The mod format is the legacy format of Tracker like music software (comparable to a step sequencer) http://en.wikipedia.org/wiki/Module_file

It’s like midi in a grid with samples instead of instruments. But nobody will stop you to exchange that samples with synthesized instruments, probably not to emulate the samples in old songs but to create new ones.

Btw. my favorite next-gen Tracker is Renoise http://www.renoise.com

I’ve no hidden agenda, the how just interests me. I know disgustingly little about sound, please don’t let me hinder you if you want to tackle mod’s yourself.

Sadly spare time is less abundant than it used to be. Will have to revisit this another time.

I have written several Java mod-player libraries over the years. The source code for the most recent ones can be found at http://code.google.com/p/micromod/

The Amiga did not have any built-in instruments, the original SoundTracker MOD format could have up to 15 8-bit samples contained within the file. Every mod file contains the sample data for all instruments within it. The early mods all sounded the same because everybody used the instruments provided with SoundTracker, on a disk called “ST-00”.

Usually they generate a PCM wave-file a fraction of a second at a time (10-100ms depending on the tempo) using sample-rate conversion for each channel and mixing them together. Java can play PCM sample data using an appropriately configured javax.sound.sampled.SourceDataLine.

Any differences in the sound between different players is generally due to the quality of the sample rate conversion. The original Amiga hardware did not have any oversampling, and the sound quality was comparable to using nearest-neighbour resampling at a high sample rate such as 96000hz.

Cheers,
Martin