@@ -8,13 +8,24 @@ public sealed class Mp3Reader
8
8
{
9
9
// http://id3.org/mp3Frame
10
10
// https://www.loc.gov/preservation/digital/formats/fdd/fdd000105.shtml
11
+ // https://id3.org/id3v2.4.0-structure
11
12
12
13
public Directory Extract ( SequentialReader reader )
13
14
{
14
15
var directory = new Mp3Directory ( ) ;
15
16
16
17
var header = reader . GetInt32 ( ) ;
17
18
19
+ // If the file starts with ID3v2 data, try to skip over it for now.
20
+ // Eventually we should extract this data properly.
21
+ if ( ( header & 0xFFFFFF00 ) == 0x49443300 ) // "ID3"
22
+ {
23
+ // Adjust start to end of header
24
+ var id3Bytes = reader . GetBytes ( 6 ) ;
25
+ reader . Skip ( id3Bytes [ 2 ] * 0x200000 + id3Bytes [ 3 ] * 0x4000 + id3Bytes [ 4 ] * 0x80 + id3Bytes [ 5 ] ) ;
26
+ header = reader . GetInt32 ( ) ;
27
+ }
28
+
18
29
// ID: MPEG-2.5, MPEG-2, or MPEG-1
19
30
int id = 0 ;
20
31
switch ( ( header & 0x000180000 ) >> 19 )
@@ -49,8 +60,7 @@ public Directory Extract(SequentialReader reader)
49
60
break ;
50
61
}
51
62
52
-
53
- int protectionBit = ( header & 0x00010000 ) >> 16 ;
63
+ // int protectionBit = (header & 0x00010000) >> 16;
54
64
55
65
// Bitrate: depends on ID and Layer
56
66
int bitrate = ( header & 0x0000F000 ) >> 12 ;
@@ -75,8 +85,7 @@ public Directory Extract(SequentialReader reader)
75
85
frequency = frequencyMapping [ 1 , frequency ] ;
76
86
}
77
87
78
-
79
- int paddingBit = ( header & 0x00000200 ) >> 9 ;
88
+ // int paddingBit = (header & 0x00000200) >> 9;
80
89
81
90
// Encoding type: Stereo, Joint Stereo, Dual Channel, or Mono
82
91
int mode = ( header & 0x000000C0 ) >> 6 ;
0 commit comments