home *** CD-ROM | disk | FTP | other *** search
- /* Comphone.pkg */
-
- var serverisroom=0;;
-
- typeof t=I;;
- typeof mainobj=ObjWin;;
-
- var state=0;;
- var t=nil;;
- var recording=0;;
- var playing=0;;
-
- typeof Alist=[S r1];;
-
- var Alist=nil;;
- var nBuffers=2;;
-
- typeof inbuf=S;;
- typeof outbuf=S;;
-
- var inbuf=nil;;
- var outbuf=nil;;
- var CloseAndPlay=0;;
- var CloseAndRecord=0;;
- var DontGetBuffers=0;;
-
- typeof codec=GsmCodec;;
- typeof codec2=GsmCodec;;
- typeof recon =ObjBitmap;;
- typeof recoff =ObjBitmap;;
- typeof playon =ObjBitmap;;
- typeof playoff =ObjBitmap;;
- typeof playmute =ObjBitmap;;
-
- defcom hear=hear S;;
- defcom entering=entering;;
- defcom GetAudio=GetAudio S;;
- defcom startaudio=startaudio;;
- defcom contact=contact;;
- defcom echo=echo S;;
-
- var Phonewindow=1;;
- var StopBTN=2;;
- var RefreshBTN=3;;
- var force_record=0;;
- var refresh=1;;
- var Frequency=11025;;
- var BufferSize=320;;
-
- typeof RecOpenCB =fun [SoundRec I] I;;
- typeof RecCloseCB =fun [SoundRec I] I;;
- typeof RecBufCB =fun [SoundRec I S I] I;;
- typeof PlayOpenCB =fun [SoundPlay I] I;;
- typeof PlayCloseCB =fun [SoundPlay I] I;;
- typeof PlayBufCB =fun [SoundPlay I I] S;;
-
- fun UpdateStatus ()=
- {
- if (playing==-1) then _BLTbitmap mainobj playmute 420 10
- else if (playing==1) then _BLTbitmap mainobj playon 420 10
- else _BLTbitmap mainobj playoff 420 10;
- if (recording==1) then _BLTbitmap mainobj recon 420 50
- else _BLTbitmap mainobj recoff 420 50; 0
- };;
-
- fun InitPhoneW ()=
- {
- 0
- };;
-
- fun DrawInPutBar (t)=
- {
- 0
- };;
-
- fun DrawOutPutBar (t)=
- {
- 0
- };;
-
- fun cutbypoints(l)=
- {
- if l==nil then [nil nil]
- else let l -> [a nxt] in
- if a==': then [nil l]
- else let cutbypoints nxt -> [x y] in [[a x] y]
- };;
-
- fun isIP(l)=
- {
- if l==nil then 1
- else let l -> [a nxt] in
- if a!='. && (a<'0 || a>'9) then 0
- else isIP nxt
- };;
-
- fun getcorresp(s)=
- {
- let cutbypoints strtolist s -> [a b] in
- if isIP a then s
- else strcat _gethostbyname listtostr a listtostr b
- };;
-
- fun DelAudio (l)=
- {
- if (l==nil) then
- {
- nil
- }
- else
- {
- let l->[s nxt] in
- {
- set Alist=nxt;
- s
- }
- }
- };;
-
- fun AddAudio (l,audio)=
- {
- if (l==nil) then
- {
- [audio nil]
- }
- else
- {
- let l->[s nxt] in
- [s (AddAudio nxt audio)]
- }
- };;
-
- fun stopplaysnd ()=
- {
- _sndPlayStop;
- 0
- };;
-
- fun startrecsnd ()=
- {
- if (recording==0) then
- {
- let (_sndRecStart _channel Frequency BufferSize*nBuffers 8 1)->res in
- if (res!=nil) then
- {
- _sndSetRflxRecOpen res RecOpenCB 0;
- _sndSetRflxRecClose res RecCloseCB 0;
- _sndSetRflxRecBuf res RecBufCB 0;
- set CloseAndRecord=0;
- set recording=1;
- 1
- }
- else
- {
- if (playing==1) then
- {
- set CloseAndRecord=1;
- stopplaysnd;
- 0
- }
- else
- {
- set CloseAndRecord=0;
- 0
- }
- }
- }
- else
- {
- 0
- }
- };;
-
- fun stoprecsnd ()=
- {
- _sndRecStop;
- 0
- };;
-
- fun startplaysnd ()=
- {
- set CloseAndPlay=0;
- if (playing==0) then
- {
- let (_sndPlayStart _channel Frequency BufferSize*nBuffers 8 1)->res in
- if (res!=nil) then
- {
- _sndSetRflxPlayOpen res PlayOpenCB 0;
- _sndSetRflxPlayClose res PlayCloseCB 0;
- _sndSetRflxPlayBuf res PlayBufCB 0;
- set playing=1;
- set DontGetBuffers=0;
- _sndUnsetPending;
- 1
- }
- else
- {
- if (recording==1) then
- {
- set CloseAndPlay=1;
- stoprecsnd;
- 0
- }
- else
- {
- set DontGetBuffers=1;
- 0
- }
- }
- }
- else
- {
- 0
- }
- };;
-
- fun mute()=
- set playing=-1;
- stopplaysnd;;
-
- fun unmute()=
- set playing=0;;
-
- fun _sndRecClose (srec,i)=
- {
- set recording=0;
- UpdateStatus;
- if (CloseAndPlay==1) then
- {
- startplaysnd;
- 0
- }
- else
- {
- 0
- }
- };;
-
- fun _sndRecOpen (srec,i)=
- {
- set recording=1;
- UpdateStatus;
- 0
- };;
-
- fun _sndPlayClose (splay,i)=
- {
- set playing=0;
- UpdateStatus;
- if (CloseAndRecord==1) then
- {
- startrecsnd;
- 0
- }
- else
- {
- 0
- }
- };;
-
- fun _sndPlayOpen (splay,i)=
- {
- set playing=1;
- UpdateStatus;
- 0
- };;
-
- fun _SoundGetBuffer (srec,i,buf,j)=
- {
- set inbuf=_AudioGsmEncode (_AudioUninterpol2 buf) codec;
- if (strlen inbuf)==nBuffers then
- {
- set inbuf=nil;
- DrawInPutBar nil;
- 0
- }
- else
- {
- _on _channel GetAudio [inbuf];
- DrawInPutBar buf;
- set inbuf=nil;
- 0
- }
- };;
-
- fun _SoundSetBuffer (splay,u,i)=
- {
- if (playing) then
- {
- set outbuf=DelAudio Alist;
- if ((strlen outbuf)==nBuffers)|(outbuf==nil) then
- {
- _sndSetPending;
- DrawOutPutBar nil;
- nil
- }
- else
- {
- _sndUnsetPending;
- let (_AudioInterpol2 _AudioGsmDecode outbuf codec2)->t in
- {
- DrawOutPutBar t;
- t
- }
- }
- }
- else
- {
- set outbuf=DelAudio Alist;
- let (_AudioInterpol2 _AudioGsmDecode outbuf codec2)->t in
- {
- DrawOutPutBar t;
- t
- }
- }
- };;
-
- fun PHONEInit()=
- {
- set RecOpenCB =@_sndRecOpen;
- set RecCloseCB =@_sndRecClose;
- set RecBufCB =@_SoundGetBuffer;
- set PlayOpenCB =@_sndPlayOpen;
- set PlayCloseCB =@_sndPlayClose;
- set PlayBufCB =@_SoundSetBuffer;
- set codec=_AudioGsmInit;
- set codec2=_AudioGsmInit;
- set recon =_LDbitmap _channel _checkpack "Comm/recon.bmp";
- set recoff =_LDbitmap _channel _checkpack "Comm/recoff.bmp";
- set playon =_LDbitmap _channel _checkpack "Comm/playon.bmp";
- set playoff =_LDbitmap _channel _checkpack "Comm/playoff.bmp";
- set playmute =_LDbitmap _channel _checkpack "Comm/playmute.bmp";
- };;
-
- fun HangUp ()=
- {
- if playing==1 then stopplaysnd else 0;
- if playing==1 then stoprecsnd else 0;
- set state=0;
- };;
-
- fun Record()=
- {
- UpdateStatus;
- set force_record=1;
- if (recording==1) then
- {
- 0
- }
- else
- {
- startrecsnd;
- 0
- }
- };;
-
- fun PauseRecord ()=
- {
- UpdateStatus;
- set force_record=0;
- if (playing==1) then
- {
- 0
- }
- else
- {
- stoprecsnd;
- 0
- }
- };;
-
- fun _paintevent (h)=
- {
- UpdateStatus;
- };;
-