• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2013 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 #ifdef HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9 
10 #include <pulsecore/macro.h>
11 
12 #include "crossover.h"
13 
lr4_set(struct lr4 * lr4,enum biquad_type type,float freq)14 void lr4_set(struct lr4 *lr4, enum biquad_type type, float freq)
15 {
16 	biquad_set(&lr4->bq, type, freq);
17 	lr4->x1 = 0;
18 	lr4->x2 = 0;
19 	lr4->y1 = 0;
20 	lr4->y2 = 0;
21 	lr4->z1 = 0;
22 	lr4->z2 = 0;
23 }
24 
lr4_process_float32(struct lr4 * lr4,int samples,int channels,float * src,float * dest)25 void lr4_process_float32(struct lr4 *lr4, int samples, int channels, float *src, float *dest)
26 {
27 	float lx1 = lr4->x1;
28 	float lx2 = lr4->x2;
29 	float ly1 = lr4->y1;
30 	float ly2 = lr4->y2;
31 	float lz1 = lr4->z1;
32 	float lz2 = lr4->z2;
33 	float lb0 = lr4->bq.b0;
34 	float lb1 = lr4->bq.b1;
35 	float lb2 = lr4->bq.b2;
36 	float la1 = lr4->bq.a1;
37 	float la2 = lr4->bq.a2;
38 
39 	int i;
40 	for (i = 0; i < samples * channels; i += channels) {
41 		float x, y, z;
42 		x = src[i];
43 		y = lb0*x + lb1*lx1 + lb2*lx2 - la1*ly1 - la2*ly2;
44 		z = lb0*y + lb1*ly1 + lb2*ly2 - la1*lz1 - la2*lz2;
45 		lx2 = lx1;
46 		lx1 = x;
47 		ly2 = ly1;
48 		ly1 = y;
49 		lz2 = lz1;
50 		lz1 = z;
51 		dest[i] = z;
52 	}
53 
54 	lr4->x1 = lx1;
55 	lr4->x2 = lx2;
56 	lr4->y1 = ly1;
57 	lr4->y2 = ly2;
58 	lr4->z1 = lz1;
59 	lr4->z2 = lz2;
60 }
61 
lr4_process_s16(struct lr4 * lr4,int samples,int channels,short * src,short * dest)62 void lr4_process_s16(struct lr4 *lr4, int samples, int channels, short *src, short *dest)
63 {
64 	float lx1 = lr4->x1;
65 	float lx2 = lr4->x2;
66 	float ly1 = lr4->y1;
67 	float ly2 = lr4->y2;
68 	float lz1 = lr4->z1;
69 	float lz2 = lr4->z2;
70 	float lb0 = lr4->bq.b0;
71 	float lb1 = lr4->bq.b1;
72 	float lb2 = lr4->bq.b2;
73 	float la1 = lr4->bq.a1;
74 	float la2 = lr4->bq.a2;
75 
76 	int i;
77 	for (i = 0; i < samples * channels; i += channels) {
78 		float x, y, z;
79 		x = src[i];
80 		y = lb0*x + lb1*lx1 + lb2*lx2 - la1*ly1 - la2*ly2;
81 		z = lb0*y + lb1*ly1 + lb2*ly2 - la1*lz1 - la2*lz2;
82 		lx2 = lx1;
83 		lx1 = x;
84 		ly2 = ly1;
85 		ly1 = y;
86 		lz2 = lz1;
87 		lz1 = z;
88 		dest[i] = PA_CLAMP_UNLIKELY((int) z, -0x8000, 0x7fff);
89 	}
90 
91 	lr4->x1 = lx1;
92 	lr4->x2 = lx2;
93 	lr4->y1 = ly1;
94 	lr4->y2 = ly2;
95 	lr4->z1 = lz1;
96 	lr4->z2 = lz2;
97 }
98