Update of /cvsroot/alpp/openalpp/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14023/src Modified Files: CMakeLists.txt audiobase.cpp audioconvert.cpp audioenvironment.cpp deviceupdater.cpp error.cpp filestream.cpp filestreamupdater.cpp groupsource.cpp inputdevice.cpp listener.cpp netstream.cpp netupdater.cpp nofilestream.cpp noinputdevice.cpp nostreaming.cpp openalpp.cpp referenced.cpp sample.cpp sounddata.cpp source.cpp sourcebase.cpp stream.cpp streamupdater.cpp Log Message: Ogg streaming revised by Dewitt Colclough [de...@tw...]. Index: nofilestream.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/src/nofilestream.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** nofilestream.cpp 11 Nov 2004 07:57:58 -0000 1.7 --- nofilestream.cpp 24 Mar 2005 11:47:48 -0000 1.8 *************** *** 1,47 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/filestream.h" ! ! namespace openalpp { ! ! FileStream::FileStream(const std::string& ,const int) ! throw (NameError,InitError,FileError) : Stream() { ! throw InitError("No support for streaming from files compiled in."); ! } ! ! FileStream::FileStream(const FileStream &stream) ! : Stream((const Stream &)stream) { ! } ! ! FileStream::~FileStream() { ! } ! ! FileStream &FileStream::operator=(const FileStream &/*stream*/) { ! return *this; ! } ! ! void FileStream::setLooping(bool) { ! } ! ! } --- 1,47 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/filestream.h" ! ! namespace openalpp { ! ! FileStream::FileStream(const std::string& ,const int) ! throw (NameError,InitError,FileError) : Stream() { ! throw InitError("No support for streaming from files compiled in."); ! } ! ! FileStream::FileStream(const FileStream &stream) ! : Stream((const Stream &)stream) { ! } ! ! FileStream::~FileStream() { ! } ! ! FileStream &FileStream::operator=(const FileStream &/*stream*/) { ! return *this; ! } ! ! void FileStream::setLooping(bool) { ! } ! ! } Index: sourcebase.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/src/sourcebase.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** sourcebase.cpp 12 Nov 2004 09:10:18 -0000 1.12 --- sourcebase.cpp 24 Mar 2005 11:47:48 -0000 1.13 *************** *** 1,440 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/sourcebase.h" ! ! /** ! * TODO: Should error checking be optional? ! * (a static bool throwflag in AudioBase)? ! */ ! ! using namespace openalpp; ! ! void SourceBase::init() throw (MemoryError,NameError) { ! alGenSources(1,&sourcename_); ! if(alGetError()!=AL_FALSE) ! throw NameError("Couldn't generate source name"); ! ! nlinkedsources_=1; ! alloclinkedsources_=2; ! //linkedsources_=(ALuint *)malloc(sizeof(ALuint)*alloclinkedsources_); ! linkedsources_ = new ALuint[alloclinkedsources_]; ! ! if(!linkedsources_) ! throw MemoryError("new failed"); ! linkedsources_[0]=sourcename_; ! reverbscale_=0.25; ! reverbdelay_=0.0; ! streaming_=false; ! } ! ! SourceBase::SourceBase() throw (MemoryError,NameError) : PositionedObject() { ! init(); ! } ! ! SourceBase::SourceBase(float x,float y,float z) ! throw (MemoryError,NameError) : PositionedObject() { ! ! init(); ! setPosition(x,y,z); ! } ! ! SourceBase::~SourceBase() { ! stop(); ! alDeleteSources(1,&sourcename_); ! //free(linkedsources_); ! delete [] linkedsources_; ! } ! ! SourceBase::SourceBase(const SourceBase &sourcebase) ! : PositionedObject(sourcebase) { ! ! if(this==&sourcebase) ! return; ! ! *this = sourcebase; ! ! ! /* float a,b,c; ! sourcebase.getPosition(a,b,c); ! setPosition(a,b,c); ! sourcebase.getVelocity(a,b,c); ! setVelocity(a,b,c); ! setPitch(sourcebase.getPitch()); ! sourcebase.getDirection(a,b,c); ! setDirection(a,b,c); ! sourcebase.getSoundCone(a,b,c); ! setSoundCone(a,b,c); ! sourcebase.getMinMaxGain(a,b); ! setMinMaxGain(a,b); ! setReferenceDistance(sourcebase.getReferenceDistance()); ! setRolloffFactor(sourcebase.getRolloffFactor()); ! setMaxDistance(sourcebase.getMaxDistance()); ! setLooping(sourcebase.isLooping()); ! setGain(sourcebase.getGain());*/ ! } ! ! SourceBase &SourceBase::operator=(const SourceBase &sourcebase) { ! if(this==&sourcebase) ! return *this; ! ! float a,b,c; ! sourcebase.getPosition(a,b,c); ! setPosition(a,b,c); ! sourcebase.getVelocity(a,b,c); ! setVelocity(a,b,c); ! setPitch(sourcebase.getPitch()); ! sourcebase.getDirection(a,b,c); ! setDirection(a,b,c); ! sourcebase.getSoundCone(a,b,c); ! setSoundCone(a,b,c); ! sourcebase.getMinMaxGain(a,b); ! setMinMaxGain(a,b); ! setReferenceDistance(sourcebase.getReferenceDistance()); ! setRolloffFactor(sourcebase.getRolloffFactor()); ! setMaxDistance(sourcebase.getMaxDistance()); ! setLooping(sourcebase.isLooping()); ! setGain(sourcebase.getGain()); ! ! return *this; ! } ! ! void SourceBase::play() { ! alSourcePlayv(nlinkedsources_,linkedsources_); ! } ! ! void SourceBase::pause() { ! alSourcePausev(nlinkedsources_,linkedsources_); ! } ! ! void SourceBase::stop() { ! alSourceStopv(nlinkedsources_,linkedsources_); ! } ! ! void SourceBase::rewind() { ! alSourceRewindv(nlinkedsources_,linkedsources_); ! } ! ! SourceState SourceBase::getState() const { ! ALint state; ! alGetSourceiv(sourcename_,AL_SOURCE_STATE,&state); ! switch(state) { ! case(AL_INITIAL): ! return Initial; ! case(AL_PLAYING): ! return Playing; ! case(AL_PAUSED): ! return Paused; ! case(AL_STOPPED): ! return Stopped; ! default: ! throw FatalError("AL_SOURCE_STATE is unknown"); ! } ! } ! ! void SourceBase::setLooping(bool loop) { ! if(loop && !streaming_) ! alSourcei(sourcename_,AL_LOOPING,AL_TRUE); ! else ! alSourcei(sourcename_,AL_LOOPING,AL_FALSE); ! } ! ! bool SourceBase::isLooping() const { ! ALint looping; ! alGetSourceiv(sourcename_,AL_LOOPING,&looping); ! return (looping==AL_TRUE); ! } ! ! void SourceBase::setDirection(float directionx, float directiony, float directionz) { ! alSource3f(sourcename_,AL_DIRECTION,directionx,directiony,directionz); ! } ! ! void SourceBase::getDirection(float &directionx, float &directiony, float &directionz) const { ! ALfloat direction[3]; ! alGetSourcefv(sourcename_,AL_DIRECTION,direction); ! directionx=direction[0]; ! directiony=direction[1]; ! directionz=direction[2]; ! } ! ! void SourceBase::makeOmniDirectional() { ! alSource3f(sourcename_,AL_DIRECTION,0.0,0.0,0.0); ! } ! ! void SourceBase::setSoundCone(float innerangle, float outerangle, float outergain) { ! alSourcef(sourcename_,AL_CONE_INNER_ANGLE,innerangle); ! alSourcef(sourcename_,AL_CONE_OUTER_ANGLE,outerangle); ! alSourcef(sourcename_,AL_CONE_OUTER_GAIN,outergain); ! } ! ! void SourceBase::getSoundCone(float &innerangle, float &outerangle, float &outergain) const { ! alGetSourcefv(sourcename_,AL_CONE_INNER_ANGLE,&innerangle); ! alGetSourcefv(sourcename_,AL_CONE_OUTER_ANGLE,&outerangle); ! alGetSourcefv(sourcename_,AL_CONE_OUTER_GAIN,&outergain); ! } ! ! void SourceBase::setGain(float gain) { ! alSourcef(sourcename_,AL_GAIN,gain); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for gain"); ! break; ! default: ! throw FatalError("Error trying to set gain!"); ! } ! } ! ! float SourceBase::getGain() const { ! ALfloat gain; ! alGetSourcefv(sourcename_,AL_GAIN,&gain); ! return gain; ! } ! ! void SourceBase::setMinMaxGain(float min, float max) { ! alSourcef(sourcename_,AL_MIN_GAIN,min); ! alSourcef(sourcename_,AL_MAX_GAIN,max); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for min/max gain"); ! break; ! default: ! throw FatalError("Error trying to set min/max gain!"); ! } ! } ! ! void SourceBase::getMinMaxGain(float & min, float &max) const { ! alGetSourcefv(sourcename_,AL_MIN_GAIN,&min); ! alGetSourcefv(sourcename_,AL_MAX_GAIN,&max); ! } ! ! void SourceBase::setAmbient(bool ambient) { ! if(ambient) { ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_TRUE); ! alSourcef(sourcename_,AL_ROLLOFF_FACTOR,0.0); ! // TODO: if AL_ROLLOFF_FACTOR doesn't work; set ! // AL_MAX_GAIN=AL_MIN_GAIN=AL_GAIN for this source.. ! makeOmniDirectional(); ! } else { ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_FALSE); ! alSourcef(sourcename_,AL_ROLLOFF_FACTOR,1.0); ! } ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to make/unmake sound ambient!"); ! } ! ! bool SourceBase::isAmbient() const { ! ALint relative; ! alGetSourceiv(sourcename_,AL_SOURCE_RELATIVE,&relative); ! ALfloat rolloff; ! alGetSourcefv(sourcename_,AL_ROLLOFF_FACTOR,&rolloff); ! return (relative==AL_TRUE && rolloff<0.001); ! } ! ! void SourceBase::setRelative(bool relative) { ! if(relative) ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_TRUE); ! else ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_FALSE); ! } ! ! bool SourceBase::isRelative() const { ! ALint relative; ! alGetSourceiv(sourcename_,AL_SOURCE_RELATIVE,&relative); ! return (relative==AL_TRUE); ! } ! ! void SourceBase::setReferenceDistance(float distance) { ! alSourcef(sourcename_,AL_REFERENCE_DISTANCE,distance); ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to set reference distance!"); ! } ! ! float SourceBase::getReferenceDistance() const { ! ALfloat ref; ! alGetSourcefv(sourcename_,AL_REFERENCE_DISTANCE,&ref); ! return ref; ! } ! ! void SourceBase::setMaxDistance(float distance) { ! alSourcef(sourcename_,AL_MAX_DISTANCE,distance); ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to set max distance!"); ! } ! ! float SourceBase::getMaxDistance() const { ! ALfloat maxdistance; ! alGetSourcefv(sourcename_,AL_MAX_DISTANCE,&maxdistance); ! return maxdistance; ! } ! ! void SourceBase::setRolloffFactor(float factor) { ! alSourcef(sourcename_,AL_ROLLOFF_FACTOR,factor); ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to set rolloff factor!"); ! } ! ! float SourceBase::getRolloffFactor() const { ! ALfloat factor; ! alGetSourcefv(sourcename_,AL_ROLLOFF_FACTOR,&factor); ! return factor; ! } ! ! void SourceBase::setPitch(float pitch) { ! alSourcef(sourcename_,AL_PITCH,pitch); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for pitch"); ! break; ! default: ! throw FatalError("Error trying to set pitch!"); ! } ! } ! ! float SourceBase::getPitch() const { ! ALfloat pitch; ! alGetSourcefv(sourcename_,AL_PITCH,&pitch); ! return pitch; ! } ! ! void SourceBase::setReverbScale(float scale) throw (InitError,ValueError) { ! if(reverbinitiated_) { ! alReverbScale(sourcename_,scale); ! if(alGetError()!=AL_FALSE) ! throw ValueError("Reverb scale must be in range [0.0,1.0]"); ! reverbscale_=scale; ! } else ! throw InitError("Reverb not initialized"); ! } ! ! void SourceBase::setReverbDelay(float delay) throw (InitError,ValueError) { ! if(reverbinitiated_) { ! alReverbDelay(sourcename_,delay); ! if(alGetError()!=AL_FALSE) ! throw ValueError("Reverb delay must be in range [0.0,2.0]"); ! reverbdelay_=delay; ! } else ! throw InitError("Reverb not initialized"); ! } ! ! float SourceBase::getReverbScale() throw (InitError) { ! if(!reverbinitiated_) ! throw InitError("Reverb not initialized"); ! return reverbscale_; ! } ! ! float SourceBase::getReverbDelay() throw (InitError) { ! if(!reverbinitiated_) ! throw InitError("Reverb not initialized"); ! return reverbdelay_; ! } ! ! ALuint SourceBase::link(const SourceBase *source) throw (MemoryError) { ! if(nlinkedsources_>=alloclinkedsources_) { ! alloclinkedsources_+=5; ! linkedsources_=(ALuint *)realloc(linkedsources_, ! sizeof(ALuint)*alloclinkedsources_); ! if(!linkedsources_) ! throw MemoryError("realloc failed"); ! } ! linkedsources_[nlinkedsources_++]=source->getAlSource(); ! return source->getAlSource(); ! } ! ! void SourceBase::unlink(const SourceBase *source) throw (NameError) { ! if(source->sourcename_==sourcename_) ! throw(NameError("Can't unlink a source from itself!")); ! for(unsigned int i=0;i<nlinkedsources_;i++) ! if(linkedsources_[i]==source->sourcename_) { ! linkedsources_[i]=linkedsources_[--nlinkedsources_]; ! return; ! } ! throw NameError("Source not linked"); ! } ! ! void SourceBase::unlink(const ALuint name) throw (NameError) { ! if(name==sourcename_) ! throw(NameError("Can't unlink a source from itself!")); ! for(unsigned int i=0;i<nlinkedsources_;i++) ! if(linkedsources_[i]==name) { ! linkedsources_[i]=linkedsources_[--nlinkedsources_]; ! return; ! } ! throw NameError("Source not linked"); ! } ! ! void SourceBase::unlinkAll() { ! nlinkedsources_=1; ! } ! ! ALuint SourceBase::getAlSource() const { ! return sourcename_; ! } ! ! void SourceBase::setPosition(float x, float y, float z) { ! alSource3f(sourcename_,AL_POSITION,x,y,z); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for position"); ! break; ! default: ! throw FatalError("Error trying to set position!"); ! } ! } ! ! void SourceBase::getPosition(float &x, float &y, float &z) const { ! ALfloat position[3]; ! alGetSourcefv(sourcename_,AL_POSITION,position); ! x=position[0]; ! y=position[1]; ! z=position[2]; ! } ! ! void SourceBase::setVelocity(float vx, float vy, float vz) { ! alSource3f(sourcename_,AL_VELOCITY,vx,vy,vz); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for velocity"); ! break; ! default: ! throw FatalError("Error trying to set velocity!"); ! } ! } ! ! void SourceBase::getVelocity(float &vx, float &vy, float &vz) const { ! ALfloat velocity[3]; ! alGetSourcefv(sourcename_,AL_VELOCITY,velocity); ! vx=velocity[0]; ! vy=velocity[1]; ! vz=velocity[2]; ! } ! --- 1,484 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/sourcebase.h" ! ! /** ! * TODO: Should error checking be optional? ! * (a static bool throwflag in AudioBase)? ! */ ! ! using namespace openalpp; ! ! void SourceBase::init() throw (MemoryError,NameError) { ! alGenSources(1,&sourcename_); ! if(alGetError()!=AL_FALSE) ! throw NameError("Couldn't generate source name"); ! ! nlinkedsources_=1; ! alloclinkedsources_=2; ! //linkedsources_=(ALuint *)malloc(sizeof(ALuint)*alloclinkedsources_); ! linkedsources_ = new ALuint[alloclinkedsources_]; ! ! if(!linkedsources_) ! throw MemoryError("new failed"); ! linkedsources_[0]=sourcename_; ! reverbscale_=0.25; ! reverbdelay_=0.0; ! streaming_=false; ! } ! ! SourceBase::SourceBase() throw (MemoryError,NameError) : PositionedObject() { ! init(); ! } ! ! SourceBase::SourceBase(float x,float y,float z) ! throw (MemoryError,NameError) : PositionedObject() { ! ! init(); ! setPosition(x,y,z); ! } ! ! SourceBase::~SourceBase() { ! stop(); ! ! alDeleteSources(1,&sourcename_); ! //free(linkedsources_); ! delete [] linkedsources_; ! ! if (alGetError() != AL_FALSE) ! { ! std::cerr << "~SourceBase() - Warning - Error deleting sources\n"; ! } ! } ! ! SourceBase::SourceBase(const SourceBase &sourcebase) ! : PositionedObject(sourcebase) { ! ! if(this==&sourcebase) ! return; ! ! *this = sourcebase; ! ! ! /* float a,b,c; ! sourcebase.getPosition(a,b,c); ! setPosition(a,b,c); ! sourcebase.getVelocity(a,b,c); ! setVelocity(a,b,c); ! setPitch(sourcebase.getPitch()); ! sourcebase.getDirection(a,b,c); ! setDirection(a,b,c); ! sourcebase.getSoundCone(a,b,c); ! setSoundCone(a,b,c); ! sourcebase.getMinMaxGain(a,b); ! setMinMaxGain(a,b); ! setReferenceDistance(sourcebase.getReferenceDistance()); ! setRolloffFactor(sourcebase.getRolloffFactor()); ! setMaxDistance(sourcebase.getMaxDistance()); ! setLooping(sourcebase.isLooping()); ! setGain(sourcebase.getGain());*/ ! } ! ! SourceBase &SourceBase::operator=(const SourceBase &sourcebase) { ! if(this==&sourcebase) ! return *this; ! ! float a,b,c; ! sourcebase.getPosition(a,b,c); ! setPosition(a,b,c); ! sourcebase.getVelocity(a,b,c); ! setVelocity(a,b,c); ! setPitch(sourcebase.getPitch()); ! sourcebase.getDirection(a,b,c); ! setDirection(a,b,c); ! sourcebase.getSoundCone(a,b,c); ! setSoundCone(a,b,c); ! sourcebase.getMinMaxGain(a,b); ! setMinMaxGain(a,b); ! setReferenceDistance(sourcebase.getReferenceDistance()); ! setRolloffFactor(sourcebase.getRolloffFactor()); ! setMaxDistance(sourcebase.getMaxDistance()); ! setLooping(sourcebase.isLooping()); ! setGain(sourcebase.getGain()); ! ! return *this; ! } ! ! void SourceBase::play() { ! alSourcePlayv(nlinkedsources_,linkedsources_); ! ! if (alGetError() != AL_NO_ERROR) ! { ! std::cerr << "SourceBase::play() - Warning - Error playing sources\n"; ! } ! } ! ! void SourceBase::pause() ! { ! if (getState() != Playing) return; // only pause when playing ! ! alSourcePausev(nlinkedsources_,linkedsources_); ! ! if (alGetError() != AL_NO_ERROR) ! { ! std::cerr << "SourceBase::pause() - Warning - Error pausing sources\n"; ! } ! } ! ! void SourceBase::stop() { ! ! SourceState state = getState(); ! ! if (state == Stopped) return; // already stopped ! ! alSourceStopv(nlinkedsources_,linkedsources_); ! ! if (alGetError() != AL_FALSE) ! { ! std::cerr << "SourceBase::stop() - Warning - Error stopping sources\n"; ! } ! } ! ! void SourceBase::rewind() { ! alSourceRewindv(nlinkedsources_,linkedsources_); ! } ! ! SourceState SourceBase::getState() const { ! ALint state; ! alGetSourceiv(sourcename_,AL_SOURCE_STATE,&state); ! ! if (ALenum errorCode = alGetError() != AL_FALSE) ! { ! /** error occurs here when switching files ! fprintf(stderr, "SourceBase::getState() - Warning - Error getting state (%d)\n", ! errorCode); ! */ ! } ! ! ! switch(state) { ! case(AL_INITIAL): ! return Initial; ! case(AL_PLAYING): ! return Playing; ! case(AL_PAUSED): ! return Paused; ! case(AL_STOPPED): ! return Stopped; ! default: ! throw FatalError("AL_SOURCE_STATE is unknown"); ! } ! } ! ! void SourceBase::setLooping(bool loop) { ! if(loop && !streaming_) ! alSourcei(sourcename_,AL_LOOPING,AL_TRUE); ! else ! alSourcei(sourcename_,AL_LOOPING,AL_FALSE); ! } ! ! bool SourceBase::isLooping() const { ! ALint looping; ! alGetSourceiv(sourcename_,AL_LOOPING,&looping); ! return (looping==AL_TRUE); ! } ! ! bool SourceBase::isPaused() const ! { ! return (getState() == Paused); ! } ! ! void SourceBase::setDirection(float directionx, float directiony, float directionz) { ! alSource3f(sourcename_,AL_DIRECTION,directionx,directiony,directionz); ! } ! ! void SourceBase::getDirection(float &directionx, float &directiony, float &directionz) const { ! ALfloat direction[3]; ! alGetSourcefv(sourcename_,AL_DIRECTION,direction); ! directionx=direction[0]; ! directiony=direction[1]; ! directionz=direction[2]; ! } ! ! void SourceBase::makeOmniDirectional() { ! alSource3f(sourcename_,AL_DIRECTION,0.0,0.0,0.0); ! } ! ! void SourceBase::setSoundCone(float innerangle, float outerangle, float outergain) { ! alSourcef(sourcename_,AL_CONE_INNER_ANGLE,innerangle); ! alSourcef(sourcename_,AL_CONE_OUTER_ANGLE,outerangle); ! alSourcef(sourcename_,AL_CONE_OUTER_GAIN,outergain); ! } ! ! void SourceBase::getSoundCone(float &innerangle, float &outerangle, float &outergain) const { ! alGetSourcefv(sourcename_,AL_CONE_INNER_ANGLE,&innerangle); ! alGetSourcefv(sourcename_,AL_CONE_OUTER_ANGLE,&outerangle); ! alGetSourcefv(sourcename_,AL_CONE_OUTER_GAIN,&outergain); ! } ! ! void SourceBase::setGain(float gain) { ! alSourcef(sourcename_,AL_GAIN,gain); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for gain"); ! break; ! default: ! throw FatalError("Error trying to set gain!"); ! } ! } ! ! float SourceBase::getGain() const { ! ALfloat gain; ! alGetSourcefv(sourcename_,AL_GAIN,&gain); ! return gain; ! } ! ! void SourceBase::setMinMaxGain(float min, float max) { ! alSourcef(sourcename_,AL_MIN_GAIN,min); ! alSourcef(sourcename_,AL_MAX_GAIN,max); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for min/max gain"); ! break; ! default: ! throw FatalError("Error trying to set min/max gain!"); ! } ! } ! ! void SourceBase::getMinMaxGain(float & min, float &max) const { ! alGetSourcefv(sourcename_,AL_MIN_GAIN,&min); ! alGetSourcefv(sourcename_,AL_MAX_GAIN,&max); ! } ! ! void SourceBase::setAmbient(bool ambient) { ! if(ambient) { ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_TRUE); ! alSourcef(sourcename_,AL_ROLLOFF_FACTOR,0.0); ! // TODO: if AL_ROLLOFF_FACTOR doesn't work; set ! // AL_MAX_GAIN=AL_MIN_GAIN=AL_GAIN for this source.. ! makeOmniDirectional(); ! } else { ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_FALSE); ! alSourcef(sourcename_,AL_ROLLOFF_FACTOR,1.0); ! } ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to make/unmake sound ambient!"); ! } ! ! bool SourceBase::isAmbient() const { ! ALint relative; ! alGetSourceiv(sourcename_,AL_SOURCE_RELATIVE,&relative); ! ALfloat rolloff; ! alGetSourcefv(sourcename_,AL_ROLLOFF_FACTOR,&rolloff); ! return (relative==AL_TRUE && rolloff<0.001); ! } ! ! void SourceBase::setRelative(bool relative) { ! if(relative) ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_TRUE); ! else ! alSourcei(sourcename_,AL_SOURCE_RELATIVE,AL_FALSE); ! } ! ! bool SourceBase::isRelative() const { ! ALint relative; ! alGetSourceiv(sourcename_,AL_SOURCE_RELATIVE,&relative); ! return (relative==AL_TRUE); ! } ! ! void SourceBase::setReferenceDistance(float distance) { ! alSourcef(sourcename_,AL_REFERENCE_DISTANCE,distance); ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to set reference distance!"); ! } ! ! float SourceBase::getReferenceDistance() const { ! ALfloat ref; ! alGetSourcefv(sourcename_,AL_REFERENCE_DISTANCE,&ref); ! return ref; ! } ! ! void SourceBase::setMaxDistance(float distance) { ! alSourcef(sourcename_,AL_MAX_DISTANCE,distance); ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to set max distance!"); ! } ! ! float SourceBase::getMaxDistance() const { ! ALfloat maxdistance; ! alGetSourcefv(sourcename_,AL_MAX_DISTANCE,&maxdistance); ! return maxdistance; ! } ! ! void SourceBase::setRolloffFactor(float factor) { ! alSourcef(sourcename_,AL_ROLLOFF_FACTOR,factor); ! if(alGetError()!=AL_FALSE) ! throw FatalError("Error trying to set rolloff factor!"); ! } ! ! float SourceBase::getRolloffFactor() const { ! ALfloat factor; ! alGetSourcefv(sourcename_,AL_ROLLOFF_FACTOR,&factor); ! return factor; ! } ! ! void SourceBase::setPitch(float pitch) { ! alSourcef(sourcename_,AL_PITCH,pitch); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for pitch"); ! break; ! default: ! throw FatalError("Error trying to set pitch!"); ! } ! } ! ! float SourceBase::getPitch() const { ! ALfloat pitch; ! alGetSourcefv(sourcename_,AL_PITCH,&pitch); ! return pitch; ! } ! ! void SourceBase::setReverbScale(float scale) throw (InitError,ValueError) { ! if(reverbinitiated_) { ! alReverbScale(sourcename_,scale); ! if(alGetError()!=AL_FALSE) ! throw ValueError("Reverb scale must be in range [0.0,1.0]"); ! reverbscale_=scale; ! } else ! throw InitError("Reverb not initialized"); ! } ! ! void SourceBase::setReverbDelay(float delay) throw (InitError,ValueError) { ! if(reverbinitiated_) { ! alReverbDelay(sourcename_,delay); ! if(alGetError()!=AL_FALSE) ! throw ValueError("Reverb delay must be in range [0.0,2.0]"); ! reverbdelay_=delay; ! } else ! throw InitError("Reverb not initialized"); ! } ! ! float SourceBase::getReverbScale() throw (InitError) { ! if(!reverbinitiated_) ! throw InitError("Reverb not initialized"); ! return reverbscale_; ! } ! ! float SourceBase::getReverbDelay() throw (InitError) { ! if(!reverbinitiated_) ! throw InitError("Reverb not initialized"); ! return reverbdelay_; ! } ! ! ALuint SourceBase::link(const SourceBase *source) throw (MemoryError) { ! if(nlinkedsources_>=alloclinkedsources_) { ! alloclinkedsources_+=5; ! linkedsources_=(ALuint *)realloc(linkedsources_, ! sizeof(ALuint)*alloclinkedsources_); ! if(!linkedsources_) ! throw MemoryError("realloc failed"); ! } ! linkedsources_[nlinkedsources_++]=source->getAlSource(); ! return source->getAlSource(); ! } ! ! void SourceBase::unlink(const SourceBase *source) throw (NameError) { ! if(source->sourcename_==sourcename_) ! throw(NameError("Can't unlink a source from itself!")); ! for(unsigned int i=0;i<nlinkedsources_;i++) ! if(linkedsources_[i]==source->sourcename_) { ! linkedsources_[i]=linkedsources_[--nlinkedsources_]; ! return; ! } ! throw NameError("Source not linked"); ! } ! ! void SourceBase::unlink(const ALuint name) throw (NameError) { ! if(name==sourcename_) ! throw(NameError("Can't unlink a source from itself!")); ! for(unsigned int i=0;i<nlinkedsources_;i++) ! if(linkedsources_[i]==name) { ! linkedsources_[i]=linkedsources_[--nlinkedsources_]; ! return; ! } ! throw NameError("Source not linked"); ! } ! ! void SourceBase::unlinkAll() { ! nlinkedsources_=1; ! } ! ! ALuint SourceBase::getAlSource() const { ! return sourcename_; ! } ! ! void SourceBase::setPosition(float x, float y, float z) { ! alSource3f(sourcename_,AL_POSITION,x,y,z); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for position"); ! break; ! default: ! throw FatalError("Error trying to set position!"); ! } ! } ! ! void SourceBase::getPosition(float &x, float &y, float &z) const { ! ALfloat position[3]; ! alGetSourcefv(sourcename_,AL_POSITION,position); ! x=position[0]; ! y=position[1]; ! z=position[2]; ! } ! ! void SourceBase::setVelocity(float vx, float vy, float vz) { ! alSource3f(sourcename_,AL_VELOCITY,vx,vy,vz); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for velocity"); ! break; ! default: ! throw FatalError("Error trying to set velocity!"); ! } ! } ! ! void SourceBase::getVelocity(float &vx, float &vy, float &vz) const { ! ALfloat velocity[3]; ! alGetSourcefv(sourcename_,AL_VELOCITY,velocity); ! vx=velocity[0]; ! vy=velocity[1]; ! vz=velocity[2]; ! } ! Index: netstream.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/src/netstream.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** netstream.cpp 11 Nov 2004 07:57:58 -0000 1.8 --- netstream.cpp 24 Mar 2005 11:47:48 -0000 1.9 *************** *** 1,82 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * CommonC++ (http://cplusplus.sourceforge.net/) ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/netupdater.h" ! #include "openalpp/netstream.h" ! #include "openalpp/sample.h" ! ! namespace openalpp { ! ! NetStream::NetStream(ost::UDPSocket *socket,ost::TCPStream *controlsocket) ! : Stream() { ! unsigned int frequency=11025,buffersize=2048; ! ALenum format=AL_FORMAT_MONO8; ! if(controlsocket) { ! *controlsocket >> format; ! *controlsocket >> frequency; ! *controlsocket >> buffersize; ! } ! updater_=new NetUpdater(socket,controlsocket, ! buffername_,buffer2_->GetName(), ! format,frequency,buffersize*SampleSize(format)); ! } ! ! NetStream::NetStream(ost::UDPSocket *socket,SampleFormat format, ! unsigned int frequency,unsigned int buffersize) ! : Stream() { ! ALenum alformat=0; ! switch(format) { ! case(Mono8): ! alformat=AL_FORMAT_MONO8; ! break; ! case(Mono16): ! alformat=AL_FORMAT_MONO16; ! break; ! case(Stereo8): ! alformat=AL_FORMAT_STEREO8; ! break; ! case(Stereo16): ! alformat=AL_FORMAT_STEREO16; ! break; ! } ! updater_=new NetUpdater(socket,NULL,buffername_,buffer2_->GetName(), ! alformat,frequency,buffersize*SampleSize(format)); ! } ! ! ! NetStream::NetStream(const NetStream &stream) : Stream((const Stream &)stream){ ! } ! ! NetStream::~NetStream() { ! } ! ! NetStream &NetStream::operator=(const NetStream &stream) { ! if(&stream!=this) { ! Stream::operator=((const Stream &)stream); ! } ! return *this; ! } ! ! } ! --- 1,82 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * CommonC++ (http://cplusplus.sourceforge.net/) ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/netupdater.h" ! #include "openalpp/netstream.h" ! #include "openalpp/sample.h" ! ! namespace openalpp { ! ! NetStream::NetStream(ost::UDPSocket *socket,ost::TCPStream *controlsocket) ! : Stream() { ! unsigned int frequency=11025,buffersize=2048; ! ALenum format=AL_FORMAT_MONO8; ! if(controlsocket) { ! *controlsocket >> format; ! *controlsocket >> frequency; ! *controlsocket >> buffersize; ! } ! updater_=new NetUpdater(socket,controlsocket, ! buffername_,buffer2_->GetName(), ! format,frequency,buffersize*SampleSize(format)); ! } ! ! NetStream::NetStream(ost::UDPSocket *socket,SampleFormat format, ! unsigned int frequency,unsigned int buffersize) ! : Stream() { ! ALenum alformat=0; ! switch(format) { ! case(Mono8): ! alformat=AL_FORMAT_MONO8; ! break; ! case(Mono16): ! alformat=AL_FORMAT_MONO16; ! break; ! case(Stereo8): ! alformat=AL_FORMAT_STEREO8; ! break; ! case(Stereo16): ! alformat=AL_FORMAT_STEREO16; ! break; ! } ! updater_=new NetUpdater(socket,NULL,buffername_,buffer2_->GetName(), ! alformat,frequency,buffersize*SampleSize(format)); ! } ! ! ! NetStream::NetStream(const NetStream &stream) : Stream((const Stream &)stream){ ! } ! ! NetStream::~NetStream() { ! } ! ! NetStream &NetStream::operator=(const NetStream &stream) { ! if(&stream!=this) { ! Stream::operator=((const Stream &)stream); ! } ! return *this; ! } ! ! } ! Index: error.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/src/error.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** error.cpp 11 Nov 2004 07:57:58 -0000 1.6 --- error.cpp 24 Mar 2005 11:47:48 -0000 1.7 *************** *** 1,36 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/error.h" ! ! using namespace openalpp; ! ! //##ModelId=3BDD35A001D5 ! std::ostream &openalpp::Error::put(std::ostream &stream) const { ! return (stream << what()); ! } ! ! std::ostream &openalpp::operator<<(std::ostream &stream,const Error &error) { ! return error.put(stream); ! } ! --- 1,36 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/error.h" ! ! using namespace openalpp; ! ! //##ModelId=3BDD35A001D5 ! std::ostream &openalpp::Error::put(std::ostream &stream) const { ! return (stream << what()); ! } ! ! std::ostream &openalpp::operator<<(std::ostream &stream,const Error &error) { ! return error.put(stream); ! } ! Index: audioenvironment.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/src/audioenvironment.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** audioenvironment.cpp 11 Nov 2004 07:57:58 -0000 1.8 --- audioenvironment.cpp 24 Mar 2005 11:47:48 -0000 1.9 *************** *** 1,158 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/audioenvironment.h" ! ! using namespace openalpp; ! ! AudioEnvironment::AudioEnvironment() throw (InitError): AudioBase() { ! } ! ! AudioEnvironment::AudioEnvironment(int frequency,int refresh,bool synchronous) ! throw (InitError) ! : AudioBase(frequency,refresh,synchronous) { ! } ! ! AudioEnvironment::AudioEnvironment(int frequency,int refresh) throw (InitError) ! : AudioBase(frequency,refresh) { ! } ! ! void AudioEnvironment::setSoundVelocity(float speed) throw(ValueError,FatalError){ ! alDopplerVelocity(speed); ! ALenum error; ! if((error=alGetError())!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError((const char *)alGetString(error)); ! break; ! default: ! throw FatalError("Unknown error in AudioEnvironment::SetSoundSpeed()"); ! break; ! } ! } ! ! float AudioEnvironment::getSoundVelocity() throw (FatalError) { ! ALfloat speed; ! alGetFloatv(AL_DOPPLER_VELOCITY,&speed); ! if(alGetError()!=AL_FALSE) // This isn't strictly necessary... ! throw FatalError("Unknown error in AudioEnviroment::GetSoundVelocity()"); ! return speed; ! } ! ! void AudioEnvironment::setDopplerFactor(float factor) ! throw (ValueError,FatalError) { ! alDopplerFactor(factor); ! ALenum error; ! if((error=alGetError())!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError((const char *)alGetString(error)); ! break; ! default: ! throw FatalError("Unknown error in AudioEnvironment::SetDopplerFactor()"); ! break; ! } ! } ! ! float AudioEnvironment::getDopplerFactor() throw (FatalError) { ! ALfloat(factor); ! alGetFloatv(AL_DOPPLER_FACTOR,&factor); ! if(alGetError()!=AL_FALSE) // This isn't strictly necessary... ! throw FatalError("Unknown error in AudioEnvironment::GetDopplerFactor()"); ! return factor; ! } ! ! void AudioEnvironment::setGain(float gain) { ! alListenerf(AL_GAIN,gain); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for gain"); ! break; ! default: ! throw FatalError("Error trying to set gain!"); ! } ! } ! ! float AudioEnvironment::getGain() throw (FatalError) { ! ALfloat gain; ! alGetListenerf(AL_GAIN,&gain); ! if(alGetError()!=AL_FALSE) // This isn't strictly necessary... ! throw FatalError("Unknown error in AudioEnvironment::GetGain()"); ! return gain; ! } ! ! void AudioEnvironment::setDistanceModel(DistanceModel model) ! throw (FatalError){ ! switch(model) { ! case(None): ! alDistanceModel(AL_NONE); ! break; ! case(InverseDistance): ! alDistanceModel(AL_INVERSE_DISTANCE); ! break; ! case(InverseDistanceClamped): ! alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); ! break; ! default: ! throw FatalError("Unknown model in AudioEnvironment::SetDistanceModel()"); ! } ! if(alGetError()!=AL_FALSE) ! throw FatalError("alDistanceModel failed in AudioEnvironment::SetDistanceModel()"); ! } ! ! DistanceModel AudioEnvironment::getDistanceModel() throw (FatalError) { ! int almodel; ! alGetIntegerv(AL_DISTANCE_MODEL,&almodel); ! switch(almodel) { ! case(AL_NONE): ! return None; ! case(AL_INVERSE_DISTANCE): ! return InverseDistance; ! case(AL_INVERSE_DISTANCE_CLAMPED): ! return InverseDistanceClamped; ! default: ! throw FatalError("Unknown distance model in AudioEnvironment::GetDistanceModel"); ! } ! } ! ! // Static fields in AudioBase ! bool AudioBase::reverbinitiated_; ! void (*AudioBase::alReverbScale)(ALuint sid, ALfloat param); ! void (*AudioBase::alReverbDelay)(ALuint sid, ALfloat param); ! ! void AudioEnvironment::initiateReverb() throw (InitError) { ! if (reverbinitiated_) ! return; ! ! alReverbScale=(void (*)(ALuint sid, ALfloat param)) ! alGetProcAddress((ALubyte *)"alReverbScale_LOKI"); ! alReverbDelay=(void (*)(ALuint sid, ALfloat param)) ! alGetProcAddress((ALubyte *)"alReverbDelay_LOKI"); ! if(!(alReverbScale && alReverbDelay)) { ! throw InitError("Couldn't initiate reverb"); ! } else ! reverbinitiated_=true; ! } ! --- 1,158 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/audioenvironment.h" ! ! using namespace openalpp; ! ! AudioEnvironment::AudioEnvironment() throw (InitError): AudioBase() { ! } ! ! AudioEnvironment::AudioEnvironment(int frequency,int refresh,bool synchronous) ! throw (InitError) ! : AudioBase(frequency,refresh,synchronous) { ! } ! ! AudioEnvironment::AudioEnvironment(int frequency,int refresh) throw (InitError) ! : AudioBase(frequency,refresh) { ! } ! ! void AudioEnvironment::setSoundVelocity(float speed) throw(ValueError,FatalError){ ! alDopplerVelocity(speed); ! ALenum error; ! if((error=alGetError())!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError((const char *)alGetString(error)); ! break; ! default: ! throw FatalError("Unknown error in AudioEnvironment::SetSoundSpeed()"); ! break; ! } ! } ! ! float AudioEnvironment::getSoundVelocity() throw (FatalError) { ! ALfloat speed; ! alGetFloatv(AL_DOPPLER_VELOCITY,&speed); ! if(alGetError()!=AL_FALSE) // This isn't strictly necessary... ! throw FatalError("Unknown error in AudioEnviroment::GetSoundVelocity()"); ! return speed; ! } ! ! void AudioEnvironment::setDopplerFactor(float factor) ! throw (ValueError,FatalError) { ! alDopplerFactor(factor); ! ALenum error; ! if((error=alGetError())!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError((const char *)alGetString(error)); ! break; ! default: ! throw FatalError("Unknown error in AudioEnvironment::SetDopplerFactor()"); ! break; ! } ! } ! ! float AudioEnvironment::getDopplerFactor() throw (FatalError) { ! ALfloat(factor); ! alGetFloatv(AL_DOPPLER_FACTOR,&factor); ! if(alGetError()!=AL_FALSE) // This isn't strictly necessary... ! throw FatalError("Unknown error in AudioEnvironment::GetDopplerFactor()"); ! return factor; ! } ! ! void AudioEnvironment::setGain(float gain) { ! alListenerf(AL_GAIN,gain); ! ALenum error=alGetError(); ! if(error!=AL_FALSE) ! switch(error) { ! case(AL_INVALID_VALUE): ! throw ValueError("Invalid value for gain"); ! break; ! default: ! throw FatalError("Error trying to set gain!"); ! } ! } ! ! float AudioEnvironment::getGain() throw (FatalError) { ! ALfloat gain; ! alGetListenerf(AL_GAIN,&gain); ! if(alGetError()!=AL_FALSE) // This isn't strictly necessary... ! throw FatalError("Unknown error in AudioEnvironment::GetGain()"); ! return gain; ! } ! ! void AudioEnvironment::setDistanceModel(DistanceModel model) ! throw (FatalError){ ! switch(model) { ! case(None): ! alDistanceModel(AL_NONE); ! break; ! case(InverseDistance): ! alDistanceModel(AL_INVERSE_DISTANCE); ! break; ! case(InverseDistanceClamped): ! alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); ! break; ! default: ! throw FatalError("Unknown model in AudioEnvironment::SetDistanceModel()"); ! } ! if(alGetError()!=AL_FALSE) ! throw FatalError("alDistanceModel failed in AudioEnvironment::SetDistanceModel()"); ! } ! ! DistanceModel AudioEnvironment::getDistanceModel() throw (FatalError) { ! int almodel; ! alGetIntegerv(AL_DISTANCE_MODEL,&almodel); ! switch(almodel) { ! case(AL_NONE): ! return None; ! case(AL_INVERSE_DISTANCE): ! return InverseDistance; ! case(AL_INVERSE_DISTANCE_CLAMPED): ! return InverseDistanceClamped; ! default: ! throw FatalError("Unknown distance model in AudioEnvironment::GetDistanceModel"); ! } ! } ! ! // Static fields in AudioBase ! bool AudioBase::reverbinitiated_; ! void (*AudioBase::alReverbScale)(ALuint sid, ALfloat param); ! void (*AudioBase::alReverbDelay)(ALuint sid, ALfloat param); ! ! void AudioEnvironment::initiateReverb() throw (InitError) { ! if (reverbinitiated_) ! return; ! ! alReverbScale=(void (*)(ALuint sid, ALfloat param)) ! alGetProcAddress((ALubyte *)"alReverbScale_LOKI"); ! alReverbDelay=(void (*)(ALuint sid, ALfloat param)) ! alGetProcAddress((ALubyte *)"alReverbDelay_LOKI"); ! if(!(alReverbScale && alReverbDelay)) { ! throw InitError("Couldn't initiate reverb"); ! } else ! reverbinitiated_=true; ! } ! Index: CMakeLists.txt =================================================================== RCS file: /cvsroot/alpp/openalpp/src/CMakeLists.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CMakeLists.txt 11 Nov 2004 07:57:58 -0000 1.3 --- CMakeLists.txt 24 Mar 2005 11:47:48 -0000 1.4 *************** *** 1,19 **** ! SET(SOURCEFILES audiobase audioconvert audioenvironment error groupsource listener sample sounddata source sourcebase referenced) ! ! IF(CCGNU_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} stream netstream streamupdater netupdater) ! IF(PORTAUDIO_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} inputdevice deviceupdater) ! ELSE(PORTAUDIO_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} noinputdevice) ! ENDIF(PORTAUDIO_FOUND) ! IF(VORBIS_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} filestream filestreamupdater) ! ELSE(VORBIS_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} nofilestream) ! ENDIF(VORBIS_FOUND) ! ELSE(CCGNU_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} nostreaming noinputdevice nofilestream) ! ENDIF(CCGNU_FOUND) ! ! ADD_LIBRARY(openalpp SOURCEFILES) --- 1,19 ---- ! SET(SOURCEFILES audiobase audioconvert audioenvironment error groupsource listener sample sounddata source sourcebase referenced) ! ! IF(CCGNU_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} stream netstream streamupdater netupdater) ! IF(PORTAUDIO_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} inputdevice deviceupdater) ! ELSE(PORTAUDIO_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} noinputdevice) ! ENDIF(PORTAUDIO_FOUND) ! IF(VORBIS_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} filestream filestreamupdater) ! ELSE(VORBIS_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} nofilestream) ! ENDIF(VORBIS_FOUND) ! ELSE(CCGNU_FOUND) ! SET(SOURCEFILES ${SOURCEFILES} nostreaming noinputdevice nofilestream) ! ENDIF(CCGNU_FOUND) ! ! ADD_LIBRARY(openalpp SOURCEFILES) Index: listener.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/src/listener.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** listener.cpp 11 Nov 2004 07:57:58 -0000 1.5 --- listener.cpp 24 Mar 2005 11:47:48 -0000 1.6 *************** *** 1,145 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/listener.h" ! ! using namespace openalpp; ! ! Listener *Listener::selectedlistener_=NULL; ! ! /** ! * Internal function for initialisation. ! */ ! void Listener::init(float x,float y,float z, ! float vx,float vy,float vz, ! float directionx, float directiony, float directionz, ! float upx, float upy, float upz) { ! setPosition(x,y,z); ! setVelocity(vx,vy,vz); ! setOrientation(directionx,directiony,directionz, ! upx,upy,upz); ! if(!selectedlistener_) ! select(); ! } ! ! Listener::Listener() : PositionedObject() { ! init(0,0,0, 0,0,0, 0,0,-1, 0,1,0); ! } ! ! Listener::Listener(const Listener &listener) : PositionedObject() { ! listener.getPosition(position_[0],position_[1],position_[2]); ! listener.getVelocity(velocity_[0],velocity_[1],velocity_[2]); ! listener.getOrientation(orientation_[0],orientation_[1],orientation_[2], ! orientation_[3],orientation_[4],orientation_[5]); ! } ! ! Listener::Listener(float x,float y,float z, ! float directionx, float directiony, float directionz, ! float upx, float upy, float upz) : PositionedObject() { ! ! init(x,y,z, 0,0,0, directionx,directiony,directionz, upx,upy,upz); ! ! } ! ! Listener::Listener(float x, float y, float z) : PositionedObject() { ! init(x,y,z, 0,0,0, 0,0,-1, 0,1,0); ! } ! ! Listener::~Listener() { ! if(selectedlistener_==this) ! selectedlistener_=NULL; ! } ! ! void Listener::select() { ! alListenerfv(AL_POSITION,position_); ! alListenerfv(AL_VELOCITY,velocity_); ! alListenerfv(AL_ORIENTATION,orientation_); ! selectedlistener_=this; ! } ! ! bool Listener::isSelected() { ! return (selectedlistener_==this); ! } ! ! void Listener::setOrientation(float directionx,float directiony, ! float directionz, ! float upx, float upy, float upz) { ! orientation_[0]=directionx; ! orientation_[1]=directiony; ! orientation_[2]=directionz; ! orientation_[3]=upx; ! orientation_[4]=upy; ! orientation_[5]=upz; ! if(isSelected()) ! alListenerfv(AL_ORIENTATION,orientation_); ! } ! ! void Listener::getOrientation(float &directionx,float &directiony, ! float &directionz, ! float &upx, float &upy, float &upz) const { ! directionx=orientation_[0]; ! directiony=orientation_[1]; ! directionz=orientation_[2]; ! upx=orientation_[3]; ! upy=orientation_[4]; ! upz=orientation_[5]; ! } ! ! Listener &Listener::operator=(const Listener &listener) { ! if(this!=&listener) { ! listener.getPosition(position_[0],position_[1],position_[2]); ! listener.getVelocity(velocity_[0],velocity_[1],velocity_[2]); ! listener.getOrientation(orientation_[0],orientation_[1],orientation_[2], ! orientation_[3],orientation_[4],orientation_[5]); ! } ! return *this; ! } ! ! void Listener::setPosition(float x, float y, float z) { ! position_[0]=x; ! position_[1]=y; ! position_[2]=z; ! if(isSelected()) ! alListenerfv(AL_POSITION,position_); ! } ! ! void Listener::getPosition(float &x, float &y, float &z) const { ! x=position_[0]; ! y=position_[1]; ! z=position_[2]; ! } ! ! void Listener::setVelocity(float vx, float vy, float vz) { ! velocity_[0]=vx; ! velocity_[1]=vy; ! velocity_[2]=vz; ! if(isSelected()) ! alListenerfv(AL_VELOCITY,velocity_); ! } ! ! void Listener::getVelocity(float &vx, float &vy, float &vz) const { ! vx=velocity_[0]; ! vy=velocity_[1]; ! vz=velocity_[2]; ! } ! --- 1,145 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! */ ! ! #include "openalpp/listener.h" ! ! using namespace openalpp; ! ! Listener *Listener::selectedlistener_=NULL; ! ! /** ! * Internal function for initialisation. ! */ ! void Listener::init(float x,float y,float z, ! float vx,float vy,float vz, ! float directionx, float directiony, float directionz, ! float upx, float upy, float upz) { ! setPosition(x,y,z); ! setVelocity(vx,vy,vz); ! setOrientation(directionx,directiony,directionz, ! upx,upy,upz); ! if(!selectedlistener_) ! select(); ! } ! ! Listener::Listener() : PositionedObject() { ! init(0,0,0, 0,0,0, 0,0,-1, 0,1,0); ! } ! ! Listener::Listener(const Listener &listener) : PositionedObject() { ! listener.getPosition(position_[0],position_[1],position_[2]); ! listener.getVelocity(velocity_[0],velocity_[1],velocity_[2]); ! listener.getOrientation(orientation_[0],orientation_[1],orientation_[2], ! orientation_[3],orientation_[4],orientation_[5]); ! } ! ! Listener::Listener(float x,float y,float z, ! float directionx, float directiony, float directionz, ! float upx, float upy, float upz) : PositionedObject() { ! ! init(x,y,z, 0,0,0, directionx,directiony,directionz, upx,upy,upz); ! ! } ! ! Listener::Listener(float x, float y, float z) : PositionedObject() { ! init(x,y,z, 0,0,0, 0,0,-1, 0,1,0); ... [truncated message content] |