Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ALStreamingBuffer

- ozEngine
  * ALStreamingBuffer for straming Ogg Vorbis files through a pair of queued AL
    buffers
  • Loading branch information...
commit 6086981ba66858aafa3ca5d6684f3f5b868f3a5c 1 parent 75f6ba9
@ducakar authored
View
2  src/builder/MD3.cc
@@ -147,7 +147,7 @@ void MD3::buildMesh( const char* name, int frame )
}
}
- // FIXME indexBase unused
+ // FIXME cppcheck: indexBase unused.
int indexBase = 0;
is.rewind();
View
2  src/client/Mesh.cc
@@ -177,7 +177,7 @@ void Mesh::drawScheduled( int mask )
shader.program( mesh->shaderId );
foreach( instance, mesh->instances.citer() ) {
- // HACK: This is not a nice way.
+ // HACK This is not a nice way to draw non-trasparent parts for which alpha < 1 has been set.
int instanceMask = mask;
if( instance->alpha != 1.0f ) {
View
2  src/client/Profile.cc
@@ -77,7 +77,7 @@ void Profile::init()
}
}
- // HACK default profile
+ // HACK Default player profile is hard-coded.
if( !configExists ) {
profileConfig.add( "class", "beast" );
profileConfig.add( "weaponItem", 0 );
View
8 src/matrix/Vehicle.cc
@@ -117,22 +117,22 @@ void Vehicle::service()
void Vehicle::staticHandler()
{
- // TODO
+ // TODO Static turret handler.
}
void Vehicle::wheeledHandler()
{
- // TODO
+ // TODO Wheeled vehicle handler.
}
void Vehicle::trackedHandler()
{
- // TODO
+ // TODO Tracked vehicle handler.
}
void Vehicle::mechHandler()
{
- // TODO
+ // TODO Mech warrior handler.
}
void Vehicle::hoverHandler()
View
2  src/ozCore/SharedLib.cc
@@ -55,7 +55,7 @@ void SharedLib::close()
#else
-const bool SharedLib::SUPPORTED = true;
+const bool SharedLib::IS_SUPPORTED = true;
SharedLib::Method* SharedLib::get( const char* symbol ) const
{
View
2  src/ozCore/SharedLib.hh
@@ -69,7 +69,7 @@ class SharedLib
/**
* True iff platform supports dynamic linking.
*/
- static const bool SUPPORTED;
+ static const bool IS_SUPPORTED;
/**
* Generic method type to avoid casts between pointer-to-function and pointer-to-object.
View
4 src/ozCore/System.hh
@@ -34,7 +34,7 @@
* @def OZ_WARNING
* Wrapper for `System::warning()`, filling in the current function, file and line parameters.
*/
-// FIXME: Add a space after ellipsis once KDevelop gets that bug fixed.
+// FIXME Add a space after ellipsis once KDevelop gets that bug fixed.
#define OZ_WARNING( ...) \
oz::System::warning( __PRETTY_FUNCTION__, __FILE__, __LINE__, 0, __VA_ARGS__ )
@@ -42,7 +42,7 @@
* @def OZ_ERROR
* Wrapper for `System::error()`, filling in the current function, file and line parameters.
*/
-// FIXME: Add a space after ellipsis once KDevelop gets that bug fixed.
+// FIXME Add a space after ellipsis once KDevelop gets that bug fixed.
#define OZ_ERROR( ...) \
oz::System::error( __PRETTY_FUNCTION__, __FILE__, __LINE__, 0, __VA_ARGS__ )
View
8 src/ozDynamics/collision/Collider.cc
@@ -163,7 +163,7 @@ bool Collider::boxCapsule( const Mat33& rot0, const Shape* box_,
const Box* box = static_cast<const Box*>( box_ );
const Capsule* capsule = static_cast<const Capsule*>( capsule_ );
- // TODO
+ // TODO Box-capsule collision.
static_cast<void>( rot0 );
static_cast<void>( rot1 );
static_cast<void>( box );
@@ -181,7 +181,7 @@ bool Collider::boxPolytope( const Mat33& rot0, const Shape* box_,
const Box* box = static_cast<const Box*>( box_ );
const Polytope* polytope = static_cast<const Polytope*>( polytope_ );
- // TODO
+ // TODO Box-polytope collision.
static_cast<void>( rot0 );
static_cast<void>( rot1 );
static_cast<void>( box );
@@ -253,7 +253,7 @@ bool Collider::capsulePolytope( const Mat33& rot0, const Shape* capsule_,
const Capsule* capsule = static_cast<const Capsule*>( capsule_ );
const Polytope* polytope = static_cast<const Polytope*>( polytope_ );
- // TODO
+ // TODO Capsule-polytope collision.
static_cast<void>( rot0 );
static_cast<void>( rot1 );
static_cast<void>( capsule );
@@ -297,7 +297,7 @@ bool Collider::polytopePolytope( const Mat33& rot0, const Shape* polytope0_,
const Polytope* polytope0 = static_cast<const Polytope*>( polytope0_ );
const Polytope* polytope1 = static_cast<const Polytope*>( polytope1_ );
- // TODO
+ // TODO Polytope-polytope collision.
static_cast<void>( rot0 );
static_cast<void>( rot1 );
static_cast<void>( polytope0 );
View
98 src/ozEngine/ALBuffer.cc
@@ -27,45 +27,11 @@
#include "ALBuffer.hh"
#include "OpenAL.hh"
-
-// We don't use those callbacks anywhere and they don't compile on MinGW.
-#define OV_EXCLUDE_STATIC_CALLBACKS
-#include <vorbis/vorbisfile.h>
+#include "vorbis.h"
namespace oz
{
-static size_t vorbisRead( void* buffer, size_t size, size_t n, void* handle )
-{
- InputStream* istream = static_cast<InputStream*>( handle );
-
- int blockSize = int( size );
- int nBlocks = min( int( n ), istream->available() / blockSize );
-
- istream->readChars( static_cast<char*>( buffer ), nBlocks * blockSize );
- return size_t( nBlocks );
-}
-
-static int vorbisSeek( void* handle, ogg_int64_t offset, int whence )
-{
- InputStream* istream = static_cast<InputStream*>( handle );
-
- const char* origin = whence == SEEK_CUR ? istream->pos() :
- whence == SEEK_END ? istream->end() : istream->begin();
-
- istream->set( origin + offset );
- return 0;
-}
-
-static long vorbisTell( void* handle )
-{
- InputStream* istream = static_cast<InputStream*>( handle );
-
- return long( istream->tell() );
-}
-
-static ov_callbacks VORBIS_CALLBACKS = { vorbisRead, vorbisSeek, nullptr, vorbisTell };
-
ALBuffer::ALBuffer() :
bufferId( 0 )
{}
@@ -85,30 +51,26 @@ ALSource ALBuffer::createSource() const
{
ALSource source;
- if( bufferId == 0 ) {
- return source;
- }
-
- source.create();
+ if( bufferId != 0 ) {
+ source.create();
- if( source.isCreated() ) {
- alSourcei( source.id(), AL_BUFFER, int( bufferId ) );
+ if( source.isCreated() ) {
+ alSourcei( source.id(), AL_BUFFER, int( bufferId ) );
+ }
}
return source;
}
bool ALBuffer::create()
{
- destroy();
-
- alGenBuffers( 1, &bufferId );
+ if( bufferId == 0 ) {
+ alGenBuffers( 1, &bufferId );
+ }
return bufferId != 0;
}
bool ALBuffer::load( const File& file )
{
- destroy();
-
Buffer buffer;
InputStream istream;
@@ -162,11 +124,14 @@ bool ALBuffer::load( const File& file )
#endif
- alGenBuffers( 1, &bufferId );
- alBufferData( bufferId, format, data, size, rate );
+ create();
+
+ if( bufferId != 0 ) {
+ alBufferData( bufferId, format, data, size, rate );
+ }
OZ_AL_CHECK_ERROR();
- return true;
+ return bufferId != 0;
}
else {
OggVorbis_File ovStream;
@@ -180,37 +145,28 @@ bool ALBuffer::load( const File& file )
return false;
}
- int rate = int( vorbisInfo->rate );
int nChannels = vorbisInfo->channels;
- int size = int( ov_pcm_total( &ovStream, -1 ) ) * nChannels * 2;
-
if( nChannels != 1 && nChannels != 2 ) {
ov_clear( &ovStream );
return false;
}
- char* data = new char[size];
- long bytesRead = 0;
- long result;
-
- do {
- int section;
- result = ov_read( &ovStream, data + bytesRead, size - int( bytesRead ), 0, 2, 1, &section );
-
- if( result < 0 ) {
- delete[] data;
- ov_clear( &ovStream );
- return false;
- }
+ ALenum format = nChannels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
+ int rate = int( vorbisInfo->rate );
+ int size = int( ov_pcm_total( &ovStream, -1 ) ) * nChannels * int( sizeof( short ) );
+ char* data = new char[size];
- bytesRead += result;
+ if( !decodeVorbis( &ovStream, data, size ) ) {
+ delete[] data;
+ ov_clear( &ovStream );
+ return false;
}
- while( result > 0 && bytesRead < size );
- ALenum format = nChannels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
+ create();
- alGenBuffers( 1, &bufferId );
- alBufferData( bufferId, format, data, size, rate );
+ if( bufferId != 0 ) {
+ alBufferData( bufferId, format, data, size, rate );
+ }
delete[] data;
ov_clear( &ovStream );
View
14 src/ozEngine/ALBuffer.hh
@@ -99,21 +99,33 @@ class ALBuffer
/**
* Create a new OpenAL source for this buffer.
+ *
+ * If the buffer does not exist, this returns an uninitialised `ALSource`.
*/
ALSource createSource() const;
/**
* Create a new uninitialised OpenAL buffer.
+ *
+ * This is a NOP if buffer already exists.
*/
bool create();
/**
- * Create a new OpenAL buffer from the given WAVE or Ogg Vorbis file.
+ * Create buffer if necessary and load data from the given WAVE or Ogg Vorbis file.
+ *
+ * If buffer already exists, its contents is replaced by the new data.
+ *
+ * @note
+ * OpenAL error is generated if a buffer contents is changed while some source plays it.
*/
bool load( const File& file );
/**
* Destroy OpenAL buffer if created.
+ *
+ * @note
+ * OpenAL error is generated if a buffer is deleted while some source is still bound to it.
*/
void destroy();
View
181 src/ozEngine/ALStreamingBuffer.cc
@@ -28,49 +28,29 @@
#include "OpenAL.hh"
-// We don't use those callbacks anywhere and they don't compile on MinGW.
-#define OV_EXCLUDE_STATIC_CALLBACKS
-#include <vorbis/vorbisfile.h>
+#include "vorbis.h"
namespace oz
{
-static size_t vorbisRead( void* buffer, size_t size, size_t n, void* handle )
+struct ALStreamingBuffer::Stream
{
- InputStream* istream = static_cast<InputStream*>( handle );
+ static const int BUFFER_SIZE = 65536 / 2;
- int blockSize = int( size );
- int nBlocks = min( int( n ), istream->available() / blockSize );
-
- istream->readChars( static_cast<char*>( buffer ), nBlocks * blockSize );
- return size_t( nBlocks );
-}
-
-static int vorbisSeek( void* handle, ogg_int64_t offset, int whence )
-{
- InputStream* istream = static_cast<InputStream*>( handle );
-
- const char* origin = whence == SEEK_CUR ? istream->pos() :
- whence == SEEK_END ? istream->end() : istream->begin();
-
- istream->set( origin + offset );
- return 0;
-}
-
-static long vorbisTell( void* handle )
-{
- InputStream* istream = static_cast<InputStream*>( handle );
-
- return long( istream->tell() );
-}
-
-static ov_callbacks VORBIS_CALLBACKS = { vorbisRead, vorbisSeek, nullptr, vorbisTell };
+ Buffer buffer;
+ InputStream istream;
+ OggVorbis_File ovStream;
+ ALenum format;
+ int rate;
+ char samples[BUFFER_SIZE];
+};
ALStreamingBuffer::ALStreamingBuffer()
{
bufferIds[0] = 0;
bufferIds[1] = 0;
sourceId = 0;
+ stream = nullptr;
}
ALStreamingBuffer::ALStreamingBuffer( const File& file )
@@ -78,6 +58,7 @@ ALStreamingBuffer::ALStreamingBuffer( const File& file )
bufferIds[0] = 0;
bufferIds[1] = 0;
sourceId = 0;
+ stream = nullptr;
load( file );
}
@@ -87,54 +68,152 @@ ALStreamingBuffer::~ALStreamingBuffer()
destroy();
}
-ALSource ALStreamingBuffer::createSource()
+bool ALStreamingBuffer::update()
{
- ALSource source;
+ if( sourceId == 0 || stream == nullptr ) {
+ return false;
+ }
+ if( !alIsSource( sourceId ) ) {
+ sourceId = 0;
+ return false;
+ }
- if( bufferIds[0] == 0 ) {
- return source;
+ int nProcessed;
+ alGetSourcei( sourceId, AL_BUFFERS_PROCESSED, &nProcessed );
+
+ if( nProcessed == 0 ) {
+ return true;
}
- source.create();
+ uint bufferId;
+ alSourceUnqueueBuffers( sourceId, 1, &bufferId );
- if( source.isCreated() ) {
- sourceId = source.id();
- alSourceQueueBuffers( source.id(), 2, bufferIds );
+ if( !decodeVorbis( &stream->ovStream, stream->samples, Stream::BUFFER_SIZE ) ) {
+ ov_clear( &stream->ovStream );
+ delete stream;
+ stream = nullptr;
+ return false;
}
- return source;
+
+ alBufferData( bufferId, stream->format, stream->samples, Stream::BUFFER_SIZE, stream->rate );
+ alSourceQueueBuffers( sourceId, 1, &bufferId );
+ return true;
}
-void ALStreamingBuffer::detachSource()
+ALSource ALStreamingBuffer::createSource()
{
- if( sourceId == 0 ) {
- return;
- }
+ ALSource source;
- alSourceStop( sourceId );
- alSourceUnqueueBuffers( sourceId, 2, bufferIds );
- sourceId = 0;
+ if( bufferIds[0] != 0 ) {
+ source.create();
+
+ if( source.isCreated() ) {
+ sourceId = source.id();
+ alSourceQueueBuffers( source.id(), 2, bufferIds );
+ }
+ }
+ return source;
}
-void ALStreamingBuffer::update()
+bool ALStreamingBuffer::create()
{
-
+ if( bufferIds[0] == 0 ) {
+ alGenBuffers( 2, bufferIds );
+ }
+ return bufferIds[0] != 0;
}
bool ALStreamingBuffer::load( const File& file )
{
- destroy();
+ if( sourceId != 0 ) {
+ if( alIsSource( sourceId ) ) {
+ alSourceStop( sourceId );
+ alSourceUnqueueBuffers( sourceId, 2, bufferIds );
+ }
+ else {
+ sourceId = 0;
+ }
+ }
+
+ stream = stream == nullptr ? new Stream() : stream;
+ stream->buffer = file.read();
+ stream->istream = stream->buffer.inputStream();
+
+ if( stream->buffer.isEmpty() ) {
+ delete stream;
+ stream = nullptr;
+ return false;
+ }
+
+ if( ov_open_callbacks( &stream->istream, &stream->ovStream, nullptr, 0, VORBIS_CALLBACKS ) != 0 )
+ {
+ delete stream;
+ stream = nullptr;
+ return false;
+ }
+
+ vorbis_info* vorbisInfo = ov_info( &stream->ovStream, -1 );
+ if( vorbisInfo == nullptr ) {
+ ov_clear( &stream->ovStream );
+ delete stream;
+ stream = nullptr;
+ return false;
+ }
+
+ int nChannels = vorbisInfo->channels;
+ if( nChannels != 1 && nChannels != 2 ) {
+ ov_clear( &stream->ovStream );
+ delete stream;
+ stream = nullptr;
+ return false;
+ }
+
+ stream->format = nChannels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
+ stream->rate = int( vorbisInfo->rate );
+ create();
+
+ if( bufferIds[0] != 0 ) {
+ if( !decodeVorbis( &stream->ovStream, stream->samples, Stream::BUFFER_SIZE ) ) {
+ ov_clear( &stream->ovStream );
+ delete stream;
+ stream = nullptr;
+ }
+
+ alBufferData( bufferIds[0], stream->format, &stream->samples, Stream::BUFFER_SIZE,
+ stream->rate );
+
+ if( !decodeVorbis( &stream->ovStream, stream->samples, Stream::BUFFER_SIZE ) ) {
+ ov_clear( &stream->ovStream );
+ delete stream;
+ stream = nullptr;
+ }
+
+ alBufferData( bufferIds[1], stream->format, &stream->samples, Stream::BUFFER_SIZE,
+ stream->rate );
+ }
+
+ if( sourceId != 0 ) {
+ alSourceQueueBuffers( sourceId, 2, bufferIds );
+ }
+ OZ_AL_CHECK_ERROR();
return true;
}
void ALStreamingBuffer::destroy()
{
if( bufferIds[0] != 0 ) {
- detachSource();
+ if( sourceId != 0 && alIsSource( sourceId ) ) {
+ alSourceStop( sourceId );
+ }
+
+ delete stream;
alDeleteBuffers( 2, bufferIds );
bufferIds[0] = 0;
bufferIds[1] = 0;
+ sourceId = 0;
+ stream = nullptr;
}
}
View
54 src/ozEngine/ALStreamingBuffer.hh
@@ -38,9 +38,11 @@ class ALStreamingBuffer
{
private:
- Buffer fileBuffer; ///< Contents of the streamed Ogg Vorbis file.
- uint bufferIds[2]; ///< OpenAL buffer ids, both 0 if not loaded.
- uint sourceId; ///< Target OpenAL source for which buffers are queued.
+ struct Stream;
+
+ uint bufferIds[2]; ///< OpenAL buffer ids, both 0 if not loaded.
+ uint sourceId; ///< Target OpenAL source for which buffers are queued.
+ Stream* stream; ///< Internal file buffer and decoder state.
public:
@@ -55,7 +57,7 @@ class ALStreamingBuffer
explicit ALStreamingBuffer( const File& file );
/**
- * Destructor, destroys OpenAL buffers if created.
+ * Destructor, invokes `destroy()`.
*/
~ALStreamingBuffer();
@@ -64,14 +66,15 @@ class ALStreamingBuffer
*/
ALStreamingBuffer( ALStreamingBuffer&& b )
{
- fileBuffer = static_cast<Buffer&&>( b.fileBuffer );
bufferIds[0] = b.bufferIds[0];
bufferIds[1] = b.bufferIds[1];
sourceId = b.sourceId;
+ stream = b.stream;
b.bufferIds[0] = 0;
b.bufferIds[1] = 0;
b.sourceId = 0;
+ b.stream = nullptr;
}
/**
@@ -83,14 +86,15 @@ class ALStreamingBuffer
return *this;
}
- fileBuffer = static_cast<Buffer&&>( b.fileBuffer );
bufferIds[0] = b.bufferIds[0];
bufferIds[1] = b.bufferIds[1];
sourceId = b.sourceId;
+ stream = b.stream;
b.bufferIds[0] = 0;
b.bufferIds[1] = 0;
b.sourceId = 0;
+ stream = nullptr;
return *this;
}
@@ -106,6 +110,14 @@ class ALStreamingBuffer
}
/**
+ * Get attached OpenAL source id.
+ */
+ uint attachedSourceId() const
+ {
+ return sourceId;
+ }
+
+ /**
* True iff loaded.
*/
bool isLoaded() const
@@ -114,39 +126,43 @@ class ALStreamingBuffer
}
/**
- * Create a new source and attach it to this buffer queue.
- *
- * Streaming only works for the attached source (the last source created by this function).
+ * True iff a source is attached.
*/
- ALSource createSource();
+ bool isSourceAttached() const
+ {
+ return sourceId != 0;
+ }
/**
- * Detach last created source.
+ * Update buffers and queue for the attached source.
*
- * Forgets the last created source and stops queuing buffers for it.
+ * If a buffer has been processed, unqueues it, fills it with new data and puts it back into
+ * the queue. This is a NOP if no source is attached.
*/
- void detachSource();
+ bool update();
/**
- * Update buffers and queue for the attached source.
+ * Create a new source and attach it to this buffer queue.
*
- * If a buffer has been processed, unqueues it, fills it with new data and puts it back into
- * the queue. This is a NOP if no source is attached.
+ * The buffers must be created to attach a source. If there already is a source attached it is
+ * forgotten.
*/
- void update();
+ ALSource createSource();
/**
- * Create a new uninitialised OpenAL buffers for queuing.
+ * Create a pair of uninitialised OpenAL buffers for streaming.
*/
bool create();
/**
* Create a new buffer queue from the given Ogg Vorbis file.
+ *
+ * If the source is already attached, it is stopped and newly filled buffers are queued for it.
*/
bool load( const File& file );
/**
- * Destroy OpenAL buffers if created and detach the source if attached.
+ * Destroy OpenAL buffers if created and forget the attached source.
*/
void destroy();
View
1  src/ozEngine/CMakeLists.txt
@@ -23,6 +23,7 @@ add_library( ozEngine
OpenAL.cc
OpenGL.cc
Pepper.cc
+ vorbis.cc
Window.cc
#END SOURCES
)
View
85 src/ozEngine/vorbis.cc
@@ -0,0 +1,85 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/vorbis.cc
+ */
+
+#include "vorbis.h"
+
+namespace oz
+{
+
+static size_t vorbisRead( void* buffer, size_t size, size_t n, void* handle )
+{
+ InputStream* istream = static_cast<InputStream*>( handle );
+
+ int blockSize = int( size );
+ int nBlocks = min( int( n ), istream->available() / blockSize );
+
+ istream->readChars( static_cast<char*>( buffer ), nBlocks * blockSize );
+ return size_t( nBlocks );
+}
+
+static int vorbisSeek( void* handle, ogg_int64_t offset, int whence )
+{
+ InputStream* istream = static_cast<InputStream*>( handle );
+
+ const char* origin = whence == SEEK_CUR ? istream->pos() :
+ whence == SEEK_END ? istream->end() : istream->begin();
+
+ istream->set( origin + offset );
+ return 0;
+}
+
+static long vorbisTell( void* handle )
+{
+ InputStream* istream = static_cast<InputStream*>( handle );
+
+ return long( istream->tell() );
+}
+
+OZ_HIDDEN
+ov_callbacks VORBIS_CALLBACKS = { vorbisRead, vorbisSeek, nullptr, vorbisTell };
+
+OZ_HIDDEN
+bool decodeVorbis( OggVorbis_File* stream, char* buffer, int size )
+{
+ long bytesRead = 0;
+ long result;
+
+ do {
+ int section;
+ result = ov_read( stream, buffer + bytesRead, size - int( bytesRead ), 0, 2, 1, &section );
+
+ if( result < 0 ) {
+ return false;
+ }
+
+ bytesRead += result;
+ }
+ while( result > 0 && bytesRead < long( size ) );
+
+ return result > 0;
+}
+
+}
View
46 src/ozEngine/vorbis.h
@@ -0,0 +1,46 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/vorbis.h
+ *
+ * Internal header with common Ogg Vorbis utilities used by `ALBuffer` and `ALStreamingBuffer`.
+ */
+
+#pragma once
+
+#include "common.hh"
+
+// We don't use those callbacks anywhere and they don't compile on MinGW.
+#define OV_EXCLUDE_STATIC_CALLBACKS
+#include <vorbis/vorbisfile.h>
+
+namespace oz
+{
+
+// Ogg Vorbis callbacks for reading from InputStream.
+extern ov_callbacks VORBIS_CALLBACKS;
+
+// Decode next chunk of Ogg Vorbis stream and write PCM data to the given buffer.
+bool decodeVorbis( OggVorbis_File* stream, char* buffer, int size );
+
+}
View
13 src/tests/test.cc
@@ -25,7 +25,6 @@
#include <ozEngine/ozEngine.hh>
#include <SDL.h>
#include <AL/alc.h>
-#include <vector>
using namespace oz;
@@ -39,11 +38,13 @@ int main( int argc, char** argv )
ALCcontext* context = alcCreateContext( device, nullptr );
alcMakeContextCurrent( context );
- ALBuffer buffer( "/usr/share/sounds/Kopete_Received.ogg" );
+// ALBuffer buffer( "/usr/share/sounds/Kopete_Received.ogg" );
+ ALStreamingBuffer buffer( "/home/davorin/Glasba/Whatever.ogg" );
ALSource source = buffer.createSource();
hard_assert( source.id() != 0 );
alSourcePlay( source.id() );
+ OZ_AL_CHECK_ERROR();
File dds( argc < 2 ? "mail.dds" : argv[1] );
GLTexture texture( dds );
@@ -71,12 +72,18 @@ int main( int argc, char** argv )
glEnd();
Window::swapBuffers();
- Time::sleep( 10 );
+
+ isAlive &= buffer.update();
+ OZ_AL_CHECK_ERROR();
+ Time::sleep( 50 );
}
source.destroy();
+ OZ_AL_CHECK_ERROR();
buffer.destroy();
+ OZ_AL_CHECK_ERROR();
+ OZ_AL_CHECK_ERROR();
alcDestroyContext( context );
alcCloseDevice( device );
Window::destroy();
View
2  src/unittest/unittest.hh
@@ -36,7 +36,7 @@
oz::System::error( __PRETTY_FUNCTION__, __FILE__, __LINE__, 0, " Check '%s' failed", #cond ); \
}
-// FIXME: Add a space after ellipsis once KDevelop gets that fixed.
+// FIXME Add a space after ellipsis once KDevelop gets that bug fixed.
#define OZ_CHECK_CONTENTS( container, ...) \
{ \
auto i = citer( container ); \
Please sign in to comment.
Something went wrong with that request. Please try again.