Vital
|
A WavetableComponent that uses an external audio sample as its source. More...
#include <file_source.h>
Classes | |
class | FileSourceKeyframe |
A specific WavetableKeyframe that uses the FileSource’s audio buffer. More... | |
struct | SampleBuffer |
A simple structure holding a buffer of samples loaded from the file source. More... | |
Public Types | |
enum | FadeStyle { kWaveBlend , kNoInterpolate , kTimeInterpolate , kFreqInterpolate , kNumFadeStyles } |
Different methods to blend or interpolate the loaded audio window into a wavetable frame. More... | |
enum | PhaseStyle { kNone , kClear , kVocode , kNumPhaseStyles } |
Methods for handling phase information in the transformed wave. More... | |
![]() | |
enum | InterpolationStyle { kNone , kLinear , kCubic , kNumInterpolationStyles } |
Defines how interpolation is performed between keyframes. More... | |
Public Member Functions | |
FileSource () | |
virtual | ~FileSource () |
WavetableKeyframe * | createKeyframe (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. | |
FileSourceKeyframe * | getKeyframe (int index) |
const SampleBuffer * | buffer () const |
FadeStyle | getFadeStyle () |
PhaseStyle | getPhaseStyle () |
bool | getNormalizeGain () |
void | setNormalizeGain (bool normalize_gain) |
void | setWindowSize (double window_size) |
void | setFadeStyle (FadeStyle fade_style) |
void | setPhaseStyle (PhaseStyle phase_style) |
void | writePhaseOverrideBuffer () |
double | getWindowSize () |
void | loadBuffer (const float *buffer, int size, int sample_rate) |
Loads audio data into the file source buffer. | |
void | detectPitch (int max_period=vital::WaveFrame::kWaveformSize) |
Attempts to detect pitch in the loaded sample to determine window size automatically. | |
void | detectWaveEditTable () |
Detects if the source audio can form a WaveEdit-style wavetable (special format). | |
force_inline const float * | getDataBuffer () |
force_inline const float * | getCubicInterpolationBuffer () |
![]() | |
WavetableComponent () | |
Constructs a WavetableComponent with a default linear interpolation style. | |
virtual | ~WavetableComponent () |
virtual void | prerender () |
Called before rendering to perform any needed precomputation. | |
virtual bool | hasKeyframes () |
Indicates whether this component relies on multiple keyframes. | |
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. | |
WavetableKeyframe * | insertNewKeyframe (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. | |
WavetableKeyframe * | getFrameAt (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. | |
WavetableKeyframe * | getFrameAtPosition (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. | |
Static Public Attributes | |
static constexpr float | kMaxFileSourceSamples = 176400 |
Maximum number of samples allowed from the file source (in samples). | |
static constexpr int | kExtraSaveSamples = 4 |
Extra samples saved for safe interpolation and boundary conditions. | |
static constexpr int | kExtraBufferSamples = 4 |
Additional buffer samples for safe reading beyond boundaries. | |
static constexpr int | kPitchDetectMaxPeriod = 8096 |
Maximum period for pitch detection to limit CPU usage. | |
Protected Attributes | |
FileSourceKeyframe | compute_frame_ |
WaveSourceKeyframe | interpolate_from_frame_ |
WaveSourceKeyframe | interpolate_to_frame_ |
SampleBuffer | sample_buffer_ |
float | overridden_phase_ [vital::WaveFrame::kWaveformSize] |
FadeStyle | fade_style_ |
PhaseStyle | phase_style_ |
bool | normalize_gain_ |
bool | normalize_mult_ |
double | window_size_ |
int | random_seed_ |
vital::utils::RandomGenerator | random_generator_ |
PitchDetector | pitch_detector_ |
![]() | |
std::vector< std::unique_ptr< WavetableKeyframe > > | keyframes_ |
The list of keyframes sorted by position. | |
InterpolationStyle | interpolation_style_ |
Current interpolation style (none, linear, cubic). | |
A WavetableComponent that uses an external audio sample as its source.
FileSource loads a segment of audio data (e.g., from a sample file) and transforms it into wavetables. It provides multiple interpolation (fade) styles and phase manipulation options for constructing a wavetable frame. Users can set how the audio frames are extracted (window size, fade style), and how phases are handled (e.g., vocoding).
Different methods to blend or interpolate the loaded audio window into a wavetable frame.
FileSource::FileSource | ( | ) |
|
inlinevirtual |
|
inline |
|
overridevirtual |
Creates a new keyframe at a given position.
Implemented by subclasses to produce a keyframe type suited to their functionality.
position | The wavetable frame index (0 to kNumOscillatorWaveFrames-1). |
Implements WavetableComponent.
void FileSource::detectPitch | ( | int | max_period = vital::WaveFrame::kWaveformSize | ) |
Attempts to detect pitch in the loaded sample to determine window size automatically.
max_period | Maximum period considered for pitch detection. |
void FileSource::detectWaveEditTable | ( | ) |
Detects if the source audio can form a WaveEdit-style wavetable (special format).
|
inline |
|
inline |
|
inline |
FileSource::FileSourceKeyframe * FileSource::getKeyframe | ( | int | index | ) |
|
inline |
|
inline |
|
overridevirtual |
Returns the type of this WavetableComponent.
Used to identify the specific component for serialization and UI mapping.
Implements WavetableComponent.
|
inline |
|
overridevirtual |
Restores the component’s state from a JSON object.
Clears existing keyframes and reconstructs them from the provided JSON data.
data | The JSON object containing saved state data. |
Reimplemented from WavetableComponent.
void FileSource::loadBuffer | ( | const float * | buffer, |
int | size, | ||
int | sample_rate ) |
Loads audio data into the file source buffer.
buffer | Pointer to the audio samples. |
size | Number of samples. |
sample_rate | The sample rate of the audio data. |
|
overridevirtual |
Renders the waveform at a given position into a WaveFrame.
Uses interpolation between keyframes based on the current interpolation style to produce a waveform for the given position.
wave_frame | The WaveFrame to fill with the resulting waveform. |
position | The position along the wavetable dimension [0, kNumOscillatorWaveFrames-1]. |
Implements WavetableComponent.
|
inline |
|
inline |
void FileSource::setPhaseStyle | ( | PhaseStyle | phase_style | ) |
|
inline |
|
overridevirtual |
Serializes the component’s state and all keyframes to a JSON object.
Reimplemented from WavetableComponent.
void FileSource::writePhaseOverrideBuffer | ( | ) |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticconstexpr |
Additional buffer samples for safe reading beyond boundaries.
|
staticconstexpr |
Extra samples saved for safe interpolation and boundary conditions.
|
staticconstexpr |
Maximum number of samples allowed from the file source (in samples).
|
staticconstexpr |
Maximum period for pitch detection to limit CPU usage.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |