source: roaraudio/libroardsp/filter_quantify.c @ 5381:430b1d26e12d

Last change on this file since 5381:430b1d26e12d was 5381:430b1d26e12d, checked in by phi, 12 years ago

updated copyright years

File size: 2.6 KB
Line 
1//filter_quantify.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
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 (void)stream, (void)id;
31
32 roardsp_filter_reset(filter, ROARDSP_RESET_FULL);
33
34 return 0;
35}
36
37static 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}
46
47#define _calcX(bits,rshift,lshift,ibits) \
48/* this code is buggy for 8 bit filters */ \
49int 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++) { \
54  samp[i]  = (int##ibits##_t)_calc((int##ibits##_t)samp[i] rshift, filter->inst) lshift; \
55 } \
56\
57 ROAR_DBG("roardsp_quantify_calc%i(*) = 0", bits); \
58 return 0; \
59}
60
61/* look at our nice parameters ;) */
62_calcX(8,<< 8,>> 8,16)
63_calcX(16,,,16)
64_calcX(32,>> 16,<< 16,32)
65
66int roardsp_quantify_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
67 int32_t old;
68
69 if ( cmd == ROARDSP_FCTL_N ) {
70  old = (ROAR_INSTINT)filter->inst;
71  filter->inst = (void*)(ROAR_INSTINT)*(int32_t*)data;
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
83int 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
105//ll
Note: See TracBrowser for help on using the repository browser.