Skip to content

Filter API

filter

filter class

template <typename T> filter

Abstract base class for filters with one argument. Mainly for DSP

Source code
template <typename T>
class filter
{
public:
    virtual ~filter() {}

    /// @brief Resets internal state (such as delay line)
    virtual void reset() {}

    /// @brief Applies filter to a static array
    template <size_t Size>
    void apply(T (&buffer)[Size])
    {
        process_buffer(buffer, buffer, Size);
    }

    /// @brief Applies filter to a static array and writes the result to another array
    template <size_t Size>
    void apply(T (&dest)[Size], T (&src)[Size])
    {
        process_buffer(dest, src, Size);
    }

    /// @brief Applies filter to a univector
    template <univector_tag Tag>
    void apply(univector<T, Tag>& buffer)
    {
        process_buffer(buffer.data(), buffer.data(), buffer.size());
    }

    /// @brief Applies filter to a univector and writes the result to another univector
    template <univector_tag Tag1, univector_tag Tag2>
    void apply(univector<T, Tag1>& dest, const univector<T, Tag2>& src)
    {
        if (dest.empty())
            dest.resize(src.size());
        process_buffer(dest.data(), src.data(), std::min(dest.size(), src.size()));
    }

    void apply(T* buffer, size_t size) { process_buffer(buffer, buffer, size); }

    void apply(T* dest, const T* src, size_t size) { process_buffer(dest, src, size); }

    template <univector_tag Tag>
    void apply(univector<T, Tag>& dest, const expression_handle<T, 1>& src)
    {
        process_expression(dest.data(), src, size_min(dest.size(), src.size()));
    }

    void apply(T* dest, const expression_handle<T, 1>& src, size_t size)
    {
        process_expression(dest, src, size_min(size, src.size()));
    }

    template <univector_tag Tag, typename Expr, KFR_ENABLE_IF(is_input_expression<Expr>)>
    void apply(univector<T, Tag>& dest, const Expr& src)
    {
        static_assert(expression_dims<Expr> == 1);
        process_expression(dest.data(), to_handle(src), size_min(dest.size(), get_shape(src).front()));
    }

    template <typename Expr, KFR_ENABLE_IF(is_input_expression<Expr>)>
    void apply(T* dest, const Expr& src, size_t size)
    {
        process_expression(dest, to_handle(src), size_min(size, src.size()));
    }

protected:
    virtual void process_buffer(T* dest, const T* src, size_t size)                           = 0;
    virtual void process_expression(T* dest, const expression_handle<T, 1>& src, size_t size) = 0;
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L38

reset function

virtual void reset()

Resets internal state (such as delay line)

Source code
virtual void reset() {}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L44

apply function

template <size_t Size> void apply(T (&buffer)[Size])

Applies filter to a static array

Source code
template <size_t Size>
void apply(T (&buffer)[Size])
{
    process_buffer(buffer, buffer, Size);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L48

template <size_t Size>
void apply(T (&dest)[Size], T (&src)[Size])

Applies filter to a static array and writes the result to another array

Source code
template <size_t Size>
void apply(T (&dest)[Size], T (&src)[Size])
{
    process_buffer(dest, src, Size);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L55

template <univector_tag Tag>
void apply(univector<T, Tag> &buffer)

Applies filter to a univector

Source code
template <univector_tag Tag>
void apply(univector<T, Tag>& buffer)
{
    process_buffer(buffer.data(), buffer.data(), buffer.size());
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L62

template <univector_tag Tag1, univector_tag Tag2>
void apply(univector<T, Tag1> &dest,
           const univector<T, Tag2> &src)

Applies filter to a univector and writes the result to another univector

Source code
template <univector_tag Tag1, univector_tag Tag2>
void apply(univector<T, Tag1>& dest, const univector<T, Tag2>& src)
{
    if (dest.empty())
        dest.resize(src.size());
    process_buffer(dest.data(), src.data(), std::min(dest.size(), src.size()));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L69

to_filter function

template <typename E, typename T = expression_value_type<E>>
expression_filter<T> to_filter(E &&e)

Converts expression with placeholder to filter. Placeholder and filter must have the same type

Source code
template <typename E, typename T = expression_value_type<E>>
KFR_INTRINSIC expression_filter<T> to_filter(E&& e)
{
    return expression_filter<T>(to_handle(std::move(e)));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L135

template <typename T, typename E>
expression_filter<T> to_filter(expression_handle<T, 1> &&e)

Converts expression with placeholder to filter. Placeholder and filter must have the same type

Source code
template <typename T, typename E>
KFR_INTRINSIC expression_filter<T> to_filter(expression_handle<T, 1>&& e)
{
    return expression_filter<T>(std::move(e));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/filter.hpp#L143


Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/