diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2016-06-19 02:58:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2016-06-19 03:31:55 +0300 |
commit | 1151d5831f19a9f24dd0c545a4968606712a62d2 (patch) | |
tree | c978c1b9a3fc86fef531dd412fe6b7668b7c0567 /src/util.h | |
parent | 8d65a0bd0774e03b3d10354e15f2f3361a2ce26a (diff) | |
download | atracdenc-1151d5831f19a9f24dd0c545a4968606712a62d2.tar.gz |
some improvements of ATRAC3 implementation:atrac3
- simple (ATRAC1 like) psychoacoustic added
- possibility to encode tonal components
- simple tonal component extractor
- refactoring
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -1,6 +1,9 @@ #pragma once #include <cstdint> +#include <vector> +#include <algorithm> +#include "config.h" template<class T> inline void SwapArray(T* p, const size_t len) { @@ -10,3 +13,30 @@ inline void SwapArray(T* p, const size_t len) { p[j] = tmp; } } + +inline uint16_t GetFirstSetBit(uint32_t x) { + static const uint16_t multiplyDeBruijnBitPosition[32] = { + 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, + 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 + }; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return multiplyDeBruijnBitPosition[(uint32_t)(x * 0x07C4ACDDU) >> 27]; +} + +template<class T> +inline uint16_t Log2FloatToIdx(T x, uint16_t shift) { + T t = x * shift; + return GetFirstSetBit(t); +} + +template<class T> +inline T CalcMedian(T* in, uint32_t len) { + std::vector<T> tmp(in, in+len); + std::sort(tmp.begin(), tmp.end()); + uint32_t pos = (len - 1) / 2; + return tmp[pos]; +} |