mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-25 09:17:12 +01:00
audio: rename fake_stream to work_buffer.
It's more than an alternative for when the OS can't provide a DMA buffer, now.
This commit is contained in:
parent
992124d4de
commit
b3e8db802e
src/audio
@ -568,16 +568,16 @@ SDL_RunAudio(void *devicep)
|
||||
stream = current_audio.impl.GetDeviceBuf(device);
|
||||
} else {
|
||||
/* if the device isn't enabled, we still write to the
|
||||
fake_stream, so the app's callback will fire with
|
||||
work_buffer, so the app's callback will fire with
|
||||
a regular frequency, in case they depend on that
|
||||
for timing or progress. They can use hotplug
|
||||
now to know if the device failed.
|
||||
Streaming playback uses fake_stream as a work buffer, too. */
|
||||
Streaming playback uses work_buffer, too. */
|
||||
stream = NULL;
|
||||
}
|
||||
|
||||
if (stream == NULL) {
|
||||
stream = device->fake_stream;
|
||||
stream = device->work_buffer;
|
||||
}
|
||||
|
||||
if ( SDL_AtomicGet(&device->enabled) ) {
|
||||
@ -614,7 +614,7 @@ SDL_RunAudio(void *devicep)
|
||||
current_audio.impl.WaitDevice(device);
|
||||
}
|
||||
}
|
||||
} else if (stream == device->fake_stream) {
|
||||
} else if (stream == device->work_buffer) {
|
||||
/* nothing to do; pause like we queued a buffer to play. */
|
||||
SDL_Delay(delay);
|
||||
} else { /* writing directly to the device. */
|
||||
@ -670,8 +670,8 @@ SDL_CaptureAudio(void *devicep)
|
||||
/* Fill the current buffer with sound */
|
||||
still_need = stream_len;
|
||||
|
||||
/* just use the "fake" stream to hold data read from the device. */
|
||||
stream = device->fake_stream;
|
||||
/* Use the work_buffer to hold data read from the device. */
|
||||
stream = device->work_buffer;
|
||||
SDL_assert(stream != NULL);
|
||||
|
||||
ptr = stream;
|
||||
@ -702,16 +702,16 @@ SDL_CaptureAudio(void *devicep)
|
||||
SDL_AudioStreamPut(device->stream, stream, stream_len);
|
||||
|
||||
while (SDL_AudioStreamAvailable(device->stream) >= ((int) device->callbackspec.size)) {
|
||||
const int got = SDL_AudioStreamGet(device->stream, device->fake_stream, device->callbackspec.size);
|
||||
const int got = SDL_AudioStreamGet(device->stream, device->work_buffer, device->callbackspec.size);
|
||||
SDL_assert((got < 0) || (got == device->callbackspec.size));
|
||||
if (got != device->callbackspec.size) {
|
||||
SDL_memset(device->fake_stream, device->spec.silence, device->callbackspec.size);
|
||||
SDL_memset(device->work_buffer, device->spec.silence, device->callbackspec.size);
|
||||
}
|
||||
|
||||
/* !!! FIXME: this should be LockDevice. */
|
||||
SDL_LockMutex(device->mixer_lock);
|
||||
if (!SDL_AtomicGet(&device->paused)) {
|
||||
callback(udata, device->fake_stream, device->callbackspec.size);
|
||||
callback(udata, device->work_buffer, device->callbackspec.size);
|
||||
}
|
||||
SDL_UnlockMutex(device->mixer_lock);
|
||||
}
|
||||
@ -958,7 +958,7 @@ close_audio_device(SDL_AudioDevice * device)
|
||||
SDL_DestroyMutex(device->mixer_lock);
|
||||
}
|
||||
|
||||
SDL_free(device->fake_stream);
|
||||
SDL_free(device->work_buffer);
|
||||
SDL_FreeAudioStream(device->stream);
|
||||
|
||||
if (device->hidden != NULL) {
|
||||
@ -1243,16 +1243,15 @@ open_audio_device(const char *devname, int iscapture,
|
||||
device->spec.userdata = device;
|
||||
}
|
||||
|
||||
/* !!! FIXME: rename this from fake_stream */
|
||||
/* Allocate a scratch audio buffer */
|
||||
device->fake_stream_len = build_stream ? device->callbackspec.size : 0;
|
||||
if (device->spec.size > device->fake_stream_len) {
|
||||
device->fake_stream_len = device->spec.size;
|
||||
device->work_buffer_len = build_stream ? device->callbackspec.size : 0;
|
||||
if (device->spec.size > device->work_buffer_len) {
|
||||
device->work_buffer_len = device->spec.size;
|
||||
}
|
||||
SDL_assert(device->fake_stream_len > 0);
|
||||
SDL_assert(device->work_buffer_len > 0);
|
||||
|
||||
device->fake_stream = (Uint8 *) SDL_malloc(device->fake_stream_len);
|
||||
if (device->fake_stream == NULL) {
|
||||
device->work_buffer = (Uint8 *) SDL_malloc(device->work_buffer_len);
|
||||
if (device->work_buffer == NULL) {
|
||||
close_audio_device(device);
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
|
@ -146,11 +146,11 @@ struct SDL_AudioDevice
|
||||
SDL_atomic_t paused;
|
||||
SDL_bool iscapture;
|
||||
|
||||
/* Fake audio buffer for when the audio hardware is busy */
|
||||
Uint8 *fake_stream;
|
||||
/* Scratch buffer used in the bridge between SDL and the user callback. */
|
||||
Uint8 *work_buffer;
|
||||
|
||||
/* Size, in bytes, of fake_stream. */
|
||||
Uint32 fake_stream_len;
|
||||
/* Size, in bytes, of work_buffer. */
|
||||
Uint32 work_buffer_len;
|
||||
|
||||
/* A mutex for locking the mixing buffers */
|
||||
SDL_mutex *mixer_lock;
|
||||
|
@ -65,26 +65,26 @@ HandleAudioProcess(_THIS)
|
||||
|
||||
if (this->stream == NULL) { /* no conversion necessary. */
|
||||
SDL_assert(this->spec.size == stream_len);
|
||||
callback(this->spec.userdata, this->fake_stream, stream_len);
|
||||
callback(this->spec.userdata, this->work_buffer, stream_len);
|
||||
} else { /* streaming/converting */
|
||||
int got;
|
||||
while (SDL_AudioStreamAvailable(this->stream) < ((int) this->spec.size)) {
|
||||
callback(this->spec.userdata, this->fake_stream, stream_len);
|
||||
if (SDL_AudioStreamPut(this->stream, this->fake_stream, stream_len) == -1) {
|
||||
callback(this->spec.userdata, this->work_buffer, stream_len);
|
||||
if (SDL_AudioStreamPut(this->stream, this->work_buffer, stream_len) == -1) {
|
||||
SDL_AudioStreamClear(this->stream);
|
||||
SDL_AtomicSet(&this->enabled, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
got = SDL_AudioStreamGet(this->stream, this->fake_stream, this->spec.size);
|
||||
got = SDL_AudioStreamGet(this->stream, this->work_buffer, this->spec.size);
|
||||
SDL_assert((got < 0) || (got == this->spec.size));
|
||||
if (got != this->spec.size) {
|
||||
SDL_memset(this->fake_stream, this->spec.silence, this->spec.size);
|
||||
SDL_memset(this->work_buffer, this->spec.silence, this->spec.size);
|
||||
}
|
||||
}
|
||||
|
||||
FeedAudioDevice(this, this->fake_stream, this->spec.size);
|
||||
FeedAudioDevice(this, this->work_buffer, this->spec.size);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -117,25 +117,25 @@ HandleCaptureProcess(_THIS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, this->fake_stream, (this->spec.size / sizeof (float)) / this->spec.channels);
|
||||
}, this->work_buffer, (this->spec.size / sizeof (float)) / this->spec.channels);
|
||||
|
||||
/* okay, we've got an interleaved float32 array in C now. */
|
||||
|
||||
if (this->stream == NULL) { /* no conversion necessary. */
|
||||
SDL_assert(this->spec.size == stream_len);
|
||||
callback(this->spec.userdata, this->fake_stream, stream_len);
|
||||
callback(this->spec.userdata, this->work_buffer, stream_len);
|
||||
} else { /* streaming/converting */
|
||||
if (SDL_AudioStreamPut(this->stream, this->fake_stream, this->spec.size) == -1) {
|
||||
if (SDL_AudioStreamPut(this->stream, this->work_buffer, this->spec.size) == -1) {
|
||||
SDL_AtomicSet(&this->enabled, 0);
|
||||
}
|
||||
|
||||
while (SDL_AudioStreamAvailable(this->stream) >= stream_len) {
|
||||
const int got = SDL_AudioStreamGet(this->stream, this->fake_stream, stream_len);
|
||||
const int got = SDL_AudioStreamGet(this->stream, this->work_buffer, stream_len);
|
||||
SDL_assert((got < 0) || (got == stream_len));
|
||||
if (got != stream_len) {
|
||||
SDL_memset(this->fake_stream, this->callbackspec.silence, stream_len);
|
||||
SDL_memset(this->work_buffer, this->callbackspec.silence, stream_len);
|
||||
}
|
||||
callback(this->spec.userdata, this->fake_stream, stream_len); /* Send it to the app. */
|
||||
callback(this->spec.userdata, this->work_buffer, stream_len); /* Send it to the app. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,8 @@ FillSound(void *device, void *stream, size_t len,
|
||||
const int stream_len = audio->callbackspec.size;
|
||||
const int ilen = (int) len;
|
||||
while (SDL_AudioStreamAvailable(audio->stream) < ilen) {
|
||||
callback(audio->spec.userdata, audio->fake_stream, stream_len);
|
||||
if (SDL_AudioStreamPut(audio->stream, audio->fake_stream, stream_len) == -1) {
|
||||
callback(audio->spec.userdata, audio->work_buffer, stream_len);
|
||||
if (SDL_AudioStreamPut(audio->stream, audio->work_buffer, stream_len) == -1) {
|
||||
SDL_AudioStreamClear(audio->stream);
|
||||
SDL_AtomicSet(&audio->enabled, 0);
|
||||
break;
|
||||
|
@ -70,8 +70,8 @@ static void nacl_audio_callback(void* stream, uint32_t buffer_size, PP_TimeDelta
|
||||
} else { /* streaming/converting */
|
||||
const int stream_len = _this->callbackspec.size;
|
||||
while (SDL_AudioStreamAvailable(_this->stream) < len) {
|
||||
callback(_this->spec.userdata, _this->fake_stream, stream_len);
|
||||
if (SDL_AudioStreamPut(_this->stream, _this->fake_stream, stream_len) == -1) {
|
||||
callback(_this->spec.userdata, _this->work_buffer, stream_len);
|
||||
if (SDL_AudioStreamPut(_this->stream, _this->work_buffer, stream_len) == -1) {
|
||||
SDL_AudioStreamClear(_this->stream);
|
||||
SDL_AtomicSet(&_this->enabled, 0);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user