Skip to content

Commit 8c09a10

Browse files
committed
Added support for AL_EXT_trace_info to some of the test apps.
1 parent ee5cfb7 commit 8c09a10

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

tests/testcapture.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
#include "AL/alc.h"
1515
#include "SDL.h"
1616

17+
static LPALCTRACEDEVICELABEL palcTraceDeviceLabel;
18+
static LPALCTRACECONTEXTLABEL palcTraceContextLabel;
19+
static LPALTRACEPUSHSCOPE palTracePushScope;
20+
static LPALTRACEPOPSCOPE palTracePopScope;
21+
static LPALTRACEMESSAGE palTraceMessage;
22+
static LPALTRACEBUFFERLABEL palTraceBufferLabel;
23+
static LPALTRACESOURCELABEL palTraceSourceLabel;
24+
1725
static int check_openal_error(const char *where)
1826
{
1927
const ALenum err = alGetError();
@@ -56,28 +64,48 @@ int main(int argc, char **argv)
5664
return 2;
5765
}
5866

67+
if (alcIsExtensionPresent(device, "ALC_EXT_trace_info")) {
68+
palcTraceDeviceLabel = (LPALCTRACEDEVICELABEL) alcGetProcAddress(device, "alcTraceDeviceLabel");
69+
palcTraceContextLabel = (LPALCTRACECONTEXTLABEL) alcGetProcAddress(device, "alcTraceContextLabel");
70+
}
71+
5972
context = alcCreateContext(device, NULL);
6073
check_openal_alc_error(device, "alcCreateContext");
6174
if (!context) {
6275
printf("Couldn't create OpenAL context.\n");
6376
alcCloseDevice(device);
6477
return 3;
6578
}
66-
79+
80+
if (palcTraceDeviceLabel) palcTraceDeviceLabel(device, "The playback device");
81+
if (palcTraceContextLabel) palcTraceContextLabel(context, "Main context");
82+
6783
alcMakeContextCurrent(context);
6884
check_openal_alc_error(device, "alcMakeContextCurrent");
6985

86+
if (alIsExtensionPresent("AL_EXT_trace_info")) {
87+
palTracePushScope = (LPALTRACEPUSHSCOPE) alGetProcAddress("alTracePushScope");
88+
palTracePopScope = (LPALTRACEPOPSCOPE) alGetProcAddress("alTracePopScope");
89+
palTraceMessage = (LPALTRACEMESSAGE) alGetProcAddress("alTraceMessage");
90+
palTraceBufferLabel = (LPALTRACEBUFFERLABEL) alGetProcAddress("alTraceBufferLabel");
91+
palTraceSourceLabel = (LPALTRACESOURCELABEL) alGetProcAddress("alTraceSourceLabel");
92+
}
93+
7094
capture = alcCaptureOpenDevice(NULL, freq, alfmt, total_samples);
7195
check_openal_alc_error(capture, "alcCaptureOpenDevice");
7296
if (!capture) {
7397
printf("Couldn't open OpenAL default capture device.\n");
7498
return 4;
7599
}
76100

101+
if (palcTraceDeviceLabel) palcTraceDeviceLabel(capture, "The recording device");
102+
77103
if (alcIsExtensionPresent(capture, "ALC_EXT_DISCONNECT")) {
78104
alc_connected = alcGetEnumValue(capture, "ALC_CONNECTED");
79105
}
80106

107+
if (palTracePushScope) palTracePushScope("Recording");
108+
81109
printf("recording...\n");
82110
alcCaptureStart(capture);
83111
check_openal_alc_error(capture, "alcCaptureStart");
@@ -103,9 +131,13 @@ int main(int argc, char **argv)
103131
alcCaptureCloseDevice(capture);
104132
check_openal_alc_error(NULL, "alcCaptureCloseDevice");
105133

134+
if (palTracePopScope) palTracePopScope();
135+
106136
alGenSources(1, &sid);
137+
if (palTraceSourceLabel) palTraceSourceLabel(sid, "Playback source");
107138
check_openal_error("alGenSources");
108139
alGenBuffers(1, &bid);
140+
if (palTraceSourceLabel) palTraceBufferLabel(bid, "Recorded audio");
109141
check_openal_error("alGenBuffers");
110142

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

152+
if (palTracePushScope) palTracePushScope("Playing");
153+
120154
do {
121155
SDL_Delay(100);
122156
alGetSourceiv(sid, AL_SOURCE_STATE, &state);
123157
check_openal_error("alGetSourceiv");
124158
} while (state == AL_PLAYING);
125159

160+
if (palTracePopScope) palTracePopScope();
161+
126162
if (alcIsExtensionPresent(device, "ALC_EXT_DISCONNECT")) {
127163
alc_connected = alcGetEnumValue(device, "ALC_CONNECTED");
128164
check_openal_alc_error(device, "alcGetEnumValue");
@@ -133,6 +169,8 @@ int main(int argc, char **argv)
133169
}
134170
}
135171

172+
if (palTracePushScope) palTracePushScope("Cleanup");
173+
136174
printf("Cleaning up...\n");
137175

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

