fix: TAD for TSVM producing distorted audio

This commit is contained in:
minjaesong
2025-11-10 10:43:49 +09:00
parent 0e6f2162c8
commit 0f5875d45b
2 changed files with 30 additions and 14 deletions

View File

@@ -142,17 +142,32 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
) )
// Base quantiser weight table (10 subbands: LL + 9 H bands) // Base quantiser weight table (10 subbands: LL + 9 H bands)
private val BASE_QUANTISER_WEIGHTS = floatArrayOf( // CRITICAL: Different weights for Mid (channel 0) and Side (channel 1) channels!
1.0f, // LL (L9) - finest preservation private val BASE_QUANTISER_WEIGHTS = arrayOf(
1.0f, // H (L9) floatArrayOf( // Mid channel (channel 0)
1.0f, // H (L8) 4.0f, // LL (L9) DC
1.0f, // H (L7) 2.0f, // H (L9) 31.25 hz
1.0f, // H (L6) 1.8f, // H (L8) 62.5 hz
1.1f, // H (L5) 1.6f, // H (L7) 125 hz
1.2f, // H (L4) 1.4f, // H (L6) 250 hz
1.3f, // H (L3) 1.2f, // H (L5) 500 hz
1.4f, // H (L2) 1.0f, // H (L4) 1 khz
1.5f // H (L1) - coarsest quantization 1.0f, // H (L3) 2 khz
1.3f, // H (L2) 4 khz
2.0f // H (L1) 8 khz
),
floatArrayOf( // Side channel (channel 1)
6.0f, // LL (L9) DC
5.0f, // H (L9) 31.25 hz
2.6f, // H (L8) 62.5 hz
2.4f, // H (L7) 125 hz
1.8f, // H (L6) 250 hz
1.3f, // H (L5) 500 hz
1.0f, // H (L4) 1 khz
1.0f, // H (L3) 2 khz
1.6f, // H (L2) 4 khz
3.2f // H (L1) 8 khz
)
) )
private val LAMBDA_FIXED = 6.0f private val LAMBDA_FIXED = 6.0f
@@ -931,7 +946,8 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
val normalizedVal = lambdaDecompanding(quantized[i], maxIndex) val normalizedVal = lambdaDecompanding(quantized[i], maxIndex)
// Denormalize using the subband scalar and apply base weight + quantiser scaling // Denormalize using the subband scalar and apply base weight + quantiser scaling
val weight = BASE_QUANTISER_WEIGHTS[sideband] * quantiserScale // CRITICAL: Use channel-specific weights (Mid=0, Side=1)
val weight = BASE_QUANTISER_WEIGHTS[channel][sideband] * quantiserScale
coeffs[i] = normalizedVal * TAD32_COEFF_SCALARS[sideband] * weight coeffs[i] = normalizedVal * TAD32_COEFF_SCALARS[sideband] * weight
// } // }
} }

View File

@@ -1070,10 +1070,10 @@ int main(int argc, char *argv[]) {
output_file[dir_len + name_len] = '\0'; output_file[dir_len + name_len] = '\0';
// Replace last dot with underscore (for .qNN pattern) // Replace last dot with underscore (for .qNN pattern)
char *last_dot = strrchr(output_file, '.'); /*char *last_dot = strrchr(output_file, '.');
if (last_dot && last_dot > output_file + dir_len) { if (last_dot && last_dot > output_file + dir_len) {
*last_dot = '_'; *last_dot = '_';
} }*/
} else { } else {
// No .tad extension, copy entire basename // No .tad extension, copy entire basename
strcpy(output_file + dir_len, basename_start); strcpy(output_file + dir_len, basename_start);