steghide
0.5.1
Main Page
Classes
Files
File List
File Members
src
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
33
enum
AUDIOSAMPLETYPE
{
35
AuMuLaw
,
37
AuPCM8
,
39
AuPCM16
,
41
AuPCM32
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
55
SampleValue
*
getNearestTargetSampleValue
(
EmbValue
t)
const
;
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>
69
AudioSampleValue<Type,ValueType>::AudioSampleValue
(ValueType v)
70
:
SampleValue
(), Value(v)
71
{
72
Key
=
calcKey
(v) ;
73
EValue
=
calcEValue
(v) ;
74
}
75
76
template
<AUDIOSAMPLETYPE Type,
class
ValueType>
77
UWORD32
AudioSampleValue<Type,ValueType>::calcDistance
(
const
SampleValue
* s)
const
78
{
79
const
AudioSampleValue<Type,ValueType>
* sample = (
const
AudioSampleValue<Type,ValueType>
*) s ;
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>
93
SampleValue
*
AudioSampleValue<Type,ValueType>::getNearestTargetSampleValue
(
EmbValue
t)
const
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>
129
std::string
AudioSampleValue<Type,ValueType>::getName
(
void
)
const
130
{
131
char
buf[128] ;
132
sprintf (buf,
"%ld"
, (
long
) Value) ;
133
return
std::string (buf) ;
134
}
135
136
#endif // ndef SH_AUDIOSAMPLEVALUE_H
Generated on Mon Jan 14 2013 04:45:06 for steghide by
1.8.3