source: roaraudio/libroardsp/filter_clip.c @ 3003:9d0935291fca

Last change on this file since 3003:9d0935291fca was 1492:1e1b7fabd0b6, checked in by phi, 15 years ago

corrected wronge cast from int to void*

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