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
48template<AUDIOSAMPLETYPE Type, class ValueType>
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
68template<AUDIOSAMPLETYPE Type, class ValueType>
70 : SampleValue(), Value(v)
71{
72 Key = calcKey(v) ;
73 EValue = calcEValue(v) ;
74}
75
76template<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
92template<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
128template<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
AUDIOSAMPLETYPE
Definition: AudioSampleValue.h:33
@ AuMuLaw
au 8 Bit mu-law
Definition: AudioSampleValue.h:35
@ AuPCM32
au 32 Bit linear pcm
Definition: AudioSampleValue.h:41
@ AuPCM16
au 16 Bit linear pcm
Definition: AudioSampleValue.h:39
@ AuPCM8
au 8 Bit linear pcm
Definition: AudioSampleValue.h:37
a class representing an audio sample
Definition: AudioSampleValue.h:49
UWORD32 calcDistance(const SampleValue *s) const
Definition: AudioSampleValue.h:77
ValueType Value
Definition: AudioSampleValue.h:60
static const ValueType MaxValue
Definition: AudioSampleValue.h:62
ValueType getValue(void) const
Definition: AudioSampleValue.h:53
std::string getName(void) const
Definition: AudioSampleValue.h:129
SampleValue * getNearestTargetSampleValue(EmbValue t) const
Definition: AudioSampleValue.h:93
UWORD32 calcKey(ValueType v) const
Definition: AudioSampleValue.h:64
static const ValueType MinValue
Definition: AudioSampleValue.h:61
AudioSampleValue(ValueType v)
Definition: AudioSampleValue.h:69
EmbValue calcEValue(ValueType v) const
Definition: AudioSampleValue.h:65
EmbValue getEmbValueModulus(void) const
Definition: CvrStgFile.h:130
CvrStgFile * TheCvrStgFile
the cover-/stego- file that is operated on (set in CvrStgFile::CvrStgFile)
Definition: Globals.h:55
bool getBool(void)
Definition: RandomSource.cc:99
the value of a sample in a CvrStgFile
Definition: SampleValue.h:61
EmbValue EValue
the bit that is embedded in this sample value - must be set in constructor of derived class
Definition: SampleValue.h:134
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
Globals Globs
Definition: Embedder.cc:41
RandomSource RndSrc
Definition: RandomSource.cc:31
unsigned long UWORD32
Definition: common.h:45
BYTE EmbValue
Definition: common.h:66