XTRX: fixed sample rate setting

pull/516/head
f4exb 2020-04-18 07:39:38 +02:00
rodzic 8653d326b3
commit c7e7215199
9 zmienionych plików z 243 dodań i 268 usunięć

Wyświetl plik

@ -125,14 +125,16 @@ double DeviceXTRX::set_samplerate(double rate, double master, bool output)
m_inputRate = rate;
}
int res = xtrx_set_samplerate(m_dev,
m_masterRate,
m_inputRate,
m_outputRate,
0,
&m_clockGen,
&m_actualInputRate,
&m_actualOutputRate);
int res = xtrx_set_samplerate(
m_dev,
m_masterRate,
m_inputRate,
m_outputRate,
XTRX_SAMPLERATE_FORCE_UPDATE,
&m_clockGen,
&m_actualInputRate,
&m_actualOutputRate
);
if (res)
{

Wyświetl plik

@ -382,12 +382,6 @@ void XTRXOutput::stop()
// remove old thread address from buddies (reset in all buddies)
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
std::vector<DeviceAPI*>::const_iterator it = sinkBuddies.begin();
for (; it != sinkBuddies.end(); ++it)
{
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_sink->setThread(0);
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_thread = 0;
}
}
else if (nbOriginalChannels == 2) // Reduce from MO to SO by deleting and re-creating the thread
{
@ -404,13 +398,6 @@ void XTRXOutput::stop()
// remove old thread address from buddies (reset in all buddies). The address being held only in the owning source.
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
std::vector<DeviceAPI*>::const_iterator it = sinkBuddies.begin();
for (; it != sinkBuddies.end(); ++it)
{
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_sink->setThread(0);
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_thread = 0;
}
applySettings(m_settings, true);
xtrxOutputThread->startWork();
}
@ -503,24 +490,20 @@ int XTRXOutput::getSampleRate() const
uint32_t XTRXOutput::getDevSampleRate() const
{
uint32_t devSampleRate = m_settings.m_devSampleRate;
if (m_deviceShared.m_dev) {
devSampleRate = m_deviceShared.m_dev->getActualOutputRate();
return m_deviceShared.m_dev->getActualOutputRate();
} else {
return m_settings.m_devSampleRate;
}
return devSampleRate;
}
uint32_t XTRXOutput::getLog2HardInterp() const
{
uint32_t log2HardInterp = m_settings.m_log2HardInterp;
if (m_deviceShared.m_dev && (m_deviceShared.m_dev->getActualOutputRate() != 0.0)) {
log2HardInterp = log2(m_deviceShared.m_dev->getClockGen() / m_deviceShared.m_dev->getActualOutputRate() / 4);
return log2(m_deviceShared.m_dev->getClockGen() / m_deviceShared.m_dev->getActualOutputRate() / 4);
} else {
return m_settings.m_log2HardInterp;
}
return log2HardInterp;
}
double XTRXOutput::getClockGen() const
@ -964,42 +947,40 @@ bool XTRXOutput::applySettings(const XTRXOutputSettings& settings, bool force, b
if (doChangeSampleRate && (settings.m_devSampleRate != 0))
{
XTRXOutputThread *txThread = findThread();
// XTRXOutputThread *txThread = findThread();
if (txThread && txThread->isRunning())
{
txThread->stopWork();
txThreadWasRunning = true;
}
// if (txThread && txThread->isRunning())
// {
// txThread->stopWork();
// txThreadWasRunning = true;
// }
suspendRxThread();
// suspendRxThread();
double master = (settings.m_log2HardInterp == 0) ? 0 : (settings.m_devSampleRate * 4 * (1 << settings.m_log2HardInterp));
double master = (m_settings.m_log2HardInterp == 0) ? 0 : (m_settings.m_devSampleRate * 4 * (1 << m_settings.m_log2HardInterp));
if (m_deviceShared.m_dev->set_samplerate(settings.m_devSampleRate,
master, //(settings.m_devSampleRate<<settings.m_log2HardDecim)*4,
true) < 0)
{
qCritical("XTRXOutput::applySettings: could not set sample rate to %f with oversampling of %d",
settings.m_devSampleRate,
1<<settings.m_log2HardInterp);
}
else
{
doChangeFreq = true;
forceNCOFrequency = true;
forwardChangeAllDSP = true;
int res = m_deviceShared.m_dev->setSamplerate(
m_settings.m_devSampleRate,
master,
true
);
qDebug("XTRXOutput::applySettings: sample rate set to %f with oversampling of %d",
m_deviceShared.m_dev->getActualOutputRate(),
1 << getLog2HardInterp());
}
doChangeFreq = true;
forceNCOFrequency = true;
forwardChangeAllDSP = true;
m_settings.m_devSampleRate = m_deviceShared.m_dev->getActualOutputRate();
m_settings.m_log2HardInterp = getLog2HardInterp();
resumeRxThread();
qDebug("XTRXOutput::applySettings: sample rate set %s to %f with hard interpolation of %d",
(res < 0) ? "changed" : "unchanged",
m_settings.m_devSampleRate,
m_settings.m_log2HardInterp);
if (txThreadWasRunning) {
txThread->startWork();
}
// resumeRxThread();
// if (txThreadWasRunning) {
// txThread->startWork();
// }
}
if (doLPCalibration)
@ -1022,12 +1003,12 @@ bool XTRXOutput::applySettings(const XTRXOutputSettings& settings, bool force, b
{
if (xtrx_tune(m_deviceShared.m_dev->getDevice(),
XTRX_TUNE_TX_FDD,
settings.m_centerFrequency,
m_settings.m_centerFrequency,
0) < 0) {
qCritical("XTRXOutput::applySettings: could not set frequency to %lu", settings.m_centerFrequency);
qCritical("XTRXOutput::applySettings: could not set frequency to %lu", m_settings.m_centerFrequency);
} else {
//doCalibration = true;
qDebug("XTRXOutput::applySettings: frequency set to %lu", settings.m_centerFrequency);
qDebug("XTRXOutput::applySettings: frequency set to %lu", m_settings.m_centerFrequency);
}
}
}
@ -1039,19 +1020,19 @@ bool XTRXOutput::applySettings(const XTRXOutputSettings& settings, bool force, b
if (xtrx_tune_ex(m_deviceShared.m_dev->getDevice(),
XTRX_TUNE_BB_TX,
m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B,
(settings.m_ncoEnable) ? settings.m_ncoFrequency : 0,
(m_settings.m_ncoEnable) ? m_settings.m_ncoFrequency : 0,
NULL) < 0)
{
qCritical("XTRXOutput::applySettings: could not %s and set NCO to %d Hz",
settings.m_ncoEnable ? "enable" : "disable",
settings.m_ncoFrequency);
m_settings.m_ncoEnable ? "enable" : "disable",
m_settings.m_ncoFrequency);
}
else
{
forwardChangeOwnDSP = true;
qDebug("XTRXOutput::applySettings: %sd and set NCO to %d Hz",
settings.m_ncoEnable ? "enable" : "disable",
settings.m_ncoFrequency);
m_settings.m_ncoEnable ? "enable" : "disable",
m_settings.m_ncoFrequency);
}
}
}

