source: roaraudio/libroardsp/filter_swap.c @ 3001:98395340e261

Last change on this file since 3001:98395340e261 was 3001:98395340e261, checked in by phi, 15 years ago

do not use malloc()/free() but roar_mm_*()

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