NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
|
This class implements the wave file type using PCM encoding (the simplest encoding). Due to its simplicity it is a seekable file type. More...
#include <wavfile.hpp>
Public Member Functions | |
WavFile (const std::string &sFileName) | |
Constructor. Tries to open the wave file, if it exists. More... | |
virtual | ~WavFile () |
Destructor. Will close the file stream and update the header. More... | |
virtual bool | isValid () const |
Returns, whether the currently opened file is actually open and readable. More... | |
virtual void | newFile () override |
Prepares the wave file header for a new file, opens the stream and writes the header to the file. Set number of channels and sample frequency before calling this member function. More... | |
virtual void | setChannels (size_t channels) override |
Set the channels, which shall be used in the new file. More... | |
virtual void | setSampleRate (size_t freq) override |
Set the sample rate, which shall be used in the new file. More... | |
virtual void | write (const Sample &sample) override |
Write a sample to the audio stream. More... | |
virtual size_t | getChannels () const override |
Get the number of channels of the current file. More... | |
virtual size_t | getSampleRate () const override |
Get the sample rate of the current file. More... | |
virtual size_t | getLength () const override |
Get the length in samples of the current file. More... | |
virtual Sample | read () const override |
Read a sample from the audio stream. More... | |
virtual size_t | getPosition () const override |
Get the current position in samples of the current file. More... | |
virtual void | setPosition (size_t pos) override |
Set the current position in Samples in the current file. More... | |
virtual std::vector< Sample > | readSome (size_t len) const override |
Read a block of samples from the audio stream. More... | |
virtual void | writeSome (const std::vector< Sample > vSamples) override |
Write a block of samples to the audio stream. More... | |
Public Member Functions inherited from Audio::SeekableFile | |
SeekableFile () | |
virtual bool | isSeekable () const override |
Overrides the base classes member function to signal the possibility to safely up-cast to this class. More... | |
virtual size_t | getPosition () const =0 |
virtual void | setPosition (size_t pos)=0 |
virtual std::vector< Sample > | readSome (size_t len) const =0 |
virtual void | writeSome (const std::vector< Sample > vFrames)=0 |
Public Member Functions inherited from Audio::File | |
File () | |
virtual | ~File () |
virtual bool | isValid () const =0 |
virtual void | newFile ()=0 |
virtual void | setChannels (size_t channels)=0 |
virtual void | setSampleRate (size_t freq)=0 |
virtual void | write (const Sample &frame)=0 |
virtual size_t | getChannels () const =0 |
virtual size_t | getSampleRate () const =0 |
virtual size_t | getLength () const =0 |
virtual Sample | read () const =0 |
virtual bool | isSeekable () const |
Audio files, which inherit from this class do not have any seeking functionality. More... | |
Private Member Functions | |
bool | readHeader () |
Private member function to read the wave file header to memory. It will ensure that the current file is actually a RIFF WAVE file. More... | |
void | closeFile () |
Updates the wave file header, which is currently open, and closes the file afterwards. More... | |
Private Attributes | |
std::string | sName |
std::fstream | m_WavFileStream |
WavFileHeader | m_Header |
uint32_t | m_DataBlockLength |
const long long int | m_StreamOffset = 44 |
bool | isNewFile |
This class implements the wave file type using PCM encoding (the simplest encoding). Due to its simplicity it is a seekable file type.
Definition at line 52 of file wavfile.hpp.
Audio::WavFile::WavFile | ( | const std::string & | sFileName | ) |
Constructor. Tries to open the wave file, if it exists.
sFileName | const std::string& |
Definition at line 61 of file wavfile.cpp.
References m_WavFileStream, readHeader(), and sName.
|
virtual |
Destructor. Will close the file stream and update the header.
Definition at line 75 of file wavfile.cpp.
References closeFile().
|
private |
Updates the wave file header, which is currently open, and closes the file afterwards.
Definition at line 141 of file wavfile.cpp.
References m_WavFileStream.
Referenced by newFile(), and ~WavFile().
|
inlineoverridevirtual |
Get the number of channels of the current file.
Implements Audio::File.
Definition at line 118 of file wavfile.hpp.
References Audio::WavFileHeader::channels, and m_Header.
|
inlineoverridevirtual |
Get the length in samples of the current file.
Implements Audio::File.
Definition at line 142 of file wavfile.hpp.
References Audio::WavFileHeader::bitsPerSample, Audio::WavFileHeader::channels, m_DataBlockLength, and m_Header.
|
inlineoverridevirtual |
Get the current position in samples of the current file.
Implements Audio::SeekableFile.
Definition at line 156 of file wavfile.hpp.
References Audio::WavFileHeader::bitsPerSample, Audio::WavFileHeader::channels, m_Header, m_StreamOffset, and m_WavFileStream.
|
inlineoverridevirtual |
Get the sample rate of the current file.
Implements Audio::File.
Definition at line 130 of file wavfile.hpp.
References m_Header, and Audio::WavFileHeader::sampleRate.
|
inlinevirtual |
Returns, whether the currently opened file is actually open and readable.
Implements Audio::File.
Definition at line 76 of file wavfile.hpp.
References m_WavFileStream.
|
overridevirtual |
Prepares the wave file header for a new file, opens the stream and writes the header to the file. Set number of channels and sample frequency before calling this member function.
Implements Audio::File.
Definition at line 167 of file wavfile.cpp.
References Audio::WavFileHeader::bitsPerSample, Audio::WavFileHeader::blockAlign, Audio::WavFileHeader::bytesPerSecond, Audio::WavFileHeader::channels, closeFile(), Audio::WavFileHeader::formatTag, m_Header, m_WavFileStream, PCM, Audio::WavFileHeader::sampleRate, sName, and date::detail::trunc().
|
overridevirtual |
Read a sample from the audio stream.
Implements Audio::File.
Definition at line 215 of file wavfile.cpp.
References Audio::WavFileHeader::bitsPerSample, Audio::WavFileHeader::blockAlign, Audio::WavFileHeader::channels, Audio::convertFromUnsigned(), Audio::getMaxVal(), m_Header, and m_WavFileStream.
Referenced by readSome().
|
private |
Private member function to read the wave file header to memory. It will ensure that the current file is actually a RIFF WAVE file.
Definition at line 90 of file wavfile.cpp.
References Audio::WavFileHeader::formatTag, m_DataBlockLength, m_Header, m_WavFileStream, and PCM.
Referenced by WavFile().
|
overridevirtual |
Read a block of samples from the audio stream.
len | size_t |
Implements Audio::SeekableFile.
Definition at line 243 of file wavfile.cpp.
References m_WavFileStream, and read().
|
inlineoverridevirtual |
Set the channels, which shall be used in the new file.
channels | size_t |
Implements Audio::File.
Definition at line 91 of file wavfile.hpp.
References Audio::WavFileHeader::channels, and m_Header.
|
inlineoverridevirtual |
Set the current position in Samples in the current file.
pos | size_t |
Implements Audio::SeekableFile.
Definition at line 172 of file wavfile.hpp.
References Audio::WavFileHeader::bitsPerSample, Audio::WavFileHeader::channels, m_DataBlockLength, m_Header, m_StreamOffset, and m_WavFileStream.
|
inlineoverridevirtual |
Set the sample rate, which shall be used in the new file.
freq | size_t |
Implements Audio::File.
Definition at line 104 of file wavfile.hpp.
References m_Header, and Audio::WavFileHeader::sampleRate.
|
overridevirtual |
Write a sample to the audio stream.
sample | const Sample& |
Implements Audio::File.
Definition at line 193 of file wavfile.cpp.
References Audio::WavFileHeader::channels, Audio::getMaxVal(), mu::isnan(), Audio::Sample::leftOrMono, m_Header, m_WavFileStream, and Audio::Sample::right.
Referenced by writeSome().
|
overridevirtual |
Write a block of samples to the audio stream.
vSamples | const std::vector<Sample> |
Implements Audio::SeekableFile.
Definition at line 267 of file wavfile.cpp.
References write().
|
private |
Definition at line 60 of file wavfile.hpp.
|
private |
Definition at line 58 of file wavfile.hpp.
Referenced by getLength(), readHeader(), and setPosition().
|
private |
Definition at line 57 of file wavfile.hpp.
Referenced by getChannels(), getLength(), getPosition(), getSampleRate(), newFile(), read(), readHeader(), setChannels(), setPosition(), setSampleRate(), and write().
|
private |
Definition at line 59 of file wavfile.hpp.
Referenced by getPosition(), and setPosition().
|
mutableprivate |
Definition at line 56 of file wavfile.hpp.
Referenced by closeFile(), getPosition(), isValid(), newFile(), read(), readHeader(), readSome(), setPosition(), WavFile(), and write().
|
private |
Definition at line 55 of file wavfile.hpp.