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.wav.util;
21
import org.jaudiotagger.audio.exceptions.CannotReadException;
22
import org.jaudiotagger.audio.generic.GenericAudioHeader;
24
import java.io.IOException;
25
import java.io.RandomAccessFile;
27
public class WavInfoReader
29
public GenericAudioHeader read(RandomAccessFile raf) throws CannotReadException, IOException
31
// Reads wav header----------------------------------------
32
GenericAudioHeader info = new GenericAudioHeader();
34
if (raf.length() < 12)
36
throw new CannotReadException("This is not a WAV File (<12 bytes)");
38
byte[] b = new byte[12];
41
WavRIFFHeader wh = new WavRIFFHeader(b);
47
WavFormatHeader wfh = new WavFormatHeader(b);
51
// encodingInfo----------------------------------------------------
52
info.setPreciseLength(((float) raf.length() - (float) 36) / wfh.getBytesPerSecond());
53
info.setChannelNumber(wfh.getChannelNumber());
54
info.setSamplingRate(wfh.getSamplingRate());
55
info.setEncodingType("WAV-RIFF " + wfh.getBitrate() + " bits");
56
info.setExtraEncodingInfos("");
57
info.setBitrate(wfh.getBytesPerSecond() * 8 / 1000);
58
info.setVariableBitRate(false);
62
throw new CannotReadException("Wav Format Header not valid");
67
throw new CannotReadException("Wav RIFF Header not valid");
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.wav.util;
21
import org.jaudiotagger.audio.exceptions.CannotReadException;
22
import org.jaudiotagger.audio.generic.GenericAudioHeader;
24
import java.io.IOException;
25
import java.io.RandomAccessFile;
27
public class WavInfoReader
29
public GenericAudioHeader read(RandomAccessFile raf) throws CannotReadException, IOException
31
// Reads wav header----------------------------------------
32
GenericAudioHeader info = new GenericAudioHeader();
34
if (raf.length() < 12)
36
throw new CannotReadException("This is not a WAV File (<12 bytes)");
38
byte[] b = new byte[12];
41
WavRIFFHeader wh = new WavRIFFHeader(b);
47
WavFormatHeader wfh = new WavFormatHeader(b);
51
// encodingInfo----------------------------------------------------
52
info.setPreciseLength(((float) raf.length() - (float) 36) / wfh.getBytesPerSecond());
53
info.setChannelNumber(wfh.getChannelNumber());
54
info.setSamplingRate(wfh.getSamplingRate());
55
info.setEncodingType("WAV-RIFF " + wfh.getBitrate() + " bits");
56
info.setExtraEncodingInfos("");
57
info.setBitrate(wfh.getBytesPerSecond() * 8 / 1000);
58
info.setVariableBitRate(false);
62
throw new CannotReadException("Wav Format Header not valid");
67
throw new CannotReadException("Wav RIFF Header not valid");
b'\\ No newline at end of file'