home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / CAVE.ZIP / CTVOICE.PAS < prev    next >
Pascal/Delphi Source File  |  1995-02-05  |  8KB  |  497 lines

  1. Unit ctvoice;
  2.  
  3. Interface
  4.  
  5. Const
  6.   callok=0;
  7.   carderror=1;
  8.   ioporterror=2;
  9.   dmaerror=3;
  10.   spon=1;
  11.   spoff=0;
  12.   endbl=0;
  13.   nwsamplebl=1;
  14.   samplebl=2;
  15.   silencebl=3;
  16.   markerbl=4;
  17.   textbl=5;
  18.   repeatbl=6;
  19.   repeatendbl=7;
  20.   extrainfobl=8;
  21.   soundblaster=0;
  22.   soundblpro=1;
  23.   soundbl20=2;
  24.   mic=0;
  25.   cd_rom=1;
  26.   line=3;
  27.   mainvl=0;
  28.   voicevl=1;
  29.   micvl=2;
  30.   cd_romvl=3;
  31.   linevl=4;
  32.   both=0;
  33.   left=1;
  34.   right=2;
  35.   lowfilter=0;
  36.   highfilter=1;
  37.   outputfilter=0;
  38.   inputfilter=1;
  39.   stereo=1;
  40.   mono=0;
  41.   on=0;
  42.   off=1;
  43.  
  44. Type
  45.     intartype=array [0..$fff0] of byte;
  46.     voctp=record
  47.         start:pointer;
  48.         length:longint;
  49.         block:^intartype;
  50.     end;
  51.     proc=procedure;
  52.     proctp=^proc;
  53.  
  54. Var
  55.    statusword:word;
  56.    blockstart:^intartype;
  57.    blocklength:longint;
  58.    blocktype:byte;
  59.    continue:boolean;
  60.    cardtype:byte;
  61.    sbioresult:word;
  62.  
  63. Procedure loadctdriver(n:string);
  64. Function checkvocfile(n:string):boolean;
  65. Procedure loadvocfile(n:string; var v:voctp);
  66. Procedure savevocfile(n:string; v:voctp);
  67. Procedure disposevoc(var v:voctp);
  68. Function ctversion:word;
  69. Procedure useport(p:word);
  70. Procedure useirq(i:word);
  71. Procedure usechannel(d:word);
  72. Procedure initializedriver;
  73. Procedure speaker(w:word);
  74. Procedure stopvprocess;
  75. Procedure driveroff;
  76. Procedure userrout(p:proctp);
  77. Procedure askrate(var max,min:word; m,k:word);
  78. Procedure recordmode(b:word);
  79. Procedure input(s:word);
  80. Procedure recordingfilter(b:word);
  81. Procedure volume(s,c,v:word);
  82. Procedure filter(s,v:word);
  83. Procedure resetmixer;
  84. Procedure readallvolumes;
  85. Function returnvolume(s,v:word):word;
  86. Function returnfilter(s:word):word;
  87. Procedure pause;
  88. Procedure continueplaying;
  89. Procedure stoprepetition(i:word);
  90. Procedure playblock(v:voctp);
  91. Procedure playembblock(h:word; s:longint);
  92. Procedure recordsample(l:longint; sr:word; var v:voctp);
  93. Procedure recordembsample(sr:word; h:word; s:longint);
  94. Procedure firstsubblock(var v:voctp);
  95. Procedure nextsubblock(var v:voctp);
  96. Procedure volumetable(v:pointer; s:byte);
  97. Procedure echobuffer(e:pointer; s:word);
  98. Procedure command(s:string);
  99. Function cvolume:byte;
  100.  
  101. Implementation
  102.  
  103. Uses Dos;
  104.  
  105. var
  106.    ctaddress:pointer;
  107.    ctsize:longint;
  108.    r:registers;
  109.  
  110. {$L CTINTER.OBJ}
  111. {$F+}
  112. Procedure ctvoiceaddress(p:pointer); external;
  113. Procedure callctvoice(var r:registers); external;
  114. Procedure variables(stpt, bspt, blpt, btpt, copt:pointer); external;
  115. Procedure userroutine(p:proctp); external;
  116. {$F-}
  117.  
  118. procedure loadctdriver(n:string);
  119.  
  120. Var
  121.   f:file;
  122.   s:string[8];
  123.   off,sg:word;
  124.  
  125. Begin
  126.   if n='' then n:='ct-voice.drv';
  127.   assign(f,n); reset(f,1);
  128.   seek(f,2); blockread(f,s,9);
  129.   seek(f,0);
  130.   s[0]:=#8;
  131.   If s='CT-VOICE' then begin
  132.     ctsize:=filesize(f);
  133.     getmem(ctaddress,ctsize+16);
  134.     off:=ofs(ctaddress^);
  135.     sg:=seg(ctaddress^);
  136.     sg:=sg+off shr 4;
  137.     off:=off and 15;
  138.     If off<>0 Then Begin
  139.        Inc(sg);
  140.        off:=0;
  141.     end;
  142.     ctaddress:=ptr(sg,off);
  143.     blockread(f,ctaddress^,ctsize);
  144.     close(f);
  145.     ctvoiceaddress(ctaddress);
  146.     sbioresult:=0;
  147.   end
  148.   else begin
  149.          close(F);
  150.          sbioresult:=1;
  151.        end
  152. end;
  153.  
  154. Function checkvocfile(n:string):boolean;
  155.  
  156. var
  157.   f:file;
  158.   s:string[19];
  159.   t1,t2:word;
  160.   r:boolean;
  161.  
  162. begin
  163.   r:=false;
  164.   assign(f,n); reset(f,1);
  165.   blockread(f,s,19);
  166.   s[0]:=#18;
  167.   If s='Creative Voice File' Then Begin
  168.      seek(f,$16);
  169.      blockread(f,t1,2);
  170.      blockread(f,t2,2);
  171.      t1:=(t1 xor $ffff) + $1234;
  172.      r:=t1=t2;
  173.   end;
  174.   close(f);
  175.   checkvocfile:=r;
  176. end;
  177.  
  178. Procedure loadvocfile(n:string; var v:voctp);
  179.  
  180. var
  181.   f:file;
  182.   t:word;
  183.   sgh,ofh:word;
  184.   sge,ofe:word;
  185.   hs:longint;
  186.  
  187. Begin
  188.   Assign(f,n); reset(f,1);
  189.   seek(f,$14);
  190.   blockread(f,t,2);
  191.   seek(f,t);
  192.   v.length:=filesize(f)-T;
  193.   getmem(v.start,v.length);
  194.   blockread(f,v.start^,v.length);
  195.   close(f);
  196.   v.block:=v.start;
  197. End;
  198.  
  199. Procedure savevocfile(n:string; v:voctp);
  200.  
  201. var
  202.   f:file;
  203.   s:string;
  204.   t:word;
  205.  
  206. Begin
  207.   assign(f,n); rewrite(f,1);
  208.   s:='Creative Voice File'+#$1a;
  209.   blockwrite(f,s,20);
  210.   t:=$001a; blockwrite(f,t,2);
  211.   t:=$010a; blockwrite(f,t,2);
  212.   t:=(t-$1234) xor $ffff;
  213.   blockwrite(f,t,2);
  214.   blockwrite(f,v.start^,v.length);
  215.   close(f);
  216. end;
  217.  
  218. Procedure disposevoc(var v:voctp);
  219. begin
  220.   freemem(v.start,v.length);
  221.   v.start:=nil;
  222.   v.length:=0;
  223.   v.block:=nil;
  224. end;
  225.  
  226. Function ctversion:word;
  227. begin
  228.   r.bx:=0;
  229.   callctvoice(r);
  230.   ctversion:=r.ax
  231. end;
  232.  
  233. Procedure useport(p:word);
  234. begin
  235.   r.bx:=1;
  236.   r.ax:=p;
  237.   callctvoice(r);
  238.   sbioresult:=r.ax;
  239. end;
  240.  
  241. Procedure useirq(i:word);
  242. begin
  243.   r.bx:=2;
  244.   r.ax:=I;
  245.   callctvoice(r);
  246.   sbioresult:=r.ax;
  247. end;
  248.  
  249. Procedure usechannel(d:word);
  250. Begin
  251.   r.bx:=19;
  252.   r.ax:=d;
  253.   callctvoice(r);
  254.   sbioresult:=r.ax;
  255. end;
  256.  
  257. Procedure initializedriver;
  258. begin
  259.   r.bx:=3;
  260.   callctvoice(r);
  261.   if r.ax=0 then
  262.     variables(@statusword,@blockstart,@blocklength,@blocktype,@continue);
  263.   sbioresult:=r.ax;
  264. end;
  265.  
  266. Procedure speaker(w:word);
  267. begin
  268.   r.bx:=4;
  269.   r.ax:=w;
  270.   callctvoice(r);
  271. end;
  272.  
  273. Procedure stopvprocess;
  274. begin
  275.   r.bx:=8;
  276.   callctvoice(r);
  277. end;
  278.  
  279. Procedure driveroff;
  280. begin
  281.   r.bx:=9;
  282.   callctvoice(r);
  283. end;
  284.  
  285. Procedure userrout(p:proctp);
  286. begin
  287.   if p=nil then
  288.      userroutine(ptr(0,0))
  289.   else
  290.     userroutine(p);
  291. end;
  292.  
  293. Procedure askrate(var max,min:word; m,k:word);
  294. begin
  295.   r.bx:=26;
  296.   r.ax:=k;
  297.   r.dx:=m;
  298.   callctvoice(r);
  299.   max:=r.dx;
  300.   min:=r.ax;
  301. end;
  302.  
  303. Procedure recordmode(b:word);
  304. begin
  305.   r.ax:=b;
  306.   r.bx:=16;
  307.   callctvoice(r);
  308.   sbioresult:=r.ax;
  309. end;
  310.  
  311. Procedure input(s:word);
  312. begin
  313.   r.ax:=s;
  314.   r.bx:=17;
  315.   callctvoice(r);
  316.   sbioresult:=r.ax;
  317. end;
  318.  
  319. Procedure recordingfilter(b:word);
  320. begin
  321.   r.ax:=b;
  322.   r.bx:=18;
  323.   callctvoice(r);
  324.   sbioresult:=r.ax;
  325. end;
  326.  
  327. Procedure volume(s,c,v:word);
  328. begin
  329.   if c=both then begin
  330.      volume(s,left,v);
  331.      c:=right;
  332.   end;
  333.   r.ax:=2;
  334.   r.bx:=21;
  335.   r.cx:=v;
  336.   r.dx:=c;
  337.   callctvoice(r);
  338.   sbioresult:=r.ax;
  339. end;
  340.  
  341. Procedure filter(s,v:word);
  342. begin
  343.   r.ax:=s;
  344.   r.bx:=22;
  345.   r.cx:=v;
  346.   callctvoice(r);
  347.   sbioresult:=r.ax;
  348. end;
  349.  
  350. Procedure resetmixer;
  351. begin
  352.   r.bx:=23;
  353.   callctvoice(r);
  354. end;
  355.  
  356. Procedure readallvolumes;
  357. begin
  358.   r.bx:=24;
  359.   callctvoice(r);
  360. end;
  361.  
  362. Function returnvolume(s,v:word):word;
  363. begin
  364.   r.ax:=s;
  365.   r.bx:=25;
  366.   r.dx:=v;
  367.   callctvoice(r);
  368.   returnvolume:=r.ax;
  369. end;
  370.  
  371. Function returnfilter(s:word):word;
  372. begin
  373.   if ctversion=$20a then
  374.     r.bx:=27
  375.   else
  376.     r.bx:=26;
  377.   r.ax:=s;
  378.   callctvoice(r);
  379.   returnfilter:=r.ax;
  380. end;
  381.  
  382. Procedure pause;
  383. begin
  384.   r.bx:=10;
  385.   callctvoice(r);
  386.   sbioresult:=r.ax;
  387. end;
  388.  
  389. Procedure continueplaying;
  390. begin
  391.   r.bx:=11;
  392.   callctvoice(r);
  393.   sbioresult:=r.ax;
  394. end;
  395.  
  396. Procedure stoprepetition(i:word);
  397. begin
  398.   r.bx:=12;
  399.   r.ax:=i;
  400.   callctvoice(r);
  401.   sbioresult:=r.ax;
  402. end;
  403.  
  404. Procedure playblock(v:voctp);
  405. begin
  406.   r.bx:=6;
  407.   r.di:=ofs(v.start^);
  408.   r.es:=seg(v.start^);
  409.   callctvoice(R);
  410. end;
  411.  
  412. Procedure playembblock(h:word; s:longint);
  413. begin
  414.   r.bx:=14;
  415.   r.dx:=h;
  416.   r.di:=s shr 16;
  417.   r.si:=s and $ffff;
  418.   callctvoice(r);
  419.   sbioresult:=r.ax;
  420. end;
  421.  
  422. Procedure recordsample(l:longint; sr:word; var v:voctp);
  423. begin
  424.   getmem(v.start,l);
  425.   v.length:=l;
  426.   r.bx:=7;
  427.   r.ax:=sr;
  428.   r.dx:=l shr 16;
  429.   r.cx:=l and 65535;
  430.   r.es:=seg(v.start^);
  431.   r.di:=ofs(v.start^);
  432.   callctvoice(r);
  433. end;
  434.  
  435. Procedure recordembsample(sr:word; h:word; s:longint);
  436. begin
  437.   r.ax:=sr;
  438.   r.bx:=15;
  439.   r.dx:=h;
  440.   r.di:=s shr 16;
  441.   r.si:=s and $ffff;
  442.   callctvoice(r);
  443.   sbioresult:=r.ax;
  444. end;
  445.  
  446. Procedure firstsubblock(var v:voctp);
  447. begin
  448.   v.block:=v.start;
  449. end;
  450.  
  451. Procedure nextsubblock(var v:voctp);
  452. Var
  453.   a:longint;
  454.  
  455. begin
  456.   a:=16*longint(seg(v.block^))+longint(ofs(v.block^));
  457.   a:=a+4+v.block^[1]+256*v.block^[2]+256*256*v.block^[3];
  458.   v.block:=ptr(a shr 4, a and 15);
  459. end;
  460.  
  461. Procedure volumetable(v:pointer; s:byte);
  462. begin
  463.   r.bx:=128;
  464.   r.ax:=0;
  465.   r.cl:=s;
  466.   r.di:=ofs(v^);
  467.   r.es:=seg(v^);
  468.   callctvoice(r);
  469. end;
  470.  
  471. Procedure echobuffer(e:pointer; s:word);
  472. Begin
  473.   r.bx:=128;
  474.   r.ax:=1;
  475.   r.cx:=s;
  476.   r.di:=ofs(e^);
  477.   r.es:=seg(e^);
  478.   callctvoice(r);
  479. end;
  480.  
  481. Procedure command(s:string);
  482. begin
  483.   s:=s+#0;
  484.   r.bx:=129;
  485.   r.di:=ofs(s[1]);
  486.   r.es:=seg(s[1]);
  487.   callctvoice(r);
  488. end;
  489.  
  490. Function cvolume:byte;
  491. begin
  492.   r.bx:=130;
  493.   callctvoice(r);
  494.   cvolume:=r.al;
  495. end;
  496.  
  497. end.