forked from amaas/rnn-speech-denoising
-
Notifications
You must be signed in to change notification settings - Fork 3
/
htkread.m
59 lines (47 loc) · 1.53 KB
/
htkread.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
function [ DATA, HTKCode ] = htkread( Filename )
% [ DATA, HTKCode ] = htkread( Filename )
%
% Read DATA from possibly compressed HTK format file.
%
% Filename (string) - Name of the file to read from
% DATA (nSamp x NUMCOFS) - Output data array
% HTKCode - HTKCode describing file contents
%
% Compression is handled using the algorithm in 5.10 of the HTKBook.
% CRC is not implemented.
%
% Mark Hasegawa-Johnson
% July 3, 2002
% Based on function mfcc_read written by Alexis Bernard
%
fid=fopen(Filename,'r','b');
if fid<0,
error(sprintf('Unable to read from file %s',Filename));
end
% Read number of frames
nSamp = fread(fid,1,'int32');
% Read sampPeriod
sampPeriod = fread(fid,1,'int32');
% Read sampSize
sampSize = fread(fid,1,'int16');
% Read HTK Code
HTKCode = fread(fid,1,'int16');
%%%%%%%%%%%%%%%%%
% Read the data
if bitget(HTKCode, 11),
DIM=sampSize/2;
nSamp = nSamp-4;
% disp(sprintf('htkread: Reading %d frames, dim %d, compressed, from %s',nSamp,DIM,Filename));
% Read the compression parameters
A = fread(fid,[1 DIM],'float');
B = fread(fid,[1 DIM],'float');
% Read and uncompress the data
DATA = fread(fid, [DIM nSamp], 'int16')';
DATA = (repmat(B, [nSamp 1]) + DATA) ./ repmat(A, [nSamp 1]);
else
DIM=sampSize/4;
% disp(sprintf('htkread: Reading %d frames, dim %d, uncompressed, from %s',nSamp,DIM,Filename));
% If not compressed: Read floating point data
DATA = fread(fid, [DIM nSamp], 'float')';
end
fclose(fid);