mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-27 15:11:36 -04:00
Move OpenAL_SoundStream function definitions out of the class
This commit is contained in:
parent
2f6b73d461
commit
1b41987e18
@ -63,125 +63,133 @@ class OpenAL_SoundStream : public Sound
|
|||||||
std::auto_ptr<Sound_Decoder> Decoder;
|
std::auto_ptr<Sound_Decoder> Decoder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenAL_SoundStream(std::auto_ptr<Sound_Decoder> decoder) : Decoder(decoder)
|
OpenAL_SoundStream(std::auto_ptr<Sound_Decoder> decoder);
|
||||||
|
virtual ~OpenAL_SoundStream();
|
||||||
|
|
||||||
|
virtual bool Play();
|
||||||
|
virtual void Stop();
|
||||||
|
virtual bool isPlaying();
|
||||||
|
};
|
||||||
|
|
||||||
|
OpenAL_SoundStream::OpenAL_SoundStream(std::auto_ptr<Sound_Decoder> decoder)
|
||||||
|
: Decoder(decoder)
|
||||||
|
{
|
||||||
|
throwALerror();
|
||||||
|
|
||||||
|
alGenSources(1, &Source);
|
||||||
|
throwALerror();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
alGenBuffers(NumBuffers, Buffers);
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
|
||||||
alGenSources(1, &Source);
|
|
||||||
throwALerror();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
alGenBuffers(NumBuffers, Buffers);
|
|
||||||
throwALerror();
|
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
alDeleteSources(1, &Source);
|
|
||||||
alGetError();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int srate;
|
|
||||||
enum Sound_Decoder::ChannelConfig chans;
|
|
||||||
enum Sound_Decoder::SampleType type;
|
|
||||||
|
|
||||||
Decoder->GetInfo(&srate, &chans, &type);
|
|
||||||
Format = getALFormat(chans, type);
|
|
||||||
SampleRate = srate;
|
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
alDeleteSources(1, &Source);
|
|
||||||
alDeleteBuffers(NumBuffers, Buffers);
|
|
||||||
alGetError();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
virtual ~OpenAL_SoundStream()
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
alDeleteSources(1, &Source);
|
||||||
|
alGetError();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int srate;
|
||||||
|
Sound_Decoder::ChannelConfig chans;
|
||||||
|
Sound_Decoder::SampleType type;
|
||||||
|
|
||||||
|
Decoder->GetInfo(&srate, &chans, &type);
|
||||||
|
Format = getALFormat(chans, type);
|
||||||
|
SampleRate = srate;
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
alDeleteSources(1, &Source);
|
alDeleteSources(1, &Source);
|
||||||
alDeleteBuffers(NumBuffers, Buffers);
|
alDeleteBuffers(NumBuffers, Buffers);
|
||||||
alGetError();
|
alGetError();
|
||||||
Decoder->Close();
|
throw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
OpenAL_SoundStream::~OpenAL_SoundStream()
|
||||||
|
{
|
||||||
|
alDeleteSources(1, &Source);
|
||||||
|
alDeleteBuffers(NumBuffers, Buffers);
|
||||||
|
alGetError();
|
||||||
|
Decoder->Close();
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Play()
|
bool OpenAL_SoundStream::Play()
|
||||||
|
{
|
||||||
|
std::vector<char> data(BufferSize);
|
||||||
|
|
||||||
|
alSourceStop(Source);
|
||||||
|
alSourcei(Source, AL_BUFFER, 0);
|
||||||
|
throwALerror();
|
||||||
|
|
||||||
|
for(ALuint i = 0;i < NumBuffers;i++)
|
||||||
|
{
|
||||||
|
size_t got;
|
||||||
|
got = Decoder->Read(&data[0], data.size());
|
||||||
|
alBufferData(Buffers[i], Format, &data[0], got, SampleRate);
|
||||||
|
}
|
||||||
|
throwALerror();
|
||||||
|
|
||||||
|
alSourceQueueBuffers(Source, NumBuffers, Buffers);
|
||||||
|
alSourcePlay(Source);
|
||||||
|
throwALerror();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenAL_SoundStream::Stop()
|
||||||
|
{
|
||||||
|
alSourceStop(Source);
|
||||||
|
alSourcei(Source, AL_BUFFER, 0);
|
||||||
|
throwALerror();
|
||||||
|
// FIXME: Rewind decoder
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenAL_SoundStream::isPlaying()
|
||||||
|
{
|
||||||
|
ALint processed, state;
|
||||||
|
|
||||||
|
alGetSourcei(Source, AL_SOURCE_STATE, &state);
|
||||||
|
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
|
||||||
|
throwALerror();
|
||||||
|
|
||||||
|
if(processed > 0)
|
||||||
{
|
{
|
||||||
std::vector<char> data(BufferSize);
|
std::vector<char> data(BufferSize);
|
||||||
|
do {
|
||||||
alSourceStop(Source);
|
ALuint bufid;
|
||||||
alSourcei(Source, AL_BUFFER, 0);
|
|
||||||
throwALerror();
|
|
||||||
|
|
||||||
for(ALuint i = 0;i < NumBuffers;i++)
|
|
||||||
{
|
|
||||||
size_t got;
|
size_t got;
|
||||||
got = Decoder->Read(&data[0], data.size());
|
|
||||||
alBufferData(Buffers[i], Format, &data[0], got, SampleRate);
|
|
||||||
}
|
|
||||||
throwALerror();
|
|
||||||
|
|
||||||
alSourceQueueBuffers(Source, NumBuffers, Buffers);
|
alSourceUnqueueBuffers(Source, 1, &bufid);
|
||||||
|
processed--;
|
||||||
|
|
||||||
|
got = Decoder->Read(&data[0], data.size());
|
||||||
|
if(got > 0)
|
||||||
|
{
|
||||||
|
alBufferData(bufid, Format, &data[0], got, SampleRate);
|
||||||
|
alSourceQueueBuffers(Source, 1, &bufid);
|
||||||
|
}
|
||||||
|
} while(processed > 0);
|
||||||
|
throwALerror();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(state != AL_PLAYING && state != AL_PAUSED)
|
||||||
|
{
|
||||||
|
ALint queued;
|
||||||
|
|
||||||
|
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
|
||||||
|
throwALerror();
|
||||||
|
if(queued == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
alSourcePlay(Source);
|
alSourcePlay(Source);
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Stop()
|
return true;
|
||||||
{
|
}
|
||||||
alSourceStop(Source);
|
|
||||||
alSourcei(Source, AL_BUFFER, 0);
|
|
||||||
throwALerror();
|
|
||||||
// FIXME: Rewind decoder
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool isPlaying()
|
|
||||||
{
|
|
||||||
ALint processed, state;
|
|
||||||
|
|
||||||
alGetSourcei(Source, AL_SOURCE_STATE, &state);
|
|
||||||
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
|
|
||||||
throwALerror();
|
|
||||||
|
|
||||||
if(processed > 0)
|
|
||||||
{
|
|
||||||
std::vector<char> data(BufferSize);
|
|
||||||
do {
|
|
||||||
ALuint bufid;
|
|
||||||
size_t got;
|
|
||||||
|
|
||||||
alSourceUnqueueBuffers(Source, 1, &bufid);
|
|
||||||
processed--;
|
|
||||||
|
|
||||||
got = Decoder->Read(&data[0], data.size());
|
|
||||||
if(got > 0)
|
|
||||||
{
|
|
||||||
alBufferData(bufid, Format, &data[0], got, SampleRate);
|
|
||||||
alSourceQueueBuffers(Source, 1, &bufid);
|
|
||||||
}
|
|
||||||
} while(processed > 0);
|
|
||||||
throwALerror();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state != AL_PLAYING && state != AL_PAUSED)
|
|
||||||
{
|
|
||||||
ALint queued;
|
|
||||||
|
|
||||||
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
|
|
||||||
throwALerror();
|
|
||||||
if(queued == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
alSourcePlay(Source);
|
|
||||||
throwALerror();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
bool OpenAL_Output::Initialize(const std::string &devname)
|
bool OpenAL_Output::Initialize(const std::string &devname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user