eChannel Class Reference

#include <eChannel.h>

Collaboration diagram for eChannel:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 eChannel ()
void SetVolume (int volume)
int GetId ()
void SetId (int newID)
void Set3d (eCoord home, eCoord soundPos, eCoord homeDirection)
void PlaySound (eWavData &sound)
void LoopSound (eWavData &sound)
void StopSound ()
void UnplaySound ()
Uint32 StartTime ()
bool IsContinuous ()
void Update ()
bool isDirty ()
bool isBusy ()
void SetOwner (eGameObject *owner)
void DelayStarting ()
bool IsDelayed ()
void Undelay ()
void SetHome (eGameObject *home)
eGameObjectGetOwner ()

Static Public Attributes

static int numChannels = 0

Private Attributes

eWavData m_Sound
bool m_Delayed
bool m_StartNow
int m_Volume
int m_ChannelID
Uint32 m_StartTime
bool m_isDirty
bool m_isPlaying
eGameObjectm_Owner
eGameObjectm_Home
bool m_continuous


Detailed Description

Definition at line 82 of file eChannel.h.


Constructor & Destructor Documentation

eChannel::eChannel (  ) 

Definition at line 86 of file eChannelSDLMixer.cpp.

References m_ChannelID, m_continuous, m_isDirty, m_isPlaying, m_Volume, and numChannels.

00086                    : m_Delayed(false) {
00087 #ifdef HAVE_LIBSDL_MIXER
00088     m_ChannelID = numChannels;
00089     numChannels++;
00090     m_Volume = 50;
00091     m_isDirty = false;
00092     m_isPlaying = false;
00093     m_continuous = false;
00094 #endif // DEDICATED
00095 }


Member Function Documentation

void eChannel::SetVolume ( int  volume  ) 

int eChannel::GetId (  )  [inline]

Definition at line 86 of file eChannel.h.

00087 { return m_ChannelID; };

void eChannel::SetId ( int  newID  )  [inline]

Definition at line 87 of file eChannel.h.

References m_ChannelID.

00087 { return m_ChannelID; };

void eChannel::Set3d ( eCoord  home,
eCoord  soundPos,
eCoord  homeDirection 
)

Definition at line 117 of file eChannelSDLMixer.cpp.

References eCoord, EPS, m_ChannelID, M_PI, REAL, and sqrt().

Referenced by Update().

