Copyright (C) 1991 by Klaus Pedersen. NT_COMP is a Public Domain program by Klaus Pedersen Nyborgvej 217 4. TH DK-5220 Odense Sē Denmark EMAIL : micro@imada.dk --------------------------------------------------------------------- / / / / / / / / INTRODUCTION / / / / / / / / / / / / / / / / / / / / --------------------------------------------------------------------- You should check that you have the following files in the NT_COMP directory: NT_COMP\ NT_COMP.PRG ; THE program NT_COMP.RSC ; - and it's resource file. SEGMPLAY.TTP ; A SEGM-file player for ST/STe and TT. SOUND\ ; might be empty DOCS\ ; NT_COMP.TXT ; This document. SOURCE\ ; The source to the SEGMPLAY.TTP PLAY_SEG.PRJ ; Project file for TC. PLAY_SEG.C ; The SEGMPLAY C-source... TINYSTRT.S ; My startup code (small) SAM_PLAY.S ; SEGM players for ROM,PRN,GI, STe/TT SAM_PLAY.H ; Function Prototype Sample player. MXALLOC.S ; Implementation of a ST/TT malloc. MXALLOC.H ; Prototype and manual page. DAC.S ; Table to get 8 bit output on the GI-chip What is NT_COMP? What can it do? - and what do I need? NT_COMP is a Compiler for 'NoiseTracker' music modules, which is pretty popular on the Amiga. NT_COMP is fully compatible with NoiseTracker v2.0 (except that you can't flip the power-on LED ;-) ). As many other hackers I have made NT-players for the ST(e), but I don't like using 1/5-1/2 of the processor to emulate Amiga chips, esp. when it is not absolutely needed. What really surprises me is that, even today, many people haven't figured out how to use the DMA in the STe and TT. In order to get really high quality sound from the STe/TT it is necessary to use the DMA, if you don't, you get a lot of hizz and high pitch noise. DIGI-COMPOSER is one of the LOFI products (sound-wise). You can recognize a LOFI product on the sample rate. For example if you see a sample sequencer for the STe, that says that it uses a sample rate of 10KHz or 16KHz it is a LOFI product! HIFI products can only use sample rates of 6.25, 12.5, 25, 50 KHz. Module players for ST computers have one big problem, they have to be very fast, which means that all programmers have to sacrifice the quality of the sound to gain the speed a 'realtime' player needs. Many players for standard ST's don't even support volume control on the voices! NT_COMP solves all these problems, by compiling the Modules. A compiled module uses 0.0% of the cpu when playing on the STe! It supports playback frequencies up to 50KHz (wasteful really). There is as a Option to use FAST scaling or PRECISION scaling. FAST uses the same principle as the realtime players. Precision scaling sounds way better! So be patient when compiling! What are the drawback then? The compiled modules (SEGM's) uses more memory. NT_COMP (should) run on all Atari ST, STe and TT computers in all resolutions, in colour and monocrome under GEM. The new TT memory are supported. Everything, except sound DMA, runs from TT memory if it is available. NT_COMP runs on ST's with 512Kb, but the more RAM the better! (I haven't tested the software on MEGA STe's, TT's and ST's with TOS 1.0). I assume that NT_COMP _DO_NOT_ run under KAOS (the TOS replacement)!! WHAT DO I DO? ------------- I would like you to contribute with : Ideas (for further developments) and code that you think needs to be included (I need compression code, filters and such). If this program shall improve and grow, then I need your help! Send in BUG-reports (I can't test the program on your computer - I need your help to do that!). If there is a thing you think is backward or silly let me know, _DO_NOT_ say "this is obvious, someone else have told him", tell me yourself! There are 3 ways to contact me : SNAIL MAIL EMAIL VOICE PHONE Klaus Pedersen micro@imada.dk 66 15 58 79 Nyborgvej 217 4.TH. (from Denmark) DK-5220 Odense Sē Denmark. What language should you write in? I prefer C and Assembler, and I don't understand a word Basic. You can fill in with Scandinavian, English and Modern (Computer) German... --------------------------------------------------------------------- / / / / / / / / CHAPTER 1 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / - HOW TO USE NT_COMP. / / / / / / / / / / / / / / / --------------------------------------------------------------------- I will try to describe the menus one at a time, and explain their interaction with each other... 'File' menu ----------- o Open - Load a file. There are 3 file name filters available: '*.MOD', '*.SEG', '*.*'. All tree Open's are equal, except for the the filter. NT_COMP recognizes SEGM files and 31 voice modules, and let you import 15 voice modules, offset binary and signed binary sample files. PLEASE NOTE: There is no way to know a 15 voice module from other file types, therefore be sure when you ask NT_COMP to import a 15 voice module, because you might crash NT_COMP, if the format is wrong or the file is corrupt!! o Save '*.SEG' - Saves the top window as a SEGM file. If the top window isn't a 'wave' window then this menu is disabled. If you have imported a sample file it will be saved as a SEGM file. o Quit - should be obvious... 'Action' menu ------------- The first two menus are enabled when the top window is a 'wave' window. o Show Sample Dist - Shows the distribution of the samples in the top wave window. The vertical resolution is 32, and there is indication for the largest and lowest sample value in the file. This function can take some time to finish. But provides some very importent information. Only one distribution window can be open at a time. o Play Image - this plays the SEGM in the top window. It uses the information set under the menu Set Replay. When playing a segment on a standard ST, you stop it by moving the mouse or touching the keyboard. On a STe/TT you select Play Image again to stop to sound. The sound can also stop at other times, for example when quitting the program. The next two menus are enabled when the top window is a 'module' window. o Compile - when you select this menu you can compile the module in the top window. You change the the parameters under the menu 'Compile Options'. o Edit Sequence - with this you can edit the module, take out the theme or remove intro and fade or set the repeat point. If you don't want the repeat, then press ESC in the 'repeat' edit field to clear it. See HINT #1 and HINT #2 below. 'Options' menu -------------- o Set Compile - Here you can set everything that have to do with the actual compiling of the module. Let us look at the adjusters one at a time. In the music section there is the o Tone adjuster - this adjusts the tone of the sound, if you double the value the sound will move up one octave (ie double the frequency). o Speed adjuster - with this you can change the playback speed, _NOT_ the tone. For more information read Chapter 2. To make a SEGM that should run at 25KHz, instead of 12.5KHz, you half the 'tone'-value the and double the 'speed'-value. This can also be done in the 'Set replay' dialog (see below). o Tolerance - can be used to pack even more music into the same space, but it degrades the music quality. The value is used when the compactor looks to see if a segment of the music already is in the file. 'tolerance' sets the maximum difference that will pass as equal. If 'Tolerance' = 0, an exact match is needed. If 'tolerance' = 2, then samples that is within the interval [-2; 2] of the original sample is equal, will pass as equal. In the section called 'Scaling', there is a switch select FAST or PRECISION scaling. If you select precision scaling you can adjust the a 'Scale value' to get full output swing, use Show Sample Dist to verify the distribution (some clipping improves the S/N ratio). Note that a larger the 'Scale value' gives smaller output. You can see if the output have been clipped by looking at the pins at -128 (leftmost pos) and at +127 (rightmost pos). The amount of clipping should not be too high to avoid metallic high pitch noise. Things are a bit more complicated when FAST have been selected, where it is possible to adjust the a clipping level. The clipping is used to ensure that, when the 4 voices are added together the result still is in the interval [-128; 127]. It don't have any meaning to make the interval less than [-32; 31], as this satisfies the about criteria, no matter how 'Scale value' is set. o Set Replay - Here you can set the sound output and the sample playing frequency. The Frequency control also changes 'Frame Size' and 'Tone' controls under 'Set Compile', to make generation of 6, 12, 25 and 50 KHz SEGM files possible. The build-in values are based on 50Hz modules. (see Chapter 2 for more information). o Set Memory - Under this menu you can see what the memory have been used to and the largest block of ST memory in the computer (the memory that holds the DMA sound images). Also under this menu, you can change the segment-list size. If you change the size, you will have to press the dialog button "RESET", to let it take action. This will unfortunately mean that all windows and memory is released to the system (you loose your work). HINT #1 ------- In order to get a click-free repeat you have to use a trick. Note that repeated patterns don't take up extra memory. Consider for example the sequence: [1,1,1,0,0] and you want a repeat from pos. 0 - If you did that there would be a click when it repeated. It is better to write the following sequence: [1,1,1,0,0,1] and then repeat from pos 1 (and not pos 0). The music is the same, but there is no click... An other example: [2,1,3,4,5](2) must be written as [2,1,3,4,5,3](3) to avoid the click. The music is the same, as you can see by expanding the loop. The first writes [2,1,3,4,5, 3,4,5, 3,4,5, ...] and the second [2,1,3,4,5,3, 4,5,3, 4,5,3, ...]. HINT #2 ------- To get keyboard shortcuts in dialogs and a easier editing of the sequence, I can recommend FORMDOIT written Dan Wilga, Gribnif Software. --------------------------------------------------------------------- / / / / / / / / CHAPTER 2 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / - TECHNICAL ISSUES. / / / / / / / / / / / / / / / / --------------------------------------------------------------------- WHY DOES THE MUSIC PLAY TO SLOW? ================================ This is probably because the music have been made on an american amiga. You can change this under the menu 'Options\ Set Compile\ Speed'. With this adjuster you can change the number of bytes in each frame. Each frame take 1/50 second or 1/60 seconds in an american module. To calculate the the frame length use : frame_length = play_freq * frame_time. For a play_freq = 12.5KHz and a frame_time = 20mS, the frame_length should be = 250, but because of a stupid optimation in the FAST scaling algorithm, it have to be divisible with 4... frame_length = 248 (giving a frame_time of 19.6 mS). If the module was made on an american amiga, the frame_length would be 208. NT_COMP have a set of 'Tone' and 'Speed' values for each of the possible playback frequencies (in Set Replay). These are based on a frame_time of 20mS. The values for 60Hz (american) modules is : Playback. Frame 6.259 KHz 104 bytes 12.517 KHz 208 bytes 25.034 KHz 416 bytes 50.068 KHz 832 bytes WHAT IS THE DIFF. BETWEEN FAST & PRECISION SCALING? =================================================== Fast scaling assumes that when the 4 voices is added together the result is between -128 and 127. The volume transfer function is made to guarantee this. In effect 6 bit resolution per voice! The Precision scaling uses 16 bit fixed point numbers and interpolation to get the exact values. EXAMPLE: -------- Take this example we have a signal sampled at 8 KHz, we now want to play it at 4 KHz. The signal is [0, 20, 40, 60, ...]. FAST would give, with full volume and ignoring the clip feature: [0, 0, 20, 20, 40, 40, 60, 60] PRECISION would give (with volume == 64): [0, 640, 1280, 1920, 2560, 3200, 3840] These values would be calculated for each channel, then added together and finally scaled and clipped to be in the interval -128 to 127. A SEGM PLAYER EXAMPLE ===================== In the directory DOCS\SOURCE\, there is the full source for the SEGM-file player 'SEGMPLAY'. To be check if the computer have Sound DMA, it checks the cookie jar to see if there is a '_SND' cookie installed. If DMA sound is listed as available it is used, else the ST sound chip is used... The SEGM file is loaded into ST memory that is allocated with the new GEMDOS function Mxalloc(), if it is available. The binding for this is also included. --------------------------------------------------------------------- / / / / / / / / APPENDIX A / / / / / / / / / / / / / / / / / / / / / / / / / / / / / - '.SEG' FILE FORMAT. / / / / / / / / / / / / / / / --------------------------------------------------------------------- The SEGM format reflects two needs, first the need to have a format modelled after the new Atari computers and second the need to have a fast compression scheme (TT and STe's uses 0.0% processor time when playing) a SEGM file. THE FILEFORMAT -------------- The file looks like this: typedef struct { SEGM_HEADER head; /* ID, and other info */ SEGMENT segments[n]; /* Tells what to play */ signed char image[m];/* this is the sound itself */ } SEGM_FILE; The file-header looks like this: typedef struct { LONG magic; /* == 'SEGM' - magic constant */ LONG freq; /* one of {'6.25', '12.5', '25.0', '50.0'}. */ WORD r_seg; /* start after end of list. -1 means no repeat */ } SEGM_HEADER; The segments can be used to repeat parts of the 'image' more time without using memory. A segment looks likes this: typedef struct { LONG offset; /* offset from start of sound image, -1 ends */ LONG length; /* the number of bytes to play from there. */ } SEGMENT; The Segment list ends with 'offset' == -1 (0xffffffff). After the segment list the sound image starts, at offset = 0. TO PLAY WITH 'SAM_PLAY' ----------------------- When a SEGM file have been loaded it is your responsibility to relocate it. The playback functions in SAM_PLAY.S assumes that each segment entry is of the following format: { signed char *samplestart; long length_of_sample_segment; } ie. SAM_PLAY expects a pointer to the start of the sample rather than a offset from the start! Note that 'samplestart' == -1, ends the segment-list. --------------------------------------------------------------------- / / / / / / / / APPENDIX B / / / / / / / / / / / / / / / / / / / / / / / / / / / / / - '.MOD' FILE FORMAT. / / / / / / / / / / / / / / / --------------------------------------------------------------------- There are two different versions of the modules - a 15 voice and a 31 voice. The two formats are not compatible, and there are hundreds of mutant versions. I have chosen to support a version that is called NoiseTracker 2.0 by M. & K. This is compatible with most 31 voice versions. NT_COMP also have a option to import 15 voice modules. LET'S LOOK AT IT ---------------- The module file is build this way : typedef struct { char mod_name[20]; INST insts[31]; /* or 15 if a old module */ char info[2]; /* info about repeat and nr of patterns */ char seq[128]; /* the sequence table for the patterns */ long id = 'M.K.' /* tells that this is a 31 voice module.*/ PATT patts[n]; char insts[m]; /* the samples for each instrument. */ } MOD_FILE An Instrument is declared in a 30 byte descriptor (why not 32??): typedef struct { char name[22]; UWORD length; /* offset to image of next instrument */ UWORD volume; UWORD transient_p; UWORD loop_p; } INST Each entry in pattern hold information to all 4 channels. The information for each channel is held in one 32 bit word. (each entry is then 16 bytes long). The information have been put in entry this way: + + + + + xxx-i-xx-ffffffffff-iiii-cccc-pppppppp * | | | | \______ parameter to command | | | \_____________ command | | \__________________ instrument (lsb's) | \___________________________ frequency (0-$400) \_____________________________________ msb of instrument nr. - the bits in a pattern entry. typedef long PAT_ENT; /* look about */ typedef struct { PAT_ENT chanl0; /* NO way to make independent tracks! */ PAT_ENT chanl1; PAT_ENT chanl2; PAT_ENT chanl3; } PATT; This is the reason I think that we should find a new format. I have a simple text based music language in mind. I should be possible to make small loops, for easy and trouble free rhythm tracks. And it should be possible to convert modules to this (more general) "language"... --------------------------------------------------------------------- / / / / / / / / APPENDIX C / / / / / / / / / / / / / / / / / / / / / / / / / / / / / - KNOWN BUGS. / / / / / / / / / / / / / / / / / / / --------------------------------------------------------------------- There are 2 shortcomings in the non DMA players (ROM, Printer and Sound chip players). 1. - they will only work if the computer runs at 8 MHz. 2. - They can't play in the background like the STe/TT player. NT_COMP treats you like an error-free master, whatever you say is law! - Also when that means that you loose everything you have made, when you change the segment list size, or quit! I included the FAST scale algorithm, that is a bug! It will disappear as soon as possible (or be reborn as a realtime-player).