commit no. 5

This commit is contained in:
2026-03-25 19:47:37 +01:00
parent 0c7ff40638
commit 7503052079
8 changed files with 76 additions and 57 deletions

View File

@@ -183,24 +183,24 @@ void Application::processAudio() {
int nSpec = analyzer_.numSpectra();
if (waterfallMultiCh_ && nSpec > 1) {
// Multi-channel overlay waterfall: physical + math channels.
std::vector<std::vector<float>> wfSpectra;
std::vector<WaterfallChannelInfo> wfChInfo;
wfSpectraScratch_.clear();
wfChInfoScratch_.clear();
for (int ch = 0; ch < nSpec; ++ch) {
const auto& c = channelColors_[ch % kMaxChannels];
wfSpectra.push_back(analyzer_.channelSpectrum(ch));
wfChInfo.push_back({c.x, c.y, c.z,
wfSpectraScratch_.push_back(analyzer_.channelSpectrum(ch));
wfChInfoScratch_.push_back({c.x, c.y, c.z,
channelEnabled_[ch % kMaxChannels]});
}
for (size_t mi = 0; mi < mathChannels_.size(); ++mi) {
if (mathChannels_[mi].enabled && mathChannels_[mi].waterfall &&
mi < mathSpectra_.size()) {
const auto& c = mathChannels_[mi].color;
wfSpectra.push_back(mathSpectra_[mi]);
wfChInfo.push_back({c.x, c.y, c.z, true});
wfSpectraScratch_.push_back(mathSpectra_[mi]);
wfChInfoScratch_.push_back({c.x, c.y, c.z, true});
}
}
waterfall_.pushLineMulti(wfSpectra, wfChInfo, minDB_, maxDB_);
waterfall_.pushLineMulti(wfSpectraScratch_, wfChInfoScratch_, minDB_, maxDB_);
} else {
int wfCh = std::clamp(waterfallChannel_, 0, nSpec - 1);
waterfall_.pushLine(analyzer_.channelSpectrum(wfCh),
@@ -601,37 +601,34 @@ void Application::renderSpectrumPanel() {
// Build per-channel styles and combine physical + math spectra.
int nPhys = analyzer_.numSpectra();
int nMath = static_cast<int>(mathSpectra_.size());
int nTotal = nPhys + nMath;
std::vector<std::vector<float>> allSpectra;
std::vector<ChannelStyle> styles;
allSpectra.reserve(nTotal);
styles.reserve(nTotal);
allSpectraScratch_.clear();
stylesScratch_.clear();
// Physical channels.
for (int ch = 0; ch < nPhys; ++ch) {
allSpectra.push_back(analyzer_.channelSpectrum(ch));
allSpectraScratch_.push_back(analyzer_.channelSpectrum(ch));
const auto& c = channelColors_[ch % kMaxChannels];
uint8_t r = static_cast<uint8_t>(c.x * 255);
uint8_t g = static_cast<uint8_t>(c.y * 255);
uint8_t b = static_cast<uint8_t>(c.z * 255);
styles.push_back({IM_COL32(r, g, b, 220), IM_COL32(r, g, b, 35)});
stylesScratch_.push_back({IM_COL32(r, g, b, 220), IM_COL32(r, g, b, 35)});
}
// Math channels.
for (int mi = 0; mi < nMath; ++mi) {
if (mi < static_cast<int>(mathChannels_.size()) && mathChannels_[mi].enabled) {
allSpectra.push_back(mathSpectra_[mi]);
allSpectraScratch_.push_back(mathSpectra_[mi]);
const auto& c = mathChannels_[mi].color;
uint8_t r = static_cast<uint8_t>(c.x * 255);
uint8_t g = static_cast<uint8_t>(c.y * 255);
uint8_t b = static_cast<uint8_t>(c.z * 255);
styles.push_back({IM_COL32(r, g, b, 220), IM_COL32(r, g, b, 35)});
stylesScratch_.push_back({IM_COL32(r, g, b, 220), IM_COL32(r, g, b, 35)});
}
}
specDisplay_.updatePeakHold(allSpectra);
specDisplay_.draw(allSpectra, styles, minDB_, maxDB_,
specDisplay_.updatePeakHold(allSpectraScratch_);
specDisplay_.draw(allSpectraScratch_, stylesScratch_, minDB_, maxDB_,
settings_.sampleRate, settings_.isIQ, freqScale_,
specPosX_, specPosY_, specSizeX_, specSizeY_,
viewLo_, viewHi_);

View File

@@ -170,6 +170,12 @@ private:
// Panel geometry (stored for cursor interaction)
float specPosX_ = 0, specPosY_ = 0, specSizeX_ = 0, specSizeY_ = 0;
float wfPosX_ = 0, wfPosY_ = 0, wfSizeX_ = 0, wfSizeY_ = 0;
// Pre-allocated scratch buffers (avoid per-frame heap allocations)
std::vector<std::vector<float>> wfSpectraScratch_;
std::vector<WaterfallChannelInfo> wfChInfoScratch_;
std::vector<std::vector<float>> allSpectraScratch_;
std::vector<ChannelStyle> stylesScratch_;
};
} // namespace baudline

View File

@@ -71,28 +71,35 @@ void WaterfallDisplay::pushLineMulti(
float minDB, float maxDB) {
if (width_ == 0 || height_ == 0) return;
int nCh = static_cast<int>(channelSpectra.size());
int row = currentRow_;
int rowOffset = row * width_ * 3;
float range = maxDB - minDB;
if (range < 1.0f) range = 1.0f;
float invRange = 1.0f / range;
// Pre-filter enabled channels to avoid per-texel branching.
struct ActiveCh { const float* data; int bins; float r, g, b; };
activeChBuf_.clear();
int nCh = std::min(static_cast<int>(channelSpectra.size()),
static_cast<int>(channels.size()));
for (int ch = 0; ch < nCh; ++ch) {
if (!channels[ch].enabled || channelSpectra[ch].empty()) continue;
activeChBuf_.push_back({channelSpectra[ch].data(),
static_cast<int>(channelSpectra[ch].size()),
channels[ch].r, channels[ch].g, channels[ch].b});
}
// One texel per bin — direct 1:1 mapping.
for (int x = 0; x < width_; ++x) {
float accR = 0.0f, accG = 0.0f, accB = 0.0f;
for (int ch = 0; ch < nCh; ++ch) {
if (ch >= static_cast<int>(channels.size()) || !channels[ch].enabled)
continue;
if (channelSpectra[ch].empty()) continue;
for (const auto& ac : activeChBuf_) {
float dB = (x < ac.bins) ? ac.data[x] : -200.0f;
float intensity = std::clamp((dB - minDB) * invRange, 0.0f, 1.0f);
int bins = static_cast<int>(channelSpectra[ch].size());
float dB = (x < bins) ? channelSpectra[ch][x] : -200.0f;
float intensity = std::clamp((dB - minDB) / range, 0.0f, 1.0f);
accR += channels[ch].r * intensity;
accG += channels[ch].g * intensity;
accB += channels[ch].b * intensity;
accR += ac.r * intensity;
accG += ac.g * intensity;
accB += ac.b * intensity;
}
pixelBuf_[rowOffset + x * 3 + 0] =
@@ -112,7 +119,7 @@ void WaterfallDisplay::uploadRow(int row) {
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, row, width_, 1,
GL_RGB, GL_UNSIGNED_BYTE,
pixelBuf_.data() + row * width_ * 3);
glBindTexture(GL_TEXTURE_2D, 0);
// Note: no unbind — ImGui will bind its own textures before drawing.
}
} // namespace baudline

View File

@@ -49,6 +49,10 @@ private:
ColorMap colorMap_;
std::vector<uint8_t> pixelBuf_;
// Scratch buffer for pushLineMulti (pre-filtered enabled channels).
struct ActiveCh { const float* data; int bins; float r, g, b; };
std::vector<ActiveCh> activeChBuf_;
};
} // namespace baudline