Mod Archive Forums Mod Archive Forums
Advanced search  

News:

Please note: Your main modarchive.org account will not work here, you must create a forum account to post on the forums.

Pages: [1] 2   Go Down

Author Topic: Where can I start learning about programming a module player?  (Read 11107 times)

0 Members and 1 Guest are viewing this topic.

wow25

  • New User
  • Offline Offline
  • Posts: 6
    • View Profile

Hi! The title is pretty much what I'm asking. I've been looking through the Openmpt source code (https://source.openmpt.org/browse/openmpt/trunk), and specifically openmpt123, to try and understand how it works. However, the complexity of the project has confused me, and I was wondering if there was a more 'simplified' player or guide I could look into.

For background, I'm no stranger to programming (though c++ isn't my strongest language), but I know very little when it comes to audio programming. I'd love to learn this stuff, either to make my own kind of player, or to contribute somehow!

Thanks!

Logged

Saga Musix

  • TMA Moderator
  • Top Poster
  • ****
  • Offline Offline
  • Posts: 2571
  • I love OpenMPT! And Modules! And TMA! And Pie! :>
    • View Profile
    • Saga Musix - free module music and more!
Re: Where can I start learning about programming a module player?
« Reply #1 on: February 06, 2021, 19:29:18 »

There will always be some complexity because the original trackers, typically being written by teenagers and young adults with no industry standard to define formats etc., often lack proper documentation, a lot of implementation details are hidden inside the original assembly code... Getting started is often easy, but you cannot expect that your results will be accurate. OpenMPT's code in particular is complex because
1) it supports dozens of formats.
2) it does its best to emulate the various little quirks of the trackers used to write those formats.
3) it is designed to be used by other software and thus has high standards with regards to security and standard conformance.

It will probably much simpler if you start out with writing a player for a single format, and if you don't care about getting every detail right. Basic understanding of how audio programming works (volume, panning, resampling with interpolation) would be very useful, too.
If you want to start with the ProTracker MOD, you can check out this tiny MOD player source. It will definitely not get every detail of the MOD format right, but it's a good start. 8bitbubsy's ft2play may also be interesting if you want to get into the XM format, as it's a direct port of the original FT2 source (so it's very accurate but might not be easy to follow).

In the end, once you have grasped the basic concepts (which these two examples may help with), writing a player for yet another format will become much easier, as it's the same stuff over and over again, just with some details being different here and there. Those details add a lot of complexity once you want to support all of those formats in a single engine (like OpenMPT does), though.
Logged
» My TMA artist profile
» Visit my music site: https://sagamusix.de/ [de, en]
» Visit my programming website: https://sagagames.de/ [de]
» Open ModPlug Tracker

wow25

  • New User
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Where can I start learning about programming a module player?
« Reply #2 on: February 06, 2021, 20:59:16 »

These look perfect! I'll do my best to learn it on my own (and with online resources), but I may come back here with a question or two if I'm having trouble.

Thank you for the help, and thanks for all the hard work you put into this site and OpenMPT!
Logged

Saga Musix

  • TMA Moderator
  • Top Poster
  • ****
  • Offline Offline
  • Posts: 2571
  • I love OpenMPT! And Modules! And TMA! And Pie! :>
    • View Profile
    • Saga Musix - free module music and more!
Re: Where can I start learning about programming a module player?
« Reply #3 on: February 06, 2021, 21:40:54 »

You're welcome. You may also have a look at the OpenMPT development forums and ask technical questions about the source or how to implement certain aspects of a mod player there.
Logged
» My TMA artist profile
» Visit my music site: https://sagamusix.de/ [de, en]
» Visit my programming website: https://sagagames.de/ [de]
» Open ModPlug Tracker

wow25

  • New User
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Where can I start learning about programming a module player?
« Reply #4 on: March 13, 2021, 03:43:18 »

So after about a month of diving into your sources I've made a pretty good understanding, though I still think there's stuff I need to learn. I wasn't able to make the tiny mod player work, which was likely my own inexperience. I instead focused mostly on the ft2 player which, as you said, was more difficult to understand.

Do you know of any other simple players that I could look into? This stuff really is cool!
Logged

Saga Musix

  • TMA Moderator
  • Top Poster
  • ****
  • Offline Offline
  • Posts: 2571
  • I love OpenMPT! And Modules! And TMA! And Pie! :>
    • View Profile
    • Saga Musix - free module music and more!
Re: Where can I start learning about programming a module player?
« Reply #5 on: March 13, 2021, 12:50:32 »

