tns: Quantize on 16 bits the RC coeffs, required for LC3 Plus HR

This commit is contained in:
Antoine Soulier
2024-01-23 14:09:16 -08:00
parent 5f70c731f5
commit d9973b605b
3 changed files with 22 additions and 9 deletions
+8 -7
View File
@@ -241,11 +241,12 @@ LC3_HOT static void lpc_reflection(
*/ */
static void quantize_rc(const float *rc, int maxorder, int *order, int *rc_q) static void quantize_rc(const float *rc, int maxorder, int *order, int *rc_q)
{ {
/* Quantization table, sin(delta * (i + 0.5)), delta = Pi / 17 */ /* Quantization table, sin(delta * (i + 0.5)), delta = Pi / 17,
* rounded to fixed point Q15 value (LC3-Plus HR requirements). */
static float q_thr[] = { static float q_thr[] = {
9.22683595e-02, 2.73662990e-01, 4.45738356e-01, 6.02634636e-01, 0x0bcfp-15, 0x2307p-15, 0x390ep-15, 0x4d23p-15,
7.39008917e-01, 8.50217136e-01, 9.32472229e-01, 9.82973100e-01 0x5e98p-15, 0x6cd4p-15, 0x775bp-15, 0x7dd2p-15,
}; };
*order = maxorder; *order = maxorder;
@@ -270,12 +271,12 @@ static void quantize_rc(const float *rc, int maxorder, int *order, int *rc_q)
*/ */
static void unquantize_rc(const int *rc_q, int order, float rc[8]) static void unquantize_rc(const int *rc_q, int order, float rc[8])
{ {
/* Quantization table, sin(delta * i), delta = Pi / 17 */ /* Quantization table, sin(delta * i), delta = Pi / 17,
* rounded to fixed point Q15 value (LC3-Plus HR requirements). */
static float q_inv[] = { static float q_inv[] = {
0.00000000e+00, 1.83749517e-01, 3.61241664e-01, 5.26432173e-01, 0x0000p-15, 0x1785p-15, 0x2e3dp-15, 0x4362p-15,
6.73695641e-01, 7.98017215e-01, 8.95163302e-01, 9.61825645e-01, 0x563cp-15, 0x6625p-15, 0x7295p-15, 0x7b1dp-15, 0x7f74p-15,
9.95734176e-01
}; };
int i; int i;
+12 -2
View File
@@ -141,9 +141,19 @@ def tns_lag_window():
def tns_quantization_table(): def tns_quantization_table():
print('\n--- tns quantization table ---') print('\n--- tns quantization table ---')
print_table(np.sin((np.arange(8) + 0.5) * (np.pi / 17)))
print_table(np.sin((np.arange(8)) * (np.pi / 17)))
xe = np.sin((np.arange(8) + 0.5) * (np.pi / 17))
xe = np.rint(xe * 2**15).astype(np.int16)
xd = np.sin(np.arange(9) * (np.pi / 17))
xd = np.rint(xd * 2**15).astype(np.int16)
for x in (xe, xd):
print()
for (i, xi) in enumerate(x):
print('0x{:04x}p-15,'.format(xi), end = '\n' if i%4 == 4-1 else ' ')
if len(x) % 4:
print()
def quant_iq_table(): def quant_iq_table():
+2
View File
@@ -203,6 +203,7 @@ class TnsAnalysis(Tns):
delta = np.pi / 17 delta = np.pi / 17
rc_i = np.rint(np.arcsin(rc) / delta).astype(int) + 8 rc_i = np.rint(np.arcsin(rc) / delta).astype(int) + 8
rc_q = np.sin(delta * (rc_i - 8)) rc_q = np.sin(delta * (rc_i - 8))
rc_q = np.rint(rc_q * 2**15) / 2**15
rc_order = len(rc_i) - np.argmin(rc_i[::-1] == 8) rc_order = len(rc_i) - np.argmin(rc_i[::-1] == 8)
@@ -337,6 +338,7 @@ class TnsSynthesis(Tns):
rc_order = self.rc_order[f] rc_order = self.rc_order[f]
rc = np.sin((np.pi / 17) * (self.rc[f] - 8)) rc = np.sin((np.pi / 17) * (self.rc[f] - 8))
rc = np.rint(rc * 2**15) / 2**15
if rc_order > 0: if rc_order > 0:
i0 = Tns.FREQ_LIM[self.dt][bw][f] i0 = Tns.FREQ_LIM[self.dt][bw][f]