<commit_before>/// @file
///	@ingroup 	minlib
/// @author		<NAME>, <NAME>, <NAME>
///	@copyright	Copyright (c) 2017, Cycling '74
///	@license	Usage of this file and its contents is governed by the MIT License

#pragma once

namespace c74 {
namespace min {
namespace lib {

	
	///	A single-channel generalized allpass filter.

	class allpass {
	public:

		/// Default constructor with minimum number of initial values.
        /// @param	capacity		Sets capacity in samples for feedforward and feedback history.
        ///							Default value is 4410 samples. Capacity is fixed at creation.
		/// @param	initial_gain	Sets the gain coefficient that is applied to samples from history.
		///							Default value is 0.0.

		explicit allpass(std::size_t capacity = 4410, number initial_gain = 0.0)
		: m_feedforward_history(capacity)
		, m_feedback_history(capacity)
		{
			this->gain(initial_gain);
		}
        
        
        /// Constructor with initial values for capacity, size, and gain.
        /// @param  capacity_and_size	Sets capacity and size in samples for feedforward and feedback history.
        ///								Uses std::pair to ensure values are set together. Capacity is fixed at creation.
		/// @param	initial_gain		Sets the gain coefficient that is applied to samples from history.
		///								Default value is 0.0.
        
        explicit allpass(std::pair<size_t, size_t> capacity_and_size, number initial_gain = 0.0)
        : m_feedforward_history(capacity_and_size)
        , m_feedback_history(capacity_and_size)
        {
            this->gain(initial_gain);
        }


		/// Set a new delay time in samples.
		/// @param	new_size	The new delay time in samples.
		///						Note this may not exceed the capacity set when the object instance is created.

		void delay(size_t new_size) {
			m_feedforward_history.resize(new_size);
			m_feedback_history.resize(new_size);
		};


		/// Return the current delay time in samples.
		/// @return The delay time in samples.

		size_t delay() {
			return m_feedforward_history.size();
		};


		/// Set the feedback coefficient.
		/// @param	new_gain	The new feedback coefficient.

		void gain(number new_gain) {
			m_gain = new_gain;
		}


		/// Return the value of the feedback coefficient
		/// @return The current feedback coefficient.

		number gain() {
			return m_gain;
		}


		///	This algorithm is an IIR filter, meaning that it relies on feedback.  If the filter should
		///	not be producing any signal (such as turning audio off and then back on in a host) or if the
		///	feedback has become corrupted (such as might happen if a NaN is fed in) then it may be
		///	neccesary to clear the filter by calling this method.

		void clear() {
			m_feedforward_history.clear();
			m_feedback_history.clear();
		}

		
		/// Calculate one sample.
		///	@return		Calculated sample

		sample operator()(sample x) {
			auto x1 = m_feedforward_history.tail();
			auto y1 = m_feedback_history.tail();
			auto alpha = m_gain;

			// Store the input in the feedforward buffer
			m_feedforward_history.write(x);

			// Apply the filter
			// We start with the equation in standard form:
			//		y = -alpha * x  +  x1  +  alpha * y1;
			// Then to a version that <NAME> refers to as a "Re-Ordered All-Pass Filter Structure" in Multirate Signal Processing
			//		y = x1  +  alpha * y1  -  alpha * x;
			// Finally, here is a "Single Coefficient All-Pass Filter", dropping from 2 adds and 2 mults down to 2 adds and 1 mult
			auto y = x1 + ((y1 - x) * alpha);

			// Store the output in the feedback buffer
			m_feedback_history.write(y);

			return y;
		}

	private:
		circular_storage<sample>	m_feedforward_history;	///< Delay line for the FIR side of the filter.
		circular_storage<sample>	m_feedback_history;		///< Delay line for the IIR side of the filter.
		number						m_gain {};				///< Feedback coefficient.
	};


}}}  // namespace c74::min::lib<commit_msg>allpass: successfully refactored m_feedforward_history using delay instead of circular_storage. PASSES TESTS. see Cycling74/min-lib/issues/26<commit_after>/// @file
///	@ingroup 	minlib
/// @author		<NAME>, <NAME>, <NAME>
///	@copyright	Copyright (c) 2017, Cycling '74
///	@license	Usage of this file and its contents is governed by the MIT License

