Skip to content

Commit f393fb3

Browse files
committed
Mark pre-calculated parameters as constant
1 parent dfec26f commit f393fb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+963
-1346
lines changed

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
BasedOnStyle: LLVM
3+
ColumnLimit: 120
4+
IndentWidth: 4
5+
TabWidth: 4
6+
---
7+
Language: Cpp
8+
AccessModifierOffset: -4
9+
AlignEscapedNewlines: DontAlign
10+
AllowShortFunctionsOnASingleLine: Inline
11+
Cpp11BracedListStyle: false
12+
IndentPPDirectives: AfterHash
13+
PointerAlignment: Middle
14+
SortIncludes: CaseInsensitive
15+
UseTab: ForIndentation
16+
---

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [open]aptx - CMakeLists.txt
22
# Copyright (c) 2017-2021 Arkadiusz Bokowy
33

4-
cmake_minimum_required(VERSION 3.2)
4+
cmake_minimum_required(VERSION 3.22)
55
project(openaptx
66
VERSION 1.3.2
77
DESCRIPTION "Reverse-engineered apt-X audio codec"

include/aptx422.h

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef OPENAPTX_APTX422_H_
1212
#define OPENAPTX_APTX422_H_
1313

14+
#include <assert.h>
1415
#include <stddef.h>
1516
#include <stdint.h>
1617

@@ -19,29 +20,29 @@ extern "C" {
1920
#endif
2021

2122
#define APTX_CHANNELS 2
23+
#define APTX_SUBBANDS 4
2224

2325
enum aptX_subband {
2426
APTX_SUBBAND_LL = 0,
2527
APTX_SUBBAND_LH = 1,
2628
APTX_SUBBAND_HL = 2,
2729
APTX_SUBBAND_HH = 3,
28-
__APTX_SUBBAND_MAX
2930
};
3031

3132
typedef struct aptX_subband_params_422_t {
32-
int32_t *p1;
33-
int32_t *bit16_sl1;
34-
int32_t *p3;
35-
int32_t *dith16_sf1;
36-
int32_t *mLamb16;
37-
int32_t *incr16;
33+
int32_t * p1;
34+
const int32_t * bit16_sl1;
35+
int32_t * p3;
36+
const int32_t * dith16_sf1;
37+
const int32_t * mLamb16;
38+
const int32_t * incr16;
3839
/* number of used bits */
3940
int32_t bits;
4041
int32_t unk1;
4142
int32_t unk2;
4243
/* width of prediction filter */
4344
int32_t filter_width;
44-
} __attribute__ ((packed)) aptX_subband_params_422;
45+
} __attribute__((packed)) aptX_subband_params_422;
4546

4647
typedef struct aptX_prediction_filter_422_t {
4748
int32_t width;
@@ -58,87 +59,93 @@ typedef struct aptX_prediction_filter_422_t {
5859
int32_t unk6;
5960
int32_t unk7;
6061
int32_t unk8;
61-
} __attribute__ ((packed)) aptX_prediction_filter_422;
62+
} __attribute__((packed)) aptX_prediction_filter_422;
6263

6364
typedef struct aptX_inverter_422_t {
64-
int32_t *subband_param_p1;
65-
int32_t *subband_param_bit16_sl1;
66-
int32_t *subband_param_dith16_sf1;
67-
int32_t *subband_param_incr16;
65+
int32_t * subband_param_p1;
66+
const int32_t * subband_param_bit16_sl1;
67+
const int32_t * subband_param_dith16_sf1;
68+
const int32_t * subband_param_incr16;
6869
int32_t subband_param_unk1;
6970
int32_t subband_param_unk2;
7071
int32_t unk9;
7172
int32_t unk10;
7273
int32_t unk11;
73-
int32_t *log;
74-
} __attribute__ ((packed)) aptX_inverter_422;
74+
const int32_t * log;
75+
} __attribute__((packed)) aptX_inverter_422;
7576

