How to compile opencore-amr in the MINGW

37 篇文章 0 订阅
32 篇文章 0 订阅

How to compile opencore-amr in the MINGW

 

Where to download opencore-amr source codes?

The latest version when I write this article is opencore-amr-0.1.1.tar.gz .

 

How to extract opencore-amr-0.1.1.tar.gz ?

$ tar xvzf ./opencore-amr-0.11.tar.gz

 

How to compile it?

opencore-amr-0.1.1.tar.gz contains two part: Amr-nb and Amr-wb. The Makefile has been defined for Darwin, Linux and Unix platform, but MINGW has not been listed in the enumeration. The article only focuses on MINGW platform, and others omitted can be solved in the light of this method.

 

Step 1: Modify the Makefile of Amr-nb.

I use green color to mark those blocks commented, and at the same time red color indicates the revision. The rule will be totally applied in this article.

# Just set OC_BASE to the opencore root, or set AMR_BASE directly to

# a detached gsm_amr directory

OC_BASE = ../opencore

AMR_BASE = $(OC_BASE)/codecs_v2/audio/gsm_amr

 

# To compile as C instead of C++, define BUILD_AS_C

ifneq (, $(BUILD_AS_C))

    CXX = $(CC)

    CXXFLAGS += -x c -std=c99

endif

 

ifeq (, $(PREFIX))

    PREFIX = /usr/local

endif

 

DEC_DIR = $(AMR_BASE)/amr_nb/dec

ENC_DIR = $(AMR_BASE)/amr_nb/enc

COMMON_DIR = $(AMR_BASE)/amr_nb/common

DEC_SRC_DIR = $(DEC_DIR)/src

ENC_SRC_DIR = $(ENC_DIR)/src

COMMON_SRC_DIR = $(COMMON_DIR)/src

OSCL = ../oscl

 

CPPFLAGS = -I$(OSCL) -I$(DEC_SRC_DIR) -I$(COMMON_DIR)/include -I$(DEC_DIR)/include -I$(AMR_BASE)/common/dec/include -I$(ENC_SRC_DIR)

 

# Find all the source files

DEC_SRC := $(shell cd $(DEC_SRC_DIR) && echo *.cpp)

ENC_SRC := $(shell cd $(ENC_SRC_DIR) && echo *.cpp)

COMMON_SRC := $(shell cd $(COMMON_SRC_DIR) && echo *.cpp)

 

# Exclude these files

DEC_SRC := $(DEC_SRC:decoder_gsm_amr.cpp=)

DEC_SRC := $(DEC_SRC:pvgsmamrdecoder.cpp=)

ENC_SRC := $(ENC_SRC:gsmamr_encoder_wrapper.cpp=)

 

DEC_OBJS := $(DEC_SRC:.cpp=.o)

DEC_OBJS := $(patsubst %,$(DEC_SRC_DIR)/%, $(DEC_OBJS))

ENC_OBJS := $(ENC_SRC:.cpp=.o)

ENC_OBJS := $(patsubst %,$(ENC_SRC_DIR)/%, $(ENC_OBJS))

COMMON_OBJS := $(COMMON_SRC:.cpp=.o)

COMMON_OBJS := $(patsubst %,$(COMMON_SRC_DIR)/%, $(COMMON_OBJS))

 

OBJS = wrapper.o $(DEC_OBJS) $(ENC_OBJS) $(COMMON_OBJS)

 

#Versioning

MAJOR = 0

MINOR = 1

REVISION = 1

 

ifeq ($(shell uname), Darwin)

    SHLIB_EXT = dylib

    SHLIB_FLAGS = -dynamiclib

else

#    SHLIB_EXT = so.$(MAJOR).$(MINOR).$(REVISION)

#    SHLIB_FLAGS = -shared

#    SONAME = libopencore-amrnb.so.$(MAJOR)

    SHLIB_EXT = $(MAJOR).$(MINOR).$(REVISION).dll

    SHLIB_FLAGS = -shared

    SONAME = libopencore-amrnb.$(MAJOR).dll

endif

 

SHLIB = libopencore-amrnb.$(SHLIB_EXT)

 

all: libopencore-amrnb.a $(SHLIB)

 

$(SHLIB): $(OBJS)

ifeq ($(shell uname), Darwin)

       $(CXX) $(SHLIB_FLAGS) -o $@ $+ $(LDFLAGS)

else

       $(CXX) $(SHLIB_FLAGS) -o $@ $+ -Wl,-soname,$(SONAME) $(LDFLAGS)

endif

 

libopencore-amrnb.a: $(OBJS)

       ar rcs $@ $+

 

install: libopencore-amrnb.a $(SHLIB)

       install -d $(DESTDIR)$(PREFIX)/lib

       install -m 644 libopencore-amrnb.a $(DESTDIR)$(PREFIX)/lib

#     install $(SHLIB) $(DESTDIR)$(PREFIX)/lib

       install $(SHLIB) $(DESTDIR)$(PREFIX)/bin

#ifneq ($(shell uname), Darwin)

#     ln -sf $(SHLIB) $(DESTDIR)$(PREFIX)/lib/$(SONAME)

#     ln -sf $(SONAME) $(DESTDIR)$(PREFIX)/lib/libopencore-amrnb.so

#endif

       install -d $(DESTDIR)$(PREFIX)/include/opencore-amrnb

       install -m 644 interf_dec.h $(DESTDIR)$(PREFIX)/include/opencore-amrnb

       install -m 644 interf_enc.h $(DESTDIR)$(PREFIX)/include/opencore-amrnb

 

clean:

       rm -f $(SHLIB) libopencore-amrnb.a *.o $(OBJS)

 

Step 2: Modify the Makefile of Amr-wb.

Changes are almost same as Amr-nb, and it is shown in the following table.

# Just set OC_BASE to the opencore root, or set AMR_BASE directly to

# a detached gsm_amr directory

OC_BASE = ../opencore

AMR_BASE = $(OC_BASE)/codecs_v2/audio/gsm_amr

 

# To compile as C instead of C++, define BUILD_AS_C

ifneq (, $(BUILD_AS_C))

    CXX = $(CC)

    CXXFLAGS += -x c -std=c99

endif

 

ifeq (, $(PREFIX))

    PREFIX = /usr/local

endif

 

DEC_DIR = $(AMR_BASE)/amr_wb/dec

DEC_SRC_DIR = $(DEC_DIR)/src

OSCL = ../oscl

 

CPPFLAGS = -I$(OSCL) -I$(DEC_SRC_DIR) -I$(DEC_DIR)/include -I$(AMR_BASE)/common/dec/include

 

# Find all the source files

# Exclude only decoder_amr_wb.cpp, not dtx_decoder_amr_wb.cpp

DEC_SRC := $(shell cd $(DEC_SRC_DIR) && echo *.cpp | sed 's/ decoder_amr_wb.cpp//')

 

DEC_OBJS := $(DEC_SRC:.cpp=.o)

DEC_OBJS := $(patsubst %,$(DEC_SRC_DIR)/%, $(DEC_OBJS))

 

OBJS = wrapper.o $(DEC_OBJS)

 

#Versioning

MAJOR = 0

MINOR = 1

REVISION = 1

 

ifeq ($(shell uname), Darwin)

    SHLIB_EXT = dylib

    SHLIB_FLAGS = -dynamiclib

else

#    SHLIB_EXT = so.$(MAJOR).$(MINOR).$(REVISION)

#    SHLIB_FLAGS = -shared

#    SONAME = libopencore-amrwb.so.$(MAJOR)

    SHLIB_EXT = $(MAJOR).$(MINOR).$(REVISION).dll

    SHLIB_FLAGS = -shared

    SONAME = libopencore-amrwb.$(MAJOR).dll

endif

SHLIB = libopencore-amrwb.$(SHLIB_EXT)

 

all: libopencore-amrwb.a $(SHLIB)

 

$(SHLIB): $(OBJS)

ifeq ($(shell uname), Darwin)

       $(CXX) $(SHLIB_FLAGS) -o $@ $+ $(LDFLAGS)

else

       $(CXX) $(SHLIB_FLAGS) -o $@ $+ -Wl,-soname,$(SONAME) $(LDFLAGS)

endif

 

libopencore-amrwb.a: $(OBJS)

       ar rcs $@ $+

 

install: libopencore-amrwb.a $(SHLIB)

       install -d $(DESTDIR)$(PREFIX)/lib

       install -m 644 libopencore-amrwb.a $(DESTDIR)$(PREFIX)/lib

#     install $(SHLIB) $(DESTDIR)$(PREFIX)/lib

       install $(SHLIB) $(DESTDIR)$(PREFIX)/bin

#ifneq ($(shell uname), Darwin)

#     ln -sf $(SHLIB) $(DESTDIR)$(PREFIX)/lib/$(SONAME)

#     ln -sf $(SONAME) $(DESTDIR)$(PREFIX)/lib/libopencore-amrwb.so

#endif

       install -d $(DESTDIR)$(PREFIX)/include/opencore-amrwb

       install -m 644 dec_if.h $(DESTDIR)$(PREFIX)/include/opencore-amrwb

       install -m 644 if_rom.h $(DESTDIR)$(PREFIX)/include/opencore-amrwb

 

clean:

       rm -f $(SHLIB) libopencore-amrwb.a *.o $(OBJS)

 

 

Step 3: Create shell script to compile them simply.

Before introducing it, I print their contents firstly.

#!/bin/sh

 

export PREFIX=/mingw

export BUILD_AS_C=1

export CC=gcc

export CFLAGS="-O3"

export CXXFLAGS="$CFLAGS"

 

make -C amrnb clean

make -C amrnb "$@" || exit 1

 

make -C amrwb clean

make -C amrwb "$@" || exit 1

 

make -C amrnb install || exit 1

 

make -C amrwb install || exit 1

 

As I need the C to replace C++, BUILD_AS_C is defined in the shell script. As the result, CC must be pointed out clearly at the same time. I prefer the optimized library, so CFLAGS and CXXFLAGS show the compiling option ‘O3’. PREFIX is referred to the destination when installing the library. Readers can re-locate it anywhere.

 

OK, everything is ready! Let’s build it(I name it as build_win32.sh ).

$ ./build_win32.sh

 

How about your result? Do you like it:- ).

 

[Summarization]

 

1. It is a boring task to compile opencore-amr. To some extents, it is only a labor. By releasing this article, I hope that it can save readers’ time.

2. The solution only focuses on the opencore-amr-0.1.1.tar.gz . For the higher versions, readers had better compare those Makefiles to confirm whether the implementation has been greatly changed. Otherwise, these Makefiles can not be simply copied to replace your current Makefiles.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值