[−][src]Trait bae_rs::sample_format::SampleFormat
Trait implementing the ability to perform math operations with a polyphonic sample format and a monophonic sample.
Dependencies:
- Default - A good default value for audio samples is 0.
- Most mathematical operators are required to be implemented to be able to perform common operations on sample values.
Mul
/MulAssign
is defined for bothMathT
as well asSampleT
for the convenience of common audio operations.From
/Into
implemented forSampleT
- These functions should be simple calls tofrom_sample
andinto_sample
respectively.TryFrom
/Into
implemented forVec<_>
- These functions should convert the sample values to the given standard integer types. AsVec
s are generic types, it cannot be assumed that any attempted conversions ofVec
s to a given sample format will succeed. Therefore those conversions useTryFrom
to indicate when there is an issue, which can be communicated with the givenString
used for the error type. An example of such an error could be (for theStereo
type):
format!("ERROR: Given vector was length {}. This function requires length 2.", v.len());
Required methods
fn from_sample(x: SampleT) -> Self
Creates an object from a single monophonic sample.
fn into_sample(self) -> SampleT
Converts the given polyphonic sample to a monophonic sample.
fn num_samples() -> usize
Returns the number of SampleT
values held within a given
SampleFormat
. A common use for this would be for ensuring Vec
s
given to try_from
have the correct size.