Vital
Loading...
Searching...
No Matches
ShepardToneSource Class Reference

A WaveSource that constructs a special looped waveform reminiscent of a Shepard tone. More...

#include <shepard_tone_source.h>

Inheritance diagram for ShepardToneSource:
WaveSource WavetableComponent

Public Member Functions

 ShepardToneSource ()
 Constructs a ShepardToneSource with a loop frame for seamless frequency content.
 
virtual ~ShepardToneSource ()
 
virtual void render (vital::WaveFrame *wave_frame, float position) override
 Renders a frame of the Shepard tone wavetable at a given position.
 
virtual WavetableComponentFactory::ComponentType getType () override
 Returns the component type associated with this source.
 
virtual bool hasKeyframes () override
 Indicates whether this component has keyframes.
 
- Public Member Functions inherited from WaveSource
 WaveSource ()
 Constructs a WaveSource with a default frequency-domain interpolation mode.
 
virtual ~WaveSource ()
 
WavetableKeyframecreateKeyframe (int position) override
 Creates a new keyframe at a given position.
 
void render (vital::WaveFrame *wave_frame, float position) override
 Renders the waveform at a given position into a WaveFrame.
 
WavetableComponentFactory::ComponentType getType () override
 Returns the type of this WavetableComponent.
 
json stateToJson () override
 Serializes the component’s state and all keyframes to a JSON object.
 
void jsonToState (json data) override
 Restores the component’s state from a JSON object.
 
vital::WaveFramegetWaveFrame (int index)
 Gets a WaveFrame from a specified keyframe index.
 
WaveSourceKeyframegetKeyframe (int index)
 Retrieves a WaveSourceKeyframe by index.
 
void setInterpolationMode (InterpolationMode mode)
 Sets the interpolation mode for morphing between keyframes.
 
InterpolationMode getInterpolationMode () const
 Gets the current interpolation mode.
 
- Public Member Functions inherited from WavetableComponent
 WavetableComponent ()
 Constructs a WavetableComponent with a default linear interpolation style.
 
virtual ~WavetableComponent ()
 
virtual void prerender ()
 Called before rendering to perform any needed precomputation.
 
void reset ()
 Clears all keyframes and inserts a default one at position 0.
 
void interpolate (WavetableKeyframe *dest, float position)
 Interpolates a destination keyframe at a given position.
 
WavetableKeyframeinsertNewKeyframe (int position)
 Inserts a new keyframe at the given position, creating and sorting it into the array.
 
void reposition (WavetableKeyframe *keyframe)
 Repositions a keyframe in the keyframe list after its position changed.
 
void remove (WavetableKeyframe *keyframe)
 Removes a specific keyframe from the component.
 
int numFrames () const
 Gets the number of keyframes.
 
int indexOf (WavetableKeyframe *keyframe) const
 Finds the index of a given keyframe.
 
WavetableKeyframegetFrameAt (int index) const
 Gets a keyframe by index.
 
int getIndexFromPosition (int position) const
 Finds the insertion index for a given position to keep keyframes sorted.
 
WavetableKeyframegetFrameAtPosition (int position)
 Gets a keyframe by position if one matches exactly, or nullptr otherwise.
 
int getLastKeyframePosition ()
 Gets the highest position among all keyframes.
 
void setInterpolationStyle (InterpolationStyle type)
 Sets the global interpolation style.
 
InterpolationStyle getInterpolationStyle () const
 Gets the current global interpolation style.
 

Protected Attributes

std::unique_ptr< WaveSourceKeyframeloop_frame_
 A loop frame used to create the repetitive Shepard effect.
 
- Protected Attributes inherited from WaveSource
std::unique_ptr< WaveSourceKeyframecompute_frame_
 A keyframe for intermediate interpolation computations.
 
InterpolationMode interpolation_mode_
 The mode of interpolation.
 
- Protected Attributes inherited from WavetableComponent
std::vector< std::unique_ptr< WavetableKeyframe > > keyframes_
 The list of keyframes sorted by position.
 
InterpolationStyle interpolation_style_
 Current interpolation style (none, linear, cubic).
 

Additional Inherited Members

- Public Types inherited from WaveSource
enum  InterpolationMode { kTime , kFrequency }
 Defines how keyframes should be interpolated. More...
 
- Public Types inherited from WavetableComponent
enum  InterpolationStyle { kNone , kLinear , kCubic , kNumInterpolationStyles }
 Defines how interpolation is performed between keyframes. More...
 

Detailed Description

A WaveSource that constructs a special looped waveform reminiscent of a Shepard tone.

ShepardToneSource uses a single keyframe and loops the spectrum in a manner that can create an auditory illusion similar to a Shepard tone—where the tone seems to continually ascend (or descend) without actually changing pitch. Internally, it duplicates and interleaves frequency components to produce a repetitive, seamless effect when traversing frames.

Constructor & Destructor Documentation

◆ ShepardToneSource()

ShepardToneSource::ShepardToneSource ( )

Constructs a ShepardToneSource with a loop frame for seamless frequency content.

◆ ~ShepardToneSource()

ShepardToneSource::~ShepardToneSource ( )
virtual

Member Function Documentation

◆ getType()

WavetableComponentFactory::ComponentType ShepardToneSource::getType ( )
overridevirtual

Returns the component type associated with this source.

Returns
The ComponentType enumerated value representing a Shepard tone source.

Implements WavetableComponent.

◆ hasKeyframes()

virtual bool ShepardToneSource::hasKeyframes ( )
inlineoverridevirtual

Indicates whether this component has keyframes.

ShepardToneSource uses a single keyframe and a looping frame; it effectively doesn't operate on multiple keyframes.

Returns
False since it does not rely on a series of keyframes.

Reimplemented from WavetableComponent.

◆ render()

void ShepardToneSource::render ( vital::WaveFrame * wave_frame,
float position )
overridevirtual

Renders a frame of the Shepard tone wavetable at a given position.

The ShepardToneSource reads from its single keyframe, duplicates frequency bins in a certain pattern, and interpolates between the base and loop frames to create a continuous tone effect.

Parameters
wave_frameThe WaveFrame to render into.
positionThe normalized position along the wavetable (0 to 1).

Implements WavetableComponent.

Member Data Documentation

◆ loop_frame_

std::unique_ptr<WaveSourceKeyframe> ShepardToneSource::loop_frame_
protected

A loop frame used to create the repetitive Shepard effect.


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