mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-06 16:05:13 -04:00
FCDProPlus: use Qt for FCD audio device handling. Fixes start up error
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
|
||||
// Copyright (C) 2016-2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
@@ -14,8 +14,6 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// FIXME: FCD is handled very badly!
|
||||
|
||||
#include <QDebug>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -47,6 +45,7 @@ FCDProPlusInput::FCDProPlusInput(DeviceSourceAPI *deviceAPI) :
|
||||
m_deviceDescription(fcd_traits<ProPlus>::displayedName),
|
||||
m_running(false)
|
||||
{
|
||||
m_fcdFIFO.setSize(4*fcd_traits<ProPlus>::convBufSize);
|
||||
openDevice();
|
||||
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
|
||||
m_deviceAPI->addSink(m_fileSink);
|
||||
@@ -113,17 +112,17 @@ bool FCDProPlusInput::start()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!openSource(fcd_traits<ProPlus>::alsaDeviceName))
|
||||
if (!openFCDAudio(fcd_traits<ProPlus>::qtDeviceName))
|
||||
{
|
||||
qCritical("FCDProPlusInput::start: could not open source");
|
||||
qCritical("FCDProPlusInput::start: could not open FCD audio source");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("FCDProPlusInput::start: source opened");
|
||||
qDebug("FCDProPlusInput::start: FCD audio source opened");
|
||||
}
|
||||
|
||||
m_FCDThread = new FCDProPlusThread(&m_sampleFifo, fcd_handle);
|
||||
m_FCDThread = new FCDProPlusThread(&m_sampleFifo, &m_fcdFIFO);
|
||||
m_FCDThread->startWork();
|
||||
|
||||
// mutexLocker.unlock();
|
||||
@@ -145,73 +144,33 @@ void FCDProPlusInput::closeDevice()
|
||||
m_dev = 0;
|
||||
}
|
||||
|
||||
bool FCDProPlusInput::openSource(const char* cardname)
|
||||
bool FCDProPlusInput::openFCDAudio(const char* cardname)
|
||||
{
|
||||
bool fail = false;
|
||||
snd_pcm_hw_params_t* params;
|
||||
//fcd_rate = FCDPP_RATE;
|
||||
//fcd_channels =2;
|
||||
//fcd_format = SND_PCM_SFMT_U16_LE;
|
||||
snd_pcm_stream_t fcd_stream = SND_PCM_STREAM_CAPTURE;
|
||||
AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
|
||||
const QList<QAudioDeviceInfo>& audioList = audioDeviceManager->getInputDevices();
|
||||
|
||||
if (fcd_handle)
|
||||
for (const auto &itAudio : audioList)
|
||||
{
|
||||
qDebug("FCDProPlusInput::OpenSource: already opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (snd_pcm_open(&fcd_handle, cardname, fcd_stream, 0) < 0)
|
||||
{
|
||||
qCritical("FCDProPlusInput::OpenSource: cannot open %s", cardname);
|
||||
return false;
|
||||
}
|
||||
|
||||
snd_pcm_hw_params_alloca(¶ms);
|
||||
|
||||
if (snd_pcm_hw_params_any(fcd_handle, params) < 0)
|
||||
{
|
||||
qCritical("FCDProPlusInput::OpenSource: snd_pcm_hw_params_any failed");
|
||||
fail = true;
|
||||
}
|
||||
else if (snd_pcm_hw_params(fcd_handle, params) < 0)
|
||||
{
|
||||
qCritical("FCDProPlusInput::OpenSource: snd_pcm_hw_params failed");
|
||||
fail = true;
|
||||
// TODO: check actual samplerate, may be crippled firmware
|
||||
}
|
||||
else
|
||||
{
|
||||
if (snd_pcm_start(fcd_handle) < 0)
|
||||
if (itAudio.deviceName().contains(QString(cardname)))
|
||||
{
|
||||
qCritical("FCDProPlusInput::OpenSource: snd_pcm_start failed");
|
||||
fail = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("FCDProPlusInput::OpenSource: snd_pcm_start OK");
|
||||
int fcdDeviceIndex = audioDeviceManager->getInputDeviceIndex(itAudio.deviceName());
|
||||
m_fcdAudioInput.start(fcdDeviceIndex, fcd_traits<ProPlus>::sampleRate);
|
||||
int fcdSampleRate = m_fcdAudioInput.getRate();
|
||||
qDebug("FCDProPlusInput::openFCDAudio: %s index %d at %d S/s",
|
||||
itAudio.deviceName().toStdString().c_str(), fcdDeviceIndex, fcdSampleRate);
|
||||
m_fcdAudioInput.addFifo(&m_fcdFIFO);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fail)
|
||||
{
|
||||
snd_pcm_close(fcd_handle);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("FCDProPlusInput::OpenSource: Funcube stream started");
|
||||
}
|
||||
|
||||
return true;
|
||||
qCritical("FCDProPlusInput::openFCDAudio: device with name %s not found", cardname);
|
||||
return false;
|
||||
}
|
||||
|
||||
void FCDProPlusInput::closeSource()
|
||||
void FCDProPlusInput::closeFCDAudio()
|
||||
{
|
||||
if (fcd_handle) {
|
||||
snd_pcm_close(fcd_handle);
|
||||
}
|
||||
|
||||
fcd_handle = nullptr;
|
||||
m_fcdAudioInput.removeFifo(&m_fcdFIFO);
|
||||
m_fcdAudioInput.stop();
|
||||
}
|
||||
|
||||
void FCDProPlusInput::stop()
|
||||
@@ -224,7 +183,7 @@ void FCDProPlusInput::stop()
|
||||
// wait for thread to quit ?
|
||||
delete m_FCDThread;
|
||||
m_FCDThread = nullptr;
|
||||
closeSource();
|
||||
closeFCDAudio();
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include <dsp/devicesamplesource.h>
|
||||
#include "dsp/devicesamplesource.h"
|
||||
#include "audio/audioinput.h"
|
||||
#include "audio/audiofifo.h"
|
||||
|
||||
#include "fcdproplussettings.h"
|
||||
#include "fcdhid.h"
|
||||
|
||||
@@ -149,13 +152,15 @@ public:
|
||||
private:
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
bool openSource(const char *filename);
|
||||
void closeSource();
|
||||
bool openFCDAudio(const char *filename);
|
||||
void closeFCDAudio();
|
||||
void applySettings(const FCDProPlusSettings& settings, bool force);
|
||||
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const FCDProPlusSettings& settings);
|
||||
|
||||
DeviceSourceAPI *m_deviceAPI;
|
||||
hid_device *m_dev;
|
||||
AudioInput m_fcdAudioInput;
|
||||
AudioFifo m_fcdFIFO;
|
||||
snd_pcm_t* fcd_handle;
|
||||
QMutex m_mutex;
|
||||
FCDProPlusSettings m_settings;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
||||
// written by Christian Daniel //
|
||||
// Copyright (C) 2016-2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
@@ -21,13 +20,13 @@
|
||||
#include "fcdproplusthread.h"
|
||||
|
||||
#include "dsp/samplesinkfifo.h"
|
||||
#include "fcdtraits.h"
|
||||
#include "audio/audiofifo.h"
|
||||
|
||||
FCDProPlusThread::FCDProPlusThread(SampleSinkFifo* sampleFifo, snd_pcm_t *fcd_handle, QObject* parent) :
|
||||
FCDProPlusThread::FCDProPlusThread(SampleSinkFifo* sampleFifo, AudioFifo *fcdFIFO, QObject* parent) :
|
||||
QThread(parent),
|
||||
m_fcd_handle(fcd_handle),
|
||||
m_fcdFIFO(fcdFIFO),
|
||||
m_running(false),
|
||||
m_convertBuffer(fcd_traits<ProPlus>::convBufSize),
|
||||
m_convertBuffer(fcd_traits<ProPlus>::convBufSize), // nb samples
|
||||
m_sampleFifo(sampleFifo)
|
||||
{
|
||||
start();
|
||||
@@ -62,43 +61,18 @@ void FCDProPlusThread::run()
|
||||
m_running = true;
|
||||
qDebug("FCDThread::run: start running loop");
|
||||
|
||||
while (m_running)
|
||||
{
|
||||
if (work(fcd_traits<ProPlus>::convBufSize) < 0) {
|
||||
break;
|
||||
}
|
||||
while (m_running) {
|
||||
work(fcd_traits<ProPlus>::convBufSize);
|
||||
}
|
||||
|
||||
qDebug("FCDThread::run: running loop stopped");
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
int FCDProPlusThread::work(int n_items)
|
||||
void FCDProPlusThread::work(unsigned int n_items)
|
||||
{
|
||||
int l;
|
||||
SampleVector::iterator it;
|
||||
void *out;
|
||||
|
||||
it = m_convertBuffer.begin();
|
||||
out = (void *)&it[0];
|
||||
|
||||
l = snd_pcm_mmap_readi(m_fcd_handle, out, (snd_pcm_uframes_t)n_items);
|
||||
|
||||
if (l > 0)
|
||||
{
|
||||
m_sampleFifo->write(it, it + l);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (l == -EPIPE) {
|
||||
qDebug("FCDProPlusThread::work: Overrun detected");
|
||||
} else if (l < 0) {
|
||||
qDebug("FCDProPlusThread::work: snd_pcm_mmap_readi failed with code %d", l);
|
||||
} else {
|
||||
qDebug("FCDProPlusThread::work: snd_pcm_mmap_readi empty");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return l;
|
||||
uint32_t nbRead = m_fcdFIFO->read((unsigned char *) m_buf, n_items); // number of samples
|
||||
SampleVector::iterator it = m_convertBuffer.begin();
|
||||
m_decimators.decimate1(&it, m_buf, 2*nbRead);
|
||||
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
||||
}
|
||||
|
||||
@@ -21,32 +21,36 @@
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include "dsp/inthalfbandfilter.h"
|
||||
#include "dsp/samplesinkfifo.h"
|
||||
#include "dsp/decimators.h"
|
||||
#include "fcdtraits.h"
|
||||
|
||||
class AudioFifo;
|
||||
|
||||
class FCDProPlusThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FCDProPlusThread(SampleSinkFifo* sampleFifo, snd_pcm_t *fcd_handle, QObject* parent = nullptr);
|
||||
FCDProPlusThread(SampleSinkFifo* sampleFifo, AudioFifo *fcdFIFO, QObject* parent = nullptr);
|
||||
~FCDProPlusThread();
|
||||
|
||||
void startWork();
|
||||
void stopWork();
|
||||
|
||||
private:
|
||||
snd_pcm_t* m_fcd_handle;
|
||||
AudioFifo* m_fcdFIFO;
|
||||
|
||||
QMutex m_startWaitMutex;
|
||||
QWaitCondition m_startWaiter;
|
||||
bool m_running;
|
||||
|
||||
qint16 m_buf[fcd_traits<ProPlus>::convBufSize*2]; // stereo (I, Q)
|
||||
SampleVector m_convertBuffer;
|
||||
SampleSinkFifo* m_sampleFifo;
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 16> m_decimators;
|
||||
|
||||
void run();
|
||||
int work(int n_items);
|
||||
void work(unsigned int n_items);
|
||||
};
|
||||
#endif // INCLUDE_FCDTHREAD_H
|
||||
|
||||
Reference in New Issue
Block a user