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
2325enum 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
3132typedef 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
4647typedef 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
6364typedef 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
7677typedef 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
8182typedef 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
9293typedef 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
100101typedef 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
107111typedef 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. */
117124int32_t updateCodewordHistory (const int32_t a [4 ], int32_t codeword );
118125int32_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 );
120127void AsmQmfConvO (const int16_t a1 [16 ], const int16_t a2 [16 ], const int32_t coeffs [16 ], int32_t out [3 ]);
121128void 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 ]);
123130int32_t BsearchLL (uint32_t a , int32_t b , const int32_t data [65 ]);
124131int32_t BsearchLH (uint32_t a , int32_t b , const int32_t data [9 ]);
125132int32_t BsearchHL (uint32_t a , int32_t b , const int32_t data [3 ]);
126133int32_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}
0 commit comments