dd checks/rejection for absurdly huge codebooks.
[xiph/unicode.git] / postfish / linkage.c
blobc091e7d63715ddf5593772389537d0c6c2c4b8a7
1 /*
3 * postfish
4 *
5 * Copyright (C) 2002-2005 Monty
7 * Postfish is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * Postfish is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Postfish; see the file COPYING. If not, write to the
19 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "postfish.h"
25 #include "internal.h"
27 void time_linkage_init(time_linkage *new,int ch){
28 int i;
30 new->samples=0;
31 new->channels=ch;
32 new->active=0;
33 new->alias=0;
34 new->data=malloc(ch*sizeof(*new->data));
36 for(i=0;i<ch;i++)
37 new->data[i]=malloc(input_size*sizeof(*new->data));
40 int time_linkage_channels(time_linkage *in){
41 return in->channels;
44 int time_linkage_samples(time_linkage *in){
45 return in->samples;
48 /* in: pointer to single initialized time_linkage structure
49 out: pointer to array of (in->channels) time_linkage structures */
51 int time_linkage_init_alias_split(time_linkage *in,time_linkage *out){
52 int i;
53 int ch=in->channels;
55 for(i=0;i<ch;i++){
56 out[i].samples=0;
57 out[i].channels=1;
58 out[i].active=0;
59 out[i].alias=1;
60 out[i].data=malloc(sizeof(*out->data));
61 out[i].data[0]=in->data[i];
63 return 0;
66 /* in: pointer to array of ch initialized time_linkage structs
67 out: pointer to single uninitialized time_linkage struct
68 ch: number of input linkages, number of channels in output linkage */
70 void time_linkage_init_alias_combine(time_linkage *in,time_linkage *out,int ch){
71 int i;
73 out->alias=1;
74 out->samples=0;
75 out->channels=ch;
76 out->active=0;
77 out->data=malloc(ch*sizeof(*out->data));
79 for(i=0;i<ch;i++)
80 out->data[i]=in[i].data[0];
83 void time_linkage_swap(time_linkage *a, time_linkage *b){
84 float **dtmp=a->data;
85 int ctmp=a->channels;
86 int stmp=a->samples;
87 u_int32_t atmp=a->active;
89 a->data=b->data;
90 b->data=dtmp;
92 a->channels=b->channels;
93 b->channels=ctmp;
95 a->samples=b->samples;
96 b->samples=stmp;
98 a->active=b->active;
99 b->active=atmp;
102 void time_linkage_clear(time_linkage *in){
103 int i;
104 for(i=0;i<in->channels;i++)
105 memset(in->data[i],0,sizeof(**in->data)*input_size);
106 in->samples=0;
107 in->active=0;
110 int time_linkage_copy(time_linkage *dest,time_linkage *src){
111 int i;
112 if(dest->channels != src->channels)return -1;
114 for(i=0;i<dest->channels;i++)
115 memcpy(dest->data[i],src->data[i],input_size*sizeof(**src->data));
116 dest->samples=src->samples;
117 dest->active=src->active;
119 return 0;