2015-07-08 11:39:24 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DSP_DECIMATE_H__
|
|
|
|
#define __DSP_DECIMATE_H__
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <array>
|
2015-11-03 15:11:32 -05:00
|
|
|
#include <memory>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "utility.hpp"
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
#include "dsp_types.hpp"
|
|
|
|
|
2015-12-29 13:48:29 -05:00
|
|
|
#include "simd.hpp"
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
namespace dsp {
|
|
|
|
namespace decimate {
|
|
|
|
|
2015-11-19 15:20:20 -05:00
|
|
|
class Complex8DecimateBy2CIC3 {
|
|
|
|
public:
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c8_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2015-11-19 15:20:20 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t _i1_i0 { 0 };
|
|
|
|
uint32_t _q1_q0 { 0 };
|
|
|
|
};
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
class TranslateByFSOver4AndDecimateBy2CIC3 {
|
|
|
|
public:
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c8_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2015-07-08 11:39:24 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t _q1_i0 { 0 };
|
|
|
|
uint32_t _q0_i1 { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
class DecimateBy2CIC3 {
|
|
|
|
public:
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c16_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2015-07-08 11:39:24 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t _iq0 { 0 };
|
|
|
|
uint32_t _iq1 { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
class FIR64AndDecimateBy2Real {
|
|
|
|
public:
|
|
|
|
static constexpr size_t taps_count = 64;
|
|
|
|
|
2016-01-02 13:35:23 -05:00
|
|
|
void configure(
|
2015-07-08 11:39:24 -04:00
|
|
|
const std::array<int16_t, taps_count>& taps
|
2016-01-02 13:35:23 -05:00
|
|
|
);
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
buffer_s16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_s16_t& src,
|
|
|
|
const buffer_s16_t& dst
|
2015-07-08 11:39:24 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<int16_t, taps_count + 2> z;
|
2016-01-02 13:35:23 -05:00
|
|
|
std::array<int16_t, taps_count> taps;
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
2016-01-02 13:34:17 -05:00
|
|
|
class FIRC8xR16x24FS4Decim4 {
|
|
|
|
public:
|
|
|
|
static constexpr size_t taps_count = 24;
|
|
|
|
static constexpr size_t decimation_factor = 4;
|
|
|
|
|
|
|
|
using sample_t = complex8_t;
|
|
|
|
using tap_t = int16_t;
|
|
|
|
|
|
|
|
enum class Shift : bool {
|
|
|
|
Down = true,
|
|
|
|
Up = false
|
|
|
|
};
|
|
|
|
|
|
|
|
void configure(
|
|
|
|
const std::array<tap_t, taps_count>& taps,
|
|
|
|
const int32_t scale,
|
|
|
|
const Shift shift = Shift::Down
|
|
|
|
);
|
|
|
|
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c8_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2016-01-02 13:34:17 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<vec2_s16, taps_count - decimation_factor> z_;
|
|
|
|
std::array<tap_t, taps_count> taps_;
|
|
|
|
int32_t output_scale = 0;
|
|
|
|
};
|
|
|
|
|
2015-12-29 13:48:29 -05:00
|
|
|
class FIRC8xR16x24FS4Decim8 {
|
|
|
|
public:
|
|
|
|
static constexpr size_t taps_count = 24;
|
|
|
|
static constexpr size_t decimation_factor = 8;
|
|
|
|
|
|
|
|
using sample_t = complex8_t;
|
|
|
|
using tap_t = int16_t;
|
|
|
|
|
|
|
|
enum class Shift : bool {
|
|
|
|
Down = true,
|
|
|
|
Up = false
|
|
|
|
};
|
|
|
|
|
|
|
|
void configure(
|
|
|
|
const std::array<tap_t, taps_count>& taps,
|
|
|
|
const int32_t scale,
|
|
|
|
const Shift shift = Shift::Down
|
|
|
|
);
|
|
|
|
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c8_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2015-12-29 13:48:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<vec2_s16, taps_count - decimation_factor> z_;
|
|
|
|
std::array<tap_t, taps_count> taps_;
|
|
|
|
int32_t output_scale = 0;
|
|
|
|
};
|
|
|
|
|
2016-01-02 13:34:17 -05:00
|
|
|
class FIRC16xR16x16Decim2 {
|
|
|
|
public:
|
|
|
|
static constexpr size_t taps_count = 16;
|
|
|
|
static constexpr size_t decimation_factor = 2;
|
|
|
|
|
|
|
|
using sample_t = complex16_t;
|
|
|
|
using tap_t = int16_t;
|
|
|
|
|
|
|
|
void configure(
|
|
|
|
const std::array<tap_t, taps_count>& taps,
|
|
|
|
const int32_t scale
|
|
|
|
);
|
|
|
|
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c16_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2016-01-02 13:34:17 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<vec2_s16, taps_count - decimation_factor> z_;
|
|
|
|
std::array<tap_t, taps_count> taps_;
|
|
|
|
int32_t output_scale = 0;
|
|
|
|
};
|
|
|
|
|
2015-12-29 13:48:29 -05:00
|
|
|
class FIRC16xR16x32Decim8 {
|
|
|
|
public:
|
|
|
|
static constexpr size_t taps_count = 32;
|
|
|
|
static constexpr size_t decimation_factor = 8;
|
|
|
|
|
|
|
|
using sample_t = complex16_t;
|
|
|
|
using tap_t = int16_t;
|
|
|
|
|
|
|
|
void configure(
|
|
|
|
const std::array<tap_t, taps_count>& taps,
|
|
|
|
const int32_t scale
|
|
|
|
);
|
|
|
|
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c16_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2015-12-29 13:48:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<vec2_s16, taps_count - decimation_factor> z_;
|
|
|
|
std::array<tap_t, taps_count> taps_;
|
|
|
|
int32_t output_scale = 0;
|
|
|
|
};
|
|
|
|
|
2015-11-03 19:52:42 -05:00
|
|
|
class FIRAndDecimateComplex {
|
2015-07-08 11:39:24 -04:00
|
|
|
public:
|
2015-11-03 15:11:32 -05:00
|
|
|
using sample_t = complex16_t;
|
|
|
|
using tap_t = complex16_t;
|
|
|
|
|
|
|
|
using taps_t = tap_t[];
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
/* NOTE! Current code makes an assumption that block of samples to be
|
|
|
|
* processed will be a multiple of the taps_count.
|
|
|
|
*/
|
2015-11-03 19:52:42 -05:00
|
|
|
FIRAndDecimateComplex(
|
2015-11-05 13:19:05 -05:00
|
|
|
) : taps_count_ { 0 },
|
|
|
|
decimation_factor_ { 1 }
|
2015-11-03 15:11:32 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2015-11-05 13:19:05 -05:00
|
|
|
void configure(
|
2015-11-03 19:52:42 -05:00
|
|
|
const T& taps,
|
|
|
|
const size_t decimation_factor
|
2015-11-05 13:19:05 -05:00
|
|
|
) {
|
2016-01-04 14:20:28 -05:00
|
|
|
configure(taps.data(), taps.size(), decimation_factor);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer_c16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_c16_t& src,
|
|
|
|
const buffer_c16_t& dst
|
2015-11-03 19:52:42 -05:00
|
|
|
);
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
private:
|
2015-11-03 15:11:32 -05:00
|
|
|
using samples_t = sample_t[];
|
|
|
|
|
2015-11-05 13:19:05 -05:00
|
|
|
std::unique_ptr<samples_t> samples_;
|
|
|
|
std::unique_ptr<taps_t> taps_reversed_;
|
|
|
|
size_t taps_count_;
|
|
|
|
size_t decimation_factor_;
|
2016-01-04 14:20:28 -05:00
|
|
|
|
2016-01-30 20:30:54 -05:00
|
|
|
template<typename T>
|
2016-01-04 14:20:28 -05:00
|
|
|
void configure(
|
2016-01-30 20:30:54 -05:00
|
|
|
const T* const taps,
|
2016-01-04 14:20:28 -05:00
|
|
|
const size_t taps_count,
|
|
|
|
const size_t decimation_factor
|
2016-01-30 20:30:54 -05:00
|
|
|
) {
|
|
|
|
samples_ = std::make_unique<samples_t>(taps_count);
|
|
|
|
taps_reversed_ = std::make_unique<taps_t>(taps_count);
|
|
|
|
taps_count_ = taps_count;
|
|
|
|
decimation_factor_ = decimation_factor;
|
|
|
|
std::reverse_copy(&taps[0], &taps[taps_count], &taps_reversed_[0]);
|
|
|
|
}
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class DecimateBy2CIC4Real {
|
|
|
|
public:
|
|
|
|
buffer_s16_t execute(
|
2016-01-04 02:09:06 -05:00
|
|
|
const buffer_s16_t& src,
|
|
|
|
const buffer_s16_t& dst
|
2015-07-08 11:39:24 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int16_t z[5];
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace decimate */
|
|
|
|
} /* namespace dsp */
|
|
|
|
|
|
|
|
#endif/*__DSP_DECIMATE_H__*/
|