From 6da7ae935f029695639604d6eba64660cc650822 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Fri, 13 Jan 2006 21:00:47 +0000 Subject: [PATCH] Added a simulation mode in which a specified SNR is generated. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/trunk@95 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- fivehz.f90 | 18 ++++++++++++++++++ gcom1.f90 | 3 ++- jtaudio.c | 8 ++++++-- wsjt.py | 21 ++++++++++++++++++--- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/fivehz.f90 b/fivehz.f90 index 32130fdae..df9950f62 100644 --- a/fivehz.f90 +++ b/fivehz.f90 @@ -209,3 +209,21 @@ subroutine fivehztx endif return end subroutine fivehztx + +subroutine addnoise(n) + integer*2 n + real r(12) + include 'gcom1.f90' + + if(txsnrdb.gt.90.0) return + snr=10.0**(0.05*(txsnrdb-1)) + call random_number(r) + x=sum(r)-6.0 + i=3000.0*x + n*snr*3000.0/32768.0 + if(i>32767) i=32767; + if(i<-32767) i=-32767; + n=i + + return +end subroutine addnoise + diff --git a/gcom1.f90 b/gcom1.f90 index 0ffc26b0c..e9515b5bd 100644 --- a/gcom1.f90 +++ b/gcom1.f90 @@ -11,6 +11,7 @@ real*8 rxdelay !Delay between PTT=1 and Tx audio SoundIn real*8 txdelay !Delay from end of Tx Audio and PTT=0 SoundOut real*8 samfacin !(Input sample rate)/11025 GUI real*8 samfacout !(Output sample rate)/11025 GUI +real*8 txsnrdb !SNR for simulations GUI integer*2 y1 !Ring buffer for audio channel 0 SoundIn integer*2 y2 !Ring buffer for audio channel 1 SoundIn integer nmax !Actual length of Rx ring buffers GUI @@ -41,7 +42,7 @@ integer mfsample2 !Measured sample rate, output SoundOut integer ns0 !Time at last ALL.TXT date entry Decoder common/gcom1/Tbuf(1024),ntrbuf(1024),Tsec,rxdelay,txdelay, & - samfacin,samfacout,y1(NRXMAX),y2(NRXMAX), & + samfacin,samfacout,txsnrdb,y1(NRXMAX),y2(NRXMAX), & nmax,iwrite,iread,iwave(NTXMAX),nwave,TxOK,Receiving,Transmitting, & TxFirst,TRPeriod,ibuf,ibuf0,ave,rms,ngo,level,mute,newdat,ndsec, & ndevin,ndevout,nx,mfsample,mfsample2,ns0 diff --git a/jtaudio.c b/jtaudio.c index 0df7a9808..1d17b4036 100644 --- a/jtaudio.c +++ b/jtaudio.c @@ -137,6 +137,7 @@ static int SoundOut( void *inputBuffer, void *outputBuffer, short *in = (short*)inputBuffer; short *wptr = (short*)outputBuffer; unsigned int i,n; + static short n2; static int n0; static int ia=0; static int ib=0; @@ -167,6 +168,7 @@ static int SoundOut( void *inputBuffer, void *outputBuffer, for(i=0 ; iTxOK) { + addnoise_(&data->iwave[ic]); *wptr++ = data->iwave[ic]; //left *wptr++ = data->iwave[ic]; //right ic++; @@ -177,8 +179,10 @@ static int SoundOut( void *inputBuffer, void *outputBuffer, } } else { - *wptr++ = 0; //left - *wptr++ = 0; //right + n2=0; + addnoise_(&n2); + *wptr++ = n2; //left + *wptr++ = n2; //right } } fivehztx_(); //Call fortran routine diff --git a/wsjt.py b/wsjt.py index 02371599a..8eed72d75 100644 --- a/wsjt.py +++ b/wsjt.py @@ -86,6 +86,7 @@ setseq=IntVar() ShOK=IntVar() slabel="Sync " textheight=7 +txsnrdb=99. TxFirst=IntVar() green=zeros(500,'f') im=Image.new('P',(500,120)) @@ -892,6 +893,9 @@ def clear_avg(event=NONE): avetext.configure(state=NORMAL) avetext.delete('1.0',END) avetext.configure(state=DISABLED) + f=open(appdir+'/decoded.ave',mode='w') + f.truncate(0) #Delete contents of decoded.ave + f.close() Audio.gcom2.nclearave=1 #------------------------------------------------------ defaults @@ -1225,7 +1229,7 @@ def plot_yellow(): def update(): global root_geom,isec0,naz,nel,ndmiles,ndkm,nhotaz,nhotabetter,nopen, \ im,pim,cmap0,isync,isync441,isync6m,isync65,isync_save,idsec, \ - first,itol + first,itol,txsnrdb utc=time.gmtime(time.time()+0.1*idsec) isec=utc[5] @@ -1335,6 +1339,16 @@ def update(): tx4.configure(bg='white') tx5.configure(bg='white') tx6.configure(bg='white') + if tx6.get()[:1]=='#': + try: + txsnrdb=float(tx6.get()[1:]) + if txsnrdb>-99.0 and txsnrdb<10.0: + Audio.gcom1.txsnrdb=txsnrdb + tx6.configure(bg='orange') + except: + txsnrdb=99.0 + else: + txsnrdb=99.0 if Audio.gcom2.monitoring and not Audio.gcom1.transmitting: bmonitor.configure(bg='green') else: @@ -1347,8 +1361,9 @@ def update(): # t="Transmitting: " # t="Txing: "+t[:nmsg] bgcolor='yellow' - if Audio.gcom2.sendingsh==1: bgcolor='#66FFFF' - if Audio.gcom2.sendingsh==-1: bgcolor='red' + if Audio.gcom2.sendingsh==1: bgcolor='#66FFFF' #Shorthand + if Audio.gcom2.sendingsh==-1: bgcolor='red' #Plain Text + if txsnrdb<90.0: bgcolor='orange' #Simulation mode if Audio.gcom2.ntxnow==1: tx1.configure(bg=bgcolor) elif Audio.gcom2.ntxnow==2: tx2.configure(bg=bgcolor) elif Audio.gcom2.ntxnow==3: tx3.configure(bg=bgcolor)