1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
#include "config.h"
#include <stdio.h>
#include <math.h>
#include <schroedinger/schro.h>
#include <schroedinger/schroorc.h>
#include "schroedinger/schrotables.c"
#if 0
static int
dequantise (int q, int quant_factor, int quant_offset)
{
if (q == 0) return 0;
if (q < 0) {
return ((q * quant_factor - quant_offset + 2)>>2);
} else {
return (q * quant_factor + quant_offset + 2)>>2;
}
}
static int
quantise (int value, int quant_factor, int quant_offset)
{
unsigned int x;
if (value == 0) return 0;
if (value < 0) {
x = ((-value)<<2) - quant_offset + (quant_factor>>1);
//x = (x*(uint64_t)inv_quant_factor)>>32;
x /= quant_factor;
value = -x;
} else {
x = (value<<2) - quant_offset + (quant_factor>>1);
//x = (x*(uint64_t)inv_quant_factor)>>32;
x /= quant_factor;
value = x;
}
return value;
}
#endif
void test_quant (int quant_index, int ack);
void test_dequant (int quant_index);
#define N 2000
int16_t a[N];
int16_t b[N];
int16_t c[N];
int16_t d[N];
int
main (int argc, char *argv[])
{
int i;
schro_init();
schro_tables_init();
#if 0
for(i=0;i<65536;i+=256) {
printf("%d\n", i);
test_quant (3, i);
}
#endif
for(i=0;i<61;i++) {
test_quant (i, 0);
}
for(i=0;i<61;i++) {
test_dequant (i);
}
return 0;
}
void
test_quant (int quant_index, int ack)
{
int quant_factor = schro_table_quant[quant_index];
int quant_offset = schro_table_offset_1_2[quant_index];
int quant_shift = quant_index/4 + 2;
int error = FALSE;
int i;
int bad_count;
//printf("index %d:\n", quant_index);
for(i=0;i<2000;i++){
a[i] = i - 1000;
b[i] = i - 1000;
c[i] = i - 1000;
d[i] = i - 1000;
}
for(i=0;i<N;i++){
a[i] = schro_quantise(a[i],quant_factor,quant_offset);
}
if (quant_index == 0) {
/* do nothing */
} else if ((quant_index & 3) == 0) {
orc_quantdequant2_s16 (b, d, quant_shift,
quant_offset - quant_factor/2, quant_factor, quant_offset + 2, N);
} else if (quant_index != 3) {
int inv_quant;
inv_quant = schro_table_inverse_quant[quant_index];
orc_quantdequant1_s16 (b, d, inv_quant,
quant_offset - quant_factor/2 - (quant_index > 8),
quant_shift, quant_factor, quant_offset + 2, N);
} else {
int inv_quant;
inv_quant = schro_table_inverse_quant[quant_index];
orc_quantdequant3_s16 (b, d, inv_quant,
quant_offset - quant_factor/2,
quant_shift + 16, quant_factor,
quant_offset + 2,
32768, N);
}
bad_count=0;
for(i=0;i<N;i++){
//if (a[i] < b[i] - 1 || a[i] > b[i] + 1) error = TRUE;
//if (a[i] != b[i]) error = TRUE;
if (a[i] != b[i]) bad_count++;
}
printf("index %d: %d\n", quant_index, bad_count);
if (error) {
for(i=0;i<N;i++){
printf("%d %d %d %d %d %d %c\n", i, c[i], a[i],
schro_dequantise (a[i], quant_factor, quant_offset),
b[i], d[i],
(a[i]!=b[i]) ? '*':' ');
}
}
}
void
test_dequant (int quant_index)
{
int quant_factor = schro_table_quant[quant_index];
int quant_offset = schro_table_offset_3_8[quant_index];
int error = FALSE;
int i;
printf("index %d:\n", quant_index);
for(i=0;i<N;i++){
a[i] = i - 1000;
b[i] = schro_quantise(a[i],quant_factor,quant_offset);
c[i] = b[i];
}
for(i=0;i<N;i++){
b[i] = schro_dequantise(b[i],quant_factor,quant_offset);
}
if (quant_index == 0) {
/* do nothing */
} else {
orc_dequantise_s16 (c, c, quant_factor, quant_offset, N);
}
for(i=0;i<N;i++){
if (b[i] < c[i] - 1 || b[i] > c[i] + 1) error = TRUE;
}
if (error) {
for(i=0;i<N;i++){
printf("%d %d %d %d %c\n", i, a[i], b[i], c[i], (b[i]!=c[i]) ? '*':' ');
}
}
}
|