AaronCameron.net
Not Left, nor right. Just correct.
Not a Member? - Login or Create an Account
Tuesday the 7th of February 2012 @ 05:22pm
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cAudioSource.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2002  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "audio/cAudioSource.h"
00026 
00027 #include "audio/cAudioChunk.h"
00028 #include "audio/cAudioMixer.h"
00029 
00030 #include "SDL_mixer.h"
00031 
00032 #include <iostream>
00033 using namespace std;
00034 
00035 /******************************************************************************/
00036 namespace n2l
00037 {
00038     /**************************************************************************/
00039     cAudioSource::cAudioSource( const cAutoPtr<const cAudioChunk> &iChunk ) :
00040         mChunk( iChunk ),
00041         mChannel( Audio_NoChannel ),
00042         mLooping( false ),
00043         mDeg( 0.0f ),
00044         mDist( 0.0f ),
00045         mRelVel( 0.0f ),
00046         mIntensity( 100.0f )
00047     {
00048         if (!mChunk.isSet())
00049             throw cBadDataUseException( "cAudioSource::cAudioSource",
00050                 "Audio sources require an audio chunk" );
00051     }
00052 
00053     /**************************************************************************/
00054     cAudioSource::~cAudioSource()
00055     {
00056     }
00057 
00058     /**************************************************************************/
00059     const tAudioChannel cAudioSource::play()
00060     {
00061         stop();
00062         mChannel = mChunk->play( mLooping );
00063         cAudioMixer::registerSource( this );
00064         // Do the effect modification stuff here.
00065         return mChannel;
00066     }
00067 
00068     /**************************************************************************/
00069     void cAudioSource::stop()
00070     {
00071         cAudioMixer::unregisterSource( this );
00072         if (mChannel != Audio_NoChannel) {
00073             Mix_HaltChannel( mChannel );
00074             mChannel = Audio_NoChannel;
00075         }
00076     }
00077 
00078     /**************************************************************************/
00079     void cAudioSource::looping( const tBool &iSet )
00080     {
00081         mLooping = iSet;
00082     }
00083 
00084     /**************************************************************************/
00085     void cAudioSource::pos( const tFloat &iDeg, const tFloat &iDist )
00086     {
00087         if (mChannel==Audio_NoChannel) return;
00088 //      Mix_SetPosition( mChannel, 0,0 );
00089 
00090         const tFloat Damp = mIntensity/1.5f;
00091 
00092         tFloat mul = n2lMax(1.0f,(iDist/Damp)*(iDist/Damp));
00093 
00094 //cout << "Intensity: " << mul << " : " << 255.0f-(255.0f/mul) << endl;
00095         Mix_SetPosition( mChannel, tUint16(iDeg)%360,
00096             tUint8(255.0f-(255.0f/mul)) );
00097     }
00098 
00099     /**************************************************************************/
00100     void cAudioSource::relVel( const tFloat &iVel )
00101     {
00102     }
00103 
00104 }
©2012 Aaron Cameron