1 | //filter_agc.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
5 | * |
---|
6 | * This file is part of libroardsp a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * libroardsp is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
22 | * |
---|
23 | */ |
---|
24 | |
---|
25 | #include "libroardsp.h" |
---|
26 | |
---|
27 | int roardsp_agc_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { |
---|
28 | struct roardsp_agc * self = roar_mm_malloc(sizeof(struct roardsp_agc)); |
---|
29 | |
---|
30 | if ( self == NULL ) |
---|
31 | return -1; |
---|
32 | |
---|
33 | memset(self, 0, sizeof(struct roardsp_agc)); |
---|
34 | |
---|
35 | if ( roardsp_filter_new(&(self->amp), stream, ROARDSP_FILTER_AMP) == -1 ) { |
---|
36 | roar_mm_free(self); |
---|
37 | return -1; |
---|
38 | } |
---|
39 | |
---|
40 | filter->inst = (void*) self; |
---|
41 | |
---|
42 | if ( roardsp_filter_reset(filter, ROARDSP_RESET_FULL) == -1 ) { |
---|
43 | roardsp_agc_uninit(filter); |
---|
44 | return -1; |
---|
45 | } |
---|
46 | |
---|
47 | return 0; |
---|
48 | } |
---|
49 | |
---|
50 | int roardsp_agc_uninit (struct roardsp_filter * filter) { |
---|
51 | struct roardsp_agc * self = filter->inst; |
---|
52 | |
---|
53 | roardsp_filter_free(self->amp); |
---|
54 | roar_mm_free(self); |
---|
55 | return 0; |
---|
56 | } |
---|
57 | |
---|
58 | int roardsp_agc_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
59 | struct roardsp_agc * self = filter->inst; |
---|
60 | |
---|
61 | return -1; |
---|
62 | } |
---|
63 | |
---|
64 | int roardsp_agc_reset (struct roardsp_filter * filter, int what) { |
---|
65 | struct roardsp_agc * self = filter->inst; |
---|
66 | |
---|
67 | switch (what) { |
---|
68 | case ROARDSP_RESET_NONE: |
---|
69 | return 0; |
---|
70 | break; |
---|
71 | case ROARDSP_RESET_FULL: |
---|
72 | if ( filter->bits < 4 ) |
---|
73 | return -1; |
---|
74 | |
---|
75 | self->target_amp = 1 << (filter->bits - 3); |
---|
76 | |
---|
77 | if ( roardsp_filter_reset(self->amp, ROARDSP_RESET_FULL) == -1 ) |
---|
78 | return -1; |
---|
79 | |
---|
80 | return -1; |
---|
81 | break; |
---|
82 | case ROARDSP_RESET_STATE: |
---|
83 | if ( roardsp_filter_reset(self->amp, ROARDSP_RESET_STATE) == -1 ) |
---|
84 | return -1; |
---|
85 | return -1; |
---|
86 | break; |
---|
87 | default: return -1; |
---|
88 | } |
---|
89 | |
---|
90 | return 0; |
---|
91 | } |
---|
92 | |
---|
93 | //ll |
---|