Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/audio/plugins/alsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
#include "alsa.h"
#include <cstring>
#include <memory>

#include <QCoreApplication>
#define ALSA_BUFFER_SIZE 1024
#define ALSA_PERIOD_SIZE 64
Expand All @@ -43,6 +45,10 @@ struct pcm_guard {
snd_pcm_t *handle = nullptr;
};

auto ptr_free = [](auto* ptr) {
return std::free(ptr);
};

namespace audio {

bool checkStatus(int errorCode, QString message = "", std::list<int> goodStatuses = {0});
Expand Down Expand Up @@ -72,14 +78,22 @@ DeviceInfo::List AlsaPlugin::getDeviceInfoList() const
{
DeviceInfo::List list = {};
int cardIndex = -1, deviceIndex = -1;
char *cardName = nullptr;
// inner ptr allocated via malloc (via strdup), so it needs free() instead of delete
std::unique_ptr<char, decltype(ptr_free)> cardName = {nullptr, ptr_free};
snd_pcm_t *pcm = nullptr;
snd_ctl_t *ctl = nullptr;

while (checkStatus(snd_card_next(&cardIndex), "snd_ctl_open") && (cardIndex > -1 )) {
char cardId[127];
snprintf(cardId, sizeof(cardId), "hw:%d", cardIndex);
checkContinue(snd_card_get_name(cardIndex, &cardName));
{
// TODO replace with C++23 std::out_ptr(card_name) instead of tmp_cardName
char* tmp_cardName = nullptr;
bool cont = snd_card_get_name(cardIndex, &tmp_cardName);
cardName.reset(tmp_cardName);
checkContinue(cont);

}
checkContinue(snd_ctl_open(&ctl, cardId, 0));

deviceIndex = -1;
Expand All @@ -89,7 +103,7 @@ DeviceInfo::List AlsaPlugin::getDeviceInfoList() const
snprintf(plugId, sizeof(plugId), "plughw:%d,%d", cardIndex, deviceIndex);

DeviceInfo deviceInfo(plugId, name());
QString deviceName(cardName);
QString deviceName(cardName.get());
deviceName += " #" + QString::number(deviceIndex);
deviceInfo.setName(deviceName);

Expand Down
2 changes: 1 addition & 1 deletion src/chart/coherenceplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void Chart::CoherenceThresholdLine::paint(QPainter *painter)
painter->setRenderHints(QPainter::Antialiasing, true);
painter->setPen(linePen);
painter->drawLine(p1, p2);
} catch (std::invalid_argument) {}
} catch (std::invalid_argument&) {}
}

void CoherenceThresholdLine::parentWidthChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/chart/magnitudeplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,5 @@ void MagnitudePlot::TargetTraceItem::paint(QPainter *painter) noexcept
}
path.lineTo(convert(points[0] + offset));
painter->drawPath(path);
} catch (std::invalid_argument) {}
} catch (std::invalid_argument&) {}
}
14 changes: 6 additions & 8 deletions src/chart/meterplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ QString MeterPlot::typeName() const noexcept
{
try {
return m_typesMap.at(m_type);
} catch (std::out_of_range) {}
} catch (std::out_of_range&) {}

return "";
}
Expand All @@ -380,14 +380,12 @@ void MeterPlot::setType(const Type &type)

void MeterPlot::setType(const QString &type)
{
std::find_if(m_typesMap.cbegin(), m_typesMap.cend(),
[&type, this](auto & e) {
if (e.second == type) {
setType(e.first);
return true;
for (auto& [enumType, strType] : m_typesMap) {
if (strType == type) {
setType(enumType);
return;
}
return false;
});
}
}

} // namespace chart
2 changes: 1 addition & 1 deletion src/chart/rtaplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void RTAPlot::setShowPeaks(bool showPeaks)

bool RTAPlot::isPointsPerOctaveValid(unsigned int &value) const
{
return value >= 0 && value <= 48;
return value <= 48; // >= 0 omitted since value is unsigned
}

RTAPlot::Scale RTAPlot::scale() const
Expand Down
1 change: 1 addition & 0 deletions src/filtersource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ complex FilterSource::calculate(float frequency) const
case Peak:
return calculatePeak(s);
}
return 1; // is this the sensible default?
}

