|
HART
0.2.0
High level Audio Regression and Testing
|
Frequency-domain representation of a multi-channel audio signal. More...
#include <hart_spectrum.hpp>
Classes | |
| class | ColouredNoise |
Options for colouredNoise() method. More... | |
Public Types | |
| enum | BetaFor { whiteNoise = 0 , pinkNoise = -1 , brownNoise = -2 , blueNoise = 1 , violetNoise = 2 } |
Common values for beta argument in the colouredNoise() factory. More... | |
Public Member Functions | |
| template<typename SampleType > | |
| Spectrum (const AudioBuffer< SampleType > &buffer) | |
| Constructs spectrum from an audio buffer. | |
| size_t | getNumChannels () const |
| Returns number of channels. | |
| size_t | getNumBins () const |
| Returns number of frequency bins per channel. | |
| size_t | getFFTSize () const |
| Returns FFT size. | |
| size_t | getSizeInTimeDomainFrames () const |
| Returns original audio buffer duration in frames. | |
| double | getSampleRateHz () const |
| Returns sample rate in Hz. | |
| template<typename SampleType > | |
| AudioBuffer< SampleType > | toAudioBuffer () const |
| Converts this spectrum to a time-domain audio buffer. | |
| template<typename SampleType > | |
| AudioBufferSignal< SampleType > | toSignal (Loop loop=Loop::no) const |
| Converts the audio represented by this Spectrum to a Signal source. | |
| bool | equalsTo (const Spectrum &other, double toleranceLinear=1e-6) const |
| Checks whether this spectrum contains approximately the same data as another spectrum. | |
| bool | operator== (const Spectrum &other) const |
| Checks whether two spectra contain approximately the same data. | |
| bool | operator!= (const Spectrum &other) const |
| Checks whether two spectra differ beyond the default comparison tolerance. | |
| Spectrum | operator* (double gainLinear) const |
| Creates a new spectrum as a multiplying each complex bin value by a provided gain value. | |
| double | getBinFrequencyHz (size_t binIndex) const |
| Returns frequency corresponding to a bin index. | |
| double | getBinWidthHz () const |
| std::complex< double > | getBinValue (size_t channel, size_t binIndex) const |
| Returns complex value of a frequency bin, by bin index. | |
| std::complex< double > | getBinValue (size_t channel, double frequencyHz) const |
| Returns complex value of a frequency bin, by frequency. | |
| double | getBinMagnitude (size_t channel, size_t binIndex) const |
| Returns magnitude of a frequency bin, by bin index. | |
| double | getBinMagnitude (size_t channel, double frequencyHz) const |
| Returns magnitude of a frequency bin, by frequency. | |
| const std::complex< double > * | operator[] (size_t channel) const |
| Returns pointer to read-only magnitudes of a specific channel. | |
| std::complex< double > * | operator[] (size_t channel) |
| Returns pointer to mutable magnitudes of a specific channel. | |
| size_t | findClosestBin (double frequencyHz) const |
| Finds closest FFT bin to a given frequency. | |
| std::pair< size_t, size_t > | getBinIndices (const Slice &slice) const |
| Returns a pair of indices representing a provided slice. | |
| void | represent (std::ostream &stream) const |
| Prints readable representation of the spectrum object. | |
Static Public Member Functions | |
| static Spectrum | zeros (size_t numChannels=CLIConfig::getInstance().getDefaultNumInputChannels(), size_t signalDurationFrames=CLIConfig::getInstance().getDefaultRenderDurationFrames(), double sampleRateHz=CLIConfig::getInstance().getDefaultSampleRateHz()) |
| static Spectrum | colouredNoise (ColouredNoise options) |
| Creates deterministic coloured noise in the frequency domain. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| std::ostream & | operator<< (std::ostream &stream, const Spectrum &spectrum) |
| Prints readable text representation of the spectrum object into the I/O stream. | |
Frequency-domain representation of a multi-channel audio signal.
Stores complex spectra for each channel independently. Spectrum is constructed by performing FFT on the entire signal, zero-padding to the next power-of-two size if necessary.
Current implementation assumptions:
fftSize / 2 + 1 bins)Definition at line 33 of file hart_spectrum.hpp.
| enum BetaFor |
Common values for beta argument in the colouredNoise() factory.
| Enumerator | |
|---|---|
| whiteNoise |
|
| pinkNoise |
|
| brownNoise |
|
| blueNoise |
|
| violetNoise |
|
Definition at line 106 of file hart_spectrum.hpp.
|
inline |
Constructs spectrum from an audio buffer.
| buffer | Audio buffer to perform FFT on |
| hart::SampleRateError | if the audio buffer has no sample rate metadata |
Definition at line 40 of file hart_spectrum.hpp.
|
inlinestatic |
Definition at line 74 of file hart_spectrum.hpp.
|
inlinestatic |
Creates deterministic coloured noise in the frequency domain.
beta is interpreted as a power-spectrum exponent, so the stored bin magnitudes follow:
\[ |X(f)| \propto {f_{rel}}^ \frac{\beta}{2} \]
(|X(f)| ~ f_rel ** (beta / 2)),
where f_rel = frequency / lowCutoffHz.
| options | ColouredNoise containing |
Definition at line 277 of file hart_spectrum.hpp.
|
inline |
Returns number of channels.
Definition at line 318 of file hart_spectrum.hpp.
|
inline |
Returns number of frequency bins per channel.
Definition at line 324 of file hart_spectrum.hpp.
|
inline |
Returns FFT size.
Definition at line 330 of file hart_spectrum.hpp.
|
inline |
Returns original audio buffer duration in frames.
Definition at line 336 of file hart_spectrum.hpp.
|
inline |
Returns sample rate in Hz.
Definition at line 342 of file hart_spectrum.hpp.
|
inline |
Converts this spectrum to a time-domain audio buffer.
Reconstructs the omitted negative-frequency bins from Hermitian symmetry, performs an inverse FFT, and trims the result to the original signal length.
| SampleType | Type of samples for the resulting buffer, typically float or double |
Definition at line 354 of file hart_spectrum.hpp.
|
inline |
Converts the audio represented by this Spectrum to a Signal source.
| loop | Whether the signal should loop after the data represented by this Spectrum's implied diration runs out |
| SampleType | Type of sample sata generated by the signal, typically float or double |
AudioBufferSignal instance, playing the signal with the spectrum identical to this one Definition at line 386 of file hart_spectrum.hpp.
|
inline |
Checks whether this spectrum contains approximately the same data as another spectrum.
The comparison is relaxed - each pair of corresponding complex bins must differ by no more than toleranceLinear. Both spectra must have the same dimensions, FFT size, time-domain size, and sample rate.
| other | Spectrum to compare against |
| toleranceLinear | Absolute complex-bin tolerance in linear domain, for both real and imaginary parts. |
true if the spectra are equal within the specified tolerance, false otherwise Definition at line 399 of file hart_spectrum.hpp.
|
inline |
Checks whether two spectra contain approximately the same data.
Equivalent to calling Spectrum::equalsTo (other) with the default tolerance
| other | Spectrum to compare against |
true if the spectra are equal within the default tolerance, false otherwise Definition at line 429 of file hart_spectrum.hpp.
|
inline |
Checks whether two spectra differ beyond the default comparison tolerance.
Equivalent to ! Spectrum::equalsTo (other)
| other | Spectrum to compare against |
true if the spectra are not equal within the default tolerance, false otherwise Definition at line 438 of file hart_spectrum.hpp.
|
inline |
Creates a new spectrum as a multiplying each complex bin value by a provided gain value.
| other | gainLinear Gain to multiply each complex bin by |
Spectrum that is a result of multiplication Definition at line 446 of file hart_spectrum.hpp.
|
inline |
Returns frequency corresponding to a bin index.
Definition at line 462 of file hart_spectrum.hpp.
|
inline |
Definition at line 470 of file hart_spectrum.hpp.
|
inline |
Returns complex value of a frequency bin, by bin index.
Definition at line 476 of file hart_spectrum.hpp.
|
inline |
Returns complex value of a frequency bin, by frequency.
Definition at line 488 of file hart_spectrum.hpp.
|
inline |
Returns magnitude of a frequency bin, by bin index.
Definition at line 494 of file hart_spectrum.hpp.
|
inline |
Returns magnitude of a frequency bin, by frequency.
Definition at line 500 of file hart_spectrum.hpp.
|
inline |
Returns pointer to read-only magnitudes of a specific channel.
Definition at line 506 of file hart_spectrum.hpp.
|
inline |
Returns pointer to mutable magnitudes of a specific channel.
Definition at line 515 of file hart_spectrum.hpp.
|
inline |
Finds closest FFT bin to a given frequency.
Definition at line 524 of file hart_spectrum.hpp.
|
inline |
Returns a pair of indices representing a provided slice.
| slice | A Slice instance. Valid slice types are Slice::Type::whole Slice::Type::bins and Slice::Type::freq |
| first | Index representing the beginning of the range, inclusive |
| second | Index representing the end of the range, non-inclusive |
Definition at line 538 of file hart_spectrum.hpp.
|
inline |
Prints readable representation of the spectrum object.
| stream | String stream to append the representation to |
Definition at line 580 of file hart_spectrum.hpp.
|
friend |
Prints readable text representation of the spectrum object into the I/O stream.
Definition at line 587 of file hart_spectrum.hpp.