Fix audio leaks in ALSA code and other issues in PA and SDL audio code.

This commit is contained in:
gameblabla 2020-01-02 13:52:18 +01:00
parent 5554715689
commit 66a625e5be
No known key found for this signature in database
GPG Key ID: B24EFBB23B5F76CB
3 changed files with 4 additions and 25 deletions

View File

@ -128,10 +128,7 @@ void Sound_Init(void)
void Sound_Update(void)
{
uint32_t i;
uint32_t len = SOUND_FREQUENCY / snd.fps;
long ret;
if (!handle) return;
long len = (SOUND_FREQUENCY / snd.fps), ret;
for (i = 0; i < (4 * len); i++)
{
@ -150,26 +147,10 @@ void Sound_Update(void)
void Sound_Close(void)
{
uint32_t i;
uint32_t len = SOUND_FREQUENCY / snd.fps;
long ret;
if (handle)
{
/* Write Silence to Audio device */
for (i = 0; i < (4 * len); i++)
{
buffer_snd[i * 2] = buffer_snd[i * 2 + 1] = 0;
}
ret = snd_pcm_writei(handle, buffer_snd, len);
while(ret != len)
{
if (ret < 0) snd_pcm_prepare( handle );
else len -= ret;
ret = snd_pcm_writei(handle, buffer_snd, len);
}
snd_pcm_drain(handle);
snd_pcm_drop(handle);
snd_pcm_close(handle);
snd_config_update_free_global();
}
}

View File

@ -15,8 +15,6 @@
PaStream *apu_stream;
static int16_t buffer_snd[SOUND_FREQUENCY * 2];
#define NONBLOCKING_AUDIO
#ifdef NONBLOCKING_AUDIO
static int patestCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,

View File

@ -145,7 +145,7 @@ void Sound_Update()
}
SDL_LockAudio();
sdl_write_buffer(buffer_snd, (SOUND_FREQUENCY / snd.fps));
sdl_write_buffer((int16_t*)buffer_snd, (SOUND_FREQUENCY / snd.fps));
SDL_UnlockAudio();
}