-
Notifications
You must be signed in to change notification settings - Fork 0
/
readSampData.m
74 lines (47 loc) · 1.79 KB
/
readSampData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function [samps] = readSampData(file_listTable, callStartSamp, sampleStop, event_pad)
% Pull the signal and buffer associated with the detection
sampleStart = callStartSamp-event_pad;
sampleStop = sampleStop+event_pad;
% If early in the file pad may overstep
if sampleStart<1
beginBuffpts=-sampleStart;
sampleStart=1;
else
beginBuffpts=[]
end
% the file where the clip is
fileIdx = find(file_listTable.SampleStrt+1 > sampleStart ,1)-1;
if isempty(fileIdx)
fileIdx = height(file_listTable);
end
% Where in file the sample starts
fstart = round(sampleStart-file_listTable.SampleStrt(fileIdx));
fstop = fstart+(sampleStop-sampleStart);
% if fstop>(fs*60*15 + (fs*3))
% disp('feeeck')
% end
% samples overlap files
if fstop>1800000
% load the audio
samps = audioread(fullfile(file_listTable.folder{fileIdx},...
file_listTable.name{fileIdx}),...
[fstart 1800000]);
try
samps = [samps;...
audioread(fullfile(file_listTable.folder{fileIdx+1},...
file_listTable.name{fileIdx+1}),...
[1 fstop-1800000-1])];
catch
disp('last files')
samps = [samps; zeros(fstop-1800000, size(samps,2)); ] ;
end
else
samps = audioread(fullfile(file_listTable.folder{fileIdx},...
file_listTable.name{fileIdx}),...
[fstart fstop-1]);
end
if beginBuffpts>0
% Add the buffer points to the sample
samps = [zeros(beginBuffpts, size(samps,2)); samps] ;
end
end