Просмотр исходного кода

implement new methods to ALRenderer, fix ALRenderer::create_buffer

mikymod 12 лет назад
Родитель
Сommit
4b1ce158e5
2 измененных файлов с 39 добавлено и 1 удалено
  1. 31 0
      engine/renderers/al/ALRenderer.cpp
  2. 8 1
      engine/renderers/al/ALRenderer.h

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

@@ -172,6 +172,8 @@ SoundBufferId ALRenderer::create_buffer(const void* data, uint32_t size, uint32_
 
 	// Fills AL buffer
 	AL_CHECK(alBufferData(al_buffer.id, al_buffer.format, data, al_buffer.size, al_buffer.freq));
+
+	return id;
 }
 
 //-----------------------------------------------------------------------------
@@ -264,6 +266,26 @@ void ALRenderer::bind_buffer(SoundSourceId sid, SoundBufferId bid)
 	alSourcei(al_source.id, AL_BUFFER, al_buffer.id);
 }
 
+//-----------------------------------------------------------------------------
+void ALRenderer::set_source_min_distance(SoundSourceId id, float min_distance)
+{
+	CE_ASSERT(m_sources_id_table.has(id), "SoundSource does not exist");
+
+	SoundSource& al_source = m_sources[id.index];
+
+	AL_CHECK(alSourcef(al_source.id, AL_REFERENCE_DISTANCE, min_distance));
+}
+
+//-----------------------------------------------------------------------------
+void ALRenderer::set_source_max_distance(SoundSourceId id, float max_distance)
+{
+	CE_ASSERT(m_sources_id_table.has(id), "SoundSource does not exist");
+
+	SoundSource& al_source = m_sources[id.index];
+
+	AL_CHECK(alSourcef(al_source.id, AL_MAX_DISTANCE, max_distance));
+}
+
 //-----------------------------------------------------------------------------
 void ALRenderer::set_source_position(SoundSourceId id, Vec3& pos)
 {
@@ -294,6 +316,15 @@ void ALRenderer::set_source_direction(SoundSourceId id, Vec3& dir)
 	AL_CHECK(alSource3f(al_source.id, AL_DIRECTION, dir.x, dir.y, dir.z));
 }
 
+void ALRenderer::set_source_pitch(SoundSourceId id, float pitch)
+{
+	CE_ASSERT(m_sources_id_table.has(id), "SoundSource does not exist");
+
+	SoundSource& al_source = m_sources[id.index];
+
+	AL_CHECK(alSourcef(al_source.id, AL_PITCH, pitch));		
+}
+
 //-----------------------------------------------------------------------------
 void ALRenderer::set_source_gain(SoundSourceId id, float gain)
 {

+ 8 - 1
engine/renderers/al/ALRenderer.h

@@ -112,13 +112,20 @@ public:
 
 	/// Binds a AL buffer to AL source
 	void					bind_buffer(SoundSourceId sid, SoundBufferId bid);
-
+	///	Sets source's @a min_distance. From @a min_distance to @a max_distance, sound
+	/// scales from full volume to silence
+	void					set_source_min_distance(SoundSourceId id, float min_distance);
+	///	Sets source's @a max_distance. From @a min_distance to @a max_distance, sound
+	/// scales from full volume to silence
+	void					set_source_max_distance(SoundSourceId id, float max_distance);
 	/// Sets source's @a position. It affects sound audibility
 	void					set_source_position(SoundSourceId id, Vec3& pos);
 	/// Sets source's @a velocity. It affects doppler shift
 	void					set_source_velocity(SoundSourceId id, Vec3& vel);
 	/// Sets source's @a direction. It affects how a sound could be heard
 	void					set_source_direction(SoundSourceId id, Vec3& dir);
+	/// Sets source's @a pitch.
+	void					set_source_pitch(SoundSourceId id, float pitch);
 	/// Sets source's @a gain, that is measure sound's amplification
 	void 					set_source_gain(SoundSourceId id, float gain);
 	/// Sets source's @a rolloff factor. Greater it is, greater sound's attenuation is