https://github.com/hendriks73/casampledsp
CoreAudio-based service provider for javax.sound.sampled.
https://github.com/hendriks73/casampledsp
aac-audio aac-decoder apple-lossless audio-library coreaudio decode-audio-files java java-library m4a macos mp3 mp3-decoder
Last synced: 10 months ago
JSON representation
CoreAudio-based service provider for javax.sound.sampled.
- Host: GitHub
- URL: https://github.com/hendriks73/casampledsp
- Owner: hendriks73
- License: lgpl-2.1
- Created: 2013-06-29T08:52:12.000Z (almost 13 years ago)
- Default Branch: dev
- Last Pushed: 2024-09-27T10:08:22.000Z (over 1 year ago)
- Last Synced: 2025-04-30T04:47:31.586Z (12 months ago)
- Topics: aac-audio, aac-decoder, apple-lossless, audio-library, coreaudio, decode-audio-files, java, java-library, m4a, macos, mp3, mp3-decoder
- Language: Java
- Homepage:
- Size: 2.39 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
README.md
==========
[](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)
[](https://maven-badges.herokuapp.com/maven-central/com.tagtraum/casampledsp-complete)
[](https://github.com/hendriks73/casampledsp/actions)
[](https://codecov.io/gh/hendriks73/casampledsp/branch/main)
*CASampledSP* is an implementation of the
[javax.sound.sampled](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/sound/sampled/spi/package-summary.html)
service provider interfaces based on Apple's Core Audio library, supporting all its file formats (mp3, aac, ...).
It is part of the [SampledSP](https://www.tagtraum.com/sampledsp.html) collection of `javax.sound.sampled`
libraries.
Its main purpose is to decode audio files or streams to signed
linear [PCM](https://en.wikipedia.org/wiki/Pulse-code_modulation).
Usage Example
-------------
To use the library with Maven, introduce the following dependency:
```xml
com.tagtraum
casampledsp-complete
```
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:
```java
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](https://stackoverflow.com/a/41850901/942774).
Build
-----
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](http://www.doxygen.org), available via [MacPorts](https://www.macports.org) or [HomeBrew](https://brew.sh)
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
Release Notes
-------------
You can find the release notes/history [here](NOTES.md).