1 ////////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2010 by The Allacrost Project
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ////////////////////////////////////////////////////////////////////////////////
9 
10 /** ****************************************************************************
11 *** \file   audio_effects.h
12 *** \author Mois�s Ferrer Serra, byaku@allacrost.org
13 *** \brief  Header file for audio effects
14 ***
15 *** This code provides the interface for effects, as well as the private classes
16 *** used for build all the audio fx system
17 ***
18 *** \todo Add an effect class that modifies an audio's position over time,
19 *** which will allow support for panning effects
20 *** ***************************************************************************/
21 
22 #ifndef __AUDIO_EFFECTS_HEADER__
23 #define __AUDIO_EFFECTS_HEADER__
24 
25 #ifdef __MACH__
26 	#include <OpenAL/al.h>
27 	#include <OpenAL/alc.h>
28 #else
29 	#include "al.h"
30 	#include "alc.h"
31 #endif
32 
33 #include "defs.h"
34 #include "utils.h"
35 
36 #include "audio_descriptor.h"
37 
38 namespace hoa_audio {
39 
40 namespace private_audio {
41 
42 /** ****************************************************************************
43 *** \brief An abstract base class for all audio effects to be derived from
44 ***
45 *** The purpose of this class is nothing more than to provide a simple common
46 *** interface for all audio effects, primarily so that they may be stored in
47 *** the same container. Most effects will only operate upon a single piece of
48 *** audio, but some effects may operate across multiple audio descriptors.
49 *** ***************************************************************************/
50 class AudioEffect {
51 public:
AudioEffect()52 	AudioEffect() :
53 		active(true) {}
54 
~AudioEffect()55 	virtual ~AudioEffect()
56 		{}
57 
58 	//! \brief Set to true while an effect is active, and set to false when the effect is finished
59 	bool active;
60 
61 	//! \brief Updates the effect and sets the active member to false when the effect is finished
62 	virtual void Update() = 0;
63 }; // class AudioEffect
64 
65 
66 /** ****************************************************************************
67 *** \brief Gradually fades a playing audio source in from mute to current volume
68 ***
69 *** This class will set the AudioDescriptor's volume level to 0.0f (mute) upon
70 *** being created, and will gradually restore the volume to its original level
71 *** over time.
72 *** ***************************************************************************/
73 class FadeInEffect : public AudioEffect {
74 public:
75 	/** \brief Constructor for the fade in effect.
76 	*** \param audio A reference to the AudioDescriptor of the audio to fade
77 	*** \param time The amount of time that the effect will take, in seconds
78 	**/
79 	FadeInEffect(AudioDescriptor& audio, float time);
80 
81 	//! \brief Gradually increases the volume until the original volume level is restored
82 	void Update();
83 
84 private:
85 	//! \brief The volume of the audio when the effect was registered
86 	float _original_volume;
87 
88 	//! \brief The amount of time that the effect lasts for
89 	float _effect_time;
90 
91 	//! \brief A reference to the audio to process the effect upon
92 	AudioDescriptor& _audio;
93 }; // class FadeInEffect : public AudioEffect {
94 
95 
96 /** ****************************************************************************
97 *** \brief Gradually fades a playing audio source from its current volume to silence
98 ***
99 *** Once this class effectively mutes the audio by setting it to 0.0f, the audio
100 *** will automatically be set in the stop state and indicate that the effect
101 *** has finished. The original volume of the audio is restored after it has
102 *** stopped playing
103 *** ***************************************************************************/
104 class FadeOutEffect : public AudioEffect {
105 public:
106 	/** \brief Constructor for the fade out effect.
107 	*** \param audio A reference to the AudioDescriptor of the audio to fade
108 	*** \param time The amount of time that the effect will take, in seconds
109 	**/
110 	FadeOutEffect(AudioDescriptor& audio, float time);
111 
112 	//! \brief Gradually decreases the volume until it reaches 0.0f
113 	void Update();
114 
115 private:
116 	//! \brief The volume of the audio when the effect was registered
117 	float _original_volume;
118 
119 	//! \brief The amount of time that the effect lasts for
120 	float _effect_time;
121 
122 	//! \brief A reference to the audio to process the effect upon
123 	AudioDescriptor& _audio;
124 }; // class FadeOutEffect : public AudioEffect {
125 
126 } // namespace private_audio
127 
128 } // namespace hoa_audio
129 
130 #endif // __AUDIO_EFFECTS_HEADER__
131