mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-01-10 21:25:35 +00:00
haikuaudio: Untested attempt to get this working with SDL_AudioStream.
This commit is contained in:
parent
1a90c72dfc
commit
115d0ce71c
|
@ -36,6 +36,7 @@ extern "C"
|
||||||
#include "../SDL_audio_c.h"
|
#include "../SDL_audio_c.h"
|
||||||
#include "../SDL_sysaudio.h"
|
#include "../SDL_sysaudio.h"
|
||||||
#include "SDL_haikuaudio.h"
|
#include "SDL_haikuaudio.h"
|
||||||
|
#include "SDL_assert.h"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,26 +48,39 @@ FillSound(void *device, void *stream, size_t len,
|
||||||
const media_raw_audio_format & format)
|
const media_raw_audio_format & format)
|
||||||
{
|
{
|
||||||
SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
|
SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
|
||||||
|
SDL_AudioCallback callback = audio->spec.callback;
|
||||||
|
|
||||||
/* Only do soemthing if audio is enabled */
|
/* Only do something if audio is enabled */
|
||||||
if (!SDL_AtomicGet(&audio->enabled)) {
|
if (!SDL_AtomicGet(&audio->enabled) || SDL_AtomicGet(&audio->paused)) {
|
||||||
|
if (audio->stream) {
|
||||||
|
SDL_AudioStreamClear(audio->stream);
|
||||||
|
}
|
||||||
|
SDL_memset(stream, audio->spec.silence, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SDL_AtomicGet(&audio->paused)) {
|
SDL_assert(audio->spec.size == len);
|
||||||
if (audio->convert.needed) {
|
|
||||||
SDL_LockMutex(audio->mixer_lock);
|
if (audio->stream == NULL) { /* no conversion necessary. */
|
||||||
(*audio->spec.callback) (audio->spec.userdata,
|
SDL_LockMutex(audio->mixer_lock);
|
||||||
(Uint8 *) audio->convert.buf,
|
callback(audio->spec.userdata, stream, len);
|
||||||
audio->convert.len);
|
SDL_UnlockMutex(audio->mixer_lock);
|
||||||
SDL_UnlockMutex(audio->mixer_lock);
|
} else { /* streaming/converting */
|
||||||
SDL_ConvertAudio(&audio->convert);
|
const int stream_len = audio->callbackspec.size;
|
||||||
SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
|
const int ilen = (int) len;
|
||||||
} else {
|
while (SDL_AudioStreamAvailable(audio->stream) < ilen) {
|
||||||
SDL_LockMutex(audio->mixer_lock);
|
callback(audio->spec.userdata, audio->fake_stream, stream_len);
|
||||||
(*audio->spec.callback) (audio->spec.userdata,
|
if (SDL_AudioStreamPut(audio->stream, audio->fake_stream, stream_len) == -1) {
|
||||||
(Uint8 *) stream, len);
|
SDL_AudioStreamClear(audio->stream);
|
||||||
SDL_UnlockMutex(audio->mixer_lock);
|
SDL_AtomicSet(&audio->enabled, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const int got = SDL_AudioStreamGet(audio->stream, ilen, stream, ilen);
|
||||||
|
SDL_assert((got < 0) || (got == ilen));
|
||||||
|
if (got != ilen) {
|
||||||
|
SDL_memset(stream, audio->spec.silence, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue