14
14
#include "AL/alc.h"
15
15
#include "SDL.h"
16
16
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
+
17
25
static int check_openal_error (const char * where )
18
26
{
19
27
const ALenum err = alGetError ();
@@ -56,28 +64,48 @@ int main(int argc, char **argv)
56
64
return 2 ;
57
65
}
58
66
67
+ if (alcIsExtensionPresent (device , "ALC_EXT_trace_info" )) {
68
+ palcTraceDeviceLabel = (LPALCTRACEDEVICELABEL ) alcGetProcAddress (device , "alcTraceDeviceLabel" );
69
+ palcTraceContextLabel = (LPALCTRACECONTEXTLABEL ) alcGetProcAddress (device , "alcTraceContextLabel" );
70
+ }
71
+
59
72
context = alcCreateContext (device , NULL );
60
73
check_openal_alc_error (device , "alcCreateContext" );
61
74
if (!context ) {
62
75
printf ("Couldn't create OpenAL context.\n" );
63
76
alcCloseDevice (device );
64
77
return 3 ;
65
78
}
66
-
79
+
80
+ if (palcTraceDeviceLabel ) palcTraceDeviceLabel (device , "The playback device" );
81
+ if (palcTraceContextLabel ) palcTraceContextLabel (context , "Main context" );
82
+
67
83
alcMakeContextCurrent (context );
68
84
check_openal_alc_error (device , "alcMakeContextCurrent" );
69
85
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
+
70
94
capture = alcCaptureOpenDevice (NULL , freq , alfmt , total_samples );
71
95
check_openal_alc_error (capture , "alcCaptureOpenDevice" );
72
96
if (!capture ) {
73
97
printf ("Couldn't open OpenAL default capture device.\n" );
74
98
return 4 ;
75
99
}
76
100
101
+ if (palcTraceDeviceLabel ) palcTraceDeviceLabel (capture , "The recording device" );
102
+
77
103
if (alcIsExtensionPresent (capture , "ALC_EXT_DISCONNECT" )) {
78
104
alc_connected = alcGetEnumValue (capture , "ALC_CONNECTED" );
79
105
}
80
106
107
+ if (palTracePushScope ) palTracePushScope ("Recording" );
108
+
81
109
printf ("recording...\n" );
82
110
alcCaptureStart (capture );
83
111
check_openal_alc_error (capture , "alcCaptureStart" );
@@ -103,9 +131,13 @@ int main(int argc, char **argv)
103
131
alcCaptureCloseDevice (capture );
104
132
check_openal_alc_error (NULL , "alcCaptureCloseDevice" );
105
133
134
+ if (palTracePopScope ) palTracePopScope ();
135
+
106
136
alGenSources (1 , & sid );
137
+ if (palTraceSourceLabel ) palTraceSourceLabel (sid , "Playback source" );
107
138
check_openal_error ("alGenSources" );
108
139
alGenBuffers (1 , & bid );
140
+ if (palTraceSourceLabel ) palTraceBufferLabel (bid , "Recorded audio" );
109
141
check_openal_error ("alGenBuffers" );
110
142
111
143
printf ("Playing...\n" );
@@ -117,12 +149,16 @@ int main(int argc, char **argv)
117
149
alSourcePlay (sid );
118
150
check_openal_error ("alSourcePlay" );
119
151
152
+ if (palTracePushScope ) palTracePushScope ("Playing" );
153
+
120
154
do {
121
155
SDL_Delay (100 );
122
156
alGetSourceiv (sid , AL_SOURCE_STATE , & state );
123
157
check_openal_error ("alGetSourceiv" );
124
158
} while (state == AL_PLAYING );
125
159
160
+ if (palTracePopScope ) palTracePopScope ();
161
+
126
162
if (alcIsExtensionPresent (device , "ALC_EXT_DISCONNECT" )) {
127
163
alc_connected = alcGetEnumValue (device , "ALC_CONNECTED" );
128
164
check_openal_alc_error (device , "alcGetEnumValue" );
@@ -133,6 +169,8 @@ int main(int argc, char **argv)
133
169
}
134
170
}
135
171
172
+ if (palTracePushScope ) palTracePushScope ("Cleanup" );
173
+
136
174
printf ("Cleaning up...\n" );
137
175
138
176
alDeleteSources (1 , & sid );
@@ -147,6 +185,8 @@ int main(int argc, char **argv)
147
185
alcCloseDevice (device );
148
186
check_openal_alc_error (NULL , "alcCloseDevice" );
149
187
188
+ if (palTracePopScope ) palTracePopScope ();
189
+
150
190
printf ("Done!\n" );
151
191
return 0 ;
152
192
}
0 commit comments