1#ifndef __EO_UTILS_WAVFILE_H__
2#define __EO_UTILS_WAVFILE_H__
35 void close()
override;
78 template <
class SampleType>
86 result.
addError(
"Can't get next audio file sample: Not in read mode");
93 std::ostringstream oss;
94 oss <<
"Audio sample size (" << mWAVFileInfo.
BitsPerSample() <<
" bits) is more than data type size (" << (
sizeof(SampleType) *
BITS_PER_BYTE) <<
" bits)";
95 result.addError(oss.str());
102 result.addError(
"WAVFile::getNextSample(): The file is not open");
108 result.addError(
"At end of file");
115 mFileStream.read((
char*)&pAudioSample, sampleSize);
117 reverseBytes((
void*)&pAudioSample,
sizeof(pAudioSample));
130 template <
class SampleType>
143 reverseBytes((
void*)&pAudioSample,
sizeof(pAudioSample));
144 const size_t sampleSize = (mWAVFileInfo.
BytesPerSample() <
sizeof(pAudioSample) ? mWAVFileInfo.
BytesPerSample() :
sizeof(pAudioSample));
145 mFileStream.write((
const char*)&pAudioSample, sampleSize);
149 result.addError(
"WAVFile::writeSample(): The file is not open");
179 template <
class SampleType>
187 result.
addError(
"WAVFile::getHighestSamplevalue(): The file is not open");
193 SampleType sampleValue = 0;
194 SampleType highestSampleValue = 0;
196 for (
size_t i = 0; (i < numAudioSamples) &&
result; ++i)
201 if (sampleValue > highestSampleValue)
202 highestSampleValue = sampleValue;
207 pAudioSample = highestSampleValue;
214 template <
class SampleType>
#define BITS_PER_BYTE
Definition AudioFileInfo.h:11
AudioFileResultType * result
Definition FLACFileInfo.cpp:24
Definition AudioFileInfo.h:14
virtual size_t BytesPerSample() const
Definition AudioFileInfo.cpp:120
Definition AudioFileResultType.h:13
void addError(const std::string &pError)
Definition AudioFileResultType.cpp:19
Definition AudioFile.h:22
size_t mDataSizeBytes
Definition AudioFile.h:233
virtual bool hasWriteMode() const
Returns whether or not write mode is enabled for the file.
Definition AudioFile.cpp:64
virtual bool hasReadMode() const
Returns whether or not read mode is enabled for the file.
Definition AudioFile.cpp:59
std::fstream mFileStream
Definition AudioFile.h:231
Definition WAVFileInfo.h:15
int16_t BitsPerSample() const
Definition WAVFileInfo.cpp:258
WAVFile(const std::string &pFilename)
AudioFileResultType goToAudioDataPos() override
Goes to the audio data position in the WAV file.
Definition WAVFile.cpp:220
const WAVFileInfo & getFileInfo() const
Returns a WAVFileInfo object with information about the WAV file.
Definition WAVFile.cpp:129
WAVFile(const std::string &pFilename, AudioFileModes pFileMode)
AudioFileResultType writeSample(SampleType pAudioSample)
Writes an audio sample to the file. This is templated so that the proper variable type can be used fo...
Definition WAVFile.h:131
void seekOutputToSampleNum(size_t pSampleNum) override
Definition WAVFile.cpp:259
~WAVFile()
Definition WAVFile.cpp:39
static AudioFileResultType getHighestSampleValue(const char *pFilename, SampleType &pAudioSample)
Definition WAVFile.h:215
AudioFileResultType open(AudioFileModes pOpenMode) override
Definition WAVFile.cpp:51
AudioFileResultType getNextSample_int64(int64_t &pAudioSample) override
Gets the next sample from the file, cast to a 64-bit integer.
Definition WAVFile.cpp:134
void close() override
Closes the WAV file.
Definition WAVFile.cpp:108
void setAudioFileInfo(const AudioFileInfo &pAudioFileInfo) override
Definition WAVFile.cpp:44
AudioFileResultType getHighestSampleValue(SampleType &pAudioSample)
Gets the highest audio sample value from the file. This is templated so that the proper variable type...
Definition WAVFile.h:180
AudioFileResultType writeSample_int64(int64_t pAudioSample) override
Writes an audio sample to the file. The parameter is a 64-bit integer but will be cast to the bitness...
Definition WAVFile.cpp:168
AudioFileInfo getAudioFileInfo() const override
Returns an AudioFile object with information about the audio file.
Definition WAVFile.cpp:265
AudioFileResultType getHighestSampleValue_int64(int64_t &pHighestAudioSample) override
Gets the highest audio sample value from the file, cast to a 64-bit integer.
Definition WAVFile.cpp:186
int64_t maxValueForSampleSize() const override
Returns the maximum possible positive value of the audio file's sample size.
Definition WAVFile.cpp:241
AudioFileResultType getNextSample(SampleType &pAudioSample)
Gets the next audio sample from the file. This is templated so that the proper variable type can be u...
Definition WAVFile.h:79
size_t numSamples() const override
Returns the number of audio samples in the WAV file.
Definition WAVFile.cpp:230
WAVFile(const std::string &pFilename, const WAVFileInfo &pWAVFileInfo)
Definition StringUtils.cpp:6
void reverseBytes(void *pStart, int pSize)
Definition EOUtils.cpp:18
AudioFileModes
Definition AudioFile.h:15
@ AUDIO_FILE_READ
Definition AudioFile.h:16
static bool machineIsBigEndian
Definition EOUtils.h:9