Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

嘗試將lame部分改成 submodue #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
701 changes: 675 additions & 26 deletions .gitignore

Large diffs are not rendered by default.

704 changes: 704 additions & 0 deletions Lame/.gitignore

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Lame/LameMP3/CMake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
22 changes: 22 additions & 0 deletions Lame/LameMP3/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

#define cpp source path
#set(SRC_DIR src/main/cpp/lamemp3)

#set *.h source path
include_directories(src/main/cpp/lamemp3)

#set cpp source path
#aux_source_directory(src/main/cpp/lamemp3 SRC_LIST)

#set *.so files output path,please add this before add_library
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI})
set(jnilibs "${CMAKE_SOURCE_DIR}/src/main/jniLibs")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${jnilibs}/${ANDROID_ABI})

ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/src/main/cpp/lamemp3)
21 changes: 21 additions & 0 deletions Lame/LameMP3/CMake/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Jay-Goo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
80 changes: 80 additions & 0 deletions Lame/LameMP3/CMake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Mp3Converter
Use latest [Lame-3.100](http://lame.sourceforge.net/) to transform PCM, WAV, AIFF and other uncompressed formats into MP3 format files.
http://gujinjie.top/article/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0Android%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8NDK%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAMP3%E8%BD%AC%E7%A0%81%E5%BA%93/
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2018/0419/9615.html
https://github.com/GavinCT/AndroidMP3Recorder
https://github.com/Jay-Goo/Mp3Converter
# Usage
## Dependencies

```
//Project build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
//Module build.gradle
dependencies {
implementation 'com.github.Jay-Goo:Mp3Converter:v0.0.3'
}
```
## Methods

```
/**
* init lame
* @param inSampleRate
* input sample rate in Hz
* @param channel
* number of channels
* @param mode
* 0 = CBR, 1 = VBR, 2 = ABR. default = 0
* @param outSampleRate
* output sample rate in Hz
* @param outBitRate
* rate compression ratio in KHz
* @param quality
* quality=0..9. 0=best (very slow). 9=worst.<br />
* recommended:<br />
* 2 near-best quality, not too slow<br />
* 5 good quality, fast<br />
* 7 ok quality, really fast
*/
Mp3Converter.init(44100, 1, 0, 44100, 96, 7);

/**
* file convert to mp3
    * it may cost a lot of time and better put it in a thread
    * @param input
* file path to be converted
* @param mp3
* mp3 output file path
*/
Mp3Converter.convertMp3(inputPath, mp3Path);


/**
* get converted bytes in inputBuffer
* @return
* converted bytes in inputBuffer
* to ignore the deviation of the file size,when return to -1 represents convert complete
*/
Mp3Converter.getConvertBytes()
```
## Build
You can use Android Studio `Make Module 'library'`to create your *.so files, they will be created in your `library/src/jniLibs`Folder.

# ABI
This library support `armeabi-v7a`, `arm64-v8a`, `mips`, `mips64`, `x86`, `x86_64`

# Blog
You can learn how to build this library through [this article](https://gujinjie.top/2018/04/19/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0Android%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8NDK%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAMP3%E8%BD%AC%E7%A0%81%E5%BA%93/).

# Future
Support amr format

# License
MIT License
Copyright (c) 2018 Jay-Goo
54 changes: 54 additions & 0 deletions Lame/LameMP3/CMake/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
abiFilters "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
}
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}

packagingOptions {
pickFirst 'lib/armeabi-v7a/libmp3lame.so'
pickFirst 'lib/arm64-v8a/libmp3lame.so'
pickFirst 'lib/armeabi/libmp3lame.so'
pickFirst 'lib/x86/libmp3lame.so'
pickFirst 'lib/mips/libmp3lame.so'
pickFirst 'lib/mips64/libmp3lame.so'
pickFirst 'lib/x86_64/libmp3lame.so'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}

// Ref :https://stackoverflow.com/questions/39613452/copy-shared-objects-to-jnilibs-when-using-cmake-for-android
task copySoTojniLibs(type: Copy, dependsOn: 'bundleDebug') {
from ('.externalNativeBuild/cmake/debug/libs') {
include '**/*.so'
}
into 'src/main/jniLibs'
}
21 changes: 21 additions & 0 deletions Lame/LameMP3/CMake/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
6 changes: 6 additions & 0 deletions Lame/LameMP3/CMake/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.sourceforge.lame">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
45 changes: 45 additions & 0 deletions Lame/LameMP3/CMake/src/main/cpp/lamemp3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#add cpp files into library
# SUBDIRECTORY method
add_library(
# Sets the name of the library.
lame
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
lame.c
bitstream.c
encoder.c
fft.c
gain_analysis.c
id3tag.c
mpglib_interface.c
newmdct.c
presets.c
psymodel.c
quantize.c
quantize_pvt.c
reservoir.c
set_get.c
tables.c
takehiro.c
vbrquantize.c
util.c
VbrTag.c
version.c
)

find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
lame
# Links the target library to the log library
# included in the NDK.
${log-lib})
Loading