pcce::OggFile Class Reference

#include <OggFile.h>

List of all members.

Public Member Functions

 OggFile (const std::string &fileName)
 ~OggFile ()
void SetFileName (const std::string &fileName)
bool IsOpen ()
void Open ()
void Close ()
void Rewind ()
size_t Read (size_t size, tCharVector &result)
size_t Read (tCharVector &result)
unsigned short GetChannelCount ()
unsigned long GetFrequency ()

Private Member Functions

void GetInfo ()
void ResetInfo ()

Private Attributes

std::string mFileName
OggVorbis_File * mVorbisFile
unsigned short mChannels
unsigned long mFreq


Detailed Description

Definition at line 45 of file OggFile.h.


Constructor & Destructor Documentation

OggFile::OggFile ( const std::string &  fileName  ) 

Definition at line 57 of file OggFile.cpp.

00057                                          : mFileName(fileName), mVorbisFile(NULL), mChannels(0), mFreq(0) {
00058 }

OggFile::~OggFile (  ) 

Definition at line 60 of file OggFile.cpp.

References Close().

00060                   {
00061   Close();
00062 }


Member Function Documentation

void OggFile::SetFileName ( const std::string &  fileName  ) 

Definition at line 64 of file OggFile.cpp.

References IsOpen(), mFileName, and PCCE_CHECK.

00064                                                    {
00065   PCCE_CHECK(!IsOpen(), "OggFile::SetFileName: Cannot set filename of open OggFile");
00066   mFileName = fileName;
00067 }

bool OggFile::IsOpen (  ) 

Definition at line 69 of file OggFile.cpp.

References mVorbisFile.

Referenced by Close(), GetChannelCount(), GetFrequency(), GetInfo(), Open(), Rewind(), and SetFileName().

00069                      {
00070   return NULL != mVorbisFile;
00071 }

void OggFile::Open (  ) 

Definition at line 73 of file OggFile.cpp.

References IsOpen(), mFileName, mVorbisFile, OggCallbacks, PCCE_CHECK, and PCCE_THROW.

Referenced by pcce::LoadOgg(), and pcce::OggStream::OggStream().

00073                    {
00074   PCCE_CHECK(!IsOpen(), "OggFile::Open: OggFile already open");
00075 
00076   FILE* f = fopen(mFileName.c_str(), "rb");
00077   if (!f) {
00078     PCCE_THROW("LoadOgg: Could not load ogg from " + mFileName);
00079   }
00080 
00081   mVorbisFile = new OggVorbis_File();
00082   if (ov_open_callbacks(f, mVorbisFile, NULL, 0, OggCallbacks) != 0) {
00083     delete mVorbisFile;
00084     mVorbisFile = NULL;
00085     fclose(f);
00086     PCCE_THROW("LoadOgg: ov_open failed on " + mFileName);
00087   }
00088 }

void OggFile::Close (  ) 

Definition at line 90 of file OggFile.cpp.

References IsOpen(), mVorbisFile, and ResetInfo().

Referenced by pcce::LoadOgg(), and ~OggFile().

00090                     {
00091   if (IsOpen()) {
00092     ov_clear(mVorbisFile);
00093     delete mVorbisFile;
00094     mVorbisFile = NULL;
00095   }
00096   ResetInfo();
00097 }

void OggFile::Rewind (  ) 

Definition at line 99 of file OggFile.cpp.

References IsOpen(), mVorbisFile, and PCCE_CHECK.

Referenced by pcce::OggStream::Stop().

00099                      {
00100   PCCE_CHECK(IsOpen(), "OggFile::Rewind: OggFile must be open to rewind");
00101   
00102   PCCE_CHECK(ov_raw_seek(mVorbisFile, 0) == 0, "OggFile::Rewind: Could not rewind");
00103 }

size_t OggFile::Read ( size_t  size,
tCharVector result 
)

Definition at line 105 of file OggFile.cpp.

References BUFFER_SIZE, mVorbisFile, and PCCE_CHECK.

Referenced by pcce::OggStream::FillBuffer(), pcce::LoadOgg(), and Read().

