00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SH_AUDIOSAMPLEVALUE_H
00022 #define SH_AUDIOSAMPLEVALUE_H
00023
00024 #include "CvrStgFile.h"
00025 #include "SampleValue.h"
00026 #include "common.h"
00027
00033 enum AUDIOSAMPLETYPE {
00035 AuMuLaw,
00037 AuPCM8,
00039 AuPCM16,
00041 AuPCM32
00042 } ;
00043
00048 template<AUDIOSAMPLETYPE Type, class ValueType>
00049 class AudioSampleValue : public SampleValue {
00050 public:
00051 AudioSampleValue (ValueType v) ;
00052
00053 ValueType getValue (void) const { return Value ; } ;
00054
00055 SampleValue* getNearestTargetSampleValue (EmbValue t) const ;
00056 UWORD32 calcDistance (const SampleValue* s) const ;
00057 std::string getName (void) const ;
00058
00059 private:
00060 ValueType Value ;
00061 static const ValueType MinValue ;
00062 static const ValueType MaxValue ;
00063
00064 UWORD32 calcKey (ValueType v) const { return (v - MinValue) ; } ;
00065 EmbValue calcEValue (ValueType v) const { return ((EmbValue) ((v - MinValue) % Globs.TheCvrStgFile->getEmbValueModulus())) ; } ;
00066 } ;
00067
00068 template<AUDIOSAMPLETYPE Type, class ValueType>
00069 AudioSampleValue<Type,ValueType>::AudioSampleValue (ValueType v)
00070 : SampleValue(), Value(v)
00071 {
00072 Key = calcKey(v) ;
00073 EValue = calcEValue(v) ;
00074 }
00075
00076 template<AUDIOSAMPLETYPE Type, class ValueType>
00077 UWORD32 AudioSampleValue<Type,ValueType>::calcDistance (const SampleValue* s) const
00078 {
00079 const AudioSampleValue<Type,ValueType>* sample = (const AudioSampleValue<Type,ValueType>*) s ;
00080
00081
00082
00083
00084 if (sample->Value > Value) {
00085 return sample->Value - Value ;
00086 }
00087 else {
00088 return Value - sample->Value ;
00089 }
00090 }
00091
00092 template<AUDIOSAMPLETYPE Type, class ValueType>
00093 SampleValue* AudioSampleValue<Type,ValueType>::getNearestTargetSampleValue (EmbValue t) const
00094 {
00095 ValueType val_up = Value, val_down = Value, newval = 0 ;
00096 bool found = false ;
00097
00098 do {
00099 if (val_up < MaxValue) {
00100 val_up++ ;
00101 }
00102 if (val_down > MinValue) {
00103 val_down-- ;
00104 }
00105
00106 if (calcEValue(val_up) == t && calcEValue(val_down) == t) {
00107 if (RndSrc.getBool()) {
00108 newval = val_up ;
00109 }
00110 else {
00111 newval = val_down ;
00112 }
00113 found = true ;
00114 }
00115 else if (calcEValue(val_up) == t) {
00116 newval = val_up ;
00117 found = true ;
00118 }
00119 else if (calcEValue(val_down) == t) {
00120 newval = val_down ;
00121 found = true ;
00122 }
00123 } while (!found) ;
00124
00125 return ((SampleValue *) new AudioSampleValue<Type,ValueType> (newval)) ;
00126 }
00127
00128 template<AUDIOSAMPLETYPE Type, class ValueType>
00129 std::string AudioSampleValue<Type,ValueType>::getName (void) const
00130 {
00131 char buf[128] ;
00132 sprintf (buf, "%ld", (long) Value) ;
00133 return std::string (buf) ;
00134 }
00135
00136 #endif // ndef SH_AUDIOSAMPLEVALUE_H