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