Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::dsp::pm::MassSpringDamper Class Reference

Detailed Description

Definition at line 63 of file mass_spring_damper.hpp.

#include <mass_spring_damper.hpp>

Public Member Functions

 MassSpringDamper ()
 
void set_frequency (float hz)
 Undamped resonance, Hz.
 
void set_q (float q)
 Quality factor: how many cycles the ringing lasts.
 
void set_mass (float m)
 Mass in string-impedance units; heavier is closer to rigid.
 
void set_resonance (float hz, float q, float match)
 The musical parametrisation: where, how wide, how much it takes.
 
float frequency () const
 
float q () const
 
float mass () const
 
float match () const
 The damper relative to the string's impedance: c / Z with Z = 1.
 
float admittance () const
 Instantaneous admittance g: how much of this sample's force shows up in this sample's velocity.
 
float history () const
 
float commit (float force)
 Apply this sample's force and advance: returns the velocity.
 
float velocity () const
 
float position () const
 
float energy () const
 Stored energy ½mv² + ½kx², for passivity tests.
 
void reset ()
 
diagram::Ports describe (diagram::Graph &g, uint8_t group, const char *name="mode") const
 One Load node: frequency and Q. Never called from audio code (AP-037).
 

Static Public Attributes

static constexpr float MIN_FREQUENCY_HZ = 1.0f
 
static constexpr float MAX_FREQUENCY_FRACTION = 0.45f
 of the sample rate
 
static constexpr float MIN_Q = 0.05f
 
static constexpr float MAX_Q = 1000.0f
 
static constexpr float MIN_MASS = 1e-4f
 
static constexpr float MAX_MASS = 1e6f
 
static constexpr float MIN_MATCH = 1e-3f
 
static constexpr float MAX_MATCH = 100.0f
 

Constructor & Destructor Documentation

◆ MassSpringDamper()

sbl::dsp::pm::MassSpringDamper::MassSpringDamper ( )
inline

Definition at line 76 of file mass_spring_damper.hpp.

Member Function Documentation

◆ set_frequency()

void sbl::dsp::pm::MassSpringDamper::set_frequency ( float  hz)
inline

Undamped resonance, Hz.

Definition at line 81 of file mass_spring_damper.hpp.

References sbl::dsp::math::clamp(), MAX_FREQUENCY_FRACTION, MIN_FREQUENCY_HZ, and sbl::dsp::types::SAMPLE_RATE_F.

Referenced by set_resonance().

◆ set_q()

void sbl::dsp::pm::MassSpringDamper::set_q ( float  q)
inline

Quality factor: how many cycles the ringing lasts.

Definition at line 88 of file mass_spring_damper.hpp.

References sbl::dsp::math::clamp(), MAX_Q, MIN_Q, and q().

Referenced by set_resonance().

◆ set_mass()

void sbl::dsp::pm::MassSpringDamper::set_mass ( float  m)
inline

Mass in string-impedance units; heavier is closer to rigid.

Definition at line 94 of file mass_spring_damper.hpp.

References sbl::dsp::math::clamp(), MAX_MASS, and MIN_MASS.

Referenced by set_resonance().

◆ set_resonance()

void sbl::dsp::pm::MassSpringDamper::set_resonance ( float  hz,
float  q,
float  match 
)
inline

The musical parametrisation: where, how wide, how much it takes.

Parameters
hzresonance
qhow long it rings — also how rigid it looks away from resonance, since the mass follows from q and match
matchdamper relative to the string's impedance at resonance; 1 absorbs the resonant wave completely

Definition at line 108 of file mass_spring_damper.hpp.

References sbl::dsp::math::clamp(), match(), MAX_MATCH, MIN_MATCH, q(), sbl::dsp::types::SAMPLE_RATE_F, set_frequency(), set_mass(), set_q(), and sbl::dsp::math::TWO_PI.

Referenced by sbl::dsp::pm::ModalResonator< MaxModes >::set_mode(), and sbl::dsp::pm::ModalResonator< MaxModes >::set_modes().

◆ frequency()

float sbl::dsp::pm::MassSpringDamper::frequency ( ) const
inline

Definition at line 116 of file mass_spring_damper.hpp.

◆ q()

float sbl::dsp::pm::MassSpringDamper::q ( ) const
inline

