source: roaraudio/libroardsp/interleave.c @ 3329:d939b3aedbc5

Last change on this file since 3329:d939b3aedbc5 was 3037:c1821f5d7d60, checked in by phi, 14 years ago

wrote interleaver...

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