diff --git a/README.md b/README.md index 9165e79..af07461 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,42 @@ -[![Release](https://jitpack.io/v/umjammer/JAADec.svg)](https://jitpack.io/#umjammer/JAADec) -[![Java CI with Maven](https://github.com/umjammer/JAADec/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/JAADec/actions/workflows/maven.yml) -[![CodeQL](https://github.com/umjammer/JAADec/actions/workflows/codeql.yml/badge.svg)](https://github.com/umjammer/JAADec/actions/workflows/codeql.yml) +[![Release](https://jitpack.io/v/umjammer/vavi-sound-aac.svg)](https://jitpack.io/#umjammer/vavi-sound-aac) +[![Java CI with Maven](https://github.com/umjammer/vavi-sound-aac/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-sound-aac/actions/workflows/maven.yml) +[![CodeQL](https://github.com/umjammer/vavi-sound-aac/actions/workflows/codeql.yml/badge.svg)](https://github.com/umjammer/vavi-sound-aac/actions/workflows/codeql.yml) ![Java](https://img.shields.io/badge/Java-8-b07219) [![Parent](https://img.shields.io/badge/Parent-vavi--sound--sandbox-pink)](https://github.com/umjammer/vavi-sound-sandbox) +# vavi-sound-aac + +Pure Java AAC decoder (Java Sound SPI) + +AAC logo© Dolby Laboratories, Inc. + +## Install + +* https://jitpack.io/#/umjammer/vavi-sound-aac + +## Usage + +```java + AudioInputStream ais = AudioSystem.getAudioInputStream(Files.newInputStream(Paths.get(m4a))); + Clip clip = AudioSystem.getClip(); + clip.open(AudioSystem.getAudioInputStream(new AudioFormat(44100, 16, 2, true, false), ais)); + clip.loop(Clip.LOOP_CONTINUOUSLY); +``` + +## TODO + + * ~~rename project into vavi-sound-aac~~ + * patches + * ~~https://github.com/Tianscar/jaac/commit/cf9b24f55fcd8f77ae76c42cac87602fdb0382a8~~ + * ~~https://github.com/Tianscar/jaac/commit/bbaaec277d6620e0233561d02185f2e901970480~~ + +--- + +## Original + # JAADec -**This is a fork of https://sourceforge.net/projects/jaadec/ +**This is a fork of https://sourceforge.net/projects/vavi-sound-aac/ containing fixes to make it play nice with other Java Sound Providers.** The original project was licensed under Public Domain @@ -16,12 +46,3 @@ JAAD is an AAC decoder and MP4 demultiplexer library written completely in Java. It uses no native libraries, is platform-independent and portable. It can read MP4 container from almost every input-stream (files, network sockets etc.) and decode AAC-LC (Low Complexity) and HE-AAC (High Efficiency/AAC+). - -## Install - - * https://jitpack.io/#/umjammer/JAADec - -## Applied Patches - - * https://github.com/Tianscar/jaac/commit/cf9b24f55fcd8f77ae76c42cac87602fdb0382a8 - * https://github.com/Tianscar/jaac/commit/bbaaec277d6620e0233561d02185f2e901970480 diff --git a/pom.xml b/pom.xml index 83da541..0f941a4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,12 +3,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 - net.sourceforge.jaadec - jaad - 0.8.9 + vavi + vavi-sound-aac + 0.8.10 - JAAD is an AAC decoder and MP4 demultiplexer library written completely in Java. It uses no native libraries, is platform-independent and portable. It can read MP4 container from almost every input-stream (files, network sockets etc.) and decode AAC-LC (Low Complexity) and HE-AAC (High Efficiency/AAC+). - https://github.com/umjammer/JAADec + vavi-sound-aac is an AAC decoder and MP4 demultiplexer library written completely in Java. It uses no native libraries, is platform-independent and portable. It can read MP4 container from almost every input-stream (files, network sockets etc.) and decode AAC-LC (Low Complexity) and HE-AAC (High Efficiency/AAC+). + https://github.com/umjammer/vavi-sound-aac Public Domain @@ -33,9 +33,9 @@ - scm:git:git@github.com:umjammer/JAADec.git - scm:git:git@github.com:umjammer/JAADec.git - scm:git:git@github.com:umjammer/JAADec.git + scm:git:git@github.com:umjammer/vavi-sound-aac.git + scm:git:git@github.com:umjammer/vavi-sound-aac.git + scm:git:git@github.com:umjammer/vavi-sound-aac.git @@ -77,7 +77,7 @@ org.junit junit-bom - 5.9.2 + 5.9.3 pom import @@ -89,7 +89,6 @@ com.github.umjammer vavi-sound 1.0.15 - test commons-beanutils diff --git a/src/main/java/net/sourceforge/jaad/MP4Info.java b/src/main/java/net/sourceforge/jaad/MP4Info.java index 4e2dbd3..70a894c 100644 --- a/src/main/java/net/sourceforge/jaad/MP4Info.java +++ b/src/main/java/net/sourceforge/jaad/MP4Info.java @@ -63,7 +63,7 @@ public static void main(String[] args) { } } - //print all boxes + // print all boxes if (boxes) { System.out.println("================================"); for (Box box : cont.getBoxes()) { diff --git a/src/main/java/net/sourceforge/jaad/Play.java b/src/main/java/net/sourceforge/jaad/Play.java index 743001b..284802f 100644 --- a/src/main/java/net/sourceforge/jaad/Play.java +++ b/src/main/java/net/sourceforge/jaad/Play.java @@ -81,7 +81,7 @@ private static void decodeMP4(MP4Input in) throws Exception { DecoderConfig conf = dec.getConfig(); AudioFormat aufmt = new AudioFormat(conf.getOutputFrequency().getFrequency(), 16, conf.getChannelCount(), true, true); - try (SourceDataLine line = AudioSystem.getSourceDataLine(aufmt)) { + try (SourceDataLine line = AudioSystem.getSourceDataLine(aufmt)) { line.open(); line.start(); diff --git a/src/main/java/net/sourceforge/jaad/Radio.java b/src/main/java/net/sourceforge/jaad/Radio.java index 94865c8..250f6cf 100644 --- a/src/main/java/net/sourceforge/jaad/Radio.java +++ b/src/main/java/net/sourceforge/jaad/Radio.java @@ -64,8 +64,7 @@ private static void decode(String arg) throws Exception { String x; do { x = in.readLine(); - } - while (x != null && !x.trim().equals("")); + } while (x != null && !x.trim().equals("")); ADTSDemultiplexer adts = new ADTSDemultiplexer(in); AudioFormat aufmt = new AudioFormat(adts.getSampleFrequency(), 16, adts.getChannelCount(), true, true); diff --git a/src/main/java/net/sourceforge/jaad/SampleBuffer.java b/src/main/java/net/sourceforge/jaad/SampleBuffer.java index d08feb8..dd4ebdc 100644 --- a/src/main/java/net/sourceforge/jaad/SampleBuffer.java +++ b/src/main/java/net/sourceforge/jaad/SampleBuffer.java @@ -131,8 +131,8 @@ public void setData(byte[] data, int sampleRate, int channels, int bitsPerSample length = 0; bitrate = 0; } else { - int bytesPerSample = bitsPerSample / 8; //usually 2 - int samplesPerChannel = data.length / (bytesPerSample * channels); //=1024 + int bytesPerSample = bitsPerSample / 8; // usually 2 + int samplesPerChannel = data.length / (bytesPerSample * channels); // =1024 length = (double) samplesPerChannel / (double) sampleRate; bitrate = (double) (samplesPerChannel * bitsPerSample * channels) / length; } diff --git a/src/main/java/net/sourceforge/jaad/aac/Decoder.java b/src/main/java/net/sourceforge/jaad/aac/Decoder.java index bac68b1..b63de35 100644 --- a/src/main/java/net/sourceforge/jaad/aac/Decoder.java +++ b/src/main/java/net/sourceforge/jaad/aac/Decoder.java @@ -23,7 +23,7 @@ public class Decoder { private final DecoderConfig config; private final SyntacticElements syntacticElements; - public int frames=0; + public int frames = 0; private ADIFHeader adifHeader; /** @@ -52,7 +52,7 @@ public static Decoder create(AudioDecoderInfo info) { } public static Decoder create(DecoderConfig config) { - if(config==null) + if (config == null) throw new IllegalArgumentException("illegal MP4 decoder specific info"); return new Decoder(config); } @@ -73,9 +73,9 @@ public Decoder(DecoderConfig config) { syntacticElements = new SyntacticElements(config); - LOGGER.log(Level.FINE, "profile: {0}", config.getProfile()); - LOGGER.log(Level.FINE, "sf: {0}", config.getSampleFrequency().getFrequency()); - LOGGER.log(Level.FINE, "channels: {0}", config.getChannelConfiguration().getDescription()); + LOGGER.log(Level.FINER, "profile: {0}", config.getProfile()); + LOGGER.log(Level.FINER, "sf: {0}", config.getSampleFrequency() != null ? config.getSampleFrequency().getFrequency() : null); + LOGGER.log(Level.FINER, "channels: {0}", config.getChannelConfiguration().getDescription()); } public DecoderConfig getConfig() { @@ -95,11 +95,11 @@ public void decodeFrame(byte[] frame, SampleBuffer buffer) throws AACException { BitStream in = BitStream.open(frame); try { - LOGGER.log(Level.FINE, () -> String.format("frame %d @%d", frames, 8 * frame.length)); + LOGGER.log(Level.FINER, () -> String.format("frame %d @%d", frames, 8 * frame.length)); decode(in, buffer); LOGGER.log(Level.FINEST, () -> String.format("left %d", in.getBitsLeft())); } catch (EOSException e) { - LOGGER.log(Level.WARNING,"unexpected end of frame",e); + LOGGER.log(Level.WARNING, "unexpected end of frame", e); } finally { ++frames; } diff --git a/src/main/java/net/sourceforge/jaad/aac/DecoderConfig.java b/src/main/java/net/sourceforge/jaad/aac/DecoderConfig.java index 54d57a8..001d526 100644 --- a/src/main/java/net/sourceforge/jaad/aac/DecoderConfig.java +++ b/src/main/java/net/sourceforge/jaad/aac/DecoderConfig.java @@ -30,8 +30,10 @@ public class DecoderConfig { // extension: SBR private final boolean sbrEnabled; private boolean sbrPresent = false; - // in case of SBR this may be twice the SampleFrequency. - // it remains null without SBR + /** + * in case of SBR this may be twice the SampleFrequency. + * it remains null without SBR + */ private SampleRate outputFrequency; private boolean psEnabled = true; @@ -43,6 +45,7 @@ public PS openPS(SBR sbr) { } // extension: error resilience + private boolean sectionDataResilience = false, scalefactorResilience = false, spectralDataResilience = false; DecoderConfig(boolean sbrEnabled) { @@ -53,7 +56,8 @@ public PS openPS(SBR sbr) { this(true); } - /* ========== gets/sets ========== */ + // gets/sets + public ChannelConfiguration getChannelConfiguration() { return channelConfiguration; } @@ -94,7 +98,7 @@ public int getFrameLength() { } public int getSampleLength() { - int upsampled = outputFrequency!= null && sampleFrequency != outputFrequency ? 2 : 1; + int upsampled = outputFrequency != null && sampleFrequency != outputFrequency ? 2 : 1; return upsampled * getFrameLength(); } @@ -131,7 +135,7 @@ public int getChannelCount() { return channelConfiguration.getChannelCount(); } - //=========== SBR ============= + // SBR ---- /** * Setup SBR and try to duplicate the output frequency if possible. @@ -163,7 +167,7 @@ public boolean isPSEnabled() { return psEnabled; } - //=========== ER ============= + // ER ---- public boolean isScalefactorResilienceUsed() { return scalefactorResilience; @@ -177,8 +181,7 @@ public boolean isSpectralDataResilienceUsed() { return spectralDataResilience; } - /* ======== static builder ========= */ - + /** static builder */ public static DecoderConfig create(AudioDecoderInfo info) { return new DecoderConfig().setAudioDecoderInfo(info); } @@ -223,10 +226,10 @@ public DecoderConfig decode(BitStream in) { case ER_AAC_LC: case ER_AAC_LTP: case ER_AAC_LD: - //ga-specific info: + // ga-specific info: frameLengthFlag = in.readBool(); if (frameLengthFlag) - throw new AACException("config uses 960-sample frames, not yet supported"); //TODO: are 960-frames working yet? + throw new AACException("config uses 960-sample frames, not yet supported"); // TODO: are 960-frames working yet? dependsOnCoreCoder = in.readBool(); @@ -243,13 +246,13 @@ public DecoderConfig decode(BitStream in) { scalefactorResilience = in.readBool(); spectralDataResilience = in.readBool(); } - //extensionFlag3 + // extensionFlag3 in.skipBit(); } if (channelConfiguration == ChannelConfiguration.NONE) { - //TODO: is this working correct? -> ISO 14496-3 part 1: 1.A.4.3 - //in.skipBits(3); //PCE + // TODO: is this working correct? -> ISO 14496-3 part 1: 1.A.4.3 + // in.skipBits(3); // PCE PCE pce = PCE.read(in); setAudioDecoderInfo(pce); } @@ -265,9 +268,9 @@ public DecoderConfig decode(BitStream in) { // expect implicit SBR for low frequencies // see 4.6.18.2.6 - // if(sbrEnabled && !sbrPresent && sampleFrequency.duplicated() != SF_NONE) { - // setSBRPresent(); - // } +// if (sbrEnabled && !sbrPresent && sampleFrequency.duplicated() != SF_NONE) { +// setSBRPresent(); +// } return this; } diff --git a/src/main/java/net/sourceforge/jaad/aac/Profile.java b/src/main/java/net/sourceforge/jaad/aac/Profile.java index 3ca8343..025fe91 100644 --- a/src/main/java/net/sourceforge/jaad/aac/Profile.java +++ b/src/main/java/net/sourceforge/jaad/aac/Profile.java @@ -47,6 +47,7 @@ public enum Profile { /** * Returns a profile instance for the given index. If the index is not * between 1 and 23 inclusive, UNKNOWN is returned. + * * @return a profile with the given index */ public static Profile forInt(int i) { diff --git a/src/main/java/net/sourceforge/jaad/aac/Receiver.java b/src/main/java/net/sourceforge/jaad/aac/Receiver.java index e91d9bb..7758a82 100644 --- a/src/main/java/net/sourceforge/jaad/aac/Receiver.java +++ b/src/main/java/net/sourceforge/jaad/aac/Receiver.java @@ -2,6 +2,7 @@ import java.util.List; + /** * Created by IntelliJ IDEA. * User: stueken diff --git a/src/main/java/net/sourceforge/jaad/aac/SampleFrequency.java b/src/main/java/net/sourceforge/jaad/aac/SampleFrequency.java index 90f8023..c0b10ed 100644 --- a/src/main/java/net/sourceforge/jaad/aac/SampleFrequency.java +++ b/src/main/java/net/sourceforge/jaad/aac/SampleFrequency.java @@ -62,6 +62,7 @@ public SampleFrequency getNominal() { return SampleFrequency.this; } + @Override public SampleRate duplicated() { SampleFrequency duplicate = SampleFrequency.this.duplicated(); return duplicate == SF_NONE ? SF_NONE : duplicate.forFrequency(2 * frequency); @@ -80,17 +81,17 @@ public static SampleFrequency nominalFrequency(int freq) { float d = sf.getDeviationTo(freq); // direct match - if(d==0) + if (d == 0) return sf; // better match - if(d * See: 1.6.2.1 AudioSpecificConfig * * @param in input bit stream to decode. @@ -34,7 +35,7 @@ static SampleRate decode(BitStream in) { int index = in.readBits(4); // indexed nominal frequency - if(index != SampleFrequency.ESCAPE_INDEX) + if (index != SampleFrequency.ESCAPE_INDEX) return SampleFrequency.TABLE.get(index); // for explicit frequency diff --git a/src/main/java/net/sourceforge/jaad/aac/Speaker.java b/src/main/java/net/sourceforge/jaad/aac/Speaker.java index a983ba3..b9c6a80 100644 --- a/src/main/java/net/sourceforge/jaad/aac/Speaker.java +++ b/src/main/java/net/sourceforge/jaad/aac/Speaker.java @@ -7,7 +7,7 @@ package net.sourceforge.jaad.aac; /** - * @see "https://en.wikipedia.org/wiki/Surround_sound" + * @see "https:// en.wikipedia.org/wiki/Surround_sound" */ public enum Speaker { diff --git a/src/main/java/net/sourceforge/jaad/aac/error/BitsBuffer.java b/src/main/java/net/sourceforge/jaad/aac/error/BitsBuffer.java index ce7fc2d..6581899 100644 --- a/src/main/java/net/sourceforge/jaad/aac/error/BitsBuffer.java +++ b/src/main/java/net/sourceforge/jaad/aac/error/BitsBuffer.java @@ -18,8 +18,8 @@ public int getLength() { public int showBits(int bits) { if (bits == 0) return 0; if (len <= 32) { - //huffman_spectral_data_2 needs to read more than may be available, - //bits maybe > len, deliver 0 than + // huffman_spectral_data_2 needs to read more than may be available, + // bits maybe > len, deliver 0 than if (len >= bits) return ((bufa >> (len - bits)) & (0xFFFFFFFF >> (32 - bits))); else return ((bufa << (bits - len)) & (0xFFFFFFFF >> (32 - bits))); } else { @@ -59,7 +59,7 @@ public void rewindReverse() { bufa = i[1]; } - //merge bits of a to b + // merge bits of a to b public void concatBits(BitsBuffer a) { if (a.len == 0) return; int al = a.bufa; @@ -67,10 +67,10 @@ public void concatBits(BitsBuffer a) { int bl, bh; if (len > 32) { - //mask off superfluous high b bits + // mask off superfluous high b bits bl = bufa; bh = bufb & ((1 << (len - 32)) - 1); - //left shift a len bits + // left shift a len bits ah = al << (len - 32); al = 0; } else { @@ -80,7 +80,7 @@ public void concatBits(BitsBuffer a) { al = al << len; } - //merge + // merge bufa = bl | al; bufb = bh | ah; diff --git a/src/main/java/net/sourceforge/jaad/aac/error/HCR.java b/src/main/java/net/sourceforge/jaad/aac/error/HCR.java index 3aad843..50b26a5 100644 --- a/src/main/java/net/sourceforge/jaad/aac/error/HCR.java +++ b/src/main/java/net/sourceforge/jaad/aac/error/HCR.java @@ -11,8 +11,9 @@ * Huffman Codeword Reordering * Decodes spectral data for ICStreams if error resilience is used for * section data. + * + * TODO needs decodeSpectralDataER() in BitStream */ -//TODO: needs decodeSpectralDataER() in BitStream public class HCR { private static class Codeword { @@ -37,11 +38,11 @@ private void fill(int sp, int cb) { private static final int[] PRE_SORT_CB_ER = {11, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 9, 7, 5, 3, 1}; private static final int[] MAX_CW_LEN = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14, 49, 0, 0, 0, 0, 14, 17, 21, 21, 25, 25, 29, 29, 29, 29, 33, 33, 33, 37, 37, 41}; - //bit-twiddling helpers + // bit-twiddling helpers private static final int[] S = {1, 2, 4, 8, 16}; private static final int[] B = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF}; - //32 bit rewind and reverse + // 32 bit rewind and reverse private static int rewindReverse(int v, int len) { v = ((v >> S[0]) & B[0]) | ((v << S[0]) & ~B[0]); v = ((v >> S[1]) & B[1]) | ((v << S[1]) & ~B[1]); @@ -49,13 +50,13 @@ private static int rewindReverse(int v, int len) { v = ((v >> S[3]) & B[3]) | ((v << S[3]) & ~B[3]); v = ((v >> S[4]) & B[4]) | ((v << S[4]) & ~B[4]); - //shift off low bits + // shift off low bits v >>= (32 - len); return v; } - //64 bit rewind and reverse + // 64 bit rewind and reverse static int[] rewindReverse64(int hi, int lo, int len) { int[] i = new int[2]; if (len <= 32) { @@ -73,7 +74,7 @@ static int[] rewindReverse64(int hi, int lo, int len) { lo = ((lo >> S[4]) & B[4]) | ((lo << S[4]) & ~B[4]); hi = ((hi >> S[4]) & B[4]) | ((hi << S[4]) & ~B[4]); - //shift off low bits + // shift off low bits i[1] = (hi >> (64 - len)) | (lo << (len - 32)); i[1] = lo >> (64 - len); } @@ -89,22 +90,22 @@ private static boolean isGoodCB(int cb, int sectCB) { return b; } - //sectionDataResilience = hDecoder->aacSectionDataResilienceFlag + /** sectionDataResilience = hDecoder->aacSectionDataResilienceFlag */ public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short[] spectralData, boolean sectionDataResilience) { ICSInfo info = ics.getInfo(); int windowGroupCount = info.getWindowGroupCount(); int maxSFB = info.getMaxSFB(); int[] swbOffsets = info.getSWBOffsets(); int swbOffsetMax = info.getSWBOffsetMax(); - //TODO: - //final SectionData sectData = ics.getSectionData(); + // TODO +// final SectionData sectData = ics.getSectionData(); int[][] sectStart = null; //sectData.getSectStart(); int[][] sectEnd = null; //sectData.getSectEnd(); int[] numSec = null; //sectData.getNumSec(); int[][] sectCB = null; //sectData.getSectCB(); int[][] sectSFBOffsets = null; //info.getSectSFBOffsets(); - //check parameter + // check parameter int spDataLen = ics.getReorderedSpectralDataLength(); if (spDataLen == 0) return; @@ -112,7 +113,7 @@ public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short if (longestLen == 0 || longestLen >= spDataLen) throw new AACException("length of longest HCR codeword out of range"); - //create spOffsets + // create spOffsets int[] spOffsets = new int[8]; int shortFrameLen = spectralData.length / 8; spOffsets[0] = 0; @@ -140,9 +141,9 @@ public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short int bitsread = 0; int sfb, w_idx, i, thisCB, thisSectCB, cws; - //step 1: decode PCW's (set 0), and stuff data in easier-to-use format + // step 1: decode PCW's (set 0), and stuff data in easier-to-use format for (int sortloop = 0; sortloop < lastCB; sortloop++) { - //select codebook to process this pass + // select codebook to process this pass thisCB = preSortCB[sortloop]; for (sfb = 0; sfb < maxSFB; sfb++) { @@ -150,35 +151,35 @@ public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short for (g = 0; g < windowGroupCount; g++) { for (i = 0; i < numSec[g]; i++) { if ((sectStart[g][i] <= sfb) && (sectEnd[g][i] > sfb)) { - /* check whether codebook used here is the one we want to process */ + // check whether codebook used here is the one we want to process thisSectCB = sectCB[g][i]; if (isGoodCB(thisCB, thisSectCB)) { - //precalculation + // precalculation int sect_sfb_size = sectSFBOffsets[g][sfb + 1] - sectSFBOffsets[g][sfb]; int inc = (thisSectCB < HCB.FIRST_PAIR_HCB) ? 4 : 2; int group_cws_count = (4 * info.getWindowGroupLength(g)) / inc; int segwidth = Math.min(MAX_CW_LEN[thisSectCB], longestLen); - //read codewords until end of sfb or end of window group + // read codewords until end of sfb or end of window group for (cws = 0; (cws < group_cws_count) && ((cws + w_idx * group_cws_count) < sect_sfb_size); cws++) { int sp = spOffsets[g] + sectSFBOffsets[g][sfb] + inc * (cws + w_idx * group_cws_count); - //read and decode PCW + // read and decode PCW if (PCWs_done == 0) { - //read in normal segments + // read in normal segments if (bitsread + segwidth <= spDataLen) { segment[segmentsCount].readSegment(segwidth, in); bitsread += segwidth; - //Huffman.decodeSpectralDataER(segment[segmentsCount], thisSectCB, spectralData, sp); + // Huffman.decodeSpectralDataER(segment[segmentsCount], thisSectCB, spectralData, sp); - //keep leftover bits + // keep leftover bits segment[segmentsCount].rewindReverse(); segmentsCount++; } else { - //remaining after last segment + // remaining after last segment if (bitsread < spDataLen) { int additional_bits = spDataLen - bitsread; @@ -220,7 +221,7 @@ public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short int numberOfSets = numberOfCodewords / segmentsCount; - //step 2: decode nonPCWs + // step 2: decode nonPCWs int trial, codewordBase, segmentID, codewordID; for (int set = 1; set <= numberOfSets; set++) { for (trial = 0; trial < segmentsCount; trial++) { @@ -228,7 +229,7 @@ public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short segmentID = (trial + codewordBase) % segmentsCount; codewordID = codewordBase + set * segmentsCount - segmentsCount; - //data up + // data up if (codewordID >= numberOfCodewords - segmentsCount) break; if ((codeword[codewordID].decoded == 0) && (segment[segmentID].len > 0)) { @@ -236,15 +237,14 @@ public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short segment[segmentID].concatBits(codeword[codewordID].bits); int tmplen = segment[segmentID].len; - /*int ret = Huffman.decodeSpectralDataER(segment[segmentID], codeword[codewordID].cb, - spectralData, codeword[codewordID].sp_offset); - - if(ret>=0) codeword[codewordID].decoded = 1; - else { - codeword[codewordID].bits = segment[segmentID]; - codeword[codewordID].bits.len = tmplen; - }*/ - +// int ret = Huffman.decodeSpectralDataER(segment[segmentID], codeword[codewordID].cb, +// spectralData, codeword[codewordID].sp_offset); +// +// if (ret >= 0) codeword[codewordID].decoded = 1; +// else { +// codeword[codewordID].bits = segment[segmentID]; +// codeword[codewordID].bits.len = tmplen; +// } } } } diff --git a/src/main/java/net/sourceforge/jaad/aac/error/RVLC.java b/src/main/java/net/sourceforge/jaad/aac/error/RVLC.java index a99d5be..5078069 100644 --- a/src/main/java/net/sourceforge/jaad/aac/error/RVLC.java +++ b/src/main/java/net/sourceforge/jaad/aac/error/RVLC.java @@ -7,7 +7,7 @@ /** - * Reversable variable length coding + * Reversible variable length coding * Decodes scalefactors if error resilience is used. */ public class RVLC implements RVLCTables { @@ -23,7 +23,7 @@ public void decode(BitStream in, ICStream ics, int[][] scaleFactors) { ICSInfo info = ics.getInfo(); int windowGroupCount = info.getWindowGroupCount(); int maxSFB = info.getMaxSFB(); - int[][] sfbCB = null; //ics.getSectionData().getSfbCB(); + int[][] sfbCB = null; // ics.getSectionData().getSfbCB(); int sf = ics.getGlobalGain(); int intensityPosition = 0; @@ -70,7 +70,7 @@ private void decodeEscapes(BitStream in, ICStream ics, int[][] scaleFactors) { ICSInfo info = ics.getInfo(); int windowGroupCount = info.getWindowGroupCount(); int maxSFB = info.getMaxSFB(); - int[][] sfbCB = null; //ics.getSectionData().getSfbCB(); + int[][] sfbCB = null; // ics.getSectionData().getSfbCB(); int escapesLen = in.readBits(8); diff --git a/src/main/java/net/sourceforge/jaad/aac/error/RVLCTables.java b/src/main/java/net/sourceforge/jaad/aac/error/RVLCTables.java index 648d970..7177afc 100644 --- a/src/main/java/net/sourceforge/jaad/aac/error/RVLCTables.java +++ b/src/main/java/net/sourceforge/jaad/aac/error/RVLCTables.java @@ -2,7 +2,7 @@ interface RVLCTables { - //index,length,codeword + // index,length,codeword int[][] RVLC_BOOK = { {0, 1, 0}, /* 0 */ {-1, 3, 5}, /* 101 */ diff --git a/src/main/java/net/sourceforge/jaad/aac/filterbank/FFT.java b/src/main/java/net/sourceforge/jaad/aac/filterbank/FFT.java index d5779f8..b85b7b3 100644 --- a/src/main/java/net/sourceforge/jaad/aac/filterbank/FFT.java +++ b/src/main/java/net/sourceforge/jaad/aac/filterbank/FFT.java @@ -47,7 +47,7 @@ public static void dump(float[][] in) { void process(float[][] in, boolean forward) { - //bit-reversal + // bit-reversal int ii = 0; for (int i = 0; i < length; i++) { rev[i][0] = in[ii][0]; @@ -65,44 +65,43 @@ void process(float[][] in, boolean forward) { } // bottom base-4 round - for(int i = 0; i 15) { - signValues(in, data, off, cb < 5 ? QUAD_LEN : PAIR_LEN); //virtual codebooks are always unsigned + signValues(in, data, off, cb < 5 ? QUAD_LEN : PAIR_LEN); // virtual codebooks are always unsigned if (Math.abs(data[off]) == 16) data[off] = getEscape(in, data[off]); if (Math.abs(data[off + 1]) == 16) data[off + 1] = getEscape(in, data[off + 1]); } else throw new AACException("Huffman: unknown spectral codebook: " + cb); diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/EnvData.java b/src/main/java/net/sourceforge/jaad/aac/ps/EnvData.java index 8dba110..34914cc 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/EnvData.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/EnvData.java @@ -1,11 +1,12 @@ package net.sourceforge.jaad.aac.ps; -import net.sourceforge.jaad.aac.syntax.BitStream; - import java.util.Arrays; +import net.sourceforge.jaad.aac.syntax.BitStream; + import static net.sourceforge.jaad.aac.ps.PSConstants.MAX_PS_ENVELOPES; + /** * Created by IntelliJ IDEA. * User: stueken @@ -28,7 +29,7 @@ abstract public class EnvData { * The first envelop refers to prev. */ int[] prev = first; - for(int l=0; l7) { + while (ld.getBitsLeft() > 7) { int ps_extension_id = ld.readBits(2); - if(ps_extension_id==0) { + if (ps_extension_id == 0) { ExtData data = data(); - if(data!=null) - data.readData(ld, num_env); + if (data != null) + data.readData(ld, num_env); } - } + } } } void decode(int num_env) { - if(enabled && data!=null) + if (enabled && data != null) data.decode(num_env); } void update(int num_env) { - if(enabled && data!=null) + if (enabled && data != null) data.update(num_env); } void restore(int num_env) { - if(enabled && data!=null) + if (enabled && data != null) data.restore(num_env); } public void mapTo34(int num_env) { - if(enabled && data!=null) + if (enabled && data != null) data.mapTo34(num_env); } int nr_par() { - if(enabled && data!=null) + if (enabled && data != null) return data.nr_par(); else return 0; diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/FBType.java b/src/main/java/net/sourceforge/jaad/aac/ps/FBType.java index f51e8cd..0478e2a 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/FBType.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/FBType.java @@ -4,6 +4,7 @@ import static net.sourceforge.jaad.aac.ps.PSConstants.NEGATE_IPD_MASK; + /** * Created by IntelliJ IDEA. * User: stueken @@ -12,32 +13,33 @@ */ public class FBType { - public static final Comparator CMP = Comparator.nullsLast(Comparator.comparingInt(t->t.nr_par_bands)); + public static final Comparator CMP = Comparator.nullsLast(Comparator.comparingInt(t -> t.nr_par_bands)); public static FBType max(FBType a, FBType b) { - return CMP.compare(a,b)<0 ? a : b; + return CMP.compare(a, b) < 0 ? a : b; } + public FBType max(FBType other) { return max(this, other); } public static final FBType T34 = new FBType(PSTables.group_border34, PSTables.map_group2bk34, - 32+18, 32, 34, 5, + 32 + 18, 32, 34, 5, PSTables.Phi_Fract_SubQmf34, PSTables.Q_Fract_allpass_SubQmf34, - new Filter[]{Filter12.f, Filter8.f34, Filter4.f, Filter4.f, Filter4.f}); + new Filter[] {Filter12.f, Filter8.f34, Filter4.f, Filter4.f, Filter4.f}); public static final FBType T20 = new FBType(PSTables.group_border20, PSTables.map_group2bk20, - 10+12, 10, 20, 3, + 10 + 12, 10, 20, 3, PSTables.Phi_Fract_SubQmf20, PSTables.Q_Fract_allpass_SubQmf20, - new Filter[]{Filter8.f20, Filter2.f, Filter2.f}); + new Filter[] {Filter8.f20, Filter2.f, Filter2.f}); final String name; final int num_groups; - final int num_hybrid_groups; - final int nr_par_bands; - final int decay_cutoff; + final int num_hybrid_groups; + final int nr_par_bands; + final int decay_cutoff; final int[] group_border; - final int[] map_group2bk; + final int[] map_group2bk; final float[][] phiFract; final float[][][] qFractAllpassSubQmf; final Filter[] filters; @@ -65,11 +67,11 @@ int bk(int gr) { } int maxsb(int gr) { - return (gr { int index = 0; - while(index>=0) { + while (index >= 0) { int bit = ld.readBit(); index = huff[index][bit]; } - return index+31; + return index + 31; }; } } diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/ICCData.java b/src/main/java/net/sourceforge/jaad/aac/ps/ICCData.java index c35bd38..74ee8c1 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/ICCData.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/ICCData.java @@ -11,6 +11,7 @@ public class ICCData extends ICData { /** * ICCMode default is mode(1) ?? */ + @Override ICCMode mode() { return mode == null ? mode(1) : mode; } diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/ICCMode.java b/src/main/java/net/sourceforge/jaad/aac/ps/ICCMode.java index 1d9c738..b54c976 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/ICCMode.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/ICCMode.java @@ -3,6 +3,7 @@ import static net.sourceforge.jaad.aac.ps.Huffman.f_huff_icc; import static net.sourceforge.jaad.aac.ps.Huffman.t_huff_icc; + /** * Created by IntelliJ IDEA. * User: stueken @@ -30,12 +31,12 @@ int clip(int idx) { } static private final ICCMode[] ICC_MODES = { - new ICCMode(0, 10), - new ICCMode(1, 20), - new ICCMode(2, 34), - new ICCMode(3, 10), - new ICCMode(4, 20), - new ICCMode(5, 34) + new ICCMode(0, 10), + new ICCMode(1, 20), + new ICCMode(2, 34), + new ICCMode(3, 10), + new ICCMode(4, 20), + new ICCMode(5, 34) }; static ICCMode mode(int id) { diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/ICData.java b/src/main/java/net/sourceforge/jaad/aac/ps/ICData.java index 3c74871..eec2bac 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/ICData.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/ICData.java @@ -2,6 +2,7 @@ import net.sourceforge.jaad.aac.syntax.BitStream; + /** * Created by IntelliJ IDEA. * User: stueken @@ -15,7 +16,7 @@ abstract public class ICData extends EnvData { } FBType fbType() { - return mode==null ? null : mode.fbType(); + return mode == null ? null : mode.fbType(); } Mode readMode(BitStream ld) { diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/ICMode.java b/src/main/java/net/sourceforge/jaad/aac/ps/ICMode.java index 98520c7..833221e 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/ICMode.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/ICMode.java @@ -13,10 +13,11 @@ public ICMode(int id, int nr_par) { } FBType fbType() { - return (id %3)==2 ? FBType.T34 : FBType.T20; - } + return (id % 3) == 2 ? FBType.T34 : FBType.T20; + } + @Override int stride() { - return (id%3)==0 ? 2 : 0; + return (id % 3) == 0 ? 2 : 0; } } diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/IIDMode.java b/src/main/java/net/sourceforge/jaad/aac/ps/IIDMode.java index f2061ad..7966dee 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/IIDMode.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/IIDMode.java @@ -2,8 +2,22 @@ import net.sourceforge.jaad.aac.tools.Utils; -import static net.sourceforge.jaad.aac.ps.Huffman.*; -import static net.sourceforge.jaad.aac.ps.PSTables.*; +import static net.sourceforge.jaad.aac.ps.Huffman.f_huff_iid_def; +import static net.sourceforge.jaad.aac.ps.Huffman.f_huff_iid_fine; +import static net.sourceforge.jaad.aac.ps.Huffman.t_huff_iid_def; +import static net.sourceforge.jaad.aac.ps.Huffman.t_huff_iid_fine; +import static net.sourceforge.jaad.aac.ps.PSTables.cos_betas_fine; +import static net.sourceforge.jaad.aac.ps.PSTables.cos_betas_normal; +import static net.sourceforge.jaad.aac.ps.PSTables.cos_gammas_fine; +import static net.sourceforge.jaad.aac.ps.PSTables.cos_gammas_normal; +import static net.sourceforge.jaad.aac.ps.PSTables.sf_iid_fine; +import static net.sourceforge.jaad.aac.ps.PSTables.sf_iid_normal; +import static net.sourceforge.jaad.aac.ps.PSTables.sin_betas_fine; +import static net.sourceforge.jaad.aac.ps.PSTables.sin_betas_normal; +import static net.sourceforge.jaad.aac.ps.PSTables.sin_gammas_fine; +import static net.sourceforge.jaad.aac.ps.PSTables.sin_gammas_normal; +import static net.sourceforge.jaad.aac.ps.PSTables.sincos_alphas_B_fine; +import static net.sourceforge.jaad.aac.ps.PSTables.sincos_alphas_B_normal; /** diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/PDData.java b/src/main/java/net/sourceforge/jaad/aac/ps/PDData.java index 78ece1b..0fd83ca 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/PDData.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/PDData.java @@ -18,7 +18,7 @@ public class PDData extends EnvData { } void setMode(IIDMode mode) { - this.mode = mode==null ? null : mode(mode.id); + this.mode = mode == null ? null : mode(mode.id); } @Override diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/PDMode.java b/src/main/java/net/sourceforge/jaad/aac/ps/PDMode.java index 59115d3..61ac024 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/PDMode.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/PDMode.java @@ -1,6 +1,10 @@ package net.sourceforge.jaad.aac.ps; -import static net.sourceforge.jaad.aac.ps.Huffman.*; +import static net.sourceforge.jaad.aac.ps.Huffman.f_huff_ipd; +import static net.sourceforge.jaad.aac.ps.Huffman.f_huff_opd; +import static net.sourceforge.jaad.aac.ps.Huffman.t_huff_ipd; +import static net.sourceforge.jaad.aac.ps.Huffman.t_huff_opd; + /** * Created by IntelliJ IDEA. @@ -51,12 +55,12 @@ private static PDMode[] modes(int[][] f, int[][] t) { EnvTables tables = new EnvTables(f, t); return new PDMode[] { - new PDMode(0, 5, tables), - new PDMode(1, 11, tables), - new PDMode(2, 17, tables), - new PDMode(3, 5, tables), - new PDMode(4, 11, tables), - new PDMode(5, 17, tables) + new PDMode(0, 5, tables), + new PDMode(1, 11, tables), + new PDMode(2, 17, tables), + new PDMode(3, 5, tables), + new PDMode(4, 11, tables), + new PDMode(5, 17, tables) }; } } diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/PSImpl.java b/src/main/java/net/sourceforge/jaad/aac/ps/PSImpl.java index f461c62..84e9bce 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/PSImpl.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/PSImpl.java @@ -1,706 +1,710 @@ package net.sourceforge.jaad.aac.ps; +import java.util.Arrays; + import net.sourceforge.jaad.aac.sbr.PS; import net.sourceforge.jaad.aac.syntax.BitStream; import net.sourceforge.jaad.aac.tools.Utils; -import java.util.Arrays; +import static net.sourceforge.jaad.aac.ps.PSTables.COEF_SQRT2; +import static net.sourceforge.jaad.aac.ps.PSTables.DECAY_SLOPE; +import static net.sourceforge.jaad.aac.ps.PSTables.MAX_PS_ENVELOPES; +import static net.sourceforge.jaad.aac.ps.PSTables.NO_ALLPASS_LINKS; +import static net.sourceforge.jaad.aac.ps.PSTables.Phi_Fract_Qmf; +import static net.sourceforge.jaad.aac.ps.PSTables.Q_Fract_allpass_Qmf; +import static net.sourceforge.jaad.aac.ps.PSTables.cos_alphas; +import static net.sourceforge.jaad.aac.ps.PSTables.delay_length_d; +import static net.sourceforge.jaad.aac.ps.PSTables.filter_a; +import static net.sourceforge.jaad.aac.ps.PSTables.ipdopd_cos_tab; +import static net.sourceforge.jaad.aac.ps.PSTables.ipdopd_sin_tab; +import static net.sourceforge.jaad.aac.ps.PSTables.num_env_tab; +import static net.sourceforge.jaad.aac.ps.PSTables.sin_alphas; -import static net.sourceforge.jaad.aac.ps.PSTables.*; public class PSImpl implements PS { - final IIDData iid = new IIDData(); - final ICCData icc = new ICCData(); - Extension ext = new Extension(iid); - - FBType fbt = FBType.T20; - - /* bitstream parameters */ - boolean var_borders; - int num_env; - int[] border_position = new int[MAX_PS_ENVELOPES+1]; - - /* ps data was correctly read */ - boolean ps_data_available; - /* a header has been read */ - boolean header_read; - - /* hybrid filterbank parameters */ - final Filterbank fb; - - static final int NR_ALLPASS_BANDS = 22; - - /* filter delay handling */ - int saved_delay; - int[] delay_buf_index_ser = new int[NO_ALLPASS_LINKS]; - int[] num_sample_delay_ser = new int[NO_ALLPASS_LINKS]; - static final int SHORT_DELAY_BAND = 35; - - int[] delay_D = new int[64]; - int[] delay_buf_index_delay = new int[64]; - float[][][] delay_Qmf = new float[14][64][2]; /* 14 samples delay max, 64 QMF channels */ - float[][][] delay_SubQmf = new float[2][32][2]; /* 2 samples delay max (SubQmf is always allpass filtered) */ - float[][][][] delay_Qmf_ser = new float[NO_ALLPASS_LINKS][5][64][2]; /* 5 samples delay max (table 8.34), 64 QMF channels */ - float[][][][] delay_SubQmf_ser = new float[NO_ALLPASS_LINKS][5][32][2]; /* 5 samples delay max (table 8.34) */ - - /* transients */ - static final float ALPHA_DECAY = 0.76592833836465f; - static final float ALPHA_SMOOTH = 0.25f; - float[] P_PeakDecayNrg = new float[34]; - float[] P_prev = new float[34]; - float[] P_SmoothPeakDecayDiffNrg_prev = new float[34]; - - /* mixing and phase */ - float[][] h11_prev = new float[50][2]; - float[][] h12_prev = new float[50][2]; - float[][] h21_prev = new float[50][2]; - float[][] h22_prev = new float[50][2]; - int phase_hist; - - public PSImpl(int frameLen) { - - fb = new Filterbank(frameLen); - - ps_data_available = false; - - /* delay stuff*/ - saved_delay = 0; - - for(int i = 0; i<64; i++) { - delay_buf_index_delay[i] = 0; - } - - for(int i = 0; i NR_ALLPASS_BANDS &&gr>=fbt.num_hybrid_groups) { - /* delay */ - float[] delay = delay_Qmf[delay_buf_index_delay[sb]][sb]; - /* never hybrid subbands here, always QMF subbands */ - r0Re = delay[0]; - r0Im = delay[1]; - delay[0] = re; - delay[1] = im; - } - else { - - float[] delayQmf = gr=2) { - temp_delay = 0; - } - - /* update delay indices */ - if(sb> NR_ALLPASS_BANDS &&gr>=fbt.num_hybrid_groups) { - /* delay_D depends on the samplerate, it can hold the values 14 and 1 */ - if(++delay_buf_index_delay[sb]>=delay_D[sb]) { - delay_buf_index_delay[sb] = 0; - } - } - - for(int m = 0; m=num_sample_delay_ser[m]) { - temp_delay_ser[m] = 0; - } - } - } - } - } - - /* update delay indices */ - saved_delay = temp_delay; - System.arraycopy(temp_delay_ser, 0, delay_buf_index_ser, 0, NO_ALLPASS_LINKS); - } - - private static float magnitude_c(float[] c) { - return (float) Math.sqrt(c[0]*c[0]+c[1]*c[1]); - } - - private void ps_mix_phase(float[][][] X_left, float[][][] X_right, - float[][][] X_hybrid_left, float[][][] X_hybrid_right) { - - float[] h11 = new float[2], h12 = new float[2], h21 = new float[2], h22 = new float[2]; - float[] H11 = new float[2], H12 = new float[2], H21 = new float[2], H22 = new float[2]; - float[] deltaH11 = new float[2], deltaH12 = new float[2], deltaH21 = new float[2], deltaH22 = new float[2]; - float[] tempLeft = new float[2]; - float[] tempRight = new float[2]; - float[] phaseLeft = new float[2]; - float[] phaseRight = new float[2]; - - IIDTables tables = iid.mode().tables(); - - for(int gr = 0; gr NR_ALLPASS_BANDS && gr >= fbt.num_hybrid_groups) { + // delay + float[] delay = delay_Qmf[delay_buf_index_delay[sb]][sb]; + // never hybrid subbands here, always QMF subbands + r0Re = delay[0]; + r0Im = delay[1]; + delay[0] = re; + delay[1] = im; + } else { + + float[] delayQmf = gr < fbt.num_hybrid_groups ? delay_SubQmf[temp_delay][sb] : delay_Qmf[temp_delay][sb]; + + // allpass filter + // int m; + float[] Phi_Fract = gr < fbt.num_hybrid_groups ? fbt.phiFract[sb] : Phi_Fract_Qmf[sb]; + + float tmp0Re = delayQmf[0]; + float tmp0Im = delayQmf[1]; + + delayQmf[0] = re; + delayQmf[1] = im; + + // z^(-2) * Phi_Fract[k] + r0Re = (tmp0Re * Phi_Fract[0]) + (tmp0Im * Phi_Fract[1]); + r0Im = (tmp0Im * Phi_Fract[0]) - (tmp0Re * Phi_Fract[1]); + + for (int m = 0; m < NO_ALLPASS_LINKS; m++) { + + float[] qFractAllpass = qFractAllpassQmf[sb][m]; + float[] delay = delay_ser[m][temp_delay_ser[m]][sb]; + + tmp0Re = delay[0]; + tmp0Im = delay[1]; + + // delay by a fraction + // z^(-d(m)) * qFractAllpass[k,m] + float tmpRe = (tmp0Re * qFractAllpass[0]) + (tmp0Im * qFractAllpass[1]); + float tmpIm = (tmp0Im * qFractAllpass[0]) - (tmp0Re * qFractAllpass[1]); + + // -a(m) * g_DecaySlope[k] + tmpRe -= g_DecaySlope_filt[m] * r0Re; + tmpIm -= g_DecaySlope_filt[m] * r0Im; + + // -a(m) * g_DecaySlope[k] * qFractAllpass[k,m] * z^(-d(m)) + delay[0] = r0Re + (g_DecaySlope_filt[m] * tmpRe); + delay[1] = r0Im + (g_DecaySlope_filt[m] * tmpIm); + + // store for next iteration (or as output value if last iteration) + r0Re = tmpRe; + r0Im = tmpIm; + } + } + + // select b(k) for reading the transient ratio + int bk = fbt.bk(gr); + + // duck if a past transient is found + Xr[n][sb][0] = (G_TransientRatio[n][bk] * r0Re); + Xr[n][sb][1] = (G_TransientRatio[n][bk] * r0Im); + + // Update delay buffer index + if (++temp_delay >= 2) { + temp_delay = 0; + } + + // update delay indices + if (sb > NR_ALLPASS_BANDS && gr >= fbt.num_hybrid_groups) { + // delay_D depends on the samplerate, it can hold the values 14 and 1 + if (++delay_buf_index_delay[sb] >= delay_D[sb]) { + delay_buf_index_delay[sb] = 0; + } + } + + for (int m = 0; m < NO_ALLPASS_LINKS; m++) { + if (++temp_delay_ser[m] >= num_sample_delay_ser[m]) { + temp_delay_ser[m] = 0; + } + } + } + } + } + + // update delay indices + saved_delay = temp_delay; + System.arraycopy(temp_delay_ser, 0, delay_buf_index_ser, 0, NO_ALLPASS_LINKS); + } + + private static float magnitude_c(float[] c) { + return (float) Math.sqrt(c[0] * c[0] + c[1] * c[1]); + } + + private void ps_mix_phase(float[][][] X_left, float[][][] X_right, + float[][][] X_hybrid_left, float[][][] X_hybrid_right) { + + float[] h11 = new float[2], h12 = new float[2], h21 = new float[2], h22 = new float[2]; + float[] H11 = new float[2], H12 = new float[2], H21 = new float[2], H22 = new float[2]; + float[] deltaH11 = new float[2], deltaH12 = new float[2], deltaH21 = new float[2], deltaH22 = new float[2]; + float[] tempLeft = new float[2]; + float[] tempRight = new float[2]; + float[] phaseLeft = new float[2]; + float[] phaseRight = new float[2]; + + IIDTables tables = iid.mode().tables(); + + for (int gr = 0; gr < fbt.num_groups; gr++) { + int bk = fbt.bk(gr); + + // use one channel per group in the subqmf domain + int maxsb = (gr < fbt.num_hybrid_groups) ? fbt.group_border[gr] + 1 : fbt.group_border[gr + 1]; + + for (int env = 0; env < num_env; env++) { + + int iid_index = iid.envs[env].index[bk]; + int iid_sign = iid_index < 0 ? -1 : 1; + iid_index = Math.abs(iid_index); + + int icc_index = icc.envs[env].index[bk]; + + if (icc.mode().id < 3) { + // type 'A' mixing as described in 8.6.4.6.2.1 + +// c_1 = sqrt(2.0 / (1.0 + pow(10.0, quant_iid[no_iid_steps + iid_index] / 10.0))); +// c_2 = sqrt(2.0 / (1.0 + pow(10.0, quant_iid[no_iid_steps - iid_index] / 10.0))); +// alpha = 0.5 * acos(quant_rho[icc_index]); +// beta = alpha * (c_1 - c_2) / sqrt(2.0); +// printf("%d\n", ps.iid_index[env][bk]); + + // calculate the scalefactors c_1 and c_2 from the intensity differences + float[] sf_iid = tables.sf; + int num_steps = tables.num_steps; + float c_1 = sf_iid[num_steps + iid_index]; + float c_2 = sf_iid[num_steps - iid_index]; + + // calculate alpha and beta using the ICC parameters + float cosa = cos_alphas[icc_index]; + float sina = sin_alphas[icc_index]; + + float cosb = tables.cos_betas[iid_index][icc_index]; + float sinb = tables.sin_betas[iid_index][icc_index] * iid_sign; + + float ab1 = (cosb * cosa); + float ab2 = (sinb * sina); + float ab3 = (sinb * cosa); + float ab4 = (cosb * sina); + + // h_xy: COEF + h11[0] = (c_2 * (ab1 - ab2)); + h12[0] = (c_1 * (ab1 + ab2)); + h21[0] = (c_2 * (ab3 + ab4)); + h22[0] = (c_1 * (ab3 - ab4)); + } else { + // type 'B' mixing as described in 8.6.4.6.2.2 + + int num_steps = tables.num_steps; + + float cosa = tables.sincos_alphas_b[num_steps + iid_index][icc_index]; + float sina = tables.sincos_alphas_b[2 * num_steps - (num_steps + iid_index)][icc_index]; + float cosg = tables.cos_gammas[iid_index][icc_index]; + float sing = tables.sin_gammas[iid_index][icc_index]; + + h11[0] = (COEF_SQRT2 * (cosa * cosg)); + h12[0] = (COEF_SQRT2 * (sina * cosg)); + h21[0] = (COEF_SQRT2 * (-cosa * sing)); + h22[0] = (COEF_SQRT2 * (sina * sing)); + } + + // calculate phase rotation parameters H_xy + + // note that the imaginary part of these parameters are only calculated when + // IPD and OPD are enabled + int nr_ipdopd_par = ext.nr_par(); + + if (bk < nr_ipdopd_par) { + + float[] ipd_prev = ext.data.ipd.prev[bk][phase_hist]; + float[] opd_prev = ext.data.opd.prev[bk][phase_hist]; + + // previous value + tempLeft[0] = (ipd_prev[0] * 0.25f); + tempLeft[1] = (ipd_prev[1] * 0.25f); + tempRight[0] = (opd_prev[0] * 0.25f); + tempRight[1] = (opd_prev[1] * 0.25f); + + // save current value + int ipd_index = Math.abs(ext.data.ipd.envs[env].index[bk]); + int opd_index = Math.abs(ext.data.ipd.envs[env].index[bk]); + + ipd_prev[0] = ipdopd_cos_tab[ipd_index]; + ipd_prev[1] = ipdopd_sin_tab[ipd_index]; + opd_prev[0] = ipdopd_cos_tab[opd_index]; + opd_prev[1] = ipdopd_sin_tab[opd_index]; + + // add current value + tempLeft[0] += ipd_prev[0]; + tempLeft[1] += ipd_prev[1]; + tempRight[0] += opd_prev[0]; + tempRight[1] += opd_prev[1]; + + ++phase_hist; + phase_hist %= 2; + + ipd_prev = ext.data.opd.prev[bk][phase_hist]; + opd_prev = ext.data.opd.prev[bk][phase_hist]; + + // get value before previous + tempLeft[0] += (ipd_prev[0] * 0.5f); + tempLeft[1] += (ipd_prev[1] * 0.5f); + tempRight[0] += (opd_prev[0] * 0.5f); + tempRight[1] += (opd_prev[1] * 0.5f); + + float xy = magnitude_c(tempRight); + float pq = magnitude_c(tempLeft); + + if (xy != 0) { + phaseLeft[0] = (tempRight[0] / xy); + phaseLeft[1] = (tempRight[1] / xy); + } else { + phaseLeft[0] = 0; + phaseLeft[1] = 0; + } + + float xypq = (xy * pq); + + if (xypq != 0) { + float tmp1 = (tempRight[0] * tempLeft[0]) + (tempRight[1] * tempLeft[1]); + float tmp2 = (tempRight[1] * tempLeft[0]) - (tempRight[0] * tempLeft[1]); + + phaseRight[0] = (tmp1 / xypq); + phaseRight[1] = (tmp2 / xypq); + } else { + phaseRight[0] = 0; + phaseRight[1] = 0; + } + + // MUL_F(COEF, REAL) = COEF + h11[1] = (h11[0] * phaseLeft[1]); + h12[1] = (h12[0] * phaseRight[1]); + h21[1] = (h21[0] * phaseLeft[1]); + h22[1] = (h22[0] * phaseRight[1]); + + h11[0] = (h11[0] * phaseLeft[0]); + h12[0] = (h12[0] * phaseRight[0]); + h21[0] = (h21[0] * phaseLeft[0]); + h22[0] = (h22[0] * phaseRight[0]); + } + + // length of the envelope n_e+1 - n_e (in time samples) + // 0 < L <= 32: integer + float L = (float) (border_position[env + 1] - border_position[env]); + + // obtain final H_xy by means of linear interpolation + deltaH11[0] = (h11[0] - h11_prev[gr][0]) / L; + deltaH12[0] = (h12[0] - h12_prev[gr][0]) / L; + deltaH21[0] = (h21[0] - h21_prev[gr][0]) / L; + deltaH22[0] = (h22[0] - h22_prev[gr][0]) / L; + + H11[0] = h11_prev[gr][0]; + H12[0] = h12_prev[gr][0]; + H21[0] = h21_prev[gr][0]; + H22[0] = h22_prev[gr][0]; + + h11_prev[gr][0] = h11[0]; + h12_prev[gr][0] = h12[0]; + h21_prev[gr][0] = h21[0]; + h22_prev[gr][0] = h22[0]; + + // only calculate imaginary part when needed + if (bk < nr_ipdopd_par) { + // obtain final H_xy by means of linear interpolation + deltaH11[1] = (h11[1] - h11_prev[gr][1]) / L; + deltaH12[1] = (h12[1] - h12_prev[gr][1]) / L; + deltaH21[1] = (h21[1] - h21_prev[gr][1]) / L; + deltaH22[1] = (h22[1] - h22_prev[gr][1]) / L; + + H11[1] = h11_prev[gr][1]; + H12[1] = h12_prev[gr][1]; + H21[1] = h21_prev[gr][1]; + H22[1] = h22_prev[gr][1]; + + if (fbt.bkm(gr)) { + deltaH11[1] = -deltaH11[1]; + deltaH12[1] = -deltaH12[1]; + deltaH21[1] = -deltaH21[1]; + deltaH22[1] = -deltaH22[1]; + + H11[1] = -H11[1]; + H12[1] = -H12[1]; + H21[1] = -H21[1]; + H22[1] = -H22[1]; + } + + h11_prev[gr][1] = h11[1]; + h12_prev[gr][1] = h12[1]; + h21_prev[gr][1] = h21[1]; + h22_prev[gr][1] = h22[1]; + } + + // apply H_xy to the current envelope band of the decorrelated subband + for (int n = border_position[env]; n < border_position[env + 1]; n++) { + // addition finalises the interpolation over every n + H11[0] += deltaH11[0]; + H12[0] += deltaH12[0]; + H21[0] += deltaH21[0]; + H22[0] += deltaH22[0]; + if (bk < nr_ipdopd_par) { + H11[1] += deltaH11[1]; + H12[1] += deltaH12[1]; + H21[1] += deltaH21[1]; + H22[1] += deltaH22[1]; + } + + // channel is an alias to the subband + for (int sb = fbt.group_border[gr]; sb < maxsb; sb++) { + float[] inLeft = new float[2], inRight = new float[2]; + + // load decorrelated samples + if (gr < fbt.num_hybrid_groups) { + inLeft[0] = X_hybrid_left[n][sb][0]; + inLeft[1] = X_hybrid_left[n][sb][1]; + inRight[0] = X_hybrid_right[n][sb][0]; + inRight[1] = X_hybrid_right[n][sb][1]; + } else { + inLeft[0] = X_left[n][sb][0]; + inLeft[1] = X_left[n][sb][1]; + inRight[0] = X_right[n][sb][0]; + inRight[1] = X_right[n][sb][1]; + } + + // apply mixing + tempLeft[0] = (H11[0] * inLeft[0]) + (H21[0] * inRight[0]); + tempLeft[1] = (H11[0] * inLeft[1]) + (H21[0] * inRight[1]); + tempRight[0] = (H12[0] * inLeft[0]) + (H22[0] * inRight[0]); + tempRight[1] = (H12[0] * inLeft[1]) + (H22[0] * inRight[1]); + + // only perform imaginary operations when needed + if (bk < nr_ipdopd_par) { + // apply rotation + tempLeft[0] -= (H11[1] * inLeft[1]) + (H21[1] * inRight[1]); + tempLeft[1] += (H11[1] * inLeft[0]) + (H21[1] * inRight[0]); + tempRight[0] -= (H12[1] * inLeft[1]) + (H22[1] * inRight[1]); + tempRight[1] += (H12[1] * inLeft[0]) + (H22[1] * inRight[0]); + } + + // store final samples + if (gr < fbt.num_hybrid_groups) { + X_hybrid_left[n][sb][0] = tempLeft[0]; + X_hybrid_left[n][sb][1] = tempLeft[1]; + X_hybrid_right[n][sb][0] = tempRight[0]; + X_hybrid_right[n][sb][1] = tempRight[1]; + } else { + X_left[n][sb][0] = tempLeft[0]; + X_left[n][sb][1] = tempLeft[1]; + X_right[n][sb][0] = tempRight[0]; + X_right[n][sb][1] = tempRight[1]; + } + } + } + } + } + } + + /** main Parametric Stereo decoding function */ + @Override + public void process(float[][][] X_left, float[][][] X_right) { + float[][][] X_hybrid_left = new float[32][32][2]; + float[][][] X_hybrid_right = new float[32][32][2]; + + // delta decoding of the bitstream data + ps_data_decode(); + + // Perform further analysis on the lowest subbands to get a higher + // frequency resolution + fb.hybrid_analysis(X_left, X_hybrid_left, fbt); + + // decorrelate mono signal + ps_decorrelate(X_left, X_right, X_hybrid_left, X_hybrid_right); + + // apply mixing and phase parameters + ps_mix_phase(X_left, X_right, X_hybrid_left, X_hybrid_right); + + // hybrid synthesis, to rebuild the SBR QMF matrices + fb.hybrid_synthesis(X_left, X_hybrid_left, fbt); + + fb.hybrid_synthesis(X_right, X_hybrid_right, fbt); + } } diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/PSOrig.java b/src/main/java/net/sourceforge/jaad/aac/ps/PSOrig.java index 6829e74..79853fa 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/PSOrig.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/PSOrig.java @@ -49,7 +49,7 @@ public class PSOrig implements PS { final int numTimeSlotsRate; - /* bitstream parameters */ + // bitstream parameters boolean enable_iid, enable_icc, enable_ext; int iid_mode; int icc_mode; @@ -66,7 +66,7 @@ public class PSOrig implements PS { boolean[] ipd_dt = new boolean[MAX_PS_ENVELOPES]; boolean[] opd_dt = new boolean[MAX_PS_ENVELOPES]; - /* indices */ + // indices int[] iid_index_prev = new int[34]; int[] icc_index_prev = new int[34]; int[] ipd_index_prev = new int[17]; @@ -76,18 +76,18 @@ public class PSOrig implements PS { int[][] ipd_index = new int[MAX_PS_ENVELOPES][17]; int[][] opd_index = new int[MAX_PS_ENVELOPES][17]; - /* ps data was correctly read */ + /** ps data was correctly read */ boolean ps_data_available; - /* a header has been read */ + /** a header has been read */ boolean header_read; - /* hybrid filterbank parameters */ + // hybrid filterbank parameters Filterbank hyb; FBType fbt = FBType.T20; static final int NR_ALLPASS_BANDS = 22; - /* filter delay handling */ + // filter delay handling int saved_delay; int[] delay_buf_index_ser = new int[NO_ALLPASS_LINKS]; int[] num_sample_delay_ser = new int[NO_ALLPASS_LINKS]; @@ -95,19 +95,23 @@ public class PSOrig implements PS { int[] delay_D = new int[64]; int[] delay_buf_index_delay = new int[64]; - float[][][] delay_Qmf = new float[14][64][2]; /* 14 samples delay max, 64 QMF channels */ - float[][][] delay_SubQmf = new float[2][32][2]; /* 2 samples delay max (SubQmf is always allpass filtered) */ - float[][][][] delay_Qmf_ser = new float[NO_ALLPASS_LINKS][5][64][2]; /* 5 samples delay max (table 8.34), 64 QMF channels */ - float[][][][] delay_SubQmf_ser = new float[NO_ALLPASS_LINKS][5][32][2]; /* 5 samples delay max (table 8.34) */ - - /* transients */ + /** 14 samples delay max, 64 QMF channels */ + float[][][] delay_Qmf = new float[14][64][2]; + /** 2 samples delay max (SubQmf is always allpass filtered) */ + float[][][] delay_SubQmf = new float[2][32][2]; + /** 5 samples delay max (table 8.34), 64 QMF channels */ + float[][][][] delay_Qmf_ser = new float[NO_ALLPASS_LINKS][5][64][2]; + /** 5 samples delay max (table 8.34) */ + float[][][][] delay_SubQmf_ser = new float[NO_ALLPASS_LINKS][5][32][2]; + + // transients static final float ALPHA_DECAY = 0.76592833836465f; static final float ALPHA_SMOOTH = 0.25f; float[] P_PeakDecayNrg = new float[34]; float[] P_prev = new float[34]; float[] P_SmoothPeakDecayDiffNrg_prev = new float[34]; - /* mixing and phase */ + // mixing and phase float[][] h11_prev = new float[50][2]; float[][] h12_prev = new float[50][2]; float[][] h21_prev = new float[50][2]; @@ -132,15 +136,15 @@ public PSOrig(int numTimeSlotsRate) { for (int i = 0; i < NO_ALLPASS_LINKS; i++) { delay_buf_index_ser[i] = 0; - /* THESE ARE CONSTANTS NOW */ + // THESE ARE CONSTANTS NOW num_sample_delay_ser[i] = delay_length_d[i]; } - /* THESE ARE CONSTANT NOW IF PS IS INDEPENDANT OF SAMPLERATE */ + // THESE ARE CONSTANT NOW IF PS IS INDEPENDANT OF SAMPLERATE Arrays.fill(delay_D, 0, SHORT_DELAY_BAND, 14); Arrays.fill(delay_D, SHORT_DELAY_BAND, delay_D.length, 1); - /* mixing and phase */ + // mixing and phase for (int i = 0; i < 50; i++) { h11_prev[i][0] = 1; h12_prev[i][1] = 1; @@ -170,13 +174,13 @@ public boolean isDataAvailable() { @Override public void decode(BitStream ld) { - /* check for new PS header */ + // check for new PS header if (ld.readBool()) { header_read = true; fbt = FBType.T20; - /* Inter-channel Intensity Difference (IID) parameters enabled */ + // Inter-channel Intensity Difference (IID) parameters enabled enable_iid = ld.readBool(); if (enable_iid) { @@ -188,11 +192,11 @@ public void decode(BitStream ld) { if (iid_mode == 2 || iid_mode == 5) fbt = FBType.T34; - /* IPD freq res equal to IID freq res */ + // IPD freq res equal to IID freq res ipd_mode = iid_mode; } - /* Inter-channel Coherence (ICC) parameters enabled */ + // Inter-channel Coherence (ICC) parameters enabled enable_icc = ld.readBool(); if (enable_icc) { @@ -204,7 +208,7 @@ public void decode(BitStream ld) { fbt = FBType.T34; } - /* PS extension layer enabled */ + // PS extension layer enabled enable_ext = ld.readBool(); } @@ -223,7 +227,7 @@ public void decode(BitStream ld) { for (int n = 0; n < num_env; n++) { iid_dt[n] = ld.readBool(); - /* iid_data */ + // iid_data if (iid_mode < 3) { huff_data(ld, iid_dt[n], nr_iid_par, t_huff_iid_def, f_huff_iid_def, iid_index[n]); @@ -238,7 +242,7 @@ public void decode(BitStream ld) { for (int n = 0; n < num_env; n++) { icc_dt[n] = ld.readBool(); - /* icc_data */ + // icc_data huff_data(ld, icc_dt[n], nr_icc_par, t_huff_icc, f_huff_icc, icc_index[n]); } @@ -271,32 +275,32 @@ private void ps_extension(BitStream ld) { for (int n = 0; n < num_env; n++) { ipd_dt[n] = ld.readBool(); - /* ipd_data */ + // ipd_data huff_data(ld, ipd_dt[n], nr_ipdopd_par, t_huff_ipd, f_huff_ipd, ipd_index[n]); opd_dt[n] = ld.readBool(); - /* opd_data */ + // opd_data huff_data(ld, opd_dt[n], nr_ipdopd_par, t_huff_opd, f_huff_opd, opd_index[n]); } } - ld.readBit(); //reserved + ld.readBit(); // reserved } } - /* read huffman data coded in either the frequency or the time direction */ + /** read huffman data coded in either the frequency or the time direction */ private static void huff_data(BitStream ld, boolean dt, int nr_par, int[][] t_huff, int[][] f_huff, int[] par) { if (dt) { - /* coded in time direction */ + // coded in time direction for (int n = 0; n < nr_par; n++) { par[n] = ps_huff_dec(ld, t_huff); } } else { - /* coded in frequency direction */ + // coded in frequency direction par[0] = ps_huff_dec(ld, f_huff); for (int n = 1; n < nr_par; n++) { @@ -305,7 +309,7 @@ private static void huff_data(BitStream ld, boolean dt, int nr_par, } } - /* binary search huffman decoding */ + /** binary search huffman decoding */ private static int ps_huff_dec(BitStream ld, int[][] t_huff) { int index = 0; @@ -317,7 +321,7 @@ private static int ps_huff_dec(BitStream ld, int[][] t_huff) { return index + 31; } - /* limits the value i to the range [min,max] */ + /** limits the value i to the range [min,max] */ private static int delta_clip(int i, int min, int max) { if (i < min) return min; @@ -325,14 +329,14 @@ private static int delta_clip(int i, int min, int max) { } - /* delta decode array */ + /** delta decode array */ private static void delta_decode(boolean enable, int[] index, int[] index_prev, boolean dt_flag, int nr_par, int stride, int min_index, int max_index) { if (enable) { if (!dt_flag) { - /* delta coded in frequency direction */ + // delta coded in frequency direction index[0] = 0 + index[0]; index[0] = delta_clip(index[0], min_index, max_index); @@ -341,34 +345,32 @@ private static void delta_decode(boolean enable, int[] index, int[] index_prev, index[i] = delta_clip(index[i], min_index, max_index); } } else { - /* delta coded in time direction */ + // delta coded in time direction for (int i = 0; i < nr_par; i++) { - //int8_t tmp2; - //int8_t tmp = index[i]; +// int8_t tmp2; +// int8_t tmp = index[i]; - //printf("%d %d\n", index_prev[i*stride], index[i]); - //printf("%d\n", index[i]); +// printf("%d %d\n", index_prev[i*stride], index[i]); +// printf("%d\n", index[i]); index[i] = index_prev[i * stride] + index[i]; - //tmp2 = index[i]; +// tmp2 = index[i]; index[i] = delta_clip(index[i], min_index, max_index); - //if (iid) - //{ - // if (index[i] == 7) - // { - // printf("%d %d %d\n", index_prev[i*stride], tmp, tmp2); - // } - //} +// if (iid) { +// if (index[i] == 7) { +// printf("%d %d %d\n", index_prev[i * stride], tmp, tmp2); +// } +// } } } } else { - /* set indices to zero */ + // set indices to zero for (int i = 0; i < nr_par; i++) { index[i] = 0; } } - /* coarse */ + // coarse if (stride == 2) { for (int i = (nr_par << 1) - 1; i > 0; i--) { index[i] = index[i >> 1]; @@ -376,15 +378,18 @@ private static void delta_decode(boolean enable, int[] index, int[] index_prev, } } - /* delta modulo decode array */ - /* in: log2 value of the modulo value to allow using AND instead of MOD */ + /** + * delta modulo decode array + * + * in: log2 value of the modulo value to allow using AND instead of MOD + */ private static void delta_modulo_decode(boolean enable, int[] index, int[] index_prev, boolean dt_flag, int nr_par, int stride, int and_modulo) { if (enable) { if (!dt_flag) { - /* delta coded in frequency direction */ + // delta coded in frequency direction index[0] = 0 + index[0]; index[0] &= and_modulo; @@ -393,20 +398,20 @@ private static void delta_modulo_decode(boolean enable, int[] index, int[] index index[i] &= and_modulo; } } else { - /* delta coded in time direction */ + // delta coded in time direction for (int i = 0; i < nr_par; i++) { index[i] = index_prev[i * stride] + index[i]; index[i] &= and_modulo; } } } else { - /* set indices to zero */ + // set indices to zero for (int i = 0; i < nr_par; i++) { index[i] = 0; } } - /* coarse */ + // coarse if (stride == 2) { index[0] = 0; for (int i = (nr_par << 1) - 1; i > 0; i--) { @@ -416,7 +421,7 @@ private static void delta_modulo_decode(boolean enable, int[] index, int[] index } private static void map20indexto34(int[] index, int bins) { - //index[0] = index[0]; + // index[0] = index[0]; index[1] = (index[0] + index[1]) / 2; index[2] = index[1]; index[3] = index[2]; @@ -455,10 +460,10 @@ private static void map20indexto34(int[] index, int bins) { } } - /* parse the bitstream data decoded in ps_data() */ + /** parse the bitstream data decoded in ps_data() */ private void ps_data_decode() { - /* ps data not available, use data from previous frame */ + // ps data not available, use data from previous frame if (!ps_data_available) { num_env = 0; } @@ -468,7 +473,7 @@ private void ps_data_decode() { int num_iid_steps = (iid_mode < 3) ? 7 : 15 /*fine quant*/; // iid = 1; - /* delta decode iid parameters */ + // delta decode iid parameters delta_decode(enable_iid, iid_index[env], env == 0 ? iid_index_prev : iid_index[env - 1], iid_dt[env], nr_iid_par, @@ -476,27 +481,27 @@ private void ps_data_decode() { -num_iid_steps, num_iid_steps); // iid = 0; - /* delta decode icc parameters */ + // delta decode icc parameters delta_decode(enable_icc, icc_index[env], env == 0 ? icc_index_prev : icc_index[env - 1], icc_dt[env], nr_icc_par, (icc_mode == 0 || icc_mode == 3) ? 2 : 1, 0, 7); - /* delta modulo decode ipd parameters */ + // delta modulo decode ipd parameters delta_modulo_decode(enable_ipdopd, ipd_index[env], env == 0 ? ipd_index_prev : ipd_index[env - 1], ipd_dt[env], nr_ipdopd_par, 1, 7); - /* delta modulo decode opd parameters */ + // delta modulo decode opd parameters delta_modulo_decode(enable_ipdopd, opd_index[env], env == 0 ? opd_index_prev : opd_index[env - 1], opd_dt[env], nr_ipdopd_par, 1, 7); } - /* handle error case */ + // handle error case if (num_env == 0) { - /* force to 1 */ + // force to 1 num_env = 1; if (enable_iid) { @@ -532,7 +537,7 @@ private void ps_data_decode() { } } - /* update previous indices */ + // update previous indices for (int bin = 0; bin < 34; bin++) { iid_index_prev[bin] = iid_index[num_env - 1][bin]; } @@ -599,25 +604,25 @@ private void ps_data_decode() { } } - /* decorrelate the mono signal using an allpass filter */ + /** decorrelate the mono signal using an allpass filter */ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, float[][][] X_hybrid_left, float[][][] X_hybrid_right) { float[][] P = new float[32][34]; float[][] G_TransientRatio = new float[32][34]; - /* clear the energy values */ + // clear the energy values for (int n = 0; n < 32; n++) { for (int bk = 0; bk < 34; bk++) { P[n][bk] = 0; } } - /* calculate the energy in each parameter band b(k) */ + // calculate the energy in each parameter band b(k) for (int gr = 0; gr < fbt.num_groups; gr++) { - /* select the parameter index b(k) to which this group belongs */ + // select the parameter index b(k) to which this group belongs int bk = fbt.bk(gr); - /* select the upper subband border for this group */ + // select the upper subband border for this group int maxsb = (gr < fbt.num_hybrid_groups) ? fbt.group_border[gr] + 1 : fbt.group_border[gr + 1]; float[][][] Xl = gr < fbt.num_hybrid_groups ? X_hybrid_left : X_left; @@ -627,13 +632,13 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, float[] xl = Xl[n][sb]; float re = xl[0]; float im = xl[1]; - /* accumulate energy */ + // accumulate energy p[bk] += (re * re) + (im * im); } } } - /* calculate transient reduction ratio for each parameter band b(k) */ + // calculate transient reduction ratio for each parameter band b(k) for (int bk = 0; bk < fbt.nr_par_bands; bk++) { for (int n = border_position[0]; n < border_position[num_env]; n++) { float gamma = 1.5f; @@ -642,17 +647,17 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, if (P_PeakDecayNrg[bk] < P[n][bk]) P_PeakDecayNrg[bk] = P[n][bk]; - /* apply smoothing filter to peak decay energy */ + // apply smoothing filter to peak decay energy float P_SmoothPeakDecayDiffNrg = P_SmoothPeakDecayDiffNrg_prev[bk]; P_SmoothPeakDecayDiffNrg += ((P_PeakDecayNrg[bk] - P[n][bk] - P_SmoothPeakDecayDiffNrg_prev[bk]) * ALPHA_SMOOTH); P_SmoothPeakDecayDiffNrg_prev[bk] = P_SmoothPeakDecayDiffNrg; - /* apply smoothing filter to energy */ + // apply smoothing filter to energy float nrg = P_prev[bk]; nrg += ((P[n][bk] - P_prev[bk]) * ALPHA_SMOOTH); P_prev[bk] = nrg; - /* calculate transient ratio */ + // calculate transient ratio if ((P_SmoothPeakDecayDiffNrg * gamma) <= nrg) { G_TransientRatio[n][bk] = 1.0f; } else { @@ -665,7 +670,7 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, int[] temp_delay_ser = new int[NO_ALLPASS_LINKS]; float[] g_DecaySlope_filt = new float[NO_ALLPASS_LINKS]; - /* apply stereo decorrelation filter to the signal */ + // apply stereo decorrelation filter to the signal for (int gr = 0; gr < fbt.num_groups; gr++) { int maxsb; if (gr < fbt.num_hybrid_groups) @@ -678,11 +683,11 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, float[][][][] delay_ser = gr < fbt.num_hybrid_groups ? delay_SubQmf_ser : delay_Qmf_ser; float[][][] qFractAllpassQmf = gr < fbt.num_hybrid_groups ? fbt.qFractAllpassSubQmf : Q_Fract_allpass_Qmf; - /* QMF channel */ + // QMF channel for (int sb = fbt.group_border[gr]; sb < maxsb; sb++) { float g_DecaySlope; - /* g_DecaySlope: [0..1] */ + // g_DecaySlope: [0..1] if (gr < fbt.num_hybrid_groups || sb <= fbt.decay_cutoff) { g_DecaySlope = 1.0f; } else { @@ -690,17 +695,17 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, if (decay <= -20 /* -1/DECAY_SLOPE */) { g_DecaySlope = 0; } else { - /* decay(int)*decay_slope(frac) = g_DecaySlope(frac) */ + //decay(int)*decay_slope(frac) = g_DecaySlope(frac) g_DecaySlope = 1.0f + DECAY_SLOPE * decay; } } - /* calculate g_DecaySlope_filt for every m multiplied by filter_a[m] */ + // calculate g_DecaySlope_filt for every m multiplied by filter_a[m] for (int m = 0; m < NO_ALLPASS_LINKS; m++) { g_DecaySlope_filt[m] = g_DecaySlope * filter_a[m]; } - /* set delay indices */ + // set delay indices temp_delay = saved_delay; for (int n = 0; n < NO_ALLPASS_LINKS; n++) { temp_delay_ser[n] = delay_buf_index_ser[n]; @@ -714,9 +719,9 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, float im = Xl[n][sb][1]; if (sb > NR_ALLPASS_BANDS && gr >= fbt.num_hybrid_groups) { - /* delay */ + // delay float[] delay = delay_Qmf[delay_buf_index_delay[sb]][sb]; - /* never hybrid subbands here, always QMF subbands */ + // never hybrid subbands here, always QMF subbands r0Re = delay[0]; r0Im = delay[1]; delay[0] = re; @@ -725,8 +730,8 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, float[] delayQmf = gr < fbt.num_hybrid_groups ? delay_SubQmf[temp_delay][sb] : delay_Qmf[temp_delay][sb]; - /* allpass filter */ - //int m; + // allpass filter + // int m; float[] Phi_Fract = gr < fbt.num_hybrid_groups ? fbt.phiFract[sb] : Phi_Fract_Qmf[sb]; float tmp0Re = delayQmf[0]; @@ -735,7 +740,7 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, delayQmf[0] = re; delayQmf[1] = im; - /* z^(-2) * Phi_Fract[k] */ + //z^(-2) * Phi_Fract[k] r0Re = (tmp0Re * Phi_Fract[0]) + (tmp0Im * Phi_Fract[1]); r0Im = (tmp0Im * Phi_Fract[0]) - (tmp0Re * Phi_Fract[1]); @@ -747,40 +752,40 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, tmp0Re = delay[0]; tmp0Im = delay[1]; - /* delay by a fraction */ - /* z^(-d(m)) * qFractAllpass[k,m] */ + // delay by a fraction + //z^(-d(m)) * qFractAllpass[k,m] float tmpRe = (tmp0Re * qFractAllpass[0]) + (tmp0Im * qFractAllpass[1]); float tmpIm = (tmp0Im * qFractAllpass[0]) - (tmp0Re * qFractAllpass[1]); - /* -a(m) * g_DecaySlope[k] */ + // -a(m) * g_DecaySlope[k] tmpRe -= g_DecaySlope_filt[m] * r0Re; tmpIm -= g_DecaySlope_filt[m] * r0Im; - /* -a(m) * g_DecaySlope[k] * qFractAllpass[k,m] * z^(-d(m)) */ + // -a(m) * g_DecaySlope[k] * qFractAllpass[k,m] * z^(-d(m)) delay[0] = r0Re + (g_DecaySlope_filt[m] * tmpRe); delay[1] = r0Im + (g_DecaySlope_filt[m] * tmpIm); - /* store for next iteration (or as output value if last iteration) */ + // store for next iteration (or as output value if last iteration) r0Re = tmpRe; r0Im = tmpIm; } } - /* select b(k) for reading the transient ratio */ + // select b(k) for reading the transient ratio int bk = fbt.bk(gr); - /* duck if a past transient is found */ + // duck if a past transient is found Xr[n][sb][0] = (G_TransientRatio[n][bk] * r0Re); Xr[n][sb][1] = (G_TransientRatio[n][bk] * r0Im); - /* Update delay buffer index */ + // Update delay buffer index if (++temp_delay >= 2) { temp_delay = 0; } - /* update delay indices */ + // update delay indices if (sb > NR_ALLPASS_BANDS && gr >= fbt.num_hybrid_groups) { - /* delay_D depends on the samplerate, it can hold the values 14 and 1 */ + // delay_D depends on the samplerate, it can hold the values 14 and 1 if (++delay_buf_index_delay[sb] >= delay_D[sb]) { delay_buf_index_delay[sb] = 0; } @@ -795,7 +800,7 @@ private void ps_decorrelate(float[][][] X_left, float[][][] X_right, } } - /* update delay indices */ + // update delay indices saved_delay = temp_delay; System.arraycopy(temp_delay_ser, 0, delay_buf_index_ser, 0, NO_ALLPASS_LINKS); } @@ -827,7 +832,7 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, int nr_ipdopd_par; // local version if (ipd_mode == 0 || ipd_mode == 3) { - nr_ipdopd_par = 11; /* resolution */ + nr_ipdopd_par = 11; // resolution } else { nr_ipdopd_par = this.nr_ipdopd_par; } @@ -835,31 +840,29 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, for (int gr = 0; gr < fbt.num_groups; gr++) { int bk = fbt.bk(gr); - /* use one channel per group in the subqmf domain */ + // use one channel per group in the subqmf domain int maxsb = (gr < fbt.num_hybrid_groups) ? fbt.group_border[gr] + 1 : fbt.group_border[gr + 1]; for (int env = 0; env < num_env; env++) { if (icc_mode < 3) { - /* type 'A' mixing as described in 8.6.4.6.2.1 */ + // type 'A' mixing as described in 8.6.4.6.2.1 float c_1, c_2; float cosa, sina; float cosb, sinb; float ab1, ab2; float ab3, ab4; - /* - c_1 = sqrt(2.0 / (1.0 + pow(10.0, quant_iid[no_iid_steps + iid_index] / 10.0))); - c_2 = sqrt(2.0 / (1.0 + pow(10.0, quant_iid[no_iid_steps - iid_index] / 10.0))); - alpha = 0.5 * acos(quant_rho[icc_index]); - beta = alpha * ( c_1 - c_2 ) / sqrt(2.0); - */ - //printf("%d\n", ps.iid_index[env][bk]); +// c_1 = sqrt(2.0 / (1.0 + pow(10.0, quant_iid[no_iid_steps + iid_index] / 10.0))); +// c_2 = sqrt(2.0 / (1.0 + pow(10.0, quant_iid[no_iid_steps - iid_index] / 10.0))); +// alpha = 0.5 * acos(quant_rho[icc_index]); +// beta = alpha * (c_1 - c_2) / sqrt(2.0); +// printf("%d\n", ps.iid_index[env][bk]); - /* calculate the scalefactors c_1 and c_2 from the intensity differences */ + // calculate the scalefactors c_1 and c_2 from the intensity differences c_1 = sf_iid[no_iid_steps + iid_index[env][bk]]; c_2 = sf_iid[no_iid_steps - iid_index[env][bk]]; - /* calculate alpha and beta using the ICC parameters */ + // calculate alpha and beta using the ICC parameters cosa = cos_alphas[icc_index[env][bk]]; sina = sin_alphas[icc_index[env][bk]]; @@ -886,13 +889,13 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, ab3 = (sinb * cosa); ab4 = (cosb * sina); - /* h_xy: COEF */ + // h_xy: COEF h11[0] = (c_2 * (ab1 - ab2)); h12[0] = (c_1 * (ab1 + ab2)); h21[0] = (c_2 * (ab3 + ab4)); h22[0] = (c_1 * (ab3 - ab4)); } else { - /* type 'B' mixing as described in 8.6.4.6.2.2 */ + // type 'B' mixing as described in 8.6.4.6.2.2 float sina, cosa; float cosg, sing; @@ -918,40 +921,40 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, h22[0] = (COEF_SQRT2 * (sina * sing)); } - /* calculate phase rotation parameters H_xy */ + // calculate phase rotation parameters H_xy /* note that the imaginary part of these parameters are only calculated when IPD and OPD are enabled */ if ((enable_ipdopd) && (bk < nr_ipdopd_par)) { - /* ringbuffer index */ + // ringbuffer index int i = phase_hist; - /* previous value */ + // previous value tempLeft[0] = (ipd_prev[bk][i][0] * 0.25f); tempLeft[1] = (ipd_prev[bk][i][1] * 0.25f); tempRight[0] = (opd_prev[bk][i][0] * 0.25f); tempRight[1] = (opd_prev[bk][i][1] * 0.25f); - /* save current value */ + // save current value ipd_prev[bk][i][0] = ipdopd_cos_tab[Math.abs(ipd_index[env][bk])]; ipd_prev[bk][i][1] = ipdopd_sin_tab[Math.abs(ipd_index[env][bk])]; opd_prev[bk][i][0] = ipdopd_cos_tab[Math.abs(opd_index[env][bk])]; opd_prev[bk][i][1] = ipdopd_sin_tab[Math.abs(opd_index[env][bk])]; - /* add current value */ + // add current value tempLeft[0] += ipd_prev[bk][i][0]; tempLeft[1] += ipd_prev[bk][i][1]; tempRight[0] += opd_prev[bk][i][0]; tempRight[1] += opd_prev[bk][i][1]; - /* ringbuffer index */ + // ringbuffer index if (i == 0) { i = 2; } i--; - /* get value before previous */ + // get value before previous tempLeft[0] += (ipd_prev[bk][i][0] * 0.5f); tempLeft[1] += (ipd_prev[bk][i][1] * 0.5f); tempRight[0] += (opd_prev[bk][i][0] * 0.5f); @@ -981,7 +984,7 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, phaseRight[1] = 0; } - /* MUL_F(COEF, REAL) = COEF */ + // MUL_F(COEF, REAL) = COEF h11[1] = (h11[0] * phaseLeft[1]); h12[1] = (h12[0] * phaseRight[1]); h21[1] = (h21[0] * phaseLeft[1]); @@ -993,11 +996,11 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, h22[0] = (h22[0] * phaseRight[0]); } - /* length of the envelope n_e+1 - n_e (in time samples) */ - /* 0 < L <= 32: integer */ + // length of the envelope n_e+1 - n_e (in time samples) + // 0 < L <= 32: integer float L = (float) (border_position[env + 1] - border_position[env]); - /* obtain final H_xy by means of linear interpolation */ + // obtain final H_xy by means of linear interpolation deltaH11[0] = (h11[0] - h11_prev[gr][0]) / L; deltaH12[0] = (h12[0] - h12_prev[gr][0]) / L; deltaH21[0] = (h21[0] - h21_prev[gr][0]) / L; @@ -1013,9 +1016,9 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, h21_prev[gr][0] = h21[0]; h22_prev[gr][0] = h22[0]; - /* only calculate imaginary part when needed */ + // only calculate imaginary part when needed if ((enable_ipdopd) && (bk < nr_ipdopd_par)) { - /* obtain final H_xy by means of linear interpolation */ + // obtain final H_xy by means of linear interpolation deltaH11[1] = (h11[1] - h11_prev[gr][1]) / L; deltaH12[1] = (h12[1] - h12_prev[gr][1]) / L; deltaH21[1] = (h21[1] - h21_prev[gr][1]) / L; @@ -1044,9 +1047,9 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, h22_prev[gr][1] = h22[1]; } - /* apply H_xy to the current envelope band of the decorrelated subband */ + // apply H_xy to the current envelope band of the decorrelated subband for (int n = border_position[env]; n < border_position[env + 1]; n++) { - /* addition finalises the interpolation over every n */ + // addition finalises the interpolation over every n H11[0] += deltaH11[0]; H12[0] += deltaH12[0]; H21[0] += deltaH21[0]; @@ -1058,11 +1061,11 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, H22[1] += deltaH22[1]; } - /* channel is an alias to the subband */ + // channel is an alias to the subband for (int sb = fbt.group_border[gr]; sb < maxsb; sb++) { float[] inLeft = new float[2], inRight = new float[2]; - /* load decorrelated samples */ + // load decorrelated samples if (gr < fbt.num_hybrid_groups) { inLeft[0] = X_hybrid_left[n][sb][0]; inLeft[1] = X_hybrid_left[n][sb][1]; @@ -1075,22 +1078,22 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, inRight[1] = X_right[n][sb][1]; } - /* apply mixing */ + // apply mixing tempLeft[0] = (H11[0] * inLeft[0]) + (H21[0] * inRight[0]); tempLeft[1] = (H11[0] * inLeft[1]) + (H21[0] * inRight[1]); tempRight[0] = (H12[0] * inLeft[0]) + (H22[0] * inRight[0]); tempRight[1] = (H12[0] * inLeft[1]) + (H22[0] * inRight[1]); - /* only perform imaginary operations when needed */ + // only perform imaginary operations when needed if ((enable_ipdopd) && (bk < nr_ipdopd_par)) { - /* apply rotation */ + // apply rotation tempLeft[0] -= (H11[1] * inLeft[1]) + (H21[1] * inRight[1]); tempLeft[1] += (H11[1] * inLeft[0]) + (H21[1] * inRight[0]); tempRight[0] -= (H12[1] * inLeft[1]) + (H22[1] * inRight[1]); tempRight[1] += (H12[1] * inLeft[0]) + (H22[1] * inRight[0]); } - /* store final samples */ + // store final samples if (gr < fbt.num_hybrid_groups) { X_hybrid_left[n][sb][0] = tempLeft[0]; X_hybrid_left[n][sb][1] = tempLeft[1]; @@ -1105,7 +1108,7 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, } } - /* shift phase smoother's circular buffer index */ + // shift phase smoother's circular buffer index phase_hist++; if (phase_hist == 2) { phase_hist = 0; @@ -1114,27 +1117,26 @@ private void ps_mix_phase(float[][][] X_left, float[][][] X_right, } } - /* main Parametric Stereo decoding function */ + /** main Parametric Stereo decoding function */ @Override public void process(float[][][] X_left, float[][][] X_right) { float[][][] X_hybrid_left = new float[32][32][2]; float[][][] X_hybrid_right = new float[32][32][2]; - /* delta decoding of the bitstream data */ + // delta decoding of the bitstream data ps_data_decode(); - /* Perform further analysis on the lowest subbands to get a higher - * frequency resolution - */ + // Perform further analysis on the lowest subbands to get a higher + // frequency resolution hyb.hybrid_analysis(X_left, X_hybrid_left, fbt); - /* decorrelate mono signal */ + // decorrelate mono signal ps_decorrelate(X_left, X_right, X_hybrid_left, X_hybrid_right); - /* apply mixing and phase parameters */ + // apply mixing and phase parameters ps_mix_phase(X_left, X_right, X_hybrid_left, X_hybrid_right); - /* hybrid synthesis, to rebuild the SBR QMF matrices */ + // hybrid synthesis, to rebuild the SBR QMF matrices hyb.hybrid_synthesis(X_left, X_hybrid_left, fbt); hyb.hybrid_synthesis(X_right, X_hybrid_right, fbt); diff --git a/src/main/java/net/sourceforge/jaad/aac/ps/PSTables.java b/src/main/java/net/sourceforge/jaad/aac/ps/PSTables.java index 21bc449..d8e67f2 100644 --- a/src/main/java/net/sourceforge/jaad/aac/ps/PSTables.java +++ b/src/main/java/net/sourceforge/jaad/aac/ps/PSTables.java @@ -2,8 +2,8 @@ interface PSTables extends PSConstants { - /* type definitaions */ - /* static data tables */ + // type definitions + // static data tables int[] nr_iid_par_tab = { 10, 20, 34, 10, 20, 34, 0, 0 }; @@ -55,8 +55,8 @@ interface PSTables extends PSConstants { int[] delay_length_d = {3, 4, 5 /* d_48kHz */}; - /* RE(ps->Phi_Fract_Qmf[j]) = (float)cos(M_PI*(j+0.5)*(0.39)); */ - /* IM(ps->Phi_Fract_Qmf[j]) = (float)sin(M_PI*(j+0.5)*(0.39)); */ + // RE(ps->Phi_Fract_Qmf[j]) = (float)cos(M_PI*(j+0.5)*(0.39)); + // IM(ps->Phi_Fract_Qmf[j]) = (float)sin(M_PI*(j+0.5)*(0.39)); float[][] Phi_Fract_Qmf = { {0.8181497455f, 0.5750052333f}, {-0.2638730407f, 0.9645574093f}, @@ -124,8 +124,8 @@ interface PSTables extends PSConstants { {-0.7396311164f, 0.6730124950f} }; - /* RE(Phi_Fract_SubQmf20[j]) = (float)cos(M_PI*f_center_20[j]*0.39); */ - /* IM(Phi_Fract_SubQmf20[j]) = (float)sin(M_PI*f_center_20[j]*0.39); */ + // RE(Phi_Fract_SubQmf20[j]) = (float)cos(M_PI*f_center_20[j]*0.39); + // IM(Phi_Fract_SubQmf20[j]) = (float)sin(M_PI*f_center_20[j]*0.39); float[][] Phi_Fract_SubQmf20 = { {0.9882950187f, 0.1525546312f}, {0.8962930441f, 0.4434623122f}, @@ -141,8 +141,8 @@ interface PSTables extends PSConstants { {-0.9741733670f, -0.2258012742f} }; - /* RE(Phi_Fract_SubQmf34[j]) = (float)cos(M_PI*f_center_34[j]*0.39); */ - /* IM(Phi_Fract_SubQmf34[j]) = (float)sin(M_PI*f_center_34[j]*0.39); */ + // RE(Phi_Fract_SubQmf34[j]) = (float)cos(M_PI*f_center_34[j]*0.39); + // IM(Phi_Fract_SubQmf34[j]) = (float)sin(M_PI*f_center_34[j]*0.39); float[][] Phi_Fract_SubQmf34 = { {1.0000000000f, 0.0000000000f}, {1.0000000000f, 0.0000000000f}, @@ -178,8 +178,8 @@ interface PSTables extends PSConstants { {-0.8607420325f, -0.5090414286f} }; - /* RE(Q_Fract_allpass_Qmf[j][i]) = (float)cos(M_PI*(j+0.5)*(frac_delay_q[i])); */ - /* IM(Q_Fract_allpass_Qmf[j][i]) = (float)sin(M_PI*(j+0.5)*(frac_delay_q[i])); */ + // RE(Q_Fract_allpass_Qmf[j][i]) = (float)cos(M_PI*(j+0.5)*(frac_delay_q[i])); + // IM(Q_Fract_allpass_Qmf[j][i]) = (float)sin(M_PI*(j+0.5)*(frac_delay_q[i])); float[][][] Q_Fract_allpass_Qmf = { {{0.7804303765f, 0.6252426505f}, {0.3826834261f, 0.9238795042f}, {0.8550928831f, 0.5184748173f}}, {{-0.4399392009f, 0.8980275393f}, {-0.9238795042f, -0.3826834261f}, {-0.0643581524f, 0.9979268909f}}, @@ -247,8 +247,8 @@ interface PSTables extends PSConstants { {{-0.5750041008f, -0.8181505203f}, {0.3826834261f, -0.9238795042f}, {0.9941320419f, 0.1081734300f}} }; - /* RE(Q_Fract_allpass_SubQmf20[j][i]) = (float)cos(M_PI*f_center_20[j]*frac_delay_q[i]); */ - /* IM(Q_Fract_allpass_SubQmf20[j][i]) = (float)sin(M_PI*f_center_20[j]*frac_delay_q[i]); */ + // RE(Q_Fract_allpass_SubQmf20[j][i]) = (float)cos(M_PI*f_center_20[j]*frac_delay_q[i]); + // IM(Q_Fract_allpass_SubQmf20[j][i]) = (float)sin(M_PI*f_center_20[j]*frac_delay_q[i]); float[][][] Q_Fract_allpass_SubQmf20 = { {{0.9857769012f, 0.1680592746f}, {0.9569403529f, 0.2902846634f}, {0.9907300472f, 0.1358452588f}}, {{0.8744080663f, 0.4851911962f}, {0.6343932748f, 0.7730104327f}, {0.9175986052f, 0.3975082636f}}, @@ -264,8 +264,8 @@ interface PSTables extends PSConstants { {{-0.8400934935f, -0.5424416065f}, {0.9807852507f, 0.1950903237f}, {-0.9896889329f, 0.1432335079f}} }; - /* RE(Q_Fract_allpass_SubQmf34[j][i]) = (float)cos(M_PI*f_center_34[j]*frac_delay_q[i]); */ - /* IM(Q_Fract_allpass_SubQmf34[j][i]) = (float)sin(M_PI*f_center_34[j]*frac_delay_q[i]); */ + // RE(Q_Fract_allpass_SubQmf34[j][i]) = (float)cos(M_PI*f_center_34[j]*frac_delay_q[i]); + // IM(Q_Fract_allpass_SubQmf34[j][i]) = (float)sin(M_PI*f_center_34[j]*frac_delay_q[i]); float[][][] Q_Fract_allpass_SubQmf34 = { {{1.0000000000f, 0.0000000000f}, {1.0000000000f, 0.0000000000f}, {1.0000000000f, 0.0000000000f}}, {{1.0000000000f, 0.0000000000f}, {1.0000000000f, 0.0000000000f}, {1.0000000000f, 0.0000000000f}}, diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/AnalysisFilterbank.java b/src/main/java/net/sourceforge/jaad/aac/sbr/AnalysisFilterbank.java index 5f5fc30..da25681 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/AnalysisFilterbank.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/AnalysisFilterbank.java @@ -12,20 +12,20 @@ void sbr_qmf_analysis_32(int numTimeSlotsRate, float[] input, float[] in_real = new float[32], in_imag = new float[32]; float[] out_real = new float[32], out_imag = new float[32]; - /* qmf subsample l */ - for (int l = 0, in=0; l < numTimeSlotsRate; l++) { + // qmf subsample l + for (int l = 0, in = 0; l < numTimeSlotsRate; l++) { int n; - /* shift input buffer x */ - /* input buffer is not shifted anymore, x is implemented as double ringbuffer */ + // shift input buffer x + // input buffer is not shifted anymore, x is implemented as double ringbuffer //memmove(qmfa.x + 32, qmfa.x, (320-32)*sizeof(real_t)); - /* add new samples to input buffer x */ + // add new samples to input buffer x for (n = 32 - 1; n >= 0; n--) { this.v[this.v_index + n] = this.v[this.v_index + n + 320] = input[in++]; } - /* window and summation to create array u */ + // window and summation to create array u for (n = 0; n < 64; n++) { u[n] = (this.v[this.v_index + n] * qmf_c[2 * n]) + (this.v[this.v_index + n + 64] * qmf_c[2 * (n + 64)]) @@ -34,12 +34,12 @@ void sbr_qmf_analysis_32(int numTimeSlotsRate, float[] input, + (this.v[this.v_index + n + 256] * qmf_c[2 * (n + 256)]); } - /* update ringbuffer index */ + // update ringbuffer index this.v_index -= 32; if (this.v_index < 0) this.v_index = (320 - 32); - /* calculate 32 subband samples by introducing X */ + // calculate 32 subband samples by introducing X // Reordering of data moved from DCT_IV to here in_imag[31] = u[1]; in_real[0] = u[0]; diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/Channel.java b/src/main/java/net/sourceforge/jaad/aac/sbr/Channel.java index 5e877eb..67ba0c7 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/Channel.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/Channel.java @@ -70,7 +70,7 @@ class Channel { final AnalysisFilterbank qmfa; - public static final int MAX_NTSRHFG = 40; //maximum of number_time_slots * rate + HFGen. 16*2+8 + public static final int MAX_NTSRHFG = 40; // maximum of number_time_slots * rate + HFGen. 16*2+8 float[][][] Xsbr = new float[MAX_NTSRHFG][64][2]; FrameClass bs_frame_class; @@ -91,7 +91,7 @@ public Channel(SBR sbr) { qmfa = new AnalysisFilterbank(32); } - /* table 8 */ + /** table 8 */ void sbr_dtdf(BitStream ld) { for (int i = 0; i < L_E; i++) { @@ -103,7 +103,7 @@ void sbr_dtdf(BitStream ld) { } } - /* table 9 */ + /** table 9 */ void invf_mode(BitStream ld) { for (int n = 0; n < sbr.N_Q; n++) { bs_invf_mode[n] = ld.readBits(2); @@ -131,7 +131,7 @@ void couple(Channel oc, int N_Q) { } } - /* table 10 */ + /** table 10 */ void sbr_envelope(BitStream ld, boolean coupled) { int delta = 0; @@ -202,7 +202,7 @@ void extract_envelope_data() { E[k][l] = 0; } - } else { /* bs_df_env == 1 */ + } else { // bs_df_env == 1 int g = (l == 0) ? f_prev : f[l - 1]; @@ -239,7 +239,7 @@ void extract_envelope_data() { } } - /* table 11 */ + /** table 11 */ void sbr_noise(BitStream ld, boolean coupled) { int delta = 0; int[][] t_huff, f_huff; @@ -306,7 +306,7 @@ void extract_noise_floor_data() { } } - /* table 7 */ + /** table 7 */ int sbr_grid(BitStream ld) { int result; int saved_L_E = L_E; @@ -418,7 +418,7 @@ int sbr_grid(BitStream ld) { else L_Q = 1; - /* TODO: this code can probably be integrated into the code above! */ + // TODO: this code can probably be integrated into the code above! if ((result = envelope_time_border_vector()) > 0) { bs_frame_class = saved_frame_class; L_E = saved_L_E; @@ -433,7 +433,7 @@ int sbr_grid(BitStream ld) { private static final int[] log2tab = {0, 0, 1, 2, 2, 3, 3, 3, 3, 4}; - /* integer log[2](x): input range [0,10) */ + /** integer log[2](x): input range [0,10) */ private static int sbr_log2(int val) { if (val < 10 && val >= 0) @@ -442,11 +442,12 @@ private static int sbr_log2(int val) { return 0; } - private final int[] eTmp = new int[6]; - /* function constructs new time border vector */ - /* first build into temp vector to be able to use previous vector on error */ + /** + * function constructs new time border vector + * first build into temp vector to be able to use previous vector on error + */ int envelope_time_border_vector() { eTmp[0] = sbr.rate * abs_bord_lead; @@ -530,7 +531,7 @@ int envelope_time_border_vector() { break; } - /* no error occured, we can safely use this t_E vector */ + // no error occured, we can safely use this t_E vector System.arraycopy(eTmp, 0, t_E, 0, 6); return 0; @@ -583,17 +584,17 @@ void process_channel(float[] channel_buf, float[][][] X, boolean reset) { boolean dont_process = sbr.hdr == null; - /* subband analysis */ + // subband analysis qmfa.sbr_qmf_analysis_32(sbr.numTimeSlotsRate, channel_buf, Xsbr, sbr.tHFGen, dont_process ? 32 : sbr.kx); if (!dont_process) { - /* insert high frequencies here */ - /* hf generation using patching */ + // insert high frequencies here + // hf generation using patching HFGeneration.hf_generation(Xsbr, Xsbr, this, reset); - /* hf adjustment */ + // hf adjustment HFAdjustment.hf_adjustment(sbr, Xsbr, this); } diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/DCT.java b/src/main/java/net/sourceforge/jaad/aac/sbr/DCT.java index e6d37d2..db62ee0 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/DCT.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/DCT.java @@ -340,15 +340,15 @@ private static void fft_dif(float[] Real, float[] Imag) { Imag[i2] = point1_imag - point2_imag; } - //FFTReorder(Real, Imag); + // FFTReorder(Real, Imag); } - /* size 64 only! */ + /** size 64 only! */ public static void dct4_kernel(float[] in_real, float[] in_imag, float[] out_real, float[] out_imag) { // Tables with bit reverse values for 5 bits, bit reverse of i at i-th position int i, i_rev; - /* Step 2: modulate */ + // Step 2: modulate // 3*32=96 multiplications // 3*32=96 additions for (i = 0; i < 32; i++) { @@ -360,10 +360,10 @@ public static void dct4_kernel(float[] in_real, float[] in_imag, float[] out_rea in_imag[i] = (x_re * dct4_64_tab[i + 32]) + tmp; } - /* Step 3: FFT, but with output in bit reverse order */ + // Step 3: FFT, but with output in bit reverse order fft_dif(in_real, in_imag); - /* Step 4: modulate + bitreverse reordering */ + // Step 4: modulate + bitreverse reordering // 3*31+2=95 multiplications // 3*31+2=95 additions for (i = 0; i < 16; i++) { diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/FBT.java b/src/main/java/net/sourceforge/jaad/aac/sbr/FBT.java index 019130c..d63574f 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/FBT.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/FBT.java @@ -24,8 +24,11 @@ class FBT { public static final int LO_RES = 0; public static final int HI_RES = 1; - /* calculate the start QMF channel for the master frequency band table */ - /* parameter is also called k0 */ + + /** + * calculate the start QMF channel for the master frequency band table + * parameter is also called k0 + */ public static int qmf_start_channel(int bs_start_freq, int bs_samplerate_mode, SampleFrequency sample_rate) { int startMin = startMinTable[sample_rate.getIndex()]; @@ -54,9 +57,11 @@ public static int qmf_start_channel(int bs_start_freq, int bs_samplerate_mode, S {0, -1, -2, -3, -4, -5, -6, -6, -6, -6, -6, -6, -6, -6}, {0, -3, -6, -9, -12, -15, -18, -20, -22, -24, -26, -28, -30, -32} }; - /* calculate the stop QMF channel for the master frequency band table */ - /* parameter is also called k2 */ + /** + * calculate the stop QMF channel for the master frequency band table + * parameter is also called k2 + */ public static int qmf_stop_channel(int bs_stop_freq, SampleFrequency sample_rate, int k0) { if (bs_stop_freq == 15) { return Math.min(64, k0 * 3); @@ -65,20 +70,21 @@ public static int qmf_stop_channel(int bs_stop_freq, SampleFrequency sample_rate } else { int stopMin = stopMinTable[sample_rate.getIndex()]; - /* bs_stop_freq <= 13 */ + // bs_stop_freq <= 13 return Math.min(64, stopMin + STOP_OFFSET_TABLE[sample_rate.getIndex()][Math.min(bs_stop_freq, 13)]); } } - /* calculate the master frequency table from k0, k2, bs_freq_scale - and bs_alter_scale - - version for bs_freq_scale = 0 + /** + * calculate the master frequency table from k0, k2, bs_freq_scale + * and bs_alter_scale + * + * version for bs_freq_scale = 0 */ public static int master_frequency_table_fs0(SBR sbr, int k0, int k2, boolean bs_alter_scale) { int[] vDk = new int[64]; - /* mft only defined for k2 > k0 */ + // mft only defined for k2 > k0 if (k2 <= k0) { sbr.N_master = 0; return 1; @@ -144,7 +150,7 @@ public static int master_frequency_table(SBR sbr, int k0, int k2, int[] vk0 = new int[64], vk1 = new int[64]; int[] temp1 = {6, 5, 4}; - /* mft only defined for k2 > k0 */ + // mft only defined for k2 > k0 if (k2 <= k0) { sbr.N_master = 0; return 1; @@ -177,8 +183,8 @@ public static int master_frequency_table(SBR sbr, int k0, int k2, vDk0[k] = A_1 - A_0; } - /* needed? */ - //qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp); + // needed? + // qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp); Arrays.sort(vDk0, 0, nrBand0); vk0[0] = k0; @@ -214,16 +220,16 @@ public static int master_frequency_table(SBR sbr, int k0, int k2, if (vDk1[0] < vDk0[nrBand0 - 1]) { int change; - /* needed? */ - //qsort(vDk1, nrBand1+1, sizeof(vDk1[0]), longcmp); + // needed? + // qsort(vDk1, nrBand1+1, sizeof(vDk1[0]), longcmp); Arrays.sort(vDk1, 0, nrBand1 + 1); change = vDk0[nrBand0 - 1] - vDk1[0]; vDk1[0] = vDk0[nrBand0 - 1]; vDk1[nrBand1 - 1] = vDk1[nrBand1 - 1] - change; } - /* needed? */ - //qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp); + // needed? + // qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp); Arrays.sort(vDk1, 0, nrBand1); vk1[0] = k1; for (int k = 1; k <= nrBand1; k++) { @@ -244,10 +250,10 @@ public static int master_frequency_table(SBR sbr, int k0, int k2, return 0; } - /* calculate the derived frequency border tables from f_master */ + /** calculate the derived frequency border tables from f_master */ public static int derived_frequency_table(SBR sbr, int bs_xover_band, int k2) { - /* The following relation shall be satisfied: bs_xover_band < N_Master */ + // The following relation shall be satisfied: bs_xover_band < N_Master if (sbr.N_master <= bs_xover_band) return 1; @@ -289,13 +295,13 @@ public static int derived_frequency_table(SBR sbr, int bs_xover_band, int k2) { if (k == 0) { i = 0; } else { - /* i = i + (int32_t)((sbr.N_low - i)/(sbr.N_Q + 1 - k)); */ + // i = i + (int32_t)((sbr.N_low - i)/(sbr.N_Q + 1 - k)); i += (sbr.N_low - i) / (sbr.N_Q + 1 - k); } sbr.f_table_noise[k] = sbr.f_table_res[LO_RES][i]; } - /* build table for mapping k to g in hf patching */ + // build table for mapping k to g in hf patching for (int k = 0; k < 64; k++) { for (int g = 0; g < sbr.N_Q; g++) { if ((sbr.f_table_noise[g] <= k) @@ -308,10 +314,11 @@ public static int derived_frequency_table(SBR sbr, int bs_xover_band, int k2) { return 0; } - /* TODO: blegh, ugly */ - /* Modified to calculate for all possible bs_limiter_bands always + /** + * Modified to calculate for all possible bs_limiter_bands always * This reduces the number calls to this functions needed (now only on * header reset) + * TODO blegh, ugly */ private static final float[] limiterBandsCompare = {1.327152f, 1.185093f, 1.119872f}; @@ -338,8 +345,8 @@ public static void limiter_frequency_table(SBR sbr) { limTable[k + sbr.N_low] = patchBorders[k]; } - /* needed */ - //qsort(limTable, sbr.noPatches+sbr.N_low, sizeof(limTable[0]), longcmp); + // needed + // qsort(limTable, sbr.noPatches+sbr.N_low, sizeof(limTable[0]), longcmp); Arrays.sort(limTable, 0, sbr.noPatches + sbr.N_low); int k = 1; int nrLim = sbr.noPatches + sbr.N_low - 1; @@ -373,24 +380,24 @@ public static void limiter_frequency_table(SBR sbr) { k++; continue; } else { - /* remove (k-1)th element */ + // remove (k-1)th element limTable[k - 1] = sbr.f_table_res[LO_RES][sbr.N_low]; - //qsort(limTable, sbr.noPatches+sbr.N_low, sizeof(limTable[0]), longcmp); + // qsort(limTable, sbr.noPatches+sbr.N_low, sizeof(limTable[0]), longcmp); Arrays.sort(limTable, 0, sbr.noPatches + sbr.N_low); nrLim--; continue; } } } - /* remove kth element */ + // remove kth element limTable[k] = sbr.f_table_res[LO_RES][sbr.N_low]; - //qsort(limTable, nrLim, sizeof(limTable[0]), longcmp); + // qsort(limTable, nrLim, sizeof(limTable[0]), longcmp); Arrays.sort(limTable, 0, nrLim); nrLim--; - //continue; + // continue; } else { k++; - //continue; + // continue; } } diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/Filterbank.java b/src/main/java/net/sourceforge/jaad/aac/sbr/Filterbank.java index df843c9..bddc4cc 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/Filterbank.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/Filterbank.java @@ -2,340 +2,343 @@ import java.util.Arrays; + class Filterbank { - static final float[] qmf_c = { - 0f, -0.00055252865047f, - -0.00056176925738f, -0.00049475180896f, - -0.00048752279712f, -0.00048937912498f, - -0.00050407143497f, -0.00052265642972f, - -0.00054665656337f, -0.00056778025613f, - -0.00058709304852f, -0.00061327473938f, - -0.00063124935319f, -0.00065403333621f, - -0.00067776907764f, -0.00069416146273f, - -0.00071577364744f, -0.00072550431222f, - -0.00074409418541f, -0.00074905980532f, - -0.0007681371927f, -0.00077248485949f, - -0.00078343322877f, -0.00077798694927f, - -0.000780366471f, -0.00078014496257f, - -0.0007757977331f, -0.00076307935757f, - -0.00075300014201f, -0.00073193571525f, - -0.00072153919876f, -0.00069179375372f, - -0.00066504150893f, -0.00063415949025f, - -0.0005946118933f, -0.00055645763906f, - -0.00051455722108f, -0.00046063254803f, - -0.00040951214522f, -0.00035011758756f, - -0.00028969811748f, -0.0002098337344f, - -0.00014463809349f, -6.173344072E-005f, - 1.349497418E-005f, 0.00010943831274f, - 0.00020430170688f, 0.00029495311041f, - 0.0004026540216f, 0.00051073884952f, - 0.00062393761391f, 0.00074580258865f, - 0.00086084433262f, 0.00098859883015f, - 0.00112501551307f, 0.00125778846475f, - 0.00139024948272f, 0.00154432198471f, - 0.00168680832531f, 0.00183482654224f, - 0.00198411407369f, 0.00214615835557f, - 0.00230172547746f, 0.00246256169126f, - 0.00262017586902f, 0.00278704643465f, - 0.00294694477165f, 0.00311254206525f, - 0.00327396134847f, 0.00344188741828f, - 0.00360082681231f, 0.00376039229104f, - 0.00392074323703f, 0.00408197531935f, - 0.0042264269227f, 0.00437307196781f, - 0.00452098527825f, 0.00466064606118f, - 0.00479325608498f, 0.00491376035745f, - 0.00503930226013f, 0.00514073539032f, - 0.00524611661324f, 0.00534716811982f, - 0.00541967759307f, 0.00548760401507f, - 0.00554757145088f, 0.00559380230045f, - 0.00562206432097f, 0.00564551969164f, - 0.00563891995151f, 0.00562661141932f, - 0.0055917128663f, 0.005540436394f, - 0.0054753783077f, 0.0053838975897f, - 0.00527157587272f, 0.00513822754514f, - 0.00498396877629f, 0.004810946906f, - 0.00460395301471f, 0.00438018617447f, - 0.0041251642327f, 0.00384564081246f, - 0.00354012465507f, 0.00320918858098f, - 0.00284467578623f, 0.00245085400321f, - 0.0020274176185f, 0.00157846825768f, - 0.00109023290512f, 0.0005832264248f, - 2.760451905E-005f, -0.00054642808664f, - -0.00115681355227f, -0.00180394725893f, - -0.00248267236449f, -0.003193377839f, - -0.00394011240522f, -0.004722259624f, - -0.00553372111088f, -0.00637922932685f, - -0.00726158168517f, -0.00817982333726f, - -0.00913253296085f, -0.01011502154986f, - -0.01113155480321f, -0.01218499959508f, - 0.01327182200351f, 0.01439046660792f, - 0.01554055533423f, 0.01673247129989f, - 0.01794333813443f, 0.01918724313698f, - 0.02045317933555f, 0.02174675502535f, - 0.02306801692862f, 0.02441609920285f, - 0.02578758475467f, 0.02718594296329f, - 0.02860721736385f, 0.03005026574279f, - 0.03150176087389f, 0.03297540810337f, - 0.03446209487686f, 0.03596975605542f, - 0.03748128504252f, 0.03900536794745f, - 0.04053491705584f, 0.04206490946367f, - 0.04360975421304f, 0.04514884056413f, - 0.04668430272642f, 0.04821657200672f, - 0.04973857556014f, 0.05125561555216f, - 0.05276307465207f, 0.05424527683589f, - 0.05571736482138f, 0.05716164501299f, - 0.0585915683626f, 0.05998374801761f, - 0.06134551717207f, 0.06268578081172f, - 0.06397158980681f, 0.0652247106438f, - 0.06643675122104f, 0.06760759851228f, - 0.06870438283512f, 0.06976302447127f, - 0.07076287107266f, 0.07170026731102f, - 0.07256825833083f, 0.07336202550803f, - 0.07410036424342f, 0.07474525581194f, - 0.07531373362019f, 0.07580083586584f, - 0.07619924793396f, 0.07649921704119f, - 0.07670934904245f, 0.07681739756964f, - 0.07682300113923f, 0.07672049241746f, - 0.07650507183194f, 0.07617483218536f, - 0.07573057565061f, 0.0751576255287f, - 0.07446643947564f, 0.0736406005762f, - 0.07267746427299f, 0.07158263647903f, - 0.07035330735093f, 0.06896640131951f, - 0.06745250215166f, 0.06576906686508f, - 0.06394448059633f, 0.06196027790387f, - 0.0598166570809f, 0.05751526919867f, - 0.05504600343009f, 0.05240938217366f, - 0.04959786763445f, 0.04663033051701f, - 0.04347687821958f, 0.04014582784127f, - 0.03664181168133f, 0.03295839306691f, - 0.02908240060125f, 0.02503075618909f, - 0.02079970728622f, 0.01637012582228f, - 0.01176238327857f, 0.00696368621617f, - 0.00197656014503f, -0.00320868968304f, - -0.00857117491366f, -0.01412888273558f, - -0.01988341292573f, -0.02582272888064f, - -0.03195312745332f, -0.03827765720822f, - -0.04478068215856f, -0.05148041767934f, - -0.05837053268336f, -0.06544098531359f, - -0.07269433008129f, -0.08013729344279f, - -0.08775475365593f, -0.09555333528914f, - -0.10353295311463f, -0.1116826931773f, - -0.120007798468f, -0.12850028503878f, - -0.13715517611934f, -0.1459766491187f, - -0.15496070710605f, -0.16409588556669f, - -0.17338081721706f, -0.18281725485142f, - -0.19239667457267f, -0.20212501768103f, - -0.21197358538056f, -0.22196526964149f, - -0.23206908706791f, -0.24230168845974f, - -0.25264803095722f, -0.26310532994603f, - -0.27366340405625f, -0.28432141891085f, - -0.29507167170646f, -0.30590985751916f, - -0.31682789136456f, -0.32781137272105f, - -0.33887226938665f, -0.3499914122931f, - 0.36115899031355f, 0.37237955463061f, - 0.38363500139043f, 0.39492117615675f, - 0.40623176767625f, 0.41756968968409f, - 0.42891199207373f, 0.44025537543665f, - 0.45159965356824f, 0.46293080852757f, - 0.47424532146115f, 0.48552530911099f, - 0.49677082545707f, 0.50798175000434f, - 0.51912349702391f, 0.53022408956855f, - 0.54125534487322f, 0.55220512585061f, - 0.5630789140137f, 0.57385241316923f, - 0.58454032354679f, 0.59511230862496f, - 0.6055783538918f, 0.61591099320291f, - 0.62612426956055f, 0.63619801077286f, - 0.64612696959461f, 0.65590163024671f, - 0.66551398801627f, 0.67496631901712f, - 0.68423532934598f, 0.69332823767032f, - 0.70223887193539f, 0.71094104263095f, - 0.71944626349561f, 0.72774489002994f, - 0.73582117582769f, 0.74368278636488f, - 0.75131374561237f, 0.75870807608242f, - 0.76586748650939f, 0.77277808813327f, - 0.77942875190216f, 0.7858353120392f, - 0.79197358416424f, 0.797846641377f, - 0.80344857518505f, 0.80876950044491f, - 0.81381912706217f, 0.81857760046468f, - 0.82304198905409f, 0.8272275347336f, - 0.8311038457152f, 0.83469373618402f, - 0.83797173378865f, 0.84095413924722f, - 0.84362382812005f, 0.84598184698206f, - 0.84803157770763f, 0.84978051984268f, - 0.85119715249343f, 0.85230470352147f, - 0.85310209497017f, 0.85357205739107f, - 0.85373856005937f /*max*/, 0.85357205739107f, - 0.85310209497017f, 0.85230470352147f, - 0.85119715249343f, 0.84978051984268f, - 0.84803157770763f, 0.84598184698206f, - 0.84362382812005f, 0.84095413924722f, - 0.83797173378865f, 0.83469373618402f, - 0.8311038457152f, 0.8272275347336f, - 0.82304198905409f, 0.81857760046468f, - 0.81381912706217f, 0.80876950044491f, - 0.80344857518505f, 0.797846641377f, - 0.79197358416424f, 0.7858353120392f, - 0.77942875190216f, 0.77277808813327f, - 0.76586748650939f, 0.75870807608242f, - 0.75131374561237f, 0.74368278636488f, - 0.73582117582769f, 0.72774489002994f, - 0.71944626349561f, 0.71094104263095f, - 0.70223887193539f, 0.69332823767032f, - 0.68423532934598f, 0.67496631901712f, - 0.66551398801627f, 0.65590163024671f, - 0.64612696959461f, 0.63619801077286f, - 0.62612426956055f, 0.61591099320291f, - 0.6055783538918f, 0.59511230862496f, - 0.58454032354679f, 0.57385241316923f, - 0.5630789140137f, 0.55220512585061f, - 0.54125534487322f, 0.53022408956855f, - 0.51912349702391f, 0.50798175000434f, - 0.49677082545707f, 0.48552530911099f, - 0.47424532146115f, 0.46293080852757f, - 0.45159965356824f, 0.44025537543665f, - 0.42891199207373f, 0.41756968968409f, - 0.40623176767625f, 0.39492117615675f, - 0.38363500139043f, 0.37237955463061f, - -0.36115899031355f, -0.3499914122931f, - -0.33887226938665f, -0.32781137272105f, - -0.31682789136456f, -0.30590985751916f, - -0.29507167170646f, -0.28432141891085f, - -0.27366340405625f, -0.26310532994603f, - -0.25264803095722f, -0.24230168845974f, - -0.23206908706791f, -0.22196526964149f, - -0.21197358538056f, -0.20212501768103f, - -0.19239667457267f, -0.18281725485142f, - -0.17338081721706f, -0.16409588556669f, - -0.15496070710605f, -0.1459766491187f, - -0.13715517611934f, -0.12850028503878f, - -0.120007798468f, -0.1116826931773f, - -0.10353295311463f, -0.09555333528914f, - -0.08775475365593f, -0.08013729344279f, - -0.07269433008129f, -0.06544098531359f, - -0.05837053268336f, -0.05148041767934f, - -0.04478068215856f, -0.03827765720822f, - -0.03195312745332f, -0.02582272888064f, - -0.01988341292573f, -0.01412888273558f, - -0.00857117491366f, -0.00320868968304f, - 0.00197656014503f, 0.00696368621617f, - 0.01176238327857f, 0.01637012582228f, - 0.02079970728622f, 0.02503075618909f, - 0.02908240060125f, 0.03295839306691f, - 0.03664181168133f, 0.04014582784127f, - 0.04347687821958f, 0.04663033051701f, - 0.04959786763445f, 0.05240938217366f, - 0.05504600343009f, 0.05751526919867f, - 0.0598166570809f, 0.06196027790387f, - 0.06394448059633f, 0.06576906686508f, - 0.06745250215166f, 0.06896640131951f, - 0.07035330735093f, 0.07158263647903f, - 0.07267746427299f, 0.0736406005762f, - 0.07446643947564f, 0.0751576255287f, - 0.07573057565061f, 0.07617483218536f, - 0.07650507183194f, 0.07672049241746f, - 0.07682300113923f, 0.07681739756964f, - 0.07670934904245f, 0.07649921704119f, - 0.07619924793396f, 0.07580083586584f, - 0.07531373362019f, 0.07474525581194f, - 0.07410036424342f, 0.07336202550803f, - 0.07256825833083f, 0.07170026731102f, - 0.07076287107266f, 0.06976302447127f, - 0.06870438283512f, 0.06760759851228f, - 0.06643675122104f, 0.0652247106438f, - 0.06397158980681f, 0.06268578081172f, - 0.06134551717207f, 0.05998374801761f, - 0.0585915683626f, 0.05716164501299f, - 0.05571736482138f, 0.05424527683589f, - 0.05276307465207f, 0.05125561555216f, - 0.04973857556014f, 0.04821657200672f, - 0.04668430272642f, 0.04514884056413f, - 0.04360975421304f, 0.04206490946367f, - 0.04053491705584f, 0.03900536794745f, - 0.03748128504252f, 0.03596975605542f, - 0.03446209487686f, 0.03297540810337f, - 0.03150176087389f, 0.03005026574279f, - 0.02860721736385f, 0.02718594296329f, - 0.02578758475467f, 0.02441609920285f, - 0.02306801692862f, 0.02174675502535f, - 0.02045317933555f, 0.01918724313698f, - 0.01794333813443f, 0.01673247129989f, - 0.01554055533423f, 0.01439046660792f, - -0.01327182200351f, -0.01218499959508f, - -0.01113155480321f, -0.01011502154986f, - -0.00913253296085f, -0.00817982333726f, - -0.00726158168517f, -0.00637922932685f, - -0.00553372111088f, -0.004722259624f, - -0.00394011240522f, -0.003193377839f, - -0.00248267236449f, -0.00180394725893f, - -0.00115681355227f, -0.00054642808664f, - 2.760451905E-005f, 0.0005832264248f, - 0.00109023290512f, 0.00157846825768f, - 0.0020274176185f, 0.00245085400321f, - 0.00284467578623f, 0.00320918858098f, - 0.00354012465507f, 0.00384564081246f, - 0.0041251642327f, 0.00438018617447f, - 0.00460395301471f, 0.004810946906f, - 0.00498396877629f, 0.00513822754514f, - 0.00527157587272f, 0.0053838975897f, - 0.0054753783077f, 0.005540436394f, - 0.0055917128663f, 0.00562661141932f, - 0.00563891995151f, 0.00564551969164f, - 0.00562206432097f, 0.00559380230045f, - 0.00554757145088f, 0.00548760401507f, - 0.00541967759307f, 0.00534716811982f, - 0.00524611661324f, 0.00514073539032f, - 0.00503930226013f, 0.00491376035745f, - 0.00479325608498f, 0.00466064606118f, - 0.00452098527825f, 0.00437307196781f, - 0.0042264269227f, 0.00408197531935f, - 0.00392074323703f, 0.00376039229104f, - 0.00360082681231f, 0.00344188741828f, - 0.00327396134847f, 0.00311254206525f, - 0.00294694477165f, 0.00278704643465f, - 0.00262017586902f, 0.00246256169126f, - 0.00230172547746f, 0.00214615835557f, - 0.00198411407369f, 0.00183482654224f, - 0.00168680832531f, 0.00154432198471f, - 0.00139024948272f, 0.00125778846475f, - 0.00112501551307f, 0.00098859883015f, - 0.00086084433262f, 0.00074580258865f, - 0.00062393761391f, 0.00051073884952f, - 0.0004026540216f, 0.00029495311041f, - 0.00020430170688f, 0.00010943831274f, - 1.349497418E-005f, -6.173344072E-005f, - -0.00014463809349f, -0.0002098337344f, - -0.00028969811748f, -0.00035011758756f, - -0.00040951214522f, -0.00046063254803f, - -0.00051455722108f, -0.00055645763906f, - -0.0005946118933f, -0.00063415949025f, - -0.00066504150893f, -0.00069179375372f, - -0.00072153919876f, -0.00073193571525f, - -0.00075300014201f, -0.00076307935757f, - -0.0007757977331f, -0.00078014496257f, - -0.000780366471f, -0.00077798694927f, - -0.00078343322877f, -0.00077248485949f, - -0.0007681371927f, -0.00074905980532f, - -0.00074409418541f, -0.00072550431222f, - -0.00071577364744f, -0.00069416146273f, - -0.00067776907764f, -0.00065403333621f, - -0.00063124935319f, -0.00061327473938f, - -0.00058709304852f, -0.00056778025613f, - -0.00054665656337f, -0.00052265642972f, - -0.00050407143497f, -0.00048937912498f, - -0.00048752279712f, -0.00049475180896f, - -0.00056176925738f, -0.00055252865047f - }; + static final float[] qmf_c = { + 0f, -0.00055252865047f, + -0.00056176925738f, -0.00049475180896f, + -0.00048752279712f, -0.00048937912498f, + -0.00050407143497f, -0.00052265642972f, + -0.00054665656337f, -0.00056778025613f, + -0.00058709304852f, -0.00061327473938f, + -0.00063124935319f, -0.00065403333621f, + -0.00067776907764f, -0.00069416146273f, + -0.00071577364744f, -0.00072550431222f, + -0.00074409418541f, -0.00074905980532f, + -0.0007681371927f, -0.00077248485949f, + -0.00078343322877f, -0.00077798694927f, + -0.000780366471f, -0.00078014496257f, + -0.0007757977331f, -0.00076307935757f, + -0.00075300014201f, -0.00073193571525f, + -0.00072153919876f, -0.00069179375372f, + -0.00066504150893f, -0.00063415949025f, + -0.0005946118933f, -0.00055645763906f, + -0.00051455722108f, -0.00046063254803f, + -0.00040951214522f, -0.00035011758756f, + -0.00028969811748f, -0.0002098337344f, + -0.00014463809349f, -6.173344072E-005f, + 1.349497418E-005f, 0.00010943831274f, + 0.00020430170688f, 0.00029495311041f, + 0.0004026540216f, 0.00051073884952f, + 0.00062393761391f, 0.00074580258865f, + 0.00086084433262f, 0.00098859883015f, + 0.00112501551307f, 0.00125778846475f, + 0.00139024948272f, 0.00154432198471f, + 0.00168680832531f, 0.00183482654224f, + 0.00198411407369f, 0.00214615835557f, + 0.00230172547746f, 0.00246256169126f, + 0.00262017586902f, 0.00278704643465f, + 0.00294694477165f, 0.00311254206525f, + 0.00327396134847f, 0.00344188741828f, + 0.00360082681231f, 0.00376039229104f, + 0.00392074323703f, 0.00408197531935f, + 0.0042264269227f, 0.00437307196781f, + 0.00452098527825f, 0.00466064606118f, + 0.00479325608498f, 0.00491376035745f, + 0.00503930226013f, 0.00514073539032f, + 0.00524611661324f, 0.00534716811982f, + 0.00541967759307f, 0.00548760401507f, + 0.00554757145088f, 0.00559380230045f, + 0.00562206432097f, 0.00564551969164f, + 0.00563891995151f, 0.00562661141932f, + 0.0055917128663f, 0.005540436394f, + 0.0054753783077f, 0.0053838975897f, + 0.00527157587272f, 0.00513822754514f, + 0.00498396877629f, 0.004810946906f, + 0.00460395301471f, 0.00438018617447f, + 0.0041251642327f, 0.00384564081246f, + 0.00354012465507f, 0.00320918858098f, + 0.00284467578623f, 0.00245085400321f, + 0.0020274176185f, 0.00157846825768f, + 0.00109023290512f, 0.0005832264248f, + 2.760451905E-005f, -0.00054642808664f, + -0.00115681355227f, -0.00180394725893f, + -0.00248267236449f, -0.003193377839f, + -0.00394011240522f, -0.004722259624f, + -0.00553372111088f, -0.00637922932685f, + -0.00726158168517f, -0.00817982333726f, + -0.00913253296085f, -0.01011502154986f, + -0.01113155480321f, -0.01218499959508f, + 0.01327182200351f, 0.01439046660792f, + 0.01554055533423f, 0.01673247129989f, + 0.01794333813443f, 0.01918724313698f, + 0.02045317933555f, 0.02174675502535f, + 0.02306801692862f, 0.02441609920285f, + 0.02578758475467f, 0.02718594296329f, + 0.02860721736385f, 0.03005026574279f, + 0.03150176087389f, 0.03297540810337f, + 0.03446209487686f, 0.03596975605542f, + 0.03748128504252f, 0.03900536794745f, + 0.04053491705584f, 0.04206490946367f, + 0.04360975421304f, 0.04514884056413f, + 0.04668430272642f, 0.04821657200672f, + 0.04973857556014f, 0.05125561555216f, + 0.05276307465207f, 0.05424527683589f, + 0.05571736482138f, 0.05716164501299f, + 0.0585915683626f, 0.05998374801761f, + 0.06134551717207f, 0.06268578081172f, + 0.06397158980681f, 0.0652247106438f, + 0.06643675122104f, 0.06760759851228f, + 0.06870438283512f, 0.06976302447127f, + 0.07076287107266f, 0.07170026731102f, + 0.07256825833083f, 0.07336202550803f, + 0.07410036424342f, 0.07474525581194f, + 0.07531373362019f, 0.07580083586584f, + 0.07619924793396f, 0.07649921704119f, + 0.07670934904245f, 0.07681739756964f, + 0.07682300113923f, 0.07672049241746f, + 0.07650507183194f, 0.07617483218536f, + 0.07573057565061f, 0.0751576255287f, + 0.07446643947564f, 0.0736406005762f, + 0.07267746427299f, 0.07158263647903f, + 0.07035330735093f, 0.06896640131951f, + 0.06745250215166f, 0.06576906686508f, + 0.06394448059633f, 0.06196027790387f, + 0.0598166570809f, 0.05751526919867f, + 0.05504600343009f, 0.05240938217366f, + 0.04959786763445f, 0.04663033051701f, + 0.04347687821958f, 0.04014582784127f, + 0.03664181168133f, 0.03295839306691f, + 0.02908240060125f, 0.02503075618909f, + 0.02079970728622f, 0.01637012582228f, + 0.01176238327857f, 0.00696368621617f, + 0.00197656014503f, -0.00320868968304f, + -0.00857117491366f, -0.01412888273558f, + -0.01988341292573f, -0.02582272888064f, + -0.03195312745332f, -0.03827765720822f, + -0.04478068215856f, -0.05148041767934f, + -0.05837053268336f, -0.06544098531359f, + -0.07269433008129f, -0.08013729344279f, + -0.08775475365593f, -0.09555333528914f, + -0.10353295311463f, -0.1116826931773f, + -0.120007798468f, -0.12850028503878f, + -0.13715517611934f, -0.1459766491187f, + -0.15496070710605f, -0.16409588556669f, + -0.17338081721706f, -0.18281725485142f, + -0.19239667457267f, -0.20212501768103f, + -0.21197358538056f, -0.22196526964149f, + -0.23206908706791f, -0.24230168845974f, + -0.25264803095722f, -0.26310532994603f, + -0.27366340405625f, -0.28432141891085f, + -0.29507167170646f, -0.30590985751916f, + -0.31682789136456f, -0.32781137272105f, + -0.33887226938665f, -0.3499914122931f, + 0.36115899031355f, 0.37237955463061f, + 0.38363500139043f, 0.39492117615675f, + 0.40623176767625f, 0.41756968968409f, + 0.42891199207373f, 0.44025537543665f, + 0.45159965356824f, 0.46293080852757f, + 0.47424532146115f, 0.48552530911099f, + 0.49677082545707f, 0.50798175000434f, + 0.51912349702391f, 0.53022408956855f, + 0.54125534487322f, 0.55220512585061f, + 0.5630789140137f, 0.57385241316923f, + 0.58454032354679f, 0.59511230862496f, + 0.6055783538918f, 0.61591099320291f, + 0.62612426956055f, 0.63619801077286f, + 0.64612696959461f, 0.65590163024671f, + 0.66551398801627f, 0.67496631901712f, + 0.68423532934598f, 0.69332823767032f, + 0.70223887193539f, 0.71094104263095f, + 0.71944626349561f, 0.72774489002994f, + 0.73582117582769f, 0.74368278636488f, + 0.75131374561237f, 0.75870807608242f, + 0.76586748650939f, 0.77277808813327f, + 0.77942875190216f, 0.7858353120392f, + 0.79197358416424f, 0.797846641377f, + 0.80344857518505f, 0.80876950044491f, + 0.81381912706217f, 0.81857760046468f, + 0.82304198905409f, 0.8272275347336f, + 0.8311038457152f, 0.83469373618402f, + 0.83797173378865f, 0.84095413924722f, + 0.84362382812005f, 0.84598184698206f, + 0.84803157770763f, 0.84978051984268f, + 0.85119715249343f, 0.85230470352147f, + 0.85310209497017f, 0.85357205739107f, + 0.85373856005937f /*max*/, 0.85357205739107f, + 0.85310209497017f, 0.85230470352147f, + 0.85119715249343f, 0.84978051984268f, + 0.84803157770763f, 0.84598184698206f, + 0.84362382812005f, 0.84095413924722f, + 0.83797173378865f, 0.83469373618402f, + 0.8311038457152f, 0.8272275347336f, + 0.82304198905409f, 0.81857760046468f, + 0.81381912706217f, 0.80876950044491f, + 0.80344857518505f, 0.797846641377f, + 0.79197358416424f, 0.7858353120392f, + 0.77942875190216f, 0.77277808813327f, + 0.76586748650939f, 0.75870807608242f, + 0.75131374561237f, 0.74368278636488f, + 0.73582117582769f, 0.72774489002994f, + 0.71944626349561f, 0.71094104263095f, + 0.70223887193539f, 0.69332823767032f, + 0.68423532934598f, 0.67496631901712f, + 0.66551398801627f, 0.65590163024671f, + 0.64612696959461f, 0.63619801077286f, + 0.62612426956055f, 0.61591099320291f, + 0.6055783538918f, 0.59511230862496f, + 0.58454032354679f, 0.57385241316923f, + 0.5630789140137f, 0.55220512585061f, + 0.54125534487322f, 0.53022408956855f, + 0.51912349702391f, 0.50798175000434f, + 0.49677082545707f, 0.48552530911099f, + 0.47424532146115f, 0.46293080852757f, + 0.45159965356824f, 0.44025537543665f, + 0.42891199207373f, 0.41756968968409f, + 0.40623176767625f, 0.39492117615675f, + 0.38363500139043f, 0.37237955463061f, + -0.36115899031355f, -0.3499914122931f, + -0.33887226938665f, -0.32781137272105f, + -0.31682789136456f, -0.30590985751916f, + -0.29507167170646f, -0.28432141891085f, + -0.27366340405625f, -0.26310532994603f, + -0.25264803095722f, -0.24230168845974f, + -0.23206908706791f, -0.22196526964149f, + -0.21197358538056f, -0.20212501768103f, + -0.19239667457267f, -0.18281725485142f, + -0.17338081721706f, -0.16409588556669f, + -0.15496070710605f, -0.1459766491187f, + -0.13715517611934f, -0.12850028503878f, + -0.120007798468f, -0.1116826931773f, + -0.10353295311463f, -0.09555333528914f, + -0.08775475365593f, -0.08013729344279f, + -0.07269433008129f, -0.06544098531359f, + -0.05837053268336f, -0.05148041767934f, + -0.04478068215856f, -0.03827765720822f, + -0.03195312745332f, -0.02582272888064f, + -0.01988341292573f, -0.01412888273558f, + -0.00857117491366f, -0.00320868968304f, + 0.00197656014503f, 0.00696368621617f, + 0.01176238327857f, 0.01637012582228f, + 0.02079970728622f, 0.02503075618909f, + 0.02908240060125f, 0.03295839306691f, + 0.03664181168133f, 0.04014582784127f, + 0.04347687821958f, 0.04663033051701f, + 0.04959786763445f, 0.05240938217366f, + 0.05504600343009f, 0.05751526919867f, + 0.0598166570809f, 0.06196027790387f, + 0.06394448059633f, 0.06576906686508f, + 0.06745250215166f, 0.06896640131951f, + 0.07035330735093f, 0.07158263647903f, + 0.07267746427299f, 0.0736406005762f, + 0.07446643947564f, 0.0751576255287f, + 0.07573057565061f, 0.07617483218536f, + 0.07650507183194f, 0.07672049241746f, + 0.07682300113923f, 0.07681739756964f, + 0.07670934904245f, 0.07649921704119f, + 0.07619924793396f, 0.07580083586584f, + 0.07531373362019f, 0.07474525581194f, + 0.07410036424342f, 0.07336202550803f, + 0.07256825833083f, 0.07170026731102f, + 0.07076287107266f, 0.06976302447127f, + 0.06870438283512f, 0.06760759851228f, + 0.06643675122104f, 0.0652247106438f, + 0.06397158980681f, 0.06268578081172f, + 0.06134551717207f, 0.05998374801761f, + 0.0585915683626f, 0.05716164501299f, + 0.05571736482138f, 0.05424527683589f, + 0.05276307465207f, 0.05125561555216f, + 0.04973857556014f, 0.04821657200672f, + 0.04668430272642f, 0.04514884056413f, + 0.04360975421304f, 0.04206490946367f, + 0.04053491705584f, 0.03900536794745f, + 0.03748128504252f, 0.03596975605542f, + 0.03446209487686f, 0.03297540810337f, + 0.03150176087389f, 0.03005026574279f, + 0.02860721736385f, 0.02718594296329f, + 0.02578758475467f, 0.02441609920285f, + 0.02306801692862f, 0.02174675502535f, + 0.02045317933555f, 0.01918724313698f, + 0.01794333813443f, 0.01673247129989f, + 0.01554055533423f, 0.01439046660792f, + -0.01327182200351f, -0.01218499959508f, + -0.01113155480321f, -0.01011502154986f, + -0.00913253296085f, -0.00817982333726f, + -0.00726158168517f, -0.00637922932685f, + -0.00553372111088f, -0.004722259624f, + -0.00394011240522f, -0.003193377839f, + -0.00248267236449f, -0.00180394725893f, + -0.00115681355227f, -0.00054642808664f, + 2.760451905E-005f, 0.0005832264248f, + 0.00109023290512f, 0.00157846825768f, + 0.0020274176185f, 0.00245085400321f, + 0.00284467578623f, 0.00320918858098f, + 0.00354012465507f, 0.00384564081246f, + 0.0041251642327f, 0.00438018617447f, + 0.00460395301471f, 0.004810946906f, + 0.00498396877629f, 0.00513822754514f, + 0.00527157587272f, 0.0053838975897f, + 0.0054753783077f, 0.005540436394f, + 0.0055917128663f, 0.00562661141932f, + 0.00563891995151f, 0.00564551969164f, + 0.00562206432097f, 0.00559380230045f, + 0.00554757145088f, 0.00548760401507f, + 0.00541967759307f, 0.00534716811982f, + 0.00524611661324f, 0.00514073539032f, + 0.00503930226013f, 0.00491376035745f, + 0.00479325608498f, 0.00466064606118f, + 0.00452098527825f, 0.00437307196781f, + 0.0042264269227f, 0.00408197531935f, + 0.00392074323703f, 0.00376039229104f, + 0.00360082681231f, 0.00344188741828f, + 0.00327396134847f, 0.00311254206525f, + 0.00294694477165f, 0.00278704643465f, + 0.00262017586902f, 0.00246256169126f, + 0.00230172547746f, 0.00214615835557f, + 0.00198411407369f, 0.00183482654224f, + 0.00168680832531f, 0.00154432198471f, + 0.00139024948272f, 0.00125778846475f, + 0.00112501551307f, 0.00098859883015f, + 0.00086084433262f, 0.00074580258865f, + 0.00062393761391f, 0.00051073884952f, + 0.0004026540216f, 0.00029495311041f, + 0.00020430170688f, 0.00010943831274f, + 1.349497418E-005f, -6.173344072E-005f, + -0.00014463809349f, -0.0002098337344f, + -0.00028969811748f, -0.00035011758756f, + -0.00040951214522f, -0.00046063254803f, + -0.00051455722108f, -0.00055645763906f, + -0.0005946118933f, -0.00063415949025f, + -0.00066504150893f, -0.00069179375372f, + -0.00072153919876f, -0.00073193571525f, + -0.00075300014201f, -0.00076307935757f, + -0.0007757977331f, -0.00078014496257f, + -0.000780366471f, -0.00077798694927f, + -0.00078343322877f, -0.00077248485949f, + -0.0007681371927f, -0.00074905980532f, + -0.00074409418541f, -0.00072550431222f, + -0.00071577364744f, -0.00069416146273f, + -0.00067776907764f, -0.00065403333621f, + -0.00063124935319f, -0.00061327473938f, + -0.00058709304852f, -0.00056778025613f, + -0.00054665656337f, -0.00052265642972f, + -0.00050407143497f, -0.00048937912498f, + -0.00048752279712f, -0.00049475180896f, + -0.00056176925738f, -0.00055252865047f + }; - protected final float[] v; //double ringbuffer - protected int v_index; //ringbuffer index + /** double ringbuffer */ + protected final float[] v; + /** ringbuffer index */ + protected int v_index; - public Filterbank(int channels) { - v = new float[2*channels*20]; - v_index = 0; - } + public Filterbank(int channels) { + v = new float[2 * channels * 20]; + v_index = 0; + } - public void reset() { - Arrays.fill(v, 0); - } + public void reset() { + Arrays.fill(v, 0); + } } \ No newline at end of file diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/FrameClass.java b/src/main/java/net/sourceforge/jaad/aac/sbr/FrameClass.java index 7e4c58d..a91bd68 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/FrameClass.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/FrameClass.java @@ -1,9 +1,10 @@ package net.sourceforge.jaad.aac.sbr; +import java.util.List; + import net.sourceforge.jaad.aac.syntax.BitStream; import net.sourceforge.jaad.aac.tools.Utils; -import java.util.List; /** * Created by IntelliJ IDEA. diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/HFAdjustment.java b/src/main/java/net/sourceforge/jaad/aac/sbr/HFAdjustment.java index 20652cb..9d4e07a 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/HFAdjustment.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/HFAdjustment.java @@ -52,18 +52,17 @@ private static int get_S_mapped(SBR sbr, Channel ch, int l, int current_band) { } else { int b, lb, ub; - /* in case of f_table_low we check if any of the HI_RES bands - * within this LO_RES band has bs_add_harmonic[l][k] turned on - * (note that borders in the LO_RES table are also present in - * the HI_RES table) - */ + // in case of f_table_low we check if any of the HI_RES bands + // within this LO_RES band has bs_add_harmonic[l][k] turned on + // (note that borders in the LO_RES table are also present in + // the HI_RES table) - /* find first HI_RES band in current LO_RES band */ + // find first HI_RES band in current LO_RES band lb = 2 * current_band - ((sbr.N_high & 1) != 0 ? 1 : 0); - /* find first HI_RES band in next LO_RES band */ + // find first HI_RES band in next LO_RES band ub = 2 * (current_band + 1) - ((sbr.N_high & 1) != 0 ? 1 : 0); - /* check all HI_RES bands in current LO_RES band for sinusoid */ + // check all HI_RES bands in current LO_RES band for sinusoid for (b = lb; b < ub; b++) { if ((l >= ch.l_A) || (ch.bs_add_harmonic_prev[b] != 0 && ch.bs_add_harmonic_flag_prev)) { @@ -162,13 +161,13 @@ private void hf_assembly(SBR sbr, float[][][] Xsbr, Channel ch) { System.arraycopy(this.G_lim_boost[l], 0, ch.G_temp_prev[n], 0, sbr.M); System.arraycopy(this.Q_M_lim_boost[l], 0, ch.Q_temp_prev[n], 0, sbr.M); } - /* reset ringbuffer index */ + // reset ringbuffer index ch.GQ_ringbuf_index = 4; assembly_reset = false; } for (int i = ch.t_E[l]; i < ch.t_E[l + 1]; i++) { - /* load new values into ringbuffer */ + // load new values into ringbuffer System.arraycopy(this.G_lim_boost[l], 0, ch.G_temp_prev[ch.GQ_ringbuf_index], 0, sbr.M); System.arraycopy(this.Q_M_lim_boost[l], 0, ch.Q_temp_prev[ch.GQ_ringbuf_index], 0, sbr.M); @@ -195,11 +194,11 @@ private void hf_assembly(SBR sbr, float[][][] Xsbr, Channel ch) { Q_filt = (this.S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt; - /* add noise to the output */ + // add noise to the output fIndexNoise = (fIndexNoise + 1) & 511; - /* the smoothed gain values are applied to Xsbr */ - /* V is defined, not calculated */ + // the smoothed gain values are applied to Xsbr + // V is defined, not calculated Xsbr[i + sbr.tHFAdj][m + sbr.kx][0] = G_filt * Xsbr[i + sbr.tHFAdj][m + sbr.kx][0] + (Q_filt * NOISE_TABLE[fIndexNoise][0]); // if (sbr.bs_extension_id == 3 && sbr.bs_extension_data == 42) @@ -219,7 +218,7 @@ private void hf_assembly(SBR sbr, float[][][] Xsbr, Channel ch) { fIndexSine = (fIndexSine + 1) & 3; - /* update the ringbuffer index used for filtering G and Q with h_smooth */ + // update the ringbuffer index used for filtering G and Q with h_smooth ch.GQ_ringbuf_index++; if (ch.GQ_ringbuf_index >= 5) ch.GQ_ringbuf_index = 0; @@ -267,7 +266,7 @@ private void calculate_gain(SBR sbr, Channel ch) { ml2 = sbr.f_table_lim[sbr.hdr.bs_limiter_bands][k + 1]; - /* calculate the accumulated E_orig and E_curr over the limiter band */ + // calculate the accumulated E_orig and E_curr over the limiter band for (int m = ml1; m < ml2; m++) { if ((m + sbr.kx) == sbr.f_table_res[ch.f[l]][current_res_band + 1]) { current_res_band++; @@ -276,11 +275,10 @@ private void calculate_gain(SBR sbr, Channel ch) { acc2 += ch.E_curr[m][l]; } + // calculate the maximum gain - /* calculate the maximum gain */ - /* ratio of the energy of the original signal and the energy - * of the HF generated signal - */ + // ratio of the energy of the original signal and the energy + // of the HF generated signal G_max = ((EPS + acc1) / (EPS + acc2)) * limGain[sbr.hdr.bs_limiter_gains]; G_max = Math.min(G_max, 1e10f); @@ -289,51 +287,45 @@ private void calculate_gain(SBR sbr, Channel ch) { float Q_div, Q_div2; int S_index_mapped; - - /* check if m is on a noise band border */ + // check if m is on a noise band border if ((m + sbr.kx) == sbr.f_table_noise[current_f_noise_band + 1]) { - /* step to next noise band */ + // step to next noise band current_f_noise_band++; } - - /* check if m is on a resolution band border */ + // check if m is on a resolution band border if ((m + sbr.kx) == sbr.f_table_res[ch.f[l]][current_res_band2 + 1]) { - /* step to next resolution band */ + // step to next resolution band current_res_band2++; - /* if we move to a new resolution band, we should check if we are - * going to add a sinusoid in this band - */ + // if we move to a new resolution band, we should check if we are + // going to add a sinusoid in this band S_mapped = get_S_mapped(sbr, ch, l, current_res_band2); } - - /* check if m is on a HI_RES band border */ + // check if m is on a HI_RES band border if ((m + sbr.kx) == sbr.f_table_res[FBT.HI_RES][current_hi_res_band + 1]) { - /* step to next HI_RES band */ + // step to next HI_RES band current_hi_res_band++; } - - /* find S_index_mapped - * S_index_mapped can only be 1 for the m in the middle of the - * current HI_RES band - */ + // find S_index_mapped + // S_index_mapped can only be 1 for the m in the middle of the + // current HI_RES band S_index_mapped = 0; if ((l >= ch.l_A) || (ch.bs_add_harmonic_prev[current_hi_res_band] != 0 && ch.bs_add_harmonic_flag_prev)) { - /* find the middle subband of the HI_RES frequency band */ + // find the middle subband of the HI_RES frequency band if ((m + sbr.kx) == (sbr.f_table_res[FBT.HI_RES][current_hi_res_band + 1] + sbr.f_table_res[FBT.HI_RES][current_hi_res_band]) >> 1) S_index_mapped = ch.bs_add_harmonic[current_hi_res_band]; } - /* Q_div: [0..1] (1/(1+Q_mapped)) */ + // Q_div: [0..1] (1/(1+Q_mapped)) Q_div = ch.Q_div[current_f_noise_band][current_t_noise_band]; - /* Q_div2: [0..1] (Q_mapped/(1+Q_mapped)) */ + // Q_div2: [0..1] (Q_mapped/(1+Q_mapped)) Q_div2 = ch.Q_div2[current_f_noise_band][current_t_noise_band]; @@ -352,24 +344,21 @@ private void calculate_gain(SBR sbr, Channel ch) { } else { S_M[m] = ch.E_orig[current_res_band2][l] * Q_div; - /* accumulate sinusoid part of the total energy */ + // accumulate sinusoid part of the total energy den += S_M[m]; } - - /* calculate gain */ - /* ratio of the energy of the original signal and the energy - * of the HF generated signal - */ + // calculate gain + // ratio of the energy of the original signal and the energy + // of the HF generated signal G = ch.E_orig[current_res_band2][l] / (1.0f + ch.E_curr[m][l]); if ((S_mapped == 0) && (delta == 1)) G *= Q_div; else if (S_mapped == 1) G *= Q_div2; - - /* limit the additional noise energy level */ - /* and apply the limiter */ + // limit the additional noise energy level + // and apply the limiter if (G_max > G) { Q_M_lim[m] = Q_M; G_lim[m] = G; @@ -378,19 +367,18 @@ else if (S_mapped == 1) G_lim[m] = G_max; } - - /* accumulate the total energy */ + // accumulate the total energy den += ch.E_curr[m][l] * G_lim[m]; if ((S_index_mapped == 0) && (l != ch.l_A)) den += Q_M_lim[m]; } - /* G_boost: [0..2.51188643] */ + // G_boost: [0..2.51188643] G_boost = (acc1 + EPS) / (den + EPS); G_boost = Math.min(G_boost, 2.51188643f /* 1.584893192 ^ 2 */); for (int m = ml1; m < ml2; m++) { - /* apply compensation to gain, noise floor sf's and sinusoid levels */ + // apply compensation to gain, noise floor sf's and sinusoid levels this.G_lim_boost[l][m] = (float) Math.sqrt(G_lim[m] * G_boost); this.Q_M_lim_boost[l][m] = (float) Math.sqrt(Q_M_lim[m] * G_boost); diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/HFGeneration.java b/src/main/java/net/sourceforge/jaad/aac/sbr/HFGeneration.java index 2d4c673..1a29e67 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/HFGeneration.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/HFGeneration.java @@ -27,16 +27,16 @@ public static void hf_generation(float[][][] Xlow, float[][][] Xhigh, Channel ch if (reset) patch_construction(ch.sbr); - /* calculate the prediction coefficients */ + // calculate the prediction coefficients - /* actual HF generation */ + // actual HF generation for (int i = 0; i < ch.sbr.noPatches; i++) { for (int x = 0; x < ch.sbr.patchNoSubbands[i]; x++) { float a0_r, a0_i, a1_r, a1_i; float bw, bw2; int q, p, k, g; - /* find the low and high band for patching */ + // find the low and high band for patching k = ch.sbr.kx + x; for (q = 0; q < i; q++) { k += ch.sbr.patchNoSubbands[q]; @@ -48,8 +48,8 @@ public static void hf_generation(float[][][] Xlow, float[][][] Xhigh, Channel ch bw = ch.bwArray[g]; bw2 = bw * bw; - /* do the patching */ - /* with or without filtering */ + // do the patching + // with or without filtering if (bw2 > 0) { float temp1_r, temp2_r, temp3_r; float temp1_i, temp2_i, temp3_i; @@ -132,16 +132,16 @@ private static void auto_correlation(SBR sbr, acorr_coef ac, float[][][] buffer, } // These are actual values in temporary variable at this point - // temp1_r = QMF_RE(buffer[len+offset-1-2][bd]; - // temp1_i = QMF_IM(buffer[len+offset-1-2][bd]; - // temp2_r = QMF_RE(buffer[len+offset-1-1][bd]; - // temp2_i = QMF_IM(buffer[len+offset-1-1][bd]; - // temp3_r = QMF_RE(buffer[len+offset-1][bd]); - // temp3_i = QMF_IM(buffer[len+offset-1][bd]); - // temp4_r = QMF_RE(buffer[offset-2][bd]); - // temp4_i = QMF_IM(buffer[offset-2][bd]); - // temp5_r = QMF_RE(buffer[offset-1][bd]); - // temp5_i = QMF_IM(buffer[offset-1][bd]); +// temp1_r = QMF_RE(buffer[len + offset - 1 - 2][bd]; +// temp1_i = QMF_IM(buffer[len + offset - 1 - 2][bd]; +// temp2_r = QMF_RE(buffer[len + offset - 1 - 1][bd]; +// temp2_i = QMF_IM(buffer[len + offset - 1 - 1][bd]; +// temp3_r = QMF_RE(buffer[len + offset - 1][bd]); +// temp3_i = QMF_IM(buffer[len + offset - 1][bd]); +// temp4_r = QMF_RE(buffer[offset - 2][bd]); +// temp4_i = QMF_IM(buffer[offset - 2][bd]); +// temp5_r = QMF_RE(buffer[offset - 1][bd]); +// temp5_i = QMF_IM(buffer[offset - 1][bd]); ac.r12[0] = r01r - (temp3_r * temp2_r + temp3_i * temp2_i) + (temp5_r * temp4_r + temp5_i * temp4_i); @@ -161,7 +161,7 @@ private static void auto_correlation(SBR sbr, acorr_coef ac, float[][][] buffer, ac.det = (ac.r11[0] * ac.r22[0]) - (rel * ((ac.r12[0] * ac.r12[0]) + (ac.r12[1] * ac.r12[1]))); } - /* calculate linear prediction coefficients using the covariance method */ + /** calculate linear prediction coefficients using the covariance method */ private static void calc_prediction_coef(SBR sbr, float[][][] Xlow, float[][] alpha_0, float[][] alpha_1, int k) { float tmp; @@ -196,38 +196,36 @@ private static void calc_prediction_coef(SBR sbr, float[][][] Xlow, } } - /* FIXED POINT: bwArray = COEF */ + /** FIXED POINT: bwArray = COEF */ private static float mapNewBw(int invf_mode, int invf_mode_prev) { switch (invf_mode) { - case 1: /* LOW */ + case 1: // LOW - if (invf_mode_prev == 0) /* NONE */ + if (invf_mode_prev == 0) // NONE return 0.6f; else return 0.75f; - case 2: /* MID */ + case 2: // MID return 0.9f; - case 3: /* HIGH */ + case 3: // HIGH return 0.98f; - default: /* NONE */ + default: // NONE - if (invf_mode_prev == 1) /* LOW */ + if (invf_mode_prev == 1) // LOW return 0.6f; else return 0.0f; } } - /* FIXED POINT: bwArray = COEF */ + /** FIXED POINT: bwArray = COEF */ private static void calc_chirp_factors(Channel ch) { - int i; - - for (i = 0; i < ch.sbr.N_Q; i++) { + for (int i = 0; i < ch.sbr.N_Q; i++) { ch.bwArray[i] = mapNewBw(ch.bs_invf_mode[i], ch.bs_invf_mode_prev[i]); if (ch.bwArray[i] < ch.bwArray_prev[i]) @@ -249,7 +247,7 @@ private static void calc_chirp_factors(Channel ch) { private static void patch_construction(SBR sbr) { int msb = sbr.k0; int usb = sbr.kx; - /* (uint8_t)(2.048e6/sbr.sample_rate + 0.5); */ + //(uint8_t)(2.048e6/sbr.sample_rate + 0.5); int goalSb = goalSbTab[sbr.sample_rate.getIndex()]; sbr.noPatches = 0; diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/Header.java b/src/main/java/net/sourceforge/jaad/aac/sbr/Header.java index 1102705..5e9c21d 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/Header.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/Header.java @@ -2,6 +2,7 @@ import net.sourceforge.jaad.aac.syntax.BitStream; + /** * Created by IntelliJ IDEA. * User: stueken @@ -9,6 +10,7 @@ * Time: 18:57 */ class Header { + boolean bs_amp_res = true; int bs_start_freq = 5; int bs_stop_freq; @@ -31,7 +33,7 @@ public void decode(BitStream ld) { this.bs_stop_freq = ld.readBits(4); this.bs_xover_band = ld.readBits(3); - ld.readBits(2); //reserved + ld.readBits(2); // reserved boolean bs_header_extra_1 = ld.readBool(); boolean bs_header_extra_2 = ld.readBool(); @@ -41,7 +43,7 @@ public void decode(BitStream ld) { this.bs_alter_scale = ld.readBool(); this.bs_noise_bands = ld.readBits(2); } else { - /* Default values */ + // Default values this.bs_freq_scale = 2; this.bs_alter_scale = true; this.bs_noise_bands = 2; @@ -53,7 +55,7 @@ public void decode(BitStream ld) { this.bs_interpol_freq = ld.readBool(); this.bs_smoothing_mode = ld.readBool(); } else { - /* Default values */ + // Default values this.bs_limiter_bands = 2; this.bs_limiter_gains = 2; this.bs_interpol_freq = true; diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseEnvelope.java b/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseEnvelope.java index 7b61318..955926b 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseEnvelope.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseEnvelope.java @@ -13,7 +13,7 @@ class NoiseEnvelope { 4.61169E+018f, 9.22337E+018f, 1.84467E+019f, 3.68935E+019f, 7.3787E+019f, 1.47574E+020f, 2.95148E+020f, 5.90296E+020f }; - /* table for Q_div2 values when no coupling */ + /** table for Q_div2 values when no coupling */ private static final float[] Q_div2_tab = { 0.984615f, 0.969697f, 0.941176f, 0.888889f, @@ -99,7 +99,7 @@ class NoiseEnvelope { {2.3836E-007f, 2.38186E-007f, 2.37491E-007f, 2.34751E-007f, 2.24394E-007f, 1.90735E-007f, 1.19209E-007f, 4.76837E-008f, 1.40246E-008f, 3.66798E-009f, 9.27699E-010f, 2.32603E-010f, 5.81935E-011f}, {1.1918E-007f, 1.19093E-007f, 1.18745E-007f, 1.17375E-007f, 1.12197E-007f, 9.53674E-008f, 5.96046E-008f, 2.38419E-008f, 7.01231E-009f, 1.83399E-009f, 4.63849E-010f, 1.16302E-010f, 2.90967E-011f} }; - /* table for Q_div values when no coupling */ + /** table for Q_div values when no coupling */ private static final float[] Q_div_tab = { 0.0153846f, 0.030303f, 0.0588235f, 0.111111f, @@ -187,16 +187,18 @@ class NoiseEnvelope { {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f} }; - /* calculates 1/(1+Q) */ - /* [0..1] */ + /** + * calculates 1/(1+Q) + * [0..1] + */ public static float calc_Q_div(SBR2 sbr, Channel ch, int m, int l) { if (sbr.bs_coupling) { - /* left channel */ + // left channel if ((sbr.ch0.Q[m][l] < 0 || sbr.ch0.Q[m][l] > 30) || (sbr.ch1.Q[m][l] < 0 || sbr.ch1.Q[m][l] > 24 /* 2*panOffset(1) */)) { return 0; } else { - /* the pan parameter is always even */ + // the pan parameter is always even if (ch == sbr.ch0) { return Q_div_tab_left[sbr.ch0.Q[m][l]][sbr.ch1.Q[m][l] >> 1]; } else { @@ -209,7 +211,7 @@ public static float calc_Q_div(SBR2 sbr, Channel ch, int m, int l) { } public static float calc_Q_div(Channel ch, int m, int l) { - /* no coupling */ + // no coupling if (ch.Q[m][l] < 0 || ch.Q[m][l] > 30) { return 0; } else { @@ -217,15 +219,17 @@ public static float calc_Q_div(Channel ch, int m, int l) { } } - /* calculates Q/(1+Q) */ - /* [0..1] */ + /** + * calculates Q/(1+Q) + * [0..1] + */ public static float calc_Q_div2(SBR2 sbr, Channel ch, int m, int l) { if (sbr.bs_coupling) { if ((sbr.ch0.Q[m][l] < 0 || sbr.ch0.Q[m][l] > 30) || (sbr.ch1.Q[m][l] < 0 || sbr.ch1.Q[m][l] > 24 /* 2*panOffset(1) */)) { return 0; } else { - /* the pan parameter is always even */ + // the pan parameter is always even if (ch == sbr.ch0) { return Q_div2_tab_left[sbr.ch0.Q[m][l]][sbr.ch1.Q[m][l] >> 1]; } else { @@ -238,7 +242,7 @@ public static float calc_Q_div2(SBR2 sbr, Channel ch, int m, int l) { } public static float calc_Q_div2(Channel ch, int m, int l) { - /* no coupling */ + // no coupling if (ch.Q[m][l] < 0 || ch.Q[m][l] > 30) { return 0; } else { @@ -251,10 +255,9 @@ public static void dequantChannel(SBR sbr, Channel ch) { for (int l = 0; l < ch.L_E; l++) { for (int k = 0; k < sbr.n[ch.f[l]]; k++) { - /* +6 for the *64 and -10 for the /32 in the synthesis QMF (fixed) - * since this is an energy value: (x/32)^2 = (x^2)/1024 - */ - /* exp = (ch.E[k][l] >> amp) + 6; */ + // +6 for the *64 and -10 for the /32 in the synthesis QMF (fixed) + // since this is an energy value: (x/32)^2 = (x^2)/1024 + //exp = (ch.E[k][l] >> amp) + 6; int exp = (ch.E[k][l] >> amp); if ((exp < 0) || (exp >= 64)) { @@ -262,7 +265,7 @@ public static void dequantChannel(SBR sbr, Channel ch) { } else { ch.E_orig[k][l] = E_deq_tab[exp]; - /* save half the table size at the cost of 1 multiply */ + // save half the table size at the cost of 1 multiply if (amp != 0 && (ch.E[k][l] & 1) != 0) { ch.E_orig[k][l] = (ch.E_orig[k][l] * 1.414213562f); } @@ -301,14 +304,13 @@ public static void unmap(SBR2 sbr) { for (int l = 0; l < sbr.ch0.L_E; l++) { for (int k = 0; k < sbr.n[sbr.ch0.f[l]]; k++) { - /* +6: * 64 ; +1: * 2 ; */ + // +6: * 64 ; +1: * 2 ; int exp0 = (sbr.ch0.E[k][l] >> amp0) + 1; - /* UN_MAP removed: (x / 4096) same as (x >> 12) */ - /* E[1] is always even so no need for compensating the divide by 2 with - * an extra multiplication - */ - /* exp1 = (sbr.ch1.E[k][l] >> amp1) - 12; */ + // UN_MAP removed: (x / 4096) same as (x >> 12) + // E[1] is always even so no need for compensating the divide by 2 with + // an extra multiplication + //exp1 = (sbr.ch1.E[k][l] >> amp1) - 12; int exp1 = (sbr.ch1.E[k][l] >> amp1); if ((exp0 < 0) || (exp0 >= 64) @@ -318,10 +320,10 @@ public static void unmap(SBR2 sbr) { } else { float tmp = E_deq_tab[exp0]; if (amp0 != 0 && (sbr.ch0.E[k][l] & 1) != 0) { - tmp *= 1.414213562; + tmp = (float) (tmp * 1.414213562); } - /* panning */ + // panning sbr.ch0.E_orig[k][l] = (tmp * E_pan_tab[exp1]); sbr.ch1.E_orig[k][l] = (tmp * E_pan_tab[24 - exp1]); } diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseTable.java b/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseTable.java index 8baac0f..c773208 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseTable.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/NoiseTable.java @@ -2,7 +2,7 @@ interface NoiseTable { - /* Table 1.A.13 Noise table V */ + /** Table 1.A.13 Noise table V */ float[][] NOISE_TABLE = { {-0.99948155879974f, -0.59483414888382f}, {0.97113454341888f, -0.67528516054153f}, diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/PS.java b/src/main/java/net/sourceforge/jaad/aac/sbr/PS.java index 1136b89..4b6d94c 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/PS.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/PS.java @@ -2,6 +2,7 @@ import net.sourceforge.jaad.aac.syntax.BitStream; + /** * Created by IntelliJ IDEA. * User: stueken @@ -14,6 +15,6 @@ public interface PS { void decode(BitStream ld); - /* main Parametric Stereo decoding function */ + /** main Parametric Stereo decoding function */ void process(float[][][] X_left, float[][][] X_right); } diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/SBR.java b/src/main/java/net/sourceforge/jaad/aac/sbr/SBR.java index b4218e2..01d4712 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/SBR.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/SBR.java @@ -8,9 +8,9 @@ abstract public class SBR { - static final int MAX_NTSR = 32; //max number_time_slots * rate, ok for DRM and not DRM mode - static final int MAX_M = 49; //maximum value for M - public static final int MAX_L_E = 5; //maximum value for L_E + static final int MAX_NTSR = 32; // max number_time_slots * rate, ok for DRM and not DRM mode + static final int MAX_M = 49; // maximum value for M + public static final int MAX_L_E = 5; // maximum value for L_E static final int EXT_SBR_DATA = 13; static final int EXT_SBR_DATA_CRC = 14; @@ -109,12 +109,11 @@ public SBR(DecoderConfig config) { this.bsco_prev = 0; this.M_prev = 0; - if(config.isSmallFrameUsed()) { - this.numTimeSlotsRate = RATE*NO_TIME_SLOTS_960; + if (config.isSmallFrameUsed()) { + this.numTimeSlotsRate = RATE * NO_TIME_SLOTS_960; this.numTimeSlots = NO_TIME_SLOTS_960; - } - else { - this.numTimeSlotsRate = RATE*NO_TIME_SLOTS; + } else { + this.numTimeSlotsRate = RATE * NO_TIME_SLOTS; this.numTimeSlots = NO_TIME_SLOTS; } } @@ -122,18 +121,18 @@ public SBR(DecoderConfig config) { int calc_sbr_tables(Header hdr) { int result = 0; - /* calculate the Master Frequency Table */ + // calculate the Master Frequency Table this.k0 = FBT.qmf_start_channel(hdr.bs_start_freq, this.bs_samplerate_mode, this.sample_rate); int k2 = FBT.qmf_stop_channel(hdr.bs_stop_freq, this.sample_rate, this.k0); - /* check k0 and k2 */ + // check k0 and k2 if (this.sample_rate.getFrequency() >= 48000) { if ((k2 - this.k0) > 32) result += 1; } else if (this.sample_rate.getFrequency() <= 32000) { if ((k2 - this.k0) > 48) result += 1; - } else { /* (sbr.sample_rate == 44100) */ + } else { // (sbr.sample_rate == 44100) if ((k2 - this.k0) > 45) result += 1; @@ -151,7 +150,7 @@ int calc_sbr_tables(Header hdr) { return result; } - /* table 2 */ + /** table 2 */ public void decode(BitStream ld, boolean crc) { if (crc) { @@ -164,7 +163,7 @@ public void decode(BitStream ld, boolean crc) { if (reset) { int rt = calc_sbr_tables(this.hdr); - /* if an error occurred with the new header values revert to the old ones */ + // if an error occurred with the new header values revert to the old ones if (rt > 0) { calc_sbr_tables(swapHeaders()); } @@ -239,7 +238,7 @@ protected void sbr_extension(BitStream ld, int bs_extension_id) { } - /* table 12 */ + /** table 12 */ protected void sinusoidal_coding(BitStream ld, Channel ch) { for (int n = 0; n < this.N_high; n++) { @@ -249,14 +248,14 @@ protected void sinusoidal_coding(BitStream ld, Channel ch) { protected void sbr_save_prev_data(Channel ch) { - /* save data for next frame */ + // save data for next frame this.kx_prev = this.kx; this.M_prev = this.M; this.bsco_prev = this.bsco; ch.L_E_prev = ch.L_E; - /* sbr.L_E[ch] can become 0 on files with bit errors */ + // sbr.L_E[ch] can become 0 on files with bit errors if (ch.L_E <= 0) throw new AACException("L_E<0"); diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/SBR1.java b/src/main/java/net/sourceforge/jaad/aac/sbr/SBR1.java index f4903a5..893442f 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/SBR1.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/SBR1.java @@ -1,9 +1,10 @@ package net.sourceforge.jaad.aac.sbr; +import java.util.Arrays; + import net.sourceforge.jaad.aac.DecoderConfig; import net.sourceforge.jaad.aac.syntax.BitStream; -import java.util.Arrays; /** * Created by IntelliJ IDEA. @@ -13,14 +14,14 @@ */ public class SBR1 extends SBR { - static final int EXTENSION_ID_PS = 2; + static final int EXTENSION_ID_PS = 2; final Channel ch0; - final SynthesisFilterbank qmfs0; - SynthesisFilterbank qmfs1; + final SynthesisFilterbank qmfs0; + SynthesisFilterbank qmfs1; - PS ps; + PS ps; public SBR1(DecoderConfig config) { super(config); @@ -30,111 +31,114 @@ public SBR1(DecoderConfig config) { } - /* table 5 */ - protected int sbr_data(BitStream ld) { - int result; + /** table 5 */ + @Override + protected int sbr_data(BitStream ld) { + int result; - if(ld.readBool()) { - ld.readBits(4); //reserved - } + if (ld.readBool()) { + ld.readBits(4); // reserved + } - if((result = ch0.sbr_grid(ld))>0) - return result; + if ((result = ch0.sbr_grid(ld)) > 0) + return result; - ch0.sbr_dtdf(ld); - ch0.invf_mode(ld); - ch0.sbr_envelope(ld,false); - ch0.sbr_noise(ld,false); + ch0.sbr_dtdf(ld); + ch0.invf_mode(ld); + ch0.sbr_envelope(ld, false); + ch0.sbr_noise(ld, false); - NoiseEnvelope.dequantChannel(this, ch0); + NoiseEnvelope.dequantChannel(this, ch0); - Arrays.fill(ch0.bs_add_harmonic, 0, 64, 0); + Arrays.fill(ch0.bs_add_harmonic, 0, 64, 0); - ch0.bs_add_harmonic_flag = ld.readBool(); - if(ch0.bs_add_harmonic_flag) - sinusoidal_coding(ld, ch0); + ch0.bs_add_harmonic_flag = ld.readBool(); + if (ch0.bs_add_harmonic_flag) + sinusoidal_coding(ld, ch0); - readExtendedData(ld); + readExtendedData(ld); - return 0; - } + return 0; + } - protected void sbr_extension(BitStream ld, int bs_extension_id) { - if(bs_extension_id==EXTENSION_ID_PS && config.isPSEnabled()) { - if(ps==null) { - this.ps = config.openPS(this); - this.qmfs1 = openFilterbank(); - } + @Override + protected void sbr_extension(BitStream ld, int bs_extension_id) { + if (bs_extension_id == EXTENSION_ID_PS && config.isPSEnabled()) { + if (ps == null) { + this.ps = config.openPS(this); + this.qmfs1 = openFilterbank(); + } - ps.decode(ld); + ps.decode(ld); - } else - super.sbr_extension(ld, bs_extension_id); - } + } else + super.sbr_extension(ld, bs_extension_id); + } - public void process(float[] left_chan, float[] right_chan) { - if(isPSUsed()) { - processPS(left_chan, right_chan); - } else { - process(left_chan); - System.arraycopy(left_chan, 0, right_chan, 0, right_chan.length); - } - } + @Override + public void process(float[] left_chan, float[] right_chan) { + if (isPSUsed()) { + processPS(left_chan, right_chan); + } else { + process(left_chan); + System.arraycopy(left_chan, 0, right_chan, 0, right_chan.length); + } + } - private void process(float[] channel) { - float[][][] X = new float[MAX_NTSR][64][2]; + private void process(float[] channel) { + float[][][] X = new float[MAX_NTSR][64][2]; - ch0.process_channel(channel, X, this.reset); + ch0.process_channel(channel, X, this.reset); - /* subband synthesis */ - qmfs0.synthesis(numTimeSlotsRate, X, channel); + // subband synthesis + qmfs0.synthesis(numTimeSlotsRate, X, channel); - if(this.hdr!=null) { - sbr_save_prev_data(ch0); - } + if (this.hdr != null) { + sbr_save_prev_data(ch0); + } - sbr_save_matrix(ch0); + sbr_save_matrix(ch0); - this.frame++; - } + this.frame++; + } - private int processPS(float[] left_channel, float[] right_channel) { - int ret = 0; - float[][][] X_left = new float[MAX_NTSR+6][64][2]; - float[][][] X_right = new float[MAX_NTSR+6][64][2]; + private int processPS(float[] left_channel, float[] right_channel) { + int ret = 0; + float[][][] X_left = new float[MAX_NTSR + 6][64][2]; + float[][][] X_right = new float[MAX_NTSR + 6][64][2]; - ch0.process_channel(left_channel, X_left, this.reset); + ch0.process_channel(left_channel, X_left, this.reset); - /* copy some extra data for PS */ - for(int l = this.numTimeSlotsRate; l 0) { - /* restore first channel data as well */ + // restore first channel data as well ch0.bs_frame_class = saved_frame_class; ch0.L_E = saved_L_E; ch0.L_Q = saved_L_Q; @@ -134,15 +135,16 @@ protected int sbr_data(BitStream ld) { return 0; } + @Override public void process(float[] left_chan, float[] right_chan) { float[][][] X = new float[MAX_NTSR][64][2]; ch0.process_channel(left_chan, X, this.reset); - /* subband synthesis */ + // subband synthesis qmfs0.synthesis(numTimeSlotsRate, X, left_chan); ch1.process_channel(right_chan, X, false); - /* subband synthesis */ + // subband synthesis qmfs1.synthesis(numTimeSlotsRate, X, right_chan); if (this.hdr != null) { diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank.java b/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank.java index 07a8629..84a9b1c 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank.java @@ -1,7 +1,5 @@ package net.sourceforge.jaad.aac.sbr; -import java.util.Arrays; - abstract class SynthesisFilterbank extends Filterbank { diff --git a/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank32.java b/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank32.java index 1959ddc..d2187ba 100644 --- a/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank32.java +++ b/src/main/java/net/sourceforge/jaad/aac/sbr/SynthesisFilterbank32.java @@ -2,941 +2,942 @@ class SynthesisFilterbank32 extends SynthesisFilterbank { - private static final float[][] qmf32_pre_twiddle = { - {0.999924701839145f, -0.012271538285720f}, - {0.999322384588350f, -0.036807222941359f}, - {0.998118112900149f, -0.061320736302209f}, - {0.996312612182778f, -0.085797312344440f}, - {0.993906970002356f, -0.110222207293883f}, - {0.990902635427780f, -0.134580708507126f}, - {0.987301418157858f, -0.158858143333861f}, - {0.983105487431216f, -0.183039887955141f}, - {0.978317370719628f, -0.207111376192219f}, - {0.972939952205560f, -0.231058108280671f}, - {0.966976471044852f, -0.254865659604515f}, - {0.960430519415566f, -0.278519689385053f}, - {0.953306040354194f, -0.302005949319228f}, - {0.945607325380521f, -0.325310292162263f}, - {0.937339011912575f, -0.348418680249435f}, - {0.928506080473216f, -0.371317193951838f}, - {0.919113851690058f, -0.393992040061048f}, - {0.909167983090522f, -0.416429560097637f}, - {0.898674465693954f, -0.438616238538528f}, - {0.887639620402854f, -0.460538710958240f}, - {0.876070094195407f, -0.482183772079123f}, - {0.863972856121587f, -0.503538383725718f}, - {0.851355193105265f, -0.524589682678469f}, - {0.838224705554838f, -0.545324988422046f}, - {0.824589302785025f, -0.565731810783613f}, - {0.810457198252595f, -0.585797857456439f}, - {0.795836904608884f, -0.605511041404326f}, - {0.780737228572094f, -0.624859488142386f}, - {0.765167265622459f, -0.643831542889791f}, - {0.749136394523459f, -0.662415777590172f}, - {0.732654271672413f, -0.680600997795453f}, - {0.715730825283819f, -0.698376249408973f} - }; + private static final float[][] qmf32_pre_twiddle = { + {0.999924701839145f, -0.012271538285720f}, + {0.999322384588350f, -0.036807222941359f}, + {0.998118112900149f, -0.061320736302209f}, + {0.996312612182778f, -0.085797312344440f}, + {0.993906970002356f, -0.110222207293883f}, + {0.990902635427780f, -0.134580708507126f}, + {0.987301418157858f, -0.158858143333861f}, + {0.983105487431216f, -0.183039887955141f}, + {0.978317370719628f, -0.207111376192219f}, + {0.972939952205560f, -0.231058108280671f}, + {0.966976471044852f, -0.254865659604515f}, + {0.960430519415566f, -0.278519689385053f}, + {0.953306040354194f, -0.302005949319228f}, + {0.945607325380521f, -0.325310292162263f}, + {0.937339011912575f, -0.348418680249435f}, + {0.928506080473216f, -0.371317193951838f}, + {0.919113851690058f, -0.393992040061048f}, + {0.909167983090522f, -0.416429560097637f}, + {0.898674465693954f, -0.438616238538528f}, + {0.887639620402854f, -0.460538710958240f}, + {0.876070094195407f, -0.482183772079123f}, + {0.863972856121587f, -0.503538383725718f}, + {0.851355193105265f, -0.524589682678469f}, + {0.838224705554838f, -0.545324988422046f}, + {0.824589302785025f, -0.565731810783613f}, + {0.810457198252595f, -0.585797857456439f}, + {0.795836904608884f, -0.605511041404326f}, + {0.780737228572094f, -0.624859488142386f}, + {0.765167265622459f, -0.643831542889791f}, + {0.749136394523459f, -0.662415777590172f}, + {0.732654271672413f, -0.680600997795453f}, + {0.715730825283819f, -0.698376249408973f} + }; - SynthesisFilterbank32() { - super(32); - } + SynthesisFilterbank32() { + super(32); + } - void synthesis(int numTimeSlotsRate, float[][][] X, float[] output) { - float[] x1 = new float[32], x2 = new float[32]; - float scale = 1.f/64.f; - int out = 0; + @Override + void synthesis(int numTimeSlotsRate, float[][][] X, float[] output) { + float[] x1 = new float[32], x2 = new float[32]; + float scale = 1.f / 64.f; + int out = 0; - /* qmf subsample l */ - for(int l = 0; l= n) { ret = (cache >> (bitsCached - n)) & maskBits(n); } else { - //old cache + // old cache int c = cache & maskBits(bitsCached); n -= bitsCached; - //read next & combine + // read next & combine ret = ((readCache(true) >> WORD_BITS - n) & maskBits(n)) | (c << n); } return ret; @@ -223,6 +230,7 @@ public int peekBit() { return ret; } + @Override public void skipBits(int n) { LOGGER.log(Level.FINER, "@%d skipBits: %d", n); @@ -248,6 +256,7 @@ public void skipBits(int n) { } } + @Override public void skipBit() { LOGGER.log(Level.FINER, "@%d skipBit: %d", 1); diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/CCE.java b/src/main/java/net/sourceforge/jaad/aac/syntax/CCE.java index a605c8d..b5b8d71 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/CCE.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/CCE.java @@ -20,11 +20,11 @@ protected Tag(int id) { @Override public int getId() { - return super.getId()%16; + return super.getId() % 16; } public boolean isIsIndSW() { - return id>=16; + return id >= 16; } @Override @@ -98,6 +98,7 @@ int getCHSelect(int index) { return chSelect[index]; } + @Override public void decode(BitStream in) throws AACException { couplingPoint = 2 * in.readBit(); coupledCount = in.readBits(3); @@ -168,7 +169,7 @@ void applyIndependentCoupling(int index, float[] data) { double g = gain[index][0]; float[] iqData = ics.getInvQuantData(); for (int i = 0; i < data.length; i++) { - data[i] += g * iqData[i]; + data[i] = (float) (data[i] + g * iqData[i]); } } diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/CPE.java b/src/main/java/net/sourceforge/jaad/aac/syntax/CPE.java index 168e939..7450757 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/CPE.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/CPE.java @@ -18,11 +18,11 @@ /** * channel_pair_element: abbreviation CPE. - * + *

* Syntactic element of the bitstream payload containing data for a pair of channels. * A channel_pair_element consists of two individual_channel_streams and additional * joint channel coding information. The two channels may share common side information. - * + *

* The channel_pair_element has the same restrictions as the single channel element * as far as element_instance_tag, and number of occurrences. */ @@ -70,18 +70,22 @@ public CPE(DecoderConfig config, ChannelTag tag) { icsR = new ICStream(config); } + @Override public boolean isChannelPair() { return true; } + @Override public boolean isStereo() { return true; } + @Override protected SBR openSBR() { return new SBR2(config); } + @Override public void decode(BitStream in) { super.decode(in); @@ -89,31 +93,29 @@ public void decode(BitStream in) { ICSInfo infoL = icsL.getInfo(); ICSInfo infoR = icsR.getInfo(); - LOGGER.log(Level.FINE, ()->String.format("CPE %s", commonWindow? "common":"")); + LOGGER.log(Level.FINER, () -> String.format("CPE %s", commonWindow ? "common" : "")); if (commonWindow) { infoL.decode(in, commonWindow); infoR.setCommonData(in, infoL); msMask = MSMask.forInt(in.readBits(2)); - if(msMask.equals(MSMask.TYPE_USED)) { + if (msMask.equals(MSMask.TYPE_USED)) { int maxSFB = infoL.getMaxSFB(); int windowGroupCount = infoL.getWindowGroupCount(); - for(int idx = 0; idx cces, Consumer target) { float[] dataL = getDataL(); @@ -175,7 +178,7 @@ public void process(FilterBank filterBank, List cces, Consumer tar icsL.processTNS(); icsR.processTNS(); - //dependent coupling + // dependent coupling processDependentCoupling(cces, CCE.AFTER_TNS, iqDataL, iqDataR); // filterbank diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/ChannelElement.java b/src/main/java/net/sourceforge/jaad/aac/syntax/ChannelElement.java index 86f2e72..acf1bcf 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/ChannelElement.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/ChannelElement.java @@ -1,11 +1,12 @@ package net.sourceforge.jaad.aac.syntax; +import java.util.List; +import java.util.function.Consumer; + import net.sourceforge.jaad.aac.DecoderConfig; import net.sourceforge.jaad.aac.filterbank.FilterBank; import net.sourceforge.jaad.aac.sbr.SBR; -import java.util.List; -import java.util.function.Consumer; /** * Created by IntelliJ IDEA. @@ -15,143 +16,145 @@ */ public abstract class ChannelElement implements Element { - abstract static class ChannelTag extends InstanceTag { + abstract static class ChannelTag extends InstanceTag { - protected ChannelTag(int id) { - super(id); - } + protected ChannelTag(int id) { + super(id); + } - abstract public boolean isChannelPair(); + abstract public boolean isChannelPair(); - @Override - abstract public ChannelElement newElement(DecoderConfig config); - } + @Override + abstract public ChannelElement newElement(DecoderConfig config); + } - protected final DecoderConfig config; + protected final DecoderConfig config; - protected final ChannelTag tag; + protected final ChannelTag tag; - protected ChannelElement(DecoderConfig config, ChannelTag tag) { - this.config = config; - this.tag = tag; - } + protected ChannelElement(DecoderConfig config, ChannelTag tag) { + this.config = config; + this.tag = tag; + } - public ChannelTag getElementInstanceTag() { - return tag; - } + @Override + public ChannelTag getElementInstanceTag() { + return tag; + } - /** - * @return if this element represents a channel pair. - */ - abstract public boolean isChannelPair(); + /** + * @return if this element represents a channel pair. + */ + abstract public boolean isChannelPair(); - /** - * A single channel may produce stereo using parametric stereo. - * @return if this stereo. - */ - abstract public boolean isStereo(); + /** + * A single channel may produce stereo using parametric stereo. + * + * @return if this stereo. + */ + abstract public boolean isStereo(); - protected SBR sbr; + protected SBR sbr; - public void decode(BitStream in) { - if(sbr!=null) - sbr.invalidate(); - } + @Override + public void decode(BitStream in) { + if (sbr != null) + sbr.invalidate(); + } - abstract protected SBR openSBR(); + abstract protected SBR openSBR(); - void decodeSBR(BitStream in, boolean crc) { + void decodeSBR(BitStream in, boolean crc) { - if(!config.isSBREnabled()) { - return; - } + if (!config.isSBREnabled()) { + return; + } - if(sbr==null) - sbr = openSBR(); + if (sbr == null) + sbr = openSBR(); - if(sbr!=null) - sbr.decode(in, crc); - } + if (sbr != null) + sbr.decode(in, crc); + } - boolean isSBRPresent() { - return sbr!=null && sbr.isValid(); - } + boolean isSBRPresent() { + return sbr != null && sbr.isValid(); + } - SBR getSBR() { - return sbr; - } + SBR getSBR() { + return sbr; + } private float[] dataL, dataR; private float[] newData() { - int len = config.getSampleLength(); - return new float[len]; - } + int len = config.getSampleLength(); + return new float[len]; + } public float[] getDataL() { - if(dataL==null) - dataL = newData(); - return dataL; - } - - public float[] getDataR() { - if(dataR==null) - dataR = newData(); - return dataR; + if (dataL == null) + dataL = newData(); + return dataL; } - abstract public void process(FilterBank filterBank, List cces, Consumer target); - - void processDependentCoupling(List cces, int couplingPoint, float[] dataL, float[] dataR) { - - int elementID = getElementInstanceTag().getId(); - - for (CCE cce : cces) { - int index = 0; - if(cce!=null&&cce.getCouplingPoint()==couplingPoint) { - for(int c = 0; c<=cce.getCoupledCount(); c++) { - int chSelect = cce.getCHSelect(c); - if(cce.isChannelPair(c)==isChannelPair()&&cce.getIDSelect(c)==elementID) { - if(chSelect!=1) { - cce.applyDependentCoupling(index, dataL); - if(chSelect!=0) - index++; - } - if(chSelect!=2) { - cce.applyDependentCoupling(index, dataR); - index++; - } - } - else - index += 1+((chSelect==3) ? 1 : 0); - } - } - } - } - - void processIndependentCoupling(List cces, float[] dataL, float[] dataR) { - - int elementID = getElementInstanceTag().getId(); - - for (CCE cce : cces) { - int index = 0; - if (cce != null && cce.getCouplingPoint() == CCE.AFTER_IMDCT) { - for (int c = 0; c <= cce.getCoupledCount(); c++) { - int chSelect = cce.getCHSelect(c); - if (cce.isChannelPair(c) == isChannelPair() && cce.getIDSelect(c) == elementID) { - if (chSelect != 1) { - cce.applyIndependentCoupling(index, dataL); - if (chSelect != 0) - index++; - } - if (chSelect != 2) { - cce.applyIndependentCoupling(index, dataR); - index++; - } - } else - index += 1 + ((chSelect == 3) ? 1 : 0); - } - } - } - } + public float[] getDataR() { + if (dataR == null) + dataR = newData(); + return dataR; + } + + abstract public void process(FilterBank filterBank, List cces, Consumer target); + + void processDependentCoupling(List cces, int couplingPoint, float[] dataL, float[] dataR) { + + int elementID = getElementInstanceTag().getId(); + + for (CCE cce : cces) { + int index = 0; + if (cce != null && cce.getCouplingPoint() == couplingPoint) { + for (int c = 0; c <= cce.getCoupledCount(); c++) { + int chSelect = cce.getCHSelect(c); + if (cce.isChannelPair(c) == isChannelPair() && cce.getIDSelect(c) == elementID) { + if (chSelect != 1) { + cce.applyDependentCoupling(index, dataL); + if (chSelect != 0) + index++; + } + if (chSelect != 2) { + cce.applyDependentCoupling(index, dataR); + index++; + } + } else + index += 1 + ((chSelect == 3) ? 1 : 0); + } + } + } + } + + void processIndependentCoupling(List cces, float[] dataL, float[] dataR) { + + int elementID = getElementInstanceTag().getId(); + + for (CCE cce : cces) { + int index = 0; + if (cce != null && cce.getCouplingPoint() == CCE.AFTER_IMDCT) { + for (int c = 0; c <= cce.getCoupledCount(); c++) { + int chSelect = cce.getCHSelect(c); + if (cce.isChannelPair(c) == isChannelPair() && cce.getIDSelect(c) == elementID) { + if (chSelect != 1) { + cce.applyIndependentCoupling(index, dataL); + if (chSelect != 0) + index++; + } + if (chSelect != 2) { + cce.applyIndependentCoupling(index, dataR); + index++; + } + } else + index += 1 + ((chSelect == 3) ? 1 : 0); + } + } + } + } } diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/DSE.java b/src/main/java/net/sourceforge/jaad/aac/syntax/DSE.java index 0989116..f5b3cea 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/DSE.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/DSE.java @@ -7,7 +7,7 @@ /** * data_stream_element Abbreviation DSE. - * + *

* Syntactic element that contains data. * Again, there are 16 element_instance_tags. * There is, however, no restriction on the number @@ -52,6 +52,7 @@ public DSE(DecoderConfig config, Tag tag) { this.tag = tag; } + @Override public void decode(BitStream in) { boolean byteAlign = in.readBool(); int count = in.readBits(8); diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/ICSInfo.java b/src/main/java/net/sourceforge/jaad/aac/syntax/ICSInfo.java index 6957dd0..dc7289c 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/ICSInfo.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/ICSInfo.java @@ -15,7 +15,7 @@ public class ICSInfo implements ScaleFactorBands { static final Logger LOGGER = Logger.getLogger(ICSInfo.class.getName()); - //maximum numbers + // maximum numbers public static final int MAX_WINDOW_COUNT = 8; public static final int MAX_WINDOW_GROUP_COUNT = MAX_WINDOW_COUNT; @@ -60,11 +60,11 @@ public static WindowSequence forInt(int i) throws AACException { private WindowSequence windowSequence; private int[] windowShape; private int maxSFB; - //prediction + // prediction private boolean predictionDataPresent; private ICPrediction icPredict; LTPrediction ltPredict; - //windows/sfbs + // windows/sfbs private int windowCount; private int windowGroupCount; private int[] windowGroupLength; @@ -83,9 +83,9 @@ public ICSInfo(DecoderConfig config) { this.ltPredict = new LTPrediction(frameLength); } - /* ========== decoding ========== */ + /** decoding */ public void decode(BitStream in, boolean commonWindow) throws AACException { - in.skipBit(); //reserved + in.skipBit(); // reserved windowSequence = WindowSequence.forInt(in.readBits(2)); windowShape[PREVIOUS] = windowShape[CURRENT]; windowShape[CURRENT] = in.readBit(); @@ -137,7 +137,7 @@ private void readPredictionData(BitStream in, boolean commonWindow) throws AACEx } } - /* =========== gets ============ */ + // =========== gets ============ public int getMaxSFB() { return maxSFB; } diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/ICStream.java b/src/main/java/net/sourceforge/jaad/aac/syntax/ICStream.java index b93d91a..91c9d7c 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/ICStream.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/ICStream.java @@ -15,7 +15,7 @@ import net.sourceforge.jaad.aac.tools.TNS; -//TODO: apply pulse data +// TODO: apply pulse data public class ICStream implements HCB, ScaleFactorTable, IQTable { static final Logger LOGGER = Logger.getLogger(ICStream.class.getName()); @@ -57,7 +57,7 @@ public ICStream(DecoderConfig config) { this.overlap = new float[frameLength]; } - /* ========= decoding ========== */ + /** decoding */ public void decode(BitStream in, boolean commonWindow, DecoderConfig conf) throws AACException { if (conf.isScalefactorResilienceUsed() && rvlc == null) rvlc = new RVLC(); boolean er = conf.getProfile().isErrorResilientProfile(); @@ -68,7 +68,7 @@ public void decode(BitStream in, boolean commonWindow, DecoderConfig conf) throw decodeSectionData(in, conf.isSectionDataResilienceUsed()); - //if(conf.isScalefactorResilienceUsed()) rvlc.decode(in, this, scaleFactors); + // if(conf.isScalefactorResilienceUsed()) rvlc.decode(in, this, scaleFactors); /*else*/ decodeScaleFactors(in); @@ -92,14 +92,14 @@ public void decode(BitStream in, boolean commonWindow, DecoderConfig conf) throw gainControl.decode(in, info.getWindowSequence()); } - //RVLC spectral data - //if(conf.isScalefactorResilienceUsed()) rvlc.decodeScalefactors(this, in, scaleFactors); + // RVLC spectral data + // if(conf.isScalefactorResilienceUsed()) rvlc.decodeScalefactors(this, in, scaleFactors); if (conf.isSpectralDataResilienceUsed()) { int max = (conf.getChannelConfiguration() == ChannelConfiguration.STEREO) ? 6144 : 12288; reorderedSpectralDataLen = Math.max(in.readBits(14), max); longestCodewordLen = Math.max(in.readBits(6), 49); - //HCR.decodeReorderedSpectralData(this, in, data, conf.isSectionDataResilienceUsed()); + // HCR.decodeReorderedSpectralData(this, in, data, conf.isSectionDataResilienceUsed()); } else decodeSpectralData(in); } @@ -141,7 +141,7 @@ private void decodePulseData(BitStream in) throws AACException { throw new AACException("pulse SWB out of range: " + pulseStartSWB + " > " + info.getSWBCount()); if (pulseOffset == null || pulseCount != pulseOffset.length) { - //only reallocate if needed + // only reallocate if needed pulseOffset = new int[pulseCount]; pulseAmp = new int[pulseCount]; } @@ -159,7 +159,7 @@ private void decodePulseData(BitStream in) throws AACException { public void decodeScaleFactors(BitStream in) throws AACException { int windowGroups = info.getWindowGroupCount(); int maxSFB = info.getMaxSFB(); - //0: spectrum, 1: noise, 2: intensity + // 0: spectrum, 1: noise, 2: intensity int[] offset = {globalGain, globalGain - 90, 0}; int tmp; @@ -224,7 +224,7 @@ private void decodeSpectralData(BitStream in) throws AACException { Arrays.fill(iqData, off, off + width, 0); } } else if (hcb == NOISE_HCB) { - //apply PNS: fill with random values + // apply PNS: fill with random values for (int w = 0; w < groupLen; w++, off += 128) { float energy = 0; @@ -245,7 +245,7 @@ private void decodeSpectralData(BitStream in) throws AACException { for (int k = 0; k < width; k += num) { Huffman.decodeSpectralData(in, hcb, buf, 0); - //inverse quantization & scaling + // inverse quantization & scaling for (int j = 0; j < num; j++) { iqData[off + k + j] = (buf[j] > 0) ? IQ_TABLE[buf[j]] : -IQ_TABLE[-buf[j]]; iqData[off + k + j] *= scaleFactors[idx]; @@ -258,7 +258,7 @@ private void decodeSpectralData(BitStream in) throws AACException { } } - /* =========== gets ============ */ + // =========== gets ============ /** * Does inverse quantization and applies the scale factors on the decoded diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/IQTable.java b/src/main/java/net/sourceforge/jaad/aac/syntax/IQTable.java index cd956d6..46a6a98 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/IQTable.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/IQTable.java @@ -6,7 +6,7 @@ * * @author in-somnia */ -//TODO: list is too big, create at startup +// TODO: list is too big, create at startup interface IQTable { float[] IQ_TABLE = { diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/LFE.java b/src/main/java/net/sourceforge/jaad/aac/syntax/LFE.java index 4dfca28..c6a1b62 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/LFE.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/LFE.java @@ -1,14 +1,14 @@ package net.sourceforge.jaad.aac.syntax; +import java.util.List; + import net.sourceforge.jaad.aac.DecoderConfig; import net.sourceforge.jaad.aac.sbr.SBR; -import java.util.List; - /** * lfe_channel_element: Abbreviation LFE. - * + *

* Syntactic element that contains a low sampling frequency enhancement channel. * The rules for the number of lfe_channel_element()’s and instance tags are * as for single_channel_element’s. @@ -16,46 +16,47 @@ class LFE extends SCE { - public static final Type TYPE = Type.LFE; + public static final Type TYPE = Type.LFE; - static class Tag extends SCE.Tag { + static class Tag extends SCE.Tag { - protected Tag(int id) { - super(id); - } + protected Tag(int id) { + super(id); + } - @Override - public boolean isChannelPair() { - return false; - } + @Override + public boolean isChannelPair() { + return false; + } - @Override - public Type getType() { - return TYPE; - } + @Override + public Type getType() { + return TYPE; + } - @Override - public ChannelElement newElement(DecoderConfig config) { - return new LFE(config, this); - } - } + @Override + public ChannelElement newElement(DecoderConfig config) { + return new LFE(config, this); + } + } - public static final List TAGS = Element.createTagList(16, Tag::new); + public static final List TAGS = Element.createTagList(16, Tag::new); - LFE(DecoderConfig config, Tag tag) { - super(config, tag); - } + LFE(DecoderConfig config, Tag tag) { + super(config, tag); + } - protected SBR openSBR() { - return null; - } + @Override + protected SBR openSBR() { + return null; + } - @Override - public boolean isChannelPair() { - return false; - } + @Override + public boolean isChannelPair() { + return false; + } - public boolean isLFE() { - return true; - } + public boolean isLFE() { + return true; + } } diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/PCE.java b/src/main/java/net/sourceforge/jaad/aac/syntax/PCE.java index 00f3468..49e2288 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/PCE.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/PCE.java @@ -127,6 +127,7 @@ public PCE(Tag tag) { sampleFrequency = SampleFrequency.SF_NONE; } + @Override public void decode(BitStream in) throws AACException { profile = Profile.forInt(in.readBits(2)); @@ -187,10 +188,12 @@ private void readTaggedElementArray(TaggedElement[] te, BitStream in, int len) t } } + @Override public Profile getProfile() { return profile; } + @Override public SampleFrequency getSampleFrequency() { return sampleFrequency; } @@ -216,6 +219,7 @@ public int getChannelCount() { * * @return a matching ChannelConfiguration according its channel count. */ + @Override public ChannelConfiguration getChannelConfiguration() { return ChannelConfiguration.forChannelCount(getChannelCount()); } diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/SCE.java b/src/main/java/net/sourceforge/jaad/aac/syntax/SCE.java index b381062..c87a334 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/SCE.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/SCE.java @@ -12,7 +12,7 @@ /** - * single_channel_element: abbreviaton SCE. + * single_channel_element: abbreviation SCE. *

* Syntactic element of the bitstream containing coded * data for a single audio channel. A single_channel_element basically @@ -58,10 +58,12 @@ public ChannelElement newElement(DecoderConfig config) { ics = new ICStream(config); } + @Override protected SBR openSBR() { return new SBR1(config); } + @Override public void decode(BitStream in) { super.decode(in); ics.decode(in, false, config); @@ -79,13 +81,14 @@ public boolean isChannelPair() { @Override public boolean isStereo() { if (sbr != null && config.isSBREnabled()) { - //if(sbr.isPSUsed()) + // if(sbr.isPSUsed()) return true; } return false; } + @Override public void process(FilterBank filterBank, List cces, Consumer target) { // inverse quantization diff --git a/src/main/java/net/sourceforge/jaad/aac/syntax/SyntacticElements.java b/src/main/java/net/sourceforge/jaad/aac/syntax/SyntacticElements.java index 6c17f6f..2a1e6ef 100644 --- a/src/main/java/net/sourceforge/jaad/aac/syntax/SyntacticElements.java +++ b/src/main/java/net/sourceforge/jaad/aac/syntax/SyntacticElements.java @@ -15,19 +15,19 @@ public class SyntacticElements { static final Logger LOGGER = Logger.getLogger(SyntacticElements.class.getName()); - //global properties + // global properties private DecoderConfig config; private final FilterBank filterBank; - //elements + // elements private List cces = new ArrayList<>(); private final Map elements = new HashMap<>(); - private final List audioElements = new ArrayList<>(); //SCE, LFE and CPE + private final List audioElements = new ArrayList<>(); // SCE, LFE and CPE private List channels = new ArrayList<>(); @@ -55,7 +55,7 @@ public final void startNewFrame() { public void decode(BitStream in) { if (!config.getProfile().isErrorResilientProfile()) { -loop: + loop: do { switch (Element.readType(in)) { case SCE: @@ -84,7 +84,7 @@ public void decode(BitStream in) { } } while (true); } else { - //error resilient raw data block + // error resilient raw data block switch (config.getChannelConfiguration()) { case MONO: decode(SCE.TAGS, in); diff --git a/src/main/java/net/sourceforge/jaad/aac/tools/ICPrediction.java b/src/main/java/net/sourceforge/jaad/aac/tools/ICPrediction.java index 1da6d17..b2c63ae 100644 --- a/src/main/java/net/sourceforge/jaad/aac/tools/ICPrediction.java +++ b/src/main/java/net/sourceforge/jaad/aac/tools/ICPrediction.java @@ -21,8 +21,8 @@ public class ICPrediction { private static final float SF_SCALE = 1.0f / -1024.0f; private static final float INV_SF_SCALE = 1.0f / SF_SCALE; private static final int MAX_PREDICTORS = 672; - private static final float A = 0.953125f; //61.0 / 64 - private static final float ALPHA = 0.90625f; //29.0 / 32 + private static final float A = 0.953125f; // 61.0 / 64 + private static final float ALPHA = 0.90625f; // 29.0 / 32 private boolean predictorReset; private int predictorResetGroup; private boolean[] predictionUsed; diff --git a/src/main/java/net/sourceforge/jaad/aac/tools/TNS.java b/src/main/java/net/sourceforge/jaad/aac/tools/TNS.java index eb224b9..d83f7b2 100644 --- a/src/main/java/net/sourceforge/jaad/aac/tools/TNS.java +++ b/src/main/java/net/sourceforge/jaad/aac/tools/TNS.java @@ -16,7 +16,7 @@ public class TNS implements TNSTables { private static final int TNS_MAX_ORDER = 20; private static final int[] SHORT_BITS = {1, 4, 3}, LONG_BITS = {2, 6, 5}; - //bitstream + // bitstream private int[] nFilt; private int[][] length, order; private boolean[][] direction; @@ -60,6 +60,6 @@ else if (order[w][filt] != 0) { } public void process(ICStream ics, float[] spec, SampleFrequency sf, boolean decode) { - //TODO... + // TODO... } } diff --git a/src/main/java/net/sourceforge/jaad/aac/tools/Utils.java b/src/main/java/net/sourceforge/jaad/aac/tools/Utils.java index f861fb5..6371c5a 100644 --- a/src/main/java/net/sourceforge/jaad/aac/tools/Utils.java +++ b/src/main/java/net/sourceforge/jaad/aac/tools/Utils.java @@ -1,6 +1,11 @@ package net.sourceforge.jaad.aac.tools; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + /** * Created by IntelliJ IDEA. @@ -13,15 +18,15 @@ public interface Utils { boolean isDebug = Boolean.parseBoolean(System.getProperty("net.sourceforge.jaad.debug", "false").toLowerCase(Locale.ROOT)); static boolean[] copyOf(boolean[] array) { - return array==null ? null : java.util.Arrays.copyOf(array, array.length); + return array == null ? null : java.util.Arrays.copyOf(array, array.length); } static int[] copyOf(int[] array) { - return array==null ? null : java.util.Arrays.copyOf(array, array.length); + return array == null ? null : java.util.Arrays.copyOf(array, array.length); } static float[] copyOf(float[] array) { - return array==null ? null : java.util.Arrays.copyOf(array, array.length); + return array == null ? null : java.util.Arrays.copyOf(array, array.length); } static void copyRange(int[] array, int srcPos, int destPos, int length) { @@ -35,13 +40,13 @@ static int clip(int idx, int min, int max) { } @SafeVarargs - static List listOf(E... elements) { + static List listOf(E... elements) { if (elements.length == 0) return Collections.emptyList(); else return Collections.unmodifiableList(Arrays.asList(elements)); } @SuppressWarnings("unchecked") - static List listCopyOf(Collection coll) { + static List listCopyOf(Collection coll) { if (coll == Collections.emptyList()) return (List) coll; else return (List) listOf(coll.toArray()); } diff --git a/src/main/java/net/sourceforge/jaad/aac/transport/ADIFHeader.java b/src/main/java/net/sourceforge/jaad/aac/transport/ADIFHeader.java index f894d8f..3c518d9 100644 --- a/src/main/java/net/sourceforge/jaad/aac/transport/ADIFHeader.java +++ b/src/main/java/net/sourceforge/jaad/aac/transport/ADIFHeader.java @@ -6,7 +6,7 @@ public final class ADIFHeader { - private static final long ADIF_ID = 0x41444946; //'ADIF' + private static final long ADIF_ID = 0x41444946; // 'ADIF' private long id; private boolean copyrightIDPresent; private byte[] copyrightID; @@ -31,7 +31,7 @@ public static ADIFHeader readHeader(BitStream in) { } private void decode(BitStream in) { - id = in.readBits(32); //'ADIF' + id = in.readBits(32); // 'ADIF' copyrightIDPresent = in.readBool(); if (copyrightIDPresent) { for (int i = 0; i < 9; i++) { diff --git a/src/main/java/net/sourceforge/jaad/adts/ADTSFrame.java b/src/main/java/net/sourceforge/jaad/adts/ADTSFrame.java index c1364aa..d6bd2c8 100644 --- a/src/main/java/net/sourceforge/jaad/adts/ADTSFrame.java +++ b/src/main/java/net/sourceforge/jaad/adts/ADTSFrame.java @@ -28,10 +28,10 @@ class ADTSFrame implements AudioDecoderInfo { if (!protectionAbsent) crcCheck = in.readUnsignedShort(); if (rawDataBlockCount == 0) { - //raw_data_block(); + // raw_data_block(); } else { int i; - //header error check + // header error check if (!protectionAbsent) { rawDataBlockPosition = new int[rawDataBlockCount]; for (i = 0; i < rawDataBlockCount; i++) { @@ -39,38 +39,38 @@ class ADTSFrame implements AudioDecoderInfo { } crcCheck = in.readUnsignedShort(); } - //raw data blocks + // raw data blocks for (i = 0; i < rawDataBlockCount; i++) { - //raw_data_block(); + // raw_data_block(); if (!protectionAbsent) crcCheck = in.readUnsignedShort(); } } } private void readHeader(DataInputStream in) throws IOException { - //fixed header: - //1 bit ID, 2 bits layer, 1 bit protection absent + // fixed header: + // 1 bit ID, 2 bits layer, 1 bit protection absent int i = in.read(); id = ((i >> 3) & 0x1) == 1; layer = (i >> 1) & 0x3; protectionAbsent = (i & 0x1) == 1; - //2 bits profile, 4 bits sample frequency, 1 bit private bit + // 2 bits profile, 4 bits sample frequency, 1 bit private bit i = in.read(); profile = ((i >> 6) & 0x3) + 1; sampleFrequency = (i >> 2) & 0xF; privateBit = ((i >> 1) & 0x1) == 1; - //3 bits channel configuration, 1 bit copy, 1 bit home + // 3 bits channel configuration, 1 bit copy, 1 bit home i = (i << 8) | in.read(); channelConfiguration = ((i >> 6) & 0x7); copy = ((i >> 5) & 0x1) == 1; home = ((i >> 4) & 0x1) == 1; - //int emphasis = in.readBits(2); + // int emphasis = in.readBits(2); - //variable header: - //1 bit copyrightIDBit, 1 bit copyrightIDStart, 13 bits frame length, - //11 bits adtsBufferFullness, 2 bits rawDataBlockCount + // variable header: + // 1 bit copyrightIDBit, 1 bit copyrightIDStart, 13 bits frame length, + // 11 bits adtsBufferFullness, 2 bits rawDataBlockCount copyrightIDBit = ((i >> 3) & 0x1) == 1; copyrightIDStart = ((i >> 2) & 0x1) == 1; i = (i << 16) | in.readUnsignedShort(); @@ -84,14 +84,17 @@ int getFrameLength() { return frameLength - (protectionAbsent ? 7 : 9); } + @Override public Profile getProfile() { return Profile.forInt(profile); } + @Override public SampleFrequency getSampleFrequency() { return SampleFrequency.forInt(sampleFrequency); } + @Override public ChannelConfiguration getChannelConfiguration() { return ChannelConfiguration.forInt(channelConfiguration); } diff --git a/src/main/java/net/sourceforge/jaad/mp4/MP4Container.java b/src/main/java/net/sourceforge/jaad/mp4/MP4Container.java index 3b0e15b..b5290cf 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/MP4Container.java +++ b/src/main/java/net/sourceforge/jaad/mp4/MP4Container.java @@ -60,7 +60,7 @@ public MP4Container(MP4Input in) throws IOException { } private void readContent() throws IOException { - //read all boxes + // read all boxes Box box = null; long type; boolean moovFound = false; diff --git a/src/main/java/net/sourceforge/jaad/mp4/MP4Input.java b/src/main/java/net/sourceforge/jaad/mp4/MP4Input.java index b2c892b..f27bce4 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/MP4Input.java +++ b/src/main/java/net/sourceforge/jaad/mp4/MP4Input.java @@ -4,6 +4,7 @@ import java.io.InputStream; import java.io.RandomAccessFile; + /** * Created by IntelliJ IDEA. * User: stueken @@ -12,214 +13,215 @@ */ public interface MP4Input extends AutoCloseable { - static MP4Input open(InputStream in) { - return new MP4InputStream(in); - } - - static MP4Input open(RandomAccessFile in) { - return new MP4RandomAccessStream(in); - } - - String UTF8 = "UTF-8"; - String UTF16 = "UTF-16"; - - /** - * Reads the next byte of data from the input. The value byte is returned as - * an int in the range 0 to 255. If no byte is available because the end of - * the stream has been reached, an EOFException is thrown. This method - * blocks until input data is available, the end of the stream is detected, - * or an I/O error occurs. - * - * @return the next byte of data - * @throws IOException If the end of the stream is detected or any I/O error occurs. - */ - int readByte() throws IOException; - - /** - * Reads len bytes of data from the input into the array - * b. If len is zero, then no bytes are read. - * - * This method blocks until all bytes could be read, the end of the stream - * is detected, or an I/O error occurs. - * - * If the stream ends before len bytes could be read an - * EOFException is thrown. - * - * @param b the buffer into which the data is read. - * @param off the start offset in array b at which the data is written. - * @param len the number of bytes to read. - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - */ - void readBytes(byte[] b, int off, int len) throws IOException; - - /** - * Reads up to eight bytes as a long value. This method blocks until all - * bytes could be read, the end of the stream is detected, or an I/O error - * occurs. - * - * @param n the number of bytes to read >0 and <=8 - * @return the read bytes as a long value - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - * @throws IndexOutOfBoundsException if n is not in the range - * [1...8] inclusive. - */ - long readBytes(int n) throws IOException; - - /** - * Reads data from the input stream and stores them into the buffer array b. - * This method blocks until all bytes could be read, the end of the stream - * is detected, or an I/O error occurs. - * If the length of b is zero, then no bytes are read. - * - * @param b the buffer into which the data is read. - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - */ - - void readBytes(byte[] b) throws IOException; - - /** - * Reads n bytes from the input as a String. The bytes are - * directly converted into characters. If not enough bytes could be read, an - * EOFException is thrown. - * This method blocks until all bytes could be read, the end of the stream - * is detected, or an I/O error occurs. - * - * @param n the length of the String. - * @return the String, that was read - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - */ - String readString(int n) throws IOException; - - /** - * Reads a null-terminated UTF-encoded String from the input. The maximum - * number of bytes that can be read before the null must appear must be - * specified. - * Although the method is preferred for unicode, the encoding can be any - * charset name, that is supported by the system. - * - * This method blocks until all bytes could be read, the end of the stream - * is detected, or an I/O error occurs. - * - * @param max the maximum number of bytes to read, before the null-terminator - * must appear. - * @param encoding the charset used to encode the String - * @return the decoded String - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - */ - String readUTFString(int max, String encoding) throws IOException; - - /** - * Reads a null-terminated UTF-encoded String from the input. The maximum - * number of bytes that can be read before the null must appear must be - * specified. - * The encoding is detected automatically, it may be UTF-8 or UTF-16 - * (determined by a byte order mask at the beginning). - * - * This method blocks until all bytes could be read, the end of the stream - * is detected, or an I/O error occurs. - * - * @param max the maximum number of bytes to read, before the null-terminator - * must appear. - * @return the decoded String - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - */ - String readUTFString(int max) throws IOException; - - /** - * Reads a byte array from the input that is terminated by a specific byte - * (the 'terminator'). The maximum number of bytes that can be read before - * the terminator must appear must be specified. - * - * The terminator will not be included in the returned array. - * - * This method blocks until all bytes could be read, the end of the stream - * is detected, or an I/O error occurs. - * - * @param max the maximum number of bytes to read, before the terminator - * must appear. - * @param terminator the byte that indicates the end of the array - * @return the buffer into which the data is read. - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - */ - byte[] readTerminated(int max, int terminator) throws IOException; - - /** - * Reads a fixed point number from the input. The number is read as a - * m.n value, that results from deviding an integer by - * 2n. - * - * @param m the number of bits before the point - * @param n the number of bits after the point - * @return a floating point number with the same value - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - * @throws IllegalArgumentException if the total number of bits (m+n) is not - * a multiple of eight - */ - double readFixedPoint(int m, int n) throws IOException; - - /** - * Skips n bytes in the input. This method blocks until all - * bytes could be skipped, the end of the stream is detected, or an I/O - * error occurs. - * - * @param n the number of bytes to skip - * @throws IOException If the end of the stream is detected, the input - * stream has been closed, or if some other I/O error occurs. - */ - void skipBytes(long n) throws IOException; - - /** - * Returns the current offset in the stream. - * - * @return the current offset - * @throws IOException if an I/O error occurs (only when using a RandomAccessFile) - */ - long getOffset() throws IOException; - - /** - * Seeks to a specific offset in the stream. This is only possible when - * using a RandomAccessFile. If an InputStream is used, this method throws - * an IOException. - * - * @param pos the offset position, measured in bytes from the beginning of the - * stream - * @throws IOException if an InputStream is used, pos is less than 0 or an - * I/O error occurs - */ - void seek(long pos) throws IOException; - - /** - * Indicates, if random access is available. That is, if this - * MP4InputStream was constructed with a RandomAccessFile. If - * this method returns false, seeking is not possible. - * - * @return true if random access is available - */ - boolean hasRandomAccess(); - - /** - * Indicates, if the input has some data left. - * - * @return true if there is at least one byte left - * @throws IOException if an I/O error occurs - */ - boolean hasLeft() throws IOException; - - - /** - * Closes the input and releases any system resources associated with it. - * Once the stream has been closed, further reading or skipping will throw - * an IOException. Closing a previously closed stream has no effect. - * - * @throws IOException if an I/O error occurs - */ - void close() throws IOException; + static MP4Input open(InputStream in) { + return new MP4InputStream(in); + } + + static MP4Input open(RandomAccessFile in) { + return new MP4RandomAccessStream(in); + } + + String UTF8 = "UTF-8"; + String UTF16 = "UTF-16"; + + /** + * Reads the next byte of data from the input. The value byte is returned as + * an int in the range 0 to 255. If no byte is available because the end of + * the stream has been reached, an EOFException is thrown. This method + * blocks until input data is available, the end of the stream is detected, + * or an I/O error occurs. + * + * @return the next byte of data + * @throws IOException If the end of the stream is detected or any I/O error occurs. + */ + int readByte() throws IOException; + + /** + * Reads len bytes of data from the input into the array + * b. If len is zero, then no bytes are read. + *

+ * This method blocks until all bytes could be read, the end of the stream + * is detected, or an I/O error occurs. + *

+ * If the stream ends before len bytes could be read an + * EOFException is thrown. + * + * @param b the buffer into which the data is read. + * @param off the start offset in array b at which the data is written. + * @param len the number of bytes to read. + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + */ + void readBytes(byte[] b, int off, int len) throws IOException; + + /** + * Reads up to eight bytes as a long value. This method blocks until all + * bytes could be read, the end of the stream is detected, or an I/O error + * occurs. + * + * @param n the number of bytes to read >0 and <=8 + * @return the read bytes as a long value + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + * @throws IndexOutOfBoundsException if n is not in the range + * [1...8] inclusive. + */ + long readBytes(int n) throws IOException; + + /** + * Reads data from the input stream and stores them into the buffer array b. + * This method blocks until all bytes could be read, the end of the stream + * is detected, or an I/O error occurs. + * If the length of b is zero, then no bytes are read. + * + * @param b the buffer into which the data is read. + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + */ + + void readBytes(byte[] b) throws IOException; + + /** + * Reads n bytes from the input as a String. The bytes are + * directly converted into characters. If not enough bytes could be read, an + * EOFException is thrown. + * This method blocks until all bytes could be read, the end of the stream + * is detected, or an I/O error occurs. + * + * @param n the length of the String. + * @return the String, that was read + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + */ + String readString(int n) throws IOException; + + /** + * Reads a null-terminated UTF-encoded String from the input. The maximum + * number of bytes that can be read before the null must appear must be + * specified. + * Although the method is preferred for unicode, the encoding can be any + * charset name, that is supported by the system. + *

+ * This method blocks until all bytes could be read, the end of the stream + * is detected, or an I/O error occurs. + * + * @param max the maximum number of bytes to read, before the null-terminator + * must appear. + * @param encoding the charset used to encode the String + * @return the decoded String + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + */ + String readUTFString(int max, String encoding) throws IOException; + + /** + * Reads a null-terminated UTF-encoded String from the input. The maximum + * number of bytes that can be read before the null must appear must be + * specified. + * The encoding is detected automatically, it may be UTF-8 or UTF-16 + * (determined by a byte order mask at the beginning). + *

+ * This method blocks until all bytes could be read, the end of the stream + * is detected, or an I/O error occurs. + * + * @param max the maximum number of bytes to read, before the null-terminator + * must appear. + * @return the decoded String + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + */ + String readUTFString(int max) throws IOException; + + /** + * Reads a byte array from the input that is terminated by a specific byte + * (the 'terminator'). The maximum number of bytes that can be read before + * the terminator must appear must be specified. + *

+ * The terminator will not be included in the returned array. + *

+ * This method blocks until all bytes could be read, the end of the stream + * is detected, or an I/O error occurs. + * + * @param max the maximum number of bytes to read, before the terminator + * must appear. + * @param terminator the byte that indicates the end of the array + * @return the buffer into which the data is read. + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + */ + byte[] readTerminated(int max, int terminator) throws IOException; + + /** + * Reads a fixed point number from the input. The number is read as a + * m.n value, that results from dividing an integer by + * 2n. + * + * @param m the number of bits before the point + * @param n the number of bits after the point + * @return a floating point number with the same value + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + * @throws IllegalArgumentException if the total number of bits (m+n) is not + * a multiple of eight + */ + double readFixedPoint(int m, int n) throws IOException; + + /** + * Skips n bytes in the input. This method blocks until all + * bytes could be skipped, the end of the stream is detected, or an I/O + * error occurs. + * + * @param n the number of bytes to skip + * @throws IOException If the end of the stream is detected, the input + * stream has been closed, or if some other I/O error occurs. + */ + void skipBytes(long n) throws IOException; + + /** + * Returns the current offset in the stream. + * + * @return the current offset + * @throws IOException if an I/O error occurs (only when using a RandomAccessFile) + */ + long getOffset() throws IOException; + + /** + * Seeks to a specific offset in the stream. This is only possible when + * using a RandomAccessFile. If an InputStream is used, this method throws + * an IOException. + * + * @param pos the offset position, measured in bytes from the beginning of the + * stream + * @throws IOException if an InputStream is used, pos is less than 0 or an + * I/O error occurs + */ + void seek(long pos) throws IOException; + + /** + * Indicates, if random access is available. That is, if this + * MP4InputStream was constructed with a RandomAccessFile. If + * this method returns false, seeking is not possible. + * + * @return true if random access is available + */ + boolean hasRandomAccess(); + + /** + * Indicates, if the input has some data left. + * + * @return true if there is at least one byte left + * @throws IOException if an I/O error occurs + */ + boolean hasLeft() throws IOException; + + + /** + * Closes the input and releases any system resources associated with it. + * Once the stream has been closed, further reading or skipping will throw + * an IOException. Closing a previously closed stream has no effect. + * + * @throws IOException if an I/O error occurs + */ + @Override + void close() throws IOException; } diff --git a/src/main/java/net/sourceforge/jaad/mp4/MP4InputReader.java b/src/main/java/net/sourceforge/jaad/mp4/MP4InputReader.java index e71fbed..e62a9f6 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/MP4InputReader.java +++ b/src/main/java/net/sourceforge/jaad/mp4/MP4InputReader.java @@ -5,6 +5,7 @@ import java.nio.charset.Charset; import java.util.Arrays; + /** * Created by IntelliJ IDEA. * User: stueken @@ -13,125 +14,127 @@ */ abstract public class MP4InputReader implements MP4Input { - private static final int BYTE_ORDER_MASK = 0xFEFF; - - // to be implemented - abstract protected int read() throws IOException; - abstract protected int read(byte[] b, int off, int len) throws IOException; - abstract protected long skip(int n) throws IOException; - - @Override - public int readByte() throws IOException { - int i = read(); - - if(i==-1){ - throw new EOFException(); - } - - return i; - } - - @Override - public void readBytes(byte[] b, int off, int len) throws IOException { - int read = 0; - - while(read8) - throw new IndexOutOfBoundsException("invalid number of bytes to read: "+n); - - byte[] b = new byte[n]; - readBytes(b, 0, n); - - long result = 0; - for(int i = 0; i 8) + throw new IndexOutOfBoundsException("invalid number of bytes to read: " + n); + + byte[] b = new byte[n]; + readBytes(b, 0, n); + + long result = 0; + for (int i = 0; i < n; i++) { + result = (result << 8) | (b[i] & 0xFF); + } + return result; + } + + @Override + public void readBytes(byte[] b) throws IOException { + readBytes(b, 0, b.length); + } + + @Override + public String readString(int n) throws IOException { + int i = -1; + int pos = 0; + char[] c = new char[n]; + while (pos < n) { + i = readByte(); + c[pos] = (char) i; + pos++; + } + return new String(c, 0, pos); + } + + @Override + public String readUTFString(int max, String encoding) throws IOException { + return new String(readTerminated(max, 0), Charset.forName(encoding)); + } + + @Override + public String readUTFString(int max) throws IOException { + // read byte order mask + byte[] bom = new byte[2]; + readBytes(bom, 0, 2); + if (bom[0] == 0 || bom[1] == 0) + return ""; + int i = (bom[0] << 8) | bom[1]; + + // read null-terminated + byte[] b = readTerminated(max - 2, 0); + // copy bom + byte[] b2 = new byte[b.length + bom.length]; + System.arraycopy(bom, 0, b2, 0, bom.length); + System.arraycopy(b, 0, b2, bom.length, b.length); + + return new String(b2, Charset.forName((i == BYTE_ORDER_MASK) ? UTF16 : UTF8)); + } + + @Override + public byte[] readTerminated(int max, int terminator) throws IOException { + byte[] b = new byte[max]; + int pos = 0; + int i = 0; + while (pos < max && i != -1) { + i = readByte(); + if (i != -1) + b[pos++] = (byte) i; + } + return Arrays.copyOf(b, pos); + } + + @Override + public double readFixedPoint(int m, int n) throws IOException { + int bits = m + n; + if ((bits % 8) != 0) + throw new IllegalArgumentException("number of bits is not a multiple of 8: " + (m + n)); + + long l = readBytes(bits / 8); + double x = Math.pow(2, n); + double d = ((double) l) / x; + return d; + } + + @Override + public void skipBytes(long n) throws IOException { + long l = 0; + + while (l < n) { + l += skip((int) (n - l)); + } + } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/MP4RandomAccessStream.java b/src/main/java/net/sourceforge/jaad/mp4/MP4RandomAccessStream.java index 07e282b..432eeaa 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/MP4RandomAccessStream.java +++ b/src/main/java/net/sourceforge/jaad/mp4/MP4RandomAccessStream.java @@ -3,59 +3,61 @@ import java.io.IOException; import java.io.RandomAccessFile; + public class MP4RandomAccessStream extends MP4InputReader { - private final RandomAccessFile fin; - - /** - * Constructs an MP4InputStream that reads from a - * RandomAccessFile. It will have random access and seeking - * will be possible. - * - * @param fin a RandomAccessFile to read from - */ - MP4RandomAccessStream(RandomAccessFile fin) { - this.fin = fin; - } - - @Override - protected int read() throws IOException { - return fin.read(); - } - - - @Override - protected int read(byte[] b, int off, int len) throws IOException { - return fin.read(b, off, len); - } - - @Override - protected long skip(int n) throws IOException { - return fin.skipBytes(n); - } - - @Override - public long getOffset() throws IOException { - return fin.getFilePointer(); - } - - @Override - public void seek(long pos) throws IOException { - fin.seek(pos); - } - - @Override - public boolean hasRandomAccess() { - return true; - } - - - @Override - public boolean hasLeft() throws IOException { - return fin.getFilePointer()<(fin.length()-1); - } - - public void close() throws IOException { - fin.close(); - } + private final RandomAccessFile fin; + + /** + * Constructs an MP4InputStream that reads from a + * RandomAccessFile. It will have random access and seeking + * will be possible. + * + * @param fin a RandomAccessFile to read from + */ + MP4RandomAccessStream(RandomAccessFile fin) { + this.fin = fin; + } + + @Override + protected int read() throws IOException { + return fin.read(); + } + + + @Override + protected int read(byte[] b, int off, int len) throws IOException { + return fin.read(b, off, len); + } + + @Override + protected long skip(int n) throws IOException { + return fin.skipBytes(n); + } + + @Override + public long getOffset() throws IOException { + return fin.getFilePointer(); + } + + @Override + public void seek(long pos) throws IOException { + fin.seek(pos); + } + + @Override + public boolean hasRandomAccess() { + return true; + } + + + @Override + public boolean hasLeft() throws IOException { + return fin.getFilePointer() < (fin.length() - 1); + } + + @Override + public void close() throws IOException { + fin.close(); + } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/AudioTrack.java b/src/main/java/net/sourceforge/jaad/mp4/api/AudioTrack.java index f1c2307..d742efc 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/AudioTrack.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/AudioTrack.java @@ -52,7 +52,7 @@ public AudioTrack(Box trak, MP4Input in) { Box stbl = minf.getChild(BoxTypes.SAMPLE_TABLE_BOX); - //sample descriptions: 'mp4a' and 'enca' have an ESDBox, all others have a CodecSpecificBox + // sample descriptions: 'mp4a' and 'enca' have an ESDBox, all others have a CodecSpecificBox SampleDescriptionBox stsd = (SampleDescriptionBox) stbl.getChild(BoxTypes.SAMPLE_DESCRIPTION_BOX); if (stsd.getChildren().get(0) instanceof AudioSampleEntry) { sampleEntry = (AudioSampleEntry) stsd.getChildren().get(0); diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/Brand.java b/src/main/java/net/sourceforge/jaad/mp4/api/Brand.java index 767c20e..f83b969 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/Brand.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/Brand.java @@ -1,14 +1,13 @@ package net.sourceforge.jaad.mp4.api; /** - * @see "https://www.ftyps.com" - * * @author in-somnia + * @see "https:// www.ftyps.com" */ public enum Brand { UNKNOWN_BRAND("\0\0\0\0", "unknown brand"), - //iso + // iso ISO_BASE_MEDIA("isom", "ISO base media file format v1"), ISO_BASE_MEDIA_2("iso2", "ISO base media file format v2"), ISO_BASE_MEDIA_3("iso3", "ISO base media file format v3"), @@ -44,7 +43,7 @@ public enum Brand { MPEG_21("mp21", "MPEG-21"), MPPI_PHOTO_PLAYER("MPPI", "MPPI Photo Player"), JPSEARCH("jpsi", "JPSearch data interchange format"), - //3gpp + // 3gpp THREE_GPP_RELEASE_1("3gp1", "3GPP Release 1"), THREE_GPP_RELEASE_2("3gp2", "3GPP Release 2"), THREE_GPP_RELEASE_3("3gp3", "3GPP Release 3"), @@ -72,13 +71,13 @@ public enum Brand { THREE_GPP2_C("3g2c", "3GPP2 compliant with 3GPP2 C.S0050-B v1.0"), THREE_GPP2_KDDI_3G_EZMOVIE("KDDI", "3GPP2 EZmovie for KDDI 3G cellphones"), MPEG_4_MOBILE_PROFILE_("mmp4", "MPEG-4/3GPP Mobile Profile"), - //others + // others DIRAC("drc1", "Dirac wavelet compression encapsulated in ISO base media"), DIGITAL_MEDIA_PROJECT("dmpf", "Digital Media Project"), DVB_OVER_RTP("dvr1", "DVB over RTP"), DVB_OVER_MPEG_2_TRANSPORT_STREAM("dvt1", "DVB over MPEG-2 Transport Stream"), SD_MEMORY_CARD_VIDEO("sdv ", "SD Memory Card Video"), - //producers + // producers ADOBE_FLASH_PLAYER_VIDEO("F4V ", "Video for Adobe Flash Player 9+"), ADOBE_FLASH_PLAYER_PROTECTED_VIDEO("F4P ", "Protected Video for Adobe Flash Player 9+"), ADOBE_FLASH_PLAYER_AUDIO("F4A ", "Audio for Adobe Flash Player 9+"), diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/DecoderInfo.java b/src/main/java/net/sourceforge/jaad/mp4/api/DecoderInfo.java index 0afeec4..bdc8304 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/DecoderInfo.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/DecoderInfo.java @@ -13,7 +13,7 @@ /** - * The DecoderInfo object contains the neccessary data to + * The DecoderInfo object contains the necessary data to * initialize a decoder. A track either contains a DecoderInfo or a * byte-Array called the 'DecoderSpecificInfo', which is e.g. used for AAC. *

@@ -46,5 +46,6 @@ static DecoderInfo parse(CodecSpecificBox css) { } private static class UnknownDecoderInfo extends DecoderInfo { + } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/Frame.java b/src/main/java/net/sourceforge/jaad/mp4/api/Frame.java index 4c717aa..3ac3e48 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/Frame.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/Frame.java @@ -30,9 +30,10 @@ public double getTime() { return time; } + @Override public int compareTo(Frame f) { double d = time - f.time; - //0 should not happen, since frames don't have the same timestamps + // 0 should not happen, since frames don't have the same timestamps return (d < 0) ? -1 : ((d > 0) ? 1 : 0); } diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/ID3Frame.java b/src/main/java/net/sourceforge/jaad/mp4/api/ID3Frame.java index 0f54146..261878d 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/ID3Frame.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/ID3Frame.java @@ -11,89 +11,89 @@ class ID3Frame { - static final int ALBUM_TITLE = 1413565506; //TALB - static final int ALBUM_SORT_ORDER = 1414745921; //TSOA - static final int ARTIST = 1414546737; //TPE1 - static final int ATTACHED_PICTURE = 1095780675; //APIC - static final int AUDIO_ENCRYPTION = 1095061059; //AENC - static final int AUDIO_SEEK_POINT_INDEX = 1095979081; //ASPI - static final int BAND = 1414546738; //TPE2 - static final int BEATS_PER_MINUTE = 1413632077; //TBPM - static final int COMMENTS = 1129270605; //COMM - static final int COMMERCIAL_FRAME = 1129270610; //COMR - static final int COMMERCIAL_INFORMATION = 1464029005; //WCOM - static final int COMPOSER = 1413697357; //TCOM - static final int CONDUCTOR = 1414546739; //TPE3 - static final int CONTENT_GROUP_DESCRIPTION = 1414091825; //TIT1 - static final int CONTENT_TYPE = 1413697358; //TCON - static final int COPYRIGHT = 1464029008; //WCOP - static final int COPYRIGHT_MESSAGE = 1413697360; //TCOP - static final int ENCODED_BY = 1413828163; //TENC - static final int ENCODING_TIME = 1413760334; //TDEN - static final int ENCRYPTION_METHOD_REGISTRATION = 1162756946; //ENCR - static final int EQUALISATION = 1162958130; //EQU2 - static final int EVENT_TIMING_CODES = 1163150159; //ETCO - static final int FILE_OWNER = 1414485838; //TOWN - static final int FILE_TYPE = 1413893204; //TFLT - static final int GENERAL_ENCAPSULATED_OBJECT = 1195724610; //GEOB - static final int GROUP_IDENTIFICATION_REGISTRATION = 1196575044; //GRID - static final int INITIAL_KEY = 1414219097; //TKEY - static final int INTERNET_RADIO_STATION_NAME = 1414681422; //TRSN - static final int INTERNET_RADIO_STATION_OWNER = 1414681423; //TRSO - static final int MODIFIED_BY = 1414546740; //TPE4 - static final int INVOLVED_PEOPLE_LIST = 1414090828; //TIPL - static final int INTERNATIONAL_STANDARD_RECORDING_CODE = 1414746691; //TSRC - static final int LANGUAGES = 1414283598; //TLAN - static final int LENGTH = 1414284622; //TLEN - static final int LINKED_INFORMATION = 1279872587; //LINK - static final int LYRICIST = 1413830740; //TEXT - static final int MEDIA_TYPE = 1414350148; //TMED - static final int MOOD = 1414352719; //TMOO - static final int MPEG_LOCATION_LOOKUP_TABLE = 1296845908; //MLLT - static final int MUSICIAN_CREDITS_LIST = 1414349644; //TMCL - static final int MUSIC_CD_IDENTIFIER = 1296254025; //MCDI - static final int OFFICIAL_ARTIST_WEBPAGE = 1464811858; //WOAR - static final int OFFICIAL_AUDIO_FILE_WEBPAGE = 1464811846; //WOAF - static final int OFFICIAL_AUDIO_SOURCE_WEBPAGE = 1464811859; //WOAS - static final int OFFICIAL_INTERNET_RADIO_STATION_HOMEPAGE = 1464816211; //WORS - static final int ORIGINAL_ALBUM_TITLE = 1414480204; //TOAL - static final int ORIGINAL_ARTIST = 1414484037; //TOPE - static final int ORIGINAL_FILENAME = 1414481486; //TOFN - static final int ORIGINAL_LYRICIST = 1414483033; //TOLY - static final int ORIGINAL_RELEASE_TIME = 1413762898; //TDOR - static final int OWNERSHIP_FRAME = 1331121733; //OWNE - static final int PART_OF_A_SET = 1414549331; //TPOS - static final int PAYMENT = 1464877401; //WPAY - static final int PERFORMER_SORT_ORDER = 1414745936; //TSOP - static final int PLAYLIST_DELAY = 1413762137; //TDLY - static final int PLAY_COUNTER = 1346588244; //PCNT - static final int POPULARIMETER = 1347375181; //POPM - static final int POSITION_SYNCHRONISATION_FRAME = 1347375955; //POSS - static final int PRIVATE_FRAME = 1347570006; //PRIV - static final int PRODUCED_NOTICE = 1414550095; //TPRO - static final int PUBLISHER = 1414550850; //TPUB - static final int PUBLISHERS_OFFICIAL_WEBPAGE = 1464882498; //WPUB - static final int RECOMMENDED_BUFFER_SIZE = 1380078918; //RBUF - static final int RECORDING_TIME = 1413763651; //TDRC - static final int RELATIVE_VOLUME_ADJUSTMENT = 1381384498; //RVA2 - static final int RELEASE_TIME = 1413763660; //TDRL - static final int REVERB = 1381388866; //RVRB - static final int SEEK_FRAME = 1397048651; //SEEK - static final int SET_SUBTITLE = 1414746964; //TSST - static final int SIGNATURE_FRAME = 1397311310; //SIGN - static final int ENCODING_TOOLS_AND_SETTINGS = 1414746949; //TSSE - static final int SUBTITLE = 1414091827; //TIT3 - static final int SYNCHRONISED_LYRIC = 1398361172; //SYLT - static final int SYNCHRONISED_TEMPO_CODES = 1398363203; //SYTC - static final int TAGGING_TIME = 1413764167; //TDTG - static final int TERMS_OF_USE = 1431520594; //USER - static final int TITLE = 1414091826; //TIT2 - static final int TITLE_SORT_ORDER = 1414745940; //TSOT - static final int TRACK_NUMBER = 1414677323; //TRCK - static final int UNIQUE_FILE_IDENTIFIER = 1430669636; //UFID - static final int UNSYNCHRONISED_LYRIC = 1431522388; //USLT - static final int USER_DEFINED_TEXT_INFORMATION_FRAME = 1415075928; //TXXX - static final int USER_DEFINED_URL_LINK_FRAME = 1465407576; //WXXX + static final int ALBUM_TITLE = 1413565506; // TALB + static final int ALBUM_SORT_ORDER = 1414745921; // TSOA + static final int ARTIST = 1414546737; // TPE1 + static final int ATTACHED_PICTURE = 1095780675; // APIC + static final int AUDIO_ENCRYPTION = 1095061059; // AENC + static final int AUDIO_SEEK_POINT_INDEX = 1095979081; // ASPI + static final int BAND = 1414546738; // TPE2 + static final int BEATS_PER_MINUTE = 1413632077; // TBPM + static final int COMMENTS = 1129270605; // COMM + static final int COMMERCIAL_FRAME = 1129270610; // COMR + static final int COMMERCIAL_INFORMATION = 1464029005; // WCOM + static final int COMPOSER = 1413697357; // TCOM + static final int CONDUCTOR = 1414546739; // TPE3 + static final int CONTENT_GROUP_DESCRIPTION = 1414091825; // TIT1 + static final int CONTENT_TYPE = 1413697358; // TCON + static final int COPYRIGHT = 1464029008; // WCOP + static final int COPYRIGHT_MESSAGE = 1413697360; // TCOP + static final int ENCODED_BY = 1413828163; // TENC + static final int ENCODING_TIME = 1413760334; // TDEN + static final int ENCRYPTION_METHOD_REGISTRATION = 1162756946; // ENCR + static final int EQUALISATION = 1162958130; // EQU2 + static final int EVENT_TIMING_CODES = 1163150159; // ETCO + static final int FILE_OWNER = 1414485838; // TOWN + static final int FILE_TYPE = 1413893204; // TFLT + static final int GENERAL_ENCAPSULATED_OBJECT = 1195724610; // GEOB + static final int GROUP_IDENTIFICATION_REGISTRATION = 1196575044; // GRID + static final int INITIAL_KEY = 1414219097; // TKEY + static final int INTERNET_RADIO_STATION_NAME = 1414681422; // TRSN + static final int INTERNET_RADIO_STATION_OWNER = 1414681423; // TRSO + static final int MODIFIED_BY = 1414546740; // TPE4 + static final int INVOLVED_PEOPLE_LIST = 1414090828; // TIPL + static final int INTERNATIONAL_STANDARD_RECORDING_CODE = 1414746691; // TSRC + static final int LANGUAGES = 1414283598; // TLAN + static final int LENGTH = 1414284622; // TLEN + static final int LINKED_INFORMATION = 1279872587; // LINK + static final int LYRICIST = 1413830740; // TEXT + static final int MEDIA_TYPE = 1414350148; // TMED + static final int MOOD = 1414352719; // TMOO + static final int MPEG_LOCATION_LOOKUP_TABLE = 1296845908; // MLLT + static final int MUSICIAN_CREDITS_LIST = 1414349644; // TMCL + static final int MUSIC_CD_IDENTIFIER = 1296254025; // MCDI + static final int OFFICIAL_ARTIST_WEBPAGE = 1464811858; // WOAR + static final int OFFICIAL_AUDIO_FILE_WEBPAGE = 1464811846; // WOAF + static final int OFFICIAL_AUDIO_SOURCE_WEBPAGE = 1464811859; // WOAS + static final int OFFICIAL_INTERNET_RADIO_STATION_HOMEPAGE = 1464816211; // WORS + static final int ORIGINAL_ALBUM_TITLE = 1414480204; // TOAL + static final int ORIGINAL_ARTIST = 1414484037; // TOPE + static final int ORIGINAL_FILENAME = 1414481486; // TOFN + static final int ORIGINAL_LYRICIST = 1414483033; // TOLY + static final int ORIGINAL_RELEASE_TIME = 1413762898; // TDOR + static final int OWNERSHIP_FRAME = 1331121733; // OWNE + static final int PART_OF_A_SET = 1414549331; // TPOS + static final int PAYMENT = 1464877401; // WPAY + static final int PERFORMER_SORT_ORDER = 1414745936; // TSOP + static final int PLAYLIST_DELAY = 1413762137; // TDLY + static final int PLAY_COUNTER = 1346588244; // PCNT + static final int POPULARIMETER = 1347375181; // POPM + static final int POSITION_SYNCHRONISATION_FRAME = 1347375955; // POSS + static final int PRIVATE_FRAME = 1347570006; // PRIV + static final int PRODUCED_NOTICE = 1414550095; // TPRO + static final int PUBLISHER = 1414550850; // TPUB + static final int PUBLISHERS_OFFICIAL_WEBPAGE = 1464882498; // WPUB + static final int RECOMMENDED_BUFFER_SIZE = 1380078918; // RBUF + static final int RECORDING_TIME = 1413763651; // TDRC + static final int RELATIVE_VOLUME_ADJUSTMENT = 1381384498; // RVA2 + static final int RELEASE_TIME = 1413763660; // TDRL + static final int REVERB = 1381388866; // RVRB + static final int SEEK_FRAME = 1397048651; // SEEK + static final int SET_SUBTITLE = 1414746964; // TSST + static final int SIGNATURE_FRAME = 1397311310; // SIGN + static final int ENCODING_TOOLS_AND_SETTINGS = 1414746949; // TSSE + static final int SUBTITLE = 1414091827; // TIT3 + static final int SYNCHRONISED_LYRIC = 1398361172; // SYLT + static final int SYNCHRONISED_TEMPO_CODES = 1398363203; // SYTC + static final int TAGGING_TIME = 1413764167; // TDTG + static final int TERMS_OF_USE = 1431520594; // USER + static final int TITLE = 1414091826; // TIT2 + static final int TITLE_SORT_ORDER = 1414745940; // TSOT + static final int TRACK_NUMBER = 1414677323; // TRCK + static final int UNIQUE_FILE_IDENTIFIER = 1430669636; // UFID + static final int UNSYNCHRONISED_LYRIC = 1431522388; // USLT + static final int USER_DEFINED_TEXT_INFORMATION_FRAME = 1415075928; // TXXX + static final int USER_DEFINED_URL_LINK_FRAME = 1465407576; // WXXX private static final String[] TEXT_ENCODINGS = {"ISO-8859-1", "UTF-16"/*BOM*/, "UTF-16", "UTF-8"}; private static final String[] VALID_TIMESTAMPS = {"yyyy, yyyy-MM", "yyyy-MM-dd", "yyyy-MM-ddTHH", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss"}; private static final String UNKNOWN_LANGUAGE = "xxx"; @@ -108,13 +108,13 @@ class ID3Frame { if (isInGroup()) groupID = in.read(); if (isEncrypted()) encryptionMethod = in.read(); - //TODO: data length indicator, unsync + // TODO: data length indicator, unsync data = new byte[(int) size]; in.readFully(data); } - //header data + // header data public int getID() { return id; } @@ -143,7 +143,7 @@ public int getEncryptionMethod() { return encryptionMethod; } - //content data + // content data public byte[] getData() { return data; } @@ -153,10 +153,10 @@ public String getText() { } public String getEncodedText() { - //first byte indicates encoding + // first byte indicates encoding int enc = data[0]; - //charsets 0,3 end with '0'; 1,2 end with '00' + // charsets 0,3 end with '0'; 1,2 end with '00' int t = -1; for (int i = 1; i < data.length && t < 0; i++) { if (data[i] == 0 && (enc == 0 || enc == 3 || data[i + 1] == 0)) t = i; @@ -169,7 +169,7 @@ public int getNumber() { } public int[] getNumbers() { - //multiple numbers separated by '/' + // multiple numbers separated by '/' String x = new String(data, Charset.forName(TEXT_ENCODINGS[0])); int i = x.indexOf('/'); int[] y; @@ -179,7 +179,7 @@ public int[] getNumbers() { } public Date getDate() { - //timestamp lengths: 4,7,10,13,16,19 + // timestamp lengths: 4,7,10,13,16,19 int i = (int) Math.floor(data.length / 3f) - 1; Date date; if (i >= 0 && i < VALID_TIMESTAMPS.length) { diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/ID3Tag.java b/src/main/java/net/sourceforge/jaad/mp4/api/ID3Tag.java index 8a42029..b0fe03f 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/ID3Tag.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/ID3Tag.java @@ -9,29 +9,29 @@ class ID3Tag { - private static final int ID3_TAG = 4801587; //'ID3' - private static final int SUPPORTED_VERSION = 4; //id3v2.4 + private static final int ID3_TAG = 4801587; // 'ID3' + private static final int SUPPORTED_VERSION = 4; // id3v2.4 private final List frames; private final int tag, flags, len; ID3Tag(DataInputStream in) throws IOException { frames = new ArrayList<>(); - //id3v2 header - tag = (in.read() << 16) | (in.read() << 8) | in.read(); //'ID3' + // id3v2 header + tag = (in.read() << 16) | (in.read() << 8) | in.read(); // 'ID3' int majorVersion = in.read(); - in.read(); //revision + in.read(); // revision flags = in.read(); len = readSynch(in); if (tag == ID3_TAG && majorVersion <= SUPPORTED_VERSION) { if ((flags & 0x40) == 0x40) { - //extended header; TODO: parse + // extended header; TODO: parse int extSize = readSynch(in); in.skipBytes(extSize - 6); } - //read all id3 frames + // read all id3 frames int left = len; ID3Frame frame; while (left > 0) { diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/MetaData.java b/src/main/java/net/sourceforge/jaad/mp4/api/MetaData.java index 252b26e..4f4894f 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/MetaData.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/MetaData.java @@ -78,7 +78,7 @@ public static class Field { public static final Field GAPLESS_PLAYBACK = new Field<>("Gapless Playback"); public static final Field HD_VIDEO = new Field<>("HD Video"); public static final Field LANGUAGE = new Field<>("Language"); - //sorting + // sorting public static final Field ARTIST_SORT_TEXT = new Field<>("Artist Sort Text"); public static final Field TITLE_SORT_TEXT = new Field<>("Title Sort Text"); public static final Field ALBUM_SORT_TEXT = new Field<>("Album Sort Text"); @@ -95,7 +95,7 @@ public String getName() { private static final String[] STANDARD_GENRES = { "undefined", - //IDv1 standard + // IDv1 standard "blues", "classic rock", "country", @@ -175,7 +175,7 @@ public String getName() { "retro", "musical", "rock and roll", - //winamp extension + // winamp extension "hard rock", "folk", "folk rock", @@ -245,34 +245,34 @@ public String getName() { * ---tshd */ void parse(Box udta, Box meta) { - //standard boxes + // standard boxes if (meta.hasChild(BoxTypes.COPYRIGHT_BOX)) { CopyrightBox cprt = (CopyrightBox) meta.getChild(BoxTypes.COPYRIGHT_BOX); put(Field.LANGUAGE, new Locale(cprt.getLanguageCode())); put(Field.COPYRIGHT, cprt.getNotice()); } - //3gpp user data + // 3gpp user data if (udta != null) parse3GPPData(udta); - //id3, TODO: can be present in different languages + // id3, TODO: can be present in different languages if (meta.hasChild(BoxTypes.ID3_TAG_BOX)) parseID3((ID3TagBox) meta.getChild(BoxTypes.ID3_TAG_BOX)); - //itunes + // itunes if (meta.hasChild(BoxTypes.ITUNES_META_LIST_BOX)) parseITunesMetaData(meta.getChild(BoxTypes.ITUNES_META_LIST_BOX)); - //nero tags + // nero tags if (meta.hasChild(BoxTypes.NERO_METADATA_TAGS_BOX)) parseNeroTags((NeroMetadataTagsBox) meta.getChild(BoxTypes.NERO_METADATA_TAGS_BOX)); } - //parses specific children of 'udta': 3GPP - //TODO: handle language codes + // parses specific children of 'udta': 3GPP + // TODO: handle language codes private void parse3GPPData(Box udta) { if (udta.hasChild(BoxTypes.THREE_GPP_ALBUM_BOX)) { ThreeGPPAlbumBox albm = (ThreeGPPAlbumBox) udta.getChild(BoxTypes.THREE_GPP_ALBUM_BOX); put(Field.ALBUM, albm.getData()); put(Field.TRACK_NUMBER, albm.getTrackNumber()); } - //if(udta.hasChild(BoxTypes.THREE_GPP_AUTHOR_BOX)); - //if(udta.hasChild(BoxTypes.THREE_GPP_CLASSIFICATION_BOX)); +// if (udta.hasChild(BoxTypes.THREE_GPP_AUTHOR_BOX)) ; +// if (udta.hasChild(BoxTypes.THREE_GPP_CLASSIFICATION_BOX)) ; if (udta.hasChild(BoxTypes.THREE_GPP_DESCRIPTION_BOX)) put(Field.DESCRIPTION, ((ThreeGPPMetadataBox) udta.getChild(BoxTypes.THREE_GPP_DESCRIPTION_BOX)).getData()); if (udta.hasChild(BoxTypes.THREE_GPP_KEYWORDS_BOX)) @@ -293,7 +293,7 @@ private void parse3GPPData(Box udta) { put(Field.TITLE, ((ThreeGPPMetadataBox) udta.getChild(BoxTypes.THREE_GPP_TITLE_BOX)).getData()); } - //parses children of 'ilst': iTunes + // parses children of 'ilst': iTunes private void parseITunesMetaData(Box ilst) { List boxes = ilst.getChildren(); long l; @@ -309,7 +309,7 @@ private void parseITunesMetaData(Box ilst) { else if (l == BoxTypes.TRACK_NUMBER_BOX) { byte[] b = data.getData(); put(Field.TRACK_NUMBER, (int) b[3]); - put(Field.TOTAL_TRACKS, new Integer(b[5])); + put(Field.TOTAL_TRACKS, (int) b[5]); } else if (l == BoxTypes.DISK_NUMBER_BOX) put(Field.DISK_NUMBER, data.getInteger()); else if (l == BoxTypes.COMPOSER_NAME_BOX) put(Field.COMPOSER, data.getText()); else if (l == BoxTypes.COMMENTS_BOX) put(Field.COMMENTS, data.getText()); @@ -358,7 +358,7 @@ else if (l == BoxTypes.COVER_BOX) { } } - //parses children of ID3 + // parses children of ID3 private void parseID3(ID3TagBox box) { try { DataInputStream in = new DataInputStream(new ByteArrayInputStream(box.getID3Data())); @@ -426,7 +426,7 @@ private void parseID3(ID3TagBox box) { } } - //parses children of 'tags': Nero + // parses children of 'tags': Nero private void parseNeroTags(NeroMetadataTagsBox tags) { Map pairs = tags.getPairs(); String val; @@ -446,16 +446,16 @@ private void parseNeroTags(NeroMetadataTagsBox tags) { if (key.equals(NERO_TAGS[6])) put(Field.GENRE, val); if (key.equals(NERO_TAGS[7])) put(Field.DISK_NUMBER, Integer.parseInt(val)); if (key.equals(NERO_TAGS[8])) put(Field.TOTAL_DISKS, Integer.parseInt(val)); - if (key.equals(NERO_TAGS[9])) ; //url + if (key.equals(NERO_TAGS[9])) ; // url if (key.equals(NERO_TAGS[10])) put(Field.COPYRIGHT, val); if (key.equals(NERO_TAGS[11])) put(Field.COMMENTS, val); if (key.equals(NERO_TAGS[12])) put(Field.LYRICS, val); - if (key.equals(NERO_TAGS[13])) ; //credits + if (key.equals(NERO_TAGS[13])) ; // credits if (key.equals(NERO_TAGS[14])) put(Field.RATING, Integer.parseInt(val)); if (key.equals(NERO_TAGS[15])) put(Field.PUBLISHER, val); if (key.equals(NERO_TAGS[16])) put(Field.COMPOSER, val); - if (key.equals(NERO_TAGS[17])) ; //isrc - if (key.equals(NERO_TAGS[18])) ; //mood + if (key.equals(NERO_TAGS[17])) ; // isrc + if (key.equals(NERO_TAGS[18])) ; // mood if (key.equals(NERO_TAGS[19])) put(Field.TEMPO, Integer.parseInt(val)); } catch (NumberFormatException e) { Logger.getLogger("MP4 API").log(Level.SEVERE, "Exception in MetaData.parseNeroTags: {0}", e.toString()); diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/Movie.java b/src/main/java/net/sourceforge/jaad/mp4/api/Movie.java index 7a2aab2..330f45e 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/Movie.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/Movie.java @@ -24,7 +24,7 @@ public class Movie { public Movie(Box moov, MP4Input in) { this.in = in; - //create tracks + // create tracks mvhd = (MovieHeaderBox) moov.getChild(BoxTypes.MOVIE_HEADER_BOX); List trackBoxes = moov.getChildren(BoxTypes.TRACK_BOX); tracks = new ArrayList<>(trackBoxes.size()); @@ -34,7 +34,7 @@ public Movie(Box moov, MP4Input in) { if (track != null) tracks.add(track); } - //read metadata: moov.meta/moov.udta.meta + // read metadata: moov.meta/moov.udta.meta metaData = new MetaData(); if (moov.hasChild(BoxTypes.META_BOX)) metaData.parse(null, moov.getChild(BoxTypes.META_BOX)); else if (moov.hasChild(BoxTypes.USER_DATA_BOX)) { @@ -42,7 +42,7 @@ else if (moov.hasChild(BoxTypes.USER_DATA_BOX)) { if (udta.hasChild(BoxTypes.META_BOX)) metaData.parse(udta, udta.getChild(BoxTypes.META_BOX)); } - //detect DRM + // detect DRM protections = new ArrayList<>(); if (moov.hasChild(BoxTypes.ITEM_PROTECTION_BOX)) { Box ipro = moov.getChild(BoxTypes.ITEM_PROTECTION_BOX); @@ -139,7 +139,7 @@ public List getProtections() { return Collections.unmodifiableList(protections); } - //mvhd + // mvhd /** * Returns the time this movie was created. diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/Protection.java b/src/main/java/net/sourceforge/jaad/mp4/api/Protection.java index cc1abae..c283756 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/Protection.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/Protection.java @@ -39,10 +39,10 @@ static Protection parse(Box sinf) { private final Codec originalFormat; protected Protection(Box sinf) { - //original format + // original format long type = ((OriginalFormatBox) sinf.getChild(BoxTypes.ORIGINAL_FORMAT_BOX)).getOriginalFormat(); Codec c; - //TODO: currently it tests for audio and video codec, can do this any other way? + // TODO: currently it tests for audio and video codec, can do this any other way? if (!(c = AudioTrack.AudioCodec.forType(type)).equals(AudioTrack.AudioCodec.UNKNOWN_AUDIO_CODEC)) originalFormat = c; else if (!(c = VideoTrack.VideoCodec.forType(type)).equals(VideoTrack.VideoCodec.UNKNOWN_VIDEO_CODEC)) @@ -56,7 +56,7 @@ Codec getOriginalFormat() { public abstract Scheme getScheme(); - //default implementation for unknown protection schemes + // default implementation for unknown protection schemes private static class UnknownProtection extends Protection { UnknownProtection(Box sinf) { diff --git a/src/main/java/net/sourceforge/jaad/mp4/api/Track.java b/src/main/java/net/sourceforge/jaad/mp4/api/Track.java index 0fb514b..2302d3c 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/api/Track.java +++ b/src/main/java/net/sourceforge/jaad/mp4/api/Track.java @@ -37,11 +37,11 @@ * * @author in-somnia */ -//TODO: expand javadoc; use generics for subclasses? +// TODO: expand javadoc; use generics for subclasses? public abstract class Track { public interface Codec { - //TODO: currently only marker interface + // TODO: currently only marker interface } private final MP4Input in; @@ -51,7 +51,7 @@ public interface Codec { private final List frames; private URL location; private int currentFrame; - //info structures + // info structures protected DecoderSpecificInfo decoderSpecificInfo; protected DecoderInfo decoderInfo; protected Protection protection; @@ -67,7 +67,7 @@ public interface Codec { Box dinf = minf.getChild(BoxTypes.DATA_INFORMATION_BOX); DataReferenceBox dref = (DataReferenceBox) dinf.getChild(BoxTypes.DATA_REFERENCE_BOX); - //TODO: support URNs + // TODO: support URNs if (dref.hasChild(BoxTypes.DATA_ENTRY_URL_BOX)) { DataEntryUrlBox url = (DataEntryUrlBox) dref.getChild(BoxTypes.DATA_ENTRY_URL_BOX); inFile = url.isInFile(); @@ -90,7 +90,7 @@ public interface Codec { location = null; } - //sample table + // sample table Box stbl = minf.getChild(BoxTypes.SAMPLE_TABLE_BOX); if (stbl.hasChildren()) { frames = new ArrayList<>(); @@ -103,21 +103,21 @@ private void parseSampleTable(Box stbl) { double timeScale = mdhd.getTimeScale(); Type type = getType(); - //sample sizes + // sample sizes long[] sampleSizes = ((SampleSizeBox) stbl.getChild(BoxTypes.SAMPLE_SIZE_BOX)).getSampleSizes(); - //chunk offsets + // chunk offsets ChunkOffsetBox stco; if (stbl.hasChild(BoxTypes.CHUNK_OFFSET_BOX)) stco = (ChunkOffsetBox) stbl.getChild(BoxTypes.CHUNK_OFFSET_BOX); else stco = (ChunkOffsetBox) stbl.getChild(BoxTypes.CHUNK_LARGE_OFFSET_BOX); long[] chunkOffsets = stco.getChunks(); - //samples to chunks + // samples to chunks SampleToChunkBox stsc = ((SampleToChunkBox) stbl.getChild(BoxTypes.SAMPLE_TO_CHUNK_BOX)); long[] firstChunks = stsc.getFirstChunks(); long[] samplesPerChunk = stsc.getSamplesPerChunk(); - //sample durations/timestamps + // sample durations/timestamps DecodingTimeToSampleBox stts = (DecodingTimeToSampleBox) stbl.getChild(BoxTypes.DECODING_TIME_TO_SAMPLE_BOX); long[] sampleCounts = stts.getSampleCounts(); long[] sampleDeltas = stts.getSampleDeltas(); @@ -129,26 +129,26 @@ private void parseSampleTable(Box stbl) { timeOffsets[off + j] = tmp; tmp += sampleDeltas[i]; } - off += sampleCounts[i]; + off = (int) (off + sampleCounts[i]); } - //create samples + // create samples int current = 0; int lastChunk; double timeStamp; long offset = 0; - //iterate over all chunk groups + // iterate over all chunk groups for (int i = 0; i < firstChunks.length; i++) { if (i < firstChunks.length - 1) lastChunk = (int) firstChunks[i + 1] - 1; else lastChunk = chunkOffsets.length; - //iterate over all chunks in current group + // iterate over all chunks in current group for (int j = (int) firstChunks[i] - 1; j < lastChunk; j++) { offset = chunkOffsets[j]; - //iterate over all samples in current chunk + // iterate over all samples in current chunk for (int k = 0; k < samplesPerChunk[i]; k++) { - //create samples + // create samples timeStamp = ((double) timeOffsets[current]) / timeScale; frames.add(new Frame(type, offset, sampleSizes[current], timeStamp)); offset += sampleSizes[current]; @@ -157,12 +157,12 @@ private void parseSampleTable(Box stbl) { } } - //frames need not to be time-ordered: sort by timestamp - //TODO: is it possible to add them to the specific position? + // frames need not to be time-ordered: sort by timestamp + // TODO: is it possible to add them to the specific position? Collections.sort(frames); } - //TODO: implement other entry descriptors + // TODO: implement other entry descriptors protected void findDecoderSpecificInfo(ESDBox esds) { Descriptor ed = esds.getEntryDescriptor(); List children = ed.getChildren(); @@ -196,7 +196,7 @@ protected void parseSampleEntry(Box sampleEntry, Class clazz) { public abstract Codec getCodec(); - //tkhd + // tkhd /** * Returns true if the track is enabled. A disabled track is treated as if @@ -244,7 +244,7 @@ public Date getModificationTime() { return Utils.getDate(tkhd.getModificationTime()); } - //mdhd + // mdhd /** * Returns the language for this media. @@ -277,7 +277,7 @@ public URL getLocation() { return location; } - //info structures + // info structures /** * Returns the decoder specific info, if present. It contains configuration @@ -315,7 +315,7 @@ public Protection getProtection() { return protection; } - //reading + // reading /** * Indicates if there are more frames to be read in this track. @@ -370,7 +370,7 @@ else if (diff < 0) { * @return the frame's timestamp that the method seeked to */ public double seek(double timestamp) { - //find first frame > timestamp + // find first frame > timestamp Frame frame = null; for (int i = 0; i < frames.size(); i++) { frame = frames.get(i++); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxFactory.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxFactory.java index c74ffe3..3a95d32 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxFactory.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxFactory.java @@ -64,7 +64,7 @@ public class BoxFactory implements BoxTypes { private static final Map PARAMETER = new HashMap<>(); static { - //classes + // classes BOX_CLASSES.put(ADDITIONAL_METADATA_CONTAINER_BOX, BoxImpl.class); BOX_CLASSES.put(APPLE_LOSSLESS_BOX, AppleLosslessBox.class); BOX_CLASSES.put(BINARY_XML_BOX, BinaryXMLBox.class); @@ -266,7 +266,7 @@ public class BoxFactory implements BoxTypes { BOX_CLASSES.put(FAIRPLAY_USER_KEY_BOX, FairPlayDataBox.class); BOX_CLASSES.put(FAIRPLAY_IV_BOX, FairPlayDataBox.class); BOX_CLASSES.put(FAIRPLAY_PRIVATE_KEY_BOX, FairPlayDataBox.class); - //parameter + // parameter PARAMETER.put(ADDITIONAL_METADATA_CONTAINER_BOX, new String[] {"Additional Metadata Container Box"}); PARAMETER.put(DATA_INFORMATION_BOX, new String[] {"Data Information Box"}); PARAMETER.put(EDIT_BOX, new String[] {"Edit Box"}); @@ -377,9 +377,9 @@ public static Box parseBox(Box parent, long offset, long size, long type, MP4Inp if (type == EXTENDED_TYPE) in.skipBytes(16); -LOGGER.finest("type: " + typeToString(type) + ", " + size); + LOGGER.finest("type: " + typeToString(type) + ", " + size); - //error protection + // error protection if (parent != null) { long parentLeft = (parent.getOffset() + parent.getSize()) - offset; if (size > parentLeft) @@ -391,11 +391,11 @@ public static Box parseBox(Box parent, long offset, long size, long type, MP4Inp box.setParams(parent, size, type, offset); box.decode(in); - //if box doesn't contain data it only contains children + // if box doesn't contain data it only contains children Class cl = box.getClass(); if (cl == BoxImpl.class || cl == FullBox.class) box.readChildren(in); - //check bytes left + // check bytes left long left = (box.getOffset() + box.getSize()) - in.getOffset(); if (left > 0 && !(box instanceof MediaDataBox) @@ -405,7 +405,7 @@ public static Box parseBox(Box parent, long offset, long size, long type, MP4Inp else if (left < 0) LOGGER.log(Level.SEVERE, "box {0} overread: {1} bytes, offset: {2}", new Object[] {typeToString(type), -left, in.getOffset()}); - //if mdat found and no random access, don't skip + // if mdat found and no random access, don't skip if (box.getType() != MEDIA_DATA_BOX || in.hasRandomAccess()) in.skipBytes(left); return box; } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxImpl.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxImpl.java index 640749a..375f7c8 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxImpl.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxImpl.java @@ -42,22 +42,27 @@ protected long getLeft(MP4Input in) throws IOException { public void decode(MP4Input in) throws IOException { } + @Override public long getType() { return type; } + @Override public long getSize() { return size; } + @Override public long getOffset() { return offset; } + @Override public Box getParent() { return parent; } + @Override public String getName() { return name; } @@ -67,11 +72,13 @@ public String toString() { return name + " [" + BoxFactory.typeToString(type) + "]"; } - //container methods + // container methods + @Override public boolean hasChildren() { return children.size() > 0; } + @Override public boolean hasChild(long type) { boolean b = false; for (Box box : children) { @@ -83,6 +90,7 @@ public boolean hasChild(long type) { return b; } + @Override public Box getChild(long type) { Box box = null, b = null; int i = 0; @@ -94,10 +102,12 @@ public Box getChild(long type) { return box; } + @Override public List getChildren() { return Collections.unmodifiableList(children); } + @Override public List getChildren(long type) { List l = new ArrayList<>(); for (Box box : children) { diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxTypes.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxTypes.java index fee2aa9..5bea928 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxTypes.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/BoxTypes.java @@ -7,218 +7,218 @@ public interface BoxTypes { Logger LOGGER = Logger.getLogger(BoxTypes.class.getName()); - long EXTENDED_TYPE = 1970628964; //uuid - //standard boxes (ISO BMFF) - long ADDITIONAL_METADATA_CONTAINER_BOX = 1835361135L; //meco - long APPLE_LOSSLESS_BOX = 1634492771L; //alac - long BINARY_XML_BOX = 1652059500L; //bxml - long BIT_RATE_BOX = 1651798644L; //btrt - long CHAPTER_BOX = 1667788908L; //chpl - long CHUNK_OFFSET_BOX = 1937007471L; //stco - long CHUNK_LARGE_OFFSET_BOX = 1668232756L; //co64 - long CLEAN_APERTURE_BOX = 1668047216L; //clap - long COMPACT_SAMPLE_SIZE_BOX = 1937013298L; //stz2 - long COMPOSITION_TIME_TO_SAMPLE_BOX = 1668576371L; //ctts - long COPYRIGHT_BOX = 1668313716L; //cprt - long DATA_ENTRY_URN_BOX = 1970433568L; //urn - long DATA_ENTRY_URL_BOX = 1970433056L; //url - long DATA_INFORMATION_BOX = 1684631142L; //dinf - long DATA_REFERENCE_BOX = 1685218662L; //dref - long DECODING_TIME_TO_SAMPLE_BOX = 1937011827L; //stts - long DEGRADATION_PRIORITY_BOX = 1937007728L; //stdp - long EDIT_BOX = 1701082227L; //edts - long EDIT_LIST_BOX = 1701606260L; //elst - long FD_ITEM_INFORMATION_BOX = 1718184302L; //fiin - long FD_SESSION_GROUP_BOX = 1936025458L; //segr - long FEC_RESERVOIR_BOX = 1717920626L; //fecr - long FILE_PARTITION_BOX = 1718641010L; //fpar - long FILE_TYPE_BOX = 1718909296L; //ftyp - long FREE_SPACE_BOX = 1718773093L; //free - long GROUP_ID_TO_NAME_BOX = 1734964334L; //gitn - long HANDLER_BOX = 1751411826L; //hdlr - long HINT_MEDIA_HEADER_BOX = 1752000612L; //hmhd - long IPMP_CONTROL_BOX = 1768975715L; //ipmc - long IPMP_INFO_BOX = 1768778086L; //imif - long ITEM_INFORMATION_BOX = 1768517222L; //iinf - long ITEM_INFORMATION_ENTRY = 1768842853L; //infe - long ITEM_LOCATION_BOX = 1768714083L; //iloc - long ITEM_PROTECTION_BOX = 1768977007L; //ipro - long MEDIA_BOX = 1835297121L; //mdia - long MEDIA_DATA_BOX = 1835295092L; //mdat - long MEDIA_HEADER_BOX = 1835296868L; //mdhd - long MEDIA_INFORMATION_BOX = 1835626086L; //minf - long META_BOX = 1835365473L; //meta - long META_BOX_RELATION_BOX = 1835364965L; //mere - long MOVIE_BOX = 1836019574L; //moov - long MOVIE_EXTENDS_BOX = 1836475768L; //mvex - long MOVIE_EXTENDS_HEADER_BOX = 1835362404L; //mehd - long MOVIE_FRAGMENT_BOX = 1836019558L; //moof - long MOVIE_FRAGMENT_HEADER_BOX = 1835427940L; //mfhd - long MOVIE_FRAGMENT_RANDOM_ACCESS_BOX = 1835430497L; //mfra - long MOVIE_FRAGMENT_RANDOM_ACCESS_OFFSET_BOX = 1835430511L; //mfro - long MOVIE_HEADER_BOX = 1836476516L; //mvhd - long NERO_METADATA_TAGS_BOX = 1952540531L; //tags - long NULL_MEDIA_HEADER_BOX = 1852663908L; //nmhd - long ORIGINAL_FORMAT_BOX = 1718775137L; //frma - long PADDING_BIT_BOX = 1885430882L; //padb - long PARTITION_ENTRY = 1885431150L; //paen - long PIXEL_ASPECT_RATIO_BOX = 1885434736L; //pasp - long PRIMARY_ITEM_BOX = 1885959277L; //pitm - long PROGRESSIVE_DOWNLOAD_INFORMATION_BOX = 1885628782L; //pdin - long PROTECTION_SCHEME_INFORMATION_BOX = 1936289382L; //sinf - long SAMPLE_DEPENDENCY_TYPE_BOX = 1935963248L; //sdtp - long SAMPLE_DESCRIPTION_BOX = 1937011556L; //stsd - long SAMPLE_GROUP_DESCRIPTION_BOX = 1936158820L; //sgpd - long SAMPLE_SCALE_BOX = 1937011564L; //stsl - long SAMPLE_SIZE_BOX = 1937011578L; //stsz - long SAMPLE_TABLE_BOX = 1937007212L; //stbl - long SAMPLE_TO_CHUNK_BOX = 1937011555L; //stsc - long SAMPLE_TO_GROUP_BOX = 1935828848L; //sbgp - long SCHEME_TYPE_BOX = 1935894637L; //schm - long SCHEME_INFORMATION_BOX = 1935894633L; //schi - long SHADOW_SYNC_SAMPLE_BOX = 1937011560L; //stsh - long SKIP_BOX = 1936419184L; //skip - long SOUND_MEDIA_HEADER_BOX = 1936549988L; //smhd - long SUB_SAMPLE_INFORMATION_BOX = 1937072755L; //subs - long SYNC_SAMPLE_BOX = 1937011571L; //stss - long TRACK_BOX = 1953653099L; //trak - long TRACK_EXTENDS_BOX = 1953654136L; //trex - long TRACK_FRAGMENT_BOX = 1953653094L; //traf - long TRACK_FRAGMENT_HEADER_BOX = 1952868452L; //tfhd - long TRACK_FRAGMENT_RANDOM_ACCESS_BOX = 1952871009L; //tfra - long TRACK_FRAGMENT_RUN_BOX = 1953658222L; //trun - long TRACK_HEADER_BOX = 1953196132L; //tkhd - long TRACK_REFERENCE_BOX = 1953654118L; //tref - long TRACK_SELECTION_BOX = 1953719660L; //tsel - long USER_DATA_BOX = 1969517665L; //udta - long VIDEO_MEDIA_HEADER_BOX = 1986881636L; //vmhd - long WIDE_BOX = 2003395685L; //wide - long XML_BOX = 2020437024L; //xml - //mp4 extension - long OBJECT_DESCRIPTOR_BOX = 1768907891L; //iods - long SAMPLE_DEPENDENCY_BOX = 1935959408L; //sdep - //metadata: id3 - long ID3_TAG_BOX = 1768174386L; //id32 - //metadata: itunes - long ITUNES_META_LIST_BOX = 1768715124L; //ilst - long CUSTOM_ITUNES_METADATA_BOX = 757935405L; //---- - long ITUNES_METADATA_BOX = 1684108385L; //data - long ITUNES_METADATA_NAME_BOX = 1851878757L; //name - long ITUNES_METADATA_MEAN_BOX = 1835360622L; //mean - long ALBUM_ARTIST_NAME_BOX = 1631670868L; //aART - long ALBUM_ARTIST_SORT_BOX = 1936679265L; //soaa - long ALBUM_NAME_BOX = 2841734242L; //©alb - long ALBUM_SORT_BOX = 1936679276L; //soal - long ARTIST_NAME_BOX = 2839630420L; //©ART - long ARTIST_SORT_BOX = 1936679282L; //soar - long CATEGORY_BOX = 1667331175L; //catg - long COMMENTS_BOX = 2841865588L; //©cmt - long COMPILATION_PART_BOX = 1668311404L; //cpil - long COMPOSER_NAME_BOX = 2843177588L; //©wrt - long COMPOSER_SORT_BOX = 1936679791L; //soco - long COVER_BOX = 1668249202L; //covr - long CUSTOM_GENRE_BOX = 2842125678L; //©gen - long DESCRIPTION_BOX = 1684370275L; //desc - long DISK_NUMBER_BOX = 1684632427L; //disk - long ENCODER_NAME_BOX = 2841996899L; //©enc - long ENCODER_TOOL_BOX = 2842980207L; //©too - long EPISODE_GLOBAL_UNIQUE_ID_BOX = 1701276004L; //egid - long GAPLESS_PLAYBACK_BOX = 1885823344L; //pgap - long GENRE_BOX = 1735291493L; //gnre - long GROUPING_BOX = 2842129008L; //©grp - long HD_VIDEO_BOX = 1751414372L; //hdvd - long ITUNES_PURCHASE_ACCOUNT_BOX = 1634748740L; //apID - long ITUNES_ACCOUNT_TYPE_BOX = 1634421060L; //akID - long ITUNES_CATALOGUE_ID_BOX = 1668172100L; //cnID - long ITUNES_COUNTRY_CODE_BOX = 1936083268L; //sfID - long KEYWORD_BOX = 1801812343L; //keyw - long LONG_DESCRIPTION_BOX = 1818518899L; //ldes - long LYRICS_BOX = 2842458482L; //©lyr - long META_TYPE_BOX = 1937009003L; //stik - long PODCAST_BOX = 1885565812L; //pcst - long PODCAST_URL_BOX = 1886745196L; //purl - long PURCHASE_DATE_BOX = 1886745188L; //purd - long RATING_BOX = 1920233063L; //rtng - long RELEASE_DATE_BOX = 2841928057L; //©day - long REQUIREMENT_BOX = 2842846577L; //©req - long TEMPO_BOX = 1953329263L; //tmpo - long TRACK_NAME_BOX = 2842583405L; //©nam - long TRACK_NUMBER_BOX = 1953655662L; //trkn - long TRACK_SORT_BOX = 1936682605L; //sonm - long TV_EPISODE_BOX = 1953916275L; //tves - long TV_EPISODE_NUMBER_BOX = 1953916270L; //tven - long TV_NETWORK_NAME_BOX = 1953918574L; //tvnn - long TV_SEASON_BOX = 1953919854L; //tvsn - long TV_SHOW_BOX = 1953919848L; //tvsh - long TV_SHOW_SORT_BOX = 1936683886L; //sosn - //metadata: 3gpp - long THREE_GPP_ALBUM_BOX = 1634493037L; //albm - long THREE_GPP_AUTHOR_BOX = 1635087464L; //auth - long THREE_GPP_CLASSIFICATION_BOX = 1668051814L; //clsf - long THREE_GPP_DESCRIPTION_BOX = 1685283696L; //dscp - long THREE_GPP_KEYWORDS_BOX = 1803122532L; //kywd - long THREE_GPP_LOCATION_INFORMATION_BOX = 1819239273L; //loci - long THREE_GPP_PERFORMER_BOX = 1885696614L; //perf - long THREE_GPP_RECORDING_YEAR_BOX = 2037543523L; //yrrc - long THREE_GPP_TITLE_BOX = 1953068140L; //titl - //metadata: google/youtube - long GOOGLE_HOST_HEADER_BOX = 1735616616L; //gshh - long GOOGLE_PING_MESSAGE_BOX = 1735618669L; //gspm - long GOOGLE_PING_URL_BOX = 1735618677L; //gspu - long GOOGLE_SOURCE_DATA_BOX = 1735619428L; //gssd - long GOOGLE_START_TIME_BOX = 1735619444L; //gsst - long GOOGLE_TRACK_DURATION_BOX = 1735619684L; //gstd - //sample entries - long MP4V_SAMPLE_ENTRY = 1836070006L; //mp4v - long H263_SAMPLE_ENTRY = 1932670515L; //s263 - long ENCRYPTED_VIDEO_SAMPLE_ENTRY = 1701733238L; //encv - long AVC_SAMPLE_ENTRY = 1635148593L; //avc1 - long MP4A_SAMPLE_ENTRY = 1836069985L; //mp4a - long AC3_SAMPLE_ENTRY = 1633889587L; //ac-3 - long EAC3_SAMPLE_ENTRY = 1700998451L; //ec-3 - long DRMS_SAMPLE_ENTRY = 1685220723L; //drms - long AMR_SAMPLE_ENTRY = 1935764850L; //samr - long AMR_WB_SAMPLE_ENTRY = 1935767394L; //sawb - long EVRC_SAMPLE_ENTRY = 1936029283L; //sevc - long QCELP_SAMPLE_ENTRY = 1936810864L; //sqcp - long SMV_SAMPLE_ENTRY = 1936944502L; //ssmv - long ENCRYPTED_AUDIO_SAMPLE_ENTRY = 1701733217L; //enca - long MPEG_SAMPLE_ENTRY = 1836070003L; //mp4s - long TEXT_METADATA_SAMPLE_ENTRY = 1835365492L; //mett - long XML_METADATA_SAMPLE_ENTRY = 1835365496L; //metx - long RTP_HINT_SAMPLE_ENTRY = 1920233504L; //rtp - long FD_HINT_SAMPLE_ENTRY = 1717858336L; //fdp - //codec infos - long ESD_BOX = 1702061171L; //esds - //video codecs - long H263_SPECIFIC_BOX = 1681012275L; //d263 - long AVC_SPECIFIC_BOX = 1635148611L; //avcC - //audio codecs - long AC3_SPECIFIC_BOX = 1684103987L; //dac3 - long EAC3_SPECIFIC_BOX = 1684366131L; //dec3 - long AMR_SPECIFIC_BOX = 1684106610L; //damr - long EVRC_SPECIFIC_BOX = 1684371043L; //devc - long QCELP_SPECIFIC_BOX = 1685152624L; //dqcp - long SMV_SPECIFIC_BOX = 1685286262L; //dsmv - //OMA DRM - long OMA_ACCESS_UNIT_FORMAT_BOX = 1868849510L; //odaf - long OMA_COMMON_HEADERS_BOX = 1869112434L; //ohdr - long OMA_CONTENT_ID_BOX = 1667459428L; //ccid - long OMA_CONTENT_OBJECT_BOX = 1868850273L; //odda - long OMA_COVER_URI_BOX = 1668706933L; //cvru - long OMA_DISCRETE_MEDIA_HEADERS_BOX = 1868851301L; //odhe - long OMA_DRM_CONTAINER_BOX = 1868853869L; //odrm - long OMA_ICON_URI_BOX = 1768124021L; //icnu - long OMA_INFO_URL_BOX = 1768842869L; //infu - long OMA_LYRICS_URI_BOX = 1819435893L; //lrcu - long OMA_MUTABLE_DRM_INFORMATION_BOX = 1835299433L; //mdri - long OMA_KEY_MANAGEMENT_BOX = 1868852077L; //odkm - long OMA_RIGHTS_OBJECT_BOX = 1868853858L; //odrb - long OMA_TRANSACTION_TRACKING_BOX = 1868854388L; //odtt - //iTunes DRM (FairPlay) - long FAIRPLAY_USER_ID_BOX = 1970496882L; //user - long FAIRPLAY_USER_NAME_BOX = 1851878757L; //name - long FAIRPLAY_USER_KEY_BOX = 1801812256L; //key - long FAIRPLAY_IV_BOX = 1769367926L; //iviv - long FAIRPLAY_PRIVATE_KEY_BOX = 1886546294L; //priv + long EXTENDED_TYPE = 1970628964; // uuid + // standard boxes (ISO BMFF) + long ADDITIONAL_METADATA_CONTAINER_BOX = 1835361135L; // meco + long APPLE_LOSSLESS_BOX = 1634492771L; // alac + long BINARY_XML_BOX = 1652059500L; // bxml + long BIT_RATE_BOX = 1651798644L; // btrt + long CHAPTER_BOX = 1667788908L; // chpl + long CHUNK_OFFSET_BOX = 1937007471L; // stco + long CHUNK_LARGE_OFFSET_BOX = 1668232756L; // co64 + long CLEAN_APERTURE_BOX = 1668047216L; // clap + long COMPACT_SAMPLE_SIZE_BOX = 1937013298L; // stz2 + long COMPOSITION_TIME_TO_SAMPLE_BOX = 1668576371L; // ctts + long COPYRIGHT_BOX = 1668313716L; // cprt + long DATA_ENTRY_URN_BOX = 1970433568L; // urn + long DATA_ENTRY_URL_BOX = 1970433056L; // url + long DATA_INFORMATION_BOX = 1684631142L; // dinf + long DATA_REFERENCE_BOX = 1685218662L; // dref + long DECODING_TIME_TO_SAMPLE_BOX = 1937011827L; // stts + long DEGRADATION_PRIORITY_BOX = 1937007728L; // stdp + long EDIT_BOX = 1701082227L; // edts + long EDIT_LIST_BOX = 1701606260L; // elst + long FD_ITEM_INFORMATION_BOX = 1718184302L; // fiin + long FD_SESSION_GROUP_BOX = 1936025458L; // segr + long FEC_RESERVOIR_BOX = 1717920626L; // fecr + long FILE_PARTITION_BOX = 1718641010L; // fpar + long FILE_TYPE_BOX = 1718909296L; // ftyp + long FREE_SPACE_BOX = 1718773093L; // free + long GROUP_ID_TO_NAME_BOX = 1734964334L; // gitn + long HANDLER_BOX = 1751411826L; // hdlr + long HINT_MEDIA_HEADER_BOX = 1752000612L; // hmhd + long IPMP_CONTROL_BOX = 1768975715L; // ipmc + long IPMP_INFO_BOX = 1768778086L; // imif + long ITEM_INFORMATION_BOX = 1768517222L; // iinf + long ITEM_INFORMATION_ENTRY = 1768842853L; // infe + long ITEM_LOCATION_BOX = 1768714083L; // iloc + long ITEM_PROTECTION_BOX = 1768977007L; // ipro + long MEDIA_BOX = 1835297121L; // mdia + long MEDIA_DATA_BOX = 1835295092L; // mdat + long MEDIA_HEADER_BOX = 1835296868L; // mdhd + long MEDIA_INFORMATION_BOX = 1835626086L; // minf + long META_BOX = 1835365473L; // meta + long META_BOX_RELATION_BOX = 1835364965L; // mere + long MOVIE_BOX = 1836019574L; // moov + long MOVIE_EXTENDS_BOX = 1836475768L; // mvex + long MOVIE_EXTENDS_HEADER_BOX = 1835362404L; // mehd + long MOVIE_FRAGMENT_BOX = 1836019558L; // moof + long MOVIE_FRAGMENT_HEADER_BOX = 1835427940L; // mfhd + long MOVIE_FRAGMENT_RANDOM_ACCESS_BOX = 1835430497L; // mfra + long MOVIE_FRAGMENT_RANDOM_ACCESS_OFFSET_BOX = 1835430511L; // mfro + long MOVIE_HEADER_BOX = 1836476516L; // mvhd + long NERO_METADATA_TAGS_BOX = 1952540531L; // tags + long NULL_MEDIA_HEADER_BOX = 1852663908L; // nmhd + long ORIGINAL_FORMAT_BOX = 1718775137L; // frma + long PADDING_BIT_BOX = 1885430882L; // padb + long PARTITION_ENTRY = 1885431150L; // paen + long PIXEL_ASPECT_RATIO_BOX = 1885434736L; // pasp + long PRIMARY_ITEM_BOX = 1885959277L; // pitm + long PROGRESSIVE_DOWNLOAD_INFORMATION_BOX = 1885628782L; // pdin + long PROTECTION_SCHEME_INFORMATION_BOX = 1936289382L; // sinf + long SAMPLE_DEPENDENCY_TYPE_BOX = 1935963248L; // sdtp + long SAMPLE_DESCRIPTION_BOX = 1937011556L; // stsd + long SAMPLE_GROUP_DESCRIPTION_BOX = 1936158820L; // sgpd + long SAMPLE_SCALE_BOX = 1937011564L; // stsl + long SAMPLE_SIZE_BOX = 1937011578L; // stsz + long SAMPLE_TABLE_BOX = 1937007212L; // stbl + long SAMPLE_TO_CHUNK_BOX = 1937011555L; // stsc + long SAMPLE_TO_GROUP_BOX = 1935828848L; // sbgp + long SCHEME_TYPE_BOX = 1935894637L; // schm + long SCHEME_INFORMATION_BOX = 1935894633L; // schi + long SHADOW_SYNC_SAMPLE_BOX = 1937011560L; // stsh + long SKIP_BOX = 1936419184L; // skip + long SOUND_MEDIA_HEADER_BOX = 1936549988L; // smhd + long SUB_SAMPLE_INFORMATION_BOX = 1937072755L; // subs + long SYNC_SAMPLE_BOX = 1937011571L; // stss + long TRACK_BOX = 1953653099L; // trak + long TRACK_EXTENDS_BOX = 1953654136L; // trex + long TRACK_FRAGMENT_BOX = 1953653094L; // traf + long TRACK_FRAGMENT_HEADER_BOX = 1952868452L; // tfhd + long TRACK_FRAGMENT_RANDOM_ACCESS_BOX = 1952871009L; // tfra + long TRACK_FRAGMENT_RUN_BOX = 1953658222L; // trun + long TRACK_HEADER_BOX = 1953196132L; // tkhd + long TRACK_REFERENCE_BOX = 1953654118L; // tref + long TRACK_SELECTION_BOX = 1953719660L; // tsel + long USER_DATA_BOX = 1969517665L; // udta + long VIDEO_MEDIA_HEADER_BOX = 1986881636L; // vmhd + long WIDE_BOX = 2003395685L; // wide + long XML_BOX = 2020437024L; // xml + // mp4 extension + long OBJECT_DESCRIPTOR_BOX = 1768907891L; // iods + long SAMPLE_DEPENDENCY_BOX = 1935959408L; // sdep + // metadata: id3 + long ID3_TAG_BOX = 1768174386L; // id32 + // metadata: itunes + long ITUNES_META_LIST_BOX = 1768715124L; // ilst + long CUSTOM_ITUNES_METADATA_BOX = 757935405L; // ---- + long ITUNES_METADATA_BOX = 1684108385L; // data + long ITUNES_METADATA_NAME_BOX = 1851878757L; // name + long ITUNES_METADATA_MEAN_BOX = 1835360622L; // mean + long ALBUM_ARTIST_NAME_BOX = 1631670868L; // aART + long ALBUM_ARTIST_SORT_BOX = 1936679265L; // soaa + long ALBUM_NAME_BOX = 2841734242L; // ©alb + long ALBUM_SORT_BOX = 1936679276L; // soal + long ARTIST_NAME_BOX = 2839630420L; // ©ART + long ARTIST_SORT_BOX = 1936679282L; // soar + long CATEGORY_BOX = 1667331175L; // catg + long COMMENTS_BOX = 2841865588L; // ©cmt + long COMPILATION_PART_BOX = 1668311404L; // cpil + long COMPOSER_NAME_BOX = 2843177588L; // ©wrt + long COMPOSER_SORT_BOX = 1936679791L; // soco + long COVER_BOX = 1668249202L; // covr + long CUSTOM_GENRE_BOX = 2842125678L; // ©gen + long DESCRIPTION_BOX = 1684370275L; // desc + long DISK_NUMBER_BOX = 1684632427L; // disk + long ENCODER_NAME_BOX = 2841996899L; // ©enc + long ENCODER_TOOL_BOX = 2842980207L; // ©too + long EPISODE_GLOBAL_UNIQUE_ID_BOX = 1701276004L; // egid + long GAPLESS_PLAYBACK_BOX = 1885823344L; // pgap + long GENRE_BOX = 1735291493L; // gnre + long GROUPING_BOX = 2842129008L; // ©grp + long HD_VIDEO_BOX = 1751414372L; // hdvd + long ITUNES_PURCHASE_ACCOUNT_BOX = 1634748740L; // apID + long ITUNES_ACCOUNT_TYPE_BOX = 1634421060L; // akID + long ITUNES_CATALOGUE_ID_BOX = 1668172100L; // cnID + long ITUNES_COUNTRY_CODE_BOX = 1936083268L; // sfID + long KEYWORD_BOX = 1801812343L; // keyw + long LONG_DESCRIPTION_BOX = 1818518899L; // ldes + long LYRICS_BOX = 2842458482L; // ©lyr + long META_TYPE_BOX = 1937009003L; // stik + long PODCAST_BOX = 1885565812L; // pcst + long PODCAST_URL_BOX = 1886745196L; // purl + long PURCHASE_DATE_BOX = 1886745188L; // purd + long RATING_BOX = 1920233063L; // rtng + long RELEASE_DATE_BOX = 2841928057L; // ©day + long REQUIREMENT_BOX = 2842846577L; // ©req + long TEMPO_BOX = 1953329263L; // tmpo + long TRACK_NAME_BOX = 2842583405L; // ©nam + long TRACK_NUMBER_BOX = 1953655662L; // trkn + long TRACK_SORT_BOX = 1936682605L; // sonm + long TV_EPISODE_BOX = 1953916275L; // tves + long TV_EPISODE_NUMBER_BOX = 1953916270L; // tven + long TV_NETWORK_NAME_BOX = 1953918574L; // tvnn + long TV_SEASON_BOX = 1953919854L; // tvsn + long TV_SHOW_BOX = 1953919848L; // tvsh + long TV_SHOW_SORT_BOX = 1936683886L; // sosn + // metadata: 3gpp + long THREE_GPP_ALBUM_BOX = 1634493037L; // albm + long THREE_GPP_AUTHOR_BOX = 1635087464L; // auth + long THREE_GPP_CLASSIFICATION_BOX = 1668051814L; // clsf + long THREE_GPP_DESCRIPTION_BOX = 1685283696L; // dscp + long THREE_GPP_KEYWORDS_BOX = 1803122532L; // kywd + long THREE_GPP_LOCATION_INFORMATION_BOX = 1819239273L; // loci + long THREE_GPP_PERFORMER_BOX = 1885696614L; // perf + long THREE_GPP_RECORDING_YEAR_BOX = 2037543523L; // yrrc + long THREE_GPP_TITLE_BOX = 1953068140L; // titl + // metadata: google/youtube + long GOOGLE_HOST_HEADER_BOX = 1735616616L; // gshh + long GOOGLE_PING_MESSAGE_BOX = 1735618669L; // gspm + long GOOGLE_PING_URL_BOX = 1735618677L; // gspu + long GOOGLE_SOURCE_DATA_BOX = 1735619428L; // gssd + long GOOGLE_START_TIME_BOX = 1735619444L; // gsst + long GOOGLE_TRACK_DURATION_BOX = 1735619684L; // gstd + // sample entries + long MP4V_SAMPLE_ENTRY = 1836070006L; // mp4v + long H263_SAMPLE_ENTRY = 1932670515L; // s263 + long ENCRYPTED_VIDEO_SAMPLE_ENTRY = 1701733238L; // encv + long AVC_SAMPLE_ENTRY = 1635148593L; // avc1 + long MP4A_SAMPLE_ENTRY = 1836069985L; // mp4a + long AC3_SAMPLE_ENTRY = 1633889587L; // ac-3 + long EAC3_SAMPLE_ENTRY = 1700998451L; // ec-3 + long DRMS_SAMPLE_ENTRY = 1685220723L; // drms + long AMR_SAMPLE_ENTRY = 1935764850L; // samr + long AMR_WB_SAMPLE_ENTRY = 1935767394L; // sawb + long EVRC_SAMPLE_ENTRY = 1936029283L; // sevc + long QCELP_SAMPLE_ENTRY = 1936810864L; // sqcp + long SMV_SAMPLE_ENTRY = 1936944502L; // ssmv + long ENCRYPTED_AUDIO_SAMPLE_ENTRY = 1701733217L; // enca + long MPEG_SAMPLE_ENTRY = 1836070003L; // mp4s + long TEXT_METADATA_SAMPLE_ENTRY = 1835365492L; // mett + long XML_METADATA_SAMPLE_ENTRY = 1835365496L; // metx + long RTP_HINT_SAMPLE_ENTRY = 1920233504L; // rtp + long FD_HINT_SAMPLE_ENTRY = 1717858336L; // fdp + // codec infos + long ESD_BOX = 1702061171L; // esds + // video codecs + long H263_SPECIFIC_BOX = 1681012275L; // d263 + long AVC_SPECIFIC_BOX = 1635148611L; // avcC + // audio codecs + long AC3_SPECIFIC_BOX = 1684103987L; // dac3 + long EAC3_SPECIFIC_BOX = 1684366131L; // dec3 + long AMR_SPECIFIC_BOX = 1684106610L; // damr + long EVRC_SPECIFIC_BOX = 1684371043L; // devc + long QCELP_SPECIFIC_BOX = 1685152624L; // dqcp + long SMV_SPECIFIC_BOX = 1685286262L; // dsmv + // OMA DRM + long OMA_ACCESS_UNIT_FORMAT_BOX = 1868849510L; // odaf + long OMA_COMMON_HEADERS_BOX = 1869112434L; // ohdr + long OMA_CONTENT_ID_BOX = 1667459428L; // ccid + long OMA_CONTENT_OBJECT_BOX = 1868850273L; // odda + long OMA_COVER_URI_BOX = 1668706933L; // cvru + long OMA_DISCRETE_MEDIA_HEADERS_BOX = 1868851301L; // odhe + long OMA_DRM_CONTAINER_BOX = 1868853869L; // odrm + long OMA_ICON_URI_BOX = 1768124021L; // icnu + long OMA_INFO_URL_BOX = 1768842869L; // infu + long OMA_LYRICS_URI_BOX = 1819435893L; // lrcu + long OMA_MUTABLE_DRM_INFORMATION_BOX = 1835299433L; // mdri + long OMA_KEY_MANAGEMENT_BOX = 1868852077L; // odkm + long OMA_RIGHTS_OBJECT_BOX = 1868853858L; // odrb + long OMA_TRANSACTION_TRACKING_BOX = 1868854388L; // odtt + // iTunes DRM (FairPlay) + long FAIRPLAY_USER_ID_BOX = 1970496882L; // user + long FAIRPLAY_USER_NAME_BOX = 1851878757L; // name + long FAIRPLAY_USER_KEY_BOX = 1801812256L; // key + long FAIRPLAY_IV_BOX = 1769367926L; // iviv + long FAIRPLAY_PRIVATE_KEY_BOX = 1886546294L; // priv } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/UnknownBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/UnknownBox.java index 96222e8..57a8fae 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/UnknownBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/UnknownBox.java @@ -18,6 +18,6 @@ class UnknownBox extends BoxImpl { @Override public void decode(MP4Input in) throws IOException { - //no need to read, box will be skipped + // no need to read, box will be skipped } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/Utils.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/Utils.java index 505f128..8e06f41 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/Utils.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/Utils.java @@ -5,7 +5,7 @@ public final class Utils { private static final long UNDETERMINED = 4294967295L; public static String getLanguageCode(long l) { - //1 bit padding, 5*3 bits language code (ISO-639-2/T) + // 1 bit padding, 5*3 bits language code (ISO-639-2/T) char[] c = new char[3]; c[0] = (char) (((l >> 10) & 31) + 0x60); c[1] = (char) (((l >> 5) & 31) + 0x60); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ChapterBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ChapterBox.java index c62b3c1..c4d5d0e 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ChapterBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ChapterBox.java @@ -28,7 +28,7 @@ public ChapterBox() { public void decode(MP4Input in) throws IOException { super.decode(in); - in.skipBytes(4); //?? + in.skipBytes(4); // ?? int count = in.readByte(); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ColorParameterBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ColorParameterBox.java index ed45e75..5331f99 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ColorParameterBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ColorParameterBox.java @@ -6,7 +6,7 @@ import net.sourceforge.jaad.mp4.boxes.FullBox; -//TODO: check decoding, add get-methods +// TODO: check decoding, add get-methods public class ColorParameterBox extends FullBox { private long colorParameterType; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/CopyrightBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/CopyrightBox.java index 036f758..b35938d 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/CopyrightBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/CopyrightBox.java @@ -26,7 +26,7 @@ public CopyrightBox() { public void decode(MP4Input in) throws IOException { if (parent.getType() == BoxTypes.USER_DATA_BOX) { super.decode(in); - //1 bit padding, 5*3 bits language code (ISO-639-2/T) + // 1 bit padding, 5*3 bits language code (ISO-639-2/T) languageCode = Utils.getLanguageCode(in.readBytes(2)); notice = in.readUTFString((int) getLeft(in)); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DataReferenceBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DataReferenceBox.java index 163e8e0..187610f 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DataReferenceBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DataReferenceBox.java @@ -28,6 +28,6 @@ public void decode(MP4Input in) throws IOException { int entryCount = (int) in.readBytes(4); - readChildren(in, entryCount); //DataEntryUrlBox, DataEntryUrnBox + readChildren(in, entryCount); // DataEntryUrlBox, DataEntryUrnBox } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DegradationPriorityBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DegradationPriorityBox.java index 2fa9742..f4b5060 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DegradationPriorityBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/DegradationPriorityBox.java @@ -26,7 +26,7 @@ public DegradationPriorityBox() { public void decode(MP4Input in) throws IOException { super.decode(in); - //get number of samples from SampleSizeBox + // get number of samples from SampleSizeBox int sampleCount = ((SampleSizeBox) parent.getChild(BoxTypes.SAMPLE_SIZE_BOX)).getSampleCount(); priorities = new int[sampleCount]; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/EditListBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/EditListBox.java index 9be6dc4..ad1507e 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/EditListBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/EditListBox.java @@ -50,8 +50,8 @@ public void decode(MP4Input in) throws IOException { segmentDuration[i] = in.readBytes(len); mediaTime[i] = in.readBytes(len); - //int(16) mediaRate_integer; - //int(16) media_rate_fraction = 0; + // int(16) mediaRate_integer; + // int(16) media_rate_fraction = 0; mediaRate[i] = in.readFixedPoint(16, 16); } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FileTypeBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FileTypeBox.java index e5d816d..5a546b6 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FileTypeBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FileTypeBox.java @@ -6,7 +6,7 @@ import net.sourceforge.jaad.mp4.boxes.BoxImpl; -//TODO: 3gpp brands +// TODO: 3gpp brands public class FileTypeBox extends BoxImpl { public static final String BRAND_ISO_BASE_MEDIA = "isom"; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FreeSpaceBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FreeSpaceBox.java index f466f66..a78e5be 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FreeSpaceBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/FreeSpaceBox.java @@ -20,6 +20,6 @@ public FreeSpaceBox() { @Override public void decode(MP4Input in) throws IOException { - //no need to read, box will be skipped + // no need to read, box will be skipped } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HandlerBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HandlerBox.java index d28dcaa..aecb67e 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HandlerBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HandlerBox.java @@ -24,20 +24,20 @@ */ public class HandlerBox extends FullBox { - //ISO BMFF types - public static final int TYPE_VIDEO = 1986618469; //vide - public static final int TYPE_SOUND = 1936684398; //soun - public static final int TYPE_HINT = 1751740020; //hint - public static final int TYPE_META = 1835365473; //meta - public static final int TYPE_NULL = 1853189228; //null - //MP4 types - public static final int TYPE_ODSM = 1868854125; //odsm - public static final int TYPE_CRSM = 1668445037; //crsm - public static final int TYPE_SDSM = 1935962989; //sdsm - public static final int TYPE_M7SM = 1832350573; //m7sm - public static final int TYPE_OCSM = 1868788589; //ocsm - public static final int TYPE_IPSM = 1768977261; //ipsm - public static final int TYPE_MJSM = 1835692909; //mjsm + // ISO BMFF types + public static final int TYPE_VIDEO = 1986618469; // vide + public static final int TYPE_SOUND = 1936684398; // soun + public static final int TYPE_HINT = 1751740020; // hint + public static final int TYPE_META = 1835365473; // meta + public static final int TYPE_NULL = 1853189228; // null + // MP4 types + public static final int TYPE_ODSM = 1868854125; // odsm + public static final int TYPE_CRSM = 1668445037; // crsm + public static final int TYPE_SDSM = 1935962989; // sdsm + public static final int TYPE_M7SM = 1832350573; // m7sm + public static final int TYPE_OCSM = 1868788589; // ocsm + public static final int TYPE_IPSM = 1768977261; // ipsm + public static final int TYPE_MJSM = 1835692909; // mjsm private long handlerType; private String handlerName; @@ -49,13 +49,13 @@ public HandlerBox() { public void decode(MP4Input in) throws IOException { super.decode(in); - in.skipBytes(4); //pre-defined: 0 + in.skipBytes(4); // pre-defined: 0 handlerType = in.readBytes(4); - in.readBytes(4); //reserved - in.readBytes(4); //reserved - in.readBytes(4); //reserved + in.readBytes(4); // reserved + in.readBytes(4); // reserved + in.readBytes(4); // reserved handlerName = in.readUTFString((int) getLeft(in), MP4Input.UTF8); } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HintMediaHeaderBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HintMediaHeaderBox.java index 552dbc3..df7999c 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HintMediaHeaderBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/HintMediaHeaderBox.java @@ -30,7 +30,7 @@ public void decode(MP4Input in) throws IOException { maxBitrate = in.readBytes(4); avgBitrate = in.readBytes(4); - in.skipBytes(4); //reserved + in.skipBytes(4); // reserved } /** diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ItemInformationEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ItemInformationEntry.java index 995bfb6..21e09d8 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ItemInformationEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ItemInformationEntry.java @@ -29,7 +29,7 @@ public void decode(MP4Input in) throws IOException { contentEncoding = in.readUTFString((int) getLeft(in), MP4Input.UTF8); // optional } if (version == 1 && getLeft(in) > 0) { - //optional + // optional extensionType = in.readBytes(4); if (getLeft(in) > 0) { extension = Extension.forType((int) extensionType); @@ -116,7 +116,7 @@ public Extension getExtension() { public abstract static class Extension { - private static final int TYPE_FDEL = 1717855596; //fdel + private static final int TYPE_FDEL = 1717855596; // fdel static Extension forType(int type) { Extension ext; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaDataBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaDataBox.java index 7ee66a0..5693a83 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaDataBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaDataBox.java @@ -25,6 +25,6 @@ public MediaDataBox() { @Override public void decode(MP4Input in) throws IOException { - //if random access: skip, else: do nothing + // if random access: skip, else: do nothing } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaHeaderBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaHeaderBox.java index fa29530..3cabc14 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaHeaderBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MediaHeaderBox.java @@ -32,7 +32,7 @@ public void decode(MP4Input in) throws IOException { language = Utils.getLanguageCode(in.readBytes(2)); - in.skipBytes(2); //pre-defined: 0 + in.skipBytes(2); // pre-defined: 0 } /** diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MetaBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MetaBox.java index 17fa51f..15fbe5b 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MetaBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MetaBox.java @@ -9,7 +9,7 @@ import net.sourceforge.jaad.mp4.boxes.FullBox; -//needs to be defined, because readChildren() is not called by factory +// needs to be defined, because readChildren() is not called by factory /* TODO: this class shouldn't be needed. at least here, things become too complicated. change this!!! */ public class MetaBox extends FullBox { @@ -37,12 +37,12 @@ protected Box parseBox(MP4Input in) throws IOException { // Indication of it that size already contains the type. // Shift back all parameters by 4 bytes: type <- size <- version:flags <- 0 - if(children.isEmpty() && size==BoxTypes.HANDLER_BOX) { + if (children.isEmpty() && size == BoxTypes.HANDLER_BOX) { offset -= 4; type = size; - size = (version&(2L*Integer.MAX_VALUE+1))<<24; + size = (version & (2L * Integer.MAX_VALUE + 1)) << 24; size += flags; - version=flags=0; + version = flags = 0; } return BoxFactory.parseBox(this, offset, size, type, in); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MovieHeaderBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MovieHeaderBox.java index 46e7d7a..c2f6bd1 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MovieHeaderBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/MovieHeaderBox.java @@ -37,14 +37,14 @@ public void decode(MP4Input in) throws IOException { rate = in.readFixedPoint(16, 16); volume = in.readFixedPoint(8, 8); - in.skipBytes(10); //reserved + in.skipBytes(10); // reserved for (int i = 0; i < 9; i++) { if (i < 6) matrix[i] = in.readFixedPoint(16, 16); else matrix[i] = in.readFixedPoint(2, 30); } - in.skipBytes(24); //reserved + in.skipBytes(24); // reserved nextTrackID = in.readBytes(4); } @@ -94,7 +94,7 @@ public long getDuration() { } /** - * The rate is a floting point number that indicates the preferred rate + * The rate is a floating point number that indicates the preferred rate * to play the presentation; 1.0 is normal forward playback * * @return the playback rate diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/PaddingBitBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/PaddingBitBox.java index 67f8e28..3cec2c8 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/PaddingBitBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/PaddingBitBox.java @@ -33,11 +33,11 @@ public void decode(MP4Input in) throws IOException { byte b; for (int i = 0; i < sampleCount; i++) { b = (byte) in.readByte(); - //1 bit reserved - //3 bits pad1 + // 1 bit reserved + // 3 bits pad1 pad1[i] = (b >> 4) & 7; - //1 bit reserved - //3 bits pad2 + // 1 bit reserved + // 3 bits pad2 pad2[i] = b & 7; } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleDependencyTypeBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleDependencyTypeBox.java index 8508338..cef2a18 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleDependencyTypeBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleDependencyTypeBox.java @@ -52,12 +52,12 @@ public SampleDependencyTypeBox() { public void decode(MP4Input in) throws IOException { super.decode(in); - //get number of samples from SampleSizeBox + // get number of samples from SampleSizeBox long sampleCount = -1; if (parent.hasChild(BoxTypes.SAMPLE_SIZE_BOX)) sampleCount = ((SampleSizeBox) parent.getChild(BoxTypes.SAMPLE_SIZE_BOX)).getSampleCount(); - //TODO: uncomment when CompactSampleSizeBox is implemented - //else if(parent.containsChild(BoxTypes.COMPACT_SAMPLE_SIZE_BOX)) sampleCount = ((CompactSampleSizeBox)parent.getChild(BoxTypes.SAMPLE_SIZE_BOX)).getSampleSize(); + // TODO: uncomment when CompactSampleSizeBox is implemented + // else if(parent.containsChild(BoxTypes.COMPACT_SAMPLE_SIZE_BOX)) sampleCount = ((CompactSampleSizeBox)parent.getChild(BoxTypes.SAMPLE_SIZE_BOX)).getSampleSize(); sampleHasRedundancy = new int[(int) sampleCount]; sampleIsDependedOn = new int[(int) sampleCount]; sampleDependsOn = new int[(int) sampleCount]; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleGroupDescriptionBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleGroupDescriptionBox.java index 4b7a01e..86d61cf 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleGroupDescriptionBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleGroupDescriptionBox.java @@ -45,36 +45,36 @@ public void decode(MP4Input in) throws IOException { int entryCount = (int) in.readBytes(4); - //TODO! - /*final HandlerBox hdlr = (HandlerBox) parent.getParent().getParent().getChild(BoxTypes.HANDLER_BOX); - final int handlerType = (int) hdlr.getHandlerType(); - - final Class boxClass; - switch(handlerType) { - case HandlerBox.TYPE_VIDEO: - boxClass = VisualSampleGroupEntry.class; - break; - case HandlerBox.TYPE_SOUND: - boxClass = AudioSampleGroupEntry.class; - break; - case HandlerBox.TYPE_HINT: - boxClass = HintSampleGroupEntry.class; - break; - default: - boxClass = null; - } - - for(int i = 1; i boxClass; +// switch (handlerType) { +// case HandlerBox.TYPE_VIDEO: +// boxClass = VisualSampleGroupEntry.class; +// break; +// case HandlerBox.TYPE_SOUND: +// boxClass = AudioSampleGroupEntry.class; +// break; +// case HandlerBox.TYPE_HINT: +// boxClass = HintSampleGroupEntry.class; +// break; +// default: +// boxClass = null; +// } +// +// for (int i = 1; i < entryCount; i++) { +// if (version == 1 && defaultLength == 0) { +// descriptionLength = in.readBytes(4); +// left -= 4; +// } +// if (boxClass != null) { +// entries[i] = (SampleGroupDescriptionEntry) BoxFactory.parseBox(in, boxClass); +// if (entries[i] != null) +// left -= entries[i].getSize(); +// } +// } } /** diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleScaleBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleScaleBox.java index 0d8a256..9c62039 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleScaleBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleScaleBox.java @@ -43,7 +43,7 @@ public SampleScaleBox() { public void decode(MP4Input in) throws IOException { super.decode(in); - //7 bits reserved, 1 bit flag + // 7 bits reserved, 1 bit flag constrained = (in.readByte() & 1) == 1; scaleMethod = in.readByte(); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleSizeBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleSizeBox.java index ade73b7..8444571 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleSizeBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SampleSizeBox.java @@ -33,7 +33,7 @@ public void decode(MP4Input in) throws IOException { sampleSizes = new long[(int) sampleCount]; if (compact) { - //compact: sampleSize can be 4, 8 or 16 bits + // compact: sampleSize can be 4, 8 or 16 bits if (sampleSize == 4) { int x; for (int i = 0; i < sampleCount; i += 2) { diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SchemeTypeBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SchemeTypeBox.java index 38f5628..946e410 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SchemeTypeBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SchemeTypeBox.java @@ -13,7 +13,7 @@ */ public class SchemeTypeBox extends FullBox { - public static final long ITUNES_SCHEME = 1769239918; //itun + public static final long ITUNES_SCHEME = 1769239918; // itun private long schemeType, schemeVersion; private String schemeURI; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ShadowSyncSampleBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ShadowSyncSampleBox.java index 11c8b7f..dfd2152 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ShadowSyncSampleBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/ShadowSyncSampleBox.java @@ -16,7 +16,7 @@ * a shadow sync will be defined for. This should always be a non-sync sample * (e.g. a frame difference). The second sample number (sync-sample-number) * indicates the sample number of the sync sample (i.e. key frame) that can be - * used when there is a random access at, or before, the shadowed-sample-number. + * used when there is random access at, or before, the shadowed-sample-number. *

* The entries in the ShadowSyncBox shall be sorted based on the * shadowed-sample-number field. The shadow sync samples are normally placed in @@ -54,8 +54,8 @@ public void decode(MP4Input in) throws IOException { sampleNumbers = new long[entryCount][2]; for (int i = 0; i < entryCount; i++) { - sampleNumbers[i][0] = in.readBytes(4); //shadowedSampleNumber; - sampleNumbers[i][1] = in.readBytes(4); //syncSampleNumber; + sampleNumbers[i][0] = in.readBytes(4); // shadowedSampleNumber; + sampleNumbers[i][1] = in.readBytes(4); // syncSampleNumber; } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SoundMediaHeaderBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SoundMediaHeaderBox.java index 9698ce7..dc9f3a6 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SoundMediaHeaderBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SoundMediaHeaderBox.java @@ -26,7 +26,7 @@ public void decode(MP4Input in) throws IOException { super.decode(in); balance = in.readFixedPoint(8, 8); - in.skipBytes(2); //reserved + in.skipBytes(2); // reserved } /** diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SubSampleInformationBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SubSampleInformationBox.java index 8124d7f..0a63cfd 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SubSampleInformationBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/SubSampleInformationBox.java @@ -54,7 +54,7 @@ public void decode(MP4Input in) throws IOException { subsampleSize[i][j] = in.readBytes(len); subsamplePriority[i][j] = in.readByte(); discardable[i][j] = (in.readByte() & 1) == 1; - in.skipBytes(4); //reserved + in.skipBytes(4); // reserved } } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentHeaderBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentHeaderBox.java index f251121..838e4fc 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentHeaderBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentHeaderBox.java @@ -33,7 +33,7 @@ public void decode(MP4Input in) throws IOException { trackID = in.readBytes(4); - //optional fields + // optional fields baseDataOffsetPresent = ((flags & 1) == 1); baseDataOffset = baseDataOffsetPresent ? in.readBytes(8) : 0; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRandomAccessBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRandomAccessBox.java index dacc9be..ececd7c 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRandomAccessBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRandomAccessBox.java @@ -21,7 +21,7 @@ public void decode(MP4Input in) throws IOException { super.decode(in); trackID = in.readBytes(4); - //26 bits reserved, 2 bits trafSizeLen, 2 bits trunSizeLen, 2 bits sampleSizeLen + // 26 bits reserved, 2 bits trafSizeLen, 2 bits trunSizeLen, 2 bits sampleSizeLen long l = in.readBytes(4); int trafNumberLen = (int) ((l >> 4) & 0x3) + 1; int trunNumberLen = (int) ((l >> 2) & 0x3) + 1; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRunBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRunBox.java index b1ee2da..95b52c2 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRunBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackFragmentRunBox.java @@ -39,14 +39,14 @@ public void decode(MP4Input in) throws IOException { sampleCount = (int) in.readBytes(4); - //optional fields + // optional fields dataOffsetPresent = ((flags & 1) == 1); if (dataOffsetPresent) dataOffset = in.readBytes(4); firstSampleFlagsPresent = ((flags & 4) == 4); if (firstSampleFlagsPresent) firstSampleFlags = in.readBytes(4); - //all fields are optional + // all fields are optional sampleDurationPresent = ((flags & 0x100) == 0x100); if (sampleDurationPresent) sampleDuration = new long[sampleCount]; sampleSizePresent = ((flags & 0x200) == 0x200); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackHeaderBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackHeaderBox.java index c97ca55..b2bedb3 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackHeaderBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/TrackHeaderBox.java @@ -49,16 +49,16 @@ public void decode(MP4Input in) throws IOException { creationTime = in.readBytes(len); modificationTime = in.readBytes(len); trackID = (int) in.readBytes(4); - in.skipBytes(4); //reserved + in.skipBytes(4); // reserved duration = Utils.detectUndetermined(in.readBytes(len)); - in.skipBytes(8); //reserved + in.skipBytes(8); // reserved layer = (int) in.readBytes(2); alternateGroup = (int) in.readBytes(2); volume = in.readFixedPoint(8, 8); - in.skipBytes(2); //reserved + in.skipBytes(2); // reserved for (int i = 0; i < 9; i++) { if (i < 6) matrix[i] = in.readFixedPoint(16, 16); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/VideoMediaHeaderBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/VideoMediaHeaderBox.java index 1511cb6..3d1d991 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/VideoMediaHeaderBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/VideoMediaHeaderBox.java @@ -27,7 +27,7 @@ public void decode(MP4Input in) throws IOException { super.decode(in); graphicsMode = in.readBytes(2); - //6 byte RGB color + // 6 byte RGB color int[] c = new int[3]; for (int i = 0; i < 3; i++) { c[i] = (in.readByte() & 0xFF) | ((in.readByte() << 8) & 0xFF); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/Base64Decoder.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/Base64Decoder.java index cd39604..cd33897 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/Base64Decoder.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/Base64Decoder.java @@ -24,7 +24,7 @@ class Base64Decoder { 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 6 '4', '5', '6', '7', '8', '9', '+', '/' // 7 };*/ - //CHAR_CONVERT_ARRAY[CHAR_ARRAY[i]] = i; + // CHAR_CONVERT_ARRAY[CHAR_ARRAY[i]] = i; private static final byte[] CHAR_CONVERT_ARRAY = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FDItemInformationBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FDItemInformationBox.java index 19535cb..6bb573b 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FDItemInformationBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FDItemInformationBox.java @@ -29,8 +29,8 @@ public void decode(MP4Input in) throws IOException { super.decode(in); int entryCount = (int) in.readBytes(2); - readChildren(in, entryCount); //partition entries + readChildren(in, entryCount); // partition entries - readChildren(in); //FDSessionGroupBox and GroupIDToNameBox + readChildren(in); // FDSessionGroupBox and GroupIDToNameBox } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FilePartitionBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FilePartitionBox.java index c029b08..e4a96af 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FilePartitionBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/fd/FilePartitionBox.java @@ -24,7 +24,7 @@ public void decode(MP4Input in) throws IOException { itemID = (int) in.readBytes(2); packetPayloadSize = (int) in.readBytes(2); - in.skipBytes(1); //reserved + in.skipBytes(1); // reserved fecEncodingID = in.readByte(); fecInstanceID = (int) in.readBytes(2); maxSourceBlockLength = (int) in.readBytes(2); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/GenreBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/GenreBox.java index 58c9110..4841d38 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/GenreBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/GenreBox.java @@ -19,7 +19,7 @@ public GenreBox() { @Override public void decode(MP4Input in) throws IOException { - //3gpp or iTunes + // 3gpp or iTunes if (parent.getType() == BoxTypes.USER_DATA_BOX) { super.decode(in); languageCode = Utils.getLanguageCode(in.readBytes(2)); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ID3TagBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ID3TagBox.java index 8cc7bf1..8fb6e52 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ID3TagBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ID3TagBox.java @@ -7,7 +7,7 @@ import net.sourceforge.jaad.mp4.boxes.Utils; -//TODO: use nio ByteBuffer instead of array +// TODO: use nio ByteBuffer instead of array public class ID3TagBox extends FullBox { private String language; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ITunesMetadataBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ITunesMetadataBox.java index 1921beb..3af133d 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ITunesMetadataBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/ITunesMetadataBox.java @@ -77,7 +77,7 @@ public void decode(MP4Input in) throws IOException { dataType = DataType.forInt(flags); - in.skipBytes(4); //padding? + in.skipBytes(4); // padding? data = new byte[(int) getLeft(in)]; in.readBytes(data); @@ -103,7 +103,7 @@ public byte[] getData() { * @return the metadata as text */ public String getText() { - //first four bytes are padding (zero) + // first four bytes are padding (zero) return new String(data, StandardCharsets.UTF_8); } @@ -113,7 +113,7 @@ public String getText() { * @return the metadata as an integer */ public long getNumber() { - //first four bytes are padding (zero) + // first four bytes are padding (zero) long l = 0; for (byte datum : data) { l <<= 8; @@ -136,7 +136,7 @@ public boolean getBoolean() { } public Date getDate() { - //timestamp lengths: 4,7,9 + // timestamp lengths: 4,7,9 int i = (int) Math.floor(data.length / 3f) - 1; Date date; if (i >= 0 && i < TIMESTAMPS.length) { diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/NeroMetadataTagsBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/NeroMetadataTagsBox.java index 97b0549..b57ce12 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/NeroMetadataTagsBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/meta/NeroMetadataTagsBox.java @@ -20,15 +20,15 @@ public NeroMetadataTagsBox() { @Override public void decode(MP4Input in) throws IOException { - in.skipBytes(12); //meta box + in.skipBytes(12); // meta box String key, val; int len; - //TODO: what are the other skipped fields for? + // TODO: what are the other skipped fields for? while (getLeft(in) > 0 && in.readByte() == 0x80) { - in.skipBytes(2); //x80 x00 x06/x05 + in.skipBytes(2); // x80 x00 x06/x05 key = in.readUTFString((int) getLeft(in), MP4InputStream.UTF8); - in.skipBytes(4); //0x00 0x01 0x00 0x00 0x00 + in.skipBytes(4); // 0x00 0x01 0x00 0x00 0x00 len = in.readByte(); val = in.readString(len); pairs.put(key, val); diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMAAccessUnitFormatBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMAAccessUnitFormatBox.java index f8a2652..9692f62 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMAAccessUnitFormatBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMAAccessUnitFormatBox.java @@ -19,9 +19,9 @@ public OMAAccessUnitFormatBox() { public void decode(MP4Input in) throws IOException { super.decode(in); - //1 bit selective encryption, 7 bits reserved + // 1 bit selective encryption, 7 bits reserved selectiveEncrypted = ((in.readByte() >> 7) & 1) == 1; - keyIndicatorLength = in.readByte(); //always zero? + keyIndicatorLength = in.readByte(); // always zero? initialVectorLength = in.readByte(); } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMACommonHeadersBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMACommonHeadersBox.java index b7ab684..e26eece 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMACommonHeadersBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/oma/OMACommonHeadersBox.java @@ -8,7 +8,7 @@ import net.sourceforge.jaad.mp4.boxes.FullBox; -//TODO: add remaining javadoc +// TODO: add remaining javadoc public class OMACommonHeadersBox extends FullBox { private int encryptionMethod, paddingScheme; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/AudioSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/AudioSampleEntry.java index 15687d1..7dca858 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/AudioSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/AudioSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; @@ -37,13 +37,13 @@ public AudioSampleEntry(String name) { public void decode(MP4Input in) throws IOException { super.decode(in); - in.skipBytes(8); //reserved + in.skipBytes(8); // reserved channelCount = (int) in.readBytes(2); sampleSize = (int) in.readBytes(2); - in.skipBytes(2); //pre-defined: 0 - in.skipBytes(2); //reserved + in.skipBytes(2); // pre-defined: 0 + in.skipBytes(2); // reserved sampleRate = (int) in.readBytes(2); - in.skipBytes(2); //not used by samplerate + in.skipBytes(2); // not used by samplerate readChildren(in); } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/FDHintSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/FDHintSampleEntry.java index e11a6cf..1e0dbd0 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/FDHintSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/FDHintSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MPEGSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MPEGSampleEntry.java index dd5de4b..812fdd8 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MPEGSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MPEGSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MetadataSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MetadataSampleEntry.java index 943e4b3..619fbf6 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MetadataSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/MetadataSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/RTPHintSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/RTPHintSampleEntry.java index f8bf86c..21c61db 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/RTPHintSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/RTPHintSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/SampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/SampleEntry.java index 614e5d1..b75d227 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/SampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/SampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; @@ -36,7 +36,7 @@ protected SampleEntry(String name) { @Override public void decode(MP4Input in) throws IOException { - in.skipBytes(6); //reserved + in.skipBytes(6); // reserved dataReferenceIndex = in.readBytes(2); } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/TextMetadataSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/TextMetadataSampleEntry.java index 1523f71..cc82e60 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/TextMetadataSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/TextMetadataSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/VideoSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/VideoSampleEntry.java index 8bc8244..eada11c 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/VideoSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/VideoSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; @@ -40,18 +40,18 @@ public VideoSampleEntry(String name) { public void decode(MP4Input in) throws IOException { super.decode(in); - in.skipBytes(2); //pre-defined: 0 - in.skipBytes(2); //reserved - //3x32 pre_defined - in.skipBytes(4); //pre-defined: 0 - in.skipBytes(4); //pre-defined: 0 - in.skipBytes(4); //pre-defined: 0 + in.skipBytes(2); // pre-defined: 0 + in.skipBytes(2); // reserved + // 3x32 pre_defined + in.skipBytes(4); // pre-defined: 0 + in.skipBytes(4); // pre-defined: 0 + in.skipBytes(4); // pre-defined: 0 width = (int) in.readBytes(2); height = (int) in.readBytes(2); horizontalResolution = in.readFixedPoint(16, 16); verticalResolution = in.readFixedPoint(16, 16); - in.skipBytes(4); //reserved + in.skipBytes(4); // reserved frameCount = (int) in.readBytes(2); int len = in.readByte(); @@ -59,7 +59,7 @@ public void decode(MP4Input in) throws IOException { in.skipBytes(31 - len); depth = (int) in.readBytes(2); - in.skipBytes(2); //pre-defined: -1 + in.skipBytes(2); // pre-defined: -1 readChildren(in); } diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/XMLMetadataSampleEntry.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/XMLMetadataSampleEntry.java index c51d472..f3e5438 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/XMLMetadataSampleEntry.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/XMLMetadataSampleEntry.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library. - * If not, see . + * If not, see . */ package net.sourceforge.jaad.mp4.boxes.impl.sampleentries; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AC3SpecificBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AC3SpecificBox.java index 8203a9c..d0f885b 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AC3SpecificBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AC3SpecificBox.java @@ -8,8 +8,8 @@ /** * This box contains parameters for AC-3 decoders. For more information see the * AC-3 specification "ETSI TS 102 366 V1.2.1 (2008-08)" at - * + * http:// www.etsi.org/deliver/etsi_ts/102300_102399/102366/01.02.01_60/ts_102366v010201p.pdf. * * @author in-somnia */ @@ -26,19 +26,19 @@ public AC3SpecificBox() { public void decode(MP4Input in) throws IOException { long l = in.readBytes(3); - //2 bits fscod + // 2 bits fscod fscod = (int) ((l >> 22) & 0x3); - //5 bits bsid + // 5 bits bsid bsid = (int) ((l >> 17) & 0x1F); - //3 bits bsmod + // 3 bits bsmod bsmod = (int) ((l >> 14) & 0x7); - //3 bits acmod + // 3 bits acmod acmod = (int) ((l >> 11) & 0x7); - //1 bit lfeon + // 1 bit lfeon lfeon = ((l >> 10) & 0x1) == 1; - //5 bits bitRateCode + // 5 bits bitRateCode bitRateCode = (int) ((l >> 5) & 0x1F); - //5 bits reserved + // 5 bits reserved } /** diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AVCSpecificBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AVCSpecificBox.java index 041a60b..3121bc1 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AVCSpecificBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/AVCSpecificBox.java @@ -5,7 +5,7 @@ import net.sourceforge.jaad.mp4.MP4Input; -//defined in ISO 14496-15 as 'AVC Configuration Record' +// defined in ISO 14496-15 as 'AVC Configuration Record' public class AVCSpecificBox extends CodecSpecificBox { private int configurationVersion, profile, level, lengthSize; @@ -22,11 +22,11 @@ public void decode(MP4Input in) throws IOException { profile = in.readByte(); profileCompatibility = (byte) in.readByte(); level = in.readByte(); - //6 bits reserved, 2 bits 'length size minus one' + // 6 bits reserved, 2 bits 'length size minus one' lengthSize = (in.readByte() & 3) + 1; int len; - //3 bits reserved, 5 bits number of sequence parameter sets + // 3 bits reserved, 5 bits number of sequence parameter sets int sequenceParameterSets = in.readByte() & 31; sequenceParameterSetNALUnit = new byte[sequenceParameterSets][]; diff --git a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/EAC3SpecificBox.java b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/EAC3SpecificBox.java index 7b67192..de03fad 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/EAC3SpecificBox.java +++ b/src/main/java/net/sourceforge/jaad/mp4/boxes/impl/sampleentries/codec/EAC3SpecificBox.java @@ -8,8 +8,8 @@ /** * This box contains parameters for Extended AC-3 decoders. For more information * see the AC-3 specification "ETSI TS 102 366 V1.2.1 (2008-08)" at - * + * http:// www.etsi.org/deliver/etsi_ts/102300_102399/102366/01.02.01_60/ts_102366v010201p.pdf. * * @author in-somnia */ @@ -26,32 +26,32 @@ public EAC3SpecificBox() { @Override public void decode(MP4Input in) throws IOException { long l = in.readBytes(2); - //13 bits dataRate + // 13 bits dataRate dataRate = (int) ((l >> 3) & 0x1FFF); - //3 bits number of independent substreams + // 3 bits number of independent substreams independentSubstreamCount = (int) (l & 0x7); for (int i = 0; i < independentSubstreamCount; i++) { l = in.readBytes(3); - //2 bits fscod + // 2 bits fscod fscods[i] = (int) ((l >> 22) & 0x3); - //5 bits bsid + // 5 bits bsid bsids[i] = (int) ((l >> 17) & 0x1F); - //5 bits bsmod + // 5 bits bsmod bsmods[i] = (int) ((l >> 12) & 0x1F); - //3 bits acmod + // 3 bits acmod acmods[i] = (int) ((l >> 9) & 0x7); - //3 bits reserved - //1 bit lfeon + // 3 bits reserved + // 1 bit lfeon lfeons[i] = ((l >> 5) & 0x1) == 1; - //4 bits number of dependent substreams + // 4 bits number of dependent substreams dependentSubstreamCount[i] = (int) ((l >> 1) & 0xF); if (dependentSubstreamCount[i] > 0) { - //9 bits dependent substream location + // 9 bits dependent substream location l = (l << 8) | in.readByte(); dependentSubstreamLocation[i] = (int) (l & 0x1FF); } - //else: 1 bit reserved + // else: 1 bit reserved } } diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/DecoderConfigDescriptor.java b/src/main/java/net/sourceforge/jaad/mp4/od/DecoderConfigDescriptor.java index 500cb26..794b744 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/DecoderConfigDescriptor.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/DecoderConfigDescriptor.java @@ -22,9 +22,10 @@ public class DecoderConfigDescriptor extends Descriptor { private boolean upstream; private long maxBitRate, averageBitRate; + @Override void decode(MP4Input in) throws IOException { objectProfile = in.readByte(); - //6 bits stream type, 1 bit upstream flag, 1 bit reserved + // 6 bits stream type, 1 bit upstream flag, 1 bit reserved int x = in.readByte(); streamType = (x >> 2) & 0x3F; upstream = ((x >> 1) & 1) == 1; diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/DecoderSpecificInfo.java b/src/main/java/net/sourceforge/jaad/mp4/od/DecoderSpecificInfo.java index b3c2950..ef0d5b8 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/DecoderSpecificInfo.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/DecoderSpecificInfo.java @@ -7,7 +7,7 @@ /** * The DecoderSpecificInfo constitutes an opaque container with - * information for a specific media decoder. Depending on the required amout of + * information for a specific media decoder. Depending on the required amount of * data, two classes with a maximum of 255 and 232-1 bytes of data * are provided. The existence and semantics of the * DecoderSpecificInfo depends on the stream type and object diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/Descriptor.java b/src/main/java/net/sourceforge/jaad/mp4/od/Descriptor.java index 582a168..4d0d89b 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/Descriptor.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/Descriptor.java @@ -18,7 +18,7 @@ */ public abstract class Descriptor { - static final Logger LOGGER = Logger.getLogger(Descriptor.class.getName()); + static final Logger LOGGER = Logger.getLogger(Descriptor.class.getName()); public static final int TYPE_OBJECT_DESCRIPTOR = 1; public static final int TYPE_INITIAL_OBJECT_DESCRIPTOR = 2; @@ -30,7 +30,7 @@ public abstract class Descriptor { public static final int TYPE_MP4_INITIAL_OBJECT_DESCRIPTOR = 16; public static Descriptor createDescriptor(MP4Input in) throws IOException { - //read tag and size + // read tag and size int type = in.readByte(); int read = 1; int size = 0; @@ -43,21 +43,21 @@ public static Descriptor createDescriptor(MP4Input in) throws IOException { } while ((b & 0x80) == 0x80); - //create descriptor + // create descriptor Descriptor desc = forTag(type); desc.type = type; desc.size = size; desc.start = in.getOffset(); - //decode + // decode desc.decode(in); - //skip remaining bytes + // skip remaining bytes long remaining = size - (in.getOffset() - desc.start); if (remaining > 0) { Logger.getLogger("MP4 Boxes").log(Level.FINE, "Descriptor: bytes left: {0}, offset: {1}", new Long[] {remaining, in.getOffset()}); in.skipBytes(remaining); } - desc.size += read; //include type and size fields + desc.size += read; // include type and size fields return desc; } @@ -82,8 +82,8 @@ private static Descriptor forTag(int tag) { desc = new DecoderSpecificInfo(); break; case TYPE_SL_CONFIG_DESCRIPTOR: - //desc = new SLConfigDescriptor(); - //break; +// desc = new SLConfigDescriptor(); +// break; default: Logger.getLogger("MP4 Boxes").log(Level.FINE, "Unknown descriptor type: {0}", tag); desc = new UnknownDescriptor(); @@ -101,7 +101,7 @@ protected Descriptor() { abstract void decode(MP4Input in) throws IOException; - //children + // children protected void readChildren(MP4Input in) throws IOException { Descriptor desc; while ((size - (in.getOffset() - start)) > 0) { @@ -114,7 +114,7 @@ public List getChildren() { return Collections.unmodifiableList(children); } - //getter + // getter public int getType() { return type; } diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/ESDescriptor.java b/src/main/java/net/sourceforge/jaad/mp4/od/ESDescriptor.java index f5b8ed2..84e46e8 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/ESDescriptor.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/ESDescriptor.java @@ -29,10 +29,11 @@ public class ESDescriptor extends Descriptor { private boolean streamDependency, urlPresent, ocrPresent; private String url; + @Override void decode(MP4Input in) throws IOException { esID = (int) in.readBytes(2); - //1 bit stream dependence flag, 1 it url flag, 1 reserved, 5 bits stream priority + // 1 bit stream dependence flag, 1 it url flag, 1 reserved, 5 bits stream priority int flags = in.readByte(); streamDependency = ((flags >> 7) & 1) == 1; urlPresent = ((flags >> 6) & 1) == 1; diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/InitialObjectDescriptor.java b/src/main/java/net/sourceforge/jaad/mp4/od/InitialObjectDescriptor.java index 074356c..1874e60 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/InitialObjectDescriptor.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/InitialObjectDescriptor.java @@ -21,8 +21,8 @@ public class InitialObjectDescriptor extends Descriptor { @Override void decode(MP4Input in) throws IOException { - //10 bits objectDescriptorID, 1 bit url flag, 1 bit - //includeInlineProfiles flag, 4 bits reserved + // 10 bits objectDescriptorID, 1 bit url flag, 1 bit + // includeInlineProfiles flag, 4 bits reserved int x = (int) in.readBytes(2); objectDescriptorID = (x >> 6) & 0x3FF; urlPresent = ((x >> 5) & 1) == 1; @@ -93,7 +93,7 @@ public boolean areProfilesPresent() { return !urlPresent; } - //TODO: javadoc + // TODO: javadoc public int getODProfile() { return odProfile; } diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/ObjectDescriptor.java b/src/main/java/net/sourceforge/jaad/mp4/od/ObjectDescriptor.java index 13ff42f..dd823ce 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/ObjectDescriptor.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/ObjectDescriptor.java @@ -29,8 +29,9 @@ public class ObjectDescriptor extends Descriptor { private boolean urlPresent; private String url; + @Override void decode(MP4Input in) throws IOException { - //10 bits objectDescriptorID, 1 bit url flag, 5 bits reserved + // 10 bits objectDescriptorID, 1 bit url flag, 5 bits reserved int x = (int) in.readBytes(2); objectDescriptorID = (x >> 6) & 0x3FF; urlPresent = ((x >> 5) & 1) == 1; diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/SLConfigDescriptor.java b/src/main/java/net/sourceforge/jaad/mp4/od/SLConfigDescriptor.java index 3603f63..d0f52a6 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/SLConfigDescriptor.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/SLConfigDescriptor.java @@ -5,8 +5,8 @@ import net.sourceforge.jaad.mp4.MP4Input; -//ISO 14496-1 - 10.2.3 -//TODO: not working: reads too much! did the specification change? +// ISO 14496-1 - 10.2.3 +// TODO: not working: reads too much! did the specification change? public class SLConfigDescriptor extends Descriptor { private boolean useAccessUnitStart, useAccessUnitEnd, useRandomAccessPoint, @@ -26,7 +26,7 @@ void decode(MP4Input in) throws IOException { boolean predefined = in.readByte() == 1; if (!predefined) { - //flags + // flags tmp = in.readByte(); useAccessUnitStart = ((tmp >> 7) & 1) == 1; useAccessUnitEnd = ((tmp >> 6) & 1) == 1; diff --git a/src/main/java/net/sourceforge/jaad/mp4/od/UnknownDescriptor.java b/src/main/java/net/sourceforge/jaad/mp4/od/UnknownDescriptor.java index 6944f4e..374ada9 100644 --- a/src/main/java/net/sourceforge/jaad/mp4/od/UnknownDescriptor.java +++ b/src/main/java/net/sourceforge/jaad/mp4/od/UnknownDescriptor.java @@ -15,6 +15,6 @@ public class UnknownDescriptor extends Descriptor { @Override void decode(MP4Input in) throws IOException { - //content will be skipped + // content will be skipped } } diff --git a/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioFileReader.java b/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioFileReader.java index bb9902e..d0d2642 100644 --- a/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioFileReader.java +++ b/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioFileReader.java @@ -35,6 +35,7 @@ public class AACAudioFileReader extends AudioFileReader { public static final AudioFormat.Encoding AAC_ENCODING = new AudioFormat.Encoding("AAC"); private static class LimitedInputStream extends FilterInputStream { + static final String ERROR_MESSAGE_REACHED_TO_LIMIT = "stop reading, prevent form eof"; protected LimitedInputStream(InputStream in) throws IOException { @@ -76,49 +77,44 @@ public long skip(long n) throws IOException { @Override public AudioFileFormat getAudioFileFormat(InputStream in) throws UnsupportedAudioFileException, IOException { - try { - if (!in.markSupported()) in = new BufferedInputStream(in); - in.mark(1000); - return getAudioFileFormat(new LimitedInputStream(in), AudioSystem.NOT_SPECIFIED); - } finally { - in.reset(); - } + return getAudioFileFormat(in, AudioSystem.NOT_SPECIFIED); } @Override public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException { try (InputStream in = url.openStream()) { - return getAudioFileFormat(in); + return getAudioFileFormat(in instanceof BufferedInputStream ? in : new BufferedInputStream(in, Integer.MAX_VALUE - 8)); } } @Override public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { - InputStream in = null; - try { - in = new BufferedInputStream(Files.newInputStream(file.toPath())); - in.mark(1000); - AudioFileFormat aff = getAudioFileFormat(new LimitedInputStream(in), (int) file.length()); - return aff; - } finally { - if (in != null) { - in.reset(); - in.close(); - } + try (InputStream in = Files.newInputStream(file.toPath())) { + return getAudioFileFormat(new BufferedInputStream(in, Integer.MAX_VALUE - 8), (int) file.length()); } } private AudioFileFormat getAudioFileFormat(InputStream in, int mediaLength) throws UnsupportedAudioFileException, IOException { try { + if (!in.markSupported()) throw new IllegalArgumentException("mark not supported"); + byte[] head = new byte[12]; - in.read(head); - boolean canHandle = false; + synchronized (this) { + in.mark(12); + in.read(head); + in.reset(); // (*a) + } + + int whole = in.available(); + in.mark(whole); +logger.fine("mark: " + whole); + in = new LimitedInputStream(in); + + boolean canHandle; AudioFileFormat.Type type = AAC; if (new String(head, 4, 4).equals("ftyp")) { - in.reset(); - in.mark(1000); - // in position should be zero + // ⚠⚠⚠ in position must be zero ⚠⚠⚠ MP4Input is = MP4Input.open(in); MP4Container cont = new MP4Container(is); Movie movie = cont.getMovie(); @@ -129,21 +125,21 @@ private AudioFileFormat getAudioFileFormat(InputStream in, int mediaLength) thro canHandle = true; type = MP4; - //This code is pulled directly from MP3-SPI. + // This code is pulled directly from MP3-SPI. } else if ((head[0] == 'R') && (head[1] == 'I') && (head[2] == 'F') && (head[3] == 'F') && (head[8] == 'W') && (head[9] == 'A') && (head[10] == 'V') && (head[11] == 'E')) { - canHandle = false; //RIFF/WAV stream found + canHandle = false; // RIFF/WAV stream found } else if ((head[0] == '.') && (head[1] == 's') && (head[2] == 'n') && (head[3] == 'd')) { - canHandle = false; //AU stream found + canHandle = false; // AU stream found } else if ((head[0] == 'F') && (head[1] == 'O') && (head[2] == 'R') && (head[3] == 'M') && (head[8] == 'A') && (head[9] == 'I') && (head[10] == 'F') && (head[11] == 'F')) { - canHandle = false; //AIFF stream found + canHandle = false; // AIFF stream found } else if (((head[0] == 'M') | (head[0] == 'm')) && ((head[1] == 'A') | (head[1] == 'a')) && ((head[2] == 'C') | (head[2] == 'c'))) { - canHandle = false; //APE stream found + canHandle = false; // APE stream found } else if (((head[0] == 'F') | (head[0] == 'f')) && ((head[1] == 'L') | (head[1] == 'l')) && ((head[2] == 'A') | (head[2] == 'a')) && ((head[3] == 'C') | (head[3] == 'c'))) { - canHandle = false; //FLAC stream found + canHandle = false; // FLAC stream found } else if (((head[0] == 'I') | (head[0] == 'i')) && ((head[1] == 'C') | (head[1] == 'c')) && ((head[2] == 'Y') | (head[2] == 'y'))) { - canHandle = false; //Shoutcast / ICE stream ? + canHandle = false; // Shoutcast / ICE stream ? } else if (((head[0] == 'O') | (head[0] == 'o')) && ((head[1] == 'G') | (head[1] == 'g')) && ((head[2] == 'G') | (head[2] == 'g'))) { - canHandle = false; //Ogg stream ? + canHandle = false; // Ogg stream ? } else { ADTSDemultiplexer adts = new ADTSDemultiplexer(in); Decoder.create(adts.getDecoderInfo()); @@ -161,40 +157,49 @@ private AudioFileFormat getAudioFileFormat(InputStream in, int mediaLength) thro } else { throw new UnsupportedAudioFileException("no match sequence"); } - } catch (Exception e) { - logger.fine(e.getClass().getSimpleName() + ": " + e.getMessage()); - throw (UnsupportedAudioFileException) new UnsupportedAudioFileException().initCause(e); + + } catch (IOException e) { + if (e.getMessage().equals(LimitedInputStream.ERROR_MESSAGE_REACHED_TO_LIMIT)) { + logger.fine(LimitedInputStream.ERROR_MESSAGE_REACHED_TO_LIMIT); + throw new UnsupportedAudioFileException(e.getMessage()); + } else if (e.getMessage().equals("no ADTS header found")) { + logger.fine("no ADTS header found"); + throw new UnsupportedAudioFileException(e.getMessage()); + } else if (e instanceof net.sourceforge.jaad.mp4.MP4Exception) { + logger.fine(e.toString()); + throw new UnsupportedAudioFileException(e.getMessage()); + } else { + logger.info(e.toString()); + throw e; + } + } finally { + try { + in.reset(); +logger.fine("reset"); + } catch (IOException e) { + logger.info("FAIL TO RESET: " + e); + } finally { + logger.fine("finally available: " + in.available()); + } } } - //================================================ + // ---- + @Override public AudioInputStream getAudioInputStream(InputStream in) throws UnsupportedAudioFileException, IOException { - boolean needReset = false; try { - if (!in.markSupported()) in = new BufferedInputStream(in); - synchronized (this) { - in.mark(1000); - logger.finer("mark: " + in.available()); - needReset = true; - } - AudioFileFormat aff = getAudioFileFormat(new LimitedInputStream(in), AudioSystem.NOT_SPECIFIED); - synchronized (this) { - logger.finer("before reset: " + in.available()); - in.reset(); - logger.finer("after reset: " + in.available()); - needReset = false; - } - synchronized (this) { - in.mark(in.available()); - logger.finer("mark2: " + in.available()); - needReset = true; - } + AudioFileFormat aff = getAudioFileFormat(in, AudioSystem.NOT_SPECIFIED); +logger.fine("format: " + aff); + + int whole = in.available(); + in.mark(whole); +logger.fine("mark: " + whole); + in = new LimitedInputStream(in); + // in position should be zero - logger.fine("format: " + aff.getFormat()); return new AudioInputStream(in, aff.getFormat(), aff.getFrameLength()); - } catch (UnsupportedAudioFileException e) { - throw e; + } catch (IOException e) { if (e.getMessage().equals(LimitedInputStream.ERROR_MESSAGE_REACHED_TO_LIMIT)) { logger.fine(LimitedInputStream.ERROR_MESSAGE_REACHED_TO_LIMIT); @@ -206,40 +211,36 @@ public AudioInputStream getAudioInputStream(InputStream in) throws UnsupportedAu logger.info(e.toString()); throw e; } - } catch (Exception e) { - logger.info(e.toString()); - throw e; } finally { - logger.fine("reset?: " + needReset + ", available: " + in.available()); try { - if (needReset) { - in.reset(); - } - logger.fine("finally available: " + in.available()); + in.reset(); +logger.fine("reset"); } catch (IOException e) { - logger.info(e.toString()); + logger.info("FAIL TO RESET: " + e); + } finally { + logger.fine("finally available: " + in.available()); } } } @Override public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException { - InputStream in = url.openStream(); + InputStream inputStream = url.openStream(); try { - return getAudioInputStream(in); + return getAudioInputStream(inputStream instanceof BufferedInputStream ? inputStream : new BufferedInputStream(inputStream, Integer.MAX_VALUE - 8)); } catch (UnsupportedAudioFileException | IOException e) { - if (in != null) in.close(); + inputStream.close(); throw e; } } @Override public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException { - InputStream in = Files.newInputStream(file.toPath()); + InputStream inputStream = Files.newInputStream(file.toPath()); try { - return getAudioInputStream(in); + return getAudioInputStream(new BufferedInputStream(inputStream, Integer.MAX_VALUE - 8)); } catch (UnsupportedAudioFileException | IOException e) { - in.close(); + inputStream.close(); throw e; } } diff --git a/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioInputStream.java b/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioInputStream.java index a3d5709..426b7c3 100644 --- a/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioInputStream.java +++ b/src/main/java/net/sourceforge/jaad/spi/javasound/AACAudioInputStream.java @@ -4,8 +4,8 @@ import java.io.InputStream; import javax.sound.sampled.AudioFormat; -import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.SampleBuffer; +import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.adts.ADTSDemultiplexer; @@ -27,7 +27,7 @@ class AACAudioInputStream extends AsynchronousAudioInputStream { @Override public AudioFormat getFormat() { if (audioFormat == null) { - //read first frame + // read first frame try { decoder.decodeFrame(adts.readNextFrame(), sampleBuffer); audioFormat = new AudioFormat(sampleBuffer.getSampleRate(), sampleBuffer.getBitsPerSample(), sampleBuffer.getChannels(), true, true); @@ -39,6 +39,7 @@ public AudioFormat getFormat() { return audioFormat; } + @Override public void execute() { try { if (saved == null) { diff --git a/src/main/java/net/sourceforge/jaad/spi/javasound/CircularBuffer.java b/src/main/java/net/sourceforge/jaad/spi/javasound/CircularBuffer.java index 0899492..9d65845 100644 --- a/src/main/java/net/sourceforge/jaad/spi/javasound/CircularBuffer.java +++ b/src/main/java/net/sourceforge/jaad/spi/javasound/CircularBuffer.java @@ -2,7 +2,7 @@ /** * CircularBuffer for asynchronous reading. - * Adopted from Tritonus ("https://www.tritonus.org/"). + * Adopted from Tritonus ("https:// www.tritonus.org/"). * * @author in-somnia */ diff --git a/src/main/java/net/sourceforge/jaad/spi/javasound/MP4AudioInputStream.java b/src/main/java/net/sourceforge/jaad/spi/javasound/MP4AudioInputStream.java index 736029b..656107d 100644 --- a/src/main/java/net/sourceforge/jaad/spi/javasound/MP4AudioInputStream.java +++ b/src/main/java/net/sourceforge/jaad/spi/javasound/MP4AudioInputStream.java @@ -5,8 +5,8 @@ import java.util.List; import javax.sound.sampled.AudioFormat; -import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.SampleBuffer; +import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.mp4.MP4Container; import net.sourceforge.jaad.mp4.MP4Input; import net.sourceforge.jaad.mp4.api.AudioTrack; @@ -42,7 +42,7 @@ class MP4AudioInputStream extends AsynchronousAudioInputStream { @Override public AudioFormat getFormat() { if (audioFormat == null) { - //read first frame + // read first frame decodeFrame(); audioFormat = new AudioFormat(sampleBuffer.getSampleRate(), sampleBuffer.getBitsPerSample(), sampleBuffer.getChannels(), true, true); saved = sampleBuffer.getData(); @@ -50,6 +50,7 @@ public AudioFormat getFormat() { return audioFormat; } + @Override public void execute() { if (saved == null) { decodeFrame(); diff --git a/src/main/java/net/sourceforge/jaad/spi/javasound/PcmAudioInputStream.java b/src/main/java/net/sourceforge/jaad/spi/javasound/PcmAudioInputStream.java index aab47ef..284c06b 100644 --- a/src/main/java/net/sourceforge/jaad/spi/javasound/PcmAudioInputStream.java +++ b/src/main/java/net/sourceforge/jaad/spi/javasound/PcmAudioInputStream.java @@ -5,8 +5,8 @@ import java.util.logging.Logger; import javax.sound.sampled.AudioFormat; -import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.SampleBuffer; +import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.adts.ADTSDemultiplexer; @@ -30,7 +30,7 @@ class PcmAudioInputStream extends AsynchronousAudioInputStream { @Override public AudioFormat getFormat() { if (audioFormat == null) { - //read first frame + // read first frame try { decoder.decodeFrame(adts.readNextFrame(), sampleBuffer); audioFormat = new AudioFormat(sampleBuffer.getSampleRate(), sampleBuffer.getBitsPerSample(), sampleBuffer.getChannels(), true, true); @@ -43,6 +43,7 @@ public AudioFormat getFormat() { return audioFormat; } + @Override public void execute() { try { if (saved == null) { diff --git a/src/main/java/net/sourceforge/jaad/util/wav/WaveFileWriter.java b/src/main/java/net/sourceforge/jaad/util/wav/WaveFileWriter.java index 2e10c63..7f4e803 100644 --- a/src/main/java/net/sourceforge/jaad/util/wav/WaveFileWriter.java +++ b/src/main/java/net/sourceforge/jaad/util/wav/WaveFileWriter.java @@ -8,9 +8,9 @@ public class WaveFileWriter { private static final int HEADER_LENGTH = 44; - private static final int RIFF = 1380533830; //'RIFF' - private static final long WAVE_FMT = 6287401410857104416L; //'WAVEfmt ' - private static final int DATA = 1684108385; //'data' + private static final int RIFF = 1380533830; // 'RIFF' + private static final long WAVE_FMT = 6287401410857104416L; // 'WAVEfmt ' + private static final int DATA = 1684108385; // 'data' private static final int BYTE_MASK = 0xFF; private final RandomAccessFile out; private final int sampleRate; @@ -25,7 +25,7 @@ public WaveFileWriter(File output, int sampleRate, int channels, int bitsPerSamp bytesWritten = 0; out = new RandomAccessFile(output, "rw"); - out.write(new byte[HEADER_LENGTH]); //space for the header + out.write(new byte[HEADER_LENGTH]); // space for the header } public void write(byte[] data) throws IOException { @@ -33,7 +33,7 @@ public void write(byte[] data) throws IOException { } public void write(byte[] data, int off, int len) throws IOException { - //convert to little endian + // convert to little endian byte tmp; for (int i = off; i < off + data.length; i += 2) { tmp = data[i + 1]; @@ -65,17 +65,17 @@ private void writeWaveHeader() throws IOException { out.seek(0); int bytesPerSec = (bitsPerSample + 7) / 8; - out.writeInt(RIFF); //wave label - out.writeInt(Integer.reverseBytes(bytesWritten + 36)); //length in bytes without header + out.writeInt(RIFF); // wave label + out.writeInt(Integer.reverseBytes(bytesWritten + 36)); // length in bytes without header out.writeLong(WAVE_FMT); - out.writeInt(Integer.reverseBytes(16)); //length of pcm format declaration area - out.writeShort(Short.reverseBytes((short) 1)); //is PCM - out.writeShort(Short.reverseBytes((short) channels)); //number of channels - out.writeInt(Integer.reverseBytes(sampleRate)); //sample rate - out.writeInt(Integer.reverseBytes(sampleRate * channels * bytesPerSec)); //bytes per second - out.writeShort(Short.reverseBytes((short) (channels * bytesPerSec))); //bytes per sample time - out.writeShort(Short.reverseBytes((short) bitsPerSample)); //bits per sample - out.writeInt(DATA); //data section label - out.writeInt(Integer.reverseBytes(bytesWritten)); //length of raw pcm data in bytes + out.writeInt(Integer.reverseBytes(16)); // length of pcm format declaration area + out.writeShort(Short.reverseBytes((short) 1)); // is PCM + out.writeShort(Short.reverseBytes((short) channels)); // number of channels + out.writeInt(Integer.reverseBytes(sampleRate)); // sample rate + out.writeInt(Integer.reverseBytes(sampleRate * channels * bytesPerSec)); // bytes per second + out.writeShort(Short.reverseBytes((short) (channels * bytesPerSec))); // bytes per sample time + out.writeShort(Short.reverseBytes((short) bitsPerSample)); // bits per sample + out.writeInt(DATA); // data section label + out.writeInt(Integer.reverseBytes(bytesWritten)); // length of raw pcm data in bytes } } diff --git a/src/test/java/Test1.java b/src/test/java/Test1.java index 89e04a9..ca556f3 100644 --- a/src/test/java/Test1.java +++ b/src/test/java/Test1.java @@ -9,32 +9,29 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; - import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.SourceDataLine; -import net.sourceforge.jaad.mp4.MP4Input; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import vavi.util.Debug; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static vavi.sound.SoundUtil.volume; -import static vavix.util.DelayedWorker.later; - -import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.SampleBuffer; +import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.adts.ADTSDemultiplexer; import net.sourceforge.jaad.mp4.MP4Container; +import net.sourceforge.jaad.mp4.MP4Input; import net.sourceforge.jaad.mp4.api.AudioTrack; import net.sourceforge.jaad.mp4.api.Frame; import net.sourceforge.jaad.mp4.api.Movie; import net.sourceforge.jaad.mp4.api.Track; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import vavi.util.Debug; import vavi.util.properties.annotation.Property; import vavi.util.properties.annotation.PropsEntity; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static vavi.sound.SoundUtil.volume; +import static vavix.util.DelayedWorker.later; + /** * test basic functions. @@ -62,7 +59,7 @@ void setup() throws Exception { static long time; static { - time = System.getProperty("vavi.test", "").equals("ide") ? 10 * 1000 : 1000 * 1000; + time = System.getProperty("vavi.test", "").equals("ide") ? 1000 * 1000 : 9 * 1000; } @Test @@ -82,7 +79,7 @@ void decodeMP4() throws Exception { track.getSampleRate(), track.getSampleSize(), track.getChannelCount(), true, true); line = AudioSystem.getSourceDataLine(aufmt); line.open(); - volume(line, .2f); + volume(line, .1f); line.start(); // create AAC decoder @@ -118,7 +115,7 @@ void decodeAAC() throws Exception { Debug.println("IN: " + aufmt); line = AudioSystem.getSourceDataLine(aufmt); line.open(); - volume(line, .2f); + volume(line, .1f); line.start(); } b = buf.getData(); diff --git a/src/test/java/net/sourceforge/jaad/spi/javasound/AacFormatConversionProviderTest.java b/src/test/java/net/sourceforge/jaad/spi/javasound/AacFormatConversionProviderTest.java index 4d52023..c702a7d 100644 --- a/src/test/java/net/sourceforge/jaad/spi/javasound/AacFormatConversionProviderTest.java +++ b/src/test/java/net/sourceforge/jaad/spi/javasound/AacFormatConversionProviderTest.java @@ -7,46 +7,78 @@ package net.sourceforge.jaad.spi.javasound; import java.io.BufferedInputStream; +import java.io.File; +import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.concurrent.CountDownLatch; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; import javax.sound.sampled.DataLine; +import javax.sound.sampled.LineEvent; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.UnsupportedAudioFileException; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import vavi.sound.SoundUtil; import vavi.util.Debug; +import vavi.util.properties.annotation.Property; +import vavi.util.properties.annotation.PropsEntity; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static vavi.sound.SoundUtil.volume; import static vavix.util.DelayedWorker.later; + +/** + * AacFormatConversionProviderTest. + * + * @author Naohide Sano (umjammer) + * @version 0.00 2023/05/23 umjammer initial version
+ */ +@PropsEntity(url = "file:local.properties") class AacFormatConversionProviderTest { - static final String inFile1 = "/test.aac"; - static final String inFile = "/test.mid"; - static final String inFile2 = "/test.m4a"; - static final String inFile4 = "/alac.m4a"; - static final String inFile3 = "/test.caf"; + static boolean localPropertiesExists() { + return Files.exists(Paths.get("local.properties")); + } + + @BeforeEach + void setup() throws Exception { + if (localPropertiesExists()) { + PropsEntity.Util.bind(this); + } + } static long time; - @BeforeAll - static void setup() throws Exception { - time = System.getProperty("vavi.test", "").equals("ide") ? 10 * 1000 : 1000 * 1000; + static { + System.setProperty("vavi.util.logging.VaviFormatter.extraClassMethod", "org\\.tritonus\\.share\\.TDebug#out"); + + time = System.getProperty("vavi.test", "").equals("ide") ? 1000 * 1000 : 9 * 1000; } + @Property + String mp4 = "src/test/resources/test.m4a"; + + static final String aac = "/test.aac"; + static final String mid = "/test.mid"; + static final String alac = "/alac.m4a"; + static final String caf = "/test.caf"; + @Test @DisplayName("unsupported exception is able to detect in 3 ways") public void test1() throws Exception { - Path path = Paths.get("src/test/resources", inFile); + Path path = Paths.get("src/test/resources", mid); assertThrows(UnsupportedAudioFileException.class, () -> { // don't replace with Files#newInputStream(Path) @@ -59,28 +91,27 @@ public void test1() throws Exception { } @Test + @DisplayName("not aac") public void test11() throws Exception { - - Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(inFile).toURI()); - + Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(mid).toURI()); +Debug.println(path); assertThrows(UnsupportedAudioFileException.class, () -> new AACAudioFileReader().getAudioInputStream(new BufferedInputStream(Files.newInputStream(path)))); } @Test @DisplayName("movie does not contain any AAC track") public void test12() throws Exception { - - Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(inFile4).toURI()); - + Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(alac).toURI()); +Debug.println(path); assertThrows(UnsupportedAudioFileException.class, () -> new AACAudioFileReader().getAudioInputStream(new BufferedInputStream(Files.newInputStream(path)))); } @Test + @Disabled("couldn't find good sample") @DisplayName("a file consumes input stream all") public void test13() throws Exception { - - Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(inFile3).toURI()); - + Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(caf).toURI()); +Debug.println(path); assertThrows(UnsupportedAudioFileException.class, () -> new AACAudioFileReader().getAudioInputStream(new BufferedInputStream(Files.newInputStream(path)))); } @@ -89,7 +120,7 @@ public void test13() throws Exception { public void test2() throws Exception { // - Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(inFile1).toURI()); + Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(aac).toURI()); Debug.println("file: " + path); AudioInputStream aacAis = AudioSystem.getAudioInputStream(path.toFile()); Debug.println("INS: " + aacAis); @@ -131,7 +162,7 @@ public void test2() throws Exception { public void test3() throws Exception { // - Path path = Paths.get(AacFormatConversionProviderTest.class.getResource(inFile2).toURI()); + Path path = Paths.get(mp4); Debug.println("file: " + path); AudioInputStream aacAis = AudioSystem.getAudioInputStream(path.toFile()); Debug.println("INS: " + aacAis); @@ -168,6 +199,53 @@ public void test3() throws Exception { line.stop(); line.close(); } + + @Test + @DisplayName("another input type 2") + void test62() throws Exception { + URL url = Paths.get(mp4).toUri().toURL(); +Debug.println(url); + AudioInputStream ais = AudioSystem.getAudioInputStream(url); + assertEquals(AACAudioFileReader.AAC_ENCODING, ais.getFormat().getEncoding()); + } + + @Test + @DisplayName("another input type 3") + void test63() throws Exception { + File file = Paths.get(mp4).toFile(); +Debug.println(file); + AudioInputStream ais = AudioSystem.getAudioInputStream(file); + assertEquals(AACAudioFileReader.AAC_ENCODING, ais.getFormat().getEncoding()); + } + + @Test + @DisplayName("clip") + void test4() throws Exception { + + AudioInputStream ais = AudioSystem.getAudioInputStream(Paths.get(mp4).toFile()); +Debug.println(ais.getFormat()); + + Clip clip = AudioSystem.getClip(); +CountDownLatch cdl = new CountDownLatch(1); +clip.addLineListener(ev -> { + Debug.println(ev.getType()); + if (ev.getType() == LineEvent.Type.STOP) + cdl.countDown(); +}); + clip.open(AudioSystem.getAudioInputStream(new AudioFormat(44100, 16, 2, true, false), ais)); +SoundUtil.volume(clip, 0.1f); + clip.start(); +if (!System.getProperty("vavi.test", "").equals("ide")) { + Thread.sleep(10 * 1000); + clip.stop(); + Debug.println("Interrupt"); +} else { + cdl.await(); +} + clip.drain(); + clip.stop(); + clip.close(); + } } /* */ diff --git a/src/test/resources/logging.properties b/src/test/resources/logging.properties index 3b2a8ba..a18586d 100644 --- a/src/test/resources/logging.properties +++ b/src/test/resources/logging.properties @@ -3,4 +3,6 @@ handlers=java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.level=ALL java.util.logging.ConsoleHandler.formatter=vavi.util.logging.VaviFormatter -#vavi.util.level=FINE +vavi.util.level=FINE +net.sourceforge.jaad.level=FINE +net.sourceforge.jaad.spi.level=FINER