Modal Synthesis

Physics-Based Sound Synthesis via Finite Element Modal Analysis

FEM CUDA OpenGL 4.5 PortAudio ImGui
33+
Preset Scenes
8
Interaction Modes
120
Max Eigenmodes
Theory

📐 Finite Element Method

Structures are discretized into triangular mesh elements. Each node has degrees of freedom (DOFs) representing displacement. The system is governed by the generalized eigenvalue problem:

K · φ = ω² · M · φ

where K is the stiffness matrix, M is the mass matrix, ω are the natural frequencies, and φ are the mode shapes.

Element Types

ElementDOFs/NodeApplication
CST (Constant Strain Triangle)2 (ux, uy)Membrane vibration
Euler-Bernoulli Beam3 (ux, uy, θ)Strings, beam shells
DKT (Discrete Kirchhoff Triangle)3 (w, θx, θy)Plate bending

Eigensolvers

MethodWhen Used
cuSOLVER (GPU dense)Small matrices (<2000 DOF)
Shift-invert Lanczos (CPU)Large sparse matrices
SimplicialLDLTFree-free boundary conditions
Audio

🔊 Modal Synthesis

Each mode is an independent damped harmonic oscillator. The total displacement (and sound pressure) is the superposition of all modes:

p(t) = Σᵢ αᵢ · Aᵢ · e−ζωᵢ(t−t₀) · sin(ωd,ᵢ · (t−t₀))

This closed-form solution is evaluated on GPU via CUDA — one thread per audio sample, all modes summed in parallel. 44.1kHz, 512-sample buffer, zero-latency analytical evaluation.

Post-Processing Chain

1-pole LP Filter Soft Clip (tanh) Peak Auto-Normalize Frequency Drift
Visualization

🌊 Medium Propagation

Acoustic radiation visualized in real-time using a Kirchhoff boundary integral evaluated on GPU via OpenGL compute shader:

p(x,t) = Σⱼ vn,ⱼ · sin(ω(t − rⱼ/c)) / √rⱼ · cos(θⱼ)

Each boundary node acts as a point source with retarded time. The compute shader evaluates this at every pixel (up to 1920×1080), with per-pixel point-in-mesh occlusion testing.

Features

  • ✦ Pixel-perfect resolution
  • ✦ Deformed mesh mask (follows vibration)
  • ✦ Directional radiation (cos θ weighting)
  • ✦ Blue/red phase coloring with exposure control

Acoustic Feedback

Optional medium→structure coupling: pressure at each boundary node from other sources is computed and applied as force, enabling sympathetic resonance between separate structures through the air.

Tools

🎹 Instrument Builder

Interactive tuning mode for creating custom instruments with precise pitch control:

7 Component Shapes

String Box-2 Elastic Box-Open Triangle Hexagon Box-Hard Ring

Fine-Tuning

Fine-W (binary search) Fine-Size (uniform) Fine-WH (alternating 2D)

Converges within ±2 cents of target. Auto-retry with jitter on collapse.

Export / Import

Native file dialogs. Save tuned instruments as .txt files. 8 notes per instrument (C major scale, any octave C1–C8).

Architecture

📁 Code Structure

libmodal/
src/fem/element_cst.cpp — CST membrane
src/fem/element_beam.cpp — Euler-Bernoulli beam
src/fem/element_dkt.cpp — DKT plate bending
src/fem/assembler.cpp — K,M assembly
src/solver/eigensolve.cpp — GPU/CPU eigensolver
src/audio/synthesis.cu — CUDA audio kernel
src/modal_api.cpp — Public C API
modal_viewer/
src/app/app.cpp — Main loop, state machine
src/renderer/mesh_renderer.cpp — OpenGL mesh
src/renderer/shader.cpp — GLSL shaders
src/audio/audio_engine.cpp — PortAudio callback
src/ui/ui_manager.cpp — ImGui toolbar
src/ui/viz_spectrum.cpp — Frequency spectrum
Content

🎼 33 Preset Scenes

Basic Shapes

Rect, Circle, L-Shape, Triangle, Tuning Fork, Ring, String, Cross, Star

Instruments

Harp, Piano, Guitar, Guitar+, Piano+, Violin, Harp+, Bow Strings

Resonators

Box variants, BigBox, HexBox, DoubleBox, Tuned8/12, Bell shapes, Open+Box, Glass chambers

Interaction

👆 8 Interaction Modes

ModeDescription
StrikeSingle impulse at click point
RapidContinuous strikes at 20Hz while held
BowGentle continuous excitation at 30Hz
PluckClick-drag to set force direction, release to strike
SweepFrequency sweep 20Hz–2kHz to find resonances
RegionCircular area strike with linear falloff
Blow*Sinusoidal excitation at local resonant frequency
Bow+Friction-based bowing with stick-slip accumulator
Stack

⚡ Technology

ComponentTechnology
FEM AssemblyEigen (C++ linear algebra)
EigensolvercuSOLVER + custom Lanczos
Audio SynthesisCUDA kernel (1 thread/sample)
Audio OutputPortAudio (44.1kHz, float32)
ComponentTechnology
RenderingOpenGL 4.5 Core + GLSL 450
Medium VizGL Compute Shader
UIDear ImGui (docking branch)
MeshingTriangle (Delaunay lib)
Roadmap

🚀 Future Directions

Near-term

3D Solid Elements — Tetrahedral FEM for volumetric vibration. Requires 3D mesher (TetGen) and 3D rendering.

Near-term

Per-Mode Damping — Frequency-dependent damping instead of uniform ζ. Higher modes decay faster (material-accurate).

Medium-term

Tension-Based Strings — Wave equation elements (f ∝ 1/L) instead of beam bending (f ∝ 1/L²) for realistic string sound.

Medium-term

Convolution Reverb — Room impulse response applied post-synthesis for spatial realism.

Long-term

BEM Acoustic Radiation — Full Boundary Element Method replacing the simplified Kirchhoff integral for accurate far-field radiation patterns.

Long-term

Multi-Material Regions — Per-element material properties for composite structures (wood body + steel strings + brass frets).