1function [B, Sync, Vcount] = Datalogger4ChConverter_ErrInsensitiveSound(Name_tmp)
2
3
4fid = fopen(Name_tmp, 'r');
5A = fread(fid,Inf,'uint8=>uint8');
6fclose(fid);
7FSize = size(A,1);
8V = NaN(ceil(FSize/6),2); Vcount = 0;
9Error = false;
10StartPos = 1;
11CurrentPos = 2;
12FSize_3 = FSize-3;
13while CurrentPos<FSize_3
14 b12 = bitand(A(CurrentPos),128);
15 b34 = bitand(A(CurrentPos+3),136);
16 if (b12~=0) && (b34==0)
17 CurrentPos = CurrentPos+6;
18 if Error
19 StartPos = CurrentPos-1;
20 end
21 Error = false;
22 else
23 if ~Error
24 Vcount = Vcount+1;
25 V(Vcount,:) = [StartPos CurrentPos-2];
26 Error = true;
27 end;
28 CurrentPos = CurrentPos+1;
29 end;
30end;
31if ~Error
32 Vcount = Vcount+1;
33 V(Vcount,1:2) = [StartPos CurrentPos-2];
34end;
35V((Vcount+1):end,:) = [];
36
37L = V(:,2)-V(:,1)+1;
38Af_length = sum(L);
39Af = zeros(Af_length,1,'uint8');
40Counter = 0;
41for I_t =1:size(V,1)
42 Af(Counter+(1:L(I_t))) = A(V(I_t,1):V(I_t,2));
43 Counter = Counter+L(I_t);
44end
45A = Af;
46Af = [];
47Am = rem(size(A,1),6)-1;
48if (Am>-1)
49 A((size(A,1)-Am):size(A,1),:) = [];
50end;
51A = reshape(A,6,size(A,1)/6)';
52B = zeros(size(A,1),4, 'single');
53B(:,1) = bitshift(uint16(bitand(A(:,2),112)),4)+uint16(A(:,1));
54B(:,2) = bitshift(uint16(bitand(A(:,2),7)),8)+uint16(A(:,3));
55B(:,3) = bitshift(uint16(bitand(A(:,2+3),112)),4)+uint16(A(:,1+3));
56B(:,4) = bitshift(uint16(bitand(A(:,2+3),7)),8)+uint16(A(:,3+3));
57Sync = bitshift(bitand(A(:,2),8),-3);