Переглянути джерело

implement create_loop_source() in ALRenderer

mikymod 12 роки тому
батько
коміт
827c84ee8b

+ 20 - 16
engine/renderers/AudioRenderer.h

@@ -56,45 +56,49 @@ public:
 
 
 	/// Sets listener parameters. @a position affects audibility of sounds, 
 	/// Sets listener parameters. @a position affects audibility of sounds, 
 	/// @a velocity affects doppler shift and @a orientation affects how a sound could be heard
 	/// @a velocity affects doppler shift and @a orientation affects how a sound could be heard
-	virtual void			set_listener(const Vec3& pos, const Vec3& vel, const Vec3& or_up, const Vec3& or_at) const =0;
+	virtual void			set_listener(const Vec3& pos, const Vec3& vel, const Vec3& or_up, const Vec3& or_at) const = 0;
 
 
 	/// Creates buffer's @a data, with a specific @a size, which contains sound raw data.
 	/// Creates buffer's @a data, with a specific @a size, which contains sound raw data.
 	/// More parameters must be specified, such as @a sample_rate, that is the number of sample per unit of time 
 	/// More parameters must be specified, such as @a sample_rate, that is the number of sample per unit of time 
 	/// taken from a continuous signal to make a discrete signal, @a channels which specifies if sound is mono or stereo and @ bxs
 	/// taken from a continuous signal to make a discrete signal, @a channels which specifies if sound is mono or stereo and @ bxs
 	/// (bits per sample) which specifies the magnitude of samples information.
 	/// (bits per sample) which specifies the magnitude of samples information.
 	/// N.B: stereo sound can not be attenuated
 	/// N.B: stereo sound can not be attenuated
-	virtual SoundBufferId	create_buffer(const void* data, const uint32_t size, const uint32_t sample_rate, const uint32_t channels, const uint32_t bxs) =0;
+	virtual SoundBufferId	create_buffer(const void* data, const uint32_t size, const uint32_t sample_rate, const uint32_t channels, const uint32_t bxs) = 0;
 	/// Destroys buffer
 	/// Destroys buffer
-	virtual void			destroy_buffer(SoundBufferId id) =0;
+	virtual void			destroy_buffer(SoundBufferId id) = 0;
 
 
 	/// Creates a source of sound 
 	/// Creates a source of sound 
-	virtual SoundSourceId	create_source() =0;
+	virtual SoundSourceId	create_source() = 0;
+	/// Creates a perpetual source of sound
+	virtual SoundSourceId	create_loop_source() = 0;
 	/// Plays a sound, specified by @a id, previously created
 	/// Plays a sound, specified by @a id, previously created
-	virtual void			play_source(SoundSourceId sid, SoundBufferId bid) =0;
+	virtual void			play_source(SoundSourceId sid, SoundBufferId bid) = 0;
 	/// Pauses a sound, specified by @a id, previously created
 	/// Pauses a sound, specified by @a id, previously created
-	virtual void			pause_source(SoundSourceId id) =0;
+	virtual void			pause_source(SoundSourceId id) = 0;
 	/// Destroys a sound, specified by @a id, previously created
 	/// Destroys a sound, specified by @a id, previously created
-	virtual void			destroy_source(SoundSourceId id) =0;
+	virtual void			destroy_source(SoundSourceId id) = 0;
+
+
 	///	Sets source's @a min_distance. From @a min_distance to @a max_distance, sound
 	///	Sets source's @a min_distance. From @a min_distance to @a max_distance, sound
 	/// scales from full volume to silence
 	/// scales from full volume to silence
-	virtual void			set_source_min_distance(SoundSourceId id,  const float min_distance) =0;
+	virtual void			set_source_min_distance(SoundSourceId id,  const float min_distance) = 0;
 	///	Sets source's @a max_distance. From @a min_distance to @a max_distance, sound
 	///	Sets source's @a max_distance. From @a min_distance to @a max_distance, sound
 	/// scales from full volume to silence
 	/// scales from full volume to silence
