[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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[979] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "libroardsp.h" |
---|
| 27 | |
---|
| 28 | int roardsp_clip_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
| 29 | int16_t * samp = (int16_t *) data; |
---|
[987] | 30 | register int32_t s = (ROAR_INSTINT)filter->inst; |
---|
[979] | 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 | |
---|
| 45 | int roardsp_clip_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
| 46 | int32_t old; |
---|
| 47 | |
---|
| 48 | if ( cmd == ROARDSP_FCTL_LIMIT ) { |
---|
[987] | 49 | old = (ROAR_INSTINT)filter->inst; |
---|
[1492] | 50 | filter->inst = (void*)(ROAR_INSTINT)labs(*(int32_t*)data); |
---|
[979] | 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 | |
---|
[1141] | 62 | int 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 | |
---|
[979] | 84 | //ll |
---|