-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* format-tests: TESTS: add a few more checks to existing tests TESTS: run testrawconverter in make check Add test for RawConverter. TESTS: avoid snr output in quiet mode TESTS: check snr in wav pipe test to catch conversion errors TESTS: add test for wav-pipe format Add helpers to audiowmark for better tests. Signed-off-by: Stefan Westerfeld <[email protected]>
- Loading branch information
Showing
9 changed files
with
238 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (C) 2018-2024 Stefan Westerfeld | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <assert.h> | ||
#include <math.h> | ||
#include <gcrypt.h> | ||
|
||
#include <set> | ||
|
||
#include "rawconverter.hh" | ||
|
||
using std::vector; | ||
using std::string; | ||
|
||
string | ||
hash_bytes (vector<unsigned char>& bytes) | ||
{ | ||
string result; | ||
std::array<unsigned char, 20> hash; | ||
gcry_md_hash_buffer (GCRY_MD_SHA1, hash.data(), bytes.data(), bytes.size()); | ||
for (auto ch : hash) | ||
result += string_printf ("%02x", ch); | ||
return result; | ||
} | ||
|
||
int | ||
main (int argc, char **argv) | ||
{ | ||
std::set<string> hashes; | ||
Error error; | ||
RawFormat format; | ||
uint64_t K = 33452759; // prime | ||
vector<float> in_samples (K), out_samples (K); | ||
vector<unsigned char> bytes (K * 4); | ||
for (uint64_t k = 0; k <= K; k++) | ||
in_samples[k] = (-1 + double (2 * k) / K); | ||
for (auto bit_depth : { 16, 24, 32 }) | ||
{ | ||
for (auto encoding : { RawFormat::SIGNED, RawFormat::UNSIGNED }) | ||
{ | ||
for (auto endian : { RawFormat::LITTLE, RawFormat::BIG }) | ||
{ | ||
format.set_bit_depth (bit_depth); | ||
format.set_encoding (encoding); | ||
format.set_endian (endian); | ||
|
||
RawConverter *converter = RawConverter::create (format, error); | ||
if (error) | ||
{ | ||
printf ("error: %s\n", error.message()); | ||
return 1; | ||
} | ||
|
||
std::fill (bytes.begin(), bytes.end(), 0); | ||
|
||
double time1 = get_time(); | ||
converter->to_raw (in_samples.data(), bytes.data(), in_samples.size()); | ||
double time2 = get_time(); | ||
converter->from_raw (bytes.data(), out_samples.data(), in_samples.size()); | ||
double time3 = get_time(); | ||
|
||
double max_err = 0; | ||
for (size_t i = 0; i < in_samples.size(); i++) | ||
max_err = std::max (max_err, std::abs (double (in_samples[i]) - double (out_samples[i]))); | ||
double ebits = log2 (max_err); | ||
printf ("%s %d %s endian %f", | ||
format.encoding() == RawFormat::SIGNED ? "signed" : "unsigned", | ||
format.bit_depth(), | ||
format.endian() == RawFormat::LITTLE ? "little" : "big", | ||
ebits); | ||
double min_ebits = -format.bit_depth() + 0.9; | ||
double max_ebits = -format.bit_depth() + 1; | ||
double ns_per_sample_to = (time2 - time1) * 1e9 / K; | ||
double ns_per_sample_from = (time3 - time2) * 1e9 / K; | ||
printf (" (should be in [%.2f,%.2f]) - to raw: %f ns/sample - from raw: %f ns/sample\n", | ||
min_ebits, max_ebits, | ||
ns_per_sample_to, ns_per_sample_from); | ||
assert (ebits <= max_ebits && ebits >= min_ebits); | ||
|
||
/* every raw converted buffer should be different */ | ||
string hash = hash_bytes (bytes); | ||
assert (hashes.count (hash) == 0); | ||
hashes.insert (hash); | ||
} | ||
} | ||
printf ("\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
source test-common.sh | ||
|
||
for TEST in testrawconverter | ||
do | ||
if [ "x$Q" == "x1" ] && [ -z "$V" ]; then | ||
$TOP_BUILDDIR/src/$TEST > /dev/null | ||
else | ||
$TOP_BUILDDIR/src/$TEST | ||
fi | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
source test-common.sh | ||
|
||
IN_WAV=wav-pipe-test.wav | ||
OUT1_WAV=wav-pipe-test-out1.wav | ||
OUT2_WAV=wav-pipe-test-out2.wav | ||
OUT3_WAV=wav-pipe-test-out3.wav | ||
|
||
for BITS in 16 24 | ||
do | ||
audiowmark test-gen-noise --bits $BITS $IN_WAV 200 44100 | ||
|
||
[ "x$BITS" == "x$(audiowmark test-info $IN_WAV bit_depth)" ] || die "generated input bit depth is not correct" | ||
|
||
cat $IN_WAV | audiowmark_add --test-key 1 --test-no-limiter --format wav-pipe - - $TEST_MSG > $OUT1_WAV || die "watermark from pipe failed" | ||
cat $OUT1_WAV | audiowmark_add --test-key 2 --test-no-limiter --format wav-pipe - - $TEST_MSG > $OUT2_WAV || die "watermark from pipe failed" | ||
cat $OUT2_WAV | audiowmark_add --test-key 3 --test-no-limiter --format wav-pipe - - $TEST_MSG > $OUT3_WAV || die "watermark from pipe failed" | ||
|
||
check_length $IN_WAV $OUT1_WAV | ||
check_length $IN_WAV $OUT2_WAV | ||
check_length $IN_WAV $OUT3_WAV | ||
check_snr $IN_WAV $OUT1_WAV 32 | ||
check_snr $IN_WAV $OUT2_WAV 29 | ||
check_snr $IN_WAV $OUT3_WAV 27 | ||
|
||
audiowmark_cmp --expect-matches 0 $OUT3_WAV $TEST_MSG | ||
audiowmark_cmp --expect-matches 5 --test-key 1 $OUT3_WAV $TEST_MSG | ||
audiowmark_cmp --expect-matches 5 --test-key 2 $OUT3_WAV $TEST_MSG | ||
audiowmark_cmp --expect-matches 5 --test-key 3 $OUT3_WAV $TEST_MSG | ||
|
||
# for wav-pipe format: 16 bit input should produce 16 bit output; 24 bit input should produce 32 bit output | ||
BTEST=$BITS:$(audiowmark test-info $OUT3_WAV bit_depth) | ||
[[ "$BTEST" =~ ^(16:16|24:32)$ ]] || die "unexpected input/output bit depth $BTEST" | ||
|
||
rm $IN_WAV $OUT1_WAV $OUT2_WAV $OUT3_WAV | ||
done | ||
|
||
exit 0 |