Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

/home/rdbrown/doxygen/cse125g1/src/modules/audio/Source.cpp

00001 /*
00002  *  Source.cpp
00003  *  MMAudio
00004  *
00005  *  Created by Rib Rdb on 4/4/05.
00006  *  Copyright 2005 __MyCompanyName__. All rights reserved.
00007  *
00008  */
00009 
00010 #include "Source.h"
00011 #include "audioint.h"
00012 #include "BufferManager.h"
00013 using namespace MMAudio;
00014 
00015 #include <iostream>
00016 
00017 Source::Source() /* throw (AlException) */ {
00018     ALLock lock;
00019     audioResetAlErrors();
00020     alGenSources(1, &name);
00021     audioCheckAlErrors();
00022 }
00023 
00024 Source::~Source() /* throw (AlException) */ {
00025     ALLock lock;
00026     audioResetAlErrors();
00027     alDeleteSources(1,&name);
00028     audioCheckAlErrors();
00029 }
00030 
00031 float Source::getGain() const /* throw (AlException) */ {
00032     ALfloat gain;
00033     audioResetAlErrors();
00034     alGetSourcef(name,AL_GAIN,&gain);
00035     audioCheckAlErrors();
00036     return gain;
00037 }
00038 
00039 void Source::setGain(float gain) /* throw (AlException) */ {
00040     ALLock lock;
00041     audioResetAlErrors();
00042     alSourcef(name, AL_GAIN,gain);
00043     audioCheckAlErrors();
00044 }
00045 
00046 float Source::getRolloff() const  /* throw (AlException) */ {
00047     ALfloat ro;
00048     audioResetAlErrors();
00049     alGetSourcef(name,AL_ROLLOFF_FACTOR,&ro);
00050     audioCheckAlErrors();
00051     return ro;
00052 }
00053 void Source::setRolloff(float ro) /* throw (AlException) */ {
00054     ALLock lock;
00055     audioResetAlErrors();
00056     alSourcef(name,AL_ROLLOFF_FACTOR,ro);
00057     audioCheckAlErrors();
00058 }
00059 
00060 Vector3 Source::getPosition() const /* throw (AlException) */ {
00061     Vector3 pos;
00062     audioResetAlErrors();
00063     alGetSourcefv(name,AL_POSITION,(ALfloat*)&pos);
00064     audioCheckAlErrors();
00065     return pos;
00066 }
00067 void Source::setPosition(Vector3 pos) /* throw (AlException) */ {
00068     ALLock lock;
00069     audioResetAlErrors();
00070     alSourcefv(name,AL_POSITION,(ALfloat*)&pos);
00071     audioCheckAlErrors();
00072 }
00073 
00074 Vector3 Source::getVelocity() const /* throw (AlException) */ {
00075     Vector3 vel;
00076     audioResetAlErrors();
00077     alGetSourcefv(name,AL_VELOCITY,(ALfloat*)&vel);
00078     audioCheckAlErrors();
00079     return vel;
00080 }
00081 void Source::setVelocity(Vector3 vel) /* throw (AlException) */ {
00082     ALLock lock;
00083     audioResetAlErrors();
00084     alSourcefv(name,AL_VELOCITY,(ALfloat*)&vel);
00085     audioCheckAlErrors();
00086 }
00087 
00088 bool Source::isSourceRelative() const /* throw (AlException) */ {
00089     ALint srel;
00090     audioResetAlErrors();
00091     alGetSourcei(name,AL_SOURCE_RELATIVE,&srel);
00092     audioCheckAlErrors();
00093     return srel != 0;
00094 }
00095 void Source::setSourceRelative(bool b) /* throw (AlException) */ {
00096     ALLock lock;
00097     audioResetAlErrors();
00098     alSourcei(name,AL_SOURCE_RELATIVE,b);
00099     audioCheckAlErrors();
00100 }
00101 
00102 bool Source::isLooping() const /* throw (AlException) */ {
00103     ALint looping;
00104     audioResetAlErrors();
00105     alGetSourcei(name,AL_LOOPING,&looping);
00106     audioCheckAlErrors();
00107     return looping != 0;
00108 }
00109 void Source::setLooping(bool looping)  /* throw (AlException) */ {
00110     ALLock lock;
00111     audioResetAlErrors();
00112     alSourcei(name,AL_LOOPING,looping);
00113     audioCheckAlErrors();
00114 }
00115 
00116 int Source::getState() const /* throw (AlException) */ {
00117     ALint state;
00118     audioResetAlErrors();
00119     alGetSourcei(name,AL_SOURCE_STATE,&state);
00120     audioCheckAlErrors();
00121     return state;
00122 }
00123 int Source::getQueuedBufferCount() const /* throw (AlException) */ {
00124     ALint queued;
00125     audioResetAlErrors();
00126     alGetSourcei(name,AL_BUFFERS_QUEUED,&queued);
00127     audioCheckAlErrors();
00128     return queued;
00129 }
00130 int Source::getProcessedBufferCount() const /* throw (AlException) */ {
00131     ALint processed;
00132     audioResetAlErrors();
00133     alGetSourcei(name,AL_BUFFERS_PROCESSED,&processed);
00134     audioCheckAlErrors();
00135     return processed;
00136 }
00137 
00138 void Source::play() /* throw (AlException) */ {
00139     ALLock lock;
00140     audioResetAlErrors();
00141     alSourcePlay(name);
00142     audioCheckAlErrors();
00143 }
00144 void Source::pause() /* throw (AlException) */ {
00145     ALLock lock;
00146     audioResetAlErrors();
00147     alSourcePause(name);
00148     audioCheckAlErrors();
00149 }
00150 void Source::stop() /* throw (AlException) */ {
00151     if (getState() != AL_PLAYING)
00152         return;
00153     ALLock lock;
00154     audioResetAlErrors();
00155     alSourceStop(name);
00156     audioCheckAlErrors();
00157 }
00158 void Source::rewind() /* throw (AlException) */ {
00159     ALLock lock;
00160     audioResetAlErrors();
00161     alSourceRewind(name);
00162     audioCheckAlErrors();
00163 }
00164 
00165 void Source::queueBuffer(ALuint bname) /* throw (AlException) */ {
00166     ALLock lock;
00167     audioResetAlErrors();
00168     alSourceQueueBuffers(name,1,&bname);
00169     audioCheckAlErrors();
00170 }
00171 ALuint Source::unqueueBuffer() /* throw (AlException) */ {
00172     ALLock lock;
00173     ALuint bname;
00174     audioResetAlErrors();
00175     alSourceUnqueueBuffers(name,1,&bname);
00176     audioCheckAlErrors();
00177 
00178     return bname;
00179 }
00180 void Source::playSound(unsigned int sname) /* throw (AlException) */ {
00181     stop();
00182     setLooping(false);
00183     setSong(sname);
00184     play();
00185 }
00186 void Source::loopSound(unsigned int sname) /* throw (AlException) */ {
00187     stop();
00188     setLooping(true);
00189     setSong(sname);
00190     play();
00191 }
00192 void Source::setSong(unsigned int sname) /* throw (AlException) */ {
00193     ALuint bufname = getBufferForSound(sname);
00194     ALLock lock;
00195     audioResetAlErrors();
00196     alSourcei(name, AL_BUFFER, bufname);
00197     audioCheckAlErrors();
00198 }

Generated on Thu Aug 18 16:03:10 2005 for Robin Hood: Thieves & Knights by doxygen1.2.18