7677
typedef struct aptX_processor_422_t {
7778
aptX_prediction_filter_422 filter;
7879
aptX_inverter_422 inverter;
79-
} __attribute__ ((packed)) aptX_processor_422;
80+
} __attribute__((packed)) aptX_processor_422;
8081

8182
typedef struct aptX_quantizer_422_t {
8283
int32_t subband_param_bits;
83-
int32_t *subband_param_p1;
84-
int32_t *subband_param_bit16_sl1;
85-
int32_t *subband_param_p3;
86-
int32_t *subband_param_mLamb16;
84+
int32_t * subband_param_p1;
85+
const int32_t * subband_param_bit16_sl1;
86+
int32_t * subband_param_p3;
87+
const int32_t * subband_param_mLamb16;
8788
int32_t unk1;
8889
int32_t unk2;
8990
int32_t unk3;
90-
} __attribute__ ((packed)) aptX_quantizer_422;
91+
} __attribute__((packed)) aptX_quantizer_422;
9192

9293
typedef struct aptX_subband_encoder_422_t {
93-
aptX_processor_422 processor[__APTX_SUBBAND_MAX];
94+
aptX_processor_422 processor[APTX_SUBBANDS];
9495
int32_t codeword;
9596
int32_t dither_sign;
96-
int32_t dither[__APTX_SUBBAND_MAX];
97-
aptX_quantizer_422 quantizer[__APTX_SUBBAND_MAX];
98-
} __attribute__ ((packed)) aptX_subband_encoder_422;
97+
int32_t dither[APTX_SUBBANDS];
98+
aptX_quantizer_422 quantizer[APTX_SUBBANDS];
99+
} __attribute__((packed)) aptX_subband_encoder_422;
99100

100101
typedef struct aptX_QMF_analyzer_422_t {
101102
int16_t outer[2][32];
102103
int32_t inner[4][32];
103104
int32_t i_inner;
104105
int32_t i_outer;
105-
} __attribute__ ((packed)) aptX_QMF_analyzer_422;
106+
} aptX_QMF_analyzer_422;
107+
108+
static_assert(sizeof(aptX_QMF_analyzer_422) ==
109+
2 * 32 * sizeof(int16_t) + 4 * 32 * sizeof(int32_t) + (1 + 1) * sizeof(int32_t));
106110

107111
typedef struct aptX_encoder_422_t {
108112
int32_t shift;
109113
int32_t sync;
110114
aptX_subband_encoder_422 encoder[APTX_CHANNELS];
111115
aptX_QMF_analyzer_422 analyzer[APTX_CHANNELS];
112-
} __attribute__ ((packed)) aptX_encoder_422;
116+
} aptX_encoder_422;
117+
118+
static_assert(sizeof(aptX_encoder_422) == (1 + 1) * sizeof(int32_t) + APTX_CHANNELS * sizeof(aptX_subband_encoder_422) +
119+
APTX_CHANNELS * sizeof(aptX_QMF_analyzer_422));
113120

