Skip to content

Commit

Permalink
Added a wrapper to make to clear an ogg vorbis struct only if initial…
Browse files Browse the repository at this point in the history
…ized.
  • Loading branch information
Yohann Ferreira committed Oct 5, 2012
1 parent 2de8456 commit 638dc36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/engine/audio/audio_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,16 @@ uint32 WavFile::Read(uint8* buffer, uint32 size, bool& end) {
// OggFile class methods
////////////////////////////////////////////////////////////////////////////////

OggFile::~OggFile() {
if (_initialized) {
ov_clear(&_vorbis_file);
_initialized = false;
}
}

bool OggFile::Initialize() {
_initialized = false;

// Windows requires a special loading method in order load ogg files
// properly when dynamically linking vorbis libs. The workaround is
// to use the ov_open_callbacks function
Expand Down Expand Up @@ -248,6 +257,7 @@ bool OggFile::Initialize() {
_sample_size = _number_channels * _bits_per_sample / 8;
_data_size = _total_number_samples * _sample_size;

_initialized = true;
return true;
} // bool OggFile::Initialize()

Expand Down
13 changes: 9 additions & 4 deletions src/engine/audio/audio_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ class WavFile : public AudioInput {
class OggFile : public AudioInput {
public:
OggFile(const std::string& file_name) :
AudioInput(), _read_buffer_position(0), _read_buffer_size(0) { _filename = file_name; }
AudioInput(), _read_buffer_position(0), _read_buffer_size(0),
_initialized(false)
{ _filename = file_name; }

~OggFile()
{ ov_clear(&_vorbis_file); }
~OggFile();

//! \brief Inherited functions from AudioInput class
//@{
Expand All @@ -209,6 +210,10 @@ class OggFile : public AudioInput {
//! \brief Size of available data on the buffer (for the emporal buffer).
uint16 _read_buffer_size;

//! \brief Tells whether the ogg/vorbis structures are successfully allocated.
//! It is used to know whether they can be deallocated.
bool _initialized;

/** \brief A wrapper function for file seek operations
*** \param ffile A pointer to the FILE struct which represents the input stream
*** \param off The number of bytes to offset from the stream's origin
Expand Down Expand Up @@ -239,7 +244,7 @@ class AudioMemory : public AudioInput {
*** fill that memory with the audio data read from the input argument
**/
AudioMemory(AudioInput* input);

AudioMemory(const AudioMemory& audio_memory);
AudioMemory& operator=(const AudioMemory& other_audio_memory);

Expand Down

0 comments on commit 638dc36

Please sign in to comment.