00117                                                                        {
00118 #ifdef HAVE_LIBSDL_MIXER
00119     // the sound position relative to the microphone
00120     eCoord soundPosRelative = (soundPos - home).Turn( homeDirection.Conj() );
00121 
00122     // the distance to the microphone
00123     REAL distance = soundPosRelative.Norm();
00124 
00125     // the bearing in radians (taken from the inverse of the direction to put the discontinuous jump in the right spot)
00126     double bearing = atan2( -soundPosRelative.x, -soundPosRelative.y );
00127 
00128     // We get it in radians and need to convert to degrees because SDL_mixer is lame.
00129     // atan2's return value is specified to be between -PI and PI,
00130     // so we need to linearily transform the result.
00131     int bearingInt = 180 + (int) (bearing * 180.0/M_PI);
00132 
00133     // and the distance needs to be an integer, too. The conversion
00134     // could use some tweaking/customization.
00135     const REAL microphoneSize = 3;
00136     int distanceInt = 255 - int( 255 * microphoneSize / ( sqrt(distance) + microphoneSize ) );
00137     // clamp. Distance == 0 seems to be dangerous :(
00138     distanceInt = distanceInt > 255 ? 255 : distanceInt;
00139     distanceInt = distanceInt < 1 ? 1 : distanceInt;
00140 
00141     // override bearing for close sounds, the value of atan2 is undefined then
00142     if ( distance < EPS * microphoneSize )
00143         bearingInt = 0;
00144 
00145     // Remove the old effect, if present
00146     Mix_SetPosition(m_ChannelID, 0, 0);
00147     // Add the new effect
00148     Mix_SetPosition(m_ChannelID, bearingInt, distanceInt );
00149 #endif // DEDICATED
00150 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eChannel::PlaySound ( eWavData sound  ) 

Definition at line 97 of file eChannelSDLMixer.cpp.

References eWavData::GetVolume(), eWavData::GetWavData(), m_ChannelID, m_isPlaying, and m_StartTime.

00097                                         {
00098 #ifdef HAVE_LIBSDL_MIXER
00099     if(m_isPlaying) {
00100         Mix_HaltChannel(m_ChannelID);
00101         //std::cerr << "Channel occupied, halting: " << m_ChannelID << "\n";
00102     }
00103     int theChannel;
00104     Mix_Volume(m_ChannelID, sound.GetVolume());
00105     theChannel = Mix_PlayChannel(m_ChannelID, sound.GetWavData(), 0);
00106 
00107     if(theChannel != m_ChannelID) {
00108         // do nothing, but there's an error
00109         //std::cerr << "Couldn't play a sound: " << m_ChannelID << "\n";
00110     } else {
00111         m_isPlaying = true;
00112         m_StartTime = SDL_GetTicks();
00113     }
00114 #endif // DEDICATED
00115 }

Here is the call graph for this function:

void eChannel::LoopSound ( eWavData sound  ) 

Definition at line 192 of file eChannelSDLMixer.cpp.

References eWavData::GetVolume(), eWavData::GetWavData(), m_ChannelID, m_continuous, m_Delayed, m_isPlaying, and m_Sound.

Referenced by Update().

00192                                         {
00193 #ifdef HAVE_LIBSDL_MIXER
00194     //std::cout << "Looping sound\n";
00195     if(m_isPlaying) {
00196         Mix_HaltChannel(m_ChannelID);
00197         //std::cerr << "Channel occupied, halting: " << m_ChannelID << "\n";
00198     }
00199     m_continuous = true;
00200     m_Sound = sound;
00201 
00202     if(m_Delayed) {
00203         return;
00204     }
00205     int theChannel;
00206     Mix_Volume(m_ChannelID, sound.GetVolume());
00207     theChannel = Mix_PlayChannel(m_ChannelID, m_Sound.GetWavData(), -1);
00208 
00209     //std::cout << "Looping sound\n";
00210     if(theChannel < 0) {
00211         // do nothing, but there's an error
00212         //std::cerr << "Couldn't play a sound on channel: " << m_ChannelID << "\n";
00213     } else {
00214         m_isPlaying = true;
00215     }
00216 #endif
00217 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eChannel::StopSound (  )  [inline]

Definition at line 92 of file eChannel.h.

Referenced by Update().

00093                      {
00094 #ifndef DEDICATED
00095         m_isDirty = true; m_isPlaying = false; Mix_HaltChannel(m_ChannelID);
00096 #endif

Here is the caller graph for this function:

void eChannel::UnplaySound (  ) 

Definition at line 179 of file eChannelSDLMixer.cpp.

References m_isDirty, and m_isPlaying.

00179                            {
00180 #ifdef HAVE_LIBSDL_MIXER
00181     m_isDirty = true;
00182     m_isPlaying = false;
00183 #endif // DEDICATED
00184 }

Uint32 eChannel::StartTime (  )  [inline]

Definition at line 102 of file eChannel.h.

00103 { return m_StartTime; };

bool eChannel::IsContinuous (  )  [inline]

Definition at line 103 of file eChannel.h.

References m_StartTime.

00103 { return m_StartTime; };

void eChannel::Update (  ) 

Definition at line 152 of file eChannelSDLMixer.cpp.

References eGameObject::Direction(), LoopSound(), m_ChannelID, m_continuous, m_Delayed, m_Home, m_isDirty, m_isPlaying, m_Owner, m_Sound, m_StartNow, eGameObject::Position(), Set3d(), and StopSound().

00152                       {
00153 #ifdef HAVE_LIBSDL_MIXER
00154     if(m_isDirty && !m_isPlaying) {
00155         Mix_UnregisterAllEffects(m_ChannelID);
00156         m_isDirty = false;
00157     }
00158 
00159     if(m_continuous) {
00160         if(m_Delayed) {
00161             if(m_StartNow) {
00162                 m_StartNow = false;
00163                 m_Delayed = false;
00164                 LoopSound(m_Sound);
00165                 Set3d(m_Home->Position(), m_Owner->Position(), m_Home->Direction());
00166                 std::cout << "Starting delayed effect\n";
00167             }
00168         } else {
00169             if(!m_Home || !m_Owner) {
00170                 StopSound();
00171                 return;
00172             }
00173             Set3d(m_Home->Position(), m_Owner->Position(), m_Home->Direction());
00174         }
00175     }
00176 #endif // DEDICATED
00177 }

Here is the call graph for this function:

bool eChannel::isDirty (  )  [inline]

Definition at line 109 of file eChannel.h.

References m_isDirty.

00110 { return m_isDirty; };

bool eChannel::isBusy (  )  [inline]

Definition at line 112 of file eChannel.h.

References m_isPlaying.

00113 { return m_isPlaying; };

void eChannel::SetOwner ( eGameObject owner  ) 

Definition at line 186 of file eChannelSDLMixer.cpp.

References m_Owner.

00186                                           {
00187 #ifdef HAVE_LIBSDL_MIXER
00188     m_Owner = owner;
00189 #endif
00190 }

void eChannel::DelayStarting (  )  [inline]

Definition at line 115 of file eChannel.h.

00116 { m_Delayed = true; m_StartNow = false; };

bool eChannel::IsDelayed (  )  [inline]

Definition at line 116 of file eChannel.h.

References m_Delayed, and m_StartNow.

00116 { m_Delayed = true; m_StartNow = false; };

void eChannel::Undelay (  )  [inline]

Definition at line 117 of file eChannel.h.

References m_Delayed.

00117 { return m_Delayed; };

void eChannel::SetHome ( eGameObject home  )  [inline]

Definition at line 118 of file eChannel.h.

References m_StartNow.

00118 { m_StartNow = true; };

eGameObject* eChannel::GetOwner (  )  [inline]

Definition at line 119 of file eChannel.h.

00119 { m_Home = home; };


Member Data Documentation

int eChannel::numChannels = 0 [static]

Definition at line 119 of file eChannel.h.

Referenced by eChannel(), and eSoundMixer::Update().

eWavData eChannel::m_Sound [private]

Definition at line 127 of file eChannel.h.

Referenced by LoopSound(), and Update().

bool eChannel::m_Delayed [private]

Definition at line 128 of file eChannel.h.

Referenced by IsDelayed(), LoopSound(), Undelay(), and Update().

bool eChannel::m_StartNow [private]

Definition at line 129 of file eChannel.h.

Referenced by IsDelayed(), SetHome(), and Update().

int eChannel::m_Volume [private]

Definition at line 130 of file eChannel.h.

Referenced by eChannel().

int eChannel::m_ChannelID [private]

Definition at line 131 of file eChannel.h.

Referenced by eChannel(), LoopSound(), PlaySound(), Set3d(), SetId(), and Update().

Uint32 eChannel::m_StartTime [private]

Definition at line 132 of file eChannel.h.

Referenced by IsContinuous(), and PlaySound().

bool eChannel::m_isDirty [private]

Definition at line 133 of file eChannel.h.

Referenced by eChannel(), isDirty(), UnplaySound(), and Update().

bool eChannel::m_isPlaying [private]

Definition at line 134 of file eChannel.h.

Referenced by eChannel(), isBusy(), LoopSound(), PlaySound(), UnplaySound(), and Update().

eGameObject* eChannel::m_Owner [private]

Definition at line 135 of file eChannel.h.

Referenced by SetOwner(), and Update().

eGameObject* eChannel::m_Home [private]

Definition at line 136 of file eChannel.h.

Referenced by Update().

bool eChannel::m_continuous [private]

Definition at line 137 of file eChannel.h.

Referenced by eChannel(), LoopSound(), and Update().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:22:06 2008 for Armagetron Advanced by  doxygen 1.5.4