pax_global_header 0000666 0000000 0000000 00000000064 12333176744 0014524 g ustar 00root root 0000000 0000000 52 comment=796ec02f09886cca5a8f68b8e56fcc40569a84b6
VorbisJava-vorbis-java-0.6/ 0000775 0000000 0000000 00000000000 12333176744 0015660 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/.gitignore 0000664 0000000 0000000 00000000553 12333176744 0017653 0 ustar 00root root 0000000 0000000 # Lines that start with '#' are comments.
# Ignore class files
*.class
# Ignore vim swp files
.*.swp
# Everyone want's their own Eclipse setup
.project
.classpath
# Skip the build directories
/target/
/core/target/
/tika/target/
/tools/target/
# Skip where we put test files not cleared for inclusion
/DO_NOT_COMMIT/
# Skip the eclipse static includes
/lib/
VorbisJava-vorbis-java-0.6/CHANGES.txt 0000664 0000000 0000000 00000001626 12333176744 0017476 0 ustar 00root root 0000000 0000000 Version 0.7 (In Progress)
(No changes yet)
Version 0.6 (2014-05-09)
* Tika audio parsers extraction of audio length
* Fixed CRC warning on all-255 checksums
Version 0.4 (2014-03-18)
* Improved Tika detection
* Improved Tika parser metadata for general types
* OggStreamIdentifier to make stream type detection cleaner
* Basic Fisbone / Skeleton read support
* Speex support at a similar level to Vorbis
* Comment tools for all supported audio formats
Version 0.3 (2014-03-09)
* Opus support at a similar level to Vorbis
Version 0.2 (2012-08-02)
* Update to Tika 1.2
* Fixed dependency scopes
Version 0.1 (2012-01-26)
* Initial Version
* Read and write support for low-level Vorbis and Ogg
* Read and write support for Vorbis info and tags
* Read support for low level FLAC (FLAC native and FLAC Ogg)
* Tools for reading and writing Vorbis Comments (tags)
* Tika plugin, with Parser and Detector
VorbisJava-vorbis-java-0.6/LICENSE.txt 0000664 0000000 0000000 00000026136 12333176744 0017513 0 ustar 00root root 0000000 0000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
VorbisJava-vorbis-java-0.6/NOTICE.txt 0000664 0000000 0000000 00000000237 12333176744 0017404 0 ustar 00root root 0000000 0000000 Ogg and Vorbis Tools for Java
Copyright 2012 Nick Burch
The Apache Tika Plugin includes developed at
The Apache Software Foundation (http://www.apache.org/).
VorbisJava-vorbis-java-0.6/README.txt 0000664 0000000 0000000 00000012442 12333176744 0017361 0 ustar 00root root 0000000 0000000 Ogg and Vorbis Tools for Java
-----------------------------
This library is a pure Java, Apache v2 licensed project for working with
Ogg, Vorbis, FLAC, Opus and Speex files
Currently, support for the Ogg container is fairly complete, offering
the ability to read, write, add and change streams within an Ogg file.
It should be possible to use the Ogg parts as a basis for dealing with
any multimedia data stored in an Ogg container. There is basic support for
Skeleton Annodex streams, which provide metadata on top of Ogg files about
the streams, but it isn't fully integrated.
Support for the Vorbis audio format so far concentrates on metadata.
It is possible to retrieve and change metadata (such as sampling rates,
user comments etc), and tools are provided to query and alter these
(see the Tools section below). At this time, there is no support for
decoding or encoding audio data. Contributions for these areas would
be welcomed!
Opus and Speex support is slightly less than that of Vorbis, covering
retrieving of metadata (such as sampling rates, user comments etc). However,
basic Opus or Speex audio frame support is outstanding. Tooling exists
for querying and changing metadata for Opus only. Contributions to expand
Opus or Speex support are most appreciated!
Very limited support is also included for FLAC comments (user metadata),
which use the same scheme as Vorbis. FLAC-native and FLAC-in-Ogg files
are both supproted for extracting the user metadata.
Tools
-----
As part of the project, a small number of pure Java tools are provided
to help when working with Ogg and Vorbis files.
Two jar files are available. **vorbis-java-tools.jar** should be used when
embedding the code, while **vorbis-java-tools-jar-with-dependencies.jar**
is what should be used for standlone cases, as all dependencies are
included.
org.gagravarr.ogg.tools.OggInfoTool
Prints basic information on the streams in a file
org.gagravarr.vorbis.tools.VorbisInfoTool
Prints detailed information on the contents of a Vorbis file, including
versions, comments, bitrates, channels and audio rates, codebooks
and file length
org.gagravarr.vorbis.tools.VorbisCommentTool
Allows the listing and editing of comments (user metadata) of a Vorbis
file. Works similar to *vorbiscomment* commandline tool that ships
with libvorbis
org.gagravarr.opus.tools.OpusCommentTool
Allows the listing and editing of comments (user metadata) of an Opus
file. Works similar to *vorbiscomment* commandline tool that ships
with libvorbis, except for Opus files
org.gagravarr.flac.tools.FlacCommentTool
Allows the listing of comments (user metadata) of a Flac file (native or
ogg contained) file. Works similar to *vorbiscomment* commandline tool
that ships with libvorbis, except for Flac files, and lists only
Apache Tika
-----------
Included in the tika module are Parser and Detector plugins for
Apache Tika for Ogg based file formats. Currently, parsers are only available
for the Audio formats (Vorbis, Opus, Speex, Flac), but a basic stream info
outputting parser exists for other Ogg types. Detection should handle all
the well known Ogg formats (Audio and Video).
The parsers and detector include appropriate service registry entries for Tika
to allow these plugins to be automatically loaded by Tika. Simply ensure that
the tika module, and the core module are present on the Tika classpath and
they will be used.
Getting Started
---------------
There are five main classes that you can start with, depending on the
kind of file you have, and your interests. These are:
org.gagravarr.ogg.OggFile
Provides read and write support for Ogg files of all types, working
at the packet / stream level
org.gagravarr.vorbis.VorbisFile
Provides read and write support for Ogg Vorbis audio files. Provides
access to the key parts of the Vorbis file, such as info and comments.
(No support yet for encoding or decoding the audio packets though)
org.gagravarr.opus.OpusFile
Provides read support for Ogg Opus audio files. Provides access to
the key parts of the Opus file, such as info and comments.
(No support at all for audio packets, for now)
org.gagravarr.flac.FlacOggFile
Provides read support for FLAC files stored in an Ogg container. Allows
access to the key parts of the file, such as Info, Tags and compressed
audio. (No encoding or decoding of audio packets though)
org.gagravarr.flac.FlacFile
Provides read support for regular FLAC files. Provides access to the
key parts of the file, such as Info, Tags and compressed audio.
(No encoding or decoding of audio packets though)
The best way to see how to use the code is to look at the Tools Package,
which has examples of reading and writing tags, and the Tika Package, which
has examples of reading audio metadata. In addition, the unit tests can
provide examples of uses too.
Information Resources
---------------------
* Ogg file format - RFC3533, plus http://xiph.org/vorbis/doc/oggstream.html
and http://xiph.org/vorbis/doc/framing.html
* Vorbis - http://xiph.org/vorbis/doc/
* Opus - http://www.opus-codec.org/docs/
* FLAC - http://flac.sourceforge.net/format.html
* FLAC in Ogg - http://flac.sourceforge.net/ogg_mapping.html
* Tika - http://tika.apache.org/
VorbisJava-vorbis-java-0.6/RELEASING.txt 0000664 0000000 0000000 00000001165 12333176744 0017735 0 ustar 00root root 0000000 0000000 Before the release:
* Update the version strings and dates in the files which embed them:
core/src/main/java/org/gagravarr/speex/SpeexInfo.java
core/src/main/java/org/gagravarr/vorbis/VorbisStyleComments.java
* Ensure the CHANGES file is up-to-date
* Try running Apache Tika with a manual build of the new version, and
ensure all Tika tests pass
To release:
* Follow the Sonatype Guide
https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-7a.DeploySnapshotsandStageReleaseswithMaven
After the release:
* Upgrade the dependency in Apache Tika
VorbisJava-vorbis-java-0.6/TODO.txt 0000664 0000000 0000000 00000000234 12333176744 0017165 0 ustar 00root root 0000000 0000000 Better exceptions
FLAC Ogg support
FLAC native support
--Tricky packet/page boundary read test
--Packet/page boundary write test
--Vorbis detection helper
VorbisJava-vorbis-java-0.6/core/ 0000775 0000000 0000000 00000000000 12333176744 0016610 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/pom.xml 0000664 0000000 0000000 00000003177 12333176744 0020135 0 ustar 00root root 0000000 0000000
4.0.0
org.gagravarr
vorbis-java-parent
../parent/pom.xml
0.6
vorbis-java-core
jar
Ogg and Vorbis for Java, Core
https://github.com/Gagravarr/VorbisJava
org.apache.maven.plugins
maven-jar-plugin
jar-test-classes
package
test-jar
VorbisJava-vorbis-java-0.6/core/src/ 0000775 0000000 0000000 00000000000 12333176744 0017377 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/src/main/ 0000775 0000000 0000000 00000000000 12333176744 0020323 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/src/main/java/ 0000775 0000000 0000000 00000000000 12333176744 0021244 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/src/main/java/org/ 0000775 0000000 0000000 00000000000 12333176744 0022033 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/ 0000775 0000000 0000000 00000000000 12333176744 0024007 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/ 0000775 0000000 0000000 00000000000 12333176744 0024714 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacAudioFrame.java 0000664 0000000 0000000 00000001730 12333176744 0030362 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
/**
* Raw, compressed audio data.
* TODO Parse into constituent parts
*/
public class FlacAudioFrame extends FlacFrame {
private byte[] data; // TODO Parse
private long position; // TODO Is this always there?
public FlacAudioFrame(byte[] data) {
this.data = data;
}
// TODO InputStream based constructor?
public byte[] getData() {
return data;
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacFile.java 0000664 0000000 0000000 00000005767 12333176744 0027243 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.gagravarr.ogg.IOUtils;
import org.gagravarr.ogg.OggFile;
/**
* This wrapper lets you work with FLAC files,
* whether they're Ogg or Native framed.
*/
public abstract class FlacFile {
protected FlacInfo info;
protected FlacTags tags;
protected List otherMetadata;
/**
* Opens the given file for reading
*/
public static FlacFile open(File f) throws IOException, FileNotFoundException {
// Open, in a way that we can skip backwards a few bytes
InputStream inp = new BufferedInputStream(new FileInputStream(f), 8);
FlacFile file = open(inp);
inp.close();
return file;
}
/**
* Opens the given file for reading.
* @param inp The InputStrem to read from, which must support mark/reset
*/
public static FlacFile open(InputStream inp) throws IOException, FileNotFoundException {
inp.mark(4);
byte[] header = new byte[4];
IOUtils.readFully(inp, header);
inp.reset();
if(header[0] == (byte)'O' && header[1] == (byte)'g' &&
header[2] == (byte)'g' && header[3] == (byte)'S') {
return new FlacOggFile(new OggFile(inp));
}
if(header[0] == (byte)'f' && header[1] == (byte)'L' &&
header[2] == (byte)'a' && header[3] == (byte)'C') {
return new FlacNativeFile(inp);
}
throw new IllegalArgumentException("File type not recognised");
}
/**
* Opens the given file for reading
*/
public static FlacFile open(OggFile ogg) throws IOException {
return new FlacOggFile(ogg);
}
public abstract FlacAudioFrame getNextAudioPacket() throws IOException;
/**
* Skips the audio data to the next packet with a granule
* of at least the given granule position.
* Note that skipping backwards is not currently supported!
*/
public abstract void skipToGranule(long granulePosition) throws IOException;
public FlacInfo getInfo() {
return info;
}
public FlacTags getTags() {
return tags;
}
/**
* In Reading mode, will close the underlying ogg/flac
* file and free its resources.
* In Writing mode, will write out the Info and
* Comments objects, and then the audio data.
*/
public abstract void close() throws IOException;
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacFirstOggPacket.java 0000664 0000000 0000000 00000010071 12333176744 0031220 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.gagravarr.ogg.HighLevelOggStreamPacket;
import org.gagravarr.ogg.IOUtils;
import org.gagravarr.ogg.OggPacket;
/**
* The first Flac packet stored in an Ogg stream is
* special. This holds both the stream information,
* and the {@link FlacFrame}
*/
public class FlacFirstOggPacket extends HighLevelOggStreamPacket {
private int majorVersion;
private int minorVersion;
private int numberOfHeaderBlocks;
private FlacInfo info;
public FlacFirstOggPacket() {
this(new FlacInfo());
}
public FlacFirstOggPacket(FlacInfo info) {
super();
majorVersion = 1;
minorVersion = 0;
numberOfHeaderBlocks = 0;
this.info = info;
}
public FlacFirstOggPacket(OggPacket oggPacket) {
super(oggPacket);
// Extract the info
byte[] data = getData();
// 0 = 0x7f
// 1-4 = FLAC
majorVersion = IOUtils.toInt(data[5]);
minorVersion = IOUtils.toInt(data[6]);
numberOfHeaderBlocks = IOUtils.getInt2BE(data, 7);
// 9-12 = fLaC
// 13-16 = 0 + length
// Then it's the info
info = new FlacInfo(data, 17);
}
@Override
public OggPacket write() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos.write("FLAC".getBytes("ASCII"));
baos.write(majorVersion);
baos.write(minorVersion);
IOUtils.writeInt2BE(baos, numberOfHeaderBlocks);
baos.write("fLaC".getBytes("ASCII"));
baos.write(info.getData());
} catch(IOException e) {
// Should never happen!
throw new RuntimeException(e);
}
setData(baos.toByteArray());
return super.write();
}
/**
* Returns the Major Version number
*/
public int getMajorVersion() {
return majorVersion;
}
public void setMajorVersion(int majorVersion) {
if(majorVersion > 255) {
throw new IllegalArgumentException("Version numbers must be in the range 0-255");
}
this.majorVersion = majorVersion;
}
public FlacInfo getInfo() {
return info;
}
/**
* Returns the Minor Version number. Decoders should be able to
* handle anything at a given major number, no matter the minor one
*/
public int getMinorVersion() {
return minorVersion;
}
public void setMinorVersion(int minorVersion) {
if(minorVersion > 255) {
throw new IllegalArgumentException("Version numbers must be in the range 0-255");
}
this.minorVersion = minorVersion;
}
/**
* Gets the number of header blocks, excluding this one, or
* zero if not known
*/
public int getNumberOfHeaderBlocks() {
return numberOfHeaderBlocks;
}
public void setNumberOfHeaderBlocks(int numberOfHeaderBlocks) {
this.numberOfHeaderBlocks = numberOfHeaderBlocks;
}
/**
* Does this packet (the first in the stream) contain
* the magic string indicating that it's a FLAC
* one?
*/
public static boolean isFlacStream(OggPacket firstPacket) {
if(! firstPacket.isBeginningOfStream()) {
return false;
}
return isFlacSpecial(firstPacket);
}
private static boolean isFlacSpecial(OggPacket packet) {
byte[] d = packet.getData();
byte type = d[0];
// Ensure 0x7f then "FLAC"
if(type == 0x7f) {
if(d[1] == (byte)'F' &&
d[2] == (byte)'L' &&
d[3] == (byte)'A' &&
d[4] == (byte)'C') {
return true;
}
}
return false;
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacFrame.java 0000664 0000000 0000000 00000001470 12333176744 0027401 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
/**
* A Flac frame may be in a native bitstream, or wrapped in an OggPacket.
* It may either be a {@link FlacMetadataBlock} or a {@link FlacAudioFrame}.
*/
public abstract class FlacFrame {
public abstract byte[] getData();
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacInfo.java 0000664 0000000 0000000 00000013764 12333176744 0027253 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.IOException;
import java.io.OutputStream;
import org.gagravarr.ogg.IOUtils;
/**
* The Stream Info metadata block holds useful
* information on the audio data of the file
*/
public class FlacInfo extends FlacMetadataBlock {
/**
* <16> The minimum block size (in samples) used in the stream.
*/
private int minimumBlockSize;
/**
* <16> The maximum block size (in samples) used in the stream. (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
*/
private int maximumBlockSize;
/**
* <24> The minimum frame size (in bytes) used in the stream. May be 0 to imply the value is not known.
*/
private int minimumFrameSize;
/**
* <24> The maximum frame size (in bytes) used in the stream. May be 0 to imply the value is not known.
*/
private int maximumFrameSize;
/**
* <20> Sample rate in Hz. Though 20 bits are available, the maximum sample
* rate is limited by the structure of frame headers to 655350Hz.
* Also, a value of 0 is invalid.
*/
private int sampleRate;
/**
* <3> (number of channels)-1. FLAC supports from 1 to 8 channels
*/
private int numChannels;
/**
* <5> (bits per sample)-1. FLAC supports from 4 to 32 bits per sample.
* Currently the reference encoder and decoders only support up to
* 24 bits per sample.
*/
private int bitsPerSample;
/**
* <36> Total samples in stream. 'Samples' means inter-channel sample,
* i.e. one second of 44.1Khz audio will have 44100 samples regardless
* of the number of channels.
* A value of zero here means the number of total samples is unknown.
*/
private long numberOfSamples;
/**
* <128> MD5 signature of the unencoded audio data.
*/
private byte[] signature;
/**
* Creates a new, empty info
*/
public FlacInfo() {
super(STREAMINFO);
signature = new byte[16];
}
/**
* Reads the Info from the specified data
*/
public FlacInfo(byte[] data, int offset) {
super(STREAMINFO);
// Grab the range numbers
minimumBlockSize = IOUtils.getIntBE(
IOUtils.toInt(data[offset++]),
IOUtils.toInt(data[offset++])
);
maximumBlockSize = IOUtils.getIntBE(
IOUtils.toInt(data[offset++]),
IOUtils.toInt(data[offset++])
);
minimumFrameSize = (int)IOUtils.getIntBE(
IOUtils.toInt(data[offset++]),
IOUtils.toInt(data[offset++]),
IOUtils.toInt(data[offset++])
);
maximumFrameSize = (int)IOUtils.getIntBE(
IOUtils.toInt(data[offset++]),
IOUtils.toInt(data[offset++]),
IOUtils.toInt(data[offset++])
);
// The next bit is stored LE, bit packed
int[] next = new int[8];
for(int i=0; i<8; i++) {
next[i] = IOUtils.toInt(data[i+offset]);
}
offset += 8;
sampleRate = (next[0]<<12) + (next[1]<<4) + ((next[2]&0xf0)>>4);
numChannels = ((next[2] & 0x0e) >> 1) + 1;
bitsPerSample = ((next[2]&0x01)<<4) + ((next[3]&0xf0)>>4) + 1;
numberOfSamples = ((next[3]&0x0f)<<30) + (next[4]<<24) +
(next[5]<<16) + (next[6]<<8) + next[7];
// Get the signature
signature = new byte[16];
System.arraycopy(data, offset, signature, 0, 16);
}
@Override
protected void write(OutputStream out) throws IOException {
// Write the frame numbers
IOUtils.writeInt2BE(out, minimumBlockSize);
IOUtils.writeInt2BE(out, maximumBlockSize);
IOUtils.writeInt3BE(out, minimumFrameSize);
IOUtils.writeInt3BE(out, maximumFrameSize);
// Write the rates/channels/samples
// TODO
out.write(new byte[8]);
// Write the signature
out.write(signature);
}
/**
* The minimum block size (in samples) used in the stream.
*/
public int getMinimumBlockSize() {
return minimumBlockSize;
}
public void setMinimumBlockSize(int minimumBlockSize) {
this.minimumBlockSize = minimumBlockSize;
}
/**
* The maximum block size (in samples) used in the stream.
* (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
*/
public int getMaximumBlockSize() {
return maximumBlockSize;
}
public void setMaximumBlockSize(int maximumBlockSize) {
this.maximumBlockSize = maximumBlockSize;
}
public int getMinimumFrameSize() {
return minimumFrameSize;
}
public void setMinimumFrameSize(int minimumFrameSize) {
this.minimumFrameSize = minimumFrameSize;
}
public int getMaximumFrameSize() {
return maximumFrameSize;
}
public void setMaximumFrameSize(int maximumFrameSize) {
this.maximumFrameSize = maximumFrameSize;
}
public int getSampleRate() {
return sampleRate;
}
public void setSampleRate(int sampleRate) {
this.sampleRate = sampleRate;
}
public int getNumChannels() {
return numChannels;
}
public void setNumChannels(int numChannels) {
this.numChannels = numChannels;
}
public int getBitsPerSample() {
return bitsPerSample;
}
public void setBitsPerSample(int bitsPerSample) {
this.bitsPerSample = bitsPerSample;
}
public long getNumberOfSamples() {
return numberOfSamples;
}
public void setNumberOfSamples(long numberOfSamples) {
this.numberOfSamples = numberOfSamples;
}
public byte[] getSignature() {
return signature;
}
public void setSignature(byte[] signature) {
this.signature = signature;
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacMetadataBlock.java 0000664 0000000 0000000 00000005472 12333176744 0031050 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.gagravarr.ogg.IOUtils;
/**
* This comes before the audio data.
* Made up of a series of:
* 1 byte type
* 3 byte length
*
*/
public abstract class FlacMetadataBlock extends FlacFrame {
public static final byte STREAMINFO = 0;
public static final byte PADDING = 1;
public static final byte APPLICATION = 2;
public static final byte SEEKTABLE = 3;
public static final byte VORBIS_COMMENT = 4;
public static final byte CUESHEET = 5;
public static final byte PICTURE = 6;
// 7-126 : reserved
// 127 : invalid, to avoid confusion with a frame sync code
private byte type;
public static FlacMetadataBlock create(InputStream inp) throws IOException {
int typeI = inp.read();
if(typeI == -1) {
throw new IllegalArgumentException();
}
byte type = IOUtils.fromInt(typeI);
byte[] l = new byte[3];
IOUtils.readFully(inp, l);
int length = (int)IOUtils.getInt3BE(l);
byte[] data = new byte[length];
IOUtils.readFully(inp, data);
switch(type) {
case STREAMINFO:
return new FlacInfo(data, 0);
case VORBIS_COMMENT:
return new FlacTags.FlacTagsAsMetadata(data);
default:
return new FlacUnhandledMetadataBlock(type, data);
}
}
protected FlacMetadataBlock(byte type) {
this.type = type;
}
public int getType() {
return type & 0x7f;
}
public boolean isLastMetadataBlock() {
return (type < 0);
}
public byte[] getData() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
// Type goes first
baos.write(type);
// Pad length, will do later
baos.write(new byte[3]);
// Do the main data
write(baos);
} catch(IOException e) {
// Shouldn't ever happen!
throw new RuntimeException(e);
}
// Fix the length
byte[] data = baos.toByteArray();
IOUtils.putInt3BE(data, 1, data.length);
// All done
return data;
}
protected abstract void write(OutputStream out) throws IOException;
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacNativeFile.java 0000664 0000000 0000000 00000005767 12333176744 0030412 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.gagravarr.flac.FlacTags.FlacTagsAsMetadata;
import org.gagravarr.ogg.IOUtils;
/**
* This lets you work with FLAC files that
* are contained in a native FLAC Stream
*/
public class FlacNativeFile extends FlacFile {
private InputStream input;
/**
* Opens the given file for reading
*/
public FlacNativeFile(File f) throws IOException, FileNotFoundException {
this(new FileInputStream(f));
}
/**
* Opens the given FLAC file
*/
public FlacNativeFile(InputStream inp) throws IOException {
// Check the header
byte[] header = new byte[4];
IOUtils.readFully(inp, header);
if(header[0] == (byte)'f' && header[1] == (byte)'L' &&
header[2] == (byte)'a' && header[3] == (byte)'C') {
// Good
} else {
throw new IllegalArgumentException("Not a FLAC file");
}
// First must be the FLAC info
info = (FlacInfo)FlacMetadataBlock.create(inp);
// Read the rest of the Metadata blocks
otherMetadata = new ArrayList();
while(true) {
FlacMetadataBlock m = FlacMetadataBlock.create(inp);
if(m instanceof FlacTagsAsMetadata) {
tags = ((FlacTagsAsMetadata)m).getTags();
} else {
otherMetadata.add(m);
}
if(m.isLastMetadataBlock()) {
break;
}
}
// Rest is audio
}
public FlacAudioFrame getNextAudioPacket() throws IOException {
// TODO How to know how long the frames are?
return new FlacAudioFrame(null);
}
/**
* Skips the audio data to the next packet with a granule
* of at least the given granule position.
* Note that skipping backwards is not currently supported!
*/
public void skipToGranule(long granulePosition) throws IOException {
throw new RuntimeException("Not supported");
}
/**
* In Reading mode, will close the underlying ogg/flac
* file and free its resources.
* In Writing mode, will write out the Info and
* Comments objects, and then the audio data.
*/
public void close() throws IOException {
if(input != null) {
input.close();
input = null;
} else {
throw new RuntimeException("Not supported");
}
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacOggFile.java 0000664 0000000 0000000 00000015115 12333176744 0027664 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.gagravarr.ogg.OggFile;
import org.gagravarr.ogg.OggPacket;
import org.gagravarr.ogg.OggPacketReader;
import org.gagravarr.ogg.OggPacketWriter;
import org.gagravarr.vorbis.VorbisPacket;
/**
* This lets you work with FLAC files that
* are contained in an Ogg Stream
*/
public class FlacOggFile extends FlacFile {
private OggFile ogg;
private OggPacketReader r;
private OggPacketWriter w;
private int sid = -1;
private FlacFirstOggPacket firstPacket;
private List writtenAudio;
/**
* Opens the given file for reading
*/
public FlacOggFile(File f) throws IOException, FileNotFoundException {
this(new OggFile(new FileInputStream(f)));
}
/**
* Opens the given file for reading
*/
public FlacOggFile(OggFile ogg) throws IOException {
this(ogg.getPacketReader());
this.ogg = ogg;
}
/**
* Loads a Vorbis File from the given packet reader.
*/
public FlacOggFile(OggPacketReader r) throws IOException {
this.r = r;
OggPacket p = null;
while( (p = r.getNextPacket()) != null ) {
if(p.isBeginningOfStream() && p.getData().length > 10) {
if(FlacFirstOggPacket.isFlacStream(p)) {
sid = p.getSid();
break;
}
}
}
// First packet is special
firstPacket = new FlacFirstOggPacket(p);
info = firstPacket.getInfo();
// Next must be the Tags (Comments)
tags = new FlacTags(r.getNextPacketWithSid(sid));
// Then continue until the last metadata
otherMetadata = new ArrayList();
while( (p = r.getNextPacketWithSid(sid)) != null ) {
FlacMetadataBlock block = FlacMetadataBlock.create(new ByteArrayInputStream(p.getData()));
otherMetadata.add(block);
if(block.isLastMetadataBlock()) {
break;
}
}
// Everything else should be audio data
}
/**
* Opens for writing.
*/
public FlacOggFile(OutputStream out) {
this(out, new FlacInfo(), new FlacTags());
}
/**
* Opens for writing, based on the settings
* from a pre-read file. The Steam ID (SID) is
* automatically allocated for you.
*/
public FlacOggFile(OutputStream out, FlacInfo info, FlacTags tags) {
this(out, -1, info, tags);
}
/**
* Opens for writing, based on the settings
* from a pre-read file, with a specific
* Steam ID (SID). You should only set the SID
* when copying one file to another!
*/
public FlacOggFile(OutputStream out, int sid, FlacInfo info, FlacTags tags) {
ogg = new OggFile(out);
if(sid > 0) {
w = ogg.getPacketWriter(sid);
this.sid = sid;
} else {
w = ogg.getPacketWriter();
this.sid = w.getSid();
}
writtenAudio = new ArrayList();
this.firstPacket = new FlacFirstOggPacket(info);
this.info = info;
this.tags = tags;
}
/**
* Returns the first Ogg Packet, which has some metadata in it
*/
public FlacFirstOggPacket getFirstPacket() {
return firstPacket;
}
public FlacAudioFrame getNextAudioPacket() throws IOException {
OggPacket p = null;
VorbisPacket vp = null;
while( (p = r.getNextPacketWithSid(sid)) != null ) {
return new FlacAudioFrame(p.getData());
}
return null;
}
/**
* Skips the audio data to the next packet with a granule
* of at least the given granule position.
* Note that skipping backwards is not currently supported!
*/
public void skipToGranule(long granulePosition) throws IOException {
r.skipToGranulePosition(sid, granulePosition);
}
/**
* Returns the Ogg Stream ID
*/
public int getSid() {
return sid;
}
/**
* Buffers the given audio ready for writing
* out. Data won't be written out yet, you
* need to call {@link #close()} to do that,
* because we assume you'll still be populating
* the Info/Comment/Setup objects
*/
public void writeAudioData(FlacAudioFrame data) {
writtenAudio.add(data);
}
/**
* In Reading mode, will close the underlying ogg
* file and free its resources.
* In Writing mode, will write out the Info, Comments
* and Setup objects, and then the audio data.
*/
public void close() throws IOException {
if(r != null) {
r = null;
ogg.close();
ogg = null;
}
if(w != null) {
w.bufferPacket(firstPacket.write(), true);
w.bufferPacket(tags.write(), false);
// TODO Write the others
//w.bufferPacket(setup.write(), true);
long lastGranule = 0;
for(FlacAudioFrame fa : writtenAudio) {
// Update the granule position as we go
// TODO Track this
// if(vd.getGranulePosition() >= 0 &&
// lastGranule != vd.getGranulePosition()) {
// w.flush();
// lastGranule = vd.getGranulePosition();
// w.setGranulePosition(lastGranule);
// }
// Write the data, flushing if needed
w.bufferPacket(new OggPacket(fa.getData()));
if(w.getSizePendingFlush() > 16384) {
w.flush();
}
}
w.close();
w = null;
ogg.close();
ogg = null;
}
}
/**
* Returns the underlying Ogg File instance
* @return
*/
public OggFile getOggFile() {
return ogg;
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacTags.java 0000664 0000000 0000000 00000005066 12333176744 0027252 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.IOException;
import java.io.OutputStream;
import org.gagravarr.ogg.IOUtils;
import org.gagravarr.ogg.OggPacket;
import org.gagravarr.vorbis.VorbisComments;
import org.gagravarr.vorbis.VorbisStyleComments;
/**
* This is a {@link VorbisComments} with a Flac metadata
* block header, rather than the usual vorbis one.
*/
public class FlacTags extends VorbisStyleComments {
public FlacTags(OggPacket packet) {
super(packet, 4);
// Verify the type
byte type = getData()[0];
if(type != FlacMetadataBlock.VORBIS_COMMENT) {
throw new IllegalArgumentException("Invalid type " + type);
}
}
public FlacTags() {
super();
}
/**
* Type plus three byte length
*/
@Override
public int getHeaderSize() {
return 4;
}
/**
* Type plus three byte length
*/
@Override
public void populateMetadataHeader(byte[] b, int dataLength) {
b[0] = FlacMetadataBlock.VORBIS_COMMENT;
IOUtils.putInt3BE(b, 1, dataLength);
}
@Override
protected void populateMetadataFooter(OutputStream out) {
// No footer needed on FLAC Tag Packets
}
protected static class FlacTagsAsMetadata extends FlacMetadataBlock {
private FlacTags tags;
protected FlacTagsAsMetadata(byte[] data) {
super(VORBIS_COMMENT);
// This is the only metadata which needs the type
// and length in addition to the main data
byte[] d = new byte[data.length+4];
d[0] = FlacMetadataBlock.VORBIS_COMMENT;
System.arraycopy(data, 0, d, 4, data.length);
this.tags = new FlacTags(new OggPacket(d));
}
@Override
public byte[] getData() {
return tags.getData();
}
@Override
protected void write(OutputStream out) throws IOException {
throw new IllegalStateException("Must not call directly");
}
public FlacTags getTags() {
return tags;
}
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/flac/FlacUnhandledMetadataBlock.java 0000664 0000000 0000000 00000001762 12333176744 0032671 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.flac;
import java.io.IOException;
import java.io.OutputStream;
/**
* Any Flac Metadata Block we don't explicitly handle
*/
public class FlacUnhandledMetadataBlock extends FlacMetadataBlock {
private byte[] data;
public FlacUnhandledMetadataBlock(byte type, byte[] data) {
super(type);
this.data = data;
}
protected void write(OutputStream out) throws IOException {
out.write(data);
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/ogg/ 0000775 0000000 0000000 00000000000 12333176744 0024563 5 ustar 00root root 0000000 0000000 VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/ogg/CRCUtils.java 0000664 0000000 0000000 00000002715 12333176744 0027063 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.ogg;
public class CRCUtils {
protected static final int CRC_POLYNOMIAL = 0x04c11db7;
private static int[] CRC_TABLE = new int[256];
static {
int crc;
for(int i=0; i<256; i++) {
crc = i << 24;
for(int j=0; j<8; j++) {
if( (crc & 0x80000000) != 0 ) {
crc = ((crc << 1) ^ CRC_POLYNOMIAL);
} else {
crc <<= 1;
}
}
CRC_TABLE[i] = crc;
}
}
public static int getCRC(byte[] data) {
return getCRC(data, 0);
}
public static int getCRC(byte[] data, int previous) {
int crc = previous;
int a,b;
for(int i=0; i>>24) & 0xff) ^ (data[i] & 0xff) ];
crc = a ^ b;
}
return crc;
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/ogg/HighLevelOggStreamPacket.java 0000664 0000000 0000000 00000002603 12333176744 0032237 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.ogg;
/**
* A high level stream packet sat atop
* of an OggPacket.
* Provides support for reading and writing
* new and existing OggPacket instances.
*/
public abstract class HighLevelOggStreamPacket implements OggStreamPacket {
private OggPacket oggPacket;
private byte[] data;
protected HighLevelOggStreamPacket(OggPacket oggPacket) {
this.oggPacket = oggPacket;
}
protected HighLevelOggStreamPacket() {
this.oggPacket = null;
}
protected OggPacket getOggPacket() {
return oggPacket;
}
public byte[] getData() {
if(data != null) {
return data;
}
if(oggPacket != null) {
return oggPacket.getData();
}
return null;
}
public void setData(byte[] data) {
this.data = data;
}
public OggPacket write() {
this.oggPacket = new OggPacket(getData());
return this.oggPacket;
}
}
VorbisJava-vorbis-java-0.6/core/src/main/java/org/gagravarr/ogg/IOUtils.java 0000664 0000000 0000000 00000024415 12333176744 0026764 0 ustar 00root root 0000000 0000000 /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gagravarr.ogg;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
/**
* Utilities for working with IO streams, such
* as reading and writing.
*
* Endian Note - Ogg and Vorbis tend to work in
* Little Endian format, while FLAC tends to
* work in Big Endian format.
*/
public class IOUtils {
public static void readFully(InputStream inp, byte[] destination) throws IOException {
readFully(inp, destination, 0, destination.length);
}
public static void readFully(InputStream inp, byte[] destination, int offset, int length) throws IOException {
int read = 0;
int r;
while(read < length) {
r = inp.read(destination, offset+read, length-read);
if(r == -1) {
throw new IOException("Asked to read " + length + " bytes from " + offset + " but hit EoF at " + read);
}
read += r;
}
}
public static int toInt(byte b) {
if(b < 0)
return b & 0xff;
return b;
}
public static byte fromInt(int i) {
if(i > 256) {
throw new IllegalArgumentException("Number " + i + " too big");
}
if(i > 127) {
return (byte)(i-256);
}
return (byte)i;
}
public static int getInt2(byte[] data) {
return getInt2(data, 0);
}
public static int getInt2(byte[] data, int offset) {
int i=offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
return getInt(b0, b1);
}
public static long getInt3(byte[] data) {
return getInt3(data, 0);
}
public static long getInt3(byte[] data, int offset) {
int i=offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
int b2 = data[i++] & 0xFF;
return getInt(b0, b1, b2);
}
public static long getInt4(byte[] data) {
return getInt4(data, 0);
}
public static long getInt4(byte[] data, int offset) {
int i=offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
int b2 = data[i++] & 0xFF;
int b3 = data[i++] & 0xFF;
return getInt(b0, b1, b2, b3);
}
public static long getInt8(byte[] data) {
return getInt8(data, 0);
}
public static long getInt8(byte[] data, int offset) {
int i=offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
int b2 = data[i++] & 0xFF;
int b3 = data[i++] & 0xFF;
int b4 = data[i++] & 0xFF;
int b5 = data[i++] & 0xFF;
int b6 = data[i++] & 0xFF;
int b7 = data[i++] & 0xFF;
return getInt(b0, b1, b2, b3, b4, b5, b6, b7);
}
public static int getInt(int i0, int i1) {
return (i1 << 8) + (i0 << 0);
}
public static long getInt(int i0, int i1, int i2) {
return (i2 << 16) + (i1 << 8) + (i0 << 0);
}
public static long getInt(int i0, int i1, int i2, int i3) {
return (i3 << 24) + (i2 << 16) + (i1 << 8) + (i0 << 0);
}
public static long getInt(int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7) {
// Special check for all 0xff, to avoid overflowing long
if (i0 == 255 && i1 == 255 && i3 == 255 && i4 == 255 && i5 == 255 && i6 == 255 && i7 == 255) return -1l;
// Otherwise normal convert
return (long)(i7 << 56) + (long)(i6 << 48) +
(long)(i5 << 40) + (long)(i4 << 32) +
(i3 << 24) + (i2 << 16) + (i1 << 8) + (i0 << 0);
}
public static int getInt2BE(byte[] data) {
return getInt2BE(data, 0);
}
public static int getInt2BE(byte[] data, int offset) {
int i=offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
return getIntBE(b0, b1);
}
public static long getInt3BE(byte[] data) {
return getInt3BE(data, 0);
}
public static long getInt3BE(byte[] data, int offset) {
int i=offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
int b2 = data[i++] & 0xFF;
return getIntBE(b0, b1, b2);
}
public static long getInt4BE(byte[] data) {
return getInt4BE(data, 0);
}
public static long getInt4BE(byte[] data, int offset) {
int i=offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
int b2 = data[i++] & 0xFF;
int b3 = data[i++] & 0xFF;
return getIntBE(b0, b1, b2, b3);
}
public static int getIntBE(int i0, int i1) {
return (i0 << 8) + (i1 << 0);
}
public static long getIntBE(int i0, int i1, int i2) {
return (i0 << 16) + (i1 << 8) + (i2 << 0);
}
public static long getIntBE(int i0, int i1, int i2, int i3) {
return (i0 << 24) + (i1 << 16) + (i2 << 8) + (i3 << 0);
}
public static void writeInt2(OutputStream out, int v) throws IOException {
byte[] b2 = new byte[2];
putInt2(b2, 0, v);
out.write(b2);
}
public static void putInt2(byte[] data, int offset, int v) {
int i = offset;
data[i++] = (byte)((v >>> 0) & 0xFF);
data[i++] = (byte)((v >>> 8) & 0xFF);
}
public static void writeInt3(OutputStream out, long v) throws IOException {
byte[] b3 = new byte[3];
putInt3(b3, 0, v);
out.write(b3);
}
public static void putInt3(byte[] data, int offset, long v) {
int i = offset;
data[i++] = (byte)((v >>> 0) & 0xFF);
data[i++] = (byte)((v >>> 8) & 0xFF);
data[i++] = (byte)((v >>> 16) & 0xFF);
}
public static void writeInt4(OutputStream out, long v) throws IOException {
byte[] b4 = new byte[4];
putInt4(b4, 0, v);
out.write(b4);
}
public static void putInt4(byte[] data, int offset, long v) {
int i = offset;
data[i++] = (byte)((v >>> 0) & 0xFF);
data[i++] = (byte)((v >>> 8) & 0xFF);
data[i++] = (byte)((v >>> 16) & 0xFF);
data[i++] = (byte)((v >>> 24) & 0xFF);
}
public static void writeInt8(OutputStream out, long v) throws IOException {
byte[] b8 = new byte[8];
putInt8(b8, 0, v);
out.write(b8);
}
public static void putInt8(byte[] data, int offset, long v) {
int i = offset;
data[i++] = (byte)((v >>> 0) & 0xFF);
data[i++] = (byte)((v >>> 8) & 0xFF);
data[i++] = (byte)((v >>> 16) & 0xFF);
data[i++] = (byte)((v >>> 24) & 0xFF);
data[i++] = (byte)((v >>> 32) & 0xFF);
data[i++] = (byte)((v >>> 40) & 0xFF);
data[i++] = (byte)((v >>> 48) & 0xFF);
data[i++] = (byte)((v >>> 56) & 0xFF);
}
public static void writeInt2BE(OutputStream out, int v) throws IOException {
byte[] b2 = new byte[2];
putInt2BE(b2, 0, v);
out.write(b2);
}
public static void putInt2BE(byte[] data, int offset, int v) {
int i = offset;
data[i+1] = (byte)((v >>> 0) & 0xFF);
data[i+0] = (byte)((v >>> 8) & 0xFF);
}
public static void writeInt3BE(OutputStream out, long v) throws IOException {
byte[] b3 = new byte[3];
putInt3BE(b3, 0, v);
out.write(b3);
}
public static void putInt3BE(byte[] data, int offset, long v) {
int i = offset;
data[i+2] = (byte)((v >>> 0) & 0xFF);
data[i+1] = (byte)((v >>> 8) & 0xFF);
data[i+0] = (byte)((v >>> 16) & 0xFF);
}
public static void writeInt4BE(OutputStream out, long v) throws IOException {
byte[] b4 = new byte[4];
putInt4BE(b4, 0, v);
out.write(b4);
}
public static void putInt4BE(byte[] data, int offset, long v) {
int i = offset;
data[i+3] = (byte)((v >>> 0) & 0xFF);
data[i+2] = (byte)((v >>> 8) & 0xFF);
data[i+1] = (byte)((v >>> 16) & 0xFF);
data[i+0] = (byte)((v >>> 24) & 0xFF);
}
/**
* @param length The length in BYTES
*/
public static String getUTF8(byte[] data, int offset, int length) {
try {
return new String(data, offset, length, "UTF-8");
} catch(UnsupportedEncodingException e) {
throw new RuntimeException("Broken JVM, UTF-8 not found", e);
}
}
/**
* Strips off any null padding, if any, from the string
*/
public static String removeNullPadding(String str) {
int idx = str.indexOf(0);
if (idx == -1) {
return str;
}
return str.substring(0, idx);
}
/**
* @return The length in BYTES
*/
public static int putUTF8(byte[] data, int offset, String str) {
byte[] s = toUTF8Bytes(str);
System.arraycopy(s, 0, data, offset, s.length);
return s.length;
}
/**
* @return The length in BYTES
*/
public static byte[] toUTF8Bytes(String str) {
try {
return str.getBytes("UTF-8");
} catch(UnsupportedEncodingException e) {
throw new RuntimeException("Broken JVM, UTF-8 not found", e);
}
}
/**
* Writes the string out as UTF-8
*/
public static void writeUTF8(OutputStream out, String str) throws IOException {
try {
byte[] s = str.getBytes("UTF-8");
out.write(s);
} catch(UnsupportedEncodingException e) {
throw new RuntimeException("Broken JVM, UTF-8 not found", e);
}
}
/**
* Writes out a 4 byte integer of the length (in bytes!) of the
* String, followed by the String (as UTF-8)
*/
public static void writeUTF8WithLength(OutputStream out, String str) throws IOException {
try {
byte[] s = str.getBytes("UTF-8");
writeInt4(out, s.length);
out.write(s);
} catch(UnsupportedEncodingException e) {
throw new RuntimeException("Broken JVM, UTF-8 not found", e);
}
}
/**
* Checks to see if the wanted byte pattern is found in the
* within bytes from the given offset
* @param wanted Byte sequence to look for
* @param within Bytes to find in
* @param withinOffset Offset to check from
*/
public static boolean byteRangeMatches(byte[] wanted, byte[] within, int withinOffset) {
for (int i=0; i