steghide 0.5.1
AudioData.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_AUDIODATA_H
22#define SH_AUDIODATA_H
23
24#include <vector>
25
26#include "AudioSampleValue.h"
27class BinaryIO ;
28#include "CvrStgObject.h"
29
37class AudioData : public CvrStgObject {
38 public:
40 static const UWORD32 NoLimit = 0 ;
41
42 virtual void read (BinaryIO* io, UWORD32 n = NoLimit) = 0 ;
43 virtual void write (BinaryIO* io, UWORD32 n = NoLimit) = 0 ;
44} ;
45
50template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType = AudioSampleValue<Type,ValueType> >
51class AudioDataImpl : public AudioData {
52 public:
54 virtual ~AudioDataImpl (void) {} ;
55
56 void read (BinaryIO* io, UWORD32 n = AudioData::NoLimit) ;
58
59 unsigned long getNumSamples (void) const ;
60 SampleValue* getSampleValue (const SamplePos pos) const ;
61 void replaceSample (const SamplePos pos, const SampleValue* s) ;
62
63 private:
64 std::vector<ValueType> Data ;
66
67 ValueType readValue (BinaryIO* io) const ;
68 void writeValue (BinaryIO* io, ValueType v) const ;
69} ;
70
71#include "error.h"
72
73template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
75{
76 try {
77 if (n == NoLimit) {
78 Data.clear() ;
79 while (!io->eof()) {
80 Data.push_back (readValue(io)) ;
81 }
82 }
83 else {
84 Data.resize (n) ;
85 for (UWORD32 i = 0 ; i < n ; i++) {
86 Data[i] = readValue(io) ;
87 }
88 }
89 }
90 catch (BinaryInputError e) {
91 switch (e.getType()) {
93 {
94 throw SteghideError (_("an error occured while reading the audio data from the file \"%s\"."), io->getName().c_str()) ;
95 break ;
96 }
97
99 {
100 throw SteghideError (_("premature end of file \"%s\" while reading audio data."), io->getName().c_str()) ;
101 break ;
102 }
103
105 {
106 throw SteghideError (_("an error occured while reading the audio data from standard input.")) ;
107 break ;
108 }
109
111 {
112 throw SteghideError (_("premature end of data from standard input while reading audio data.")) ;
113 break ;
114 }
115 }
116 }
117}
118
119template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
121{
122 try {
123 if (n == NoLimit) {
124 n = Data.size() ;
125 }
126 for (UWORD32 i = 0 ; i < n ; i++) {
127 writeValue (io, Data[i]) ;
128 }
129 }
130 catch (BinaryOutputError e) {
131 switch (e.getType()) {
133 {
134 throw SteghideError (_("an error occured while writing the audio data to the file \"%s\"."), io->getName().c_str()) ;
135 break ;
136 }
137
139 {
140 throw SteghideError (_("an error occured while writing the audio data to standard output.")) ;
141 break ;
142 }
143 }
144 }
145}
146
147template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
149{
150 return Data.size() ;
151}
152
153template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
155{
156 myassert (pos < Data.size()) ;
157 return ((SampleValue*) new SampleValueType (Data[pos])) ;
158}
159
160template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
162{
163 const SampleValueType* sample = dynamic_cast<const SampleValueType*> (s) ;
164 myassert (sample) ;
165 myassert (pos < Data.size()) ;
166 Data[pos] = sample->getValue() ;
167}
168
169#endif // ndef SH_AUDIODATA_H
implementation of the AudioData-Interface
Definition: AudioData.h:51
ValueType readValue(BinaryIO *io) const
Definition: AuData.h:29
void replaceSample(const SamplePos pos, const SampleValue *s)
Definition: AudioData.h:161
SampleValue * getSampleValue(const SamplePos pos) const
Definition: AudioData.h:154
AudioDataImpl(CvrStgFile *f)
Definition: AudioData.h:53
void write(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition: AudioData.h:120
void read(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition: AudioData.h:74
virtual ~AudioDataImpl(void)
Definition: AudioData.h:54
unsigned long getNumSamples(void) const
Definition: AudioData.h:148
std::vector< ValueType > Data
Definition: AudioData.h:64
CvrStgFile * TheCvrStgFile
Definition: AudioData.h:65
void writeValue(BinaryIO *io, ValueType v) const
interface definition for AudioData objects.
Definition: AudioData.h:37
virtual void read(BinaryIO *io, UWORD32 n=NoLimit)=0
static const UWORD32 NoLimit
constant that can be used as parameter to read and write to indicate that there is no limit
Definition: AudioData.h:40
virtual void write(BinaryIO *io, UWORD32 n=NoLimit)=0
provides methods for file i/o as needed by the rest of steghide
Definition: BinaryIO.h:33
bool eof(void) const
Definition: BinaryIO.cc:123
const std::string & getName(void) const
Definition: BinaryIO.h:53
Definition: error.h:38
@ STDIN_ERR
Definition: error.h:40
@ FILE_ERR
Definition: error.h:40
@ STDIN_EOF
Definition: error.h:40
@ FILE_EOF
Definition: error.h:40
TYPE getType(void)
Definition: error.cc:76
Definition: error.h:53
TYPE getType(void)
Definition: error.cc:102
@ STDOUT_ERR
Definition: error.h:55
@ FILE_ERR
Definition: error.h:55
a cover-/stego-file
Definition: CvrStgFile.h:46
an object that can hold embedded data
Definition: CvrStgObject.h:40
the value of a sample in a CvrStgFile
Definition: SampleValue.h:61
Definition: SteghideError.h:28
UWORD32 SamplePos
Definition: common.h:67
unsigned long UWORD32
Definition: common.h:45
#define _(S)
Definition: common.h:78
#define myassert(expr)
Definition: common.h:89