Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added support for AL_EXT_trace_info to some of the test apps.
  • Loading branch information
icculus committed Sep 19, 2019
1 parent ee5cfb7 commit 8c09a10
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
42 changes: 41 additions & 1 deletion tests/testcapture.c
Expand Up @@ -14,6 +14,14 @@
#include "AL/alc.h"
#include "SDL.h"

static LPALCTRACEDEVICELABEL palcTraceDeviceLabel;
static LPALCTRACECONTEXTLABEL palcTraceContextLabel;
static LPALTRACEPUSHSCOPE palTracePushScope;
static LPALTRACEPOPSCOPE palTracePopScope;
static LPALTRACEMESSAGE palTraceMessage;
static LPALTRACEBUFFERLABEL palTraceBufferLabel;
static LPALTRACESOURCELABEL palTraceSourceLabel;

static int check_openal_error(const char *where)
{
const ALenum err = alGetError();
Expand Down Expand Up @@ -56,28 +64,48 @@ int main(int argc, char **argv)
return 2;
}

if (alcIsExtensionPresent(device, "ALC_EXT_trace_info")) {
palcTraceDeviceLabel = (LPALCTRACEDEVICELABEL) alcGetProcAddress(device, "alcTraceDeviceLabel");
palcTraceContextLabel = (LPALCTRACECONTEXTLABEL) alcGetProcAddress(device, "alcTraceContextLabel");
}

context = alcCreateContext(device, NULL);
check_openal_alc_error(device, "alcCreateContext");
if (!context) {
printf("Couldn't create OpenAL context.\n");
alcCloseDevice(device);
return 3;
}


if (palcTraceDeviceLabel) palcTraceDeviceLabel(device, "The playback device");
if (palcTraceContextLabel) palcTraceContextLabel(context, "Main context");

alcMakeContextCurrent(context);
check_openal_alc_error(device, "alcMakeContextCurrent");

if (alIsExtensionPresent("AL_EXT_trace_info")) {
palTracePushScope = (LPALTRACEPUSHSCOPE) alGetProcAddress("alTracePushScope");
palTracePopScope = (LPALTRACEPOPSCOPE) alGetProcAddress("alTracePopScope");
palTraceMessage = (LPALTRACEMESSAGE) alGetProcAddress("alTraceMessage");
palTraceBufferLabel = (LPALTRACEBUFFERLABEL) alGetProcAddress("alTraceBufferLabel");
palTraceSourceLabel = (LPALTRACESOURCELABEL) alGetProcAddress("alTraceSourceLabel");
}

capture = alcCaptureOpenDevice(NULL, freq, alfmt, total_samples);
check_openal_alc_error(capture, "alcCaptureOpenDevice");
if (!capture) {
printf("Couldn't open OpenAL default capture device.\n");
return 4;
}

if (palcTraceDeviceLabel) palcTraceDeviceLabel(capture, "The recording device");

if (alcIsExtensionPresent(capture, "ALC_EXT_DISCONNECT")) {
alc_connected = alcGetEnumValue(capture, "ALC_CONNECTED");
}

if (palTracePushScope) palTracePushScope("Recording");

printf("recording...\n");
alcCaptureStart(capture);
check_openal_alc_error(capture, "alcCaptureStart");
Expand All @@ -103,9 +131,13 @@ int main(int argc, char **argv)
alcCaptureCloseDevice(capture);
check_openal_alc_error(NULL, "alcCaptureCloseDevice");

if (palTracePopScope) palTracePopScope();

alGenSources(1, &sid);
if (palTraceSourceLabel) palTraceSourceLabel(sid, "Playback source");
check_openal_error("alGenSources");
alGenBuffers(1, &bid);
if (palTraceSourceLabel) palTraceBufferLabel(bid, "Recorded audio");
check_openal_error("alGenBuffers");

printf("Playing...\n");
Expand All @@ -117,12 +149,16 @@ int main(int argc, char **argv)
alSourcePlay(sid);
check_openal_error("alSourcePlay");

if (palTracePushScope) palTracePushScope("Playing");

do {
SDL_Delay(100);
alGetSourceiv(sid, AL_SOURCE_STATE, &state);
check_openal_error("alGetSourceiv");
} while (state == AL_PLAYING);

if (palTracePopScope) palTracePopScope();

if (alcIsExtensionPresent(device, "ALC_EXT_DISCONNECT")) {
alc_connected = alcGetEnumValue(device, "ALC_CONNECTED");
check_openal_alc_error(device, "alcGetEnumValue");
Expand All @@ -133,6 +169,8 @@ int main(int argc, char **argv)
}
}

if (palTracePushScope) palTracePushScope("Cleanup");

printf("Cleaning up...\n");

alDeleteSources(1, &sid);
Expand All @@ -147,6 +185,8 @@ int main(int argc, char **argv)
alcCloseDevice(device);
check_openal_alc_error(NULL, "alcCloseDevice");

