Coverage Report - org.jaudiotagger.audio.mp3.LameFrame
 
Classes in this File Line Coverage Branch Coverage Complexity
LameFrame
100%
11/11
100%
2/2
1.667
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
 4  
  * 
 5  
  * This library is free software; you can redistribute it and/or
 6  
  * modify it under the terms of the GNU Lesser General Public
 7  
  * License as published by the Free Software Foundation; either
 8  
  * version 2.1 of the License, or (at your option) any later version.
 9  
  *  
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  * Lesser General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU Lesser General Public
 16  
  * License along with this library; if not, write to the Free Software
 17  
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.jaudiotagger.audio.mp3;
 20  
 
 21  
 import org.jaudiotagger.audio.generic.Utils;
 22  
 import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
 23  
 
 24  
 import java.nio.ByteBuffer;
 25  
 
 26  
 /**
 27  
  * The first frame can sometimes contain a LAME frame at the end of the Xing frame
 28  
  * <p/>
 29  
  * <p>This useful to the library because it allows the encoder to be identified, full specification
 30  
  * can be found at http://gabriel.mp3-tech.org/mp3infotag.html
 31  
  * <p/>
 32  
  * Summarized here:
 33  
  * 4 bytes:LAME
 34  
  * 5 bytes:LAME Encoder Version
 35  
  * 1 bytes:VNR Method
 36  
  * 1 bytes:Lowpass filter value
 37  
  * 8 bytes:Replay Gain
 38  
  * 1 byte:Encoding Flags
 39  
  * 1 byte:minimal byte rate
 40  
  * 3 bytes:extra samples
 41  
  * 1 byte:Stereo Mode
 42  
  * 1 byte:MP3 Gain
 43  
  * 2 bytes:Surround Dound
 44  
  * 4 bytes:MusicLength
 45  
  * 2 bytes:Music CRC
 46  
  * 2 bytes:CRC Tag
 47  
  */
 48  
 public class LameFrame
 49  
 {
 50  
     public static final int LAME_HEADER_BUFFER_SIZE = 36;
 51  
     public static final int ENCODER_SIZE = 9;   //Includes LAME ID
 52  
     public static final int LAME_ID_SIZE = 4;
 53  
     public static final String LAME_ID = "LAME";
 54  
     private String encoder;
 55  
 
 56  
     /**
 57  
      * Initilise a Lame Mpeg Frame
 58  
      */
 59  
     private LameFrame(ByteBuffer lameHeader)
 60  423
     {
 61  423
         encoder = Utils.getString(lameHeader, 0, ENCODER_SIZE, TextEncoding.CHARSET_ISO_8859_1);
 62  423
     }
 63  
 
 64  
     /**
 65  
      * Parse frame
 66  
      *
 67  
      * @return frame or null if not exists    
 68  
      */
 69  
     public static LameFrame parseLameFrame(ByteBuffer bb)
 70  
     {
 71  425
         ByteBuffer lameHeader = bb.slice();
 72  425
         String id = Utils.getString(lameHeader, 0, LAME_ID_SIZE, TextEncoding.CHARSET_ISO_8859_1);
 73  425
         lameHeader.rewind();
 74  425
         if (id.equals(LAME_ID))
 75  
         {
 76  423
             LameFrame lameFrame = new LameFrame(lameHeader);
 77  423
             return lameFrame;
 78  
         }
 79  2
         return null;
 80  
     }
 81  
 
 82  
     /**
 83  
      * @return encoder
 84  
      */
 85  
     public String getEncoder()
 86  
     {
 87  423
         return encoder;
 88  
     }
 89  
 }
 90