source: roaraudio/libroardsp/filter_clip.c @ 979:2d5a48c15b5f

Last change on this file since 979:2d5a48c15b5f was 979:2d5a48c15b5f, checked in by phi, 15 years ago

added new filter: Add, Quantifier, Clip

File size: 1.8 KB
Line 
1//clip.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - December 2008
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "libroardsp.h"
26
27int roardsp_clip_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
28 int n = 64;
29
30 roardsp_amp_ctl(filter, ROARDSP_FCTL_N, &n);
31
32 return 0;
33}
34
35int roardsp_clip_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
36 int16_t * samp = (int16_t *) data;
37 register int32_t s = (int32_t)filter->inst;
38 size_t i;
39
40 for (i = 0; i < samples; i++) {
41  if ( samp[i] > s ) {
42   samp[i]  = s;
43  } else if ( -samp[i] > s ) {
44   samp[i]  = -s;
45  }
46 }
47
48 ROAR_DBG("roardsp_quantify_calc16(*) = 0");
49 return 0;
50}
51
52int roardsp_clip_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
53 int32_t old;
54
55 if ( cmd == ROARDSP_FCTL_LIMIT ) {
56  old = (int32_t)filter->inst;
57  filter->inst = (void*)labs(*(int32_t*)data);
58  *(int32_t*)data = old;
59 } else {
60  ROAR_DBG("roardsp_clip_ctl(*) = -1");
61  return -1;
62 }
63
64
65 ROAR_DBG("roardsp_clip_ctl(*) = 0");
66 return 0;
67}
68
69//ll
Note: See TracBrowser for help on using the repository browser.