summaryrefslogtreecommitdiffstats
path: root/media/libeffects/loudness/common
diff options
context:
space:
mode:
Diffstat (limited to 'media/libeffects/loudness/common')
-rw-r--r--media/libeffects/loudness/common/core/basic_types.h114
-rw-r--r--media/libeffects/loudness/common/core/byte_swapper.h151
-rw-r--r--media/libeffects/loudness/common/core/math.h89
-rw-r--r--media/libeffects/loudness/common/core/os.h29
-rw-r--r--media/libeffects/loudness/common/core/types.h31
5 files changed, 414 insertions, 0 deletions
diff --git a/media/libeffects/loudness/common/core/basic_types.h b/media/libeffects/loudness/common/core/basic_types.h
new file mode 100644
index 0000000..593e914
--- /dev/null
+++ b/media/libeffects/loudness/common/core/basic_types.h
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LE_FX_ENGINE_COMMON_CORE_BASIC_TYPES_H_
+#define LE_FX_ENGINE_COMMON_CORE_BASIC_TYPES_H_
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string>
+using ::std::string;
+using ::std::basic_string;
+#include <vector>
+using ::std::vector;
+
+#include "common/core/os.h"
+
+// -----------------------------------------------------------------------------
+// Definitions of common basic types:
+// -----------------------------------------------------------------------------
+
+#if !defined(G_COMPILE) && !defined(BASE_INTEGRAL_TYPES_H_)
+
+namespace le_fx {
+
+typedef signed char schar;
+typedef signed char int8;
+typedef short int16;
+typedef int int32;
+typedef long long int64;
+
+typedef unsigned char uint8;
+typedef unsigned short uint16;
+typedef unsigned int uint32;
+typedef unsigned long long uint64;
+
+} // namespace le_fx
+
+#endif
+
+namespace le_fx {
+
+struct FloatArray {
+ int length;
+ float *data;
+
+ FloatArray(void) {
+ data = NULL;
+ length = 0;
+ }
+};
+
+struct Int16Array {
+ int length;
+ int16 *data;
+
+ Int16Array(void) {
+ data = NULL;
+ length = 0;
+ }
+};
+
+struct Int32Array {
+ int length;
+ int32 *data;
+
+ Int32Array(void) {
+ data = NULL;
+ length = 0;
+ }
+};
+
+struct Int8Array {
+ int length;
+ uint8 *data;
+
+ Int8Array(void) {
+ data = NULL;
+ length = 0;
+ }
+};
+
+//
+// Simple wrapper for waveform data:
+//
+class WaveData : public vector<int16> {
+ public:
+ WaveData();
+ ~WaveData();
+
+ void Set(int number_samples, int sampling_rate, int16 *data);
+ int sample_rate(void) const;
+ void set_sample_rate(int sample_rate);
+ bool Equals(const WaveData &wave_data, int threshold = 0) const;
+
+ private:
+ int sample_rate_;
+};
+
+} // namespace le_fx
+
+#endif // LE_FX_ENGINE_COMMON_CORE_BASIC_TYPES_H_
diff --git a/media/libeffects/loudness/common/core/byte_swapper.h b/media/libeffects/loudness/common/core/byte_swapper.h
new file mode 100644
index 0000000..8f0caf3
--- /dev/null
+++ b/media/libeffects/loudness/common/core/byte_swapper.h
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LE_FX_ENGINE_COMMON_CORE_BYTE_SWAPPER_H_
+#define LE_FX_ENGINE_COMMON_CORE_BYTE_SWAPPER_H_
+
+#include <stdio.h>
+#include <string.h>
+
+#include "common/core/basic_types.h"
+#include "common/core/os.h"
+
+namespace le_fx {
+
+namespace arch {
+
+inline bool IsLittleEndian(void) {
+ int16 word = 1;
+ char *cp = reinterpret_cast<char *>(&word);
+ return cp[0] != 0;
+}
+
+inline bool IsBigEndian(void) {
+ return !IsLittleEndian();
+}
+
+template <typename T, unsigned int kValSize>
+struct ByteSwapper {
+ static T Swap(const T &val) {
+ T new_val = val;
+ char *first = &new_val, *last = first + kValSize - 1, x;
+ for (; first < last; ++first, --last) {
+ x = *last;
+ *last = *first;
+ *first = x;
+ }
+ return new_val;
+ }
+};
+
+template <typename T>
+struct ByteSwapper<T, 1> {
+ static T Swap(const T &val) {
+ return val;
+ }
+};
+
+template <typename T>
+struct ByteSwapper<T, 2> {
+ static T Swap(const T &val) {
+ T new_val;
+ const char *o = (const char *)&val;
+ char *p = reinterpret_cast<char *>(&new_val);
+ p[0] = o[1];
+ p[1] = o[0];
+ return new_val;
+ }
+};
+
+template <typename T>
+struct ByteSwapper<T, 4> {
+ static T Swap(const T &val) {
+ T new_val;
+ const char *o = (const char *)&val;
+ char *p = reinterpret_cast<char *>(&new_val);
+ p[0] = o[3];
+ p[1] = o[2];
+ p[2] = o[1];
+ p[3] = o[0];
+ return new_val;
+ }
+};
+
+template <typename T>
+struct ByteSwapper<T, 8> {
+ static T Swap(const T &val) {
+ T new_val = val;
+ const char *o = (const char *)&val;
+ char *p = reinterpret_cast<char *>(&new_val);
+ p[0] = o[7];
+ p[1] = o[6];
+ p[2] = o[5];
+ p[3] = o[4];
+ p[4] = o[3];
+ p[5] = o[2];
+ p[6] = o[1];
+ p[7] = o[0];
+ return new_val;
+ }
+};
+
+template <typename T>
+T SwapBytes(const T &val, bool force_swap) {
+ if (force_swap) {
+#if !defined(LE_FX__NEED_BYTESWAP)
+ return ByteSwapper<T, sizeof(T)>::Swap(val);
+#else
+ return val;
+#endif // !LE_FX_NEED_BYTESWAP
+ } else {
+#if !defined(LE_FX_NEED_BYTESWAP)
+ return val;
+#else
+ return ByteSwapper<T, sizeof(T)>::Swap(val);
+#endif // !LE_FX_NEED_BYTESWAP
+ }
+}
+
+template <typename T>
+const T *SwapBytes(const T *vals, unsigned int num_items, bool force_swap) {
+ if (force_swap) {
+#if !defined(LE_FX_NEED_BYTESWAP)
+ T *writeable_vals = const_cast<T *>(vals);
+ for (unsigned int i = 0; i < num_items; i++) {
+ writeable_vals[i] = ByteSwapper<T, sizeof(T)>::Swap(vals[i]);
+ }
+ return writeable_vals;
+#else
+ return vals;
+#endif // !LE_FX_NEED_BYTESWAP
+ } else {
+#if !defined(LE_FX_NEED_BYTESWAP)
+ return vals;
+#else
+ T *writeable_vals = const_cast<T *>(vals);
+ for (unsigned int i = 0; i < num_items; i++) {
+ writeable_vals[i] = ByteSwapper<T, sizeof(T)>::Swap(vals[i]);
+ }
+ return writeable_vals;
+#endif // !LE_FX_NEED_BYTESWAP
+ }
+}
+
+} // namespace arch
+
+} // namespace le_fx
+
+#endif // LE_FX_ENGINE_COMMON_CORE_BYTE_SWAPPER_H_
diff --git a/media/libeffects/loudness/common/core/math.h b/media/libeffects/loudness/common/core/math.h
new file mode 100644
index 0000000..3f302cc
--- /dev/null
+++ b/media/libeffects/loudness/common/core/math.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LE_FX_ENGINE_COMMON_CORE_MATH_H_
+#define LE_FX_ENGINE_COMMON_CORE_MATH_H_
+
+#include <math.h>
+#include <algorithm>
+using ::std::min;
+using ::std::max;
+using ::std::fill;
+using ::std::fill_n;using ::std::lower_bound;
+#include <cmath>
+#include <math.h>
+//using ::std::fpclassify;
+
+#include "common/core/os.h"
+#include "common/core/types.h"
+
+namespace le_fx {
+namespace math {
+
+// A fast approximation to log2(.)
+inline float fast_log2(float val) {
+ int* const exp_ptr = reinterpret_cast <int *> (&val);
+ int x = *exp_ptr;
+ const int log_2 = ((x >> 23) & 255) - 128;
+ x &= ~(255 << 23);
+ x += 127 << 23;
+ *exp_ptr = x;
+ val = ((-1.0f / 3) * val + 2) * val - 2.0f / 3;
+ return static_cast<float>(val + log_2);
+}
+
+// A fast approximation to log(.)
+inline float fast_log(float val) {
+ return fast_log2(val) *
+ 0.693147180559945286226763982995180413126945495605468750f;
+}
+
+// An approximation of the exp(.) function using a 5-th order Taylor expansion.
+// It's pretty accurate between +-0.1 and accurate to 10e-3 between +-1
+template <typename T>
+inline T ExpApproximationViaTaylorExpansionOrder5(T x) {
+ const T x2 = x * x;
+ const T x3 = x2 * x;
+ const T x4 = x2 * x2;
+ const T x5 = x3 * x2;
+ return 1.0f + x + 0.5f * x2 +
+ 0.16666666666666665741480812812369549646973609924316406250f * x3 +
+ 0.0416666666666666643537020320309238741174340248107910156250f * x4 +
+ 0.008333333333333333217685101601546193705871701240539550781250f * x5;
+}
+
+} // namespace math
+} // namespace le_fx
+
+// Math functions missing in Android NDK:
+#if defined(LE_FX_OS_ANDROID)
+
+namespace std {
+
+//
+// Round to the nearest integer: We need this implementation
+// since std::round is missing on android.
+//
+template <typename T>
+inline T round(const T &x) {
+ return static_cast<T>(std::floor(static_cast<double>(x) + 0.5));
+}
+
+} // namespace std
+
+#endif // LE_FX_OS_ANDROID
+
+#endif // LE_FX_ENGINE_COMMON_CORE_MATH_H_
diff --git a/media/libeffects/loudness/common/core/os.h b/media/libeffects/loudness/common/core/os.h
new file mode 100644
index 0000000..4a8ce82
--- /dev/null
+++ b/media/libeffects/loudness/common/core/os.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LE_FX_ENGINE_COMMON_CORE_OS_H_
+#define LE_FX_ENGINE_COMMON_CORE_OS_H_
+
+// -----------------------------------------------------------------------------
+// OS Identification:
+// -----------------------------------------------------------------------------
+
+#define LE_FX_OS_UNIX
+#if defined(__ANDROID__)
+# define LE_FX_OS_ANDROID
+#endif // Android
+
+#endif // LE_FX_ENGINE_COMMON_CORE_OS_H_
diff --git a/media/libeffects/loudness/common/core/types.h b/media/libeffects/loudness/common/core/types.h
new file mode 100644
index 0000000..d1b6c6a
--- /dev/null
+++ b/media/libeffects/loudness/common/core/types.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LE_FX_ENGINE_COMMON_CORE_TYPES_H_
+#define LE_FX_ENGINE_COMMON_CORE_TYPES_H_
+
+#include "common/core/os.h"
+
+#include "common/core/basic_types.h"
+
+#ifndef LE_FX_DISALLOW_COPY_AND_ASSIGN
+#define LE_FX_DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&); \
+ void operator=(const TypeName&)
+#endif // LE_FX_DISALLOW_COPY_AND_ASSIGN
+
+
+#endif // LE_FX_ENGINE_COMMON_CORE_TYPES_H_