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