Lephisto/trunk/src/SoundStream.h

56 lines
1.5 KiB
C++

/* This software is the propery of 'SaraCraft' - developed by Allanis.
* Only members directly assosiated with the SaraCraft project may view/change
* this code.
*
* This class streams music from disk so that
* all the music doesn't need to be in memory.
*/
#ifndef _SOUNDSTREAM_H_
#define _SOUNDSTREAM_H_
#include <string>
#include <iostream>
using namespace std;
#include <AL/al.h>
#include <ogg/ogg.h>
#include <vorbis/codec.h>
#include <vorbis/vorbisenc.h>
#include <vorbis/vorbisfile.h>
#define BUFFER_SIZE (4096 * 8)
class SoundStream {
public:
void open(string path); // Obtain a handle to the file
void release(); // Release the file handle
void display(); // display some info on the Ogg
bool playback(); // Play the Ogg stream
bool playing(); // Check if the source is playing
bool update(); // Update the stream if needed
void reload(); // Starts the file from beginning
protected:
bool stream(ALuint buffer); // Reload a buffer
void empty(); // Empties the queue
void check(); // checks OpenAL error state
string errorString(int code); // stringify an error code
private:
FILE* oggFile; // file handle
OggVorbis_File oggStream; // stream handle
vorbis_info* vorbisInfo; // some formatting data
vorbis_comment* vorbisComment; // user comments
ALuint buffers[2]; // Front and back buffers
ALuint source; // audio source
ALuint format; // Internal format
string file; // Used to store where the file is
};
#endif