| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <string> |
| 4 |
|
| 5 |
#ifdef __APPLE__ |
| 6 |
#include <OpenAL/al.h> |
| 7 |
#include <OpenAL/alc.h> |
| 8 |
#else |
| 9 |
#include <AL/al.h> |
| 10 |
#include <AL/alc.h> |
| 11 |
#endif |
| 12 |
|
| 13 |
#include <wx/timer.h> |
| 14 |
|
| 15 |
class ArchiveFile; |
| 16 |
|
| 17 |
namespace sound { |
| 18 |
|
| 19 |
class SoundPlayer : |
| 20 |
public wxEvtHandler |
| 21 |
{ |
| 22 |
protected: |
| 23 |
// Are we set up yet? Defer initialisation until we play something. |
| 24 |
bool _initialised; |
| 25 |
|
| 26 |
ALCcontext* _context; |
| 27 |
|
| 28 |
// The buffer containing the currently played audio data |
| 29 |
ALuint _buffer; |
| 30 |
|
| 31 |
// The source playing the buffer |
| 32 |
ALuint _source; |
| 33 |
|
| 34 |
// The timer object to check whether the sound is done playing |
| 35 |
// to destroy the buffer afterwards |
| 36 |
wxTimer _timer; |
| 37 |
|
| 38 |
public: |
| 39 |
// Constructor |
| 40 |
SoundPlayer(); |
| 41 |
|
| 42 |
/** |
| 43 |
* greebo: Destroys the alut context |
| 44 |
*/ |
| 45 |
virtual ~SoundPlayer(); |
| 46 |
|
| 47 |
/** greebo: Call this with the ArchiveFile object containing |
| 48 |
* the file to be played. |
| 49 |
*/ |
| 50 |
virtual void play(ArchiveFile& file, bool loopSound); |
| 51 |
|
| 52 |
/** greebo: Stops the playback immediately. |
| 53 |
*/ |
| 54 |
virtual void stop(); |
| 55 |
|
| 56 |
protected: |
| 57 |
// Initialises the AL context |
| 58 |
void initialise(); |
| 59 |
|
| 60 |
// Clears the buffer, stops playing |
| 61 |
void clearBuffer(); |
| 62 |
|
| 63 |
// This is called periodically to check whether the buffer can be cleared |
| 64 |
void onTimerIntervalReached(wxTimerEvent& ev); |
| 65 |
|
| 66 |
void createBufferDataFromOgg(ArchiveFile& file); |
| 67 |
void createBufferDataFromWav(ArchiveFile& file); |
| 68 |
}; |
| 69 |
|
| 70 |
} // namespace sound |