|
libpsynth 0.2.1
|
Converting from one sample type to anotherConversion is done as a simple linear mapping of one sample range to the other, such that the minimum/maximum value of the source maps to the minimum/maximum value of the destination. More...
|
Classes | |
| struct | psynth::sound::sample_converter< SrcSampleV, DstSampleV > |
| A unary function object converting between sample types. More... | |
| struct | psynth::sound::default_sample_converter |
| Same as sample_converter, except it takes the destination sample by reference, which allows us to move the templates from the class level to the method level. More... | |
Modules | |
| sample_converter_unsigned | |
Convert one unsigned/floating point sample to another. | |
Functions | |
| template<typename DstSample , typename SrcSample > | |
| sample_traits< DstSample > ::value_type | psynth::sound::sample_convert (const SrcSample &src) |
| Converting from one sample type to another. | |
Converting from one sample type to another
Conversion is done as a simple linear mapping of one sample range to the other, such that the minimum/maximum value of the source maps to the minimum/maximum value of the destination.
One implication of this is that the value 0 of signed samples may not be preserved!
When creating new sample models, it is often a good idea to provide specializations for the sample conversion algorithms, for example, for performance optimizations. If the new model is an integral type that can be signed, it is easier to define the conversion only for the unsigned type (sample_converter_unsigned) and provide specializations of detail::sample_convert_to_unsigned and detail::sample_convert_from_unsigned to convert between the signed and unsigned type.
Example:
// bits32f is a floating point sample with range [0.0f ... 1.0f] bits32f src_sample = sample_traits<bits32f>::max_value(); assert(src_sample == 1); // bits8 is 8-bit unsigned integral sample (typedef-ed from unsigned char) bits8 dst_sample = sample_convert<bits8>(src_sample); assert(dst_sample == 255); // max value goes to max value
| sample_traits<DstSample>::value_type psynth::sound::sample_convert | ( | const SrcSample & | src | ) | [inline] |
Converting from one sample type to another.
1.7.4