Commit d23a767c authored by Leander Schulten's avatar Leander Schulten

Audio + GUI: You can now see the raw (not logarithmic) spectrum in the gui

parent 855f8f17
......@@ -98,10 +98,14 @@ void AudioCaptureManager::dataCallback(float* data, unsigned int frames, bool*do
}
// db scale
auto spectrum = spectrumAnalysis->getSpectrum();
std::transform(spectrum.cbegin(), spectrum.cend(), spectrumAnalysis->getPointerToSpectrum(), [](auto i) { return 10 * std::log10(1 + i); });
std::transform(spectrum.cbegin(), spectrum.cend(), spectrumLogarithmic.begin(), [](auto i) { return 10 * std::log10(1 + i); });
if (GUI::Graph::getLast() && run) {
GUI::Graph::getLast()->showData(spectrumAnalysis->getPointerToSpectrum(), spectrum.size());
if (GUI::Graph::getLast()->useLogarithmicScale()) {
GUI::Graph::getLast()->showData(spectrumLogarithmic.data(), static_cast<int>(spectrumLogarithmic.size()));
} else {
GUI::Graph::getLast()->showData(spectrumAnalysis->getPointerToSpectrum(), static_cast<int>(spectrum.size()));
}
}
if (GUI::Colorplot::getLast() && run) {
GUI::Colorplot::getLast()->startBlock();
......
......@@ -44,6 +44,7 @@ class AudioCaptureManager : public QObject
// we use a optional to delay the creation of the object until we know the samplesPerFrame value
std::optional<Aubio::SpectrumAnalysis> spectrumAnalysis;
static constexpr int SPECTRUM_BUCKET_COUNT = 2048;
std::array<float, SPECTRUM_BUCKET_COUNT + 1> spectrumLogarithmic;
int channels = -1;
int samplesPerSecond = -1;
......
......@@ -15,6 +15,13 @@ Graph::~Graph() {
}
}
void Graph::setUseLogarithmicScale(bool use) {
if (useLogarithmicScale_ != use) {
useLogarithmicScale_ = use;
emit useLogarithmicScaleChanged();
}
}
void Graph::fillVertexData(QSGGeometry::Point2D *vertices) {
const auto &data = getData();
for (int i = 0; i < static_cast<int>(data.size()); ++i) {
......
......@@ -8,6 +8,8 @@ namespace GUI {
class Graph : public LineGeometry {
Q_OBJECT
static Graph *lastCreated;
bool useLogarithmicScale_ = true;
Q_PROPERTY(bool useLogarithmicScale READ useLogarithmicScale WRITE setUseLogarithmicScale NOTIFY useLogarithmicScaleChanged)
public:
explicit Graph(QQuickItem *parent = nullptr);
......@@ -16,9 +18,15 @@ public:
static Graph *getLast() { return lastCreated; }
[[nodiscard]] bool useLogarithmicScale() const { return useLogarithmicScale_; }
void setUseLogarithmicScale(bool use);
private:
void fillVertexData(QSGGeometry::Point2D *vertices) override;
void processNewData() override;
signals:
void useLogarithmicScaleChanged();
};
} // namespace GUI
......
......@@ -113,6 +113,13 @@ Item {
anchors.horizontalCenter: parent.handle.horizontalCenter
}
}
Item {}
CheckBox {
text: "Logarithmic scale"
checked: graph.useLogarithmicScale
onCheckedChanged: graph.useLogarithmicScale = checked
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment