1 /*
2 	This file is part of Warzone 2100.
3 	Copyright (C) 2007  Giel van Schijndel
4 	Copyright (C) 2007-2020  Warzone 2100 Project
5 
6 	Warzone 2100 is free software; you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation; either version 2 of the License, or
9 	(at your option) any later version.
10 
11 	Warzone 2100 is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with Warzone 2100; if not, write to the Free Software
18 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include "lib/framework/frame.h"
21 
22 #include "openal_error.h"
23 
24 #include "lib/framework/stdio_ext.h"
25 
26 #include <AL/al.h>
27 #include <AL/alc.h>
28 
__sound_GetError(const char * location_description)29 ALenum __sound_GetError(const char *location_description)
30 {
31 	const char *errorString = nullptr;
32 	ALenum error = alGetError();
33 
34 	if (error == AL_NO_ERROR)
35 	{
36 		return error;
37 	}
38 
39 	switch (error)
40 	{
41 	case AL_INVALID_NAME:
42 		errorString = "AL_INVALID_NAME: Invalid name parameter passed";
43 		break;
44 
45 	case AL_INVALID_ENUM:
46 		errorString = "AL_INVALID_ENUM: Invalid enum value";
47 		break;
48 
49 	case AL_INVALID_VALUE:
50 		errorString = "AL_INVALID_VALUE: Invalid parameter value";
51 		break;
52 
53 	case AL_INVALID_OPERATION:
54 		errorString = "AL_INVALID_OPERATION: Illegal call";
55 		break;
56 
57 	case AL_OUT_OF_MEMORY:
58 		errorString = "AL_OUT_OF_MEMORY: OpenAL ran out of memory";
59 		break;
60 
61 	default:
62 		errorString = nullptr;
63 		debug(LOG_SOUND, "OpenAL raised an unknown error code (%d), at %s. Please report this number "
64 				  "(along with the fact that it is an \"unknown OpenAL error code\"): 0x%x", (int)error, location_description, (unsigned int)error);
65 		break;
66 	}
67 
68 	if (errorString)
69 	{
70 		debug(LOG_SOUND, "OpenAL raised an error: \"%s\"; at %s", errorString, location_description);
71 	}
72 
73 	return error;
74 }
75 
__sound_GetContextError(ALCdevice * device,const char * location_description)76 ALenum __sound_GetContextError(ALCdevice *device, const char *location_description)
77 {
78 	const char *errorString = nullptr;
79 	ALCenum error = alcGetError(device);
80 
81 	if (error == ALC_NO_ERROR)
82 	{
83 		return error;
84 	}
85 
86 	switch (error)
87 	{
88 	case ALC_INVALID_DEVICE:
89 		errorString = "ALC_INVALID_DEVICE: Invalid or no device selected";
90 		break;
91 
92 	case ALC_INVALID_CONTEXT:
93 		errorString = "ALC_INVALID_CONTEXT: Invalid or no context selected";
94 		break;
95 
96 	case ALC_INVALID_ENUM:
97 		errorString = "ALC_INVALID_ENUM: Invalid enum value";
98 		break;
99 
100 	case ALC_INVALID_VALUE:
101 		errorString = "ALC_INVALID_VALUE: Invalid parameter value";
102 		break;
103 
104 	case ALC_OUT_OF_MEMORY:
105 		errorString = "ALC_OUT_OF_MEMORY: OpenAL ran out of memory";
106 		break;
107 
108 	default:
109 		errorString = nullptr;
110 		debug(LOG_SOUND, "OpenAL raised an unknown context error code (%d), at %s. Please report this number "
111 				  "(along with the fact that it is an \"unknown OpenAL error code\"): 0x%x", (int)error, location_description, (unsigned int)error);
112 		break;
113 	}
114 
115 	if (errorString)
116 	{
117 		debug(LOG_SOUND, "OpenAL raised a context error: \"%s\"; at %s", errorString, location_description);
118 	}
119 
120 	return error;
121 }
122