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