├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── mobi │ │ └── cangol │ │ └── mobile │ │ └── utils │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── test.raw │ ├── java │ │ └── mobi │ │ │ └── cangol │ │ │ └── mobile │ │ │ └── utils │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── mobi │ └── cangol │ └── mobile │ └── utils │ └── ExampleUnitTest.java ├── build.gradle ├── downloads ├── arm64-v8a │ └── libmp3lame.so ├── armeabi-v7a │ └── libmp3lame.so ├── armeabi │ └── libmp3lame.so ├── lame.jar ├── mips │ └── libmp3lame.so ├── mips64 │ └── libmp3lame.so ├── x86 │ └── libmp3lame.so └── x86_64 │ └── libmp3lame.so ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── lame ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── mobi │ │ └── cangol │ │ └── mobile │ │ └── utils │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── cpp │ │ └── CMakeLists.txt │ ├── java │ │ └── mobi │ │ │ └── cangol │ │ │ └── mobile │ │ │ └── utils │ │ │ └── LameUtils.java │ └── jni │ │ ├── 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 │ │ ├── mobi_cangol_mobile_utils_LameUtils.c │ │ ├── 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 │ └── test │ └── java │ └── mobi │ └── cangol │ └── mobile │ └── utils │ └── ExampleUnitTest.java ├── maven_push.gradle └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | 9 | # Java class files 10 | *.class 11 | 12 | # generated files 13 | bin/ 14 | gen/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | gradlew.bat 20 | gradlew 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Eclipse project files 29 | .classpath 30 | .project 31 | .settings 32 | eclipsebin 33 | 34 | build 35 | out 36 | lib 37 | 38 | target 39 | pom.xml.* 40 | release.properties 41 | 42 | .idea 43 | *.iml 44 | *.ipr 45 | *.iws 46 | classes 47 | 48 | obj 49 | 50 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | sudo: true 4 | os: 5 | - linux 6 | addons: 7 | apt_packages: 8 | - pandoc 9 | android: 10 | components: 11 | - tools 12 | - platform-tools 13 | - build-tools-26.0.2 14 | - android-26 15 | - android-22 16 | - extra-android-m2repository 17 | - extra-android-support 18 | - sys-img-armeabi-v7a-android-22 19 | - add-on 20 | - extra 21 | licenses: 22 | - 'android-sdk-preview-license-.+' 23 | - 'android-sdk-license-.+' 24 | - 'google-gdk-license-.+' 25 | - '.+' 26 | before_cache: 27 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 28 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 29 | cache: 30 | directories: 31 | - $HOME/.gradle/caches/ 32 | - $HOME/.gradle/wrapper/ 33 | - $HOME/.android/build-cache 34 | before_install: 35 | - mkdir -p $ANDROID_HOME/licenses 36 | - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license 37 | - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> $ANDROID_HOME/licenses/android-sdk-license 38 | # Gradle 39 | - wget -q http://services.gradle.org/distributions/gradle-4.1-all.zip 40 | - unzip -q gradle-4.1-all.zip 41 | - export GRADLE_HOME=$PWD/gradle-4.1 42 | - export PATH=$GRADLE_HOME/bin:$PATH 43 | install: 44 | - echo y | sdkmanager 'ndk-bundle' 45 | - echo y | sdkmanager 'cmake;3.6.4111459' 46 | - echo y | sdkmanager 'lldb;3.0' 47 | before_script: 48 | - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a 49 | - emulator -avd test -no-audio -no-window & 50 | - android-wait-for-emulator 51 | - adb shell input keyevent 82 & -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidLame 2 | [ ![Download](https://api.bintray.com/packages/cangol/maven/AndroidLame/images/download.svg) ](https://bintray.com/cangol/maven/AndroidLame/_latestVersion) 3 | [![Build Status](https://travis-ci.org/Cangol/AndroidLame.svg?branch=master)](https://travis-ci.org/Cangol/AndroidLame) 4 | 5 | # lame 6 | [lame 官网](http://lame.sourceforge.net/) 7 | 本项目主要方便大家在android上使用lame。 8 | Android使用AudioRecord录音时不支持mp3格式,需要先录制为raw格式,然后在使用lame转换成mp3 9 | 10 | ## 引用方式 11 | Maven 12 | 13 | 14 | mobi.cangol.mobile 15 | lame 16 |     1.0.1 17 | pom 18 | 19 | Gradle 20 | 21 | compile 'mobi.cangol.mobile:lame:1.0.1' 22 | 直接下载jar和so文件使用 23 | 24 | https://github.com/Cangol/AndroidLame/tree/master/downloads 25 | ## 使用方法 26 | 27 | LameUtils lameUtils = new LameUtils(1, 16000, 96); 28 | boolean result = lameUtils.raw2mp3(sourcePath, targetPath); 29 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | android { 3 | compileSdkVersion 26 4 | buildToolsVersion '26.0.2' 5 | defaultConfig { 6 | applicationId "com.jince.goldmaster.customer" 7 | multiDexEnabled false 8 | minSdkVersion 14 9 | versionCode 2 10 | versionName "1.0.1" 11 | sourceSets.main.jniLibs.srcDirs = ['libs'] 12 | } 13 | compileOptions { 14 | sourceCompatibility JavaVersion.VERSION_1_7 15 | targetCompatibility JavaVersion.VERSION_1_7 16 | } 17 | packagingOptions { 18 | exclude 'META-INF/LICENSE' 19 | exclude 'META-INF/NOTICE' 20 | } 21 | lintOptions { 22 | abortOnError false 23 | } 24 | } 25 | dependencies { 26 | compile fileTree(include: ['*.jar'], dir: 'libs') 27 | testCompile 'junit:junit:4.12' 28 | compile project(':lame') 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Dev\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/mobi/cangol/mobile/utils/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package mobi.cangol.mobile.utils; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/assets/test.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/app/src/main/assets/test.raw -------------------------------------------------------------------------------- /app/src/main/java/mobi/cangol/mobile/utils/MainActivity.java: -------------------------------------------------------------------------------- 1 | package mobi.cangol.mobile.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.AsyncTask; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.util.Log; 8 | import android.widget.TextView; 9 | 10 | import java.io.File; 11 | import java.io.FileOutputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | 15 | public class MainActivity extends Activity { 16 | 17 | private static final String TAG="LAME"; 18 | TextView textView; 19 | LameUtils lameUtils; 20 | File raw; 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | textView= (TextView) findViewById(R.id.textView); 26 | lameUtils=new LameUtils(); 27 | printLog("version="+lameUtils.getVersion()); 28 | printLog("ABI="+lameUtils.getSystemABI()); 29 | copyAssetsFileToAppData("test.raw",Environment.getExternalStorageDirectory().getPath()+ "/test.raw"); 30 | raw=new File(Environment.getExternalStorageDirectory().getPath()+ "/test.raw"); 31 | printLog("file="+raw.getAbsolutePath()); 32 | printLog("exists="+raw.exists()); 33 | AsyncTask asyncTask=new AsyncTask() { 34 | @Override 35 | protected Boolean doInBackground(String... params) { 36 | return lameUtils.raw2mp3(params[0],params[0].replace("raw","mp3")); 37 | } 38 | 39 | @Override 40 | protected void onPostExecute(Boolean result) { 41 | super.onPostExecute(result); 42 | printLog("result="+result); 43 | } 44 | }; 45 | asyncTask.execute(raw.getAbsolutePath()); 46 | } 47 | 48 | void printLog(String str){ 49 | Log.d(TAG,str); 50 | textView.append("\n"+str); 51 | } 52 | 53 | private void copyAssetsFileToAppData(String assetsPath, String savePath) { 54 | try { 55 | File dstFile = new File(savePath); 56 | if (!dstFile.getParentFile().exists()) { 57 | dstFile.getParentFile().mkdirs(); 58 | } 59 | if (dstFile.exists()) 60 | dstFile.delete(); 61 | dstFile.createNewFile(); 62 | int bytesum = 0; 63 | int byteread = 0; 64 | InputStream inStream = this.getResources().getAssets().open(assetsPath); 65 | FileOutputStream fs = new FileOutputStream(dstFile); 66 | byte[] buffer = new byte[1024]; 67 | while ((byteread = inStream.read(buffer)) != -1) { 68 | bytesum += byteread; 69 | fs.write(buffer, 0, byteread); 70 | } 71 | inStream.close(); 72 | Log.d(TAG, "copy " + assetsPath + " --> " + savePath); 73 | } catch (IOException e) { 74 | Log.e(TAG, "copy file error!"); 75 | Log.e(TAG, "IOException", e); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidLame 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/test/java/mobi/cangol/mobile/utils/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package mobi.cangol.mobile.utils; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.0.1' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | google() 21 | } 22 | } 23 | 24 | task clean(type: Delete) { 25 | delete rootProject.buildDir 26 | } 27 | -------------------------------------------------------------------------------- /downloads/arm64-v8a/libmp3lame.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/arm64-v8a/libmp3lame.so -------------------------------------------------------------------------------- /downloads/armeabi-v7a/libmp3lame.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/armeabi-v7a/libmp3lame.so -------------------------------------------------------------------------------- /downloads/armeabi/libmp3lame.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/armeabi/libmp3lame.so -------------------------------------------------------------------------------- /downloads/lame.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/lame.jar -------------------------------------------------------------------------------- /downloads/mips/libmp3lame.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/mips/libmp3lame.so -------------------------------------------------------------------------------- /downloads/mips64/libmp3lame.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/mips64/libmp3lame.so -------------------------------------------------------------------------------- /downloads/x86/libmp3lame.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/x86/libmp3lame.so -------------------------------------------------------------------------------- /downloads/x86_64/libmp3lame.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/downloads/x86_64/libmp3lame.so -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | #org.gradle.daemon=true 21 | #pom 22 | POM_GROUP_ID=mobi.cangol.mobile 23 | POM_VERSION=1.0.1 24 | POM_NAME=AndroidLame 25 | POM_ARTIFACT_ID=lame 26 | POM_PACKAGING=aar 27 | POM_DESCRIPTION=android lame 28 | POM_URL=https://github.com/Cangol/AndroidLame 29 | #licenses 30 | POM_LICENSE_NAME=The Apache Software License, Version 2.0 31 | POM_LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 32 | POM_LICENCE_DIST=repo 33 | #developers 34 | POM_DEVELOPER_ID=Cangol 35 | POM_DEVELOPER_NAME=Cangol 36 | POM_DEVELOPER_EMAIL=wxw404@gmail.com 37 | #scm 38 | POM_SCM_URL=https://github.com/Cangol/AndroidLame 39 | POM_SCM_CONNECTION=scm:git@github.com:Cangol/AndroidLame.git 40 | POM_SCM_DEV_CONNECTION=scm:git@github.com:Cangol/AndroidLame.git 41 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cangol/AndroidLame/d2c154dad89bae4607365a4335c54c15809e6aed/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Aug 23 16:45:26 CST 2017 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.1-all.zip 7 | -------------------------------------------------------------------------------- /lame/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /.externalNativeBuild 3 | -------------------------------------------------------------------------------- /lame/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion '26.0.2' 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | externalNativeBuild { 13 | cmake { 14 | cFlags '-DSTDC_HEADERS' 15 | arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static' 16 | } 17 | } 18 | } 19 | lintOptions.with { 20 | abortOnError false 21 | } 22 | externalNativeBuild { 23 | cmake { 24 | path 'src/main/jni/CMakeLists.txt' 25 | } 26 | } 27 | } 28 | task sourcesJar(type: Jar) { 29 | from android.sourceSets.main.java.srcDirs 30 | classifier = 'sources' 31 | } 32 | 33 | task javadoc(type: Javadoc) { 34 | source = android.sourceSets.main.java.srcDirs 35 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 36 | options { 37 | encoding "UTF-8" 38 | links "http://docs.oracle.com/javase/7/docs/api/" 39 | linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference" 40 | } 41 | destinationDir = file("../docs/") 42 | } 43 | 44 | task javadocJar(type: Jar, dependsOn: javadoc) { 45 | classifier = 'javadoc' 46 | from javadoc.destinationDir 47 | } 48 | 49 | artifacts { 50 | archives javadocJar 51 | archives sourcesJar 52 | } 53 | dependencies { 54 | compile 'junit:junit:4.12' 55 | } 56 | apply from: '../maven_push.gradle' -------------------------------------------------------------------------------- /lame/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Dev\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /lame/src/androidTest/java/mobi/cangol/mobile/utils/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2013 Cangol 4 | *

5 | * Licensed under the Apache License, Version 2.0 (the "License") 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package mobi.cangol.mobile.utils; 19 | 20 | import android.app.Application; 21 | import android.test.ApplicationTestCase; 22 | 23 | /** 24 | * Testing Fundamentals 25 | */ 26 | public class ApplicationTest extends ApplicationTestCase { 27 | public ApplicationTest() { 28 | super(Application.class); 29 | } 30 | } -------------------------------------------------------------------------------- /lame/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 20 | 21 | -------------------------------------------------------------------------------- /lame/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) The Android Open Source Project 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # Generate one static lib and one shared lib, copy them into 18 | # ${project_dir}/distribution for other indepdendent applications 19 | # to use. 20 | cmake_minimum_required(VERSION 3.4.1) 21 | 22 | file(GLOB source_files "src/main/cpp/*.c" "src/main/cpp/vector/*.c") 23 | 24 | add_library(mp3lame SHARED ${source_files}) 25 | 26 | 27 | # add lib dependencies 28 | target_link_libraries(mp3lame 29 | android 30 | log) 31 | 32 | -------------------------------------------------------------------------------- /lame/src/main/java/mobi/cangol/mobile/utils/LameUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2013 Cangol 4 | *

