source: roaraudio/libroardsp/filter_clip.c @ 4668:0c34aa4e8ccf

Last change on this file since 4668:0c34aa4e8ccf was 4668:0c34aa4e8ccf, checked in by phi, 13 years ago

some typos in filenames...

File size: 2.0 KB
Line 
1//filter_clip.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
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_clip_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
29 int16_t * samp = (int16_t *) data;
30 register int32_t s = (ROAR_INSTINT)filter->inst;
31 size_t i;
32
33 for (i = 0; i < samples; i++) {
34  if ( samp[i] > s ) {
35   samp[i]  = s;
36  } else if ( -samp[i] > s ) {
37   samp[i]  = -s;
38  }
39 }
40
41 ROAR_DBG("roardsp_quantify_calc16(*) = 0");
42 return 0;
43}
44
45int roardsp_clip_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
46 int32_t old;
47
48 if ( cmd == ROARDSP_FCTL_LIMIT ) {
49  old = (ROAR_INSTINT)filter->inst;
50  filter->inst = (void*)(ROAR_INSTINT)labs(*(int32_t*)data);
51  *(int32_t*)data = old;
52 } else {
53  ROAR_DBG("roardsp_clip_ctl(*) = -1");
54  return -1;
55 }
56
57
58 ROAR_DBG("roardsp_clip_ctl(*) = 0");
59 return 0;
60}
61
62int roardsp_clip_reset (struct roardsp_filter * filter, int what) {
63 int32_t n = 16384;
64
65 if ( filter == NULL )
66  return -1;
67
68 switch (what) {
69  case ROARDSP_RESET_NONE:
70  case ROARDSP_RESET_STATE:
71    return  0;
72   break;
73  case ROARDSP_RESET_FULL:
74    roardsp_clip_ctl(filter, ROARDSP_FCTL_LIMIT, &n);
75    return  0;
76   break;
77  default:
78    return -1;
79 }
80
81 return -1;
82}
83
84//ll
Note: See TracBrowser for help on using the repository browser.