Commit 75f86bee authored by Stefan Westerfeld's avatar Stefan Westerfeld

Make number of short payload bits a command line parameter.

 * use --short <bits> where bits is one of 12, 16 or 20.
Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent c36cb764
......@@ -26,6 +26,7 @@
#include "utils.hh"
#include "random.hh"
#include "wmcommon.hh"
#include "shortcode.hh"
#include <assert.h>
......@@ -57,7 +58,7 @@ print_usage()
printf ("Global options:\n");
printf (" --strength <s> set watermark strength [%.6g]\n", Params::water_delta * 1000);
printf (" --linear disable non-linear bit storage\n");
printf (" --short enable short payload mode (12 bits)\n");
printf (" --short <bits> enable short payload mode\n");
printf (" --key <file> load watermarking key from file\n");
printf (" -q, --quiet disable information messages\n");
printf ("\n");
......@@ -184,9 +185,14 @@ parse_options (int *argc_p,
{
Params::mix = false;
}
else if (check_arg (argc, argv, &i, "--short"))
else if (check_arg (argc, argv, &i, "--short", &opt_arg))
{
Params::payload_size = 12;
Params::payload_size = atoi (opt_arg);
if (!short_code_init (Params::payload_size))
{
error ("audiowmark: unsupported short payload size %zd\n", Params::payload_size);
exit (1);
}
Params::payload_short = true;
}
else if (check_arg (argc, argv, &i, "--hard"))
......
......@@ -25,7 +25,6 @@ using std::vector;
/* Codes from codetables.de / magma online calculator BKLC (GF(2), N, K) */
#if 0
static vector<vector<int>> block_65_20_20 = {
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,0,0,1,1,1,0,1,1,1},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,0,0,1,1,0,1,0,0,0,0,0,1,1,1,1,0,1,1,0,0,1,0,0,0,0,0,1,1,1,0,1,1,1,1,1,1},
......@@ -49,12 +48,6 @@ static vector<vector<int>> block_65_20_20 = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,1,1,0,1,1,1,0,0,1,0,0,0,0,1},
};
static const auto& gen_matrix = block_65_20_20;
static constexpr int gen_in_count = 20;
static constexpr int gen_out_count = 65;
#endif
#if 0
static vector<vector<int>> block_61_16_21 = {
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,1,0,0,1,0,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,1,0,0,1,0},
......@@ -74,11 +67,6 @@ static vector<vector<int>> block_61_16_21 = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,1,1,1,0,1,0,1,1,1,0,1,1},
};
static const auto& gen_matrix = block_61_16_21;
static constexpr int gen_in_count = 16;
static constexpr int gen_out_count = 61;
#endif
static vector<vector<int>> block_56_12_22 = {
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1 },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0 },
......@@ -94,9 +82,37 @@ static vector<vector<int>> block_56_12_22 = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1 },
};
static const auto& gen_matrix = block_56_12_22;
static constexpr int gen_in_count = 12;
static constexpr int gen_out_count = 56;
static vector<vector<int>> gen_matrix;
static size_t gen_in_count = 0;
static size_t gen_out_count = 0;
size_t
short_code_init (size_t k)
{
if (k == 12)
{
gen_matrix = block_56_12_22;
gen_in_count = 12;
gen_out_count = 56;
}
else if (k == 16)
{
gen_matrix = block_61_16_21;
gen_in_count = 16;
gen_out_count = 61;
}
else if (k == 20)
{
gen_matrix = block_65_20_20;
gen_in_count = 20;
gen_out_count = 65;
}
else /* unsupported k */
{
return 0;
}
return gen_out_count;
}
vector<int>
code_encode (ConvBlockType block_type, const vector<int>& in_bits)
......@@ -157,7 +173,7 @@ vector<int>
short_decode_blk (const vector<int>& coded_bits)
{
vector<int> out_bits;
for (size_t c = 0; c < (1 << gen_in_count); c++)
for (size_t c = 0; c < size_t (1 << gen_in_count); c++)
{
bool match = true;
for (size_t j = 0; j < gen_out_count; j++)
......@@ -201,10 +217,3 @@ short_decode_soft (ConvBlockType block_type, const std::vector<float>& coded_bit
{
return short_decode_blk (conv_decode_soft (block_type, coded_bits, error_out));
}
void
short_code_get_n_k (size_t& n, size_t& k)
{
k = gen_in_count;
n = gen_out_count;
}
......@@ -33,6 +33,6 @@ std::vector<int> short_decode_soft (ConvBlockType block_type, const std::vector<
std::vector<int> short_encode_blk (const std::vector<int>& in_bits);
std::vector<int> short_decode_blk (const std::vector<int>& coded_bits);
void short_code_get_n_k (size_t& n, size_t& k);
size_t short_code_init (size_t k);
#endif /* AUDIOWMARK_SHORT_CODE_HH */
......@@ -84,13 +84,23 @@ number_format (double d)
int
main (int argc, char **argv)
{
size_t N, K;
short_code_get_n_k (N, K);
printf ("using (%zd,%zd) code\n", N, K);
srand (time (NULL));
if (argc == 1)
if (argc < 2)
{
printf ("first argument must be code size (12, 16, 20)\n");
return 1;
}
size_t K = atoi (argv[1]);
size_t N = short_code_init (K);
if (!N)
{
printf ("bad code size\n");
return 1;
}
printf ("using (%zd,%zd) code\n", N, K);
if (argc == 2)
{
vector<int> in_bits;
while (in_bits.size() != K)
......@@ -113,7 +123,7 @@ main (int argc, char **argv)
printf ("%d", b);
printf ("\n");
}
if (argc == 2 && string (argv[1]) == "perf")
if (argc == 3 && string (argv[2]) == "perf")
{
const double start_t = gettime();
const size_t runs = 100;
......@@ -128,7 +138,7 @@ main (int argc, char **argv)
}
printf ("%.1f ms/block\n", (gettime() - start_t) / runs * 1000.0);
}
if (argc == 2 && string (argv[1]) == "table")
if (argc == 3 && string (argv[2]) == "table")
{
map<vector<int>, vector<int>> table;
vector<int> weight (N + 1);
......@@ -179,7 +189,7 @@ main (int argc, char **argv)
}
}
}
if (argc == 2 && string (argv[1]) == "distance")
if (argc == 3 && string (argv[2]) == "distance")
{
vector<vector<int>> cwords;
for (size_t i = 0; i < size_t (1 << K); i++)
......
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