Om  1.0.0
A universal framework for multimedia simulation
Public Types | Public Member Functions | Static Public Member Functions | List of all members
om::sound::base::Sample< T > Class Template Reference

A class that represents a template primitive-typed sound sample. More...

#include <omSoundSample.h>

Public Types

typedef T BaseType
 The underlying type used to represent this sample. More...
 

Public Member Functions

 Sample ()
 Create a new Sample with value equal to 0. More...
 
 Sample (const T &newSample)
 Create a new Sample with the specified value. More...
 
 Sample (Float32 newSample)
 Create a new Sample with the specified floating-point value, converted to the sample type. More...
 
 Sample (Float64 newSample)
 Create a new Sample with the specified floating-point value, converted to the sample type. More...
 
template<typename U >
 Sample (const Sample< U > &other)
 Convert a sample of another templated type to this sample type. More...
 
template<typename U >
 operator U () const
 Convert this sample's internal primitive type to the templated primitive type. More...
 
Sample operator+ (const Sample &other) const
 Mix this sample with another and return the result. More...
 
Sampleoperator+= (const Sample &other)
 Mix another sample with this sample and overwrite this sample. More...
 
Sample operator- (const Sample &other) const
 Subtract another sample from this sample and return the result. More...
 
Sampleoperator-= (const Sample &other)
 Subtract another sample from this sample and overwrite this sample. More...
 
Sample operator* (Float gain) const
 Scale this sample by a linear gain factor and return the result. More...
 
Sample operator* (Double gain) const
 Scale this sample by a linear gain factor and return the result. More...
 
Sampleoperator*= (Float gain)
 Scale this sample by a linear gain factor and overwite this sample. More...
 
Sampleoperator*= (Double gain)
 Scale this sample by a linear gain factor and overwite this sample. More...
 
template<>
Int8 convert (Int8 sample)
 
template<>
Int8 convert (Int16 sample)
 
template<>
Int8 convert (Int24 sample)
 
template<>
Int8 convert (Int32 sample)
 
template<>
Int8 convert (Int64 sample)
 
template<>
Int8 convert (Float32 sample)
 
template<>
Int8 convert (Float64 sample)
 
template<>
Int16 convert (Int8 sample)
 
template<>
Int16 convert (Int16 sample)
 
template<>
Int16 convert (Int24 sample)
 
template<>
Int16 convert (Int32 sample)
 
template<>
Int16 convert (Int64 sample)
 
template<>
Int16 convert (Float32 sample)
 
template<>
Int16 convert (Float64 sample)
 
template<>
Int24 convert (Int8 sample)
 
template<>
Int24 convert (Int16 sample)
 
template<>
Int24 convert (Int24 sample)
 
template<>
Int24 convert (Int32 sample)
 
template<>
Int24 convert (Int64 sample)
 
template<>
Int24 convert (Float32 sample)
 
template<>
Int24 convert (Float64 sample)
 
template<>
Int32 convert (Int8 sample)
 
template<>
Int32 convert (Int16 sample)
 
template<>
Int32 convert (Int24 sample)
 
template<>
Int32 convert (Int32 sample)
 
template<>
Int32 convert (Int64 sample)
 
template<>
Int32 convert (Float32 sample)
 
template<>
Int32 convert (Float64 sample)
 
template<>
Int64 convert (Int8 sample)
 
template<>
Int64 convert (Int16 sample)
 
template<>
Int64 convert (Int24 sample)
 
template<>
Int64 convert (Int32 sample)
 
template<>
Int64 convert (Int64 sample)
 
template<>
Int64 convert (Float32 sample)
 
template<>
Int64 convert (Float64 sample)
 
template<>
Float32 convert (Int8 sample)
 
template<>
Float32 convert (Int16 sample)
 
template<>
Float32 convert (Int24 sample)
 
template<>
Float32 convert (Int32 sample)
 
template<>
Float32 convert (Int64 sample)
 
