ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
SpectrumHistory Class Reference

Runtime-sized ring buffer stored in one 1D array texture. More...

Public Member Functions

void bind () const
 Bind the complete spectrum history array to its single texture unit.
void cleanup ()
 Delete the array texture and reset state.
int count () const
 Number of history layers currently allocated.
int init (int requested_count)
 Allocate one array texture with requested_count history layers.
int newestLayer () const
 Physical layer containing the newest spectrum frame.
 SpectrumHistory (const acmx2::audio::AudioAnalyzer &analyzer)
void update (float scale=0.0f)
 Push the current FFT magnitudes into the head of the ring buffer.
 ~SpectrumHistory ()

Static Public Attributes

static constexpr int TEXTURE_UNIT = 10
 Texture unit assigned to the complete spectrum history array.

Private Attributes

const acmx2::audio::AudioAnalyzer & analyzer
int bins = 0
 Texels per layer (== FFT_SIZE / 2).
int layer_count = 0
 Runtime-selected array depth.
std::vector< float > scaled_buf
 Scratch for sensitivity-scaled magnitudes.
GLuint texture_id = 0
 One GL_TEXTURE_1D_ARRAY object.
int write_idx = 0
 Next physical layer to overwrite.

Detailed Description

Runtime-sized ring buffer stored in one 1D array texture.

Enabled via the --enable-audio-buffers <N> CLI option. Allocates one GL_TEXTURE_1D_ARRAY with N GL_R32F layers and exposes it to GLSL as uniform sampler1DArray spectrum_history;. The requested layer count is clamped only to the active GPU's GL_MAX_ARRAY_TEXTURE_LAYERS limit.

Each call to update() writes the current FFT magnitudes into the layer at the ring head and advances the head. No texture data is copied between layers. Shaders use spectrum_history_head and spectrum_history_size to convert a logical age into a physical layer.

The complete array uses only texture unit 10. Unit 9 remains the live spectrum/spectrum0 texture.

Definition at line 2947 of file ACMX2/acmx.cpp.

Constructor & Destructor Documentation

◆ SpectrumHistory()

SpectrumHistory::SpectrumHistory ( const acmx2::audio::AudioAnalyzer & analyzer)
inlineexplicit

Definition at line 2949 of file ACMX2/acmx.cpp.

References analyzer.

◆ ~SpectrumHistory()

SpectrumHistory::~SpectrumHistory ( )
inline

Definition at line 3041 of file ACMX2/acmx.cpp.

References cleanup().

Member Function Documentation

◆ bind()

void SpectrumHistory::bind ( ) const
inline

Bind the complete spectrum history array to its single texture unit.

Definition at line 3017 of file ACMX2/acmx.cpp.

References texture_id, and TEXTURE_UNIT.

◆ cleanup()

void SpectrumHistory::cleanup ( )
inline

Delete the array texture and reset state.

Definition at line 3032 of file ACMX2/acmx.cpp.

References layer_count, texture_id, and write_idx.

Referenced by init(), ACView::~ACView(), and ~SpectrumHistory().

◆ count()

int SpectrumHistory::count ( ) const
inline

Number of history layers currently allocated.

Definition at line 3029 of file ACMX2/acmx.cpp.

References layer_count.

◆ init()

int SpectrumHistory::init ( int requested_count)
inline

Allocate one array texture with requested_count history layers.

Parameters
requested_countNumber of requested history frames.
Returns
The allocated layer count after applying the GPU limit.

Definition at line 2960 of file ACMX2/acmx.cpp.

References bins, cleanup(), FFT_SIZE, layer_count, texture_id, and write_idx.

◆ newestLayer()

int SpectrumHistory::newestLayer ( ) const
inline

Physical layer containing the newest spectrum frame.

Definition at line 3026 of file ACMX2/acmx.cpp.

References layer_count, and write_idx.

◆ update()

void SpectrumHistory::update ( float scale = 0.0f)
inline

Push the current FFT magnitudes into the head of the ring buffer.

Reuses magnitudes already computed by SpectrumTexture::update() for the same frame (caller must invoke that first). When scale is non-zero, magnitudes are multiplied by it (matching the live spectrum's sensitivity scaling).

Definition at line 2999 of file ACMX2/acmx.cpp.

References analyzer, bins, layer_count, scaled_buf, acmx2::audio::AudioAnalyzer::spectrum(), texture_id, and write_idx.

Member Data Documentation

◆ analyzer

const acmx2::audio::AudioAnalyzer& SpectrumHistory::analyzer
private

Definition at line 3044 of file ACMX2/acmx.cpp.

Referenced by SpectrumHistory(), and update().

◆ bins

int SpectrumHistory::bins = 0
private

Texels per layer (== FFT_SIZE / 2).

Definition at line 3046 of file ACMX2/acmx.cpp.

Referenced by init(), and update().

◆ layer_count

int SpectrumHistory::layer_count = 0
private

Runtime-selected array depth.

Definition at line 3047 of file ACMX2/acmx.cpp.

Referenced by cleanup(), count(), init(), newestLayer(), and update().

◆ scaled_buf

std::vector<float> SpectrumHistory::scaled_buf
private

Scratch for sensitivity-scaled magnitudes.

Definition at line 3049 of file ACMX2/acmx.cpp.

Referenced by update().

◆ texture_id

GLuint SpectrumHistory::texture_id = 0
private

One GL_TEXTURE_1D_ARRAY object.

Definition at line 3045 of file ACMX2/acmx.cpp.

Referenced by bind(), cleanup(), init(), and update().

◆ TEXTURE_UNIT

int SpectrumHistory::TEXTURE_UNIT = 10
staticconstexpr

Texture unit assigned to the complete spectrum history array.

Definition at line 2952 of file ACMX2/acmx.cpp.

Referenced by bind(), ShaderLibrary::update(), ShaderLibrary::updateShaderUniforms(), and ShaderLibrary::updateShaderUniforms2D().

◆ write_idx

int SpectrumHistory::write_idx = 0
private

Next physical layer to overwrite.

Definition at line 3048 of file ACMX2/acmx.cpp.

Referenced by cleanup(), init(), newestLayer(), and update().


The documentation for this class was generated from the following file: