[979] | 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 | |
---|
| 27 | int roardsp_clip_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
| 28 | int16_t * samp = (int16_t *) data; |
---|
[987] | 29 | register int32_t s = (ROAR_INSTINT)filter->inst; |
---|
[979] | 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 | |
---|
| 44 | int roardsp_clip_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
| 45 | int32_t old; |
---|
| 46 | |
---|
| 47 | if ( cmd == ROARDSP_FCTL_LIMIT ) { |
---|
[987] | 48 | old = (ROAR_INSTINT)filter->inst; |
---|
[1492] | 49 | filter->inst = (void*)(ROAR_INSTINT)labs(*(int32_t*)data); |
---|
[979] | 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 | |
---|
[1141] | 61 | int 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 | |
---|
[979] | 83 | //ll |
---|