Explorar el Código

test about streaming, need a lot of additional work such as async file implementation

mikymod hace 12 años
padre
commit
6441f3e1be

+ 4 - 2
engine/CMakeLists.txt

@@ -269,6 +269,7 @@ set (RENDERERS_HEADERS
 	renderers/DebugRenderer.h
 	renderers/PixelFormat.h
 	renderers/VertexFormat.h
+	renderers/OggBufferCallback.h
 )
 
 set (RESOURCE_SRC
@@ -386,6 +387,7 @@ if (LINUX)
 		GLEW
 		GL
 		openal
+		vorbisfile
 		luajit-5.1
 	)
 
@@ -393,10 +395,10 @@ if (LINUX)
 		-pipe
 		-std=c++03
 		-ansi
-		#-pedantic-errors
+		-pedantic-errors
 		-Wall
 		-Wextra
-		#-Werror
+		-Werror
 		-Wno-long-long
 		-Wno-variadic-macros
 		-g

+ 9 - 3
engine/renderers/AudioRenderer.h

@@ -34,9 +34,9 @@ namespace crown
 
 class Vec3;
 
-typedef Id SoundId;
-typedef Id SoundBufferId;
-typedef Id SoundSourceId;
+typedef		Id 		SoundId;
+typedef 	Id 		SoundBufferId;
+typedef 	Id 		SoundSourceId;
 
 class AudioRenderer
 {
@@ -99,6 +99,12 @@ public:
 	virtual void			set_source_rolloff(SoundSourceId id, const float rolloff) = 0;
 	/// Is source #@a id playing?
 	virtual bool			source_playing(SoundSourceId id) = 0;
+
+	// Tests
+	virtual void			create_stream(const void* data, const uint32_t size, const uint32_t sample_rate, 
+								const uint32_t channels, const uint32_t bxs, SoundBufferId* ids) = 0;
+	virtual void			play_source(SoundSourceId sid, SoundBufferId* bids) = 0;
+
 };
 
 } // namespace crown

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

@@ -26,6 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "ALRenderer.h"
 #include "StringUtils.h"
+#include <vorbis/vorbisfile.h>
+#include "OggBufferCallback.h"
 
 namespace crown
 {
@@ -370,4 +372,62 @@ bool ALRenderer::source_playing(SoundSourceId id)
 	return source_state == AL_PLAYING;
 }
 
+//-----------------------------------------------------------------------------
+void ALRenderer::create_stream(const void* data, const uint32_t size, const uint32_t sample_rate, 
+	const uint32_t channels, const uint32_t bxs, SoundBufferId* ids)
+{
+	ov_callbacks callbacks;
+
+	callbacks.read_func 	= ogg_buffer_read;
+	callbacks.seek_func 	= ogg_buffer_seek;
+	callbacks.close_func	= ogg_buffer_close;
+	callbacks.tell_func 	= ogg_buffer_tell;
+
+	OggBuffer buffer((char*)data, size);
+
+	OggVorbis_File stream;
+
+	int32_t ret;
+
+	ret = ov_open_callbacks((void *)&buffer, &stream, NULL, -1, callbacks);
+	CE_ASSERT(ret == 0, "Unable to open custom callbacks");
+
+	(void)sample_rate;
+	(void)channels;
+	(void)bxs;
+
+	SoundBufferId id1 = m_buffers_id_table.create();
+	SoundBufferId id2 = m_buffers_id_table.create();
+
+	SoundBuffer& al_buffer1 = m_buffers[id1.index];
+	SoundBuffer& al_buffer2 = m_buffers[id2.index];
+
+	// Generates first AL buffer
+	AL_CHECK(alGenBuffers(1, &al_buffer1.id));
+	AL_CHECK(alGenBuffers(1, &al_buffer2.id));
+
+	ids[0] = id1;
+	ids[1] = id2;
+}
+
+//-----------------------------------------------------------------------------
+void ALRenderer::play_source(SoundSourceId sid, SoundBufferId* bids)
+{
+	CE_ASSERT(m_sources_id_table.has(sid), "SoundSource does not exist");
+	CE_ASSERT(m_buffers_id_table.has(bids[0]), "SoundBuffer does not exist");
+	CE_ASSERT(m_buffers_id_table.has(bids[1]), "SoundBuffer does not exist");
+
+	SoundSource& al_source = m_sources[sid.index];
+
+	SoundBuffer& al_buffer1 = m_buffers[bids[0].index];
+	SoundBuffer& al_buffer2 = m_buffers[bids[1].index];
+
+	ALuint buffers[] = {al_buffer1.id, al_buffer2.id};
+
+	alSourceQueueBuffers(source, 2, buffers);
+
+	AL_CHECK(alSourcePlay(al_source.id));
+}
+
+
 } // namespace crown

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

@@ -97,6 +97,13 @@ public:
 
 	bool					source_playing(SoundSourceId id);
 
+	// Tests
+
+	void					create_stream(const void* data, const uint32_t size, const uint32_t sample_rate, 
+								const uint32_t channels, const uint32_t bxs, SoundBufferId* ids);
+
+	void					play_source(SoundSourceId sid, SoundBufferId* bids);
+
 private:
 
 	HeapAllocator 			m_allocator;