Skip to content

Commit

Permalink
JDK 11 upgrade
Browse files Browse the repository at this point in the history
JNA Upgrade
  • Loading branch information
sheinbergon committed Nov 24, 2023
1 parent 224ad6e commit 0b70fa4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 59 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Artifacts are available on maven central:
<dependency>
<groupId>org.sheinbergon</groupId>
<artifactId>jna-aac-encoder</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
</dependency>
```

**_Gradle_**
```groovy
compile 'org.sheinbergon:jna-aac-encoder:2.0.0'
compile 'org.sheinbergon:jna-aac-encoder:2.1.0'
```

#### Additional information
Expand All @@ -51,7 +51,8 @@ compile 'org.sheinbergon:jna-aac-encoder:2.0.0'
* Windows (64-bit)
* OSX (Intel 64-bit / Apple Silicon, compiled with Xcode 13.3 SDK)
* Tested with FDK-AAC version is 2.0.2
* Lower `2.0.x` versions of FDK-AAC might work, but haven't been tested.
* Earlier `2.0.x` versions of FDK-AAC might work, but haven't been tested.
* For JDK 8 compatibility, please use version `2.0.0` of this library
* For `0.1.6`/`0.1.5` FDK-AAC support and Windows 32 bit support, please use version `0.1.9` of this library

### Encoding using the JVM AudioSystem
Expand Down Expand Up @@ -92,7 +93,7 @@ the encoding process to fail.

Additional restrictions:
* A maximum of 6 audio input/output channels
* Only the AAC-LC/HE-AAC/HE-AACv2 encoding profiles are supported
* Only the AAC-LC/HE-AAC/HE-AACv2 encoding profiles are supported

## Roadmap
* Improved lower-level interface (with examples).
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
ext {
depVersions = [
lombok : '1.18.30',
jna : '5.12.1',
jna : '5.13.0',
commonsLang3: '3.14.0',
jsr305 : '3.0.2'
]
Expand All @@ -40,7 +40,7 @@ ext {
}

group 'org.sheinbergon'
version '2.0.0'
version '2.1.0'

repositories {
mavenCentral()
Expand Down Expand Up @@ -74,7 +74,7 @@ dependencies {
benchmarkImplementation "commons-io:commons-io:${benchmarkDepVersions.commonsIO}"
}

sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11

test {

Expand Down Expand Up @@ -105,7 +105,7 @@ jacoco {
}

checkstyle {
toolVersion '9.3'
toolVersion '10.12.5'
configFile file("$rootDir/checkstyle.xml")
}

Expand Down
24 changes: 9 additions & 15 deletions src/benchmark/java/org/sheinbergon/aac/AACEncodingBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
Expand All @@ -41,12 +40,10 @@ public class AACEncodingBenchmark {
private static final String AAC_ENC_COMMAND_TEMPLATE = AAC_ENC_BIN + " -r %d -t %d -a 1 %s %s";

@SuppressWarnings("MagicNumber")
private static final Map<AACEncodingProfile, Float> AAC_ENCODING_PROFILE_BITRATE_FACTOR = new HashMap<AACEncodingProfile, Float>() {
{
put(AACEncodingProfile.AAC_LC, 1.5f);
put(AACEncodingProfile.HE_AAC, 0.625f);
}
};
private static final Map<AACEncodingProfile, Float> AAC_ENCODING_PROFILE_BITRATE_FACTOR = Map.of(
AACEncodingProfile.AAC_LC, 1.5f,
AACEncodingProfile.HE_AAC, 0.625f
);

private static final AudioFileFormat.Type WAV = AudioFileFormat.Type.WAVE;
private static final String WAV_EXT = "." + WAV.getExtension();
Expand All @@ -60,14 +57,11 @@ public class AACEncodingBenchmark {

private static final String INPUT_RESOURCE_NAME = "africa-toto.wav";

private static final Map<AACEncodingProfile, AudioFileFormat.Type> ENCODING_PROFILES_TO_FILE_TYPES =
new HashMap<AACEncodingProfile, AudioFileFormat.Type>() {
{
put(AACEncodingProfile.AAC_LC, AACFileTypes.AAC_LC);
put(AACEncodingProfile.HE_AAC, AACFileTypes.AAC_HE);
put(AACEncodingProfile.HE_AAC_V2, AACFileTypes.AAC_HE_V2);
}
};
private static final Map<AACEncodingProfile, AudioFileFormat.Type> ENCODING_PROFILES_TO_FILE_TYPES = Map.of(
AACEncodingProfile.AAC_LC, AACFileTypes.AAC_LC,
AACEncodingProfile.HE_AAC, AACFileTypes.AAC_HE,
AACEncodingProfile.HE_AAC_V2, AACFileTypes.AAC_HE_V2
);

/* This is manually set by each benchmark iteration. @Param annotations are not used
* in order to allow better visualization via JMH visualizer.
Expand Down
31 changes: 12 additions & 19 deletions src/main/java/org/sheinbergon/aac/encoder/AACAudioEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import javax.annotation.concurrent.NotThreadSafe;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand All @@ -34,16 +32,13 @@
public final class AACAudioEncoder implements AutoCloseable {

@SuppressWarnings("MagicNumber")
private static final Set<Integer> SAMPLE_RATES = new HashSet<Integer>() {
{
add(16000);
add(22050);
add(24000);
add(32000);
add(44100);
add(48000);
}
};
private static final Set<Integer> SAMPLE_RATES = Set.of(
16000,
22050,
24000,
32000,
44100,
48000);

// Some fdk-aac internal constants
private static final int PARAMETRIC_STEREO_CHANNEL_COUNT = 2;
Expand Down Expand Up @@ -107,13 +102,11 @@ public static class Builder {
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/include/aacenc_lib.h">fdk-aac/libAACenc/include/aacenc_lib.h</a>
*/
@SuppressWarnings("MagicNumber")
private static final Map<AACEncodingProfile, Float> SAMPLES_TO_BIT_RATE_RATIO = new HashMap<AACEncodingProfile, Float>() {
{
put(AACEncodingProfile.AAC_LC, 1.5f);
put(AACEncodingProfile.HE_AAC, 0.625f);
put(AACEncodingProfile.HE_AAC_V2, 0.5f);
}
};
private static final Map<AACEncodingProfile, Float> SAMPLES_TO_BIT_RATE_RATIO = Map.of(
AACEncodingProfile.AAC_LC, 1.5f,
AACEncodingProfile.HE_AAC, 0.625f,
AACEncodingProfile.HE_AAC_V2, 0.5f
);

// Defaults
private boolean afterBurner = true;
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/org/sheinbergon/aac/sound/AACFileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -29,14 +28,11 @@ public final class AACFileWriter extends AudioFileWriter {

private static final int INPUT_BUFFER_MULTIPLIER = 16;

private static final Map<AudioFileFormat.Type, AACEncodingProfile> FILE_TYPES_TO_ENCODING_PROFILES =
new HashMap<AudioFileFormat.Type, AACEncodingProfile>() {
{
put(AACFileTypes.AAC_LC, AACEncodingProfile.AAC_LC);
put(AACFileTypes.AAC_HE, AACEncodingProfile.HE_AAC);
put(AACFileTypes.AAC_HE_V2, AACEncodingProfile.HE_AAC_V2);
}
};
private static final Map<AudioFileFormat.Type, AACEncodingProfile> FILE_TYPES_TO_ENCODING_PROFILES = Map.of(
AACFileTypes.AAC_LC, AACEncodingProfile.AAC_LC,
AACFileTypes.AAC_HE, AACEncodingProfile.HE_AAC,
AACFileTypes.AAC_HE_V2, AACEncodingProfile.HE_AAC_V2
);

@Override
public AudioFileFormat.Type[] getAudioFileTypes() {
Expand Down
13 changes: 6 additions & 7 deletions src/test/java/org/sheinbergon/aac/MediaInfoSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import javax.sound.sampled.AudioFormat;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@SuppressWarnings("MissingJavadocMethod")
public final class MediaInfoSupport {
Expand Down Expand Up @@ -35,19 +34,19 @@ public static void assertAACOutput(
final AACEncodingProfile profile) {
boolean opened = false;
try {
if (opened = MEDIA_INFO.open(aac)) {
if (!(opened = MEDIA_INFO.open(aac))) {
throw new IllegalStateException("Could not open AAC file " + aac + " via the mediainfo shared library");
} else {
Assertions
.assertEquals(EXPECTED_AUDIO_STREAMS_COUNT, MEDIA_INFO.streamCount(MediaInfoLibFacade.StreamKind.Audio));
Assertions.assertEquals(inputFormat.getSampleRate(),
Float.valueOf(getParam("SamplingRate")).floatValue());
Assertions.assertEquals(inputFormat.getChannels(), Integer.valueOf(getParam("Channel(s)")).intValue());
Assertions.assertEquals(AAC_MEDIAINFO_FORMAT, getParam("Format"));
Assertions.assertTrue(new HashSet<>(Arrays.asList(
Assertions.assertTrue(Set.of(
getParam("Format_AdditionalFeatures"),
getParam("Format_Commercial")
)).contains(profile.code()));
} else {
throw new IllegalStateException("Could not open AAC file " + aac + " via the mediainfo shared library");
).contains(profile.code()));
}
} finally {
if (opened) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void supportedAudioInput() throws UnsupportedAudioFileException, IOExcept
@DisplayName("Unsupported audio input")
public void unsupportedAudioEncoding() throws IOException {
val aac = TestSupport.tempAACOutputFile();
Assertions.assertThrows(UnsupportedAudioFileException.class, () -> {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
try (val input = TestSupport.unsupported24bitWAVAudioInputStream()) {
writer.write(input, AACFileTypes.AAC_LC, aac);
} finally {
Expand Down

0 comments on commit 0b70fa4

Please sign in to comment.