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
AudioSampleValue.h
CvrStgObject.h
AudioDataImpl::replaceSample
void replaceSample(const SamplePos pos, const SampleValue *s)
Definition AudioData.h:161
AudioDataImpl::getSampleValue
SampleValue * getSampleValue(const SamplePos pos) const
Definition AudioData.h:154
AudioDataImpl::AudioDataImpl
AudioDataImpl(CvrStgFile *f)
Definition AudioData.h:53
AudioDataImpl::write
void write(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition AudioData.h:120
AudioDataImpl::read
void read(BinaryIO *io, UWORD32 n=AudioData::NoLimit)
Definition AudioData.h:74
AudioDataImpl::~AudioDataImpl
virtual ~AudioDataImpl(void)
Definition AudioData.h:54
AudioDataImpl::getNumSamples
unsigned long getNumSamples(void) const
Definition AudioData.h:148
AudioDataImpl< AuMuLaw, BYTE >::Data
std::vector< BYTE > Data
Definition AudioData.h:64
AudioDataImpl::readValue
ValueType readValue(BinaryIO *io) const
AudioDataImpl< AuMuLaw, BYTE >::TheCvrStgFile
CvrStgFile * TheCvrStgFile
Definition AudioData.h:65
AudioDataImpl::writeValue
void writeValue(BinaryIO *io, ValueType v) const
AudioData
interface definition for AudioData objects.
Definition AudioData.h:37
AudioData::read
virtual void read(BinaryIO *io, UWORD32 n=NoLimit)=0
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
AudioData::write
virtual void write(BinaryIO *io, UWORD32 n=NoLimit)=0
BinaryIO
provides methods for file i/o as needed by the rest of steghide
Definition BinaryIO.h:33
BinaryIO::eof
bool eof(void) const
Definition BinaryIO.cc:123
BinaryIO::getName
const std::string & getName(void) const
Definition BinaryIO.h:53
BinaryInputError
Definition error.h:38
BinaryInputError::STDIN_ERR
@ STDIN_ERR
Definition error.h:40
BinaryInputError::FILE_ERR
@ FILE_ERR
Definition error.h:40
BinaryInputError::STDIN_EOF
@ STDIN_EOF
Definition error.h:40
BinaryInputError::FILE_EOF
@ FILE_EOF
Definition error.h:40
BinaryInputError::getType
TYPE getType(void)
Definition error.cc:76
BinaryOutputError
Definition error.h:53
BinaryOutputError::getType
TYPE getType(void)
Definition error.cc:102
BinaryOutputError::STDOUT_ERR
@ STDOUT_ERR
Definition error.h:55
BinaryOutputError::FILE_ERR
@ FILE_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
SampleValue
the value of a sample in a CvrStgFile
Definition SampleValue.h:61
SteghideError
Definition SteghideError.h:28
SamplePos
UWORD32 SamplePos
Definition common.h:67
UWORD32
unsigned long UWORD32
Definition common.h:45
_
#define _(S)
Definition common.h:78
myassert
#define myassert(expr)
Definition common.h:89
error.h