MOD-player 3


>>>> WARNING: very poor translation!!! <<<<

   Few years ago I've published first version of my AVR MOD-player. Since then few authors have published videos of their own versions of this player. At least one of them seems to be really good programmer besause he actually undestood my VERY badly formated and almost uncommented code and modified it for playing directly from internal FLASH. I've made something similar but largest AVR in DIL was ATmega32 and 27kiB is to few for listenable ProTracker so I've didn't published it.
   This interest in my MOD-player was good motivation to try to optimize my very inefficient code (original code was actually my first AVR try ever). After few hours of staring into my own code I've decided that it would be much more effective to loose original code and to start again, this time using correct MOD specifications and louds of macros to make it "readable". To ensure maximum performance I've chosen biggest and fastes DIL AVR - ATmega644 (64kB FLASH, 4kB RAM, 20MHz) which should be enough for 4 channel trackers at 33kHz at least. Thanks to good documentation and Modplus tracker sources it sounds much better and this time it took me only two weeks or so to write the code.

This is how MOD-player 3 looks like. MCU (lower row), SRAM and USB-COM (middle row), audio output in top row and IDE interface and LCD cables over it. This is how MOD-player 3 looks like. MCU (lower row), SRAM and USB-COM (middle row), audio output in top row and IDE interface and LCD cables over it. MOD-player with nice big LCD.

1. Basic features

Mixing: 16-bit mono/stereo
Vzorkování: 4 - 48kHz (maybe more)
Resampling: no resampling or linear interpolation
Max. channels: 4 at 36kHz sampling rate
8 at 21kHz sampling rate
10 at 17kHz sampling rate
Data src.: HDD of CF card with FAT16 (basic folder support)
or serial port
Formats: Uncompressed ProTracker (*.MOD)

   All values are for AVR at 20MHz but it's of course possible to overclock.

2. Hardware

   It is almost identical to the original version (not big surprise - I've found original breadboard in table sediments :D). Lot of dust there and "some" idiot removed few very important wires but I've made it working with original code after few tries.
   Only important difference is differently connected SRAM which is now not limited to 512kiB but could have any size from 64kiB up to 2MiB. In my version I'm using two 512kiB SRAMs with chip select logic between them.

   As I've said before player is based on relatively powerfull MCU AVR ATmega644-PU at 20MHz. It has 64kiB of FLASH and 4kiB of RAM which is quite enough for all structures and some audio FIFO. External SRAM is addressed in SW mode using two address buffers IC2 and IC3. It's using only two ports and few control signals. SRAM should be at least 55ns version. Same ports are shared with IDE interface in 16-bit mode, with HD44780 LCD in 8-bit mode and with buttons interface.
   Audio output is same as in last version with I2S-like serial DAC connected at SPI interface. More information how to handle it with AVR can be found here (but only in czech right now).
   A little note here - I've spent good few hours trying to identify source of noise in sound. At first I thought it is caused by reflections in long IDE cable but termination resistors didn't changed anything. Then I've coincidently find out that source of problem is 15cm ground path which is obviously long enough to induce some 800mV interpreted as high level by TDA1545. So be carefull designing anything on breadboards (even louds of capacitors doesn't ensure that it will work correctly). Solution in my situation was GND wire connected directly between MCU to DAC.

2.1 Overclocking

   Used MCU should work at least at 20MHz but while experimenting with mutlichannel trackers I've tried to push it up a bit. At first only for 24MHz but since it seemed to work I've tried 27MHz and still no problem. This is quite interesting because my old ATmega32 had problems even at 18MHz (code worked only if it was aligned from even address :D). Because I haven't found any faster crystal I've tried to use some 32MHz oscillator from table sediments and after few aditional wait cycles for SRAM and IDE interface it works with no problems! It actually worked at 40MHz @ 6V1 but that was a bit much for other components. ;-)

3. Software

   Code it written in pure ASM but this time I've used louds of macros and I've tried to make comments everywhere. I've also separated code from 5k+ lines long "noodle" into several modules so it should be easier to undestand it.
   Surprise to me was that not only it sounds much better than last version but it also needs only some 60% of CPU power compared to original version. New performance is enough for decoding 8-channel trackers at 21kHz sampling rate.
   Song can be loaded via serial interface without flow control of from FAT16 formated HDD or CF card with one level of folders (short file names only supported). Only first 255 folders and 255 files from each folder can be selected but I think it's more than enough.
   Sources for TDA1543, Sources for TDA1545.

3.1 Control

   At first external SRAM is tested. If there is at least 64kiB program should continue. If no SRAM is found or there is error detected program should stop. Next step is detection of IDE device. If something is found and first partition is formated as FAT16 player should enter into folder menu. If no IDE device is detected or IDE interface is disabled player should enter into serial port loading mode. In this mode player waits for MOD data that can be send by any terminal without flow control (MCU is fast enough). End of file is detected automatically - file loading is finished if there is no recieved byte for more than 1.5sec. Serial load could be also activated manually by "COM" button.
   Other button functions in different modes should be obvious from the scheme.

