| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| WavFormatHeader |
|
| 1.25;1.25 |
| 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 | 20 | private boolean isValid = false; |
| 25 | ||
| 26 | private int channels, sampleRate, bytesPerSecond, bitrate; | |
| 27 | ||
| 28 | public WavFormatHeader(byte[] b) | |
| 29 | 20 | { |
| 30 | 20 | String fmt = new String(b, 0, 3); |
| 31 | //System.err.println(fmt); | |
| 32 | 20 | if (fmt.equals("fmt") && b[8] == 1) |
| 33 | { | |
| 34 | 20 | channels = b[10]; |
| 35 | //System.err.println(channels); | |
| 36 | 20 | sampleRate = u(b[15]) * 16777216 + u(b[14]) * 65536 + u(b[13]) * 256 + u(b[12]); |
| 37 | //System.err.println(sampleRate); | |
| 38 | 20 | bytesPerSecond = u(b[19]) * 16777216 + u(b[18]) * 65536 + u(b[17]) * 256 + u(b[16]); |
| 39 | //System.err.println(bytesPerSecond); | |
| 40 | 20 | bitrate = u(b[22]); |
| 41 | ||
| 42 | 20 | isValid = true; |
| 43 | } | |
| 44 | ||
| 45 | 20 | } |
| 46 | ||
| 47 | public boolean isValid() | |
| 48 | { | |
| 49 | 20 | return isValid; |
| 50 | } | |
| 51 | ||
| 52 | public int getChannelNumber() | |
| 53 | { | |
| 54 | 20 | return channels; |
| 55 | } | |
| 56 | ||
| 57 | public int getSamplingRate() | |
| 58 | { | |
| 59 | 20 | return sampleRate; |
| 60 | } | |
| 61 | ||
| 62 | public int getBytesPerSecond() | |
| 63 | { | |
| 64 | 40 | return bytesPerSecond; |
| 65 | } | |
| 66 | ||
| 67 | public int getBitrate() | |
| 68 | { | |
| 69 | 20 | return bitrate; |
| 70 | } | |
| 71 | ||
| 72 | private int u(int n) | |
| 73 | { | |
| 74 | 180 | 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 | } |