114121
/* Functions (theoretically) available in the apt-X library. Some of them
115122
* might not be present in the particular version of the apt-X library due
116123
* to compiler optimizations. Also note, that not all of them are public. */
117124
int32_t updateCodewordHistory(const int32_t a[4], int32_t codeword);
118125
int32_t generateDither(int32_t codeword, int32_t dither[4]);
119-
uint16_t packCodeword(const aptX_subband_encoder_422 *e);
126+
uint16_t packCodeword(const aptX_subband_encoder_422 * e);
120127
void AsmQmfConvO(const int16_t a1[16], const int16_t a2[16], const int32_t coeffs[16], int32_t out[3]);
121128
void AsmQmfConvI(const int32_t a1[16], const int32_t a2[16], const int32_t coeffs[16], int32_t out[2]);
122-
void QmfAnalysisFilter(const int32_t pcm[4], aptX_QMF_analyzer_422 *a, const int32_t refs[4], int32_t diff[4]);
129+
void QmfAnalysisFilter(const int32_t pcm[4], aptX_QMF_analyzer_422 * a, const int32_t refs[4], int32_t diff[4]);
123130
int32_t BsearchLL(uint32_t a, int32_t b, const int32_t data[65]);
124131
int32_t BsearchLH(uint32_t a, int32_t b, const int32_t data[9]);
125132
int32_t BsearchHL(uint32_t a, int32_t b, const int32_t data[3]);
126133
int32_t BsearchHH(uint32_t a, int32_t b, const int32_t data[5]);
127-
void quantiseDifferenceLL(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 *q);
128-
void quantiseDifferenceLH(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 *q);
129-
void quantiseDifferenceHL(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 *q);
130-
void quantiseDifferenceHH(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 *q);
131-
void aptxEncode(int32_t pcm[4], aptX_QMF_analyzer_422 *a, aptX_subband_encoder_422 *e);
132-
void insertSync(aptX_subband_encoder_422 *e1, aptX_subband_encoder_422 *e2, int32_t *sync);
133-
void invertQuantisation(int32_t a, int32_t dither, aptX_inverter_422 *i);
134-
void invertQuantisationHL(int32_t a, int32_t dither, aptX_inverter_422 *i);
135-
void performPredictionFiltering(int32_t a, aptX_prediction_filter_422 *f);
136-
void performPredictionFilteringLL(int32_t a, aptX_prediction_filter_422 *f);
137-
void performPredictionFilteringHL(int32_t a, aptX_prediction_filter_422 *f);
138-
void processSubband(int32_t a, int32_t dither, aptX_prediction_filter_422 *f, aptX_inverter_422 *i);
139-
void processSubbandLL(int32_t a, int32_t dither, aptX_prediction_filter_422 *f, aptX_inverter_422 *i);
140-
void processSubbandHL(int32_t a, int32_t dither, aptX_prediction_filter_422 *f, aptX_inverter_422 *i);
141-
void aptxPostEncode(aptX_subband_encoder_422 *e);
134+
void quantiseDifferenceLL(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 * q);
135+
void quantiseDifferenceLH(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 * q);
136+
void quantiseDifferenceHL(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 * q);
137+
void quantiseDifferenceHH(int32_t diff, int32_t dither, int32_t c, aptX_quantizer_422 * q);
138+
void aptxEncode(int32_t pcm[4], aptX_QMF_analyzer_422 * a, aptX_subband_encoder_422 * e);
139+
void insertSync(aptX_subband_encoder_422 * e1, aptX_subband_encoder_422 * e2, int32_t * sync);
140+
void invertQuantisation(int32_t a, int32_t dither, aptX_inverter_422 * i);
141+
void invertQuantisationHL(int32_t a, int32_t dither, aptX_inverter_422 * i);
142+
void performPredictionFiltering(int32_t a, aptX_prediction_filter_422 * f);
143+
void performPredictionFilteringLL(int32_t a, aptX_prediction_filter_422 * f);
144+
void performPredictionFilteringHL(int32_t a, aptX_prediction_filter_422 * f);
145+
void processSubband(int32_t a, int32_t dither, aptX_prediction_filter_422 * f, aptX_inverter_422 * i);
146+
void processSubbandLL(int32_t a, int32_t dither, aptX_prediction_filter_422 * f, aptX_inverter_422 * i);
147+
void processSubbandHL(int32_t a, int32_t dither, aptX_prediction_filter_422 * f, aptX_inverter_422 * i);
148+
void aptxPostEncode(aptX_subband_encoder_422 * e);
142149

143150
#ifdef __cplusplus
144151
}

include/aptxHD100.h

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef OPENAPTX_APTXHD100_H_
1212
#define OPENAPTX_APTXHD100_H_
1313

14+
#include <assert.h>
1415
#include <stddef.h>
1516
#include <stdint.h>
1617

