-
Notifications
You must be signed in to change notification settings - Fork 2
/
mp3stream.pas
79 lines (62 loc) · 1.45 KB
/
mp3stream.pas
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
75
76
77
78
79
unit mp3stream;
interface
uses
sysUtils, classes,
Layer3, Header, BitStream, L3Tables;
type
TDecodedSlice = record
data: pbyte; //decoded samples
size: integer; //decoded data size in bytes
frame_bytes: integer; //how many bytes of input have been consumed
end;
TMP3StreamInfo = record
layer: byte;
channels: byte;
freq_khz: byte;
frame_count: int32;
length: int32;
error: string;
end;
{ TMP3Stream }
TMP3Stream = class
private
FLayer3: TLayerIII_Decoder;
public
constructor Create;
procedure DecodeFile(input: TStream; Output: TStream);
end;
implementation
{ TMP3Stream }
constructor TMP3Stream.Create;
begin
InitPower43Table;
InitReorderTable;
InitGlobalGainTable;
end;
procedure TMP3Stream.DecodeFile(input: TStream; Output: TStream);
var
has_frame: Boolean;
frame_count: integer;
stream: TBitStream;
header: THeader;
begin
stream := TBitStream.Create(input);
header := THeader.Create();
header.ReadHeader(stream);
FLayer3 := TLayerIII_Decoder.Create(stream, header, Output);
has_frame := True;
frame_count := 0;
while has_frame do begin
if (header.Layer <> 3) or (header.Version <> MPEG1) then begin
//set error?
break;
end;
FLayer3.DecodeSingleFrame;
has_frame := header.ReadHeader(stream);
frame_count += 1;
end;
FreeAndNil(FLayer3);
header.Free;
stream.Free;
end;
end.