Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmake/Android/Mengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ADD_PLATFORM(AndroidPlatform "MENGINE_PLATFORM")

# systems
ADD_SYSTEM(MENGINE_SYSTEM_ALLOCATOR POSIXAllocatorSystem "MENGINE_SYSTEM_ALLOCATOR")
ADD_SYSTEM(MENGINE_SYSTEM_SOUND OpenALSoundSystem "MENGINE_SYSTEM_SOUND")
ADD_SYSTEM(MENGINE_SYSTEM_SOUND AndroidSoundSystem "MENGINE_SYSTEM_SOUND")
ADD_SYSTEM(MENGINE_SYSTEM_FILE AndroidFileSystem "MENGINE_SYSTEM_FILE")
ADD_SYSTEM(MENGINE_SYSTEM_DATETIME POSIXDateTimeSystem "MENGINE_SYSTEM_DATETIME")
ADD_SYSTEM(MENGINE_SYSTEM_UNICODE NativeUnicodeSystem "MENGINE_SYSTEM_UNICODE")
Expand Down Expand Up @@ -92,6 +92,8 @@ ADD_PLUGIN(MENGINE_PLUGIN_WIN32_CRITICALERRORSMONITOR OFF OFF "MENGINE_PLUGIN_WI

ADD_PLUGIN(MENGINE_PLUGIN_ANDROID_NATIVE_PYTHON ON OFF "MENGINE_PLUGIN_ANDROID_NATIVE_PYTHON")

ADD_PLUGIN(MENGINE_PLUGIN_ANDROID_SOUND ON OFF "MENGINE_PLUGIN_ANDROID_SOUND")

MENGINE_ADD_DEFINITION(MENGINE_RENDER_TEXTURE_RGBA)
MENGINE_ADD_DEFINITION(MENGINE_RENDER_COLOR_RGBA)
#MENGINE_ADD_DEFINITION(MENGINE_SETJMP_UNSUPPORTED)
Expand Down
11 changes: 0 additions & 11 deletions gradle/app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,6 @@ android {
jniLibs {
pickFirsts += ['lib/**/libc++_shared.so']

if(MENGINE_APP_LIBRARY_OPENAL32) {
pickFirsts += ['lib/**/libopenal.so']
}
}
}

Expand All @@ -360,14 +357,6 @@ if (ANDROID_APP_SPLIT_ENABLE == true) {
}
}

Utils.logAvailable("MENGINE_APP_LIBRARY_OPENAL32", MENGINE_APP_LIBRARY_OPENAL32)

if (MENGINE_APP_LIBRARY_OPENAL32 == true) {
dependencies {
implementation project(':libraries:OpenAL32')
}
}

Utils.logAvailable("MENGINE_APP_LIBRARY_MENGINE", MENGINE_APP_LIBRARY_MENGINE)

if (MENGINE_APP_LIBRARY_MENGINE == true) {
Expand Down
7 changes: 0 additions & 7 deletions gradle/libraries/Mengine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,10 @@ android {
}
}

if (MENGINE_APP_LIBRARY_OPENAL32 == true) {
preBuild.dependsOn ":libraries:OpenAL32:build"
}

namespace "org.Mengine.Base"
}

dependencies {
if (MENGINE_APP_LIBRARY_OPENAL32 == true) {
implementation project(':libraries:OpenAL32')
}
}

