source: roaraudio/libroardsp/filter_swap.c @ 5181:ca57e34b2a35

Last change on this file since 5181:ca57e34b2a35 was 5181:ca57e34b2a35, checked in by phi, 13 years ago

updated filters to support 8 and 32 bit as well as 16 bit

File size: 2.6 KB
Line 
1//filter_swap.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "libroardsp.h"
27
28int roardsp_swap_init   (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
29 struct roardsp_swap * inst = roar_mm_malloc(sizeof(struct roardsp_swap));
30
31 ROAR_DBG("roardsp_swap_init(*): inst=%p", inst);
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);
42}
43
44int roardsp_swap_uninit (struct roardsp_filter * filter) {
45 if ( filter == NULL )
46  return -1;
47
48 if ( filter->inst == NULL )
49  return -1;
50
51 roar_mm_free(filter->inst);
52
53 return 0;
54}
55
56#define _calcX2(bits) \
57int roardsp_swap_calc##bits##2(struct roardsp_filter * filter, void * data, size_t samples) { \
58 int##bits##_t * d = data; \
59 register int##bits##_t s; \
60 size_t i; \
61\
62 for (i = 0; i < samples; i += 2) { \
63  ROAR_DBG("roardsp_swap_calc*2(*): d[i]=%i, d[i+1]=%i", d[i], d[i+1]); \
64  s      = d[i]; \
65  d[i]   = d[i+1]; \
66  d[i+1] = s; \
67 } \
68\
69 return 0; \
70}
71
72_calcX2(8)
73_calcX2(16)
74_calcX2(32)
75
76int roardsp_swap_ctl    (struct roardsp_filter * filter, int cmd, void * data) {
77 return -1;
78}
79
80int roardsp_swap_reset  (struct roardsp_filter * filter, int what) {
81 struct roardsp_swap * inst = NULL;
82 int i;
83
84 if ( filter == NULL )
85  return -1;
86
87 if ( (inst = filter->inst) == NULL )
88  return -1;
89
90 switch (what) {
91  case ROARDSP_RESET_NONE:
92  case ROARDSP_RESET_STATE:
93    return  0;
94   break;
95  case ROARDSP_RESET_FULL:
96    memset(inst, 0, sizeof(struct roardsp_swap));
97
98    for (i = 0; i < ROAR_MAX_CHANNELS; i++)
99     inst->map[i] = i;
100
101    inst->map[0] = 1;
102    inst->map[1] = 0;
103    return  0;
104   break;
105  default:
106    return -1;
107 }
108
109 return -1;
110}
111
112//ll
Note: See TracBrowser for help on using the repository browser.