Use appropriate functions and namings

Signed-off-by: Arnav Bhatt <arnav@ghativega.in>
This commit is contained in:
Arnav Bhatt
2024-06-17 04:21:30 +05:30
parent 8e4cb091f9
commit fac5afe2f6
3 changed files with 89 additions and 85 deletions

View File

@@ -90,16 +90,16 @@
#define HAVE_TRUNCF 1
#define HAVE_SETJMP 1
/* Enable the N-Gage thread support (src/thread/ngage/\*.c) */
/* Enable the dummy thread support (src/thread/dummy/\*.c) */
#define SDL_THREADS_DISABLED 1
/* Enable the N-Gage timer support (src/timer/ngage/\*.c) */
/* Enable the dummy timer support (src/timer/dummy/\*.c) */
#define SDL_TIMER_DUMMY 1
/* Enable the N-Gage video driver (src/video/ngage/\*.c) */
/* Enable the dummy video driver (src/video/dummy/\*.c) */
#define SDL_VIDEO_DRIVER_DUMMY 1
/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
/* Enable the Kolibri audio driver (src/audio/kolibri/\*.c) */
#define SDL_AUDIO_DRIVER_KOLIBRI 1
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */

View File

@@ -26,35 +26,35 @@ static SDL_AudioDevice *global_device;
static void kolibri_audio_callback(void)
{
ksys_signal_info_t snd_signal;
SDL_AudioDevice *this;
SDL_AudioDevice *_this;
SDL_AudioCallback callback;
int bPaused;
char str[100];
// initialize
this = global_device;
callback = this->spec.callback;
_this = global_device;
callback = _this->spec.callback;
if (CreateBuffer(private->used_format | PCM_RING, 0, &private->hBuff)) {
private->audio_response = 1;
exit(0);
}
GetBufferSize(private->hBuff, &this->spec.size);
sprintf(str, "buffer created, size is %d\n", this->spec.size);
GetBufferSize(private->hBuff, &_this->spec.size);
sprintf(str, "buffer created, size is %d\n", _this->spec.size);
_ksys_debug_puts(str);
this->spec.size >>= 1;
this->work_buffer = SDL_calloc(1, this->spec.size);
_this->spec.size >>= 1;
_this->work_buffer = SDL_malloc(_this->spec.size);
private->audio_response = 1;
if (!this->work_buffer) {
if (!_this->work_buffer) {
DestroyBuffer(private->hBuff);
exit(0);
}
// wait for resume
while (SDL_AtomicGet(&this->paused))
while (SDL_AtomicGet(&_this->paused))
_ksys_thread_yield();
_ksys_debug_puts("audio_thread created\n");
@@ -64,15 +64,15 @@ static void kolibri_audio_callback(void)
// main loop
while (1) {
if (!SDL_AtomicGet(&this->paused)) {
if (!SDL_AtomicGet(&_this->paused)) {
PlayBuffer(private->hBuff, 0);
bPaused = 0;
private->audio_response = 1;
} else if (SDL_AtomicGet(&this->paused)) {
} else if (SDL_AtomicGet(&_this->paused)) {
StopBuffer(private->hBuff);
bPaused = 1;
private->audio_response = 1;
} else if (SDL_AtomicGet(&this->shutdown)) {
} else if (SDL_AtomicGet(&_this->shutdown)) {
private->audio_response = 1;
StopBuffer(private->hBuff);
DestroyBuffer(private->hBuff);
@@ -80,7 +80,7 @@ static void kolibri_audio_callback(void)
} else {
_ksys_thread_info(&thread_info, main_slot);
if (thread_info.slot_state == KSYS_SLOT_STATE_FREE || thread_info.pid != main_tid) {
SDL_AtomicSet(&this->shutdown, 1);
SDL_AtomicSet(&_this->shutdown, 1);
continue;
}
}
@@ -90,8 +90,8 @@ static void kolibri_audio_callback(void)
_ksys_wait_signal(&snd_signal);
if (snd_signal.id != 0xFF000001)
continue;
callback(this->spec.userdata, this->work_buffer, this->spec.size);
SetBuffer(private->hBuff, this->work_buffer, ((int *)snd_signal.data)[2], this->spec.size);
callback(_this->spec.userdata, _this->work_buffer, _this->spec.size);
SetBuffer(private->hBuff, _this->work_buffer, ((int *)snd_signal.data)[2], _this->spec.size);
}
}
}
@@ -115,7 +115,7 @@ static int KOLIBRIAUDIO_OpenDevice(_THIS, const char *devname)
char buff[100];
if (InitSound(&ver)) {
_ksys_debug_puts("Error: cannot load drivers!\n");
SDL_SetError("Error: cannot load drivers!\n");
return -1;
}
@@ -124,32 +124,36 @@ static int KOLIBRIAUDIO_OpenDevice(_THIS, const char *devname)
return SDL_OutOfMemory();
}
switch (this->spec.freq) {
switch (_this->spec.freq) {
#define HANDLE_FREQ(freq, symb) \
case freq: \
switch (this->spec.channels) { \
switch (_this->spec.channels) { \
case 1: \
switch (this->spec.format) { \
switch (_this->spec.format) { \
case AUDIO_U8: \
case AUDIO_S8: \
private->used_format = PCM_1_8_##symb; \
private \
->used_format = PCM_1_8_##symb; \
break; \
case AUDIO_U16SYS: \
case AUDIO_S16SYS: \
private->used_format = PCM_1_16_##symb; \
private \
->used_format = PCM_1_16_##symb; \
break; \
} \
break; \
case 2: \
switch (this->spec.format) { \
switch (_this->spec.format) { \
case AUDIO_U8: \
case AUDIO_S8: \
private->used_format = PCM_2_8_##symb; \
private \
->used_format = PCM_2_8_##symb; \
break; \
case AUDIO_U16SYS: \
case AUDIO_S16SYS: \
private->used_format = PCM_2_16_##symb; \
private \
->used_format = PCM_2_16_##symb; \
break; \
} \
break; \
@@ -168,7 +172,7 @@ static int KOLIBRIAUDIO_OpenDevice(_THIS, const char *devname)
}
if (!private->used_format) {
_ksys_debug_puts("Unknown audio format");
SDL_SetError("Unknown audio format");
return -1;
}
@@ -180,10 +184,10 @@ static int KOLIBRIAUDIO_OpenDevice(_THIS, const char *devname)
break;
}
global_device = this;
global_device = _this;
private->audio_tid = _ksys_create_thread(kolibri_audio_callback, thread_stack + AUDIO_THREAD_STACK_SIZE);
if (private->audio_tid < 0) {
_ksys_debug_puts("Cannot create audio thread");
SDL_SetError("Cannot create audio thread");
return -1;
}
@@ -192,20 +196,20 @@ static int KOLIBRIAUDIO_OpenDevice(_THIS, const char *devname)
_ksys_thread_yield();
if (!private->hBuff) {
_ksys_debug_puts("Cannot create audio buffer");
SDL_SetError("Cannot create audio buffer");
return -1;
}
if (!this->work_buffer) {
_ksys_debug_puts("Cannot allocate audio buffer");
if (!_this->work_buffer) {
SDL_SetError("Cannot allocate audio buffer");
return -1;
}
this->spec.silence = (this->spec.format == AUDIO_U8 ? 0x80 : 0);
this->spec.samples = this->spec.size / this->spec.channels;
if (this->spec.format == AUDIO_U16SYS || this->spec.format == AUDIO_S16SYS)
this->spec.samples /= 2;
_this->spec.silence = (_this->spec.format == AUDIO_U8 ? 0x80 : 0);
_this->spec.samples = _this->spec.size / _this->spec.channels;
if (_this->spec.format == AUDIO_U16SYS || _this->spec.format == AUDIO_S16SYS)
_this->spec.samples /= 2;
sprintf(buff, "obtained size is %d, samples %d\n", this->spec.size, this->spec.samples);
sprintf(buff, "obtained size is %d, samples %d\n", _this->spec.size, _this->spec.samples);
_ksys_debug_puts(buff);
return 0;

View File

@@ -2,8 +2,8 @@
#ifndef SDL_kolibriaudio_h_
#define SDL_kolibriaudio_h_
#define _THIS SDL_AudioDevice *this
#define private this->hidden
#define _THIS SDL_AudioDevice *_this
#define private _this->hidden
typedef struct SDL_PrivateAudioData
{