| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.jaudiotagger.audio.ogg.util; |
| 20 | |
|
| 21 | |
import org.jaudiotagger.audio.generic.Utils; |
| 22 | |
import org.jaudiotagger.audio.ogg.VorbisVersion; |
| 23 | |
|
| 24 | |
import java.util.logging.Logger; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public class VorbisIdentificationHeader implements VorbisHeader |
| 52 | |
{ |
| 53 | |
|
| 54 | 6 | public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.ogg.atom"); |
| 55 | |
|
| 56 | |
private int audioChannels; |
| 57 | 43 | private boolean isValid = false; |
| 58 | |
|
| 59 | |
private int vorbisVersion, audioSampleRate; |
| 60 | |
private int bitrateMinimal, bitrateNominal, bitrateMaximal; |
| 61 | |
|
| 62 | |
public static final int FIELD_VORBIS_VERSION_POS = 7; |
| 63 | |
public static final int FIELD_AUDIO_CHANNELS_POS = 11; |
| 64 | |
public static final int FIELD_AUDIO_SAMPLE_RATE_POS = 12; |
| 65 | |
public static final int FIELD_BITRATE_MAX_POS = 16; |
| 66 | |
public static final int FIELD_BITRATE_NOMAIML_POS = 20; |
| 67 | |
public static final int FIELD_BITRATE_MIN_POS = 24; |
| 68 | |
public static final int FIELD_BLOCKSIZE_POS = 28; |
| 69 | |
public static final int FIELD_FRAMING_FLAG_POS = 29; |
| 70 | |
|
| 71 | |
public static final int FIELD_VORBIS_VERSION_LENGTH = 4; |
| 72 | |
public static final int FIELD_AUDIO_CHANNELS_LENGTH = 1; |
| 73 | |
public static final int FIELD_AUDIO_SAMPLE_RATE_LENGTH = 4; |
| 74 | |
public static final int FIELD_BITRATE_MAX_LENGTH = 4; |
| 75 | |
public static final int FIELD_BITRATE_NOMAIML_LENGTH = 4; |
| 76 | |
public static final int FIELD_BITRATE_MIN_LENGTH = 4; |
| 77 | |
public static final int FIELD_BLOCKSIZE_LENGTH = 1; |
| 78 | |
public static final int FIELD_FRAMING_FLAG_LENGTH = 1; |
| 79 | |
|
| 80 | |
|
| 81 | |
public VorbisIdentificationHeader(byte[] vorbisData) |
| 82 | 43 | { |
| 83 | 43 | decodeHeader(vorbisData); |
| 84 | 43 | } |
| 85 | |
|
| 86 | |
|
| 87 | |
public int getChannelNumber() |
| 88 | |
{ |
| 89 | 43 | return audioChannels; |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
public String getEncodingType() |
| 94 | |
{ |
| 95 | 43 | return VorbisVersion.values()[vorbisVersion].toString(); |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
public int getSamplingRate() |
| 100 | |
{ |
| 101 | 86 | return audioSampleRate; |
| 102 | |
} |
| 103 | |
|
| 104 | |
public int getNominalBitrate() |
| 105 | |
{ |
| 106 | 172 | return bitrateNominal; |
| 107 | |
} |
| 108 | |
|
| 109 | |
public int getMaxBitrate() |
| 110 | |
{ |
| 111 | 86 | return bitrateMaximal; |
| 112 | |
} |
| 113 | |
|
| 114 | |
public int getMinBitrate() |
| 115 | |
{ |
| 116 | 43 | return bitrateMinimal; |
| 117 | |
} |
| 118 | |
|
| 119 | |
public boolean isValid() |
| 120 | |
{ |
| 121 | 0 | return isValid; |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | |
public void decodeHeader(byte[] b) |
| 126 | |
{ |
| 127 | 43 | int packetType = b[FIELD_PACKET_TYPE_POS]; |
| 128 | 43 | logger.fine("packetType" + packetType); |
| 129 | 43 | String vorbis = Utils.getString(b, VorbisHeader.FIELD_CAPTURE_PATTERN_POS, VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH, "ISO-8859-1"); |
| 130 | |
|
| 131 | 43 | if (packetType == VorbisPacketType.IDENTIFICATION_HEADER.getType() && vorbis.equals(CAPTURE_PATTERN)) |
| 132 | |
{ |
| 133 | 43 | this.vorbisVersion = b[7] + (b[8] << 8) + (b[9] << 16) + (b[10] << 24); |
| 134 | 43 | logger.fine("vorbisVersion" + vorbisVersion); |
| 135 | 43 | this.audioChannels = u(b[FIELD_AUDIO_CHANNELS_POS]); |
| 136 | 43 | logger.fine("audioChannels" + audioChannels); |
| 137 | 43 | this.audioSampleRate = u(b[12]) + (u(b[13]) << 8) + (u(b[14]) << 16) + (u(b[15]) << 24); |
| 138 | 43 | logger.fine("audioSampleRate" + audioSampleRate); |
| 139 | 43 | logger.fine("audioSampleRate" + b[12] + " " + b[13] + " " + b[14]); |
| 140 | |
|
| 141 | |
|
| 142 | 43 | this.bitrateMinimal = u(b[16]) + (u(b[17]) << 8) + (u(b[18]) << 16) + (u(b[19]) << 24); |
| 143 | 43 | this.bitrateNominal = u(b[20]) + (u(b[21]) << 8) + (u(b[22]) << 16) + (u(b[23]) << 24); |
| 144 | 43 | this.bitrateMaximal = u(b[24]) + (u(b[25]) << 8) + (u(b[26]) << 16) + (u(b[27]) << 24); |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | 43 | int framingFlag = b[FIELD_FRAMING_FLAG_POS]; |
| 149 | 43 | logger.fine("framingFlag" + framingFlag); |
| 150 | 43 | if (framingFlag != 0) |
| 151 | |
{ |
| 152 | 43 | isValid = true; |
| 153 | |
} |
| 154 | |
|
| 155 | |
} |
| 156 | 43 | } |
| 157 | |
|
| 158 | |
private int u(int i) |
| 159 | |
{ |
| 160 | 731 | return i & 0xFF; |
| 161 | |
} |
| 162 | |
} |
| 163 | |
|