Implementing the SBC subband filters (analysis and synthesis)
2024-03-14 11:30:29

Hello, I'd like to dabble a bit with subband coding and I feel the best way for me to grasp something is to implement it. The Bluetooth SBC codec looks like it has a neat, publicly available spec (https://www.bluetooth.com/specifications/specs/advanced-audio-distribution-profile-1-4/ - "Advanced Audio Distribution Profile 1.4"), so I'd like to implement the 8 band analysis and synthesis as a base for my experiments. The "Advanced Audio Distribution Profile 1.4"-document includes two flow charts I'm interested in, as they appear to provide clear guidance on how to implement the filters: SBC Analysis (from page 68): SBC Synthesis (from page 66): My understanding is that one can drop 8 audio samples into Analysis, get 8 subband samples, which can be dropped into Synthesis, which reconstructs the original 8 audio samples (or at least close approximations). An actual codec would quantize the subband samples to achieve compression, but without quantization, things should be nearly lossless. That's not what I'm getting (recognizable audio, but it appears the lowest band is duplicated and "mirrored" 8 times where the other bands should be), so I suspect I misunderstand how to read the flow diagrams. I'm unsure in Analysis starting with the step "Partial Calculation": For me, it's unclear what the "sum(X[i+k*16)" is, as "X[i+k*16]" is a single value and I expect a sum to be defined over multiple elements. As such I just read this to mean that I shall sum up the contributions for all values of k: // Step 3: "Partial Calculation" for(int i = 0; i <= 15; i++) { double sum = 0.0; for(int k = 0; k <= 4; k++) { sum += z[i + (k * 16)]; } y[i] = sum; } If this is not the correct interpretation of the "sum(...)" operation, that'd explain the garbled output, otherwise I'm quite stumped on what's going wrong in my implementation.