diff options
author | paulhsia <paulhsia@chromium.org> | 2020-08-07 01:06:30 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-10 08:17:24 +0000 |
commit | 3418709c9ee544524a130228a6c4bba41089dcc4 (patch) | |
tree | e7c98825410f1ba5a10ccc10e45fd7389059dc17 /cras/src/tests | |
parent | d9d433df224d2282a91dda8bd39450fae428f791 (diff) | |
download | adhd-3418709c9ee544524a130228a6c4bba41089dcc4.tar.gz |
fmt_conv_ops: Fix slow and corrupted default_all_to_all
1. While dividing `int32_t` by `size_t`, we should convert `size_t`
to `int32_t` explicitly to prevent corrupted results.
2. Swap divide and summation order to preserve sample accuracy.
3. Reduce time complexity from O(N * M * Frames) to O((N + M) * Frames)
4. Add unit test `6chTo8chS16LE` which goes trough all int16_t cases (
from INT16_MIN to INT16_MAX).
BUG=b:163052978
TEST=Unit tests
TEST=`speaker-test -c 6 -D hw:0,0 -f 440 -t sine=use` in Crostini and
check output results from 8-channel device.
Change-Id: I08d93c6f4a6c33d9ee69c1ecfc93b9a8be9b95d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2341187
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Diffstat (limited to 'cras/src/tests')
-rw-r--r-- | cras/src/tests/fmt_conv_ops_unittest.cc | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/cras/src/tests/fmt_conv_ops_unittest.cc b/cras/src/tests/fmt_conv_ops_unittest.cc index a76087f6..d8feeab3 100644 --- a/cras/src/tests/fmt_conv_ops_unittest.cc +++ b/cras/src/tests/fmt_conv_ops_unittest.cc @@ -619,10 +619,10 @@ TEST(FormatConverterOpsTest, StereoTo3chS16LE) { EXPECT_EQ(ret, frames); for (size_t i = 0; i < frames; ++i) { + int32_t sum = 0; for (size_t k = 0; k < in_ch; ++k) - src[i * in_ch + k] /= in_ch; - for (size_t k = 1; k < in_ch; ++k) - src[i * in_ch + 0] += src[i * in_ch + k]; + sum += (int32_t)src[i * in_ch + k]; + src[i * in_ch + 0] = (int16_t)(sum / (int32_t)in_ch); } for (size_t i = 0; i < frames; ++i) { for (size_t k = 0; k < out_ch; ++k) @@ -630,6 +630,36 @@ TEST(FormatConverterOpsTest, StereoTo3chS16LE) { } } +// Test 6ch to 8ch conversion. S16_LE. +TEST(FormatConverterOpsTest, 6chTo8chS16LE) { + const size_t frames = 65536; + const size_t in_ch = 6; + const size_t out_ch = 8; + struct cras_audio_format fmt = { + .format = SND_PCM_FORMAT_S16_LE, + .frame_rate = 48000, + .num_channels = 8, + }; + + S16LEPtr src = CreateS16LE(frames * in_ch); + S16LEPtr dst = CreateS16LE(frames * out_ch); + for (size_t i = 0; i < frames; ++i) { + for (size_t k = 0; k < in_ch; k++) { + src[i * in_ch + k] = (k == 0) ? (INT16_MIN + (int16_t)i) : 0; + } + } + + size_t ret = s16_default_all_to_all(&fmt, in_ch, out_ch, (uint8_t*)src.get(), + frames, (uint8_t*)dst.get()); + EXPECT_EQ(ret, frames); + + for (size_t i = 0; i < frames; ++i) { + src[i * in_ch + 0] /= (int16_t)in_ch; + for (size_t k = 0; k < out_ch; ++k) + EXPECT_EQ(src[i * in_ch + 0], dst[i * out_ch + k]); + } +} + // Test Multiply with Coef. S16_LE. TEST(FormatConverterOpsTest, MultiplyWithCoefS16LE) { const size_t buf_size = 4096; |