Wyświetl plik

@ -173,6 +173,7 @@ bool XTRXOutputGUI::handleMessage(const Message& message)
else if (XTRXOutput::MsgReportClockGenChange::match(message))
{
m_settings.m_devSampleRate = m_XTRXOutput->getDevSampleRate();
m_settings.m_log2HardInterp = m_XTRXOutput->getLog2HardInterp();
blockApplySettings(true);
displaySettings();

Wyświetl plik

@ -302,6 +302,71 @@
<property name="topMargin">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="sampleRateMode">
<property name="minimumSize">
<size>
<width>24</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Toggle between device to host (SR) and base band (BB) sample rate input</string>
</property>
<property name="text">
<string>SR</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="ValueDial" name="sampleRate" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>12</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="toolTip">
<string>Device to host sample rate</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="samplerateUnit">
<property name="text">
<string>S/s</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="hwInterpLabel">
<property name="text">
@ -356,6 +421,11 @@
<string>32</string>
</property>
</item>
<item>
<property name="text">
<string>64</string>
</property>
</item>
</widget>
</item>
<item>
@ -432,71 +502,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="sampleRateMode">
<property name="minimumSize">
<size>
<width>24</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Toggle between device to host (SR) and base band (BB) sample rate input</string>
</property>
<property name="text">
<string>SR</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="ValueDial" name="sampleRate" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>12</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="toolTip">
<string>Device to host sample rate</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="samplerateUnit">
<property name="text">
<string>S/s</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

Wyświetl plik

@ -36,7 +36,7 @@
const PluginDescriptor XTRXOutputPlugin::m_pluginDescriptor = {
QString("XTRX"),
QString("XTRX Output"),
QString("4.12.3"),
QString("4.14.4"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,

Wyświetl plik

@ -400,12 +400,6 @@ void XTRXInput::stop()
// remove old thread address from buddies (reset in all buddies)
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
for (; it != sourceBuddies.end(); ++it)
{
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_source->setThread(0);
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_thread = 0;
}
}
else if (nbOriginalChannels == 2) // Reduce from MI to SI by deleting and re-creating the thread
{
@ -422,13 +416,6 @@ void XTRXInput::stop()
// remove old thread address from buddies (reset in all buddies). The address being held only in the owning source.
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
for (; it != sourceBuddies.end(); ++it)
{
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_source->setThread(0);
((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_thread = 0;
}
applySettings(m_settings, true);
xtrxInputThread->startWork();
}
@ -521,24 +508,20 @@ int XTRXInput::getSampleRate() const
uint32_t XTRXInput::getDevSampleRate() const
{
uint32_t devSampleRate = m_settings.m_devSampleRate;
if (m_deviceShared.m_dev) {
devSampleRate = m_deviceShared.m_dev->getActualInputRate();
return m_deviceShared.m_dev->getActualInputRate();
} else {
return m_settings.m_devSampleRate;
}
return devSampleRate;
}
uint32_t XTRXInput::getLog2HardDecim() const
{
uint32_t log2HardDecim = m_settings.m_log2HardDecim;
if (m_deviceShared.m_dev && (m_deviceShared.m_dev->getActualInputRate() != 0.0)) {
log2HardDecim = log2(m_deviceShared.m_dev->getClockGen() / m_deviceShared.m_dev->getActualInputRate() / 4);
return log2(m_deviceShared.m_dev->getClockGen() / m_deviceShared.m_dev->getActualInputRate() / 4);
} else {
return m_settings.m_log2HardDecim;
}
return log2HardDecim;
}
double XTRXInput::getClockGen() const
@ -630,15 +613,14 @@ bool XTRXInput::handleMessage(const Message& message)
{
m_settings.m_devSampleRate = m_deviceShared.m_dev->getActualInputRate();
m_settings.m_log2HardDecim = getLog2HardDecim();
qDebug() << "XTRXInput::handleMessage: MsgReportBuddyChange:"
<< " host_Hz: " << m_deviceShared.m_dev->getActualInputRate()
<< " adc_Hz: " << m_deviceShared.m_dev->getClockGen() / 4
<< " m_log2HardDecim: " << m_settings.m_log2HardDecim;
}
if (m_settings.m_ncoEnable) // need to reset NCO after sample rate change
{
qDebug() << "XTRXInput::handleMessage: MsgReportBuddyChange:"
<< " host_Hz: " << m_deviceShared.m_dev->getActualInputRate()
<< " adc_Hz: " << m_deviceShared.m_dev->getClockGen() / 4
<< " m_log2HardDecim: " << m_settings.m_log2HardDecim;
if (m_settings.m_ncoEnable) { // need to reset NCO after sample rate change
applySettings(m_settings, false, true);
}
@ -1102,44 +1084,42 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
m_settings = settings;
if (doChangeSampleRate && (settings.m_devSampleRate != 0))
if (doChangeSampleRate && (m_settings.m_devSampleRate != 0))
{
XTRXInputThread *rxThread = findThread();
// XTRXInputThread *rxThread = findThread();
if (rxThread && rxThread->isRunning())
{
rxThread->stopWork();
rxThreadWasRunning = true;
}
// if (rxThread && rxThread->isRunning())
// {
// rxThread->stopWork();
// rxThreadWasRunning = true;
// }
suspendTxThread();
// suspendTxThread();
double master = (settings.m_log2HardDecim == 0) ? 0 : (settings.m_devSampleRate * 4 * (1 << settings.m_log2HardDecim));
double master = (m_settings.m_log2HardDecim == 0) ? 0 : (m_settings.m_devSampleRate * 4 * (1 << m_settings.m_log2HardDecim));
if (m_deviceShared.m_dev->set_samplerate(settings.m_devSampleRate,
master, //(settings.m_devSampleRate<<settings.m_log2HardDecim)*4,
false) < 0)
{
qCritical("XTRXInput::applySettings: could not set sample rate to %f with oversampling of %d",
settings.m_devSampleRate,
1<<settings.m_log2HardDecim);
}
else
{
doChangeFreq = true;
forceNCOFrequency = true;
forwardChangeAllDSP = true;
int res = m_deviceShared.m_dev->setSamplerate(
m_settings.m_devSampleRate,
master,
false
);
qDebug("XTRXInput::applySettings: sample rate set to %f with oversampling of %d",
m_deviceShared.m_dev->getActualInputRate(),
1 << getLog2HardDecim());
}
doChangeFreq = true;
forceNCOFrequency = true;
forwardChangeAllDSP = true;
m_settings.m_devSampleRate = m_deviceShared.m_dev->getActualInputRate();
m_settings.m_log2HardDecim = getLog2HardDecim();
resumeTxThread();
qDebug("XTRXInput::applySettings: sample rate set %s to %f with hard decimation of %d",
(res < 0) ? "changed" : "unchanged",
m_settings.m_devSampleRate,
m_settings.m_log2HardDecim);
if (rxThreadWasRunning) {
rxThread->startWork();
}
// resumeTxThread();
// if (rxThreadWasRunning) {
// rxThread->startWork();
// }
}
if (doLPCalibration)
@ -1179,12 +1159,12 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
{
if (xtrx_tune(m_deviceShared.m_dev->getDevice(),
XTRX_TUNE_RX_FDD,
settings.m_centerFrequency,
m_settings.m_centerFrequency,
0) < 0) {
qCritical("XTRXInput::applySettings: could not set frequency to %lu", settings.m_centerFrequency);
qCritical("XTRXInput::applySettings: could not set frequency to %lu", m_settings.m_centerFrequency);
} else {
//doCalibration = true;
qDebug("XTRXInput::applySettings: frequency set to %lu", settings.m_centerFrequency);
qDebug("XTRXInput::applySettings: frequency set to %lu", m_settings.m_centerFrequency);
}
}
}
@ -1196,19 +1176,19 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
if (xtrx_tune_ex(m_deviceShared.m_dev->getDevice(),
XTRX_TUNE_BB_RX,
m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B,
(settings.m_ncoEnable) ? settings.m_ncoFrequency : 0,
(m_settings.m_ncoEnable) ? m_settings.m_ncoFrequency : 0,
NULL) < 0)
{
qCritical("XTRXInput::applySettings: could not %s and set NCO to %d Hz",
settings.m_ncoEnable ? "enable" : "disable",
settings.m_ncoFrequency);
m_settings.m_ncoEnable ? "enable" : "disable",
m_settings.m_ncoFrequency);
}
else
{
forwardChangeOwnDSP = true;
qDebug("XTRXInput::applySettings: %sd and set NCO to %d Hz",
settings.m_ncoEnable ? "enable" : "disable",
settings.m_ncoFrequency);
m_settings.m_ncoEnable ? "enable" : "disable",
m_settings.m_ncoFrequency);
}
}
}