I mean, there are tons of Amiga module formats that are very simple conceptually, but most of their sources will be in Motorola 68000 assembly language so depending on your background they are probably more difficult to get into (plus the hardware does the mixing, so you will actually not see any of the magic of that - the players just tell the hardware which pieces of memory to mix at which volume).
I don't know to be honest, maybe it's time to bite the apple and try something more complex. ;) In the end, you will see the same concepts being repeated again and again. Being able to at least read assembly language (Motorola 68000 and x86) can greatly help understanding how some of the older trackers work, as some of them are open-source these days but were obviously not written in high-level languages back then. Or maybe you'd want to start from scratch and write a new MOD or XM player with the stuff you've learned so far. You're always welcome to ask questions how certain things work if you're stuck.
Logged
» My TMA artist profile
» Visit my music site: https://sagamusix.de/ [de, en]
» Visit my programming website: https://sagagames.de/ [de]
» Open ModPlug Tracker

wow25

  • New User
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Where can I start learning about programming a module player?
« Reply #6 on: March 13, 2021, 22:23:39 »

I think you're right. I tend to use MilkyTracker pretty often, so I'll try to jump into the source, maybe make a primitive player.

I did have one question before that. The ft2 player used Windows Multimedia to actually play the audio once it was decoded and put into the buffer, and it seems that OpenMPT does not. Is there a preferred audio driver (if that's the right word for it) for making players? I wouldn't want to use one and find out it's depreciated.

As always, thank you for your help!
Logged

Saga Musix

  • TMA Moderator
  • Top Poster
  • ****
  • Offline Offline
  • Posts: 2571
  • I love OpenMPT! And Modules! And TMA! And Pie! :>
    • View Profile
    • Saga Musix - free module music and more!
Re: Where can I start learning about programming a module player?
« Reply #7 on: March 14, 2021, 14:44:02 »

Quote
I think you're right. I tend to use MilkyTracker pretty often, so I'll try to jump into the source, maybe make a primitive player.

Note that the MilkyTracker source isn't necessarily any easier than OpenMPT's, because it's also a multi-format player, and in particular because it uses a lot of magic numbers everywhere. For example you will find that the internal IDs for all pattern commands are hardcoded integers rather than having descriptive names like you can find them in OpenMPT (something like CMD_VOLUME) and other players.

Quote
I did have one question before that. The ft2 player used Windows Multimedia to actually play the audio once it was decoded and put into the buffer, and it seems that OpenMPT does not. Is there a preferred audio driver (if that's the right word for it) for making players? I wouldn't want to use one and find out it's depreciated.

Both WinMM and DirectSound are just emulation layers on top of WASAPI since Windows Vista. Modern Windows audio code should use WASAPI. It's somewhat more complex than WinMM so if you don't want to fiddle with the details, you can resort to using something like PortAudio or RtAudio as an API abstraction. That way the same audio code would also work on macOS, Linux and some other platforms.
Logged
» My TMA artist profile
» Visit my music site: https://sagamusix.de/ [de, en]
» Visit my programming website: https://sagagames.de/ [de]
» Open ModPlug Tracker

wow25

  • New User
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Where can I start learning about programming a module player?
« Reply #8 on: April 20, 2021, 04:58:08 »

Ok! So I've made a lot of progress, but I keep running into errors with reading mod files. Is there a place I can find the 'anatomy' of a mod? It's a bit hard trying to figure it out by just analyzing other programs' load functions.

Also let me know if this conversation is better suited for somewhere else. Thank you!
Logged

Saga Musix

  • TMA Moderator
  • Top Poster
  • ****
  • Offline Offline
  • Posts: 2571
  • I love OpenMPT! And Modules! And TMA! And Pie! :>
    • View Profile
    • Saga Musix - free module music and more!
Re: Where can I start learning about programming a module player?
« Reply #9 on: April 20, 2021, 19:25:51 »

A variety of module formats is documented at https://ftp.modland.com/pub/documents/format_documentation/ - but it's important to keep in mind that often this documentation is not very formal or complete, because
- it was written by teenagers :)
- it was reverse-engineered and thus might be missing some details.
As MOD is a pretty popular format, there are several documents on the format with various degrees of completeness. You may want to look into this one in particular, because it's essentially a corrected version of another popular document:
https://ftp.modland.com/pub/documents/format_documentation/Protracker%20effects%20(MODFIL12.TXT)%20(.mod).txt

It's also important to keep in mind that a MOD file isn't necessarily a MOD file. By that I mean that there are several closely related variants of the format with tiny differences. For example, the original Ultimate Soundtracker format is almost identical to the "M.K." ProTracker format, with the difference that it only contains 15 instead of 31 sample slots, and doesn't contain the magic bytes ("M.K."). There are many more tiny differences beyond that, but those two would be the main reason why a SoundTracker MOD wouldn't load in a regular MOD loader. Many of these small details are not properly documented and can only be found by dissecting other loaders.
Logged
» My TMA artist profile
» Visit my music site: https://sagamusix.de/ [de, en]
» Visit my programming website: https://sagagames.de/ [de]
» Open ModPlug Tracker
Pages: [1] 2   Go Up