Some fixes.

This commit is contained in:
Themaister 2010-08-25 22:53:52 +02:00
parent cb6ea2a26f
commit 83fb1390fa

View File

@ -73,6 +73,9 @@ static void* __al_init(const char* device, int rate, int latency)
alGenSources(1, &al->source); alGenSources(1, &al->source);
alGenBuffers(al->num_buffers, al->buffers); alGenBuffers(al->num_buffers, al->buffers);
memcpy(al->res_buf, al->buffers, al->num_buffers * sizeof(ALuint));
al->res_ptr = al->num_buffers;
return al; return al;
error: error:
@ -160,45 +163,23 @@ static ssize_t __al_write(void* data, const void* buf, size_t size)
if (al->tmpbuf_ptr != BUFSIZE) if (al->tmpbuf_ptr != BUFSIZE)
break; break;
if (al->queue < al->num_buffers) ALuint buffer;
{ if (!al_get_buffer(al, &buffer))
alBufferData(al->buffers[al->queue++], AL_FORMAT_STEREO16, al->tmpbuf, BUFSIZE, al->rate); return 0;
al->tmpbuf_ptr = 0;
if ( alGetError() != AL_NO_ERROR )
{
return -1;
}
if ( al->queue == al->num_buffers ) alBufferData(buffer, AL_FORMAT_STEREO16, al->tmpbuf, BUFSIZE, al->rate);
{ al->tmpbuf_ptr = 0;
alSourceQueueBuffers(al->source, al->num_buffers, al->buffers); alSourceQueueBuffers(al->source, 1, &buffer);
alSourcePlay(al->source); if (alGetError() != AL_NO_ERROR)
if ( alGetError() != AL_NO_ERROR ) return -1;
{
return -1;
}
}
}
else
{
ALuint buffer;
if (!al_get_buffer(al, &buffer))
return 0;
alBufferData(buffer, AL_FORMAT_STEREO16, al->tmpbuf, BUFSIZE, al->rate); ALint val;
al->tmpbuf_ptr = 0; alGetSourcei(al->source, AL_SOURCE_STATE, &val);
alSourceQueueBuffers(al->source, 1, &buffer); if (val != AL_PLAYING)
if (alGetError() != AL_NO_ERROR) alSourcePlay(al->source);
return -1;
ALint val; if (alGetError() != AL_NO_ERROR)
alGetSourcei(al->source, AL_SOURCE_STATE, &val); return -1;
if (val != AL_PLAYING)
alSourcePlay(al->source);
if (alGetError() != AL_NO_ERROR)
return -1;
}
} }
return size; return size;