CASampledSP is an implementation of the
javax.sound.sampled
service provider interfaces based on Apple's Core Audio library, supporting all its file formats (mp3, aac, ...).
It is part of the SampledSP collection of javax.sound.sampled
libraries.
Its main purpose is to decode audio files or streams to signed linear PCM.
To use the library with Maven, introduce the following dependency:
<dependency>
<groupId>com.tagtraum</groupId>
<artifactId>casampledsp-complete</artifactId>
</dependency>
Note that when opening a compressed file with CASampledSP, you still need to convert to PCM in order to actually decode the file.
Here's a simple example for how that's done for mp3 to wave:
public static void mp3ToWav(File mp3Data) throws UnsupportedAudioFileException, IOException {
// open stream
AudioInputStream mp3Stream = AudioSystem.getAudioInputStream(mp3Data);
AudioFormat sourceFormat = mp3Stream.getFormat();
// create audio format object for the desired stream/audio format
// this is *not* the same as the file format (wav)
AudioFormat convertFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
sourceFormat.getSampleRate(), 16,
sourceFormat.getChannels(),
sourceFormat.getChannels() * 2,
sourceFormat.getSampleRate(),
false);
// create stream that delivers the desired format
AudioInputStream converted = AudioSystem.getAudioInputStream(convertFormat, mp3Stream);
// write stream into a file with file format wav
AudioSystem.write(converted, Type.WAVE, new File("C:\\temp\\out.wav"));
}
See also here.
You can only build this library on macOS.
To do so, you also need:
- Maven 3.0.5 or later, https://maven.apache.org/
- Apple Command Line Tools, available via https://developer.apple.com/, or XCode, https://developer.apple.com/xcode/
- a JDK (to run Maven and get the JNI headers)
- Doxygen, available via MacPorts or HomeBrew
Once you have all this, you need to adjust some properties in the parent pom.xml
.
Or.. simply override them using -Dname=value
notation. E.g. to point to your
Oracle JDK JNI headers, add e.g.
-Ddarwin.headers.jni=/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/include/
to your mvn call. You might also need to change mmacosx-version-min
and isysroot
, if you
don't have an OS X 10.7 SDK installed.
So all in all, something like the following might work for you:
mvn -Ddarwin.headers.jni=/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/include/ \
-Dmmacosx-version-min=10.7 \
-Disysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/ \
clean install
You can find the release notes/history here.