mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-22 04:11:16 -05:00
Do necessary COM thread initializations for ASIO audio
This commit is contained in:
parent
e28e9ff9b5
commit
1c86b18b24
@ -19,7 +19,7 @@ int main(int argc, char *argv[])
|
|||||||
QApplication a {argc, argv};
|
QApplication a {argc, argv};
|
||||||
// Override programs executable basename as application name.
|
// Override programs executable basename as application name.
|
||||||
a.setApplicationName ("MAP65");
|
a.setApplicationName ("MAP65");
|
||||||
a.setApplicationVersion ("3.0.0-rc1");
|
a.setApplicationVersion ("3.0.0-devel");
|
||||||
// switch off as we share an Info.plist file with WSJT-X
|
// switch off as we share an Info.plist file with WSJT-X
|
||||||
a.setAttribute (Qt::AA_DontUseNativeMenuBar);
|
a.setAttribute (Qt::AA_DontUseNativeMenuBar);
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
|
@ -1,45 +1,52 @@
|
|||||||
#include "soundin.h"
|
#include "soundin.h"
|
||||||
#include <stdexcept>
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NFFT 32768
|
#define NFFT 32768
|
||||||
#define FRAMES_PER_BUFFER 1024
|
#define FRAMES_PER_BUFFER 1024
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
extern struct {
|
extern "C"
|
||||||
double d8[2*60*96000]; //This is "common/datcom/..." in fortran
|
{
|
||||||
float ss[4*322*NFFT];
|
struct
|
||||||
float savg[4*NFFT];
|
{
|
||||||
double fcenter;
|
double d8[2*60*96000]; //This is "common/datcom/..." in fortran
|
||||||
int nutc;
|
float ss[4*322*NFFT];
|
||||||
int idphi; //Phase correction for Y pol'n, degrees
|
float savg[4*NFFT];
|
||||||
int mousedf; //User-selected DF
|
double fcenter;
|
||||||
int mousefqso; //User-selected QSO freq (kHz)
|
int nutc;
|
||||||
int nagain; //1 ==> decode only at fQSO +/- Tol
|
int idphi; //Phase correction for Y pol'n, degrees
|
||||||
int ndepth; //How much hinted decoding to do?
|
int mousedf; //User-selected DF
|
||||||
int ndiskdat; //1 ==> data read from *.tf2 or *.iq file
|
int mousefqso; //User-selected QSO freq (kHz)
|
||||||
int neme; //Hinted decoding tries only for EME calls
|
int nagain; //1 ==> decode only at fQSO +/- Tol
|
||||||
int newdat; //1 ==> new data, must do long FFT
|
int ndepth; //How much hinted decoding to do?
|
||||||
int nfa; //Low decode limit (kHz)
|
int ndiskdat; //1 ==> data read from *.tf2 or *.iq file
|
||||||
int nfb; //High decode limit (kHz)
|
int neme; //Hinted decoding tries only for EME calls
|
||||||
int nfcal; //Frequency correction, for calibration (Hz)
|
int newdat; //1 ==> new data, must do long FFT
|
||||||
int nfshift; //Shift of displayed center freq (kHz)
|
int nfa; //Low decode limit (kHz)
|
||||||
int mcall3; //1 ==> CALL3.TXT has been modified
|
int nfb; //High decode limit (kHz)
|
||||||
int ntimeout; //Max for timeouts in Messages and BandMap
|
int nfcal; //Frequency correction, for calibration (Hz)
|
||||||
int ntol; //+/- decoding range around fQSO (Hz)
|
int nfshift; //Shift of displayed center freq (kHz)
|
||||||
int nxant; //1 ==> add 45 deg to measured pol angle
|
int mcall3; //1 ==> CALL3.TXT has been modified
|
||||||
int map65RxLog; //Flags to control log files
|
int ntimeout; //Max for timeouts in Messages and BandMap
|
||||||
int nfsample; //Input sample rate
|
int ntol; //+/- decoding range around fQSO (Hz)
|
||||||
int nxpol; //1 if using xpol antennas, 0 otherwise
|
int nxant; //1 ==> add 45 deg to measured pol angle
|
||||||
int mode65; //JT65 sub-mode: A=1, B=2, C=4
|
int map65RxLog; //Flags to control log files
|
||||||
int nfast; //1No longer used
|
int nfsample; //Input sample rate
|
||||||
int nsave; //Number of s3(64,63) spectra saved
|
int nxpol; //1 if using xpol antennas, 0 otherwise
|
||||||
char mycall[12];
|
int mode65; //JT65 sub-mode: A=1, B=2, C=4
|
||||||
char mygrid[6];
|
int nfast; //1No longer used
|
||||||
char hiscall[12];
|
int nsave; //Number of s3(64,63) spectra saved
|
||||||
char hisgrid[6];
|
char mycall[12];
|
||||||
char datetime[20];
|
char mygrid[6];
|
||||||
} datcom_;
|
char hiscall[12];
|
||||||
|
char hisgrid[6];
|
||||||
|
char datetime[20];
|
||||||
|
} datcom_;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -133,6 +140,26 @@ extern "C" int a2dCallback( const void *inputBuffer, void *outputBuffer,
|
|||||||
return paContinue;
|
return paContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct COMWrapper
|
||||||
|
{
|
||||||
|
explicit COMWrapper ()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
// required because Qt only does this for GUI thread
|
||||||
|
CoInitializeEx (nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
~COMWrapper ()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
CoUninitialize ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void SoundInThread::run() //SoundInThread::run()
|
void SoundInThread::run() //SoundInThread::run()
|
||||||
{
|
{
|
||||||
quitExecution = false;
|
quitExecution = false;
|
||||||
@ -144,8 +171,10 @@ void SoundInThread::run() //SoundInThread::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------- Soundcard Setup
|
COMWrapper c;
|
||||||
// qDebug() << "Start souncard input";
|
|
||||||
|
//---------------------------------------------------- Soundcard Setup
|
||||||
|
// qDebug() << "Start souncard input";
|
||||||
|
|
||||||
PaError paerr;
|
PaError paerr;
|
||||||
PaStreamParameters inParam;
|
PaStreamParameters inParam;
|
||||||
@ -158,15 +187,27 @@ void SoundInThread::run() //SoundInThread::run()
|
|||||||
udata.iqswap=m_IQswap;
|
udata.iqswap=m_IQswap;
|
||||||
udata.b10db=m_10db;
|
udata.b10db=m_10db;
|
||||||
|
|
||||||
|
auto device_info = Pa_GetDeviceInfo (m_nDevIn);
|
||||||
|
|
||||||
inParam.device=m_nDevIn; //### Input Device Number ###
|
inParam.device=m_nDevIn; //### Input Device Number ###
|
||||||
inParam.channelCount=2*m_nrx; //Number of analog channels
|
inParam.channelCount=2*m_nrx; //Number of analog channels
|
||||||
inParam.sampleFormat=paFloat32; //Get floats from Portaudio
|
inParam.sampleFormat=paFloat32; //Get floats from Portaudio
|
||||||
inParam.suggestedLatency=0.05;
|
inParam.suggestedLatency=device_info->defaultHighInputLatency;
|
||||||
inParam.hostApiSpecificStreamInfo=NULL;
|
inParam.hostApiSpecificStreamInfo=NULL;
|
||||||
|
|
||||||
paerr=Pa_IsFormatSupported(&inParam,NULL,96000.0);
|
paerr=Pa_IsFormatSupported(&inParam,NULL,96000.0);
|
||||||
if(paerr<0) {
|
if(paerr<0) {
|
||||||
emit error("PortAudio says requested soundcard format not supported.");
|
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;
|
// return;
|
||||||
}
|
}
|
||||||
paerr=Pa_OpenStream(&inStream, //Input stream
|
paerr=Pa_OpenStream(&inStream, //Input stream
|
||||||
|
@ -6,12 +6,6 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <valarray>
|
#include <valarray>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
#include <winsock.h>
|
|
||||||
#else
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#endif //Q_OS_WIN32
|
|
||||||
|
|
||||||
// Thread gets audio data from soundcard and signals when a buffer of
|
// Thread gets audio data from soundcard and signals when a buffer of
|
||||||
// specified size is available.
|
// specified size is available.
|
||||||
class SoundInThread : public QThread
|
class SoundInThread : public QThread
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#include "soundout.h"
|
#include "soundout.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define FRAMES_PER_BUFFER 256
|
#define FRAMES_PER_BUFFER 256
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
}
|
|
||||||
|
|
||||||
extern float gran(); //Noise generator (for tests only)
|
extern float gran(); //Noise generator (for tests only)
|
||||||
|
|
||||||
@ -120,18 +122,42 @@ extern "C" int d2aCallback(const void * /*inputBuffer*/, void *outputBuffer,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct COMWrapper
|
||||||
|
{
|
||||||
|
explicit COMWrapper ()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
// required because Qt only does this for GUI thread
|
||||||
|
CoInitializeEx (nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
~COMWrapper ()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
CoUninitialize ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void SoundOutThread::run()
|
void SoundOutThread::run()
|
||||||
{
|
{
|
||||||
|
COMWrapper c;
|
||||||
|
|
||||||
PaError paerr;
|
PaError paerr;
|
||||||
PaStreamParameters outParam;
|
PaStreamParameters outParam;
|
||||||
PaStream *outStream;
|
PaStream *outStream;
|
||||||
paUserData udata;
|
paUserData udata;
|
||||||
quitExecution = false;
|
quitExecution = false;
|
||||||
|
|
||||||
|
auto device_info = Pa_GetDeviceInfo (m_nDevOut);
|
||||||
|
|
||||||
outParam.device=m_nDevOut; //Output device number
|
outParam.device=m_nDevOut; //Output device number
|
||||||
outParam.channelCount=2; //Number of analog channels
|
outParam.channelCount=2; //Number of analog channels
|
||||||
outParam.sampleFormat=paInt16; //Send short ints to PortAudio
|
outParam.sampleFormat=paInt16; //Send short ints to PortAudio
|
||||||
outParam.suggestedLatency=0.05;
|
outParam.suggestedLatency=device_info->defaultLowOutputLatency;
|
||||||
outParam.hostApiSpecificStreamInfo=NULL;
|
outParam.hostApiSpecificStreamInfo=NULL;
|
||||||
|
|
||||||
udata.nTRperiod=m_TRperiod;
|
udata.nTRperiod=m_TRperiod;
|
||||||
|
Loading…
Reference in New Issue
Block a user