-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitstream_formatting.m
40 lines (33 loc) · 1001 Bytes
/
bitstream_formatting.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
function params = bitstream_formatting(filename, params, allocation, scalefactor, sample)
% Form a MPEG-1 Layer 1 bitstream and append it to output file.
N_SUBBANDS = 32;
FRAMES_PER_BLOCK = 12;
buffer = BitStream((params.nslots + params.padbit) * 4);
buffer = buffer.insert(params.header, 32);
params = params.updateheader();
for sb = 1:N_SUBBANDS
for ch = 1:params.nch
buffer = buffer.insert(max(allocation(ch,sb)-1, 0), 4);
end
end
for sb = 1:N_SUBBANDS
for ch = 1:params.nch
if allocation(ch,sb) ~= 0
buffer = buffer.insert(scalefactor(ch,sb),6);
end
end
end
for s = 1:FRAMES_PER_BLOCK
for sb = 1:N_SUBBANDS
for ch = 1:params.nch
if allocation(ch,sb) ~= 0
buffer = buffer.insert(sample(ch,sb,s), allocation(ch,sb), true);
end
end
end
end
fp = fopen(filename, 'ab+');
fwrite(fp,buffer.data);
fclose(fp);
% disp(numel(buffer.data));
end