// Global header files
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
// Local header files
#include "s_soundbuffer.h"
// Definitions
#define S_OGGVORBIS_LITTLEENDIAN 0
#define S_OGGVORBIS_BIGENDIAN 1
// Include library(s)
#pragma comment(lib, "ogg.lib")
#pragma comment(lib, "vorbis.lib")
#pragma comment(lib, "vorbisfile.lib")
// Prototypes
class OggVorbis;
// Classes
class OggVorbis : public SoundBuffer {
public:
BOOL LoadOGG(LPCSTR pFilename);
BOOL Decode(VOID);
protected:
vorbis_info* m_pFileInfo;
OggVorbis_File m_oggFile;
};
#include "s_oggvorbis.h"
using namespace std;
BOOL OggVorbis::LoadOGG(LPCSTR pFilename) {
BOOL bEndian=FALSE;
FILE* fp=NULL;
// Open the Ogg file for reading
fp = fopen(/* pFilename */ "Test.ogg", "rb");
if(!fp)
return FALSE; // Unable to open file for reading in binary mode, failed
// ZeroMemory(&m_oggFile, sizeof(OggVorbis_File));
// Open the Ogg file for reading within the Ogg Vorbis SDK Library
ov_open(fp, &m_oggFile, NULL, 0);
// Get Ogg file information
m_pFileInfo = ov_info(&m_oggFile, -1);
// Set the PCM format of the Ogg File
SetFormat(m_pFileInfo->rate, m_pFileInfo->channels, /* TODO: Find proper bit rate here */ 16);
// Create an empty buffer
Create(0);
// Read and Decode the Ogg File
Decode();
// Close the Ogg file in the SDK
ov_clear(&m_oggFile);
// Close the Ogg file
fp=NULL;
return TRUE;
}
//
//
//
BOOL OggVorbis::Decode(VOID) {
LONG lBytes=0;
CHAR szBuffer[32768];
int nBitstream;
do {
// Read a buffers worth of decoded sound data
lBytes = ov_read(&m_oggFile, szBuffer, 32768, S_OGGVORBIS_LITTLEENDIAN, 2, 1, (int*)&nBitstream);
// Append the sound data to the buffer
Append((BYTE*)szBuffer, lBytes);
} while(lBytes > 0);
return TRUE;
}