source: roaraudio/libroardsp/interleave.c @ 5889:d866fb1213d6

Last change on this file since 5889:d866fb1213d6 was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

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