berndporr / Flac2Raw

Android library which turns a compressed audio file into a raw audio file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flac to Raw

This Android package converts a flac file to a raw file. The flac file can be in the filesystem or be an Android asset. The output format is 16 bit / little endian without any header. Just raw audio. Supported sampling rates are 8kHz, 44.1kHz and 48kHz.

It uses the C high performance audio stack of Android so the only limiting factor is the writing speed of the memory card.

Usage

Compile the library

Select Build -> Build variant and select release. Then compile the library.

Importing the library into your project

In your project do File -> New -> New Module -> Import AAR. Import the library from Flac2Raw/flac2raw/build/outputs/aar/flac2raw-release.aar.

Add to your gradle config file the line: implementation project(":flac2raw-release").

JAVA code

It's implemented as a class with a single method. Instantiating the class loads the shared library into memory and then you can call uncompressFile2File or uncompressAsset2File which converts the audio. The call is blocking but should be thread safe if called multiple times from different threads.

If you want to convert from file to file:

// instantiate the converter
Flac2Raw flac2Raw = new Flac2Raw();
// run it
flac2Raw.uncompressFile2File(getFullPath(audioFileName+".flac"),getFullPath(audioFileName+".raw"),48000);

If you want to decompress an Android asset to a raw file:

        AssetManager assetManager = getAssets();
        flac2Raw.uncompressAsset2File(
                assetManager,
                "myasset.flac",
                getFullPath(audioAsset+".raw"),48000);

Unit test

The unit test UncompressFlacFileTest.java contains a full example. Place a mono flac file called test.flac which has a sampling rate of 48kHz in the Music folder of your phone. Run the unit test and you should then see a test.raw in the Music folder. It also decompresses an asset from the asset directory.

Status

Converts properly flac mono to mono raw (see unit test) but not tested for any other formats. It should also work with aac and mp3.

Credit

Google open source project

About

Android library which turns a compressed audio file into a raw audio file

License:Apache License 2.0


Languages

Language:C++ 74.4%Language:Java 19.1%Language:CMake 6.3%Language:Shell 0.2%