home *** CD-ROM | disk | FTP | other *** search
/ Treasure Hunt 2001 PRESSKIT / TH2001_PRESSKIT.iso / demo / scol_install / Partition / comm / comphone.pkg < prev    next >
Encoding:
Text File  |  2000-09-18  |  6.4 KB  |  376 lines

  1. /* Comphone.pkg */
  2.  
  3. var serverisroom=0;; 
  4.  
  5. typeof t=I;; 
  6. typeof mainobj=ObjWin;; 
  7.  
  8. var state=0;; 
  9. var t=nil;; 
  10. var recording=0;; 
  11. var playing=0;; 
  12.  
  13. typeof Alist=[S r1];; 
  14.  
  15. var Alist=nil;; 
  16. var nBuffers=2;; 
  17.  
  18. typeof inbuf=S;; 
  19. typeof outbuf=S;; 
  20.  
  21. var inbuf=nil;; 
  22. var outbuf=nil;; 
  23. var CloseAndPlay=0;; 
  24. var CloseAndRecord=0;; 
  25. var DontGetBuffers=0;; 
  26.  
  27. typeof codec=GsmCodec;; 
  28. typeof codec2=GsmCodec;; 
  29. typeof recon =ObjBitmap;; 
  30. typeof recoff =ObjBitmap;; 
  31. typeof playon =ObjBitmap;; 
  32. typeof playoff =ObjBitmap;; 
  33. typeof playmute =ObjBitmap;; 
  34.  
  35. defcom hear=hear S;; 
  36. defcom entering=entering;; 
  37. defcom GetAudio=GetAudio S;; 
  38. defcom startaudio=startaudio;; 
  39. defcom contact=contact;; 
  40. defcom echo=echo S;; 
  41.  
  42. var Phonewindow=1;; 
  43. var StopBTN=2;; 
  44. var RefreshBTN=3;; 
  45. var force_record=0;; 
  46. var refresh=1;; 
  47. var Frequency=11025;; 
  48. var BufferSize=320;; 
  49.  
  50. typeof RecOpenCB =fun [SoundRec I] I;; 
  51. typeof RecCloseCB =fun [SoundRec I] I;; 
  52. typeof RecBufCB =fun [SoundRec I S I] I;; 
  53. typeof PlayOpenCB =fun [SoundPlay I] I;; 
  54. typeof PlayCloseCB =fun [SoundPlay I] I;; 
  55. typeof PlayBufCB =fun [SoundPlay I I] S;; 
  56.  
  57. fun UpdateStatus ()= 
  58.   if (playing==-1) then _BLTbitmap mainobj playmute 420 10 
  59.   else if (playing==1) then _BLTbitmap mainobj playon 420 10 
  60.        else _BLTbitmap mainobj playoff 420 10; 
  61.   if (recording==1) then _BLTbitmap mainobj recon 420 50 
  62.   else _BLTbitmap mainobj recoff 420 50; 0 
  63. };; 
  64.  
  65. fun InitPhoneW ()= 
  66.   0 
  67. };; 
  68.  
  69. fun DrawInPutBar (t)= 
  70.   0 
  71. };; 
  72.  
  73. fun DrawOutPutBar (t)= 
  74.   0 
  75. };; 
  76.  
  77. fun cutbypoints(l)= 
  78.   if l==nil then [nil nil] 
  79.   else let l -> [a nxt] in 
  80.     if a==': then [nil l] 
  81.     else let cutbypoints nxt -> [x y] in [[a x] y] 
  82. };; 
  83.  
  84. fun isIP(l)= 
  85.   if l==nil then 1 
  86.   else let l -> [a nxt] in 
  87.     if a!='. && (a<'0 || a>'9) then 0 
  88.     else isIP nxt 
  89. };; 
  90.  
  91. fun getcorresp(s)= 
  92.   let cutbypoints strtolist s -> [a b] in 
  93.     if isIP a then s 
  94.     else strcat _gethostbyname listtostr a listtostr b 
  95. };; 
  96.  
  97. fun DelAudio (l)= 
  98.   if (l==nil) then 
  99.   { 
  100.     nil 
  101.   } 
  102.   else 
  103.   { 
  104.     let l->[s nxt] in 
  105.     { 
  106.       set Alist=nxt; 
  107.       s 
  108.     } 
  109.   }
  110. };; 
  111.  
  112. fun AddAudio (l,audio)= 
  113.   if (l==nil) then 
  114.   { 
  115.     [audio nil] 
  116.   } 
  117.   else 
  118.   { 
  119.     let l->[s nxt] in 
  120.       [s (AddAudio nxt audio)] 
  121.   } 
  122. };; 
  123.  
  124. fun stopplaysnd ()= 
  125.   _sndPlayStop; 
  126.   0 
  127. };; 
  128.  
  129. fun startrecsnd ()= 
  130.   if (recording==0) then 
  131.   { 
  132.     let (_sndRecStart _channel Frequency BufferSize*nBuffers 8 1)->res in 
  133.     if (res!=nil) then 
  134.     { 
  135.       _sndSetRflxRecOpen res RecOpenCB 0; 
  136.       _sndSetRflxRecClose res RecCloseCB 0; 
  137.       _sndSetRflxRecBuf res RecBufCB 0; 
  138.       set CloseAndRecord=0; 
  139.       set recording=1; 
  140.       1 
  141.     } 
  142.     else 
  143.     { 
  144.       if (playing==1) then 
  145.       { 
  146.         set CloseAndRecord=1; 
  147.         stopplaysnd; 
  148.         0 
  149.       } 
  150.       else 
  151.       { 
  152.         set CloseAndRecord=0; 
  153.         0 
  154.       } 
  155.     }
  156.   } 
  157.   else 
  158.   { 
  159.     0 
  160.   } 
  161. };; 
  162.  
  163. fun stoprecsnd ()= 
  164.   _sndRecStop; 
  165.   0 
  166. };; 
  167.  
  168. fun startplaysnd ()= 
  169.   set CloseAndPlay=0; 
  170.   if (playing==0) then 
  171.   { 
  172.     let (_sndPlayStart _channel Frequency BufferSize*nBuffers 8 1)->res in 
  173.     if (res!=nil) then 
  174.     { 
  175.       _sndSetRflxPlayOpen res PlayOpenCB 0; 
  176.       _sndSetRflxPlayClose res PlayCloseCB 0; 
  177.       _sndSetRflxPlayBuf res PlayBufCB 0; 
  178.       set playing=1; 
  179.       set DontGetBuffers=0; 
  180.       _sndUnsetPending; 
  181.       1 
  182.     } 
  183.     else 
  184.     { 
  185.       if (recording==1) then 
  186.       { 
  187.         set CloseAndPlay=1; 
  188.         stoprecsnd; 
  189.         0 
  190.       } 
  191.       else 
  192.       { 
  193.         set DontGetBuffers=1; 
  194.         0 
  195.       } 
  196.     } 
  197.   } 
  198.   else 
  199.   { 
  200.     0 
  201.   } 
  202. };; 
  203.  
  204. fun mute()= 
  205.   set playing=-1; 
  206.   stopplaysnd;; 
  207.  
  208. fun unmute()= 
  209.   set playing=0;; 
  210.  
  211. fun _sndRecClose (srec,i)= 
  212.   set recording=0; 
  213.   UpdateStatus; 
  214.   if (CloseAndPlay==1) then 
  215.   { 
  216.     startplaysnd; 
  217.     0 
  218.   } 
  219.   else 
  220.   { 
  221.     0 
  222.   } 
  223. };; 
  224.  
  225. fun _sndRecOpen (srec,i)= 
  226.   set recording=1; 
  227.   UpdateStatus; 
  228.   0 
  229. };; 
  230.  
  231. fun _sndPlayClose (splay,i)= 
  232.   set playing=0;
  233.   UpdateStatus; 
  234.   if (CloseAndRecord==1) then 
  235.   { 
  236.     startrecsnd; 
  237.     0 
  238.   } 
  239.   else 
  240.   { 
  241.     0 
  242.   } 
  243. };; 
  244.  
  245. fun _sndPlayOpen (splay,i)= 
  246.   set playing=1; 
  247.   UpdateStatus; 
  248.   0 
  249. };; 
  250.  
  251. fun _SoundGetBuffer (srec,i,buf,j)= 
  252.   set inbuf=_AudioGsmEncode (_AudioUninterpol2 buf) codec; 
  253.   if (strlen inbuf)==nBuffers then 
  254.   { 
  255.     set inbuf=nil; 
  256.     DrawInPutBar nil; 
  257.     0 
  258.   } 
  259.   else 
  260.   { 
  261.     _on _channel GetAudio [inbuf]; 
  262.     DrawInPutBar buf; 
  263.     set inbuf=nil; 
  264.     0 
  265.   } 
  266. };; 
  267.  
  268. fun _SoundSetBuffer (splay,u,i)= 
  269.   if (playing) then 
  270.   { 
  271.     set outbuf=DelAudio Alist; 
  272.     if ((strlen outbuf)==nBuffers)|(outbuf==nil) then 
  273.     { 
  274.       _sndSetPending; 
  275.       DrawOutPutBar nil; 
  276.       nil 
  277.     } 
  278.     else 
  279.     { 
  280.       _sndUnsetPending; 
  281.       let (_AudioInterpol2 _AudioGsmDecode outbuf codec2)->t in 
  282.       { 
  283.         DrawOutPutBar t; 
  284.         t 
  285.       } 
  286.     } 
  287.   } 
  288.   else 
  289.   { 
  290.     set outbuf=DelAudio Alist; 
  291.     let (_AudioInterpol2 _AudioGsmDecode outbuf codec2)->t in 
  292.     { 
  293.       DrawOutPutBar t; 
  294.       t 
  295.     } 
  296.   } 
  297. };; 
  298.  
  299. fun PHONEInit()= 
  300.   set RecOpenCB =@_sndRecOpen; 
  301.   set RecCloseCB =@_sndRecClose; 
  302.   set RecBufCB =@_SoundGetBuffer; 
  303.   set PlayOpenCB =@_sndPlayOpen; 
  304.   set PlayCloseCB =@_sndPlayClose; 
  305.   set PlayBufCB =@_SoundSetBuffer; 
  306.   set codec=_AudioGsmInit; 
  307.   set codec2=_AudioGsmInit; 
  308.   set recon =_LDbitmap _channel _checkpack "Comm/recon.bmp"; 
  309.   set recoff =_LDbitmap _channel _checkpack "Comm/recoff.bmp"; 
  310.   set playon =_LDbitmap _channel _checkpack "Comm/playon.bmp"; 
  311.   set playoff =_LDbitmap _channel _checkpack "Comm/playoff.bmp"; 
  312.   set playmute =_LDbitmap _channel _checkpack "Comm/playmute.bmp"; 
  313. };; 
  314.  
  315. fun HangUp ()= 
  316.   if playing==1 then stopplaysnd else 0; 
  317.   if playing==1 then stoprecsnd else 0; 
  318.   set state=0; 
  319. };; 
  320.  
  321. fun Record()= 
  322.   UpdateStatus; 
  323.   set force_record=1; 
  324.   if (recording==1) then 
  325.   { 
  326.     0 
  327.   } 
  328.   else 
  329.   {
  330.     startrecsnd; 
  331.     0 
  332.   } 
  333. };; 
  334.  
  335. fun PauseRecord ()= 
  336.   UpdateStatus; 
  337.   set force_record=0; 
  338.   if (playing==1) then 
  339.   { 
  340.     0 
  341.   } 
  342.   else 
  343.   { 
  344.     stoprecsnd; 
  345.     0 
  346.   } 
  347. };; 
  348.  
  349. fun _paintevent (h)= 
  350. UpdateStatus; 
  351. };;
  352.