mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-27 14:48:46 -05:00
Changed soundin to i*2 rather than r*4.
Activated saving of WAV files. (but so far, without headers). Tx waveform now uses sinc() pulses. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/jtms3@2489 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
1ad65e34b3
commit
52172ce346
@ -6,7 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
extern struct { //This is "common/datcom/..." in Fortran
|
extern struct { //This is "common/datcom/..." in Fortran
|
||||||
float d4[30*48000]; //Raw data
|
float d2[30*48000]; //Raw data
|
||||||
int kin;
|
int kin;
|
||||||
int ndiskdat;
|
int ndiskdat;
|
||||||
/*
|
/*
|
||||||
|
65
getfile.cpp
65
getfile.cpp
@ -8,76 +8,39 @@ extern qint16 id[4*60*96000];
|
|||||||
|
|
||||||
void getfile(QString fname, bool xpol, int dbDgrd)
|
void getfile(QString fname, bool xpol, int dbDgrd)
|
||||||
{
|
{
|
||||||
int npts=2*52*96000;
|
|
||||||
if(xpol) npts=2*npts;
|
|
||||||
|
|
||||||
// Degrade S/N by dbDgrd dB -- for tests only!!
|
|
||||||
float dgrd=0.0;
|
|
||||||
if(dbDgrd<0) dgrd = 23.0*sqrt(pow(10.0,-0.1*(double)dbDgrd) - 1.0);
|
|
||||||
float fac=23.0/sqrt(dgrd*dgrd + 23.0*23.0);
|
|
||||||
|
|
||||||
memset(id,0,2*npts);
|
|
||||||
char name[80];
|
char name[80];
|
||||||
strcpy(name,fname.toAscii());
|
strcpy(name,fname.toAscii());
|
||||||
FILE* fp=fopen(name,"rb");
|
FILE* fp=fopen(name,"rb");
|
||||||
|
|
||||||
|
int npts=30*48000;
|
||||||
|
memset(datcom_.d2,0,2*npts);
|
||||||
|
|
||||||
if(fp != NULL) {
|
if(fp != NULL) {
|
||||||
// fread(&datcom_.fcenter,sizeof(datcom_.fcenter),1,fp);
|
// Should read WAV header first
|
||||||
fread(id,2,npts,fp);
|
fread(datcom_.d2,2,npts,fp);
|
||||||
int j=0;
|
|
||||||
|
|
||||||
if(dbDgrd<0) {
|
|
||||||
for(int i=0; i<npts; i+=2) {
|
|
||||||
datcom_.d4[j++]=fac*((float)id[i] + dgrd*gran());
|
|
||||||
datcom_.d4[j++]=fac*((float)id[i+1] + dgrd*gran());
|
|
||||||
if(!xpol) j+=2; //Skip over d4(3,x) and d4(4,x)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(int i=0; i<npts; i+=2) {
|
|
||||||
datcom_.d4[j++]=(float)id[i];
|
|
||||||
datcom_.d4[j++]=(float)id[i+1];
|
|
||||||
if(!xpol) j+=2; //Skip over d4(3,x) and d4(4,x)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/*
|
|
||||||
datcom_.ndiskdat=1;
|
|
||||||
int nfreq=(int)datcom_.fcenter;
|
|
||||||
if(nfreq!=144 and nfreq != 432 and nfreq != 1296) datcom_.fcenter=144.125;
|
|
||||||
int i0=fname.indexOf(".tf2");
|
|
||||||
if(i0<0) i0=fname.indexOf(".iq");
|
|
||||||
datcom_.nutc=0;
|
|
||||||
if(i0>0) datcom_.nutc=100*fname.mid(i0-4,2).toInt() +
|
|
||||||
fname.mid(i0-2,2).toInt();
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void savewav(QString fname)
|
void savewav(QString fname)
|
||||||
{
|
{
|
||||||
/*
|
int npts=30*48000;
|
||||||
int npts=2*52*96000;
|
// qint16* buf=(qint16*)malloc(2*npts);
|
||||||
if(xpol) npts=2*npts;
|
|
||||||
|
|
||||||
qint16* buf=(qint16*)malloc(2*npts);
|
|
||||||
char name[80];
|
char name[80];
|
||||||
strcpy(name,fname.toAscii());
|
strcpy(name,fname.toAscii());
|
||||||
FILE* fp=fopen(name,"wb");
|
FILE* fp=fopen(name,"wb");
|
||||||
|
|
||||||
if(fp != NULL) {
|
if(fp != NULL) {
|
||||||
fwrite(&datcom_.fcenter,sizeof(datcom_.fcenter),1,fp);
|
// Write a WAV header
|
||||||
int j=0;
|
// fwrite(&datcom_.fcenter,sizeof(datcom_.fcenter),1,fp);
|
||||||
for(int i=0; i<npts; i+=2) {
|
|
||||||
buf[i]=(qint16)datcom_.d4[j++];
|
// memcpy(datcom_.d2,buf,2*npts);
|
||||||
buf[i+1]=(qint16)datcom_.d4[j++];
|
// fwrite(buf,2,npts,fp);
|
||||||
if(!xpol) j+=2; //Skip over d4(3,x) and d4(4,x)
|
fwrite(datcom_.d2,2,npts,fp);
|
||||||
}
|
|
||||||
fwrite(buf,2,npts,fp);
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
free(buf);
|
// free(buf);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define MAX_RANDOM 0x7fffffff
|
//#define MAX_RANDOM 0x7fffffff
|
||||||
|
@ -6,8 +6,45 @@ subroutine genjtms3(msg,msgsent,iwave,nwave)
|
|||||||
integer dgen(13)
|
integer dgen(13)
|
||||||
integer*1 data0(13)
|
integer*1 data0(13)
|
||||||
integer*1 datsym(215)
|
integer*1 datsym(215)
|
||||||
integer indx0(9) !Indices of duplicated data symbols
|
real*8 pi,twopi,f0,dt,phi,dphi
|
||||||
|
real*4 p(-3095:3096)
|
||||||
|
real*4 s(6192)
|
||||||
|
real*4 carrier(6192)
|
||||||
|
logical first
|
||||||
|
integer indx0(9) !Indices of duplicated symbols
|
||||||
data indx0 /16,38,60,82,104,126,148,170,192/
|
data indx0 /16,38,60,82,104,126,148,170,192/
|
||||||
|
data first/.true./
|
||||||
|
save
|
||||||
|
sinc(x)=sin(pi*x)/(pi*x)
|
||||||
|
|
||||||
|
if(first) then
|
||||||
|
pi=4.d0*atan(1.d0)
|
||||||
|
twopi=2.d0*pi
|
||||||
|
k=0
|
||||||
|
x=0.
|
||||||
|
dx=1.0/24.0
|
||||||
|
do i=1,3096 !Generate the BPSK pulse shape
|
||||||
|
k=k+1
|
||||||
|
if(k.gt.3096) k=k-6192
|
||||||
|
x=x+dx
|
||||||
|
p(k)=sinc(x) * (sinc(x/2.0))**2
|
||||||
|
! p(k)=sinc(x) * exp(-(x/2.0)**2)
|
||||||
|
if(k.ne.3096) p(-k)=p(k)
|
||||||
|
enddo
|
||||||
|
p(0)=1.0
|
||||||
|
|
||||||
|
f0=193.d0*48000.d0/(258.d0*24.d0)
|
||||||
|
dt=1.d0/48000.d0
|
||||||
|
dphi=twopi*f0*dt
|
||||||
|
phi=0.d0
|
||||||
|
nmax=0.
|
||||||
|
do i=1,6192 !Generate the carrier
|
||||||
|
phi=phi+dphi
|
||||||
|
if(phi.gt.twopi)phi=phi-twopi
|
||||||
|
xphi=phi
|
||||||
|
carrier(i)=sin(xphi)
|
||||||
|
enddo
|
||||||
|
endif
|
||||||
|
|
||||||
call packmsg(msg,dgen) !Pack message into 12 six-bit symbols
|
call packmsg(msg,dgen) !Pack message into 12 six-bit symbols
|
||||||
call entail(dgen,data0) !Move from 6-bit to 8-bit symbols, add tail
|
call entail(dgen,data0) !Move from 6-bit to 8-bit symbols, add tail
|
||||||
@ -21,24 +58,25 @@ subroutine genjtms3(msg,msgsent,iwave,nwave)
|
|||||||
call scr258(isync,datsym,1,chansym) !Insert sync and data into chansym(258)
|
call scr258(isync,datsym,1,chansym) !Insert sync and data into chansym(258)
|
||||||
|
|
||||||
if(msg(1:1).eq.'@') chansym=0
|
if(msg(1:1).eq.'@') chansym=0
|
||||||
twopi=8.0*atan(1.0)
|
|
||||||
f0=1500.0
|
|
||||||
dphi=twopi*f0/48000.0
|
|
||||||
phi=0.
|
|
||||||
k=0
|
|
||||||
do j=1,258
|
|
||||||
do i=1,24
|
|
||||||
phi=phi+dphi
|
|
||||||
if(phi.gt.twopi) phi=phi-twopi
|
|
||||||
n=32767.0*sin(phi)
|
|
||||||
if(chansym(j).eq.0) n=-n
|
|
||||||
k=k+1
|
|
||||||
iwave(k)=n
|
|
||||||
enddo
|
|
||||||
enddo
|
|
||||||
nwave=k
|
|
||||||
|
|
||||||
! call genjtms3a(chansym,258,iwave,nwave)
|
s=0.
|
||||||
|
do j=1,258
|
||||||
|
k1=-3096-24*j
|
||||||
|
if(chansym(j).eq.1) s=s + cshift(p,k1)
|
||||||
|
if(chansym(j).eq.0) s=s - cshift(p,k1)
|
||||||
|
enddo
|
||||||
|
|
||||||
|
nmax=0
|
||||||
|
do i=1,6192
|
||||||
|
n=30000.0*carrier(i)*s(i)
|
||||||
|
nmax=max(nmax,abs(n))
|
||||||
|
if(n.gt.32767) n=32767
|
||||||
|
if(n.lt.-32767) n=-32767
|
||||||
|
iwave(i)=n
|
||||||
|
enddo
|
||||||
|
|
||||||
|
! print*,'nmax:',nmax
|
||||||
|
nwave=6192
|
||||||
msgsent=msg
|
msgsent=msg
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -194,8 +194,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
soundInThread.start(QThread::HighestPriority);
|
soundInThread.start(QThread::HighestPriority);
|
||||||
|
|
||||||
// Assign output device and start output thread
|
// Assign output device and start output thread
|
||||||
// soundOutThread.setOutputDevice(m_paOutDevice);
|
soundOutThread.setOutputDevice(m_paOutDevice);
|
||||||
soundOutThread.setOutputDevice(13); //###???###
|
|
||||||
// soundOutThread.start(QThread::HighPriority);
|
// soundOutThread.start(QThread::HighPriority);
|
||||||
|
|
||||||
m_monitoring=true; // Start with Monitoring ON
|
m_monitoring=true; // Start with Monitoring ON
|
||||||
@ -399,8 +398,14 @@ void MainWindow::readSettings()
|
|||||||
void MainWindow::dataSink(int k)
|
void MainWindow::dataSink(int k)
|
||||||
{
|
{
|
||||||
static int ndiskdat;
|
static int ndiskdat;
|
||||||
|
static int nwrite=0;
|
||||||
|
static int k0=99999999;
|
||||||
static float px=0.0;
|
static float px=0.0;
|
||||||
|
|
||||||
|
if(k < k0) {
|
||||||
|
nwrite=0;
|
||||||
|
}
|
||||||
|
|
||||||
if(m_diskData) {
|
if(m_diskData) {
|
||||||
ndiskdat=1;
|
ndiskdat=1;
|
||||||
datcom_.ndiskdat=1;
|
datcom_.ndiskdat=1;
|
||||||
@ -412,7 +417,7 @@ void MainWindow::dataSink(int k)
|
|||||||
double sq=0.0;
|
double sq=0.0;
|
||||||
float x;
|
float x;
|
||||||
for(int i=0; i<6192; i++) {
|
for(int i=0; i<6192; i++) {
|
||||||
x=datcom_.d4[k-6192+i];
|
x=datcom_.d2[k-6192+i];
|
||||||
sq += x*x;
|
sq += x*x;
|
||||||
}
|
}
|
||||||
px = 10.0*log10(sq/6192.0) + 70.0; // Why +70 ???
|
px = 10.0*log10(sq/6192.0) + 70.0; // Why +70 ???
|
||||||
@ -456,17 +461,18 @@ void MainWindow::dataSink(int k)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ihsym=0;
|
if(k >= (int)(29.5*48000) and nwrite==0) {
|
||||||
if(ihsym == 279) {
|
nwrite=1;
|
||||||
|
if(m_saveAll) {
|
||||||
QDateTime t = QDateTime::currentDateTimeUtc();
|
QDateTime t = QDateTime::currentDateTimeUtc();
|
||||||
m_dateTime=t.toString("yyyy-MMM-dd hh:mm");
|
m_dateTime=t.toString("yyyy-MMM-dd hh:mm");
|
||||||
if(m_saveAll) {
|
|
||||||
QString fname=m_saveDir + "/" + t.date().toString("yyMMdd") + "_" +
|
QString fname=m_saveDir + "/" + t.date().toString("yyMMdd") + "_" +
|
||||||
t.time().toString("hhmm") + ".wav";
|
t.time().toString("hhmm") + ".wav";
|
||||||
*future2 = QtConcurrent::run(savewav, fname);
|
*future2 = QtConcurrent::run(savewav, fname);
|
||||||
watcher2->setFuture(*future2);
|
watcher2->setFuture(*future2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
k0=k;
|
||||||
soundInThread.m_dataSinkBusy=false;
|
soundInThread.m_dataSinkBusy=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,9 +867,7 @@ void MainWindow::on_actionDelete_all_wav_files_in_SaveDir_triggered()
|
|||||||
QList<QString>::iterator f;
|
QList<QString>::iterator f;
|
||||||
for(f=files.begin(); f!=files.end(); ++f) {
|
for(f=files.begin(); f!=files.end(); ++f) {
|
||||||
fname=*f;
|
fname=*f;
|
||||||
i=(fname.indexOf(".tf2"));
|
i=(fname.indexOf(".wav"));
|
||||||
if(i==11) dir.remove(fname);
|
|
||||||
i=(fname.indexOf(".iq"));
|
|
||||||
if(i==11) dir.remove(fname);
|
if(i==11) dir.remove(fname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
soundin.cpp
19
soundin.cpp
@ -7,7 +7,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
extern struct {
|
extern struct {
|
||||||
float d4[30*48000]; //This is "common/datcom/..." in fortran
|
short int d2[30*48000]; //This is "common/datcom/..." in fortran
|
||||||
int kin;
|
int kin;
|
||||||
} datcom_;
|
} datcom_;
|
||||||
}
|
}
|
||||||
@ -46,22 +46,12 @@ extern "C" int a2dCallback( const void *inputBuffer, void *outputBuffer,
|
|||||||
udata->bzero=false;
|
udata->bzero=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbytes=4*framesToProcess; //Bytes per frame
|
nbytes=2*framesToProcess; //Bytes per frame
|
||||||
k=udata->kin;
|
k=udata->kin;
|
||||||
memcpy(&datcom_.d4[k],inputBuffer,nbytes); //Copy all samples to d4
|
memcpy(&datcom_.d2[k],inputBuffer,nbytes); //Copy all samples to d2
|
||||||
udata->kin += framesToProcess;
|
udata->kin += framesToProcess;
|
||||||
datcom_.kin=udata->kin;
|
datcom_.kin=udata->kin;
|
||||||
|
|
||||||
/*
|
|
||||||
double sq=0.0;
|
|
||||||
float x;
|
|
||||||
for(i=0; i<int(framesToProcess); i++) {
|
|
||||||
x=datcom_.d4[k++];
|
|
||||||
sq += x*x;
|
|
||||||
}
|
|
||||||
float rms = 32767.0*sqrt(sq/framesToProcess);
|
|
||||||
qDebug() << "A" << udata->kin/48000.0 << rms;
|
|
||||||
*/
|
|
||||||
return paContinue;
|
return paContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +70,7 @@ void SoundInThread::run() //SoundInThread::run()
|
|||||||
|
|
||||||
inParam.device=m_nDevIn; //### Input Device Number ###
|
inParam.device=m_nDevIn; //### Input Device Number ###
|
||||||
inParam.channelCount=1; //Number of analog channels
|
inParam.channelCount=1; //Number of analog channels
|
||||||
inParam.sampleFormat=paFloat32; //Get floats from Portaudio
|
inParam.sampleFormat=paInt16; //Get i*2 from Portaudio
|
||||||
inParam.suggestedLatency=0.05;
|
inParam.suggestedLatency=0.05;
|
||||||
inParam.hostApiSpecificStreamInfo=NULL;
|
inParam.hostApiSpecificStreamInfo=NULL;
|
||||||
|
|
||||||
@ -134,6 +124,7 @@ void SoundInThread::run() //SoundInThread::run()
|
|||||||
nBusy++;
|
nBusy++;
|
||||||
} else {
|
} else {
|
||||||
// m_dataSinkBusy=true;
|
// m_dataSinkBusy=true;
|
||||||
|
// qDebug() << "A" << k;
|
||||||
emit readyForFFT(k); //Signal to compute new FFTs
|
emit readyForFFT(k); //Signal to compute new FFTs
|
||||||
}
|
}
|
||||||
nstep0=m_step;
|
nstep0=m_step;
|
||||||
|
Loading…
Reference in New Issue
Block a user