1 /* Copyright 2017 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #include <stdlib.h> 7 #include "dcblock.h" 8 9 struct dcblock { 10 float R; 11 float x_prev; 12 float y_prev; 13 }; 14 dcblock_new(float R)15struct dcblock *dcblock_new(float R) 16 { 17 struct dcblock *dcblock = (struct dcblock *)calloc(1, sizeof(*dcblock)); 18 dcblock->R = R; 19 return dcblock; 20 } 21 dcblock_free(struct dcblock * dcblock)22void dcblock_free(struct dcblock *dcblock) 23 { 24 free(dcblock); 25 } 26 27 /* This is the prototype of the processing loop. */ dcblock_process(struct dcblock * dcblock,float * data,int count)28void dcblock_process(struct dcblock *dcblock, float *data, int count) 29 { 30 int n; 31 float x_prev = dcblock->x_prev; 32 float y_prev = dcblock->y_prev; 33 float R = dcblock->R; 34 for (n = 0; n < count; n++) { 35 float x = data[n]; 36 data[n] = x - x_prev + R * y_prev; 37 y_prev = data[n]; 38 x_prev = x; 39 } 40 dcblock->x_prev = x_prev; 41 dcblock->y_prev = y_prev; 42 } 43