Do necessary COM thread initializations for ASIO audio

This commit is contained in:
Bill Somerville 2021-06-16 15:02:40 +01:00
parent e28e9ff9b5
commit 1c86b18b24
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
4 changed files with 111 additions and 50 deletions

View File

@ -19,7 +19,7 @@ int main(int argc, char *argv[])
QApplication a {argc, argv};
// Override programs executable basename as application name.
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
a.setAttribute (Qt::AA_DontUseNativeMenuBar);
MainWindow w;

View File

@ -1,12 +1,19 @@
#include "soundin.h"
#include <stdexcept>
#ifdef Q_OS_WIN32
#include <windows.h>
#else
#include <sys/socket.h>
#endif
#define NFFT 32768
#define FRAMES_PER_BUFFER 1024
extern "C" {
#include <portaudio.h>
extern struct {
extern "C"
{
struct
{
double d8[2*60*96000]; //This is "common/datcom/..." in fortran
float ss[4*322*NFFT];
float savg[4*NFFT];
@ -133,6 +140,26 @@ extern "C" int a2dCallback( const void *inputBuffer, void *outputBuffer,
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()
{
quitExecution = false;
@ -144,6 +171,8 @@ void SoundInThread::run() //SoundInThread::run()
return;
}
COMWrapper c;
//---------------------------------------------------- Soundcard Setup
// qDebug() << "Start souncard input";
@ -158,15 +187,27 @@ void SoundInThread::run() //SoundInThread::run()
udata.iqswap=m_IQswap;
udata.b10db=m_10db;
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=0.05;
inParam.suggestedLatency=device_info->defaultHighInputLatency;
inParam.hostApiSpecificStreamInfo=NULL;
paerr=Pa_IsFormatSupported(&inParam,NULL,96000.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;
}
paerr=Pa_OpenStream(&inStream, //Input stream

View File

@ -6,12 +6,6 @@
#include <QDebug>
#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
// specified size is available.
class SoundInThread : public QThread

View File

@ -1,10 +1,12 @@
#include "soundout.h"
#ifdef Q_OS_WIN32
#include <windows.h>
#endif
#define FRAMES_PER_BUFFER 256
extern "C" {
#include <portaudio.h>
}
extern float gran(); //Noise generator (for tests only)
@ -120,18 +122,42 @@ extern "C" int d2aCallback(const void * /*inputBuffer*/, void *outputBuffer,
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()
{
COMWrapper c;
PaError paerr;
PaStreamParameters outParam;
PaStream *outStream;
paUserData udata;
quitExecution = false;
auto device_info = Pa_GetDeviceInfo (m_nDevOut);
outParam.device=m_nDevOut; //Output device number
outParam.channelCount=2; //Number of analog channels
outParam.sampleFormat=paInt16; //Send short ints to PortAudio
outParam.suggestedLatency=0.05;
outParam.suggestedLatency=device_info->defaultLowOutputLatency;
outParam.hostApiSpecificStreamInfo=NULL;
udata.nTRperiod=m_TRperiod;