Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

AudioSampleValue.h

Go to the documentation of this file.
00001 /* 00002 * steghide 0.5.1 - a steganography program 00003 * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at> 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 /* If s is not a correct AudioSampleValue then we get into real trouble here. 00081 But calcDistance is called very often, a dynamic_cast costs a lot of time and 00082 it does not make sense to pass anything but a correct AudioSampleValue as s anyway. */ 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

Generated on Fri Jul 16 19:41:20 2004 for steghide by doxygen 1.3.7