2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "average_filter.h"
22 static double mean(double *array, int size)
26 for (int i = 0; i < size; ++i)
27 avrg = avrg + array[i];
32 average_filter::average_filter(int sz)
37 m_array = (double *)calloc(sz, sizeof(double));
40 average_filter::~average_filter()
50 double average_filter::filter(double value)
52 m_array[m_index++] = value;
54 if (m_index >= m_size) {
58 return mean(m_array, (m_ready ? m_size : m_index));
61 void average_filter::reset(void)