home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / mwave2.zip / mwave.tp < prev    next >
Text File  |  1994-01-25  |  7KB  |  198 lines

  1. program makewave;
  2.  
  3. {
  4.  ***************************************************************************
  5.  *                                                                         *
  6.  *            Wave maker for SoundBlaster 1.5 by HaJott                    *
  7.  *                                                                         *
  8.  ***************************************************************************
  9.    Discription of data types :
  10.  
  11.    type
  12.       chunk = record
  13.         main               : string[4];             = RIFF
  14.         main_length        : array[0..3] of byte;   = length of file
  15.         chunk_type         : string[4];             = WAVE
  16.         sub_chunk          : string[4];             = fmt_ :_=space=ASCII 32
  17.         sub_chunk_length   : array[0..3] of byte;   = always 16 bytes
  18.                                                       don't know why !
  19.         format             : word;                  = always 1 for PCM mode
  20.                              every SoundBlaster works with format = 1
  21.         modus              : word;                  1 = mono, 2 = stereo
  22.         sample_freq        : array[0..3] of byte;   11.025 kHz = $2B11
  23.                                                     22.050 kHz = $5622
  24.                                                     44.100 kHz = $AC44
  25.         bytes_per_sec      : array[0..3] of byte;   as it is
  26.         bytes_per_sample   : word;                  1 = 8 Bit, 2 = 16 Bit
  27.         bits_per_sample    : word;                  only 8, 12 or 16
  28.         data_chunk         : string[4];             = data
  29.         data_length        : array[0..3] of byte;   length of data block
  30.       end;
  31.  
  32. }
  33.  
  34. {$N+,R-} {try E+ if you have a 486SX or if you have no x87}
  35.  
  36. uses dos,crt;
  37.  
  38.  type
  39.         w                  = word;
  40.         dw                 = array[0..3] of byte;
  41. {       w                  = array[0..1] of byte;}
  42. {       st                 = string[4]; }
  43.         dat                = array[1..16384] of byte;
  44.  
  45.       recordType = record
  46.         main               : dw{st} ;
  47.         main_length        : dw;
  48.         chunk_type         : dw{st};
  49.         sub_chunk          : dw{st};
  50.         sub_chunk_length   : dw;
  51.         format             : w;
  52.         modus              : w;
  53.         sample_freq        : dw;
  54.         bytes_per_sec      : dw;
  55.         bytes_per_sample   : w;
  56.         bits_per_sample    : w;
  57.         data_chunk         : dw{st};
  58.         data_length        : dw;
  59.         rf                 : dat;
  60.       end;
  61.     datafile = recordType;
  62.  
  63. var i,j,k,maxdat:integer;
  64.     datei1:file of datafile;
  65.     ri : byte;
  66.     x:extended;
  67.     stepx : real;
  68.     code:word;
  69.     p:pointer;
  70.     lenght : integer;
  71.     chunk                :  recordType;
  72.     step                 :  Integer;
  73.     bol                  :  Boolean;
  74.     wo                   :  word;
  75.     sinortri             :  char;
  76.  
  77.  
  78. { function Fsin works only with 387 or 486DX !!! }
  79.  
  80. function Fsin (a:EXTENDED):EXTENDED;
  81. begin
  82.      asm fld a END;
  83.      Inline($d9/$fe);
  84.      asm fstp a END;
  85.      fsin := a ;
  86. end;
  87.  
  88.  
  89. procedure initall;
  90. begin
  91.   x:=0; code:=0;i:=0;k:=0;j:=0;bol:=true;
  92.   chunk.main[0]:=ord('R');
  93.   chunk.main[1]:=ord('I');
  94.   chunk.main[2]:=ord('F');
  95.   chunk.main[3]:=ord('F');
  96.   chunk.main_length[0]:=45;
  97.   chunk.main_length[1]:=64;
  98.   chunk.main_length[2]:=0;
  99.   chunk.main_length[3]:=0;
  100.   chunk.chunk_type[0]:=ord('W');
  101.   chunk.chunk_type[1]:=ord('A');
  102.   chunk.chunk_type[2]:=ord('V');
  103.   chunk.chunk_type[3]:=ord('E');
  104.   chunk.sub_chunk[0]:=ord('f');
  105.   chunk.sub_chunk[1]:=ord('m');
  106.   chunk.sub_chunk[2]:=ord('t');
  107.   chunk.sub_chunk[3]:=ord(' ');
  108.   chunk.sub_chunk_length[0]:=16;
  109.   chunk.sub_chunk_length[1]:=0;
  110.   chunk.sub_chunk_length[2]:=0;
  111.   chunk.sub_chunk_length[3]:=0;
  112.   chunk.format:=1;
  113.   chunk.modus:=1;
  114.   chunk.sample_freq[0]:=17;
  115.   chunk.sample_freq[1]:=43;
  116.   chunk.sample_freq[2]:=0;
  117.   chunk.sample_freq[3]:=0;
  118.   chunk.bytes_per_sec[0]:=68;
  119.   chunk.bytes_per_sec[1]:=172;
  120.   chunk.bytes_per_sec[2]:=0;
  121.   chunk.bytes_per_sec[3]:=0;
  122.   chunk.bytes_per_sample:=4;
  123.   chunk.bits_per_sample:=8;
  124.   chunk.data_chunk[0]:=ord('d');
  125.   chunk.data_chunk[1]:=ord('a');
  126.   chunk.data_chunk[2]:=ord('t');
  127.   chunk.data_chunk[3]:=ord('a');
  128.   chunk.data_length[0]:=0;
  129.   chunk.data_length[1]:=40;
  130.   chunk.data_length[2]:=0;
  131.   chunk.data_length[3]:=0;
  132. for j:=1 to 16384 do chunk.rf[i]:=0;
  133. end;
  134.  
  135. begin
  136. clrscr;
  137. initall;
  138. writeln (' Wave maker for SoundBlaster 1.5 by HaJott ');
  139. writeln;
  140. writeln (' Enter number in () to create wave ');
  141. write ('Pulse wave (2), Sinus wave (1), triangle wave (0) : ');
  142. sinortri:=readkey;
  143. case sinortri of
  144. ('1') :
  145.       begin
  146.            stepx:=0.4;
  147.                {*** stepx makes the frequency, 0.4=low 0.8=high ***}
  148.            writeln;
  149.            writeln ('Make Sinus ');
  150.            for i:=1 to 16384 do
  151.              begin
  152.               chunk.rf[i]:=abs(round(127+127*Fsin(x)));
  153.               {this makes a sinus wave between 0 and 254 (8bit)}
  154.               {replace Fsin with sin if you have no x87 or 486DX}
  155.               x:=x+stepx;
  156.              end; {for i:=1 to 16384 do}
  157.       end;
  158. ('2') :
  159.       begin
  160.            i:=0;
  161.            step:=16;
  162.             {*** step makes the frequency, step=64 means low step=16 high}
  163.            maxdat:=16384 div (2*step);
  164.            writeln;
  165.            writeln ('Make Pulse ');
  166.            for k:=1 to maxdat do
  167.             begin
  168.              for j:=1 to step do begin inc(i); chunk.rf[i]:=0;end;
  169.              for j:=1 to step do begin inc(i); chunk.rf[i]:=255;end;
  170.              {*** makes a pulse wave between 0 and 255 (8bit) ***}
  171.             end; {for k:=1 to 256 do}
  172.        end
  173. else
  174.        begin {makes a triangle wave between 0 an 254 (8bit)}
  175.          writeln;
  176.          writeln ('Make Triangle ');
  177.          step:=8; {step makes the frequency, step=8 means low step=16 high}
  178.          while (i<=16384) do
  179.            begin
  180.              if chunk.rf[i]>=(255-step) then begin step:=-step;bol:=false;end;
  181.              if chunk.rf[i]<=(step) then begin step:=abs(step);bol:=true;end;
  182.              inc(i);
  183.              chunk.rf[i]:=chunk.rf[i-1]+step;
  184.            end;
  185.        end;
  186. end;{case}
  187.  
  188. writeln ('Size of complete Datafile : ',SizeOf(chunk));
  189. writeln ('Size of wave data : ',SizeOf(chunk.rf));
  190.   chunk.main_length[0]:=lo(SizeOf(chunk));
  191.   chunk.main_length[1]:=hi(SizeOf(chunk));
  192.   chunk.data_length[0]:=lo(SizeOf(chunk.rf));
  193.   chunk.data_length[1]:=hi(SizeOf(chunk.rf));
  194. assign(datei1,'c:\mmos2\sounds\aaa.wav');
  195. rewrite(datei1);
  196. write (datei1,datafile(chunk));
  197. close(datei1);
  198. end.