home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / ast102.zip / ASTFORMA.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-05  |  10KB  |  299 lines

  1. {-------------------------------AST FORMAT-----------------------------------
  2. FIRST, i am really sorry for my ugly english
  3.  
  4. HERE IS AN EXEMPLE OF A TP7 PROCEDURE TO LOAD AN AST FILE
  5. {---------------------------------------------------------------------------}
  6.  
  7. {AWE SAMPLE***********************}
  8.  
  9. type aws= record
  10.       t:array[0..5] of longint;
  11.       loop:byte;
  12.       nom:string[8];
  13.       binf:byte;
  14.       end;
  15.   {t[0] :address in awe32 memory
  16.   t[1] :size of the sample in word
  17.   t[2] :begin position
  18.   t[3] :loop begin
  19.   t[4] :loop end
  20.   t[5] :base pitch
  21.         if you want to play sample send to
  22.         awe pitch register note*341.33+t[5]
  23.   loop: loop and $80 =1 ==> looping (don't matter, just care about t[3] & t[4]
  24.         loop and 1   =1 ==> sample in ram ,0==> sample in rom
  25.                             (don't matter, just care about t[0])
  26. binf: =16 ==>16 bits signed sample
  27.         7 ==> 8 bits signed sample
  28. awe playposition register:=t[0]+t[2]
  29. awe loop begin register  :=t[0]+t[3]
  30. awe loop end register :=t[0]+t[4]-2 ( i don't know if it's a bug,but
  31.                                       if you forget -2 you are going to have
  32.                                       noise at the end of sample
  33.         }
  34.  awss=record
  35.       t:array[0..15] of integer;
  36.       ad:longint;
  37.       end;
  38.   { it's sound data removed from awe32 memory
  39.    to avoid noise at the end of sample,only used by ast
  40.    don't care about that}
  41.  
  42. {AWE INSTRUMENT**************************************}
  43.  
  44. aweins=record
  45.        t:array[0..28] of byte;
  46.        nom:string[8];
  47.        flg:byte;
  48.        end;
  49. {t[0]:number of the sample associated
  50.  t[1]:pan level
  51.  t[2]:chorus level
  52.  t[3]:reverb level
  53.  t[4]:filter cut
  54.  t[5]:filterQ
  55.  t[6]:volume /awe volume register:= (t[4] shl 8) +not(current volume +t[6])
  56.  
  57. ENVELLOPE 1
  58.  t[7]:delay  /awe delay register:=(128-t[7]) shl 8
  59.  t[8]:sustain
  60.  t[9]:decay
  61.  t[10]:hold
  62.  t[11]:attack /awe hold attack register:=(127-t[10]) shl 8+(127-t[11])
  63.  t[12]:override/ awe sust dec register:=(t[12] shl 15)+(t[8] shl 8)+(127-t[9])
  64.  t[13]:env 1 to filter
  65.  t[14]:env 1 to pitch
  66.  
  67. ENVELLOPE 2
  68.  t[15]:delay /awe delay  register:=(128-t[15]) shl 8
  69.  t[16]:sustain
  70.  t[17]:decay
  71.  t[18]:hold
  72.  t[19]:attack /awe hold attack register:=(127-t[18]) shl 8+(127-t[19])
  73.  t[20]:override / awe sust dec register:=(t[20] shl 15)+(t[16] shl 8)+(127-t[17])
  74.  
  75. LFO1
  76.  t[21]: delay /delay register:= (128-t[21]) shl 8
  77.  t[22]: pitch
  78.  t[23]: to volume
  79.  t[24]: to pitch
  80.  t[25]: to filter
  81.  
  82. LFO2
  83.  t[26] :delay /delay register:=(128-t[26]) shl 8
  84.  t[27] :pitch
  85.  t[28] :to pitch
  86.  
  87. flg :decomposed in 8 bits
  88.      1st bit (flg and 1)  : set lfo1
  89.      2nd bit (flg and 2)  : set lfo2
  90.      3   bit (flg and 4)  : set filter
  91.      4   bit (flg and 8)  : set lfo1 pitch
  92.      5   bit (flg and 16) : set chorus level
  93.      6   bit (flg and 32) : set reverb level
  94.      7   bit (flg and 64) : set pan level
  95.      8   bit (flg and 128): set lfo2 pitch}
  96.  
  97.  
  98. {AWE DRUM INSTRUMENT************************************}
  99. awdrum=record
  100.        ist:byte;
  101.        f:word;
  102.        end;
  103. {ist : awe instrument
  104.  f: awe pitch register value}
  105.  
  106. {PATTERN************************************}
  107. pattern=record
  108.          pat_size:word;
  109.          pat:pointer;
  110.          end;
  111.  
  112. var
  113. header:string;   {header ='AST 0001'}
  114. def:byte;         {def is the definition (4 to 8);
  115.                   it's the number of commande in a time
  116.                   a pattern has 16*def lines}
  117.  
  118. tsm:word;        {size of the song message}
  119. sm:array[0..1000] of char;   {song message}
  120. no:byte;                     {size of the order}
  121. order:array[0..255] of byte; { order  , should be init to  255}
  122. fmin:array[0..127] of string[8];   { name of the FM instruments}
  123. fmi:array[0..127] of array[0..10] of byte;
  124.                    {----FM INSTRUMENTS---
  125.                    0: AM/VIB/EG/KSR/MULTI        M
  126.                    1:KSL/TOTAL LEVEL             O
  127.                    2: AR/DR                      D
  128.                    3: SL/RR                      U
  129.                    4: WAV SEL                    L
  130.  
  131.                    5: AM/VIB/EG/KSR/MULTI        C
  132.                    6:KSL/TOTAL LEVEL             A
  133.                    7: AR/DR                      R
  134.                    8: SL/RR                      R
  135.                    9: WAV SEL                    i
  136.  
  137.                    10: FB/CON}
  138. sample:array[0..127] of aws;
  139. svs:array[0..127] of awss;
  140. awei:array[0..127] of aweins;
  141. awd:array[0..35] of awdrum;
  142. {CHORUS AND REVERB****************************************}
  143. cht:byte;  {type of chorus }
  144. customch:array[0..4] of word; {customize chorus  data}
  145. custchname:string[8]; {customize chorus name}
  146. revt:byte; {type of reverb}
  147. custrevname:string[8]; {customize reverb name}
  148. customrev:array[0..27] of word; {customize reverb data}
  149. {**********************PATTERN DATA************************}
  150. pattab:array[0..254] of pattern;   {pattern data}
  151.  
  152. {the pattern have a little compression
  153.  1st byte :number of command used in a line of the pattern
  154.  2nf byte :track of the 1st command
  155.  3,4,5,6  :1st command data
  156.       7   :track of th 2nd command
  157.  8,9,10,11:2nd command data
  158.  
  159.   etc.. when you have red all the command of the line the next byte
  160.   is the number of command used at the 2nd line of the pattern and etc..
  161.  
  162.   there is 16*def lines in a pattern
  163.  
  164. command stucture
  165.  1st byte : note
  166.  2nd byte and 127 :volume
  167.  2nd byte and $80 : note off
  168.  3rd byte: effect
  169.  4   byte:effect value}
  170.  
  171.  
  172. {*************************************************************}
  173. procedure LOAD_AST_FILE( filename:string);
  174. var
  175. f:file;
  176. i,k:byte;
  177. fmpos,awpos,patpos,awesonpos,wavepos:longint;
  178. begin
  179. assign(f,filename);
  180. reset(f,1);
  181.  
  182. blockread(f,header,9);  {header must be 'AST 0001'}
  183. blockread(f,def,1);     {def is the definition (4 to 8);
  184.                          it's the number of commande in a time
  185.                          a pattern has 16*def lines}
  186.  
  187. blockread(f,tsm,2);      {size of the message}
  188. blockread(f,sm,tsm+1);   {read message}
  189.  
  190. blockread(f,no,1);        {size of the order}
  191. blockread(f,order,no+1);  {read order }
  192. blockread(f,fmpos,4);     {position of the FM instrument in the file}
  193. blockread(f,awpos,4);     {"  "  "  "  the AWE data( sample,instrument, chorus)}
  194. blockread(f,patpos,4);    {"  "  "  "  the patterns}
  195. blockread(f,awesonpos,4); {"  "  "  "  the awe sample data}
  196. blockread(f,wavepos,4);   {"  "  "  "  the wav data, not used yet}
  197.  
  198.    {INSTRUMENTS FM}
  199.    seek(f,fmpos);        {go at the right position}
  200.  
  201.    blockread(f,i,1);    {read first byte, if different of 255 then
  202.                          number of the 1st instrument}
  203.  
  204.    while i<255 do
  205.                begin
  206.                blockread(f,fmi[i],11); {data of instrument}
  207.                blockread(f,fmin[i],9); {name of the instrument}
  208.                blockread(f,i,1);       {number of the next instrument}
  209.                end;
  210.  
  211.   {SAMPLE AWE}
  212.   seek(f,awpos);    {go at the right position}
  213.   blockread(f,i,1); {read first byte, if different of 255 then
  214.                      number of the 1st sample}
  215.  
  216.   while i<255 do
  217.               begin
  218.               blockread(f,sample[i],35);  {sample parameter}
  219.               blockread(f,svs[i],16);     {reserved for ast}
  220.               blockread(f,i,1);           {next sample}
  221.               end;
  222.   {INSTRUMENT AWE}
  223.   blockread(f,i,1);{read first byte, if different of 255 then
  224.                     number of the 1st awe instrument}
  225.  
  226.   while i<255 do
  227.               begin
  228.               blockread(f,awei[i],39); {awe instrument data}
  229.               blockread(f,i,1);        {next instrument}
  230.               end;
  231.  
  232.   blockread(f,i,1); {read first byte, if different of 255 then
  233.                      number of the 1st awe drum instrument}
  234.  
  235.   while i<255 do
  236.               begin
  237.               blockread(f,awd[i],3); {awe drum instrument data}
  238.               blockread(f,i,1);      {next}
  239.               end;
  240.  
  241.   blockread(f,cht,1);   {read the type of chorus}
  242.   blockread(f,custchname,9);   {customize chorus name}
  243.   blockread(f,customch,10);       {customize chorus data}
  244.  
  245.   blockread(f,revt,1);  {read the type of reverb}
  246.   blockread(f,custrevname,9);  {customize reverb name}
  247.   blockread(f,customrev,56);      {customize reverb data}
  248.  
  249.   blockread(f,i,1);  {read a byte for future extension}
  250.  
  251.   {PATTERN}
  252. seek(f,patpos);   {go at the right place in the file}
  253. blockread(f,i,1); {read 1st byte if <> of 255 then it's the number of the
  254.                    1st pattern}
  255. while i<255 do
  256.       begin
  257.       blockread(f,pattab[i].pat_size,2);    {read size of the pattern}
  258.       if maxavail > pattab[i].pat_size then
  259.           begin
  260.           getmem(pattab[i].pat,pattab[i].pat_size);         {alloc memory}
  261.           blockread(f,pattab[i].pat^,pattab[i].pat_size);  {read pattern data}
  262.           end else pattab[i].pat_size:=16*def;   {not enough memory==>empty pattern
  263.                                       you should use an array[0..127] of byte,
  264.                                       full of 0 to point empty pattern}
  265.  
  266.       blockread(f,i,1);
  267.       end;
  268.  
  269.  {AWE SOUND DATA}
  270.  seek(f,awesonpos); {go at the right place in the file
  271.                    it' the sound data,
  272.   for each sample, size in the file in byte of sound data is
  273.                                                      t[1] for 8 bits sample
  274.                                                    2*t[1] for 16 bits sample
  275.    so read sound data of the first sample,2nd sample, etc..}
  276.  
  277.  
  278.  
  279. close(f);
  280. end;
  281.  
  282. begin
  283. end.
  284.  
  285. {I hope  it' s clear enough , but write me if you don't understand something
  286.  
  287.                        Patrice BOUCHAND
  288.                        LE BOURG
  289.                        42990 St Georges en couzan
  290.                        FRANCE
  291.  
  292.                                          See you soon...
  293.   and again,  thanks to Vince Vu  and Cygnus X-1     }
  294.  
  295.  
  296.  
  297.  
  298.  
  299.