@@ -19,29 +20,29 @@ extern "C" {
1920
#endif
2021

2122
#define APTXHD_CHANNELS 2
23+
#define APTXHD_SUBBANDS 4
2224

2325
enum aptXHD_subband {
2426
APTXHD_SUBBAND_LL = 0,
2527
APTXHD_SUBBAND_LH = 1,
2628
APTXHD_SUBBAND_HL = 2,
2729
APTXHD_SUBBAND_HH = 3,
28-
__APTXHD_SUBBAND_MAX
2930
};
3031

3132
typedef struct aptXHD_subband_params_100_t {
32-
int32_t *p1;
33-
int32_t *bit16_sl1;
34-
int32_t *p3;
35-
int32_t *dith16_sf1;
36-
int32_t *mLamb16;
37-
int32_t *incr16;
33+
int32_t * p1;
34+
const int32_t * bit16_sl1;
35+
int32_t * p3;
36+
const int32_t * dith16_sf1;
37+
const int32_t * mLamb16;
38+
const int32_t * incr16;
3839
/* number of used bits */
3940
int32_t bits;
4041
int32_t unk1;
4142
int32_t unk2;
4243
/* width of prediction filter */
4344
int32_t filter_width;
44-
} __attribute__ ((packed)) aptXHD_subband_params_100;
45+
} __attribute__((packed)) aptXHD_subband_params_100;
4546

4647
typedef struct aptXHD_prediction_filter_100_t {
4748
int32_t width;
@@ -58,70 +59,77 @@ typedef struct aptXHD_prediction_filter_100_t {
5859
int32_t unk6;
5960
int32_t unk7;
6061
int32_t unk8;
61-
} __attribute__ ((packed)) aptXHD_prediction_filter_100;
62+
} __attribute__((packed)) aptXHD_prediction_filter_100;
6263

6364
typedef struct aptXHD_inverter_100_t {
64-
int32_t *subband_param_p1;
65-
int32_t *subband_param_bit16_sl1;
66-
int32_t *subband_param_dith16_sf1;
67-
int32_t *subband_param_incr16;
65+
int32_t * subband_param_p1;
66+
const int32_t * subband_param_bit16_sl1;
67+
const int32_t * subband_param_dith16_sf1;
68+
const int32_t * subband_param_incr16;
6869
int32_t subband_param_unk1;
6970
int32_t subband_param_unk2;
7071
int32_t unk9;
7172
int32_t unk10;
7273
int32_t unk11;
73-
int32_t *log;
74-
} __attribute__ ((packed)) aptXHD_inverter_100;
74+
const int32_t * log;
75+
} __attribute__((packed)) aptXHD_inverter_100;
7576

7677
typedef struct aptXHD_processor_100_t {
7778
aptXHD_prediction_filter_100 filter;
7879
aptXHD_inverter_100 inverter;
79-
} __attribute__ ((packed)) aptXHD_processor_100;
80+
} __attribute__((packed)) aptXHD_processor_100;
8081

8182
typedef struct aptXHD_quantizer_100_t {
8283
int32_t subband_param_bits;
83-
int32_t *subband_param_p1;
84-
int32_t *subband_param_bit16_sl1;
85-
int32_t *subband_param_p3;
86-
int32_t *subband_param_mLamb16;
84+
int32_t * subband_param_p1;
85+
const int32_t * subband_param_bit16_sl1;
86+
int32_t * subband_param_p3;
87+
const int32_t * subband_param_mLamb16;
8788
int32_t unk1;
8889
int32_t unk2;
8990
int32_t unk3;
90-
} __attribute__ ((packed)) aptXHD_quantizer_100;
91+
} __attribute__((packed)) aptXHD_quantizer_100;
9192

