summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorJerome Jutteau2010-09-21 16:47:19 +0200
committerJerome Jutteau2010-09-29 14:22:20 +0200
commitc2d4434fa55569771de17f6e249bc5cab7c6b9d1 (patch)
tree86f089ad273f85ee3725fa1035c170e94dd6f345 /cesar
parent0f6e1ab724c3aeda2ec040d04454d1d4f81df51c (diff)
cesar/mac/common: increase and decrease tones from a tonemap, refs #1881
Diffstat (limited to 'cesar')
-rw-r--r--cesar/mac/common/src/tonemap.c32
-rw-r--r--cesar/mac/common/test/tonemap/src/test_tonemap.c99
-rw-r--r--cesar/mac/common/tonemap.h26
3 files changed, 157 insertions, 0 deletions
diff --git a/cesar/mac/common/src/tonemap.c b/cesar/mac/common/src/tonemap.c
index ebc6c0fca8..11c71c782f 100644
--- a/cesar/mac/common/src/tonemap.c
+++ b/cesar/mac/common/src/tonemap.c
@@ -248,6 +248,38 @@ tonemap_write_tone (tonemap_t *tm, uint index, uint tone)
*word_ptr = word;
}
+bool
+tonemap_decrease_tone (tonemap_t *tonemap, uint index)
+{
+ u32 *word_ptr = NULL;
+ u8 mod = tonemap_get_tone (tonemap, index, &word_ptr);
+
+ dbg_assert (word_ptr);
+
+ /* Already on the min modulation. */
+ if (mod == 0)
+ return false;
+ else
+ tonemap_write_tone_to_word (word_ptr, index, mod - 1);
+ return true;
+}
+
+bool
+tonemap_increase_tone (tonemap_t *tonemap, uint index)
+{
+ u32 *word_ptr = NULL;
+ u8 mod = tonemap_get_tone (tonemap, index, &word_ptr);
+
+ dbg_assert (word_ptr);
+
+ /* Already on the max modulation. */
+ if (mod == CE_MOD_COUNT - 1)
+ return false;
+ else
+ tonemap_write_tone_to_word (word_ptr, index, mod + 1);
+ return true;
+}
+
uint
tonemap_bits_per_pb (phy_mod_t mod, phy_fecrate_t fecrate,
phy_pb_size_t pb_size, uint bits_per_symbol)
diff --git a/cesar/mac/common/test/tonemap/src/test_tonemap.c b/cesar/mac/common/test/tonemap/src/test_tonemap.c
index 05f8f36865..1604cdab1a 100644
--- a/cesar/mac/common/test/tonemap/src/test_tonemap.c
+++ b/cesar/mac/common/test/tonemap/src/test_tonemap.c
@@ -18,6 +18,7 @@
#include "mac/common/tonemap.h"
#include "mac/common/tonemask.h"
#include "mac/common/timings.h"
+#include "ce/common/mod.h"
void
tonemap_access_test (test_t t)
@@ -588,6 +589,102 @@ tonemap_copy_test (test_t t)
}
void
+tonemap_decrease_test (test_t t)
+{
+ tonemask_info_t ti;
+ ti.carrier_nb = tonemask_default (ti.tonemask);
+ tonemap_t *tm = tonemap_alloc ();
+ u8 tone = 0;
+
+ /* Fill with some data. */
+ TONEMAP_WRITE_BEGIN (tm, ti.tonemask)
+ {
+ TONEMAP_WRITE_MOD (tone);
+ if (++tone == CE_MOD_COUNT)
+ tone = 0;
+ }
+ TONEMAP_WRITE_END;
+
+ test_begin (t, "Decrease tones of a tone map")
+ {
+ u32 *word_ptr = NULL;
+ bool out;
+ u8 mod;
+ u8 new_mod;
+ uint index;
+
+ for (index = 0; index < ti.carrier_nb; index++)
+ {
+ mod = tonemap_get_tone (tm, index, &word_ptr);
+ out = tonemap_decrease_tone (tm, index);
+ new_mod = tonemap_get_tone (tm, index, &word_ptr);
+
+ /* Already on min. */
+ test_fail_if (mod == 0 && out != false);
+ test_fail_if (out == false && mod != new_mod);
+ if (mod != 0)
+ {
+ /* Modulation decreased. */
+ test_fail_if (new_mod != mod - 1);
+ /* Modulation output is ok. */
+ test_fail_if (out != true);
+ }
+ }
+ } test_end;
+
+ /* Clean. */
+ tonemap_free (tm);
+}
+
+void
+tonemap_increase_test (test_t t)
+{
+ tonemask_info_t ti;
+ ti.carrier_nb = tonemask_default (ti.tonemask);
+ tonemap_t *tm = tonemap_alloc ();
+ u8 tone = 0;
+
+ /* Fill with some data. */
+ TONEMAP_WRITE_BEGIN (tm, ti.tonemask)
+ {
+ TONEMAP_WRITE_MOD (tone);
+ if (++tone == CE_MOD_COUNT)
+ tone = 0;
+ }
+ TONEMAP_WRITE_END;
+
+ test_begin (t, "Increase tones of a tone map")
+ {
+ u32 *word_ptr = NULL;
+ bool out;
+ u8 mod;
+ u8 new_mod;
+ uint index;
+
+ for (index = 0; index < ti.carrier_nb; index++)
+ {
+ mod = tonemap_get_tone (tm, index, &word_ptr);
+ out = tonemap_increase_tone (tm, index);
+ new_mod = tonemap_get_tone (tm, index, &word_ptr);
+
+ /* Already on max. */
+ test_fail_if (mod == CE_MOD_COUNT - 1 && out != false);
+ test_fail_if (out == false && mod != new_mod);
+ if (mod < CE_MOD_COUNT - 1)
+ {
+ /* Modulation increased. */
+ test_fail_if (new_mod != mod + 1);
+ /* Modulation output is ok. */
+ test_fail_if (out != true);
+ }
+ }
+ } test_end;
+
+ /* Clean. */
+ tonemap_free (tm);
+}
+
+void
tonemaps_access_test (test_t t)
{
tonemaps_t *tms = tonemaps_alloc ();
@@ -684,6 +781,8 @@ tonemap_test_suite (test_t t)
tonemap_tonemask_test_case (t);
tonemap_access_test (t);
tonemap_copy_test (t);
+ tonemap_decrease_test (t);
+ tonemap_increase_test (t);
tonemaps_access_test (t);
tonemaps_reset_test (t);
diff --git a/cesar/mac/common/tonemap.h b/cesar/mac/common/tonemap.h
index bb3db30fb1..e992ea6485 100644
--- a/cesar/mac/common/tonemap.h
+++ b/cesar/mac/common/tonemap.h
@@ -610,6 +610,32 @@ void
tonemap_write_tone (tonemap_t *tm, uint index, uint tone);
/**
+ * Decrease modulation of a tone in a tone map.
+ * \param tonemap tonemap to use.
+ * \param index index of the tone in the tone map.
+ * \return true if decrease succeeded, false otherwise.
+ *
+ * The decrease may fail if the tone is already set at the minimal value.
+ * \warning The given index must be in the tone map.
+ * The function will assert otherwise.
+ */
+bool
+tonemap_decrease_tone (tonemap_t *tonemap, uint index);
+
+/**
+ * Increase modulation of a tone in a tone map.
+ * \param tonemap tonemap to use.
+ * \param index index of the tone in the tone map.
+ * \return true if increase succeeded, false otherwise.
+ *
+ * The increase fail if the tone is already set at the maximal value.
+ * \warning The given index must be in the tone map.
+ * The function will assert otherwise.
+ */
+bool
+tonemap_increase_tone (tonemap_t *tonemap, uint index);
+
+/**
* Compute the number of bits per Physical Block.
* \param mod tone map kind used.
* \param fecrate FEC encoding rate.