Capsim Block Documentation
This star converts a bit stream to variable length vectors.
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | y |
| Port | Type | Name | |
|---|---|---|---|
| 0 | byteVector_t | x |
| Num | Type | Name | Initial Value | Description |
|---|---|---|---|---|
| 0 | UINT8 | byteval | 0 | |
| 1 | int | bitCount | 0 | |
| 2 | int | byteCount | 0 | |
| 3 | UINT8* | vect_P | ||
| 4 | int | markerFlag | 0 |
int no_samples; int i,j,k,kk; long templ; byteVector_t codedBlock; int bit; short *decode_P; |
|---|
for (no_samples = MIN_AVAIL(); no_samples > 0; --no_samples) {
/*
* collect the bits
*/
IT_IN(0);
bit=(int)(y(0)+0.001);
byteval |= (bit << bitCount);
bitCount += 1;
if(bitCount == 8) {
if(vect_P==NULL) {
vect_P=(unsigned char*)malloc(16*sizeof(char));
if(vect_P == NULL) {
fprintf(stderr,"bitvec: could not allocate space\n");
return(2);
}
}
vect_P[byteCount]=byteval;
byteCount++;
if(!(byteCount % 16)) {
/*
* time to reallocate vect_P in 16 byte chunks
*/
vect_P=(unsigned char*)realloc((char*)vect_P,
sizeof(char)*(byteCount+16));
if(vect_P == NULL) {
fprintf(stderr,"bitvec: could not allocate space\n");
return(3);
}
}
if(markerFlag) {
if(byteval) {
/*
* found marker
* package vector and length and output
*/
codedBlock.length=byteCount;
codedBlock.vector_P=vect_P;
if(IT_OUT(0) ){ KrnOverflow("bitvec",0); return(99); }
x(0) = codedBlock;
/*
* set vect_P to NULL so that it will be allocated
* for next segment
*/
vect_P=NULL;
/*
* reset all others
*/
byteCount=0;
markerFlag=0;
} else {
/*
* 0xFF followed by a zero. Treat as regular data
* so reset markerFlag
*/
markerFlag=0;
}
}
if(byteval == 0xff) {
markerFlag=1;
}
byteval=0;
bitCount=0;
}
}
return(0);
|
|---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
Copyright (C) 1989-2002 XCAD Corporation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://capsimtmk.sourceforge.net
XCAD Corporation
Raleigh, North Carolina */
|
|---|
/* bitvec.s */
/***********************************************************************
bitvec()
************************************************************************
|
|---|