Audacity 3.2.0
MapToPositiveHalfIndex.h
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4
12constexpr auto MapToPositiveHalfIndex(int index, int fullSize)
13{
14 assert(fullSize > 0 && fullSize % 2 == 0);
15 if (index >= 0)
16 index = index % fullSize;
17 else
18 index = fullSize - (-index % fullSize);
19 if (index > fullSize / 2)
20 index = fullSize - index;
21 return index;
22}
23
24static_assert(MapToPositiveHalfIndex(-3, 4) == 1);
25static_assert(MapToPositiveHalfIndex(-2, 4) == 2);
26static_assert(MapToPositiveHalfIndex(-1, 4) == 1);
27static_assert(MapToPositiveHalfIndex(0, 4) == 0);
28static_assert(MapToPositiveHalfIndex(1, 4) == 1);
29static_assert(MapToPositiveHalfIndex(2, 4) == 2);
30static_assert(MapToPositiveHalfIndex(3, 4) == 1);
31static_assert(MapToPositiveHalfIndex(4, 4) == 0);
constexpr auto MapToPositiveHalfIndex(int index, int fullSize)
Useful when dealing with symmetric spectra reduced only to their positive half. See tests below for m...