[4668] | 1 | //filter_amp.c: |
---|
[882] | 2 | |
---|
| 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015 |
---|
[882] | 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. |
---|
[882] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "libroardsp.h" |
---|
| 27 | |
---|
| 28 | int roardsp_amp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { |
---|
[3001] | 29 | struct roardsp_amp * self = roar_mm_malloc(sizeof(struct roardsp_amp)); |
---|
[882] | 30 | |
---|
[5270] | 31 | (void)stream, (void)id; |
---|
| 32 | |
---|
[882] | 33 | if ( self == NULL ) |
---|
| 34 | return -1; |
---|
| 35 | |
---|
| 36 | memset(self, 0, sizeof(struct roardsp_amp)); |
---|
| 37 | |
---|
| 38 | filter->inst = (void*) self; |
---|
| 39 | |
---|
[1141] | 40 | roardsp_filter_reset(filter, ROARDSP_RESET_FULL); |
---|
[882] | 41 | |
---|
| 42 | return 0; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | int roardsp_amp_uninit(struct roardsp_filter * filter) { |
---|
| 46 | |
---|
[3001] | 47 | roar_mm_free(filter->inst); |
---|
[882] | 48 | return 0; |
---|
| 49 | } |
---|
| 50 | |
---|
[5181] | 51 | #define _calcX(bits,twobits) \ |
---|
| 52 | int roardsp_amp_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ |
---|
| 53 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; \ |
---|
| 54 | int##bits##_t * samp = (int##bits##_t *) data; \ |
---|
| 55 | register int##twobits##_t s; \ |
---|
| 56 | size_t i; \ |
---|
| 57 | \ |
---|
| 58 | for (i = 0; i < samples; i++) { \ |
---|
| 59 | s = samp[i]; \ |
---|
| 60 | s *= self->mul; \ |
---|
| 61 | s /= self->div; \ |
---|
| 62 | samp[i] = s; \ |
---|
| 63 | }; \ |
---|
| 64 | \ |
---|
| 65 | return 0; \ |
---|
[882] | 66 | } |
---|
| 67 | |
---|
[5181] | 68 | _calcX(8,16) |
---|
| 69 | _calcX(16,32) |
---|
| 70 | _calcX(32,64) |
---|
[882] | 71 | |
---|
| 72 | int roardsp_amp_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
| 73 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
| 74 | int32_t old; |
---|
| 75 | |
---|
| 76 | if ( cmd == ROARDSP_FCTL_MUL ) { |
---|
| 77 | old = self->div; |
---|
| 78 | self->mul = *(int32_t*)data; |
---|
| 79 | *(int32_t*)data = old; |
---|
| 80 | } else if ( cmd == ROARDSP_FCTL_DIV ) { |
---|
| 81 | old = self->div; |
---|
| 82 | self->div = *(int32_t*)data; |
---|
| 83 | *(int32_t*)data = old; |
---|
| 84 | } else { |
---|
| 85 | return -1; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | return 0; |
---|
| 90 | } |
---|
| 91 | |
---|
[1141] | 92 | int roardsp_amp_reset (struct roardsp_filter * filter, int what) { |
---|
| 93 | struct roardsp_amp * self; |
---|
| 94 | |
---|
| 95 | if ( filter == NULL ) |
---|
| 96 | return -1; |
---|
| 97 | |
---|
| 98 | if ( filter->inst == NULL ) |
---|
| 99 | return -1; |
---|
| 100 | |
---|
| 101 | self = filter->inst; |
---|
| 102 | |
---|
| 103 | switch (what) { |
---|
| 104 | case ROARDSP_RESET_NONE: |
---|
| 105 | case ROARDSP_RESET_STATE: |
---|
| 106 | return 0; |
---|
| 107 | break; |
---|
| 108 | case ROARDSP_RESET_FULL: |
---|
| 109 | self->mul = 1; |
---|
| 110 | self->div = 1; |
---|
| 111 | return 0; |
---|
| 112 | break; |
---|
| 113 | default: |
---|
| 114 | return -1; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return -1; |
---|
| 118 | } |
---|
| 119 | |
---|
[882] | 120 | //ll |
---|