[4668] | 1 | //filter_quantify.c: |
---|
[979] | 2 | |
---|
| 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015 |
---|
[979] | 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. |
---|
[979] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "libroardsp.h" |
---|
| 27 | |
---|
| 28 | int roardsp_quantify_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { |
---|
| 29 | |
---|
[5270] | 30 | (void)stream, (void)id; |
---|
| 31 | |
---|
[1141] | 32 | roardsp_filter_reset(filter, ROARDSP_RESET_FULL); |
---|
[979] | 33 | |
---|
| 34 | return 0; |
---|
| 35 | } |
---|
| 36 | |
---|
[5181] | 37 | static inline int16_t _calc(int16_t val, void * inst) { |
---|
| 38 | register float s = val; |
---|
| 39 | s /= 32768; |
---|
| 40 | s *= (ROAR_INSTINT)inst; |
---|
| 41 | s = (int16_t)s; |
---|
| 42 | s /= (ROAR_INSTINT)inst; |
---|
| 43 | s *= 32768; |
---|
| 44 | return s; |
---|
| 45 | } |
---|
[979] | 46 | |
---|
[5282] | 47 | #define _calcX(bits,rshift,lshift,ibits) \ |
---|
[5181] | 48 | /* this code is buggy for 8 bit filters */ \ |
---|
| 49 | int roardsp_quantify_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ |
---|
| 50 | int##bits##_t * samp = (int##bits##_t *) data; \ |
---|
| 51 | size_t i; \ |
---|
| 52 | \ |
---|
| 53 | for (i = 0; i < samples; i++) { \ |
---|
[5282] | 54 | samp[i] = (int##ibits##_t)_calc((int##ibits##_t)samp[i] rshift, filter->inst) lshift; \ |
---|
[5181] | 55 | } \ |
---|
| 56 | \ |
---|
| 57 | ROAR_DBG("roardsp_quantify_calc%i(*) = 0", bits); \ |
---|
| 58 | return 0; \ |
---|
| 59 | } |
---|
[979] | 60 | |
---|
[5181] | 61 | /* look at our nice parameters ;) */ |
---|
[5282] | 62 | _calcX(8,<< 8,>> 8,16) |
---|
| 63 | _calcX(16,,,16) |
---|
| 64 | _calcX(32,>> 16,<< 16,32) |
---|
[979] | 65 | |
---|
| 66 | int roardsp_quantify_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
| 67 | int32_t old; |
---|
| 68 | |
---|
| 69 | if ( cmd == ROARDSP_FCTL_N ) { |
---|
[987] | 70 | old = (ROAR_INSTINT)filter->inst; |
---|
| 71 | filter->inst = (void*)(ROAR_INSTINT)*(int32_t*)data; |
---|
[979] | 72 | *(int32_t*)data = old; |
---|
| 73 | } else { |
---|
| 74 | ROAR_DBG("roardsp_quantify_ctl(*) = -1"); |
---|
| 75 | return -1; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | ROAR_DBG("roardsp_quantify_ctl(*) = 0"); |
---|
| 80 | return 0; |
---|
| 81 | } |
---|
| 82 | |
---|
[1141] | 83 | int roardsp_quantify_reset (struct roardsp_filter * filter, int what) { |
---|
| 84 | int n = 64; |
---|
| 85 | |
---|
| 86 | if ( filter == NULL ) |
---|
| 87 | return -1; |
---|
| 88 | |
---|
| 89 | switch (what) { |
---|
| 90 | case ROARDSP_RESET_NONE: |
---|
| 91 | case ROARDSP_RESET_STATE: |
---|
| 92 | return 0; |
---|
| 93 | break; |
---|
| 94 | case ROARDSP_RESET_FULL: |
---|
| 95 | roardsp_quantify_ctl(filter, ROARDSP_FCTL_N, &n); |
---|
| 96 | return 0; |
---|
| 97 | break; |
---|
| 98 | default: |
---|
| 99 | return -1; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | return -1; |
---|
| 103 | } |
---|
| 104 | |
---|
[979] | 105 | //ll |
---|