AudioData.h
Go to the documentation of this file.
/*
* steghide 0.5.1 - a steganography program
* Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef SH_AUDIODATA_H
#define SH_AUDIODATA_H
#include <vector>
#include "AudioSampleValue.h"
class BinaryIO ;
#include "CvrStgObject.h"
class AudioData : public CvrStgObject {
public:
static const UWORD32 NoLimit = 0 ;
virtual void read (BinaryIO* io, UWORD32 n = NoLimit) = 0 ;
virtual void write (BinaryIO* io, UWORD32 n = NoLimit) = 0 ;
} ;
template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType = AudioSampleValue<Type,ValueType> >
class AudioDataImpl : public AudioData {
public:
AudioDataImpl (CvrStgFile* f) : TheCvrStgFile(f) {} ;
virtual ~AudioDataImpl (void) {} ;
void read (BinaryIO* io, UWORD32 n = AudioData::NoLimit) ;
void write (BinaryIO* io, UWORD32 n = AudioData::NoLimit) ;
unsigned long getNumSamples (void) const ;
SampleValue* getSampleValue (const SamplePos pos) const ;
void replaceSample (const SamplePos pos, const SampleValue* s) ;
private:
std::vector<ValueType> Data ;
CvrStgFile* TheCvrStgFile ;
ValueType readValue (BinaryIO* io) const ;
void writeValue (BinaryIO* io, ValueType v) const ;
} ;
#include "error.h"
template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
void AudioDataImpl<Type,ValueType,SampleValueType>::read (BinaryIO* io, UWORD32 n)
{
try {
if (n == NoLimit) {
Data.clear() ;
while (!io->eof()) {
Data.push_back (readValue(io)) ;
}
}
else {
Data.resize (n) ;
for (UWORD32 i = 0 ; i < n ; i++) {
Data[i] = readValue(io) ;
}
}
}
catch (BinaryInputError e) {
switch (e.getType()) {
case BinaryInputError::FILE_ERR:
{
throw SteghideError (_("an error occurred while reading the audio data from the file \"%s\"."), io->getName().c_str()) ;
break ;
}
case BinaryInputError::FILE_EOF:
{
throw SteghideError (_("premature end of file \"%s\" while reading audio data."), io->getName().c_str()) ;
break ;
}
case BinaryInputError::STDIN_ERR:
{
throw SteghideError (_("an error occurred while reading the audio data from standard input.")) ;
break ;
}
case BinaryInputError::STDIN_EOF:
{
throw SteghideError (_("premature end of data from standard input while reading audio data.")) ;
break ;
}
}
}
}
template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
void AudioDataImpl<Type,ValueType,SampleValueType>::write (BinaryIO* io, UWORD32 n)
{
try {
if (n == NoLimit) {
n = Data.size() ;
}
for (UWORD32 i = 0 ; i < n ; i++) {
writeValue (io, Data[i]) ;
}
}
catch (BinaryOutputError e) {
switch (e.getType()) {
case BinaryOutputError::FILE_ERR:
{
throw SteghideError (_("an error occurred while writing the audio data to the file \"%s\"."), io->getName().c_str()) ;
break ;
}
case BinaryOutputError::STDOUT_ERR:
{
throw SteghideError (_("an error occurred while writing the audio data to standard output.")) ;
break ;
}
}
}
}
template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
unsigned long AudioDataImpl<Type,ValueType,SampleValueType>::getNumSamples (void) const
{
return Data.size() ;
}
template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
SampleValue* AudioDataImpl<Type,ValueType,SampleValueType>::getSampleValue (const SamplePos pos) const
{
myassert (pos < Data.size()) ;
return ((SampleValue*) new SampleValueType (Data[pos])) ;
}
template<AUDIOSAMPLETYPE Type, class ValueType, class SampleValueType>
void AudioDataImpl<Type,ValueType,SampleValueType>::replaceSample (const SamplePos pos, const SampleValue* s)
{
const SampleValueType* sample = dynamic_cast<const SampleValueType*> (s) ;
myassert (sample) ;
myassert (pos < Data.size()) ;
Data[pos] = sample->getValue() ;
}
#endif // ndef SH_AUDIODATA_H
SteghideError
Definition: SteghideError.h:28
BinaryInputError::getType
TYPE getType(void)
Definition: error.cc:76
_
#define _(S)
Definition: common.h:78
BinaryIO::eof
bool eof(void) const
Definition: BinaryIO.cc:123
BinaryInputError::FILE_ERR
Definition: error.h:40
BinaryOutputError::STDOUT_ERR
Definition: error.h:55
CvrStgFile
a cover-/stego-file
Definition: CvrStgFile.h:46
CvrStgObject
an object that can hold embedded data
Definition: CvrStgObject.h:40
SamplePos
UWORD32 SamplePos
Definition: common.h:67
AudioDataImpl::Data
std::vector< ValueType > Data
Definition: AudioData.h:64
AudioDataImpl::getSampleValue
SampleValue * getSampleValue(const SamplePos pos) const
Definition: AudioData.h:154
CvrStgObject::getSampleValue
virtual SampleValue * getSampleValue(const SamplePos pos) const =0
BinaryOutputError::FILE_ERR
Definition: error.h:55
SampleValue
the value of a sample in a CvrStgFile
Definition: SampleValue.h:61
error.h
myassert
#define myassert(expr)
Definition: common.h:89
AudioSampleValue.h
AudioDataImpl
implementation of the AudioData-Interface
Definition: AudioData.h:51
AudioDataImpl::TheCvrStgFile
CvrStgFile * TheCvrStgFile
Definition: AudioData.h:65
UWORD32
unsigned long UWORD32
Definition: common.h:45
AudioDataImpl::~AudioDataImpl
virtual ~AudioDataImpl(void)
Definition: AudioData.h:54
AudioData
interface definition for AudioData objects.
Definition: AudioData.h:37
BinaryIO
provides methods for file i/o as needed by the rest of steghide
Definition: BinaryIO.h:33
AudioDataImpl::read
void read(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition: AudioData.h:74
BinaryOutputError::getType
TYPE getType(void)
Definition: error.cc:102
CvrStgObject::getNumSamples
virtual unsigned long getNumSamples(void) const =0
AudioData::write
virtual void write(BinaryIO *io, UWORD32 n=NoLimit)=0
BinaryOutputError
Definition: error.h:53
BinaryInputError
Definition: error.h:38
BinaryIO::getName
const std::string & getName(void) const
Definition: BinaryIO.h:53
BinaryInputError::STDIN_ERR
Definition: error.h:40
AudioDataImpl::write
void write(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition: AudioData.h:120
AudioDataImpl::getNumSamples
unsigned long getNumSamples(void) const
Definition: AudioData.h:148
AudioData::read
virtual void read(BinaryIO *io, UWORD32 n=NoLimit)=0
AudioDataImpl::replaceSample
void replaceSample(const SamplePos pos, const SampleValue *s)
Definition: AudioData.h:161
AudioData::NoLimit
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
CvrStgObject::replaceSample
virtual void replaceSample(const SamplePos pos, const SampleValue *s)=0
BinaryInputError::STDIN_EOF
Definition: error.h:40
AudioDataImpl::AudioDataImpl
AudioDataImpl(CvrStgFile *f)
Definition: AudioData.h:53
CvrStgObject.h
BinaryInputError::FILE_EOF
Definition: error.h:40