9293
typedef struct aptXHD_subband_encoder_100_t {
93-
aptXHD_processor_100 processor[__APTXHD_SUBBAND_MAX];
94+
aptXHD_processor_100 processor[APTXHD_SUBBANDS];
9495
int32_t codeword;
9596
int32_t dither_sign;
96-
int32_t dither[__APTXHD_SUBBAND_MAX];
97-
aptXHD_quantizer_100 quantizer[__APTXHD_SUBBAND_MAX];
98-
} __attribute__ ((packed)) aptXHD_subband_encoder_100;
97+
int32_t dither[APTXHD_SUBBANDS];
98+
aptXHD_quantizer_100 quantizer[APTXHD_SUBBANDS];
99+
} __attribute__((packed)) aptXHD_subband_encoder_100;
99100

100101
typedef struct aptXHD_QMF_analyzer_100_t {
101102
int32_t outer[2][32];
102103
int32_t inner[4][32];
103104
int32_t i_inner;
104105
int32_t i_outer;
105-
} __attribute__ ((packed)) aptXHD_QMF_analyzer_100;
106+
} aptXHD_QMF_analyzer_100;
107+
108+
static_assert(sizeof(aptXHD_QMF_analyzer_100) ==
109+
2 * 32 * sizeof(int32_t) + 4 * 32 * sizeof(int32_t) + (1 + 1) * sizeof(int32_t));
106110

107111
typedef struct aptXHD_encoder_t {
108112
int32_t shift;
109113
int32_t sync;
110114
aptXHD_subband_encoder_100 encoder[APTXHD_CHANNELS];
111115
aptXHD_QMF_analyzer_100 analyzer[APTXHD_CHANNELS];
112-
} __attribute__ ((packed)) aptXHD_encoder_100;
116+
} aptXHD_encoder_100;
117+
118+
static_assert(sizeof(aptXHD_encoder_100) == (1 + 1) * sizeof(int32_t) +
119+
APTXHD_CHANNELS * sizeof(aptXHD_subband_encoder_100) +
120+
APTXHD_CHANNELS * sizeof(aptXHD_QMF_analyzer_100));
113121

114122
void AsmQmfConvO(const int32_t a1[16], const int32_t a2[16], const int32_t coeffs[16], int32_t out[3]);
115123
void AsmQmfConvI(const int32_t a1[16], const int32_t a2[16], const int32_t coeffs[16], int32_t out[2]);
116124
int32_t BsearchLH(uint32_t a, int32_t b, const int32_t data[9]);
117-
void quantiseDifferenceLL(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
118-
void quantiseDifferenceLH(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
119-
void quantiseDifferenceHL(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
120-
void quantiseDifferenceHH(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 *q);
121-
void aptxEncode(int32_t pcm[4], aptXHD_QMF_analyzer_100 *a, aptXHD_subband_encoder_100 *e);
122-
void processSubband(int32_t a, int32_t dither, aptXHD_prediction_filter_100 *f, aptXHD_inverter_100 *i);
123-
void processSubbandLL(int32_t a, int32_t dither, aptXHD_prediction_filter_100 *f, aptXHD_inverter_100 *i);
124-
void processSubbandHL(int32_t a, int32_t dither, aptXHD_prediction_filter_100 *f, aptXHD_inverter_100 *i);
125+
void quantiseDifferenceLL(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 * q);
126+
void quantiseDifferenceLH(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 * q);
127+
void quantiseDifferenceHL(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 * q);
128+
void quantiseDifferenceHH(int32_t diff, int32_t dither, int32_t c, aptXHD_quantizer_100 * q);
129+
void aptxEncode(int32_t pcm[4], aptXHD_QMF_analyzer_100 * a, aptXHD_subband_encoder_100 * e);
130+
void processSubband(int32_t a, int32_t dither, aptXHD_prediction_filter_100 * f, aptXHD_inverter_100 * i);
131+
void processSubbandLL(int32_t a, int32_t dither, aptXHD_prediction_filter_100 * f, aptXHD_inverter_100 * i);
132+
void processSubbandHL(int32_t a, int32_t dither, aptXHD_prediction_filter_100 * f, aptXHD_inverter_100 * i);
125133

126134
#ifdef __cplusplus
127135
}

0 commit comments

Comments
 (0)