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

  1. { ------------------------------------------------------------------------ }
  2. {  @@ Source Documentation                           *** TP6 Version ***   }
  3. {                                                                          }
  4. {  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   }
  5. {                                                                          }
  6. {   TITLE       : DEMOVDR.PAS                                              }
  7. {                                                                          }
  8. {   DESCRIPTION :                                                          }
  9. {       This program demostrates how to perform voice recording using      }
  10. {       the CTVDSK.DRV driver. The voice recording is using the Disk       }
  11. {       Double 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 demovdr;
  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 GetCreateFileHandle (szFilename: String;                      }
  35. {                                 var Error: Boolean) : integer            }
  36. {                                                                          }
  37. {   DESCRIPTION:                                                           }
  38. {       Create a file with the filename specified and returns the file     }
  39. {       handle.                                                            }
  40. {                                                                          }
  41. {   ENTRY:                                                                 }
  42. {       szFilename :- filename to create                                   }
  43. {       Error :- Error flag                                                }
  44. {                                                                          }
  45. {   EXIT:                                                                  }
  46. {       File handle. Error flag set to True if error occurs.               }
  47. {                                                                          }
  48. { ------------------------------------------------------------------------ }
  49.  
  50. function GetCreateFileHandle (szFilename: String; var Error: Boolean) : integer;
  51. var
  52.     Regs : Registers;
  53.  
  54. begin
  55.     szFilename := szFilename + #0;
  56.     FillChar( Regs, SizeOf(Regs), 0 );
  57.     With Regs Do
  58.         begin
  59.             AX := $3c00;
  60.             DS := Seg(szFilename);
  61.             DX := Ofs(szFilename)+1;
  62.             CX := $20;
  63.         end;
  64.  
  65.     intr($21,Regs);
  66.  
  67.     if (Lo(Regs.Flags) And $01) > 0  then begin
  68.         Error := True;
  69.         GetCreateFileHandle := 0;
  70.     end
  71.     else begin
  72.         GetCreateFileHandle := Regs.AX;
  73.         Error := False;
  74.     end;
  75. end;
  76.  
  77.  
  78. { ------------------------------------------------------------------------ }
  79. {  @@ Usage                                                                }
  80. {                                                                          }
  81. {   procedure CloseFileHandle (Handle: integer)                            }
  82. {                                                                          }
  83. {   DESCRIPTION:                                                           }
  84. {       Close a file with file handle specified.                           }
  85. {                                                                          }
  86. {   ENTRY:                                                                 }
  87. {       Handle :- handle of file to be closed.                             }
  88. {                                                                          }
  89. {   EXIT:                                                                  }
  90. {       None.                                                              }
  91. {                                                                          }
  92. { ------------------------------------------------------------------------ }
  93.  
  94. procedure CloseFileHandle (Handle: integer);
  95. var
  96.     Regs : Registers;
  97.  
  98. begin
  99.     FillChar( Regs, SizeOf(Regs), 0 );
  100.     With Regs Do
  101.         begin
  102.             AX := $3e00;
  103.             BX := Handle;
  104.         end;
  105.  
  106.     intr($21,Regs);
  107.  
  108. end;
  109.  
  110.  
  111. { ------------------------------------------------------------------------ }
  112. {  @@ Usage                                                                }
  113. {                                                                          }
  114. {   procedure ShowError                                                    }
  115. {                                                                          }
  116. {   DESCRIPTION:                                                           }
  117. {       Display error occurred during the process of voice I/O.            }
  118. {                                                                          }
  119. {   ENTRY:                                                                 }
  120. {       None.                                                              }
  121. {                                                                          }
  122. {   EXIT:                                                                  }
  123. {       None.                                                              }
  124. {                                                                          }
  125. { ------------------------------------------------------------------------ }
  126.  
  127. procedure ShowError;
  128. var
  129.     Err : integer;
  130.  
  131. begin
  132.  
  133.     Err := ctvd_drv_error;
  134.     writeln('Driver error = ',Err);
  135.  
  136.     Err := ctvd_ext_error;
  137.     if (Err <> 0) then
  138.         writeln('DOS error = ',Err);
  139. end;
  140.  
  141.  
  142. { ------------------------------------------------------------------------ }
  143. {  @@ Usage                                                                }
  144. {                                                                          }
  145. {   procedure RecordUntilStopped                                           }
  146. {                                                                          }
  147. {   DESCRIPTION:                                                           }
  148. {       Starts voice recording. Press ESC key to terminate the recording.  }
  149. {                                                                          }
  150. {   ENTRY:                                                                 }
  151. {       None.                                                              }
  152. {                                                                          }
  153. {   EXIT:                                                                  }
  154. {       None.                                                              }
  155. {                                                                          }
  156. { ------------------------------------------------------------------------ }
  157.  
  158. procedure RecordUntilStopped;
  159. begin
  160.  
  161.     repeat
  162.         if keypressed then
  163.             if Readkey = #27 then
  164.                 ctvd_stop;
  165.  
  166.     until not boolean(_ct_voice_status);
  167.  
  168. end;
  169.  
  170.  
  171. { ------------------------------------------------------------------------ }
  172. {  @@ Usage                                                                }
  173. {                                                                          }
  174. {   procedure RecordFile (szFilename : string)                             }
  175. {                                                                          }
  176. {   DESCRIPTION:                                                           }
  177. {       Record voice with the filename specified.                          }
  178. {                                                                          }
  179. {   ENTRY:                                                                 }
  180. {       szFilename :- filename to be output.                               }
  181. {                                                                          }
  182. {   EXIT:                                                                  }
  183. {       None.                                                              }
  184. {                                                                          }
  185. { ------------------------------------------------------------------------ }
  186.  
  187. procedure RecordFile (szFilename : string);
  188. var
  189.     Handle: integer;
  190.     Error: Boolean;
  191.  
  192. begin
  193.  
  194.     Handle := GetCreateFileHandle(szFilename,Error);
  195.  
  196.     if not Error then begin
  197.         ctvd_speaker(0);
  198.  
  199.         if ctvd_input(Handle,8000) = 0 then begin
  200.             RecordUntilStopped;
  201.  
  202.             if ctvd_drv_error <> 0 then
  203.                 ShowError
  204.             else
  205.                 writeln('Voice record ended.');
  206.         end
  207.         else
  208.             ShowError;
  209.  
  210.         CloseFileHandle(Handle);
  211.     end
  212.     else
  213.         writeln('Create ',szFilename,' file error ...');
  214.  
  215. end;
  216.  
  217.  
  218. { ------------------------------------------------------------------------ }
  219.  
  220. var
  221.     lpDoubleBuf: pointer;
  222.  
  223. { main function }
  224. begin  { program body }
  225.  
  226.     if GetEnvSetting = 0 then begin
  227.  
  228.         if boolean( sbc_check_card and $0004 ) then begin
  229.  
  230.             if boolean(sbc_test_int) then begin
  231.  
  232.                 if sbc_test_dma >= 0 then begin
  233.  
  234.                     _ctvdsk_drv := LoadDriver('CTVDSK.DRV');
  235.  
  236.                     if _ctvdsk_drv <> nil then begin
  237.  
  238.                         { Allocate memory for Disk Double Buffer. }
  239.                         { Note the the program has to allocate 16 }
  240.                         { bytes more for paragraph adjust.        }
  241.  
  242.                         GetMem(lpDoubleBuf,61456);
  243.                         ctvd_buffer_addx(lpDoubleBuf,15);
  244.  
  245.                         if ctvd_init(15) = 0 then begin
  246.  
  247.                             ctvd_speaker(0);
  248.  
  249.                             RecordFile('TEMP.VOC');
  250.  
  251.                             ctvd_terminate;
  252.  
  253.                         end
  254.                         else
  255.                             ShowError;
  256.                     end;
  257.                 end
  258.                 else
  259.                     writeln('Error on DMA channel.');
  260.             end
  261.             else
  262.                 writeln('Error on interrupt.');
  263.         end
  264.         else
  265.             writeln('Sound Blaster card not found or wrong I/O setting.');
  266.     end
  267.     else
  268.         writeln('BLASTER environment variable not set or incomplete or invalid.');
  269.  
  270. end.
  271.