bitvec

Capsim Block Documentation

Short Description

This star converts a bit stream to variable length vectors.

Top
Input Connections
Port Type Name
0 float y
Top
Output Connections
Port Type Name
0 byteVector_t x
Top
States
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
Top

Declarations


 

	int no_samples;
	int i,j,k,kk;
	long	templ;
	byteVector_t 	codedBlock;
	int	bit;
	short	*decode_P;



Top

Initialization Code



 





Top

Main Code



 

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);




Top

Wrapup Code



 





Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP 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://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/* bitvec.s */
/***********************************************************************
                             bitvec()
************************************************************************

bitvec


This star converts a bit stream to variable length vectors.
Note that the END of a stream segment is designated by an 0xff followed by
a non zero byte. 
Each segment is packed into bytes. A vector with a pointer to the
bytes and  the length of the vector is output. The output contains the
0xFF and following byte.
At the beginning, a 16 byte array is allocated. If more bytes are needed
a reallocation takes place.


Programmer:  	Sasan Ardalan	
Date: 		Nov. 22, 1993

*/