|
AudioDataLib
A C++ library of classes supporting a variety of audio-data tasks.
|
This is the time-domain representation of a wave-form. More...
#include <WaveForm.h>
Classes | |
| struct | Sample |
| A wave-form is simply a list of samples. More... | |
| struct | SampleBounds |
Public Types | |
| enum | InterpolationMethod { LINEAR , CUBIC } |
| enum | TrimSection { BEFORE , AFTER } |
Public Member Functions | |
| WaveForm () | |
| virtual | ~WaveForm () |
| virtual double | EvaluateAt (double timeSeconds) const override |
| uint64_t | GetSizeBytes (const AudioData::Format &format, bool allChannels) const |
| bool | ConvertFromAudioBuffer (const AudioData::Format &format, const uint8_t *audioBuffer, uint64_t audioBufferSize, uint16_t channel, Error &error) |
| bool | ConvertToAudioBuffer (const AudioData::Format &format, uint8_t *audioBuffer, uint64_t audioBufferSize, uint16_t channel, Error &error) const |
| void | Clear () |
| void | Copy (const WaveForm *waveForm) |
| void | AddSample (const Sample &sample) |
| void | MakeSilence (double samplesPerSecond, double totalSeconds) |
| void | SumTogether (const std::list< WaveForm * > &waveFormList) |
| bool | FindTightestSampleBounds (double timeSeconds, SampleBounds &sampleBounds) const |
| bool | Renormalize () |
| void | Scale (double scale) |
| void | Clamp (double minAmplitude, double maxAmplitude) |
| bool | Trim (double startTimeSeconds, double stopTimeSeconds, bool rebaseTime, Error &error) |
| void | QuickTrim (double timeSeconds, TrimSection trimSection) |
| void | SortSamples () |
| uint64_t | PadWithSilence (double desiredDurationSeconds, double sampleRate) |
| double | AverageSampleRate () const |
| double | GetStartTime () const |
| double | GetEndTime () const |
| double | GetTimespan () const |
| uint64_t | GetNumSamples () const |
| double | GetMaxAmplitude () const |
| double | GetMinAmplitude () const |
| double | CalcAverageVolume () const |
| bool | ContainsTime (double timeSeconds) const |
| InterpolationMethod | GetInterpolationMethod () const |
| void | SetInterpolateionMethod (InterpolationMethod interpMethod) |
| const std::vector< Sample > & | GetSampleArray () const |
| std::vector< Sample > & | GetSampleArray () |
| void | Interpolate (const SampleBounds &sampleBounds, double timeSeconds, Sample &interpolatedSample) const |
Public Member Functions inherited from AudioDataLib::Function | |
| Function () | |
| virtual | ~Function () |
| virtual double | EvaluateDerivativeAt (double x) const |
Protected Member Functions | |
| template<typename T > | |
| void | CopyIntSampleToBuffer (uint8_t *sampleBuffer, double sampleNormalized) const |
| template<typename T > | |
| void | CopyFloatSampleToBuffer (uint8_t *sampleBuffer, double sampleNormalized) const |
| template<typename T > | |
| double | CopyIntSampleFromBuffer (const uint8_t *sampleBuffer) |
| template<typename T > | |
| double | CopyFloatSampleFromBuffer (const uint8_t *sampleBuffer) |
Protected Attributes | |
| std::vector< Sample > * | sampleArray |
| InterpolationMethod | interpMethod |
Friends | |
| class | Index |
This is the time-domain representation of a wave-form.
To be more specific, this is a descrete wave-form. Since we represent the wave-form function as a sequence of plots (or samples) in the plane, this form is independent of format and sampling rate. Most math operations performed on wave-forms are done using this class, since it is format-ignostic or free from the considerations and limitations of any particular audio format.
A wave-form, therefore, is just a list of audio samples, each being a time and "amplitude" pair. Most operations assume that the samples are in chronological order.
| WaveForm::WaveForm | ( | ) |
|
virtual |
| void WaveForm::AddSample | ( | const Sample & | sample | ) |
Add a sample to the end of this wave-form's list of samples.
| double WaveForm::AverageSampleRate | ( | ) | const |
Calculate and return the average sampling rate of this wave-form. The samples in a wave-form don't necessarily have a uniform distribution, but if they did, then this would return the sampling rate of the wave-form.
| double WaveForm::CalcAverageVolume | ( | ) | const |
This function is not very well defined. I may remove it at some point.
| void WaveForm::Clamp | ( | double | minAmplitude, |
| double | maxAmplitude ) |
Make sure that all samples are in the given range.
| void WaveForm::Clear | ( | ) |
Remove all samples from this wave-form.
| bool WaveForm::ContainsTime | ( | double | timeSeconds | ) | const |
Return true if and only if the given time is within this wave-form's time-span.
| bool WaveForm::ConvertFromAudioBuffer | ( | const AudioData::Format & | format, |
| const uint8_t * | audioBuffer, | ||
| uint64_t | audioBufferSize, | ||
| uint16_t | channel, | ||
| Error & | error ) |
Read the given raw audio data in the given format and generate from it a wave-form in the cartesian coordinate plane.
| [in] | format | This is the format of the given audio data. |
| [in] | audioBuffer | This is a buffer containing the raw audio data, presumably in the given format. |
| [in] | audioBufferSize | This is the size in bytes of the given audio buffer. |
| [in] | channel | This is which channel of the audio buffer to read as this wave-form. |
| [out] | error | This will contain detailed error information if false is returned. |
| bool WaveForm::ConvertToAudioBuffer | ( | const AudioData::Format & | format, |
| uint8_t * | audioBuffer, | ||
| uint64_t | audioBufferSize, | ||
| uint16_t | channel, | ||
| Error & | error ) const |
Write this wave-form into the given audio buffer in the given format.
| [in] | format | This is the format in which to write the audio data. |
| [out] | audioBuffer | This is where to write the raw audio data in the given format. |
| [in] | audioBufferSize | This is the size of the given audio buffer in bytes. |
| [in] | channel | This is the channel of the audio buffer to write as this wave-form. |
| [out] | error | This will contain detailed error information if false is returned. |
| void WaveForm::Copy | ( | const WaveForm * | waveForm | ) |
Make this wave-form a copy of the given wave-form.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
overridevirtual |
Return the amplitude of the wave-form at the given time (in seconds.) Note that this has O(log N) time-complexity, which is usually reasonably, but clearly not as fast as O(1), which can be achieved with raw audio data.
Implements AudioDataLib::Function.
| bool WaveForm::FindTightestSampleBounds | ( | double | timeSeconds, |
| SampleBounds & | sampleBounds ) const |
Find the pair of adjacent samples that bounds the given time. This is an O(log N) operation, where N is the number of samples in the wave-form.
| double WaveForm::GetEndTime | ( | ) | const |
Return the time location of the last sample in this wave-form's list of samples.
|
inline |
Return the interpolation method being used to evaluate this wave-form at any particular time within its time-span.
| double WaveForm::GetMaxAmplitude | ( | ) | const |
Find and return the most positive amplitude found in this wave-form's list of samples.
| double WaveForm::GetMinAmplitude | ( | ) | const |
Find and return the most negative amplitude found in this wave-form's list of samples.
| uint64_t WaveForm::GetNumSamples | ( | ) | const |
Return the number of samples in this wave-form's list of samples.
|
inline |
Get read/write access to this wave-form's sample array.
|
inline |
Get read-only access to this wave-form's sample array.
| uint64_t WaveForm::GetSizeBytes | ( | const AudioData::Format & | format, |
| bool | allChannels ) const |
Return the number of bytes required to represent this wave-form in the given format for 1 or all channels.
| [in] | format | This is the format of the audio-data you're considering the wave-form being written in. |
| [in] | allChannels | This is true if you're considering this or a similar wave-form being written to all channels of the audio data. |
| double WaveForm::GetStartTime | ( | ) | const |
Return the time location of the first sample in this wave-form's list of samples.
| double WaveForm::GetTimespan | ( | ) | const |
Return the difference in time between the first and last sample of this wave-form.
| void WaveForm::Interpolate | ( | const SampleBounds & | sampleBounds, |
| double | timeSeconds, | ||
| Sample & | interpolatedSample ) const |
Evaluate this wave-form at the given time, between the two given samples, using the set interpolation method. This function is typically used internally by the EvaluateAt method. Note that the given time is typically somewhere in the time-span between the two given samples, but this is not a requirement. Also, the two given samples are typically adjacent, but this is also not a requirement.
| [in] | sampleBounds | This is the pair of sample between which to perform the interpolation. |
| [in] | timeSeconds | This is the time (in seconds) where the wave-form function is to be evaluated. |
| [out] | interpolatedSample | This is the sample calculated as an interpolation between the two given samples. |
| void WaveForm::MakeSilence | ( | double | samplesPerSecond, |
| double | totalSeconds ) |
Make this wave-form a flat light representing silence for the given time period.
| [in] | samplesPerSecond | This is the sampling rate, combined with the period, needed to determine how many samples to generate. |
| [in] | totalSeconds | This is the desired duration (or time period) of silence to generate. |
| uint64_t WaveForm::PadWithSilence | ( | double | desiredDurationSeconds, |
| double | sampleRate ) |
Add some silence to the end of this wave-form.
| [in] | desiredDurationSeconds | This is the amount of silence to add in seconds. |
| [in] | sampleRate | This, combined with the duration, indicates how many samples to add. |
| void WaveForm::QuickTrim | ( | double | timeSeconds, |
| TrimSection | trimSection ) |
Try to perform a trim that's sometimes faster than that perfomed by the Trim function.
| [in] | timeSeconds | This is the point at which everything is trimmed before or after. |
| [in] | trimeSecion | This indicates whether everything is trimmed before or after the given time point. |
| bool WaveForm::Renormalize | ( | ) |
Find the sample with the maximum amplitude and then divide this out from all the samples.
| void WaveForm::Scale | ( | double | scale | ) |
Scale all samples by the given scale. This does not change the timing of the samples.
|
inline |
Set the interpolation method used to evaluate this wave-form at any particular time within its time-span.
| void WaveForm::SortSamples | ( | ) |
Make sure all samples in the wave-form's list of such is sorted chronologically.
| void WaveForm::SumTogether | ( | const std::list< WaveForm * > & | waveFormList | ) |
Make this wave-form the sum of the given list of wave-forms. A minimum amount of silence will be padded to all given wave-forms so that the resulting wave-form is of the length of the largest given wave-form. The average sampling rate of all the wave-forms is used.
| bool WaveForm::Trim | ( | double | startTimeSeconds, |
| double | stopTimeSeconds, | ||
| bool | rebaseTime, | ||
| Error & | error ) |
Trim the beginning and end of this wave-form.
| [in] | startTimeSeconds | Remove everything up to this time. |
| [in] | stopTimeSeconds | Remove everything after this time. |
| [in] | rebaseTime | If true, once the trim has occurred, shift the wave-form back so that it starts at origin. |
| [out] | error | This will contain detailed error information if false is returned. |
|
friend |
|
protected |
|
protected |