mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-04-13 06:48:39 -04:00
Remove portaudio input code.
This commit is contained in:
parent
43c3a5ec26
commit
52b946f546
196
q65w/soundin.cpp
196
q65w/soundin.cpp
@ -50,96 +50,6 @@ extern "C"
|
||||
} datcom_;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int kin; //Parameters sent to/from the portaudio callback function
|
||||
int nrx;
|
||||
int dB;
|
||||
bool bzero;
|
||||
bool iqswap;
|
||||
} paUserData;
|
||||
|
||||
//--------------------------------------------------------------- a2dCallback
|
||||
extern "C" int a2dCallback( const void *inputBuffer, void *outputBuffer,
|
||||
unsigned long framesToProcess,
|
||||
const PaStreamCallbackTimeInfo* timeInfo,
|
||||
PaStreamCallbackFlags statusFlags,
|
||||
void *userData )
|
||||
|
||||
// This routine called by the PortAudio engine when samples are available.
|
||||
// It may be called at interrupt level, so don't do anything
|
||||
// that could mess up the system like calling malloc() or free().
|
||||
|
||||
{
|
||||
paUserData *udata=(paUserData*)userData;
|
||||
(void) outputBuffer; //Prevent unused variable warnings.
|
||||
(void) timeInfo;
|
||||
(void) userData;
|
||||
int nbytes,i,j;
|
||||
float d4[4*FRAMES_PER_BUFFER];
|
||||
float d4a[4*FRAMES_PER_BUFFER];
|
||||
float tmp;
|
||||
float fac;
|
||||
|
||||
if( (statusFlags&paInputOverflow) != 0) {
|
||||
qDebug() << "Input Overflow";
|
||||
}
|
||||
if(udata->bzero) { //Start of a new minute
|
||||
udata->kin=0; //Reset buffer pointer
|
||||
udata->bzero=false;
|
||||
}
|
||||
|
||||
nbytes=udata->nrx*8*framesToProcess; //Bytes per frame
|
||||
memcpy(d4,inputBuffer,nbytes); //Copy all samples to d4
|
||||
|
||||
fac=32767.0 * pow(10.0,0.05*udata->dB);
|
||||
|
||||
if(udata->nrx==2) {
|
||||
for(i=0; i<4*int(framesToProcess); i++) { //Negate odd-numbered frames
|
||||
d4[i]=fac*d4[i];
|
||||
j=i/4;
|
||||
if((j%2)==1) d4[i]=-d4[i];
|
||||
}
|
||||
if(!udata->iqswap) {
|
||||
for(i=0; i<int(framesToProcess); i++) {
|
||||
j=4*i;
|
||||
tmp=d4[j];
|
||||
d4[j]=d4[j+1];
|
||||
d4[j+1]=tmp;
|
||||
tmp=d4[j+2];
|
||||
d4[j+2]=d4[j+3];
|
||||
d4[j+3]=tmp;
|
||||
}
|
||||
}
|
||||
memcpy(&datcom_.d8[2*udata->kin],d4,nbytes); //Copy from d4 to dd()
|
||||
} else {
|
||||
int k=0;
|
||||
for(i=0; i<2*int(framesToProcess); i+=2) { //Negate odd-numbered frames
|
||||
j=i/2;
|
||||
if(j%2==0) {
|
||||
d4a[k++]=fac*d4[i];
|
||||
d4a[k++]=fac*d4[i+1];
|
||||
} else {
|
||||
d4a[k++]=-fac*d4[i];
|
||||
d4a[k++]=-fac*d4[i+1];
|
||||
}
|
||||
d4a[k++]=0.0;
|
||||
d4a[k++]=0.0;
|
||||
}
|
||||
if(!udata->iqswap) {
|
||||
for(i=0; i<int(framesToProcess); i++) {
|
||||
j=4*i;
|
||||
tmp=d4a[j];
|
||||
d4a[j]=d4a[j+1];
|
||||
d4a[j+1]=tmp;
|
||||
}
|
||||
}
|
||||
memcpy(&datcom_.d8[2*udata->kin],d4a,2*nbytes); //Copy from d4a to dd()
|
||||
}
|
||||
udata->kin += framesToProcess;
|
||||
return paContinue;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct COMWrapper
|
||||
@ -165,115 +75,9 @@ void SoundInThread::run() //SoundInThread::run()
|
||||
quitExecution = false;
|
||||
|
||||
if (m_net) {
|
||||
// qDebug() << "Start inputUDP()";
|
||||
inputUDP();
|
||||
// qDebug() << "Finished inputUDP()";
|
||||
return;
|
||||
}
|
||||
|
||||
COMWrapper c;
|
||||
|
||||
//---------------------------------------------------- Soundcard Setup
|
||||
// qDebug() << "Start souncard input";
|
||||
|
||||
PaError paerr;
|
||||
PaStreamParameters inParam;
|
||||
PaStream *inStream;
|
||||
paUserData udata;
|
||||
|
||||
udata.kin=0; //Buffer pointer
|
||||
udata.bzero=false; //Flag to request reset of kin
|
||||
udata.nrx=m_nrx; //Number of polarizations
|
||||
udata.iqswap=m_IQswap;
|
||||
udata.dB=m_dB;
|
||||
|
||||
auto device_info = Pa_GetDeviceInfo (m_nDevIn);
|
||||
|
||||
inParam.device=m_nDevIn; //### Input Device Number ###
|
||||
inParam.channelCount=2*m_nrx; //Number of analog channels
|
||||
inParam.sampleFormat=paFloat32; //Get floats from Portaudio
|
||||
inParam.suggestedLatency=device_info->defaultHighInputLatency;
|
||||
inParam.hostApiSpecificStreamInfo=NULL;
|
||||
|
||||
paerr=Pa_IsFormatSupported(&inParam,NULL,96000.0);
|
||||
if(paerr<0) {
|
||||
QString error_message;
|
||||
if (paUnanticipatedHostError == paerr)
|
||||
{
|
||||
auto const * last_host_error = Pa_GetLastHostErrorInfo ();
|
||||
error_message = QString {"PortAudio Host API error: %1"}.arg (last_host_error->errorText);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_message = "PortAudio says requested soundcard format not supported.";
|
||||
}
|
||||
emit error(error_message);
|
||||
// return;
|
||||
}
|
||||
paerr=Pa_OpenStream(&inStream, //Input stream
|
||||
&inParam, //Input parameters
|
||||
NULL, //No output parameters
|
||||
96000.0, //Sample rate
|
||||
FRAMES_PER_BUFFER, //Frames per buffer
|
||||
// paClipOff+paDitherOff, //No clipping or dithering
|
||||
paClipOff, //No clipping
|
||||
a2dCallback, //Input callbeck routine
|
||||
&udata); //userdata
|
||||
|
||||
paerr=Pa_StartStream(inStream);
|
||||
if(paerr<0) {
|
||||
emit error("Failed to start audio input stream.");
|
||||
return;
|
||||
}
|
||||
// const PaStreamInfo* p=Pa_GetStreamInfo(inStream);
|
||||
|
||||
bool qe = quitExecution;
|
||||
int ntr0=99;
|
||||
int k=0;
|
||||
int nsec;
|
||||
int ntr;
|
||||
int nBusy=0;
|
||||
int nhsym0=0;
|
||||
|
||||
//---------------------------------------------- Soundcard input loop
|
||||
while (!qe) {
|
||||
qe = quitExecution;
|
||||
if (qe) break;
|
||||
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
|
||||
nsec = ms/1000; // Time according to this computer
|
||||
ntr = nsec % m_TRperiod;
|
||||
|
||||
// Reset buffer pointer and symbol number at start of minute
|
||||
if(ntr < ntr0 or !m_monitoring or m_TRperiod!=m_TRperiod0) {
|
||||
nhsym0=0;
|
||||
udata.bzero=true;
|
||||
m_TRperiod0=m_TRperiod;
|
||||
}
|
||||
k=udata.kin;
|
||||
udata.iqswap=m_IQswap;
|
||||
udata.dB=m_dB;
|
||||
if(m_monitoring) {
|
||||
if(m_bForceCenterFreq) {
|
||||
datcom_.fcenter=m_dForceCenterFreq;
|
||||
} else {
|
||||
datcom_.fcenter=144.125;
|
||||
}
|
||||
m_hsym=(k-2048)*11025.0/(2048.0*m_rate);
|
||||
if(m_hsym != nhsym0) {
|
||||
if(m_dataSinkBusy) {
|
||||
nBusy++;
|
||||
} else {
|
||||
m_dataSinkBusy=true;
|
||||
emit readyForFFT(k); //Signal to compute new FFTs
|
||||
}
|
||||
nhsym0=m_hsym;
|
||||
}
|
||||
}
|
||||
msleep(100);
|
||||
ntr0=ntr;
|
||||
}
|
||||
Pa_StopStream(inStream);
|
||||
Pa_CloseStream(inStream);
|
||||
}
|
||||
|
||||
void SoundInThread::setSwapIQ(bool b)
|
||||
|
Loading…
Reference in New Issue
Block a user