Skip to content

Commit

Permalink
Use mp3spi library for mp3 file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nianna committed Oct 24, 2024
1 parent e4284c2 commit 3dfb464
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 232 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ You can found the newest version in the [Releases](https://github.com/Nianna/Kar

Karedi uses the following libraries:
* [JavaFX](https://github.com/openjdk/jfx) with [ControlsFX](https://github.com/controlsfx/controlsfx) & [RichTextFx](https://github.com/TomasMikula/RichTextFX) for GUI,
* [mp3agic](https://github.com/mpatric/mp3agic) for reading mp3 info,
* [jLayer](http://www.javazoom.net/javalayer/javalayer.html) for playing mp3 files,
* [jFugue](http://www.jfugue.org) to simplify the process of creating MIDI sequences,
* [hyphenator](https://github.com/Nianna/hyphenator) for syllabification,
* [javasound-aac](https://github.com/Tianscar/javasound-aac) for m4a files support,
* mp3spi for mp3 files support,
* [java-vorbis-support](https://github.com/Trilarion/java-vorbis-support) for Ogg Vorbis support.

## License
Expand Down
Binary file not shown.
92 changes: 57 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
<javasound-aac.version>0.9.8</javasound-aac.version>
<javasound-resloader.version>0.1.3</javasound-resloader.version>
<java-vorbis-support.version>1.2.1</java-vorbis-support.version>
<jlayer.version>1.0.1</jlayer.version>
<mp3spi.version>1.9.5.4</mp3spi.version>
<junit.version>5.11.0</junit.version>
<mp3agic.version>0.8.1</mp3agic.version>
<richtextfx.version>0.11.0</richtextfx.version>
<hyphenator.version>1.0.1</hyphenator.version>
</properties>
Expand Down Expand Up @@ -117,23 +116,6 @@
<overwriteExistingFiles>true</overwriteExistingFiles>
<outputDirectory>${project.jars.outputDirectory}</outputDirectory>
<modules>
<module>
<artifact>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>jlayer</artifactId>
<version>${jlayer.version}</version>
</artifact>
<moduleInfoSource>
module jlayer {
requires transitive java.desktop;

exports javazoom.jl.converter;
exports javazoom.jl.decoder;
exports javazoom.jl.player;
exports javazoom.jl.player.advanced;
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>jfugue</groupId>
Expand Down Expand Up @@ -207,13 +189,57 @@
</module>
<module>
<artifact>
<groupId>com.mpatric</groupId>
<artifactId>mp3agic</artifactId>
<version>${mp3agic.version}</version>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>mp3spi</artifactId>
<version>${mp3spi.version}</version>
</artifact>
<moduleInfoSource>
module mp3agic {
exports com.mpatric.mp3agic;
module mp3spi {
requires java.desktop;
requires java.logging;
requires tritonus.share;
requires jlayer;

exports javazoom.spi.mpeg.sampled.convert;
exports javazoom.spi.mpeg.sampled.file;

provides javax.sound.sampled.spi.AudioFileReader
with javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
provides javax.sound.sampled.spi.FormatConversionProvider
with javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider;
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>tritonus-share</artifactId>
<version>0.3.7.4</version>
</artifact>
<moduleInfoSource>
module tritonus.share {
requires java.desktop;
requires java.logging;

exports org.tritonus.share.sampled.file;
exports org.tritonus.share.sampled.convert;
exports org.tritonus.share.sampled;
exports org.tritonus.share;
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>jlayer</artifactId>
<version>1.0.1.4</version>
</artifact>
<moduleInfoSource>
module jlayer {
requires transitive java.desktop;

exports javazoom.jl.converter;
exports javazoom.jl.decoder;
}
</moduleInfoSource>
</module>
Expand Down Expand Up @@ -402,12 +428,6 @@
<version>${hyphenator.version}</version>
</dependency>

<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>jlayer</artifactId>
<version>${jlayer.version}</version>
</dependency>

<dependency>
<groupId>jfugue</groupId>
<artifactId>jfugue</artifactId>
Expand All @@ -432,16 +452,18 @@
<version>${java-vorbis-support.version}</version>
</dependency>

<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>mp3spi</artifactId>
<version>${mp3spi.version}</version>
</dependency>

<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>${controlsfx.version}</version>
</dependency>
<dependency>
<groupId>com.mpatric</groupId>
<artifactId>mp3agic</artifactId>
<version>${mp3agic.version}</version>
</dependency>

<dependency>
<groupId>org.fxmisc.richtext</groupId>
<artifactId>richtextfx</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private AudioFileLoader() {
}

/**
* Loads the specified mp3 file on a background thread and passes the
* Loads the specified audio file on a background thread and passes the
* optional result to the given consumer.
*
* @param file
Expand Down Expand Up @@ -57,10 +57,10 @@ private static class LoadAudioFileTask extends Task<PreloadedAudioFile> {
}

@Override
protected PreloadedAudioFile call() throws Exception {
protected PreloadedAudioFile call() {
String extension = Utils.getFileExtension(file);
if (MP3_EXT.contains(extension)) {
return new Mp3File(file);
return SourceDataLineAudioFile.mp3File(file);
}
if (WAV_EXT.contains(extension)) {
return SourceDataLineAudioFile.wavFile(file);
Expand Down
69 changes: 0 additions & 69 deletions src/main/java/com/github/nianna/karedi/audio/Mp3File.java

This file was deleted.

53 changes: 0 additions & 53 deletions src/main/java/com/github/nianna/karedi/audio/Mp3FilePlayTask.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ void play(long startMillis, long endMillis) {
}

private static Task<Long> createPlayTask(PreloadedAudioFile file, Long startMillis, Long endMillis) {
if (file instanceof Mp3File) {
return new Mp3FilePlayTask((Mp3File) file, startMillis, endMillis);
}
if (file instanceof SourceDataLineAudioFile) {
return new SourceDataLineAudioFilePlayTask((SourceDataLineAudioFile) file, startMillis, endMillis);
}
Expand Down
55 changes: 0 additions & 55 deletions src/main/java/com/github/nianna/karedi/audio/SamplesPerFrame.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.nianna.karedi.audio;

import net.sourceforge.jaad.spi.javasound.AACAudioFileReader;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
Expand Down Expand Up @@ -46,7 +48,7 @@ public void releaseResources() {

public static SourceDataLineAudioFile aacFile(File file) {
try {
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioInputStream in = new AACAudioFileReader().getAudioInputStream(file);
AudioFormat inAudioFormat = in.getFormat();
AudioFormat decodedAudioFormat = new AudioFormat(
AudioSystem.NOT_SPECIFIED,
Expand All @@ -71,6 +73,16 @@ public static PreloadedAudioFile vorbisFile(File file) {
}
}

public static PreloadedAudioFile mp3File(File file) {
try {
AudioInputStream in = AudioSystem.getAudioInputStream(file);
return convertAndLoadAudio(file, in);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

public static PreloadedAudioFile wavFile(File file) {
try {
AudioInputStream in = AudioSystem.getAudioInputStream(file);
Expand Down
Loading

0 comments on commit 3dfb464

Please sign in to comment.