diff engine/core/audio/soundemitter.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/engine/core/audio/soundemitter.h	Sun Jun 29 18:44:17 2008 +0000
@@ -0,0 +1,191 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2008 by the FIFE Team                              *
+ *   http://www.fifengine.de                                               *
+ *   This file is part of FIFE.                                            *
+ *                                                                         *
+ *   FIFE is free software; you can redistribute it and/or modify          *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
+ ***************************************************************************/
+ 
+#ifndef FIFE_SOUNDEMITTER_H_
+#define FIFE_SOUNDEMITTER_H_
+
+// Standard C++ library includes
+
+// Platform specific includes
+
+// 3rd party library includes
+
+// FIFE includes
+// These includes are split up in two parts, separated by one empty line
+// First block: files included from the FIFE root src directory
+// Second block: files included from the same folder
+#include "vfs/raw/rawdata.h"
+#include "util/time/timeevent.h"
+
+#include "soundclip.h"
+
+namespace FIFE {
+
+	class SoundManager;
+	class SoundClipPool;
+	
+	/** The class for playing audio files
+	 */
+	class SoundEmitter : private TimeEvent {
+	public:
+		SoundEmitter(SoundManager* manager, SoundClipPool* pool, unsigned int uid);
+		
+		~SoundEmitter();
+		
+		/** Returns the emitter-id
+		 */
+		unsigned int getID() {
+			return m_emitterid;
+		}
+		
+		/** Sets Positioning-Type
+		 * Default is false
+		 * 
+		 * @param relative If set to true, the emitters position will be interpreted relative to the listener object
+		 * 
+		 */
+		void setPositioning(bool relative) {
+			alSourcei(m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
+		}
+
+		/** Sets the sound clip to be used by this emitter.
+		 * @param sound_id SoundClipPool id of the sound to be used.
+		 */
+		void setSoundClip(unsigned int sound_id);
+		
+		/** Reset the emitter, free all internal buffers
+		 *  
+		 * @param defaultall If set to true, emitter position, velocity, gain and type will be set to the default values
+		 */
+		void reset(bool defaultall = false);
+
+		/** Releases the emitter
+		 */
+		void release();
+		
+		/** Sets the playing mode
+		 */
+		void setLooping(bool loop);
+		
+		/** Plays the associated audio file.
+		 */
+		void play();
+		
+		/** Stops playing the audio file and rewinds to the beginning
+		 */
+		void stop();
+		
+		/** Pauses playing the audio file
+		 */
+		void pause() {
+			if (m_soundclip) {
+				alSourcePause(m_source);
+			}
+		}
+		
+		/** Sets the gain of the emitter
+		 *
+		 * @param gain The gain value. 0=silence ... 1.0=normal loudness.
+		 */
+		void setGain(float gain) {
+			alSourcef(m_source, AL_GAIN, gain);
+		}
+		
+		/** Returns the gain of the emitter
+		 *
+		 * @return The gain value. 0=silence ... 1.0=normal loudness.
+		 */
+		float getGain() {
+			float tmp;
+			alGetSourcef(m_source, AL_GAIN, &tmp);
+			return tmp;
+		}
+		
+		/** Tests if the audio data is stereo data or mono.
+		 * 
+		 * @return Returns true if the audio data is stereo, false if mono.
+		 */		
+		bool isStereo() {
+			if (m_soundclip) {
+				return m_soundclip->getDecoder()->isStereo();
+			}
+			return false;
+		}
+		
+		/** Returns the bit resolution
+		 */
+		short getBitResolution() {
+			if (m_soundclip) {
+				return m_soundclip->getDecoder()->getBitResolution();
+			}
+			return 0;
+		}
+		
+		/** Returns the sample rate
+		 */
+		unsigned long getSampleRate() {
+			if (m_soundclip) {
+				return m_soundclip->getDecoder()->getSampleRate();
+			}
+			return 0;
+		}
+		
+		/** Sets the cursor position in the audio file
+		 */
+		void setCursor(SoundPositionType type, float value);
+		
+		/** Returns the cursor position in the audio file
+		 */
+		float getCursor(SoundPositionType type);
+		
+		/** Sets the position of the SoundEmitter in the virtual audio space.
+		 */
+		void setPosition(float x, float y, float z) {
+			alSource3f(m_source, AL_POSITION, x, y, z);
+		}
+		
+		/** Sets the velocity of the SoundEmitter in the virtual audio space.
+		 */
+		void setVelocity(float x, float y, float z) {
+			alSource3f(m_source, AL_VELOCITY, x, y, z);
+		}
+		
+	private:
+		/** Implementation of the pure virtual function from TimeEvent to update streaming
+		 */
+		virtual void updateEvent(unsigned long time);
+
+		/** Internal function to attach a soundclip to the source
+		 */
+		void attachSoundClip();
+
+		SoundManager*       m_manager;
+		SoundClipPool*			m_pool;
+		ALuint							m_source;			// The openAL-source
+		SoundClip*					m_soundclip;	// the attached soundclip
+		unsigned int				m_soundclipid;// id of the attached soundclip
+		unsigned int				m_streamid;		// the id of the stream
+		unsigned int				m_emitterid;	// the emitter-id
+		bool								m_loop;				// loop?
+	};
+}
+
+#endif