Definition at line 117 of file mass_spring_damper.hpp.

Referenced by set_q(), and set_resonance().

◆ mass()

float sbl::dsp::pm::MassSpringDamper::mass ( ) const
inline

Definition at line 118 of file mass_spring_damper.hpp.

◆ match()

float sbl::dsp::pm::MassSpringDamper::match ( ) const
inline

The damper relative to the string's impedance: c / Z with Z = 1.

Definition at line 121 of file mass_spring_damper.hpp.

Referenced by set_resonance().

◆ admittance()

float sbl::dsp::pm::MassSpringDamper::admittance ( ) const
inline

Instantaneous admittance g: how much of this sample's force shows up in this sample's velocity.

Definition at line 126 of file mass_spring_damper.hpp.

◆ history()

float sbl::dsp::pm::MassSpringDamper::history ( ) const
inline

What the past state contributes to this sample's velocity, before any force. Fixed once the previous sample is committed, so it is computed there and read here — the junction reads it, then commits.

Definition at line 131 of file mass_spring_damper.hpp.

◆ commit()

float sbl::dsp::pm::MassSpringDamper::commit ( float  force)
inline

Apply this sample's force and advance: returns the velocity.

Definition at line 134 of file mass_spring_damper.hpp.

Referenced by sbl::dsp::pm::ModalResonator< MaxModes >::commit().

◆ velocity()

float sbl::dsp::pm::MassSpringDamper::velocity ( ) const
inline

Definition at line 143 of file mass_spring_damper.hpp.

◆ position()

float sbl::dsp::pm::MassSpringDamper::position ( ) const
inline

Definition at line 144 of file mass_spring_damper.hpp.

◆ energy()

float sbl::dsp::pm::MassSpringDamper::energy ( ) const
inline

Stored energy ½mv² + ½kx², for passivity tests.

Definition at line 147 of file mass_spring_damper.hpp.

◆ reset()

void sbl::dsp::pm::MassSpringDamper::reset ( )
inline

Definition at line 149 of file mass_spring_damper.hpp.

◆ describe()

diagram::Ports sbl::dsp::pm::MassSpringDamper::describe ( diagram::Graph &  g,
uint8_t  group,
const char *  name = "mode" 
) const
inline

Member Data Documentation

◆ MIN_FREQUENCY_HZ

constexpr float sbl::dsp::pm::MassSpringDamper::MIN_FREQUENCY_HZ = 1.0f
staticconstexpr
Note
All public methods are ISR-safe — bounded computation, no I/O.

Definition at line 67 of file mass_spring_damper.hpp.

Referenced by set_frequency().

◆ MAX_FREQUENCY_FRACTION

constexpr float sbl::dsp::pm::MassSpringDamper::MAX_FREQUENCY_FRACTION = 0.45f
staticconstexpr

of the sample rate

Definition at line 68 of file mass_spring_damper.hpp.

Referenced by set_frequency().

◆ MIN_Q

constexpr float sbl::dsp::pm::MassSpringDamper::MIN_Q = 0.05f
staticconstexpr

Definition at line 69 of file mass_spring_damper.hpp.

Referenced by set_q().

◆ MAX_Q

constexpr float sbl::dsp::pm::MassSpringDamper::MAX_Q = 1000.0f
staticconstexpr

Definition at line 70 of file mass_spring_damper.hpp.

Referenced by set_q().

◆ MIN_MASS

constexpr float sbl::dsp::pm::MassSpringDamper::MIN_MASS = 1e-4f
staticconstexpr

Definition at line 71 of file mass_spring_damper.hpp.

Referenced by set_mass().

◆ MAX_MASS

constexpr float sbl::dsp::pm::MassSpringDamper::MAX_MASS = 1e6f
staticconstexpr

Definition at line 72 of file mass_spring_damper.hpp.

Referenced by set_mass().

◆ MIN_MATCH

constexpr float sbl::dsp::pm::MassSpringDamper::MIN_MATCH = 1e-3f
staticconstexpr

Definition at line 73 of file mass_spring_damper.hpp.

Referenced by set_resonance().

◆ MAX_MATCH

constexpr float sbl::dsp::pm::MassSpringDamper::MAX_MATCH = 100.0f
staticconstexpr

Definition at line 74 of file mass_spring_damper.hpp.

Referenced by set_resonance().


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