Skip to content

Commit

Permalink
Opus enabled
Browse files Browse the repository at this point in the history
- ozEngine
  * Opus decoder is enabled and opusfile library is required to build openzone
  • Loading branch information
ducakar committed Feb 28, 2017
1 parent 2a3760b commit 963aa48
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ endif()

find_package(OpenAL REQUIRED)
find_package(PNG REQUIRED)
#pkg_check_modules(OPUSFILE REQUIRED opusfile)
pkg_check_modules(OPUSFILE REQUIRED opusfile)
pkg_check_modules(VORBISFILE REQUIRED vorbisfile)

#include_directories(SYSTEM ${OPUSFILE_INCLUDE_DIRS})
include_directories(SYSTEM ${OPUSFILE_INCLUDE_DIRS})

# On embedded platforms, linking is mostly static, so indirect dependencies must be linked too.
if(PLATFORM_EMBEDDED)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Development packages of the following libraries are required to build OpenZone f
- Lua or LuaJIT
- openal-soft
- OpenGL or OpenGL ES
- opusfile
- PhysicsFS
- SDL2
- SDL2_ttf
Expand Down
32 changes: 13 additions & 19 deletions src/ozEngine/AL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@

#include <AL/alext.h>
#include <cstring>
# ifdef OZ_OPUS
#include <opus/opusfile.h>
# endif
#include <vorbis/vorbisfile.h>

namespace oz
Expand Down Expand Up @@ -188,8 +186,6 @@ bool AL::Decoder::WaveStream::decode(AL::Decoder* decoder)
return true;
}

#ifdef OZ_OPUS

struct AL::Decoder::OpusStream : AL::Decoder::StreamBase
{
OZ_INTERNAL
Expand Down Expand Up @@ -218,10 +214,10 @@ struct AL::Decoder::OpusStream : AL::Decoder::StreamBase
OZ_ERROR("oz::AL::Decoder: Only mono and stereo Opus supported `%s'", file.c());
}

decoder->format = nChannels == 2 ? AL_FORMAT_STEREO_FLOAT32 : AL_FORMAT_MONO_FLOAT32;
decoder->rate = 48000;
decoder->capacity = isStreaming ? FRAME_SIZE * nChannels : nSamples * nChannels;
decoder->samples = new float[decoder->capacity];
decoder->format_ = nChannels == 2 ? AL_FORMAT_STEREO_FLOAT32 : AL_FORMAT_MONO_FLOAT32;
decoder->rate_ = 48000;
decoder->capacity_ = isStreaming ? FRAME_SIZE * nChannels : nSamples * nChannels;
decoder->samples_ = new float[decoder->capacity_];
}

OZ_INTERNAL
Expand All @@ -242,33 +238,31 @@ AL::Decoder::OpusStream::~OpusStream()

bool AL::Decoder::OpusStream::decode(AL::Decoder* decoder)
{
decoder->count = 0;
decoder->size_ = 0;

do {
int result;

if (decoder->format == AL_FORMAT_STEREO_FLOAT32) {
result = op_read_float_stereo(opFile, decoder->samples + decoder->count,
decoder->capacity - decoder->count) * 2;
if (decoder->format_ == AL_FORMAT_STEREO_FLOAT32) {
result = op_read_float_stereo(opFile, decoder->samples_ + decoder->size_,
decoder->capacity_ - decoder->size_) * 2;
}
else {
result = op_read_float(opFile, decoder->samples + decoder->count,
decoder->capacity - decoder->count, nullptr);
result = op_read_float(opFile, decoder->samples_ + decoder->size_,
decoder->capacity_ - decoder->size_, nullptr);
}

if (result <= 0) {
return decoder->count != 0;
return decoder->size_ != 0;
}

decoder->count += result;
decoder->size_ += result;
}
while (decoder->count != decoder->capacity);
while (decoder->size_ != decoder->capacity_);

return true;
}

#endif

struct AL::Decoder::VorbisStream : AL::Decoder::StreamBase
{
OggVorbis_File ovFile;
Expand Down
6 changes: 3 additions & 3 deletions src/ozEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ add_library(ozEngine
#END SOURCES
)

target_link_libraries(ozEngine ${LUA_LIBRARIES} ${GL_LIBRARIES} ${OPENAL_LIBRARY} ${PNG_LIBRARIES}
# ${OPUSFILE_LIBRARIES}
${VORBISFILE_LIBRARIES} ${SDL_LIBRARIES} ${SDL_TTF_LIBRARIES})
target_link_libraries(ozEngine ${LUA_LIBRARIES} ${GL_LIBRARIES} ${OPENAL_LIBRARY}
${PNG_LIBRARIES} ${OPUSFILE_LIBRARIES} ${VORBISFILE_LIBRARIES}
${SDL_LIBRARIES} ${SDL_TTF_LIBRARIES})

if(NOT NACL)
# target_link_libraries(ozEngine ${SDL_NET_LIBRARIES})
Expand Down
8 changes: 3 additions & 5 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ if(NOT OZ_GL_ES AND OZ_TOOLS)
target_link_libraries(noise ozCore ozEngine ozFactory)
endif()

if (OZ_OPUS)
add_executable(opus opus.cc)
target_link_libraries(opus ozEngine ozCore -logg -lopus)
endif()
#add_executable(opus opus.cc)
#target_link_libraries(opus ozEngine ozCore)

add_executable(quicksort quicksort.cc)
target_link_libraries(quicksort ozCore)

add_executable(scratch scratch.cc)
target_link_libraries(scratch ozCore)
target_link_libraries(scratch ozEngine ozCore)

add_executable(simd simd.cc)
target_link_libraries(simd ozCore)
2 changes: 1 addition & 1 deletion src/tests/opus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void decoderMain(void*)
else {
nSamples += result * nChannels;

if (nSamples + FRAME_SIZE * nChannels > samples.length()) {
if (nSamples + FRAME_SIZE * nChannels > samples.size()) {
decodeMainSemaphore.post();
decodeThreadSemaphore.wait();

Expand Down

0 comments on commit 963aa48

Please sign in to comment.