Initialize more stuff in OpenALPlayer's constructor (CID #1111296)

This commit is contained in:
Thomas Goyne 2013-10-23 14:27:38 -07:00
parent 0e2cc0938f
commit 09a3174cb8
1 changed files with 7 additions and 6 deletions

View File

@ -54,15 +54,19 @@ OpenALPlayer::OpenALPlayer(AudioProvider *provider)
: AudioPlayer(provider) : AudioPlayer(provider)
, playing(false) , playing(false)
, volume(1.f) , volume(1.f)
, samplerate(0) , samplerate(provider->GetSampleRate())
, bpf(0) , bpf(provider->GetChannels() * provider->GetBytesPerSample())
, start_frame(0) , start_frame(0)
, cur_frame(0) , cur_frame(0)
, end_frame(0) , end_frame(0)
, device(0) , device(0)
, context(0) , context(0)
, source(0)
, buf_first_free(0)
, buf_first_queued(0)
, buffers_free(0)
, buffers_played(0)
{ {
bpf = provider->GetChannels() * provider->GetBytesPerSample();
try { try {
// Open device // Open device
device = alcOpenDevice(0); device = alcOpenDevice(0);
@ -91,13 +95,10 @@ OpenALPlayer::OpenALPlayer(AudioProvider *provider)
{ {
alcDestroyContext(context); alcDestroyContext(context);
alcCloseDevice(device); alcCloseDevice(device);
context = 0;
device = 0;
throw; throw;
} }
// Determine buffer length // Determine buffer length
samplerate = provider->GetSampleRate();
decode_buffer.resize(samplerate * bpf / num_buffers / 2); // buffers for half a second of audio decode_buffer.resize(samplerate * bpf / num_buffers / 2); // buffers for half a second of audio
} }