Android OpenAL编译

1. OpenAL

OpenAL是一个开源的音频后处理工具包,可以添加各种音效,修改声源空间位置等等。在前面的文章【OpenAL简介】中也有介绍。
IOS上已经集成了OpenAL,android平台暂未集成。但是OpenAL全部用C实现,而且不大,集成起来比较方便。
PS:android平台也有专门的音频后处理模块,但是使用起来感觉不是很好,貌似还不太稳定。


2. 下载源代码

https://github.com/AerialX/openal-soft-android

下载完源代码配置Android cmake编译比较麻烦,问题多多(主要是生产config.h文件)。
我把配置好的config.h文件提供给大家,大家可以拿来用,地址如下:
config.h

3. 编写mk

这里面有个坑需要点出来就是,Openal需要OpenSLES支持,所以需要android-9以上才能支持。

3.1 Application.mk

#
# Application.mk
#
# Created by wistone on 16/9/8.
# Author  : wistone
# Email   : [email protected]
#

APP_OPTIM := release
APP_ABI := armeabi-v7a
APP_PLATFORM := android-9

3.2 Android.mk

#
# Android.mk
#
# Created by wistone on 16/7/8.
# Author  : wistone
# Email   : xiyanglu@gmail.com
#

TARGET_PLATFORM := android-9
ROOT_PATH := $(call my-dir)


########################################################################################################
include $(CLEAR_VARS)

OPENAL_ROOT      := $(ROOT_PATH)/openal
OPENAL_ALC       := $(OPENAL_ROOT)/Alc
OPENAL_AL32      := $(OPENAL_ROOT)/OpenAL32

$(warning OpenAL Root = $(OPENAL_ROOT))
$(warning $(OPENAL_ALC))
$(warning $(OPENAL_AL32))

LOCAL_MODULE     := openal
LOCAL_ARM_MODE   := arm
LOCAL_PATH       := $(ROOT_PATH)
LOCAL_C_INCLUDES := $(LOCAL_PATH)                          \
                    $(OPENAL_ROOT)                         \
                    $(OPENAL_ROOT)/include                     \
                    $(OPENAL_ROOT)/Alc                         \
                    $(OPENAL_ROOT)/OpenAL32                \
                    $(OPENAL_ROOT)/OpenAL32/Include

LOCAL_SRC_FILES  := \
            $(OPENAL_ALC)/ALc.c \
            $(OPENAL_ALC)/alcConfig.c \
            $(OPENAL_ALC)/alcRing.c \
            $(OPENAL_ALC)/ALu.c \
            $(OPENAL_ALC)/ambdec.c \
            $(OPENAL_ALC)/bformatdec.c \
            $(OPENAL_ALC)/bs2b.c \
            $(OPENAL_ALC)/bsinc.c \
            $(OPENAL_ALC)/helpers.c \
            $(OPENAL_ALC)/hrtf.c \
            $(OPENAL_ALC)/mixer.c \
            $(OPENAL_ALC)/mixer_c.c \
            $(OPENAL_ALC)/panning.c \
            $(OPENAL_ALC)/uhjfilter.c \
            \
            $(OPENAL_ALC)/effects/autowah.c \
            $(OPENAL_ALC)/effects/chorus.c \
            $(OPENAL_ALC)/effects/compressor.c \
            $(OPENAL_ALC)/effects/dedicated.c \
            $(OPENAL_ALC)/effects/distortion.c \
            $(OPENAL_ALC)/effects/echo.c \
            $(OPENAL_ALC)/effects/equalizer.c \
            $(OPENAL_ALC)/effects/flanger.c \
            $(OPENAL_ALC)/effects/modulator.c \
            $(OPENAL_ALC)/effects/null.c \
            $(OPENAL_ALC)/effects/reverb.c \
            \
            $(OPENAL_ALC)/backends/base.c \
            $(OPENAL_ALC)/backends/loopback.c \
            $(OPENAL_ALC)/backends/null.c \
            $(OPENAL_ALC)/backends/opensl.c \
            $(OPENAL_ALC)/backends/wave.c \
            \
            $(OPENAL_AL32)/alAuxEffectSlot.c \
            $(OPENAL_AL32)/alBuffer.c \
            $(OPENAL_AL32)/alEffect.c \
            $(OPENAL_AL32)/alError.c \
            $(OPENAL_AL32)/alExtension.c \
            $(OPENAL_AL32)/alFilter.c \
            $(OPENAL_AL32)/alListener.c \
            $(OPENAL_AL32)/alSource.c \
            $(OPENAL_AL32)/alState.c \
            $(OPENAL_AL32)/alThunk.c \
            $(OPENAL_AL32)/sample_cvt.c \
            \
            $(OPENAL_ROOT)/common/almalloc.c \
            $(OPENAL_ROOT)/common/alhelpers.c \
            $(OPENAL_ROOT)/common/atomic.c \
            $(OPENAL_ROOT)/common/rwlock.c \
            $(OPENAL_ROOT)/common/threads.c \
            $(OPENAL_ROOT)/common/uintmap.c \

LOCAL_CFLAGS     := -DAL_BUILD_LIBRARY \
                    -DAL_ALEXT_PROTOTYPES \
                    -DANDROID \
                    -fpic \
                    -ffunction-sections \
                    -funwind-tables \
                    -fstack-protector \
                    -fno-short-enums \
                    -DHAVE_GCC_VISIBILITY \
                    -O3 \
                    -mfpu=neon \
                    -mfloat-abi=softfp \
                    -march=armv7-a \
                    -ffast-math \
                    -std=c99 \

LOCAL_LDLIBS     := -lOpenSLES -llog
LOCAL_ARM_NEON := true

LOCAL_STATIC_LIBRARIES := libtremolo

include $(BUILD_SHARED_LIBRARY)


4. 编译

进入工程jni目录执行:

$NDK/ndk-build

Android OpenAL编译_第1张图片

5. 项目源代码

匆匆忙忙把OpenAL的代码给拆分出来:
https://github.com/xiyanglu/AndroidOpenAL


6. 后记

Android Studio 2.2之后支持CMake,OpenAL也支持CMake编译,之后有时间可以搞一搞。

你可能感兴趣的:(Android,多媒体,OpenAL,Android,FFmpeg多媒体)