android {
Expand Down
1 change: 0 additions & 1 deletion gradle/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ if (extra.has("ANDROID_APP_DELIVERY_PACKAGES") == true) {
}

includeLibrary("MENGINE_APP_LIBRARY_MENGINE", ":libraries:Mengine")
includeLibrary("MENGINE_APP_LIBRARY_OPENAL32", ":libraries:OpenAL32")

/*****************************************************************************
/ * - MENGINE_APP_PLUGIN_FIREBASE [https://firebase.google.com]
Expand Down
8 changes: 8 additions & 0 deletions src/Bootstrapper/Bootstrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ PLUGIN_EXPORT( Win32AntifreezeMonitor );
PLUGIN_EXPORT( AndroidNativePython );
#endif
//////////////////////////////////////////////////////////////////////////
#if defined(MENGINE_PLUGIN_ANDROID_SOUND_STATIC)
PLUGIN_EXPORT( AndroidSound );
#endif
//////////////////////////////////////////////////////////////////////////
#if defined(MENGINE_PLUGIN_APPLE_NATIVE_PYTHON_STATIC)
PLUGIN_EXPORT( AppleNativePython );
#endif
Expand Down Expand Up @@ -1449,6 +1453,10 @@ namespace Mengine
MENGINE_ADD_PLUGIN( AndroidNativePython, "plugin AndroidNativePython...", MENGINE_DOCUMENT_FACTORABLE );
#endif

#if defined(MENGINE_PLUGIN_ANDROID_SOUND_STATIC)
MENGINE_ADD_PLUGIN( AndroidSound, "plugin AndroidSound...", MENGINE_DOCUMENT_FACTORABLE );
#endif

#if defined(MENGINE_PLUGIN_APPLE_NATIVE_PYTHON_STATIC)
MENGINE_ADD_PLUGIN( AppleNativePython, "plugin AppleNativePython...", MENGINE_DOCUMENT_FACTORABLE );
#endif
Expand Down
42 changes: 42 additions & 0 deletions src/Plugins/AndroidSoundPlugin/AndroidSoundPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "AndroidSoundPlugin.h"

#include "Interface/SoundSystemInterface.h"

#include "Kernel/Logger.h"
#include "Kernel/PluginHelper.h"

//////////////////////////////////////////////////////////////////////////
SERVICE_EXTERN( SoundSystem );
//////////////////////////////////////////////////////////////////////////
PLUGIN_FACTORY( AndroidSound, Mengine::AndroidSoundPlugin );
//////////////////////////////////////////////////////////////////////////
namespace Mengine
{
//////////////////////////////////////////////////////////////////////////
AndroidSoundPlugin::AndroidSoundPlugin()
{
}
//////////////////////////////////////////////////////////////////////////
AndroidSoundPlugin::~AndroidSoundPlugin()
{
}
//////////////////////////////////////////////////////////////////////////
bool AndroidSoundPlugin::_initializePlugin()
{
if( SERVICE_IS_EXIST( SoundSystemInterface ) == false )
{
LOGGER_INFO( "android_sound", "AndroidSoundPlugin waiting for sound system service initialization" );
}

return true;
}
//////////////////////////////////////////////////////////////////////////
void AndroidSoundPlugin::_finalizePlugin()
{
}
//////////////////////////////////////////////////////////////////////////
void AndroidSoundPlugin::_destroyPlugin()
{
}
//////////////////////////////////////////////////////////////////////////
}
21 changes: 21 additions & 0 deletions src/Plugins/AndroidSoundPlugin/AndroidSoundPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "Kernel/PluginBase.h"

namespace Mengine
{
class AndroidSoundPlugin
: public PluginBase
{
PLUGIN_DECLARE( "AndroidSound" );

public:
AndroidSoundPlugin();
~AndroidSoundPlugin() override;

protected:
bool _initializePlugin() override;
void _finalizePlugin() override;
void _destroyPlugin() override;
};
}
11 changes: 11 additions & 0 deletions src/Plugins/AndroidSoundPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MENGINE_PROJECT(AndroidSoundPlugin)

ADD_FILTER(
src
AndroidSoundPlugin.h
AndroidSoundPlugin.cpp
)

ADD_MENGINE_PLUGIN(MENGINE_PLUGIN_ANDROID_SOUND)

TARGET_LINK_LIBRARIES(${PROJECT_NAME} Kernel)
4 changes: 4 additions & 0 deletions src/Plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ if(MENGINE_PLUGIN_ANDROID_NATIVE_PYTHON)
ADD_SUBDIRECTORY(AndroidNativePythonPlugin)
endif()

if(MENGINE_PLUGIN_ANDROID_SOUND)
ADD_SUBDIRECTORY(AndroidSoundPlugin)
endif()

if(MENGINE_PLUGIN_DAZZLE)
ADD_SUBDIRECTORY(DazzlePlugin)
endif()
Expand Down
154 changes: 154 additions & 0 deletions src/Systems/AndroidSoundSystem/AndroidSoundBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include "AndroidSoundBuffer.h"

#include "Interface/SoundCodecInterface.h"

#include "Kernel/Logger.h"
#include "Kernel/MemoryStreamHelper.h"

namespace Mengine
{
//////////////////////////////////////////////////////////////////////////
AndroidSoundBuffer::AndroidSoundBuffer()
: m_frequency( 0 )
, m_channels( 0 )
, m_bits( 0 )
, m_duration( 0.f )
, m_streamable( false )
{
}
//////////////////////////////////////////////////////////////////////////
AndroidSoundBuffer::~AndroidSoundBuffer()
{
}
//////////////////////////////////////////////////////////////////////////
bool AndroidSoundBuffer::acquireSoundBuffer()
{
return true;
}
//////////////////////////////////////////////////////////////////////////
void AndroidSoundBuffer::releaseSoundBuffer()
{
//Empty
}
//////////////////////////////////////////////////////////////////////////
bool AndroidSoundBuffer::updateSoundBuffer()
{
return false;
}
//////////////////////////////////////////////////////////////////////////
const SoundDecoderInterfacePtr & AndroidSoundBuffer::getDecoder() const
{
return m_soundDecoder;
}
//////////////////////////////////////////////////////////////////////////
bool AndroidSoundBuffer::load( const SoundDecoderInterfacePtr & _soundDecoder, bool _streamable )
{
m_soundDecoder = _soundDecoder;

const SoundCodecDataInfo * dataInfo = m_soundDecoder->getCodecDataInfo();

if( dataInfo == nullptr )
{
LOGGER_ERROR( "AndroidSoundBuffer invalid codec data info" );

return false;
}

m_frequency = dataInfo->frequency;
m_channels = dataInfo->channels;
m_bits = dataInfo->bits;
m_duration = dataInfo->duration;
m_streamable = _streamable;

if( m_channels == 0 || m_channels > 2 )
{
LOGGER_ERROR( "AndroidSoundBuffer unsupported channel count %u", m_channels );

return false;
}

if( m_bits != 8 && m_bits != 16 )
{
LOGGER_ERROR( "AndroidSoundBuffer unsupported bits %u", m_bits );

return false;
}

size_t pcmSize = dataInfo->size;

if( pcmSize == 0 )
{
LOGGER_ERROR( "AndroidSoundBuffer invalid data size" );

return false;
}

MemoryInterfacePtr pcmMemory = Helper::createMemoryCacheBuffer( pcmSize, MENGINE_DOCUMENT_FACTORABLE );

if( pcmMemory == nullptr )
{
LOGGER_ERROR( "AndroidSoundBuffer invalid memory allocate size %zu", pcmSize );

return false;
}

SoundDecoderData data;
data.buffer = pcmMemory->getBuffer();
data.size = pcmSize;

size_t decodeSize = m_soundDecoder->decode( &data );

if( decodeSize == 0 )
{
LOGGER_ERROR( "AndroidSoundBuffer invalid decode size" );

return false;
}

m_pcmData.assign( (uint8_t *)data.buffer, (uint8_t *)data.buffer + decodeSize );

return true;
}
//////////////////////////////////////////////////////////////////////////
const uint8_t * AndroidSoundBuffer::getData() const
{
if( m_pcmData.empty() == true )
{
return nullptr;
}

return m_pcmData.data();
}
//////////////////////////////////////////////////////////////////////////
size_t AndroidSoundBuffer::getDataSize() const
{
return m_pcmData.size();
}
//////////////////////////////////////////////////////////////////////////
uint32_t AndroidSoundBuffer::getFrequency() const
{
return m_frequency;
}
//////////////////////////////////////////////////////////////////////////
uint32_t AndroidSoundBuffer::getChannels() const
{
return m_channels;
}
//////////////////////////////////////////////////////////////////////////
uint32_t AndroidSoundBuffer::getBits() const
{
return m_bits;
}
//////////////////////////////////////////////////////////////////////////
float AndroidSoundBuffer::getDuration() const
{
return m_duration;
}
//////////////////////////////////////////////////////////////////////////
bool AndroidSoundBuffer::isStreamable() const
{
return m_streamable;
}
//////////////////////////////////////////////////////////////////////////
}

54 changes: 54 additions & 0 deletions src/Systems/AndroidSoundSystem/AndroidSoundBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include "Interface/SoundSystemInterface.h"

#include "Kernel/Factorable.h"
#include "Kernel/Vector.h"

namespace Mengine
{
class AndroidSoundBuffer
: public SoundBufferInterface
{
DECLARE_FACTORABLE( AndroidSoundBuffer );

public:
AndroidSoundBuffer();
~AndroidSoundBuffer() override;

public:
bool acquireSoundBuffer() override;
void releaseSoundBuffer() override;

public:
bool updateSoundBuffer() override;

public:
const SoundDecoderInterfacePtr & getDecoder() const override;

public:
bool load( const SoundDecoderInterfacePtr & _soundDecoder, bool _streamable );

public:
const uint8_t * getData() const;
size_t getDataSize() const;
uint32_t getFrequency() const;
uint32_t getChannels() const;
uint32_t getBits() const;
float getDuration() const;
bool isStreamable() const;

protected:
SoundDecoderInterfacePtr m_soundDecoder;
Vector<uint8_t> m_pcmData;

uint32_t m_frequency;
uint32_t m_channels;
uint32_t m_bits;
float m_duration;
bool m_streamable;
};

typedef IntrusivePtr<AndroidSoundBuffer, SoundBufferInterface> AndroidSoundBufferPtr;
}

Loading