Coverage Report - org.jaudiotagger.audio.wav.util.WavFormatHeader
 
Classes in this File Line Coverage Branch Coverage Complexity
WavFormatHeader
84%
16/19
50%
2/4
1.125
 
 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.wav.util;
 20  
 
 21  
 public class WavFormatHeader
 22  
 {
 23  
 
 24  3
     private boolean isValid = false;
 25  
 
 26  
     private int channels, sampleRate, bytesPerSecond, bitrate;
 27  
 
 28  
     public WavFormatHeader(byte[] b)
 29  3
     {
 30  3
         String fmt = new String(b, 0, 3);
 31  
         //System.err.println(fmt);
 32  3
         if (fmt.equals("fmt") && b[8] == 1)
 33  
         {
 34  3
             channels = b[10];
 35  
             //System.err.println(channels);
 36  3
             sampleRate = u(b[15]) * 16777216 + u(b[14]) * 65536 + u(b[13]) * 256 + u(b[12]);
 37  
             //System.err.println(sampleRate);
 38  3
             bytesPerSecond = u(b[19]) * 16777216 + u(b[18]) * 65536 + u(b[17]) * 256 + u(b[16]);
 39  
             //System.err.println(bytesPerSecond);
 40  3
             bitrate = u(b[22]);
 41  
 
 42  3
             isValid = true;
 43  
         }
 44  
 
 45  3
     }
 46  
 
 47  
     public boolean isValid()
 48  
     {
 49  3
         return isValid;
 50  
     }
 51  
 
 52  
     public int getChannelNumber()
 53  
     {
 54  3
         return channels;
 55  
     }
 56  
 
 57  
     public int getSamplingRate()
 58  
     {
 59  3
         return sampleRate;
 60  
     }
 61  
 
 62  
     public int getBytesPerSecond()
 63  
     {
 64  6
         return bytesPerSecond;
 65  
     }
 66  
 
 67  
     public int getBitrate()
 68  
     {
 69  3
         return bitrate;
 70  
     }
 71  
 
 72  
     private int u(int n)
 73  
     {
 74  27
         return n & 0xff;
 75  
     }
 76  
 
 77  
     public String toString()
 78  
     {
 79  0
         String out = "RIFF-WAVE Header:\n";
 80  0
         out += "Is valid?: " + isValid;
 81  0
         return out;
 82  
     }
 83  
 }