[4668] | 1 | //filter_swap.c: |
---|
[1586] | 2 | |
---|
| 3 | /* |
---|
[3811] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010 |
---|
[1586] | 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. |
---|
[1586] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "libroardsp.h" |
---|
| 27 | |
---|
[1587] | 28 | int roardsp_swap_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { |
---|
[3001] | 29 | struct roardsp_swap * inst = roar_mm_malloc(sizeof(struct roardsp_swap)); |
---|
[1588] | 30 | |
---|
[3000] | 31 | ROAR_DBG("roardsp_swap_init(*): inst=%p", inst); |
---|
[1588] | 32 | |
---|
| 33 | if ( inst == NULL ) { |
---|
| 34 | ROAR_ERR("roardsp_swap_init(*): Can not alloc memory for filter swap: %s", strerror(errno)); |
---|
| 35 | filter->inst = NULL; |
---|
| 36 | return -1; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | filter->inst = inst; |
---|
| 40 | |
---|
| 41 | return roardsp_swap_reset(filter, ROARDSP_RESET_FULL); |
---|
[1587] | 42 | } |
---|
| 43 | |
---|
| 44 | int roardsp_swap_uninit (struct roardsp_filter * filter) { |
---|
[1588] | 45 | if ( filter == NULL ) |
---|
| 46 | return -1; |
---|
| 47 | |
---|
| 48 | if ( filter->inst == NULL ) |
---|
| 49 | return -1; |
---|
| 50 | |
---|
[3001] | 51 | roar_mm_free(filter->inst); |
---|
[1588] | 52 | |
---|
| 53 | return 0; |
---|
[1587] | 54 | } |
---|
| 55 | |
---|
| 56 | int roardsp_swap_calc162(struct roardsp_filter * filter, void * data, size_t samples) { |
---|
[1588] | 57 | int16_t * d = data; |
---|
| 58 | register int16_t s; |
---|
| 59 | int i; |
---|
| 60 | |
---|
| 61 | for (i = 0; i < samples; i += 2) { |
---|
[3000] | 62 | ROAR_DBG("roardsp_swap_calc162(*): d[i]=%i, d[i+1]=%i", d[i], d[i+1]); |
---|
[1588] | 63 | s = d[i]; |
---|
| 64 | d[i] = d[i+1]; |
---|
| 65 | d[i+1] = s; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | return 0; |
---|
[1587] | 69 | } |
---|
| 70 | |
---|
| 71 | int roardsp_swap_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
| 72 | return -1; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | int roardsp_swap_reset (struct roardsp_filter * filter, int what) { |
---|
[1588] | 76 | struct roardsp_swap * inst = NULL; |
---|
| 77 | int i; |
---|
| 78 | |
---|
| 79 | if ( filter == NULL ) |
---|
| 80 | return -1; |
---|
| 81 | |
---|
| 82 | if ( (inst = filter->inst) == NULL ) |
---|
| 83 | return -1; |
---|
| 84 | |
---|
| 85 | switch (what) { |
---|
| 86 | case ROARDSP_RESET_NONE: |
---|
| 87 | case ROARDSP_RESET_STATE: |
---|
| 88 | return 0; |
---|
| 89 | break; |
---|
| 90 | case ROARDSP_RESET_FULL: |
---|
| 91 | memset(inst, 0, sizeof(struct roardsp_swap)); |
---|
| 92 | |
---|
| 93 | for (i = 0; i < ROAR_MAX_CHANNELS; i++) |
---|
| 94 | inst->map[i] = i; |
---|
| 95 | |
---|
| 96 | inst->map[0] = 1; |
---|
| 97 | inst->map[1] = 0; |
---|
| 98 | return 0; |
---|
| 99 | break; |
---|
| 100 | default: |
---|
| 101 | return -1; |
---|
| 102 | } |
---|
| 103 | |
---|
[1587] | 104 | return -1; |
---|
| 105 | } |
---|
[1586] | 106 | |
---|
| 107 | //ll |
---|