template<>
Float32 convert (Float32 sample)
 
template<>
Float32 convert (Float64 sample)
 
template<>
Float64 convert (Int8 sample)
 
template<>
Float64 convert (Int16 sample)
 
template<>
Float64 convert (Int24 sample)
 
template<>
Float64 convert (Int32 sample)
 
template<>
Float64 convert (Int64 sample)
 
template<>
Float64 convert (Float32 sample)
 
template<>
Float64 convert (Float64 sample)
 
template<>
Sample< Int8operator+ (const Sample< Int8 > &other) const
 
template<>
Sample< Int16operator+ (const Sample< Int16 > &other) const
 
template<>
Sample< Int24operator+ (const Sample< Int24 > &other) const
 
template<>
Sample< Int32operator+ (const Sample< Int32 > &other) const
 
template<>
Sample< Int64operator+ (const Sample< Int64 > &other) const
 
template<>
Sample< Int8operator- (const Sample< Int8 > &other) const
 
template<>
Sample< Int16operator- (const Sample< Int16 > &other) const
 
template<>
Sample< Int24operator- (const Sample< Int24 > &other) const
 
template<>
Sample< Int32operator- (const Sample< Int32 > &other) const
 
template<>
Sample< Int64operator- (const Sample< Int64 > &other) const
 
template<>
Sample< Int8operator* (Gain gain) const
 
template<>
Sample< Int16operator* (Gain gain) const
 
template<>
Sample< Int24operator* (Gain gain) const
 
template<>
Sample< Int32operator* (Gain gain) const
 
template<>
Sample< Int64operator* (Gain gain) const
 

Static Public Member Functions

template<typename U >
static T convert (U sample)
 Convert a sample value with the specified underlying primitive type to the templated primitive type. More...
 

Detailed Description

template<typename T>
class om::sound::base::Sample< T >

A class that represents a template primitive-typed sound sample.

This class provides a wrapper for basic primitive types which provides automatic sample saturation and proper conversion between different sample types using standard arithmetic and cast operators.

Floating-point template instantiations do not do saturating sample arithmetic because of their much greater dynamic range.

Member Typedef Documentation

template<typename T >
typedef T om::sound::base::Sample< T >::BaseType

The underlying type used to represent this sample.

Constructor & Destructor Documentation

template<typename T >
om::sound::base::Sample< T >::Sample ( )
inline

Create a new Sample with value equal to 0.

template<typename T >
om::sound::base::Sample< T >::Sample ( const T &  newSample)
inline

Create a new Sample with the specified value.

template<typename T >
om::sound::base::Sample< T >::Sample ( Float32  newSample)
inline

Create a new Sample with the specified floating-point value, converted to the sample type.

template<typename T >
om::sound::base::Sample< T >::Sample ( Float64  newSample)
inline

Create a new Sample with the specified floating-point value, converted to the sample type.

template<typename T >
template<typename U >
om::sound::base::Sample< T >::Sample ( const Sample< U > &  other)
inline

Convert a sample of another templated type to this sample type.

This method applies the best conversion from the specified sample type to this sample type. For conversions to the 8-bit sample type, a simple dither is performed to improve the audio quality. One might want to implement a higher quality dither for these conversions, depending on the application.

Member Function Documentation

template<typename T >
template<typename U >
om::sound::base::Sample< T >::operator U ( ) const
inline

Convert this sample's internal primitive type to the templated primitive type.

template<typename T >
Sample om::sound::base::Sample< T >::operator+ ( const Sample< T > &  other) const
inline

Mix this sample with another and return the result.

template<typename T >
Sample& om::sound::base::Sample< T >::operator+= ( const Sample< T > &  other)
inline

Mix another sample with this sample and overwrite this sample.

template<typename T >
Sample om::sound::base::Sample< T >::operator- ( const Sample< T > &  other) const
inline

Subtract another sample from this sample and return the result.

template<typename T >
Sample& om::sound::base::Sample< T >::operator-= ( const Sample< T > &  other)
inline