if (palTracePopScope) palTracePopScope();

printf("Done!\n");
return 0;
}
Expand Down
38 changes: 37 additions & 1 deletion tests/testposition.c
Expand Up @@ -18,6 +18,15 @@
#include <emscripten.h>
#endif


static LPALCTRACEDEVICELABEL palcTraceDeviceLabel;
static LPALCTRACECONTEXTLABEL palcTraceContextLabel;
static LPALTRACEPUSHSCOPE palTracePushScope;
static LPALTRACEPOPSCOPE palTracePopScope;
static LPALTRACEMESSAGE palTraceMessage;
static LPALTRACEBUFFERLABEL palTraceBufferLabel;
static LPALTRACESOURCELABEL palTraceSourceLabel;

static int check_openal_error(const char *where)
{
const ALenum err = alGetError();
Expand Down Expand Up @@ -91,8 +100,10 @@ static int mainloop(SDL_Renderer *renderer)
case SDL_MOUSEBUTTONDOWN:
if (e.button.button == 1) {
if (e.button.state == SDL_RELEASED) {
if (palTraceMessage) palTraceMessage("Mouse button released");
draggingobj = -1;
} else {
if (palTraceMessage) palTraceMessage("Mouse button pressed");
draggingobj = obj_under_mouse(e.button.x, e.button.y);
}
}
Expand Down Expand Up @@ -170,12 +181,16 @@ static void spatialize(SDL_Renderer *renderer, const char *fname)

printf("Now queueing '%s'...\n", fname);

if (palTracePushScope) palTracePushScope("Initial setup");

alGenSources(1, &sid);
if (check_openal_error("alGenSources")) {
SDL_FreeWAV(buf);
return;
}

if (palTraceSourceLabel) palTraceSourceLabel(sid, "Moving source");

alGenBuffers(1, &bid);
if (check_openal_error("alGenBuffers")) {
alDeleteSources(1, &sid);
Expand All @@ -184,6 +199,8 @@ static void spatialize(SDL_Renderer *renderer, const char *fname)
return;
}

if (palTraceBufferLabel) palTraceBufferLabel(bid, "Sound effect");

alBufferData(bid, alfmt, buf, buflen, spec.freq);
SDL_FreeWAV(buf);
check_openal_error("alBufferData");
Expand All @@ -207,12 +224,15 @@ static void spatialize(SDL_Renderer *renderer, const char *fname)
alSource3f(o->sid, AL_POSITION, ((o->x / 400.0f) - 1.0f) * 10.0f, 0.0f, ((o->y / 300.0f) - 1.0f) * 10.0f);
o++;

if (palTracePopScope) palTracePopScope();

#ifdef __EMSCRIPTEN__
emscripten_set_main_loop_arg(emscriptenMainloop, renderer, 0, 1);
#else
while (mainloop(renderer)) { /* go again */ }
#endif


//alSourcei(sid, AL_BUFFER, 0); /* force unqueueing */
alDeleteSources(1, &sid);
check_openal_error("alDeleteSources");
Expand Down Expand Up @@ -270,6 +290,11 @@ int main(int argc, char **argv)
return 5;
}

if (alcIsExtensionPresent(device, "ALC_EXT_trace_info")) {
palcTraceDeviceLabel = (LPALCTRACEDEVICELABEL) alcGetProcAddress(device, "alcTraceDeviceLabel");
palcTraceContextLabel = (LPALCTRACECONTEXTLABEL) alcGetProcAddress(device, "alcTraceContextLabel");
}

context = alcCreateContext(device, NULL);
if (!context) {
printf("Couldn't create OpenAL context.\n");
Expand All @@ -279,9 +304,20 @@ int main(int argc, char **argv)
SDL_Quit();
return 6;
}


if (palcTraceDeviceLabel) palcTraceDeviceLabel(device, "The playback device");
if (palcTraceContextLabel) palcTraceContextLabel(context, "Main context");

alcMakeContextCurrent(context);

if (alIsExtensionPresent("AL_EXT_trace_info")) {
palTracePushScope = (LPALTRACEPUSHSCOPE) alGetProcAddress("alTracePushScope");
palTracePopScope = (LPALTRACEPOPSCOPE) alGetProcAddress("alTracePopScope");
palTraceMessage = (LPALTRACEMESSAGE) alGetProcAddress("alTraceMessage");
palTraceBufferLabel = (LPALTRACEBUFFERLABEL) alGetProcAddress("alTraceBufferLabel");
palTraceSourceLabel = (LPALTRACESOURCELABEL) alGetProcAddress("alTraceSourceLabel");
}

spatialize(renderer, argv[1]);

alcMakeContextCurrent(NULL);
Expand Down

0 comments on commit 8c09a10

Please sign in to comment.