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"
27 class BinaryIO ;
28 #include "CvrStgObject.h"
29 
37 class 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 
50 template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType = AudioSampleValue<Type,ValueType> >
51 class AudioDataImpl : public AudioData {
52  public:
53  AudioDataImpl (CvrStgFile* f) : TheCvrStgFile(f) {} ;
54  virtual ~AudioDataImpl (void) {} ;
55 
56  void read (BinaryIO* io, UWORD32 n = AudioData::NoLimit) ;
57  void write (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 
73 template<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 
119 template<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 
147 template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
149 {
150  return Data.size() ;
151 }
152 
153 template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
155 {
156  myassert (pos < Data.size()) ;
157  return ((SampleValue*) new SampleValueType (Data[pos])) ;
158 }
159 
160 template<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
Definition: SteghideError.h:28
TYPE getType(void)
Definition: error.cc:76
#define _(S)
Definition: common.h:78
Definition: error.h:40
Definition: error.h:55
a cover-/stego-file
Definition: CvrStgFile.h:46
SampleValue * getSampleValue(const SamplePos pos) const
Definition: AudioData.h:154
an object that can hold embedded data
Definition: CvrStgObject.h:40
UWORD32 SamplePos
Definition: common.h:67
bool eof(void) const
Definition: BinaryIO.cc:123
std::vector< ValueType > Data
Definition: AudioData.h:64
Definition: error.h:55
the value of a sample in a CvrStgFile
Definition: SampleValue.h:61
#define myassert(expr)
Definition: common.h:89
implementation of the AudioData-Interface
Definition: AudioData.h:51
CvrStgFile * TheCvrStgFile
Definition: AudioData.h:65
unsigned long getNumSamples(void) const
Definition: AudioData.h:148
unsigned long UWORD32
Definition: common.h:45
virtual ~AudioDataImpl(void)
Definition: AudioData.h:54
interface definition for AudioData objects.
Definition: AudioData.h:37
provides methods for file i/o as needed by the rest of steghide
Definition: BinaryIO.h:33
void read(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition: AudioData.h:74
TYPE getType(void)
Definition: error.cc:102
virtual void write(BinaryIO *io, UWORD32 n=NoLimit)=0
Definition: error.h:53
Definition: error.h:38
Definition: error.h:40
void write(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition: AudioData.h:120
const std::string & getName(void) const
Definition: BinaryIO.h:53
virtual SampleValue * getSampleValue(const SamplePos pos) const =0
virtual unsigned long getNumSamples(void) const =0
virtual void read(BinaryIO *io, UWORD32 n=NoLimit)=0
void replaceSample(const SamplePos pos, const SampleValue *s)
Definition: AudioData.h:161
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 replaceSample(const SamplePos pos, const SampleValue *s)=0
Definition: error.h:40
AudioDataImpl(CvrStgFile *f)
Definition: AudioData.h:53
Definition: error.h:40