-	virtual void			set_source_max_distance(SoundSourceId id,  const float max_distance) =0;
+	virtual void			set_source_max_distance(SoundSourceId id,  const float max_distance) = 0;
 	/// Sets source's @a position. It affects sound audibility
 	/// Sets source's @a position. It affects sound audibility
-	virtual void			set_source_position(SoundSourceId id, const Vec3& pos) =0;
+	virtual void			set_source_position(SoundSourceId id, const Vec3& pos) = 0;
 	/// Sets source's @a velocity. It affects doppler shift
 	/// Sets source's @a velocity. It affects doppler shift
-	virtual void			set_source_velocity(SoundSourceId id, const Vec3& vel) =0;
+	virtual void			set_source_velocity(SoundSourceId id, const Vec3& vel) = 0;
 	/// Sets source's @a direction. It affects how a sound could be heard
 	/// Sets source's @a direction. It affects how a sound could be heard
-	virtual void			set_source_direction(SoundSourceId id, const Vec3& dir) =0;
+	virtual void			set_source_direction(SoundSourceId id, const Vec3& dir) = 0;
 	/// Sets source's @a pitch.
 	/// Sets source's @a pitch.
-	virtual void			set_source_pitch(SoundSourceId id, const float pitch) =0;
+	virtual void			set_source_pitch(SoundSourceId id, const float pitch) = 0;
 	/// Sets source's @a gain, that is measure sound's amplification
 	/// Sets source's @a gain, that is measure sound's amplification
-	virtual void			set_source_gain(SoundSourceId id, const float gain) =0;
+	virtual void			set_source_gain(SoundSourceId id, const float gain) = 0;
 	/// Sets source's @a rolloff factor. Greater it is, greater sound's attenuation is
 	/// Sets source's @a rolloff factor. Greater it is, greater sound's attenuation is
-	virtual void			set_source_rolloff(SoundSourceId id, const float rolloff) =0;
+	virtual void			set_source_rolloff(SoundSourceId id, const float rolloff) = 0;
 	/// Is source #@a id playing?
 	/// Is source #@a id playing?
-	virtual bool			source_playing(SoundSourceId id) =0;
+	virtual bool			source_playing(SoundSourceId id) = 0;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 22 - 0
engine/renderers/al/ALRenderer.cpp

@@ -217,6 +217,28 @@ SoundSourceId ALRenderer::create_source()
 	return id;
 	return id;
 }
 }
 
 
+//-----------------------------------------------------------------------------
+SoundSourceId ALRenderer::create_loop_source()
+{
+	SoundSourceId id = m_sources_id_table.create();
+
+	SoundSource& al_source = m_sources[id.index];
+
+	// Creates AL source
+	AL_CHECK(alGenSources(1, &al_source.id));
+
+	AL_CHECK(alSourcef(al_source.id, AL_PITCH, 1.0f));
+
+	AL_CHECK(alSourcef(al_source.id, AL_REFERENCE_DISTANCE, 0.1f));
+
+	AL_CHECK(alSourcef(al_source.id, AL_MAX_DISTANCE, 1000.0f));
+
+	AL_CHECK(alSourcef(al_source.id, AL_LOOPING, AL_TRUE));
+
+	return id;
+}
+
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void ALRenderer::play_source(SoundSourceId sid, SoundBufferId bid)
 void ALRenderer::play_source(SoundSourceId sid, SoundBufferId bid)
 {
 {

+ 2 - 0
engine/renderers/al/ALRenderer.h

@@ -69,6 +69,8 @@ public:
 
 
 	SoundSourceId			create_source();
 	SoundSourceId			create_source();
 
 
+	SoundSourceId			create_loop_source();
+
 	void 					play_source(SoundSourceId sid, SoundBufferId bid);
 	void 					play_source(SoundSourceId sid, SoundBufferId bid);
 
 
 	void					pause_source(SoundSourceId id);
 	void					pause_source(SoundSourceId id);