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,12 +1,19 @@
|
|||||||
#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"
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
double d8[2*60*96000]; //This is "common/datcom/..." in fortran
|
double d8[2*60*96000]; //This is "common/datcom/..." in fortran
|
||||||
float ss[4*322*NFFT];
|
float ss[4*322*NFFT];
|
||||||
float savg[4*NFFT];
|
float savg[4*NFFT];
|
||||||
@ -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,6 +171,8 @@ void SoundInThread::run() //SoundInThread::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
COMWrapper c;
|
||||||
|
|
||||||
//---------------------------------------------------- Soundcard Setup
|
//---------------------------------------------------- Soundcard Setup
|
||||||
// qDebug() << "Start souncard input";
|
// qDebug() << "Start souncard input";
|
||||||
|
|
||||||
@ -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