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 write 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_pointer<T>& src)
    {
        process_expression(dest.data(), src, size_min(dest.size(), src.size()));
    }

    void apply(T* dest, const expression_pointer<T>& 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>::value)>
    void apply(univector<T, Tag>& dest, const Expr& src)
    {
        process_expression(dest.data(), to_pointer(src), size_min(dest.size(), src.size()));
    }

    template <typename Expr, KFR_ENABLE_IF(is_input_expression<Expr>::value)>
    void apply(T* dest, const Expr& src, size_t size)
    {
        process_expression(dest, to_pointer(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_pointer<T>& src, size_t size) = 0;
}

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

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#L46

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#L50

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#L57

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#L64

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

Applies filter to a univector and write 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#L71

to_filter function

template <typename E, typename T = value_type_of<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 = value_type_of<E>>
KFR_INTRINSIC expression_filter<T> to_filter(E&& e)
{
    return expression_filter<T>(to_pointer(std::move(e)));
}

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

template <typename T, typename E>
expression_filter<T> to_filter(expression_pointer<T> &&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_pointer<T>&& 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/