Skip to content

Commit

Permalink
Proprietary internal encoder structure for HD
Browse files Browse the repository at this point in the history
The structure provided in this commit has been reconstructed based
on the aptXHD-1.0.0-ARMv7A library build.
  • Loading branch information
arkq committed Oct 19, 2018
1 parent 3c69c7a commit ebcf004
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 18 deletions.
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ AM_COND_IF([ENABLE_APTX422], [
AC_DEFINE([ENABLE_APTX422], [1], [Define to 1 if aptx422 is enabled.])
])

AC_ARG_ENABLE([aptxHD100],
[AS_HELP_STRING([--enable-aptxHD100], [build reverse-engineered library])])
AM_CONDITIONAL([ENABLE_APTXHD100], [test "x$enable_aptxHD100" = "xyes"])
AM_COND_IF([ENABLE_APTXHD100], [
AC_DEFINE([ENABLE_APTXHD100], [1], [Define to 1 if aptxHD100 is enabled.])
])

AC_ARG_WITH([sndfile],
[AS_HELP_STRING([--with-sndfile], [use sndfile for reading audio])])
AM_CONDITIONAL([WITH_SNDFILE], [test "x$with_sndfile" = "xyes"])
Expand Down
130 changes: 130 additions & 0 deletions include/aptxHD100.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* aptxHD100.h
* Copyright (c) 2017-2018 Arkadiusz Bokowy
*
* This file is a part of [open]aptx.
*
* This project is licensed under the terms of the MIT license.
*
*/

#ifndef OPENAPTX_APTXHD100_H_
#define OPENAPTX_APTXHD100_H_

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define APTXHD_CHANNELS 2

enum aptXHD_subband {
APTXHD_SUBBAND_LL = 0,
APTXHD_SUBBAND_LH = 1,
APTXHD_SUBBAND_HL = 2,
APTXHD_SUBBAND_HH = 3,
__APTXHD_SUBBAND_MAX
};

typedef struct aptXHD_subband_params_100_t {
int32_t *p1;
int32_t *bit16_sl1;
int32_t *p3;
int32_t *dith16_sf1;
int32_t *mLamb16;
int32_t *incr16;
/* number of used bits */
int32_t bits;
int32_t unk1;
int32_t unk2;
/* width of prediction filter */
int32_t filter_width;
} __attribute__ ((packed)) aptXHD_subband_params_100;

typedef struct aptXHD_prediction_filter_100_t {
int32_t width;
int32_t arr1[24];
int16_t sign1;
int16_t sign2;
int32_t unk2;
int32_t unk3;
int32_t subband_param_unk3_2;
int32_t arr2[48];
int32_t i;
int32_t subband_param_unk3_3;
int32_t unk5;
int32_t unk6;
int32_t unk7;
int32_t unk8;
} __attribute__ ((packed)) aptXHD_prediction_filter_100;

typedef struct aptXHD_inverter_100_t {
int32_t *subband_param_p1;
int32_t *subband_param_bit16_sl1;
int32_t *subband_param_dith16_sf1;
int32_t *subband_param_incr16;
int32_t subband_param_unk1;
int32_t subband_param_unk2;
int32_t unk9;
int32_t unk10;
int32_t unk11;
int32_t *log;
} __attribute__ ((packed)) aptXHD_inverter_100;

typedef struct aptXHD_processor_100_t {
aptXHD_prediction_filter_100 filter;
aptXHD_inverter_100 inverter;
} __attribute__ ((packed)) aptXHD_processor_100;

typedef struct aptXHD_quantizer_100_t {
int32_t subband_param_bits;
int32_t *subband_param_p1;
int32_t *subband_param_bit16_sl1;
int32_t *subband_param_p3;
int32_t *subband_param_mLamb16;
int32_t unk1;
int32_t unk2;
int32_t unk3;
} __attribute__ ((packed)) aptXHD_quantizer_100;

