2
* Entagged Audio Tag library
3
* Copyright (c) 2003-2005 Raphaël Slinckx <raphael@slinckx.net>
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.
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.
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
19
package org.jaudiotagger.audio.ogg.util;
21
import org.jaudiotagger.audio.generic.Utils;
22
import org.jaudiotagger.audio.ogg.VorbisVersion;
24
import java.util.logging.Logger;
28
* Vorbis Identification header
30
* From http://xiph.org/vorbis/doc/Vorbis_I_spec.html#id326710
32
* The identification header is a short header of only a few fields used to declare the stream definitively as Vorbis,
33
* and provide a few externally relevant pieces of information about the audio stream. The identification header is
36
* 1) [vorbis_version] = read 32 bits as unsigned integer
37
* 2) [audio_channels] = read 8 bit integer as unsigned
38
* 3) [audio_sample_rate] = read 32 bits as unsigned integer
39
* 4) [bitrate_maximum] = read 32 bits as signed integer
40
* 5) [bitrate_nominal] = read 32 bits as signed integer
41
* 6) [bitrate_minimum] = read 32 bits as signed integer
42
* 7) [blocksize_0] = 2 exponent (read 4 bits as unsigned integer)
43
* 8) [blocksize_1] = 2 exponent (read 4 bits as unsigned integer)
44
* 9) [framing_flag] = read one bit
46
* $Id: VorbisIdentificationHeader.java,v 1.8 2009/09/03 09:19:13 paultaylor Exp $
48
* @author Raphael Slinckx (KiKiDonK)
49
* @version 16 d�cembre 2003
51
public class VorbisIdentificationHeader implements VorbisHeader
54
public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.ogg.atom");
56
private int audioChannels;
57
private boolean isValid = false;
59
private int vorbisVersion, audioSampleRate;
60
private int bitrateMinimal, bitrateNominal, bitrateMaximal;
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;
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;
81
public VorbisIdentificationHeader(byte[] vorbisData)
83
decodeHeader(vorbisData);
87
public int getChannelNumber()
93
public String getEncodingType()
95
return VorbisVersion.values()[vorbisVersion].toString();
99
public int getSamplingRate()
101
return audioSampleRate;
104
public int getNominalBitrate()
106
return bitrateNominal;
109
public int getMaxBitrate()
111
return bitrateMaximal;
114
public int getMinBitrate()
116
return bitrateMinimal;
119
public boolean isValid()
125
public void decodeHeader(byte[] b)
127
int packetType = b[FIELD_PACKET_TYPE_POS];
128
logger.fine("packetType" + packetType);
129
String vorbis = Utils.getString(b, VorbisHeader.FIELD_CAPTURE_PATTERN_POS, VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH, "ISO-8859-1");
131
if (packetType == VorbisPacketType.IDENTIFICATION_HEADER.getType() && vorbis.equals(CAPTURE_PATTERN))
133
this.vorbisVersion = b[7] + (b[8] << 8) + (b[9] << 16) + (b[10] << 24);
134
logger.fine("vorbisVersion" + vorbisVersion);
135
this.audioChannels = u(b[FIELD_AUDIO_CHANNELS_POS]);
136
logger.fine("audioChannels" + audioChannels);
137
this.audioSampleRate = u(b[12]) + (u(b[13]) << 8) + (u(b[14]) << 16) + (u(b[15]) << 24);
138
logger.fine("audioSampleRate" + audioSampleRate);
139
logger.fine("audioSampleRate" + b[12] + " " + b[13] + " " + b[14]);
141
//TODO is this right spec says signed
142
this.bitrateMinimal = u(b[16]) + (u(b[17]) << 8) + (u(b[18]) << 16) + (u(b[19]) << 24);
143
this.bitrateNominal = u(b[20]) + (u(b[21]) << 8) + (u(b[22]) << 16) + (u(b[23]) << 24);
144
this.bitrateMaximal = u(b[24]) + (u(b[25]) << 8) + (u(b[26]) << 16) + (u(b[27]) << 24);
145
//byte blockSize0 = (byte) ( b[28] & 240 );
146
//byte blockSize1 = (byte) ( b[28] & 15 );
148
int framingFlag = b[FIELD_FRAMING_FLAG_POS];
149
logger.fine("framingFlag" + framingFlag);
150
if (framingFlag != 0)
2
* Entagged Audio Tag library
3
* Copyright (c) 2003-2005 Raphaël Slinckx <raphael@slinckx.net>
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.
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.
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
19
package org.jaudiotagger.audio.ogg.util;
21
import org.jaudiotagger.audio.generic.Utils;
22
import org.jaudiotagger.audio.ogg.VorbisVersion;
24
import java.util.logging.Logger;
28
* Vorbis Identification header
30
* From http://xiph.org/vorbis/doc/Vorbis_I_spec.html#id326710
32
* The identification header is a short header of only a few fields used to declare the stream definitively as Vorbis,
33
* and provide a few externally relevant pieces of information about the audio stream. The identification header is
36
* 1) [vorbis_version] = read 32 bits as unsigned integer
37
* 2) [audio_channels] = read 8 bit integer as unsigned
38
* 3) [audio_sample_rate] = read 32 bits as unsigned integer
39
* 4) [bitrate_maximum] = read 32 bits as signed integer
40
* 5) [bitrate_nominal] = read 32 bits as signed integer
41
* 6) [bitrate_minimum] = read 32 bits as signed integer
42
* 7) [blocksize_0] = 2 exponent (read 4 bits as unsigned integer)
43
* 8) [blocksize_1] = 2 exponent (read 4 bits as unsigned integer)
44
* 9) [framing_flag] = read one bit
46
* $Id: VorbisIdentificationHeader.java 813 2009-09-03 09:23:25Z paultaylor $
48
* @author Raphael Slinckx (KiKiDonK)
49
* @version 16 d�cembre 2003
51
public class VorbisIdentificationHeader implements VorbisHeader
54
public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.ogg.atom");
56
private int audioChannels;
57
private boolean isValid = false;
59
private int vorbisVersion, audioSampleRate;
60
private int bitrateMinimal, bitrateNominal, bitrateMaximal;
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;
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;
81
public VorbisIdentificationHeader(byte[] vorbisData)
83
decodeHeader(vorbisData);
87
public int getChannelNumber()
93
public String getEncodingType()
95
return VorbisVersion.values()[vorbisVersion].toString();
99
public int getSamplingRate()
101
return audioSampleRate;
104
public int getNominalBitrate()
106
return bitrateNominal;
109
public int getMaxBitrate()
111
return bitrateMaximal;
114
public int getMinBitrate()
116
return bitrateMinimal;
119
public boolean isValid()
125
public void decodeHeader(byte[] b)
127
int packetType = b[FIELD_PACKET_TYPE_POS];
128
logger.fine("packetType" + packetType);
129
String vorbis = Utils.getString(b, VorbisHeader.FIELD_CAPTURE_PATTERN_POS, VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH, "ISO-8859-1");
131
if (packetType == VorbisPacketType.IDENTIFICATION_HEADER.getType() && vorbis.equals(CAPTURE_PATTERN))
133
this.vorbisVersion = b[7] + (b[8] << 8) + (b[9] << 16) + (b[10] << 24);
134
logger.fine("vorbisVersion" + vorbisVersion);
135
this.audioChannels = u(b[FIELD_AUDIO_CHANNELS_POS]);
136
logger.fine("audioChannels" + audioChannels);
137
this.audioSampleRate = u(b[12]) + (u(b[13]) << 8) + (u(b[14]) << 16) + (u(b[15]) << 24);
138
logger.fine("audioSampleRate" + audioSampleRate);
139
logger.fine("audioSampleRate" + b[12] + " " + b[13] + " " + b[14]);
141
//TODO is this right spec says signed
142
this.bitrateMinimal = u(b[16]) + (u(b[17]) << 8) + (u(b[18]) << 16) + (u(b[19]) << 24);
143
this.bitrateNominal = u(b[20]) + (u(b[21]) << 8) + (u(b[22]) << 16) + (u(b[23]) << 24);
144
this.bitrateMaximal = u(b[24]) + (u(b[25]) << 8) + (u(b[26]) << 16) + (u(b[27]) << 24);
145
//byte blockSize0 = (byte) ( b[28] & 240 );
146
//byte blockSize1 = (byte) ( b[28] & 15 );
148
int framingFlag = b[FIELD_FRAMING_FLAG_POS];
149
logger.fine("framingFlag" + framingFlag);
150
if (framingFlag != 0)