home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / TPASCAL / VOICE / DEMOVMR.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1991-09-27  |  10.9 KB  |  278 lines

  1. { ------------------------------------------------------------------------ }
  2. {  @@ Source Documentation                           *** TP6 Version ***   }
  3. {                                                                          }
  4. {  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   }
  5. {                                                                          }
  6. {   TITLE       : DEMOVMR.PAS                                              }
  7. {                                                                          }
  8. {   DESCRIPTION :                                                          }
  9. {       This program demostrates how to perform voice recording using the  }
  10. {       CT-VOICE.DRV driver. The voice recording is using the Conventional }
  11. {       memory method. The recording can be terminated by pressing ESC.    }
  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 CT-VOICE.DRV into memory.                             }
  19. {                                                                          }
  20. { ------------------------------------------------------------------------ }
  21.  
  22. program demovmr;
  23.  
  24. { Include the SBC Unit, and any other units needed }
  25. uses sbc_tp6, dos, crt;
  26.  
  27. { Include type-defined for VOC header }
  28. {$I sbcvoice.inc }
  29.  
  30. { Include load driver function }
  31. {$I loaddrv.pas  }
  32.  
  33.  
  34. { ------------------------------------------------------------------------ }
  35. {  @@ Usage                                                                }
  36. {                                                                          }
  37. {   function WriteToFile(var F: file; lpBuf: pointer;                      }
  38. {                        lSize: longint) : Boolean                         }
  39. {                                                                          }
  40. {   DESCRIPTION:                                                           }
  41. {       Write data from buffer to file.                                    }
  42. {                                                                          }
  43. {   ENTRY:                                                                 }
  44. {       F :- File where data to be written to.                             }
  45. {       lpBuf :- buffer to be written to file.                             }
  46. {       lSize :- Size to be written to file.                               }
  47. {                                                                          }
  48. {   EXIT:                                                                  }
  49. {       Return True if successful, else return False.                      }
  50. {                                                                          }
  51. { ------------------------------------------------------------------------ }
  52.  
  53. function WriteToFile (var F: file; lpBuf: pointer; lSize: longint) : Boolean;
  54. type
  55.     PtrRec = record
  56.         lo, hi : word
  57.     end;
  58.  
  59. var
  60.     wByteToWrite, wByteWritten, wTemp : word;
  61.  
  62. begin
  63.  
  64.     WriteToFile := True;
  65.     wTemp := 0;
  66.  
  67.     repeat
  68.         wByteToWrite := $8000;
  69.  
  70.         if lSize < $8000 then
  71.             wByteToWrite := Word(lSize);
  72.  
  73.         BlockWrite(F,lpBuf^,wByteToWrite,wByteWritten);
  74.  
  75.         if wByteWritten <> wByteToWrite then begin
  76.             writeln('Disk Full ...');
  77.             WriteToFile := False;
  78.             lSize := 0;
  79.         end
  80.         else begin
  81.             wTemp := wTemp + wByteWritten;
  82.  
  83.             { advance pointer }
  84.             PtrRec(lpBuf).lo := PtrRec(lpBuf).lo + wByteWritten;
  85.  
  86.             { adjust when cross segment }
  87.             if not Boolean(Hi(wTemp)) then
  88.                 PtrRec(lpBuf).hi := PtrRec(lpBuf).hi + $1000;
  89.  
  90.             lSize := lSize - wByteWritten;
  91.         end;
  92.     until not boolean(Lo(word(lSize)));
  93.  
  94. end;
  95.  
  96.  
  97. { ------------------------------------------------------------------------ }
  98. {  @@ Usage                                                                }
  99. {                                                                          }
  100. {   function Recording (lpBuf: pointer; lBufSize: longint) : Boolean       }
  101. {                                                                          }
  102. {   DESCRIPTION:                                                           }
  103. {       Start recording voice.                                             }
  104. {                                                                          }
  105. {   ENTRY:                                                                 }
  106. {       lpBuf :- buffer for voice recording.                               }
  107. {       lBufSize :- buffer size.                                           }
  108. {                                                                          }
  109. {   EXIT:                                                                  }
  110. {       True if successful, else return False.                             }
  111. {                                                                          }
  112. { ------------------------------------------------------------------------ }
  113.  
  114. function Recording (lpBuf: pointer; lpBufSize: longint) : Boolean;
  115. begin
  116.     Recording := False;
  117.     ctvm_speaker(0);
  118.  
  119.     if ctvm_input(lpBuf,lpBufSize,8000) = 0 then begin
  120.         Recording := True;
  121.         writeln('Start recording, press ESC key to terminate .....');
  122.  
  123.         repeat
  124.             if KeyPressed then
  125.                 if ReadKey = #27 then
  126.                     ctvm_stop;
  127.  
  128.         until not Boolean(_ct_voice_status);
  129.  
  130.         writeln('Recording end.');
  131.     end;
  132.  
  133. end;
  134.  
  135.  
  136. { ------------------------------------------------------------------------ }
  137. {  @@ Usage                                                                }
  138. {                                                                          }
  139. {   procedure SaveVoiceFile(szFilename: string; lpBuf: pointer)            }
  140. {                                                                          }
  141. {   DESCRIPTION:                                                           }
  142. {       Save recorded voice from memory to file.                           }
  143. {                                                                          }
  144. {   ENTRY:                                                                 }
  145. {       szFilename :- file name to be saved to.                            }
  146. {       lpBuf :- recorded voice buffer.                                    }
  147. {                                                                          }
  148. {   EXIT:                                                                  }
  149. {       None                                                               }
  150. {                                                                          }
  151. { ------------------------------------------------------------------------ }
  152.  
  153. procedure SaveVoiceFile (szFilename: string; lpBuf: pointer);
  154. var
  155.     F : file;
  156.     lVoiceSize, lTemp : longint;
  157.     header : VOCHDR;
  158.     dummy : boolean;
  159.     S : String[20];
  160.  
  161. begin
  162.     S := 'Creative Voice File';
  163.     move( S[1], header.id, 20 );
  164.     header.id[19] := #26;
  165.     header.voice_offset := SizeOf(VOCHDR);
  166.     header.version := $010a;
  167.     header.check_code := $1129;
  168.  
  169.     {$I-}
  170.     Assign(F, szFilename);
  171.     Rewrite(F,1);
  172.     {$I+}
  173.  
  174.     if IOResult = 0 then begin
  175.         if WriteToFile(F,@header,longint(SizeOf(VOCHDR))) then begin
  176.             lVoiceSize := longint( pointer(longint(lpBuf)+1)^ );
  177.             lVoiceSize := lVoiceSize and $00ffffff;
  178.  
  179.             { add 5 bytes for the bloack header and terminating block }
  180.             lVoiceSize := lVoiceSize + 5;
  181.  
  182.             dummy := WriteToFile(F,lpBuf,lVoiceSize);
  183.         end;
  184.  
  185.         Close(F);
  186.     end
  187.     else
  188.         writeln('Create ',szFilename,' error.');
  189.  
  190. end;
  191.  
  192.  
  193. { ------------------------------------------------------------------------ }
  194. {  @@ Usage                                                                }
  195. {                                                                          }
  196. {   procedure RecordVoice (szFilename: string)                             }
  197. {                                                                          }
  198. {   DESCRIPTION:                                                           }
  199. {       Record voice into a file with filename specified. 128 KB           }
  200. {       memory is allocated for voice recording.                           }
  201. {                                                                          }
  202. {   ENTRY:                                                                 }
  203. {       szFileName :- File to be recorded.                                 }
  204. {                                                                          }
  205. {   EXIT:                                                                  }
  206. {       None                                                               }
  207. {                                                                          }
  208. { ------------------------------------------------------------------------ }
  209.  
  210. procedure RecordVoice (szFilename: string);
  211. var
  212.     lpVoiceBuf, lpTmpPtr, lpMarkPtr : pointer;
  213.     lBufSize : longint;
  214.  
  215. begin
  216.  
  217.     { allocate memory 128 KB memory }
  218.     Mark(lpMarkPtr);
  219.     GetMem(lpVoiceBuf,$ffff);
  220.     GetMem(lpTmpPtr,$ffff);
  221.  
  222.     if (lpVoiceBuf <> nil) and (lpTmpPtr <> nil) then begin
  223.         lBufSize := $ffff + $ffff;
  224.  
  225.         if Recording(lpVoiceBuf,lBufSize) then
  226.             SaveVoiceFile(szFilename,lpVoiceBuf);
  227.     end
  228.     else
  229.         writeln('Memory allocation error ...');
  230.  
  231.     { release allocated memory }
  232.     Release(lpMarkPtr);
  233.  
  234. end;
  235.  
  236.  
  237. { ------------------------------------------------------------------------ }
  238.  
  239. { main function }
  240. begin  { program body }
  241.  
  242.     if GetEnvSetting = 0 then begin
  243.  
  244.         if boolean( sbc_check_card and $0004 ) then begin
  245.  
  246.             if boolean(sbc_test_int) then begin
  247.  
  248.                 if sbc_test_dma >= 0 then begin
  249.  
  250.                     _voice_drv := LoadDriver('CT-VOICE.DRV');
  251.  
  252.                     if _voice_drv <> nil then begin
  253.  
  254.                         if ctvm_init = 0 then begin
  255.  
  256.                             ctvm_speaker(0);
  257.  
  258.                             RecordVoice('TEMP.VOC');
  259.  
  260.                             ctvm_terminate;
  261.  
  262.                         end;
  263.                     end;
  264.                 end
  265.                 else
  266.                     writeln('Error on DMA channel.');
  267.             end
  268.             else
  269.                 writeln('Error on interrupt.');
  270.         end
  271.         else
  272.             writeln('Sound Blaster card not found or wrong I/O setting.');
  273.     end
  274.     else
  275.         writeln('BLASTER environment variable not set or incomplete or invalid.');
  276. end.
  277.  
  278.