Subtract another sample from this sample and overwrite this sample.

template<typename T >
Sample om::sound::base::Sample< T >::operator* ( Float  gain) const
inline

Scale this sample by a linear gain factor and return the result.

template<typename T >
Sample om::sound::base::Sample< T >::operator* ( Double  gain) const
inline

Scale this sample by a linear gain factor and return the result.

template<typename T >
Sample& om::sound::base::Sample< T >::operator*= ( Float  gain)
inline

Scale this sample by a linear gain factor and overwite this sample.

template<typename T >
Sample& om::sound::base::Sample< T >::operator*= ( Double  gain)
inline

Scale this sample by a linear gain factor and overwite this sample.

template<typename T >
template<typename U >
static T om::sound::base::Sample< T >::convert ( sample)
inlinestatic

Convert a sample value with the specified underlying primitive type to the templated primitive type.

template<>
Int8 om::sound::base::Sample< Int8 >::convert ( Int8  sample)
inline
template<>
Int8 om::sound::base::Sample< Int8 >::convert ( Int16  sample)
inline
template<>
Int8 om::sound::base::Sample< Int8 >::convert ( Int24  sample)
inline
template<>
Int8 om::sound::base::Sample< Int8 >::convert ( Int32  sample)
inline
template<>
Int8 om::sound::base::Sample< Int8 >::convert ( Int64  sample)
inline
template<>
Int8 om::sound::base::Sample< Int8 >::convert ( Float32  sample)
inline
template<>
Int8 om::sound::base::Sample< Int8 >::convert ( Float64  sample)
inline
template<>
Int16 om::sound::base::Sample< Int16 >::convert ( Int8  sample)
inline
template<>
Int16 om::sound::base::Sample< Int16 >::convert ( Int16  sample)
inline
template<>
Int16 om::sound::base::Sample< Int16 >::convert ( Int24  sample)
inline
template<>
Int16 om::sound::base::Sample< Int16 >::convert ( Int32  sample)
inline
template<>
Int16 om::sound::base::Sample< Int16 >::convert ( Int64  sample)
inline
template<>
Int16 om::sound::base::Sample< Int16 >::convert ( Float32  sample)
inline
template<>
Int16 om::sound::base::Sample< Int16 >::convert ( Float64  sample)
inline
template<>
Int24 om::sound::base::Sample< Int24 >::convert ( Int8  sample)
inline
template<>
Int24 om::sound::base::Sample< Int24 >::convert ( Int16  sample)
inline
template<>
Int24 om::sound::base::Sample< Int24 >::convert ( Int24  sample)
inline
template<>
Int24 om::sound::base::Sample< Int24 >::convert ( Int32  sample)
inline
template<>
Int24 om::sound::base::Sample< Int24 >::convert ( Int64  sample)
inline
template<>
Int24 om::sound::base::Sample< Int24 >::convert ( Float32  sample)
inline
template<>
Int24 om::sound::base::Sample< Int24 >::convert ( Float64  sample)
inline
template<>
Int32 om::sound::base::Sample< Int32 >::convert ( Int8  sample)
inline
template<>
Int32 om::sound::base::Sample< Int32 >::convert ( Int16  sample)
inline
template<>
Int32 om::sound::base::Sample< Int32 >::convert ( Int24  sample)
inline
template<>
Int32 om::sound::base::Sample< Int32 >::convert ( Int32  sample)
inline
template<>
Int32 om::sound::base::Sample< Int32 >::convert ( Int64  sample)
inline
template<>
Int32 om::sound::base::Sample< Int32 >::convert ( Float32  sample)
inline
template<>
Int32 om::sound::base::Sample< Int32 >::convert ( Float64  sample)
inline
template<>
Int64 om::sound::base::Sample< Int64 >::convert ( Int8  sample)
inline
template<>
Int64 om::sound::base::Sample< Int64 >::convert ( Int16  sample)
inline
template<>
Int64 om::sound::base::Sample< Int64 >::convert ( Int24  sample)
inline
template<>
Int64 om::sound::base::Sample< Int64 >::convert ( Int32  sample)
inline
template<>
Int64 om::sound::base::Sample< Int64 >::convert ( Int64  sample)
inline
template<>
Int64 om::sound::base::Sample< Int64 >::convert ( Float32  sample)
inline
template<>
Int64 om::sound::base::Sample< Int64 >::convert ( Float64  sample)
inline
template<>
Float32 om::sound::base::Sample< Float32 >::convert ( Int8  sample)
inline
template<>
Float32 om::sound::base::Sample< Float32 >::convert ( Int16  sample)
inline
template<>
Float32 om::sound::base::Sample< Float32 >::convert ( Int24  sample)
inline
template<>
Float32 om::sound::base::Sample< Float32 >::convert ( Int32  sample)
inline
template<>
Float32 om::sound::base::Sample< Float32 >::convert ( Int64  sample)
inline
template<>
Float32 om::sound::base::Sample< Float32 >::convert ( Float32  sample)
inline
template<>
Float32 om::sound::base::Sample< Float32 >::convert ( Float64  sample)
inline
template<>
Float64 om::sound::base::Sample< Float64 >::convert ( Int8  sample)
inline
template<>
Float64 om::sound::base::Sample< Float64 >::convert ( Int16  sample)
inline
template<>
Float64 om::sound::base::Sample< Float64 >::convert ( Int24  sample)
inline
template<>
Float64 om::sound::base::Sample< Float64 >::convert ( Int32  sample)
inline
template<>
Float64 om::sound::base::Sample< Float64 >::convert ( Int64  sample)
inline
template<>
Float64 om::sound::base::Sample< Float64 >::convert ( Float32  sample)
inline
template<>
Float64 om::sound::base::Sample< Float64 >::convert ( Float64  sample)
inline
template<>
Sample< Int8 > om::sound::base::Sample< Int8 >::operator+ ( const Sample< Int8 > &  other) const
inline
template<>
Sample< Int16 > om::sound::base::Sample< Int16 >::operator+ ( const Sample< Int16 > &  other) const
inline
template<>
Sample< Int24 > om::sound::base::Sample< Int24 >::operator+ ( const Sample< Int24 > &  other) const
inline
template<>
Sample< Int32 > om::sound::base::Sample< Int32 >::operator+ ( const Sample< Int32 > &  other) const
inline
template<>
Sample< Int64 > om::sound::base::Sample< Int64 >::operator+ ( const Sample< Int64 > &  other) const
inline
template<>
Sample< Int8 > om::sound::base::Sample< Int8 >::operator- ( const Sample< Int8 > &  other) const
inline
template<>
Sample< Int16 > om::sound::base::Sample< Int16 >::operator- ( const Sample< Int16 > &  other) const
inline
template<>
Sample< Int24 > om::sound::base::Sample< Int24 >::operator- ( const Sample< Int24 > &  other) const
inline
template<>
Sample< Int32 > om::sound::base::Sample< Int32 >::operator- ( const Sample< Int32 > &  other) const
inline
template<>
Sample< Int64 > om::sound::base::Sample< Int64 >::operator- ( const Sample< Int64 > &  other) const
inline
template<>
Sample< Int8 > om::sound::base::Sample< Int8 >::operator* ( Gain  gain) const
inline
template<>
Sample< Int16 > om::sound::base::Sample< Int16 >::operator* ( Gain  gain) const
inline
template<>
Sample< Int24 > om::sound::base::Sample< Int24 >::operator* ( Gain  gain) const
inline
template<>
Sample< Int32 > om::sound::base::Sample< Int32 >::operator* ( Gain  gain) const
inline
template<>
Sample< Int64 > om::sound::base::Sample< Int64 >::operator* ( Gain  gain) const
inline

The documentation for this class was generated from the following file: