Skip to content

Commit

Permalink
New version 0.2.0 with lot of fixes
Browse files Browse the repository at this point in the history
* Introduce a new library functions aptx_decode_sync() and
  aptx_decode_sync_finish() for synchronization and decoding
  partially corrupted continuous stream

* Improve synchronization support in openaptxdec utility via
  these new library functions

* Fix openaptxdec utility to not output data which are result of
  decoding the trailing aptx padding from the last aptX sample

* Fix exit codes from utilities, returns 1 when error occurred

* Make utilities to be compatible with Windows systems, set
  stdin and stdout to binary mode

* Make source code to be compatible with ISO C90, C99, C11, C17,
  ISO C++ 1998, 2011, 2014, 2017, 2020 and also with MSVC 6.0
  (and new), but there is one exception that stdint.h header file
  with basic fixed width integer types needs to be provided

* Fix integer variable types, size, signedness and const qualifiers

* Make Makefile to be POSIX compatible

* Do not install static executables

* Generate and install a new pkg-config file for library

* Provide and install static library libopenaptx.a

* Enable -O3 optimizations in Makefile by default

* Update parameters for sox/play examples in README and help
  • Loading branch information
pali committed Apr 11, 2020
1 parent 5a2f1ec commit 2459ed4
Show file tree
Hide file tree
Showing 6 changed files with 643 additions and 338 deletions.
110 changes: 78 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,93 @@
MAJOR := 0
MINOR := 1
PATCH := 0
.POSIX:
.SUFFIXES:
.PHONY: all clean install uninstall

PREFIX := /usr/local
BINDIR := bin
LIBDIR := lib
INCDIR := include
RM = rm -f
CP = cp -a
LNS = ln -sf
MKDIR = mkdir -p
PRINTF = printf

LIBNAME := libopenaptx.so
SONAME := $(LIBNAME).$(MAJOR)
FILENAME := $(SONAME).$(MINOR).$(PATCH)
CFLAGS = -W -Wall -O3
LDFLAGS = -s
ARFLAGS = -rcs

UTILITIES := openaptxenc openaptxdec openaptxenc-static openaptxdec-static
PREFIX = /usr/local
BINDIR = bin
LIBDIR = lib
INCDIR = include
PKGDIR = $(LIBDIR)/pkgconfig

HEADERS := openaptx.h
SOURCES := openaptx.c
NAME = openaptx
MAJOR = 0
MINOR = 2
PATCH = 0

BUILD := $(FILENAME) $(SONAME) $(LIBNAME) $(UTILITIES)
LIBNAME = lib$(NAME).so
SONAME = $(LIBNAME).$(MAJOR)
SOFILENAME = $(SONAME).$(MINOR).$(PATCH)
ANAME = lib$(NAME).a
PCNAME = lib$(NAME).pc

UTILITIES = $(NAME)enc $(NAME)dec
STATIC_UTILITIES = $(NAME)enc.static $(NAME)dec.static

HEADERS = $(NAME).h
SOURCES = $(NAME).c
AOBJECTS = $(NAME).o
IOBJECTS = $(NAME)enc.o $(NAME)dec.o

BUILD = $(SOFILENAME) $(SONAME) $(LIBNAME) $(ANAME) $(AOBJECTS) $(IOBJECTS) $(UTILITIES) $(STATIC_UTILITIES)

all: $(BUILD)

clean:
$(RM) $(BUILD)

install: $(BUILD)
mkdir -p $(DESTDIR)/$(PREFIX)/$(LIBDIR)
cp -a $(FILENAME) $(SONAME) $(LIBNAME) $(DESTDIR)/$(PREFIX)/$(LIBDIR)
mkdir -p $(DESTDIR)/$(PREFIX)/$(BINDIR)
cp -a $(UTILITIES) $(DESTDIR)/$(PREFIX)/$(BINDIR)
mkdir -p $(DESTDIR)/$(PREFIX)/$(INCDIR)
cp -a $(HEADERS) $(DESTDIR)/$(PREFIX)/$(INCDIR)

