Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] How to play a mod sound file in java!  (Read 3385 times)
0 Members and 1 Guest are viewing this topic.
Offline jonjava
« Posted 2012-04-22 10:21:30 »

Hi,

First to refresh everyone's memory, here's a quick description of a mod file form wikipedia.
Quote
This is the original module format. Uses inverse-frequency note numbers. 4 voices, with up to 32 in later variations of the format. Pattern data is not packed. Instruments are simple volume levels; samples and instruments correspond one-to-one. 15 instruments in the original Soundtracker, 31 in later trackers. This format was originally created to be easily playable with the Amiga hardware, since it was equipped with a four-channel DAC. The CPU has to do very little work to play these modules on an Amiga.[citation needed] Many games utilize this format - often with small player programs included. In the early 1990s, usage of this format with games was widespread across platforms, with games on PC and Nintendo systems utilizing it, as well.
[size=6pt]source: http://en.wikipedia.org/wiki/Module_file[/size]

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

Offline jonjava
« Reply #1 - Posted 2012-04-22 15:01:08 »

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.
:)

Offline cylab

JGO Ninja


Medals: 38



« Reply #2 - Posted 2012-04-22 16:53:25 »

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.

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #3 - Posted 2012-04-22 22:18:19 »

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.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline cylab

JGO Ninja


Medals: 38



« Reply #4 - Posted 2012-04-23 10:25:56 »

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?

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

Mathias - I Know What [you] Did Last Summer!
Offline jonjava
« Reply #5 - Posted 2012-04-23 13:03:29 »

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.

Offline mumart

Junior Member


Medals: 1
Projects: 1


IBXM Java Music Player


« Reply #6 - Posted 2012-05-13 21:57:56 »

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/

Quote
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?

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".

Quote
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?

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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (34 views)
2014-07-23 21:16:32

Riven (22 views)
2014-07-23 21:07:15

Riven (25 views)
2014-07-23 20:56:16

ctomni231 (56 views)
2014-07-18 06:55:21

Zero Volt (48 views)
2014-07-17 23:47:54

danieldean (39 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!