steghide  0.5.1
AudioSampleValue.h
Go to the documentation of this file.
1 /*
2  * steghide 0.5.1 - a steganography program
3  * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  */
20 
21 #ifndef SH_AUDIOSAMPLEVALUE_H
22 #define SH_AUDIOSAMPLEVALUE_H
23 
24 #include "CvrStgFile.h"
25 #include "SampleValue.h"
26 #include "common.h"
27 
42 } ;
43 
48 template<AUDIOSAMPLETYPE Type, class ValueType>
49 class AudioSampleValue : public SampleValue {
50  public:
51  AudioSampleValue (ValueType v) ;
52 
53  ValueType getValue (void) const { return Value ; } ;
54 
56  UWORD32 calcDistance (const SampleValue* s) const ;
57  std::string getName (void) const ;
58 
59  private:
60  ValueType Value ;
61  static const ValueType MinValue ;
62  static const ValueType MaxValue ;
63 
64  UWORD32 calcKey (ValueType v) const { return (v - MinValue) ; } ;
65  EmbValue calcEValue (ValueType v) const { return ((EmbValue) ((v - MinValue) % Globs.TheCvrStgFile->getEmbValueModulus())) ; } ;
66 } ;
67 
68 template<AUDIOSAMPLETYPE Type, class ValueType>
70  : SampleValue(), Value(v)
71 {
72  Key = calcKey(v) ;
73  EValue = calcEValue(v) ;
74 }
75 
76 template<AUDIOSAMPLETYPE Type, class ValueType>
78 {
80  /* If s is not a correct AudioSampleValue then we get into real trouble here.
81  But calcDistance is called very often, a dynamic_cast costs a lot of time and
82  it does not make sense to pass anything but a correct AudioSampleValue as s anyway. */
83 
84  if (sample->Value > Value) {
85  return sample->Value - Value ;
86  }
87  else {
88  return Value - sample->Value ;
89  }
90 }
91 
92 template<AUDIOSAMPLETYPE Type, class ValueType>
94 {
95  ValueType val_up = Value, val_down = Value, newval = 0 ;
96  bool found = false ;
97 
98  do {
99  if (val_up < MaxValue) {
100  val_up++ ;
101  }
102  if (val_down > MinValue) {
103  val_down-- ;
104  }
105 
106  if (calcEValue(val_up) == t && calcEValue(val_down) == t) {
107  if (RndSrc.getBool()) {
108  newval = val_up ;
109  }
110  else {
111  newval = val_down ;
112  }
113  found = true ;
114  }
115  else if (calcEValue(val_up) == t) {
116  newval = val_up ;
117  found = true ;
118  }
119  else if (calcEValue(val_down) == t) {
120  newval = val_down ;
121  found = true ;
122  }
123  } while (!found) ;
124 
125  return ((SampleValue *) new AudioSampleValue<Type,ValueType> (newval)) ;
126 }
127 
128 template<AUDIOSAMPLETYPE Type, class ValueType>
130 {
131  char buf[128] ;
132  sprintf (buf, "%ld", (long) Value) ;
133  return std::string (buf) ;
134 }
135 
136 #endif // ndef SH_AUDIOSAMPLEVALUE_H
CvrStgFile::getEmbValueModulus
EmbValue getEmbValueModulus(void) const
Definition: CvrStgFile.h:130
AudioSampleValue::MaxValue
static const ValueType MaxValue
Definition: AudioSampleValue.h:62
AudioSampleValue::getName
std::string getName(void) const
Definition: AudioSampleValue.h:129
AuMuLaw
au 8 Bit mu-law
Definition: AudioSampleValue.h:35
CvrStgFile.h
AudioSampleValue
a class representing an audio sample
Definition: AudioSampleValue.h:49
UWORD32
unsigned long UWORD32
Definition: common.h:45
SampleValue::Key
UWORD32 Key
the key of this sample value - must be different for two different sample values - must be set in con...
Definition: SampleValue.h:137
AudioSampleValue::Value
ValueType Value
Definition: AudioSampleValue.h:60
AudioSampleValue::AudioSampleValue
AudioSampleValue(ValueType v)
Definition: AudioSampleValue.h:69
AUDIOSAMPLETYPE
AUDIOSAMPLETYPE
Definition: AudioSampleValue.h:33
SampleValue
the value of a sample in a CvrStgFile
Definition: SampleValue.h:61
SampleValue::EValue
EmbValue EValue
the bit that is embedded in this sample value - must be set in constructor of derived class
Definition: SampleValue.h:134
AudioSampleValue::getNearestTargetSampleValue
SampleValue * getNearestTargetSampleValue(EmbValue t) const
Definition: AudioSampleValue.h:93
AuPCM16
au 16 Bit linear pcm
Definition: AudioSampleValue.h:39
AuPCM32
au 32 Bit linear pcm
Definition: AudioSampleValue.h:41
EmbValue
BYTE EmbValue
Definition: common.h:66
common.h
AuPCM8
au 8 Bit linear pcm
Definition: AudioSampleValue.h:37
RndSrc
RandomSource RndSrc
Definition: RandomSource.cc:31
AudioSampleValue::getValue
ValueType getValue(void) const
Definition: AudioSampleValue.h:53
AudioSampleValue::calcKey
UWORD32 calcKey(ValueType v) const
Definition: AudioSampleValue.h:64
AudioSampleValue::calcDistance
UWORD32 calcDistance(const SampleValue *s) const
Definition: AudioSampleValue.h:77
SampleValue.h
AudioSampleValue::calcEValue
EmbValue calcEValue(ValueType v) const
Definition: AudioSampleValue.h:65
RandomSource::getBool
bool getBool(void)
Definition: RandomSource.cc:99
AudioSampleValue::MinValue
static const ValueType MinValue
Definition: AudioSampleValue.h:61
Globs
Globals Globs
Definition: Embedder.cc:41
Globals::TheCvrStgFile
CvrStgFile * TheCvrStgFile
the cover-/stego- file that is operated on (set in CvrStgFile::CvrStgFile)
Definition: Globals.h:55