xref: /btstack/test/sbc/sbc_synthesis_v1.py (revision 6ccd8248590f666db07dd7add13fecb4f5664fb5)
1#!/usr/bin/env python3
2import numpy as np
3import wave
4import struct
5import sys
6import time
7from sbc import *
8
9matrix_R = np.zeros(shape = (16,8))
10matrix_C2 = np.zeros(shape = (8,8))
11matrix_N = np.zeros(shape = (16,16))
12V_SGN = [1,1,1,1, 0, -1,-1,-1,-1, 1,1,1,1,1,1,1]
13V_remap = np.zeros(80)
14
15def sbc_init_synthesis_v1(M):
16    global matrix_R, matrix_C2, matrix_N
17    if M == 4:
18        print("SBC V1 init failed, 4-subband version not implemented yet")
19    M2 = M << 1
20    Mh = M >> 1
21    L  = 10 * M
22    L2 = L << 1
23
24    matrix_R = np.zeros(shape = (M2,M))
25    matrix_C2 = np.zeros(shape = (M,M))
26    matrix_N = np.zeros(shape = (M2,M2))
27    V_remap  = np.zeros(L)
28
29    R_c1 = 12
30
31    for k in range(Mh):
32        matrix_R[k][k+Mh] = 1
33
34    for k in range(Mh+1,M2):
35        matrix_R[k][abs(R_c1-k)] = -1
36
37    for k in range(M):
38        for i in range(M):
39            matrix_C2[k][i] = np.cos((i+0.5)*k*np.pi/M)
40
41    matrix_N = np.dot(matrix_R, matrix_C2)
42
43    for i in range(L):
44        offset = i%M2
45        if offset >= M:
46            offset += M2
47        V_remap[i] = L2/5 * (i/M2) + offset
48
49
50
51def VSGN(i,M2):
52    return V_SGN[i%M2]
53
54def remap_V(i):
55    global V_remap
56    return V_remap[i]
57
58def sbc_frame_synthesis_v1_4subbands(frame, ch, blk):
59    print ("sbc_frame_synthesis_v1_4subbands(frame, ch, blk) not implemented yet")
60    exit(1)
61
62def sbc_frame_synthesis_v1_8subbands(frame, ch, blk):
63    print ("sbc_frame_synthesis_v1_8subbands(frame, ch, blk) not implemented yet")
64    exit(1)
65
66def matrix_R():
67    global matrix_R
68    return matrix_R
69
70def matrix_C2():
71    global matrix_C2
72    return matrix_C2
73
74def matrix_N():
75    global matrix_N
76    return matrix_N
77
78def R(k,i):
79    global matrix_R
80    return matrix_R[k][i]
81
82def C2(k,i):
83    global matrix_C2
84    return matrix_C2[k][i]