Free Electron
AudioAL.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __openal_AudioAL_h__
8 #define __openal_AudioAL_h__
9 
10 #define FE_RETURN_AL_ERROR(text) \
11  { Result al_result=checkError(text); \
12  if(failure(al_result)) return al_result; }
13 namespace fe
14 {
15 namespace ext
16 {
17 
18 /**************************************************************************//**
19  @brief Audio handling using OpenAL
20 
21  @ingroup openal
22 
23  http://www.openal.org
24 *//***************************************************************************/
25 class AudioAL:
26  virtual public AudioI,
27  public CastableAs<AudioAL>
28 {
29  public:
30  AudioAL(void);
31 virtual ~AudioAL(void);
32 
33  //* As AudioI
34 virtual Result load(String name,String filename);
35 virtual Result unload(String name);
36 virtual Result flush(void);
37 
38  void remember(sp<VoiceI> spVoiceI);
39  void forget(sp<VoiceI> spVoiceI);
40 
41  ALuint lookup(String name) const;
42 static Result checkError(String text);
43 
44  private:
45  void forgetAll(void);
46 
47  typedef HashMap<String,ALuint,hash_string,eq_string> BufferMap;
48 
49  ALCdevice* m_pDevice;
50  ALCcontext* m_pContext;
51 
52  BufferMap m_bufferMap;
53 
54  List< hp<VoiceI> > m_chorus; // persistent voices
55 };
56 
57 inline ALuint AudioAL::lookup(String name) const
58 {
59  BufferMap::const_iterator it=m_bufferMap.find(name);
60  if(it==m_bufferMap.end())
61  {
62  return ALuint(-1);
63  }
64 
65  return it->second;
66 }
67 
68 inline Result AudioAL::checkError(String text)
69 {
70  ALuint error=alGetError();
71  switch(error)
72  {
73  case AL_NO_ERROR:
74  return e_ok;
75  case AL_INVALID_NAME:
76  feLog("AudioAL::checkError AL_INVALID_NAME (%s)\n",text.c_str());
77  return e_invalidHandle;
78  case AL_INVALID_ENUM:
79  feLog("AudioAL::checkError AL_INVALID_ENUM (%s)\n",text.c_str());
80  return e_unsupported;
81  case AL_INVALID_VALUE:
82  feLog("AudioAL::checkError AL_INVALID_VALUE (%s)\n",text.c_str());
83  return e_invalidRange;
84  case AL_INVALID_OPERATION:
85  feLog("AudioAL::checkError AL_INVALID_OPERATION (%s)\n",
86  text.c_str());
87  return e_unsupported;
88  case AL_OUT_OF_MEMORY:
89  feLog("AudioAL::checkError AL_OUT_OF_MEMORY (%s)\n",text.c_str());
90  return e_outOfMemory;
91  default:
92  feLog("AudioAL::checkError undefined error (%s)\n",text.c_str());
93  return e_undefinedFailure;
94  }
95 }
96 
97 } /* namespace ext */
98 } /* namespace fe */
99 
100 #endif /* __openal_AudioAL_h__ */
Fully Bidirectional Doubly-Linked List.
Definition: List.h:496
const FESTRING_I8 * c_str(void) const
Return the contents of the 8-bit buffer cast as signed bytes.
Definition: String.h:352
kernel
Definition: namespace.dox:3
Automatically reference-counted string container.
Definition: String.h:128
Result
Generalized return value indicating success or failure, and why.
Definition: Result.h:24
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
const String & name(void) const
Return the components chosen name.
Definition: Component.h:77
Audio handling using OpenAL.
Definition: AudioAL.h:25
Sound system.
Definition: AudioI.h:19
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192