Rename some more sound class member variables and functions

This commit is contained in:
Chris Robinson 2012-03-18 11:30:53 -07:00
parent 162642e672
commit 362e254720
4 changed files with 102 additions and 102 deletions

View file

@ -78,16 +78,16 @@ class OpenAL_SoundStream : public Sound
{ {
// This should be something sane, like 4, but currently cell loads tend to // This should be something sane, like 4, but currently cell loads tend to
// cause the stream to underrun // cause the stream to underrun
static const ALuint NumBuffers = 150; static const ALuint sNumBuffers = 150;
static const ALuint BufferSize = 32768; static const ALuint sBufferSize = 32768;
ALuint Source; ALuint mSource;
ALuint Buffers[NumBuffers]; ALuint mBuffers[sNumBuffers];
ALenum Format; ALenum mFormat;
ALsizei SampleRate; ALsizei mSampleRate;
DecoderPtr Decoder; DecoderPtr mDecoder;
public: public:
OpenAL_SoundStream(DecoderPtr decoder); OpenAL_SoundStream(DecoderPtr decoder);
@ -102,8 +102,8 @@ public:
class OpenAL_Sound : public Sound class OpenAL_Sound : public Sound
{ {
public: public:
ALuint Source; ALuint mSource;
ALuint Buffer; ALuint mBuffer;
OpenAL_Sound(ALuint src, ALuint buf); OpenAL_Sound(ALuint src, ALuint buf);
virtual ~OpenAL_Sound(); virtual ~OpenAL_Sound();
@ -115,20 +115,20 @@ public:
OpenAL_SoundStream::OpenAL_SoundStream(DecoderPtr decoder) OpenAL_SoundStream::OpenAL_SoundStream(DecoderPtr decoder)
: Decoder(decoder) : mDecoder(decoder)
{ {
throwALerror(); throwALerror();
alGenSources(1, &Source); alGenSources(1, &mSource);
throwALerror(); throwALerror();
try try
{ {
alGenBuffers(NumBuffers, Buffers); alGenBuffers(sNumBuffers, mBuffers);
throwALerror(); throwALerror();
} }
catch(std::exception &e) catch(std::exception &e)
{ {
alDeleteSources(1, &Source); alDeleteSources(1, &mSource);
alGetError(); alGetError();
throw; throw;
} }
@ -139,53 +139,53 @@ OpenAL_SoundStream::OpenAL_SoundStream(DecoderPtr decoder)
Sound_Decoder::ChannelConfig chans; Sound_Decoder::ChannelConfig chans;
Sound_Decoder::SampleType type; Sound_Decoder::SampleType type;
Decoder->GetInfo(&srate, &chans, &type); mDecoder->GetInfo(&srate, &chans, &type);
Format = getALFormat(chans, type); mFormat = getALFormat(chans, type);
SampleRate = srate; mSampleRate = srate;
} }
catch(std::exception &e) catch(std::exception &e)
{ {
alDeleteSources(1, &Source); alDeleteSources(1, &mSource);
alDeleteBuffers(NumBuffers, Buffers); alDeleteBuffers(sNumBuffers, mBuffers);
alGetError(); alGetError();
throw; throw;
} }
} }
OpenAL_SoundStream::~OpenAL_SoundStream() OpenAL_SoundStream::~OpenAL_SoundStream()
{ {
alDeleteSources(1, &Source); alDeleteSources(1, &mSource);
alDeleteBuffers(NumBuffers, Buffers); alDeleteBuffers(sNumBuffers, mBuffers);
alGetError(); alGetError();
Decoder->Close(); mDecoder->Close();
} }
void OpenAL_SoundStream::Play(float volume, float pitch) void OpenAL_SoundStream::Play(float volume, float pitch)
{ {
std::vector<char> data(BufferSize); std::vector<char> data(sBufferSize);
alSourceStop(Source); alSourceStop(mSource);
alSourcei(Source, AL_BUFFER, 0); alSourcei(mSource, AL_BUFFER, 0);
alSourcef(Source, AL_GAIN, volume); alSourcef(mSource, AL_GAIN, volume);
alSourcef(Source, AL_PITCH, pitch); alSourcef(mSource, AL_PITCH, pitch);
throwALerror(); throwALerror();
for(ALuint i = 0;i < NumBuffers;i++) for(ALuint i = 0;i < sNumBuffers;i++)
{ {
size_t got; size_t got;
got = Decoder->Read(&data[0], data.size()); got = mDecoder->Read(&data[0], data.size());
alBufferData(Buffers[i], Format, &data[0], got, SampleRate); alBufferData(mBuffers[i], mFormat, &data[0], got, mSampleRate);
} }
throwALerror(); throwALerror();
alSourceQueueBuffers(Source, NumBuffers, Buffers); alSourceQueueBuffers(mSource, sNumBuffers, mBuffers);
alSourcePlay(Source); alSourcePlay(mSource);
throwALerror(); throwALerror();
} }
void OpenAL_SoundStream::Stop() void OpenAL_SoundStream::Stop()
{ {
alSourceStop(Source); alSourceStop(mSource);
alSourcei(Source, AL_BUFFER, 0); alSourcei(mSource, AL_BUFFER, 0);
throwALerror(); throwALerror();
// FIXME: Rewind decoder // FIXME: Rewind decoder
} }
@ -194,25 +194,25 @@ bool OpenAL_SoundStream::isPlaying()
{ {
ALint processed, state; ALint processed, state;
alGetSourcei(Source, AL_SOURCE_STATE, &state); alGetSourcei(mSource, AL_SOURCE_STATE, &state);
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed); alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
throwALerror(); throwALerror();
if(processed > 0) if(processed > 0)
{ {
std::vector<char> data(BufferSize); std::vector<char> data(sBufferSize);
do { do {
ALuint bufid; ALuint bufid;
size_t got; size_t got;
alSourceUnqueueBuffers(Source, 1, &bufid); alSourceUnqueueBuffers(mSource, 1, &bufid);
processed--; processed--;
got = Decoder->Read(&data[0], data.size()); got = mDecoder->Read(&data[0], data.size());
if(got > 0) if(got > 0)
{ {
alBufferData(bufid, Format, &data[0], got, SampleRate); alBufferData(bufid, mFormat, &data[0], got, mSampleRate);
alSourceQueueBuffers(Source, 1, &bufid); alSourceQueueBuffers(mSource, 1, &bufid);
} }
} while(processed > 0); } while(processed > 0);
throwALerror(); throwALerror();
@ -222,12 +222,12 @@ bool OpenAL_SoundStream::isPlaying()
{ {
ALint queued; ALint queued;
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued); alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
throwALerror(); throwALerror();
if(queued == 0) if(queued == 0)
return false; return false;
alSourcePlay(Source); alSourcePlay(mSource);
throwALerror(); throwALerror();
} }
@ -236,27 +236,27 @@ bool OpenAL_SoundStream::isPlaying()
void OpenAL_SoundStream::Update(const float *pos) void OpenAL_SoundStream::Update(const float *pos)
{ {
alSource3f(Source, AL_POSITION, pos[0], pos[2], -pos[1]); alSource3f(mSource, AL_POSITION, pos[0], pos[2], -pos[1]);
alSource3f(Source, AL_DIRECTION, 0.0f, 0.0f, 0.0f); alSource3f(mSource, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSource3f(Source, AL_VELOCITY, 0.0f, 0.0f, 0.0f); alSource3f(mSource, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
throwALerror(); throwALerror();
} }
OpenAL_Sound::OpenAL_Sound(ALuint src, ALuint buf) OpenAL_Sound::OpenAL_Sound(ALuint src, ALuint buf)
: Source(src), Buffer(buf) : mSource(src), mBuffer(buf)
{ {
} }
OpenAL_Sound::~OpenAL_Sound() OpenAL_Sound::~OpenAL_Sound()
{ {
alDeleteSources(1, &Source); alDeleteSources(1, &mSource);
alDeleteBuffers(1, &Buffer); alDeleteBuffers(1, &mBuffer);
alGetError(); alGetError();
} }
void OpenAL_Sound::Stop() void OpenAL_Sound::Stop()
{ {
alSourceStop(Source); alSourceStop(mSource);
throwALerror(); throwALerror();
} }
@ -264,7 +264,7 @@ bool OpenAL_Sound::isPlaying()
{ {
ALint state; ALint state;
alGetSourcei(Source, AL_SOURCE_STATE, &state); alGetSourcei(mSource, AL_SOURCE_STATE, &state);
throwALerror(); throwALerror();
return state==AL_PLAYING; return state==AL_PLAYING;
@ -272,35 +272,35 @@ bool OpenAL_Sound::isPlaying()
void OpenAL_Sound::Update(const float *pos) void OpenAL_Sound::Update(const float *pos)
{ {
alSource3f(Source, AL_POSITION, pos[0], pos[2], -pos[1]); alSource3f(mSource, AL_POSITION, pos[0], pos[2], -pos[1]);
alSource3f(Source, AL_DIRECTION, 0.0f, 0.0f, 0.0f); alSource3f(mSource, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSource3f(Source, AL_VELOCITY, 0.0f, 0.0f, 0.0f); alSource3f(mSource, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
throwALerror(); throwALerror();
} }
bool OpenAL_Output::Initialize(const std::string &devname) bool OpenAL_Output::init(const std::string &devname)
{ {
if(Context) if(mContext)
fail("Device already initialized"); fail("Device already initialized");
Device = alcOpenDevice(devname.c_str()); mDevice = alcOpenDevice(devname.c_str());
if(!Device) if(!mDevice)
{ {
std::cout << "Failed to open \""<<devname<<"\"" << std::endl; std::cout << "Failed to open \""<<devname<<"\"" << std::endl;
return false; return false;
} }
std::cout << "Opened \""<<alcGetString(Device, ALC_DEVICE_SPECIFIER)<<"\"" << std::endl; std::cout << "Opened \""<<alcGetString(mDevice, ALC_DEVICE_SPECIFIER)<<"\"" << std::endl;
Context = alcCreateContext(Device, NULL); mContext = alcCreateContext(mDevice, NULL);
if(!Context || alcMakeContextCurrent(Context) == ALC_FALSE) if(!mContext || alcMakeContextCurrent(mContext) == ALC_FALSE)
{ {
std::cout << "Failed to setup device context" << std::endl; std::cout << "Failed to setup device context" << std::endl;
if(Context) if(mContext)
alcDestroyContext(Context); alcDestroyContext(mContext);
Context = 0; mContext = 0;
alcCloseDevice(Device); alcCloseDevice(mDevice);
Device = 0; mDevice = 0;
return false; return false;
} }
alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
@ -309,23 +309,23 @@ bool OpenAL_Output::Initialize(const std::string &devname)
return true; return true;
} }
void OpenAL_Output::Deinitialize() void OpenAL_Output::deinit()
{ {
alcMakeContextCurrent(0); alcMakeContextCurrent(0);
if(Context) if(mContext)
alcDestroyContext(Context); alcDestroyContext(mContext);
Context = 0; mContext = 0;
if(Device) if(mDevice)
alcCloseDevice(Device); alcCloseDevice(mDevice);
Device = 0; mDevice = 0;
} }
Sound* OpenAL_Output::PlaySound(const std::string &fname, float volume, float pitch, bool loop) Sound* OpenAL_Output::playSound(const std::string &fname, float volume, float pitch, bool loop)
{ {
throwALerror(); throwALerror();
DecoderPtr decoder = mgr.getDecoder(); DecoderPtr decoder = mManager.getDecoder();
decoder->Open(fname); decoder->Open(fname);
ALuint src=0, buf=0; ALuint src=0, buf=0;
@ -368,12 +368,12 @@ Sound* OpenAL_Output::PlaySound(const std::string &fname, float volume, float pi
return sound.release(); return sound.release();
} }
Sound* OpenAL_Output::PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch, Sound* OpenAL_Output::playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop) float min, float max, bool loop)
{ {
throwALerror(); throwALerror();
DecoderPtr decoder = mgr.getDecoder(); DecoderPtr decoder = mManager.getDecoder();
decoder->Open(fname); decoder->Open(fname);
ALuint src=0, buf=0; ALuint src=0, buf=0;
@ -417,11 +417,11 @@ Sound* OpenAL_Output::PlaySound3D(const std::string &fname, const float *pos, fl
} }
Sound* OpenAL_Output::StreamSound(const std::string &fname, float volume, float pitch) Sound* OpenAL_Output::streamSound(const std::string &fname, float volume, float pitch)
{ {
std::auto_ptr<OpenAL_SoundStream> sound; std::auto_ptr<OpenAL_SoundStream> sound;
DecoderPtr decoder = mgr.getDecoder(); DecoderPtr decoder = mManager.getDecoder();
decoder->Open(fname); decoder->Open(fname);
sound.reset(new OpenAL_SoundStream(decoder)); sound.reset(new OpenAL_SoundStream(decoder));
@ -431,7 +431,7 @@ Sound* OpenAL_Output::StreamSound(const std::string &fname, float volume, float
} }
void OpenAL_Output::UpdateListener(const float *pos, const float *atdir, const float *updir) void OpenAL_Output::updateListener(const float *pos, const float *atdir, const float *updir)
{ {
float orient[6] = { float orient[6] = {
atdir[0], atdir[2], -atdir[1], atdir[0], atdir[2], -atdir[1],
@ -445,13 +445,13 @@ void OpenAL_Output::UpdateListener(const float *pos, const float *atdir, const f
OpenAL_Output::OpenAL_Output(SoundManager &mgr) OpenAL_Output::OpenAL_Output(SoundManager &mgr)
: Sound_Output(mgr), Device(0), Context(0) : Sound_Output(mgr), mDevice(0), mContext(0)
{ {
} }
OpenAL_Output::~OpenAL_Output() OpenAL_Output::~OpenAL_Output()
{ {
Deinitialize(); deinit();
} }
} }

View file

@ -16,19 +16,19 @@ namespace MWSound
class OpenAL_Output : public Sound_Output class OpenAL_Output : public Sound_Output
{ {
ALCdevice *Device; ALCdevice *mDevice;
ALCcontext *Context; ALCcontext *mContext;
virtual bool Initialize(const std::string &devname=""); virtual bool init(const std::string &devname="");
virtual void Deinitialize(); virtual void deinit();
virtual Sound *PlaySound(const std::string &fname, float volume, float pitch, bool loop); virtual Sound *playSound(const std::string &fname, float volume, float pitch, bool loop);
virtual Sound *PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch, virtual Sound *playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop); float min, float max, bool loop);
virtual Sound *StreamSound(const std::string &fname, float volume, float pitch); virtual Sound *streamSound(const std::string &fname, float volume, float pitch);
virtual void UpdateListener(const float *pos, const float *atdir, const float *updir); virtual void updateListener(const float *pos, const float *atdir, const float *updir);
OpenAL_Output(SoundManager &mgr); OpenAL_Output(SoundManager &mgr);
virtual ~OpenAL_Output(); virtual ~OpenAL_Output();

View file

@ -14,19 +14,19 @@ namespace MWSound
class Sound_Output class Sound_Output
{ {
SoundManager &mgr; SoundManager &mManager;
virtual bool Initialize(const std::string &devname="") = 0; virtual bool init(const std::string &devname="") = 0;
virtual void Deinitialize() = 0; virtual void deinit() = 0;
virtual Sound *PlaySound(const std::string &fname, float volume, float pitch, bool loop) = 0; virtual Sound *playSound(const std::string &fname, float volume, float pitch, bool loop) = 0;
virtual Sound *PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch, virtual Sound *playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop) = 0; float min, float max, bool loop) = 0;
virtual Sound *StreamSound(const std::string &fname, float volume, float pitch) = 0; virtual Sound *streamSound(const std::string &fname, float volume, float pitch) = 0;
virtual void UpdateListener(const float *pos, const float *atdir, const float *updir) = 0; virtual void updateListener(const float *pos, const float *atdir, const float *updir) = 0;
Sound_Output(SoundManager &mgr) : mgr(mgr) { } Sound_Output(SoundManager &mgr) : mManager(mgr) { }
public: public:
virtual ~Sound_Output() { } virtual ~Sound_Output() { }

View file

@ -48,7 +48,7 @@ namespace MWSound
std::cout << "Sound decoder: " << SOUND_IN << std::endl; std::cout << "Sound decoder: " << SOUND_IN << std::endl;
mOutput.reset(new DEFAULT_OUTPUT(*this)); mOutput.reset(new DEFAULT_OUTPUT(*this));
if(!mOutput->Initialize()) if(!mOutput->init())
{ {
mOutput.reset(); mOutput.reset();
return; return;
@ -130,7 +130,7 @@ namespace MWSound
{ {
Sound *sound; Sound *sound;
const ESM::Position &pos = ptr.getCellRef().pos; const ESM::Position &pos = ptr.getCellRef().pos;
sound = mOutput->PlaySound3D(file, pos.pos, volume, pitch, min, max, loop); sound = mOutput->playSound3D(file, pos.pos, volume, pitch, min, max, loop);
if(untracked) if(untracked)
mLooseSounds[id] = SoundPtr(sound); mLooseSounds[id] = SoundPtr(sound);
else else
@ -167,7 +167,7 @@ namespace MWSound
{ {
if(mMusic) if(mMusic)
mMusic->Stop(); mMusic->Stop();
mMusic.reset(mOutput->StreamSound(filename, 0.4f, 1.0f)); mMusic.reset(mOutput->streamSound(filename, 0.4f, 1.0f));
} }
void SoundManager::streamMusic(const std::string& filename) void SoundManager::streamMusic(const std::string& filename)
@ -277,7 +277,7 @@ namespace MWSound
try try
{ {
Sound *sound; Sound *sound;
sound = mOutput->PlaySound(file, volume, pitch, loop); sound = mOutput->playSound(file, volume, pitch, loop);
mLooseSounds[soundId] = SoundPtr(sound); mLooseSounds[soundId] = SoundPtr(sound);
} }
catch(std::exception &e) catch(std::exception &e)
@ -443,7 +443,7 @@ namespace MWSound
float pos[3] = { nPos[0], -nPos[2], nPos[1] }; float pos[3] = { nPos[0], -nPos[2], nPos[1] };
float at[3] = { nDir[0], -nDir[2], nDir[1] }; float at[3] = { nDir[0], -nDir[2], nDir[1] };
float up[3] = { nUp[0], -nUp[2], nUp[1] }; float up[3] = { nUp[0], -nUp[2], nUp[1] };
mOutput->UpdateListener(pos, at, up); mOutput->updateListener(pos, at, up);
// Check if any "untracked" sounds are finished playing, and trash // Check if any "untracked" sounds are finished playing, and trash
// them // them