Vital
|
Holds and manages a single sampled waveform, including stereo or mono data and multiple band-limited versions for different playback rates. More...
#include <sample_source.h>
Classes | |
struct | SampleData |
Holds the actual audio buffers (left/right) for multiple band-limited versions (both looped and non-looped), and associated metadata like length and sample rate. More... | |
Public Member Functions | |
Sample () | |
Default constructor. Initializes the sample with default noise data. | |
void | loadSample (const mono_float *buffer, int size, int sample_rate) |
Loads a mono sample from raw float data. | |
void | loadSample (const mono_float *left_buffer, const mono_float *right_buffer, int size, int sample_rate) |
Loads a stereo sample from two float arrays (left/right). | |
void | setName (const std::string &name) |
Sets the user-facing name of the sample. | |
std::string | getName () const |
Returns the user-facing name of the sample. | |
void | setLastBrowsedFile (const std::string &path) |
Sets the last browsed file path (if applicable). | |
std::string | getLastBrowsedFile () const |
Returns the last browsed file path. | |
force_inline int | originalLength () const |
Returns the length of the originally loaded sample in frames. | |
force_inline int | upsampleLength () |
Returns the length of the upsampled data (1 << kUpsampleTimes). | |
force_inline int | sampleRate () const |
Returns the sample rate of the originally loaded data. | |
force_inline int | activeLength () const |
Returns the active (currently used) sample length in frames, taking into account upsample factor and possibly another data set. | |
force_inline int | activeSampleRate () const |
Returns the sample rate of the currently active sample data. | |
force_inline const mono_float * | buffer () const |
Returns a pointer to the (current) left channel buffer at the base upsample level. | |
void | init () |
Generates default data for the sample (e.g., random noise). | |
int | getActiveIndex (mono_float delta) |
Determines which band-limited buffer index should be used for a given pitch delta. | |
force_inline const mono_float * | getActiveLeftBuffer (int index) |
Retrieves a pointer to the active left channel buffer at a specific band-limited index. | |
force_inline const mono_float * | getActiveLeftLoopBuffer (int index) |
Retrieves a pointer to the active left loop buffer at a specific band-limited index. | |
force_inline const mono_float * | getActiveRightBuffer (int index) |
Retrieves a pointer to the active right channel buffer at a band-limited index. If the sample is mono, it returns the left buffer. | |
force_inline const mono_float * | getActiveRightLoopBuffer (int index) |
Retrieves a pointer to the active right loop buffer at a band-limited index. If the sample is mono, returns the left loop buffer. | |
force_inline void | markUsed () |
Marks this sample as "in use" by updating the active_audio_data_ pointer. | |
force_inline void | markUnused () |
Marks this sample as "not in use," clearing the active_audio_data_ pointer. | |
json | stateToJson () |
Exports the sample state (metadata and sample data) to a JSON object. | |
void | jsonToState (json data) |
Restores the sample's state from a JSON object (including audio data). | |
Static Public Attributes | |
static constexpr int | kDefaultSampleLength = 44100 |
Default length for a newly created (noise) sample if none is provided. | |
static constexpr int | kUpsampleTimes = 1 |
Upsampling factor exponent (i.e., 1 << kUpsampleTimes). | |
static constexpr int | kBufferSamples = 4 |
Extra buffer samples at start and end to avoid interpolation issues. | |
static constexpr int | kMinSize = 4 |
Minimum sample size for further downsampling. | |
Protected Attributes | |
std::string | name_ |
The user-facing name of the sample. | |
std::string | last_browsed_file_ |
The last browsed file path for this sample (if any). | |
SampleData * | current_data_ |
Pointer to the currently loaded data. | |
std::atomic< SampleData * > | active_audio_data_ |
Atomic pointer to data in active use. | |
std::unique_ptr< SampleData > | data_ |
Owned sample data for this sample. | |
Holds and manages a single sampled waveform, including stereo or mono data and multiple band-limited versions for different playback rates.
The Sample class can load samples from raw float buffers or from a stereo pair. It also supports generating default content (e.g., noise) and can produce a JSON representation for saving/loading states.
vital::Sample::Sample | ( | ) |
Default constructor. Initializes the sample with default noise data.
|
inline |
Returns the active (currently used) sample length in frames, taking into account upsample factor and possibly another data set.
|
inline |
Returns the sample rate of the currently active sample data.
|
inline |
Returns a pointer to the (current) left channel buffer at the base upsample level.
This is primarily for quick access to the default buffer, offset by kBufferSamples.
|
inline |
Determines which band-limited buffer index should be used for a given pitch delta.
delta | Frequency ratio or pitch factor to find appropriate band-limited buffer. |
|
inline |
Retrieves a pointer to the active left channel buffer at a specific band-limited index.
index | The band-limited index, computed from getActiveIndex(). |
|
inline |
Retrieves a pointer to the active left loop buffer at a specific band-limited index.
|
inline |
Retrieves a pointer to the active right channel buffer at a band-limited index. If the sample is mono, it returns the left buffer.
|
inline |
Retrieves a pointer to the active right loop buffer at a band-limited index. If the sample is mono, returns the left loop buffer.
|
inline |
Returns the last browsed file path.
|
inline |
Returns the user-facing name of the sample.
void vital::Sample::init | ( | ) |
Generates default data for the sample (e.g., random noise).
void vital::Sample::jsonToState | ( | json | data | ) |
Restores the sample's state from a JSON object (including audio data).
data | A JSON object containing sample data. |
void vital::Sample::loadSample | ( | const mono_float * | buffer, |
int | size, | ||
int | sample_rate ) |
Loads a mono sample from raw float data.
buffer | Pointer to the float array containing sample data. |
size | Number of frames in the buffer. |
sample_rate | The sample rate of the data. |
void vital::Sample::loadSample | ( | const mono_float * | left_buffer, |
const mono_float * | right_buffer, | ||
int | size, | ||
int | sample_rate ) |
Loads a stereo sample from two float arrays (left/right).
left_buffer | Pointer to float array for the left channel. |
right_buffer | Pointer to float array for the right channel. |
size | Number of frames in each buffer. |
sample_rate | The sample rate of the data. |
|
inline |
Marks this sample as "not in use," clearing the active_audio_data_ pointer.
|
inline |
Marks this sample as "in use" by updating the active_audio_data_ pointer.
|
inline |
Returns the length of the originally loaded sample in frames.
|
inline |
Returns the sample rate of the originally loaded data.
|
inline |
Sets the last browsed file path (if applicable).
|
inline |
Sets the user-facing name of the sample.
json vital::Sample::stateToJson | ( | ) |
Exports the sample state (metadata and sample data) to a JSON object.
|
inline |
Returns the length of the upsampled data (1 << kUpsampleTimes).
|
protected |
Atomic pointer to data in active use.
|
protected |
Pointer to the currently loaded data.
|
protected |
Owned sample data for this sample.
|
staticconstexpr |
Extra buffer samples at start and end to avoid interpolation issues.
|
staticconstexpr |
Default length for a newly created (noise) sample if none is provided.
|
staticconstexpr |
Minimum sample size for further downsampling.
|
staticconstexpr |
Upsampling factor exponent (i.e., 1 << kUpsampleTimes).
|
protected |
The last browsed file path for this sample (if any).
|
protected |
The user-facing name of the sample.