#pragma once

#include "c74_lib_delay.h"

namespace c74 {
namespace min {
namespace lib {

	
	///	A single-channel generalized allpass filter.

	class allpass {
	public:

		/// Default constructor with minimum number of initial values.
        /// @param	capacity		Sets capacity in samples for feedforward and feedback history.
        ///							Default value is 4410 samples. Capacity is fixed at creation.
		/// @param	initial_gain	Sets the gain coefficient that is applied to samples from history.
		///							Default value is 0.0.

		explicit allpass(std::size_t capacity = 4410, number initial_gain = 0.0)
		: m_feedforward_history(capacity)
		, m_feedback_history(capacity)
		{
			this->gain(initial_gain);
		}
        
        
        /// Constructor with initial values for capacity, size, and gain.
        /// @param  capacity_and_size	Sets capacity and size in samples for feedforward and feedback history.
        ///								Uses std::pair to ensure values are set together. Capacity is fixed at creation.
		/// @param	initial_gain		Sets the gain coefficient that is applied to samples from history.
		///								Default value is 0.0.
        
        explicit allpass(std::pair<size_t, size_t> capacity_and_size, number initial_gain = 0.0)
        : m_feedforward_history(capacity_and_size)
        , m_feedback_history(capacity_and_size)
        {
            this->gain(initial_gain);
        }


		/// Set a new delay time in samples.
		/// @param	new_size	The new delay time in samples.
		///						Note this may not exceed the capacity set when the object instance is created.

		void delay(size_t new_size) {
			m_feedforward_history.size(new_size);
			m_feedback_history.resize(new_size);
		};


		/// Return the current delay time in samples.
		/// @return The delay time in samples.

		size_t delay() {
			return m_feedforward_history.size();
		};


		/// Set the feedback coefficient.
		/// @param	new_gain	The new feedback coefficient.

		void gain(number new_gain) {
			m_gain = new_gain;
		}


		/// Return the value of the feedback coefficient
		/// @return The current feedback coefficient.

		number gain() {
			return m_gain;
		}


		///	This algorithm is an IIR filter, meaning that it relies on feedback.  If the filter should
		///	not be producing any signal (such as turning audio off and then back on in a host) or if the
		///	feedback has become corrupted (such as might happen if a NaN is fed in) then it may be
		///	neccesary to clear the filter by calling this method.

		void clear() {
			m_feedforward_history.clear();
			m_feedback_history.clear();
		}

		
		/// Calculate one sample.
		///	@return		Calculated sample

		sample operator()(sample x) {
			auto x1 = m_feedforward_history(x);
			auto y1 = m_feedback_history.tail();
			auto alpha = m_gain;

			// Store the input in the feedforward buffer
			//m_feedforward_history.write(x);

			// Apply the filter
			// We start with the equation in standard form:
			//		y = -alpha * x  +  x1  +  alpha * y1;
			// Then to a version that <NAME> refers to as a "Re-Ordered All-Pass Filter Structure" in Multirate Signal Processing
			//		y = x1  +  alpha * y1  -  alpha * x;
			// Finally, here is a "Single Coefficient All-Pass Filter", dropping from 2 adds and 2 mults down to 2 adds and 1 mult
			auto y = x1 + ((y1 - x) * alpha);

			// Store the output in the feedback buffer
			m_feedback_history.write(y);

			return y;
		}

	private:
		c74::min::lib::delay<>		m_feedforward_history {};	///< Delay line for the FIR side of the filter.
		circular_storage<sample>	m_feedback_history;		///< Delay line for the IIR side of the filter.
		number						m_gain {};				///< Feedback coefficient.
		
	};


}}}  // namespace c74::min::lib
{'fraction_non_alphanumeric': 0.09401175146893362, 'fraction_numerical': 0.01050131266408301, 'mean_word_length': 2.691739732348869, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3711260', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2389, 'n_words': 903}