$(FILENAME): $(SOURCES) $(HEADERS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -I. -shared -fPIC -Wl,-soname,$(SONAME) -o $@ $(SOURCES)
$(MKDIR) $(DESTDIR)$(PREFIX)/$(LIBDIR)
$(CP) $(SOFILENAME) $(SONAME) $(LIBNAME) $(ANAME) $(DESTDIR)$(PREFIX)/$(LIBDIR)
$(MKDIR) $(DESTDIR)$(PREFIX)/$(BINDIR)
$(CP) $(UTILITIES) $(DESTDIR)$(PREFIX)/$(BINDIR)
$(MKDIR) $(DESTDIR)$(PREFIX)/$(INCDIR)
$(CP) $(HEADERS) $(DESTDIR)$(PREFIX)/$(INCDIR)
$(MKDIR) $(DESTDIR)$(PREFIX)/$(PKGDIR)
$(PRINTF) 'prefix=%s\nexec_prefix=$${prefix}\nlibdir=$${exec_prefix}/%s\nincludedir=$${prefix}/%s\n\n' $(PREFIX) $(LIBDIR) $(INCDIR) > $(DESTDIR)$(PREFIX)/$(PKGDIR)/$(PCNAME)
$(PRINTF) 'Name: lib%s\nDescription: Open Source aptX codec library\nVersion: %u.%u.%u\n' $(NAME) $(MAJOR) $(MINOR) $(PATCH) >> $(DESTDIR)$(PREFIX)/$(PKGDIR)/$(PCNAME)
$(PRINTF) 'Libs: -Wl,-rpath=$${libdir} -L$${libdir} -l%s\nCflags: -I$${includedir}\n' $(NAME) >> $(DESTDIR)$(PREFIX)/$(PKGDIR)/$(PCNAME)

uninstall:
for f in $(SOFILENAME) $(SONAME) $(LIBNAME) $(ANAME); do $(RM) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$$f; done
for f in $(UTILITIES); do $(RM) $(DESTDIR)$(PREFIX)/$(BINDIR)/$$f; done
for f in $(HEADERS); do $(RM) $(DESTDIR)$(PREFIX)/$(INCDIR)/$$f; done
$(RM) $(DESTDIR)$(PREFIX)/$(PKGDIR)/$(PCNAME)

$(UTILITIES): $(LIBNAME)

$(SONAME): $(FILENAME)
ln -sf $< $@
$(STATIC_UTILITIES): $(ANAME)

$(AOBJECTS) $(IOBJECTS): $(HEADERS)

$(LIBNAME): $(SONAME)
ln -sf $< $@
$(LNS) $(SONAME) $@

%-static: %.c $(SOURCES) $(HEADERS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -I. -o $@ $< $(SOURCES)
$(SONAME): $(SOFILENAME)
$(LNS) $(SOFILENAME) $@

%: %.c $(LIBNAME) $(HEADERS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -I. -o $@ $< $(LIBNAME)
$(SOFILENAME): $(SOURCES) $(HEADERS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -I. -shared -fPIC -Wl,-soname,$(SONAME) -o $@ $(SOURCES)

clean:
$(RM) $(BUILD)
$(ANAME): $(AOBJECTS)
$(RM) $@
$(AR) $(ARFLAGS) $@ $(AOBJECTS)

.SUFFIXES: .o .c .static

.o:
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBNAME)

.o.static:
$(CC) $(CFLAGS) $(LDFLAGS) -static -o $@ $< $(ANAME)

.c.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -I. -c -o $@ $<
18 changes: 13 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,35 @@ mainly used in Bluetooth A2DP profile.

It provides dynamic linked shared library libopenaptx.so and simple command line
utilities openaptxenc and openaptxdec for encoding and decoding operations.
Documentation for shared library is provided in C header file openaptx.h.

There is support for aptX and aptX HD codec variants. Both variants operates on
a raw 24 bit signed stereo audio samples. aptX provides fixed compress ratio 6:1
and aptX HD fixed compress ratio 4:1.

For building and installing into system simply run: make install. For building
without installing run: LD_RUN_PATH='$ORIGIN' make
without installing run: LD_RUN_PATH='$ORIGIN' make. For producing windows builds
run: make SOFILENAME=openaptx0.dll.

It is suggested to compile library with -O3 optimizations (enabled by default
when env variable CFLAGS is not set) and -mavx2 switch (not enabled by default,
needs CPU with AVX2: Intel Haswell or AMD Excavator) as it provides significant
boost to the performance.

Usage of command line utilities together with sox for resampling or playing:

To convert Wave audio file sample.wav into aptX audio file sample.aptx run:

$ sox sample.wav -t raw -r 44.1k -s -3 -c 2 - | openaptxenc > sample.aptx
$ sox sample.wav -t raw -r 44.1k -L -e s -b 24 -c 2 - | openaptxenc > sample.aptx

To convert aptX audio file sample.aptx into Wave audio file sample.wav run:

$ openaptxdec < sample.aptx | sox -t raw -r 44.1k -s -3 -c 2 - sample.wav
$ openaptxdec < sample.aptx | sox -t raw -r 44.1k -L -e s -b 24 -c 2 - sample.wav

To convert MP3 audio file sample.mp3 into aptX HD audio file sample.aptxhd run:

$ sox sample.mp3 -t raw -r 44.1k -s -3 -c 2 - | openaptxenc --hd > sample.aptxhd
$ sox sample.mp3 -t raw -r 44.1k -L -e s -b 24 -c 2 - | openaptxenc --hd > sample.aptxhd

To play aptX HD audio file sample.aptxhd run:

$ openaptxdec --hd < sample.aptxhd | play -t raw -r 44.1k -s -3 -c 2 -
$ openaptxdec --hd < sample.aptxhd | play -t raw -r 44.1k -L -e s -b 24 -c 2 -
Loading

0 comments on commit 2459ed4

Please sign in to comment.