[3010] | 1 | //filter_agc.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012 |
---|
[3010] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[3010] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "libroardsp.h" |
---|
| 27 | |
---|
| 28 | int roardsp_agc_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { |
---|
| 29 | struct roardsp_agc * self = roar_mm_malloc(sizeof(struct roardsp_agc)); |
---|
| 30 | |
---|
[5270] | 31 | (void)id; |
---|
| 32 | |
---|
[3010] | 33 | if ( self == NULL ) |
---|
| 34 | return -1; |
---|
| 35 | |
---|
| 36 | memset(self, 0, sizeof(struct roardsp_agc)); |
---|
| 37 | |
---|
| 38 | if ( roardsp_filter_new(&(self->amp), stream, ROARDSP_FILTER_AMP) == -1 ) { |
---|
| 39 | roar_mm_free(self); |
---|
| 40 | return -1; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | filter->inst = (void*) self; |
---|
| 44 | |
---|
| 45 | if ( roardsp_filter_reset(filter, ROARDSP_RESET_FULL) == -1 ) { |
---|
| 46 | roardsp_agc_uninit(filter); |
---|
| 47 | return -1; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | return 0; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | int roardsp_agc_uninit (struct roardsp_filter * filter) { |
---|
| 54 | struct roardsp_agc * self = filter->inst; |
---|
| 55 | |
---|
| 56 | roardsp_filter_free(self->amp); |
---|
| 57 | roar_mm_free(self); |
---|
| 58 | return 0; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | int roardsp_agc_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
| 62 | struct roardsp_agc * self = filter->inst; |
---|
| 63 | |
---|
[4518] | 64 | (void)self; |
---|
| 65 | |
---|
[3010] | 66 | return -1; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | int roardsp_agc_reset (struct roardsp_filter * filter, int what) { |
---|
| 70 | struct roardsp_agc * self = filter->inst; |
---|
| 71 | |
---|
| 72 | switch (what) { |
---|
| 73 | case ROARDSP_RESET_NONE: |
---|
| 74 | return 0; |
---|
| 75 | break; |
---|
| 76 | case ROARDSP_RESET_FULL: |
---|
| 77 | if ( filter->bits < 4 ) |
---|
| 78 | return -1; |
---|
| 79 | |
---|
| 80 | self->target_amp = 1 << (filter->bits - 3); |
---|
| 81 | |
---|
| 82 | if ( roardsp_filter_reset(self->amp, ROARDSP_RESET_FULL) == -1 ) |
---|
| 83 | return -1; |
---|
| 84 | |
---|
| 85 | return -1; |
---|
| 86 | break; |
---|
| 87 | case ROARDSP_RESET_STATE: |
---|
| 88 | if ( roardsp_filter_reset(self->amp, ROARDSP_RESET_STATE) == -1 ) |
---|
| 89 | return -1; |
---|
| 90 | return -1; |
---|
| 91 | break; |
---|
| 92 | default: return -1; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | return 0; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | //ll |
---|