5 | * Licensed under the Apache License, Version 2.0 (the "License") 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package mobi.cangol.mobile.utils; 19 | 20 | /** 21 | * Created by xuewu.wei on 2016/6/13. 22 | */ 23 | public class LameUtils { 24 | private int bitRate = 96; 25 | private int sampleRate = 16000; 26 | private int numChannels = 1; 27 | 28 | static { 29 | System.loadLibrary("mp3lame"); 30 | } 31 | public native String getSystemABI(); 32 | 33 | public native String getVersion(); 34 | 35 | private native void initEncoder(int numChannels, int sampleRate, int bitRate, int mode, int quality); 36 | 37 | private native void destroyEncoder(); 38 | 39 | private native int encodeFile(String sourcePath, String targetPath); 40 | 41 | public int getNumChannels() { 42 | return this.numChannels; 43 | } 44 | 45 | public void setNumChannels(int numChannels) { 46 | this.numChannels = numChannels; 47 | } 48 | 49 | public int getSampleRate() { 50 | return this.sampleRate; 51 | } 52 | 53 | public void setSampleRate(int sampleRate) { 54 | this.sampleRate = sampleRate; 55 | } 56 | 57 | public int getBitRate() { 58 | return this.bitRate; 59 | } 60 | 61 | public void setBitRate(int bitRate) { 62 | this.bitRate = bitRate; 63 | } 64 | 65 | public LameUtils() { 66 | } 67 | 68 | public LameUtils(int numChannels, int sampleRate, int bitRate) { 69 | this.numChannels = numChannels; 70 | this.sampleRate = sampleRate; 71 | this.bitRate = bitRate; 72 | } 73 | 74 | public boolean raw2mp3(String source, String destination) { 75 | initEncoder(this.numChannels, this.sampleRate, this.bitRate, 1, 2); 76 | int result = encodeFile(source, destination); 77 | destroyEncoder(); 78 | if (result == 0) { 79 | return true; 80 | } 81 | return false; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lame/src/main/jni/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) The Android Open Source Project 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # Generate one static lib and one shared lib, copy them into 18 | # ${project_dir}/distribution for other indepdendent applications 19 | # to use. 20 | cmake_minimum_required(VERSION 3.4.1) 21 | 22 | file(GLOB source_files "*.c" "vector/*.c") 23 | 24 | add_library(mp3lame SHARED ${source_files}) 25 | 26 | 27 | # add lib dependencies 28 | target_link_libraries(mp3lame 29 | android 30 | log) 31 | 32 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/encoder.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LAME MP3 encoding engine 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * Copyright (c) 2000-2002 Takehiro Tominaga 6 | * Copyright (c) 2000-2011 Robert Hegemann 7 | * Copyright (c) 2001 Gabriel Bouvigne 8 | * Copyright (c) 2001 John Dahlstrom 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Library General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Library General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Library General Public 21 | * License along with this library; if not, write to the 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 | * Boston, MA 02111-1307, USA. 24 | */ 25 | 26 | /* $Id: encoder.c,v 1.111 2011/05/07 16:05:17 rbrito Exp $ */ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include 30 | #endif 31 | 32 | 33 | #include "lame.h" 34 | #include "machine.h" 35 | #include "encoder.h" 36 | #include "util.h" 37 | #include "lame_global_flags.h" 38 | #include "newmdct.h" 39 | #include "psymodel.h" 40 | #include "lame-analysis.h" 41 | #include "bitstream.h" 42 | #include "VbrTag.h" 43 | #include "quantize_pvt.h" 44 | 45 | 46 | 47 | /* 48 | * auto-adjust of ATH, useful for low volume 49 | * Gabriel Bouvigne 3 feb 2001 50 | * 51 | * modifies some values in 52 | * gfp->internal_flags->ATH 53 | * (gfc->ATH) 54 | */ 55 | static void 56 | adjust_ATH(lame_internal_flags const *const gfc) 57 | { 58 | SessionConfig_t const *const cfg = &gfc->cfg; 59 | FLOAT gr2_max, max_pow; 60 | 61 | if (gfc->ATH->use_adjust == 0) { 62 | gfc->ATH->adjust_factor = 1.0; /* no adjustment */ 63 | return; 64 | } 65 | 66 | /* jd - 2001 mar 12, 27, jun 30 */ 67 | /* loudness based on equal loudness curve; */ 68 | /* use granule with maximum combined loudness */ 69 | max_pow = gfc->ov_psy.loudness_sq[0][0]; 70 | gr2_max = gfc->ov_psy.loudness_sq[1][0]; 71 | if (cfg->channels_out == 2) { 72 | max_pow += gfc->ov_psy.loudness_sq[0][1]; 73 | gr2_max += gfc->ov_psy.loudness_sq[1][1]; 74 | } 75 | else { 76 | max_pow += max_pow; 77 | gr2_max += gr2_max; 78 | } 79 | if (cfg->mode_gr == 2) { 80 | max_pow = Max(max_pow, gr2_max); 81 | } 82 | max_pow *= 0.5; /* max_pow approaches 1.0 for full band noise */ 83 | 84 | /* jd - 2001 mar 31, jun 30 */ 85 | /* user tuning of ATH adjustment region */ 86 | max_pow *= gfc->ATH->aa_sensitivity_p; 87 | 88 | /* adjust ATH depending on range of maximum value 89 | */ 90 | 91 | /* jd - 2001 feb27, mar12,20, jun30, jul22 */ 92 | /* continuous curves based on approximation */ 93 | /* to GB's original values. */ 94 | /* For an increase in approximate loudness, */ 95 | /* set ATH adjust to adjust_limit immediately */ 96 | /* after a delay of one frame. */ 97 | /* For a loudness decrease, reduce ATH adjust */ 98 | /* towards adjust_limit gradually. */ 99 | /* max_pow is a loudness squared or a power. */ 100 | if (max_pow > 0.03125) { /* ((1 - 0.000625)/ 31.98) from curve below */ 101 | if (gfc->ATH->adjust_factor >= 1.0) { 102 | gfc->ATH->adjust_factor = 1.0; 103 | } 104 | else { 105 | /* preceding frame has lower ATH adjust; */ 106 | /* ascend only to the preceding adjust_limit */ 107 | /* in case there is leading low volume */ 108 | if (gfc->ATH->adjust_factor < gfc->ATH->adjust_limit) { 109 | gfc->ATH->adjust_factor = gfc->ATH->adjust_limit; 110 | } 111 | } 112 | gfc->ATH->adjust_limit = 1.0; 113 | } 114 | else { /* adjustment curve */ 115 | /* about 32 dB maximum adjust (0.000625) */ 116 | FLOAT const adj_lim_new = 31.98 * max_pow + 0.000625; 117 | if (gfc->ATH->adjust_factor >= adj_lim_new) { /* descend gradually */ 118 | gfc->ATH->adjust_factor *= adj_lim_new * 0.075 + 0.925; 119 | if (gfc->ATH->adjust_factor < adj_lim_new) { /* stop descent */ 120 | gfc->ATH->adjust_factor = adj_lim_new; 121 | } 122 | } 123 | else { /* ascend */ 124 | if (gfc->ATH->adjust_limit >= adj_lim_new) { 125 | gfc->ATH->adjust_factor = adj_lim_new; 126 | } 127 | else { /* preceding frame has lower ATH adjust; */ 128 | /* ascend only to the preceding adjust_limit */ 129 | if (gfc->ATH->adjust_factor < gfc->ATH->adjust_limit) { 130 | gfc->ATH->adjust_factor = gfc->ATH->adjust_limit; 131 | } 132 | } 133 | } 134 | gfc->ATH->adjust_limit = adj_lim_new; 135 | } 136 | } 137 | 138 | /*********************************************************************** 139 | * 140 | * some simple statistics 141 | * 142 | * bitrate index 0: free bitrate -> not allowed in VBR mode 143 | * : bitrates, kbps depending on MPEG version 144 | * bitrate index 15: forbidden 145 | * 146 | * mode_ext: 147 | * 0: LR 148 | * 1: LR-i 149 | * 2: MS 150 | * 3: MS-i 151 | * 152 | ***********************************************************************/ 153 | 154 | static void 155 | updateStats(lame_internal_flags * const gfc) 156 | { 157 | SessionConfig_t const *const cfg = &gfc->cfg; 158 | EncResult_t *eov = &gfc->ov_enc; 159 | int gr, ch; 160 | assert(0 <= eov->bitrate_index && eov->bitrate_index < 16); 161 | assert(0 <= eov->mode_ext && eov->mode_ext < 4); 162 | 163 | /* count bitrate indices */ 164 | eov->bitrate_channelmode_hist[eov->bitrate_index][4]++; 165 | eov->bitrate_channelmode_hist[15][4]++; 166 | 167 | /* count 'em for every mode extension in case of 2 channel encoding */ 168 | if (cfg->channels_out == 2) { 169 | eov->bitrate_channelmode_hist[eov->bitrate_index][eov->mode_ext]++; 170 | eov->bitrate_channelmode_hist[15][eov->mode_ext]++; 171 | } 172 | for (gr = 0; gr < cfg->mode_gr; ++gr) { 173 | for (ch = 0; ch < cfg->channels_out; ++ch) { 174 | int bt = gfc->l3_side.tt[gr][ch].block_type; 175 | if (gfc->l3_side.tt[gr][ch].mixed_block_flag) 176 | bt = 4; 177 | eov->bitrate_blocktype_hist[eov->bitrate_index][bt]++; 178 | eov->bitrate_blocktype_hist[eov->bitrate_index][5]++; 179 | eov->bitrate_blocktype_hist[15][bt]++; 180 | eov->bitrate_blocktype_hist[15][5]++; 181 | } 182 | } 183 | } 184 | 185 | 186 | 187 | 188 | static void 189 | lame_encode_frame_init(lame_internal_flags * gfc, const sample_t *const inbuf[2]) 190 | { 191 | SessionConfig_t const *const cfg = &gfc->cfg; 192 | 193 | int ch, gr; 194 | 195 | if (gfc->lame_encode_frame_init == 0) { 196 | sample_t primebuff0[286 + 1152 + 576]; 197 | sample_t primebuff1[286 + 1152 + 576]; 198 | int const framesize = 576 * cfg->mode_gr; 199 | /* prime the MDCT/polyphase filterbank with a short block */ 200 | int i, j; 201 | gfc->lame_encode_frame_init = 1; 202 | memset(primebuff0, 0, sizeof(primebuff0)); 203 | memset(primebuff1, 0, sizeof(primebuff1)); 204 | for (i = 0, j = 0; i < 286 + 576 * (1 + cfg->mode_gr); ++i) { 205 | if (i < framesize) { 206 | primebuff0[i] = 0; 207 | if (cfg->channels_out == 2) 208 | primebuff1[i] = 0; 209 | } 210 | else { 211 | primebuff0[i] = inbuf[0][j]; 212 | if (cfg->channels_out == 2) 213 | primebuff1[i] = inbuf[1][j]; 214 | ++j; 215 | } 216 | } 217 | /* polyphase filtering / mdct */ 218 | for (gr = 0; gr < cfg->mode_gr; gr++) { 219 | for (ch = 0; ch < cfg->channels_out; ch++) { 220 | gfc->l3_side.tt[gr][ch].block_type = SHORT_TYPE; 221 | } 222 | } 223 | mdct_sub48(gfc, primebuff0, primebuff1); 224 | 225 | /* check FFT will not use a negative starting offset */ 226 | #if 576 < FFTOFFSET 227 | # error FFTOFFSET greater than 576: FFT uses a negative offset 228 | #endif 229 | /* check if we have enough data for FFT */ 230 | assert(gfc->sv_enc.mf_size >= (BLKSIZE + framesize - FFTOFFSET)); 231 | /* check if we have enough data for polyphase filterbank */ 232 | assert(gfc->sv_enc.mf_size >= (512 + framesize - 32)); 233 | } 234 | 235 | } 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | /************************************************************************ 244 | * 245 | * encodeframe() Layer 3 246 | * 247 | * encode a single frame 248 | * 249 | ************************************************************************ 250 | lame_encode_frame() 251 | 252 | 253 | gr 0 gr 1 254 | inbuf: |--------------|--------------|--------------| 255 | 256 | 257 | Polyphase (18 windows, each shifted 32) 258 | gr 0: 259 | window1 <----512----> 260 | window18 <----512----> 261 | 262 | gr 1: 263 | window1 <----512----> 264 | window18 <----512----> 265 | 266 | 267 | 268 | MDCT output: |--------------|--------------|--------------| 269 | 270 | FFT's <---------1024----------> 271 | <---------1024--------> 272 | 273 | 274 | 275 | inbuf = buffer of PCM data size=MP3 framesize 276 | encoder acts on inbuf[ch][0], but output is delayed by MDCTDELAY 277 | so the MDCT coefficints are from inbuf[ch][-MDCTDELAY] 278 | 279 | psy-model FFT has a 1 granule delay, so we feed it data for the 280 | next granule. 281 | FFT is centered over granule: 224+576+224 282 | So FFT starts at: 576-224-MDCTDELAY 283 | 284 | MPEG2: FFT ends at: BLKSIZE+576-224-MDCTDELAY (1328) 285 | MPEG1: FFT ends at: BLKSIZE+2*576-224-MDCTDELAY (1904) 286 | 287 | MPEG2: polyphase first window: [0..511] 288 | 18th window: [544..1055] (1056) 289 | MPEG1: 36th window: [1120..1631] (1632) 290 | data needed: 512+framesize-32 291 | 292 | A close look newmdct.c shows that the polyphase filterbank 293 | only uses data from [0..510] for each window. Perhaps because the window 294 | used by the filterbank is zero for the last point, so Takehiro's 295 | code doesn't bother to compute with it. 296 | 297 | FFT starts at 576-224-MDCTDELAY (304) = 576-FFTOFFSET 298 | 299 | */ 300 | 301 | typedef FLOAT chgrdata[2][2]; 302 | 303 | 304 | int 305 | lame_encode_mp3_frame( /* Output */ 306 | lame_internal_flags * gfc, /* Context */ 307 | sample_t const *inbuf_l, /* Input */ 308 | sample_t const *inbuf_r, /* Input */ 309 | unsigned char *mp3buf, /* Output */ 310 | int mp3buf_size) 311 | { /* Output */ 312 | SessionConfig_t const *const cfg = &gfc->cfg; 313 | int mp3count; 314 | III_psy_ratio masking_LR[2][2]; /*LR masking & energy */ 315 | III_psy_ratio masking_MS[2][2]; /*MS masking & energy */ 316 | const III_psy_ratio (*masking)[2]; /*pointer to selected maskings */ 317 | const sample_t *inbuf[2]; 318 | 319 | FLOAT tot_ener[2][4]; 320 | FLOAT ms_ener_ratio[2] = { .5, .5 }; 321 | FLOAT pe[2][2] = { {0., 0.}, {0., 0.} }, pe_MS[2][2] = { { 322 | 0., 0.}, { 323 | 0., 0.}}; 324 | FLOAT (*pe_use)[2]; 325 | 326 | int ch, gr; 327 | 328 | inbuf[0] = inbuf_l; 329 | inbuf[1] = inbuf_r; 330 | 331 | if (gfc->lame_encode_frame_init == 0) { 332 | /*first run? */ 333 | lame_encode_frame_init(gfc, inbuf); 334 | 335 | } 336 | 337 | 338 | /********************** padding *****************************/ 339 | /* padding method as described in 340 | * "MPEG-Layer3 / Bitstream Syntax and Decoding" 341 | * by Martin Sieler, Ralph Sperschneider 342 | * 343 | * note: there is no padding for the very first frame 344 | * 345 | * Robert Hegemann 2000-06-22 346 | */ 347 | gfc->ov_enc.padding = FALSE; 348 | if ((gfc->sv_enc.slot_lag -= gfc->sv_enc.frac_SpF) < 0) { 349 | gfc->sv_enc.slot_lag += cfg->samplerate_out; 350 | gfc->ov_enc.padding = TRUE; 351 | } 352 | 353 | 354 | 355 | /**************************************** 356 | * Stage 1: psychoacoustic model * 357 | ****************************************/ 358 | 359 | { 360 | /* psychoacoustic model 361 | * psy model has a 1 granule (576) delay that we must compensate for 362 | * (mt 6/99). 363 | */ 364 | int ret; 365 | const sample_t *bufp[2] = {0, 0}; /* address of beginning of left & right granule */ 366 | int blocktype[2]; 367 | 368 | for (gr = 0; gr < cfg->mode_gr; gr++) { 369 | 370 | for (ch = 0; ch < cfg->channels_out; ch++) { 371 | bufp[ch] = &inbuf[ch][576 + gr * 576 - FFTOFFSET]; 372 | } 373 | ret = L3psycho_anal_vbr(gfc, bufp, gr, 374 | masking_LR, masking_MS, 375 | pe[gr], pe_MS[gr], tot_ener[gr], blocktype); 376 | if (ret != 0) 377 | return -4; 378 | 379 | if (cfg->mode == JOINT_STEREO) { 380 | ms_ener_ratio[gr] = tot_ener[gr][2] + tot_ener[gr][3]; 381 | if (ms_ener_ratio[gr] > 0) 382 | ms_ener_ratio[gr] = tot_ener[gr][3] / ms_ener_ratio[gr]; 383 | } 384 | 385 | /* block type flags */ 386 | for (ch = 0; ch < cfg->channels_out; ch++) { 387 | gr_info *const cod_info = &gfc->l3_side.tt[gr][ch]; 388 | cod_info->block_type = blocktype[ch]; 389 | cod_info->mixed_block_flag = 0; 390 | } 391 | } 392 | } 393 | 394 | 395 | /* auto-adjust of ATH, useful for low volume */ 396 | adjust_ATH(gfc); 397 | 398 | 399 | /**************************************** 400 | * Stage 2: MDCT * 401 | ****************************************/ 402 | 403 | /* polyphase filtering / mdct */ 404 | mdct_sub48(gfc, inbuf[0], inbuf[1]); 405 | 406 | 407 | /**************************************** 408 | * Stage 3: MS/LR decision * 409 | ****************************************/ 410 | 411 | /* Here will be selected MS or LR coding of the 2 stereo channels */ 412 | gfc->ov_enc.mode_ext = MPG_MD_LR_LR; 413 | 414 | if (cfg->force_ms) { 415 | gfc->ov_enc.mode_ext = MPG_MD_MS_LR; 416 | } 417 | else if (cfg->mode == JOINT_STEREO) { 418 | /* ms_ratio = is scaled, for historical reasons, to look like 419 | a ratio of side_channel / total. 420 | 0 = signal is 100% mono 421 | .5 = L & R uncorrelated 422 | */ 423 | 424 | /* [0] and [1] are the results for the two granules in MPEG-1, 425 | * in MPEG-2 it's only a faked averaging of the same value 426 | * _prev is the value of the last granule of the previous frame 427 | * _next is the value of the first granule of the next frame 428 | */ 429 | 430 | FLOAT sum_pe_MS = 0; 431 | FLOAT sum_pe_LR = 0; 432 | for (gr = 0; gr < cfg->mode_gr; gr++) { 433 | for (ch = 0; ch < cfg->channels_out; ch++) { 434 | sum_pe_MS += pe_MS[gr][ch]; 435 | sum_pe_LR += pe[gr][ch]; 436 | } 437 | } 438 | 439 | /* based on PE: M/S coding would not use much more bits than L/R */ 440 | if (sum_pe_MS <= 1.00 * sum_pe_LR) { 441 | 442 | gr_info const *const gi0 = &gfc->l3_side.tt[0][0]; 443 | gr_info const *const gi1 = &gfc->l3_side.tt[cfg->mode_gr - 1][0]; 444 | 445 | if (gi0[0].block_type == gi0[1].block_type && gi1[0].block_type == gi1[1].block_type) { 446 | 447 | gfc->ov_enc.mode_ext = MPG_MD_MS_LR; 448 | } 449 | } 450 | } 451 | 452 | /* bit and noise allocation */ 453 | if (gfc->ov_enc.mode_ext == MPG_MD_MS_LR) { 454 | masking = (const III_psy_ratio (*)[2])masking_MS; /* use MS masking */ 455 | pe_use = pe_MS; 456 | } 457 | else { 458 | masking = (const III_psy_ratio (*)[2])masking_LR; /* use LR masking */ 459 | pe_use = pe; 460 | } 461 | 462 | 463 | /* copy data for MP3 frame analyzer */ 464 | if (cfg->analysis && gfc->pinfo != NULL) { 465 | for (gr = 0; gr < cfg->mode_gr; gr++) { 466 | for (ch = 0; ch < cfg->channels_out; ch++) { 467 | gfc->pinfo->ms_ratio[gr] = 0; 468 | gfc->pinfo->ms_ener_ratio[gr] = ms_ener_ratio[gr]; 469 | gfc->pinfo->blocktype[gr][ch] = gfc->l3_side.tt[gr][ch].block_type; 470 | gfc->pinfo->pe[gr][ch] = pe_use[gr][ch]; 471 | memcpy(gfc->pinfo->xr[gr][ch], &gfc->l3_side.tt[gr][ch].xr[0], sizeof(FLOAT) * 576); 472 | /* in psymodel, LR and MS data was stored in pinfo. 473 | switch to MS data: */ 474 | if (gfc->ov_enc.mode_ext == MPG_MD_MS_LR) { 475 | gfc->pinfo->ers[gr][ch] = gfc->pinfo->ers[gr][ch + 2]; 476 | memcpy(gfc->pinfo->energy[gr][ch], gfc->pinfo->energy[gr][ch + 2], 477 | sizeof(gfc->pinfo->energy[gr][ch])); 478 | } 479 | } 480 | } 481 | } 482 | 483 | 484 | /**************************************** 485 | * Stage 4: quantization loop * 486 | ****************************************/ 487 | 488 | if (cfg->vbr == vbr_off || cfg->vbr == vbr_abr) { 489 | static FLOAT const fircoef[9] = { 490 | -0.0207887 * 5, -0.0378413 * 5, -0.0432472 * 5, -0.031183 * 5, 491 | 7.79609e-18 * 5, 0.0467745 * 5, 0.10091 * 5, 0.151365 * 5, 492 | 0.187098 * 5 493 | }; 494 | 495 | int i; 496 | FLOAT f; 497 | 498 | for (i = 0; i < 18; i++) 499 | gfc->sv_enc.pefirbuf[i] = gfc->sv_enc.pefirbuf[i + 1]; 500 | 501 | f = 0.0; 502 | for (gr = 0; gr < cfg->mode_gr; gr++) 503 | for (ch = 0; ch < cfg->channels_out; ch++) 504 | f += pe_use[gr][ch]; 505 | gfc->sv_enc.pefirbuf[18] = f; 506 | 507 | f = gfc->sv_enc.pefirbuf[9]; 508 | for (i = 0; i < 9; i++) 509 | f += (gfc->sv_enc.pefirbuf[i] + gfc->sv_enc.pefirbuf[18 - i]) * fircoef[i]; 510 | 511 | f = (670 * 5 * cfg->mode_gr * cfg->channels_out) / f; 512 | for (gr = 0; gr < cfg->mode_gr; gr++) { 513 | for (ch = 0; ch < cfg->channels_out; ch++) { 514 | pe_use[gr][ch] *= f; 515 | } 516 | } 517 | } 518 | gfc->iteration_loop(gfc, (const FLOAT (*)[2])pe_use, ms_ener_ratio, masking); 519 | 520 | 521 | /**************************************** 522 | * Stage 5: bitstream formatting * 523 | ****************************************/ 524 | 525 | 526 | /* write the frame to the bitstream */ 527 | (void) format_bitstream(gfc); 528 | 529 | /* copy mp3 bit buffer into array */ 530 | mp3count = copy_buffer(gfc, mp3buf, mp3buf_size, 1); 531 | 532 | 533 | if (cfg->write_lame_tag) { 534 | AddVbrFrame(gfc); 535 | } 536 | 537 | if (cfg->analysis && gfc->pinfo != NULL) { 538 | int framesize = 576 * cfg->mode_gr; 539 | for (ch = 0; ch < cfg->channels_out; ch++) { 540 | int j; 541 | for (j = 0; j < FFTOFFSET; j++) 542 | gfc->pinfo->pcmdata[ch][j] = gfc->pinfo->pcmdata[ch][j + framesize]; 543 | for (j = FFTOFFSET; j < 1600; j++) { 544 | gfc->pinfo->pcmdata[ch][j] = inbuf[ch][j - FFTOFFSET]; 545 | } 546 | } 547 | gfc->sv_qnt.masking_lower = 1.0; 548 | 549 | set_frame_pinfo(gfc, masking); 550 | } 551 | 552 | ++gfc->ov_enc.frame_number; 553 | 554 | updateStats(gfc); 555 | 556 | return mp3count; 557 | } 558 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/fft.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** FFT and FHT routines 3 | ** Copyright 1988, 1993; Ron Mayer 4 | ** Copyright (c) 1999-2000 Takehiro Tominaga 5 | ** 6 | ** fht(fz,n); 7 | ** Does a hartley transform of "n" points in the array "fz". 8 | ** 9 | ** NOTE: This routine uses at least 2 patented algorithms, and may be 10 | ** under the restrictions of a bunch of different organizations. 11 | ** Although I wrote it completely myself; it is kind of a derivative 12 | ** of a routine I once authored and released under the GPL, so it 13 | ** may fall under the free software foundation's restrictions; 14 | ** it was worked on as a Stanford Univ project, so they claim 15 | ** some rights to it; it was further optimized at work here, so 16 | ** I think this company claims parts of it. The patents are 17 | ** held by R. Bracewell (the FHT algorithm) and O. Buneman (the 18 | ** trig generator), both at Stanford Univ. 19 | ** If it were up to me, I'd say go do whatever you want with it; 20 | ** but it would be polite to give credit to the following people 21 | ** if you use this anywhere: 22 | ** Euler - probable inventor of the fourier transform. 23 | ** Gauss - probable inventor of the FFT. 24 | ** Hartley - probable inventor of the hartley transform. 25 | ** Buneman - for a really cool trig generator 26 | ** Mayer(me) - for authoring this particular version and 27 | ** including all the optimizations in one package. 28 | ** Thanks, 29 | ** Ron Mayer; mayer@acuson.com 30 | ** and added some optimization by 31 | ** Mather - idea of using lookup table 32 | ** Takehiro - some dirty hack for speed up 33 | */ 34 | 35 | /* $Id: fft.c,v 1.38 2009/04/20 21:48:00 robert Exp $ */ 36 | 37 | #ifdef HAVE_CONFIG_H 38 | # include 39 | #endif 40 | 41 | #include "lame.h" 42 | #include "machine.h" 43 | #include "encoder.h" 44 | #include "util.h" 45 | #include "fft.h" 46 | 47 | #include "vector/lame_intrin.h" 48 | 49 | 50 | 51 | #define TRI_SIZE (5-1) /* 1024 = 4**5 */ 52 | 53 | /* fft.c */ 54 | static FLOAT window[BLKSIZE], window_s[BLKSIZE_s / 2]; 55 | 56 | static const FLOAT costab[TRI_SIZE * 2] = { 57 | 9.238795325112867e-01, 3.826834323650898e-01, 58 | 9.951847266721969e-01, 9.801714032956060e-02, 59 | 9.996988186962042e-01, 2.454122852291229e-02, 60 | 9.999811752826011e-01, 6.135884649154475e-03 61 | }; 62 | 63 | static void 64 | fht(FLOAT * fz, int n) 65 | { 66 | const FLOAT *tri = costab; 67 | int k4; 68 | FLOAT *fi, *gi; 69 | FLOAT const *fn; 70 | 71 | n <<= 1; /* to get BLKSIZE, because of 3DNow! ASM routine */ 72 | fn = fz + n; 73 | k4 = 4; 74 | do { 75 | FLOAT s1, c1; 76 | int i, k1, k2, k3, kx; 77 | kx = k4 >> 1; 78 | k1 = k4; 79 | k2 = k4 << 1; 80 | k3 = k2 + k1; 81 | k4 = k2 << 1; 82 | fi = fz; 83 | gi = fi + kx; 84 | do { 85 | FLOAT f0, f1, f2, f3; 86 | f1 = fi[0] - fi[k1]; 87 | f0 = fi[0] + fi[k1]; 88 | f3 = fi[k2] - fi[k3]; 89 | f2 = fi[k2] + fi[k3]; 90 | fi[k2] = f0 - f2; 91 | fi[0] = f0 + f2; 92 | fi[k3] = f1 - f3; 93 | fi[k1] = f1 + f3; 94 | f1 = gi[0] - gi[k1]; 95 | f0 = gi[0] + gi[k1]; 96 | f3 = SQRT2 * gi[k3]; 97 | f2 = SQRT2 * gi[k2]; 98 | gi[k2] = f0 - f2; 99 | gi[0] = f0 + f2; 100 | gi[k3] = f1 - f3; 101 | gi[k1] = f1 + f3; 102 | gi += k4; 103 | fi += k4; 104 | } while (fi < fn); 105 | c1 = tri[0]; 106 | s1 = tri[1]; 107 | for (i = 1; i < kx; i++) { 108 | FLOAT c2, s2; 109 | c2 = 1 - (2 * s1) * s1; 110 | s2 = (2 * s1) * c1; 111 | fi = fz + i; 112 | gi = fz + k1 - i; 113 | do { 114 | FLOAT a, b, g0, f0, f1, g1, f2, g2, f3, g3; 115 | b = s2 * fi[k1] - c2 * gi[k1]; 116 | a = c2 * fi[k1] + s2 * gi[k1]; 117 | f1 = fi[0] - a; 118 | f0 = fi[0] + a; 119 | g1 = gi[0] - b; 120 | g0 = gi[0] + b; 121 | b = s2 * fi[k3] - c2 * gi[k3]; 122 | a = c2 * fi[k3] + s2 * gi[k3]; 123 | f3 = fi[k2] - a; 124 | f2 = fi[k2] + a; 125 | g3 = gi[k2] - b; 126 | g2 = gi[k2] + b; 127 | b = s1 * f2 - c1 * g3; 128 | a = c1 * f2 + s1 * g3; 129 | fi[k2] = f0 - a; 130 | fi[0] = f0 + a; 131 | gi[k3] = g1 - b; 132 | gi[k1] = g1 + b; 133 | b = c1 * g2 - s1 * f3; 134 | a = s1 * g2 + c1 * f3; 135 | gi[k2] = g0 - a; 136 | gi[0] = g0 + a; 137 | fi[k3] = f1 - b; 138 | fi[k1] = f1 + b; 139 | gi += k4; 140 | fi += k4; 141 | } while (fi < fn); 142 | c2 = c1; 143 | c1 = c2 * tri[0] - s1 * tri[1]; 144 | s1 = c2 * tri[1] + s1 * tri[0]; 145 | } 146 | tri += 2; 147 | } while (k4 < n); 148 | } 149 | 150 | 151 | static const unsigned char rv_tbl[] = { 152 | 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 153 | 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 154 | 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 155 | 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 156 | 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 157 | 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 158 | 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 159 | 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 160 | 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 161 | 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 162 | 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 163 | 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 164 | 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 165 | 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 166 | 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 167 | 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe 168 | }; 169 | 170 | #define ch01(index) (buffer[chn][index]) 171 | 172 | #define ml00(f) (window[i ] * f(i)) 173 | #define ml10(f) (window[i + 0x200] * f(i + 0x200)) 174 | #define ml20(f) (window[i + 0x100] * f(i + 0x100)) 175 | #define ml30(f) (window[i + 0x300] * f(i + 0x300)) 176 | 177 | #define ml01(f) (window[i + 0x001] * f(i + 0x001)) 178 | #define ml11(f) (window[i + 0x201] * f(i + 0x201)) 179 | #define ml21(f) (window[i + 0x101] * f(i + 0x101)) 180 | #define ml31(f) (window[i + 0x301] * f(i + 0x301)) 181 | 182 | #define ms00(f) (window_s[i ] * f(i + k)) 183 | #define ms10(f) (window_s[0x7f - i] * f(i + k + 0x80)) 184 | #define ms20(f) (window_s[i + 0x40] * f(i + k + 0x40)) 185 | #define ms30(f) (window_s[0x3f - i] * f(i + k + 0xc0)) 186 | 187 | #define ms01(f) (window_s[i + 0x01] * f(i + k + 0x01)) 188 | #define ms11(f) (window_s[0x7e - i] * f(i + k + 0x81)) 189 | #define ms21(f) (window_s[i + 0x41] * f(i + k + 0x41)) 190 | #define ms31(f) (window_s[0x3e - i] * f(i + k + 0xc1)) 191 | 192 | 193 | void 194 | fft_short(lame_internal_flags const *const gfc, 195 | FLOAT x_real[3][BLKSIZE_s], int chn, const sample_t *const buffer[2]) 196 | { 197 | int i; 198 | int j; 199 | int b; 200 | 201 | for (b = 0; b < 3; b++) { 202 | FLOAT *x = &x_real[b][BLKSIZE_s / 2]; 203 | short const k = (576 / 3) * (b + 1); 204 | j = BLKSIZE_s / 8 - 1; 205 | do { 206 | FLOAT f0, f1, f2, f3, w; 207 | 208 | i = rv_tbl[j << 2]; 209 | 210 | f0 = ms00(ch01); 211 | w = ms10(ch01); 212 | f1 = f0 - w; 213 | f0 = f0 + w; 214 | f2 = ms20(ch01); 215 | w = ms30(ch01); 216 | f3 = f2 - w; 217 | f2 = f2 + w; 218 | 219 | x -= 4; 220 | x[0] = f0 + f2; 221 | x[2] = f0 - f2; 222 | x[1] = f1 + f3; 223 | x[3] = f1 - f3; 224 | 225 | f0 = ms01(ch01); 226 | w = ms11(ch01); 227 | f1 = f0 - w; 228 | f0 = f0 + w; 229 | f2 = ms21(ch01); 230 | w = ms31(ch01); 231 | f3 = f2 - w; 232 | f2 = f2 + w; 233 | 234 | x[BLKSIZE_s / 2 + 0] = f0 + f2; 235 | x[BLKSIZE_s / 2 + 2] = f0 - f2; 236 | x[BLKSIZE_s / 2 + 1] = f1 + f3; 237 | x[BLKSIZE_s / 2 + 3] = f1 - f3; 238 | } while (--j >= 0); 239 | 240 | gfc->fft_fht(x, BLKSIZE_s / 2); 241 | /* BLKSIZE_s/2 because of 3DNow! ASM routine */ 242 | } 243 | } 244 | 245 | void 246 | fft_long(lame_internal_flags const *const gfc, 247 | FLOAT x[BLKSIZE], int chn, const sample_t *const buffer[2]) 248 | { 249 | int i; 250 | int jj = BLKSIZE / 8 - 1; 251 | x += BLKSIZE / 2; 252 | 253 | do { 254 | FLOAT f0, f1, f2, f3, w; 255 | 256 | i = rv_tbl[jj]; 257 | f0 = ml00(ch01); 258 | w = ml10(ch01); 259 | f1 = f0 - w; 260 | f0 = f0 + w; 261 | f2 = ml20(ch01); 262 | w = ml30(ch01); 263 | f3 = f2 - w; 264 | f2 = f2 + w; 265 | 266 | x -= 4; 267 | x[0] = f0 + f2; 268 | x[2] = f0 - f2; 269 | x[1] = f1 + f3; 270 | x[3] = f1 - f3; 271 | 272 | f0 = ml01(ch01); 273 | w = ml11(ch01); 274 | f1 = f0 - w; 275 | f0 = f0 + w; 276 | f2 = ml21(ch01); 277 | w = ml31(ch01); 278 | f3 = f2 - w; 279 | f2 = f2 + w; 280 | 281 | x[BLKSIZE / 2 + 0] = f0 + f2; 282 | x[BLKSIZE / 2 + 2] = f0 - f2; 283 | x[BLKSIZE / 2 + 1] = f1 + f3; 284 | x[BLKSIZE / 2 + 3] = f1 - f3; 285 | } while (--jj >= 0); 286 | 287 | gfc->fft_fht(x, BLKSIZE / 2); 288 | /* BLKSIZE/2 because of 3DNow! ASM routine */ 289 | } 290 | 291 | #ifdef HAVE_NASM 292 | extern void fht_3DN(FLOAT * fz, int n); 293 | extern void fht_SSE(FLOAT * fz, int n); 294 | #endif 295 | 296 | void 297 | init_fft(lame_internal_flags * const gfc) 298 | { 299 | int i; 300 | 301 | /* The type of window used here will make no real difference, but */ 302 | /* in the interest of merging nspsytune stuff - switch to blackman window */ 303 | for (i = 0; i < BLKSIZE; i++) 304 | /* blackman window */ 305 | window[i] = 0.42 - 0.5 * cos(2 * PI * (i + .5) / BLKSIZE) + 306 | 0.08 * cos(4 * PI * (i + .5) / BLKSIZE); 307 | 308 | for (i = 0; i < BLKSIZE_s / 2; i++) 309 | window_s[i] = 0.5 * (1.0 - cos(2.0 * PI * (i + 0.5) / BLKSIZE_s)); 310 | 311 | gfc->fft_fht = fht; 312 | #ifdef HAVE_NASM 313 | if (gfc->CPU_features.AMD_3DNow) { 314 | gfc->fft_fht = fht_3DN; 315 | } 316 | else if (gfc->CPU_features.SSE) { 317 | gfc->fft_fht = fht_SSE; 318 | } 319 | else { 320 | gfc->fft_fht = fht; 321 | } 322 | #else 323 | #ifdef HAVE_XMMINTRIN_H 324 | #ifdef MIN_ARCH_SSE 325 | gfc->fft_fht = fht_SSE2; 326 | #endif 327 | #endif 328 | #endif 329 | } 330 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/gain_analysis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ReplayGainAnalysis - analyzes input samples and give the recommended dB change 3 | * Copyright (C) 2001 David Robinson and Glen Sawyer 4 | * Improvements and optimizations added by Frank Klemm, and by Marcel Muller 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 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 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser 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 | * concept and filter values by David Robinson (David@Robinson.org) 21 | * -- blame him if you think the idea is flawed 22 | * original coding by Glen Sawyer (mp3gain@hotmail.com) 23 | * -- blame him if you think this runs too slowly, or the coding is otherwise flawed 24 | * 25 | * lots of code improvements by Frank Klemm ( http://www.uni-jena.de/~pfk/mpp/ ) 26 | * -- credit him for all the _good_ programming ;) 27 | * 28 | * 29 | * For an explanation of the concepts and the basic algorithms involved, go to: 30 | * http://www.replaygain.org/ 31 | */ 32 | 33 | /* 34 | * Here's the deal. Call 35 | * 36 | * InitGainAnalysis ( long samplefreq ); 37 | * 38 | * to initialize everything. Call 39 | * 40 | * AnalyzeSamples ( const Float_t* left_samples, 41 | * const Float_t* right_samples, 42 | * size_t num_samples, 43 | * int num_channels ); 44 | * 45 | * as many times as you want, with as many or as few samples as you want. 46 | * If mono, pass the sample buffer in through left_samples, leave 47 | * right_samples NULL, and make sure num_channels = 1. 48 | * 49 | * GetTitleGain() 50 | * 51 | * will return the recommended dB level change for all samples analyzed 52 | * SINCE THE LAST TIME you called GetTitleGain() OR InitGainAnalysis(). 53 | * 54 | * GetAlbumGain() 55 | * 56 | * will return the recommended dB level change for all samples analyzed 57 | * since InitGainAnalysis() was called and finalized with GetTitleGain(). 58 | * 59 | * Pseudo-code to process an album: 60 | * 61 | * Float_t l_samples [4096]; 62 | * Float_t r_samples [4096]; 63 | * size_t num_samples; 64 | * unsigned int num_songs; 65 | * unsigned int i; 66 | * 67 | * InitGainAnalysis ( 44100 ); 68 | * for ( i = 1; i <= num_songs; i++ ) { 69 | * while ( ( num_samples = getSongSamples ( song[i], left_samples, right_samples ) ) > 0 ) 70 | * AnalyzeSamples ( left_samples, right_samples, num_samples, 2 ); 71 | * fprintf ("Recommended dB change for song %2d: %+6.2f dB\n", i, GetTitleGain() ); 72 | * } 73 | * fprintf ("Recommended dB change for whole album: %+6.2f dB\n", GetAlbumGain() ); 74 | */ 75 | 76 | /* 77 | * So here's the main source of potential code confusion: 78 | * 79 | * The filters applied to the incoming samples are IIR filters, 80 | * meaning they rely on up to number of previous samples 81 | * AND up to number of previous filtered samples. 82 | * 83 | * I set up the AnalyzeSamples routine to minimize memory usage and interface 84 | * complexity. The speed isn't compromised too much (I don't think), but the 85 | * internal complexity is higher than it should be for such a relatively 86 | * simple routine. 87 | * 88 | * Optimization/clarity suggestions are welcome. 89 | */ 90 | 91 | #ifdef HAVE_CONFIG_H 92 | #include 93 | #endif 94 | 95 | #include 96 | #include 97 | #include 98 | 99 | #include "lame.h" 100 | #include "machine.h" 101 | #include "gain_analysis.h" 102 | 103 | /* for each filter: */ 104 | /* [0] 48 kHz, [1] 44.1 kHz, [2] 32 kHz, [3] 24 kHz, [4] 22050 Hz, [5] 16 kHz, [6] 12 kHz, [7] is 11025 Hz, [8] 8 kHz */ 105 | 106 | #ifdef WIN32 107 | #pragma warning ( disable : 4305 ) 108 | #endif 109 | 110 | /*lint -save -e736 loss of precision */ 111 | static const Float_t ABYule[9][2 * YULE_ORDER + 1] = { 112 | {0.03857599435200, -3.84664617118067, -0.02160367184185, 7.81501653005538, -0.00123395316851, 113 | -11.34170355132042, -0.00009291677959, 13.05504219327545, -0.01655260341619, 114 | -12.28759895145294, 0.02161526843274, 9.48293806319790, -0.02074045215285, -5.87257861775999, 115 | 0.00594298065125, 2.75465861874613, 0.00306428023191, -0.86984376593551, 0.00012025322027, 116 | 0.13919314567432, 0.00288463683916}, 117 | {0.05418656406430, -3.47845948550071, -0.02911007808948, 6.36317777566148, -0.00848709379851, 118 | -8.54751527471874, -0.00851165645469, 9.47693607801280, -0.00834990904936, -8.81498681370155, 119 | 0.02245293253339, 6.85401540936998, -0.02596338512915, -4.39470996079559, 0.01624864962975, 120 | 2.19611684890774, -0.00240879051584, -0.75104302451432, 0.00674613682247, 0.13149317958808, 121 | -0.00187763777362}, 122 | {0.15457299681924, -2.37898834973084, -0.09331049056315, 2.84868151156327, -0.06247880153653, 123 | -2.64577170229825, 0.02163541888798, 2.23697657451713, -0.05588393329856, -1.67148153367602, 124 | 0.04781476674921, 1.00595954808547, 0.00222312597743, -0.45953458054983, 0.03174092540049, 125 | 0.16378164858596, -0.01390589421898, -0.05032077717131, 0.00651420667831, 0.02347897407020, 126 | -0.00881362733839}, 127 | {0.30296907319327, -1.61273165137247, -0.22613988682123, 1.07977492259970, -0.08587323730772, 128 | -0.25656257754070, 0.03282930172664, -0.16276719120440, -0.00915702933434, -0.22638893773906, 129 | -0.02364141202522, 0.39120800788284, -0.00584456039913, -0.22138138954925, 0.06276101321749, 130 | 0.04500235387352, -0.00000828086748, 0.02005851806501, 0.00205861885564, 0.00302439095741, 131 | -0.02950134983287}, 132 | {0.33642304856132, -1.49858979367799, -0.25572241425570, 0.87350271418188, -0.11828570177555, 133 | 0.12205022308084, 0.11921148675203, -0.80774944671438, -0.07834489609479, 0.47854794562326, 134 | -0.00469977914380, -0.12453458140019, -0.00589500224440, -0.04067510197014, 0.05724228140351, 135 | 0.08333755284107, 0.00832043980773, -0.04237348025746, -0.01635381384540, 0.02977207319925, 136 | -0.01760176568150}, 137 | {0.44915256608450, -0.62820619233671, -0.14351757464547, 0.29661783706366, -0.22784394429749, 138 | -0.37256372942400, -0.01419140100551, 0.00213767857124, 0.04078262797139, -0.42029820170918, 139 | -0.12398163381748, 0.22199650564824, 0.04097565135648, 0.00613424350682, 0.10478503600251, 140 | 0.06747620744683, -0.01863887810927, 0.05784820375801, -0.03193428438915, 0.03222754072173, 141 | 0.00541907748707}, 142 | {0.56619470757641, -1.04800335126349, -0.75464456939302, 0.29156311971249, 0.16242137742230, 143 | -0.26806001042947, 0.16744243493672, 0.00819999645858, -0.18901604199609, 0.45054734505008, 144 | 0.30931782841830, -0.33032403314006, -0.27562961986224, 0.06739368333110, 0.00647310677246, 145 | -0.04784254229033, 0.08647503780351, 0.01639907836189, -0.03788984554840, 0.01807364323573, 146 | -0.00588215443421}, 147 | {0.58100494960553, -0.51035327095184, -0.53174909058578, -0.31863563325245, -0.14289799034253, 148 | -0.20256413484477, 0.17520704835522, 0.14728154134330, 0.02377945217615, 0.38952639978999, 149 | 0.15558449135573, -0.23313271880868, -0.25344790059353, -0.05246019024463, 0.01628462406333, 150 | -0.02505961724053, 0.06920467763959, 0.02442357316099, -0.03721611395801, 0.01818801111503, 151 | -0.00749618797172}, 152 | {0.53648789255105, -0.25049871956020, -0.42163034350696, -0.43193942311114, -0.00275953611929, 153 | -0.03424681017675, 0.04267842219415, -0.04678328784242, -0.10214864179676, 0.26408300200955, 154 | 0.14590772289388, 0.15113130533216, -0.02459864859345, -0.17556493366449, -0.11202315195388, 155 | -0.18823009262115, -0.04060034127000, 0.05477720428674, 0.04788665548180, 0.04704409688120, 156 | -0.02217936801134} 157 | }; 158 | 159 | static const Float_t ABButter[9][2 * BUTTER_ORDER + 1] = { 160 | {0.98621192462708, -1.97223372919527, -1.97242384925416, 0.97261396931306, 0.98621192462708}, 161 | {0.98500175787242, -1.96977855582618, -1.97000351574484, 0.97022847566350, 0.98500175787242}, 162 | {0.97938932735214, -1.95835380975398, -1.95877865470428, 0.95920349965459, 0.97938932735214}, 163 | {0.97531843204928, -1.95002759149878, -1.95063686409857, 0.95124613669835, 0.97531843204928}, 164 | {0.97316523498161, -1.94561023566527, -1.94633046996323, 0.94705070426118, 0.97316523498161}, 165 | {0.96454515552826, -1.92783286977036, -1.92909031105652, 0.93034775234268, 0.96454515552826}, 166 | {0.96009142950541, -1.91858953033784, -1.92018285901082, 0.92177618768381, 0.96009142950541}, 167 | {0.95856916599601, -1.91542108074780, -1.91713833199203, 0.91885558323625, 0.95856916599601}, 168 | {0.94597685600279, -1.88903307939452, -1.89195371200558, 0.89487434461664, 0.94597685600279} 169 | }; 170 | 171 | /*lint -restore */ 172 | 173 | #ifdef WIN32 174 | #pragma warning ( default : 4305 ) 175 | #endif 176 | 177 | /* When calling this procedure, make sure that ip[-order] and op[-order] point to real data! */ 178 | 179 | static void 180 | filterYule(const Float_t * input, Float_t * output, size_t nSamples, const Float_t * const kernel) 181 | { 182 | /*register double y; */ 183 | 184 | while (nSamples--) { 185 | *output = 1e-10 /* 1e-10 is a hack to avoid slowdown because of denormals */ 186 | + input[0] * kernel[0] 187 | - output[-1] * kernel[1] 188 | + input[-1] * kernel[2] 189 | - output[-2] * kernel[3] 190 | + input[-2] * kernel[4] 191 | - output[-3] * kernel[5] 192 | + input[-3] * kernel[6] 193 | - output[-4] * kernel[7] 194 | + input[-4] * kernel[8] 195 | - output[-5] * kernel[9] 196 | + input[-5] * kernel[10] 197 | - output[-6] * kernel[11] 198 | + input[-6] * kernel[12] 199 | - output[-7] * kernel[13] 200 | + input[-7] * kernel[14] 201 | - output[-8] * kernel[15] 202 | + input[-8] * kernel[16] 203 | - output[-9] * kernel[17] 204 | + input[-9] * kernel[18] 205 | - output[-10] * kernel[19] 206 | + input[-10] * kernel[20]; 207 | ++output; 208 | ++input; 209 | /* *output++ = (Float_t)y; */ 210 | } 211 | } 212 | 213 | static void 214 | filterButter(const Float_t * input, Float_t * output, size_t nSamples, const Float_t * const kernel) 215 | { /*register double y; */ 216 | 217 | while (nSamples--) { 218 | *output = input[0] * kernel[0] 219 | - output[-1] * kernel[1] 220 | + input[-1] * kernel[2] 221 | - output[-2] * kernel[3] 222 | + input[-2] * kernel[4]; 223 | ++output; 224 | ++input; 225 | /* *output++ = (Float_t)y; */ 226 | } 227 | } 228 | 229 | 230 | 231 | static int ResetSampleFrequency(replaygain_t * rgData, long samplefreq); 232 | 233 | /* returns a INIT_GAIN_ANALYSIS_OK if successful, INIT_GAIN_ANALYSIS_ERROR if not */ 234 | 235 | int 236 | ResetSampleFrequency(replaygain_t * rgData, long samplefreq) 237 | { 238 | int i; 239 | 240 | /* zero out initial values */ 241 | for (i = 0; i < MAX_ORDER; i++) 242 | rgData->linprebuf[i] = rgData->lstepbuf[i] 243 | = rgData->loutbuf[i] 244 | = rgData->rinprebuf[i] 245 | = rgData->rstepbuf[i] 246 | = rgData->routbuf[i] = 0.; 247 | 248 | switch ((int) (samplefreq)) { 249 | case 48000: 250 | rgData->freqindex = 0; 251 | break; 252 | case 44100: 253 | rgData->freqindex = 1; 254 | break; 255 | case 32000: 256 | rgData->freqindex = 2; 257 | break; 258 | case 24000: 259 | rgData->freqindex = 3; 260 | break; 261 | case 22050: 262 | rgData->freqindex = 4; 263 | break; 264 | case 16000: 265 | rgData->freqindex = 5; 266 | break; 267 | case 12000: 268 | rgData->freqindex = 6; 269 | break; 270 | case 11025: 271 | rgData->freqindex = 7; 272 | break; 273 | case 8000: 274 | rgData->freqindex = 8; 275 | break; 276 | default: 277 | return INIT_GAIN_ANALYSIS_ERROR; 278 | } 279 | 280 | rgData->sampleWindow = 281 | (samplefreq * RMS_WINDOW_TIME_NUMERATOR + RMS_WINDOW_TIME_DENOMINATOR - 282 | 1) / RMS_WINDOW_TIME_DENOMINATOR; 283 | 284 | rgData->lsum = 0.; 285 | rgData->rsum = 0.; 286 | rgData->totsamp = 0; 287 | 288 | memset(rgData->A, 0, sizeof(rgData->A)); 289 | 290 | return INIT_GAIN_ANALYSIS_OK; 291 | } 292 | 293 | int 294 | InitGainAnalysis(replaygain_t * rgData, long samplefreq) 295 | { 296 | if (ResetSampleFrequency(rgData, samplefreq) != INIT_GAIN_ANALYSIS_OK) { 297 | return INIT_GAIN_ANALYSIS_ERROR; 298 | } 299 | 300 | rgData->linpre = rgData->linprebuf + MAX_ORDER; 301 | rgData->rinpre = rgData->rinprebuf + MAX_ORDER; 302 | rgData->lstep = rgData->lstepbuf + MAX_ORDER; 303 | rgData->rstep = rgData->rstepbuf + MAX_ORDER; 304 | rgData->lout = rgData->loutbuf + MAX_ORDER; 305 | rgData->rout = rgData->routbuf + MAX_ORDER; 306 | 307 | memset(rgData->B, 0, sizeof(rgData->B)); 308 | 309 | return INIT_GAIN_ANALYSIS_OK; 310 | } 311 | 312 | /* returns GAIN_ANALYSIS_OK if successful, GAIN_ANALYSIS_ERROR if not */ 313 | 314 | static inline double 315 | fsqr(const double d) 316 | { 317 | return d * d; 318 | } 319 | 320 | int 321 | AnalyzeSamples(replaygain_t * rgData, const Float_t * left_samples, const Float_t * right_samples, 322 | size_t num_samples, int num_channels) 323 | { 324 | const Float_t *curleft; 325 | const Float_t *curright; 326 | long batchsamples; 327 | long cursamples; 328 | long cursamplepos; 329 | int i; 330 | 331 | if (num_samples == 0) 332 | return GAIN_ANALYSIS_OK; 333 | 334 | cursamplepos = 0; 335 | batchsamples = (long) num_samples; 336 | 337 | switch (num_channels) { 338 | case 1: 339 | right_samples = left_samples; 340 | break; 341 | case 2: 342 | break; 343 | default: 344 | return GAIN_ANALYSIS_ERROR; 345 | } 346 | 347 | if (num_samples < MAX_ORDER) { 348 | memcpy(rgData->linprebuf + MAX_ORDER, left_samples, num_samples * sizeof(Float_t)); 349 | memcpy(rgData->rinprebuf + MAX_ORDER, right_samples, num_samples * sizeof(Float_t)); 350 | } 351 | else { 352 | memcpy(rgData->linprebuf + MAX_ORDER, left_samples, MAX_ORDER * sizeof(Float_t)); 353 | memcpy(rgData->rinprebuf + MAX_ORDER, right_samples, MAX_ORDER * sizeof(Float_t)); 354 | } 355 | 356 | while (batchsamples > 0) { 357 | cursamples = batchsamples > rgData->sampleWindow - rgData->totsamp ? 358 | rgData->sampleWindow - rgData->totsamp : batchsamples; 359 | if (cursamplepos < MAX_ORDER) { 360 | curleft = rgData->linpre + cursamplepos; 361 | curright = rgData->rinpre + cursamplepos; 362 | if (cursamples > MAX_ORDER - cursamplepos) 363 | cursamples = MAX_ORDER - cursamplepos; 364 | } 365 | else { 366 | curleft = left_samples + cursamplepos; 367 | curright = right_samples + cursamplepos; 368 | } 369 | 370 | YULE_FILTER(curleft, rgData->lstep + rgData->totsamp, cursamples, 371 | ABYule[rgData->freqindex]); 372 | YULE_FILTER(curright, rgData->rstep + rgData->totsamp, cursamples, 373 | ABYule[rgData->freqindex]); 374 | 375 | BUTTER_FILTER(rgData->lstep + rgData->totsamp, rgData->lout + rgData->totsamp, cursamples, 376 | ABButter[rgData->freqindex]); 377 | BUTTER_FILTER(rgData->rstep + rgData->totsamp, rgData->rout + rgData->totsamp, cursamples, 378 | ABButter[rgData->freqindex]); 379 | 380 | curleft = rgData->lout + rgData->totsamp; /* Get the squared values */ 381 | curright = rgData->rout + rgData->totsamp; 382 | 383 | i = cursamples % 8; 384 | while (i--) { 385 | rgData->lsum += fsqr(*curleft++); 386 | rgData->rsum += fsqr(*curright++); 387 | } 388 | i = cursamples / 8; 389 | while (i--) { 390 | rgData->lsum += fsqr(curleft[0]) 391 | + fsqr(curleft[1]) 392 | + fsqr(curleft[2]) 393 | + fsqr(curleft[3]) 394 | + fsqr(curleft[4]) 395 | + fsqr(curleft[5]) 396 | + fsqr(curleft[6]) 397 | + fsqr(curleft[7]); 398 | curleft += 8; 399 | rgData->rsum += fsqr(curright[0]) 400 | + fsqr(curright[1]) 401 | + fsqr(curright[2]) 402 | + fsqr(curright[3]) 403 | + fsqr(curright[4]) 404 | + fsqr(curright[5]) 405 | + fsqr(curright[6]) 406 | + fsqr(curright[7]); 407 | curright += 8; 408 | } 409 | 410 | batchsamples -= cursamples; 411 | cursamplepos += cursamples; 412 | rgData->totsamp += cursamples; 413 | if (rgData->totsamp == rgData->sampleWindow) { /* Get the Root Mean Square (RMS) for this set of samples */ 414 | double const val = 415 | STEPS_per_dB * 10. * log10((rgData->lsum + rgData->rsum) / rgData->totsamp * 0.5 + 416 | 1.e-37); 417 | size_t ival = (val <= 0) ? 0 : (size_t) val; 418 | if (ival >= sizeof(rgData->A) / sizeof(*(rgData->A))) 419 | ival = sizeof(rgData->A) / sizeof(*(rgData->A)) - 1; 420 | rgData->A[ival]++; 421 | rgData->lsum = rgData->rsum = 0.; 422 | memmove(rgData->loutbuf, rgData->loutbuf + rgData->totsamp, 423 | MAX_ORDER * sizeof(Float_t)); 424 | memmove(rgData->routbuf, rgData->routbuf + rgData->totsamp, 425 | MAX_ORDER * sizeof(Float_t)); 426 | memmove(rgData->lstepbuf, rgData->lstepbuf + rgData->totsamp, 427 | MAX_ORDER * sizeof(Float_t)); 428 | memmove(rgData->rstepbuf, rgData->rstepbuf + rgData->totsamp, 429 | MAX_ORDER * sizeof(Float_t)); 430 | rgData->totsamp = 0; 431 | } 432 | if (rgData->totsamp > rgData->sampleWindow) /* somehow I really screwed up: Error in programming! Contact author about totsamp > sampleWindow */ 433 | return GAIN_ANALYSIS_ERROR; 434 | } 435 | if (num_samples < MAX_ORDER) { 436 | memmove(rgData->linprebuf, rgData->linprebuf + num_samples, 437 | (MAX_ORDER - num_samples) * sizeof(Float_t)); 438 | memmove(rgData->rinprebuf, rgData->rinprebuf + num_samples, 439 | (MAX_ORDER - num_samples) * sizeof(Float_t)); 440 | memcpy(rgData->linprebuf + MAX_ORDER - num_samples, left_samples, 441 | num_samples * sizeof(Float_t)); 442 | memcpy(rgData->rinprebuf + MAX_ORDER - num_samples, right_samples, 443 | num_samples * sizeof(Float_t)); 444 | } 445 | else { 446 | memcpy(rgData->linprebuf, left_samples + num_samples - MAX_ORDER, 447 | MAX_ORDER * sizeof(Float_t)); 448 | memcpy(rgData->rinprebuf, right_samples + num_samples - MAX_ORDER, 449 | MAX_ORDER * sizeof(Float_t)); 450 | } 451 | 452 | return GAIN_ANALYSIS_OK; 453 | } 454 | 455 | 456 | static Float_t 457 | analyzeResult(uint32_t const *Array, size_t len) 458 | { 459 | uint32_t elems; 460 | uint32_t upper; 461 | uint32_t sum; 462 | size_t i; 463 | 464 | elems = 0; 465 | for (i = 0; i < len; i++) 466 | elems += Array[i]; 467 | if (elems == 0) 468 | return GAIN_NOT_ENOUGH_SAMPLES; 469 | 470 | upper = (uint32_t) ceil(elems * (1. - RMS_PERCENTILE)); 471 | sum = 0; 472 | for (i = len; i-- > 0;) { 473 | sum += Array[i]; 474 | if (sum >= upper) { 475 | break; 476 | } 477 | } 478 | 479 | return (Float_t) ((Float_t) PINK_REF - (Float_t) i / (Float_t) STEPS_per_dB); 480 | } 481 | 482 | 483 | Float_t 484 | GetTitleGain(replaygain_t * rgData) 485 | { 486 | Float_t retval; 487 | unsigned int i; 488 | 489 | retval = analyzeResult(rgData->A, sizeof(rgData->A) / sizeof(*(rgData->A))); 490 | 491 | for (i = 0; i < sizeof(rgData->A) / sizeof(*(rgData->A)); i++) { 492 | rgData->B[i] += rgData->A[i]; 493 | rgData->A[i] = 0; 494 | } 495 | 496 | for (i = 0; i < MAX_ORDER; i++) 497 | rgData->linprebuf[i] = rgData->lstepbuf[i] 498 | = rgData->loutbuf[i] 499 | = rgData->rinprebuf[i] 500 | = rgData->rstepbuf[i] 501 | = rgData->routbuf[i] = 0.f; 502 | 503 | rgData->totsamp = 0; 504 | rgData->lsum = rgData->rsum = 0.; 505 | return retval; 506 | } 507 | 508 | #if 0 509 | static Float_t GetAlbumGain(replaygain_t const* rgData); 510 | 511 | Float_t 512 | GetAlbumGain(replaygain_t const* rgData) 513 | { 514 | return analyzeResult(rgData->B, sizeof(rgData->B) / sizeof(*(rgData->B))); 515 | } 516 | #endif 517 | 518 | /* end of gain_analysis.c */ 519 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 33 | #else 34 | # ifdef HAVE_STDINT_H 35 | # include 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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | FrameDataNode *v2_head, *v2_tail; 51 | } id3tag_spec; 52 | 53 | 54 | /* write tag into stream at current position */ 55 | extern int id3tag_write_v2(lame_global_flags * gfp); 56 | extern int id3tag_write_v1(lame_global_flags * gfp); 57 | /* 58 | * NOTE: A version 2 tag will NOT be added unless one of the text fields won't 59 | * fit in a version 1 tag (e.g. the title string is longer than 30 characters), 60 | * or the "id3tag_add_v2" or "id3tag_v2_only" functions are used. 61 | */ 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/lame_global_flags.h: -------------------------------------------------------------------------------- 1 | #ifndef LAME_GLOBAL_FLAGS_H 2 | #define LAME_GLOBAL_FLAGS_H 3 | 4 | #ifndef lame_internal_flags_defined 5 | #define lame_internal_flags_defined 6 | struct lame_internal_flags; 7 | typedef struct lame_internal_flags lame_internal_flags; 8 | #endif 9 | 10 | 11 | typedef enum short_block_e { 12 | short_block_not_set = -1, /* allow LAME to decide */ 13 | short_block_allowed = 0, /* LAME may use them, even different block types for L/R */ 14 | short_block_coupled, /* LAME may use them, but always same block types in L/R */ 15 | short_block_dispensed, /* LAME will not use short blocks, long blocks only */ 16 | short_block_forced /* LAME will not use long blocks, short blocks only */ 17 | } short_block_t; 18 | 19 | /*********************************************************************** 20 | * 21 | * Control Parameters set by User. These parameters are here for 22 | * backwards compatibility with the old, non-shared lib API. 23 | * Please use the lame_set_variablename() functions below 24 | * 25 | * 26 | ***********************************************************************/ 27 | struct lame_global_struct { 28 | unsigned int class_id; 29 | 30 | /* input description */ 31 | unsigned long num_samples; /* number of samples. default=2^32-1 */ 32 | int num_channels; /* input number of channels. default=2 */ 33 | int samplerate_in; /* input_samp_rate in Hz. default=44.1 kHz */ 34 | int samplerate_out; /* output_samp_rate. 35 | default: LAME picks best value 36 | at least not used for MP3 decoding: 37 | Remember 44.1 kHz MP3s and AC97 */ 38 | float scale; /* scale input by this amount before encoding 39 | at least not used for MP3 decoding */ 40 | float scale_left; /* scale input of channel 0 (left) by this 41 | amount before encoding */ 42 | float scale_right; /* scale input of channel 1 (right) by this 43 | amount before encoding */ 44 | 45 | /* general control params */ 46 | int analysis; /* collect data for a MP3 frame analyzer? */ 47 | int write_lame_tag; /* add Xing VBR tag? */ 48 | int decode_only; /* use lame/mpglib to convert mp3 to wav */ 49 | int quality; /* quality setting 0=best, 9=worst default=5 */ 50 | MPEG_mode mode; /* see enum in lame.h 51 | default = LAME picks best value */ 52 | int force_ms; /* force M/S mode. requires mode=1 */ 53 | int free_format; /* use free format? default=0 */ 54 | int findReplayGain; /* find the RG value? default=0 */ 55 | int decode_on_the_fly; /* decode on the fly? default=0 */ 56 | int write_id3tag_automatic; /* 1 (default) writes ID3 tags, 0 not */ 57 | 58 | int nogap_total; 59 | int nogap_current; 60 | 61 | int substep_shaping; 62 | int noise_shaping; 63 | int subblock_gain; /* 0 = no, 1 = yes */ 64 | int use_best_huffman; /* 0 = no. 1=outside loop 2=inside loop(slow) */ 65 | 66 | /* 67 | * set either brate>0 or compression_ratio>0, LAME will compute 68 | * the value of the variable not set. 69 | * Default is compression_ratio = 11.025 70 | */ 71 | int brate; /* bitrate */ 72 | float compression_ratio; /* sizeof(wav file)/sizeof(mp3 file) */ 73 | 74 | 75 | /* frame params */ 76 | int copyright; /* mark as copyright. default=0 */ 77 | int original; /* mark as original. default=1 */ 78 | int extension; /* the MP3 'private extension' bit. 79 | Meaningless */ 80 | int emphasis; /* Input PCM is emphased PCM (for 81 | instance from one of the rarely 82 | emphased CDs), it is STRONGLY not 83 | recommended to use this, because 84 | psycho does not take it into account, 85 | and last but not least many decoders 86 | don't care about these bits */ 87 | int error_protection; /* use 2 bytes per frame for a CRC 88 | checksum. default=0 */ 89 | int strict_ISO; /* enforce ISO spec as much as possible */ 90 | 91 | int disable_reservoir; /* use bit reservoir? */ 92 | 93 | /* quantization/noise shaping */ 94 | int quant_comp; 95 | int quant_comp_short; 96 | int experimentalY; 97 | int experimentalZ; 98 | int exp_nspsytune; 99 | 100 | int preset; 101 | 102 | /* VBR control */ 103 | vbr_mode VBR; 104 | float VBR_q_frac; /* Range [0,...,1[ */ 105 | int VBR_q; /* Range [0,...,9] */ 106 | int VBR_mean_bitrate_kbps; 107 | int VBR_min_bitrate_kbps; 108 | int VBR_max_bitrate_kbps; 109 | int VBR_hard_min; /* strictly enforce VBR_min_bitrate 110 | normaly, it will be violated for analog 111 | silence */ 112 | 113 | 114 | /* resampling and filtering */ 115 | int lowpassfreq; /* freq in Hz. 0=lame choses. 116 | -1=no filter */ 117 | int highpassfreq; /* freq in Hz. 0=lame choses. 118 | -1=no filter */ 119 | int lowpasswidth; /* freq width of filter, in Hz 120 | (default=15%) */ 121 | int highpasswidth; /* freq width of filter, in Hz 122 | (default=15%) */ 123 | 124 | 125 | 126 | /* 127 | * psycho acoustics and other arguments which you should not change 128 | * unless you know what you are doing 129 | */ 130 | float maskingadjust; 131 | float maskingadjust_short; 132 | int ATHonly; /* only use ATH */ 133 | int ATHshort; /* only use ATH for short blocks */ 134 | int noATH; /* disable ATH */ 135 | int ATHtype; /* select ATH formula */ 136 | float ATHcurve; /* change ATH formula 4 shape */ 137 | float ATH_lower_db; /* lower ATH by this many db */ 138 | int athaa_type; /* select ATH auto-adjust scheme */ 139 | float athaa_sensitivity; /* dB, tune active region of auto-level */ 140 | short_block_t short_blocks; 141 | int useTemporal; /* use temporal masking effect */ 142 | float interChRatio; 143 | float msfix; /* Naoki's adjustment of Mid/Side maskings */ 144 | 145 | int tune; /* 0 off, 1 on */ 146 | float tune_value_a; /* used to pass values for debugging and stuff */ 147 | 148 | float attackthre; /* attack threshold for L/R/M channel */ 149 | float attackthre_s; /* attack threshold for S channel */ 150 | 151 | 152 | struct { 153 | void (*msgf) (const char *format, va_list ap); 154 | void (*debugf) (const char *format, va_list ap); 155 | void (*errorf) (const char *format, va_list ap); 156 | } report; 157 | 158 | /************************************************************************/ 159 | /* internal variables, do not set... */ 160 | /* provided because they may be of use to calling application */ 161 | /************************************************************************/ 162 | 163 | int lame_allocated_gfp; /* is this struct owned by calling 164 | program or lame? */ 165 | 166 | 167 | 168 | /**************************************************************************/ 169 | /* more internal variables are stored in this structure: */ 170 | /**************************************************************************/ 171 | lame_internal_flags *internal_flags; 172 | 173 | 174 | struct { 175 | int mmx; 176 | int amd3dnow; 177 | int sse; 178 | 179 | } asm_optimizations; 180 | }; 181 | 182 | int is_lame_global_flags_valid(const lame_global_flags * gfp); 183 | 184 | #endif /* LAME_GLOBAL_FLAGS_H */ 185 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | #if (LAME_RELEASE_VERSION == 0) 28 | #undef NDEBUG 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef STDC_HEADERS 36 | # include 37 | # include 38 | #else 39 | # ifndef HAVE_STRCHR 40 | # define strchr index 41 | # define strrchr rindex 42 | # endif 43 | char *strchr(), *strrchr(); 44 | # ifndef HAVE_MEMCPY 45 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) 46 | # define memmove(d, s, n) bcopy ((s), (d), (n)) 47 | # endif 48 | #endif 49 | 50 | #if defined(__riscos__) && defined(FPA10) 51 | # include "ymath.h" 52 | #else 53 | # include 54 | #endif 55 | #include 56 | 57 | #include 58 | 59 | #ifdef HAVE_ERRNO_H 60 | # include 61 | #endif 62 | #ifdef HAVE_FCNTL_H 63 | # include 64 | #endif 65 | 66 | #if defined(macintosh) 67 | # include 68 | # include 69 | #else 70 | # include 71 | # include 72 | #endif 73 | 74 | #ifdef HAVE_INTTYPES_H 75 | # include 76 | #else 77 | # ifdef HAVE_STDINT_H 78 | # include 79 | # endif 80 | #endif 81 | 82 | #ifdef WITH_DMALLOC 83 | #include 84 | #endif 85 | 86 | /* 87 | * 3 different types of pow() functions: 88 | * - table lookup 89 | * - pow() 90 | * - exp() on some machines this is claimed to be faster than pow() 91 | */ 92 | 93 | #define POW20(x) (assert(0 <= (x+Q_MAX2) && x < Q_MAX), pow20[x+Q_MAX2]) 94 | /*#define POW20(x) pow(2.0,((double)(x)-210)*.25) */ 95 | /*#define POW20(x) exp( ((double)(x)-210)*(.25*LOG2) ) */ 96 | 97 | #define IPOW20(x) (assert(0 <= x && x < Q_MAX), ipow20[x]) 98 | /*#define IPOW20(x) exp( -((double)(x)-210)*.1875*LOG2 ) */ 99 | /*#define IPOW20(x) pow(2.0,-((double)(x)-210)*.1875) */ 100 | 101 | /* in case this is used without configure */ 102 | #ifndef inline 103 | # define inline 104 | #endif 105 | 106 | #if defined(_MSC_VER) 107 | # undef inline 108 | # define inline _inline 109 | #elif defined(__SASC) || defined(__GNUC__) || defined(__ICC) || defined(__ECC) 110 | /* if __GNUC__ we always want to inline, not only if the user requests it */ 111 | # undef inline 112 | # define inline __inline 113 | #endif 114 | 115 | #if defined(_MSC_VER) 116 | # pragma warning( disable : 4244 ) 117 | /*# pragma warning( disable : 4305 ) */ 118 | #endif 119 | 120 | /* 121 | * FLOAT for variables which require at least 32 bits 122 | * FLOAT8 for variables which require at least 64 bits 123 | * 124 | * On some machines, 64 bit will be faster than 32 bit. Also, some math 125 | * routines require 64 bit float, so setting FLOAT=float will result in a 126 | * lot of conversions. 127 | */ 128 | 129 | #if ( defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) ) 130 | # define WIN32_LEAN_AND_MEAN 131 | # include 132 | # include 133 | # define FLOAT_MAX FLT_MAX 134 | #else 135 | # ifndef FLOAT 136 | typedef float FLOAT; 137 | # ifdef FLT_MAX 138 | # define FLOAT_MAX FLT_MAX 139 | # else 140 | # define FLOAT_MAX 1e37 /* approx */ 141 | # endif 142 | # endif 143 | #endif 144 | 145 | #ifndef FLOAT8 146 | typedef double FLOAT8; 147 | # ifdef DBL_MAX 148 | # define FLOAT8_MAX DBL_MAX 149 | # else 150 | # define FLOAT8_MAX 1e99 /* approx */ 151 | # endif 152 | #else 153 | # ifdef FLT_MAX 154 | # define FLOAT8_MAX FLT_MAX 155 | # else 156 | # define FLOAT8_MAX 1e37 /* approx */ 157 | # endif 158 | #endif 159 | 160 | /* sample_t must be floating point, at least 32 bits */ 161 | typedef FLOAT sample_t; 162 | 163 | #define dimension_of(array) (sizeof(array)/sizeof(array[0])) 164 | #define beyond(array) (array+dimension_of(array)) 165 | #define compiletime_assert(expression) extern char static_assert_##FILE##_##LINE[expression?1:0] 166 | 167 | #if 1 168 | #define EQ(a,b) (\ 169 | (fabs(a) > fabs(b)) \ 170 | ? (fabs((a)-(b)) <= (fabs(a) * 1e-6f)) \ 171 | : (fabs((a)-(b)) <= (fabs(b) * 1e-6f))) 172 | #else 173 | #define EQ(a,b) (fabs((a)-(b))<1E-37) 174 | #endif 175 | 176 | #define NEQ(a,b) (!EQ(a,b)) 177 | 178 | #endif 179 | 180 | #ifdef _MSC_VER 181 | # if _MSC_VER < 1400 182 | # define fabsf fabs 183 | # define powf pow 184 | # define log10f log10 185 | # endif 186 | #endif 187 | 188 | 189 | /* end of machine.h */ 190 | -------------------------------------------------------------------------------- /lame/src/main/jni/mobi_cangol_mobile_utils_LameUtils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "lame.h" 6 | 7 | #define LOG_TAG "LAME ENCODER" 8 | #define LOGD(format, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, format, ##args); 9 | #define BUFFER_SIZE 8192 10 | #define be_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8)) 11 | 12 | lame_t lame; 13 | 14 | int read_samples(FILE *input_file, short *input) { 15 | int nb_read; 16 | nb_read = fread(input, 1, sizeof(short), input_file) / sizeof(short); 17 | int i = 0; 18 | while (i < nb_read) { 19 | input[i] = be_short(input[i]); 20 | i++; 21 | } 22 | 23 | return nb_read; 24 | } 25 | 26 | void Java_mobi_cangol_mobile_utils_LameUtils_initEncoder(JNIEnv *env, 27 | jobject jobj, jint in_num_channels, jint in_samplerate, jint in_brate, 28 | jint in_mode, jint in_quality) { 29 | lame = lame_init(); 30 | 31 | LOGD("Init parameters:",NULL); 32 | lame_set_num_channels(lame, in_num_channels); 33 | LOGD("Number of channels: %d", in_num_channels); 34 | lame_set_in_samplerate(lame, in_samplerate); 35 | LOGD("Sample rate: %d", in_samplerate); 36 | lame_set_brate(lame, in_brate); 37 | LOGD("Bitrate: %d", in_brate); 38 | lame_set_mode(lame, in_mode); 39 | LOGD("Mode: %d", in_mode); 40 | lame_set_quality(lame, in_quality); 41 | LOGD("Quality: %d", in_quality); 42 | 43 | int res = lame_init_params(lame); 44 | LOGD("Init returned: %d", res); 45 | } 46 | 47 | void Java_mobi_cangol_mobile_utils_LameUtils_destroyEncoder( 48 | JNIEnv *env, jobject jobj) { 49 | int res = lame_close(lame); 50 | LOGD("Deinit returned: %d", res); 51 | } 52 | void Java_mobi_cangol_mobile_utils_LameUtils_encodeFile(JNIEnv *env, 53 | jobject jobj, jstring in_source_path, jstring in_target_path) { 54 | const char *source_path, *target_path; 55 | source_path = (*env)->GetStringUTFChars(env, in_source_path, NULL); 56 | target_path = (*env)->GetStringUTFChars(env, in_target_path, NULL); 57 | 58 | FILE *input_file, *output_file; 59 | input_file = fopen(source_path, "rb"); 60 | output_file = fopen(target_path, "wb"); 61 | 62 | short input[BUFFER_SIZE]; 63 | char output[BUFFER_SIZE]; 64 | int nb_read = 0; 65 | int nb_write = 0; 66 | int nb_total = 0; 67 | 68 | LOGD("Encoding started",NULL); 69 | while (nb_read = read_samples(input_file, input)) { 70 | nb_write = lame_encode_buffer(lame, input, input, nb_read, output, 71 | BUFFER_SIZE); 72 | fwrite(output, nb_write, 1, output_file); 73 | nb_total += nb_write; 74 | } 75 | LOGD("Encoded %d bytes", nb_total); 76 | 77 | nb_write = lame_encode_flush(lame, output, BUFFER_SIZE); 78 | fwrite(output, nb_write, 1, output_file); 79 | LOGD("Flushed %d bytes", nb_write); 80 | 81 | fclose(input_file); 82 | fclose(output_file); 83 | } 84 | jstring Java_mobi_cangol_mobile_utils_LameUtils_getVersion(JNIEnv *env, jobject instance) { 85 | 86 | return (*env)->NewStringUTF(env, get_lame_version()); 87 | } 88 | 89 | jstring 90 | Java_mobi_cangol_mobile_utils_LameUtils_getSystemABI(JNIEnv *env, 91 | jobject thiz) { 92 | #if defined(__arm__) 93 | #if defined(__ARM_ARCH_7A__) 94 | #if defined(__ARM_NEON__) 95 | #if defined(__ARM_PCS_VFP) 96 | #define ABI "armeabi-v7a/NEON (hard-float)" 97 | #else 98 | #define ABI "armeabi-v7a/NEON" 99 | #endif 100 | #else 101 | #if defined(__ARM_PCS_VFP) 102 | #define ABI "armeabi-v7a (hard-float)" 103 | #else 104 | #define ABI "armeabi-v7a" 105 | #endif 106 | #endif 107 | #else 108 | #define ABI "armeabi" 109 | #endif 110 | #elif defined(__i386__) 111 | #define ABI "x86" 112 | #elif defined(__x86_64__) 113 | #define ABI "x86_64" 114 | #elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */ 115 | #define ABI "mips64" 116 | #elif defined(__mips__) 117 | #define ABI "mips" 118 | #elif defined(__aarch64__) 119 | #define ABI "arm64-v8a" 120 | #else 121 | #define ABI "unknown" 122 | #endif 123 | 124 | return (*env)->NewStringUTF(env, ABI); 125 | } 126 | -------------------------------------------------------------------------------- /lame/src/main/jni/mpglib_interface.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; mode: fold -*- */ 2 | /* 3 | * LAME MP3 encoding engine 4 | * 5 | * Copyright (c) 1999-2000 Mark Taylor 6 | * Copyright (c) 2003 Olcios 7 | * Copyright (c) 2008 Robert Hegemann 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Library General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Library General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Library General Public 20 | * License along with this library; if not, write to the 21 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 | * Boston, MA 02111-1307, USA. 23 | */ 24 | 25 | /* $Id: mpglib_interface.c,v 1.42 2011/05/07 16:05:17 rbrito Exp $ */ 26 | 27 | #ifdef HAVE_CONFIG_H 28 | # include 29 | #endif 30 | 31 | #ifdef HAVE_MPGLIB 32 | #define hip_global_struct mpstr_tag 33 | #include "lame.h" 34 | #include "machine.h" 35 | #include "encoder.h" 36 | #include "interface.h" 37 | 38 | #include "util.h" 39 | 40 | 41 | 42 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 43 | /* 44 | * OBSOLETE: 45 | * - kept to let it link 46 | * - forward declaration to silence compiler 47 | */ 48 | int CDECL lame_decode_init(void); 49 | int CDECL lame_decode( 50 | unsigned char * mp3buf, 51 | int len, 52 | short pcm_l[], 53 | short pcm_r[] ); 54 | int CDECL lame_decode_headers( 55 | unsigned char* mp3buf, 56 | int len, 57 | short pcm_l[], 58 | short pcm_r[], 59 | mp3data_struct* mp3data ); 60 | int CDECL lame_decode1( 61 | unsigned char* mp3buf, 62 | int len, 63 | short pcm_l[], 64 | short pcm_r[] ); 65 | int CDECL lame_decode1_headers( 66 | unsigned char* mp3buf, 67 | int len, 68 | short pcm_l[], 69 | short pcm_r[], 70 | mp3data_struct* mp3data ); 71 | int CDECL lame_decode1_headersB( 72 | unsigned char* mp3buf, 73 | int len, 74 | short pcm_l[], 75 | short pcm_r[], 76 | mp3data_struct* mp3data, 77 | int *enc_delay, 78 | int *enc_padding ); 79 | int CDECL lame_decode_exit(void); 80 | #endif 81 | 82 | 83 | static MPSTR mp; 84 | 85 | int 86 | lame_decode_exit(void) 87 | { 88 | ExitMP3(&mp); 89 | return 0; 90 | } 91 | 92 | 93 | int 94 | lame_decode_init(void) 95 | { 96 | (void) InitMP3(&mp); 97 | return 0; 98 | } 99 | 100 | 101 | 102 | 103 | /* copy mono samples */ 104 | #define COPY_MONO(DST_TYPE, SRC_TYPE) \ 105 | DST_TYPE *pcm_l = (DST_TYPE *)pcm_l_raw; \ 106 | SRC_TYPE const *p_samples = (SRC_TYPE const *)p; \ 107 | for (i = 0; i < processed_samples; i++) \ 108 | *pcm_l++ = (DST_TYPE)(*p_samples++); 109 | 110 | /* copy stereo samples */ 111 | #define COPY_STEREO(DST_TYPE, SRC_TYPE) \ 112 | DST_TYPE *pcm_l = (DST_TYPE *)pcm_l_raw, *pcm_r = (DST_TYPE *)pcm_r_raw; \ 113 | SRC_TYPE const *p_samples = (SRC_TYPE const *)p; \ 114 | for (i = 0; i < processed_samples; i++) { \ 115 | *pcm_l++ = (DST_TYPE)(*p_samples++); \ 116 | *pcm_r++ = (DST_TYPE)(*p_samples++); \ 117 | } 118 | 119 | 120 | 121 | /* 122 | * For lame_decode: return code 123 | * -1 error 124 | * 0 ok, but need more data before outputing any samples 125 | * n number of samples output. either 576 or 1152 depending on MP3 file. 126 | */ 127 | 128 | static int 129 | decode1_headersB_clipchoice(PMPSTR pmp, unsigned char *buffer, int len, 130 | char pcm_l_raw[], char pcm_r_raw[], mp3data_struct * mp3data, 131 | int *enc_delay, int *enc_padding, 132 | char *p, size_t psize, int decoded_sample_size, 133 | int (*decodeMP3_ptr) (PMPSTR, unsigned char *, int, char *, int, 134 | int *)) 135 | { 136 | static const int smpls[2][4] = { 137 | /* Layer I II III */ 138 | {0, 384, 1152, 1152}, /* MPEG-1 */ 139 | {0, 384, 1152, 576} /* MPEG-2(.5) */ 140 | }; 141 | 142 | int processed_bytes; 143 | int processed_samples; /* processed samples per channel */ 144 | int ret; 145 | int i; 146 | 147 | mp3data->header_parsed = 0; 148 | 149 | ret = (*decodeMP3_ptr) (pmp, buffer, len, p, (int) psize, &processed_bytes); 150 | /* three cases: 151 | * 1. headers parsed, but data not complete 152 | * pmp->header_parsed==1 153 | * pmp->framesize=0 154 | * pmp->fsizeold=size of last frame, or 0 if this is first frame 155 | * 156 | * 2. headers, data parsed, but ancillary data not complete 157 | * pmp->header_parsed==1 158 | * pmp->framesize=size of frame 159 | * pmp->fsizeold=size of last frame, or 0 if this is first frame 160 | * 161 | * 3. frame fully decoded: 162 | * pmp->header_parsed==0 163 | * pmp->framesize=0 164 | * pmp->fsizeold=size of frame (which is now the last frame) 165 | * 166 | */ 167 | if (pmp->header_parsed || pmp->fsizeold > 0 || pmp->framesize > 0) { 168 | mp3data->header_parsed = 1; 169 | mp3data->stereo = pmp->fr.stereo; 170 | mp3data->samplerate = freqs[pmp->fr.sampling_frequency]; 171 | mp3data->mode = pmp->fr.mode; 172 | mp3data->mode_ext = pmp->fr.mode_ext; 173 | mp3data->framesize = smpls[pmp->fr.lsf][pmp->fr.lay]; 174 | 175 | /* free format, we need the entire frame before we can determine 176 | * the bitrate. If we haven't gotten the entire frame, bitrate=0 */ 177 | if (pmp->fsizeold > 0) /* works for free format and fixed, no overrun, temporal results are < 400.e6 */ 178 | mp3data->bitrate = 8 * (4 + pmp->fsizeold) * mp3data->samplerate / 179 | (1.e3 * mp3data->framesize) + 0.5; 180 | else if (pmp->framesize > 0) 181 | mp3data->bitrate = 8 * (4 + pmp->framesize) * mp3data->samplerate / 182 | (1.e3 * mp3data->framesize) + 0.5; 183 | else 184 | mp3data->bitrate = tabsel_123[pmp->fr.lsf][pmp->fr.lay - 1][pmp->fr.bitrate_index]; 185 | 186 | 187 | 188 | if (pmp->num_frames > 0) { 189 | /* Xing VBR header found and num_frames was set */ 190 | mp3data->totalframes = pmp->num_frames; 191 | mp3data->nsamp = mp3data->framesize * pmp->num_frames; 192 | *enc_delay = pmp->enc_delay; 193 | *enc_padding = pmp->enc_padding; 194 | } 195 | } 196 | 197 | switch (ret) { 198 | case MP3_OK: 199 | switch (pmp->fr.stereo) { 200 | case 1: 201 | processed_samples = processed_bytes / decoded_sample_size; 202 | if (decoded_sample_size == sizeof(short)) { 203 | COPY_MONO(short, short) 204 | } 205 | else { 206 | COPY_MONO(sample_t, FLOAT) 207 | } 208 | break; 209 | case 2: 210 | processed_samples = (processed_bytes / decoded_sample_size) >> 1; 211 | if (decoded_sample_size == sizeof(short)) { 212 | COPY_STEREO(short, short) 213 | } 214 | else { 215 | COPY_STEREO(sample_t, FLOAT) 216 | } 217 | break; 218 | default: 219 | processed_samples = -1; 220 | assert(0); 221 | break; 222 | } 223 | break; 224 | 225 | case MP3_NEED_MORE: 226 | processed_samples = 0; 227 | break; 228 | 229 | case MP3_ERR: 230 | processed_samples = -1; 231 | break; 232 | 233 | default: 234 | processed_samples = -1; 235 | assert(0); 236 | break; 237 | } 238 | 239 | /*fprintf(stderr,"ok, more, err: %i %i %i\n", MP3_OK, MP3_NEED_MORE, MP3_ERR ); */ 240 | /*fprintf(stderr,"ret = %i out=%i\n", ret, processed_samples ); */ 241 | return processed_samples; 242 | } 243 | 244 | 245 | #define OUTSIZE_CLIPPED (4096*sizeof(short)) 246 | 247 | int 248 | lame_decode1_headersB(unsigned char *buffer, 249 | int len, 250 | short pcm_l[], short pcm_r[], mp3data_struct * mp3data, 251 | int *enc_delay, int *enc_padding) 252 | { 253 | static char out[OUTSIZE_CLIPPED]; 254 | 255 | return decode1_headersB_clipchoice(&mp, buffer, len, (char *) pcm_l, (char *) pcm_r, mp3data, 256 | enc_delay, enc_padding, out, OUTSIZE_CLIPPED, 257 | sizeof(short), decodeMP3); 258 | } 259 | 260 | 261 | 262 | 263 | 264 | /* 265 | * For lame_decode: return code 266 | * -1 error 267 | * 0 ok, but need more data before outputing any samples 268 | * n number of samples output. Will be at most one frame of 269 | * MPEG data. 270 | */ 271 | 272 | int 273 | lame_decode1_headers(unsigned char *buffer, 274 | int len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data) 275 | { 276 | int enc_delay, enc_padding; 277 | return lame_decode1_headersB(buffer, len, pcm_l, pcm_r, mp3data, &enc_delay, &enc_padding); 278 | } 279 | 280 | 281 | int 282 | lame_decode1(unsigned char *buffer, int len, short pcm_l[], short pcm_r[]) 283 | { 284 | mp3data_struct mp3data; 285 | 286 | return lame_decode1_headers(buffer, len, pcm_l, pcm_r, &mp3data); 287 | } 288 | 289 | 290 | /* 291 | * For lame_decode: return code 292 | * -1 error 293 | * 0 ok, but need more data before outputing any samples 294 | * n number of samples output. a multiple of 576 or 1152 depending on MP3 file. 295 | */ 296 | 297 | int 298 | lame_decode_headers(unsigned char *buffer, 299 | int len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data) 300 | { 301 | int ret; 302 | int totsize = 0; /* number of decoded samples per channel */ 303 | 304 | for (;;) { 305 | switch (ret = lame_decode1_headers(buffer, len, pcm_l + totsize, pcm_r + totsize, mp3data)) { 306 | case -1: 307 | return ret; 308 | case 0: 309 | return totsize; 310 | default: 311 | totsize += ret; 312 | len = 0; /* future calls to decodeMP3 are just to flush buffers */ 313 | break; 314 | } 315 | } 316 | } 317 | 318 | 319 | int 320 | lame_decode(unsigned char *buffer, int len, short pcm_l[], short pcm_r[]) 321 | { 322 | mp3data_struct mp3data; 323 | 324 | return lame_decode_headers(buffer, len, pcm_l, pcm_r, &mp3data); 325 | } 326 | 327 | 328 | 329 | 330 | hip_t hip_decode_init(void) 331 | { 332 | hip_t hip = calloc(1, sizeof(hip_global_flags)); 333 | InitMP3(hip); 334 | return hip; 335 | } 336 | 337 | 338 | int hip_decode_exit(hip_t hip) 339 | { 340 | if (hip) { 341 | ExitMP3(hip); 342 | free(hip); 343 | } 344 | return 0; 345 | } 346 | 347 | 348 | /* we forbid input with more than 1152 samples per channel for output in the unclipped mode */ 349 | #define OUTSIZE_UNCLIPPED (1152*2*sizeof(FLOAT)) 350 | 351 | int 352 | hip_decode1_unclipped(hip_t hip, unsigned char *buffer, size_t len, sample_t pcm_l[], sample_t pcm_r[]) 353 | { 354 | static char out[OUTSIZE_UNCLIPPED]; 355 | mp3data_struct mp3data; 356 | int enc_delay, enc_padding; 357 | 358 | if (hip) { 359 | return decode1_headersB_clipchoice(hip, buffer, len, (char *) pcm_l, (char *) pcm_r, &mp3data, 360 | &enc_delay, &enc_padding, out, OUTSIZE_UNCLIPPED, 361 | sizeof(FLOAT), decodeMP3_unclipped); 362 | } 363 | return 0; 364 | } 365 | 366 | /* 367 | * For hip_decode: return code 368 | * -1 error 369 | * 0 ok, but need more data before outputing any samples 370 | * n number of samples output. Will be at most one frame of 371 | * MPEG data. 372 | */ 373 | 374 | int 375 | hip_decode1_headers(hip_t hip, unsigned char *buffer, 376 | size_t len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data) 377 | { 378 | int enc_delay, enc_padding; 379 | return hip_decode1_headersB(hip, buffer, len, pcm_l, pcm_r, mp3data, &enc_delay, &enc_padding); 380 | } 381 | 382 | 383 | int 384 | hip_decode1(hip_t hip, unsigned char *buffer, size_t len, short pcm_l[], short pcm_r[]) 385 | { 386 | mp3data_struct mp3data; 387 | return hip_decode1_headers(hip, buffer, len, pcm_l, pcm_r, &mp3data); 388 | } 389 | 390 | 391 | /* 392 | * For hip_decode: return code 393 | * -1 error 394 | * 0 ok, but need more data before outputing any samples 395 | * n number of samples output. a multiple of 576 or 1152 depending on MP3 file. 396 | */ 397 | 398 | int 399 | hip_decode_headers(hip_t hip, unsigned char *buffer, 400 | size_t len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data) 401 | { 402 | int ret; 403 | int totsize = 0; /* number of decoded samples per channel */ 404 | 405 | for (;;) { 406 | switch (ret = hip_decode1_headers(hip, buffer, len, pcm_l + totsize, pcm_r + totsize, mp3data)) { 407 | case -1: 408 | return ret; 409 | case 0: 410 | return totsize; 411 | default: 412 | totsize += ret; 413 | len = 0; /* future calls to decodeMP3 are just to flush buffers */ 414 | break; 415 | } 416 | } 417 | } 418 | 419 | 420 | int 421 | hip_decode(hip_t hip, unsigned char *buffer, size_t len, short pcm_l[], short pcm_r[]) 422 | { 423 | mp3data_struct mp3data; 424 | return hip_decode_headers(hip, buffer, len, pcm_l, pcm_r, &mp3data); 425 | } 426 | 427 | 428 | int 429 | hip_decode1_headersB(hip_t hip, unsigned char *buffer, 430 | size_t len, 431 | short pcm_l[], short pcm_r[], mp3data_struct * mp3data, 432 | int *enc_delay, int *enc_padding) 433 | { 434 | static char out[OUTSIZE_CLIPPED]; 435 | if (hip) { 436 | return decode1_headersB_clipchoice(hip, buffer, len, (char *) pcm_l, (char *) pcm_r, mp3data, 437 | enc_delay, enc_padding, out, OUTSIZE_CLIPPED, 438 | sizeof(short), decodeMP3); 439 | } 440 | return -1; 441 | } 442 | 443 | 444 | void hip_set_pinfo(hip_t hip, plotting_data* pinfo) 445 | { 446 | if (hip) { 447 | hip->pinfo = pinfo; 448 | } 449 | } 450 | 451 | 452 | 453 | void hip_set_errorf(hip_t hip, lame_report_function func) 454 | { 455 | if (hip) { 456 | hip->report_err = func; 457 | } 458 | } 459 | 460 | void hip_set_debugf(hip_t hip, lame_report_function func) 461 | { 462 | if (hip) { 463 | hip->report_dbg = func; 464 | } 465 | } 466 | 467 | void hip_set_msgf (hip_t hip, lame_report_function func) 468 | { 469 | if (hip) { 470 | hip->report_msg = func; 471 | } 472 | } 473 | 474 | #endif 475 | 476 | /* end of mpglib_interface.c */ 477 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/presets.c: -------------------------------------------------------------------------------- 1 | /* 2 | * presets.c -- Apply presets 3 | * 4 | * Copyright (c) 2002-2008 Gabriel Bouvigne 5 | * Copyright (c) 2007-2011 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 Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | 23 | #ifdef HAVE_CONFIG_H 24 | # include 25 | #endif 26 | 27 | #include "lame.h" 28 | #include "machine.h" 29 | #include "set_get.h" 30 | #include "encoder.h" 31 | #include "util.h" 32 | #include "lame_global_flags.h" 33 | 34 | #define SET_OPTION(opt, val, def) if (enforce) \ 35 | (void) lame_set_##opt(gfp, val); \ 36 | else if (!(fabs(lame_get_##opt(gfp) - def) > 0)) \ 37 | (void) lame_set_##opt(gfp, val); 38 | 39 | #define SET__OPTION(opt, val, def) if (enforce) \ 40 | lame_set_##opt(gfp, val); \ 41 | else if (!(fabs(lame_get_##opt(gfp) - def) > 0)) \ 42 | lame_set_##opt(gfp, val); 43 | 44 | #undef Min 45 | #undef Max 46 | 47 | static inline int 48 | min_int(int a, int b) 49 | { 50 | if (a < b) { 51 | return a; 52 | } 53 | return b; 54 | } 55 | 56 | static inline int 57 | max_int(int a, int b) 58 | { 59 | if (a > b) { 60 | return a; 61 | } 62 | return b; 63 | } 64 | 65 | 66 | 67 | typedef struct { 68 | int vbr_q; 69 | int quant_comp; 70 | int quant_comp_s; 71 | int expY; 72 | FLOAT st_lrm; /*short threshold */ 73 | FLOAT st_s; 74 | FLOAT masking_adj; 75 | FLOAT masking_adj_short; 76 | FLOAT ath_lower; 77 | FLOAT ath_curve; 78 | FLOAT ath_sensitivity; 79 | FLOAT interch; 80 | int safejoint; 81 | int sfb21mod; 82 | FLOAT msfix; 83 | FLOAT minval; 84 | FLOAT ath_fixpoint; 85 | } vbr_presets_t; 86 | 87 | /* *INDENT-OFF* */ 88 | 89 | /* Switch mappings for VBR mode VBR_RH */ 90 | static const vbr_presets_t vbr_old_switch_map[] = { 91 | /*vbr_q qcomp_l qcomp_s expY st_lrm st_s mask adj_l adj_s ath_lower ath_curve ath_sens interChR safejoint sfb21mod msfix */ 92 | {0, 9, 9, 0, 5.20, 125.0, -4.2, -6.3, 4.8, 1, 0, 0, 2, 21, 0.97, 5, 100}, 93 | {1, 9, 9, 0, 5.30, 125.0, -3.6, -5.6, 4.5, 1.5, 0, 0, 2, 21, 1.35, 5, 100}, 94 | {2, 9, 9, 0, 5.60, 125.0, -2.2, -3.5, 2.8, 2, 0, 0, 2, 21, 1.49, 5, 100}, 95 | {3, 9, 9, 1, 5.80, 130.0, -1.8, -2.8, 2.6, 3, -4, 0, 2, 20, 1.64, 5, 100}, 96 | {4, 9, 9, 1, 6.00, 135.0, -0.7, -1.1, 1.1, 3.5, -8, 0, 2, 0, 1.79, 5, 100}, 97 | {5, 9, 9, 1, 6.40, 140.0, 0.5, 0.4, -7.5, 4, -12, 0.0002, 0, 0, 1.95, 5, 100}, 98 | {6, 9, 9, 1, 6.60, 145.0, 0.67, 0.65, -14.7, 6.5, -19, 0.0004, 0, 0, 2.30, 5, 100}, 99 | {7, 9, 9, 1, 6.60, 145.0, 0.8, 0.75, -19.7, 8, -22, 0.0006, 0, 0, 2.70, 5, 100}, 100 | {8, 9, 9, 1, 6.60, 145.0, 1.2, 1.15, -27.5, 10, -23, 0.0007, 0, 0, 0, 5, 100}, 101 | {9, 9, 9, 1, 6.60, 145.0, 1.6, 1.6, -36, 11, -25, 0.0008, 0, 0, 0, 5, 100}, 102 | {10, 9, 9, 1, 6.60, 145.0, 2.0, 2.0, -36, 12, -25, 0.0008, 0, 0, 0, 5, 100} 103 | }; 104 | 105 | static const vbr_presets_t vbr_mt_psy_switch_map[] = { 106 | /*vbr_q qcomp_l qcomp_s expY st_lrm st_s mask adj_l adj_s ath_lower ath_curve ath_sens --- safejoint sfb21mod msfix */ 107 | {0, 9, 9, 0, 4.20, 25.0, -6.8, -6.8, 7.1, 1, 0, 0, 2, 31, 1.000, 5, 100}, 108 | {1, 9, 9, 0, 4.20, 25.0, -4.8, -4.8, 5.4, 1.4, -1, 0, 2, 27, 1.122, 5, 98}, 109 | {2, 9, 9, 0, 4.20, 25.0, -2.6, -2.6, 3.7, 2.0, -3, 0, 2, 23, 1.288, 5, 97}, 110 | {3, 9, 9, 1, 4.20, 25.0, -1.6, -1.6, 2.0, 2.0, -5, 0, 2, 18, 1.479, 5, 96}, 111 | {4, 9, 9, 1, 4.20, 25.0, -0.0, -0.0, 0.0, 2.0, -8, 0, 2, 12, 1.698, 5, 95}, 112 | {5, 9, 9, 1, 4.20, 25.0, 1.3, 1.3, -6, 3.5, -11, 0, 2, 8, 1.950, 5, 94.2}, 113 | #if 0 114 | {6, 9, 9, 1, 4.50, 100.0, 1.5, 1.5, -24.0, 6.0, -14, 0, 2, 4, 2.239, 3, 93.9}, 115 | {7, 9, 9, 1, 4.80, 200.0, 1.7, 1.7, -28.0, 9.0, -20, 0, 2, 0, 2.570, 1, 93.6}, 116 | #else 117 | {6, 9, 9, 1, 4.50, 100.0, 2.2, 2.3, -12.0, 6.0, -14, 0, 2, 4, 2.239, 3, 93.9}, 118 | {7, 9, 9, 1, 4.80, 200.0, 2.7, 2.7, -18.0, 9.0, -17, 0, 2, 0, 2.570, 1, 93.6}, 119 | #endif 120 | {8, 9, 9, 1, 5.30, 300.0, 2.8, 2.8, -21.0, 10.0, -23, 0.0002, 0, 0, 2.951, 0, 93.3}, 121 | {9, 9, 9, 1, 6.60, 300.0, 2.8, 2.8, -23.0, 11.0, -25, 0.0006, 0, 0, 3.388, 0, 93.3}, 122 | {10, 9, 9, 1, 25.00, 300.0, 2.8, 2.8, -25.0, 12.0, -27, 0.0025, 0, 0, 3.500, 0, 93.3} 123 | }; 124 | 125 | /* *INDENT-ON* */ 126 | 127 | static vbr_presets_t const* 128 | get_vbr_preset(int v) 129 | { 130 | switch (v) { 131 | case vbr_mtrh: 132 | case vbr_mt: 133 | return &vbr_mt_psy_switch_map[0]; 134 | default: 135 | return &vbr_old_switch_map[0]; 136 | } 137 | } 138 | 139 | #define NOOP(m) (void)p.m 140 | #define LERP(m) (p.m = p.m + x * (q.m - p.m)) 141 | 142 | static void 143 | apply_vbr_preset(lame_global_flags * gfp, int a, int enforce) 144 | { 145 | vbr_presets_t const *vbr_preset = get_vbr_preset(lame_get_VBR(gfp)); 146 | float x = gfp->VBR_q_frac; 147 | vbr_presets_t p = vbr_preset[a]; 148 | vbr_presets_t q = vbr_preset[a + 1]; 149 | vbr_presets_t const *set = &p; 150 | 151 | NOOP(vbr_q); 152 | NOOP(quant_comp); 153 | NOOP(quant_comp_s); 154 | NOOP(expY); 155 | LERP(st_lrm); 156 | LERP(st_s); 157 | LERP(masking_adj); 158 | LERP(masking_adj_short); 159 | LERP(ath_lower); 160 | LERP(ath_curve); 161 | LERP(ath_sensitivity); 162 | LERP(interch); 163 | NOOP(safejoint); 164 | LERP(sfb21mod); 165 | LERP(msfix); 166 | LERP(minval); 167 | LERP(ath_fixpoint); 168 | 169 | (void) lame_set_VBR_q(gfp, set->vbr_q); 170 | SET_OPTION(quant_comp, set->quant_comp, -1); 171 | SET_OPTION(quant_comp_short, set->quant_comp_s, -1); 172 | if (set->expY) { 173 | (void) lame_set_experimentalY(gfp, set->expY); 174 | } 175 | SET_OPTION(short_threshold_lrm, set->st_lrm, -1); 176 | SET_OPTION(short_threshold_s, set->st_s, -1); 177 | SET_OPTION(maskingadjust, set->masking_adj, 0); 178 | SET_OPTION(maskingadjust_short, set->masking_adj_short, 0); 179 | if (lame_get_VBR(gfp) == vbr_mt || lame_get_VBR(gfp) == vbr_mtrh) { 180 | lame_set_ATHtype(gfp, 5); 181 | } 182 | SET_OPTION(ATHlower, set->ath_lower, 0); 183 | SET_OPTION(ATHcurve, set->ath_curve, -1); 184 | SET_OPTION(athaa_sensitivity, set->ath_sensitivity, 0); 185 | if (set->interch > 0) { 186 | SET_OPTION(interChRatio, set->interch, -1); 187 | } 188 | 189 | /* parameters for which there is no proper set/get interface */ 190 | if (set->safejoint > 0) { 191 | (void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); 192 | } 193 | if (set->sfb21mod > 0) { 194 | int const nsp = lame_get_exp_nspsytune(gfp); 195 | int const val = (nsp >> 20) & 63; 196 | if (val == 0) { 197 | int const sf21mod = (set->sfb21mod << 20) | nsp; 198 | (void) lame_set_exp_nspsytune(gfp, sf21mod); 199 | } 200 | } 201 | SET__OPTION(msfix, set->msfix, -1); 202 | 203 | if (enforce == 0) { 204 | gfp->VBR_q = a; 205 | gfp->VBR_q_frac = x; 206 | } 207 | gfp->internal_flags->cfg.minval = set->minval; 208 | gfp->internal_flags->cfg.ATHfixpoint = set->ath_fixpoint; 209 | } 210 | 211 | static int 212 | apply_abr_preset(lame_global_flags * gfp, int preset, int enforce) 213 | { 214 | typedef struct { 215 | int abr_kbps; 216 | int quant_comp; 217 | int quant_comp_s; 218 | int safejoint; 219 | FLOAT nsmsfix; 220 | FLOAT st_lrm; /*short threshold */ 221 | FLOAT st_s; 222 | FLOAT scale; 223 | FLOAT masking_adj; 224 | FLOAT ath_lower; 225 | FLOAT ath_curve; 226 | FLOAT interch; 227 | int sfscale; 228 | } abr_presets_t; 229 | 230 | 231 | /* *INDENT-OFF* */ 232 | 233 | /* 234 | * Switch mappings for ABR mode 235 | */ 236 | const abr_presets_t abr_switch_map[] = { 237 | /* kbps quant q_s safejoint nsmsfix st_lrm st_s scale msk ath_lwr ath_curve interch , sfscale */ 238 | { 8, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -30.0, 11, 0.0012, 1}, /* 8, impossible to use in stereo */ 239 | { 16, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -25.0, 11, 0.0010, 1}, /* 16 */ 240 | { 24, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -20.0, 11, 0.0010, 1}, /* 24 */ 241 | { 32, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -15.0, 11, 0.0010, 1}, /* 32 */ 242 | { 40, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -10.0, 11, 0.0009, 1}, /* 40 */ 243 | { 48, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -10.0, 11, 0.0009, 1}, /* 48 */ 244 | { 56, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -6.0, 11, 0.0008, 1}, /* 56 */ 245 | { 64, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -2.0, 11, 0.0008, 1}, /* 64 */ 246 | { 80, 9, 9, 0, 0, 6.60, 145, 0.95, 0, .0, 8, 0.0007, 1}, /* 80 */ 247 | { 96, 9, 9, 0, 2.50, 6.60, 145, 0.95, 0, 1.0, 5.5, 0.0006, 1}, /* 96 */ 248 | {112, 9, 9, 0, 2.25, 6.60, 145, 0.95, 0, 2.0, 4.5, 0.0005, 1}, /* 112 */ 249 | {128, 9, 9, 0, 1.95, 6.40, 140, 0.95, 0, 3.0, 4, 0.0002, 1}, /* 128 */ 250 | {160, 9, 9, 1, 1.79, 6.00, 135, 0.95, -2, 5.0, 3.5, 0, 1}, /* 160 */ 251 | {192, 9, 9, 1, 1.49, 5.60, 125, 0.97, -4, 7.0, 3, 0, 0}, /* 192 */ 252 | {224, 9, 9, 1, 1.25, 5.20, 125, 0.98, -6, 9.0, 2, 0, 0}, /* 224 */ 253 | {256, 9, 9, 1, 0.97, 5.20, 125, 1.00, -8, 10.0, 1, 0, 0}, /* 256 */ 254 | {320, 9, 9, 1, 0.90, 5.20, 125, 1.00, -10, 12.0, 0, 0, 0} /* 320 */ 255 | }; 256 | 257 | /* *INDENT-ON* */ 258 | 259 | /* Variables for the ABR stuff */ 260 | int r; 261 | int actual_bitrate = preset; 262 | 263 | r = nearestBitrateFullIndex(preset); 264 | 265 | (void) lame_set_VBR(gfp, vbr_abr); 266 | (void) lame_set_VBR_mean_bitrate_kbps(gfp, (actual_bitrate)); 267 | (void) lame_set_VBR_mean_bitrate_kbps(gfp, min_int(lame_get_VBR_mean_bitrate_kbps(gfp), 320)); 268 | (void) lame_set_VBR_mean_bitrate_kbps(gfp, max_int(lame_get_VBR_mean_bitrate_kbps(gfp), 8)); 269 | (void) lame_set_brate(gfp, lame_get_VBR_mean_bitrate_kbps(gfp)); 270 | 271 | 272 | /* parameters for which there is no proper set/get interface */ 273 | if (abr_switch_map[r].safejoint > 0) 274 | (void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); /* safejoint */ 275 | 276 | if (abr_switch_map[r].sfscale > 0) 277 | (void) lame_set_sfscale(gfp, 1); 278 | 279 | 280 | SET_OPTION(quant_comp, abr_switch_map[r].quant_comp, -1); 281 | SET_OPTION(quant_comp_short, abr_switch_map[r].quant_comp_s, -1); 282 | 283 | SET__OPTION(msfix, abr_switch_map[r].nsmsfix, -1); 284 | 285 | SET_OPTION(short_threshold_lrm, abr_switch_map[r].st_lrm, -1); 286 | SET_OPTION(short_threshold_s, abr_switch_map[r].st_s, -1); 287 | 288 | /* ABR seems to have big problems with clipping, especially at low bitrates */ 289 | /* so we compensate for that here by using a scale value depending on bitrate */ 290 | lame_set_scale(gfp, lame_get_scale(gfp) * abr_switch_map[r].scale); 291 | 292 | SET_OPTION(maskingadjust, abr_switch_map[r].masking_adj, 0); 293 | if (abr_switch_map[r].masking_adj > 0) { 294 | SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * .9, 0); 295 | } 296 | else { 297 | SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * 1.1, 0); 298 | } 299 | 300 | 301 | SET_OPTION(ATHlower, abr_switch_map[r].ath_lower, 0); 302 | SET_OPTION(ATHcurve, abr_switch_map[r].ath_curve, -1); 303 | 304 | SET_OPTION(interChRatio, abr_switch_map[r].interch, -1); 305 | 306 | (void) abr_switch_map[r].abr_kbps; 307 | 308 | gfp->internal_flags->cfg.minval = 5. * (abr_switch_map[r].abr_kbps / 320.); 309 | 310 | return preset; 311 | } 312 | 313 | 314 | 315 | int 316 | apply_preset(lame_global_flags * gfp, int preset, int enforce) 317 | { 318 | /*translate legacy presets */ 319 | switch (preset) { 320 | case R3MIX: 321 | { 322 | preset = V3; 323 | (void) lame_set_VBR(gfp, vbr_mtrh); 324 | break; 325 | } 326 | case MEDIUM: 327 | case MEDIUM_FAST: 328 | { 329 | preset = V4; 330 | (void) lame_set_VBR(gfp, vbr_mtrh); 331 | break; 332 | } 333 | case STANDARD: 334 | case STANDARD_FAST: 335 | { 336 | preset = V2; 337 | (void) lame_set_VBR(gfp, vbr_mtrh); 338 | break; 339 | } 340 | case EXTREME: 341 | case EXTREME_FAST: 342 | { 343 | preset = V0; 344 | (void) lame_set_VBR(gfp, vbr_mtrh); 345 | break; 346 | } 347 | case INSANE: 348 | { 349 | preset = 320; 350 | gfp->preset = preset; 351 | (void) apply_abr_preset(gfp, preset, enforce); 352 | lame_set_VBR(gfp, vbr_off); 353 | return preset; 354 | } 355 | } 356 | 357 | gfp->preset = preset; 358 | { 359 | switch (preset) { 360 | case V9: 361 | apply_vbr_preset(gfp, 9, enforce); 362 | return preset; 363 | case V8: 364 | apply_vbr_preset(gfp, 8, enforce); 365 | return preset; 366 | case V7: 367 | apply_vbr_preset(gfp, 7, enforce); 368 | return preset; 369 | case V6: 370 | apply_vbr_preset(gfp, 6, enforce); 371 | return preset; 372 | case V5: 373 | apply_vbr_preset(gfp, 5, enforce); 374 | return preset; 375 | case V4: 376 | apply_vbr_preset(gfp, 4, enforce); 377 | return preset; 378 | case V3: 379 | apply_vbr_preset(gfp, 3, enforce); 380 | return preset; 381 | case V2: 382 | apply_vbr_preset(gfp, 2, enforce); 383 | return preset; 384 | case V1: 385 | apply_vbr_preset(gfp, 1, enforce); 386 | return preset; 387 | case V0: 388 | apply_vbr_preset(gfp, 0, enforce); 389 | return preset; 390 | default: 391 | break; 392 | } 393 | } 394 | if (8 <= preset && preset <= 320) { 395 | return apply_abr_preset(gfp, preset, enforce); 396 | } 397 | 398 | gfp->preset = 0; /*no corresponding preset found */ 399 | return preset; 400 | } 401 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/reservoir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bit reservoir source file 3 | * 4 | * Copyright (c) 1999-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: reservoir.c,v 1.45 2011/05/07 16:05:17 rbrito Exp $ */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | # include 26 | #endif 27 | 28 | 29 | #include "lame.h" 30 | #include "machine.h" 31 | #include "encoder.h" 32 | #include "util.h" 33 | #include "reservoir.h" 34 | 35 | #include "bitstream.h" 36 | #include "lame-analysis.h" 37 | #include "lame_global_flags.h" 38 | 39 | 40 | /* 41 | ResvFrameBegin: 42 | Called (repeatedly) at the beginning of a frame. Updates the maximum 43 | size of the reservoir, and checks to make sure main_data_begin 44 | was set properly by the formatter 45 | */ 46 | 47 | /* 48 | * Background information: 49 | * 50 | * This is the original text from the ISO standard. Because of 51 | * sooo many bugs and irritations correcting comments are added 52 | * in brackets []. A '^W' means you should remove the last word. 53 | * 54 | * 1) The following rule can be used to calculate the maximum 55 | * number of bits used for one granule [^W frame]: 56 | * At the highest possible bitrate of Layer III (320 kbps 57 | * per stereo signal [^W^W^W], 48 kHz) the frames must be of 58 | * [^W^W^W are designed to have] constant length, i.e. 59 | * one buffer [^W^W the frame] length is: 60 | * 61 | * 320 kbps * 1152/48 kHz = 7680 bit = 960 byte 62 | * 63 | * This value is used as the maximum buffer per channel [^W^W] at 64 | * lower bitrates [than 320 kbps]. At 64 kbps mono or 128 kbps 65 | * stereo the main granule length is 64 kbps * 576/48 kHz = 768 bit 66 | * [per granule and channel] at 48 kHz sampling frequency. 67 | * This means that there is a maximum deviation (short time buffer 68 | * [= reservoir]) of 7680 - 2*2*768 = 4608 bits is allowed at 64 kbps. 69 | * The actual deviation is equal to the number of bytes [with the 70 | * meaning of octets] denoted by the main_data_end offset pointer. 71 | * The actual maximum deviation is (2^9-1)*8 bit = 4088 bits 72 | * [for MPEG-1 and (2^8-1)*8 bit for MPEG-2, both are hard limits]. 73 | * ... The xchange of buffer bits between the left and right channel 74 | * is allowed without restrictions [exception: dual channel]. 75 | * Because of the [constructed] constraint on the buffer size 76 | * main_data_end is always set to 0 in the case of bit_rate_index==14, 77 | * i.e. data rate 320 kbps per stereo signal [^W^W^W]. In this case 78 | * all data are allocated between adjacent header [^W sync] words 79 | * [, i.e. there is no buffering at all]. 80 | */ 81 | 82 | int 83 | ResvFrameBegin(lame_internal_flags * gfc, int *mean_bits) 84 | { 85 | SessionConfig_t const *const cfg = &gfc->cfg; 86 | EncStateVar_t *const esv = &gfc->sv_enc; 87 | int fullFrameBits; 88 | int resvLimit; 89 | int maxmp3buf; 90 | III_side_info_t *const l3_side = &gfc->l3_side; 91 | int frameLength; 92 | int meanBits; 93 | 94 | frameLength = getframebits(gfc); 95 | meanBits = (frameLength - cfg->sideinfo_len * 8) / cfg->mode_gr; 96 | 97 | /* 98 | * Meaning of the variables: 99 | * resvLimit: (0, 8, ..., 8*255 (MPEG-2), 8*511 (MPEG-1)) 100 | * Number of bits can be stored in previous frame(s) due to 101 | * counter size constaints 102 | * maxmp3buf: ( ??? ... 8*1951 (MPEG-1 and 2), 8*2047 (MPEG-2.5)) 103 | * Number of bits allowed to encode one frame (you can take 8*511 bit 104 | * from the bit reservoir and at most 8*1440 bit from the current 105 | * frame (320 kbps, 32 kHz), so 8*1951 bit is the largest possible 106 | * value for MPEG-1 and -2) 107 | * 108 | * maximum allowed granule/channel size times 4 = 8*2047 bits., 109 | * so this is the absolute maximum supported by the format. 110 | * 111 | * 112 | * fullFrameBits: maximum number of bits available for encoding 113 | * the current frame. 114 | * 115 | * mean_bits: target number of bits per granule. 116 | * 117 | * frameLength: 118 | * 119 | * gfc->ResvMax: maximum allowed reservoir 120 | * 121 | * gfc->ResvSize: current reservoir size 122 | * 123 | * l3_side->resvDrain_pre: 124 | * ancillary data to be added to previous frame: 125 | * (only usefull in VBR modes if it is possible to have 126 | * maxmp3buf < fullFrameBits)). Currently disabled, 127 | * see #define NEW_DRAIN 128 | * 2010-02-13: RH now enabled, it seems to be needed for CBR too, 129 | * as there exists one example, where the FhG decoder 130 | * can't decode a -b320 CBR file anymore. 131 | * 132 | * l3_side->resvDrain_post: 133 | * ancillary data to be added to this frame: 134 | * 135 | */ 136 | 137 | /* main_data_begin has 9 bits in MPEG-1, 8 bits MPEG-2 */ 138 | resvLimit = (8 * 256) * cfg->mode_gr - 8; 139 | 140 | /* maximum allowed frame size. dont use more than this number of 141 | bits, even if the frame has the space for them: */ 142 | maxmp3buf = cfg->buffer_constraint; 143 | esv->ResvMax = maxmp3buf - frameLength; 144 | if (esv->ResvMax > resvLimit) 145 | esv->ResvMax = resvLimit; 146 | if (esv->ResvMax < 0 || cfg->disable_reservoir) 147 | esv->ResvMax = 0; 148 | 149 | fullFrameBits = meanBits * cfg->mode_gr + Min(esv->ResvSize, esv->ResvMax); 150 | 151 | if (fullFrameBits > maxmp3buf) 152 | fullFrameBits = maxmp3buf; 153 | 154 | assert(0 == esv->ResvMax % 8); 155 | assert(esv->ResvMax >= 0); 156 | 157 | l3_side->resvDrain_pre = 0; 158 | 159 | if (gfc->pinfo != NULL) { 160 | gfc->pinfo->mean_bits = meanBits / 2; /* expected bits per channel per granule [is this also right for mono/stereo, MPEG-1/2 ?] */ 161 | gfc->pinfo->resvsize = esv->ResvSize; 162 | } 163 | *mean_bits = meanBits; 164 | return fullFrameBits; 165 | } 166 | 167 | 168 | /* 169 | ResvMaxBits 170 | returns targ_bits: target number of bits to use for 1 granule 171 | extra_bits: amount extra available from reservoir 172 | Mark Taylor 4/99 173 | */ 174 | void 175 | ResvMaxBits(lame_internal_flags * gfc, int mean_bits, int *targ_bits, int *extra_bits, int cbr) 176 | { 177 | SessionConfig_t const *const cfg = &gfc->cfg; 178 | EncStateVar_t *const esv = &gfc->sv_enc; 179 | int add_bits, targBits, extraBits; 180 | int ResvSize = esv->ResvSize, ResvMax = esv->ResvMax; 181 | 182 | /* conpensate the saved bits used in the 1st granule */ 183 | if (cbr) 184 | ResvSize += mean_bits; 185 | 186 | if (gfc->sv_qnt.substep_shaping & 1) 187 | ResvMax *= 0.9; 188 | 189 | targBits = mean_bits; 190 | 191 | /* extra bits if the reservoir is almost full */ 192 | if (ResvSize * 10 > ResvMax * 9) { 193 | add_bits = ResvSize - (ResvMax * 9) / 10; 194 | targBits += add_bits; 195 | gfc->sv_qnt.substep_shaping |= 0x80; 196 | } 197 | else { 198 | add_bits = 0; 199 | gfc->sv_qnt.substep_shaping &= 0x7f; 200 | /* build up reservoir. this builds the reservoir a little slower 201 | * than FhG. It could simple be mean_bits/15, but this was rigged 202 | * to always produce 100 (the old value) at 128kbs */ 203 | /* *targ_bits -= (int) (mean_bits/15.2); */ 204 | if (!cfg->disable_reservoir && !(gfc->sv_qnt.substep_shaping & 1)) 205 | targBits -= .1 * mean_bits; 206 | } 207 | 208 | 209 | /* amount from the reservoir we are allowed to use. ISO says 6/10 */ 210 | extraBits = (ResvSize < (esv->ResvMax * 6) / 10 ? ResvSize : (esv->ResvMax * 6) / 10); 211 | extraBits -= add_bits; 212 | 213 | if (extraBits < 0) 214 | extraBits = 0; 215 | 216 | *targ_bits = targBits; 217 | *extra_bits = extraBits; 218 | } 219 | 220 | /* 221 | ResvAdjust: 222 | Called after a granule's bit allocation. Readjusts the size of 223 | the reservoir to reflect the granule's usage. 224 | */ 225 | void 226 | ResvAdjust(lame_internal_flags * gfc, gr_info const *gi) 227 | { 228 | gfc->sv_enc.ResvSize -= gi->part2_3_length + gi->part2_length; 229 | } 230 | 231 | 232 | /* 233 | ResvFrameEnd: 234 | Called after all granules in a frame have been allocated. Makes sure 235 | that the reservoir size is within limits, possibly by adding stuffing 236 | bits. 237 | */ 238 | void 239 | ResvFrameEnd(lame_internal_flags * gfc, int mean_bits) 240 | { 241 | SessionConfig_t const *const cfg = &gfc->cfg; 242 | EncStateVar_t *const esv = &gfc->sv_enc; 243 | III_side_info_t *const l3_side = &gfc->l3_side; 244 | int stuffingBits; 245 | int over_bits; 246 | 247 | esv->ResvSize += mean_bits * cfg->mode_gr; 248 | stuffingBits = 0; 249 | l3_side->resvDrain_post = 0; 250 | l3_side->resvDrain_pre = 0; 251 | 252 | /* we must be byte aligned */ 253 | if ((over_bits = esv->ResvSize % 8) != 0) 254 | stuffingBits += over_bits; 255 | 256 | 257 | over_bits = (esv->ResvSize - stuffingBits) - esv->ResvMax; 258 | if (over_bits > 0) { 259 | assert(0 == over_bits % 8); 260 | assert(over_bits >= 0); 261 | stuffingBits += over_bits; 262 | } 263 | 264 | 265 | /* NOTE: enabling the NEW_DRAIN code fixes some problems with FhG decoder 266 | shipped with MS Windows operating systems. Using this, it is even 267 | possible to use Gabriel's lax buffer consideration again, which 268 | assumes, any decoder should have a buffer large enough 269 | for a 320 kbps frame at 32 kHz sample rate. 270 | 271 | old drain code: 272 | lame -b320 BlackBird.wav ---> does not play with GraphEdit.exe using FhG decoder V1.5 Build 50 273 | 274 | new drain code: 275 | lame -b320 BlackBird.wav ---> plays fine with GraphEdit.exe using FhG decoder V1.5 Build 50 276 | 277 | Robert Hegemann, 2010-02-13. 278 | */ 279 | /* drain as many bits as possible into previous frame ancillary data 280 | * In particular, in VBR mode ResvMax may have changed, and we have 281 | * to make sure main_data_begin does not create a reservoir bigger 282 | * than ResvMax mt 4/00*/ 283 | { 284 | int mdb_bytes = Min(l3_side->main_data_begin * 8, stuffingBits) / 8; 285 | l3_side->resvDrain_pre += 8 * mdb_bytes; 286 | stuffingBits -= 8 * mdb_bytes; 287 | esv->ResvSize -= 8 * mdb_bytes; 288 | l3_side->main_data_begin -= mdb_bytes; 289 | } 290 | /* drain the rest into this frames ancillary data */ 291 | l3_side->resvDrain_post += stuffingBits; 292 | esv->ResvSize -= stuffingBits; 293 | } 294 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 | -------------------------------------------------------------------------------- /lame/src/main/jni/vector/xmm_quantize_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MP3 quantization, intrinsics functions 3 | * 4 | * Copyright (c) 2005-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 | #ifdef HAVE_CONFIG_H 24 | # include 25 | #endif 26 | 27 | #include "../lame.h" 28 | #include "../machine.h" 29 | #include "../encoder.h" 30 | #include "../util.h" 31 | #include "lame_intrin.h" 32 | 33 | 34 | 35 | #ifdef HAVE_XMMINTRIN_H 36 | 37 | #include 38 | 39 | typedef union { 40 | int32_t _i_32[4]; /* unions are initialized by its first member */ 41 | float _float[4]; 42 | __m128 _m128; 43 | } vecfloat_union; 44 | 45 | #define TRI_SIZE (5-1) /* 1024 = 4**5 */ 46 | static const FLOAT costab[TRI_SIZE * 2] = { 47 | 9.238795325112867e-01, 3.826834323650898e-01, 48 | 9.951847266721969e-01, 9.801714032956060e-02, 49 | 9.996988186962042e-01, 2.454122852291229e-02, 50 | 9.999811752826011e-01, 6.135884649154475e-03 51 | }; 52 | 53 | 54 | 55 | void 56 | init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum) 57 | { 58 | int i; 59 | float tmp_max = 0; 60 | float tmp_sum = 0; 61 | int upper4 = (upper / 4) * 4; 62 | int rest = upper-upper4; 63 | 64 | const vecfloat_union fabs_mask = {{ 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF }}; 65 | const __m128 vec_fabs_mask = _mm_loadu_ps(&fabs_mask._float[0]); 66 | vecfloat_union vec_xrpow_max; 67 | vecfloat_union vec_sum; 68 | vecfloat_union vec_tmp; 69 | 70 | _mm_prefetch((char *) cod_info->xr, _MM_HINT_T0); 71 | _mm_prefetch((char *) xrpow, _MM_HINT_T0); 72 | 73 | vec_xrpow_max._m128 = _mm_set_ps1(0); 74 | vec_sum._m128 = _mm_set_ps1(0); 75 | 76 | for (i = 0; i < upper4; i += 4) { 77 | vec_tmp._m128 = _mm_loadu_ps(&(cod_info->xr[i])); /* load */ 78 | vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */ 79 | vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128); 80 | vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128))); 81 | vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */ 82 | _mm_storeu_ps(&(xrpow[i]), vec_tmp._m128); /* store into xrpow[] */ 83 | } 84 | vec_tmp._m128 = _mm_set_ps1(0); 85 | switch (rest) { 86 | case 3: vec_tmp._float[2] = cod_info->xr[upper4+2]; 87 | case 2: vec_tmp._float[1] = cod_info->xr[upper4+1]; 88 | case 1: vec_tmp._float[0] = cod_info->xr[upper4+0]; 89 | vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */ 90 | vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128); 91 | vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128))); 92 | vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */ 93 | switch (rest) { 94 | case 3: xrpow[upper4+2] = vec_tmp._float[2]; 95 | case 2: xrpow[upper4+1] = vec_tmp._float[1]; 96 | case 1: xrpow[upper4+0] = vec_tmp._float[0]; 97 | default: 98 | break; 99 | } 100 | default: 101 | break; 102 | } 103 | tmp_sum = vec_sum._float[0] + vec_sum._float[1] + vec_sum._float[2] + vec_sum._float[3]; 104 | { 105 | float ma = vec_xrpow_max._float[0] > vec_xrpow_max._float[1] 106 | ? vec_xrpow_max._float[0] : vec_xrpow_max._float[1]; 107 | float mb = vec_xrpow_max._float[2] > vec_xrpow_max._float[3] 108 | ? vec_xrpow_max._float[2] : vec_xrpow_max._float[3]; 109 | tmp_max = ma > mb ? ma : mb; 110 | } 111 | cod_info->xrpow_max = tmp_max; 112 | *sum = tmp_sum; 113 | } 114 | 115 | 116 | static void store4(__m128 v, float* f0, float* f1, float* f2, float* f3) 117 | { 118 | vecfloat_union r; 119 | r._m128 = v; 120 | *f0 = r._float[0]; 121 | *f1 = r._float[1]; 122 | *f2 = r._float[2]; 123 | *f3 = r._float[3]; 124 | } 125 | 126 | 127 | void 128 | fht_SSE2(FLOAT * fz, int n) 129 | { 130 | const FLOAT *tri = costab; 131 | int k4; 132 | FLOAT *fi, *gi; 133 | FLOAT const *fn; 134 | 135 | n <<= 1; /* to get BLKSIZE, because of 3DNow! ASM routine */ 136 | fn = fz + n; 137 | k4 = 4; 138 | do { 139 | FLOAT s1, c1; 140 | int i, k1, k2, k3, kx; 141 | kx = k4 >> 1; 142 | k1 = k4; 143 | k2 = k4 << 1; 144 | k3 = k2 + k1; 145 | k4 = k2 << 1; 146 | fi = fz; 147 | gi = fi + kx; 148 | do { 149 | FLOAT f0, f1, f2, f3; 150 | f1 = fi[0] - fi[k1]; 151 | f0 = fi[0] + fi[k1]; 152 | f3 = fi[k2] - fi[k3]; 153 | f2 = fi[k2] + fi[k3]; 154 | fi[k2] = f0 - f2; 155 | fi[0] = f0 + f2; 156 | fi[k3] = f1 - f3; 157 | fi[k1] = f1 + f3; 158 | f1 = gi[0] - gi[k1]; 159 | f0 = gi[0] + gi[k1]; 160 | f3 = SQRT2 * gi[k3]; 161 | f2 = SQRT2 * gi[k2]; 162 | gi[k2] = f0 - f2; 163 | gi[0] = f0 + f2; 164 | gi[k3] = f1 - f3; 165 | gi[k1] = f1 + f3; 166 | gi += k4; 167 | fi += k4; 168 | } while (fi < fn); 169 | c1 = tri[0]; 170 | s1 = tri[1]; 171 | for (i = 1; i < kx; i++) { 172 | __m128 v_s2; 173 | __m128 v_c2; 174 | __m128 v_c1; 175 | __m128 v_s1; 176 | FLOAT c2, s2, s1_2 = s1+s1; 177 | c2 = 1 - s1_2 * s1; 178 | s2 = s1_2 * c1; 179 | fi = fz + i; 180 | gi = fz + k1 - i; 181 | v_c1 = _mm_set_ps1(c1); 182 | v_s1 = _mm_set_ps1(s1); 183 | v_c2 = _mm_set_ps1(c2); 184 | v_s2 = _mm_set_ps1(s2); 185 | { 186 | static const vecfloat_union sign_mask = {{0x80000000,0,0,0}}; 187 | v_c1 = _mm_xor_ps(sign_mask._m128, v_c1); /* v_c1 := {-c1, +c1, +c1, +c1} */ 188 | } 189 | { 190 | static const vecfloat_union sign_mask = {{0,0x80000000,0,0}}; 191 | v_s1 = _mm_xor_ps(sign_mask._m128, v_s1); /* v_s1 := {+s1, -s1, +s1, +s1} */ 192 | } 193 | { 194 | static const vecfloat_union sign_mask = {{0,0,0x80000000,0x80000000}}; 195 | v_c2 = _mm_xor_ps(sign_mask._m128, v_c2); /* v_c2 := {+c2, +c2, -c2, -c2} */ 196 | } 197 | do { 198 | __m128 p, q, r; 199 | 200 | q = _mm_setr_ps(fi[k1], fi[k3], gi[k1], gi[k3]); /* Q := {fi_k1,fi_k3,gi_k1,gi_k3}*/ 201 | p = _mm_mul_ps(_mm_set_ps1(s2), q); /* P := s2 * Q */ 202 | q = _mm_mul_ps(v_c2, q); /* Q := c2 * Q */ 203 | q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(1,0,3,2)); /* Q := {-c2*gi_k1,-c2*gi_k3,c2*fi_k1,c2*fi_k3} */ 204 | p = _mm_add_ps(p, q); 205 | 206 | r = _mm_setr_ps(gi[0], gi[k2], fi[0], fi[k2]); /* R := {gi_0,gi_k2,fi_0,fi_k2} */ 207 | q = _mm_sub_ps(r, p); /* Q := {gi_0-p0,gi_k2-p1,fi_0-p2,fi_k2-p3} */ 208 | r = _mm_add_ps(r, p); /* R := {gi_0+p0,gi_k2+p1,fi_0+p2,fi_k2+p3} */ 209 | p = _mm_shuffle_ps(q, r, _MM_SHUFFLE(2,0,2,0)); /* P := {q0,q2,r0,r2} */ 210 | p = _mm_shuffle_ps(p, p, _MM_SHUFFLE(3,1,2,0)); /* P := {q0,r0,q2,r2} */ 211 | q = _mm_shuffle_ps(q, r, _MM_SHUFFLE(3,1,3,1)); /* Q := {q1,q3,r1,r3} */ 212 | r = _mm_mul_ps(v_c1, q); 213 | q = _mm_mul_ps(v_s1, q); 214 | q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(0,1,2,3)); /* Q := {q3,q2,q1,q0} */ 215 | q = _mm_add_ps(q, r); 216 | 217 | store4(_mm_sub_ps(p, q), &gi[k3], &gi[k2], &fi[k3], &fi[k2]); 218 | store4(_mm_add_ps(p, q), &gi[k1], &gi[ 0], &fi[k1], &fi[ 0]); 219 | 220 | gi += k4; 221 | fi += k4; 222 | } while (fi < fn); 223 | c2 = c1; 224 | c1 = c2 * tri[0] - s1 * tri[1]; 225 | s1 = c2 * tri[1] + s1 * tri[0]; 226 | } 227 | tri += 2; 228 | } while (k4 < n); 229 | } 230 | 231 | #endif /* HAVE_XMMINTRIN_H */ 232 | 233 | -------------------------------------------------------------------------------- /lame/src/main/jni/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.32.2.2 2011/11/18 09:18:28 robert Exp $ 30 | \ingroup libmp3lame 31 | */ 32 | 33 | 34 | #ifdef HAVE_CONFIG_H 35 | # include 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 | -------------------------------------------------------------------------------- /lame/src/main/jni/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 99 /* Minor version number */ 39 | # define LAME_TYPE_VERSION 2 /* 0:alpha 1:beta 2:release */ 40 | # define LAME_PATCH_VERSION 5 /* 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 | -------------------------------------------------------------------------------- /lame/src/test/java/mobi/cangol/mobile/utils/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2013 Cangol 4 | *

5 | * Licensed under the Apache License, Version 2.0 (the "License") 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package mobi.cangol.mobile.utils; 19 | 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.*; 23 | 24 | /** 25 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 26 | */ 27 | public class ExampleUnitTest { 28 | @Test 29 | public void addition_isCorrect() throws Exception { 30 | assertEquals(4, 2 + 2); 31 | } 32 | } -------------------------------------------------------------------------------- /maven_push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | 5 | version = POM_VERSION 6 | group= POM_GROUP_ID 7 | 8 | bintray (){ 9 | 10 | user = System.env.BINTRAY_USER 11 | key = System.env.BINTRAY_APIKEY 12 | 13 | 14 | configurations = ['archives'] 15 | pkg { 16 | repo = 'maven' 17 | name = POM_NAME 18 | desc = POM_DESCRIPTION 19 | websiteUrl = POM_URL 20 | issueTrackerUrl = POM_URL+'/issues' 21 | vcsUrl = POM_SCM_CONNECTION 22 | licenses = ["Apache-2.0"] 23 | labels = ['android'] 24 | publish = true 25 | publicDownloadNumbers = true 26 | 27 | version { 28 | vcsTag = POM_VERSION 29 | desc = POM_DESCRIPTION 30 | gpg { 31 | sign = true //Determines whether to GPG sign the files. The default is false 32 | passphrase = System.env.BINTRAY_GPG_PASSWORD //"$System.env.BINTRAY_GPG_PASSWORD" 33 | //Optional. The passphrase for GPG signing' 34 | } 35 | } 36 | } 37 | } 38 | 39 | install { 40 | repositories.mavenInstaller { 41 | //This generates POM.xml with proper parameters 42 | pom { 43 | project { 44 | packaging POM_PACKAGING 45 | groupId POM_GROUP_ID 46 | artifactId POM_ARTIFACT_ID 47 | 48 | // Add your description here 49 | name POM_NAME 50 | description POM_DESCRIPTION 51 | url POM_URL 52 | 53 | // Set your license 54 | licenses { 55 | license { 56 | name POM_LICENSE_NAME 57 | url POM_LICENSE_URL 58 | distribution POM_LICENCE_DIST 59 | } 60 | } 61 | developers { 62 | developer { 63 | id POM_DEVELOPER_ID 64 | name POM_DEVELOPER_NAME 65 | email POM_DEVELOPER_EMAIL 66 | } 67 | } 68 | scm { 69 | connection POM_SCM_CONNECTION 70 | developerConnection POM_SCM_DEV_CONNECTION 71 | url POM_SCM_URL 72 | 73 | } 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2013 Cangol 4 | *

5 | * Licensed under the Apache License, Version 2.0 (the "License") 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | include ':app',':lame' 19 | --------------------------------------------------------------------------------