1 |
kusanagi |
5.1 |
/************************************************************ |
2 |
|
|
* 11/9/2005 modified by david fedele to read buffer-data |
3 |
|
|
* instead raw-data-file |
4 |
|
|
************************************************************** |
5 |
|
|
|
6 |
|
|
* include needed system headers |
7 |
|
|
*/ |
8 |
kusanagi |
1.1 |
#include <stdio.h> /* include standard i/o library */ |
9 |
|
|
#include <stdlib.h> /* include standard library */ |
10 |
|
|
#include <string.h> /* include string library */ |
11 |
|
|
#include <unistd.h> /* include unix standard library */ |
12 |
|
|
#include <sys/types.h> /* */ |
13 |
|
|
#include <sys/stat.h> /* */ |
14 |
|
|
#include <fcntl.h> /* */ |
15 |
|
|
#include <errno.h> /* error simbol definitions */ |
16 |
|
|
#include <time.h> /* system time definitions */ |
17 |
|
|
#include <math.h> /* math library */ |
18 |
|
|
|
19 |
kusanagi |
5.1 |
/* looks for a DSP header beginning (a word beginning with 1110) */ |
20 |
kusanagi |
1.1 |
|
21 |
kusanagi |
5.1 |
/************************************************************ |
22 |
|
|
* 11/9/2005 modified by david fedele |
23 |
|
|
* void findstart_(int *error, int *fd)*/ |
24 |
|
|
void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value); |
25 |
kusanagi |
1.1 |
|
26 |
kusanagi |
5.1 |
void findstart_(int *error,char *buffer, int *len, int *curpos) |
27 |
|
|
{ |
28 |
|
|
char *buff=buffer; |
29 |
|
|
int nbytes2=2; |
30 |
|
|
/* int nread */ |
31 |
|
|
/* unsigned short word; */ |
32 |
|
|
/* unsigned short temp; */ |
33 |
|
|
unsigned int word; |
34 |
|
|
/***********************************************************/ |
35 |
kusanagi |
1.1 |
|
36 |
kusanagi |
5.1 |
*error=0; |
37 |
kusanagi |
1.1 |
do { |
38 |
kusanagi |
5.1 |
/************************************************************/ |
39 |
|
|
/* 11/9/2005 modified by david fedele */ |
40 |
|
|
/* nread=read(*fd, &word, 2); //reads 16 bits */ |
41 |
|
|
/* if(nread == 0) { */ |
42 |
|
|
/* // printf("findstart: Unexpected end of file %d at %d \n",*fd,nread); */ |
43 |
|
|
/* *error=1; */ |
44 |
|
|
/* return ; */ |
45 |
|
|
/* } */ |
46 |
|
|
/* if(nread != 2) { */ |
47 |
|
|
/* // printf("findstart: Error on reading: bytes read -> nread = %d \n",nread); */ |
48 |
|
|
/* *error=-1; */ |
49 |
|
|
/* return ; */ |
50 |
|
|
/* } */ |
51 |
|
|
|
52 |
|
|
/* /\*** corrects byte ***\/ //endianess... */ |
53 |
|
|
/* temp = word; */ |
54 |
|
|
/* word = ( (temp&0x00ff) << 8 ) | ( (temp&0xff00) >> 8 ); */ |
55 |
|
|
/* // printf("word %x , temp: %x: \n", word, temp);//??? */ |
56 |
|
|
|
57 |
|
|
/* /\*** goes back 8 bits ***\/ */ |
58 |
|
|
/* lseek(*fd, -1, SEEK_CUR); //SEEK_CUR ---> from current position */ |
59 |
|
|
|
60 |
|
|
/* // unsigned short num=lseek(*fd, -1, SEEK_CUR); //SEEK_CUR ---> from current position */ |
61 |
|
|
/* // printf("%i \n",num); */ |
62 |
|
|
|
63 |
|
|
getbytes_(&nbytes2,buff,curpos,&word); |
64 |
|
|
|
65 |
|
|
*curpos=*curpos-1; |
66 |
|
|
if(*curpos-1 > *len) { |
67 |
kusanagi |
6.1 |
printf("findstart: Unexpected end of file \n"); |
68 |
|
|
*error=1; |
69 |
|
|
return ; |
70 |
|
|
} |
71 |
kusanagi |
5.1 |
/***********************************************************/ |
72 |
|
|
|
73 |
|
|
} while ((word&0xf000) != 0xe000); |
74 |
|
|
|
75 |
|
|
/************************************************************/ |
76 |
|
|
/* 11/9/2005 modified by david fedele */ |
77 |
|
|
/* /\*** goes back 8 bits ***\/ */ |
78 |
|
|
/* lseek(*fd, -1, SEEK_CUR); */ |
79 |
|
|
*curpos=*curpos-1; |
80 |
kusanagi |
1.1 |
|
81 |
kusanagi |
5.1 |
/************************************************************/ |
82 |
kusanagi |
1.1 |
return; |
83 |
|
|
} |