var recording=0;; /* le client enregistre un son */ var playing=0;; /* le client reçoit un son */ typeof Alist=[S r1];; typeof cbrec=fun[S] I;; var nBuffers=2;; var CloseAndPlay=0;; var CloseAndRecord=0;; var DontGetBuffers=0;; typeof codec=GsmCodec;; typeof codec2=GsmCodec;; proto RecOpenCB =fun [SoundRec I] I;; proto RecCloseCB =fun [SoundRec I] I;; proto RecBufCB =fun [SoundRec I S I] I;; proto PlayOpenCB =fun [SoundPlay I] I;; proto PlayCloseCB =fun [SoundPlay I] I;; proto PlayBufCB =fun [SoundPlay I I] S;; proto _paintE = fun [ObjWin u0] I;; defcom Audio=Audio S S;; defcom AudioD=AudioD S S;; fun UpdateStatus ()= _paintE nil nil; 0;; fun DelAudio (l)= if l==nil then nil else let Alist -> [a n] in (set Alist=n; a);; fun AddAudio (l,audio,n)= if n==0 then nil else if l==nil then audio::nil else let l->[s nxt] in s::AddAudio nxt audio n-1;; fun stopplaysnd ()= _sndPlayStop;; fun startrecsnd ()= if (recording==0) then let (_sndRecStart _channel 5512 160*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;; fun startplaysnd ()= set CloseAndPlay=0; if (playing==0) then let (_sndPlayStart _channel 5512 160*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 RecCloseCB (srec,i)= set recording=0; UpdateStatus; if (CloseAndPlay==1) then startplaysnd else 0 ;; fun RecOpenCB (srec,i)= set recording=1; UpdateStatus; 0 ;; fun PlayCloseCB (splay,i)= set playing=0; UpdateStatus; if (CloseAndRecord==1) then startrecsnd else 0 ;; fun PlayOpenCB (splay,i)= set playing=1; UpdateStatus; 0 ;; fun RecBufCB (srec,i,buf,j)= exec cbrec with [_AudioGsmEncode buf codec];0;; fun PlayBufCB (splay,u,i)= if (playing) then let DelAudio Alist -> outbuf in if ((strlen outbuf)==nBuffers)||(outbuf==nil) then {_sndSetPending; nil } else {_sndUnsetPending; outbuf } else let DelAudio Alist->outbuf in outbuf ;; fun GetAudio (name,audio)= if recording then nil else if (playing==0) then {if (sizelist Alist)<2 then nil else startplaysnd; set Alist=AddAudio Alist _AudioGsmDecode audio codec2 30; 0 } else {set Alist=AddAudio Alist _AudioGsmDecode audio codec2 30; 0 } ;; fun iniAudio()= set codec=_AudioGsmInit; set codec2=_AudioGsmInit; 0 ;; fun HangUp ()= { if playing==1 then stopplaysnd else 0; if recording==1 then stoprecsnd else 0; };; fun Record()= UpdateStatus; if (recording==1) then 0 else startrecsnd ;; fun PauseRecord ()= UpdateStatus; if (playing==1) then 0 else stoprecsnd ;;