3.2 Options

   Most of usefull options are present at beggining of "m644_modplay.asm" module. Parameters are described in following table.

Název parametru Význam
XTAL Crystal frequency [Hz]
HCOC Adds aditional wait-cycle for external SRAM routines (usually necessary for >24MHz)
USRDIV Clock divider for USART, baud=XTAL/(16*(USRDIV+1))
MEMTST Enables full SRAM test (it will take 1s/1MB/20MHz), usefull for easy SRAM functionality test
STORA Enables IDE interface
SRATE Desired sampling rate (from 4 up to 48kHz, maybe more)
DAC DAC interface type, 1543=I2S, 1545=TDA1545
STEREO Enables stereo mixing
LINRES Enables linear interpolation mixing (needs some more MCU power)
DRAWVU Enables VU-meters (needs some 5% MCU power)
MAXCH Maximum supported channel count, min. 4, max. 32, but it'll need some more RAM, so it would be necessary to set smaller size of audio FIFO (defaultly it's 16 channels)

   There are some more parameters in this module but it's usually not neccessary to change them. Only important parameter is audio FIFO size which should be always maximal (it should use entire unused RAM) but it can't be shorter than 1kiB because it's shared with another module as data buffer ("storage.asm").

3.3 Fuse bits

   If player is used with crystal CKOPT fuse should be programmed (full swing oscilator amplitude). JTAG should be disabled because it's located at data pins which are therefore in weak-high level mode. This is a bit problematic for fast data transfers. Another solution could be usage of external pull-ups but I've didn't tried that.

4. Supported formats and effects

   Player should be able to play uncompressed ProTracker files (*.MOD) theoreticaly with any channel count.

Supported effects
# Effect name Implementation
0 Arpeggio full support
1 Portamento up full support
2 Portamento down full support
3 Tone-portamento full support
4 Vibrato supported, only sine waveform
5 Tone-portamneto + Volume slide full support
6 Vibrato + Volume slide full support
7 Tremolo no - I've never seen it used
8 Panning (stereováha) no - mixing needs more CPU power
9 Nastevení ofsetu vzorku full support
A Volume slide full support
B Skok na jiný list only forward
C Nastav hlasitost full support
D Skok v listu full support
E0 Nastav filtr no
E1 Portamento up jemně full support
E2 Portamento down jemně full support
E3 Glissandro no - it's not used anywhere
E4 Vibrato waveform no - always sine
E5 Fine-tune no
E6 Pattern loop no
E7 Tremolo waveform no
E9 Retrig note full support
EA Volume slide up jemně full support
EB Volume slide down jemně full support
EC Cut note full support
ED Note delay full support
EE Pattern delay no
EF Invert loop no
F Set speed/tempo full support

   Implemented effects should sound exactly as in Modplug tracker - I've used it and its sources almost as a standard. ;-)
   If you'll find any MOD that sounds differently than it should send it to me - I'll try to fix my code.

5. ProTracker format

   Last version of my MOD player was designed without detailed documentation so result was terrible but this time I've fortunately found some good specifications:

File Description
FH-MFDL2.ZIP Original documentation, simple description for most of tracker formats
MOD-FORM.TXT Detailed specification from some mid2mod utility
MODFILXX.TXT Detailed specification from MOD player TNT MP11

5.1 Conversion into ProTracker format

   Since there are only few good multichannel ProTracker files I've decided to try to convert some newer formats into it. Problem is that all newer formats have separated volume commands so there could be volume command and special command in one row at the time. Only solution is to manually solve/remove theese collisions.
   Next problem is that newer formats supports note frequency transposition to any sampling rate. One possible solution is to resample all samples to basic frequency 8363Hz but this is very bad idea for percussion instruments. Another possibility is to change playing periods instead of resampling. This could be done with simple utility I wrote for this purpose. The utility reads instructions from "*.ini" file where you must specify sample rates of each channel you want to convert. It also allows you to change order of channels. That could be usefull if source tracker hase different default panning than ProTracker.

Utility for download: (120kB).

6. Some records from MOD-player

   Here are some videos of my player in action. First video shows MOD player playing some 4 channel and then multichannel trackers. Second video shows a bit edited version that is cappable to play 28-channel monster tracker from well known demo Dope (I think best demo from that times).
   Last video is actually not from this player - it's from newer version that supports ScreamTracker 3 directly (well, ehm, almost ...), this player wasn't documented yet.

(c) 2011, Stanislav Maslan - All rights reserved.

Last update: 15.3.2011 Up