-
Notifications
You must be signed in to change notification settings - Fork 0
/
WavRead.m
48 lines (45 loc) · 1.42 KB
/
WavRead.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
classdef WavRead
properties
filename
fs
nch
nbits
nsamples
nprocessed_samples
audio
data
pos
end
methods
function self = WavRead(filename)
FRAME_SIZE = 512;
info = audioinfo(filename);
self.filename = info.Filename;
self.fs = info.SampleRate;
self.nch = info.NumChannels;
self.nbits = info.BitsPerSample;
self.nsamples = info.TotalSamples;
self.nprocessed_samples = 0;
self.audio = cell(1,self.nch);
for ch = 1:self.nch
self.audio{ch} = CircBuffer(FRAME_SIZE);
end
assert(self.nch==1,'Not sure yet how to set multichannel case');
self.data = audioread(filename);
self.pos = 0;
end
function [self,s] = read_samples(self,nsamples)
p = self.nprocessed_samples;
if p + nsamples <= size(self.data,1)
frame = self.data(p+(1:nsamples),:);
else
frame = self.data(p+1:end,:);
end
for ch = 1:self.nch
self.audio{ch} = self.audio{ch}.insert(frame(:,ch));
end
self.nprocessed_samples = self.nprocessed_samples + size(frame,1);
s = size(frame,1);
end
end
end