1 /*
2  * Copyright (c) 2000 Mark B. Allan. All rights reserved.
3  *
4  * "Chromium B.S.U." is free software; you can redistribute
5  * it and/or use it and/or modify it under the terms of the
6  * "Clarified Artistic License"
7  */
8 #ifndef AudioOpenAL_h
9 #define AudioOpenAL_h
10 
11 #ifdef HAVE_CONFIG_H
12 #include <chromium-bsu-config.h>
13 #endif
14 
15 #ifdef AUDIO_OPENAL
16 
17 #include "Audio.h"
18 
19 #ifdef HAVE_OPENAL_AL_H
20 #include <OpenAL/al.h>
21 #elif defined(HAVE_AL_AL_H)
22 #include <AL/al.h>
23 #endif
24 
25 #ifdef HAVE_ALUT_ALUT_H
26 #include <ALUT/alut.h>
27 #elif defined(HAVE_AL_ALUT_H)
28 #include <AL/alut.h>
29 #endif
30 
31 /**
32  * Use OpenAL for sound effects (positional audio) as well as music
33  * playback if playlist support is selected.
34  */
35 //====================================================================
36 class AudioOpenAL	: public Audio
37 {
38 public:
39 	AudioOpenAL();
40 	~AudioOpenAL();
41 
42 	virtual void	update();
43 	virtual void	playSound(SoundType type, float *pos, int age = 0);
44 	virtual void	stopMusic();
45 	virtual void	pauseGameMusic(bool);
46 	virtual void	setMusicMode(SoundType);
47 	virtual void	setMusicVolume(float);
48 	virtual void	setSoundVolume(float);
49 	virtual void	setMusicIndex(int);
50 
51 protected:
52 	virtual void	initSound();
53 
54 	bool	createContext();
55 	void	loadSounds();
56 
57 private:
58 	void	checkError(const char* tag = "");
59 
60 	void	playSoundExplosion(float pos[3]);
61 	void	playSoundExploPop(float pos[3]);
62 
63 	//-- OpenAL extensions
64 	void		checkForExtensions();
65 	void		(*alAttenuationScale)(ALfloat param);
66 	void		(*alcSetAudioChannel)(ALuint channel, ALfloat volume);
67 	float		(*alcGetAudioChannel)(ALuint channel);
68 	ALboolean	(*alutLoadMP3)(ALuint, ALvoid *, ALint);
69 	ALboolean	(*alutLoadVorbis)(ALuint, ALvoid *, ALint);
70 
71 	//-- Format loaders
72 	bool	loadWAV(const char* filename);
73 	bool	loadMP3(const char* filename);
74 	bool	loadVorbis(const char* filename);
75 
76 private:
77 	ALuint	buffer[NumSoundTypes];
78 	ALuint	source[NumSoundTypes];
79 	ALfloat	sourcePos[NumSoundTypes][3];
80 
81 	ALuint	sourceExplosion[NUM_EXPLO];
82 	ALuint	sourceExploPop[NUM_EXPLO_POP];
83 	int		explosionIndex;
84 	int		exploPopIndex;
85 	int		numReqThisFrame[NumSoundTypes];
86 
87 	ALfloat	gain[NumSoundTypes];
88 
89 	/** audio formats for playList. Determined my file extension */
90 	enum AudioFormat	{
91 							Unknown = -1,	/**< error condition */
92 							WAV,			/**< .wav extension */
93 							MP3,			/**< .mp3 extension */
94 							OGG,			/**< .ogg extension */
95 							NumAudioFormats	/**< number of available extensions */
96 						};
97 	AudioFormat	extensionFormat(char*);
98 	void		loadMusicList();
99 
100 	float	origCDvolume;
101 
102 	ALCdevice	*dev;
103 	ALCcontext	*context_id;
104 	bool	initialized;
105 	float	audioScale[3];
106 
107 	float	soundVolume;
108 	float	musicVolume;
109 
110 	SoundInfo	*soundQueue;
111 };
112 
113 #endif // AUDIO_OPENAL
114 
115 #endif // AudioOpenAL_h
116