00105                                                      {
00106   // 0 for Little-Endian, 1 for Big-Endian
00107   #if PCCE_BIG_ENDIAN
00108   int endian = 1;
00109   #else
00110   int endian = 0;
00111   #endif
00112   char array[BUFFER_SIZE];
00113   long bytes;
00114   int bitStream;
00115   size_t totalRead = 0;
00116   
00117   PCCE_CHECK(size > 0, "OggFile::Read: size must be > 0");
00118   
00119   do {
00120     PCCE_CHECK(totalRead < size, "OggFile::Read: Internal error");
00121     
00122     // Read up to a buffer's worth of decoded sound data
00123     bytes = ov_read(mVorbisFile, array, std::min(size - totalRead, BUFFER_SIZE), endian, 2, 1, &bitStream);
00124     // Append to end of buffer
00125     result.insert(result.end(), array, array + bytes);
00126     
00127     totalRead += bytes;
00128   } while ((bytes > 0) && (totalRead < size));
00129   
00130   return totalRead;
00131 }

size_t OggFile::Read ( tCharVector result  ) 

Definition at line 133 of file OggFile.cpp.

References BUFFER_SIZE, and Read().

00133                                         {
00134   size_t totalCount = 0;
00135   size_t readCount;
00136   
00137   do {
00138     readCount = Read(BUFFER_SIZE, result);
00139     totalCount += readCount;
00140   } while (readCount == BUFFER_SIZE);
00141   
00142   return totalCount;
00143 }

unsigned short OggFile::GetChannelCount (  ) 

Definition at line 145 of file OggFile.cpp.

References GetInfo(), IsOpen(), mChannels, and PCCE_CHECK.

Referenced by pcce::LoadOgg(), and pcce::OggStream::OggStream().

00145                                         {
00146   PCCE_CHECK(IsOpen(), "OggFile::GetFormat: You must open a file first");
00147   if (mChannels == 0) {
00148     GetInfo();
00149   }
00150   return mChannels;
00151 }

unsigned long OggFile::GetFrequency (  ) 

Definition at line 153 of file OggFile.cpp.

References GetInfo(), IsOpen(), mFreq, and PCCE_CHECK.

Referenced by pcce::LoadOgg(), and pcce::OggStream::OggStream().

00153                                     {
00154   PCCE_CHECK(IsOpen(), "OggFile::GetFrequency: You must open a file first");
00155   if (mFreq == 0) {
00156     GetInfo();
00157   }
00158   return mFreq;
00159 }

void OggFile::GetInfo (  )  [private]

Definition at line 161 of file OggFile.cpp.

References IsOpen(), mChannels, mFileName, mFreq, mVorbisFile, and PCCE_CHECK.

Referenced by GetChannelCount(), and GetFrequency().

00161                       {
00162   PCCE_CHECK(IsOpen(), "OggFile::LoadInfo: You must open a file first");
00163   
00164   vorbis_info* info = ov_info(mVorbisFile, -1);
00165   PCCE_CHECK(info != NULL, "OggFile::LoadInfo: ov_info failed on " + mFileName);
00166 
00167   mChannels = info->channels;
00168   mFreq = info->rate;
00169 }

void OggFile::ResetInfo (  )  [private]

Definition at line 171 of file OggFile.cpp.

References mChannels, and mFreq.

Referenced by Close().

00171                         {
00172   mChannels = 0;
00173   mFreq = 0;
00174 }


Member Data Documentation

std::string pcce::OggFile::mFileName [private]

Definition at line 66 of file OggFile.h.

Referenced by GetInfo(), Open(), and SetFileName().

OggVorbis_File* pcce::OggFile::mVorbisFile [private]

Definition at line 67 of file OggFile.h.

Referenced by Close(), GetInfo(), IsOpen(), Open(), Read(), and Rewind().

unsigned short pcce::OggFile::mChannels [private]

Definition at line 68 of file OggFile.h.

Referenced by GetChannelCount(), GetInfo(), and ResetInfo().

unsigned long pcce::OggFile::mFreq [private]

Definition at line 69 of file OggFile.h.

Referenced by GetFrequency(), GetInfo(), and ResetInfo().


The documentation for this class was generated from the following files:

Generated on Thu Mar 6 11:39:28 2008 for Protocce by  doxygen 1.5.5