@@ -15,10 +15,10 @@ import 'mp3.dart';
1515/// Processes an MP3 file extracting key metadata information. The current version
1616/// does not support extracting metadata from ID3 tags.
1717class MP3Processor {
18- static int FRAME_1 = 0 ;
19- static int FRAME_2 = 1 ;
20- static int FRAME_3 = 2 ;
21- static int FRAME_4 = 3 ;
18+ static int frame1 = 0 ;
19+ static int frame2 = 1 ;
20+ static int frame3 = 2 ;
21+ static int frame4 = 3 ;
2222
2323 /// Process the MP3 contained within the [File] instance.
2424 static MP3Info fromFile (File file) {
@@ -40,13 +40,14 @@ class MP3Processor {
4040 /// the ID3 tag space (excluding the 10 byte header itself. This function
4141 /// calculates the start of the first MP3 frame.
4242 int _processID3 (Uint8List bytes) {
43- var headerSize = (bytes[6 ] << 21 ) + (bytes[7 ] << 14 ) + (bytes[8 ] << 7 ) + (bytes[9 ]);
43+ var headerSize =
44+ (bytes[6 ] << 21 ) + (bytes[7 ] << 14 ) + (bytes[8 ] << 7 ) + (bytes[9 ]);
4445
4546 return headerSize + 10 ;
4647 }
4748
4849 Version _processMpegVersion (Uint8List frameHeader) {
49- var version = frameHeader[FRAME_2 ] & mpegVersionMask;
50+ var version = frameHeader[frame2 ] & mpegVersionMask;
5051
5152 switch (version) {
5253 case mpegVersion1:
@@ -61,7 +62,7 @@ class MP3Processor {
6162 }
6263
6364 Layer _processMpegLayer (Uint8List frameHeader) {
64- final mpegLayer = frameHeader[FRAME_2 ] & mpegLayerMask;
65+ final mpegLayer = frameHeader[frame2 ] & mpegLayerMask;
6566
6667 switch (mpegLayer) {
6768 case layer1:
@@ -76,15 +77,15 @@ class MP3Processor {
7677 }
7778
7879 bool _processCrcCheck (Uint8List frameHeader) {
79- final mpegProtection = frameHeader[FRAME_2 ] & mpegProtectionMask;
80+ final mpegProtection = frameHeader[frame2 ] & mpegProtectionMask;
8081
8182 return mpegProtection > 0 ;
8283 }
8384
8485 int ? _processBitRate (Uint8List frameHeader, Version version, Layer layer) {
85- final sampleInfo = frameHeader[FRAME_3 ];
86- final bitRate =
87- (sampleInfo & mpegBitRateMask) >> 4 ; // Easier to compare if we shift the bits down.
86+ final sampleInfo = frameHeader[frame3 ];
87+ final bitRate = (sampleInfo & mpegBitRateMask) >>
88+ 4 ; // Easier to compare if we shift the bits down.
8889 Map <int , int > bitRateMap;
8990
9091 if (version == Version .MPEG_1 ) {
@@ -109,7 +110,7 @@ class MP3Processor {
109110 }
110111
111112 SampleRate ? _processSampleRate (Uint8List frameHeader) {
112- final sampleRate = (frameHeader[FRAME_3 ] & mpegSampleRateMask);
113+ final sampleRate = (frameHeader[frame3 ] & mpegSampleRateMask);
113114 SampleRate ? rate;
114115
115116 switch (sampleRate) {
@@ -138,7 +139,7 @@ class MP3Processor {
138139 }
139140
140141 ChannelMode _processChannelMode (Uint8List frameHeader) {
141- final channelMode = (frameHeader[FRAME_4 ] & mpegChannelModeMask);
142+ final channelMode = (frameHeader[frame4 ] & mpegChannelModeMask);
142143 ChannelMode mode;
143144
144145 switch (channelMode) {
@@ -160,19 +161,19 @@ class MP3Processor {
160161 }
161162
162163 bool _processCopyright (Uint8List frameHeader) {
163- final copyright = (frameHeader[FRAME_4 ] & mpegCopyrightMask);
164+ final copyright = (frameHeader[frame4 ] & mpegCopyrightMask);
164165
165166 return copyright > 0 ;
166167 }
167168
168169 bool _processOriginal (Uint8List frameHeader) {
169- final original = (frameHeader[FRAME_4 ] & mpegOriginalMask);
170+ final original = (frameHeader[frame4 ] & mpegOriginalMask);
170171
171172 return original > 0 ;
172173 }
173174
174175 Emphasis ? _processEmphasis (Uint8List frameHeader) {
175- final emphasis = (frameHeader[FRAME_4 ] & mpegEmphasisMask);
176+ final emphasis = (frameHeader[frame4 ] & mpegEmphasisMask);
176177 Emphasis ? e;
177178
178179 switch (emphasis) {
@@ -201,7 +202,8 @@ class MP3Processor {
201202 // Does the MP3 start with an ID3 tag?
202203 firstFrameOffset = latin1.decode (tag) == 'ID3' ? _processID3 (header) : 0 ;
203204
204- final frameHeaderBytes = bytes.sublist (firstFrameOffset, firstFrameOffset + 10 );
205+ final frameHeaderBytes =
206+ bytes.sublist (firstFrameOffset, firstFrameOffset + 10 );
205207
206208 // Ensure we have a valid MP3 frame
207209 final frameSync1 = frameHeaderBytes[0 ] & frameSyncA;
@@ -234,7 +236,8 @@ class MP3Processor {
234236 emphasis,
235237 );
236238 } else {
237- throw InvalidMP3FileException ('The file cannot be processed as it is not a valid MP3 file' );
239+ throw InvalidMP3FileException (
240+ 'The file cannot be processed as it is not a valid MP3 file' );
238241 }
239242 }
240243}
0 commit comments