# andruxa-smirnov/signalhound_spectrum_analyzer architecture

> Architecture diagram of the GitHub repository andruxa-smirnov/signalhound_spectrum_analyzer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andruxa-smirnov/signalhound_spectrum_analyzer
- Repository: https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer

## Overview

##### Project Type and Purpose
- This is a Windows-only, Qt5 C++ desktop application (“Spike Spectrum Analysis Software”) that drives Signal Hound spectrum analyzers.
- It provides a rich GUI (Qt widgets and OpenGL views), interacts with the hardware via the Signal Hound C++ API (sa_api.dll), and performs DSP (FFT via kiss_fft) to render spectrum, phase noise, demodulation, and other plots.

##### High-Level Components
a. External Hardware & API
- Signal Hound Spectrum Analyzer Device
- sa_api.dll / sa_api.lib (C++ DLL interface)
b. Core Library Layer (BBApp/src/lib)
- bb_lib.cpp/h, device_traits, threadsafe_queue, time_type, etc.
- Wraps sa_api calls, manages raw IQ/sample data, threading, queuing
c. DSP Engine (BBApp/src/src/kiss_fft)
- kiss_fft routines, test harnesses, tools
d. Application Model (BBApp/src/model)
- Domain objects: Device, Session, TraceManager, Settings, Persistence
- Encapsulates application state, audio/demodulation/sweep parameters
e. Presentation Layer
- Views (BBApp/src/views): OpenGL plots, central “controllers” for each measurement type
- Widgets (BBApp/src/widgets): dialog panels, controls, toolbars, status bar
f. Entry Point & Qt Integration
- main.cpp and MainWindow (BBApp/src/main.cpp, mainwindow.cpp/h)
g. Build System
- Qt .pro file, generated Makefiles, link against sa_api.lib and bb_api.lib

##### Relationships and Data Flows
- On startup, main() and MainWindow initialize the Model and UI
- User interacts with Widgets → Model settings update (e.g., sweep_settings, demod_settings)
- Model instructs Core Library to open device via sa_api
- Core Library spawns data‐acquisition thread → continuous raw samples from hardware
- Raw data sent through threadsafe_queue → DSP Engine (kiss_fft) transforms to frequency domain
- Processed data pushed to TraceManager → notifies Views to repaint OpenGL widgets
- Views pull data from TraceManager & Model, render plots, and send user commands back to Model

##### Architectural Patterns & Principles
- MVC / MVVM-style separation:
- Model layer holds state and business logic
- Views/widgets present data and capture user input
- Core Library abstracts hardware and DSP details
- Threading & Concurrency
- Data acquisition and UI run in separate threads
- threadsafe_queue ensures lock-free data exchange
- Plugin-like extensibility
- Adding new measurement types only requires new Model + View components

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Hardware & API"
        device["SignalHound Device"]:::external
        apiDLL["sa_api.dll / sa_api.lib"]:::external
        device -->|communicates| apiDLL
    end

    subgraph "Core Library Layer"
        libDir["BBApp/src/lib"]:::core
        bbLib["bb_lib.cpp/h (C++11)"]:::core
        queue["threadsafe_queue.h"]:::core
        timeType["time_type.cpp/h"]:::core
        deviceTraits["device_traits.cpp/h"]:::core
        libDir --> bbLib
        libDir --> queue
        libDir --> timeType
        libDir --> deviceTraits
    end

    apiDLL -->|wrapped by| libDir

    subgraph "DSP Engine"
        dspDir["BBApp/src/kiss_fft"]:::dsp
        fft["kiss_fft.c/h (FFT)"]:::dsp
        guts["_kiss_fft_guts.h"]:::dsp
        dspDir --> fft
        dspDir --> guts
    end

    libDir -->|raw IQ samples| queue -->|FFT input| dspDir

    subgraph "Application Model"
        modelDir["BBApp/src/model"]:::model
        traceMgr["trace_manager.cpp/h"]:::model
        settings["sweep_settings.cpp/h"]:::model
        demodSettings["demod_settings.cpp/h"]:::model
        modelDir --> traceMgr
        modelDir --> settings
        modelDir --> demodSettings
    end

    dspDir -->|processed data| traceMgr

    subgraph "Presentation Layer"
        subgraph "Views"
            viewsDir["BBApp/src/views"]:::ui
            viewPlots["OpenGL Plots & Controllers (Qt5/OpenGL)"]:::ui
            viewsDir --> viewPlots
        end
        subgraph "Widgets"
            widgetsDir["BBApp/src/widgets"]:::ui
            controls["GUI Panels & Dialogs (Qt Widgets)"]:::ui
            widgetsDir --> controls
        end
    end

    traceMgr -->|data for render| viewPlots
    controls -->|user actions| settings
    viewPlots -->|UI commands| settings

    subgraph "Entry Point & Qt Integration"
        mainFiles["BBApp/src/main.cpp & mainwindow.cpp/h"]:::external
        resources["BBApp/resources (QRC, CSS, icons)"]:::external
        mainFiles --> resources
    end

    mainFiles -->|initialize| settings
    mainFiles -->|initialize| viewPlots
    mainFiles -->|initialize| controls
    mainFiles -->|calls| apiDLL

    subgraph "Build System"
        pro["BBApp/BBApp.pro"]:::build
        make["build/Makefile*"]:::build
        pro --> make
    end

    classDef external fill:#999999,stroke:#333,color:#fff
    classDef core fill:#0074D9,stroke:#03396C,color:#fff
    classDef dsp fill:#7FDBFF,stroke:#39CCCC,color:#000
    classDef model fill:#2ECC40,stroke:#01A04F,color:#fff
    classDef ui fill:#FF851B,stroke:#FF4136,color:#fff
    classDef build fill:#FFDC00,stroke:#B8860B,color:#000

    click apiDLL "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/sa_api.lib"
    click libDir "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/tree/master/BBApp/src/lib"
    click bbLib "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/lib/bb_lib.cpp"
    click queue "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/lib/threadsafe_queue.h"
    click dspDir "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/tree/master/BBApp/src/kiss_fft"
    click fft "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/kiss_fft/kiss_fft.c"
    click modelDir "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/tree/master/BBApp/src/model"
    click traceMgr "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/model/trace_manager.cpp"
    click settings "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/model/sweep_settings.cpp"
    click viewsDir "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/tree/master/BBApp/src/views"
    click viewPlots "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/views/trace_view.cpp"
    click widgetsDir "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/tree/master/BBApp/src/widgets"
    click controls "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/widgets/sweep_panel.cpp"
    click mainFiles "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/src/main.cpp"
    click resources "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/resources/bb_app.qrc"
    click pro "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/blob/master/BBApp/BBApp.pro"
    click make "https://github.com/andruxa-smirnov/signalhound_spectrum_analyzer/tree/master/build/Makefile"
```
