Coverage Report - org.jaudiotagger.audio.asf.data.AudioStreamChunk
 
Classes in this File Line Coverage Branch Coverage Complexity
AudioStreamChunk
72%
34/47
67%
4/6
1.143
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de>
 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.asf.data;
 20  
 
 21  
 import java.math.BigInteger;
 22  
 
 23  
 import org.jaudiotagger.audio.asf.util.Utils;
 24  
 
 25  
 /**
 26  
  * This class represents the stream chunk describing an audio stream. <br>
 27  
  *
 28  
  * @author Christian Laireiter
 29  
  */
 30  
 public final class AudioStreamChunk extends StreamChunk
 31  
 {
 32  
     /**
 33  
      * Stores the audio codec number for WMA
 34  
      */
 35  
     public final static long WMA = 0x161;
 36  
     /**
 37  
      * Stores the audio codec number for WMA_PRO
 38  
      */
 39  
     public final static long WMA_PRO = 0x162;
 40  
     /**
 41  
      * Stores the audio codec number for WMA_LOSSLESS
 42  
      */
 43  
     public final static long WMA_LOSSLESS = 0x163;
 44  
     /**
 45  
      * Stores the audio codec number for WMA (CBR)
 46  
      */
 47  
     public final static long WMA_CBR = 0x7A21;
 48  
     /**
 49  
      * Stores the audio codec number for WMA (VBR)
 50  
      */
 51  
     public final static long WMA_VBR = 0x7A22;
 52  
 
 53  
     /**
 54  
      * Stores the hex values of codec identifiers to their descriptions. <br>
 55  
      */
 56  5
     public final static String[][] CODEC_DESCRIPTIONS = {{"161", " (Windows Media Audio (ver 7,8,9))"}, {"162", " (Windows Media Audio 9 series (Professional))"}, {"163", "(Windows Media Audio 9 series (Lossless))"}, {"7A21", " (GSM-AMR (CBR))"}, {"7A22", " (GSM-AMR (VBR))"}};
 57  
 
 58  
     /**
 59  
      * Stores the average amount of bytes used by audio stream. <br>
 60  
      * This value is a field within type specific data of audio stream. Maybe it
 61  
      * could be used to calculate the KBPs.
 62  
      */
 63  
     private long averageBytesPerSec;
 64  
 
 65  
     /**
 66  
      * Amount of bits used per sample. <br>
 67  
      */
 68  
     private int bitsPerSample;
 69  
 
 70  
     /**
 71  
      * The block alignment of the audio data.
 72  
      */
 73  
     private long blockAlignment;
 74  
 
 75  
     /**
 76  
      * Number of channels.
 77  
      */
 78  
     private long channelCount;
 79  
 
 80  
     /**
 81  
      * Some data which needs to be interpreted if the codec is handled.
 82  
      */
 83  
     private byte[] codecData;
 84  
 
 85  
     /**
 86  
      * The audio compression format code.
 87  
      */
 88  
     private long compressionFormat;
 89  
 
 90  
     /**
 91  
      * this field stores the error concealment type.
 92  
      */
 93  
     private GUID errorConcealment;
 94  
 
 95  
     /**
 96  
      * Sampling rate of audio stream.
 97  
      */
 98  
     private long samplingRate;
 99  
 
 100  
     /**
 101  
      * Creates an instance.
 102  
      *
 103  
      * @param chunkLen Length of the entire chunk (including guid and size)
 104  
      */
 105  
     public AudioStreamChunk(BigInteger chunkLen)
 106  
     {
 107  55
         super(GUID.GUID_AUDIOSTREAM, chunkLen);
 108  55
     }
 109  
 
 110  
     /**
 111  
      * @return Returns the averageBytesPerSec.
 112  
      */
 113  
     public long getAverageBytesPerSec()
 114  
     {
 115  39
         return averageBytesPerSec;
 116  
     }
 117  
 
 118  
     /**
 119  
      * @return Returns the bitsPerSample.
 120  
      */
 121  
     public int getBitsPerSample()
 122  
     {
 123  0
         return bitsPerSample;
 124  
     }
 125  
 
 126  
     /**
 127  
      * @return Returns the blockAlignment.
 128  
      */
 129  
     public long getBlockAlignment()
 130  
     {
 131  0
         return blockAlignment;
 132  
     }
 133  
 
 134  
     /**
 135  
      * @return Returns the channelCount.
 136  
      */
 137  
     public long getChannelCount()
 138  
     {
 139  39
         return channelCount;
 140  
     }
 141  
 
 142  
     /**
 143  
      * @return Returns the codecData.
 144  
      */
 145  
     public byte[] getCodecData()
 146  
     {
 147  0
         return codecData;
 148  
     }
 149  
 
 150  
     /**
 151  
      * This method will take a look at {@link #compressionFormat}and returns a
 152  
      * String with its hex value and if known a textual note on what coded it
 153  
      * represents. <br>
 154  
      *
 155  
      * @return A description for the used codec.
 156  
      */
 157  
     public String getCodecDescription()
 158  
     {
 159  39
         StringBuffer result = new StringBuffer(Long.toHexString(getCompressionFormat()));
 160  39
         String furtherDesc = " (Unknown)";
 161  42
         for (int i = 0; i < CODEC_DESCRIPTIONS.length; i++)
 162  
         {
 163  42
             if (CODEC_DESCRIPTIONS[i][0].equalsIgnoreCase(result.toString()))
 164  
             {
 165  39
                 furtherDesc = CODEC_DESCRIPTIONS[i][1];
 166  39
                 break;
 167  
             }
 168  
         }
 169  39
         if (result.length() % 2 != 0)
 170  
         {
 171  39
             result.insert(0, "0x0");
 172  
         }
 173  
         else
 174  
         {
 175  0
             result.insert(0, "0x");
 176  
         }
 177  39
         result.append(furtherDesc);
 178  39
         return result.toString();
 179  
     }
 180  
 
 181  
     /**
 182  
      * @return Returns the compressionFormat.
 183  
      */
 184  
     public long getCompressionFormat()
 185  
     {
 186  78
         return compressionFormat;
 187  
     }
 188  
 
 189  
     /**
 190  
      * @return Returns the errorConcealment.
 191  
      */
 192  
     public GUID getErrorConcealment()
 193  
     {
 194  0
         return errorConcealment;
 195  
     }
 196  
 
 197  
     /**
 198  
      * This method takes the value of {@link #getAverageBytesPerSec()}and
 199  
      * calculates the kbps out of it, by simply multiplying by 8 and dividing by
 200  
      * 1000. <br>
 201  
      *
 202  
      * @return amount of bits per second in kilo bits.
 203  
      */
 204  
     public int getKbps()
 205  
     {
 206  39
         return (int) getAverageBytesPerSec() * 8 / 1000;
 207  
     }
 208  
 
 209  
     /**
 210  
      * @return Returns the samplingRate.
 211  
      */
 212  
     public long getSamplingRate()
 213  
     {
 214  39
         return samplingRate;
 215  
     }
 216  
 
 217  
     /**
 218  
      * This mehtod returns whether the audio stream data is error concealed.
 219  
      * <br>
 220  
      * For now only interleaved concealment is known. <br>
 221  
      *
 222  
      * @return <code>true</code> if error concealment is used.
 223  
      */
 224  
     public boolean isErrorConcealed()
 225  
     {
 226  0
         return getErrorConcealment().equals(GUID.GUID_AUDIO_ERROR_CONCEALEMENT_INTERLEAVED);
 227  
     }
 228  
 
 229  
     /**
 230  
      * 
 231  
      * {@inheritDoc}
 232  
      */
 233  
     public String prettyPrint(final String prefix)
 234  
     {
 235  0
         StringBuffer result = new StringBuffer(super.prettyPrint(prefix));
 236  0
         result.append(prefix + "  |-> Audio info:" + Utils.LINE_SEPARATOR);
 237  0
         result.append(prefix + "  |  : Bitrate : " + getKbps() + Utils.LINE_SEPARATOR);
 238  0
         result
 239  
                         .append(prefix + "  |  : Channels : " + getChannelCount() + " at " + getSamplingRate() + " Hz" + Utils.LINE_SEPARATOR);
 240  0
         result.append(prefix + "  |  : Bits per Sample: " + getBitsPerSample() + Utils.LINE_SEPARATOR);
 241  0
         result.append(prefix + "  |  : Formatcode: " + getCodecDescription() + Utils.LINE_SEPARATOR);
 242  0
         return result.toString();
 243  
     }
 244  
 
 245  
     /**
 246  
      * @param avgeBytesPerSec The averageBytesPerSec to set.
 247  
      */
 248  
     public void setAverageBytesPerSec(long avgeBytesPerSec)
 249  
     {
 250  55
         this.averageBytesPerSec = avgeBytesPerSec;
 251  55
     }
 252  
 
 253  
     /**
 254  
      * Sets the bitsPerSample
 255  
      *
 256  
      * @param bps
 257  
      */
 258  
     public void setBitsPerSample(int bps)
 259  
     {
 260  55
         this.bitsPerSample = bps;
 261  55
     }
 262  
 
 263  
     /**
 264  
      * Sets the blockAlignment.
 265  
      *
 266  
      * @param align
 267  
      */
 268  
     public void setBlockAlignment(long align)
 269  
     {
 270  55
         this.blockAlignment = align;
 271  55
     }
 272  
 
 273  
     /**
 274  
      * @param channels The channelCount to set.
 275  
      */
 276  
     public void setChannelCount(long channels)
 277  
     {
 278  55
         this.channelCount = channels;
 279  55
     }
 280  
 
 281  
     /**
 282  
      * Sets the codecData
 283  
      *
 284  
      * @param codecSpecificData
 285  
      */
 286  
     public void setCodecData(byte[] codecSpecificData)
 287  
     {
 288  55
         this.codecData = codecSpecificData;
 289  55
     }
 290  
 
 291  
     /**
 292  
      * @param cFormatCode The compressionFormat to set.
 293  
      */
 294  
     public void setCompressionFormat(long cFormatCode)
 295  
     {
 296  55
         this.compressionFormat = cFormatCode;
 297  55
     }
 298  
 
 299  
     /**
 300  
      * This method sets the error concealment type which is given by two GUIDs.
 301  
      * <br>
 302  
      *
 303  
      * @param errConc the type of error concealment the audio stream is stored as.
 304  
      */
 305  
     public void setErrorConcealment(GUID errConc)
 306  
     {
 307  55
         this.errorConcealment = errConc;
 308  55
     }
 309  
 
 310  
     /**
 311  
      * @param sampRate The samplingRate to set.
 312  
      */
 313  
     public void setSamplingRate(long sampRate)
 314  
     {
 315  55
         this.samplingRate = sampRate;
 316  55
     }
 317  
 }