home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / LEDGERS / LEDG_07B.MSA / SOURCE / MR_MUSIC.V2 / MR_FORMT.TXT next >
Text File  |  1985-11-20  |  18KB  |  410 lines

  1.  
  2. Electronic Images presents:
  3.  
  4.                       //** MR MUSIC FILE FORMAT **\\
  5.  
  6.  
  7. First, a few words from The Phantom:
  8.  
  9. Hello my little diamonds!  Here, for your benefit/pleasure, is the Mr Music 
  10. file format structure so you can make your own .SNG files in whichever manner 
  11. you want, or to simply convert soundtracker (aggh!) format to Mr Music.
  12. Hope you find this information useful - contact me if you have any problems 
  13. (address below) or leave me some mail on CONTACT BBS (London England) on:
  14. +44 (081) 6460746 9PM to 9AM UK time.  You can also call it for other things 
  15. - it's the best board for your programming/demo/naughty needs!
  16.  
  17.  
  18.  
  19. SECTION 1 - Features.
  20.  
  21. Apart from being blindingly fast, Mr Music has several features which make it 
  22. a little bit more 'special'...
  23. Ability to manipulate over 32000 samples.
  24. Samples can be up to 64K in length.
  25. Extremely small .SNG file size.
  26. Plays from current sample pointer or start of sample (selectable).
  27. Looped samples (or vice versa) can be automatically made non-looped.
  28. It is not restricted by fixed length patterns.
  29. Has up to 255 pattern loops.
  30. Duration of a note/slide/rest up to 32767 units (about 10 minutes!).
  31. And a few more, but they're to do with the player itself.
  32.  
  33.  
  34. SECTION 2 - .SNG FILE FORMAT.
  35.  
  36. Mr Music files are so small because it works bit-wise.  Some may moan for the 
  37. 'slowness' of this method (which it isn't!!!);  The Phantom programmed Mr 
  38. Music mainly to emulate an expensive keyboard, not a 0.000% CPU time, 
  39. old-fashioned music driver.  The main advantage of this bit wise format 
  40. (apart from compactness) is that ALL operations are perfromed AT THE SAME 
  41. TIME.  Poor music drivers (like soundtracker and all the derivatives) perform 
  42. their functions one-at-a-time.  For example; in soundtracker or whatever, if 
  43. you want to play a note and slide it then the driver waits one frame (being 
  44. 1/50th second or whatever it is calibrated at) to play the note, then the 
  45. next to slide it.  This is hardly noticeable (actually you can't notice it AT 
  46. ALL!) but it's not right.  Mr Music does it the proper way - performing all 
  47. operations concurrently!!!
  48.  
  49.  
  50. SONG FORMAT
  51.  
  52. Simple - you have four 'channels', each channel's data is terminated by a 
  53. negative value of -9999.  Note that this NEEDS to be -9999 and NO OTHER.
  54. The four channels' data is one after the other.  That is, channel 1's data is 
  55. first, then a -9999, then channel 2's data, then -9999 and so on, until the 
  56. end of channel 4 (again, signalled by a WORD value of -9999).  While playing, 
  57. when -9999 is reached, the player will automatically loop to the start of the 
  58. channel's data and start again.
  59.  
  60. The actual musical data is governed by a command word, and acted on bitwise 
  61. and step-by-step.  That is, it starts processing bit 0, then 1 then 2... 
  62. Taking each bit's relevant data in step.
  63.  
  64.  
  65. Here's a quick summary.  The number of '1 W' means the number of WORDS 
  66. (2-byte values) that it needs as data.
  67.  
  68. COMMAND WORD:
  69.  
  70. Word (bits) - 0100000000001111
  71.                |__________||||___ Sustain.  Does auto sustain (0 = off).
  72.                           ||||
  73.                           |______ Rest. 1 W: Duration.
  74.                            |||
  75.                            |_____ Slide. 1 W: To note, 1 W: Speed, 1 W: Dur.
  76.                             ||
  77.                             |____ New note. 1 W: Note, 1 W: Duration.
  78.                              |
  79.                              |___ New sample. 1 W: Sample number.
  80.  
  81. (Dur. means duration.)
  82.  
  83. (Pattern loops will be explained later)
  84.  
  85.  
  86. BIT 15 - Sustain.
  87. This needs no data.  This bit in the command word just says that this sample 
  88. (if any) has a loop.  You can have sustain on non-loop samples; it will 
  89. simply loop from the start of the sample.
  90.  
  91. BIT 0  - New sample.
  92. This bit sets a new sample.  It does not play a new sample unless a note or 
  93. slide command is issued.
  94. It needs one WORD signifying the sample number (starting from 0).
  95.  
  96. BIT 1  - New note.
  97. This bit sets a new note - actually playing the sample at your required note.
  98. It needs two WORDS.  The first word is the note (0-63 with 31 being the 
  99. middle (440Hz) note).  The second word the duration in VBL's (in units of 
  100. 1/50th of a second at 50Hz or 1/60th of a second at 60hz).  So a duration 
  101. value of 25 will play the note for 1/2 a second at 50Hz.  Note that this is 
  102. also the time until the next command word is read.
  103.  
  104. BIT 2  - Slide.
  105. This performs a note slide.  For speed, it is not as 'smooth' as other 
  106. trackers, but used right, it is very good.
  107. It needs three WORDS.  The first word is the destination note it slides to 
  108. (from 0-63), the second word is the slide speed in 1/50ths of a second (or 
  109. 1/60th at 60Hz).  The third word is the duration of the slide.  If the slide 
  110. speed is 2, then slides are performed at 2/50ths of a second (or at 60Hz, 
  111. 2/60ths) and so on.  Please do not let the slide speed exceed the duration 
  112. time, otherwise it might go all strange!  Say the duration time is 30.  If it 
  113. has to slide from note 0 to note 63 every 2 units, then it will not reach the 
  114. destination note in time (2*63 = 126, which exceeds 30 by a lot!).  A slide 
  115. from note 10 to 20 at 3 units WILL just do it; 10-20= 10 notes to slide, * 3 
  116. units each = 30 duration units (just in, so it will work).  Note that slides 
  117. that fall well within the duration time will work - they sustain the 
  118. destination note for the remaining time until the next note or slide command. 
  119. One thing: the smaller the slide speed, the faster it will slide (1 being the 
  120. fastest and 32767 the slowest).
  121. Note that this is also the time until the next command word is read.
  122.  
  123. BIT 3 - Rest.
  124. This simply 'rests' (stops playing the sample) for the required time.
  125. It needs one WORD.  The word value is in 1/50ths of a second at 50Hz (or 
  126. 1/60ths of a second at 60Hz).  So a duration value of 50 would wait for 1 
  127. second (at 50Hz).  Note that this is also the time until the next commnd word 
  128. is read.
  129.  
  130.  
  131. Now's a little demonstration of a typical command sequence:
  132.  
  133. Example - Say we want to play a new sample with middle note... Then it would 
  134. look like this:  (DC.W in assembler is DEFINE CONSTANT of word length)
  135.  
  136.  dc.w  %0100000000000011
  137.  dc.w  0    Sample number.
  138.  dc.w  31   Note.
  139.  dc.w  6    Duration.
  140. Observe that the sustain (loop sample) bit is set.  The above sequence will 
  141. start playing a sample at middle note for 6 units.
  142.  
  143. And now, let's say that we only want to slide from the current note (which, 
  144. say, is 31) to a higher note (slide taking place immediately):
  145.  
  146.  dc.w  %0000000000000100
  147.  dc.w  41   Destination note.
  148.  dc.w  2    Speed of slide.
  149.  dc.w  80   Duration.
  150. Observe that the sustain (loop sample) bit is off (just to show that you can 
  151. toggle a sample's loop status on-the-fly!).  The above sequence (on hearing 
  152. it) will slide from middle note (assuming it WAS that) to a higher note and 
  153. hold it there until the duration ends (since the slide will get there before 
  154. the note ends).
  155.  
  156. How about a new (looped) sample (number 2) at note 40 sliding down to 30 with 
  157. duration 10?  Simple.
  158.  dc.w  %0100000000000111
  159.  dc.w  1    Sample number (remember, we start from 0).
  160.  dc.w  40   Note.
  161.  dc.w  99   Duration - this one is ignorend since the slide's dur. is taken.
  162.  dc.w  30   Slide to this note.
  163.  dc.w  1    Slide every 1 unit.
  164.  dc.w  10   Duration of 10 units.
  165.  
  166. Pattern loops:
  167. Each voice has INDEPENDENTLY handled loops.  That is, they have no fixed 
  168. sequence like soundtrackers - this means that the music has a much greater 
  169. scope for musical change & rhythm, but the downside of this method is that 
  170. you have to look out that all four channels loop at the same time, otherwise 
  171. the music will restart out of sync.  Mind you, you could always use this to 
  172. your advantage and make music NOT loop properly to get a sort-of infinite 
  173. length song!
  174.  
  175. Pattern loops are governed with a negative command word with the value of 
  176. -128 followed by the identical loop values (minus one) as two bytes - Eg 9,9 
  177. giving nine loops followed by a word containing the offset to the start of 
  178. the pattern to be looped.  Remember, that looping THREE times means that the 
  179. section will play ONCE, then loop THREE times (so you hear it four times).
  180. There is a maximum of 256 loops.
  181.  
  182. An example:
  183.  dc.w  -128   Signal pattern loop.
  184.  dc.b  3,3    Loop 3 times.  Remember, pair those loops!
  185.  dc.w  40     Loop back 40 bytes from here.  The loop offset.
  186. ...  Continues here after 3 loops.
  187.  The above shows a 40 byte pattern being looped 3 times (+1 played).
  188.  
  189. When it jumps back, it subtracts the loop offset value from the address where 
  190. the loop offset is.  To clarify, here's a pattern repeat command that will 
  191. loop back on itself and therefore stay doing that forever!
  192.  dc.w  -128   Signal pattern loop.
  193.  dc.w  1,1    Loop once (no matter - this example will loop forever!).
  194.  dc.w  4      Loop back 4 bytes from here.
  195.  
  196.  
  197. When a pattern has looped the required amount of times, it will 'fall though' 
  198. and continue on to the next command word.
  199.  
  200.  
  201. Bits & bobs:
  202.  
  203. There are 10 bits (10 commands) left in the command word.  These bits are 
  204. reserved for future versions; planned are:
  205. Volume control.
  206. Flange and digital distortion effects.
  207. Echo/room/hall/crossfade effects.
  208. Digital filtering.
  209. Infinite note range.
  210. All these features are NOT in this version simply because of speed and use. 
  211. When the right hardware comes along (like Atari's new Jaguar - we're hoping 
  212. that Atari have the good sense of making a computer out of it), or we figure 
  213. a way of doing any of the above without slowing Mr Music down too much.
  214.  
  215. A command word containing the word value -9999 will signify the end of
  216. that channel's song and will loop back to the start of the channel data.
  217.  
  218. NOTE:
  219. When a new note or slide is performed, the sample is not re-started.  This is 
  220. because of the end-sustain feature, where you can play a new note on a looped 
  221. sample without making it play from the start (this allows you to do some very 
  222. nice effects without a 'key release').  For example, say you have a looped 
  223. sample that is someone's voice saying "HELLO YOU" and when it loops it says 
  224. "YOU YOU YOU YOU..." and so on.  When you play a new note, it will play from 
  225. the "YOU YOU..." point, NOT from the start of the sample.  If you DO want the 
  226. slide or note to be in effect from the START of the sample (as in from the 
  227. "HELLO..." point) then you signal a NEW SAMPLE with the sample value.  This 
  228. allows you flexibility - you can play the sample from the start, or continue 
  229. from the current point (yay!).
  230.  
  231. Here's an example 4-channel song (note that all the other 3 channels are 
  232. empty, thus filled with a rest of 1 unit).  This is what a basic .SNG file 
  233. would look like.
  234.  
  235. CHANNEL 1.
  236.  dc.w  %0100000000000011        Play new sample (looped) and note.
  237.  dc.w  0                        Sample number (0 = first sample).
  238.  dc.w  63                       Note (63 is highest).
  239.  dc.w  50                       Duration (50 units = 1 second at 50Hz).
  240.  dc.w  -128                     Pattern loop.
  241.  dc.b  3,3                      Loop three times.
  242.  dc.w  12                       12 bytes back from here.
  243.  dc.w  %0100000000000100        Slide current note.
  244.  dc.w  31                       To note 31 (middle).
  245.  dc.w  1                        Speed.
  246.  dc.w  40                       Duration.
  247.  dc.w  %0100000000000101        Slide from sample start.
  248.  dc.w  0                        Sample number.
  249.  dc.w  40                       To note 40.
  250.  dc.w  2                        Speed.
  251.  dc.w  80                       Duration.
  252.  dc.w  -9999                    END OF CHANNEL 1.
  253. CHANNEL 2.
  254.  dc.w  %0000000000001000        Rest.
  255.  dc.w  1                        Duration of 1 unit.
  256.  dc.w  -9999                    END OF CHANNEL 2.
  257. CHANNEL 3.
  258.  dc.w  %0000000000001000        Rest.
  259.  dc.w  1                        Duration of 1 unit.
  260.  dc.w  -9999                    END OF CHANNEL 3.
  261. CHANNEL 4.
  262.  dc.w  %0000000000001000        Rest.
  263.  dc.w  1                        Duration of 1 unit.
  264.  dc.w  -9999                    END OF CHANNEL 4.
  265.  
  266. The above will play a few notes & slides on channel 1, while the other 
  267. channels are quiet (it doesn't matter that all the channels loop at the same 
  268. point, since only one channel is heard).  Note that any empty channels need 
  269. to be filled with a rest (of any duration).
  270.  
  271.  
  272. SECTION 3 - .EIT file structure.
  273.  
  274. Right, here's the sample (.EIT) file structure.
  275.  
  276. NOTE:  One of the principal speed factors of Mr Music is because of a naughty 
  277. trick The Phantom did with the sample ends (lately, it seems, people have 
  278. been using this technique for their trackers...  Wonder why??!!).  You NEED 
  279. to do this 'trick' otherwise the sample playback will not work plroperly.
  280. The one problem this has is that your samples are 1.4 K longer.  Yikes!  When 
  281. you have a lot of samples (even if they are 128 bytes each) then expect the 
  282. size to grow.  The reason is:
  283. Each sample has 1400 bytes (1.4K) tagged on at the end of it.  This is done 
  284. so the player has to do NO loop/end checks (saving about 10% CPU time or 
  285. more!!!).  If the sample has no loop, then you tag onto the end of it null 
  286. bytes with the value 128 (or any value but this works best) - remember, 1400 
  287. bytes of null data.  If it DOES have a loop, then tag 1400 bytes FROM the 
  288. loop start.  Say the sample is 4096 bytes long and the loop is at 230 bytes. 
  289. Then you tag 1400 bytes from start_of_sample+230 bytes.  A problem arises 
  290. when the loop point to the end of the sample is less than 1400 bytes in 
  291. length.  In this case, you keep copying from the loop pointer until you reach 
  292. 1400 bytes (E.G.  If the sample loop is at 23 bytes from the start of the 
  293. sample and there's only 60 bytes from there to the end of the sample) you 
  294. copy 37 (60-23) byte blocks until you reach 1400 bytes copied).
  295. With small samples with no loop, there's none of this since you merely tag on 
  296. 1400 bytes of null data.
  297. Note that the maximum length of a sample is 64K (65535 bytes).
  298.  
  299.  
  300. Data structure:
  301.  
  302. The first 'block' (of two) contains the sample offsets, lengths and loop 
  303. points.  The second 'block' contains the actual samples.
  304.  
  305. In the first 'block' the data is as follows.
  306. A LONGWORD (4-byte value) containing this instrument's offset from the end of 
  307. this block.  This is very simple to work out.  Just get the sample's address 
  308. and subtract it from the address of the start of your sample block.  Simple 
  309. as that!
  310. A WORD (2-byte value) containing the sample length.
  311. A WORD (2-byte value) containing thhe sample loop point (=0 if none).
  312.  
  313. ...  This continues for the number of instruments you have and then to signal 
  314. the end of the block you put in a negative WORD (2-byte value) as the sample 
  315. offset (for example, a -9999).  Immediately after that the sample data 
  316. starts; note that you do not need to mark the end of the sample data block.
  317.  
  318. To make things clearer, here's a little assembly listing to help you.  It 
  319. does not have any 68000 code, so it should be pretty simple!
  320.  
  321.  
  322. slist:         dc.l    bdru-soffs   <- Sample offset (note the calculation)..
  323.                dc.w    1848,0
  324.                         |   |_________ Sample loop (none here, so zero).
  325.                         |_____________ Sample length.
  326.  
  327. That's the first instrument...  We have more, so we continue...
  328.                dc.l    snar-soffs
  329.                dc.w    2156,0
  330.                dc.l    hhop-soffs
  331.                dc.w    2621,0
  332.                dc.l    orga-soffs
  333.                dc.w    4886,319
  334.                dc.l    synt-soffs
  335.                dc.w    14701,0
  336.                dc.l    wobb-soffs
  337.                dc.w    6101,2428
  338.                dc.l    stre-soffs
  339.                dc.w    4886,913
  340.                dc.l    panf-soffs
  341.                dc.w    12936,4754
  342.                dc.l    hhop-soffs
  343.                dc.w    2621,0
  344.                dc.l    bas2-soffs
  345.                dc.w    6875,0
  346.                dc.l    solo-soffs
  347.                dc.w    3811,0
  348.                dc.l    brig-soffs
  349.                dc.w    4170,0
  350.                dc.l    barr-soffs
  351.                dc.w    5280,0
  352.                dc.l    mono-soffs
  353.                dc.w    4900,0
  354.                dc.l    funk-soffs
  355.                dc.w    3932,0
  356.                dc.l    maxb-soffs
  357.                dc.w    1694,517
  358.                dc.w    -9999        <- Finally, the terminator word.
  359.  
  360. Right, and now the samples.  INCBIN for those non-assembler types is a 
  361. command used in the assembler to load in a binary file (like a picture).
  362.  
  363. soffs:          <- We use this 'address' to get the sample offsets.
  364.  
  365. bdru:           incbin  bdru.spl
  366. snar:           incbin  snar.spl
  367. hhop:           incbin  hhop.spl
  368. orga:           incbin  orga.spl
  369. synt:           incbin  synt.spl
  370. wobb:           incbin  wobb.spl
  371. stre:           incbin  stre.spl
  372. panf:           incbin  panf.spl
  373. bas2:           incbin  bas2.spl
  374. solo:           incbin  solo.spl
  375. brig:           incbin  brig.spl
  376. barr:           incbin  barr.spl
  377. mono;           incbin  mono.spl
  378. funk:           incbin  funk.spl
  379. maxb:           incbin  maxb.spl
  380.  
  381.  
  382. SECTION 4 - THE END.
  383.  
  384. Right, if you have any problems or questions, then either contact The Phantom 
  385. via Contact BBS (details above), or via mail:
  386.  
  387. The Phantom
  388. 21 Bledlow House
  389. Capland Street
  390. London
  391. NW8 8RU
  392. ENGLAND
  393.  
  394. Please note that if you want anything on disk/s, send the required disk/s so 
  395. that poor Phantom can put the software on them.
  396.  
  397.  
  398. Members of Electronic Images are:
  399.   Gizmo
  400.     The Phantom
  401.       Nightowl
  402.         Count Zero
  403.           Griff
  404.             Master
  405.  
  406.  
  407. This has been an Electronic Images production!
  408.  
  409.  
  410.