source: roaraudio/libroardsp/filter_quantify.c @ 5181:ca57e34b2a35

Last change on this file since 5181:ca57e34b2a35 was 5181:ca57e34b2a35, checked in by phi, 13 years ago

updated filters to support 8 and 32 bit as well as 16 bit

File size: 2.6 KB
Line 
1//filter_quantify.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "libroardsp.h"
27
28int roardsp_quantify_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
29
30 roardsp_filter_reset(filter, ROARDSP_RESET_FULL);
31
32 return 0;
33}
34
35static 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}
44
45#define _calcX(bits,rshift,lshift) \
46/* this code is buggy for 8 bit filters */ \
47int 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}
58
59/* look at our nice parameters ;) */
60_calcX(8,<< 8,>> 8)
61_calcX(16,,)
62_calcX(32,>> 16,<< 16)
63
64int roardsp_quantify_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
65 int32_t old;
66
67 if ( cmd == ROARDSP_FCTL_N ) {
68  old = (ROAR_INSTINT)filter->inst;
69  filter->inst = (void*)(ROAR_INSTINT)*(int32_t*)data;
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
81int 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
103//ll
Note: See TracBrowser for help on using the repository browser.