diff --git a/video_encoder/decoder_tad.c b/video_encoder/decoder_tad.c
index 74b01c1..a41ed81 100644
--- a/video_encoder/decoder_tad.c
+++ b/video_encoder/decoder_tad.c
@@ -22,16 +22,16 @@ static const float TAD32_COEFF_SCALARS[] = {64.0f, 45.255f, 32.0f, 22.627f, 16.0
// Linearly spaced from 1.0 (LL) to 2.0 (H9)
// These weights are multiplied by quantiser_scale during dequantization
static const float BASE_QUANTISER_WEIGHTS[] = {
- 1.0f, // LL (L9) - finest preservation
- 1.111f, // H (L9)
- 1.222f, // H (L8)
- 1.333f, // H (L7)
- 1.444f, // H (L6)
- 1.556f, // H (L5)
- 1.667f, // H (L4)
- 1.778f, // H (L3)
- 1.889f, // H (L2)
- 2.0f // H (L1) - coarsest quantization
+ 1.0f, // LL (L9) - finest preservation
+ 1.0f, // H (L9)
+ 1.0f, // H (L8)
+ 1.0f, // H (L7)
+ 1.0f, // H (L6)
+ 1.1f, // H (L5)
+ 1.2f, // H (L4)
+ 1.3f, // H (L3)
+ 1.4f, // H (L2)
+ 1.5f // H (L1) - coarsest quantization
};
#define TAD_DEFAULT_CHUNK_SIZE 32768
@@ -52,6 +52,37 @@ static inline float FCLAMP(float x, float min, float max) {
return x < min ? min : (x > max ? max : x);
}
+//=============================================================================
+// WAV Header Writing
+//=============================================================================
+
+static void write_wav_header(FILE *output, uint32_t data_size, uint16_t channels, uint32_t sample_rate, uint16_t bits_per_sample) {
+ uint32_t byte_rate = sample_rate * channels * bits_per_sample / 8;
+ uint16_t block_align = channels * bits_per_sample / 8;
+ uint32_t chunk_size = 36 + data_size;
+
+ // RIFF header
+ fwrite("RIFF", 1, 4, output);
+ fwrite(&chunk_size, 4, 1, output);
+ fwrite("WAVE", 1, 4, output);
+
+ // fmt chunk
+ fwrite("fmt ", 1, 4, output);
+ uint32_t fmt_size = 16;
+ fwrite(&fmt_size, 4, 1, output);
+ uint16_t audio_format = 1; // PCM
+ fwrite(&audio_format, 2, 1, output);
+ fwrite(&channels, 2, 1, output);
+ fwrite(&sample_rate, 4, 1, output);
+ fwrite(&byte_rate, 4, 1, output);
+ fwrite(&block_align, 2, 1, output);
+ fwrite(&bits_per_sample, 2, 1, output);
+
+ // data chunk header
+ fwrite("data", 1, 4, output);
+ fwrite(&data_size, 4, 1, output);
+}
+
// Calculate DWT levels from chunk size (must be power of 2, >= 1024)
static int calculate_dwt_levels(int chunk_size) {
/*if (chunk_size < TAD_MIN_CHUNK_SIZE) {
@@ -287,9 +318,9 @@ static void expand_gamma(float *left, float *right, size_t count) {
for (size_t i = 0; i < count; i++) {
// decode(y) = sign(y) * |y|^(1/γ) where γ=0.5
float x = left[i]; float a = fabsf(x);
- left[i] = signum(x) * a * a;
+ left[i] = signum(x) * powf(a, 1.4142f);
float y = right[i]; float b = fabsf(y);
- right[i] = signum(y) * b * b;
+ right[i] = signum(y) * powf(b, 1.4142f);
}
}
@@ -514,24 +545,34 @@ static int decode_chunk(const uint8_t *input, size_t input_size, uint8_t *pcmu8_
//=============================================================================
static void print_usage(const char *prog_name) {
- printf("Usage: %s -i -o