commit no. 2

This commit is contained in:
2026-03-25 19:46:50 +01:00
parent a513c66503
commit f45278123f
6 changed files with 328 additions and 72 deletions

View File

@@ -10,12 +10,62 @@
#include "ui/Cursors.h"
#include <SDL.h>
#include <complex>
#include <memory>
#include <string>
#include <vector>
namespace baudline {
// ── Channel math operations ──────────────────────────────────────────────────
enum class MathOp {
// Unary (on channel X)
Negate, // -x (negate dB)
Absolute, // |x| (absolute value of dB)
Square, // x^2 in linear → 2*x_dB
Cube, // x^3 in linear → 3*x_dB
Sqrt, // sqrt in linear → 0.5*x_dB
Log, // 10*log10(10^(x_dB/10) + 1) — compressed scale
// Binary (on channels X and Y)
Add, // linear(x) + linear(y) → dB
Subtract, // |linear(x) - linear(y)| → dB
Multiply, // x_dB + y_dB (multiply in linear = add in dB)
Phase, // angle(X_cplx * conj(Y_cplx)) in degrees
CrossCorr, // |X_cplx * conj(Y_cplx)| → dB
Count
};
inline bool mathOpIsBinary(MathOp op) {
return op >= MathOp::Add;
}
inline const char* mathOpName(MathOp op) {
switch (op) {
case MathOp::Negate: return "-x";
case MathOp::Absolute: return "|x|";
case MathOp::Square: return "x^2";
case MathOp::Cube: return "x^3";
case MathOp::Sqrt: return "sqrt(x)";
case MathOp::Log: return "log(x)";
case MathOp::Add: return "x + y";
case MathOp::Subtract: return "x - y";
case MathOp::Multiply: return "x * y";
case MathOp::Phase: return "phase(x,y)";
case MathOp::CrossCorr: return "xcorr(x,y)";
default: return "?";
}
}
struct MathChannel {
MathOp op = MathOp::Subtract;
int sourceX = 0;
int sourceY = 1;
ImVec4 color = {1.0f, 1.0f, 1.0f, 1.0f};
bool enabled = true;
bool waterfall = false; // include on waterfall overlay
};
class Application {
public:
Application();
@@ -36,6 +86,8 @@ private:
void openPortAudio();
void openFile(const std::string& path, InputFormat format, double sampleRate);
void updateAnalyzerSettings();
void computeMathChannels();
void renderMathPanel();
// SDL / GL / ImGui
SDL_Window* window_ = nullptr;
@@ -103,6 +155,10 @@ private:
bool waterfallMultiCh_ = true; // true = multi-channel overlay mode
bool channelEnabled_[kMaxChannels] = {true,true,true,true,true,true,true,true};
// Math channels
std::vector<MathChannel> mathChannels_;
std::vector<std::vector<float>> mathSpectra_; // computed each frame
// Spectrum panel geometry (stored for cursor interaction)
float specPosX_ = 0, specPosY_ = 0, specSizeX_ = 0, specSizeY_ = 0;
};