path
stringlengths
14
112
content
stringlengths
0
6.32M
size
int64
0
6.32M
max_lines
int64
1
100k
repo_name
stringclasses
2 values
autogenerated
bool
1 class
cosmopolitan/test/dsp/tty/windex_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/windex.h" #include "libc/assert.h" #include "libc/intrin/bits.h" #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" unsigned windex_k8(short *, size_t) _Hide; unsigned windex_avx2(short *, size_t) _Hide; unsigned windex_sse4(short *, size_t) _Hide; const short kW[64] forcealign(32) = { 8281, 3883, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923, 3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905, 2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, 33, 1085, 7806, 3248, 1186, 1357, 6738, 1311, 1092, 6195, 7089, 6631, 1261, 1364, 9007, 8289, 1409, 1090, 8358, 1502, 7658, 2668, 3522, 1730, 2041, 7707, 5096, 6876, 1324, 1242, 5283, 0x7fff, }; const short kW2[32] forcealign(32) = { 8281, 1, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923, 3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905, 2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, }; const short kW3[64] forcealign(32) = { 8281, 0x7fff, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923, 3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905, 2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, 33, 1085, 7806, 3248, 1186, 1357, 6738, 1311, 1092, 6195, 7089, 6631, 1261, 1364, 9007, 8289, 1409, 1090, 8358, 1502, 7658, 2668, 3522, 1730, 2041, 7707, 5096, 6876, 1324, 1242, 7, 0x7fff, }; #define TestIt(impl, index, value, n, array) \ ({ \ short *a = memcpy(gc(memalign(32, n * 2)), array, n * 2); \ unsigned res = impl(array, n); \ ASSERT_EQ(index, res); \ ASSERT_EQ(value, a[res]); \ }) TEST(windex, testRealWorldPicks) { const short kPicks[96] forcealign(32) = { 103, 85, 145, 146, 121, 103, 145, 187, 146, 189, 121, 103, 139, 121, 63, 105, 105, 147, 60, 103, 103, 146, 121, 103, 139, 121, 139, 121, 157, 139, 199, 200, 163, 223, 164, 225, 81, 141, 105, 165, 78, 139, 103, 164, 61, 103, 103, 145, 79, 139, 103, 163, 21, 63, 21, 81, 63, 45, 105, 106, 106, 107, 102, 103, 103, 104, 64, 107, 107, 150, 82, 143, 107, 168, 108, 109, 109, 110, 21, 64, 21, 82, 105, 106, 64, 46, 106, 107, 0x7fff, 0x7fff, 0x7fff, 0x7fff, 0x7fff, 0x7fff, 0x7fff, 0x7fff, }; /* multiple valid answers are fine if it's deterministic */ TestIt(windex_k8, 52, 21, ARRAYLEN(kPicks), kPicks); if (X86_HAVE(AVX2)) TestIt(windex_avx2, 78, 21, ARRAYLEN(kPicks), kPicks); if (X86_HAVE(SSE4_2)) TestIt(windex_sse4, 80, 21, ARRAYLEN(kPicks), kPicks); } TEST(windex, test) { TestIt(windex, 13, 32, ARRAYLEN(kW), kW); TestIt(windex, 1, 1, ARRAYLEN(kW2), kW2); TestIt(windex, 62, 7, ARRAYLEN(kW3), kW3); } TEST(windex_avx2, test) { if (X86_HAVE(AVX2)) { TestIt(windex_avx2, 13, 32, ARRAYLEN(kW), kW); TestIt(windex_avx2, 1, 1, ARRAYLEN(kW2), kW2); TestIt(windex_avx2, 62, 7, ARRAYLEN(kW3), kW3); } } TEST(windex_sse4, test) { if (X86_HAVE(SSE4_2)) { TestIt(windex_sse4, 13, 32, ARRAYLEN(kW), kW); TestIt(windex_sse4, 1, 1, ARRAYLEN(kW2), kW2); TestIt(windex_sse4, 62, 7, ARRAYLEN(kW3), kW3); } } TEST(windex_k8, test) { TestIt(windex_k8, 13, 32, ARRAYLEN(kW), kW); TestIt(windex_k8, 1, 1, ARRAYLEN(kW2), kW2); TestIt(windex_k8, 62, 7, ARRAYLEN(kW3), kW3); } //////////////////////////////////////////////////////////////////////////////// BENCH(windex, bench) { EZBENCH(donothing, windex(kW, ARRAYLEN(kW))); } BENCH(windex_k8, bench) { EZBENCH(donothing, windex_k8(kW, ARRAYLEN(kW))); } BENCH(windex_avx2, bench) { if (X86_HAVE(AVX2)) { EZBENCH(donothing, windex_avx2(kW, ARRAYLEN(kW))); } } BENCH(windex_sse4, bench) { if (X86_HAVE(SSE4_2)) { EZBENCH(donothing, windex_sse4(kW, ARRAYLEN(kW))); } }
6,197
132
jart/cosmopolitan
false
cosmopolitan/test/dsp/tty/rgb2ansi_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/quant.h" #include "libc/testlib/testlib.h" struct TtyRgb res; TEST(rgb2ansi, testDesaturatedPurple_isQuantizedBetterThanEuclideanDistance) { ttyquantsetup(kTtyQuantXterm256, kTtyQuantRgb, kTtyBlocksUnicode); /* * the challenge to the xterm256 palette is that it was likely * intended for just syntax highlighting, rather than accurately * modeling the natural phenomenon of illumination. * * as a syntax highlighting palette, it focuses mostly on bright * saturated colors, while also providing a really good greyscale for * everything else. * * as such, if one were to project the colors of this palette into a * three-dimensional space, we might see something like an HSV cone, * where all the color samples are projected mostly around the outside * of the cone, and the greyscale dots tracing through the middle. * * if we want to convert an a real color into an xterm color, we can * use euclidean distance functions to pick the closest color, such as * sum of squared distance. however this will only work well if it's * either a pure grey color, or a bright saturated one. * * but euclidean distance doesnt work well for the sorts of colors * that are generally used for things like film, which conservatively * edits for the colors more towards the middle of the space; and as * such, which basically causes the distance function to pick greys * for almost everything. */ res = rgb2tty(0x56, 0x38, 0x66); /* EXPECT_NE(0x4e, res.r); */ /* EXPECT_NE(0x4e, res.g); */ /* EXPECT_NE(0x4e, res.b); */ /* EXPECT_NE(239, res.xt); */ /* EXPECT_EQ(0x5f, res.r); */ /* EXPECT_EQ(0x00, res.g); */ /* EXPECT_EQ(0x5f, res.b); */ /* EXPECT_EQ(53, res.xt); */ }
3,607
65
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/mulaw_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/core/ituround.h" #include "libc/assert.h" #include "libc/macros.internal.h" #include "libc/math.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" TEST(mulaw, outOfRange) { EXPECT_EQ(0, mulaw(-32769)); EXPECT_EQ(128, mulaw(32768)); EXPECT_EQ(0, mulaw(-131072)); EXPECT_EQ(128, mulaw(131072)); } TEST(unmulaw, outOfRange_modulo256) { EXPECT_EQ(8, unmulaw(-2)); EXPECT_EQ(8, unmulaw(-2 & 255)); EXPECT_EQ(31100, unmulaw(-127)); EXPECT_EQ(31100, unmulaw(-127 & 255)); } TEST(mulaw, regressiontest) { int i; static const int V[][2] = { {13, -18474}, {143, 17241}, {131, 28876}, {10, -21786}, {146, 15194}, {16, -16141}, {137, 23194}, {10, -22282}, {157, 9513}, {128, 31674}, {143, 16891}, {13, -19214}, {15, -17028}, {172, 4896}, {11, -21318}, {131, 28684}, {149, 13594}, {197, 1567}, {132, 27860}, {135, 25141}, {147, 14699}, {144, 15757}, {140, 19422}, {29, -9374}, {4, -28099}, {137, 22448}, {176, 3876}, {7, -24928}, {157, 9553}, {167, 6048}, {133, 26527}, {9, -23278}, {29, -9188}, {24, -12091}, {136, 23694}, {169, 5722}, {17, -15670}, {149, 13674}, {135, 24796}, {156, 10013}, {201, 1279}, {144, 15844}, {21, -13686}, {8, -24136}, {161, 7629}, {18, -15082}, {29, -9484}, {11, -20731}, {131, 28975}, {158, 8866}, {134, 25514}, {36, -6936}, {29, -9348}, {167, 6082}, {25, -11235}, {139, 20776}, {45, -4650}, {236, 179}, {141, 18807}, {10, -21498}, {9, -22455}, {141, 19222}, {1, -31252}, {7, -25035}, {87, -665}, {134, 25759}, {30, -9037}, {13, -18312}, {13, -18782}, {139, 21031}, {187, 2466}, {141, 19229}, {131, 29425}, {7, -25428}, {10, -22393}, {203, 1156}, {13, -19223}, {155, 10566}, {133, 27311}, {45, -4603}, {134, 25985}, {161, 7595}, {1, -31305}, {130, 30274}, {133, 27410}, {24, -11919}, {130, 29752}, {40, -5901}, {9, -22472}, {145, 15486}, {62, -2154}, {172, 4888}, {140, 19967}, {142, 17750}, {7, -25279}, {56, -2846}, {10, -21643}, {2, -30140}, {201, 1307}, {0, -32480}, }; for (i = 0; i < ARRAYLEN(V); ++i) { EXPECT_EQ(V[i][0], mulaw(V[i][1])); } } TEST(unmulaw, test) { int i; static const int V[][2] = { {-32124, 0}, {-31100, 1}, {-30076, 2}, {-29052, 3}, {-28028, 4}, {-27004, 5}, {-25980, 6}, {-24956, 7}, {-23932, 8}, {-22908, 9}, {-21884, 10}, {-20860, 11}, {-19836, 12}, {-18812, 13}, {-17788, 14}, {-16764, 15}, {-15996, 16}, {-15484, 17}, {-14972, 18}, {-14460, 19}, {-13948, 20}, {-13436, 21}, {-12924, 22}, {-12412, 23}, {-11900, 24}, {-11388, 25}, {-10876, 26}, {-10364, 27}, {-9852, 28}, {-9340, 29}, {-8828, 30}, {-8316, 31}, {-7932, 32}, {-7676, 33}, {-7420, 34}, {-7164, 35}, {-6908, 36}, {-6652, 37}, {-6396, 38}, {-6140, 39}, {-5884, 40}, {-5628, 41}, {-5372, 42}, {-5116, 43}, {-4860, 44}, {-4604, 45}, {-4348, 46}, {-4092, 47}, {-3900, 48}, {-3772, 49}, {-3644, 50}, {-3516, 51}, {-3388, 52}, {-3260, 53}, {-3132, 54}, {-3004, 55}, {-2876, 56}, {-2748, 57}, {-2620, 58}, {-2492, 59}, {-2364, 60}, {-2236, 61}, {-2108, 62}, {-1980, 63}, {-1884, 64}, {-1820, 65}, {-1756, 66}, {-1692, 67}, {-1628, 68}, {-1564, 69}, {-1500, 70}, {-1436, 71}, {-1372, 72}, {-1308, 73}, {-1244, 74}, {-1180, 75}, {-1116, 76}, {-1052, 77}, {-988, 78}, {-924, 79}, {-876, 80}, {-844, 81}, {-812, 82}, {-780, 83}, {-748, 84}, {-716, 85}, {-684, 86}, {-652, 87}, {-620, 88}, {-588, 89}, {-556, 90}, {-524, 91}, {-492, 92}, {-460, 93}, {-428, 94}, {-396, 95}, {-372, 96}, {-356, 97}, {-340, 98}, {-324, 99}, {-308, 100}, {-292, 101}, {-276, 102}, {-260, 103}, {-244, 104}, {-228, 105}, {-212, 106}, {-196, 107}, {-180, 108}, {-164, 109}, {-148, 110}, {-132, 111}, {-120, 112}, {-112, 113}, {-104, 114}, {-96, 115}, {-88, 116}, {-80, 117}, {-72, 118}, {-64, 119}, {-56, 120}, {-48, 121}, {-40, 122}, {-32, 123}, {-24, 124}, {-16, 125}, {-8, 126}, {0, 127}, {32124, 128}, {31100, 129}, {30076, 130}, {29052, 131}, {28028, 132}, {27004, 133}, {25980, 134}, {24956, 135}, {23932, 136}, {22908, 137}, {21884, 138}, {20860, 139}, {19836, 140}, {18812, 141}, {17788, 142}, {16764, 143}, {15996, 144}, {15484, 145}, {14972, 146}, {14460, 147}, {13948, 148}, {13436, 149}, {12924, 150}, {12412, 151}, {11900, 152}, {11388, 153}, {10876, 154}, {10364, 155}, {9852, 156}, {9340, 157}, {8828, 158}, {8316, 159}, {7932, 160}, {7676, 161}, {7420, 162}, {7164, 163}, {6908, 164}, {6652, 165}, {6396, 166}, {6140, 167}, {5884, 168}, {5628, 169}, {5372, 170}, {5116, 171}, {4860, 172}, {4604, 173}, {4348, 174}, {4092, 175}, {3900, 176}, {3772, 177}, {3644, 178}, {3516, 179}, {3388, 180}, {3260, 181}, {3132, 182}, {3004, 183}, {2876, 184}, {2748, 185}, {2620, 186}, {2492, 187}, {2364, 188}, {2236, 189}, {2108, 190}, {1980, 191}, {1884, 192}, {1820, 193}, {1756, 194}, {1692, 195}, {1628, 196}, {1564, 197}, {1500, 198}, {1436, 199}, {1372, 200}, {1308, 201}, {1244, 202}, {1180, 203}, {1116, 204}, {1052, 205}, {988, 206}, {924, 207}, {876, 208}, {844, 209}, {812, 210}, {780, 211}, {748, 212}, {716, 213}, {684, 214}, {652, 215}, {620, 216}, {588, 217}, {556, 218}, {524, 219}, {492, 220}, {460, 221}, {428, 222}, {396, 223}, {372, 224}, {356, 225}, {340, 226}, {324, 227}, {308, 228}, {292, 229}, {276, 230}, {260, 231}, {244, 232}, {228, 233}, {212, 234}, {196, 235}, {180, 236}, {164, 237}, {148, 238}, {132, 239}, {120, 240}, {112, 241}, {104, 242}, {96, 243}, {88, 244}, {80, 245}, {72, 246}, {64, 247}, {56, 248}, {48, 249}, {40, 250}, {32, 251}, {24, 252}, {16, 253}, {8, 254}, {0, 255}, }; for (i = 0; i < ARRAYLEN(V); ++i) { EXPECT_EQ(V[i][0], unmulaw(V[i][1])); } } BENCH(mulaw, bench) { EZBENCH2("mulaw -32k", donothing, mulaw(-32768)); EZBENCH2("mulaw 32k", donothing, mulaw(32767)); EZBENCH2("unmulaw 0", donothing, unmulaw(0)); EZBENCH2("unmulaw 255", donothing, unmulaw(255)); }
8,320
139
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/scalevolume_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/mpeg/mpeg.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/runtime/buffer.internal.h" #include "libc/stdio/rand.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" short pcm[8][8]; TEST(scalevolume, testIncreaseVolumeByOneIncrement) { pcm[0][0] = INT16_MIN; pcm[0][1] = INT16_MIN / 2; pcm[0][2] = -2; pcm[0][3] = -1; pcm[0][4] = 0; pcm[0][5] = 1; pcm[0][6] = 2; pcm[0][7] = INT16_MAX / 2; pcm[1][0] = INT16_MAX; scalevolume(ARRAYLEN(pcm), pcm, 1); EXPECT_EQ(INT16_MIN, pcm[0][0]); EXPECT_EQ(INT16_MIN, pcm[0][1]); EXPECT_EQ(-4, pcm[0][2]); EXPECT_EQ(-2, pcm[0][3]); EXPECT_EQ(0, pcm[0][4]); EXPECT_EQ(2, pcm[0][5]); EXPECT_EQ(4, pcm[0][6]); EXPECT_EQ(INT16_MAX - 1, pcm[0][7]); EXPECT_EQ(INT16_MAX, pcm[1][0]); } TEST(scalevolume, testDecreaseVolumeByOneIncrement) { pcm[0][0] = INT16_MIN; pcm[0][1] = INT16_MIN / 2; pcm[0][2] = -2; pcm[0][3] = -1; pcm[0][4] = 0; pcm[0][5] = 1; pcm[0][6] = 2; pcm[0][7] = INT16_MAX / 2; pcm[1][0] = INT16_MAX; scalevolume(ARRAYLEN(pcm), pcm, -1); EXPECT_EQ(INT16_MIN / 2, pcm[0][0]); EXPECT_EQ(INT16_MIN / 4, pcm[0][1]); EXPECT_EQ(-1, pcm[0][2]); EXPECT_EQ(-1, pcm[0][3]); EXPECT_EQ(0, pcm[0][4]); EXPECT_EQ(0, pcm[0][5]); EXPECT_EQ(1, pcm[0][6]); EXPECT_EQ(INT16_MAX / 4, pcm[0][7]); EXPECT_EQ(INT16_MAX / 2, pcm[1][0]); } TEST(scalevolume, testScaleByZero_doesNothing) { pcm[0][0] = INT16_MIN; pcm[0][1] = INT16_MIN / 2; pcm[0][2] = -2; pcm[0][3] = -1; pcm[0][4] = 0; pcm[0][5] = 1; pcm[0][6] = 2; pcm[0][7] = INT16_MAX / 2; pcm[1][0] = INT16_MAX; scalevolume(ARRAYLEN(pcm), pcm, 0); EXPECT_EQ(INT16_MIN, pcm[0][0]); EXPECT_EQ(INT16_MIN / 2, pcm[0][1]); EXPECT_EQ(-2, pcm[0][2]); EXPECT_EQ(-1, pcm[0][3]); EXPECT_EQ(0, pcm[0][4]); EXPECT_EQ(1, pcm[0][5]); EXPECT_EQ(2, pcm[0][6]); EXPECT_EQ(INT16_MAX / 2, pcm[0][7]); EXPECT_EQ(INT16_MAX, pcm[1][0]); } TEST(scalevolume, testBiggestScale_justSaturates) { pcm[0][0] = INT16_MIN; pcm[0][1] = INT16_MIN / 2; pcm[0][2] = -2; pcm[0][3] = -1; pcm[0][4] = 0; pcm[0][5] = 1; pcm[0][6] = 2; pcm[0][7] = INT16_MAX / 2; pcm[1][0] = INT16_MAX; scalevolume(ARRAYLEN(pcm), pcm, 123); EXPECT_EQ(INT16_MIN, pcm[0][0]); EXPECT_EQ(INT16_MIN, pcm[0][1]); EXPECT_EQ(INT16_MIN, pcm[0][2]); EXPECT_EQ(INT16_MIN, pcm[0][3]); EXPECT_EQ(0, pcm[0][4]); EXPECT_EQ(INT16_MAX, pcm[0][5]); EXPECT_EQ(INT16_MAX, pcm[0][6]); EXPECT_EQ(INT16_MAX, pcm[0][7]); EXPECT_EQ(INT16_MAX, pcm[1][0]); } TEST(scalevolume, testSmallestScale_justSaturates) { pcm[0][0] = INT16_MIN; pcm[0][1] = INT16_MIN / 2; pcm[0][2] = -2; pcm[0][3] = -1; pcm[0][4] = 0; pcm[0][5] = 1; pcm[0][6] = 2; pcm[0][7] = INT16_MAX / 2; pcm[1][0] = INT16_MAX; scalevolume(ARRAYLEN(pcm), pcm, -123); EXPECT_EQ(-1, pcm[0][0]); EXPECT_EQ(-1, pcm[0][1]); EXPECT_EQ(-1, pcm[0][2]); EXPECT_EQ(-1, pcm[0][3]); EXPECT_EQ(0, pcm[0][4]); EXPECT_EQ(0, pcm[0][5]); EXPECT_EQ(0, pcm[0][6]); EXPECT_EQ(0, pcm[0][7]); EXPECT_EQ(0, pcm[1][0]); } ////////////////////////////////////////////////////////////////////// // audio volume adjustment latency: // - ~1µs w/ -Os // - ~500ns w/ -O3 // - ~200ns w/ -O3 -march=skylake MODE=rel void randomizeaudio(void) { rngset(pcm, sizeof(pcm), _rand64, -1); } void scalevolume_pure(int amt) { scalevolume(ARRAYLEN(pcm), pcm, amt); } BENCH(scalevolume, audioframe) { EZBENCH(randomizeaudio(), scalevolume_pure(0)); EZBENCH(randomizeaudio(), scalevolume_pure(1)); EZBENCH(randomizeaudio(), scalevolume_pure(15)); }
5,565
161
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/gamma_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "libc/math.h" #include "libc/testlib/testlib.h" TEST(gamma, test) { int i; double g, x, a, b; g = 2.4; for (i = 0; i < 256; ++i) { x = i; x /= 255; a = rgb2stdpc(x, g); b = tv2pcgamma(rgb2stdtv(x), g); ASSERT_EQ(true, fabs(a - b) < .000000001, "%d %f %f %f", i, x, a, b); } }
2,179
35
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/getintegercoefficients_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/core/q.h" #include "libc/dce.h" #include "libc/macros.internal.h" #include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" long I[6]; TEST(GetIntegerCoefficients, testBt601Vectors) { const struct { int m, L, H; double r[6]; long n[6]; } V[] = { {8, 16, 235, {.299, .587, .114}, {77, 150, 29}}, {9, 16, 235, {.299, .587, .114}, {153, 301, 58}}, {10, 16, 235, {.299, .587, .114}, {306, 601, 117}}, {11, 16, 235, {.299, .587, .114, 1, 1, 1}, {612, 1202, NoDebug() ? 233 : 234, 2048, 2048, 2048}}, {12, 16, 235, {.299, .587, .114}, {1225, 2404, 467}}, {13, 16, 235, {.299, .587, .114}, {2449, 4809, 934}}, {14, 16, 235, {.299, .587, .114}, {4899, 9617, 1868}}, {15, 16, 235, {.299, .587, .114}, {9798, 19235, NoDebug() ? 3736 : 3735}}, {16, 16, 235, {.299, .587, .114}, {19595, 38470, 7471}}, }; long i, got[6]; for (i = 0; i < ARRAYLEN(V); ++i) { GetIntegerCoefficients(got, V[i].r, V[i].m, V[i].L, V[i].H); EXPECT_EQ(0, memcmp(V[i].n, got, sizeof(got)), "got={%ld,%ld,%ld,%ld,%ld,%ld}, want={%ld,%ld,%ld,%ld,%ld,%ld}", got[0], got[1], got[2], got[3], got[4], got[5], V[i].n[0], V[i].n[1], V[i].n[2], V[i].n[3], V[i].n[4], V[i].n[5]); } } TEST(GetIntegerCoefficients, testForYCbCr2Rgb) { double C[6] = {.299, .587, .114}; GetIntegerCoefficients(I, C, 11, 16, 232); EXPECT_EQ(612, I[0]); EXPECT_EQ(1202, I[1]); EXPECT_EQ(NoDebug() ? 233 : 234, I[2]); } TEST(GetIntegerCoefficients, testForGaussian) { #define G(A, B, C, D, E) lrint((A + 4 * B + 6 * C + 4 * D + E) / 16.) double C[6] = {1 / 16., 4 / 16., 6 / 16., 4 / 16., 1 / 16.}; long M = 22, N[6], B[6] = {12, 191, 174, 205, 35}; GetIntegerCoefficients(N, C, M, 0, 255); EXPECT_EQ(262144, N[0]); EXPECT_EQ(1048576, N[1]); EXPECT_EQ(1572864, N[2]); EXPECT_EQ(1048576, N[3]); EXPECT_EQ(262144, N[4]); EXPECT_EQ(G(B[0], B[1], B[2], B[3], B[4]), (N[0] * B[0] + N[1] * B[1] + N[2] * B[2] + N[3] * B[3] + N[4] * B[4] + N[5] * B[5] + (1l << (M - 1))) >> M); } BENCH(GetIntegerCoefficients, bench) { double C[6] = {.299, .587, .114}; EZBENCH2("getintegercoefficients", donothing, GetIntegerCoefficients(I, C, 11, 16, 232)); }
4,282
90
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/alaw_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/mem/gc.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" TEST(unalaw, outOfRange_modulo256) { EXPECT_EQ(880, unalaw(-2)); EXPECT_EQ(880, unalaw(-2 & 255)); EXPECT_EQ(5248, unalaw(-127)); EXPECT_EQ(5248, unalaw(-127 & 255)); } TEST(alaw, test) { int i; static const int V[][2] = { {42, -32768}, {42, -32691}, {42, -32376}, {42, -32328}, {42, -32235}, {42, -31923}, {43, -31645}, {43, -31328}, {43, -31147}, {43, -31129}, {43, -31110}, {43, -31092}, {43, -30824}, {43, -30728}, {40, -30473}, {40, -30297}, {40, -30074}, {40, -30013}, {40, -29972}, {40, -29830}, {40, -29707}, {41, -29595}, {41, -29384}, {41, -29235}, {41, -28959}, {41, -28947}, {41, -28816}, {41, -28708}, {46, -28580}, {46, -28538}, {46, -28483}, {46, -28256}, {46, -27976}, {46, -27829}, {47, -27644}, {47, -27471}, {47, -27189}, {47, -27042}, {47, -26999}, {47, -26707}, {44, -26610}, {44, -26464}, {44, -26145}, {44, -25897}, {44, -25722}, {44, -25638}, {45, -25556}, {45, -25310}, {45, -25310}, {45, -25083}, {45, -24986}, {45, -24920}, {45, -24676}, {45, -24650}, {34, -24565}, {34, -24531}, {34, -24349}, {34, -24203}, {34, -24073}, {34, -23997}, {34, -23804}, {34, -23714}, {34, -23654}, {35, -23435}, {35, -23370}, {35, -23060}, {35, -22908}, {35, -22784}, {32, -22493}, {32, -22409}, {32, -22342}, {32, -22018}, {32, -21952}, {32, -21866}, {32, -21699}, {33, -21436}, {33, -21161}, {33, -21041}, {33, -20744}, {33, -20711}, {38, -20430}, {38, -20300}, {38, -20162}, {38, -19939}, {38, -19820}, {38, -19765}, {38, -19576}, {39, -19427}, {39, -19268}, {39, -19098}, {39, -19049}, {39, -18888}, {39, -18845}, {39, -18803}, {39, -18528}, {36, -18424}, {36, -18119}, {36, -17808}, {36, -17685}, {36, -17589}, {36, -17481}, {37, -17397}, {37, -17190}, {37, -17119}, {37, -16916}, {37, -16910}, {37, -16747}, {37, -16706}, {37, -16682}, {37, -16406}, {58, -16311}, {58, -16292}, {58, -16187}, {58, -16103}, {59, -15864}, {59, -15753}, {59, -15520}, {59, -15373}, {56, -15289}, {56, -15020}, {57, -14748}, {57, -14604}, {57, -14538}, {62, -14315}, {62, -14236}, {62, -14046}, {62, -14043}, {62, -13985}, {63, -13664}, {63, -13453}, {60, -13143}, {60, -13099}, {60, -13044}, {60, -12802}, {61, -12538}, {61, -12476}, {61, -12411}, {61, -12340}, {50, -12073}, {51, -11760}, {51, -11442}, {48, -11133}, {48, -11102}, {48, -10928}, {48, -10791}, {49, -10697}, {49, -10534}, {49, -10331}, {49, -10257}, {54, -9991}, {54, -9732}, {55, -9714}, {55, -9544}, {55, -9389}, {55, -9385}, {55, -9245}, {52, -9102}, {52, -8838}, {53, -8534}, {53, -8405}, {53, -8321}, {53, -8232}, {10, -8101}, {11, -7879}, {8, -7650}, {8, -7630}, {8, -7616}, {8, -7559}, {8, -7442}, {9, -7305}, {9, -7267}, {14, -7141}, {14, -6962}, {15, -6838}, {15, -6734}, {12, -6502}, {12, -6479}, {13, -6162}, {2, -6142}, {2, -5933}, {3, -5648}, {0, -5523}, {1, -5291}, {1, -5149}, {6, -4868}, {7, -4807}, {7, -4677}, {4, -4556}, {4, -4484}, {4, -4353}, {5, -4149}, {26, -4048}, {27, -3935}, {24, -3720}, {31, -3447}, {31, -3392}, {28, -3313}, {29, -3106}, {19, -2891}, {19, -2838}, {16, -2745}, {17, -2663}, {22, -2481}, {20, -2184}, {21, -2084}, {105, -1847}, {105, -1808}, {98, -1520}, {99, -1471}, {103, -1168}, {126, -876}, {112, -673}, {119, -578}, {68, -287}, {88, -220}, {81, -76}, {85, -13}, {213, 13}, {218, 253}, {197, 256}, {245, 540}, {246, 634}, {248, 931}, {229, 1063}, {229, 1066}, {225, 1305}, {227, 1451}, {239, 1715}, {239, 1725}, {235, 1982}, {149, 2122}, {148, 2205}, {148, 2219}, {150, 2539}, {145, 2679}, {144, 2752}, {146, 3025}, {156, 3239}, {156, 3239}, {159, 3346}, {153, 3633}, {153, 3649}, {153, 3704}, {152, 3799}, {152, 3799}, {154, 4089}, {132, 4369}, {132, 4606}, {135, 4712}, {134, 5031}, {129, 5183}, {129, 5211}, {128, 5396}, {128, 5535}, {131, 5761}, {131, 5821}, {131, 5878}, {130, 5970}, {141, 6156}, {141, 6206}, {141, 6307}, {140, 6607}, {143, 6661}, {142, 6915}, {142, 7126}, {137, 7296}, {137, 7391}, {139, 7684}, {139, 7707}, {139, 7736}, {139, 7820}, {138, 7982}, {181, 8300}, {181, 8335}, {181, 8582}, {181, 8655}, {180, 8850}, {180, 8961}, {180, 9008}, {183, 9301}, {183, 9597}, {183, 9605}, {183, 9697}, {182, 9921}, {182, 10143}, {182, 10223}, {177, 10477}, {177, 10749}, {176, 10951}, {176, 11121}, {179, 11321}, {179, 11620}, {179, 11645}, {179, 11708}, {179, 11716}, {179, 11763}, {178, 11949}, {178, 12271}, {178, 12287}, {189, 12514}, {189, 12561}, {189, 12575}, {188, 12844}, {188, 13162}, {191, 13337}, {191, 13631}, {190, 13957}, {190, 14175}, {190, 14270}, {185, 14411}, {185, 14720}, {184, 14975}, {184, 15047}, {184, 15135}, {184, 15246}, {187, 15477}, {187, 15491}, {187, 15581}, {187, 15646}, {187, 15785}, {186, 15983}, {186, 15993}, {186, 16169}, {186, 16178}, {186, 16355}, {165, 16536}, {165, 16850}, {165, 17132}, {165, 17366}, {164, 17593}, {164, 17667}, {164, 17679}, {164, 17765}, {164, 17771}, {164, 17807}, {164, 17843}, {164, 18079}, {164, 18325}, {167, 18625}, {167, 18931}, {167, 19160}, {167, 19381}, {166, 19677}, {166, 19805}, {166, 19972}, {166, 20140}, {166, 20404}, {161, 20515}, {161, 20767}, {161, 21071}, {161, 21339}, {161, 21369}, {161, 21411}, {160, 21685}, {160, 21701}, {160, 21963}, {160, 22109}, {160, 22187}, {160, 22197}, {160, 22378}, {163, 22670}, {163, 22990}, {163, 23063}, {163, 23156}, {163, 23158}, {163, 23459}, {163, 23471}, {162, 23792}, {162, 23955}, {162, 24163}, {162, 24300}, {173, 24589}, {173, 24722}, {173, 24865}, {173, 25135}, {173, 25225}, {173, 25341}, {173, 25480}, {172, 25653}, {172, 25779}, {172, 26018}, {172, 26257}, {172, 26576}, {175, 26894}, {175, 27191}, {175, 27294}, {175, 27468}, {175, 27498}, {175, 27575}, {175, 27644}, {174, 27723}, {174, 27764}, {174, 27954}, {174, 27969}, {174, 27979}, {174, 28059}, {174, 28124}, {174, 28330}, {174, 28408}, {174, 28627}, {169, 28704}, {169, 28880}, {169, 29014}, {169, 29095}, {169, 29301}, {169, 29429}, {169, 29515}, {169, 29520}, {169, 29661}, {168, 29812}, {168, 30030}, {168, 30157}, {168, 30405}, {168, 30476}, {171, 30760}, {171, 30883}, {171, 31029}, {171, 31249}, {171, 31482}, {171, 31578}, {171, 31696}, {170, 31902}, {170, 32116}, {170, 32440}, {170, 32472}, {170, 32711}, }; for (i = 0; i < ARRAYLEN(V); ++i) { ASSERT_EQ(V[i][0], alaw(V[i][1])); } } TEST(unalaw, test) { int i; static const int V[][2] = { {-5504, 0}, {-5248, 1}, {-6016, 2}, {-5760, 3}, {-4480, 4}, {-4224, 5}, {-4992, 6}, {-4736, 7}, {-7552, 8}, {-7296, 9}, {-8064, 10}, {-7808, 11}, {-6528, 12}, {-6272, 13}, {-7040, 14}, {-6784, 15}, {-2752, 16}, {-2624, 17}, {-3008, 18}, {-2880, 19}, {-2240, 20}, {-2112, 21}, {-2496, 22}, {-2368, 23}, {-3776, 24}, {-3648, 25}, {-4032, 26}, {-3904, 27}, {-3264, 28}, {-3136, 29}, {-3520, 30}, {-3392, 31}, {-22016, 32}, {-20992, 33}, {-24064, 34}, {-23040, 35}, {-17920, 36}, {-16896, 37}, {-19968, 38}, {-18944, 39}, {-30208, 40}, {-29184, 41}, {-32256, 42}, {-31232, 43}, {-26112, 44}, {-25088, 45}, {-28160, 46}, {-27136, 47}, {-11008, 48}, {-10496, 49}, {-12032, 50}, {-11520, 51}, {-8960, 52}, {-8448, 53}, {-9984, 54}, {-9472, 55}, {-15104, 56}, {-14592, 57}, {-16128, 58}, {-15616, 59}, {-13056, 60}, {-12544, 61}, {-14080, 62}, {-13568, 63}, {-344, 64}, {-328, 65}, {-376, 66}, {-360, 67}, {-280, 68}, {-264, 69}, {-312, 70}, {-296, 71}, {-472, 72}, {-456, 73}, {-504, 74}, {-488, 75}, {-408, 76}, {-392, 77}, {-440, 78}, {-424, 79}, {-88, 80}, {-72, 81}, {-120, 82}, {-104, 83}, {-24, 84}, {-8, 85}, {-56, 86}, {-40, 87}, {-216, 88}, {-200, 89}, {-248, 90}, {-232, 91}, {-152, 92}, {-136, 93}, {-184, 94}, {-168, 95}, {-1376, 96}, {-1312, 97}, {-1504, 98}, {-1440, 99}, {-1120, 100}, {-1056, 101}, {-1248, 102}, {-1184, 103}, {-1888, 104}, {-1824, 105}, {-2016, 106}, {-1952, 107}, {-1632, 108}, {-1568, 109}, {-1760, 110}, {-1696, 111}, {-688, 112}, {-656, 113}, {-752, 114}, {-720, 115}, {-560, 116}, {-528, 117}, {-624, 118}, {-592, 119}, {-944, 120}, {-912, 121}, {-1008, 122}, {-976, 123}, {-816, 124}, {-784, 125}, {-880, 126}, {-848, 127}, {5504, 128}, {5248, 129}, {6016, 130}, {5760, 131}, {4480, 132}, {4224, 133}, {4992, 134}, {4736, 135}, {7552, 136}, {7296, 137}, {8064, 138}, {7808, 139}, {6528, 140}, {6272, 141}, {7040, 142}, {6784, 143}, {2752, 144}, {2624, 145}, {3008, 146}, {2880, 147}, {2240, 148}, {2112, 149}, {2496, 150}, {2368, 151}, {3776, 152}, {3648, 153}, {4032, 154}, {3904, 155}, {3264, 156}, {3136, 157}, {3520, 158}, {3392, 159}, {22016, 160}, {20992, 161}, {24064, 162}, {23040, 163}, {17920, 164}, {16896, 165}, {19968, 166}, {18944, 167}, {30208, 168}, {29184, 169}, {32256, 170}, {31232, 171}, {26112, 172}, {25088, 173}, {28160, 174}, {27136, 175}, {11008, 176}, {10496, 177}, {12032, 178}, {11520, 179}, {8960, 180}, {8448, 181}, {9984, 182}, {9472, 183}, {15104, 184}, {14592, 185}, {16128, 186}, {15616, 187}, {13056, 188}, {12544, 189}, {14080, 190}, {13568, 191}, {344, 192}, {328, 193}, {376, 194}, {360, 195}, {280, 196}, {264, 197}, {312, 198}, {296, 199}, {472, 200}, {456, 201}, {504, 202}, {488, 203}, {408, 204}, {392, 205}, {440, 206}, {424, 207}, {88, 208}, {72, 209}, {120, 210}, {104, 211}, {24, 212}, {8, 213}, {56, 214}, {40, 215}, {216, 216}, {200, 217}, {248, 218}, {232, 219}, {152, 220}, {136, 221}, {184, 222}, {168, 223}, {1376, 224}, {1312, 225}, {1504, 226}, {1440, 227}, {1120, 228}, {1056, 229}, {1248, 230}, {1184, 231}, {1888, 232}, {1824, 233}, {2016, 234}, {1952, 235}, {1632, 236}, {1568, 237}, {1760, 238}, {1696, 239}, {688, 240}, {656, 241}, {752, 242}, {720, 243}, {560, 244}, {528, 245}, {624, 246}, {592, 247}, {944, 248}, {912, 249}, {1008, 250}, {976, 251}, {816, 252}, {784, 253}, {880, 254}, {848, 255}, }; for (i = 0; i < ARRAYLEN(V); ++i) { ASSERT_EQ(V[i][0], unalaw(V[i][1])); } } BENCH(alaw, bench) { char *p = gc(malloc(kHyperionSize)); EZBENCH2("alaw -32k", donothing, alaw(-32768)); EZBENCH2("alaw 32k", donothing, alaw(32767)); EZBENCH2("unalaw 0", donothing, unalaw(0)); EZBENCH2("unalaw 255", donothing, unalaw(255)); }
13,075
197
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/illumination_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/core/illumination.h" #include "libc/log/log.h" #include "libc/math.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "tool/viz/lib/formatstringtable-testlib.h" TEST(GetChromaticAdaptationMatrix, testSuperiorIlluminationBannedInCalifornia) { double M[3][3]; GetChromaticAdaptationMatrix(M, kIlluminantD65, kIlluminantA); EXPECT_DBLMATRIXEQ(5, rint, 3, 3, M, "\n\ 1.2165 .11099 -.15493\n\ .15333 .91523 -.055995\n\ -.023947 .035898 .31475"); } TEST(GetChromaticAdaptationMatrix, testD65ToD50_soWeCanCieLab) { double M[3][3]; GetChromaticAdaptationMatrix(M, kIlluminantD65, kIlluminantD50); EXPECT_DBLMATRIXEQ(6, rint, 3, 3, M, "\n\ 1.04781 .0228866 -.050127\n\ .0295424 .990484 -.0170491\n\ -.00923449 .0150436 .752132"); } BENCH(GetChromaticAdaptationMatrix, bench) { double M[3][3]; EZBENCH2("GetChromaticAdaptationMatrix", donothing, GetChromaticAdaptationMatrix(M, kIlluminantD65, kIlluminantA)); }
2,868
50
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/getintegercoefficients8_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/core/q.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" long I[8]; TEST(GetIntegerCoefficients8, testBt601Vectors) { const struct { int m, L, H; double r[8]; long n[8]; } V[] = { {8, 16, 235, {.299, .587, .114}, {77, 150, 29}}, {9, 16, 235, {.299, .587, .114}, {153, 301, 58}}, {10, 16, 235, {.299, .587, .114}, {306, 601, 117}}, {11, 16, 235, {.299, .587, .114, 1, 1, 1}, {612, 1202, 234, 2048, 2048, 2048}}, {12, 16, 235, {.299, .587, .114}, {1225, 2404, 467}}, {13, 16, 235, {.299, .587, .114}, {2449, 4809, 934}}, {14, 16, 235, {.299, .587, .114}, {4899, 9617, 1868}}, {15, 16, 235, {.299, .587, .114}, {9798, 19235, 3735}}, {16, 16, 235, {.299, .587, .114}, {19595, 38470, 7471}}, }; long i, got[8]; for (i = 0; i < ARRAYLEN(V); ++i) { GetIntegerCoefficients8(got, V[i].r, V[i].m, V[i].L, V[i].H); EXPECT_EQ(0, memcmp(V[i].n, got, sizeof(got)), "got={%ld,%ld,%ld,%ld,%ld,%ld}, want = { % ld, % ld, % ld, % ld, " "% ld, % ld } ", got[0], got[1], got[2], got[3], got[4], got[5], V[i].n[0], V[i].n[1], V[i].n[2], V[i].n[3], V[i].n[4], V[i].n[5]); } } BENCH(GetIntegerCoefficients8, bench) { double C[8] = {.299, .587, .114, .299, .587, .114, .114, .114}; EZBENCH2("GetIntegerCoefficients8", donothing, GetIntegerCoefficients8(I, C, 11, 16, 232)); }
3,394
64
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/inv3_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/core/illumination.h" #include "libc/math.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "tool/viz/lib/formatstringtable-testlib.h" TEST(inv3, test) { double M[3][3]; inv3(M, kBradford, det3(kBradford)); EXPECT_DBLMATRIXEQ(7, rint, 3, 3, M, "\n\ .9869929 -.1470543 .1599627\n\ .4323053 .5183603 .04929123\n\ -.008528665 .04004282 .9684867"); } BENCH(inv3, bench) { double M[3][3], d; EZBENCH2("det3", donothing, EXPROPRIATE((d = det3(kBradford)))); EZBENCH2("inv3", donothing, EXPROPRIATE(inv3(M, kBradford, d))); }
2,460
40
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/test.mk
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ #───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘ PKGS += TEST_DSP_CORE TEST_DSP_CORE_SRCS := $(wildcard test/dsp/core/*.c) TEST_DSP_CORE_SRCS_TEST = $(filter %_test.c,$(TEST_DSP_CORE_SRCS)) TEST_DSP_CORE_BINS = $(TEST_DSP_CORE_COMS) $(TEST_DSP_CORE_COMS:%=%.dbg) TEST_DSP_CORE_OBJS = \ $(TEST_DSP_CORE_SRCS:%.c=o/$(MODE)/%.o) TEST_DSP_CORE_COMS = \ $(TEST_DSP_CORE_SRCS:%.c=o/$(MODE)/%.com) TEST_DSP_CORE_TESTS = \ $(TEST_DSP_CORE_SRCS_TEST:%.c=o/$(MODE)/%.com.ok) TEST_DSP_CORE_CHECKS = \ $(TEST_DSP_CORE_SRCS_TEST:%.c=o/$(MODE)/%.com.runs) TEST_DSP_CORE_DIRECTDEPS = \ DSP_CORE \ DSP_MPEG \ LIBC_TINYMATH \ LIBC_LOG \ LIBC_RUNTIME \ LIBC_TESTLIB \ TOOL_VIZ_LIB \ THIRD_PARTY_BLAS \ THIRD_PARTY_COMPILER_RT TEST_DSP_CORE_DEPS := \ $(call uniq,$(foreach x,$(TEST_DSP_CORE_DIRECTDEPS),$($(x)))) o/$(MODE)/test/dsp/core/core.pkg: \ $(TEST_DSP_CORE_OBJS) \ $(foreach x,$(TEST_DSP_CORE_DIRECTDEPS),$($(x)_A).pkg) o/$(MODE)/test/dsp/core/%.com.dbg: \ $(TEST_DSP_CORE_DEPS) \ o/$(MODE)/test/dsp/core/%.o \ $(LIBC_TESTMAIN) \ $(CRT) \ $(APE_NO_MODIFY_SELF) @$(APELINK) .PHONY: o/$(MODE)/test/dsp/core o/$(MODE)/test/dsp/core: \ $(TEST_DSP_CORE_BINS) \ $(TEST_DSP_CORE_CHECKS)
1,461
52
jart/cosmopolitan
false
cosmopolitan/test/dsp/core/sad16x8n_test.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "dsp/mpeg/mpeg.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/nexgen32e/x86feature.h" #include "libc/runtime/buffer.internal.h" #include "libc/stdio/rand.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" void addsw_pure(size_t n, short x[n][8], const short y[n][8]) { size_t i, j; for (i = 0; i < n; ++i) { for (j = 0; j < 8; ++j) { x[i][j] = MIN(MAX(x[i][j] + y[i][j], INT16_MIN), INT16_MAX); } } } short *pcm1; short *pcm2; struct GuardedBuffer b1, b2; TEST(sad16x8n, test) { CHECK_NOTNULL((pcm1 = balloc(&b1, 32, 128 * 2))); CHECK_NOTNULL((pcm2 = balloc(&b2, 32, 128 * 2))); pcm1[0] = 0; pcm2[0] = 0; pcm1[1] = 23; pcm2[1] = 10; pcm1[2] = 23; pcm2[2] = -10; pcm1[3] = 23; pcm2[3] = -46; pcm1[120 + 0] = 0; pcm2[120 + 0] = 0; pcm1[120 + 1] = 23; pcm2[120 + 1] = 10; pcm1[120 + 2] = 23; pcm2[120 + 2] = -10; pcm1[120 + 3] = 23; pcm2[120 + 3] = -46; sad16x8n(128 / 8, (void *)pcm1, (void *)pcm2); EXPECT_EQ(0, pcm1[0]); EXPECT_EQ(33, pcm1[1]); EXPECT_EQ(13, pcm1[2]); EXPECT_EQ(-23, pcm1[3]); EXPECT_EQ(0, pcm1[120 + 0]); EXPECT_EQ(33, pcm1[120 + 1]); EXPECT_EQ(13, pcm1[120 + 2]); EXPECT_EQ(-23, pcm1[120 + 3]); bfree(&b1); bfree(&b2); } ////////////////////////////////////////////////////////////////////// // audio frame mixing latency: ~60ns (sse2 10x faster than pure) // // 1f ~= 14ms (cd quality) // (1.0 / 41000) * (1.0 / 2) * (1152 / 1.0) // // 1f ~= 845µs (dolby truehd) // (1.0 / 192000) * (1.0 / 7.1) * (1152 / 1.0) // // @note plm frame always has exactly 1152 floats void randomizeaudio(void) { size_t i; for (i = 0; i < PLM_AUDIO_SAMPLES_PER_FRAME; ++i) { pcm1[i] = (rand() - INT_MAX / 2) % INT16_MAX; pcm2[i] = (rand() - INT_MAX / 2) % INT16_MAX; } } void sad16x8n_sse2(void) { sad16x8n(PLM_AUDIO_SAMPLES_PER_FRAME / 8, (void *)pcm1, (void *)pcm2); } void sad16x8n_pure(void) { addsw_pure(PLM_AUDIO_SAMPLES_PER_FRAME / 8, (void *)pcm1, (void *)pcm2); } BENCH(sad16x8n, audioframe) { CHECK_NOTNULL((pcm1 = balloc(&b1, 32, PLM_AUDIO_SAMPLES_PER_FRAME * 2))); CHECK_NOTNULL((pcm2 = balloc(&b2, 32, PLM_AUDIO_SAMPLES_PER_FRAME * 2))); EZBENCH(randomizeaudio(), sad16x8n_pure()); EZBENCH(randomizeaudio(), sad16x8n_sse2()); bfree(&b1); bfree(&b2); }
4,203
108
jart/cosmopolitan
false