source: roaraudio/libroardsp/interleave.c @ 3811:49db840fb4f4

Last change on this file since 3811:49db840fb4f4 was 3811:49db840fb4f4, checked in by phi, 14 years ago

fixed some copyright statements

File size: 2.9 KB
Line 
1//interleave.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010
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 roar_interl_init  (struct roar_interleave * state, size_t channels, size_t bits) {
29 if ( state == NULL )
30  return -1;
31
32 // we can currently only hanle full bytes:
33 if ( bits % 8 )
34  return -1;
35
36 // currently we have a channel limit
37 if ( channels > ROAR_INTERLEAVE_MAX_CHANNELS )
38  return -1;
39
40 memset(state, 0, sizeof(struct roar_interleave));
41
42 state->channels = channels;
43 state->bits     = bits;
44
45 return 0;
46}
47
48int roar_interl_uninit(struct roar_interleave * state) {
49 if ( state == NULL )
50  return -1;
51
52 memset(state, 0, sizeof(struct roar_interleave));
53
54 return 0;
55}
56
57int roar_interl_ctl   (struct roar_interleave * state, int cmd, void * data) {
58 if ( state == NULL )
59  return -1;
60
61 return -1;
62}
63
64int roar_interl_encode_ext(struct roar_interleave * state, void ** in, void  * out, size_t len) {
65 size_t chan = 0;
66 size_t oc;
67 size_t bc   = 0; // bit counter
68 char   * ip[ROAR_INTERLEAVE_MAX_CHANNELS]; // output pointer
69
70 if ( state == NULL )
71  return -1;
72
73 if ( in == NULL || out == NULL )
74  return -1;
75
76 if ( len == 0 )
77  return 0;
78
79 memcpy(ip, in, sizeof(void*)*state->channels);
80
81 for (oc = 0; oc < len; oc++) {
82  ((char*)out)[oc] = *(ip[chan]);
83  ip[chan]++;
84
85  bc += 8;
86
87  if ( bc == state->bits ) {
88   bc = 0;
89   chan++;
90   if ( chan == state->channels )
91    chan = 0;
92  }
93 }
94
95 return -1;
96}
97
98int roar_interl_decode_ext(struct roar_interleave * state, void * in, void ** out, size_t len) {
99 size_t chan = 0;
100 size_t ic;       // input counter
101 size_t bc   = 0; // bit counter
102 char   * op[ROAR_INTERLEAVE_MAX_CHANNELS]; // output pointer
103
104 if ( state == NULL )
105  return -1;
106
107 if ( in == NULL || out == NULL )
108  return -1;
109
110 if ( len == 0 )
111  return 0;
112
113 memcpy(op, out, sizeof(void*)*state->channels);
114
115 for (ic = 0; ic < len; ic++) {
116  // get char and copy it
117  *(op[chan]) = ((char*)in)[ic];
118  op[chan]++;
119
120  bc += 8;
121
122  if ( bc == state->bits ) {
123   bc = 0;
124   chan++;
125   if ( chan == state->channels )
126    chan = 0;
127  }
128 }
129
130 return -1;
131}
132
133//ll
Note: See TracBrowser for help on using the repository browser.