complex FilterSource::Bessel(bool hpf, complex s) const
Expand Down
7 changes: 4 additions & 3 deletions src/generator/sinburst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QtMath>
#include "sinburst.h"

#include <cmath>

SinBurst::SinBurst(QObject *parent)
: OutputDevice{parent},
m_frequency(1000.f),
Expand Down Expand Up @@ -48,8 +49,8 @@ Sample SinBurst::sample()
}
}

const static float PI10 = M_PI / 10;
Sample output = { m_burst ? m_gain *static_cast<float>(sin(m_phase)) *sin(m_periods * PI10) / 2 : 0.f };
constexpr static float PI10 = M_PI / 10.0;
Sample output = { m_burst ? m_gain * static_cast<float>(std::sin(m_phase)) * std::sin(m_periods * PI10) / 2.f : 0.f };
return output;
}

Expand Down
2 changes: 2 additions & 0 deletions src/math/windowfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ float WindowFunction::pointGain(float i, unsigned int N) const
return std::pow(M_E, power);
}
}
// no windowing
return 1.0;
}

WindowFunction::Type WindowFunction::type() const
Expand Down
2 changes: 1 addition & 1 deletion src/remote/generatorremote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void GeneratorRemote::connectProperties()
}
}

void GeneratorRemote::dataError(const uint hash, const bool deactivate)
void GeneratorRemote::dataError(const uint hash, const bool)
{
if (hash != qHash(serverId())) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/remote/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void Item::properiesChanged()


property("active");
if (!m_eventSilence && signalName != "stateChanged" & signalName != "activeChanged" ) {
if (!m_eventSilence && signalName != "stateChanged" && signalName != "activeChanged" ) {
emit localChanged(propertyName);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/source/sourcewindowing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ void Windowing::resizeData()
case Mode::LTW3:
m_dataFT.setLogWindowDenominator(25);
break;
default:
qDebug() << "unhandled usedMode" << m_usedMode; // Namely the different FFT modes, can they be handled?
}
m_dataFT.prepare();

Expand Down Expand Up @@ -358,7 +360,8 @@ void Windowing::updateFromTimeDomain(const Source::Shared &source)

auto windowKoefficient = m_window.gain() / m_window.norm();
int j = 0;
for (int i = from/*, j = 0*/, f = m_deconvolutionSize / 2 + 1; i < end; ++i, ++j, time += dt, ++f) {
unsigned int f = m_deconvolutionSize / 2 + 1;
for (int i = from/*, j = 0*/; i < end; ++i, ++j, time += dt, ++f) {

float value = (i >= 0 ? source->impulseValue(i) * m_window.get(j) * windowKoefficient : 0);

Expand Down
6 changes: 3 additions & 3 deletions src/targettrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const QList<std::pair<QString, std::vector<QPointF>>> TargetTrace::m_presets = {
};

TargetTrace::TargetTrace(Settings *settings, QObject *parent) : QObject(parent),
m_points{ m_presets[0].second }, m_settings(settings), m_preset(0)
m_points{ m_presets[0].second }, m_preset(0), m_settings(settings)
{
Q_ASSERT(!m_instance);

Expand Down Expand Up @@ -199,9 +199,9 @@ void TargetTrace::setPreset(unsigned newPreset)

std::lock_guard<std::mutex> guard(m_mutex);

if (m_presets.size() > newPreset) {
if (static_cast<unsigned>(m_presets.size()) > newPreset) {
m_preset = newPreset;
for (auto i = 0; i < m_points.size(); ++i) {
for (std::size_t i = 0; i < static_cast<std::size_t>(m_points.size()); ++i) {
m_points[i].setX(m_presets[m_preset].second[i].x());
m_points[i].setY(m_presets[m_preset].second[i].y());
}
Expand Down
2 changes: 1 addition & 1 deletion src/targettrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TargetTrace : public QObject
QColor m_color = "#8BC34A";

std::vector<QPointF> m_points;
unsigned m_preset;
unsigned int m_preset;

Settings *m_settings = nullptr;
static TargetTrace *m_instance;
Expand Down