Initial experimental import of bq resampler
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
#include <new> // for std::bad_alloc
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#ifndef HAVE_POSIX_MEMALIGN
|
||||
#ifndef _WIN32
|
||||
#ifndef __APPLE__
|
||||
@@ -309,6 +311,96 @@ private:
|
||||
T *m_t;
|
||||
};
|
||||
|
||||
/** Allocator for use with STL classes, e.g. vector, to ensure
|
||||
* alignment. Based on example code by Stephan T. Lavavej.
|
||||
*
|
||||
* e.g. std::vector<float, StlAllocator<float> > v;
|
||||
*/
|
||||
template <typename T>
|
||||
class StlAllocator
|
||||
{
|
||||
public:
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef T &reference;
|
||||
typedef const T &const_reference;
|
||||
typedef T value_type;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
StlAllocator() { }
|
||||
StlAllocator(const StlAllocator&) { }
|
||||
template <typename U> StlAllocator(const StlAllocator<U>&) { }
|
||||
~StlAllocator() { }
|
||||
|
||||
T *
|
||||
allocate(const size_t n) const {
|
||||
if (n == 0) return 0;
|
||||
if (n > max_size()) {
|
||||
#ifndef NO_EXCEPTIONS
|
||||
throw std::length_error("Size overflow in StlAllocator::allocate()");
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
return ::RubberBand::allocate<T>(n);
|
||||
}
|
||||
|
||||
void
|
||||
deallocate(T *const p, const size_t) const {
|
||||
::RubberBand::deallocate(p);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
T *
|
||||
allocate(const size_t n, const U *) const {
|
||||
return allocate(n);
|
||||
}
|
||||
|
||||
T *
|
||||
address(T &r) const {
|
||||
return &r;
|
||||
}
|
||||
|
||||
const T *
|
||||
address(const T &s) const {
|
||||
return &s;
|
||||
}
|
||||
|
||||
size_t
|
||||
max_size() const {
|
||||
return (static_cast<size_t>(0) - static_cast<size_t>(1)) / sizeof(T);
|
||||
}
|
||||
|
||||
template <typename U> struct rebind {
|
||||
typedef StlAllocator<U> other;
|
||||
};
|
||||
|
||||
bool
|
||||
operator==(const StlAllocator &) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(const StlAllocator &) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
construct(T *const p, const T &t) const {
|
||||
void *const pv = static_cast<void *>(p);
|
||||
new (pv) T(t);
|
||||
}
|
||||
|
||||
void
|
||||
destroy(T *const p) const {
|
||||
p->~T();
|
||||
}
|
||||
|
||||
private:
|
||||
StlAllocator& operator=(const StlAllocator&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -491,6 +491,58 @@ inline T v_sum(const T *const R__ src,
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T v_multiply_and_sum(const T *const R__ src1,
|
||||
const T *const R__ src2,
|
||||
const int count)
|
||||
{
|
||||
T result = T();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
result += src1[i] * src2[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined HAVE_IPP
|
||||
template<>
|
||||
inline float v_multiply_and_sum(const float *const R__ src1,
|
||||
const float *const R__ src2,
|
||||
const int count)
|
||||
{
|
||||
float dp;
|
||||
ippsDotProd_32f(src1, src2, count, &dp);
|
||||
return dp;
|
||||
}
|
||||
template<>
|
||||
inline double v_multiply_and_sum(const double *const R__ src1,
|
||||
const double *const R__ src2,
|
||||
const int count)
|
||||
{
|
||||
double dp;
|
||||
ippsDotProd_64f(src1, src2, count, &dp);
|
||||
return dp;
|
||||
}
|
||||
#elif defined HAVE_VDSP
|
||||
template<>
|
||||
inline float v_multiply_and_sum(const float *const R__ src1,
|
||||
const float *const R__ src2,
|
||||
const int count)
|
||||
{
|
||||
float dp;
|
||||
vDSP_dotpr(src1, 1, src2, 1, &dp, count);
|
||||
return dp;
|
||||
}
|
||||
template<>
|
||||
inline double v_multiply_and_sum(const double *const R__ src1,
|
||||
const double *const R__ src2,
|
||||
const int count)
|
||||
{
|
||||
double dp;
|
||||
vDSP_dotprD(src1, 1, src2, 1, &dp, count);
|
||||
return dp;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
inline void v_log(T *const R__ dst,
|
||||
const int count)
|
||||
|
||||
Reference in New Issue
Block a user