├── .gitignore ├── LICENSE ├── README.md ├── ame-lite ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── auxo │ │ └── ame │ │ └── lite │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── cpp │ │ ├── CMakeLists.txt │ │ ├── callback.c │ │ ├── callback.h │ │ ├── jni_util.c │ │ ├── jni_util.h │ │ ├── mp3_encoder.c │ │ ├── mp3_encoder.h │ │ ├── parse.c │ │ └── parse.h │ └── java │ │ └── io │ │ └── auxo │ │ └── ame │ │ └── lite │ │ └── Mp3Encoder.java │ └── test │ └── java │ └── io │ └── auxo │ └── ame │ └── lite │ └── ExampleUnitTest.java ├── ame ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── auxo │ │ └── ame │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── cpp │ │ ├── CMakeLists.txt │ │ ├── ame_main.c │ │ ├── ame_main.h │ │ ├── frontend │ │ │ ├── Makefile.am │ │ │ ├── Makefile.in │ │ │ ├── amiga_mpega.c │ │ │ ├── brhist.c │ │ │ ├── brhist.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── depcomp │ │ │ ├── get_audio.c │ │ │ ├── get_audio.h │ │ │ ├── lame_main.c │ │ │ ├── lametime.c │ │ │ ├── lametime.h │ │ │ ├── parse.c │ │ │ ├── parse.h │ │ │ ├── timestatus.c │ │ │ └── timestatus.h │ │ ├── jni_util.c │ │ ├── jni_util.h │ │ ├── mp3_encoder.c │ │ └── mp3_encoder.h │ └── java │ │ └── io │ │ └── auxo │ │ └── ame │ │ ├── Mp3Encoder.java │ │ └── options │ │ ├── AbrOptions.java │ │ ├── CbrOptions.java │ │ ├── FilterOptions.java │ │ ├── Id3TagOptions.java │ │ ├── InputOptions.java │ │ ├── Mp3HeaderStreamOptions.java │ │ ├── OperationalOptions.java │ │ ├── RawPcmInputOptions.java │ │ └── VbrOptions.java │ └── test │ └── java │ └── io │ └── auxo │ └── ame │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mavenUpload.gradle ├── mp3lame ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── cpp │ ├── CMakeLists.txt │ ├── VbrTag.c │ ├── VbrTag.h │ ├── bitstream.c │ ├── bitstream.h │ ├── encoder.c │ ├── encoder.h │ ├── fft.c │ ├── fft.h │ ├── gain_analysis.c │ ├── gain_analysis.h │ ├── id3tag.c │ ├── id3tag.h │ ├── l3side.h │ ├── lame-analysis.h │ ├── lame.c │ ├── lame.h │ ├── lame_global_flags.h │ ├── lameerror.h │ ├── machine.h │ ├── mpglib_interface.c │ ├── newmdct.c │ ├── newmdct.h │ ├── presets.c │ ├── psymodel.c │ ├── psymodel.h │ ├── quantize.c │ ├── quantize.h │ ├── quantize_pvt.c │ ├── quantize_pvt.h │ ├── reservoir.c │ ├── reservoir.h │ ├── set_get.c │ ├── set_get.h │ ├── tables.c │ ├── tables.h │ ├── takehiro.c │ ├── util.c │ ├── util.h │ ├── vbrquantize.c │ ├── vbrquantize.h │ ├── vector │ ├── lame_intrin.h │ └── xmm_quantize_sub.c │ ├── version.c │ └── version.h ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── auxo │ │ └── ame │ │ └── sample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── io │ │ │ └── auxo │ │ │ └── ame │ │ │ └── sample │ │ │ ├── AmeActivity.java │ │ │ ├── AmeLiteActivity.java │ │ │ ├── FileChooser.java │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_ame.xml │ │ ├── activity_ame_lite.xml │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── io │ └── auxo │ └── ame │ └── sample │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | /*/build/ 3 | 4 | # Crashlytics configuations 5 | com_crashlytics_export_strings.xml 6 | 7 | # Local configuration file (sdk path, etc) 8 | local.properties 9 | 10 | # Gradle generated files 11 | .gradle/ 12 | 13 | # Signing files 14 | .signing/ 15 | 16 | # User-specific configurations 17 | *.iml 18 | 19 | # OS-specific files 20 | .DS_Store 21 | .DS_Store? 22 | ._* 23 | .Spotlight-V100 24 | .Trashes 25 | 26 | .svn 27 | ehthumbs.db 28 | Thumbs.db 29 | build/ 30 | .idea/ 31 | *.apk 32 | 33 | .externalNativeBuild 34 | 35 | dist/ 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Victor Chiu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Android MP3 Encoder 2 | ===================== 3 | 添加依赖 4 | ------- 5 | ```groovy 6 | dependencies { 7 | implementation 'io.auxo.ame:ame-lite:0.1' 8 | } 9 | ``` 10 | 11 | AME-lite使用方法 12 | ------- 13 | 14 | 转码过程属于耗时操作,注意不要在UI线程中执行。 15 | ```java 16 | Mp3Encoder.Options options = new Mp3Encoder.Options() 17 | .sampleRate(44000) 18 | .bitrate(120) 19 | .numChannels(2) 20 | .quality(3) 21 | .mode(Mp3Encoder.Options.STEREO); 22 | 23 | Mp3Encoder.Callback callback = new Mp3Encoder.Callback() { 24 | @Override 25 | public void onStart() { 26 | } 27 | 28 | @Override 29 | public void onProgress(int total, int current) { 30 | } 31 | 32 | @Override 33 | public void onComplete() { 34 | } 35 | 36 | @Override 37 | public void onError() { 38 | } 39 | }; 40 | 41 | Mp3Encoder.encode(input, output, options, callback); 42 | // Mp3Encoder.encode(input, output); 43 | // Mp3Encoder.encode(input, output, options); 44 | // Mp3Encoder.encode(input, output, callback); 45 | ``` 46 | 47 | License 48 | ------- 49 | 50 | Copyright (c) 2018 Victor Chiu 51 | 52 | Permission is hereby granted, free of charge, to any person obtaining a copy 53 | of this software and associated documentation files (the "Software"), to deal 54 | in the Software without restriction, including without limitation the rights 55 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 56 | copies of the Software, and to permit persons to whom the Software is 57 | furnished to do so, subject to the following conditions: 58 | 59 | The above copyright notice and this permission notice shall be included in all 60 | copies or substantial portions of the Software. 61 | 62 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 63 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 64 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 65 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 66 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 67 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 68 | SOFTWARE. -------------------------------------------------------------------------------- /ame-lite/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ame-lite/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion versions.compileSdk 5 | 6 | defaultConfig { 7 | minSdkVersion versions.minSdk 8 | targetSdkVersion versions.compileSdk 9 | versionName versions.ame_lite 10 | 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | 13 | ndk { 14 | abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64" 15 | } 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | externalNativeBuild { 26 | cmake { 27 | path "src/main/cpp/CMakeLists.txt" 28 | } 29 | } 30 | } 31 | 32 | dependencies { 33 | 34 | testImplementation deps.junit 35 | androidTestImplementation deps.test.runner 36 | androidTestImplementation deps.test.espresso 37 | 38 | api deps.support.annotations 39 | } 40 | 41 | tasks.whenTaskAdded { task -> 42 | if (task.name == 'externalNativeBuildRelease') { 43 | task.dependsOn ":mp3lame:externalNativeBuildRelease" 44 | } else if (task.name == 'externalNativeBuildDebug') { 45 | task.dependsOn ":mp3lame:externalNativeBuildDebug" 46 | } 47 | if (task.name == 'uploadArchives') { 48 | dependencies.add('implementation', "io.auxo.ame:mp3lame:$versions.mp3lame") 49 | } 50 | } 51 | 52 | apply from: "../mavenUpload.gradle" -------------------------------------------------------------------------------- /ame-lite/gradle.properties: -------------------------------------------------------------------------------- 1 | MAVEN_REPO_RELEASE=https://api.bintray.com/maven/4332weizi/Android/ame-lite/;publish=1 2 | MAVEN_REPO_SNAPSHOT= 3 | MAVEN_REPO_ARTIFACT=ame-lite -------------------------------------------------------------------------------- /ame-lite/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /ame-lite/src/androidTest/java/io/auxo/ame/lite/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.lite; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("io.auxo.ame.lite.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ame-lite/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | set( DIST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../dist ) 4 | 5 | # 添加ame-lite源文件 6 | aux_source_directory( ${CMAKE_HOME_DIRECTORY} AME_LITE_SRC_LIST ) 7 | 8 | add_library( ame-lite 9 | SHARED 10 | ${AME_LITE_SRC_LIST} ) 11 | 12 | # 添加mp3lame动态链接库 13 | add_library( mp3lame SHARED IMPORTED ) 14 | set_target_properties( mp3lame PROPERTIES IMPORTED_LOCATION 15 | ${DIST_DIR}/mp3lame/lib/${ANDROID_ABI}/libmp3lame.so ) 16 | 17 | # 添加mp3lame中的头文件 18 | target_include_directories( ame-lite 19 | PRIVATE 20 | ${DIST_DIR}/mp3lame/include ) 21 | 22 | find_library( log-lib log ) 23 | 24 | target_link_libraries( ame-lite 25 | mp3lame 26 | ${log-lib} ) 27 | 28 | # 设定动态链接库输出路径 29 | set_target_properties( ame-lite 30 | PROPERTIES 31 | LIBRARY_OUTPUT_DIRECTORY 32 | "${DIST_DIR}/ame-lite/lib/${ANDROID_ABI}" ) -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/callback.c: -------------------------------------------------------------------------------- 1 | #include "callback.h" 2 | #include "jni_util.h" 3 | 4 | void on_start(JNIEnv *env, jobject callback) { 5 | if (callback != NULL) { 6 | jmethodID methodId = get_method_id(env, CLASS_NAME_CALLBACK, METHOD_NAME_ON_START, 7 | SIGNATURE_VOID); 8 | (*env)->CallVoidMethod(env, callback, methodId); 9 | } 10 | } 11 | 12 | void on_progress(JNIEnv *env, jobject callback, long total, long current) { 13 | if (callback != NULL) { 14 | jmethodID methodId = get_method_id(env, CLASS_NAME_CALLBACK, METHOD_NAME_ON_PROGRESS, 15 | "(II)V"); 16 | (*env)->CallVoidMethod(env, callback, methodId, total, current); 17 | } 18 | } 19 | 20 | void on_complete(JNIEnv *env, jobject callback) { 21 | if (callback != NULL) { 22 | jmethodID methodId = get_method_id(env, CLASS_NAME_CALLBACK, METHOD_NAME_ON_COMPLETE, 23 | SIGNATURE_VOID); 24 | (*env)->CallVoidMethod(env, callback, methodId); 25 | } 26 | } 27 | 28 | void on_error(JNIEnv *env, jobject callback) { 29 | if (callback != NULL) { 30 | jmethodID methodId = get_method_id(env, CLASS_NAME_CALLBACK, METHOD_NAME_ON_ERROR, 31 | SIGNATURE_VOID); 32 | (*env)->CallVoidMethod(env, callback, methodId); 33 | } 34 | } -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/callback.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #define CLASS_NAME_CALLBACK "io/auxo/ame/lite/Mp3Encoder$Callback" 5 | #define METHOD_NAME_ON_START "onStart" 6 | #define METHOD_NAME_ON_PROGRESS "onProgress" 7 | #define METHOD_NAME_ON_COMPLETE "onComplete" 8 | #define METHOD_NAME_ON_ERROR "onError" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | void on_start(JNIEnv *env, jobject callback); 15 | 16 | void on_progress(JNIEnv *env, jobject callback, long total, long current); 17 | 18 | void on_complete(JNIEnv *env, jobject callback); 19 | 20 | void on_error(JNIEnv *env, jobject callback); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/jni_util.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by ZHAOWEIWEI on 2018/2/8. 3 | // 4 | #include 5 | #include 6 | #include "jni_util.h" 7 | 8 | #define UTF8 "UTF-8" 9 | #define LOG_TAG "ame" 10 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 11 | 12 | char *parse_jstring(JNIEnv *env, jstring jstr) { 13 | char *rtn = NULL; 14 | 15 | jmethodID methodID = get_method_id(env, "java/lang/String", "getBytes", 16 | "(Ljava/lang/String;)[B"); 17 | 18 | jbooleanArray barr = (*env)->CallObjectMethod(env, jstr, methodID, 19 | (*env)->NewStringUTF(env, UTF8)); 20 | 21 | jsize length = (*env)->GetArrayLength(env, barr); 22 | jbyte *ba = (*env)->GetByteArrayElements(env, barr, JNI_FALSE); 23 | 24 | if (length > 0) { 25 | rtn = (char *) malloc(length + 1); 26 | memcpy(rtn, ba, length); 27 | rtn[length] = 0; 28 | } 29 | 30 | (*env)->ReleaseByteArrayElements(env, barr, ba, 0); 31 | (*env)->DeleteLocalRef(env, barr); 32 | 33 | return rtn; 34 | } 35 | 36 | jmethodID 37 | get_method_id(JNIEnv *env, char *className, char *methodName, 38 | char *signature) { 39 | jclass clazz = (*env)->FindClass(env, className); 40 | jmethodID methodID = (*env)->GetMethodID(env, clazz, methodName, signature); 41 | (*env)->DeleteLocalRef(env, clazz); 42 | return methodID; 43 | } 44 | 45 | jobject 46 | invoke_method_get_jobject(JNIEnv *env, jobject obj, char *objClassName, char *methodName, 47 | char *signature) { 48 | jmethodID methodID = get_method_id(env, objClassName, methodName, signature); 49 | return (*env)->CallObjectMethod(env, obj, methodID); 50 | } 51 | 52 | jboolean 53 | invoke_method_get_jboolean(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 54 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_BOOLEAN); 55 | return (*env)->CallBooleanMethod(env, obj, methodID); 56 | } 57 | 58 | jint 59 | invoke_method_get_jint(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 60 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_INT); 61 | return (*env)->CallIntMethod(env, obj, methodID); 62 | } 63 | 64 | jfloat 65 | invoke_method_get_jfloat(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 66 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_FLOAT); 67 | return (*env)->CallFloatMethod(env, obj, methodID); 68 | } 69 | 70 | jdouble 71 | invoke_method_get_jdouble(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 72 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_DOUBLE); 73 | return (*env)->CallDoubleMethod(env, obj, methodID); 74 | } -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/jni_util.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define LOG_TAG "ame" 5 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 6 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 7 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 8 | 9 | #define SIGNATURE_BOOLEAN "()Z" 10 | #define SIGNATURE_BYTE "()B" 11 | #define SIGNATURE_CHAR "()C" 12 | #define SIGNATURE_SHORT "()S" 13 | #define SIGNATURE_INT "()I" 14 | #define SIGNATURE_LONG "()J" 15 | #define SIGNATURE_FLOAT "()F" 16 | #define SIGNATURE_DOUBLE "()D" 17 | #define SIGNATURE_VOID "()V" 18 | #define SIGNATURE_OBJECTS "()L" 19 | 20 | jmethodID 21 | get_method_id(JNIEnv *env, char *className, char *methodName, 22 | char *signature); 23 | 24 | jobject 25 | invoke_method_get_jobject(JNIEnv *env, jobject obj, char *objClassName, char *methodName, 26 | char *signature); 27 | 28 | jboolean 29 | invoke_method_get_jboolean(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 30 | 31 | jint 32 | invoke_method_get_jint(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 33 | 34 | jfloat 35 | invoke_method_get_jfloat(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 36 | 37 | jdouble 38 | invoke_method_get_jdouble(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 39 | 40 | char *parse_jstring(JNIEnv *env, jstring jstr); -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/mp3_encoder.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mp3_encoder.h" 5 | #include "lame.h" 6 | #include "jni_util.h" 7 | #include "callback.h" 8 | #include "parse.h" 9 | 10 | long fsize(FILE *fp) { 11 | long n; 12 | // 当前位置 13 | fpos_t fpos; 14 | // 获取当前位置 15 | fgetpos(fp, &fpos); 16 | fseek(fp, 0, SEEK_END); 17 | n = ftell(fp); 18 | // 恢复之前的位置 19 | fsetpos(fp, &fpos); 20 | return n; 21 | } 22 | 23 | void encode(JNIEnv *env, jclass clazz, jstring in, jstring out, jobject options, jobject callback) { 24 | 25 | lame_global_flags *gf = lame_init(); 26 | // 解析参数 27 | parse_options(env, gf, options); 28 | // 初始化参数 29 | int ret = lame_init_params(gf); 30 | // LAME参数初始化失败 31 | if (ret != 0) { 32 | on_error(env, callback); 33 | return; 34 | } 35 | 36 | // 获取输入输出文件路径 37 | char *src = parse_jstring(env, in); 38 | char *tar = parse_jstring(env, out); 39 | 40 | LOGI("source file is = %s", src); 41 | LOGI("target file is = %s", tar); 42 | 43 | // 打开输入文件 44 | FILE *fin = fopen(src, "rb"); 45 | 46 | if (fin != NULL) { 47 | 48 | // 打开输出文件 49 | FILE *fout = fopen(tar, "wb"); 50 | 51 | short int wav_buffer[8192 * 2]; 52 | unsigned char mp3_buffer[8192]; 53 | 54 | int read; 55 | int write; //代表读了多少个次 和写了多少次 56 | long current = 0; // 当前读的wav文件的byte数目 57 | 58 | long total = fsize(fin); 59 | 60 | // 回调开始转码 61 | on_start(env, callback); 62 | 63 | do { 64 | 65 | read = fread(wav_buffer, sizeof(short int) * 2, 8192, fin); 66 | 67 | current += read * sizeof(short int) * 2; 68 | 69 | if (read != 0) { 70 | write = lame_encode_buffer_interleaved(gf, wav_buffer, read, mp3_buffer, 8192); 71 | // 把转化后的mp3数据写到文件里 72 | fwrite(mp3_buffer, sizeof(unsigned char), write, fout); 73 | } 74 | 75 | if (read == 0) { 76 | lame_encode_flush(gf, mp3_buffer, 8192); 77 | } 78 | 79 | LOGI("on_progress %ld,%ld", total, current); 80 | on_progress(env, callback, total, current); 81 | } while (read != 0); 82 | 83 | LOGI("convert finish"); 84 | 85 | // 关闭文件 86 | lame_close(gf); 87 | fclose(fin); 88 | fclose(fout); 89 | // 回调转码成功 90 | on_complete(env, callback); 91 | } else { 92 | LOGE("Can not found file %s", src); 93 | on_error(env, callback); 94 | } 95 | } 96 | 97 | /* 98 | * Class: io_auxo_ame_lite_Mp3Encoder 99 | * Method: encode 100 | * Signature: (Ljava/lang/String;Ljava/lang/String;Lio/auxo/ame/lite/Mp3Encoder$Options;Lio/auxo/ame/lite/Mp3Encoder$Callback;)V 101 | */ 102 | JNIEXPORT void JNICALL 103 | Java_io_auxo_ame_lite_Mp3Encoder_encode__Ljava_lang_String_2Ljava_lang_String_2Lio_auxo_ame_lite_Mp3Encoder_00024Options_2Lio_auxo_ame_lite_Mp3Encoder_00024Callback_2 104 | (JNIEnv *env, jclass clazz, jstring in, jstring out, jobject options, jobject callback) { 105 | encode(env, clazz, in, out, options, callback); 106 | } 107 | 108 | /* 109 | * Class: io_auxo_ame_lite_Mp3Encoder 110 | * Method: getLameVersion 111 | * Signature: ()Ljava/lang/String; 112 | */ 113 | JNIEXPORT jstring JNICALL Java_io_auxo_ame_lite_Mp3Encoder_getLameVersion 114 | (JNIEnv *env, jobject obj) { 115 | return (*env)->NewStringUTF(env, get_lame_version()); 116 | } -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/mp3_encoder.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class io_auxo_ame_lite_Mp3Encoder */ 4 | 5 | #ifndef _Included_io_auxo_ame_lite_Mp3Encoder 6 | #define _Included_io_auxo_ame_lite_Mp3Encoder 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* 12 | * Class: io_auxo_ame_lite_Mp3Encoder 13 | * Method: encode 14 | * Signature: (Ljava/lang/String;Ljava/lang/String;Lio/auxo/ame/lite/Mp3Encoder$Options;Lio/auxo/ame/lite/Mp3Encoder$Callback;)V 15 | */ 16 | JNIEXPORT void JNICALL Java_io_auxo_ame_lite_Mp3Encoder_encode__Ljava_lang_String_2Ljava_lang_String_2Lio_auxo_ame_lite_Mp3Encoder_00024Options_2Lio_auxo_ame_lite_Mp3Encoder_00024Callback_2 17 | (JNIEnv *, jclass, jstring, jstring, jobject, jobject); 18 | 19 | /* 20 | * Class: io_auxo_ame_lite_Mp3Encoder 21 | * Method: getLameVersion 22 | * Signature: ()Ljava/lang/String; 23 | */ 24 | JNIEXPORT jstring JNICALL Java_io_auxo_ame_lite_Mp3Encoder_getLameVersion 25 | (JNIEnv *, jclass); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | #endif 31 | /* Header for class io_auxo_ame_lite_Mp3Encoder_Options */ 32 | 33 | #ifndef _Included_io_auxo_ame_lite_Mp3Encoder_Options 34 | #define _Included_io_auxo_ame_lite_Mp3Encoder_Options 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | #undef io_auxo_ame_lite_Mp3Encoder_Options_STEREO 39 | #define io_auxo_ame_lite_Mp3Encoder_Options_STEREO 0L 40 | #undef io_auxo_ame_lite_Mp3Encoder_Options_JOINT_STEREO 41 | #define io_auxo_ame_lite_Mp3Encoder_Options_JOINT_STEREO 1L 42 | #undef io_auxo_ame_lite_Mp3Encoder_Options_DUAL_CHANNEL 43 | #define io_auxo_ame_lite_Mp3Encoder_Options_DUAL_CHANNEL 2L 44 | #undef io_auxo_ame_lite_Mp3Encoder_Options_MONO 45 | #define io_auxo_ame_lite_Mp3Encoder_Options_MONO 3L 46 | #undef io_auxo_ame_lite_Mp3Encoder_Options_NOT_SET 47 | #define io_auxo_ame_lite_Mp3Encoder_Options_NOT_SET 4L 48 | #undef io_auxo_ame_lite_Mp3Encoder_Options_VBR_OFF 49 | #define io_auxo_ame_lite_Mp3Encoder_Options_VBR_OFF 0L 50 | #undef io_auxo_ame_lite_Mp3Encoder_Options_VBR_MT 51 | #define io_auxo_ame_lite_Mp3Encoder_Options_VBR_MT 1L 52 | #undef io_auxo_ame_lite_Mp3Encoder_Options_VBR_RH 53 | #define io_auxo_ame_lite_Mp3Encoder_Options_VBR_RH 2L 54 | #undef io_auxo_ame_lite_Mp3Encoder_Options_VBR_ABR 55 | #define io_auxo_ame_lite_Mp3Encoder_Options_VBR_ABR 3L 56 | #undef io_auxo_ame_lite_Mp3Encoder_Options_VBR_MTRH 57 | #define io_auxo_ame_lite_Mp3Encoder_Options_VBR_MTRH 4L 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | #endif 62 | /* Header for class io_auxo_ame_lite_Mp3Encoder_Options_MPEGMode */ 63 | 64 | #ifndef _Included_io_auxo_ame_lite_Mp3Encoder_Options_MPEGMode 65 | #define _Included_io_auxo_ame_lite_Mp3Encoder_Options_MPEGMode 66 | #ifdef __cplusplus 67 | extern "C" { 68 | #endif 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | #endif 73 | /* Header for class io_auxo_ame_lite_Mp3Encoder_Options_VBRMode */ 74 | 75 | #ifndef _Included_io_auxo_ame_lite_Mp3Encoder_Options_VBRMode 76 | #define _Included_io_auxo_ame_lite_Mp3Encoder_Options_VBRMode 77 | #ifdef __cplusplus 78 | extern "C" { 79 | #endif 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #endif 84 | /* Header for class io_auxo_ame_lite_Mp3Encoder_Callback */ 85 | 86 | #ifndef _Included_io_auxo_ame_lite_Mp3Encoder_Callback 87 | #define _Included_io_auxo_ame_lite_Mp3Encoder_Callback 88 | #ifdef __cplusplus 89 | extern "C" { 90 | #endif 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | #endif 95 | -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/parse.c: -------------------------------------------------------------------------------- 1 | 2 | #include "parse.h" 3 | #include "jni_util.h" 4 | 5 | void parse_options(JNIEnv *env, lame_global_flags *gf, jobject options) { 6 | if (options != NULL) { 7 | int sample_rate = invoke_method_get_jint(env, options, OPTIONS_CLASS_NAME, 8 | METHOD_GET_SAMPLE_RATE); 9 | lame_set_out_samplerate(gf, sample_rate); 10 | int bit_rate = invoke_method_get_jint(env, options, OPTIONS_CLASS_NAME, 11 | METHOD_GET_BIT_RATE); 12 | lame_set_brate(gf, bit_rate); 13 | int num_channels = invoke_method_get_jint(env, options, OPTIONS_CLASS_NAME, 14 | METHOD_GET_NUM_CHANNELS); 15 | lame_set_num_channels(gf, num_channels); 16 | int mode = invoke_method_get_jint(env, options, OPTIONS_CLASS_NAME, METHOD_GET_MODE); 17 | lame_set_mode(gf, mode); 18 | int quality = invoke_method_get_jint(env, options, OPTIONS_CLASS_NAME, METHOD_GET_QUALITY); 19 | lame_set_quality(gf, quality); 20 | int vbr_mode = invoke_method_get_jint(env, options, OPTIONS_CLASS_NAME, 21 | METHOD_GET_VBR_MODE); 22 | lame_set_VBR(gf, vbr_mode); 23 | int vbr_quality = invoke_method_get_jint(env, options, OPTIONS_CLASS_NAME, 24 | METHOD_GET_VBR_QUALITY); 25 | lame_set_VBR_q(gf, vbr_quality); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ame-lite/src/main/cpp/parse.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "lame.h" 4 | 5 | #define OPTIONS_CLASS_NAME "io/auxo/ame/lite/Mp3Encoder$Options" 6 | 7 | #define METHOD_GET_SAMPLE_RATE "getSampleRate" 8 | #define METHOD_GET_BIT_RATE "getBitrate" 9 | #define METHOD_GET_NUM_CHANNELS "getNumChannels" 10 | #define METHOD_GET_MODE "getMode" 11 | #define METHOD_GET_QUALITY "getQuality" 12 | #define METHOD_GET_VBR_MODE "getVbrMode" 13 | #define METHOD_GET_VBR_QUALITY "getVbrQuality" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | void parse_options(JNIEnv *env, lame_global_flags *gf, jobject options); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif -------------------------------------------------------------------------------- /ame-lite/src/main/java/io/auxo/ame/lite/Mp3Encoder.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.lite; 2 | 3 | import android.support.annotation.IntDef; 4 | import android.support.annotation.IntRange; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | /** 10 | * Mp3Encoder 11 | * 12 | * @author Victor Chiu 13 | * @date 2018/3/8 14 | */ 15 | 16 | public class Mp3Encoder { 17 | 18 | public static class Options { 19 | 20 | @IntDef({STEREO, JOINT_STEREO, DUAL_CHANNEL, MONO, NOT_SET}) 21 | @Retention(RetentionPolicy.SOURCE) 22 | public @interface MPEGMode { 23 | } 24 | 25 | public static final int STEREO = 0; 26 | public static final int JOINT_STEREO = 1; 27 | public static final int DUAL_CHANNEL = 2; 28 | public static final int MONO = 3; 29 | public static final int NOT_SET = 4; 30 | 31 | @IntDef({VBR_OFF, VBR_MT, VBR_RH, VBR_ABR, VBR_MTRH}) 32 | @Retention(RetentionPolicy.SOURCE) 33 | public @interface VBRMode { 34 | } 35 | 36 | public static final int VBR_OFF = 0; 37 | public static final int VBR_MT = 1; 38 | public static final int VBR_RH = 2; 39 | public static final int VBR_ABR = 3; 40 | public static final int VBR_MTRH = 4; 41 | 42 | private int sampleRate = -1; 43 | private int bitrate = -1; 44 | private int numChannels = -1; 45 | private int mode = -1; 46 | /** 47 | * Internal algorithm selection. 48 | * True quality is determined by the bitrate but this variable will effect 49 | * quality by selecting expensive or cheap algorithms. 50 | * quality=0..9. 51 | * 0=best (very slow). 52 | * 9=worst. 53 | * recommended: 3 near-best quality, not too slow 54 | * 5 good quality, fast 55 | * 7 ok quality, really fast 56 | */ 57 | private int quality = -1; 58 | private int vbrMode = -1; 59 | /** 60 | * 0 = highest 61 | * 9 = lowest 62 | */ 63 | private int vbrQuality = -1; 64 | 65 | public Options sampleRate(int sampleRate) { 66 | this.sampleRate = sampleRate; 67 | return this; 68 | } 69 | 70 | public Options bitrate(int bitrate) { 71 | this.bitrate = bitrate; 72 | return this; 73 | } 74 | 75 | public Options numChannels(@IntRange(from = 1, to = 2) int numChannels) { 76 | this.numChannels = numChannels; 77 | return this; 78 | } 79 | 80 | public Options mode(@MPEGMode int mode) { 81 | this.mode = mode; 82 | return this; 83 | } 84 | 85 | public Options quality(@IntRange(from = 0, to = 9) int quality) { 86 | this.quality = quality; 87 | return this; 88 | } 89 | 90 | public Options vbrMode(@VBRMode int vbrMode) { 91 | this.vbrMode = vbrMode; 92 | return this; 93 | } 94 | 95 | public Options vbrQuality(@IntRange(from = 0, to = 9) int vbrQuality) { 96 | this.vbrQuality = vbrQuality; 97 | return this; 98 | } 99 | 100 | public int getSampleRate() { 101 | return sampleRate; 102 | } 103 | 104 | public int getBitrate() { 105 | return bitrate; 106 | } 107 | 108 | public int getNumChannels() { 109 | return numChannels; 110 | } 111 | 112 | public int getMode() { 113 | return mode; 114 | } 115 | 116 | public int getQuality() { 117 | return quality; 118 | } 119 | 120 | public int getVbrMode() { 121 | return vbrMode; 122 | } 123 | 124 | public int getVbrQuality() { 125 | return vbrQuality; 126 | } 127 | } 128 | 129 | public interface Callback { 130 | void onStart(); 131 | 132 | void onProgress(int total, int current); 133 | 134 | void onComplete(); 135 | 136 | void onError(); 137 | } 138 | 139 | static { 140 | System.loadLibrary("ame-lite"); 141 | } 142 | 143 | public static void encode(String in, String out) { 144 | encode(in, out, null, null); 145 | } 146 | 147 | public static void encode(String in, String out, Options options) { 148 | encode(in, out, options, null); 149 | } 150 | 151 | public static void encode(String in, String out, Callback callback) { 152 | encode(in, out, null, callback); 153 | } 154 | 155 | public static native void encode(String in, String out, Options options, Callback callback); 156 | 157 | /** 158 | * 获取LAME版本 159 | * 160 | * @return LAME版本号 161 | */ 162 | public static native String getLameVersion(); 163 | } 164 | -------------------------------------------------------------------------------- /ame-lite/src/test/java/io/auxo/ame/lite/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.lite; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /ame/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ame/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion versions.compileSdk 5 | 6 | defaultConfig { 7 | minSdkVersion versions.minSdk 8 | targetSdkVersion versions.compileSdk 9 | versionName versions.ame 10 | 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | 13 | externalNativeBuild { 14 | cmake { 15 | cFlags "-DSTDC_HEADERS" 16 | targets 'ame' 17 | } 18 | } 19 | 20 | ndk { 21 | abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64" 22 | } 23 | } 24 | 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | 32 | externalNativeBuild { 33 | cmake { 34 | path "src/main/cpp/CMakeLists.txt" 35 | } 36 | } 37 | } 38 | 39 | dependencies { 40 | 41 | testImplementation deps.junit 42 | androidTestImplementation deps.test.runner 43 | androidTestImplementation deps.test.espresso 44 | 45 | api deps.support.annotations 46 | } 47 | 48 | tasks.whenTaskAdded { task -> 49 | if (task.name == 'externalNativeBuildRelease') { 50 | task.dependsOn ":mp3lame:externalNativeBuildRelease" 51 | } else if (task.name == 'externalNativeBuildDebug') { 52 | task.dependsOn ":mp3lame:externalNativeBuildDebug" 53 | } 54 | if (task.name == 'uploadArchives') { 55 | dependencies.add('implementation', "io.auxo.ame:mp3lame:$versions.mp3lame") 56 | } 57 | } 58 | 59 | apply from: "../mavenUpload.gradle" -------------------------------------------------------------------------------- /ame/gradle.properties: -------------------------------------------------------------------------------- 1 | MAVEN_REPO_RELEASE=https://api.bintray.com/maven/4332weizi/Android/ame/;publish=1 2 | MAVEN_REPO_SNAPSHOT= 3 | MAVEN_REPO_ARTIFACT=ame -------------------------------------------------------------------------------- /ame/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /ame/src/androidTest/java/io/auxo/ame/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("io.auxo.ame.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ame/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /ame/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | set( DIST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../dist ) 4 | 5 | # 添加ame源文件 6 | aux_source_directory( ${CMAKE_HOME_DIRECTORY} AME_SRC_LIST ) 7 | aux_source_directory( ${CMAKE_HOME_DIRECTORY}/frontend AME_FRONTEND_SRC_LIST ) 8 | 9 | add_library( ame 10 | SHARED 11 | ${AME_SRC_LIST} 12 | ${AME_FRONTEND_SRC_LIST}) 13 | 14 | # 添加mp3lame动态链接库 15 | add_library( mp3lame SHARED IMPORTED ) 16 | set_target_properties( mp3lame PROPERTIES IMPORTED_LOCATION 17 | ${DIST_DIR}/mp3lame/lib/${ANDROID_ABI}/libmp3lame.so ) 18 | 19 | # 添加mp3lame中的头文件 20 | target_include_directories( ame 21 | PRIVATE 22 | ${DIST_DIR}/mp3lame/include ) 23 | 24 | target_link_libraries( ame mp3lame ) 25 | 26 | # 设定动态链接库输出路径 27 | set_target_properties( ame 28 | PROPERTIES 29 | LIBRARY_OUTPUT_DIRECTORY 30 | "${DIST_DIR}/ame/lib/${ANDROID_ABI}" ) -------------------------------------------------------------------------------- /ame/src/main/cpp/ame_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef STDC_HEADERS 4 | 5 | # include 6 | # include 7 | 8 | #else 9 | # ifndef HAVE_STRCHR 10 | # define strchr index 11 | # define strrchr rindex 12 | # endif 13 | 14 | char *strchr(), *strrchr(); 15 | 16 | # ifndef HAVE_MEMCPY 17 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) 18 | # define memmove(d, s, n) bcopy ((s), (d), (n)) 19 | # endif 20 | #endif 21 | 22 | /* 23 | main.c is example code for how to use libmp3lame.a. To use this library, 24 | you only need the library and lame.h. All other .h files are private 25 | to the library. 26 | */ 27 | #include "lame.h" 28 | 29 | #include "ame_main.h" 30 | #include "frontend/console.h" 31 | 32 | #ifdef WITH_DMALLOC 33 | #include 34 | #endif 35 | 36 | extern int lame_main(JNIEnv *env, lame_t gf, jstring input, jstring output, jobject options, 37 | jobject callback); 38 | 39 | /************************************************************************ 40 | * 41 | * main 42 | * 43 | * PURPOSE: MPEG-1,2 Layer III encoder with GPSYCHO 44 | * psychoacoustic model. 45 | * 46 | ************************************************************************/ 47 | 48 | FILE *lame_fopen(char const *file, char const *mode) { 49 | return fopen(file, mode); 50 | } 51 | 52 | char *lame_getenv(char const *var) { 53 | char *str = getenv(var); 54 | if (str) { 55 | return strdup(str); 56 | } 57 | return 0; 58 | } 59 | 60 | int ame_main(JNIEnv *env, jstring input, jstring output, jobject options, 61 | jobject callback) { 62 | 63 | lame_t gf; 64 | int ret; 65 | 66 | frontend_open_console(); 67 | gf = lame_init(); /* initialize libmp3lame */ 68 | if (NULL == gf) { 69 | error_printf("fatal error during initialization\n"); 70 | ret = 1; 71 | } else { 72 | ret = lame_main(env, gf, input, output, options, callback); 73 | lame_close(gf); 74 | } 75 | frontend_close_console(); 76 | 77 | return ret; 78 | } -------------------------------------------------------------------------------- /ame/src/main/cpp/ame_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Command line frontend program 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 2000 Takehiro TOMIANGA 6 | * 2010-2011 Robert Hegemann 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | 24 | #ifndef MAIN_H_INCLUDED 25 | #define MAIN_H_INCLUDED 26 | 27 | #ifdef HAVE_LIMITS_H 28 | # include 29 | #endif 30 | 31 | #include 32 | #include "frontend/get_audio.h" 33 | 34 | #if defined(__cplusplus) 35 | extern "C" { 36 | #endif 37 | 38 | #ifndef PATH_MAX 39 | #define PATH_MAX 1024 40 | #endif 41 | 42 | 43 | /* GLOBAL VARIABLES used by parse.c and main.c. 44 | instantiated in parce.c. ugly, ugly */ 45 | 46 | typedef struct ReaderConfig { 47 | sound_file_format input_format; 48 | int swapbytes; /* force byte swapping default=0 */ 49 | int swap_channel; /* 0: no-op, 1: swaps input channels */ 50 | int input_samplerate; 51 | int ignorewavlength; 52 | } ReaderConfig; 53 | 54 | typedef struct WriterConfig { 55 | int flush_write; 56 | } WriterConfig; 57 | 58 | typedef struct UiConfig { 59 | int silent; /* Verbosity */ 60 | int brhist; 61 | int print_clipping_info; /* print info whether waveform clips */ 62 | float update_interval; /* to use Frank's time status display */ 63 | } UiConfig; 64 | 65 | typedef struct DecoderConfig { 66 | int mp3_delay; /* to adjust the number of samples truncated during decode */ 67 | int mp3_delay_set; /* user specified the value of the mp3 encoder delay to assume for decoding */ 68 | int disable_wav_header; 69 | mp3data_struct mp3input_data; 70 | } DecoderConfig; 71 | 72 | typedef enum ByteOrder { 73 | ByteOrderLittleEndian, ByteOrderBigEndian 74 | } ByteOrder; 75 | 76 | typedef struct RawPCMConfig { 77 | int in_bitwidth; 78 | int in_signed; 79 | ByteOrder in_endian; 80 | } RawPCMConfig; 81 | 82 | extern ReaderConfig global_reader; 83 | extern WriterConfig global_writer; 84 | extern UiConfig global_ui_config; 85 | extern DecoderConfig global_decoder; 86 | extern RawPCMConfig global_raw_pcm; 87 | 88 | extern FILE *lame_fopen(char const *file, char const *mode); 89 | 90 | extern char *utf8ToConsole8Bit(const char *str); 91 | 92 | extern char *utf8ToLocal8Bit(const char *str); 93 | 94 | extern unsigned short *utf8ToUtf16(char const *str); 95 | 96 | extern char *utf8ToLatin1(char const *str); 97 | 98 | extern void dosToLongFileName(char *filename); 99 | 100 | extern int lame_main(JNIEnv *env, lame_t gf, jstring input, jstring output, jobject options, 101 | jobject callback); 102 | 103 | extern char *lame_getenv(char const *var); 104 | 105 | int ame_main(JNIEnv *env, jstring input, jstring output, jobject options, 106 | jobject callback); 107 | 108 | #if defined(__cplusplus) 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/Makefile.am: -------------------------------------------------------------------------------- 1 | ## $Id: Makefile.am,v 1.35 2011/10/16 13:09:01 robert Exp $ 2 | 3 | include $(top_srcdir)/Makefile.am.global 4 | 5 | bin_PROGRAMS = @WITH_FRONTEND@ @WITH_MP3RTP@ @WITH_MP3X@ 6 | EXTRA_PROGRAMS = lame$(EXEEXT) mp3rtp$(EXEEXT) mp3x$(EXEEXT) 7 | 8 | EXTRA_DIST = \ 9 | amiga_mpega.c 10 | 11 | DEFS = @DEFS@ @CONFIG_DEFS@ 12 | 13 | common_sources = \ 14 | main.c \ 15 | brhist.c \ 16 | console.c \ 17 | get_audio.c \ 18 | lametime.c \ 19 | parse.c \ 20 | timestatus.c 21 | 22 | noinst_HEADERS = \ 23 | brhist.h \ 24 | console.h \ 25 | get_audio.h \ 26 | gtkanal.h \ 27 | gpkplotting.h \ 28 | lametime.h \ 29 | main.h \ 30 | parse.h \ 31 | rtp.h \ 32 | timestatus.h 33 | 34 | lame_SOURCES = lame_main.c $(common_sources) 35 | mp3rtp_SOURCES = mp3rtp.c rtp.c $(common_sources) 36 | mp3x_SOURCES = mp3x.c gtkanal.c gpkplotting.c $(common_sources) 37 | 38 | CFLAGS = @CFLAGS@ @GTK_CFLAGS@ @FRONTEND_CFLAGS@ @SNDFILE_CFLAGS@ 39 | LDFLAGS = @LDFLAGS@ @FRONTEND_LDFLAGS@ @SNDFILE_LIBS@ 40 | 41 | INCLUDES = -I$(top_srcdir)/libmp3lame -I$(top_srcdir)/include -I$(top_builddir) 42 | 43 | LDADD = @LDADD@ \ 44 | $(top_builddir)/libmp3lame/libmp3lame.la \ 45 | @FRONTEND_LDADD@ 46 | 47 | mp3x_LDADD = $(LDADD) @GTK_LIBS@ 48 | 49 | CLEANFILES = lclint.txt $(EXTRA_PROGRAMS) 50 | 51 | LCLINTFLAGS= \ 52 | +posixlib \ 53 | +showsummary \ 54 | +showalluses \ 55 | +whichlib \ 56 | +forcehints \ 57 | -fixedformalarray \ 58 | +matchanyintegral \ 59 | -Dlint 60 | 61 | lclint.txt: ${lame_SOURCES} ${noinst_HEADERS} 62 | @lclint ${LCLINTFLAGS} ${INCLUDES} ${DEFS} ${lame_SOURCES} 2>&1 >lclint.txt || true 63 | 64 | lclint: lclint.txt 65 | more lclint.txt 66 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/amiga_mpega.c: -------------------------------------------------------------------------------- 1 | /* MPGLIB replacement using mpega.library (AmigaOS) 2 | * Written by Thomas Wenzel and Sigbjrn (CISC) Skj�et. 3 | * 4 | * Big thanks to St�hane Tavernard for mpega.library. 5 | * 6 | */ 7 | 8 | /* $Id: amiga_mpega.c,v 1.3 2005/11/01 13:01:56 robert Exp $ */ 9 | 10 | #ifdef HAVE_CONFIG_H 11 | #include 12 | #endif 13 | 14 | #ifdef AMIGA_MPEGA 15 | 16 | #define __USE_SYSBASE 17 | #include "lame.h" 18 | #include 19 | #include 20 | 21 | /* We need a small workaround here so GCC doesn't fail upon redefinition. :P */ 22 | #define FLOAT _FLOAT 23 | #include 24 | #include 25 | #undef _FLOAT 26 | 27 | #ifndef __GNUC__ 28 | #include 29 | #endif 30 | 31 | struct Library *MPEGABase = NULL; 32 | MPEGA_STREAM *mstream = NULL; 33 | MPEGA_CTRL mctrl; 34 | 35 | static const int smpls[2][4] = { 36 | /* Layer x I II III */ 37 | {0, 384, 1152, 1152}, /* MPEG-1 */ 38 | {0, 384, 1152, 576} /* MPEG-2(.5) */ 39 | }; 40 | 41 | 42 | #ifndef __GNUC__ 43 | static int 44 | break_cleanup(void) 45 | { 46 | /* Dummy break function to make atexit() work. :P */ 47 | return 1; 48 | } 49 | #endif 50 | 51 | static void 52 | exit_cleanup(void) 53 | { 54 | if (mstream) { 55 | MPEGA_close(mstream); 56 | mstream = NULL; 57 | } 58 | if (MPEGABase) { 59 | CloseLibrary(MPEGABase); 60 | MPEGABase = NULL; 61 | } 62 | } 63 | 64 | 65 | int 66 | lame_decode_initfile(const char *fullname, mp3data_struct * mp3data) 67 | { 68 | mctrl.bs_access = NULL; 69 | 70 | mctrl.layer_1_2.mono.quality = 2; 71 | mctrl.layer_1_2.stereo.quality = 2; 72 | mctrl.layer_1_2.mono.freq_div = 1; 73 | mctrl.layer_1_2.stereo.freq_div = 1; 74 | mctrl.layer_1_2.mono.freq_max = 48000; 75 | mctrl.layer_1_2.stereo.freq_max = 48000; 76 | mctrl.layer_3.mono.quality = 2; 77 | mctrl.layer_3.stereo.quality = 2; 78 | mctrl.layer_3.mono.freq_div = 1; 79 | mctrl.layer_3.stereo.freq_div = 1; 80 | mctrl.layer_3.mono.freq_max = 48000; 81 | mctrl.layer_3.stereo.freq_max = 48000; 82 | mctrl.layer_1_2.force_mono = 0; 83 | mctrl.layer_3.force_mono = 0; 84 | 85 | MPEGABase = OpenLibrary("mpega.library", 2); 86 | if (!MPEGABase) { 87 | error_printf("Unable to open mpega.library v2\n"); 88 | exit(1); 89 | } 90 | #ifndef __GNUC__ 91 | onbreak(break_cleanup); 92 | #endif 93 | atexit(exit_cleanup); 94 | 95 | mp3data->header_parsed = 0; 96 | mstream = MPEGA_open((char *) fullname, &mctrl); 97 | if (!mstream) 98 | return (-1); 99 | 100 | mp3data->header_parsed = 1; 101 | mp3data->stereo = mstream->dec_channels; 102 | mp3data->samplerate = mstream->dec_frequency; 103 | mp3data->bitrate = mstream->bitrate; 104 | mp3data->nsamp = (float) mstream->ms_duration / 1000 * mstream->dec_frequency; 105 | mp3data->mode = mstream->mode; 106 | mp3data->mode_ext = 0; /* mpega.library doesn't supply this info! :( */ 107 | mp3data->framesize = smpls[mstream->norm - 1][mstream->layer]; 108 | 109 | return 0; 110 | } 111 | 112 | int 113 | lame_decode_fromfile(FILE * fd, short pcm_l[], short pcm_r[], mp3data_struct * mp3data) 114 | { 115 | int outsize = 0; 116 | WORD *b[MPEGA_MAX_CHANNELS]; 117 | 118 | b[0] = pcm_l; 119 | b[1] = pcm_r; 120 | 121 | mp3data->header_parsed = 0; 122 | while ((outsize == 0) || (outsize == MPEGA_ERR_BADFRAME)) /* Skip bad frames */ 123 | outsize = MPEGA_decode_frame(mstream, b); 124 | 125 | if (outsize < 0) 126 | return (-1); 127 | 128 | mp3data->header_parsed = 1; 129 | mp3data->stereo = mstream->dec_channels; 130 | mp3data->samplerate = mstream->dec_frequency; 131 | mp3data->bitrate = mstream->bitrate; 132 | mp3data->mode = mstream->mode; 133 | mp3data->mode_ext = 0; /* mpega.library doesn't supply this info! :( */ 134 | mp3data->framesize = smpls[mstream->norm - 1][mstream->layer]; 135 | 136 | return outsize; 137 | } 138 | 139 | #endif /* AMIGA_MPEGA */ 140 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/brhist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Bitrate histogram include file 3 | * 4 | * Copyright (c) 2000 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_BRHIST_H 23 | #define LAME_BRHIST_H 24 | 25 | #include "lame.h" 26 | 27 | #if defined(__cplusplus) 28 | extern "C" { 29 | #endif 30 | 31 | int brhist_init(const lame_global_flags * gf, const int bitrate_kbps_min, 32 | const int bitrate_kbps_max); 33 | void brhist_disp(const lame_global_flags * gf); 34 | void brhist_jump_back(void); 35 | 36 | #if defined(__cplusplus) 37 | } 38 | #endif 39 | 40 | #endif /* LAME_BRHIST_H */ 41 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/console.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | # include 3 | #endif 4 | 5 | #ifdef STDC_HEADERS 6 | # include 7 | # include 8 | #else 9 | # ifndef HAVE_STRCHR 10 | # define strchr index 11 | # define strrchr rindex 12 | # endif 13 | char *strchr(), *strrchr(); 14 | # ifndef HAVE_MEMCPY 15 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) 16 | # define memmove(d, s, n) bcopy ((s), (d), (n)) 17 | # endif 18 | #endif 19 | 20 | #if defined(HAVE_NCURSES_TERMCAP_H) 21 | # include 22 | #elif defined(HAVE_TERMCAP_H) 23 | # include 24 | #elif defined(HAVE_TERMCAP) 25 | # include 26 | # if !defined(__bsdi__) 27 | # include 28 | # endif 29 | #endif 30 | 31 | #include 32 | #include 33 | #include "console.h" 34 | #include "../ame_main.h" 35 | 36 | #ifdef WITH_DMALLOC 37 | #include 38 | #endif 39 | 40 | #define CLASS_ID 0x434F4E53 41 | #define REPORT_BUFF_SIZE 1024 42 | 43 | #if defined(_WIN32) && !defined(__CYGWIN__) 44 | # include 45 | #endif 46 | 47 | 48 | 49 | static int 50 | my_console_printing(FILE * fp, const char *format, va_list ap) 51 | { 52 | if (fp != NULL) 53 | return vfprintf(fp, format, ap); 54 | return 0; 55 | } 56 | 57 | static int 58 | my_error_printing(FILE * fp, const char *format, va_list ap) 59 | { 60 | if (fp != NULL) 61 | return vfprintf(fp, format, ap); 62 | return 0; 63 | } 64 | 65 | static int 66 | my_report_printing(FILE * fp, const char *format, va_list ap) 67 | { 68 | if (fp != NULL) 69 | return vfprintf(fp, format, ap); 70 | return 0; 71 | } 72 | 73 | 74 | /* 75 | * Taken from Termcap_Manual.html: 76 | * 77 | * With the Unix version of termcap, you must allocate space for the description yourself and pass 78 | * the address of the space as the argument buffer. There is no way you can tell how much space is 79 | * needed, so the convention is to allocate a buffer 2048 characters long and assume that is 80 | * enough. (Formerly the convention was to allocate 1024 characters and assume that was enough. 81 | * But one day, for one kind of terminal, that was not enough.) 82 | */ 83 | 84 | #ifdef HAVE_TERMCAP 85 | 86 | static void 87 | get_termcap_string(char const* id, char* dest, size_t n) 88 | { 89 | char tc[16]; 90 | char *tp = tc; 91 | tp[0] = '\0'; 92 | tp = tgetstr(id, &tp); 93 | if (tp != NULL && dest != NULL && n > 0) { 94 | strncpy(dest, tp, n); 95 | dest[n-1] = '\0'; 96 | } 97 | } 98 | 99 | static void 100 | get_termcap_number(char const* id, int* dest, int low, int high) 101 | { 102 | int const val = tgetnum(id); 103 | if (low <= val && val <= high) { 104 | *dest = val; 105 | } 106 | } 107 | 108 | static void 109 | apply_termcap_settings(Console_IO_t * const mfp) 110 | { 111 | /* try to catch additional information about special console sequences */ 112 | char const* term_name = getenv("TERM"); 113 | if (NULL != term_name) { 114 | char term_buff[4096]; 115 | int const ret = tgetent(term_buff, term_name); 116 | if (1 == ret) { 117 | get_termcap_number("co", &mfp->disp_width, 40, 512); 118 | get_termcap_number("li", &mfp->disp_height, 16, 256); 119 | get_termcap_string("up", mfp->str_up, sizeof(mfp->str_up)); 120 | get_termcap_string("md", mfp->str_emph, sizeof(mfp->str_emph)); 121 | get_termcap_string("me", mfp->str_norm, sizeof(mfp->str_norm)); 122 | get_termcap_string("ce", mfp->str_clreoln, sizeof(mfp->str_clreoln)); 123 | } 124 | } 125 | } 126 | #endif /* TERMCAP_AVAILABLE */ 127 | 128 | static int 129 | init_console(Console_IO_t * const mfp) 130 | { 131 | /* setup basics of brhist I/O channels */ 132 | mfp->disp_width = 80; 133 | mfp->disp_height = 25; 134 | mfp->Console_fp = stderr; 135 | mfp->Error_fp = stderr; 136 | mfp->Report_fp = NULL; 137 | 138 | /*mfp -> Console_buff = calloc ( 1, REPORT_BUFF_SIZE ); */ 139 | setvbuf(mfp->Console_fp, mfp->Console_buff, _IOFBF, sizeof(mfp->Console_buff)); 140 | /* setvbuf ( mfp -> Error_fp , NULL , _IONBF, 0 ); */ 141 | 142 | #if defined(_WIN32) && !defined(__CYGWIN__) 143 | mfp->Console_Handle = GetStdHandle(STD_ERROR_HANDLE); 144 | #endif 145 | 146 | strcpy(mfp->str_up, "\033[A"); 147 | 148 | #ifdef HAVE_TERMCAP 149 | apply_termcap_settings(mfp); 150 | #endif /* TERMCAP_AVAILABLE */ 151 | 152 | mfp->ClassID = CLASS_ID; 153 | 154 | #if defined(_WIN32) && !defined(__CYGWIN__) 155 | mfp->Console_file_type = GetFileType(Console_IO.Console_Handle); 156 | #else 157 | mfp->Console_file_type = 0; 158 | #endif 159 | return 0; 160 | } 161 | 162 | static void 163 | deinit_console(Console_IO_t * const mfp) 164 | { 165 | if (mfp->Report_fp != NULL) { 166 | fclose(mfp->Report_fp); 167 | mfp->Report_fp = NULL; 168 | } 169 | fflush(mfp->Console_fp); 170 | setvbuf(mfp->Console_fp, NULL, _IONBF, (size_t) 0); 171 | 172 | memset(mfp->Console_buff, 0x55, REPORT_BUFF_SIZE); 173 | } 174 | 175 | 176 | /* LAME console 177 | */ 178 | Console_IO_t Console_IO; 179 | 180 | int 181 | frontend_open_console(void) 182 | { 183 | return init_console(&Console_IO); 184 | } 185 | 186 | void 187 | frontend_close_console(void) 188 | { 189 | deinit_console(&Console_IO); 190 | } 191 | 192 | void 193 | frontend_debugf(const char *format, va_list ap) 194 | { 195 | (void) my_report_printing(Console_IO.Report_fp, format, ap); 196 | } 197 | 198 | void 199 | frontend_msgf(const char *format, va_list ap) 200 | { 201 | (void) my_console_printing(Console_IO.Console_fp, format, ap); 202 | } 203 | 204 | void 205 | frontend_errorf(const char *format, va_list ap) 206 | { 207 | (void) my_error_printing(Console_IO.Error_fp, format, ap); 208 | } 209 | 210 | void 211 | frontend_print_null(const char *format, va_list ap) 212 | { 213 | (void) format; 214 | (void) ap; 215 | } 216 | 217 | int 218 | console_printf(const char *format, ...) 219 | { 220 | va_list args; 221 | int ret; 222 | 223 | va_start(args, format); 224 | ret = my_console_printing(Console_IO.Console_fp, format, args); 225 | va_end(args); 226 | 227 | return ret; 228 | } 229 | 230 | int 231 | error_printf(const char *format, ...) 232 | { 233 | va_list args; 234 | int ret; 235 | 236 | va_start(args, format); 237 | ret = my_console_printing(Console_IO.Error_fp, format, args); 238 | va_end(args); 239 | 240 | return ret; 241 | } 242 | 243 | int 244 | report_printf(const char *format, ...) 245 | { 246 | va_list args; 247 | int ret; 248 | 249 | va_start(args, format); 250 | ret = my_console_printing(Console_IO.Report_fp, format, args); 251 | va_end(args); 252 | 253 | return ret; 254 | } 255 | 256 | void 257 | console_flush() 258 | { 259 | fflush(Console_IO.Console_fp); 260 | } 261 | 262 | void 263 | error_flush() 264 | { 265 | fflush(Console_IO.Error_fp); 266 | } 267 | 268 | void 269 | report_flush() 270 | { 271 | fflush(Console_IO.Report_fp); 272 | } 273 | 274 | void 275 | console_up(int n_lines) 276 | { 277 | #if defined(_WIN32) && !defined(__CYGWIN__) 278 | if (Console_IO.Console_file_type != FILE_TYPE_PIPE) { 279 | COORD Pos; 280 | CONSOLE_SCREEN_BUFFER_INFO CSBI; 281 | 282 | console_flush(); 283 | GetConsoleScreenBufferInfo(Console_IO.Console_Handle, &CSBI); 284 | Pos.Y = (SHORT)(CSBI.dwCursorPosition.Y - n_lines); 285 | Pos.X = 0; 286 | SetConsoleCursorPosition(Console_IO.Console_Handle, Pos); 287 | } 288 | #else 289 | while (n_lines-- > 0) 290 | fputs(Console_IO.str_up, Console_IO.Console_fp); 291 | console_flush(); 292 | #endif 293 | } 294 | 295 | 296 | void 297 | set_debug_file(const char *fn) 298 | { 299 | if (Console_IO.Report_fp == NULL) { 300 | Console_IO.Report_fp = lame_fopen(fn, "a"); 301 | if (Console_IO.Report_fp != NULL) { 302 | error_printf("writing debug info into: %s\n", fn); 303 | } 304 | else { 305 | error_printf("Error: can't open for debug info: %s\n", fn); 306 | } 307 | } 308 | } 309 | 310 | /* end of console.c */ 311 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * frontend/console.h 3 | * 4 | * This 5 | * 6 | * 7 | */ 8 | 9 | #ifndef LAME_CONSOLE_H 10 | #define LAME_CONSOLE_H 11 | 12 | #if defined(_WIN32) && !defined(__CYGWIN__) 13 | # include 14 | #endif 15 | 16 | #if defined(__cplusplus) 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct console_io_struct { 21 | unsigned long ClassID; 22 | unsigned long ClassProt; 23 | FILE *Console_fp; /* filepointer to stream reporting information */ 24 | FILE *Error_fp; /* filepointer to stream fatal error reporting information */ 25 | FILE *Report_fp; /* filepointer to stream reports (normally a text file or /dev/null) */ 26 | #if defined(_WIN32) && !defined(__CYGWIN__) 27 | HANDLE Console_Handle; 28 | #endif 29 | int disp_width; 30 | int disp_height; 31 | char str_up[10]; 32 | char str_clreoln[10]; 33 | char str_emph[10]; 34 | char str_norm[10]; 35 | char Console_buff[2048]; 36 | int Console_file_type; 37 | } Console_IO_t; 38 | 39 | extern Console_IO_t Console_IO; 40 | extern int frontend_open_console(void); 41 | extern void frontend_close_console(void); 42 | 43 | extern void frontend_msgf(const char *format, va_list ap); 44 | extern void frontend_debugf(const char *format, va_list ap); 45 | extern void frontend_errorf(const char *format, va_list ap); 46 | extern void frontend_print_null(const char *format, va_list ap); 47 | 48 | int console_printf(const char *format, ...); 49 | int error_printf(const char *format, ...); 50 | int report_printf(const char *format, ...); 51 | 52 | void console_flush(void); 53 | void error_flush(void); 54 | void report_flush(void); 55 | 56 | void console_up(int n_lines); 57 | 58 | void set_debug_file(const char *fn); 59 | 60 | #if defined(__cplusplus) 61 | } 62 | #endif 63 | 64 | #endif /* LAME_CONSOLE_H */ 65 | 66 | /* end of console.h */ 67 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/get_audio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Get Audio routines include file 3 | * 4 | * Copyright (c) 1999 Albert L Faber 5 | * 2010 Robert Hegemann 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Library General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Library General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Library General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | #ifndef LAME_GET_AUDIO_H 25 | #define LAME_GET_AUDIO_H 26 | #include "lame.h" 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | typedef enum sound_file_format_e { 34 | sf_unknown, 35 | sf_raw, 36 | sf_wave, 37 | sf_aiff, 38 | sf_mp1, /* MPEG Layer 1, aka mpg */ 39 | sf_mp2, /* MPEG Layer 2 */ 40 | sf_mp3, /* MPEG Layer 3 */ 41 | sf_mp123, /* MPEG Layer 1,2 or 3; whatever .mp3, .mp2, .mp1 or .mpg contains */ 42 | sf_ogg 43 | } sound_file_format; 44 | 45 | int is_mpeg_file_format( int input_format ); 46 | 47 | int init_infile(lame_t gfp, char const * inPath); 48 | int samples_to_skip_at_start(void); 49 | int samples_to_skip_at_end(void); 50 | void close_infile(void); 51 | int get_audio(lame_t gfp, int buffer[2][1152]); 52 | int get_audio16(lame_t gfp, short buffer[2][1152]); 53 | int get_audio_float(lame_t gfp, float buffer[2][1152]); 54 | int get_audio_double(lame_t gfp, double buffer[2][1152]); 55 | hip_t get_hip(void); 56 | 57 | FILE *init_outfile(char const *outPath, int decode); 58 | int WriteWaveHeader(FILE * const fp, int pcmbytes, int freq, int channels, int bits); 59 | void put_audio16(FILE* outf, short Buffer[2][1152], int iread, int nch); 60 | 61 | /* 62 | struct AudioReader; 63 | typedef struct AudioReader* AudioReader; 64 | 65 | AudioReader ar_open(lame_t gfp, char const* inPath); 66 | int ar_samplesToSkipAtStart(AudioReader ar); 67 | int ar_samplesToSkipAtEnd(AudioReader ar); 68 | void ar_close(AudioReader ar); 69 | int ar_readInt(AudioReader ar, lame_t gfp, int buffer[2][1152]); 70 | int ar_readShort(AudioReader ar, lame_t gfp, short buffer[2][1152]); 71 | int ar_readFloat(AudioReader ar, lame_t gfp, float buffer[2][1152]); 72 | 73 | struct AudioWriter; 74 | typedef struct AudioWriter* AudioWriter; 75 | 76 | AudioWriter aw_open(lame_t gfp, char const* outPath, int pcmbystes, int freq, int channels, int bits); 77 | int aw_writeWaveHeader(AudioWriter aw); 78 | int aw_write(AudioWriter aw, short buffer[2][1152], int n); 79 | int aw_write(AudioWriter aw, float buffer[2][1152], int n); 80 | 81 | */ 82 | 83 | extern size_t sizeOfOldTag(lame_t gf); 84 | extern unsigned char* getOldTag(lame_t gf); 85 | 86 | #ifdef _cplusplus 87 | } 88 | #endif 89 | 90 | #endif /* ifndef LAME_GET_AUDIO_H */ 91 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/lametime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Lame time routines source file 3 | * 4 | * Copyright (c) 2000 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | /* $Id: lametime.c,v 1.21 2011/05/07 16:05:17 rbrito Exp $ */ 23 | 24 | /* 25 | * name: GetCPUTime ( void ) 26 | * 27 | * description: returns CPU time used by the process 28 | * input: none 29 | * output: time in seconds 30 | * known bugs: may not work in SMP and RPC 31 | * conforming: ANSI C 32 | * 33 | * There is some old difficult to read code at the end of this file. 34 | * Can someone integrate this into this function (if useful)? 35 | */ 36 | 37 | #ifdef HAVE_CONFIG_H 38 | # include 39 | #endif 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #ifdef WITH_DMALLOC 46 | #include 47 | #endif 48 | 49 | #include "lametime.h" 50 | 51 | #if !defined(CLOCKS_PER_SEC) 52 | # warning Your system does not define CLOCKS_PER_SEC, guessing one... 53 | # define CLOCKS_PER_SEC 1000000 54 | #endif 55 | 56 | 57 | double 58 | GetCPUTime(void) 59 | { 60 | clock_t t; 61 | 62 | #if defined(_MSC_VER) || defined(__BORLANDC__) 63 | t = clock(); 64 | #else 65 | t = clock(); 66 | #endif 67 | return t / (double) CLOCKS_PER_SEC; 68 | } 69 | 70 | 71 | /* 72 | * name: GetRealTime ( void ) 73 | * 74 | * description: returns real (human) time elapsed relative to a fixed time (mostly 1970-01-01 00:00:00) 75 | * input: none 76 | * output: time in seconds 77 | * known bugs: bad precision with time() 78 | */ 79 | 80 | #if defined(__unix__) || defined(SVR4) || defined(BSD) 81 | 82 | # include 83 | # include 84 | 85 | double 86 | GetRealTime(void) 87 | { /* conforming: SVr4, BSD 4.3 */ 88 | struct timeval t; 89 | 90 | if (0 != gettimeofday(&t, NULL)) 91 | assert(0); 92 | return t.tv_sec + 1.e-6 * t.tv_usec; 93 | } 94 | 95 | #elif defined(WIN16) || defined(WIN32) 96 | 97 | # include 98 | # include 99 | # include 100 | 101 | double 102 | GetRealTime(void) 103 | { /* conforming: Win 95, Win NT */ 104 | struct timeb t; 105 | 106 | ftime(&t); 107 | return t.time + 1.e-3 * t.millitm; 108 | } 109 | 110 | #else 111 | 112 | double 113 | GetRealTime(void) 114 | { /* conforming: SVr4, SVID, POSIX, X/OPEN, BSD 4.3 */ /* BUT NOT GUARANTEED BY ANSI */ 115 | time_t t; 116 | 117 | t = time(NULL); 118 | return (double) t; 119 | } 120 | 121 | #endif 122 | 123 | 124 | #if defined(_WIN32) || defined(__CYGWIN__) 125 | # include 126 | # include 127 | #else 128 | # include 129 | #endif 130 | 131 | int 132 | lame_set_stream_binary_mode(FILE * const fp) 133 | { 134 | #if defined __EMX__ 135 | _fsetmode(fp, "b"); 136 | #elif defined __BORLANDC__ 137 | setmode(_fileno(fp), O_BINARY); 138 | #elif defined __CYGWIN__ 139 | setmode(fileno(fp), _O_BINARY); 140 | #elif defined _WIN32 141 | _setmode(_fileno(fp), _O_BINARY); 142 | #else 143 | (void) fp; /* doing nothing here, silencing the compiler only. */ 144 | #endif 145 | return 0; 146 | } 147 | 148 | 149 | /* End of lametime.c */ 150 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/lametime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lame time routines include file 3 | * 4 | * Copyright (c) 2000 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_LAMETIME_H 23 | #define LAME_LAMETIME_H 24 | 25 | #include 26 | #include "lame.h" 27 | 28 | #if defined(__cplusplus) 29 | extern "C" { 30 | #endif 31 | 32 | extern double GetCPUTime(void); 33 | extern double GetRealTime(void); 34 | 35 | extern int lame_set_stream_binary_mode(FILE * const fp); 36 | 37 | #if defined(__cplusplus) 38 | } 39 | #endif 40 | 41 | #endif /* LAME_LAMETIME_H */ 42 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSE_H_INCLUDED 2 | #define PARSE_H_INCLUDED 3 | 4 | #if defined(__cplusplus) 5 | extern "C" { 6 | #endif 7 | 8 | int usage(FILE * const fp, const char *ProgramName); 9 | int short_help(const lame_global_flags * gfp, FILE * const fp, const char *ProgramName); 10 | int long_help(const lame_global_flags * gfp, FILE * const fp, const char *ProgramName, 11 | int lessmode); 12 | int display_bitrates(FILE * const fp); 13 | 14 | int parse_args(lame_global_flags * gfp, int argc, char **argv, char *const inPath, 15 | char *const outPath, char **nogap_inPath, int *max_nogap); 16 | 17 | void parse_close(); 18 | 19 | int generateOutPath(char const* inPath, char const* outDir, char const* suffix, char* outPath); 20 | 21 | #if defined(__cplusplus) 22 | } 23 | #endif 24 | 25 | #endif 26 | /* end of parse.h */ 27 | -------------------------------------------------------------------------------- /ame/src/main/cpp/frontend/timestatus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * time status related function include file 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_TIMESTATUS_H 23 | #define LAME_TIMESTATUS_H 24 | 25 | #if defined(__cplusplus) 26 | extern "C" { 27 | #endif 28 | 29 | void encoder_progress_begin( lame_global_flags const* gfp 30 | , char const* inpath 31 | , char const* outpath ); 32 | void encoder_progress( lame_global_flags const* gfp ); 33 | void encoder_progress_end(lame_global_flags const* gfp); 34 | 35 | struct DecoderProgress; 36 | typedef struct DecoderProgress* DecoderProgress; 37 | 38 | DecoderProgress decoder_progress_init(unsigned long n, int framesize); 39 | void decoder_progress(DecoderProgress dp, const mp3data_struct *, int iread); 40 | void decoder_progress_finish(DecoderProgress dp); 41 | 42 | #if defined(__cplusplus) 43 | } 44 | #endif 45 | 46 | #endif /* LAME_TIMESTATUS_H */ 47 | -------------------------------------------------------------------------------- /ame/src/main/cpp/jni_util.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by ZHAOWEIWEI on 2018/2/8. 3 | // 4 | #include 5 | #include 6 | #include "jni_util.h" 7 | 8 | #define UTF8 "UTF-8" 9 | #define LOG_TAG "ame" 10 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 11 | 12 | char *parse_jstring(JNIEnv *env, jstring jstr) { 13 | char *rtn = NULL; 14 | 15 | jmethodID methodID = get_method_id(env, "java/lang/String", "getBytes", 16 | "(Ljava/lang/String;)[B"); 17 | 18 | jbooleanArray barr = (*env)->CallObjectMethod(env, jstr, methodID, 19 | (*env)->NewStringUTF(env, UTF8)); 20 | 21 | jsize length = (*env)->GetArrayLength(env, barr); 22 | jbyte *ba = (*env)->GetByteArrayElements(env, barr, JNI_FALSE); 23 | 24 | if (length > 0) { 25 | rtn = (char *) malloc(length + 1); 26 | memcpy(rtn, ba, length); 27 | rtn[length] = 0; 28 | } 29 | 30 | (*env)->ReleaseByteArrayElements(env, barr, ba, 0); 31 | (*env)->DeleteLocalRef(env, barr); 32 | 33 | return rtn; 34 | } 35 | 36 | jmethodID 37 | get_method_id(JNIEnv *env, char *className, char *methodName, 38 | char *signature) { 39 | jclass clazz = (*env)->FindClass(env, className); 40 | jmethodID methodID = (*env)->GetMethodID(env, clazz, methodName, signature); 41 | (*env)->DeleteLocalRef(env, clazz); 42 | return methodID; 43 | } 44 | 45 | jobject 46 | invoke_method_get_jobject(JNIEnv *env, jobject obj, char *objClassName, char *methodName, 47 | char *signature) { 48 | jmethodID methodID = get_method_id(env, objClassName, methodName, signature); 49 | return (*env)->CallObjectMethod(env, obj, methodID); 50 | } 51 | 52 | jboolean 53 | invoke_method_get_jboolean(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 54 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_BOOLEAN); 55 | return (*env)->CallBooleanMethod(env, obj, methodID); 56 | } 57 | 58 | jint 59 | invoke_method_get_jint(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 60 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_INT); 61 | return (*env)->CallIntMethod(env, obj, methodID); 62 | } 63 | 64 | jfloat 65 | invoke_method_get_jfloat(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 66 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_FLOAT); 67 | return (*env)->CallFloatMethod(env, obj, methodID); 68 | } 69 | 70 | jdouble 71 | invoke_method_get_jdouble(JNIEnv *env, jobject obj, char *objClassName, char *methodName) { 72 | jmethodID methodID = get_method_id(env, objClassName, methodName, SIGNATURE_DOUBLE); 73 | return (*env)->CallDoubleMethod(env, obj, methodID); 74 | } -------------------------------------------------------------------------------- /ame/src/main/cpp/jni_util.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define LOG_TAG "ame" 5 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 6 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 7 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 8 | 9 | #define SIGNATURE_BOOLEAN "()Z" 10 | #define SIGNATURE_BYTE "()B" 11 | #define SIGNATURE_CHAR "()C" 12 | #define SIGNATURE_SHORT "()S" 13 | #define SIGNATURE_INT "()I" 14 | #define SIGNATURE_LONG "()J" 15 | #define SIGNATURE_FLOAT "()F" 16 | #define SIGNATURE_DOUBLE "()D" 17 | #define SIGNATURE_VOID "()V" 18 | #define SIGNATURE_OBJECTS "()L" 19 | 20 | jmethodID 21 | get_method_id(JNIEnv *env, char *className, char *methodName, 22 | char *signature); 23 | 24 | jobject 25 | invoke_method_get_jobject(JNIEnv *env, jobject obj, char *objClassName, char *methodName, 26 | char *signature); 27 | 28 | jboolean 29 | invoke_method_get_jboolean(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 30 | 31 | jint 32 | invoke_method_get_jint(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 33 | 34 | jfloat 35 | invoke_method_get_jfloat(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 36 | 37 | jdouble 38 | invoke_method_get_jdouble(JNIEnv *env, jobject obj, char *objClassName, char *methodName); 39 | 40 | char *parse_jstring(JNIEnv *env, jstring jstr); -------------------------------------------------------------------------------- /ame/src/main/cpp/mp3_encoder.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "lame.h" 3 | #include "ame_main.h" 4 | 5 | /* 6 | * Class: io_auxo_ame_Mp3Encoder 7 | * Method: encode 8 | * Signature: (Ljava/lang/String;Ljava/lang/String;Lio/auxo/ame/Mp3Encoder$Options;Lio/auxo/ame/Mp3Encoder$Callback;)V 9 | */ 10 | JNIEXPORT void JNICALL Java_io_auxo_ame_Mp3Encoder_encode 11 | (JNIEnv *env, jclass clazz, jstring input, jstring output, jobject options, 12 | jobject callback) { 13 | 14 | ame_main(env, input, output, options, callback); 15 | } 16 | 17 | /* 18 | * Class: io_auxo_ame_Mp3Encoder 19 | * Method: getLameVersion 20 | * Signature: ()Ljava/lang/String; 21 | */ 22 | JNIEXPORT jstring JNICALL Java_io_auxo_ame_Mp3Encoder_getLameVersion 23 | (JNIEnv *env, jobject obj) { 24 | return (*env)->NewStringUTF(env, get_lame_version()); 25 | } 26 | -------------------------------------------------------------------------------- /ame/src/main/cpp/mp3_encoder.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class io_auxo_ame_Mp3Encoder */ 4 | 5 | #ifndef _Included_io_auxo_ame_Mp3Encoder 6 | #define _Included_io_auxo_ame_Mp3Encoder 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: io_auxo_ame_Mp3Encoder 12 | * Method: encode 13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Lio/auxo/ame/Mp3Encoder$Options;Lio/auxo/ame/Mp3Encoder$Callback;)V 14 | */ 15 | JNIEXPORT void JNICALL Java_io_auxo_ame_Mp3Encoder_encode 16 | (JNIEnv *, jclass, jstring, jstring, jobject, jobject); 17 | 18 | /* 19 | * Class: io_auxo_ame_Mp3Encoder 20 | * Method: getLameVersion 21 | * Signature: ()Ljava/lang/String; 22 | */ 23 | JNIEXPORT jstring JNICALL Java_io_auxo_ame_Mp3Encoder_getLameVersion 24 | (JNIEnv *, jobject); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif 30 | /* Header for class io_auxo_ame_Mp3Encoder_Options */ 31 | 32 | #ifndef _Included_io_auxo_ame_Mp3Encoder_Options 33 | #define _Included_io_auxo_ame_Mp3Encoder_Options 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | /* Header for class io_auxo_ame_Mp3Encoder_Callback */ 42 | 43 | #ifndef _Included_io_auxo_ame_Mp3Encoder_Callback 44 | #define _Included_io_auxo_ame_Mp3Encoder_Callback 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | #endif 52 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/Mp3Encoder.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame; 2 | 3 | import io.auxo.ame.options.AbrOptions; 4 | import io.auxo.ame.options.CbrOptions; 5 | import io.auxo.ame.options.FilterOptions; 6 | import io.auxo.ame.options.Id3TagOptions; 7 | import io.auxo.ame.options.InputOptions; 8 | import io.auxo.ame.options.Mp3HeaderStreamOptions; 9 | import io.auxo.ame.options.OperationalOptions; 10 | import io.auxo.ame.options.RawPcmInputOptions; 11 | import io.auxo.ame.options.VbrOptions; 12 | 13 | /** 14 | * Mp3Encoder 15 | * 16 | * @author Victor Chiu 17 | * @date 2018/3/8 18 | */ 19 | 20 | public class Mp3Encoder { 21 | 22 | public static class Options { 23 | 24 | private InputOptions inputOptions; 25 | private RawPcmInputOptions rawPcmInputOptions; 26 | private OperationalOptions operationalOptions; 27 | private CbrOptions cbrOptions; 28 | private AbrOptions abrOptions; 29 | private VbrOptions vbrOptions; 30 | private Mp3HeaderStreamOptions mp3HeaderStreamOptions; 31 | private FilterOptions filterOptions; 32 | private Id3TagOptions id3TagOptions; 33 | 34 | public Options addInputOptions(InputOptions inputOptions) { 35 | this.inputOptions = inputOptions; 36 | return this; 37 | } 38 | 39 | public Options addRawPcmInputOptions(RawPcmInputOptions rawPcmInputOptions) { 40 | this.rawPcmInputOptions = rawPcmInputOptions; 41 | return this; 42 | } 43 | 44 | public Options addOperationalOptions(OperationalOptions operationalOptions) { 45 | this.operationalOptions = operationalOptions; 46 | return this; 47 | } 48 | 49 | public Options addCBROptions(CbrOptions cbrOptions) { 50 | this.cbrOptions = cbrOptions; 51 | return this; 52 | } 53 | 54 | public Options addABROptions(AbrOptions abrOptions) { 55 | this.abrOptions = abrOptions; 56 | return this; 57 | } 58 | 59 | public Options addVBROptions(VbrOptions vbrOptions) { 60 | this.vbrOptions = vbrOptions; 61 | return this; 62 | } 63 | 64 | public Options addFilterOptions(FilterOptions filterOptions) { 65 | this.filterOptions = filterOptions; 66 | return this; 67 | } 68 | 69 | public Options addID3TagOptions(Id3TagOptions id3TagOptions) { 70 | this.id3TagOptions = id3TagOptions; 71 | return this; 72 | } 73 | 74 | public Options addMP3HeaderStreamOptions(Mp3HeaderStreamOptions mp3HeaderStreamOptions) { 75 | this.mp3HeaderStreamOptions = mp3HeaderStreamOptions; 76 | return this; 77 | } 78 | } 79 | 80 | public interface Callback { 81 | void onStart(); 82 | 83 | void onProgress(int total, int current); 84 | 85 | void onComplete(); 86 | 87 | void onError(); 88 | } 89 | 90 | static { 91 | System.loadLibrary("ame"); 92 | } 93 | 94 | public static void encode(String in, String out) { 95 | encode(in, out, null, null); 96 | } 97 | 98 | public static void encode(String in, String out, Options options) { 99 | encode(in, out, options, null); 100 | } 101 | 102 | public static void encode(String in, String out, Callback callback) { 103 | encode(in, out, null, callback); 104 | } 105 | 106 | public static native void encode(String in, String out, Options options, Callback callback); 107 | 108 | /** 109 | * 获取LAME版本 110 | * 111 | * @return LAME版本号 112 | */ 113 | public native String getLameVersion(); 114 | } 115 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/AbrOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | /** 4 | * ABR options: 5 | * --abr specify average bitrate desired (instead of quality) ); 6 | * 7 | * @author Victor Chiu 8 | */ 9 | public class AbrOptions { 10 | 11 | /** 12 | * 比特率 13 | */ 14 | private int bitrate; 15 | 16 | public AbrOptions(){ 17 | } 18 | 19 | public AbrOptions(int bitrate){ 20 | bitrate(bitrate); 21 | } 22 | 23 | public AbrOptions bitrate(int bitrate) { 24 | this.bitrate = bitrate; 25 | return this; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/CbrOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | /** 4 | * -b set the bitrate in kbps, default 128 kbps 5 | * --cbr enforce use of constant bitrate 6 | * 7 | * @author Victor Chiu 8 | */ 9 | public class CbrOptions { 10 | 11 | /** 12 | * 比特率,单位kbps,默认128kbps 13 | */ 14 | private int bitrate = -1; 15 | /** 16 | * 是否严格使用CBR编码 17 | */ 18 | private boolean enforce = false; 19 | 20 | public CbrOptions bitrate(int bitrate) { 21 | this.bitrate = bitrate; 22 | return this; 23 | } 24 | 25 | public CbrOptions enforce() { 26 | this.enforce = true; 27 | return this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/FilterOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | /** 4 | * Filter options: 5 | * --lowpass frequency(kHz), lowpass filter cutoff above freq 6 | * --lowpass-width frequency(kHz) - default 15% of lowpass freq 7 | * --highpass frequency(kHz), highpass filter cutoff below freq 8 | * --highpass-width frequency(kHz) - default 15% of highpass freq 9 | * --resample sampling frequency of output file(kHz)- default=automatic 10 | * 11 | * @author Victor Chiu 12 | */ 13 | public class FilterOptions { 14 | 15 | /** 16 | * 低通滤波器,过滤掉频率lowPass以上的数据。 17 | * 范围为[0.001..50]kHz或[50..50000]Hz。 18 | */ 19 | private double lowPass = -1; 20 | /** 21 | * 低通曲线宽度。范围为[0.001..16]kHz或 [16..50000]Hz。 22 | */ 23 | private double lowPassWidth = -1; 24 | /** 25 | * 高通滤波器,过滤掉频率freq以下的数据。 26 | * 范围为[0.001..16]kHz或[16..50000]Hz。 27 | */ 28 | private double highPass = -1; 29 | /** 30 | * 高通曲线宽度。 31 | */ 32 | private double highPassWidth = -1; 33 | /** 34 | * 输出文件的采样率。 35 | */ 36 | private double sampleRate = -1; 37 | 38 | public FilterOptions lowPass(double lowPass) { 39 | this.lowPass = lowPass; 40 | return this; 41 | } 42 | 43 | public FilterOptions lowPassWidth(double lowPassWidth) { 44 | this.lowPassWidth = lowPassWidth; 45 | return this; 46 | } 47 | 48 | public FilterOptions highPass(double highPass) { 49 | this.highPass = highPass; 50 | return this; 51 | } 52 | 53 | public FilterOptions highPassWidth(double highPassWidth) { 54 | this.highPassWidth = highPassWidth; 55 | return this; 56 | } 57 | 58 | public FilterOptions sampleRate(double sampleRate) { 59 | this.sampleRate = sampleRate; 60 | return this; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/Id3TagOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * ID3 tag options: 8 | * --tt audio/song title (max 30 chars for version 1 tag) 9 | * --ta <artist> audio/song artist (max 30 chars for version 1 tag) 10 | * --tl <album> audio/song album (max 30 chars for version 1 tag) 11 | * --ty <year> audio/song year of issue (1 to 9999) 12 | * --tc <comment> user-defined text (max 30 chars for v1 tag, 28 for v1.1) 13 | * --tn <track[/total]> audio/song track number and (optionally) the total 14 | * number of tracks on the original recording. (track 15 | * and total each 1 to 255. just the track number 16 | * creates v1.1 tag, providing a total forces v2.0). 17 | * --tg <genre> audio/song genre (name or number in list) 18 | * --ti <file> audio/song albumArt (jpeg/png/gif file, v2.3 tag) 19 | * --tv <id=value> user-defined frame specified by id and value (v2.3 tag) 20 | * --add-id3v2 force addition of version 2 tag 21 | * --id3v1-only add only a version 1 tag 22 | * --id3v2-only add only a version 2 tag 23 | * --id3v2-utf16 add following options in unicode text encoding 24 | * --id3v2-latin1 add following options in latin-1 text encoding 25 | * --space-id3v1 pad version 1 tag with spaces instead of nulls 26 | * --pad-id3v2 same as '--pad-id3v2-size 128' 27 | * --pad-id3v2-size <value> adds version 2 tag, pad with extra <value> bytes 28 | * --genre-list print alphabetically sorted ID3 genre list and exit 29 | * --ignore-tag-errors ignore errors in values passed for tags 30 | * <p> 31 | * Note: A version 2 tag will NOT be added unless one of the input fields 32 | * won't fit in a version 1 tag (e.g. the title string is longer than 30 33 | * characters), or the '--add-id3v2' or '--id3v2-only' options are used, 34 | * or output is redirected to stdout. 35 | * 36 | * @author Victor Chiu 37 | */ 38 | public class Id3TagOptions { 39 | 40 | /** 41 | * 标题 42 | */ 43 | private String title; 44 | /** 45 | * 作者 46 | */ 47 | private String artist; 48 | /** 49 | * 专集 50 | */ 51 | private String album; 52 | /** 53 | * 出品年代 54 | */ 55 | private String year; 56 | /** 57 | * 备注 58 | */ 59 | private String comment; 60 | /** 61 | * 类型 62 | * 一系列<a href="https://4332weizi.github.io/lame-mirror/doc/html/detailed.html#genre-list">艺术类型清单</a> 63 | * 中的一个 64 | */ 65 | private String genre; 66 | /** 67 | * 类型 68 | * 一系列中的<a href="https://4332weizi.github.io/lame-mirror/doc/html/detailed.html#genre-list">艺术类型清单</a> 69 | * 中的一个编号 70 | */ 71 | private int genreId; 72 | /** 73 | * 曲目 74 | */ 75 | private int track; 76 | /** 77 | * 曲目 78 | */ 79 | private int totalTrack; 80 | /** 81 | * 封面 82 | */ 83 | private String albumArt; 84 | /** 85 | * 由id和value(v2.3)定义的文本或URL帧。 86 | * 用户自定义帧。 87 | */ 88 | private Map<String, String> userDefinedFrames; 89 | private boolean forceAddId3v2; 90 | private boolean addId3v1Only; 91 | private boolean addId3v2Only; 92 | private boolean useUtf16; 93 | private boolean useLation1; 94 | private boolean space; 95 | private int pad = -1; 96 | private int padv2; 97 | /** 98 | * 忽略传入的标签值中的错误 99 | */ 100 | private boolean ignoreErrors = false; 101 | 102 | public Id3TagOptions() { 103 | userDefinedFrames = new HashMap<>(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/InputOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | import android.support.annotation.FloatRange; 4 | 5 | /** 6 | * Input options:<p> 7 | * --scale <arg> scale input (multiply PCM data) by <arg><p> 8 | * --scale-l <arg> scale channel 0 (left) input (multiply PCM data) by <arg><p> 9 | * --scale-r <arg> scale channel 1 (right) input (multiply PCM data) by <arg><p> 10 | * --swap-channel swap L/R channels<p> 11 | * --ignorelength ignore file length in WAV header<p> 12 | * --gain <arg> apply Gain adjustment in decibels, range -20.0 to +12.0<p> 13 | * --mp1input input file is a MPEG Layer I file<p> 14 | * --mp2input input file is a MPEG Layer II file<p> 15 | * --mp3input input file is a MPEG Layer III file<p> 16 | * --nogap <file1> <file2> <...><p> 17 | * gapless encoding for a set of contiguous files<p> 18 | * --nogapout <dir><p> 19 | * output dir for gapless encoding (must precede --nogap)<p> 20 | * --nogaptags allow the use of VBR tags in gapless encoding<p> 21 | * --out-dir <dir> output dir, must exist<p> 22 | * 23 | * @author Victor Chiu 24 | */ 25 | 26 | public class InputOptions { 27 | 28 | /** 29 | * 按scale缩放输入数据 30 | */ 31 | private float scale = -1; 32 | /** 33 | * 按scaleLeft缩放channel 0 (左声道)数据 34 | */ 35 | private float scaleLeft = -1; 36 | /** 37 | * 按scaleRight缩放channel 1 (右声道)数据 38 | */ 39 | private float scaleRight = -1; 40 | /** 41 | * 在[-20.0,+12.0]范围内以分贝为单位进行增益调整 42 | */ 43 | private float gain = 0; 44 | /** 45 | * 交换左右声道 46 | */ 47 | private boolean swapChannel = false; 48 | /** 49 | * 忽略WAV文件头中的文件长度 50 | */ 51 | private boolean ignoreLength = false; 52 | 53 | public InputOptions scale(float scale) { 54 | this.scale = scale; 55 | return this; 56 | } 57 | 58 | public InputOptions scaleLeft(float scaleLeft) { 59 | this.scaleLeft = scaleLeft; 60 | return this; 61 | } 62 | 63 | public InputOptions scaleRight(float scaleRight) { 64 | this.scaleRight = scaleRight; 65 | return this; 66 | } 67 | 68 | public InputOptions gain(@FloatRange(from = -20, to = 12) float gain) { 69 | this.gain = gain; 70 | return this; 71 | } 72 | 73 | public InputOptions swapChannel(boolean swapChannel) { 74 | this.swapChannel = swapChannel; 75 | return this; 76 | } 77 | 78 | public InputOptions ignoreLength(boolean ignoreLength) { 79 | this.ignoreLength = ignoreLength; 80 | return this; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/Mp3HeaderStreamOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | import android.support.annotation.IntDef; 4 | 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | /** 9 | * MP3 header/stream options:\n" 10 | * -e <emp> de-emphasis n/5/c (obsolete) 11 | * -c mark as copyright 12 | * -o mark as non-original 13 | * -p error protection. adds 16 bit checksum to every frame 14 | * . (the checksum is computed correctly) 15 | * --nores disable the bit reservoir 16 | * --strictly-enforce-ISO comply as much as possible to ISO MPEG spec); 17 | * --buffer-constraint <constraint> available values for constraint: 18 | * . default, strict, maximum 19 | * 20 | * @author Victor Chiu 21 | */ 22 | public class Mp3HeaderStreamOptions { 23 | 24 | @IntDef({MDB_DEFAULT, MDB_STRICT_ISO, MDB_MAXIMUM}) 25 | @Retention(RetentionPolicy.SOURCE) 26 | public @interface BufferConstraint { 27 | } 28 | 29 | public static final int MDB_DEFAULT = 0; 30 | public static final int MDB_STRICT_ISO = 1; 31 | public static final int MDB_MAXIMUM = 2; 32 | 33 | @IntDef({EMPHASIS_N, EMPHASIS_5, EMPHASIS_C}) 34 | @Retention(RetentionPolicy.SOURCE) 35 | public @interface DeEmphasis { 36 | } 37 | 38 | public static final int EMPHASIS_N = 0; 39 | public static final int EMPHASIS_5 = 1; 40 | public static final int EMPHASIS_C = 5; 41 | 42 | /** 43 | * 去加重 44 | */ 45 | private int deEmphasis = -1; 46 | /** 47 | * 标记为版权 48 | */ 49 | private boolean markAsCopyright; 50 | /** 51 | * 标记为非原创 52 | */ 53 | private boolean markAsNonOriginal; 54 | /** 55 | * 错误检测 56 | */ 57 | private boolean errorProtection = false; 58 | /** 59 | * 缓冲区 60 | */ 61 | private boolean bitReservoir = true; 62 | /** 63 | * 严格遵守ISO MPEG规范 64 | */ 65 | private boolean strictlyEnforceISO = false; 66 | /** 67 | * 缓冲约束 68 | */ 69 | private int bufferConstraint = MDB_DEFAULT; 70 | 71 | public Mp3HeaderStreamOptions deEmphasis(@DeEmphasis int deEmphasis) { 72 | this.deEmphasis = deEmphasis; 73 | return this; 74 | } 75 | 76 | public Mp3HeaderStreamOptions markAsCopyright() { 77 | this.markAsCopyright = true; 78 | return this; 79 | } 80 | 81 | public Mp3HeaderStreamOptions markAsNonOriginal() { 82 | this.markAsNonOriginal = true; 83 | return this; 84 | } 85 | 86 | public Mp3HeaderStreamOptions enableErrorProtection() { 87 | this.errorProtection = true; 88 | return this; 89 | } 90 | 91 | public Mp3HeaderStreamOptions disableErrorProtection() { 92 | this.errorProtection = false; 93 | return this; 94 | } 95 | 96 | public Mp3HeaderStreamOptions disabledBitReservoir() { 97 | this.bitReservoir = false; 98 | return this; 99 | } 100 | 101 | public Mp3HeaderStreamOptions strictlyEnforceISO(){ 102 | this.strictlyEnforceISO = true; 103 | return this; 104 | } 105 | 106 | public Mp3HeaderStreamOptions bufferConstraint(@BufferConstraint int bufferConstraint) { 107 | this.bufferConstraint = bufferConstraint; 108 | return this; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/OperationalOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | import android.support.annotation.IntDef; 4 | 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | /** 9 | * Operational options:<p> 10 | * -m <mode> (j)oint, (s)imple, (f)orce, (d)ual-mono, (m)ono (l)eft (r)ight 11 | * default is (j)<p> 12 | * joint = Uses the best possible of MS and LR stereo<p> 13 | * simple = force LR stereo on all frames<p> 14 | * force = force MS stereo on all frames.<p> 15 | * --preset type type must be "medium", "standard", "extreme", "insane",<p> 16 | * or a value for an average desired bitrate and depending 17 | * on the value specified, appropriate quality settings will 18 | * be used. 19 | * "--preset help" gives more info on these<p> 20 | * --comp <arg> choose bitrate to achieve a compression ratio of <arg><p> 21 | * --replaygain-fast compute RG fast but slightly inaccurately (default)<p> 22 | * --replaygain-accurate compute RG more accurately and find the peak sample<p> 23 | * --noreplaygain disable ReplayGain analysis<p> 24 | * --clipdetect enable --replaygain-accurate and print a message whether 25 | * clipping occurs and how far the waveform is from full scale<p> 26 | * --flush flush output stream as soon as possible<p> 27 | * --freeformat produce a free format bitstream<p> 28 | * --decode input=mp3 file, output=wav<p> 29 | * -t disable writing wav header when using --decode<p> 30 | * 31 | * @author Victor Chiu 32 | */ 33 | 34 | public class OperationalOptions { 35 | 36 | @IntDef({MODE_JOINT, MODE_SIMPLE, MODE_FORCE, MODE_DUAL_MONO, 37 | MODE_MONO, MODE_LEFT, MODE_RIGHT}) 38 | @Retention(RetentionPolicy.SOURCE) 39 | public @interface Mode { 40 | } 41 | 42 | public static final int MODE_JOINT = 1; 43 | public static final int MODE_SIMPLE = 2; 44 | public static final int MODE_FORCE = 3; 45 | public static final int MODE_DUAL_MONO = 4; 46 | public static final int MODE_MONO = 5; 47 | public static final int MODE_LEFT = 6; 48 | public static final int MODE_RIGHT = 7; 49 | 50 | @IntDef({TYPE_MEDIUM, TYPE_STANDARD, TYPE_EXTREME, TYPE_INSANE}) 51 | @Retention(RetentionPolicy.SOURCE) 52 | public @interface Type { 53 | } 54 | 55 | public static final int TYPE_MEDIUM = 1; 56 | public static final int TYPE_STANDARD = 2; 57 | public static final int TYPE_EXTREME = 3; 58 | public static final int TYPE_INSANE = 4; 59 | 60 | @IntDef({REPLAY_GAIN_FAST, REPLAY_GAIN_ACCURATE, REPLAY_GAIN_NO}) 61 | @Retention(RetentionPolicy.SOURCE) 62 | public @interface ReplayGain { 63 | } 64 | 65 | public static final int REPLAY_GAIN_FAST = 1; 66 | public static final int REPLAY_GAIN_ACCURATE = 2; 67 | public static final int REPLAY_GAIN_NO = 3; 68 | 69 | /** 70 | * 编码模式 71 | * 72 | * @see #MODE_JOINT 73 | * @see #MODE_SIMPLE 74 | * @see #MODE_FORCE 75 | * @see #MODE_DUAL_MONO 76 | * @see #MODE_MONO 77 | * @see #MODE_LEFT 78 | * @see #MODE_RIGHT 79 | */ 80 | private int mode = -1; 81 | /** 82 | * 使用预设 83 | * 84 | * @see #TYPE_MEDIUM 85 | * @see #TYPE_STANDARD 86 | * @see #TYPE_EXTREME 87 | * @see #TYPE_INSANE 88 | */ 89 | private int preset; 90 | /** 91 | * 压缩率 92 | */ 93 | private float ratio; 94 | /** 95 | * 回放增益 96 | * 97 | * @see #REPLAY_GAIN_FAST 98 | * @see #REPLAY_GAIN_ACCURATE 99 | * @see #REPLAY_GAIN_NO 100 | */ 101 | private int replayGain; 102 | /** 103 | * 尽快清空输出流 104 | */ 105 | private boolean flush; 106 | /** 107 | * 生成自由格式的比特流(bitstream),而不是标准格式, 108 | * 支持8到640kbps之间的比特率。但解码器提供的支持不足。 109 | */ 110 | private boolean freeFormat; 111 | /** 112 | * 输入为mp3文件,输出wav文件。 113 | */ 114 | private boolean decode; 115 | /** 116 | * 使用decode时禁止写入wav header 117 | */ 118 | private boolean writingWavHeader; 119 | 120 | 121 | public OperationalOptions mode(@Mode int mode) { 122 | this.mode = mode; 123 | return this; 124 | } 125 | 126 | public OperationalOptions preset(@Type int type) { 127 | this.preset = type; 128 | return this; 129 | } 130 | 131 | public OperationalOptions ratio(int ratio) { 132 | this.ratio = ratio; 133 | return this; 134 | } 135 | 136 | public OperationalOptions replayGain(@ReplayGain int replayGain) { 137 | this.replayGain = replayGain; 138 | return this; 139 | } 140 | 141 | public OperationalOptions flush(boolean flush) { 142 | this.flush = flush; 143 | return this; 144 | } 145 | 146 | public OperationalOptions freeFormat(boolean freeFormat) { 147 | this.freeFormat = freeFormat; 148 | return this; 149 | } 150 | 151 | public OperationalOptions decode(boolean decode) { 152 | this.decode = decode; 153 | return this; 154 | } 155 | 156 | public OperationalOptions writingWavHeader(boolean writingWavHeader) { 157 | this.writingWavHeader = writingWavHeader; 158 | return this; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/RawPcmInputOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | import android.support.annotation.IntDef; 4 | 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | /** 9 | * Input options for RAW PCM:<p> 10 | * -r input is raw pcm<p> 11 | * -s sfreq sampling frequency of input file (kHz) - default 44.1 kHz<p> 12 | * --signed input is signed (default)<p> 13 | * --unsigned input is unsigned<p> 14 | * --bitwidth w input bit width is w (default 16)<p> 15 | * -x force byte-swapping of input<p> 16 | * --little-endian input is little-endian (default)<p> 17 | * --big-endian input is big-endian<p> 18 | * -a downmix from stereo to mono file for mono encoding<p> 19 | * 20 | * @author Victor Chiu 21 | */ 22 | 23 | public class RawPcmInputOptions { 24 | 25 | @IntDef({LITTLE_ENDIAN, BIG_ENDIAN}) 26 | @Retention(RetentionPolicy.SOURCE) 27 | public @interface Endian { 28 | } 29 | 30 | public static final int LITTLE_ENDIAN = 1; 31 | public static final int BIG_ENDIAN = 2; 32 | 33 | /** 34 | * 输入文件为原始PCM数据 35 | */ 36 | private boolean rawPcm; 37 | /** 38 | * 采样率(单位Khz)(默认44.1Khz) 39 | */ 40 | private float sampleRate; 41 | /** 42 | * 输入源数据为有符号(默认)或无符号 43 | */ 44 | private boolean signed = true; 45 | /** 46 | * 输入源数据位宽(默认16) 47 | */ 48 | private int bitWidth; 49 | /** 50 | * 是否强制进行字节交换 51 | */ 52 | private boolean forceByteSwapping; 53 | /** 54 | * 输入源数据的字节存储机制 55 | * 56 | * @see #LITTLE_ENDIAN 57 | * @see #BIG_ENDIAN 58 | */ 59 | private int endian; 60 | /** 61 | * 是否从立体声(stereo)下混音(downmix)到单声道(mono)以进行单声道编码 62 | */ 63 | private boolean downmix; 64 | 65 | public RawPcmInputOptions rawPcm(boolean rawPcm) { 66 | this.rawPcm = rawPcm; 67 | return this; 68 | } 69 | 70 | public RawPcmInputOptions forceByteSwapping(boolean forceByteSwapping) { 71 | this.forceByteSwapping = forceByteSwapping; 72 | return this; 73 | } 74 | 75 | public RawPcmInputOptions sampleRate(float sampleRate) { 76 | this.sampleRate = sampleRate; 77 | return this; 78 | } 79 | 80 | public RawPcmInputOptions bitWidth(int bitWidth) { 81 | this.bitWidth = bitWidth; 82 | return this; 83 | } 84 | 85 | public RawPcmInputOptions signed(boolean signed) { 86 | this.signed = signed; 87 | return this; 88 | } 89 | 90 | public RawPcmInputOptions endian(@Endian int endian) { 91 | this.endian = endian; 92 | return this; 93 | } 94 | 95 | public RawPcmInputOptions downmix(boolean downmix) { 96 | this.downmix = downmix; 97 | return this; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /ame/src/main/java/io/auxo/ame/options/VbrOptions.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.options; 2 | 3 | import android.support.annotation.FloatRange; 4 | import android.support.annotation.IntDef; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | /** 10 | * VBR options:<p> 11 | * -V n quality setting for VBR. default n=%i<p> 12 | * . 0=high quality,bigger files. 9=smaller files<p> 13 | * -v the same as -V 4<p> 14 | * --vbr-old use old variable bitrate (VBR) routine<p> 15 | * --vbr-new use new variable bitrate (VBR) routine (default)<p> 16 | * -Y lets LAME ignore noise in sfb21, like in CBR<p> 17 | * . (Default for V3 to V9.999)<p> 18 | * -b <bitrate> specify minimum allowed bitrate, default 32 kbps<p> 19 | * -B <bitrate> specify maximum allowed bitrate, default 320 kbps<p> 20 | * -F strictly enforce the -b option, for use with players that<p> 21 | * . do not support low bitrate mp3<p> 22 | * -t disable writing LAME Tag<p> 23 | * -T enable and force writing LAME Tag);<p> 24 | * 25 | * @author Victor Chiu 26 | */ 27 | public class VbrOptions { 28 | 29 | @IntDef({VBR_OFF, VBR_MT, VBR_RH, VBR_ABR, VBR_MTRH, VBR_MAX_INDICATOR}) 30 | @Retention(RetentionPolicy.SOURCE) 31 | public @interface VbrMode { 32 | } 33 | 34 | public static final int VBR_OFF = 0; 35 | public static final int VBR_MT = 1; 36 | public static final int VBR_RH = 2; 37 | public static final int VBR_ABR = 3; 38 | public static final int VBR_MTRH = 4; 39 | public static final int VBR_MAX_INDICATOR = 5; 40 | 41 | /** 42 | * VBR的质量设置。默认quality=4. 43 | * 可以指定Decima类型的值, 如:4.51 44 | * 0=最高质量,生成的文件较大; 45 | * 9.999=最低质量,生成的文件较小。 46 | */ 47 | private double quality = -1; 48 | /** 49 | * VBR模式 50 | */ 51 | private int vbrMode = -1; 52 | private boolean ignoreNoise = false; 53 | /** 54 | * 可接受的最低比特率,默认32kbps 55 | */ 56 | private int minBitrate = -1; 57 | /** 58 | * 可接受的最高比特率,默认320kbps 59 | */ 60 | private int maxBitrate = -1; 61 | /** 62 | * 严格限制最低比特率 63 | */ 64 | private boolean strictlyEnforceMinBitrate = false; 65 | /** 66 | * 写入LAME标签 67 | */ 68 | private boolean writingLameTag = false; 69 | 70 | public VbrOptions quality(@FloatRange(from = 0, to = 10, toInclusive = false) float quality) { 71 | this.quality = quality; 72 | return this; 73 | } 74 | 75 | public VbrOptions mode(@VbrMode int mode) { 76 | this.vbrMode = mode; 77 | return this; 78 | } 79 | 80 | public VbrOptions ignoreNoise() { 81 | this.ignoreNoise = true; 82 | return this; 83 | } 84 | 85 | public VbrOptions minBitrate(int min) { 86 | this.minBitrate = min; 87 | return this; 88 | } 89 | 90 | public VbrOptions maxBitrate(int max) { 91 | this.maxBitrate = max; 92 | return this; 93 | } 94 | 95 | public VbrOptions strictlyEnforceMinBitrate() { 96 | this.strictlyEnforceMinBitrate = true; 97 | return this; 98 | } 99 | 100 | public VbrOptions writingLameTag() { 101 | this.writingLameTag = true; 102 | return this; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ame/src/test/java/io/auxo/ame/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.1.0' 12 | } 13 | 14 | ext.versions = [ 15 | 'minSdk' : 14, 16 | 'compileSdk' : 27, 17 | 18 | 'supportLibrary': '27.1.0', 19 | 20 | 'mp3lame' : '3.100', 21 | 'ame' : '0', 22 | 'ame_lite' : '0.1' 23 | ] 24 | 25 | ext.deps = [ 26 | 'support': [ 27 | 'appcompat' : "com.android.support:appcompat-v7:$versions.supportLibrary", 28 | 'annotations': "com.android.support:support-annotations:$versions.supportLibrary" 29 | ], 30 | 'junit' : 'junit:junit:4.12', 31 | 'test' : [ 32 | 'runner' : 'com.android.support.test:runner:1.0.1', 33 | 'espresso': 'com.android.support.test.espresso:espresso-core:3.0.1' 34 | ] 35 | ] 36 | } 37 | 38 | allprojects { 39 | repositories { 40 | google() 41 | jcenter() 42 | } 43 | } 44 | 45 | task clean(type: Delete) { 46 | delete rootProject.buildDir 47 | } 48 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | MAVEN_REPO_GROUP=io.auxo.ame 15 | MAVEN_REPO_USERNAME= 16 | MAVEN_REPO_PASSWORD= -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Apr 02 09:19:19 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /mavenUpload.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven' 2 | 3 | def VERSION_NAME = android.getDefaultConfig().versionName 4 | 5 | def isSnapshotBuild = VERSION_NAME.contains("SNAPSHOT") 6 | 7 | task sourcesJar(type: Jar) { 8 | from android.sourceSets.main.java.srcDirs 9 | classifier = 'sources' 10 | } 11 | 12 | task javadoc(type: Javadoc) { 13 | failOnError = false 14 | options.encoding = "UTF-8" 15 | source = android.sourceSets.main.java.srcDirs 16 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 17 | } 18 | 19 | task javadocJar(type: Jar, dependsOn: javadoc) { 20 | classifier = 'javadoc' 21 | from javadoc.destinationDir 22 | } 23 | 24 | artifacts { 25 | if (!isSnapshotBuild) { 26 | archives javadocJar 27 | archives sourcesJar 28 | } 29 | } 30 | 31 | uploadArchives { 32 | repositories { 33 | mavenDeployer { 34 | snapshotRepository(url: MAVEN_REPO_SNAPSHOT) { 35 | authentication(userName: MAVEN_REPO_USERNAME, password: MAVEN_REPO_PASSWORD) 36 | } 37 | repository(url: MAVEN_REPO_RELEASE) { 38 | authentication(userName: MAVEN_REPO_USERNAME, password: MAVEN_REPO_PASSWORD) 39 | } 40 | pom.project { 41 | groupId MAVEN_REPO_GROUP 42 | artifactId MAVEN_REPO_ARTIFACT 43 | version VERSION_NAME 44 | packaging 'aar' 45 | } 46 | 47 | println 'Group Id:' + MAVEN_REPO_GROUP 48 | println 'Artifact:' + MAVEN_REPO_ARTIFACT 49 | println 'Version:' + VERSION_NAME 50 | println 'Maven Repository:' + (isSnapshotBuild ? MAVEN_REPO_SNAPSHOT : MAVEN_REPO_RELEASE) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /mp3lame/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.so -------------------------------------------------------------------------------- /mp3lame/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion versions.compileSdk 5 | 6 | defaultConfig { 7 | minSdkVersion versions.minSdk 8 | targetSdkVersion versions.compileSdk 9 | versionName versions.mp3lame 10 | 11 | externalNativeBuild { 12 | cmake { 13 | cFlags "-DSTDC_HEADERS" 14 | targets 'mp3lame' 15 | } 16 | } 17 | 18 | ndk { 19 | abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64" 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | 30 | externalNativeBuild { 31 | cmake { 32 | path "src/main/cpp/CMakeLists.txt" 33 | } 34 | } 35 | } 36 | 37 | apply from: "../mavenUpload.gradle" -------------------------------------------------------------------------------- /mp3lame/gradle.properties: -------------------------------------------------------------------------------- 1 | MAVEN_REPO_RELEASE=https://api.bintray.com/maven/4332weizi/Android/mp3lame/;publish=1 2 | MAVEN_REPO_SNAPSHOT= 3 | MAVEN_REPO_ARTIFACT=mp3lame -------------------------------------------------------------------------------- /mp3lame/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /mp3lame/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 | package="io.auxo.lame" /> 3 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | set( DIST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../dist ) 4 | 5 | # 添加mp3lame源文件 6 | aux_source_directory( ${CMAKE_HOME_DIRECTORY} LAME_SRC_LIST ) 7 | aux_source_directory( ${CMAKE_HOME_DIRECTORY}/vector LAME_VECTOR_SRC_LIST ) 8 | 9 | add_library( mp3lame 10 | SHARED 11 | ${LAME_SRC_LIST} 12 | ${LAME_VECTOR_SRC_LIST} ) 13 | 14 | # 设定动态链接库输出路径 15 | set_target_properties( mp3lame 16 | PROPERTIES 17 | LIBRARY_OUTPUT_DIRECTORY 18 | "${DIST_DIR}/mp3lame/lib/${ANDROID_ABI}" ) 19 | 20 | # 拷贝头文件到分发路径 21 | add_custom_command(TARGET mp3lame POST_BUILD 22 | COMMAND "${CMAKE_COMMAND}" -E 23 | copy "${CMAKE_CURRENT_SOURCE_DIR}/lame.h" 24 | "${DIST_DIR}/mp3lame/include/lame.h" 25 | COMMENT "Copying lame to output directory" ) -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/VbrTag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Xing VBR tagging for LAME. 3 | * 4 | * Copyright (c) 1999 A.L. Faber 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_VRBTAG_H 23 | #define LAME_VRBTAG_H 24 | 25 | 26 | /* ----------------------------------------------------------- 27 | * A Vbr header may be present in the ancillary 28 | * data field of the first frame of an mp3 bitstream 29 | * The Vbr header (optionally) contains 30 | * frames total number of audio frames in the bitstream 31 | * bytes total number of bytes in the bitstream 32 | * toc table of contents 33 | 34 | * toc (table of contents) gives seek points 35 | * for random access 36 | * the ith entry determines the seek point for 37 | * i-percent duration 38 | * seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes 39 | * e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes 40 | */ 41 | 42 | 43 | #define FRAMES_FLAG 0x0001 44 | #define BYTES_FLAG 0x0002 45 | #define TOC_FLAG 0x0004 46 | #define VBR_SCALE_FLAG 0x0008 47 | 48 | #define NUMTOCENTRIES 100 49 | 50 | #ifndef lame_internal_flags_defined 51 | #define lame_internal_flags_defined 52 | struct lame_internal_flags; 53 | typedef struct lame_internal_flags lame_internal_flags; 54 | #endif 55 | 56 | 57 | /*structure to receive extracted header */ 58 | /* toc may be NULL*/ 59 | typedef struct { 60 | int h_id; /* from MPEG header, 0=MPEG2, 1=MPEG1 */ 61 | int samprate; /* determined from MPEG header */ 62 | int flags; /* from Vbr header data */ 63 | int frames; /* total bit stream frames from Vbr header data */ 64 | int bytes; /* total bit stream bytes from Vbr header data */ 65 | int vbr_scale; /* encoded vbr scale from Vbr header data */ 66 | unsigned char toc[NUMTOCENTRIES]; /* may be NULL if toc not desired */ 67 | int headersize; /* size of VBR header, in bytes */ 68 | int enc_delay; /* encoder delay */ 69 | int enc_padding; /* encoder paddign added at end of stream */ 70 | } VBRTAGDATA; 71 | 72 | int GetVbrTag(VBRTAGDATA * pTagData, const unsigned char *buf); 73 | 74 | int InitVbrTag(lame_global_flags * gfp); 75 | int PutVbrTag(lame_global_flags const *gfp, FILE * fid); 76 | void AddVbrFrame(lame_internal_flags * gfc); 77 | void UpdateMusicCRC(uint16_t * crc, const unsigned char *buffer, int size); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/bitstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MP3 bitstream Output interface for LAME 3 | * 4 | * Copyright (c) 1999 Takehiro TOMINAGA 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_BITSTREAM_H 23 | #define LAME_BITSTREAM_H 24 | 25 | int getframebits(const lame_internal_flags * gfc); 26 | 27 | int format_bitstream(lame_internal_flags * gfc); 28 | 29 | void flush_bitstream(lame_internal_flags * gfc); 30 | void add_dummy_byte(lame_internal_flags * gfc, unsigned char val, unsigned int n); 31 | 32 | int copy_buffer(lame_internal_flags * gfc, unsigned char *buffer, int buffer_size, 33 | int update_crc); 34 | void init_bit_stream_w(lame_internal_flags * gfc); 35 | void CRC_writeheader(lame_internal_flags const *gfc, char *buffer); 36 | int compute_flushbits(const lame_internal_flags * gfp, int *nbytes); 37 | 38 | int get_max_frame_buffer_size_by_constraint(SessionConfig_t const * cfg, int constraint); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/encoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * encoder.h include file 3 | * 4 | * Copyright (c) 2000 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | 23 | #ifndef LAME_ENCODER_H 24 | #define LAME_ENCODER_H 25 | 26 | /*********************************************************************** 27 | * 28 | * encoder and decoder delays 29 | * 30 | ***********************************************************************/ 31 | 32 | /* 33 | * layer III enc->dec delay: 1056 (1057?) (observed) 34 | * layer II enc->dec delay: 480 (481?) (observed) 35 | * 36 | * polyphase 256-16 (dec or enc) = 240 37 | * mdct 256+32 (9*32) (dec or enc) = 288 38 | * total: 512+16 39 | * 40 | * My guess is that delay of polyphase filterbank is actualy 240.5 41 | * (there are technical reasons for this, see postings in mp3encoder). 42 | * So total Encode+Decode delay = ENCDELAY + 528 + 1 43 | */ 44 | 45 | /* 46 | * ENCDELAY The encoder delay. 47 | * 48 | * Minimum allowed is MDCTDELAY (see below) 49 | * 50 | * The first 96 samples will be attenuated, so using a value less than 96 51 | * will result in corrupt data for the first 96-ENCDELAY samples. 52 | * 53 | * suggested: 576 54 | * set to 1160 to sync with FhG. 55 | */ 56 | 57 | #define ENCDELAY 576 58 | 59 | 60 | 61 | /* 62 | * make sure there is at least one complete frame after the 63 | * last frame containing real data 64 | * 65 | * Using a value of 288 would be sufficient for a 66 | * a very sophisticated decoder that can decode granule-by-granule instead 67 | * of frame by frame. But lets not assume this, and assume the decoder 68 | * will not decode frame N unless it also has data for frame N+1 69 | * 70 | */ 71 | /*#define POSTDELAY 288*/ 72 | #define POSTDELAY 1152 73 | 74 | 75 | 76 | /* 77 | * delay of the MDCT used in mdct.c 78 | * original ISO routines had a delay of 528! 79 | * Takehiro's routines: 80 | */ 81 | 82 | #define MDCTDELAY 48 83 | #define FFTOFFSET (224+MDCTDELAY) 84 | 85 | /* 86 | * Most decoders, including the one we use, have a delay of 528 samples. 87 | */ 88 | 89 | #define DECDELAY 528 90 | 91 | 92 | /* number of subbands */ 93 | #define SBLIMIT 32 94 | 95 | /* parition bands bands */ 96 | #define CBANDS 64 97 | 98 | /* number of critical bands/scale factor bands where masking is computed*/ 99 | #define SBPSY_l 21 100 | #define SBPSY_s 12 101 | 102 | /* total number of scalefactor bands encoded */ 103 | #define SBMAX_l 22 104 | #define SBMAX_s 13 105 | #define PSFB21 6 106 | #define PSFB12 6 107 | 108 | 109 | 110 | /* FFT sizes */ 111 | #define BLKSIZE 1024 112 | #define HBLKSIZE (BLKSIZE/2 + 1) 113 | #define BLKSIZE_s 256 114 | #define HBLKSIZE_s (BLKSIZE_s/2 + 1) 115 | 116 | 117 | /* #define switch_pe 1800 */ 118 | #define NORM_TYPE 0 119 | #define START_TYPE 1 120 | #define SHORT_TYPE 2 121 | #define STOP_TYPE 3 122 | 123 | /* 124 | * Mode Extention: 125 | * When we are in stereo mode, there are 4 possible methods to store these 126 | * two channels. The stereo modes -m? are using a subset of them. 127 | * 128 | * -ms: MPG_MD_LR_LR 129 | * -mj: MPG_MD_LR_LR and MPG_MD_MS_LR 130 | * -mf: MPG_MD_MS_LR 131 | * -mi: all 132 | */ 133 | #if 0 134 | #define MPG_MD_LR_LR 0 135 | #define MPG_MD_LR_I 1 136 | #define MPG_MD_MS_LR 2 137 | #define MPG_MD_MS_I 3 138 | #endif 139 | enum MPEGChannelMode 140 | { MPG_MD_LR_LR = 0 141 | , MPG_MD_LR_I = 1 142 | , MPG_MD_MS_LR = 2 143 | , MPG_MD_MS_I = 3 144 | }; 145 | 146 | #ifndef lame_internal_flags_defined 147 | #define lame_internal_flags_defined 148 | struct lame_internal_flags; 149 | typedef struct lame_internal_flags lame_internal_flags; 150 | #endif 151 | 152 | int lame_encode_mp3_frame(lame_internal_flags * gfc, 153 | sample_t const *inbuf_l, 154 | sample_t const *inbuf_r, unsigned char *mp3buf, int mp3buf_size); 155 | 156 | #endif /* LAME_ENCODER_H */ 157 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/fft.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fast Fourier Transform include file 3 | * 4 | * Copyright (c) 2000 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_FFT_H 23 | #define LAME_FFT_H 24 | 25 | void fft_long(lame_internal_flags const *const gfc, FLOAT x_real[BLKSIZE], 26 | int chn, const sample_t *const data[2]); 27 | 28 | void fft_short(lame_internal_flags const *const gfc, FLOAT x_real[3][BLKSIZE_s], 29 | int chn, const sample_t *const data[2]); 30 | 31 | void init_fft(lame_internal_flags * const gfc); 32 | 33 | #endif 34 | 35 | /* End of fft.h */ 36 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/gain_analysis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ReplayGainAnalysis - analyzes input samples and give the recommended dB change 3 | * Copyright (C) 2001 David Robinson and Glen Sawyer 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * concept and filter values by David Robinson (David@Robinson.org) 20 | * -- blame him if you think the idea is flawed 21 | * coding by Glen Sawyer (mp3gain@hotmail.com) 735 W 255 N, Orem, UT 84057-4505 USA 22 | * -- blame him if you think this runs too slowly, or the coding is otherwise flawed 23 | * 24 | * For an explanation of the concepts and the basic algorithms involved, go to: 25 | * http://www.replaygain.org/ 26 | */ 27 | 28 | #ifndef GAIN_ANALYSIS_H 29 | #define GAIN_ANALYSIS_H 30 | 31 | #ifdef HAVE_INTTYPES_H 32 | # include <inttypes.h> 33 | #else 34 | # ifdef HAVE_STDINT_H 35 | # include <stdint.h> 36 | # endif 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | 44 | typedef sample_t Float_t; /* Type used for filtering */ 45 | 46 | 47 | #define PINK_REF 64.82 /* 298640883795 */ /* calibration value for 89dB */ 48 | 49 | 50 | #define YULE_ORDER 10 51 | #define BUTTER_ORDER 2 52 | #define YULE_FILTER filterYule 53 | #define BUTTER_FILTER filterButter 54 | #define RMS_PERCENTILE 0.95 /* percentile which is louder than the proposed level */ 55 | #define MAX_SAMP_FREQ 48000L /* maximum allowed sample frequency [Hz] */ 56 | #define RMS_WINDOW_TIME_NUMERATOR 1L 57 | #define RMS_WINDOW_TIME_DENOMINATOR 20L /* numerator / denominator = time slice size [s] */ 58 | #define STEPS_per_dB 100 /* Table entries per dB */ 59 | #define MAX_dB 120 /* Table entries for 0...MAX_dB (normal max. values are 70...80 dB) */ 60 | 61 | enum { GAIN_NOT_ENOUGH_SAMPLES = -24601, GAIN_ANALYSIS_ERROR = 0, GAIN_ANALYSIS_OK = 62 | 1, INIT_GAIN_ANALYSIS_ERROR = 0, INIT_GAIN_ANALYSIS_OK = 1 63 | }; 64 | 65 | enum { MAX_ORDER = (BUTTER_ORDER > YULE_ORDER ? BUTTER_ORDER : YULE_ORDER) 66 | , MAX_SAMPLES_PER_WINDOW = ((MAX_SAMP_FREQ * RMS_WINDOW_TIME_NUMERATOR) / RMS_WINDOW_TIME_DENOMINATOR + 1) /* max. Samples per Time slice */ 67 | }; 68 | 69 | struct replaygain_data { 70 | Float_t linprebuf[MAX_ORDER * 2]; 71 | Float_t *linpre; /* left input samples, with pre-buffer */ 72 | Float_t lstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 73 | Float_t *lstep; /* left "first step" (i.e. post first filter) samples */ 74 | Float_t loutbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 75 | Float_t *lout; /* left "out" (i.e. post second filter) samples */ 76 | Float_t rinprebuf[MAX_ORDER * 2]; 77 | Float_t *rinpre; /* right input samples ... */ 78 | Float_t rstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 79 | Float_t *rstep; 80 | Float_t routbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 81 | Float_t *rout; 82 | long sampleWindow; /* number of samples required to reach number of milliseconds required for RMS window */ 83 | long totsamp; 84 | double lsum; 85 | double rsum; 86 | int freqindex; 87 | int first; 88 | uint32_t A[STEPS_per_dB * MAX_dB]; 89 | uint32_t B[STEPS_per_dB * MAX_dB]; 90 | 91 | }; 92 | #ifndef replaygain_data_defined 93 | #define replaygain_data_defined 94 | typedef struct replaygain_data replaygain_t; 95 | #endif 96 | 97 | 98 | 99 | 100 | int InitGainAnalysis(replaygain_t * rgData, long samplefreq); 101 | int AnalyzeSamples(replaygain_t * rgData, const Float_t * left_samples, 102 | const Float_t * right_samples, size_t num_samples, int num_channels); 103 | Float_t GetTitleGain(replaygain_t * rgData); 104 | 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | #endif /* GAIN_ANALYSIS_H */ 110 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/id3tag.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef LAME_ID3_H 3 | #define LAME_ID3_H 4 | 5 | 6 | #define CHANGED_FLAG (1U << 0) 7 | #define ADD_V2_FLAG (1U << 1) 8 | #define V1_ONLY_FLAG (1U << 2) 9 | #define V2_ONLY_FLAG (1U << 3) 10 | #define SPACE_V1_FLAG (1U << 4) 11 | #define PAD_V2_FLAG (1U << 5) 12 | 13 | enum { 14 | MIMETYPE_NONE = 0, 15 | MIMETYPE_JPEG, 16 | MIMETYPE_PNG, 17 | MIMETYPE_GIF 18 | }; 19 | 20 | typedef struct FrameDataNode { 21 | struct FrameDataNode *nxt; 22 | uint32_t fid; /* Frame Identifier */ 23 | char lng[4]; /* 3-character language descriptor */ 24 | struct { 25 | union { 26 | char *l; /* ptr to Latin-1 chars */ 27 | unsigned short *u; /* ptr to UCS-2 text */ 28 | unsigned char *b; /* ptr to raw bytes */ 29 | } ptr; 30 | size_t dim; 31 | int enc; /* 0:Latin-1, 1:UCS-2, 2:RAW */ 32 | } dsc , txt; 33 | } FrameDataNode; 34 | 35 | 36 | typedef struct id3tag_spec { 37 | /* private data members */ 38 | unsigned int flags; 39 | int year; 40 | char *title; 41 | char *artist; 42 | char *album; 43 | char *comment; 44 | int track_id3v1; 45 | int genre_id3v1; 46 | unsigned char *albumart; 47 | unsigned int albumart_size; 48 | unsigned int padding_size; 49 | int albumart_mimetype; 50 | char language[4]; /* the language of the frame's content, according to ISO-639-2 */ 51 | FrameDataNode *v2_head, *v2_tail; 52 | } id3tag_spec; 53 | 54 | 55 | /* write tag into stream at current position */ 56 | extern int id3tag_write_v2(lame_global_flags * gfp); 57 | extern int id3tag_write_v1(lame_global_flags * gfp); 58 | /* 59 | * NOTE: A version 2 tag will NOT be added unless one of the text fields won't 60 | * fit in a version 1 tag (e.g. the title string is longer than 30 characters), 61 | * or the "id3tag_add_v2" or "id3tag_v2_only" functions are used. 62 | */ 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/l3side.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Layer 3 side include file 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_L3SIDE_H 23 | #define LAME_L3SIDE_H 24 | 25 | /* max scalefactor band, max(SBMAX_l, SBMAX_s*3, (SBMAX_s-3)*3+8) */ 26 | #define SFBMAX (SBMAX_s*3) 27 | 28 | /* Layer III side information. */ 29 | typedef struct { 30 | int l[1 + SBMAX_l]; 31 | int s[1 + SBMAX_s]; 32 | int psfb21[1 + PSFB21]; 33 | int psfb12[1 + PSFB12]; 34 | } scalefac_struct; 35 | 36 | 37 | typedef struct { 38 | FLOAT l[SBMAX_l]; 39 | FLOAT s[SBMAX_s][3]; 40 | } III_psy_xmin; 41 | 42 | typedef struct { 43 | III_psy_xmin thm; 44 | III_psy_xmin en; 45 | } III_psy_ratio; 46 | 47 | typedef struct { 48 | FLOAT xr[576]; 49 | int l3_enc[576]; 50 | int scalefac[SFBMAX]; 51 | FLOAT xrpow_max; 52 | 53 | int part2_3_length; 54 | int big_values; 55 | int count1; 56 | int global_gain; 57 | int scalefac_compress; 58 | int block_type; 59 | int mixed_block_flag; 60 | int table_select[3]; 61 | int subblock_gain[3 + 1]; 62 | int region0_count; 63 | int region1_count; 64 | int preflag; 65 | int scalefac_scale; 66 | int count1table_select; 67 | 68 | int part2_length; 69 | int sfb_lmax; 70 | int sfb_smin; 71 | int psy_lmax; 72 | int sfbmax; 73 | int psymax; 74 | int sfbdivide; 75 | int width[SFBMAX]; 76 | int window[SFBMAX]; 77 | int count1bits; 78 | /* added for LSF */ 79 | const int *sfb_partition_table; 80 | int slen[4]; 81 | 82 | int max_nonzero_coeff; 83 | char energy_above_cutoff[SFBMAX]; 84 | } gr_info; 85 | 86 | typedef struct { 87 | gr_info tt[2][2]; 88 | int main_data_begin; 89 | int private_bits; 90 | int resvDrain_pre; 91 | int resvDrain_post; 92 | int scfsi[2][4]; 93 | } III_side_info_t; 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/lame-analysis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GTK plotting routines source file 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_GTKANAL_H 23 | #define LAME_GTKANAL_H 24 | 25 | 26 | #define READ_AHEAD 40 /* number of frames to read ahead */ 27 | #define MAXMPGLAG READ_AHEAD /* if the mpg123 lag becomes bigger than this 28 | we have to stop */ 29 | #define NUMBACK 6 /* number of frames we can back up */ 30 | #define NUMPINFO (NUMBACK+READ_AHEAD+1) 31 | 32 | 33 | 34 | struct plotting_data { 35 | int frameNum; /* current frame number */ 36 | int frameNum123; 37 | int num_samples; /* number of pcm samples read for this frame */ 38 | double frametime; /* starting time of frame, in seconds */ 39 | double pcmdata[2][1600]; 40 | double pcmdata2[2][1152 + 1152 - DECDELAY]; 41 | double xr[2][2][576]; 42 | double mpg123xr[2][2][576]; 43 | double ms_ratio[2]; 44 | double ms_ener_ratio[2]; 45 | 46 | /* L,R, M and S values */ 47 | double energy_save[4][BLKSIZE]; /* psymodel is one ahead */ 48 | double energy[2][4][BLKSIZE]; 49 | double pe[2][4]; 50 | double thr[2][4][SBMAX_l]; 51 | double en[2][4][SBMAX_l]; 52 | double thr_s[2][4][3 * SBMAX_s]; 53 | double en_s[2][4][3 * SBMAX_s]; 54 | double ers_save[4]; /* psymodel is one ahead */ 55 | double ers[2][4]; 56 | 57 | double sfb[2][2][SBMAX_l]; 58 | double sfb_s[2][2][3 * SBMAX_s]; 59 | double LAMEsfb[2][2][SBMAX_l]; 60 | double LAMEsfb_s[2][2][3 * SBMAX_s]; 61 | 62 | int LAMEqss[2][2]; 63 | int qss[2][2]; 64 | int big_values[2][2]; 65 | int sub_gain[2][2][3]; 66 | 67 | double xfsf[2][2][SBMAX_l]; 68 | double xfsf_s[2][2][3 * SBMAX_s]; 69 | 70 | int over[2][2]; 71 | double tot_noise[2][2]; 72 | double max_noise[2][2]; 73 | double over_noise[2][2]; 74 | int over_SSD[2][2]; 75 | int blocktype[2][2]; 76 | int scalefac_scale[2][2]; 77 | int preflag[2][2]; 78 | int mpg123blocktype[2][2]; 79 | int mixed[2][2]; 80 | int mainbits[2][2]; 81 | int sfbits[2][2]; 82 | int LAMEmainbits[2][2]; 83 | int LAMEsfbits[2][2]; 84 | int framesize, stereo, js, ms_stereo, i_stereo, emph, bitrate, sampfreq, maindata; 85 | int crc, padding; 86 | int scfsi[2], mean_bits, resvsize; 87 | int totbits; 88 | }; 89 | #ifndef plotting_data_defined 90 | #define plotting_data_defined 91 | typedef struct plotting_data plotting_data; 92 | #endif 93 | #if 0 94 | extern plotting_data *pinfo; 95 | #endif 96 | #endif 97 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/lameerror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * A collection of LAME Error Codes 3 | * 4 | * Please use the constants defined here instead of some arbitrary 5 | * values. Currently the values starting at -10 to avoid intersection 6 | * with the -1, -2, -3 and -4 used in the current code. 7 | * 8 | * May be this should be a part of the include/lame.h. 9 | */ 10 | 11 | typedef enum { 12 | LAME_OKAY = 0, 13 | LAME_NOERROR = 0, 14 | LAME_GENERICERROR = -1, 15 | LAME_NOMEM = -10, 16 | LAME_BADBITRATE = -11, 17 | LAME_BADSAMPFREQ = -12, 18 | LAME_INTERNALERROR = -13, 19 | 20 | FRONTEND_READERROR = -80, 21 | FRONTEND_WRITEERROR = -81, 22 | FRONTEND_FILETOOLARGE = -82, 23 | 24 | } lame_errorcodes_t; 25 | 26 | /* end of lameerror.h */ 27 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/machine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Machine dependent defines/includes for LAME. 3 | * 4 | * Copyright (c) 1999 A.L. Faber 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_MACHINE_H 23 | #define LAME_MACHINE_H 24 | 25 | #include "version.h" 26 | 27 | #include <stdio.h> 28 | #include <assert.h> 29 | 30 | #ifdef STDC_HEADERS 31 | # include <stdlib.h> 32 | # include <string.h> 33 | #else 34 | # ifndef HAVE_STRCHR 35 | # define strchr index 36 | # define strrchr rindex 37 | # endif 38 | char *strchr(), *strrchr(); 39 | # ifndef HAVE_MEMCPY 40 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) 41 | # define memmove(d, s, n) bcopy ((s), (d), (n)) 42 | # endif 43 | #endif 44 | 45 | #if defined(__riscos__) && defined(FPA10) 46 | # include "ymath.h" 47 | #else 48 | # include <math.h> 49 | #endif 50 | #include <limits.h> 51 | 52 | #include <ctype.h> 53 | 54 | #ifdef HAVE_ERRNO_H 55 | # include <errno.h> 56 | #endif 57 | #ifdef HAVE_FCNTL_H 58 | # include <fcntl.h> 59 | #endif 60 | 61 | #if defined(macintosh) 62 | # include <types.h> 63 | # include <stat.h> 64 | #else 65 | # include <sys/types.h> 66 | # include <sys/stat.h> 67 | #endif 68 | 69 | #ifdef HAVE_INTTYPES_H 70 | # include <inttypes.h> 71 | #else 72 | # ifdef HAVE_STDINT_H 73 | # include <stdint.h> 74 | # endif 75 | #endif 76 | 77 | #ifdef WITH_DMALLOC 78 | #include <dmalloc.h> 79 | #endif 80 | 81 | /* 82 | * 3 different types of pow() functions: 83 | * - table lookup 84 | * - pow() 85 | * - exp() on some machines this is claimed to be faster than pow() 86 | */ 87 | 88 | #define POW20(x) (assert(0 <= (x+Q_MAX2) && x < Q_MAX), pow20[x+Q_MAX2]) 89 | /*#define POW20(x) pow(2.0,((double)(x)-210)*.25) */ 90 | /*#define POW20(x) exp( ((double)(x)-210)*(.25*LOG2) ) */ 91 | 92 | #define IPOW20(x) (assert(0 <= x && x < Q_MAX), ipow20[x]) 93 | /*#define IPOW20(x) exp( -((double)(x)-210)*.1875*LOG2 ) */ 94 | /*#define IPOW20(x) pow(2.0,-((double)(x)-210)*.1875) */ 95 | 96 | /* in case this is used without configure */ 97 | #ifndef inline 98 | # define inline 99 | #endif 100 | 101 | #if defined(_MSC_VER) 102 | # undef inline 103 | # define inline _inline 104 | #elif defined(__SASC) || defined(__GNUC__) || defined(__ICC) || defined(__ECC) 105 | /* if __GNUC__ we always want to inline, not only if the user requests it */ 106 | # undef inline 107 | # define inline __inline 108 | #endif 109 | 110 | #if defined(_MSC_VER) 111 | # pragma warning( disable : 4244 ) 112 | /*# pragma warning( disable : 4305 ) */ 113 | #endif 114 | 115 | /* 116 | * FLOAT for variables which require at least 32 bits 117 | * FLOAT8 for variables which require at least 64 bits 118 | * 119 | * On some machines, 64 bit will be faster than 32 bit. Also, some math 120 | * routines require 64 bit float, so setting FLOAT=float will result in a 121 | * lot of conversions. 122 | */ 123 | 124 | #if ( defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) ) 125 | # define WIN32_LEAN_AND_MEAN 126 | # include <windows.h> 127 | # include <float.h> 128 | # define FLOAT_MAX FLT_MAX 129 | #else 130 | # ifndef FLOAT 131 | typedef float FLOAT; 132 | # ifdef FLT_MAX 133 | # define FLOAT_MAX FLT_MAX 134 | # else 135 | # define FLOAT_MAX 1e37 /* approx */ 136 | # endif 137 | # endif 138 | #endif 139 | 140 | #ifndef FLOAT8 141 | typedef double FLOAT8; 142 | # ifdef DBL_MAX 143 | # define FLOAT8_MAX DBL_MAX 144 | # else 145 | # define FLOAT8_MAX 1e99 /* approx */ 146 | # endif 147 | #else 148 | # ifdef FLT_MAX 149 | # define FLOAT8_MAX FLT_MAX 150 | # else 151 | # define FLOAT8_MAX 1e37 /* approx */ 152 | # endif 153 | #endif 154 | 155 | /* sample_t must be floating point, at least 32 bits */ 156 | typedef FLOAT sample_t; 157 | 158 | #define dimension_of(array) (sizeof(array)/sizeof(array[0])) 159 | #define beyond(array) (array+dimension_of(array)) 160 | #define compiletime_assert(expression) enum{static_assert_##FILE##_##LINE = 1/((expression)?1:0)} 161 | #define lame_calloc(TYPE, COUNT) ((TYPE*)calloc(COUNT, sizeof(TYPE))) 162 | #define multiple_of(CHUNK, COUNT) (\ 163 | ( (COUNT) < 1 || (CHUNK) < 1 || (COUNT) % (CHUNK) == 0 ) \ 164 | ? (COUNT) \ 165 | : ((COUNT) + (CHUNK) - (COUNT) % (CHUNK)) \ 166 | ) 167 | 168 | #if 1 169 | #define EQ(a,b) (\ 170 | (fabs(a) > fabs(b)) \ 171 | ? (fabs((a)-(b)) <= (fabs(a) * 1e-6f)) \ 172 | : (fabs((a)-(b)) <= (fabs(b) * 1e-6f))) 173 | #else 174 | #define EQ(a,b) (fabs((a)-(b))<1E-37) 175 | #endif 176 | 177 | #define NEQ(a,b) (!EQ(a,b)) 178 | 179 | #ifdef _MSC_VER 180 | # if _MSC_VER < 1400 181 | # define fabsf fabs 182 | # define powf pow 183 | # define log10f log10 184 | # endif 185 | #endif 186 | 187 | #endif 188 | 189 | /* end of machine.h */ 190 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/newmdct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * New Modified DCT include file 3 | * 4 | * Copyright (c) 1999 Takehiro TOMINAGA 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_NEWMDCT_H 23 | #define LAME_NEWMDCT_H 24 | 25 | void mdct_sub48(lame_internal_flags * gfc, const sample_t * w0, const sample_t * w1); 26 | 27 | #endif /* LAME_NEWMDCT_H */ 28 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/psymodel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * psymodel.h 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_PSYMODEL_H 23 | #define LAME_PSYMODEL_H 24 | 25 | 26 | int L3psycho_anal_ns(lame_internal_flags * gfc, 27 | const sample_t *const buffer[2], int gr, 28 | III_psy_ratio ratio[2][2], 29 | III_psy_ratio MS_ratio[2][2], 30 | FLOAT pe[2], FLOAT pe_MS[2], FLOAT ener[2], int blocktype_d[2]); 31 | 32 | int L3psycho_anal_vbr(lame_internal_flags * gfc, 33 | const sample_t *const buffer[2], int gr, 34 | III_psy_ratio ratio[2][2], 35 | III_psy_ratio MS_ratio[2][2], 36 | FLOAT pe[2], FLOAT pe_MS[2], FLOAT ener[2], int blocktype_d[2]); 37 | 38 | 39 | int psymodel_init(lame_global_flags const* gfp); 40 | 41 | 42 | #define rpelev 2 43 | #define rpelev2 16 44 | #define rpelev_s 2 45 | #define rpelev2_s 16 46 | 47 | /* size of each partition band, in barks: */ 48 | #define DELBARK .34 49 | 50 | 51 | /* tuned for output level (sensitive to energy scale) */ 52 | #define VO_SCALE (1./( 14752*14752 )/(BLKSIZE/2)) 53 | 54 | #define temporalmask_sustain_sec 0.01 55 | 56 | #define NS_PREECHO_ATT0 0.8 57 | #define NS_PREECHO_ATT1 0.6 58 | #define NS_PREECHO_ATT2 0.3 59 | 60 | #define NS_MSFIX 3.5 61 | #define NSATTACKTHRE 4.4 62 | #define NSATTACKTHRE_S 25 63 | 64 | #endif /* LAME_PSYMODEL_H */ 65 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/quantize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MP3 quantization 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_QUANTIZE_H 23 | #define LAME_QUANTIZE_H 24 | 25 | void CBR_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2], 26 | const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]); 27 | 28 | void VBR_old_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2], 29 | const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]); 30 | 31 | void VBR_new_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2], 32 | const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]); 33 | 34 | void ABR_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2], 35 | const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]); 36 | 37 | 38 | #endif /* LAME_QUANTIZE_H */ 39 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/quantize_pvt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * quantize_pvt include file 3 | * 4 | * Copyright (c) 1999 Takehiro TOMINAGA 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_QUANTIZE_PVT_H 23 | #define LAME_QUANTIZE_PVT_H 24 | 25 | #define IXMAX_VAL 8206 /* ix always <= 8191+15. see count_bits() */ 26 | 27 | /* buggy Winamp decoder cannot handle values > 8191 */ 28 | /* #define IXMAX_VAL 8191 */ 29 | 30 | #define PRECALC_SIZE (IXMAX_VAL+2) 31 | 32 | 33 | extern const int nr_of_sfb_block[6][3][4]; 34 | extern const int pretab[SBMAX_l]; 35 | extern const int slen1_tab[16]; 36 | extern const int slen2_tab[16]; 37 | 38 | extern const scalefac_struct sfBandIndex[9]; 39 | 40 | extern FLOAT pow43[PRECALC_SIZE]; 41 | #ifdef TAKEHIRO_IEEE754_HACK 42 | extern FLOAT adj43asm[PRECALC_SIZE]; 43 | #else 44 | extern FLOAT adj43[PRECALC_SIZE]; 45 | #endif 46 | 47 | #define Q_MAX (256+1) 48 | #define Q_MAX2 116 /* minimum possible number of 49 | -cod_info->global_gain 50 | + ((scalefac[] + (cod_info->preflag ? pretab[sfb] : 0)) 51 | << (cod_info->scalefac_scale + 1)) 52 | + cod_info->subblock_gain[cod_info->window[sfb]] * 8; 53 | 54 | for long block, 0+((15+3)<<2) = 18*4 = 72 55 | for short block, 0+(15<<2)+7*8 = 15*4+56 = 116 56 | */ 57 | 58 | extern FLOAT pow20[Q_MAX + Q_MAX2 + 1]; 59 | extern FLOAT ipow20[Q_MAX]; 60 | 61 | typedef struct calc_noise_result_t { 62 | FLOAT over_noise; /* sum of quantization noise > masking */ 63 | FLOAT tot_noise; /* sum of all quantization noise */ 64 | FLOAT max_noise; /* max quantization noise */ 65 | int over_count; /* number of quantization noise > masking */ 66 | int over_SSD; /* SSD-like cost of distorted bands */ 67 | int bits; 68 | } calc_noise_result; 69 | 70 | 71 | /** 72 | * allows re-use of previously 73 | * computed noise values 74 | */ 75 | typedef struct calc_noise_data_t { 76 | int global_gain; 77 | int sfb_count1; 78 | int step[39]; 79 | FLOAT noise[39]; 80 | FLOAT noise_log[39]; 81 | } calc_noise_data; 82 | 83 | 84 | int on_pe(lame_internal_flags * gfc, const FLOAT pe[2][2], 85 | int targ_bits[2], int mean_bits, int gr, int cbr); 86 | 87 | void reduce_side(int targ_bits[2], FLOAT ms_ener_ratio, int mean_bits, int max_bits); 88 | 89 | 90 | void iteration_init(lame_internal_flags * gfc); 91 | 92 | 93 | int calc_xmin(lame_internal_flags const *gfc, 94 | III_psy_ratio const *const ratio, gr_info * const cod_info, FLOAT * l3_xmin); 95 | 96 | int calc_noise(const gr_info * const cod_info, 97 | const FLOAT * l3_xmin, 98 | FLOAT * distort, calc_noise_result * const res, calc_noise_data * prev_noise); 99 | 100 | void set_frame_pinfo(lame_internal_flags * gfc, const III_psy_ratio ratio[2][2]); 101 | 102 | 103 | 104 | 105 | /* takehiro.c */ 106 | 107 | int count_bits(lame_internal_flags const *const gfc, const FLOAT * const xr, 108 | gr_info * const cod_info, calc_noise_data * prev_noise); 109 | int noquant_count_bits(lame_internal_flags const *const gfc, 110 | gr_info * const cod_info, calc_noise_data * prev_noise); 111 | 112 | 113 | void best_huffman_divide(const lame_internal_flags * const gfc, gr_info * const cod_info); 114 | 115 | void best_scalefac_store(const lame_internal_flags * gfc, const int gr, const int ch, 116 | III_side_info_t * const l3_side); 117 | 118 | int scale_bitcount(const lame_internal_flags * gfc, gr_info * cod_info); 119 | 120 | void huffman_init(lame_internal_flags * const gfc); 121 | 122 | void init_xrpow_core_init(lame_internal_flags * const gfc); 123 | 124 | FLOAT athAdjust(FLOAT a, FLOAT x, FLOAT athFloor, float ATHfixpoint); 125 | 126 | #define LARGE_BITS 100000 127 | 128 | #endif /* LAME_QUANTIZE_PVT_H */ 129 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/reservoir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * bit reservoir include file 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_RESERVOIR_H 23 | #define LAME_RESERVOIR_H 24 | 25 | int ResvFrameBegin(lame_internal_flags * gfc, int *mean_bits); 26 | void ResvMaxBits(lame_internal_flags * gfc, int mean_bits, int *targ_bits, int *max_bits, 27 | int cbr); 28 | void ResvAdjust(lame_internal_flags * gfc, gr_info const *gi); 29 | void ResvFrameEnd(lame_internal_flags * gfc, int mean_bits); 30 | 31 | #endif /* LAME_RESERVOIR_H */ 32 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/set_get.h: -------------------------------------------------------------------------------- 1 | /* 2 | * set_get.h -- Internal set/get definitions 3 | * 4 | * Copyright (C) 2003 Gabriel Bouvigne / Lame project 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef __SET_GET_H__ 22 | #define __SET_GET_H__ 23 | 24 | #include "lame.h" 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | /* select psychoacoustic model */ 31 | 32 | /* manage short blocks */ 33 | int CDECL lame_set_short_threshold(lame_global_flags *, float, float); 34 | int CDECL lame_set_short_threshold_lrm(lame_global_flags *, float); 35 | float CDECL lame_get_short_threshold_lrm(const lame_global_flags *); 36 | int CDECL lame_set_short_threshold_s(lame_global_flags *, float); 37 | float CDECL lame_get_short_threshold_s(const lame_global_flags *); 38 | 39 | 40 | int CDECL lame_set_maskingadjust(lame_global_flags *, float); 41 | float CDECL lame_get_maskingadjust(const lame_global_flags *); 42 | 43 | int CDECL lame_set_maskingadjust_short(lame_global_flags *, float); 44 | float CDECL lame_get_maskingadjust_short(const lame_global_flags *); 45 | 46 | /* select ATH formula 4 shape */ 47 | int CDECL lame_set_ATHcurve(lame_global_flags *, float); 48 | float CDECL lame_get_ATHcurve(const lame_global_flags *); 49 | 50 | int CDECL lame_set_preset_notune(lame_global_flags *, int); 51 | 52 | /* substep shaping method */ 53 | int CDECL lame_set_substep(lame_global_flags *, int); 54 | int CDECL lame_get_substep(const lame_global_flags *); 55 | 56 | /* scalefactors scale */ 57 | int CDECL lame_set_sfscale(lame_global_flags *, int); 58 | int CDECL lame_get_sfscale(const lame_global_flags *); 59 | 60 | /* subblock gain */ 61 | int CDECL lame_set_subblock_gain(lame_global_flags *, int); 62 | int CDECL lame_get_subblock_gain(const lame_global_flags *); 63 | 64 | 65 | 66 | /*presets*/ 67 | int apply_preset(lame_global_flags *, int preset, int enforce); 68 | 69 | void CDECL lame_set_tune(lame_t, float); /* FOR INTERNAL USE ONLY */ 70 | void CDECL lame_set_msfix(lame_t gfp, double msfix); 71 | 72 | 73 | #if defined(__cplusplus) 74 | } 75 | #endif 76 | #endif 77 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/tables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MPEG layer 3 tables include file 3 | * 4 | * Copyright (c) 1999 Albert L Faber 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_TABLES_H 23 | #define LAME_TABLES_H 24 | 25 | #if 0 26 | typedef struct { 27 | unsigned char no; 28 | unsigned char width; 29 | unsigned char minval_2; 30 | float quiet_thr; 31 | float norm; 32 | float bark; 33 | } type1_t; 34 | 35 | typedef struct { 36 | unsigned char no; 37 | unsigned char width; 38 | float quiet_thr; 39 | float norm; 40 | float SNR; 41 | float bark; 42 | } type2_t; 43 | 44 | typedef struct { 45 | unsigned int no:5; 46 | unsigned int cbw:3; 47 | unsigned int bu:6; 48 | unsigned int bo:6; 49 | unsigned int w1_576:10; 50 | unsigned int w2_576:10; 51 | } type34_t; 52 | 53 | typedef struct { 54 | size_t len1; 55 | const type1_t *const tab1; 56 | size_t len2; 57 | const type2_t *const tab2; 58 | size_t len3; 59 | const type34_t *const tab3; 60 | size_t len4; 61 | const type34_t *const tab4; 62 | } type5_t; 63 | 64 | extern const type5_t table5[6]; 65 | 66 | #endif 67 | 68 | #define HTN 34 69 | 70 | struct huffcodetab { 71 | const unsigned int xlen; /* max. x-index+ */ 72 | const unsigned int linmax; /* max number to be stored in linbits */ 73 | const uint16_t *table; /* pointer to array[xlen][ylen] */ 74 | const uint8_t *hlen; /* pointer to array[xlen][ylen] */ 75 | }; 76 | 77 | extern const struct huffcodetab ht[HTN]; 78 | /* global memory block */ 79 | /* array of all huffcodtable headers */ 80 | /* 0..31 Huffman code table 0..31 */ 81 | /* 32,33 count1-tables */ 82 | 83 | extern const uint8_t t32l[]; 84 | extern const uint8_t t33l[]; 85 | 86 | extern const uint32_t largetbl[16 * 16]; 87 | extern const uint32_t table23[3 * 3]; 88 | extern const uint32_t table56[4 * 4]; 89 | 90 | extern const int scfsi_band[5]; 91 | 92 | extern const int bitrate_table [3][16]; 93 | extern const int samplerate_table [3][ 4]; 94 | 95 | #endif /* LAME_TABLES_H */ 96 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/vbrquantize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MP3 VBR quantization 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_VBRQUANTIZE_H 23 | #define LAME_VBRQUANTIZE_H 24 | 25 | int VBR_encode_frame(lame_internal_flags * gfc, const FLOAT xr34orig[2][2][576], 26 | const FLOAT l3_xmin[2][2][SFBMAX], const int maxbits[2][2]); 27 | 28 | #endif /* LAME_VBRQUANTIZE_H */ 29 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/vector/lame_intrin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lame_intrin.h include file 3 | * 4 | * Copyright (c) 2006 Gabriel Bouvigne 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | 23 | #ifndef LAME_INTRIN_H 24 | #define LAME_INTRIN_H 25 | 26 | 27 | void 28 | init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum); 29 | 30 | void 31 | fht_SSE2(FLOAT* , int); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version numbering for LAME. 3 | * 4 | * Copyright (c) 1999 A.L. Faber 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | /*! 23 | \file version.c 24 | \brief Version numbering for LAME. 25 | 26 | Contains functions which describe the version of LAME. 27 | 28 | \author A.L. Faber 29 | \version \$Id: version.c,v 1.34 2011/11/18 09:51:02 robert Exp $ 30 | \ingroup libmp3lame 31 | */ 32 | 33 | 34 | #ifdef HAVE_CONFIG_H 35 | # include <config.h> 36 | #endif 37 | 38 | 39 | #include "lame.h" 40 | #include "machine.h" 41 | 42 | #include "version.h" /* macros of version numbers */ 43 | 44 | 45 | 46 | 47 | 48 | /*! Get the LAME version string. */ 49 | /*! 50 | \param void 51 | \return a pointer to a string which describes the version of LAME. 52 | */ 53 | const char * 54 | get_lame_version(void) 55 | { /* primary to write screen reports */ 56 | /* Here we can also add informations about compile time configurations */ 57 | 58 | #if LAME_ALPHA_VERSION 59 | static /*@observer@ */ const char *const str = 60 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " " 61 | "(alpha " STR(LAME_PATCH_VERSION) ", " __DATE__ " " __TIME__ ")"; 62 | #elif LAME_BETA_VERSION 63 | static /*@observer@ */ const char *const str = 64 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " " 65 | "(beta " STR(LAME_PATCH_VERSION) ", " __DATE__ ")"; 66 | #elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0) 67 | static /*@observer@ */ const char *const str = 68 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) "." STR(LAME_PATCH_VERSION); 69 | #else 70 | static /*@observer@ */ const char *const str = 71 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION); 72 | #endif 73 | 74 | return str; 75 | } 76 | 77 | 78 | /*! Get the short LAME version string. */ 79 | /*! 80 | It's mainly for inclusion into the MP3 stream. 81 | 82 | \param void 83 | \return a pointer to the short version of the LAME version string. 84 | */ 85 | const char * 86 | get_lame_short_version(void) 87 | { 88 | /* adding date and time to version string makes it harder for output 89 | validation */ 90 | 91 | #if LAME_ALPHA_VERSION 92 | static /*@observer@ */ const char *const str = 93 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " (alpha " STR(LAME_PATCH_VERSION) ")"; 94 | #elif LAME_BETA_VERSION 95 | static /*@observer@ */ const char *const str = 96 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " (beta " STR(LAME_PATCH_VERSION) ")"; 97 | #elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0) 98 | static /*@observer@ */ const char *const str = 99 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) "." STR(LAME_PATCH_VERSION); 100 | #else 101 | static /*@observer@ */ const char *const str = 102 | STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION); 103 | #endif 104 | 105 | return str; 106 | } 107 | 108 | /*! Get the _very_ short LAME version string. */ 109 | /*! 110 | It's used in the LAME VBR tag only. 111 | 112 | \param void 113 | \return a pointer to the short version of the LAME version string. 114 | */ 115 | const char * 116 | get_lame_very_short_version(void) 117 | { 118 | /* adding date and time to version string makes it harder for output 119 | validation */ 120 | #if LAME_ALPHA_VERSION 121 | #define P "a" 122 | #elif LAME_BETA_VERSION 123 | #define P "b" 124 | #elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0) 125 | #define P "r" 126 | #else 127 | #define P " " 128 | #endif 129 | static /*@observer@ */ const char *const str = 130 | #if (LAME_PATCH_VERSION > 0) 131 | "LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P STR(LAME_PATCH_VERSION) 132 | #else 133 | "LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P 134 | #endif 135 | ; 136 | return str; 137 | } 138 | 139 | /*! Get the _very_ short LAME version string. */ 140 | /*! 141 | It's used in the LAME VBR tag only, limited to 9 characters max. 142 | Due to some 3rd party HW/SW decoders, it has to start with LAME. 143 | 144 | \param void 145 | \return a pointer to the short version of the LAME version string. 146 | */ 147 | const char* 148 | get_lame_tag_encoder_short_version(void) 149 | { 150 | static /*@observer@ */ const char *const str = 151 | /* FIXME: new scheme / new version counting / drop versioning here ? */ 152 | "LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P 153 | ; 154 | return str; 155 | } 156 | 157 | /*! Get the version string for GPSYCHO. */ 158 | /*! 159 | \param void 160 | \return a pointer to a string which describes the version of GPSYCHO. 161 | */ 162 | const char * 163 | get_psy_version(void) 164 | { 165 | #if PSY_ALPHA_VERSION > 0 166 | static /*@observer@ */ const char *const str = 167 | STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION) 168 | " (alpha " STR(PSY_ALPHA_VERSION) ", " __DATE__ " " __TIME__ ")"; 169 | #elif PSY_BETA_VERSION > 0 170 | static /*@observer@ */ const char *const str = 171 | STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION) 172 | " (beta " STR(PSY_BETA_VERSION) ", " __DATE__ ")"; 173 | #else 174 | static /*@observer@ */ const char *const str = 175 | STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION); 176 | #endif 177 | 178 | return str; 179 | } 180 | 181 | 182 | /*! Get the URL for the LAME website. */ 183 | /*! 184 | \param void 185 | \return a pointer to a string which is a URL for the LAME website. 186 | */ 187 | const char * 188 | get_lame_url(void) 189 | { 190 | static /*@observer@ */ const char *const str = LAME_URL; 191 | 192 | return str; 193 | } 194 | 195 | 196 | /*! Get the numerical representation of the version. */ 197 | /*! 198 | Writes the numerical representation of the version of LAME and 199 | GPSYCHO into lvp. 200 | 201 | \param lvp 202 | */ 203 | void 204 | get_lame_version_numerical(lame_version_t * lvp) 205 | { 206 | static /*@observer@ */ const char *const features = ""; /* obsolete */ 207 | 208 | /* generic version */ 209 | lvp->major = LAME_MAJOR_VERSION; 210 | lvp->minor = LAME_MINOR_VERSION; 211 | #if LAME_ALPHA_VERSION 212 | lvp->alpha = LAME_PATCH_VERSION; 213 | lvp->beta = 0; 214 | #elif LAME_BETA_VERSION 215 | lvp->alpha = 0; 216 | lvp->beta = LAME_PATCH_VERSION; 217 | #else 218 | lvp->alpha = 0; 219 | lvp->beta = 0; 220 | #endif 221 | 222 | /* psy version */ 223 | lvp->psy_major = PSY_MAJOR_VERSION; 224 | lvp->psy_minor = PSY_MINOR_VERSION; 225 | lvp->psy_alpha = PSY_ALPHA_VERSION; 226 | lvp->psy_beta = PSY_BETA_VERSION; 227 | 228 | /* compile time features */ 229 | /*@-mustfree@ */ 230 | lvp->features = features; 231 | /*@=mustfree@ */ 232 | } 233 | 234 | 235 | const char * 236 | get_lame_os_bitness(void) 237 | { 238 | static /*@observer@ */ const char *const strXX = ""; 239 | static /*@observer@ */ const char *const str32 = "32bits"; 240 | static /*@observer@ */ const char *const str64 = "64bits"; 241 | 242 | switch (sizeof(void *)) { 243 | case 4: 244 | return str32; 245 | 246 | case 8: 247 | return str64; 248 | 249 | default: 250 | return strXX; 251 | } 252 | } 253 | 254 | /* end of version.c */ 255 | -------------------------------------------------------------------------------- /mp3lame/src/main/cpp/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Version numbering for LAME. 3 | * 4 | * Copyright (c) 1999 A.L. Faber 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef LAME_VERSION_H 23 | #define LAME_VERSION_H 24 | 25 | 26 | /* 27 | * To make a string from a token, use the # operator: 28 | */ 29 | #ifndef STR 30 | # define __STR(x) #x 31 | # define STR(x) __STR(x) 32 | #endif 33 | 34 | # define LAME_URL "http://lame.sf.net" 35 | 36 | 37 | # define LAME_MAJOR_VERSION 3 /* Major version number */ 38 | # define LAME_MINOR_VERSION 100 /* Minor version number */ 39 | # define LAME_TYPE_VERSION 2 /* 0:alpha 1:beta 2:release */ 40 | # define LAME_PATCH_VERSION 0 /* Patch level */ 41 | # define LAME_ALPHA_VERSION (LAME_TYPE_VERSION==0) 42 | # define LAME_BETA_VERSION (LAME_TYPE_VERSION==1) 43 | # define LAME_RELEASE_VERSION (LAME_TYPE_VERSION==2) 44 | 45 | # define PSY_MAJOR_VERSION 1 /* Major version number */ 46 | # define PSY_MINOR_VERSION 0 /* Minor version number */ 47 | # define PSY_ALPHA_VERSION 0 /* Set number if this is an alpha version, otherwise zero */ 48 | # define PSY_BETA_VERSION 0 /* Set number if this is a beta version, otherwise zero */ 49 | 50 | #if LAME_ALPHA_VERSION 51 | #define LAME_PATCH_LEVEL_STRING " alpha " STR(LAME_PATCH_VERSION) 52 | #endif 53 | #if LAME_BETA_VERSION 54 | #define LAME_PATCH_LEVEL_STRING " beta " STR(LAME_PATCH_VERSION) 55 | #endif 56 | #if LAME_RELEASE_VERSION 57 | #if LAME_PATCH_VERSION 58 | #define LAME_PATCH_LEVEL_STRING " release " STR(LAME_PATCH_VERSION) 59 | #else 60 | #define LAME_PATCH_LEVEL_STRING "" 61 | #endif 62 | #endif 63 | 64 | # define LAME_VERSION_STRING STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) LAME_PATCH_LEVEL_STRING 65 | 66 | #endif /* LAME_VERSION_H */ 67 | 68 | /* End of version.h */ 69 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion versions.compileSdk 5 | 6 | defaultConfig { 7 | applicationId "io.auxo.ame.sample" 8 | minSdkVersion versions.minSdk 9 | targetSdkVersion versions.compileSdk 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | signingConfig signingConfigs.debug 15 | } 16 | 17 | buildTypes { 18 | debug { 19 | debuggable true 20 | } 21 | release { 22 | debuggable true 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | 28 | sourceSets { 29 | main { 30 | jniLibs.srcDirs = [ 31 | '../dist/mp3lame/lib', 32 | "../dist/ame/lib", 33 | "../dist/ame-lite/lib" 34 | ] 35 | } 36 | } 37 | } 38 | 39 | dependencies { 40 | 41 | implementation fileTree(include: ['*.jar'], dir: 'libs') 42 | 43 | testImplementation deps.junit 44 | androidTestImplementation deps.test.runner 45 | androidTestImplementation deps.test.espresso 46 | 47 | api deps.support.appcompat 48 | 49 | implementation 'pub.devrel:easypermissions:1.2.0' 50 | implementation 'com.github.warkiz.widget:indicatorseekbar:1.2.9' 51 | 52 | implementation project(':ame') 53 | implementation project(':ame-lite') 54 | } -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/io/auxo/ame/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.sample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("io.auxo.ame.sample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 | package="io.auxo.ame.sample"> 4 | 5 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 6 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 7 | 8 | <application 9 | android:allowBackup="true" 10 | android:icon="@mipmap/ic_launcher" 11 | android:label="@string/app_name" 12 | android:roundIcon="@mipmap/ic_launcher_round" 13 | android:supportsRtl="true" 14 | android:theme="@style/AppTheme"> 15 | <activity android:name=".MainActivity"> 16 | <intent-filter> 17 | <action android:name="android.intent.action.MAIN" /> 18 | 19 | <category android:name="android.intent.category.LAUNCHER" /> 20 | </intent-filter> 21 | </activity> 22 | <activity android:name=".AmeLiteActivity" /> 23 | <activity android:name=".AmeActivity"></activity> 24 | </application> 25 | 26 | </manifest> -------------------------------------------------------------------------------- /sample/src/main/java/io/auxo/ame/sample/AmeActivity.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.sample; 2 | 3 | import android.os.Bundle; 4 | import android.os.Environment; 5 | import android.support.v7.app.ActionBar; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.util.Log; 8 | 9 | import io.auxo.ame.Mp3Encoder; 10 | 11 | public class AmeActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_ame); 17 | 18 | ActionBar actionBar = getSupportActionBar(); 19 | actionBar.setTitle("Ame"); 20 | actionBar.setSubtitle("LAME:" + new Mp3Encoder().getLameVersion()); 21 | 22 | new Thread(new Runnable() { 23 | @Override 24 | public void run() { 25 | Mp3Encoder.Callback callback = new Mp3Encoder.Callback() { 26 | @Override 27 | public void onStart() { 28 | Log.i("AmeLiteActivity", "onStart"); 29 | } 30 | 31 | @Override 32 | public void onProgress(int total, int current) { 33 | Log.i("AmeLiteActivity", "onProgress: total->" + total + " current->" + current); 34 | } 35 | 36 | @Override 37 | public void onComplete() { 38 | Log.i("AmeLiteActivity", "onComplete"); 39 | } 40 | 41 | @Override 42 | public void onError() { 43 | Log.i("AmeLiteActivity", "onError"); 44 | } 45 | }; 46 | Mp3Encoder.encode(Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.wav", 47 | Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.mp3", callback); 48 | } 49 | }).start(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sample/src/main/java/io/auxo/ame/sample/AmeLiteActivity.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.sample; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.os.Message; 7 | import android.support.v7.app.ActionBar; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.util.Log; 10 | import android.view.View; 11 | import android.widget.Button; 12 | import android.widget.CheckBox; 13 | import android.widget.LinearLayout; 14 | import android.widget.ProgressBar; 15 | import android.widget.RadioGroup; 16 | import android.widget.Toast; 17 | 18 | import com.warkiz.widget.IndicatorSeekBar; 19 | 20 | import java.io.File; 21 | 22 | import io.auxo.ame.lite.Mp3Encoder; 23 | 24 | public class AmeLiteActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, 25 | View.OnClickListener { 26 | 27 | private final String TAG = "AmeLiteActivity"; 28 | 29 | private LinearLayout mBitrateGroup; 30 | private LinearLayout mQualityGroup; 31 | 32 | private RadioGroup mTarget; 33 | private RadioGroup mEngineQuality; 34 | private RadioGroup mVbrMode; 35 | 36 | private CheckBox mMonoEncoding; 37 | private CheckBox mForceCbr; 38 | 39 | private IndicatorSeekBar mBitrate; 40 | private IndicatorSeekBar mVbrQuality; 41 | 42 | private Button mEncode; 43 | 44 | private ProgressBar mProgressBar; 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(R.layout.activity_ame_lite); 50 | 51 | ActionBar actionBar = getSupportActionBar(); 52 | actionBar.setTitle("Ame-Lite"); 53 | actionBar.setSubtitle("LAME:" + Mp3Encoder.getLameVersion()); 54 | 55 | mBitrateGroup = findViewById(R.id.ame_lite_bitrate_group); 56 | mQualityGroup = findViewById(R.id.ame_lite_vbr_quality_group); 57 | 58 | mTarget = findViewById(R.id.ame_lite_target); 59 | mEngineQuality = findViewById(R.id.ame_lite_engine_quality); 60 | mVbrMode = findViewById(R.id.ame_lite_vbr_mode); 61 | 62 | mMonoEncoding = findViewById(R.id.ame_lite_mono); 63 | mForceCbr = findViewById(R.id.ame_lite_force_cbr); 64 | 65 | mBitrate = findViewById(R.id.ame_lite_bitrate); 66 | mVbrQuality = findViewById(R.id.ame_lite_vbr_quality); 67 | 68 | mEncode = findViewById(R.id.ame_lite_encode); 69 | 70 | mProgressBar = findViewById(R.id.ame_lite_encode_progress_bar); 71 | 72 | mTarget.setOnCheckedChangeListener(this); 73 | mEngineQuality.setOnCheckedChangeListener(this); 74 | mVbrMode.setOnCheckedChangeListener(this); 75 | 76 | mEncode.setOnClickListener(this); 77 | 78 | mProgressBar.setVisibility(View.GONE); 79 | } 80 | 81 | @Override 82 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 83 | super.onActivityResult(requestCode, resultCode, data); 84 | String file = FileChooser.onActivityResult(this, requestCode, resultCode, data); 85 | if (file != null) { 86 | decodeFile(file); 87 | } 88 | } 89 | 90 | @Override 91 | public void onCheckedChanged(RadioGroup group, int checkedId) { 92 | switch (checkedId) { 93 | case R.id.ame_lite_target_bitrate: 94 | mBitrateGroup.setVisibility(View.VISIBLE); 95 | mQualityGroup.setVisibility(View.GONE); 96 | break; 97 | case R.id.ame_lite_target_quality: 98 | mBitrateGroup.setVisibility(View.GONE); 99 | mQualityGroup.setVisibility(View.VISIBLE); 100 | break; 101 | } 102 | } 103 | 104 | @Override 105 | public void onClick(View v) { 106 | switch (v.getId()) { 107 | case R.id.ame_lite_encode: 108 | FileChooser.choose(this, FileChooser.TYPE_AUDIO); 109 | break; 110 | default: 111 | break; 112 | } 113 | } 114 | 115 | protected void decodeFile(final String file) { 116 | File fin = new File(file); 117 | if (fin.exists() && !fin.isDirectory()) { 118 | final String out = file.substring(0, file.lastIndexOf(".")) + ".mp3"; 119 | new EncodeThread(file, out).start(); 120 | } 121 | } 122 | 123 | protected Mp3Encoder.Options getOptions() { 124 | Mp3Encoder.Options options = new Mp3Encoder.Options(); 125 | switch (mEngineQuality.getCheckedRadioButtonId()) { 126 | case R.id.ame_lite_engine_quality_fast: 127 | options.quality(9); 128 | break; 129 | case R.id.ame_lite_engine_quality_standard: 130 | options.quality(5); 131 | break; 132 | case R.id.ame_lite_engine_quality_high: 133 | options.quality(0); 134 | break; 135 | default: 136 | break; 137 | } 138 | if (mMonoEncoding.isChecked()) { 139 | options.mode(Mp3Encoder.Options.MONO); 140 | options.numChannels(1); 141 | } 142 | if (mTarget.getCheckedRadioButtonId() == R.id.ame_lite_target_bitrate) { 143 | options.bitrate(mBitrate.getProgress()); 144 | if (mForceCbr.isChecked()) { 145 | options.vbrMode(Mp3Encoder.Options.VBR_OFF); 146 | } 147 | } else { 148 | options.vbrQuality(mVbrQuality.getProgress()); 149 | if (mVbrMode.getCheckedRadioButtonId() == R.id.ame_lite_vbr_standard) { 150 | options.vbrQuality(0); 151 | } else if (mVbrMode.getCheckedRadioButtonId() == R.id.ame_lite_vbr_fast) { 152 | options.vbrQuality(9); 153 | } 154 | } 155 | return options; 156 | } 157 | 158 | protected final int MESSAGE_START = 0; 159 | protected final int MESSAGE_PROGRESS = 1; 160 | protected final int MESSAGE_COMPLETE = 2; 161 | protected final int MESSAGE_ERROR = 3; 162 | 163 | protected Handler mEncodeHandler = new Handler() { 164 | @Override 165 | public void handleMessage(Message msg) { 166 | super.handleMessage(msg); 167 | switch (msg.what) { 168 | case MESSAGE_START: 169 | mProgressBar.setVisibility(View.VISIBLE); 170 | mProgressBar.setProgress(0); 171 | mEncode.setEnabled(false); 172 | break; 173 | case MESSAGE_PROGRESS: 174 | mProgressBar.setMax(msg.arg1); 175 | mProgressBar.setProgress(msg.arg2); 176 | mEncode.setText(msg.arg2 / 1000000f + "M/" + msg.arg1 / 1000000f + "M"); 177 | break; 178 | case MESSAGE_COMPLETE: 179 | Toast.makeText(getApplicationContext(), "转码完成", Toast.LENGTH_LONG).show(); 180 | case MESSAGE_ERROR: 181 | mProgressBar.setVisibility(View.GONE); 182 | mEncode.setEnabled(true); 183 | mEncode.setText("encode file"); 184 | break; 185 | default: 186 | break; 187 | } 188 | } 189 | }; 190 | 191 | protected class EncodeThread extends Thread implements Mp3Encoder.Callback { 192 | 193 | private String input; 194 | private String output; 195 | 196 | public EncodeThread(String input, String output) { 197 | this.input = input; 198 | this.output = output; 199 | } 200 | 201 | @Override 202 | public void run() { 203 | super.run(); 204 | Mp3Encoder.encode(input, output, getOptions(), this); 205 | } 206 | 207 | @Override 208 | public void onStart() { 209 | Log.i(TAG, "onStart"); 210 | mEncodeHandler.sendEmptyMessage(MESSAGE_START); 211 | } 212 | 213 | @Override 214 | public void onProgress(final int total, final int current) { 215 | Log.i(TAG, "onProgress total -> " + total + " current -> " + current); 216 | Message msg = mEncodeHandler.obtainMessage(MESSAGE_PROGRESS); 217 | msg.arg1 = total; 218 | msg.arg2 = current; 219 | mEncodeHandler.sendMessage(msg); 220 | } 221 | 222 | @Override 223 | public void onComplete() { 224 | Log.i(TAG, "onComplete"); 225 | mEncodeHandler.sendEmptyMessage(MESSAGE_COMPLETE); 226 | } 227 | 228 | @Override 229 | public void onError() { 230 | Log.e(TAG, "onError"); 231 | mEncodeHandler.sendEmptyMessage(MESSAGE_ERROR); 232 | } 233 | } 234 | 235 | } 236 | -------------------------------------------------------------------------------- /sample/src/main/java/io/auxo/ame/sample/FileChooser.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.sample; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.ContentUris; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.database.Cursor; 9 | import android.net.Uri; 10 | import android.os.Build; 11 | import android.os.Environment; 12 | import android.provider.DocumentsContract; 13 | import android.provider.MediaStore; 14 | 15 | public class FileChooser { 16 | 17 | protected static int REQUEST_CODE = 1; 18 | 19 | /** 20 | * 选择图片 21 | */ 22 | public static final String TYPE_IMAGE = "image/*"; 23 | /** 24 | * 选择音频 25 | */ 26 | public static final String TYPE_AUDIO = "audio/*"; 27 | /** 28 | * 选择视频 (mp4 3gp 是android支持的视频格式) 29 | */ 30 | public static final String TYPE_VIDEO = "video/*"; 31 | //intent.setType(“video/*;image/*”);//同时选择视频和图片 32 | /** 33 | * 无类型限制 34 | */ 35 | public static final String TYPE_ALL = "*/*"; 36 | 37 | public static void choose(Activity activity, String type) { 38 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 39 | intent.setType(type); 40 | intent.addCategory(Intent.CATEGORY_OPENABLE); 41 | activity.startActivityForResult(intent, REQUEST_CODE); 42 | } 43 | 44 | public static String onActivityResult(Context context, int requestCode, int resultCode, Intent data) { 45 | if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) { 46 | String path; 47 | Uri uri = data.getData(); 48 | if ("file".equalsIgnoreCase(uri.getScheme())) { 49 | //使用第三方应用打开 50 | path = uri.getPath(); 51 | return path; 52 | } 53 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { 54 | //4.4以后 55 | path = getPath(context, uri); 56 | } else {//4.4以下下系统调用方法 57 | path = getRealPathFromURI(context, uri); 58 | } 59 | return path; 60 | } 61 | return null; 62 | } 63 | 64 | protected static String getRealPathFromURI(Context context, Uri contentUri) { 65 | String res = null; 66 | String[] proj = {MediaStore.Images.Media.DATA}; 67 | Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); 68 | if (null != cursor && cursor.moveToFirst()) { 69 | ; 70 | int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 71 | res = cursor.getString(column_index); 72 | cursor.close(); 73 | } 74 | return res; 75 | } 76 | 77 | @SuppressLint("NewApi") 78 | protected static String getPath(Context context, final Uri uri) { 79 | 80 | final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 81 | 82 | // DocumentProvider 83 | if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { 84 | // ExternalStorageProvider 85 | if (isExternalStorageDocument(uri)) { 86 | final String docId = DocumentsContract.getDocumentId(uri); 87 | final String[] split = docId.split(":"); 88 | final String type = split[0]; 89 | 90 | if ("primary".equalsIgnoreCase(type)) { 91 | return Environment.getExternalStorageDirectory() + "/" + split[1]; 92 | } 93 | } 94 | // DownloadsProvider 95 | else if (isDownloadsDocument(uri)) { 96 | 97 | final String id = DocumentsContract.getDocumentId(uri); 98 | final Uri contentUri = ContentUris.withAppendedId( 99 | Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); 100 | 101 | return getDataColumn(context, contentUri, null, null); 102 | } 103 | // MediaProvider 104 | else if (isMediaDocument(uri)) { 105 | final String docId = DocumentsContract.getDocumentId(uri); 106 | final String[] split = docId.split(":"); 107 | final String type = split[0]; 108 | 109 | Uri contentUri = null; 110 | if ("image".equals(type)) { 111 | contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 112 | } else if ("video".equals(type)) { 113 | contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 114 | } else if ("audio".equals(type)) { 115 | contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 116 | } 117 | 118 | final String selection = "_id=?"; 119 | final String[] selectionArgs = new String[]{split[1]}; 120 | 121 | return getDataColumn(context, contentUri, selection, selectionArgs); 122 | } 123 | } 124 | // MediaStore (and general) 125 | else if ("content".equalsIgnoreCase(uri.getScheme())) { 126 | return getDataColumn(context, uri, null, null); 127 | } 128 | // File 129 | else if ("file".equalsIgnoreCase(uri.getScheme())) { 130 | return uri.getPath(); 131 | } 132 | return null; 133 | } 134 | 135 | protected static String getDataColumn(Context context, Uri uri, String selection, 136 | String[] selectionArgs) { 137 | 138 | Cursor cursor = null; 139 | final String column = "_data"; 140 | final String[] projection = {column}; 141 | 142 | try { 143 | cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, 144 | null); 145 | if (cursor != null && cursor.moveToFirst()) { 146 | final int column_index = cursor.getColumnIndexOrThrow(column); 147 | return cursor.getString(column_index); 148 | } 149 | } finally { 150 | if (cursor != null) { 151 | cursor.close(); 152 | } 153 | } 154 | return null; 155 | } 156 | 157 | protected static boolean isExternalStorageDocument(Uri uri) { 158 | return "com.android.externalstorage.documents".equals(uri.getAuthority()); 159 | } 160 | 161 | protected static boolean isDownloadsDocument(Uri uri) { 162 | return "com.android.providers.downloads.documents".equals(uri.getAuthority()); 163 | } 164 | 165 | protected static boolean isMediaDocument(Uri uri) { 166 | return "com.android.providers.media.documents".equals(uri.getAuthority()); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /sample/src/main/java/io/auxo/ame/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.sample; 2 | 3 | import android.Manifest; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | import android.widget.Button; 9 | 10 | import pub.devrel.easypermissions.AfterPermissionGranted; 11 | import pub.devrel.easypermissions.EasyPermissions; 12 | 13 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 14 | 15 | protected final int REQUEST_PERMISSIONS = 1; 16 | 17 | private Button mAmeLite; 18 | private Button mAme; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | 25 | mAmeLite = findViewById(R.id.main_ame_lite); 26 | mAme = findViewById(R.id.main_ame); 27 | 28 | mAmeLite.setOnClickListener(this); 29 | mAme.setOnClickListener(this); 30 | 31 | requestPermissions(); 32 | } 33 | 34 | @AfterPermissionGranted(REQUEST_PERMISSIONS) 35 | protected void requestPermissions() { 36 | String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}; 37 | if (EasyPermissions.hasPermissions(this, perms)) { 38 | mAme.setEnabled(true); 39 | mAmeLite.setEnabled(true); 40 | } else { 41 | EasyPermissions.requestPermissions(this, "Mp3 Encoder需要读写权限", 42 | REQUEST_PERMISSIONS, perms); 43 | mAme.setEnabled(false); 44 | mAmeLite.setEnabled(false); 45 | } 46 | } 47 | 48 | @Override 49 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 50 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 51 | EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); 52 | } 53 | 54 | @Override 55 | public void onClick(View v) { 56 | switch (v.getId()) { 57 | case R.id.main_ame_lite: 58 | startActivity(new Intent(this, AmeLiteActivity.class)); 59 | break; 60 | case R.id.main_ame: 61 | startActivity(new Intent(this, AmeActivity.class)); 62 | break; 63 | default: 64 | break; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | <vector xmlns:android="http://schemas.android.com/apk/res/android" 2 | xmlns:aapt="http://schemas.android.com/aapt" 3 | android:width="108dp" 4 | android:height="108dp" 5 | android:viewportHeight="108" 6 | android:viewportWidth="108"> 7 | <path 8 | android:fillType="evenOdd" 9 | android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" 10 | android:strokeColor="#00000000" 11 | android:strokeWidth="1"> 12 | <aapt:attr name="android:fillColor"> 13 | <gradient 14 | android:endX="78.5885" 15 | android:endY="90.9159" 16 | android:startX="48.7653" 17 | android:startY="61.0927" 18 | android:type="linear"> 19 | <item 20 | android:color="#44000000" 21 | android:offset="0.0" /> 22 | <item 23 | android:color="#00000000" 24 | android:offset="1.0" /> 25 | </gradient> 26 | </aapt:attr> 27 | </path> 28 | <path 29 | android:fillColor="#FFFFFF" 30 | android:fillType="nonZero" 31 | android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" 32 | android:strokeColor="#00000000" 33 | android:strokeWidth="1" /> 34 | </vector> 35 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <vector xmlns:android="http://schemas.android.com/apk/res/android" 3 | android:width="108dp" 4 | android:height="108dp" 5 | android:viewportHeight="108" 6 | android:viewportWidth="108"> 7 | <path 8 | android:fillColor="#26A69A" 9 | android:pathData="M0,0h108v108h-108z" /> 10 | <path 11 | android:fillColor="#00000000" 12 | android:pathData="M9,0L9,108" 13 | android:strokeColor="#33FFFFFF" 14 | android:strokeWidth="0.8" /> 15 | <path 16 | android:fillColor="#00000000" 17 | android:pathData="M19,0L19,108" 18 | android:strokeColor="#33FFFFFF" 19 | android:strokeWidth="0.8" /> 20 | <path 21 | android:fillColor="#00000000" 22 | android:pathData="M29,0L29,108" 23 | android:strokeColor="#33FFFFFF" 24 | android:strokeWidth="0.8" /> 25 | <path 26 | android:fillColor="#00000000" 27 | android:pathData="M39,0L39,108" 28 | android:strokeColor="#33FFFFFF" 29 | android:strokeWidth="0.8" /> 30 | <path 31 | android:fillColor="#00000000" 32 | android:pathData="M49,0L49,108" 33 | android:strokeColor="#33FFFFFF" 34 | android:strokeWidth="0.8" /> 35 | <path 36 | android:fillColor="#00000000" 37 | android:pathData="M59,0L59,108" 38 | android:strokeColor="#33FFFFFF" 39 | android:strokeWidth="0.8" /> 40 | <path 41 | android:fillColor="#00000000" 42 | android:pathData="M69,0L69,108" 43 | android:strokeColor="#33FFFFFF" 44 | android:strokeWidth="0.8" /> 45 | <path 46 | android:fillColor="#00000000" 47 | android:pathData="M79,0L79,108" 48 | android:strokeColor="#33FFFFFF" 49 | android:strokeWidth="0.8" /> 50 | <path 51 | android:fillColor="#00000000" 52 | android:pathData="M89,0L89,108" 53 | android:strokeColor="#33FFFFFF" 54 | android:strokeWidth="0.8" /> 55 | <path 56 | android:fillColor="#00000000" 57 | android:pathData="M99,0L99,108" 58 | android:strokeColor="#33FFFFFF" 59 | android:strokeWidth="0.8" /> 60 | <path 61 | android:fillColor="#00000000" 62 | android:pathData="M0,9L108,9" 63 | android:strokeColor="#33FFFFFF" 64 | android:strokeWidth="0.8" /> 65 | <path 66 | android:fillColor="#00000000" 67 | android:pathData="M0,19L108,19" 68 | android:strokeColor="#33FFFFFF" 69 | android:strokeWidth="0.8" /> 70 | <path 71 | android:fillColor="#00000000" 72 | android:pathData="M0,29L108,29" 73 | android:strokeColor="#33FFFFFF" 74 | android:strokeWidth="0.8" /> 75 | <path 76 | android:fillColor="#00000000" 77 | android:pathData="M0,39L108,39" 78 | android:strokeColor="#33FFFFFF" 79 | android:strokeWidth="0.8" /> 80 | <path 81 | android:fillColor="#00000000" 82 | android:pathData="M0,49L108,49" 83 | android:strokeColor="#33FFFFFF" 84 | android:strokeWidth="0.8" /> 85 | <path 86 | android:fillColor="#00000000" 87 | android:pathData="M0,59L108,59" 88 | android:strokeColor="#33FFFFFF" 89 | android:strokeWidth="0.8" /> 90 | <path 91 | android:fillColor="#00000000" 92 | android:pathData="M0,69L108,69" 93 | android:strokeColor="#33FFFFFF" 94 | android:strokeWidth="0.8" /> 95 | <path 96 | android:fillColor="#00000000" 97 | android:pathData="M0,79L108,79" 98 | android:strokeColor="#33FFFFFF" 99 | android:strokeWidth="0.8" /> 100 | <path 101 | android:fillColor="#00000000" 102 | android:pathData="M0,89L108,89" 103 | android:strokeColor="#33FFFFFF" 104 | android:strokeWidth="0.8" /> 105 | <path 106 | android:fillColor="#00000000" 107 | android:pathData="M0,99L108,99" 108 | android:strokeColor="#33FFFFFF" 109 | android:strokeWidth="0.8" /> 110 | <path 111 | android:fillColor="#00000000" 112 | android:pathData="M19,29L89,29" 113 | android:strokeColor="#33FFFFFF" 114 | android:strokeWidth="0.8" /> 115 | <path 116 | android:fillColor="#00000000" 117 | android:pathData="M19,39L89,39" 118 | android:strokeColor="#33FFFFFF" 119 | android:strokeWidth="0.8" /> 120 | <path 121 | android:fillColor="#00000000" 122 | android:pathData="M19,49L89,49" 123 | android:strokeColor="#33FFFFFF" 124 | android:strokeWidth="0.8" /> 125 | <path 126 | android:fillColor="#00000000" 127 | android:pathData="M19,59L89,59" 128 | android:strokeColor="#33FFFFFF" 129 | android:strokeWidth="0.8" /> 130 | <path 131 | android:fillColor="#00000000" 132 | android:pathData="M19,69L89,69" 133 | android:strokeColor="#33FFFFFF" 134 | android:strokeWidth="0.8" /> 135 | <path 136 | android:fillColor="#00000000" 137 | android:pathData="M19,79L89,79" 138 | android:strokeColor="#33FFFFFF" 139 | android:strokeWidth="0.8" /> 140 | <path 141 | android:fillColor="#00000000" 142 | android:pathData="M29,19L29,89" 143 | android:strokeColor="#33FFFFFF" 144 | android:strokeWidth="0.8" /> 145 | <path 146 | android:fillColor="#00000000" 147 | android:pathData="M39,19L39,89" 148 | android:strokeColor="#33FFFFFF" 149 | android:strokeWidth="0.8" /> 150 | <path 151 | android:fillColor="#00000000" 152 | android:pathData="M49,19L49,89" 153 | android:strokeColor="#33FFFFFF" 154 | android:strokeWidth="0.8" /> 155 | <path 156 | android:fillColor="#00000000" 157 | android:pathData="M59,19L59,89" 158 | android:strokeColor="#33FFFFFF" 159 | android:strokeWidth="0.8" /> 160 | <path 161 | android:fillColor="#00000000" 162 | android:pathData="M69,19L69,89" 163 | android:strokeColor="#33FFFFFF" 164 | android:strokeWidth="0.8" /> 165 | <path 166 | android:fillColor="#00000000" 167 | android:pathData="M79,19L79,89" 168 | android:strokeColor="#33FFFFFF" 169 | android:strokeWidth="0.8" /> 170 | </vector> 171 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_ame.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 | xmlns:app="http://schemas.android.com/apk/res-auto" 4 | xmlns:tools="http://schemas.android.com/tools" 5 | android:layout_width="match_parent" 6 | android:layout_height="match_parent" 7 | tools:context="io.auxo.ame.sample.AmeActivity"> 8 | 9 | </LinearLayout> 10 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 | xmlns:tools="http://schemas.android.com/tools" 4 | android:layout_width="match_parent" 5 | android:layout_height="match_parent" 6 | android:orientation="vertical" 7 | tools:context="io.auxo.ame.sample.MainActivity"> 8 | 9 | <Button 10 | android:id="@+id/main_ame_lite" 11 | android:layout_width="match_parent" 12 | android:layout_height="wrap_content" 13 | android:text="Ame Lite" /> 14 | 15 | <Button 16 | android:id="@+id/main_ame" 17 | android:layout_width="match_parent" 18 | android:layout_height="wrap_content" 19 | android:text="Ame" /> 20 | 21 | </LinearLayout> 22 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> 3 | <background android:drawable="@drawable/ic_launcher_background" /> 4 | <foreground android:drawable="@drawable/ic_launcher_foreground" /> 5 | </adaptive-icon> -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> 3 | <background android:drawable="@drawable/ic_launcher_background" /> 4 | <foreground android:drawable="@drawable/ic_launcher_foreground" /> 5 | </adaptive-icon> -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4332weizi/AME/e6823c837ead9e6e71e2b8a844fdefb6770d7e91/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <resources> 3 | <color name="colorPrimary">#3F51B5</color> 4 | <color name="colorPrimaryDark">#303F9F</color> 5 | <color name="colorAccent">#FF4081</color> 6 | </resources> 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | <resources> 2 | <string name="app_name">AME</string> 3 | </resources> 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | <resources> 2 | 3 | <!-- Base application theme. --> 4 | <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 5 | <!-- Customize your theme here. --> 6 | <item name="colorPrimary">@color/colorPrimary</item> 7 | <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 8 | <item name="colorAccent">@color/colorAccent</item> 9 | </style> 10 | 11 | </resources> 12 | -------------------------------------------------------------------------------- /sample/src/test/java/io/auxo/ame/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package io.auxo.ame.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':mp3lame', ':ame', ':ame-lite' --------------------------------------------------------------------------------