188+
if (palTracePopScope) palTracePopScope();
189+
150190
printf("Done!\n");
151191
return 0;
152192
}

tests/testposition.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
#include <emscripten.h>
1919
#endif
2020

21+
22+
static LPALCTRACEDEVICELABEL palcTraceDeviceLabel;
23+
static LPALCTRACECONTEXTLABEL palcTraceContextLabel;
24+
static LPALTRACEPUSHSCOPE palTracePushScope;
25+
static LPALTRACEPOPSCOPE palTracePopScope;
26+
static LPALTRACEMESSAGE palTraceMessage;
27+
static LPALTRACEBUFFERLABEL palTraceBufferLabel;
28+
static LPALTRACESOURCELABEL palTraceSourceLabel;
29+
2130
static int check_openal_error(const char *where)
2231
{
2332
const ALenum err = alGetError();
@@ -91,8 +100,10 @@ static int mainloop(SDL_Renderer *renderer)
91100
case SDL_MOUSEBUTTONDOWN:
92101
if (e.button.button == 1) {
93102
if (e.button.state == SDL_RELEASED) {
103+
if (palTraceMessage) palTraceMessage("Mouse button released");
94104
draggingobj = -1;
95105
} else {
106+
if (palTraceMessage) palTraceMessage("Mouse button pressed");
96107
draggingobj = obj_under_mouse(e.button.x, e.button.y);
97108
}
98109
}
@@ -170,12 +181,16 @@ static void spatialize(SDL_Renderer *renderer, const char *fname)
170181

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

184+
if (palTracePushScope) palTracePushScope("Initial setup");
185+
173186
alGenSources(1, &sid);
174187
if (check_openal_error("alGenSources")) {
175188
SDL_FreeWAV(buf);
176189
return;
177190
}
178191

192+
if (palTraceSourceLabel) palTraceSourceLabel(sid, "Moving source");
193+
179194
alGenBuffers(1, &bid);
180195
if (check_openal_error("alGenBuffers")) {
181196
alDeleteSources(1, &sid);
@@ -184,6 +199,8 @@ static void spatialize(SDL_Renderer *renderer, const char *fname)
184199
return;
185200
}
186201

202+
if (palTraceBufferLabel) palTraceBufferLabel(bid, "Sound effect");
203+
187204
alBufferData(bid, alfmt, buf, buflen, spec.freq);
188205
SDL_FreeWAV(buf);
189206
check_openal_error("alBufferData");
@@ -207,12 +224,15 @@ static void spatialize(SDL_Renderer *renderer, const char *fname)
207224
alSource3f(o->sid, AL_POSITION, ((o->x / 400.0f) - 1.0f) * 10.0f, 0.0f, ((o->y / 300.0f) - 1.0f) * 10.0f);
208225
o++;
209226

227+
if (palTracePopScope) palTracePopScope();
228+
210229
#ifdef __EMSCRIPTEN__
211230
emscripten_set_main_loop_arg(emscriptenMainloop, renderer, 0, 1);
212231
#else
213232
while (mainloop(renderer)) { /* go again */ }
214233
#endif
215234

235+
216236
//alSourcei(sid, AL_BUFFER, 0); /* force unqueueing */
217237
alDeleteSources(1, &sid);
218238
check_openal_error("alDeleteSources");
@@ -270,6 +290,11 @@ int main(int argc, char **argv)
270290
return 5;
271291
}
272292

293+
if (alcIsExtensionPresent(device, "ALC_EXT_trace_info")) {
294+
palcTraceDeviceLabel = (LPALCTRACEDEVICELABEL) alcGetProcAddress(device, "alcTraceDeviceLabel");
295+
palcTraceContextLabel = (LPALCTRACECONTEXTLABEL) alcGetProcAddress(device, "alcTraceContextLabel");
296+
}
297+
273298
context = alcCreateContext(device, NULL);
274299
if (!context) {
275300
printf("Couldn't create OpenAL context.\n");
@@ -279,9 +304,20 @@ int main(int argc, char **argv)
279304
SDL_Quit();
280305
return 6;
281306
}
282-
307+
308+
if (palcTraceDeviceLabel) palcTraceDeviceLabel(device, "The playback device");
309+
if (palcTraceContextLabel) palcTraceContextLabel(context, "Main context");
310+
283311
alcMakeContextCurrent(context);
284312

313+
if (alIsExtensionPresent("AL_EXT_trace_info")) {
314+
palTracePushScope = (LPALTRACEPUSHSCOPE) alGetProcAddress("alTracePushScope");
315+
palTracePopScope = (LPALTRACEPOPSCOPE) alGetProcAddress("alTracePopScope");
316+
palTraceMessage = (LPALTRACEMESSAGE) alGetProcAddress("alTraceMessage");
317+
palTraceBufferLabel = (LPALTRACEBUFFERLABEL) alGetProcAddress("alTraceBufferLabel");
318+
palTraceSourceLabel = (LPALTRACESOURCELABEL) alGetProcAddress("alTraceSourceLabel");
319+
}
320+
285321
spatialize(renderer, argv[1]);
286322

287323
alcMakeContextCurrent(NULL);

0 commit comments

Comments
 (0)