Wyświetl plik

@ -179,6 +179,7 @@ bool XTRXInputGUI::handleMessage(const Message& message)
else if (XTRXInput::MsgReportClockGenChange::match(message))
{
m_settings.m_devSampleRate = m_XTRXInput->getDevSampleRate();
m_settings.m_log2HardDecim = m_XTRXInput->getLog2HardDecim();
blockApplySettings(true);
displaySettings();

Wyświetl plik

@ -337,6 +337,71 @@
<property name="topMargin">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="sampleRateMode">
<property name="minimumSize">
<size>
<width>24</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Toggle between device to host (SR) and base band (BB) sample rate input</string>
</property>
<property name="text">
<string>SR</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="ValueDial" name="sampleRate" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>12</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="toolTip">
<string>Device to host sample rate</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="samplerateUnit">
<property name="text">
<string>S/s</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="hwDecimLabel">
<property name="text">
@ -391,6 +456,11 @@
<string>32</string>
</property>
</item>
<item>
<property name="text">
<string>64</string>
</property>
</item>
</widget>
</item>
<item>
@ -467,71 +537,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="sampleRateMode">
<property name="minimumSize">
<size>
<width>24</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Toggle between device to host (SR) and base band (BB) sample rate input</string>
</property>
<property name="text">
<string>SR</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="ValueDial" name="sampleRate" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>12</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="toolTip">
<string>Device to host sample rate</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="samplerateUnit">
<property name="text">
<string>S/s</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

Wyświetl plik

@ -38,7 +38,7 @@
const PluginDescriptor XTRXInputPlugin::m_pluginDescriptor = {
QString("XTRX"),
QString("XTRX Input"),
QString("4.12.3"),
QString("4.14.4"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,