TAD: EZBC with fixes

This commit is contained in:
minjaesong
2025-11-10 01:45:33 +09:00
parent 3f97f1a59e
commit 28e9a88f8d
3 changed files with 17 additions and 7 deletions

View File

@@ -733,6 +733,9 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
val absVal = kotlin.math.abs(coeffs[idx].toInt())
coeffs[idx] = (sign * (absVal or (1 shl bitplane))).toByte()
}
// Add to nextSignificant so it continues being refined
nextSignificant.push(block)
}
// Swap queues for next bitplane
@@ -783,7 +786,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
return
}
// Decode using binary tree EZBC
// Decode using binary tree EZBC - FIXED!
val quantMid = ByteArray(sampleCount)
val quantSide = ByteArray(sampleCount)

View File

@@ -834,6 +834,9 @@ static int tad_decode_channel_ezbc(const uint8_t *input, size_t input_size, int8
abs_val |= (1 << bitplane);
coeffs[idx] = sign * abs_val;
}
// Add to next_significant so it continues being refined
tad_decode_queue_push(&next_significant, block);
}
// Swap queues for next bitplane
@@ -916,7 +919,7 @@ static int decode_chunk(const uint8_t *input, size_t input_size, uint8_t *pcmu8_
uint8_t *pcm8_left = malloc(sample_count * sizeof(uint8_t));
uint8_t *pcm8_right = malloc(sample_count * sizeof(uint8_t));
// Decode Mid/Side using binary tree EZBC
// Decode Mid/Side using binary tree EZBC - FIXED!
size_t mid_bytes_consumed = 0;
size_t side_bytes_consumed = 0;

View File

@@ -435,16 +435,16 @@ static void quantize_dwt_coefficients(int channel, const float *coeffs, int8_t *
}
// Check for deadzone marker (special handling)
if (coeffs[i] == DEADZONE_MARKER_FLOAT) {
/*if (coeffs[i] == DEADZONE_MARKER_FLOAT) {
// Map to special quantized marker for stochastic reconstruction
quantized[i] = (int8_t)DEADZONE_MARKER_QUANT;
} else {
} else {*/
// Normal quantization
float weight = BASE_QUANTISER_WEIGHTS[channel][sideband] * quantiser_scale;
float val = (coeffs[i] / (TAD32_COEFF_SCALARS[sideband] * weight)); // val is normalised to [-1,1]
int8_t quant_val = lambda_companding(val, max_index);
quantized[i] = quant_val;
}
// }
}
free(sideband_starts);
@@ -1035,7 +1035,8 @@ static void tad_process_significant_block_recursive(tad_ezbc_context_t *ctx, tad
}
// Binary tree EZBC encoding for a single channel (1D variant)
static size_t tad_encode_channel_ezbc(int8_t *coeffs, size_t count, uint8_t **output) {
// Made non-static for testing
size_t tad_encode_channel_ezbc(int8_t *coeffs, size_t count, uint8_t **output) {
tad_bitstream_t bs;
tad_bitstream_init(&bs, count / 4); // Initial guess
@@ -1105,6 +1106,9 @@ static size_t tad_encode_channel_ezbc(int8_t *coeffs, size_t count, uint8_t **ou
// Emit refinement bit (bit at position 'bitplane')
int bit = (abs(coeffs[idx]) >> bitplane) & 1;
tad_bitstream_write_bit(&bs, bit);
// Add to next_significant so it continues being refined
tad_queue_push(&next_significant, block);
}
// Swap queues for next bitplane
@@ -1212,7 +1216,7 @@ size_t tad32_encode_chunk(const float *pcm32_stereo, size_t num_samples,
accumulate_quantized(quant_side, dwt_levels, num_samples, side_quant_accumulators);
}
// Step 5: Encode with binary tree EZBC (1D variant)
// Step 5: Encode with binary tree EZBC (1D variant) - FIXED!
uint8_t *mid_ezbc = NULL;
uint8_t *side_ezbc = NULL;