typedef struct aptXHD_subband_encoder_100_t {
aptXHD_processor_100 processor[__APTXHD_SUBBAND_MAX];
int32_t codeword;
int32_t dither_sign;
int32_t dither[__APTXHD_SUBBAND_MAX];
aptXHD_quantizer_100 quantizer[__APTXHD_SUBBAND_MAX];
} __attribute__ ((packed)) aptXHD_subband_encoder_100;

typedef struct aptXHD_QMF_analyzer_100_t {
int32_t outer[2][32];
int32_t inner[4][32];
int32_t i_inner;
int32_t i_outer;
} __attribute__ ((packed)) aptXHD_QMF_analyzer_100;

typedef struct aptXHD_encoder_t {
int32_t swap;
int32_t sync;
aptXHD_subband_encoder_100 encoder[APTXHD_CHANNELS];
aptXHD_QMF_analyzer_100 analyzer[APTXHD_CHANNELS];
} __attribute__ ((packed)) aptXHD_encoder_100;

void AsmQmfConvO(const int32_t a1[16], const int32_t a2[16], const int32_t coeffs[16], int32_t out[3]);
void AsmQmfConvI(const int32_t a1[16], const int32_t a2[16], const int32_t coeffs[16], int32_t out[2]);
int32_t BsearchLH(uint32_t a, int32_t b, const int32_t data[9]);
void quantiseDifferenceLL(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
void quantiseDifferenceLH(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
void quantiseDifferenceHL(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
void quantiseDifferenceHH(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
void aptxEncode(int32_t pcm[4], aptXHD_QMF_analyzer_100 *a, aptXHD_subband_encoder_100 *e);
void processSubband(int32_t a, int32_t dither, aptXHD_prediction_filter_100 *f, aptXHD_inverter_100 *i);
void processSubbandLL(int32_t a, int32_t dither, aptXHD_prediction_filter_100 *f, aptXHD_inverter_100 *i);
void processSubbandHL(int32_t a, int32_t dither, aptXHD_prediction_filter_100 *f, aptXHD_inverter_100 *i);

#ifdef __cplusplus
}
#endif

#endif
7 changes: 7 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if ENABLE_APTX422
lib_LTLIBRARIES += libaptx422.la
endif

if ENABLE_APTXHD100
lib_LTLIBRARIES += libaptxHD100.la
endif

libaptx_la_SOURCES = \
sample-sonar.c \
stub-aptx.c
Expand All @@ -29,6 +33,9 @@ libaptx422_la_SOURCES = \
aptx422/search.c \
aptx422/main.c

libaptxHD100_la_SOURCES = \
aptxhd100/main.c

sample-sonar.c: $(srcdir)/sample/sonar.aptx
echo " \
unsigned char sonar_aptx[] = { `xxd -i < $<` }; \
Expand Down
60 changes: 60 additions & 0 deletions src/aptxhd100/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* main.c
* Copyright (c) 2017-2018 Arkadiusz Bokowy
*
* This file is a part of [open]aptx.
*
* This project is licensed under the terms of the MIT license.
*
*/

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include "openaptx.h"
#include "aptxHD100.h"

#include <string.h>

static aptXHD_encoder_100 aptXHD_encoder;

int aptxhdbtenc_init(
APTXENC enc,
bool swap) {

aptXHD_encoder_100 *e = (aptXHD_encoder_100 *)enc;
size_t i, ii;

memset(e, 0, sizeof(*e));

return 0;
}

int aptxhdbtenc_encodestereo(
APTXENC enc,
const int32_t pcmL[4],
const int32_t pcmR[4],
uint32_t code[2]) {

aptXHD_encoder_100 *enc_ = (aptXHD_encoder_100 *)enc;

return 0;
}

const char *aptxhdbtenc_build(void) {
return PACKAGE_STRING;
}

const char *aptxhdbtenc_version(void) {
return VERSION;
}

size_t SizeofAptxhdbtenc(void) {
return sizeof(aptXHD_encoder);
}

APTXENC NewAptxhdEnc(bool swap) {
aptxhdbtenc_init(&aptXHD_encoder, swap);
return &aptXHD_encoder;
}
16 changes: 13 additions & 3 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ if ENABLE_APTX422
check_PROGRAMS += heval422
endif

if ENABLE_APTXHD100
check_PROGRAMS += hevalhd100
endif

heval422_LDADD = \
$(top_builddir)/libbt-aptX-x86-4.2.2.so
$(top_srcdir)/aptx/libbt-aptX-x86-4.2.2.so
heval422_SOURCES = \
../src/aptx422/encode.c \
../src/aptx422/params.c \
../src/aptx422/processor.c \
../src/aptx422/qmf.c \
../src/aptx422/quantizer.c \
../src/aptx422/search.c \
inspect422.c \
heval422.c
inspect-422.c \
heval-422.c

hevalhd100_LDADD = \
$(top_srcdir)/aptx/libaptXHD-1.0.0-rel-Android21-ARMv7A.so
hevalhd100_SOURCES = \
inspect-hd100.c \
heval-hd100.c
12 changes: 6 additions & 6 deletions test/heval422.c → test/heval-422.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* [open]aptx - heval422.c
* heval-422.c
* Copyright (c) 2017-2018 Arkadiusz Bokowy
*
* This file is a part of [open]aptx.
Expand All @@ -14,7 +14,7 @@
#include <time.h>

#include "aptx422.h"
#include "inspect422.h"
#include "inspect-422.h"
#include "openaptx.h"

#include "../src/aptx422/encode.h"
Expand Down Expand Up @@ -136,7 +136,7 @@ static int eval_BsearchLL(size_t nloops) {
if (o_new != o_422) {
printf("\n\ta: %u", a);
printf("\n\tx: %d", x);
printf("\n\tout: %ld != %zd", o_new, o_422);
printf("\n\tout: %zd != %zd", o_new, o_422);
printf("\n");
return -1;
}
Expand All @@ -162,7 +162,7 @@ static int eval_BsearchLH(size_t nloops) {
if (o_new != o_422) {
printf("\n\ta: %u", a);
printf("\n\tx: %d", x);
printf("\n\tout: %ld != %zd", o_new, o_422);
printf("\n\tout: %zd != %zd", o_new, o_422);
printf("\n");
return -1;
}
Expand All @@ -188,7 +188,7 @@ static int eval_BsearchHL(size_t nloops) {
if (o_new != o_422) {
printf("\n\ta: %u", a);
printf("\n\tx: %d", x);
printf("\n\tout: %ld != %zd", o_new, o_422);
printf("\n\tout: %zd != %zd", o_new, o_422);
printf("\n");
return -1;
}
Expand All @@ -214,7 +214,7 @@ static int eval_BsearchHH(size_t nloops) {
if (o_new != o_422) {
printf("\n\ta: %u", a);
printf("\n\tx: %d", x);
printf("\n\tout: %ld != %zd", o_new, o_422);
printf("\n\tout: %zd != %zd", o_new, o_422);
printf("\n");
return -1;
}
Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions test/heval-hd100.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* heval-hd100.c
* Copyright (c) 2017-2018 Arkadiusz Bokowy
*
* This file is a part of [open]aptx.
*
* This project is licensed under the terms of the MIT license.
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "aptxHD100.h"
#include "inspect-hd100.h"
#include "openaptx.h"

int main(int argc, char *argv[]) {

size_t count;
int ret = 0;

if (argc == 2) {
count = atoi(argv[1]);
srand(time(NULL));
}
else if (argc == 3) {
count = atoi(argv[1]);
srand(atoi(argv[2]));
}
else {
printf("usage: %s [COUNT [SEED]]\n", argv[0]);
return -1;
}

printf("== HEURISTIC EVALUATION ==\n");

return ret;
}
Loading

0 comments on commit ebcf004

Please sign in to comment.