From 04e17d4e4606e48c023a7f4f4ef3544cb08c6ea9 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Tue, 9 May 2023 13:23:33 +0200
Subject: [PATCH] Remove _THIS in src/audio/
---
src/audio/SDL_audio.c | 20 +-
src/audio/SDL_sysaudio.h | 24 +-
src/audio/aaudio/SDL_aaudio.c | 92 +++---
src/audio/aaudio/SDL_aaudio.h | 3 -
src/audio/alsa/SDL_alsa_audio.c | 140 ++++-----
src/audio/alsa/SDL_alsa_audio.h | 5 +-
src/audio/android/SDL_androidaudio.c | 40 +--
src/audio/android/SDL_androidaudio.h | 3 -
src/audio/coreaudio/SDL_coreaudio.h | 3 -
src/audio/coreaudio/SDL_coreaudio.m | 324 ++++++++++-----------
src/audio/directsound/SDL_directsound.c | 178 +++++------
src/audio/directsound/SDL_directsound.h | 3 -
src/audio/disk/SDL_diskaudio.c | 14 +-
src/audio/disk/SDL_diskaudio.h | 3 -
src/audio/dsp/SDL_dspaudio.c | 96 +++---
src/audio/dsp/SDL_dspaudio.h | 3 -
src/audio/dummy/SDL_dummyaudio.c | 4 +-
src/audio/dummy/SDL_dummyaudio.h | 3 -
src/audio/emscripten/SDL_emscriptenaudio.c | 106 +++----
src/audio/emscripten/SDL_emscriptenaudio.h | 3 -
src/audio/haiku/SDL_haikuaudio.cc | 4 +-
src/audio/haiku/SDL_haikuaudio.h | 3 -
src/audio/jack/SDL_jackaudio.c | 126 ++++----
src/audio/jack/SDL_jackaudio.h | 3 -
src/audio/n3ds/SDL_n3dsaudio.c | 188 ++++++------
src/audio/n3ds/SDL_n3dsaudio.h | 3 -
src/audio/netbsd/SDL_netbsdaudio.c | 90 +++---
src/audio/netbsd/SDL_netbsdaudio.h | 2 -
src/audio/openslES/SDL_openslES.c | 142 ++++-----
src/audio/openslES/SDL_openslES.h | 3 -
src/audio/pipewire/SDL_pipewire.c | 146 +++++-----
src/audio/pipewire/SDL_pipewire.h | 3 -
src/audio/ps2/SDL_ps2audio.c | 82 +++---
src/audio/ps2/SDL_ps2audio.h | 3 -
src/audio/psp/SDL_pspaudio.c | 90 +++---
src/audio/psp/SDL_pspaudio.h | 3 -
src/audio/pulseaudio/SDL_pulseaudio.c | 82 +++---
src/audio/pulseaudio/SDL_pulseaudio.h | 3 -
src/audio/qnx/SDL_qsa_audio.c | 138 ++++-----
src/audio/qnx/SDL_qsa_audio.h | 3 -
src/audio/sndio/SDL_sndioaudio.c | 114 ++++----
src/audio/sndio/SDL_sndioaudio.h | 3 -
src/audio/vita/SDL_vitaaudio.c | 108 +++----
src/audio/vita/SDL_vitaaudio.h | 3 -
src/audio/wasapi/SDL_wasapi.c | 308 ++++++++++----------
src/audio/wasapi/SDL_wasapi.h | 19 +-
src/audio/wasapi/SDL_wasapi_win32.c | 32 +-
src/audio/wasapi/SDL_wasapi_winrt.cpp | 6 +-
48 files changed, 1352 insertions(+), 1425 deletions(-)
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 487c7a5593f0..3910b8dc3b17 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -27,8 +27,6 @@
#include "../thread/SDL_systhread.h"
#include "../SDL_utils_c.h"
-#define _THIS SDL_AudioDevice *_this
-
static SDL_AudioDriver current_audio;
static SDL_AudioDevice *open_devices[16];
@@ -137,37 +135,37 @@ static void SDL_AudioDetectDevices_Default(void)
}
}
-static void SDL_AudioThreadInit_Default(_THIS)
+static void SDL_AudioThreadInit_Default(SDL_AudioDevice *_this)
{ /* no-op. */
}
-static void SDL_AudioThreadDeinit_Default(_THIS)
+static void SDL_AudioThreadDeinit_Default(SDL_AudioDevice *_this)
{ /* no-op. */
}
-static void SDL_AudioWaitDevice_Default(_THIS)
+static void SDL_AudioWaitDevice_Default(SDL_AudioDevice *_this)
{ /* no-op. */
}
-static void SDL_AudioPlayDevice_Default(_THIS)
+static void SDL_AudioPlayDevice_Default(SDL_AudioDevice *_this)
{ /* no-op. */
}
-static Uint8 *SDL_AudioGetDeviceBuf_Default(_THIS)
+static Uint8 *SDL_AudioGetDeviceBuf_Default(SDL_AudioDevice *_this)
{
return NULL;
}
-static int SDL_AudioCaptureFromDevice_Default(_THIS, void *buffer, int buflen)
+static int SDL_AudioCaptureFromDevice_Default(SDL_AudioDevice *_this, void *buffer, int buflen)
{
return -1; /* just fail immediately. */
}
-static void SDL_AudioFlushCapture_Default(_THIS)
+static void SDL_AudioFlushCapture_Default(SDL_AudioDevice *_this)
{ /* no-op. */
}
-static void SDL_AudioCloseDevice_Default(_THIS)
+static void SDL_AudioCloseDevice_Default(SDL_AudioDevice *_this)
{ /* no-op. */
}
@@ -179,7 +177,7 @@ static void SDL_AudioFreeDeviceHandle_Default(void *handle)
{ /* no-op. */
}
-static int SDL_AudioOpenDevice_Default(_THIS, const char *devname)
+static int SDL_AudioOpenDevice_Default(SDL_AudioDevice *_this, const char *devname)
{
return SDL_Unsupported();
}
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index f82d2d654622..7c6fd29851f2 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -32,7 +32,6 @@
/* The SDL audio driver */
typedef struct SDL_AudioDevice SDL_AudioDevice;
-#define _THIS SDL_AudioDevice *_this
/* Audio targets should call this as devices are added to the system (such as
a USB headset being plugged in), and should also be called for
@@ -63,17 +62,17 @@ extern void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device);
typedef struct SDL_AudioDriverImpl
{
void (*DetectDevices)(void);
- int (*OpenDevice)(_THIS, const char *devname);
- void (*ThreadInit)(_THIS); /* Called by audio thread at start */
- void (*ThreadDeinit)(_THIS); /* Called by audio thread at end */
- void (*WaitDevice)(_THIS);
- void (*PlayDevice)(_THIS);
- Uint8 *(*GetDeviceBuf)(_THIS);
- int (*CaptureFromDevice)(_THIS, void *buffer, int buflen);
- void (*FlushCapture)(_THIS);
- void (*CloseDevice)(_THIS);
- void (*LockDevice)(_THIS);
- void (*UnlockDevice)(_THIS);
+ int (*OpenDevice)(SDL_AudioDevice *_this, const char *devname);
+ void (*ThreadInit)(SDL_AudioDevice *_this); /* Called by audio thread at start */
+ void (*ThreadDeinit)(SDL_AudioDevice *_this); /* Called by audio thread at end */
+ void (*WaitDevice)(SDL_AudioDevice *_this);
+ void (*PlayDevice)(SDL_AudioDevice *_this);
+ Uint8 *(*GetDeviceBuf)(SDL_AudioDevice *_this);
+ int (*CaptureFromDevice)(SDL_AudioDevice *_this, void *buffer, int buflen);
+ void (*FlushCapture)(SDL_AudioDevice *_this);
+ void (*CloseDevice)(SDL_AudioDevice *_this);
+ void (*LockDevice)(SDL_AudioDevice *_this);
+ void (*UnlockDevice)(SDL_AudioDevice *_this);
void (*FreeDeviceHandle)(void *handle); /**< SDL is done with handle from SDL_AddAudioDevice() */
void (*Deinitialize)(void);
int (*GetDefaultAudioInfo)(char **name, SDL_AudioSpec *spec, int iscapture);
@@ -165,7 +164,6 @@ struct SDL_AudioDevice
void *handle;
};
-#undef _THIS
typedef struct AudioBootStrap
{
diff --git a/src/audio/aaudio/SDL_aaudio.c b/src/audio/aaudio/SDL_aaudio.c
index ed8da7d6345a..7dc53fa60eb1 100644
--- a/src/audio/aaudio/SDL_aaudio.c
+++ b/src/audio/aaudio/SDL_aaudio.c
@@ -65,10 +65,10 @@ void aaudio_errorCallback(AAudioStream *stream, void *userData, aaudio_result_t
#define LIB_AAUDIO_SO "libaaudio.so"
-static int aaudio_OpenDevice(_THIS, const char *devname)
+static int aaudio_OpenDevice(SDL_AudioDevice *_this, const char *devname)
{
struct SDL_PrivateAudioData *private;
- SDL_bool iscapture = this->iscapture;
+ SDL_bool iscapture = _this->iscapture;
aaudio_result_t res;
LOGI(__func__);
@@ -79,14 +79,14 @@ static int aaudio_OpenDevice(_THIS, const char *devname)
}
}
- this->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*this->hidden));
- if (this->hidden == NULL) {
+ _this->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*_this->hidden));
+ if (_this->hidden == NULL) {
return SDL_OutOfMemory();
}
- private = this->hidden;
+ private = _this->hidden;
- ctx.AAudioStreamBuilder_setSampleRate(ctx.builder, this->spec.freq);
- ctx.AAudioStreamBuilder_setChannelCount(ctx.builder, this->spec.channels);
+ ctx.AAudioStreamBuilder_setSampleRate(ctx.builder, _this->spec.freq);
+ ctx.AAudioStreamBuilder_setChannelCount(ctx.builder, _this->spec.channels);
if(devname != NULL) {
int aaudio_device_id = SDL_atoi(devname);
LOGI("Opening device id %d", aaudio_device_id);
@@ -98,9 +98,9 @@ static int aaudio_OpenDevice(_THIS, const char *devname)
}
{
aaudio_format_t format = AAUDIO_FORMAT_PCM_FLOAT;
- if (this->spec.format == SDL_AUDIO_S16SYS) {
+ if (_this->spec.format == SDL_AUDIO_S16SYS) {
format = AAUDIO_FORMAT_PCM_I16;
- } else if (this->spec.format == SDL_AUDIO_S16SYS) {
+ } else if (_this->spec.format == SDL_AUDIO_S16SYS) {
format = AAUDIO_FORMAT_PCM_FLOAT;
}
ctx.AAudioStreamBuilder_setFormat(ctx.builder, format);
@@ -109,8 +109,8 @@ static int aaudio_OpenDevice(_THIS, const char *devname)
ctx.AAudioStreamBuilder_setErrorCallback(ctx.builder, aaudio_errorCallback, private);
LOGI("AAudio Try to open %u hz %u bit chan %u %s samples %u",
- this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
- this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples);
+ _this->spec.freq, SDL_AUDIO_BITSIZE(_this->spec.format),
+ _this->spec.channels, (_this->spec.format & 0x1000) ? "BE" : "LE", _this->spec.samples);
res = ctx.AAudioStreamBuilder_openStream(ctx.builder, &private->stream);
if (res != AAUDIO_OK) {
@@ -118,34 +118,34 @@ static int aaudio_OpenDevice(_THIS, const char *devname)
return SDL_SetError("%s : %s", __func__, ctx.AAudio_convertResultToText(res));
}
- this->spec.freq = ctx.AAudioStream_getSampleRate(private->stream);
- this->spec.channels = ctx.AAudioStream_getChannelCount(private->stream);
+ _this->spec.freq = ctx.AAudioStream_getSampleRate(private->stream);
+ _this->spec.channels = ctx.AAudioStream_getChannelCount(private->stream);
{
aaudio_format_t fmt = ctx.AAudioStream_getFormat(private->stream);
if (fmt == AAUDIO_FORMAT_PCM_I16) {
- this->spec.format = SDL_AUDIO_S16SYS;
+ _this->spec.format = SDL_AUDIO_S16SYS;
} else if (fmt == AAUDIO_FORMAT_PCM_FLOAT) {
- this->spec.format = SDL_AUDIO_F32SYS;
+ _this->spec.format = SDL_AUDIO_F32SYS;
}
}
LOGI("AAudio Try to open %u hz %u bit chan %u %s samples %u",
- this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
- this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples);
+ _this->spec.freq, SDL_AUDIO_BITSIZE(_this->spec.format),
+ _this->spec.channels, (_this->spec.format & 0x1000) ? "BE" : "LE", _this->spec.samples);
- SDL_CalculateAudioSpec(&this->spec);
+ SDL_CalculateAudioSpec(&_this->spec);
/* Allocate mixing buffer */
if (!iscapture) {
- private->mixlen = this->spec.size;
+ private->mixlen = _this->spec.size;
private->mixbuf = (Uint8 *)SDL_malloc(private->mixlen);
if (private->mixbuf == NULL) {
return SDL_OutOfMemory();
}
- SDL_memset(private->mixbuf, this->spec.silence, this->spec.size);
+ SDL_memset(private->mixbuf, _this->spec.silence, _this->spec.size);
}
- private->frame_size = this->spec.channels * (SDL_AUDIO_BITSIZE(this->spec.format) / 8);
+ private->frame_size = _this->spec.channels * (SDL_AUDIO_BITSIZE(_this->spec.format) / 8);
res = ctx.AAudioStream_requestStart(private->stream);
if (res != AAUDIO_OK) {
@@ -157,9 +157,9 @@ static int aaudio_OpenDevice(_THIS, const char *devname)
return 0;
}
-static void aaudio_CloseDevice(_THIS)
+static void aaudio_CloseDevice(SDL_AudioDevice *_this)
{
- struct SDL_PrivateAudioData *private = this->hidden;
+ struct SDL_PrivateAudioData *private = _this->hidden;
aaudio_result_t res;
LOGI(__func__);
@@ -179,19 +179,19 @@ static void aaudio_CloseDevice(_THIS)
}
}
- SDL_free(this->hidden->mixbuf);
- SDL_free(this->hidden);
+ SDL_free(_this->hidden->mixbuf);
+ SDL_free(_this->hidden);
}
-static Uint8 *aaudio_GetDeviceBuf(_THIS)
+static Uint8 *aaudio_GetDeviceBuf(SDL_AudioDevice *_this)
{
- struct SDL_PrivateAudioData *private = this->hidden;
+ struct SDL_PrivateAudioData *private = _this->hidden;
return private->mixbuf;
}
-static void aaudio_PlayDevice(_THIS)
+static void aaudio_PlayDevice(SDL_AudioDevice *_this)
{
- struct SDL_PrivateAudioData *private = this->hidden;
+ struct SDL_PrivateAudioData *private = _this->hidden;
aaudio_result_t res;
int64_t timeoutNanoseconds = 1 * 1000 * 1000; /* 8 ms */
res = ctx.AAudioStream_write(private->stream, private->mixbuf, private->mixlen / private->frame_size, timeoutNanoseconds);
@@ -214,9 +214,9 @@ static void aaudio_PlayDevice(_THIS)
#endif
}
-static int aaudio_CaptureFromDevice(_THIS, void *buffer, int buflen)
+static int aaudio_CaptureFromDevice(SDL_AudioDevice *_this, void *buffer, int buflen)
{
- struct SDL_PrivateAudioData *private = this->hidden;
+ struct SDL_PrivateAudioData *private = _this->hidden;
aaudio_result_t res;
int64_t timeoutNanoseconds = 8 * 1000 * 1000; /* 8 ms */
res = ctx.AAudioStream_read(private->stream, buffer, buflen / private->frame_size, timeoutNanoseconds);
@@ -328,18 +328,18 @@ void aaudio_PauseDevices(void)
}
for (i = 0; i < get_max_num_audio_dev(); i++) {
- SDL_AudioDevice *this = get_audio_dev(i);
+ SDL_AudioDevice *_this = get_audio_dev(i);
SDL_AudioDevice *audioDevice = NULL;
SDL_AudioDevice *captureDevice = NULL;
- if (this == NULL) {
+ if (_this == NULL) {
continue;
}
- if (this->iscapture) {
- captureDevice = this;
+ if (_this->iscapture) {
+ captureDevice = _this;
} else {
- audioDevice = this;
+ audioDevice = _this;
}
if (audioDevice != NULL && audioDevice->hidden != NULL) {
@@ -399,18 +399,18 @@ void aaudio_ResumeDevices(void)
}
for (i = 0; i < get_max_num_audio_dev(); i++) {
- SDL_AudioDevice *this = get_audio_dev(i);
+ SDL_AudioDevice *_this = get_audio_dev(i);
SDL_AudioDevice *audioDevice = NULL;
SDL_AudioDevice *captureDevice = NULL;
- if (this == NULL) {
+ if (_this == NULL) {
continue;
}
- if (this->iscapture) {
- captureDevice = this;
+ if (_this->iscapture) {
+ captureDevice = _this;
} else {
- audioDevice = this;
+ audioDevice = _this;
}
if (audioDevice != NULL && audioDevice->hidden != NULL) {
@@ -466,18 +466,18 @@ SDL_bool aaudio_DetectBrokenPlayState(void)
}
for (i = 0; i < get_max_num_audio_dev(); i++) {
- SDL_AudioDevice *this = get_audio_dev(i);
+ SDL_AudioDevice *_this = get_audio_dev(i);
SDL_AudioDevice *audioDevice = NULL;
SDL_AudioDevice *captureDevice = NULL;
- if (this == NULL) {
+ if (_this == NULL) {
continue;
}
- if (this->iscapture) {
- captureDevice = this;
+ if (_this->iscapture) {
+ captureDevice = _this;
} else {
- audioDevice = this;
+ audioDevice = _this;
}
if (audioDevice != NULL && audioDevice->hidden != NULL) {
diff --git a/src/audio/aaudio/SDL_aaudio.h b/src/audio/aaudio/SDL_aaudio.h
index c09ae23b8bef..2c99998208a0 100644
--- a/src/audio/aaudio/SDL_aaudio.h
+++ b/src/audio/aaudio/SDL_aaudio.h
@@ -27,9 +27,6 @@
#include <stdbool.h>
#include <aaudio/AAudio.h>
-/* Hidden "this" pointer for the audio functions */
-#define _THIS SDL_AudioDevice *this
-
struct SDL_PrivateAudioData
{
AAudioStream *stream;
diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c
index d63e727c81c5..27e5557ea4ea 100644
--- a/src/audio/alsa/SDL_alsa_audio.c
+++ b/src/audio/alsa/SDL_alsa_audio.c
@@ -225,20 +225,20 @@ static const char *get_audio_device(void *handle, const int channels)
}
/* This function waits until it is possible to write a full sound buffer */
-static void ALSA_WaitDevice(_THIS)
+static void ALSA_WaitDevice(SDL_AudioDevice *_this)
{
#if SDL_ALSA_NON_BLOCKING
- const snd_pcm_sframes_t needed = (snd_pcm_sframes_t)this->spec.samples;
- while (SDL_AtomicGet(&this->enabled)) {
- const snd_pcm_sframes_t rc = ALSA_snd_pcm_avail(this->hidden->pcm_handle);
+ const snd_pcm_sframes_t needed = (snd_pcm_sframes_t)_this->spec.samples;
+ while (SDL_AtomicGet(&_this->enabled)) {
+ const snd_pcm_sframes_t rc = ALSA_snd_pcm_avail(_this->hidden->pcm_handle);
if ((rc < 0) && (rc != -EAGAIN)) {
/* Hmm, not much we can do - abort */
fprintf(stderr, "ALSA snd_pcm_avail failed (unrecoverable): %s\n",
ALSA_snd_strerror(rc));
- SDL_OpenedAudioDeviceDisconnected(this);
+ SDL_OpenedAudioDeviceDisconnected(_this);
return;
} else if (rc < needed) {
- const Uint32 delay = ((needed - (SDL_max(rc, 0))) * 1000) / this->spec.freq;
+ const Uint32 delay = ((needed - (SDL_max(rc, 0))) * 1000) / _this->spec.freq;
SDL_Delay(SDL_max(delay, 10));
} else {
break; /* ready to go! */
@@ -311,15 +311,15 @@ CHANNEL_SWIZZLE(SWIZ8)
#undef SWIZ8
/*
- * Called right before feeding this->hidden->mixbuf to the hardware. Swizzle
+ * Called right before feeding _this->hidden->mixbuf to the hardware. Swizzle
* channels from Windows/Mac order to the format alsalib will want.
*/
-static void swizzle_alsa_channels(_THIS, void *buffer, Uint32 bufferlen)
+static void swizzle_alsa_channels(SDL_AudioDevice *_this, void *buffer, Uint32 bufferlen)
{
- switch (this->spec.channels) {
+ switch (_this->spec.channels) {
#define CHANSWIZ(chans) \
case chans: \
- switch ((this->spec.format & (0xFF))) { \
+ switch ((_this->spec.format & (0xFF))) { \
case 8: \
swizzle_alsa_channels_##chans##_Uint8(buffer, bufferlen); \
break; \
@@ -348,22 +348,22 @@ static void swizzle_alsa_channels(_THIS, void *buffer, Uint32 bufferlen)
#ifdef SND_CHMAP_API_VERSION
/* Some devices have the right channel map, no swizzling necessary */
-static void no_swizzle(_THIS, void *buffer, Uint32 bufferlen)
+static void no_swizzle(SDL_AudioDevice *_this, void *buffer, Uint32 bufferlen)
{
}
#endif /* SND_CHMAP_API_VERSION */
-static void ALSA_PlayDevice(_THIS)
+static void ALSA_PlayDevice(SDL_AudioDevice *_this)
{
- const Uint8 *sample_buf = (const Uint8 *)this->hidden->mixbuf;
- const int frame_size = ((SDL_AUDIO_BITSIZE(this->spec.format)) / 8) *
- this->spec.channels;
- snd_pcm_uframes_t frames_left = ((snd_pcm_uframes_t)this->spec.samples);
+ const Uint8 *sample_buf = (const Uint8 *)_this->hidden->mixbuf;
+ const int frame_size = ((SDL_AUDIO_BITSIZE(_this->spec.format)) / 8) *
+ _this->spec.channels;
+ snd_pcm_uframes_t frames_left = ((snd_pcm_uframes_t)_this->spec.samples);
- this->hidden->swizzle_func(this, this->hidden->mixbuf, frames_left);
+ _this->hidden->swizzle_func(_this, _this->hidden->mixbuf, frames_left);
- while (frames_left > 0 && SDL_AtomicGet(&this->enabled)) {
- int status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
+ while (frames_left > 0 && SDL_AtomicGet(&_this->enabled)) {
+ int status = ALSA_snd_pcm_writei(_this->hidden->pcm_handle,
sample_buf, frames_left);
if (status < 0) {
@@ -373,20 +373,20 @@ static void ALSA_PlayDevice(_THIS)
SDL_Delay(1);
continue;
}
- status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
+ status = ALSA_snd_pcm_recover(_this->hidden->pcm_handle, status, 0);
if (status < 0) {
/* Hmm, not much we can do - abort */
SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
"ALSA write failed (unrecoverable): %s\n",
ALSA_snd_strerror(status));
- SDL_OpenedAudioDeviceDisconnected(this);
+ SDL_OpenedAudioDeviceDisconnected(_this);
return;
}
continue;
} else if (status == 0) {
/* No frames were written (no available space in pcm device).
Allow other threads to catch up. */
- Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq;
+ Uint32 delay = (frames_left / 2 * 1000) / _this->spec.freq;
SDL_Delay(delay);
}
@@ -395,34 +395,34 @@ static void ALSA_PlayDevice(_THIS)
}
}
-static Uint8 *ALSA_GetDeviceBuf(_THIS)
+static Uint8 *ALSA_GetDeviceBuf(SDL_AudioDevice *_this)
{
- return this->hidden->mixbuf;
+ return _this->hidden->mixbuf;
}
-static int ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
+static int ALSA_CaptureFromDevice(SDL_AudioDevice *_this, void *buffer, int buflen)
{
Uint8 *sample_buf = (Uint8 *)buffer;
- const int frame_size = ((SDL_AUDIO_BITSIZE(this->spec.format)) / 8) *
- this->spec.channels;
+ const int frame_size = ((SDL_AUDIO_BITSIZE(_this->spec.format)) / 8) *
+ _this->spec.channels;
const int total_frames = buflen / frame_size;
snd_pcm_uframes_t frames_left = total_frames;
snd_pcm_uframes_t wait_time = frame_size / 2;
SDL_assert((buflen % frame_size) == 0);
- while (frames_left > 0 && SDL_AtomicGet(&this->enabled)) {
+ while (frames_left > 0 && SDL_AtomicGet(&_this->enabled)) {
int status;
- status = ALSA_snd_pcm_readi(this->hidden->pcm_handle,
+ status = ALSA_snd_pcm_readi(_this->hidden->pcm_handle,
sample_buf, frames_left);
if (status == -EAGAIN) {
- ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time);
+ ALSA_snd_pcm_wait(_this->hidden->pcm_handle, wait_time);
status = 0;
} else if (status < 0) {
/*printf("ALSA: capture error %d\n", status);*/
- status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
+ status = ALSA_snd_pcm_recover(_this->hidden->pcm_handle, status, 0);
if (status < 0) {
/* Hmm, not much we can do - abort */
SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
@@ -438,32 +438,32 @@ static int ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
frames_left -= status;
}
- this->hidden->swizzle_func(this, buffer, total_frames - frames_left);
+ _this->hidden->swizzle_func(_this, buffer, total_frames - frames_left);
return (total_frames - frames_left) * frame_size;
}
-static void ALSA_FlushCapture(_THIS)
+static void ALSA_FlushCapture(SDL_AudioDevice *_this)
{
- ALSA_snd_pcm_reset(this->hidden->pcm_handle);
+ ALSA_snd_pcm_reset(_this->hidden->pcm_handle);
}
-static void ALSA_CloseDevice(_THIS)
+static void ALSA_CloseDevice(SDL_AudioDevice *_this)
{
- if (this->hidden->pcm_handle) {
+ if (_this->hidden->pcm_handle) {
/* Wait for the submitted audio to drain
ALSA_snd_pcm_drop() can hang, so don't use that.
*/
- Uint32 delay = ((this->spec.samples * 1000) / this->spec.freq) * 2;
+ Uint32 delay = ((_this->spec.samples * 1000) / _this->spec.freq) * 2;
SDL_Delay(delay);
- ALSA_snd_pcm_close(this->hidden->pcm_handle);
+ ALSA_snd_pcm_close(_this->hidden->pcm_handle);
}
- SDL_free(this->hidden->mixbuf);
- SDL_free(this->hidden);
+ SDL_free(_this->hidden->mixbuf);
+ SDL_free(_this->hidden);
}
-static int ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
+static int ALSA_set_buffer_size(SDL_AudioDevice *_this, snd_pcm_hw_params_t *params)
{
int status;
snd_pcm_hw_params_t *hwparams;
@@ -475,9 +475,9 @@ static int ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
ALSA_snd_pcm_hw_params_copy(hwparams, params);
/* Attempt to match the period size to the requested buffer size */
- persize = this->spec.samples;
+ persize = _this->spec.samples;
status = ALSA_snd_pcm_hw_params_set_period_size_near(
- this->hidden->pcm_handle, hwparams, &persize, NULL);
+ _this->hidden->pcm_handle, hwparams, &persize, NULL);
if (status < 0) {
return -1;
}
@@ -485,24 +485,24 @@ static int ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
/* Need to at least double buffer */
periods = 2;
status = ALSA_snd_pcm_hw_params_set_periods_min(
- this->hidden->pcm_handle, hwparams, &periods, NULL);
+ _this->hidden->pcm_handle, hwparams, &periods, NULL);
if (status < 0) {
return -1;
}
status = ALSA_snd_pcm_hw_params_set_periods_first(
- this->hidden->pcm_handle, hwparams, &periods, NULL);
+ _this->hidden->pcm_handle, hwparams, &periods, NULL);
if (status < 0) {
return -1;
}
/* "set" the hardware with the desired parameters */
- status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams);
+ status = ALSA_snd_pcm_hw_params(_this->hidden->pcm_handle, hwparams);
if (status < 0) {
return -1;
}
- this->spec.samples = persize;
+ _this->spec.samples = persize;
/* This is useful for debugging */
if (SDL_getenv("SDL_AUDIO_ALSA_DEBUG")) {
@@ -518,10 +518,10 @@ static int ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
return 0;
}
-static int ALSA_OpenDevice(_THIS, const char *devname)
+static int ALSA_OpenDevice(SDL_AudioDevice *_this, const char *devname)
{
int status = 0;
- SDL_bool iscapture = this->iscapture;
+ SDL_bool iscapture = _this->iscapture;
snd_pcm_t *pcm_handle = NULL;
snd_pcm_hw_params_t *hwparams = NULL;
snd_pcm_sw_params_t *swparams = NULL;
@@ -536,16 +536,16 @@ static int ALSA_OpenDevice(_THIS, const char *devname)
#endif
/* Initialize all variables that we clean on shutdown */
- this->hidden = (struct SDL_PrivateAudioData *)SDL_malloc(sizeof(*this->hidden));
- if (this->hidden == NULL) {
+ _this->hidden = (struct SDL_PrivateAudioData *)SDL_malloc(sizeof(*_this->hidden));
+ if (_this->hidden == NULL) {
return SDL_OutOfMemory();
}
- SDL_zerop(this->hidden);
+ SDL_zerop(_this->hidden);
/* Open the audio device */
/* Name of device should depend on # channels in spec */
status = ALSA_snd_pcm_open(&pcm_handle,
- get_audio_device(this->handle, this->spec.channels),
+ get_audio_device(_this->handle, _this->spec.channels),
iscapture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK);
@@ -553,7 +553,7 @@ static int ALSA_OpenDevice(_THIS, const char *devname)
return SDL_SetError("ALSA: Couldn't open audio device: %s", ALSA_snd_strerror(status));
}
- this->hidden->pcm_handle = pcm_handle;
+ _this->hidden->pcm_handle = pcm_handle;
/* Figure out what the hardware is capable of */
snd_pcm_hw_params_alloca(&hwparams);
@@ -570,7 +570,7 @@ static int ALSA_OpenDevice(_THIS, const char *devname)
}
/* Try for a closest match on audio format */
- closefmts = SDL_ClosestAudioFormats(this->spec.format);
+ closefmts = SDL_ClosestAudioFormats(_this->spec.format);
while ((test_format = *(closefmts++)) != 0) {
switch (test_format) {
case SDL_AUDIO_U8:
@@ -607,19 +607,19 @@ static int ALSA_OpenDevice(_THIS, const char *devname)
if (!test_format) {
return SDL_SetError("%s: Unsupported audio format", "alsa");
}
- this->spec.format = test_format;
+ _this->spec.format = test_format;
/* Validate number of channels and determine if swizzling is necessary
* Assume original swizzling, until proven otherwise.
*/
- this->hidden->swizzle_func = swizzle_alsa_channels;
+ _this->hidden->swizzle_func = swizzle_alsa_channels;
#ifdef SND_CHMAP_API_VERSION
chmap = ALSA_snd_pcm_get_chmap(pcm_handle);
if (chmap) {
if (ALSA_snd_pcm_chmap_print(chmap, sizeof(chmap_str), chmap_str) > 0) {
if (SDL_strcmp("FL FR FC LFE RL RR", chmap_str) == 0 ||
SDL_strcmp("FL FR FC LFE SL SR", chmap_str) == 0) {
- this->hidden->swizzle_func = no_swizzle;
+ _this->hidden->swizzle_func = no_swizzle;
}
}
free(chmap);
@@ -628,27 +628,27 @@ static int ALSA_OpenDevice(_THIS, const char *devname)
/* Set the number of channels */
status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
- this->spec.channels);
- channels = this->spec.channels;
+ _this->spec.channels);
+ channels = _this->spec.channels;
if (status < 0) {
status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't set audio channels");
}
- this->spec.channels = channels;
+ _this->spec.channels = channels;
}
/* Set the audio rate */
- rate = this->spec.freq;
+ rate = _this->spec.freq;
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
&rate, NULL);
if (status < 0) {
return SDL_SetError("ALSA: Couldn't set audio frequency: %s", ALSA_snd_strerror(status));
}
- this->spec.freq = rate;
+ _this->spec.freq = rate;
/* Set the buffer size, in samples */
- status = ALSA_set_buffer_size(this, hwparams);
+ status = ALSA_set_buffer_size(_this, hwparams);
if (status < 0) {
return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
}
@@ -659,7 +659,7 @@ static int ALSA_OpenDevice(_THIS, const char *devname)
if (status < 0) {
return SDL_SetError("ALSA: Couldn't get software config: %s", ALSA_snd_strerror(status));
}
- status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
+ status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, _this->spec.samples);
if (status < 0) {
return SDL_SetError("Couldn't set minimum available samples: %s", ALSA_snd_strerror(status));
}
@@ -674,16 +674,16 @@ static int ALSA_OpenDevice(_THIS, const char *devname)
}
/* Calculate the final parameters for this audio specification */
- SDL_CalculateAudioSpec(&this->spec);
+ SDL_CalculateAudioSpec(&_this->spec);
/* Allocate mixing buffer */
if (!iscapture) {
- this->hidd
(Patch may be truncated, please check the link at the top of this post.)