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...
|struct||psynth::sound::sample_converter< SrcSampleV, DstSampleV >|
|A unary function object converting between sample types. More...|
|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...|
Convert one unsigned/floating point sample to another.
|template<typename DstSample , typename SrcSample >|
|sample_traits< DstSample >|
|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_from_unsigned to convert between the signed and unsigned type.
// 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||)||
Converting from one sample type to another.