View Javadoc

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 entagged.audioformats.mpc.util;
20  
21  import entagged.audioformats.generic.Utils;
22  
23  public class MpcHeader {
24  	
25  	byte[] b;
26  	public MpcHeader(byte[] b) {
27  		this.b = b;
28  	}
29  	
30  	public int getSamplesNumber() {
31  		if(b[0] == 7)
32  			return Utils.getNumber(b, 1,4);
33  		
34  
35  		return -1;
36  	}
37  	
38  	public int getSamplingRate() {
39  		if(b[0] == 7) {
40  			switch (b[6] & 0x02) {
41  				case 0: return 44100;
42  				case 1: return 48000;
43                  case 2: return 37800;
44                  case 3: return 32000;
45                  default: return -1;
46  			}
47  		}
48  		
49  		return -1;
50  	}
51  	
52  	public int getChannelNumber() {
53  		if(b[0] == 7)
54  			return 2;
55  		
56  		return 2;
57  	}
58  	
59  	public String getEncodingType() {
60  		StringBuffer out = new StringBuffer().append("MPEGplus (MPC)");
61  		if(b[0] == 7) {
62  			out.append(" rev.7, Profile:");
63  			switch ((b[7] & 0xF0) >> 4) {
64  				case 0: out.append( "No profile"); break;
65  				case 1: out.append( "Unstable/Experimental"); break;
66  				case 2: out.append( "Unused"); break;
67  				case 3: out.append( "Unused"); break;
68  				case 4: out.append( "Unused"); break;
69  				case 5: out.append( "Below Telephone (q= 0.0)"); break;
70  				case 6: out.append( "Below Telephone (q= 1.0)"); break;
71  				case 7: out.append( "Telephone (q= 2.0)"); break;
72  				case 8: out.append( "Thumb (q= 3.0)"); break;
73  				case 9: out.append( "Radio (q= 4.0)"); break;
74  				case 10: out.append( "Standard (q= 5.0)"); break;
75  				case 11: out.append( "Xtreme (q= 6.0)"); break;
76  				case 12: out.append( "Insane (q= 7.0)"); break;
77  				case 13: out.append( "BrainDead (q= 8.0)"); break;
78  				case 14: out.append( "Above BrainDead (q= 9.0)"); break;
79  				case 15: out.append( "Above BrainDead (q=10.0)"); break;
80  				default: out.append("No profile"); break;
81  			}
82  		}
83  		
84  		return out.toString();
85  	}
86  	
87  	public String getEncoderInfo() {
88  		int encoder = b[24];
89  		StringBuffer out = new StringBuffer().append("Mpc encoder v").append(((double)encoder)/100).append(" ");
90  		if(encoder % 10 == 0)
91  			out.append("Release");
92  		else if(encoder %  2 == 0)
93  			out.append("Beta");
94  		else if(encoder %  2 == 1)
95  			out.append("Alpha");
96  		
97  		return out.toString();
98  	}
99  
100 }