Commit 3c314c27 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Add tests for shortcode.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 6be13df3
......@@ -11,7 +11,7 @@ COMMON_LIBS = $(SNDFILE_LIBS) $(FFTW_LIBS) $(LIBGCRYPT_LIBS) $(LIBMPG123_LIBS)
audiowmark_SOURCES = audiowmark.cc wmget.cc wmadd.cc $(COMMON_SRC)
audiowmark_LDFLAGS = $(COMMON_LIBS)
noinst_PROGRAMS = testconvcode testrandom testmp3 teststream testlimiter
noinst_PROGRAMS = testconvcode testrandom testmp3 teststream testlimiter testshortcode
testconvcode_SOURCES = testconvcode.cc $(COMMON_SRC)
testconvcode_LDFLAGS = $(COMMON_LIBS)
......@@ -27,3 +27,6 @@ teststream_LDFLAGS = $(COMMON_LIBS)
testlimiter_SOURCES = testlimiter.cc $(COMMON_SRC)
testlimiter_LDFLAGS = $(COMMON_LIBS)
testshortcode_SOURCES = testshortcode.cc $(COMMON_SRC)
testshortcode_LDFLAGS = $(COMMON_LIBS)
......@@ -87,7 +87,7 @@ code_decode_soft (ConvBlockType block_type, const std::vector<float>& coded_bits
}
vector<int>
short_encode (ConvBlockType block_type, const vector<int>& in_bits)
short_encode_blk (const vector<int>& in_bits)
{
assert (gen_matrix.size() == in_bits.size());
......@@ -104,7 +104,13 @@ short_encode (ConvBlockType block_type, const vector<int>& in_bits)
}
out_bits.push_back (x);
}
return conv_encode (block_type, out_bits);
return out_bits;
}
vector<int>
short_encode (ConvBlockType block_type, const vector<int>& in_bits)
{
return conv_encode (block_type, short_encode_blk (in_bits));
}
size_t
......@@ -116,10 +122,8 @@ short_code_size (ConvBlockType block_type, size_t msg_size)
}
vector<int>
short_decode_soft (ConvBlockType block_type, const std::vector<float>& coded_bits, float *error_out)
short_decode_blk (const vector<int>& coded_bits)
{
vector<int> xbits = conv_decode_soft (block_type, coded_bits, error_out);
vector<int> out_bits;
for (size_t c = 0; c < (1 << gen_in_count); c++)
{
......@@ -136,7 +140,7 @@ short_decode_soft (ConvBlockType block_type, const std::vector<float>& coded_bit
}
w.push_back (x);
}
if (w == xbits)
if (w == coded_bits)
{
for (size_t bit = 0; bit < gen_in_count; bit++)
{
......@@ -155,3 +159,9 @@ short_decode_soft (ConvBlockType block_type, const std::vector<float>& coded_bit
return out_bits;
}
vector<int>
short_decode_soft (ConvBlockType block_type, const std::vector<float>& coded_bits, float *error_out)
{
return short_decode_blk (conv_decode_soft (block_type, coded_bits, error_out));
}
......@@ -31,4 +31,7 @@ size_t short_code_size (ConvBlockType block_type, size_t msg_size);
std::vector<int> short_encode (ConvBlockType block_type, const std::vector<int>& in_bits);
std::vector<int> short_decode_soft (ConvBlockType block_type, const std::vector<float>& coded_bits, float *error_out = nullptr);
std::vector<int> short_encode_blk (const std::vector<int>& in_bits);
std::vector<int> short_decode_blk (const std::vector<int>& coded_bits);
#endif /* AUDIOWMARK_SHORT_CODE_HH */
/*
* Copyright (C) 2018-2020 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 <vector>
#include <sys/time.h>
#include <assert.h>
#include "shortcode.hh"
using std::vector;
using std::string;
static double
gettime()
{
timeval tv;
gettimeofday (&tv, 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
int
main (int argc, char **argv)
{
if (argc == 1)
{
vector<int> in_bits = { 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 };
printf ("in: ");
for (auto b : in_bits)
printf ("%d", b);
printf ("\n");
printf ("coded: ");
vector<int> coded_bits = short_encode_blk (in_bits);
for (auto b : coded_bits)
printf ("%d", b);
printf ("\n");
vector<int> decoded_bits = short_decode_blk (coded_bits);
printf ("out: ");
for (auto b : decoded_bits)
printf ("%d", b);
printf ("\n");
}
if (argc == 2 && string (argv[1]) == "perf")
{
vector<int> in_bits;
while (in_bits.size() != 16)
in_bits.push_back (rand() & 1);
const double start_t = gettime();
const size_t runs = 20;
for (size_t i = 0; i < runs; i++)
{
vector<int> out_bits = short_decode_blk (short_encode_blk (in_bits));
assert (out_bits == in_bits);
}
printf ("%.1f ms/block\n", (gettime() - start_t) / runs * 1000.0);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment