home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / TPASCAL / VOICE / DEMOVDP.PAS next >
Encoding:
Pascal/Delphi Source File  |  1991-10-29  |  12.3 KB  |  321 lines

  1. { ------------------------------------------------------------------------ }
  2. {  @@ Source Documentation                           *** TP6 Version ***   }
  3. {                                                                          }
  4. {  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   }
  5. {                                                                          }
  6. {   TITLE       : DEMOVDP.PAS                                              }
  7. {                                                                          }
  8. {   DESCRIPTION :                                                          }
  9. {       This program demostrates how to perform voice out using the        }
  10. {       CTVDSK.DRV driver. The voice out is using the Disk Double          }
  11. {       Buffering method.                                                  }
  12. {                                                                          }
  13. {       The program checks BLASTER environment for the Card settings.      }
  14. {       It also performs test base on BLASTER environment settings to      }
  15. {       ensure they are tally with the hardware settings on the Card.      }
  16. {                                                                          }
  17. {       Note that the program included the module LOADDRV.PAS to load      }
  18. {       the loadable CTVDSK.DRV into memory.                               }
  19. {                                                                          }
  20. { ------------------------------------------------------------------------ }
  21.  
  22. program demovdp;
  23.  
  24. { Include the SBC Unit, and any other units needed }
  25. uses sbc_tp6, dos, crt;
  26.  
  27. { Include load driver function }
  28. {$I loaddrv.pas  }
  29.  
  30.  
  31. { ------------------------------------------------------------------------ }
  32. {  @@ Usage                                                                }
  33. {                                                                          }
  34. {   function GetFileHandle (szFilename: String;                            }
  35. {                           var Error: Boolean) : integer                  }
  36. {                                                                          }
  37. {   DESCRIPTION:                                                           }
  38. {       Get the handle of a file with the filename specified.              }
  39. {                                                                          }
  40. {   ENTRY:                                                                 }
  41. {       szFilename :- filename to create                                   }
  42. {       Error :- Error flag                                                }
  43. {                                                                          }
  44. {   EXIT:                                                                  }
  45. {       File handle. Error flag set to True if error occurs.               }
  46. {                                                                          }
  47. { ------------------------------------------------------------------------ }
  48.  
  49. function GetFileHandle (szFilename: String; var Error: Boolean) : integer;
  50. var
  51.     Regs : Registers;
  52.  
  53. begin
  54.     szFilename := szFilename + #0;
  55.     FillChar( Regs, SizeOf(Regs), 0 );
  56.     With Regs Do
  57.         begin
  58.             AX := $3d00;
  59.             DS := Seg(szFilename);
  60.             DX := Ofs(szFilename)+1;
  61.         end;
  62.  
  63.     intr($21,Regs);
  64.  
  65.     if (Lo(Regs.Flags) And $01) > 0  then begin
  66.         Error := True;
  67.         GetFileHandle := 0;
  68.     end
  69.     else begin
  70.         GetFileHandle := Regs.AX;
  71.         Error := False;
  72.     end;
  73. end;
  74.  
  75.  
  76. { ------------------------------------------------------------------------ }
  77. {  @@ Usage                                                                }
  78. {                                                                          }
  79. {   procedure CloseFileHandle (Handle: integer)                            }
  80. {                                                                          }
  81. {   DESCRIPTION:                                                           }
  82. {       Close a file with file handle specified.                           }
  83. {                                                                          }
  84. {   ENTRY:                                                                 }
  85. {       Handle :- handle of file to be closed.                             }
  86. {                                                                          }
  87. {   EXIT:                                                                  }
  88. {       None.                                                              }
  89. {                                                                          }
  90. { ------------------------------------------------------------------------ }
  91.  
  92. procedure CloseFileHandle (Handle: integer);
  93. var
  94.     Regs : Registers;
  95.  
  96. begin
  97.     FillChar( Regs, SizeOf(Regs), 0 );
  98.     With Regs Do
  99.         begin
  100.             AX := $3e00;
  101.             BX := Handle;
  102.         end;
  103.  
  104.     intr($21,Regs);
  105.  
  106. end;
  107.  
  108.  
  109. { ------------------------------------------------------------------------ }
  110. {  @@ Usage                                                                }
  111. {                                                                          }
  112. {   procedure ShowError                                                    }
  113. {                                                                          }
  114. {   DESCRIPTION:                                                           }
  115. {       Display error occurred during the process of voice I/O.            }
  116. {                                                                          }
  117. {   ENTRY:                                                                 }
  118. {       None.                                                              }
  119. {                                                                          }
  120. {   EXIT:                                                                  }
  121. {       None.                                                              }
  122. {                                                                          }
  123. { ------------------------------------------------------------------------ }
  124.  
  125. procedure ShowError;
  126. var
  127.     Err : integer;
  128.  
  129. begin
  130.  
  131.     Err := ctvd_drv_error;
  132.     writeln('Driver error = ',Err);
  133.  
  134.     Err := ctvd_ext_error;
  135.     if (Err <> 0) then
  136.         writeln('DOS error = ',Err);
  137.  
  138. end;
  139.  
  140.  
  141. { ------------------------------------------------------------------------ }
  142. {  @@ Usage                                                                }
  143. {                                                                          }
  144. {   procedure PlayVoiceInBkgnd                                             }
  145. {                                                                          }
  146. {   DESCRIPTION:                                                           }
  147. {       Control voice plaing at the background using keyboard.             }
  148. {                                                                          }
  149. {   ENTRY:                                                                 }
  150. {       None.                                                              }
  151. {                                                                          }
  152. {   EXIT:                                                                  }
  153. {       None.                                                              }
  154. {                                                                          }
  155. { ------------------------------------------------------------------------ }
  156.  
  157. procedure PlayVoiceInBkgnd;
  158. const
  159.     ESC            = 27;
  160.     SPACE          = 32;
  161.     TAB            = 9;
  162.     CR             = 13;
  163.  
  164.     EXT            = 256;
  165.     LEFTARROW      = (EXT+75);
  166.     RIGHTARROW     = (EXT+77);
  167.  
  168. var
  169.     key : char;
  170.     keyval : integer;
  171.  
  172. begin
  173.  
  174.     repeat
  175.         if KeyPressed then begin
  176.             key := ReadKey;
  177.             keyval := ord(key);
  178.  
  179.             if ((key = #0) and keyPressed) then begin
  180.                 key := ReadKey;
  181.                 keyval := ord(key)+EXT;
  182.             end;
  183.  
  184.             case (keyval) of
  185.                 ESC :
  186.                     begin
  187.                         ctvd_stop;
  188.                         writeln('     Voice Stopped ....');
  189.                     end;
  190.  
  191.                 SPACE :
  192.                     begin
  193.                         ctvd_pause;
  194.                         writeln('     Pause ....');
  195.                         writeln('     Press any key to continue ....');
  196.                         key := Readkey;
  197.                         ctvd_continue;
  198.                     end;
  199.  
  200.                 CR :
  201.                     begin
  202.                         ctvd_break_loop(1);
  203.                         writeln('     Break-out takes place immediately ....');
  204.                     end;
  205.  
  206.                 TAB :
  207.                     begin
  208.                         ctvd_break_loop(0);
  209.                         writeln('     Break-out takes place after the',
  210.                                 ' current loop finishes ....');
  211.                     end;
  212.             end;
  213.         end;
  214.     until not boolean(_ct_voice_status);
  215.  
  216. end;
  217.  
  218.  
  219. { ------------------------------------------------------------------------ }
  220. {  @@ Usage                                                                }
  221. {                                                                          }
  222. {   procedure OutputFile (szFilename : string)                             }
  223. {                                                                          }
  224. {   DESCRIPTION:                                                           }
  225. {       Output voice with the filename specified.                          }
  226. {                                                                          }
  227. {   ENTRY:                                                                 }
  228. {       szFilename :- filename to be output.                               }
  229. {                                                                          }
  230. {   EXIT:                                                                  }
  231. {       None.                                                              }
  232. {                                                                          }
  233. { ------------------------------------------------------------------------ }
  234.  
  235. procedure OutputFile (szFilename : string);
  236. var
  237.     Handle: integer;
  238.     Error: Boolean;
  239.  
  240. begin
  241.  
  242.     Handle := GetFileHandle(szFilename,Error);
  243.  
  244.     if not Error then begin
  245.         ctvd_speaker(1);
  246.  
  247.         if ctvd_output(Handle) = 0 then begin
  248.             PlayVoiceInBkgnd;
  249.  
  250.             if ctvd_drv_error <> 0 then
  251.                 ShowError
  252.             else
  253.                 writeln('Voice output ended.');
  254.         end
  255.         else
  256.             ShowError;
  257.  
  258.         ctvd_speaker(0);
  259.  
  260.         CloseFileHandle(Handle);
  261.     end
  262.     else
  263.         writeln('Open ',szFilename,' error ...');
  264.  
  265. end;
  266.  
  267.  
  268. { ------------------------------------------------------------------------ }
  269.  
  270. var
  271.     lpDoubleBuf: pointer;
  272.  
  273. { main function }
  274. begin  { program body }
  275.  
  276.     if GetEnvSetting = 0 then begin
  277.  
  278.         if boolean( sbc_check_card and $0004 ) then begin
  279.  
  280.             if boolean(sbc_test_int) then begin
  281.  
  282.                 if sbc_test_dma >= 0 then begin
  283.  
  284.                     _ctvdsk_drv := LoadDriver('CTVDSK.DRV');
  285.  
  286.                     if _ctvdsk_drv <> nil then begin
  287.  
  288.                         { Allocate memory for Disk Double Buffer. }
  289.                         { Note the the program has to allocate 16 }
  290.                         { bytes more for paragraph adjust.        }
  291.  
  292.                         GetMem(lpDoubleBuf,61456);
  293.                         ctvd_buffer_addx(lpDoubleBuf,15);
  294.  
  295.                         if ctvd_init(15) = 0 then begin
  296.  
  297.                             ctvd_speaker(0);
  298.  
  299.                             OutputFile('DEMO.VOC');
  300.  
  301.                             ctvd_terminate;
  302.  
  303.                         end
  304.                         else
  305.                             ShowError;
  306.                     end;
  307.                 end
  308.                 else
  309.                     writeln('Error on DMA channel.');
  310.             end
  311.             else
  312.                 writeln('Error on interrupt.');
  313.         end
  314.         else
  315.             writeln('Sound Blaster card not found or wrong I/O setting.');
  316.     end
  317.     else
  318.         writeln('BLASTER variable environment not set or incomplete or invalid.');
  319.  
  320. end.
  321.