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

  1. { ------------------------------------------------------------------------ }
  2. {  @@ Source Documentation                           *** TP6 Version ***   }
  3. {                                                                          }
  4. {  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   }
  5. {                                                                          }
  6. {   TITLE       : DEMOVMP.PAS                                              }
  7. {                                                                          }
  8. {   DESCRIPTION :                                                          }
  9. {       This program demostrates how to perform voice out using the        }
  10. {       CT-VOICE.DRV driver. The voice out is using the Conventional       }
  11. {       memory 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 CT-VOICE.DRV into memory.                             }
  19. {                                                                          }
  20. { ------------------------------------------------------------------------ }
  21.  
  22. program demovmp;
  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. var
  34.     lpVoiceBuf : pointer;
  35.  
  36.  
  37. { ------------------------------------------------------------------------ }
  38. {  @@ Usage                                                                }
  39. {                                                                          }
  40. {   function LoadFile (szFilename : string) : Boolean                      }
  41. {                                                                          }
  42. {   DESCRIPTION:                                                           }
  43. {       Load file into memory.                                             }
  44. {                                                                          }
  45. {   ENTRY:                                                                 }
  46. {       szFileName :- File to be loaded.                                   }
  47. {                                                                          }
  48. {   EXIT:                                                                  }
  49. {       True if successful, else return False.                             }
  50. {                                                                          }
  51. { ------------------------------------------------------------------------ }
  52.  
  53. function LoadFile (szFilename : string) : Boolean;
  54. type
  55.     PtrRec = record
  56.         lo, hi : word
  57.     end;
  58.  
  59. var
  60.     wTemp, wByteRead : word;
  61.     lpTmpPtr : pointer;
  62.     lFSize : longint;
  63.     F : file;
  64.  
  65. begin
  66.     {$I-}
  67.     Assign(F, szFilename);
  68.     Reset(F,1);
  69.     {$I+}
  70.  
  71.     LoadFile := False;
  72.  
  73.     if IOResult = 0 then begin
  74.         lFSize := FileSize(F);
  75.  
  76.         { allocate memory }
  77.         Mark(lpVoiceBuf);
  78.  
  79.         repeat
  80.             wTemp := $8000;
  81.  
  82.             if lFSize < $8000 then
  83.                 wTemp := word(lFSize);
  84.  
  85.             GetMem(lpTmpPtr,wTemp);
  86.  
  87.             lFSize := lFSize - wTemp;
  88.         until not Boolean(Lo(word(lFSize)));
  89.  
  90.         if (lpTmpPtr <> nil) then begin
  91.             lpTmpPtr := lpVoiceBuf;
  92.             LoadFile := True;
  93.             wByteRead := 0;
  94.  
  95.             { Read data from file to buffer }
  96.             repeat
  97.                 BlockRead(F,lpTmpPtr^,$8000,wTemp);
  98.                 wByteRead := wByteRead + wTemp;
  99.  
  100.                 { advance pointer }
  101.                 PtrRec(lpTmpPtr).lo := PtrRec(lpTmpPtr).lo + wTemp;
  102.  
  103.                 { adjust when cross segment }
  104.                 if not Boolean(Hi(wByteRead)) then
  105.                     PtrRec(lpTmpPtr).hi := PtrRec(lpTmpPtr).hi + $1000;
  106.  
  107.             until wTemp <> $8000;
  108.         end
  109.         else
  110.             writeln('Memory allocation error ...');
  111.  
  112.         close(F);
  113.     end
  114.     else
  115.         writeln('Open ',szFilename,' error ...');
  116. end;
  117.  
  118.  
  119.  
  120. { ------------------------------------------------------------------------ }
  121. {  @@ Usage                                                                }
  122. {                                                                          }
  123. {   procedure OutputVoice                                                  }
  124. {                                                                          }
  125. {   DESCRIPTION:                                                           }
  126. {       Output voice from a memory buffer. The user is allowed to control  }
  127. {       the voice output from the keyboard.                                }
  128. {                                                                          }
  129. {   ENTRY:                                                                 }
  130. {       None                                                               }
  131. {                                                                          }
  132. {   EXIT:                                                                  }
  133. {       None                                                               }
  134. {                                                                          }
  135. { ------------------------------------------------------------------------ }
  136.  
  137. procedure OutputVoice;
  138. const
  139.     ESC     = 27;
  140.     up_P    = 80;
  141.     lo_p    = 112;
  142.     up_C    = 67;
  143.     lo_c    = 99;
  144.     up_B    = 66;
  145.     lo_b    = 98;
  146.     up_S    = 83;
  147.     lo_s    = 115;
  148.     EXT     = 256;
  149.  
  150. var
  151.     key : char;
  152.     keyval, dummy : integer;
  153.     lpBufPtr : pointer;
  154.     lTemp : Longint;
  155.  
  156. begin
  157.  
  158.     lTemp := Longint(lpVoiceBuf) + Longint((VOCHDR(lpVoiceBuf^)).voice_offset);
  159.     lpBufPtr := pointer(lTemp);
  160.  
  161.     ctvm_speaker(1);
  162.  
  163.     if ctvm_output(lpBufPtr) = 0 then begin
  164.         repeat
  165.             if keyPressed then begin
  166.                 key := ReadKey;
  167.                 keyval := ord(key);
  168.  
  169.                 if ((key = #0) and keypressed) then begin
  170.                     key := ReadKey;
  171.                     keyval := ord(key)+EXT;
  172.                 end;
  173.  
  174.                 case (keyval) of
  175.                     up_S,lo_s,ESC :
  176.                         ctvm_stop;
  177.                     up_P,lo_p :
  178.                         dummy := ctvm_pause;
  179.                     up_C,lo_c :
  180.                         dummy := ctvm_continue;
  181.                     up_B,lo_b :
  182.                         dummy := ctvm_break_loop(1);
  183.                 end;
  184.             end;
  185.         until not boolean(_ct_voice_status);
  186.     end;
  187.  
  188.     ctvm_speaker(0);
  189. end;
  190.  
  191.  
  192.  
  193. { ------------------------------------------------------------------------ }
  194.  
  195. { main function }
  196. var
  197.     wVersion : word;
  198.  
  199. begin  { program body }
  200.  
  201.     if GetEnvSetting = 0 then begin
  202.  
  203.         if boolean( sbc_check_card and $0004 ) then begin
  204.  
  205.             if boolean(sbc_test_int) then begin
  206.  
  207.                 if sbc_test_dma >= 0 then begin
  208.  
  209.                     _voice_drv := LoadDriver('CT-VOICE.DRV');
  210.  
  211.                     if _voice_drv <> nil then begin
  212.                         if ctvm_init = 0 then begin
  213.                             ctvm_speaker(0);
  214.                             wVersion := ctvm_version;
  215.                             writeln('     CT-VOICE version ',Hi(wVersion),
  216.                                     '.',Lo(wVersion):2);
  217.  
  218.                             if LoadFile('DEMO.VOC')  then begin
  219.                                 OutputVoice;
  220.                                 Release(lpVoiceBuf);
  221.                             end;
  222.  
  223.                             ctvm_terminate;
  224.                         end;
  225.                     end;
  226.                 end
  227.                 else
  228.                     writeln('Error on DMA channel.');
  229.             end
  230.             else
  231.                 writeln('Error on interrupt.');
  232.         end
  233.         else
  234.             writeln('Sound Blaster card not found or wrong I/O setting.');
  235.     end
  236.     else
  237.         writeln('BLASTER environment variable not set or incomplete or invalid.');
  238. end.
  239.