diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 0000000..eba5aec
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,45 @@
+# Java Gradle CircleCI 2.0 configuration file
+#
+# Check https://circleci.com/docs/2.0/language-java/ for more details
+#
+version: 2.1
+jobs:
+ build:
+ docker:
+ # specify the version you desire here
+ - image: circleci/openjdk:11-jdk
+
+ # Specify service dependencies here if necessary
+ # CircleCI maintains a library of pre-built images
+ # documented at https://circleci.com/docs/2.0/circleci-images/
+ # - image: circleci/postgres:9.4
+
+ working_directory: ~/repo
+
+ environment:
+ # Customize the JVM maximum heap limit
+ JVM_OPTS: -Xmx3200m
+ TERM: dumb
+
+ steps:
+ - checkout
+
+ # Download and cache dependencies
+ - restore_cache:
+ keys:
+ - v1-dependencies-{{ checksum "build.gradle" }}
+ # fallback to using the latest cache if no exact match is found
+ - v1-dependencies-
+
+ - run: gradle build sonarqube
+
+ - save_cache:
+ paths:
+ - ~/.gradle
+ key: v1-dependencies-{{ checksum "build.gradle" }}
+
+workflows:
+ main:
+ jobs:
+ - build:
+ context: SonarCloud
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index c2bbd3e..2e82ad9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,20 @@ buildNumber.properties
.classpath
.project
.vscode/
+
+
+.gradle
+bin
+/build/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+# Cache of project
+.gradletasknamecache
+
+# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
+# gradle/wrapper/gradle-wrapper.properties
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 321c4da..6ccc1d9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,2 +1,11 @@
language: java
-jdk: openjdk13
+jdk: openjdk11
+git:
+ depth: false
+addons:
+ sonarcloud:
+ organization: "saharatul"
+ token:
+ secure: "bHfjjQSZ43qT1DTR0vb3WOAPSeGO20SXXhTS/0QcWUyg8c3xqHLQ0nUXmNvuOc+Sw3aRHXI9dlYqFkGAQ3+tcayVZeKqVCAgLjadJXg74y1dP0A0cwcAxdo6NzI8gEWCWOoIBWJG5eYutsgRfTZsrkEAOyEmhceDtcp/bKXlOIgrTXC6flrhRrIIbI+BpSx/BR08OaY0F2j3b3I7bYsZ9mxvc1GT4z6lZDR+7cu5z+ftbhe6SvgzLWYs26MynAkYwk/ldHZptn4WvUtZyasuBhd1rSirBjZ5JvPprtX5tfWSP1gaEswWv2PKwlzBfw6A6eyicJfPWxTjhuQcsf80N5raPV0wayYCVvgHpYY1Pqf+s61Cxoq/iUKmgJtwaQJJGnEUqx0Z+HnBLgInXjYO/v3veCLiXfE8QvAFTSoI0tDDLJ/TZ2nEuFAO1LIXgWN84l4MV0aMODuH3Z0D0esASe+pGUx8/5c9d4qnKDcwAzR7iz2uObPf6eGlKo53F/XI43A+aURXF3lIYT/zCPMzSgt9DJhVOKNoupahURrUlC+j7OI4kXYBTkvJU5u8vcvkEfbNOL6uQ5ZQ1fXayylKtOk+SzCWLBgT5KrP9gcaVcs8C/r8oZ5RD/tUN0RU0B2dfmHS9NcZAVyh9yspkIftCW0crKeg8+87EyC7rrJHS0E="
+script:
+ - ./gradlew sonarqube
\ No newline at end of file
diff --git a/README.md b/README.md
index db11fd8..499ae56 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,11 @@
### SimplE Lossless Audio
Java rewrite of the original [sela project](https://github.com/sahaRatul/sela).
+[](https://circleci.com/gh/sahaRatul/sela-java/tree/master)
+[](https://sonarcloud.io/dashboard?id=sahaRatul_sela-java)
+[](https://sonarcloud.io/dashboard?id=sahaRatul_sela-java)
+[](https://opensource.org/licenses/MIT)
+
### Block Diagrams


@@ -26,5 +31,3 @@ Java rewrite of the original [sela project](https://github.com/sahaRatul/sela).
- [FLAC overview](https://xiph.org/flac/documentation_format_overview.html)
- [Paper on shorten, the original open source lossless codec](ftp://svr-ftp.eng.cam.ac.uk/pub/reports/robinson_tr156.ps.Z)
- ISO/IEC 14496 Part 3, Subpart 11 (Audio Lossless Coding)
-
-### License : MIT
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..15e6cbc
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,52 @@
+/*
+ * This file was generated by the Gradle 'init' task.
+ */
+
+plugins {
+ id 'java'
+ id 'jacoco'
+ id 'maven-publish'
+ id 'org.sonarqube' version '2.8'
+}
+
+jacocoTestReport {
+ reports {
+ xml.enabled true
+ }
+}
+
+sonarqube {
+ properties {
+ property "sonar.projectKey", "sahaRatul_sela-java"
+ property "sonar.organization", "saharatul"
+ property "sonar.java.libraries", "build/libs"
+ property "sonar.host.url", "https://sonarcloud.io"
+ }
+}
+
+repositories {
+ mavenLocal()
+ maven {
+ url = 'https://repo.maven.apache.org/maven2'
+ }
+}
+
+dependencies {
+ testImplementation 'junit:junit:4.12'
+}
+
+group = 'org.sela'
+version = '2.0.2'
+sourceCompatibility = '1.8'
+
+publishing {
+ publications {
+ maven(MavenPublication) {
+ from(components.java)
+ }
+ }
+}
+
+tasks.withType(JavaCompile) {
+ options.encoding = 'UTF-8'
+}
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..cc4fdc2
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..9492014
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..2fe81a7
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,183 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=`expr $i + 1`
+ done
+ case $i in
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..9618d8d
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,100 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/pom.xml b/pom.xml
index 75c3f60..9f5e0ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,6 +8,7 @@
11
11
UTF-8
+
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..e25a760
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,5 @@
+/*
+ * This file was generated by the Gradle 'init' task.
+ */
+
+rootProject.name = 'sela'
diff --git a/src/main/java/org/sela/App.java b/src/main/java/org/sela/App.java
index 9b85eb6..a9e4ebc 100644
--- a/src/main/java/org/sela/App.java
+++ b/src/main/java/org/sela/App.java
@@ -89,7 +89,7 @@ private static void printUsage() {
System.out.println("Playing a sela file:");
System.out.println("java -jar sela.jar -p path/to/input.sela");
System.out.println("");
- System.out.println("Playing a sela file:");
+ System.out.println("Playing a wav file:");
System.out.println("java -jar sela.jar -w path/to/input.wav");
System.out.println("");
}
diff --git a/src/main/java/org/sela/Player.java b/src/main/java/org/sela/Player.java
index c541e7a..b17a733 100644
--- a/src/main/java/org/sela/Player.java
+++ b/src/main/java/org/sela/Player.java
@@ -45,7 +45,7 @@ public void play() throws LineUnavailableException, InterruptedException {
for (int i = 0; i < wavFrames.size(); i++) {
final byte[] bytes = wavFrames.get(i).getDemuxedSamplesInByteArray(bytesPerSample);
line.write(bytes, 0, bytes.length);
- progress.current++;
+ progress.setCurrent(progress.getCurrent() + 1);
}
printThread.join();
line.drain();
diff --git a/src/main/java/org/sela/WavPlayer.java b/src/main/java/org/sela/WavPlayer.java
index 8846789..56d2c23 100644
--- a/src/main/java/org/sela/WavPlayer.java
+++ b/src/main/java/org/sela/WavPlayer.java
@@ -62,7 +62,7 @@ public void play() throws LineUnavailableException, InterruptedException, FileEx
for (int i = 0; i < wavFrames.size(); i++) {
final byte[] bytes = wavFrames.get(i).getDemuxedSamplesInByteArray(bytesPerSample);
line.write(bytes, 0, bytes.length);
- progress.current++;
+ progress.setCurrent(progress.getCurrent() + 1);
}
printThread.join();
line.drain();
diff --git a/src/main/java/org/sela/data/Progress.java b/src/main/java/org/sela/data/Progress.java
index f96945b..e7390af 100644
--- a/src/main/java/org/sela/data/Progress.java
+++ b/src/main/java/org/sela/data/Progress.java
@@ -1,13 +1,23 @@
package org.sela.data;
+import java.util.concurrent.atomic.AtomicInteger;
+
// Data Class for keeping track of progress. Will be shared between audio thread
// and print thread
public class Progress {
- public volatile int current;
+ private AtomicInteger current;
public final int total;
public Progress(final int total) {
- current = 0;
+ current = new AtomicInteger(0);
this.total = total;
}
+
+ public int getCurrent() {
+ return current.get();
+ }
+
+ public void setCurrent(int value) {
+ current.set(value);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/sela/data/SelaFile.java b/src/main/java/org/sela/data/SelaFile.java
index 30885a6..84369d0 100644
--- a/src/main/java/org/sela/data/SelaFile.java
+++ b/src/main/java/org/sela/data/SelaFile.java
@@ -119,7 +119,10 @@ public void readFromStream() throws IOException, FileException {
}
final byte[] inputBytes = new byte[inputStream.available()];
- inputStream.read(inputBytes);
+ final int readCount = inputStream.read(inputBytes);
+ if (!(readCount > 0)) {
+ throw new FileException("InputStream read error");
+ }
final ByteBuffer buffer = ByteBuffer.wrap(inputBytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
diff --git a/src/main/java/org/sela/data/WavFile.java b/src/main/java/org/sela/data/WavFile.java
index 8645f82..25ea646 100644
--- a/src/main/java/org/sela/data/WavFile.java
+++ b/src/main/java/org/sela/data/WavFile.java
@@ -25,6 +25,8 @@ public class WavFile {
private int[][] demuxedSamples; // Used for reading
private List frames; // Used for writing
private short bitsPerSample;
+ private final String fmtNotFound = "fmt subchunk not found in wav";
+ private final String dataNotFound = "data subchunk not found in wav";
private DataOutputStream outputStream;
@@ -45,16 +47,16 @@ public WavFile(final int sampleRate, final short bitsPerSample, final byte chann
}
private void allocateBuffer() throws IOException {
- final DataInputStream inputStream = new DataInputStream(
- new BufferedInputStream(new FileInputStream(inputFile)));
+ try (final DataInputStream inputStream = new DataInputStream(
+ new BufferedInputStream(new FileInputStream(inputFile)))) {
+ final byte[] bytes = new byte[(int) inputFile.length()];
+ inputStream.readFully(bytes);
- final byte[] bytes = new byte[(int) inputFile.length()];
- inputStream.readFully(bytes);
+ buffer = ByteBuffer.wrap(bytes);
+ buffer.order(ByteOrder.LITTLE_ENDIAN);
- buffer = ByteBuffer.wrap(bytes);
- buffer.order(ByteOrder.LITTLE_ENDIAN);
-
- inputStream.close();
+ inputStream.close();
+ }
}
private void readChunk() throws FileException {
@@ -101,9 +103,10 @@ private void readSubChunks() throws FileException {
}
private void generateFormatSubChunk() throws FileException {
- final SubChunk subChunk = chunk.subChunks.stream().filter(x -> x.subChunkId.equals("fmt ")).findFirst().get();
+ final SubChunk subChunk = chunk.subChunks.stream().filter(x -> x.subChunkId.equals("fmt ")).findFirst()
+ .orElse(null);
if (subChunk == null) {
- throw new FileException("fmt subchunk not found in wav");
+ throw new FileException(fmtNotFound);
}
final int subChunkIndex = chunk.subChunks.indexOf(subChunk);
@@ -144,15 +147,19 @@ private void createFormatSubChunk(final int sampleRate, final byte channels, fin
private void generateDataChunk() throws FileException {
// Get Data subChunk
- final SubChunk subChunk = chunk.subChunks.stream().filter(x -> x.subChunkId.equals("data")).findFirst().get();
+ final SubChunk subChunk = chunk.subChunks.stream().filter(x -> x.subChunkId.equals("data")).findFirst()
+ .orElse(null);
if (subChunk == null) {
- throw new FileException("data subchunk not found in wav");
+ throw new FileException(dataNotFound);
}
final int subChunkIndex = chunk.subChunks.indexOf(subChunk);
// Get fmt subChunk
final FormatSubChunk formatSubChunk = (FormatSubChunk) chunk.subChunks.stream()
- .filter(x -> x.subChunkId.equals("fmt ")).findFirst().get();
+ .filter(x -> x.subChunkId.equals("fmt ")).findFirst().orElse(null);
+ if (formatSubChunk == null) {
+ throw new FileException(fmtNotFound);
+ }
final DataSubChunk dataSubChunk = new DataSubChunk((byte) formatSubChunk.bitsPerSample);
@@ -172,7 +179,8 @@ private void generateDataChunk() throws FileException {
}
} else {
for (int i = 0; i < sampleCount; i++) {
- dataSubChunk.samples[i] = (buffer.get()) << 24 | (buffer.get() & 0xFF) << 16 | (buffer.get() & 0xFF) << 8;
+ dataSubChunk.samples[i] = (buffer.get()) << 24 | (buffer.get() & 0xFF) << 16
+ | (buffer.get() & 0xFF) << 8;
}
}
dataSubChunk.validate();
@@ -190,11 +198,18 @@ private void createDataChunk() {
chunk.subChunks.add(subChunk);
}
- private void demuxSamples() {
+ private void demuxSamples() throws FileException {
final FormatSubChunk formatSubChunk = (FormatSubChunk) chunk.subChunks.stream()
- .filter(x -> x.subChunkId.equals("fmt ")).findFirst().get();
+ .filter(x -> x.subChunkId.equals("fmt ")).findFirst().orElse(null);
final DataSubChunk dataSubChunk = (DataSubChunk) chunk.subChunks.stream()
- .filter(x -> x.subChunkId.equals("data")).findFirst().get();
+ .filter(x -> x.subChunkId.equals("data")).findFirst().orElse(null);
+
+ if (formatSubChunk == null) {
+ throw new FileException(fmtNotFound);
+ }
+ if (dataSubChunk == null) {
+ throw new FileException(dataNotFound);
+ }
final int[][] demuxedSamples = new int[formatSubChunk.numChannels][dataSubChunk.samples.length
/ formatSubChunk.numChannels];
diff --git a/src/main/java/org/sela/lpc/LookupTables.java b/src/main/java/org/sela/lpc/LookupTables.java
index 0147530..7be3f7e 100644
--- a/src/main/java/org/sela/lpc/LookupTables.java
+++ b/src/main/java/org/sela/lpc/LookupTables.java
@@ -1,7 +1,7 @@
package org.sela.lpc;
public final class LookupTables {
- public static final double[] firstOrderCoefficients = { -1, -0.9998779296875, -0.99951171875, -0.9989013671875,
+ protected static final double[] firstOrderCoefficients = { -1, -0.9998779296875, -0.99951171875, -0.9989013671875,
-0.998046875, -0.9969482421875, -0.99560546875, -0.9940185546875, -0.9921875, -0.9901123046875,
-0.98779296875, -0.9852294921875, -0.982421875, -0.9793701171875, -0.97607421875, -0.9725341796875,
-0.96875, -0.9647216796875, -0.96044921875, -0.9559326171875, -0.951171875, -0.9461669921875,
@@ -26,7 +26,7 @@ public final class LookupTables {
0.69970703124999956, 0.7286376953125, 0.75781249999999956, 0.78723144531249978, 0.81689453125,
0.84680175781249956, 0.876953125, 0.90734863281249956, 0.93798828124999978, 0.9688720703125 };
- public static final double[] secondOrderCoefficients = { -0.50000000000000011, 0.9998779296875, 0.99951171875,
+ protected static final double[] secondOrderCoefficients = { -0.50000000000000011, 0.9998779296875, 0.99951171875,
0.9989013671875, 0.998046875, 0.9969482421875, 0.99560546875, 0.9940185546875, 0.9921875, 0.9901123046875,
0.98779296875, 0.9852294921875, 0.982421875, 0.9793701171875, 0.97607421875, 0.9725341796875, 0.96875,
0.9647216796875, 0.96044921875, 0.9559326171875, 0.951171875, 0.9461669921875, 0.94091796875,
@@ -50,7 +50,7 @@ public final class LookupTables {
-0.69970703124999956, -0.7286376953125, -0.75781249999999956, -0.78723144531249978, -0.81689453125,
-0.84680175781249956, -0.876953125, -0.90734863281249956, -0.93798828124999978, -0.9688720703125 };
- public static final double[] higherOrderCoefficients = { -1, -0.984375, -0.96875, -0.953125, -0.9375, -0.921875,
+ protected static final double[] higherOrderCoefficients = { -1, -0.984375, -0.96875, -0.953125, -0.9375, -0.921875,
-0.90625, -0.890625, -0.875, -0.859375, -0.84375, -0.828125, -0.8125, -0.796875, -0.78125, -0.765625, -0.75,
-0.734375, -0.71875, -0.703125, -0.6875, -0.671875, -0.65625, -0.640625, -0.625, -0.609375, -0.59375,
-0.578125, -0.5625, -0.546875, -0.53125, -0.515625, -0.5, -0.484375, -0.46875, -0.453125, -0.4375,
diff --git a/src/main/java/org/sela/utils/ProgressPrinter.java b/src/main/java/org/sela/utils/ProgressPrinter.java
index a61ea9f..f4e147c 100644
--- a/src/main/java/org/sela/utils/ProgressPrinter.java
+++ b/src/main/java/org/sela/utils/ProgressPrinter.java
@@ -14,15 +14,10 @@ public ProgressPrinter(final Progress progress) {
}
public void run() {
- while (progress.current < progress.total) {
- printProgress(progress.current, progress.total);
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ while (progress.getCurrent() < progress.total) {
+ printProgress(progress.getCurrent(), progress.total);
}
- printProgress(progress.current, progress.total); // Print one last time to make it 100%
+ printProgress(progress.getCurrent(), progress.total); // Print one last time to make it 100%
}
private void printProgress(final long current, final long total) {