Browse Source

implement set_sound_loop and fix somethings in AL

mikymod 12 years ago
parent
commit
46bba66bd4
3 changed files with 24 additions and 5 deletions
  1. 3 0
      engine/audio/SoundRenderer.h
  2. 8 0
      engine/audio/al/ALRenderer.cpp
  3. 13 5
      engine/audio/al/ALRenderer.h

+ 3 - 0
engine/audio/SoundRenderer.h

@@ -74,6 +74,9 @@ public:
 	/// Pauses a sound, specified by @a id
 	/// Pauses a sound, specified by @a id
 	void					pause_sound(SoundId id);
 	void					pause_sound(SoundId id);
 
 
+	/// 
+	void					set_sound_loop(SoundId id, bool loop);
+
 	///	Sets sound's @a min_distance. From @a min_distance to @a max_distance, sound
 	///	Sets sound'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
 	void					set_sound_min_distance(SoundId id, const float min_distance);
 	void					set_sound_min_distance(SoundId id, const float min_distance);

+ 8 - 0
engine/audio/al/ALRenderer.cpp

@@ -204,6 +204,14 @@ void SoundRenderer::pause_sound(SoundId id)
 	m_backend->m_sounds[id.index].pause();
 	m_backend->m_sounds[id.index].pause();
 }
 }
 
 
+//-----------------------------------------------------------------------------
+void SoundRenderer::set_sound_loop(SoundId id, bool loop)
+{
+	CE_ASSERT(m_sounds_id_table.has(id), "Sound does not exists");
+
+	m_backend->m_sounds[id.index].loop(loop);
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void SoundRenderer::set_sound_min_distance(SoundId id, const float min_distance)
 void SoundRenderer::set_sound_min_distance(SoundId id, const float min_distance)
 {
 {

+ 13 - 5
engine/audio/al/ALRenderer.h

@@ -156,6 +156,14 @@ struct Sound
 					{
 					{
 						AL_CHECK(alBufferData(buffer, m_format, m_decoder.data(), m_decoder.size(), m_res->sample_rate()));
 						AL_CHECK(alBufferData(buffer, m_format, m_decoder.data(), m_decoder.size(), m_res->sample_rate()));
 					}
 					}
+					else if (m_looping)
+					{
+						Log::i("Restart sound");
+						m_decoder.rewind();
+						m_decoder.stream();
+						AL_CHECK(alBufferData(buffer, m_format, m_decoder.data(), m_decoder.size(), m_res->sample_rate()));
+					}
+
 
 
 					AL_CHECK(alSourceQueueBuffers(m_id, 1, &buffer));
 					AL_CHECK(alSourceQueueBuffers(m_id, 1, &buffer));
 				}
 				}
@@ -188,15 +196,15 @@ struct Sound
 	}
 	}
 
 
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
-	void set_mode(bool loop)
+	void loop(bool loop)
 	{
 	{
-		if (loop)
+		if (loop && !m_streaming)
 		{
 		{
-			AL_CHECK(alSourcef(m_id, AL_LOOPING, AL_TRUE));
+			AL_CHECK(alSourcei(m_id, AL_LOOPING, AL_TRUE));
 		}
 		}
-		else
+		else if (!loop && !m_streaming)
 		{
 		{
-			AL_CHECK(alSourcef(m_id, AL_LOOPING, AL_FALSE));
+			AL_CHECK(alSourcei(m_id, AL_LOOPING, AL_FALSE));
 		}
 		}
 
 
 		m_looping = loop;
 		m_looping = loop;