#ifndef SOUND_SDL_HXX
#define SOUND_SDL_HXX
#ifdef SOUND_SUPPORT
class OSystem;
#include "SDL.h"
#include "../emucore/Sound.hxx"
#include "../emucore/m6502/src/bspf/src/bspf.hxx"
#include "MediaSrc.hxx"
#include "TIASnd.hxx"
#include "SoundExporter.hpp"
#include <memory>
class SoundSDL : public Sound
{
public:
SoundSDL(OSystem* osystem);
virtual ~SoundSDL();
public:
void setEnabled(bool state);
void adjustCycleCounter(Int32 amount);
void setChannels(uInt32 channels);
void setFrameRate(uInt32 framerate);
void initialize();
void close();
bool isSuccessfullyInitialized() const;
void mute(bool state);
void reset();
void set(uInt16 addr, uInt8 value, Int32 cycle);
void setVolume(Int32 percent);
void adjustVolume(Int8 direction);
void recordNextFrame();
public:
bool load(Deserializer& in);
bool save(Serializer& out);
protected:
void processFragment(uInt8* stream, Int32 length);
protected:
struct RegWrite
{
uInt16 addr;
uInt8 value;
double delta;
};
class RegWriteQueue
{
public:
RegWriteQueue(uInt32 capacity = 512);
virtual ~RegWriteQueue();
public:
void clear();
void dequeue();
double duration();
void enqueue(const RegWrite& info);
RegWrite& front();
uInt32 size() const;
private:
void grow();
private:
uInt32 myCapacity;
RegWrite* myBuffer;
uInt32 mySize;
uInt32 myHead;
uInt32 myTail;
};
private:
TIASound myTIASound;
bool myIsEnabled;
bool myIsInitializedFlag;
Int32 myLastRegisterSetCycle;
uInt32 myDisplayFrameRate;
uInt32 myNumChannels;
double myFragmentSizeLogBase2;
bool myIsMuted;
uInt32 myVolume;
SDL_AudioSpec myHardwareSpec;
RegWriteQueue myRegWriteQueue;
private:
static void callback(void* udata, uInt8* stream, int len);
int myNumRecordSamplesNeeded;
std::auto_ptr<ale::sound::SoundExporter> mySoundExporter;
};
#endif #endif