#include <stdint.h>
#include <time.h>
#ifndef __GCF_H__
#define __GCF_H__
typedef struct
{
int day;
int sec;
}
gcf_time;
typedef struct gcf_block_struct
{
unsigned char *buf;
int size;
int csize;
unsigned char *text;
int tlen;
char sysid[7];
char strid[7];
gcf_time start;
time_t estart;
double estart_offset; /* RL 2016 */
double sample_rate;
int format;
int records;
int samples;
int fic;
int ric;
int data[2048];
}
*gcf_block;
#define GCF_BLOCK_LEN 1024
#define GCF_EPOCH 627264000L
int gcf_dispatch (uint8_t * buf, int sz);
#endif /* __GCF_H__ */
#ifndef __GPUTIL_H__
#define __GPUTIL_H__
int gp_uint8 (uint8_t * buf);
int gp_uint16 (uint8_t * buf);
int gp_uint24 (uint8_t * buf);
int gp_uint32 (uint8_t * buf);
int gp_int8 (uint8_t * buf);
int gp_int16 (uint8_t * buf);
int gp_int24 (uint8_t * buf);
int gp_int32 (uint8_t * buf);
int gp_a_to_base36 (char *a);
char *gp_base36_to_a (int i);
#endif /* __GPUTIL_H__ */
void warning( const char * );
int
extract_24 (gcf_block b)
{
uint8_t *ptr = b->buf;
int *optr = b->data;
int32_t val;
int n = b->samples;
ptr += 16;
val = gp_int32 (ptr);
ptr += 4;
if ( ( ( val & 0xFF800000 ) != 0 ) &&
( ( val & 0xFF800000 ) != 0xFF800000 ) ) {
warning(("claimed 24 bit data isn't"));
return 1;
}
if (gp_int24 (ptr)) {
warning(("First difference is not zero"));
return 1;
}
/* Summation must be done using 24-bit arithmetic, i.e., modulo 2^24 with */
/* silent overflow and underflow. Without a 24-bit int datatype, we use */
/* 32 bit int summands, left shifting them (multiplying by 256) into the */
/* upper 24 bits of a 32-bit int for the modular arithmetic. The sum is */
/* then arithmetically right shifted and sign extended (divided by 256) */
/* into the proper position for the int output buffer. */
/* Note: >> cannot be used for the arithmetic right shift since the C90 */
/* standard (6.3.7) says whether >> is a logical or arithmetic shift for */
/* negative signed int values is implementation-defined. Thus, >> does */
/* not guarantee a sign-extended result. We use * 256 instead of << 8 */
/* for the left shift to be consistent with the use of / 256 instead of */
/* >> 8 for the right shift. Optimizing compilers generate the same code */
/* either way. */
val *= 256;
while (n--)
{
val += gp_int24 (ptr) * 256;
ptr += 3;
*(optr++) = val / 256;
}
val /= 256;
if ( ( ( val & 0xFF800000 ) != 0 ) &&
( ( val & 0xFF800000 ) != 0xFF800000 ) ) {
warning(("claimed 24 bit data isn't"));
return 1;
}
b->fic = val;
b->ric = gp_int32 (ptr);
if (b->fic != b->ric) {
warning(("Fic!=Ric"));
return 1;
}
return 0;
}