├── .gitattributes ├── .gitignore ├── Dev.MD ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── dev │ │ └── mars │ │ └── openslesdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── dev │ │ │ └── mars │ │ │ └── openslesdemo │ │ │ ├── AudioUtils.java │ │ │ ├── Common.java │ │ │ ├── LogUtils.java │ │ │ ├── MainActivity.java │ │ │ ├── NativeLib.java │ │ │ ├── OpenSLPlayer.java │ │ │ ├── OpenSLRecorder.java │ │ │ ├── SpeexUtils.java │ │ │ └── base │ │ │ └── BaseApplication.java │ ├── jni │ │ ├── CMakeLists.txt │ │ ├── log.h │ │ ├── native.cpp │ │ ├── opensl_io.c │ │ └── opensl_io.h │ ├── jnilibs │ │ ├── arm64-v8a │ │ │ ├── libspeex.so │ │ │ └── libspeexdsp.so │ │ ├── armeabi │ │ │ ├── libspeex.so │ │ │ └── libspeexdsp.so │ │ ├── speex_include │ │ │ ├── speex.h │ │ │ ├── speex_bits.h │ │ │ ├── speex_buffer.h │ │ │ ├── speex_callbacks.h │ │ │ ├── speex_config_types.h │ │ │ ├── speex_echo.h │ │ │ ├── speex_header.h │ │ │ ├── speex_jitter.h │ │ │ ├── speex_preprocess.h │ │ │ ├── speex_resampler.h │ │ │ ├── speex_stereo.h │ │ │ ├── speex_types.h │ │ │ ├── speexdsp_config_types.h │ │ │ └── speexdsp_types.h │ │ └── x86 │ │ │ ├── libspeex.so │ │ │ └── libspeexdsp.so │ └── 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 │ └── dev │ └── mars │ └── openslesdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea 3 | app/.externNativeBuild 4 | app/.externalNativeBuild 5 | /build 6 | local.properties 7 | app/app.iml 8 | *.iml 9 | -------------------------------------------------------------------------------- /Dev.MD: -------------------------------------------------------------------------------- 1 | 2017.3.16 待加入回声消除和降噪处理 2 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "dev.mars.openslesdemo" 8 | minSdkVersion 14 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | ndk { 14 | abiFilters 'armeabi','arm64-v8a', 'x86' 15 | } 16 | externalNativeBuild { 17 | cmake { 18 | arguments '-DANDROID_TOOLCHAIN=clang','-DANDROID_STL=gnustl_static' 19 | } 20 | } 21 | //, 'arm64-v8a', 'x86', 'x86_64' 22 | } 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | externalNativeBuild { 30 | cmake { 31 | path "src/main/jni/CMakeLists.txt" 32 | } 33 | } 34 | } 35 | 36 | dependencies { 37 | compile fileTree(dir: 'libs', include: ['*.jar']) 38 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 39 | exclude group: 'com.android.support', module: 'support-annotations' 40 | }) 41 | compile 'com.android.support:appcompat-v7:24.2.1' 42 | testCompile 'junit:junit:4.12' 43 | } 44 | -------------------------------------------------------------------------------- /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 F:\IDE\AndroidSDK/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/dev/mars/openslesdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("dev.mars.openslesdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/AudioUtils.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.atomic.AtomicBoolean; 6 | 7 | /** 8 | * Created by mars_ma on 2017/3/16. 9 | */ 10 | 11 | public class AudioUtils { 12 | private ExecutorService executor = Executors.newSingleThreadExecutor(); 13 | private NativeLib nativeBridge; 14 | 15 | public AudioUtils(){ 16 | nativeBridge = new NativeLib(); 17 | } 18 | 19 | public boolean recordAndPlayPCM(final boolean enable1, final boolean enable2){ 20 | if(!nativeBridge.isRecordingAndPlaying()) { 21 | executor.execute(new Runnable() { 22 | @Override 23 | public void run() { 24 | nativeBridge.recordAndPlayPCM(enable1,enable2); 25 | } 26 | }); 27 | return true; 28 | }else{ 29 | return false; 30 | } 31 | } 32 | 33 | public boolean stopRecordAndPlay(){ 34 | if(!nativeBridge.isRecordingAndPlaying()) { 35 | return false; 36 | }else{ 37 | nativeBridge.stopRecordingAndPlaying(); 38 | return true; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/Common.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import android.os.Environment; 4 | 5 | /** 6 | * Created by 37550 on 2017/3/8. 7 | */ 8 | 9 | public class Common { 10 | public static final int SAMPLERATE = 44100; //bit/s 11 | public static final int CHANNELS = 1; //1:单/2:双声道 12 | public static final int PERIOD_TIME = 20; //ms 13 | public static final String DEFAULT_PCM_FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/test_pcm.pcm"; 14 | public static final String DEFAULT_PCM_OUTPUT_FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/output_pcm.pcm"; 15 | public static final String DEFAULT_SPEEX_FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/test_speex.raw"; 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/LogUtils.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by ma.xuanwei on 2017/3/7. 7 | */ 8 | 9 | public class LogUtils { 10 | public static void DEBUG(String msg){ 11 | android.util.Log.d("dev_mars",msg); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import android.Manifest; 4 | import android.content.pm.PackageManager; 5 | import android.os.Build; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 9 | import android.view.View; 10 | import android.widget.CheckBox; 11 | import android.widget.Toast; 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | String[] pers = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.RECORD_AUDIO}; 15 | private OpenSLRecorder recorder; 16 | private OpenSLPlayer player; 17 | private SpeexUtils speexUtils; 18 | private AudioUtils audioUtils; 19 | CheckBox cb1,cb2; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | cb1 = (CheckBox) findViewById(R.id.cb1); 26 | cb2 = (CheckBox) findViewById(R.id.cb2); 27 | recorder = new OpenSLRecorder(); 28 | player = new OpenSLPlayer(); 29 | speexUtils = new SpeexUtils(); 30 | audioUtils= new AudioUtils(); 31 | } 32 | 33 | 34 | public void startRecord(View view) { 35 | if (hasPermission()) { 36 | startToRecord(); 37 | } else { 38 | requestPermissions(); 39 | } 40 | } 41 | 42 | public void startToRecord(){ 43 | if(!recorder.startToRecord(Common.SAMPLERATE,Common.PERIOD_TIME,Common.CHANNELS,Common.DEFAULT_PCM_FILE_PATH)){ 44 | Toast.makeText(MainActivity.this,"Already in recording state!",Toast.LENGTH_SHORT).show(); 45 | }else{ 46 | Toast.makeText(MainActivity.this,"Start recording!",Toast.LENGTH_SHORT).show(); 47 | } 48 | } 49 | 50 | public void stopRecord(View view) { 51 | if(!recorder.stopRecording()){ 52 | Toast.makeText(MainActivity.this,"Not in recording state!",Toast.LENGTH_SHORT).show(); 53 | }else{ 54 | Toast.makeText(MainActivity.this,"Recording stopped!",Toast.LENGTH_SHORT).show(); 55 | } 56 | } 57 | 58 | private void requestPermissions(){ 59 | if(isLollipop()) { 60 | requestPermissions(pers, 0); 61 | } 62 | } 63 | 64 | @Override 65 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 66 | if(requestCode==0){ 67 | if(hasPermission()){ 68 | startToRecord(); 69 | }else{ 70 | Toast.makeText(MainActivity.this,"Unable to get permissions",Toast.LENGTH_SHORT).show(); 71 | } 72 | } 73 | } 74 | 75 | private boolean hasPermission() { 76 | return hasPermission(pers); 77 | } 78 | 79 | 80 | private boolean hasPermission(String[] pers) { 81 | if(isLollipop()){ 82 | for(String per:pers){ 83 | if(checkSelfPermission(per)!= PackageManager.PERMISSION_GRANTED){ 84 | return false; 85 | } 86 | } 87 | } 88 | return true; 89 | } 90 | 91 | private boolean isLollipop(){ 92 | return Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP_MR1; 93 | } 94 | 95 | 96 | public void startPlay(View view) { 97 | if(!player.startToPlay(Common.SAMPLERATE,Common.PERIOD_TIME,Common.CHANNELS,Common.DEFAULT_PCM_FILE_PATH)){ 98 | Toast.makeText(MainActivity.this,"Is playing!",Toast.LENGTH_SHORT).show(); 99 | }else{ 100 | Toast.makeText(MainActivity.this,"Start playing!",Toast.LENGTH_SHORT).show(); 101 | } 102 | } 103 | 104 | public void stopPlay(View view) { 105 | if(!player.stopPlaying()){ 106 | Toast.makeText(MainActivity.this,"Not playing!",Toast.LENGTH_SHORT).show(); 107 | }else{ 108 | Toast.makeText(MainActivity.this,"Playing stopped!",Toast.LENGTH_SHORT).show(); 109 | } 110 | } 111 | 112 | public void encodeWithSpeex(View view) { 113 | speexUtils.encode(Common.DEFAULT_PCM_FILE_PATH,Common.DEFAULT_SPEEX_FILE_PATH); 114 | } 115 | 116 | public void decodeWithSpeex(View view) { 117 | speexUtils.decode(Common.DEFAULT_SPEEX_FILE_PATH,Common.DEFAULT_PCM_OUTPUT_FILE_PATH); 118 | } 119 | 120 | public void playOutpuPCM(View view) { 121 | if(!player.startToPlay(Common.SAMPLERATE,Common.PERIOD_TIME,Common.CHANNELS,Common.DEFAULT_PCM_OUTPUT_FILE_PATH)){ 122 | Toast.makeText(MainActivity.this,"Is playing!",Toast.LENGTH_SHORT).show(); 123 | }else{ 124 | Toast.makeText(MainActivity.this,"Start playing!",Toast.LENGTH_SHORT).show(); 125 | } 126 | } 127 | 128 | public void recordAndPlayPCM(View view) { 129 | if(!audioUtils.recordAndPlayPCM(cb1.isChecked(),cb2.isChecked())){ 130 | Toast.makeText(MainActivity.this,"Is recording and playing!",Toast.LENGTH_SHORT).show(); 131 | }else{ 132 | Toast.makeText(MainActivity.this,"Start recording and playing!",Toast.LENGTH_SHORT).show(); 133 | } 134 | } 135 | 136 | public void stopRecordAndPlayPCM(View view) { 137 | if(!audioUtils.stopRecordAndPlay()){ 138 | Toast.makeText(MainActivity.this,"not in recording and playing state!",Toast.LENGTH_SHORT).show(); 139 | }else{ 140 | Toast.makeText(MainActivity.this,"recording and playing stoped!",Toast.LENGTH_SHORT).show(); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/NativeLib.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import java.util.concurrent.atomic.AtomicBoolean; 4 | 5 | /** 6 | * Created by ma.xuanwei on 2017/3/7. 7 | */ 8 | 9 | public class NativeLib { 10 | 11 | private AtomicBoolean isRecording = new AtomicBoolean(false); 12 | private AtomicBoolean isPlaying = new AtomicBoolean(false); 13 | private AtomicBoolean isRecordAndPlay=new AtomicBoolean(false); 14 | static { 15 | System.loadLibrary("native"); 16 | } 17 | 18 | public void setIsRecording(boolean v){ 19 | isRecording.set(v); 20 | LogUtils.DEBUG("setIsRecording "+v); 21 | } 22 | 23 | public void setIsRecordingAndPlaying(boolean v){ 24 | isRecordAndPlay.set(v); 25 | LogUtils.DEBUG("setIsRecordingAndPlaying "+v); 26 | } 27 | 28 | public boolean isRecording(){ 29 | return isRecording.get(); 30 | } 31 | 32 | public void setIsPlaying(boolean b){ 33 | isPlaying.set(b); 34 | } 35 | 36 | public boolean isPlaying(){ 37 | return isPlaying.get(); 38 | } 39 | 40 | public boolean isRecordingAndPlaying(){ 41 | return isRecordAndPlay.get(); 42 | } 43 | 44 | public native void startRecording(int sampleRate, int period, int channels, String path); 45 | public native void stopRecording(); 46 | public native void playRecording(int sampleRate, int period, int channels, String path); 47 | public native void stopPlaying(); 48 | public native int encode(String pcm,String speex); 49 | public native int decode(String speex,String pcm); 50 | 51 | public native int recordAndPlayPCM(boolean enableProcess,boolean enableEchoCancel); 52 | 53 | public native int stopRecordingAndPlaying() ; 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/OpenSLPlayer.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | 7 | /** 8 | * Created by mars_ma on 2017/3/8. 9 | */ 10 | 11 | public class OpenSLPlayer { 12 | private ExecutorService executor = Executors.newSingleThreadExecutor(); 13 | private NativeLib nativeBridge; 14 | public OpenSLPlayer(){ 15 | nativeBridge= new NativeLib(); 16 | } 17 | 18 | public boolean startToPlay(final int sampleRate, final int period, final int channels, final String path){ 19 | if(nativeBridge.isPlaying()) 20 | return false; 21 | else{ 22 | executor.execute(new Runnable() { 23 | @Override 24 | public void run() { 25 | try { 26 | nativeBridge.playRecording(sampleRate,period,channels,new String(path.getBytes(),"UTF-8")); 27 | } catch (UnsupportedEncodingException e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | }); 32 | return true; 33 | } 34 | } 35 | 36 | public boolean stopPlaying(){ 37 | if(nativeBridge.isPlaying()){ 38 | nativeBridge.stopPlaying(); 39 | return true; 40 | }else{ 41 | return false; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/OpenSLRecorder.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | 7 | /** 8 | * Created by mars_ma on 2017/3/8. 9 | */ 10 | 11 | public class OpenSLRecorder { 12 | private ExecutorService executor = Executors.newSingleThreadExecutor(); 13 | private NativeLib nativeBridge; 14 | public OpenSLRecorder(){ 15 | nativeBridge= new NativeLib(); 16 | } 17 | 18 | public boolean startToRecord(final int sampleRate, final int period, final int channels, final String path){ 19 | if(nativeBridge.isRecording()) 20 | return false; 21 | else{ 22 | executor.execute(new Runnable() { 23 | @Override 24 | public void run() { 25 | int bufferSize = sampleRate*period*channels/1000; 26 | try { 27 | nativeBridge.startRecording(sampleRate,period,channels,new String(path.getBytes(),"UTF-8")); 28 | } catch (UnsupportedEncodingException e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | }); 33 | return true; 34 | } 35 | } 36 | 37 | public boolean stopRecording(){ 38 | if(nativeBridge.isRecording()){ 39 | nativeBridge.stopRecording(); 40 | return true; 41 | }else{ 42 | return false; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/SpeexUtils.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | 7 | /** 8 | * Created by ma.xuanwei on 2017/3/16. 9 | */ 10 | 11 | public class SpeexUtils { 12 | private ExecutorService executor = Executors.newSingleThreadExecutor(); 13 | private NativeLib nativeBridge; 14 | 15 | public SpeexUtils() { 16 | nativeBridge = new NativeLib(); 17 | } 18 | 19 | public void encode(final String pcm, final String speex) { 20 | executor.execute(new Runnable() { 21 | @Override 22 | public void run() { 23 | nativeBridge.encode(pcm,speex); 24 | } 25 | }); 26 | } 27 | 28 | public void decode(final String defaultSpeexFilePath, final String defaultPcmOutputFilePath) { 29 | executor.execute(new Runnable() { 30 | @Override 31 | public void run() { 32 | nativeBridge.decode(defaultSpeexFilePath, defaultPcmOutputFilePath); 33 | } 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/dev/mars/openslesdemo/base/BaseApplication.java: -------------------------------------------------------------------------------- 1 | package dev.mars.openslesdemo.base; 2 | 3 | import android.app.Application; 4 | 5 | /** 6 | * Created by mars_ma on 2017/3/12. 7 | */ 8 | 9 | public class BaseApplication extends Application { 10 | 11 | @Override 12 | public void onCreate() { 13 | super.onCreate(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/jni/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | set(JNI_LIBS ${CMAKE_SOURCE_DIR}/../jnilibs) 4 | 5 | add_library(speex-lib SHARED IMPORTED) 6 | set_target_properties(speex-lib PROPERTIES IMPORTED_LOCATION ${JNI_LIBS}/${ANDROID_ABI}/libspeex.so) 7 | 8 | 9 | add_library(speexdsp-lib SHARED IMPORTED) 10 | set_target_properties(speexdsp-lib PROPERTIES IMPORTED_LOCATION ${JNI_LIBS}/${ANDROID_ABI}/libspeexdsp.so) 11 | 12 | include_directories( ${JNI_LIBS}/speex_include ) 13 | 14 | add_library(native SHARED 15 | native.cpp 16 | opensl_io.c 17 | opensl_io.h 18 | log.h) 19 | 20 | target_link_libraries( 21 | native 22 | log 23 | OpenSLES 24 | speex-lib 25 | speexdsp-lib 26 | ) 27 | -------------------------------------------------------------------------------- /app/src/main/jni/log.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef ANDROID_OPENSLES_DEMO_LOG_H 4 | #define ANDROID_OPENSLES_DEMO_LOG_H 5 | 6 | #endif //ANDROID_OPENSLES_DEMO_LOG_H 7 | #define LOG_OPEN 1 8 | #if(LOG_OPEN==1) 9 | #define LOG(...) __android_log_print(ANDROID_LOG_DEBUG,"dev_mars",__VA_ARGS__) 10 | #else 11 | #define LOG(...) NULL 12 | #endif 13 | -------------------------------------------------------------------------------- /app/src/main/jni/native.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include "log.h" 7 | #include "opensl_io.h" 8 | 9 | 10 | 11 | /*#define SAMPLERATE 44100 12 | #define CHANNELS 1 13 | #define PERIOD_TIME 20 //ms 14 | #define FRAME_SIZE SAMPLERATE*PERIOD_TIME/1000 15 | #define BUFFER_SIZE FRAME_SIZE*CHANNELS 16 | #define TEST_CAPTURE_FILE_PATH "/sdcard/audio.pcm"*/ 17 | 18 | /*static int SAMPLERATE; 19 | static int CHANNELS; 20 | static int PERIOD_TIME; 21 | static int FRAME_SIZE; 22 | static int BUFFER_SIZE;*/ 23 | 24 | static volatile int g_loop_exit = 0; 25 | static volatile int recording_playing = 0; 26 | 27 | 28 | 29 | extern "C" { 30 | #include "speex.h" 31 | #include "speex_preprocess.h" 32 | #include "speex_echo.h" 33 | 34 | #define SPEEX_FRAME_SIZE 160 35 | #define TAIL 1024 36 | 37 | 38 | JNIEXPORT jint JNICALL 39 | Java_dev_mars_openslesdemo_NativeLib_stopRecordingAndPlaying(JNIEnv *env, jobject instance) { 40 | recording_playing = 1; 41 | return 0; 42 | } 43 | 44 | JNIEXPORT jint JNICALL 45 | Java_dev_mars_openslesdemo_NativeLib_recordAndPlayPCM(JNIEnv *env, jobject instance,jboolean enableProcess,jboolean enableEchoCancel) { 46 | bool initEchoBuffer = false; 47 | SpeexPreprocessState *preprocess_state; 48 | SpeexEchoState *echo_state; 49 | spx_int16_t echo_buf[SPEEX_FRAME_SIZE],echo_canceled_buf[SPEEX_FRAME_SIZE]; 50 | int sampleRate = 8000; 51 | if(enableEchoCancel){ 52 | 53 | echo_state = speex_echo_state_init(SPEEX_FRAME_SIZE,TAIL); 54 | if(echo_state==NULL){ 55 | LOG("speex_echo_state_init failed"); 56 | return -3; 57 | } 58 | speex_echo_ctl(echo_state, SPEEX_ECHO_SET_SAMPLING_RATE,&sampleRate); 59 | } 60 | 61 | if (enableProcess) { 62 | /** 63 | * 音频处理器初始化 start 64 | */ 65 | 66 | preprocess_state = speex_preprocess_state_init(SPEEX_FRAME_SIZE, 67 | sampleRate); 68 | spx_int32_t denoise = 1; 69 | //SPEEX_PREPROCESS_SET_DENOISE Turns denoising on(1) or off(2) (spx_int32_t) 70 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_DENOISE, &denoise); //降噪 71 | spx_int32_t noiseSuppress = -25;//负的32位整数 72 | //SPEEX_PREPROCESS_SET_NOISE_SUPPRESS Set maximum attenuation of the noise in dB (negative spx_int32_t) 73 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, 74 | &noiseSuppress); //设置噪声的dB 75 | 76 | spx_int32_t agc = 1; 77 | //Turns automatic gain control (AGC) on(1) or off(2) (spx_int32_t) 78 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_AGC, &agc);//增益 79 | spx_int32_t level = 24000; 80 | //actually default is 8000(0,32768),here make it louder for voice is not loudy enough by default. 81 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_AGC_LEVEL, &level); 82 | 83 | int vad = 1; 84 | int vadProbStart = 80; 85 | int vadProbContinue = 65; 86 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_VAD, &vad); //静音检测 87 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_PROB_START, &vadProbStart); 88 | //Set probability required for the VAD to Go from silence to voice 89 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_PROB_CONTINUE, 90 | &vadProbContinue); //Set probability required for the VAD to 91 | 92 | if (preprocess_state == NULL) { 93 | LOG("speex_preprocess_state_init failed!"); 94 | return -1; 95 | } else { 96 | LOG("speex_preprocess_state_init speex_frame_size = %d sampleRate = %d ", 97 | SPEEX_FRAME_SIZE, sampleRate); 98 | } 99 | 100 | /** 101 | * 音频处理器初始化 end 102 | */ 103 | } 104 | 105 | jclass native_bridge_class = env->GetObjectClass(instance); 106 | jmethodID method_id_setIsRecordingAndPlaying = env->GetMethodID(native_bridge_class, 107 | "setIsRecordingAndPlaying", 108 | "(Z)V"); 109 | 110 | 111 | //参数依次为采样率、频道数量、录入频道数量、播放频道数量,每帧的大学,模式 112 | OPENSL_STREAM *stream_record = android_OpenAudioDevice(sampleRate, 1, 1, 113 | SPEEX_FRAME_SIZE, RECORD_MODE); 114 | OPENSL_STREAM *stream_play = android_OpenAudioDevice(sampleRate, 1, 1, SPEEX_FRAME_SIZE, 115 | PLAY_MODE); 116 | if (stream_play == NULL || stream_record == NULL) { 117 | LOG("stream_record or stream_play open failed!"); 118 | } else { 119 | LOG("stream_record or stream_play open success!"); 120 | } 121 | 122 | if (stream_record == NULL || stream_play == NULL) { 123 | LOG("failed to open audio device ! \n"); 124 | env->CallVoidMethod(instance, method_id_setIsRecordingAndPlaying, false); 125 | return -1; 126 | } 127 | 128 | LOG("IN RECORDING AND PLAYING STATE"); 129 | env->CallVoidMethod(instance, method_id_setIsRecordingAndPlaying, true); 130 | uint32_t samples; 131 | //缓冲数组,单位usigned short,16bit 132 | uint16_t buffer[SPEEX_FRAME_SIZE]; 133 | recording_playing = 0; 134 | while (!recording_playing) { 135 | samples = android_AudioIn(stream_record, buffer, SPEEX_FRAME_SIZE); 136 | if (samples < 0) { 137 | LOG("android_AudioIn failed !\n"); 138 | break; 139 | } 140 | spx_int16_t *ptr ; 141 | if(enableEchoCancel||enableProcess){ 142 | ptr = (spx_int16_t *) buffer; 143 | } 144 | if(enableEchoCancel&&initEchoBuffer){ 145 | /** 146 | * 将录音的数组复制一份给回声数组 147 | */ 148 | //第二个参数就是上一次播放的音频数据 149 | speex_echo_cancellation(echo_state, ptr, echo_buf, echo_canceled_buf); 150 | for(int i=0;iCallVoidMethod(instance, method_id_setIsRecordingAndPlaying, false); 184 | LOG("native recordAndPlayPCM completed "); 185 | return 0; 186 | } 187 | 188 | 189 | JNIEXPORT jint JNICALL 190 | Java_dev_mars_openslesdemo_NativeLib_encode(JNIEnv *env, jobject instance, jstring pcm_, 191 | jstring speex_) { 192 | const char *pcm_path = env->GetStringUTFChars(pcm_, 0); 193 | const char *speex_path = env->GetStringUTFChars(speex_, 0); 194 | time_t t1, t2; 195 | time(&t1); 196 | // TODO 197 | /*帧的大小在这个例程中是一个固定的值,但它并不是必须这样*/ 198 | int FRAME_SIZE = 160; 199 | 200 | const char *inFile; 201 | FILE *fin; 202 | FILE *fout; 203 | short in[FRAME_SIZE]; 204 | float input[FRAME_SIZE]; 205 | char cbits[200]; 206 | int nbBytes; 207 | /*保存编码的状态*/ 208 | void *state; 209 | /*保存字节因此他们可以被speex常规读写*/ 210 | SpeexBits bits; 211 | int i, tmp; 212 | //新建一个新的编码状态在窄宽(narrowband)模式下 213 | state = speex_encoder_init(&speex_nb_mode); 214 | //设置质量为8(15kbps) 215 | tmp = 8; 216 | speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp); 217 | inFile = pcm_path; 218 | 219 | fin = fopen(inFile, "r"); 220 | if (fin == NULL) { 221 | LOG("%s open failed", inFile); 222 | } 223 | fout = fopen(speex_path, "wb"); 224 | if (fout == NULL) { 225 | LOG("%s open failed", speex_path); 226 | } 227 | //初始化结构使他们保存数据 228 | speex_bits_init(&bits); 229 | while (1) { 230 | //读入一帧16bits的声音 231 | fread(in, sizeof(short), FRAME_SIZE, fin); 232 | if (feof(fin)) 233 | break; 234 | //把16bits的值转化为float,以便speex库可以在上面工作 235 | for (i = 0; i < FRAME_SIZE; i++) 236 | input[i] = in[i]; 237 | 238 | //清空这个结构体里所有的字节,以便我们可以编码一个新的帧 239 | speex_bits_reset(&bits); 240 | //对帧进行编码 241 | speex_encode(state, input, &bits); 242 | //把bits拷贝到一个利用写出的char型数组 243 | nbBytes = speex_bits_write(&bits, cbits, 200); 244 | //首先写出帧的大小,这是sampledec文件需要的一个值,但是你的应用程序中可能不一样 245 | 246 | fwrite(&nbBytes, sizeof(int), 1, fout); 247 | //LOG("写入4bit : %d ",nbBytes); 248 | //写出压缩后的数组 249 | fwrite(cbits, 1, nbBytes, fout); 250 | //LOG("写入%d bit ",nbBytes); 251 | } 252 | 253 | //释放编码器状态量 254 | speex_encoder_destroy(state); 255 | //释放bit_packing结构 256 | speex_bits_destroy(&bits); 257 | fclose(fin); 258 | fclose(fout); 259 | env->ReleaseStringUTFChars(pcm_, pcm_path); 260 | env->ReleaseStringUTFChars(speex_, speex_path); 261 | time(&t2); 262 | LOG("%s convert to %s success! spend %f s", inFile, speex_path, difftime(t2, t1)); 263 | return 0; 264 | } 265 | 266 | JNIEXPORT jint JNICALL 267 | Java_dev_mars_openslesdemo_NativeLib_decode(JNIEnv *env, jobject instance, jstring speex_, 268 | jstring pcm_) { 269 | const char *speex = env->GetStringUTFChars(speex_, 0); 270 | const char *pcm = env->GetStringUTFChars(pcm_, 0); 271 | time_t t1, t2; 272 | time(&t1); 273 | // TODO 274 | /*帧的大小在这个例程中是一个固定的值,但它并不是必须这样*/ 275 | int FRAME_SIZE = 160; 276 | 277 | const char *inFile; 278 | FILE *fin; 279 | FILE *fout; 280 | short out[FRAME_SIZE]; 281 | float output[FRAME_SIZE]; 282 | char cbits[200]; 283 | int nbBytes; 284 | /*保存编码的状态*/ 285 | void *state; 286 | /*保存字节因此他们可以被speex常规读写*/ 287 | SpeexBits bits; 288 | int i, tmp; 289 | //新建一个新的编码状态在窄宽(narrowband)模式下 290 | state = speex_decoder_init(&speex_nb_mode); 291 | //设置质量为8(15kbps) 292 | tmp = 8; 293 | inFile = speex; 294 | 295 | fin = fopen(inFile, "r"); 296 | if (fin == NULL) { 297 | LOG("%s open failed", inFile); 298 | return -1; 299 | } 300 | fout = fopen(pcm, "wb"); 301 | if (fout == NULL) { 302 | LOG("%s open failed", pcm); 303 | return -1; 304 | } 305 | //初始化结构使他们保存数据 306 | speex_bits_init(&bits); 307 | 308 | while (1) { 309 | 310 | int size = 0; 311 | fread(&size, sizeof(int), 1, fin); 312 | fread(cbits, 1, size, fin); 313 | if (feof(fin)) { 314 | LOG("文件解析完毕"); 315 | break; 316 | } 317 | 318 | speex_bits_reset(&bits); 319 | //把读入的char数组拷贝到bits 320 | speex_bits_read_from(&bits, cbits, size); 321 | //将bits中的数据解码到output 322 | speex_decode(state, &bits, output); 323 | //把16bits的float转换short,以便pcm播放 324 | for (i = 0; i < FRAME_SIZE; i++) 325 | out[i] = output[i]; 326 | 327 | fwrite(out, sizeof(short), FRAME_SIZE, fout); 328 | } 329 | 330 | //释放编码器状态量 331 | speex_decoder_destroy(state); 332 | //释放bit_packing结构 333 | speex_bits_destroy(&bits); 334 | fclose(fin); 335 | fclose(fout); 336 | 337 | time(&t2); 338 | LOG("%s convert to %s success! spend %f s", inFile, pcm, difftime(t2, t1)); 339 | env->ReleaseStringUTFChars(speex_, speex); 340 | env->ReleaseStringUTFChars(pcm_, pcm); 341 | return 0; 342 | } 343 | 344 | JNIEXPORT void JNICALL 345 | Java_dev_mars_openslesdemo_NativeLib_startRecording(JNIEnv *env, jobject instance, jint sampleRate, 346 | jint periodTime, jint channels, 347 | jstring audioPath) { 348 | time_t t1, t2; 349 | time(&t1); 350 | double total_time = 0; 351 | const char *audio_path = env->GetStringUTFChars(audioPath, NULL); 352 | jclass native_bridge_class = env->GetObjectClass(instance); 353 | //此方法用于设置录音状况的同步标记 354 | jmethodID method_id_setIsRecording = env->GetMethodID(native_bridge_class, "setIsRecording", 355 | "(Z)V"); 356 | 357 | //以只写方式打开或新建一个二进制文件,只允许写数据。 358 | FILE *fp = fopen(audio_path, "wb"); //创建文件 359 | if (fp == NULL) { 360 | LOG("cannot open file (%s)\n", audio_path); 361 | //设置状态录音状态为:空闲 362 | env->CallVoidMethod(instance, method_id_setIsRecording, false); 363 | return; 364 | } else { 365 | LOG("open file %s", audio_path); 366 | } 367 | 368 | //参数依次为采样率、频道数量、录入频道数量、播放频道数量,每帧的大学,模式 369 | uint32_t FRAME_SIZE = sampleRate * periodTime / 1000; 370 | OPENSL_STREAM *stream = android_OpenAudioDevice(sampleRate, channels, channels, FRAME_SIZE, 371 | RECORD_MODE); 372 | if (stream == NULL) { 373 | fclose(fp); 374 | LOG("failed to open audio device ! \n"); 375 | env->CallVoidMethod(instance, method_id_setIsRecording, false); 376 | return; 377 | } 378 | 379 | LOG("IN RECORDING STATE"); 380 | env->CallVoidMethod(instance, method_id_setIsRecording, true); 381 | uint32_t samples; 382 | //缓冲数组,单位usigned short,16bit 383 | uint32_t BUFFER_SIZE = FRAME_SIZE * channels; 384 | uint16_t buffer[BUFFER_SIZE]; 385 | g_loop_exit = 0; 386 | while (!g_loop_exit) { 387 | samples = android_AudioIn(stream, buffer, BUFFER_SIZE); 388 | if (samples < 0) { 389 | LOG("android_AudioIn failed !\n"); 390 | break; 391 | } 392 | LOG(" samples*sizeof(uint16_t) : %d", samples * sizeof(uint16_t)); 393 | LOG(" sizeof(buffer) : %d", sizeof(buffer)); 394 | //为了防止缓冲数组未写满,所以用samples*sizeof(uint16_t),samples表示缓冲数组中有效写入的字节 395 | if (fwrite(buffer, samples * sizeof(uint16_t), 1, fp) != 1) { 396 | LOG("failed to save captured data !\n "); 397 | break; 398 | } 399 | total_time += 20; 400 | LOG("capture %d samples !\n", samples); 401 | } 402 | 403 | android_CloseAudioDevice(stream); 404 | fclose(fp); 405 | env->CallVoidMethod(instance, method_id_setIsRecording, false); 406 | time(&t2); 407 | LOG("native startRecord completed spend %f s %f ms!", difftime(t2, t1), total_time); 408 | 409 | } 410 | 411 | JNIEXPORT void JNICALL 412 | Java_dev_mars_openslesdemo_NativeLib_stopRecording(JNIEnv *env, jobject instance) { 413 | g_loop_exit = 1; 414 | } 415 | 416 | JNIEXPORT void JNICALL 417 | Java_dev_mars_openslesdemo_NativeLib_playRecording(JNIEnv *env, jobject instance, jint sampleRate, 418 | jint periodTime, jint channels, 419 | jstring audioPath) { 420 | const char *audio_path = env->GetStringUTFChars(audioPath, NULL); 421 | jclass native_bridge_class = env->GetObjectClass(instance); 422 | jmethodID method_id_setIsPlaying = env->GetMethodID(native_bridge_class, "setIsPlaying", 423 | "(Z)V"); 424 | 425 | FILE *fp = fopen(audio_path, "rb"); 426 | if (fp == NULL) { 427 | LOG("cannot open file (%s) !\n", audio_path); 428 | env->CallVoidMethod(instance, method_id_setIsPlaying, false); 429 | return; 430 | } else { 431 | LOG("open file %s", audio_path); 432 | } 433 | 434 | uint32_t FRAME_SIZE = sampleRate * periodTime / 1000; 435 | OPENSL_STREAM *stream = android_OpenAudioDevice(sampleRate, channels, channels, FRAME_SIZE, 436 | PLAY_MODE); 437 | if (stream == NULL) { 438 | fclose(fp); 439 | LOG("failed to open audio device ! \n"); 440 | env->CallVoidMethod(instance, method_id_setIsPlaying, false); 441 | return; 442 | } 443 | LOG("In playing state"); 444 | env->CallVoidMethod(instance, method_id_setIsPlaying, true); 445 | int samples; 446 | int BUFFER_SIZE = FRAME_SIZE * channels; 447 | uint16_t buffer[BUFFER_SIZE]; 448 | g_loop_exit = 0; 449 | while (!g_loop_exit && !feof(fp)) { 450 | if (fread(buffer, BUFFER_SIZE * sizeof(uint16_t), 1, fp) != 1) { 451 | LOG("failed to read data \n "); 452 | break; 453 | } 454 | samples = android_AudioOut(stream, buffer, BUFFER_SIZE); 455 | if (samples < 0) { 456 | LOG("android_AudioOut failed !\n"); 457 | } 458 | LOG("playback %d samples !\n", samples); 459 | } 460 | 461 | android_CloseAudioDevice(stream); 462 | fclose(fp); 463 | env->CallVoidMethod(instance, method_id_setIsPlaying, false); 464 | LOG("native playRecord completed !"); 465 | return; 466 | } 467 | 468 | JNIEXPORT void JNICALL 469 | Java_dev_mars_openslesdemo_NativeLib_stopPlaying(JNIEnv *env, jobject instance) { 470 | g_loop_exit = 1; 471 | return; 472 | } 473 | 474 | } -------------------------------------------------------------------------------- /app/src/main/jni/opensl_io.c: -------------------------------------------------------------------------------- 1 | /* 2 | opensl_io.c: 3 | Android OpenSL input/output module 4 | Copyright (c) 2012, Victor Lazzarini All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "opensl_io.h" 30 | #include "log.h" 31 | 32 | #define CONV16BIT 32768 33 | #define CONVMYFLT (1./32768.) 34 | 35 | static void* createThreadLock(void); 36 | static int waitThreadLock(void *lock); 37 | static void notifyThreadLock(void *lock); 38 | static void destroyThreadLock(void *lock); 39 | static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context); 40 | static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context); 41 | 42 | // creates the OpenSL ES audio engine 43 | static SLresult openSLCreateEngine(OPENSL_STREAM *p) 44 | { 45 | SLresult result; 46 | // create engine 47 | result = slCreateEngine(&(p->engineObject), 0, NULL, 0, NULL, NULL); 48 | if(result != SL_RESULT_SUCCESS) goto engine_end; 49 | 50 | // realize the engine 51 | result = (*p->engineObject)->Realize(p->engineObject, SL_BOOLEAN_FALSE); 52 | if(result != SL_RESULT_SUCCESS) goto engine_end; 53 | 54 | // get the engine interface, which is needed in order to create other objects 55 | result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE, &(p->engineEngine)); 56 | if(result != SL_RESULT_SUCCESS) goto engine_end; 57 | 58 | engine_end: 59 | return result; 60 | } 61 | 62 | // opens the OpenSL ES device for output 63 | static SLresult openSLPlayOpen(OPENSL_STREAM *p) 64 | { 65 | SLresult result; 66 | SLuint32 sr = p->sampleRate; 67 | SLuint32 channels = p->outchannels; 68 | 69 | if(channels) { 70 | // configure audio source 71 | SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2}; 72 | 73 | switch(sr){ 74 | case 8000: 75 | sr = SL_SAMPLINGRATE_8; 76 | break; 77 | case 11025: 78 | sr = SL_SAMPLINGRATE_11_025; 79 | break; 80 | case 16000: 81 | sr = SL_SAMPLINGRATE_16; 82 | break; 83 | case 22050: 84 | sr = SL_SAMPLINGRATE_22_05; 85 | break; 86 | case 24000: 87 | sr = SL_SAMPLINGRATE_24; 88 | break; 89 | case 32000: 90 | sr = SL_SAMPLINGRATE_32; 91 | break; 92 | case 44100: 93 | sr = SL_SAMPLINGRATE_44_1; 94 | break; 95 | case 48000: 96 | sr = SL_SAMPLINGRATE_48; 97 | break; 98 | case 64000: 99 | sr = SL_SAMPLINGRATE_64; 100 | break; 101 | case 88200: 102 | sr = SL_SAMPLINGRATE_88_2; 103 | break; 104 | case 96000: 105 | sr = SL_SAMPLINGRATE_96; 106 | break; 107 | case 192000: 108 | sr = SL_SAMPLINGRATE_192; 109 | break; 110 | default: 111 | break; 112 | 113 | return -1; 114 | } 115 | 116 | const SLInterfaceID ids[] = {SL_IID_VOLUME}; 117 | const SLboolean req[] = {SL_BOOLEAN_FALSE}; 118 | result = (*p->engineEngine)->CreateOutputMix(p->engineEngine, &(p->outputMixObject), 1, ids, req); 119 | if(result != SL_RESULT_SUCCESS) goto end_openaudio; 120 | 121 | // realize the output mix 122 | result = (*p->outputMixObject)->Realize(p->outputMixObject, SL_BOOLEAN_FALSE); 123 | 124 | int speakers; 125 | if(channels > 1) 126 | speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; 127 | else speakers = SL_SPEAKER_FRONT_CENTER; 128 | 129 | SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM,channels, sr, 130 | SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16, 131 | speakers, SL_BYTEORDER_LITTLEENDIAN}; 132 | 133 | SLDataSource audioSrc = {&loc_bufq, &format_pcm}; 134 | 135 | // configure audio sink 136 | SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, p->outputMixObject}; 137 | SLDataSink audioSnk = {&loc_outmix, NULL}; 138 | 139 | // create audio player 140 | const SLInterfaceID ids1[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE}; 141 | const SLboolean req1[] = {SL_BOOLEAN_TRUE}; 142 | result = (*p->engineEngine)->CreateAudioPlayer(p->engineEngine, &(p->bqPlayerObject), &audioSrc, &audioSnk, 143 | 1, ids1, req1); 144 | if(result != SL_RESULT_SUCCESS) goto end_openaudio; 145 | 146 | // realize the player 147 | result = (*p->bqPlayerObject)->Realize(p->bqPlayerObject, SL_BOOLEAN_FALSE); 148 | if(result != SL_RESULT_SUCCESS) goto end_openaudio; 149 | 150 | // get the play interface 151 | result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_PLAY, &(p->bqPlayerPlay)); 152 | if(result != SL_RESULT_SUCCESS) goto end_openaudio; 153 | 154 | // get the buffer queue interface 155 | result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, 156 | &(p->bqPlayerBufferQueue)); 157 | if(result != SL_RESULT_SUCCESS) goto end_openaudio; 158 | 159 | // register callback on the buffer queue 160 | result = (*p->bqPlayerBufferQueue)->RegisterCallback(p->bqPlayerBufferQueue, bqPlayerCallback, p); 161 | if(result != SL_RESULT_SUCCESS) goto end_openaudio; 162 | 163 | // set the player's state to playing 164 | result = (*p->bqPlayerPlay)->SetPlayState(p->bqPlayerPlay, SL_PLAYSTATE_PLAYING); 165 | 166 | end_openaudio: 167 | return result; 168 | 169 | } 170 | 171 | return SL_RESULT_SUCCESS; 172 | } 173 | 174 | // Open the OpenSL ES device for input 175 | static SLresult openSLRecOpen(OPENSL_STREAM *p) 176 | { 177 | SLresult result; 178 | SLuint32 sr = p->sampleRate; 179 | SLuint32 channels = p->inchannels; 180 | 181 | if(channels) { 182 | switch(sr) { 183 | case 8000: 184 | sr = SL_SAMPLINGRATE_8; 185 | break; 186 | case 11025: 187 | sr = SL_SAMPLINGRATE_11_025; 188 | break; 189 | case 16000: 190 | sr = SL_SAMPLINGRATE_16; 191 | break; 192 | case 22050: 193 | sr = SL_SAMPLINGRATE_22_05; 194 | break; 195 | case 24000: 196 | sr = SL_SAMPLINGRATE_24; 197 | break; 198 | case 32000: 199 | sr = SL_SAMPLINGRATE_32; 200 | break; 201 | case 44100: 202 | sr = SL_SAMPLINGRATE_44_1; 203 | break; 204 | case 48000: 205 | sr = SL_SAMPLINGRATE_48; 206 | break; 207 | case 64000: 208 | sr = SL_SAMPLINGRATE_64; 209 | break; 210 | case 88200: 211 | sr = SL_SAMPLINGRATE_88_2; 212 | break; 213 | case 96000: 214 | sr = SL_SAMPLINGRATE_96; 215 | break; 216 | case 192000: 217 | sr = SL_SAMPLINGRATE_192; 218 | break; 219 | default: 220 | break; 221 | 222 | return -1; 223 | } 224 | 225 | // configure audio source 226 | SLDataLocator_IODevice loc_dev = {SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT, 227 | SL_DEFAULTDEVICEID_AUDIOINPUT, NULL}; 228 | SLDataSource audioSrc = {&loc_dev, NULL}; 229 | 230 | // configure audio sink 231 | int speakers; 232 | if(channels > 1) 233 | speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; 234 | else speakers = SL_SPEAKER_FRONT_CENTER; 235 | 236 | SLDataLocator_AndroidSimpleBufferQueue loc_bq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2}; 237 | SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, channels, sr, 238 | SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16, 239 | speakers, SL_BYTEORDER_LITTLEENDIAN}; 240 | SLDataSink audioSnk = {&loc_bq, &format_pcm}; 241 | 242 | // create audio recorder 243 | // (requires the RECORD_AUDIO permission) 244 | const SLInterfaceID id[1] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE}; 245 | const SLboolean req[1] = {SL_BOOLEAN_TRUE}; 246 | result = (*p->engineEngine)->CreateAudioRecorder(p->engineEngine, &(p->recorderObject), &audioSrc, 247 | &audioSnk, 1, id, req); 248 | if (SL_RESULT_SUCCESS != result) goto end_recopen; 249 | 250 | // realize the audio recorder 251 | result = (*p->recorderObject)->Realize(p->recorderObject, SL_BOOLEAN_FALSE); 252 | if (SL_RESULT_SUCCESS != result) goto end_recopen; 253 | 254 | // get the record interface 255 | result = (*p->recorderObject)->GetInterface(p->recorderObject, SL_IID_RECORD, &(p->recorderRecord)); 256 | if (SL_RESULT_SUCCESS != result) goto end_recopen; 257 | 258 | // get the buffer queue interface 259 | result = (*p->recorderObject)->GetInterface(p->recorderObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, 260 | &(p->recorderBufferQueue)); 261 | if (SL_RESULT_SUCCESS != result) goto end_recopen; 262 | 263 | // register callback on the buffer queue 264 | result = (*p->recorderBufferQueue)->RegisterCallback(p->recorderBufferQueue, bqRecorderCallback, 265 | p); 266 | if (SL_RESULT_SUCCESS != result) goto end_recopen; 267 | result = (*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING); 268 | 269 | end_recopen: 270 | return result; 271 | } 272 | else 273 | return SL_RESULT_SUCCESS; 274 | } 275 | 276 | // close the OpenSL IO and destroy the audio engine 277 | static void openSLDestroyEngine(OPENSL_STREAM *p) 278 | { 279 | // destroy buffer queue audio player object, and invalidate all associated interfaces 280 | if (p->bqPlayerObject != NULL) { 281 | (*p->bqPlayerObject)->Destroy(p->bqPlayerObject); 282 | p->bqPlayerObject = NULL; 283 | p->bqPlayerPlay = NULL; 284 | p->bqPlayerBufferQueue = NULL; 285 | p->bqPlayerEffectSend = NULL; 286 | } 287 | 288 | // destroy audio recorder object, and invalidate all associated interfaces 289 | if (p->recorderObject != NULL) { 290 | (*p->recorderObject)->Destroy(p->recorderObject); 291 | p->recorderObject = NULL; 292 | p->recorderRecord = NULL; 293 | p->recorderBufferQueue = NULL; 294 | } 295 | 296 | // destroy output mix object, and invalidate all associated interfaces 297 | if (p->outputMixObject != NULL) { 298 | (*p->outputMixObject)->Destroy(p->outputMixObject); 299 | p->outputMixObject = NULL; 300 | } 301 | 302 | // destroy engine object, and invalidate all associated interfaces 303 | if (p->engineObject != NULL) { 304 | (*p->engineObject)->Destroy(p->engineObject); 305 | p->engineObject = NULL; 306 | p->engineEngine = NULL; 307 | } 308 | } 309 | 310 | // open the android audio device for input and/or output 311 | OPENSL_STREAM *android_OpenAudioDevice(uint32_t sr, uint32_t inchannels, uint32_t outchannels, uint32_t bufferframes,uint32_t mode) 312 | { 313 | OPENSL_STREAM *p; 314 | //分配内存空间并初始化 315 | p = (OPENSL_STREAM *) calloc(1,sizeof(OPENSL_STREAM)); 316 | //采样率 317 | p->sampleRate = sr; 318 | 319 | //创建引擎对象及接口 320 | if(openSLCreateEngine(p) != SL_RESULT_SUCCESS) { 321 | android_CloseAudioDevice(p); 322 | return NULL; 323 | } 324 | 325 | if(mode==RECORD_MODE){ 326 | 327 | //输入声道数 328 | p->inchannels = inchannels; 329 | //创建录入锁 330 | p->inlock = createThreadLock(); 331 | if((p->inBufSamples = bufferframes*inchannels) != 0){ 332 | //初始化录入缓冲数组 333 | if((p->inputBuffer[0] = (uint16_t *) calloc(p->inBufSamples, sizeof(uint16_t))) == NULL || 334 | (p->inputBuffer[1] = (uint16_t *) calloc(p->inBufSamples, sizeof(uint16_t))) == NULL){ 335 | android_CloseAudioDevice(p); 336 | return NULL; 337 | } 338 | } 339 | p->currentInputIndex = 0; 340 | p->currentInputIndex = p->inBufSamples; 341 | p->currentInputBuffer = 0; 342 | 343 | if(openSLRecOpen(p) != SL_RESULT_SUCCESS) { 344 | android_CloseAudioDevice(p); 345 | return NULL; 346 | } 347 | 348 | notifyThreadLock(p->inlock); 349 | 350 | }else if(mode==PLAY_MODE){ 351 | 352 | //输出声道数 353 | p->outchannels = outchannels; 354 | //创建播放锁 355 | p->outlock = createThreadLock(); 356 | if((p->outBufSamples = bufferframes*outchannels) != 0) { 357 | //初始化播放缓冲数组 358 | if((p->outputBuffer[0] = (uint16_t *) calloc(p->outBufSamples, sizeof(uint16_t))) == NULL || 359 | (p->outputBuffer[1] = (uint16_t *) calloc(p->outBufSamples, sizeof(uint16_t))) == NULL) { 360 | android_CloseAudioDevice(p); 361 | return NULL; 362 | } 363 | } 364 | p->currentOutputBuffer = 0; 365 | 366 | if(openSLPlayOpen(p) != SL_RESULT_SUCCESS) { 367 | android_CloseAudioDevice(p); 368 | return NULL; 369 | } 370 | 371 | notifyThreadLock(p->outlock); 372 | }else{ 373 | return NULL; 374 | } 375 | 376 | p->time = 0.; 377 | return p; 378 | } 379 | 380 | // close the android audio device 381 | void android_CloseAudioDevice(OPENSL_STREAM *p) 382 | { 383 | if (p == NULL) 384 | return; 385 | 386 | openSLDestroyEngine(p); 387 | 388 | if (p->inlock != NULL) { 389 | notifyThreadLock(p->inlock); 390 | destroyThreadLock(p->inlock); 391 | p->inlock = NULL; 392 | } 393 | 394 | if (p->outlock != NULL) { 395 | notifyThreadLock(p->outlock); 396 | destroyThreadLock(p->outlock); 397 | p->inlock = NULL; 398 | } 399 | 400 | if (p->outputBuffer[0] != NULL) { 401 | free(p->outputBuffer[0]); 402 | p->outputBuffer[0] = NULL; 403 | } 404 | 405 | if (p->outputBuffer[1] != NULL) { 406 | free(p->outputBuffer[1]); 407 | p->outputBuffer[1] = NULL; 408 | } 409 | 410 | if (p->inputBuffer[0] != NULL) { 411 | free(p->inputBuffer[0]); 412 | p->inputBuffer[0] = NULL; 413 | } 414 | 415 | if (p->inputBuffer[1] != NULL) { 416 | free(p->inputBuffer[1]); 417 | p->inputBuffer[1] = NULL; 418 | } 419 | 420 | free(p); 421 | } 422 | 423 | // returns timestamp of the processed stream 424 | double android_GetTimestamp(OPENSL_STREAM *p) 425 | { 426 | return p->time; 427 | } 428 | 429 | // this callback handler is called every time a buffer finishes recording 430 | void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context) 431 | { 432 | LOG("bqRecorderCallback"); 433 | OPENSL_STREAM *p = (OPENSL_STREAM *) context; 434 | notifyThreadLock(p->inlock); 435 | } 436 | 437 | // gets a buffer of size samples from the device 438 | uint32_t android_AudioIn(OPENSL_STREAM *p,uint16_t *buffer,uint32_t size) 439 | { 440 | uint16_t *inBuffer; 441 | //录音缓冲数组的大小 442 | uint32_t bufsamps = p->inBufSamples; 443 | uint32_t index = p->currentInputIndex; 444 | if(p == NULL || bufsamps == 0) return 0; 445 | //得到缓冲数组指针 446 | inBuffer = p->inputBuffer[p->currentInputBuffer]; 447 | uint32_t i; 448 | for(i=0; i < size; i++){ 449 | if (index >= bufsamps) { 450 | waitThreadLock(p->inlock); 451 | (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,inBuffer,bufsamps*sizeof(uint16_t)); 452 | p->currentInputBuffer = (p->currentInputBuffer ? 0 : 1); 453 | index = 0; 454 | inBuffer = p->inputBuffer[p->currentInputBuffer]; 455 | } 456 | buffer[i] = (uint16_t)inBuffer[index++]; 457 | } 458 | p->currentInputIndex = index; 459 | if(p->outchannels == 0) p->time += (double) size/(p->sampleRate*p->inchannels); 460 | return i; 461 | } 462 | 463 | // this callback handler is called every time a buffer finishes playing 464 | void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) 465 | { 466 | LOG("bqPlayerCallback"); 467 | OPENSL_STREAM *p = (OPENSL_STREAM *) context; 468 | notifyThreadLock(p->outlock); 469 | } 470 | 471 | // puts a buffer of size samples to the device 472 | uint32_t android_AudioOut(OPENSL_STREAM *p, uint16_t *buffer,uint32_t size) 473 | { 474 | uint16_t *outBuffer; 475 | uint32_t i, bufsamps = p->outBufSamples, index = p->currentOutputIndex; 476 | if(p == NULL || bufsamps == 0) return 0; 477 | outBuffer = p->outputBuffer[p->currentOutputBuffer]; 478 | 479 | for(i=0; i < size; i++){ 480 | outBuffer[index++] = (uint16_t)(buffer[i]); 481 | if (index >= p->outBufSamples) { 482 | waitThreadLock(p->outlock); 483 | (*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue, 484 | outBuffer,bufsamps*sizeof(uint16_t)); 485 | p->currentOutputBuffer = (p->currentOutputBuffer ? 0 : 1); 486 | index = 0; 487 | outBuffer = p->outputBuffer[p->currentOutputBuffer]; 488 | } 489 | } 490 | p->currentOutputIndex = index; 491 | p->time += (double) size/(p->sampleRate*p->outchannels); 492 | return i; 493 | } 494 | 495 | //---------------------------------------------------------------------- 496 | // thread Locks 497 | // to ensure synchronisation between callbacks and processing code 498 | void* createThreadLock(void) 499 | { 500 | threadLock *p; 501 | p = (threadLock*) malloc(sizeof(threadLock)); 502 | if (p == NULL) 503 | return NULL; 504 | memset(p, 0, sizeof(threadLock)); 505 | if (pthread_mutex_init(&(p->m), (pthread_mutexattr_t*) NULL) != 0) { 506 | free((void*) p); 507 | return NULL; 508 | } 509 | if (pthread_cond_init(&(p->c), (pthread_condattr_t*) NULL) != 0) { 510 | pthread_mutex_destroy(&(p->m)); 511 | free((void*) p); 512 | return NULL; 513 | } 514 | p->s = (unsigned char)1; 515 | 516 | return p; 517 | } 518 | 519 | int waitThreadLock(void *lock) 520 | { 521 | threadLock *p; 522 | int retval = 0; 523 | p = (threadLock*)lock; 524 | pthread_mutex_lock(&(p->m)); 525 | while (!p->s) { 526 | pthread_cond_wait(&(p->c), &(p->m)); 527 | } 528 | p->s = (unsigned char)0; 529 | pthread_mutex_unlock(&(p->m)); 530 | } 531 | 532 | void notifyThreadLock(void *lock) 533 | { 534 | threadLock *p; 535 | p = (threadLock*) lock; 536 | pthread_mutex_lock(&(p->m)); 537 | p->s = (unsigned char)1; 538 | pthread_cond_signal(&(p->c)); 539 | pthread_mutex_unlock(&(p->m)); 540 | } 541 | 542 | void destroyThreadLock(void *lock) 543 | { 544 | threadLock *p; 545 | p = (threadLock*) lock; 546 | if (p == NULL) 547 | return; 548 | notifyThreadLock(p); 549 | pthread_cond_destroy(&(p->c)); 550 | pthread_mutex_destroy(&(p->m)); 551 | free(p); 552 | } 553 | -------------------------------------------------------------------------------- /app/src/main/jni/opensl_io.h: -------------------------------------------------------------------------------- 1 | /* opensl_io.c: 2 | Android OpenSL input/output module header 3 | Copyright (c) 2012, Victor Lazzarini All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef OPENSL_IO 29 | #define OPENSL_IO 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define RECORD_MODE 0 37 | #define PLAY_MODE 1 38 | 39 | typedef struct threadLock_ { 40 | pthread_mutex_t m; 41 | pthread_cond_t c; 42 | unsigned char s; 43 | } threadLock; 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | typedef struct opensl_stream { 50 | 51 | // engine interfaces 52 | SLObjectItf engineObject; 53 | SLEngineItf engineEngine; 54 | 55 | // output mix interfaces 56 | SLObjectItf outputMixObject; 57 | 58 | // buffer queue player interfaces 59 | SLObjectItf bqPlayerObject; 60 | SLPlayItf bqPlayerPlay; 61 | SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; 62 | SLEffectSendItf bqPlayerEffectSend; 63 | 64 | // recorder interfaces 65 | SLObjectItf recorderObject; 66 | SLRecordItf recorderRecord; 67 | SLAndroidSimpleBufferQueueItf recorderBufferQueue; 68 | 69 | // buffer indexes 70 | uint32_t currentInputIndex; 71 | uint32_t currentOutputIndex; 72 | 73 | // current buffer half (0, 1) 74 | uint8_t currentOutputBuffer; 75 | uint8_t currentInputBuffer; 76 | 77 | // buffers 78 | uint16_t *outputBuffer[2]; 79 | uint16_t *inputBuffer[2]; 80 | 81 | // size of buffers 82 | uint32_t outBufSamples; //播放缓冲数组的大小 83 | uint32_t inBufSamples; //录入缓冲数组的大小 84 | 85 | // locks 86 | void* inlock; //录入同步锁 87 | void* outlock; //播放同步锁 88 | 89 | double time; 90 | uint32_t inchannels; //输入的声道数量 91 | uint32_t outchannels; //输出的声道数量 92 | uint32_t sampleRate; //采样率 93 | 94 | } OPENSL_STREAM; 95 | 96 | /* 97 | Open the audio device with a given sampling rate (sr), input and output channels and IO buffer size 98 | in frames. Returns a handle to the OpenSL stream 99 | */ 100 | OPENSL_STREAM* android_OpenAudioDevice(uint32_t sr, uint32_t inchannels, uint32_t outchannels, uint32_t bufferframes , uint32_t mode); 101 | 102 | /* 103 | Close the audio device 104 | */ 105 | void android_CloseAudioDevice(OPENSL_STREAM *p); 106 | 107 | /* 108 | Read a buffer from the OpenSL stream *p, of size samples. Returns the number of samples read. 109 | */ 110 | uint32_t android_AudioIn(OPENSL_STREAM *p, uint16_t *buffer,uint32_t size); 111 | 112 | /* 113 | Write a buffer to the OpenSL stream *p, of size samples. Returns the number of samples written. 114 | */ 115 | uint32_t android_AudioOut(OPENSL_STREAM *p, uint16_t *buffer,uint32_t size); 116 | 117 | /* 118 | Get the current IO block time in seconds 119 | */ 120 | double android_GetTimestamp(OPENSL_STREAM *p); 121 | 122 | #ifdef __cplusplus 123 | }; 124 | #endif 125 | 126 | #endif // #ifndef OPENSL_IO 127 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/arm64-v8a/libspeex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-ma/Android-OpenSLES-Demo/65a67363d80e579e36be01703e42b26a216a9364/app/src/main/jnilibs/arm64-v8a/libspeex.so -------------------------------------------------------------------------------- /app/src/main/jnilibs/arm64-v8a/libspeexdsp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-ma/Android-OpenSLES-Demo/65a67363d80e579e36be01703e42b26a216a9364/app/src/main/jnilibs/arm64-v8a/libspeexdsp.so -------------------------------------------------------------------------------- /app/src/main/jnilibs/armeabi/libspeex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-ma/Android-OpenSLES-Demo/65a67363d80e579e36be01703e42b26a216a9364/app/src/main/jnilibs/armeabi/libspeex.so -------------------------------------------------------------------------------- /app/src/main/jnilibs/armeabi/libspeexdsp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-ma/Android-OpenSLES-Demo/65a67363d80e579e36be01703e42b26a216a9364/app/src/main/jnilibs/armeabi/libspeexdsp.so -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002-2006 Jean-Marc Valin*/ 2 | /** 3 | @file speex.h 4 | @brief Describes the different modes of the codec 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #ifndef SPEEX_H 37 | #define SPEEX_H 38 | /** @defgroup Codec Speex encoder and decoder 39 | * This is the Speex codec itself. 40 | * @{ 41 | */ 42 | 43 | #include "speex_types.h" 44 | #include "speex_bits.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | /* Values allowed for *ctl() requests */ 51 | 52 | /** Set enhancement on/off (decoder only) */ 53 | #define SPEEX_SET_ENH 0 54 | /** Get enhancement state (decoder only) */ 55 | #define SPEEX_GET_ENH 1 56 | 57 | /*Would be SPEEX_SET_FRAME_SIZE, but it's (currently) invalid*/ 58 | /** Obtain frame size used by encoder/decoder */ 59 | #define SPEEX_GET_FRAME_SIZE 3 60 | 61 | /** Set quality value */ 62 | #define SPEEX_SET_QUALITY 4 63 | /** Get current quality setting */ 64 | /* #define SPEEX_GET_QUALITY 5 -- Doesn't make much sense, does it? */ 65 | 66 | /** Set sub-mode to use */ 67 | #define SPEEX_SET_MODE 6 68 | /** Get current sub-mode in use */ 69 | #define SPEEX_GET_MODE 7 70 | 71 | /** Set low-band sub-mode to use (wideband only)*/ 72 | #define SPEEX_SET_LOW_MODE 8 73 | /** Get current low-band mode in use (wideband only)*/ 74 | #define SPEEX_GET_LOW_MODE 9 75 | 76 | /** Set high-band sub-mode to use (wideband only)*/ 77 | #define SPEEX_SET_HIGH_MODE 10 78 | /** Get current high-band mode in use (wideband only)*/ 79 | #define SPEEX_GET_HIGH_MODE 11 80 | 81 | /** Set VBR on (1) or off (0) */ 82 | #define SPEEX_SET_VBR 12 83 | /** Get VBR status (1 for on, 0 for off) */ 84 | #define SPEEX_GET_VBR 13 85 | 86 | /** Set quality value for VBR encoding (0-10) */ 87 | #define SPEEX_SET_VBR_QUALITY 14 88 | /** Get current quality value for VBR encoding (0-10) */ 89 | #define SPEEX_GET_VBR_QUALITY 15 90 | 91 | /** Set complexity of the encoder (0-10) */ 92 | #define SPEEX_SET_COMPLEXITY 16 93 | /** Get current complexity of the encoder (0-10) */ 94 | #define SPEEX_GET_COMPLEXITY 17 95 | 96 | /** Set bit-rate used by the encoder (or lower) */ 97 | #define SPEEX_SET_BITRATE 18 98 | /** Get current bit-rate used by the encoder or decoder */ 99 | #define SPEEX_GET_BITRATE 19 100 | 101 | /** Define a handler function for in-band Speex request*/ 102 | #define SPEEX_SET_HANDLER 20 103 | 104 | /** Define a handler function for in-band user-defined request*/ 105 | #define SPEEX_SET_USER_HANDLER 22 106 | 107 | /** Set sampling rate used in bit-rate computation */ 108 | #define SPEEX_SET_SAMPLING_RATE 24 109 | /** Get sampling rate used in bit-rate computation */ 110 | #define SPEEX_GET_SAMPLING_RATE 25 111 | 112 | /** Reset the encoder/decoder memories to zero*/ 113 | #define SPEEX_RESET_STATE 26 114 | 115 | /** Get VBR info (mostly used internally) */ 116 | #define SPEEX_GET_RELATIVE_QUALITY 29 117 | 118 | /** Set VAD status (1 for on, 0 for off) */ 119 | #define SPEEX_SET_VAD 30 120 | 121 | /** Get VAD status (1 for on, 0 for off) */ 122 | #define SPEEX_GET_VAD 31 123 | 124 | /** Set Average Bit-Rate (ABR) to n bits per seconds */ 125 | #define SPEEX_SET_ABR 32 126 | /** Get Average Bit-Rate (ABR) setting (in bps) */ 127 | #define SPEEX_GET_ABR 33 128 | 129 | /** Set DTX status (1 for on, 0 for off) */ 130 | #define SPEEX_SET_DTX 34 131 | /** Get DTX status (1 for on, 0 for off) */ 132 | #define SPEEX_GET_DTX 35 133 | 134 | /** Set submode encoding in each frame (1 for yes, 0 for no, setting to no breaks the standard) */ 135 | #define SPEEX_SET_SUBMODE_ENCODING 36 136 | /** Get submode encoding in each frame */ 137 | #define SPEEX_GET_SUBMODE_ENCODING 37 138 | 139 | /*#define SPEEX_SET_LOOKAHEAD 38*/ 140 | /** Returns the lookahead used by Speex separately for an encoder and a decoder. 141 | * Sum encoder and decoder lookahead values to get the total codec lookahead. */ 142 | #define SPEEX_GET_LOOKAHEAD 39 143 | 144 | /** Sets tuning for packet-loss concealment (expected loss rate) */ 145 | #define SPEEX_SET_PLC_TUNING 40 146 | /** Gets tuning for PLC */ 147 | #define SPEEX_GET_PLC_TUNING 41 148 | 149 | /** Sets the max bit-rate allowed in VBR mode */ 150 | #define SPEEX_SET_VBR_MAX_BITRATE 42 151 | /** Gets the max bit-rate allowed in VBR mode */ 152 | #define SPEEX_GET_VBR_MAX_BITRATE 43 153 | 154 | /** Turn on/off input/output high-pass filtering */ 155 | #define SPEEX_SET_HIGHPASS 44 156 | /** Get status of input/output high-pass filtering */ 157 | #define SPEEX_GET_HIGHPASS 45 158 | 159 | /** Get "activity level" of the last decoded frame, i.e. 160 | how much damage we cause if we remove the frame */ 161 | #define SPEEX_GET_ACTIVITY 47 162 | 163 | 164 | /* Preserving compatibility:*/ 165 | /** Equivalent to SPEEX_SET_ENH */ 166 | #define SPEEX_SET_PF 0 167 | /** Equivalent to SPEEX_GET_ENH */ 168 | #define SPEEX_GET_PF 1 169 | 170 | 171 | 172 | 173 | /* Values allowed for mode queries */ 174 | /** Query the frame size of a mode */ 175 | #define SPEEX_MODE_FRAME_SIZE 0 176 | 177 | /** Query the size of an encoded frame for a particular sub-mode */ 178 | #define SPEEX_SUBMODE_BITS_PER_FRAME 1 179 | 180 | 181 | 182 | /** Get major Speex version */ 183 | #define SPEEX_LIB_GET_MAJOR_VERSION 1 184 | /** Get minor Speex version */ 185 | #define SPEEX_LIB_GET_MINOR_VERSION 3 186 | /** Get micro Speex version */ 187 | #define SPEEX_LIB_GET_MICRO_VERSION 5 188 | /** Get extra Speex version */ 189 | #define SPEEX_LIB_GET_EXTRA_VERSION 7 190 | /** Get Speex version string */ 191 | #define SPEEX_LIB_GET_VERSION_STRING 9 192 | 193 | /*#define SPEEX_LIB_SET_ALLOC_FUNC 10 194 | #define SPEEX_LIB_GET_ALLOC_FUNC 11 195 | #define SPEEX_LIB_SET_FREE_FUNC 12 196 | #define SPEEX_LIB_GET_FREE_FUNC 13 197 | 198 | #define SPEEX_LIB_SET_WARNING_FUNC 14 199 | #define SPEEX_LIB_GET_WARNING_FUNC 15 200 | #define SPEEX_LIB_SET_ERROR_FUNC 16 201 | #define SPEEX_LIB_GET_ERROR_FUNC 17 202 | */ 203 | 204 | /** Number of defined modes in Speex */ 205 | #define SPEEX_NB_MODES 3 206 | 207 | /** modeID for the defined narrowband mode */ 208 | #define SPEEX_MODEID_NB 0 209 | 210 | /** modeID for the defined wideband mode */ 211 | #define SPEEX_MODEID_WB 1 212 | 213 | /** modeID for the defined ultra-wideband mode */ 214 | #define SPEEX_MODEID_UWB 2 215 | 216 | struct SpeexMode; 217 | 218 | 219 | /* Prototypes for mode function pointers */ 220 | 221 | /** Encoder state initialization function */ 222 | typedef void *(*encoder_init_func)(const struct SpeexMode *mode); 223 | 224 | /** Encoder state destruction function */ 225 | typedef void (*encoder_destroy_func)(void *st); 226 | 227 | /** Main encoding function */ 228 | typedef int (*encode_func)(void *state, void *in, SpeexBits *bits); 229 | 230 | /** Function for controlling the encoder options */ 231 | typedef int (*encoder_ctl_func)(void *state, int request, void *ptr); 232 | 233 | /** Decoder state initialization function */ 234 | typedef void *(*decoder_init_func)(const struct SpeexMode *mode); 235 | 236 | /** Decoder state destruction function */ 237 | typedef void (*decoder_destroy_func)(void *st); 238 | 239 | /** Main decoding function */ 240 | typedef int (*decode_func)(void *state, SpeexBits *bits, void *out); 241 | 242 | /** Function for controlling the decoder options */ 243 | typedef int (*decoder_ctl_func)(void *state, int request, void *ptr); 244 | 245 | 246 | /** Query function for a mode */ 247 | typedef int (*mode_query_func)(const void *mode, int request, void *ptr); 248 | 249 | /** Struct defining a Speex mode */ 250 | typedef struct SpeexMode { 251 | /** Pointer to the low-level mode data */ 252 | const void *mode; 253 | 254 | /** Pointer to the mode query function */ 255 | mode_query_func query; 256 | 257 | /** The name of the mode (you should not rely on this to identify the mode)*/ 258 | const char *modeName; 259 | 260 | /**ID of the mode*/ 261 | int modeID; 262 | 263 | /**Version number of the bitstream (incremented every time we break 264 | bitstream compatibility*/ 265 | int bitstream_version; 266 | 267 | /** Pointer to encoder initialization function */ 268 | encoder_init_func enc_init; 269 | 270 | /** Pointer to encoder destruction function */ 271 | encoder_destroy_func enc_destroy; 272 | 273 | /** Pointer to frame encoding function */ 274 | encode_func enc; 275 | 276 | /** Pointer to decoder initialization function */ 277 | decoder_init_func dec_init; 278 | 279 | /** Pointer to decoder destruction function */ 280 | decoder_destroy_func dec_destroy; 281 | 282 | /** Pointer to frame decoding function */ 283 | decode_func dec; 284 | 285 | /** ioctl-like requests for encoder */ 286 | encoder_ctl_func enc_ctl; 287 | 288 | /** ioctl-like requests for decoder */ 289 | decoder_ctl_func dec_ctl; 290 | 291 | } SpeexMode; 292 | 293 | /** 294 | * Returns a handle to a newly created Speex encoder state structure. For now, 295 | * the "mode" argument can be &nb_mode or &wb_mode . In the future, more modes 296 | * may be added. Note that for now if you have more than one channels to 297 | * encode, you need one state per channel. 298 | * 299 | * @param mode The mode to use (either speex_nb_mode or speex_wb.mode) 300 | * @return A newly created encoder state or NULL if state allocation fails 301 | */ 302 | void *speex_encoder_init(const SpeexMode *mode); 303 | 304 | /** Frees all resources associated to an existing Speex encoder state. 305 | * @param state Encoder state to be destroyed */ 306 | void speex_encoder_destroy(void *state); 307 | 308 | /** Uses an existing encoder state to encode one frame of speech pointed to by 309 | "in". The encoded bit-stream is saved in "bits". 310 | @param state Encoder state 311 | @param in Frame that will be encoded with a +-2^15 range. This data MAY be 312 | overwritten by the encoder and should be considered uninitialised 313 | after the call. 314 | @param bits Bit-stream where the data will be written 315 | @return 0 if frame needs not be transmitted (DTX only), 1 otherwise 316 | */ 317 | int speex_encode(void *state, float *in, SpeexBits *bits); 318 | 319 | /** Uses an existing encoder state to encode one frame of speech pointed to by 320 | "in". The encoded bit-stream is saved in "bits". 321 | @param state Encoder state 322 | @param in Frame that will be encoded with a +-2^15 range 323 | @param bits Bit-stream where the data will be written 324 | @return 0 if frame needs not be transmitted (DTX only), 1 otherwise 325 | */ 326 | int speex_encode_int(void *state, spx_int16_t *in, SpeexBits *bits); 327 | 328 | /** Used like the ioctl function to control the encoder parameters 329 | * 330 | * @param state Encoder state 331 | * @param request ioctl-type request (one of the SPEEX_* macros) 332 | * @param ptr Data exchanged to-from function 333 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter 334 | */ 335 | int speex_encoder_ctl(void *state, int request, void *ptr); 336 | 337 | 338 | /** Returns a handle to a newly created decoder state structure. For now, 339 | * the mode argument can be &nb_mode or &wb_mode . In the future, more modes 340 | * may be added. Note that for now if you have more than one channels to 341 | * decode, you need one state per channel. 342 | * 343 | * @param mode Speex mode (one of speex_nb_mode or speex_wb_mode) 344 | * @return A newly created decoder state or NULL if state allocation fails 345 | */ 346 | void *speex_decoder_init(const SpeexMode *mode); 347 | 348 | /** Frees all resources associated to an existing decoder state. 349 | * 350 | * @param state State to be destroyed 351 | */ 352 | void speex_decoder_destroy(void *state); 353 | 354 | /** Uses an existing decoder state to decode one frame of speech from 355 | * bit-stream bits. The output speech is saved written to out. 356 | * 357 | * @param state Decoder state 358 | * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost) 359 | * @param out Where to write the decoded frame 360 | * @return return status (0 for no error, -1 for end of stream, -2 corrupt stream) 361 | */ 362 | int speex_decode(void *state, SpeexBits *bits, float *out); 363 | 364 | /** Uses an existing decoder state to decode one frame of speech from 365 | * bit-stream bits. The output speech is saved written to out. 366 | * 367 | * @param state Decoder state 368 | * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost) 369 | * @param out Where to write the decoded frame 370 | * @return return status (0 for no error, -1 for end of stream, -2 corrupt stream) 371 | */ 372 | int speex_decode_int(void *state, SpeexBits *bits, spx_int16_t *out); 373 | 374 | /** Used like the ioctl function to control the encoder parameters 375 | * 376 | * @param state Decoder state 377 | * @param request ioctl-type request (one of the SPEEX_* macros) 378 | * @param ptr Data exchanged to-from function 379 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter 380 | */ 381 | int speex_decoder_ctl(void *state, int request, void *ptr); 382 | 383 | 384 | /** Query function for mode information 385 | * 386 | * @param mode Speex mode 387 | * @param request ioctl-type request (one of the SPEEX_* macros) 388 | * @param ptr Data exchanged to-from function 389 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter 390 | */ 391 | int speex_mode_query(const SpeexMode *mode, int request, void *ptr); 392 | 393 | /** Functions for controlling the behavior of libspeex 394 | * @param request ioctl-type request (one of the SPEEX_LIB_* macros) 395 | * @param ptr Data exchanged to-from function 396 | * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter 397 | */ 398 | int speex_lib_ctl(int request, void *ptr); 399 | 400 | /** Default narrowband mode */ 401 | extern const SpeexMode speex_nb_mode; 402 | 403 | /** Default wideband mode */ 404 | extern const SpeexMode speex_wb_mode; 405 | 406 | /** Default "ultra-wideband" mode */ 407 | extern const SpeexMode speex_uwb_mode; 408 | 409 | /** List of all modes available */ 410 | extern const SpeexMode * const speex_mode_list[SPEEX_NB_MODES]; 411 | 412 | /** Obtain one of the modes available */ 413 | const SpeexMode * speex_lib_get_mode (int mode); 414 | 415 | #ifndef WIN32 416 | /* We actually override the function in the narrowband case so that we can avoid linking in the wideband stuff */ 417 | #define speex_lib_get_mode(mode) ((mode)==SPEEX_MODEID_NB ? &speex_nb_mode : speex_lib_get_mode (mode)) 418 | #endif 419 | 420 | #ifdef __cplusplus 421 | } 422 | #endif 423 | 424 | /** @}*/ 425 | #endif 426 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_bits.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin */ 2 | /** 3 | @file speex_bits.h 4 | @brief Handles bit packing/unpacking 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #ifndef BITS_H 37 | #define BITS_H 38 | /** @defgroup SpeexBits SpeexBits: Bit-stream manipulations 39 | * This is the structure that holds the bit-stream when encoding or decoding 40 | * with Speex. It allows some manipulations as well. 41 | * @{ 42 | */ 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | /** Bit-packing data structure representing (part of) a bit-stream. */ 49 | typedef struct SpeexBits { 50 | char *chars; /**< "raw" data */ 51 | int nbBits; /**< Total number of bits stored in the stream*/ 52 | int charPtr; /**< Position of the byte "cursor" */ 53 | int bitPtr; /**< Position of the bit "cursor" within the current char */ 54 | int owner; /**< Does the struct "own" the "raw" buffer (member "chars") */ 55 | int overflow;/**< Set to one if we try to read past the valid data */ 56 | int buf_size;/**< Allocated size for buffer */ 57 | int reserved1; /**< Reserved for future use */ 58 | void *reserved2; /**< Reserved for future use */ 59 | } SpeexBits; 60 | 61 | /** Initializes and allocates resources for a SpeexBits struct */ 62 | void speex_bits_init(SpeexBits *bits); 63 | 64 | /** Initializes SpeexBits struct using a pre-allocated buffer*/ 65 | void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size); 66 | 67 | /** Sets the bits in a SpeexBits struct to use data from an existing buffer (for decoding without copying data) */ 68 | void speex_bits_set_bit_buffer(SpeexBits *bits, void *buff, int buf_size); 69 | 70 | /** Frees all resources associated to a SpeexBits struct. Right now this does nothing since no resources are allocated, but this could change in the future.*/ 71 | void speex_bits_destroy(SpeexBits *bits); 72 | 73 | /** Resets bits to initial value (just after initialization, erasing content)*/ 74 | void speex_bits_reset(SpeexBits *bits); 75 | 76 | /** Rewind the bit-stream to the beginning (ready for read) without erasing the content */ 77 | void speex_bits_rewind(SpeexBits *bits); 78 | 79 | /** Initializes the bit-stream from the data in an area of memory */ 80 | void speex_bits_read_from(SpeexBits *bits, const char *bytes, int len); 81 | 82 | /** Append bytes to the bit-stream 83 | * 84 | * @param bits Bit-stream to operate on 85 | * @param bytes pointer to the bytes what will be appended 86 | * @param len Number of bytes of append 87 | */ 88 | void speex_bits_read_whole_bytes(SpeexBits *bits, const char *bytes, int len); 89 | 90 | /** Write the content of a bit-stream to an area of memory 91 | * 92 | * @param bits Bit-stream to operate on 93 | * @param bytes Memory location where to write the bits 94 | * @param max_len Maximum number of bytes to write (i.e. size of the "bytes" buffer) 95 | * @return Number of bytes written to the "bytes" buffer 96 | */ 97 | int speex_bits_write(SpeexBits *bits, char *bytes, int max_len); 98 | 99 | /** Like speex_bits_write, but writes only the complete bytes in the stream. Also removes the written bytes from the stream */ 100 | int speex_bits_write_whole_bytes(SpeexBits *bits, char *bytes, int max_len); 101 | 102 | /** Append bits to the bit-stream 103 | * @param bits Bit-stream to operate on 104 | * @param data Value to append as integer 105 | * @param nbBits number of bits to consider in "data" 106 | */ 107 | void speex_bits_pack(SpeexBits *bits, int data, int nbBits); 108 | 109 | /** Interpret the next bits in the bit-stream as a signed integer 110 | * 111 | * @param bits Bit-stream to operate on 112 | * @param nbBits Number of bits to interpret 113 | * @return A signed integer represented by the bits read 114 | */ 115 | int speex_bits_unpack_signed(SpeexBits *bits, int nbBits); 116 | 117 | /** Interpret the next bits in the bit-stream as an unsigned integer 118 | * 119 | * @param bits Bit-stream to operate on 120 | * @param nbBits Number of bits to interpret 121 | * @return An unsigned integer represented by the bits read 122 | */ 123 | unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits); 124 | 125 | /** Returns the number of bytes in the bit-stream, including the last one even if it is not "full" 126 | * 127 | * @param bits Bit-stream to operate on 128 | * @return Number of bytes in the stream 129 | */ 130 | int speex_bits_nbytes(SpeexBits *bits); 131 | 132 | /** Same as speex_bits_unpack_unsigned, but without modifying the cursor position 133 | * 134 | * @param bits Bit-stream to operate on 135 | * @param nbBits Number of bits to look for 136 | * @return Value of the bits peeked, interpreted as unsigned 137 | */ 138 | unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits); 139 | 140 | /** Get the value of the next bit in the stream, without modifying the 141 | * "cursor" position 142 | * 143 | * @param bits Bit-stream to operate on 144 | * @return Value of the bit peeked (one bit only) 145 | */ 146 | int speex_bits_peek(SpeexBits *bits); 147 | 148 | /** Advances the position of the "bit cursor" in the stream 149 | * 150 | * @param bits Bit-stream to operate on 151 | * @param n Number of bits to advance 152 | */ 153 | void speex_bits_advance(SpeexBits *bits, int n); 154 | 155 | /** Returns the number of bits remaining to be read in a stream 156 | * 157 | * @param bits Bit-stream to operate on 158 | * @return Number of bits that can still be read from the stream 159 | */ 160 | int speex_bits_remaining(SpeexBits *bits); 161 | 162 | /** Insert a terminator so that the data can be sent as a packet while auto-detecting 163 | * the number of frames in each packet 164 | * 165 | * @param bits Bit-stream to operate on 166 | */ 167 | void speex_bits_insert_terminator(SpeexBits *bits); 168 | 169 | #ifdef __cplusplus 170 | } 171 | #endif 172 | 173 | /* @} */ 174 | #endif 175 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_buffer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Jean-Marc Valin 2 | 3 | File: speex_buffer.h 4 | This is a very simple ring buffer implementation. It is not thread-safe 5 | so you need to do your own locking. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef SPEEX_BUFFER_H 35 | #define SPEEX_BUFFER_H 36 | 37 | #include "speexdsp_types.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | struct SpeexBuffer_; 44 | typedef struct SpeexBuffer_ SpeexBuffer; 45 | 46 | SpeexBuffer *speex_buffer_init(int size); 47 | 48 | void speex_buffer_destroy(SpeexBuffer *st); 49 | 50 | int speex_buffer_write(SpeexBuffer *st, void *data, int len); 51 | 52 | int speex_buffer_writezeros(SpeexBuffer *st, int len); 53 | 54 | int speex_buffer_read(SpeexBuffer *st, void *data, int len); 55 | 56 | int speex_buffer_get_available(SpeexBuffer *st); 57 | 58 | int speex_buffer_resize(SpeexBuffer *st, int len); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_callbacks.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin*/ 2 | /** 3 | @file speex_callbacks.h 4 | @brief Describes callback handling and in-band signalling 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #ifndef SPEEX_CALLBACKS_H 37 | #define SPEEX_CALLBACKS_H 38 | /** @defgroup SpeexCallbacks Various definitions for Speex callbacks supported by the decoder. 39 | * @{ 40 | */ 41 | 42 | #include "speex.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | /** Total number of callbacks */ 49 | #define SPEEX_MAX_CALLBACKS 16 50 | 51 | /* Describes all the in-band requests */ 52 | 53 | /*These are 1-bit requests*/ 54 | /** Request for perceptual enhancement (1 for on, 0 for off) */ 55 | #define SPEEX_INBAND_ENH_REQUEST 0 56 | /** Reserved */ 57 | #define SPEEX_INBAND_RESERVED1 1 58 | 59 | /*These are 4-bit requests*/ 60 | /** Request for a mode change */ 61 | #define SPEEX_INBAND_MODE_REQUEST 2 62 | /** Request for a low mode change */ 63 | #define SPEEX_INBAND_LOW_MODE_REQUEST 3 64 | /** Request for a high mode change */ 65 | #define SPEEX_INBAND_HIGH_MODE_REQUEST 4 66 | /** Request for VBR (1 on, 0 off) */ 67 | #define SPEEX_INBAND_VBR_QUALITY_REQUEST 5 68 | /** Request to be sent acknowledge */ 69 | #define SPEEX_INBAND_ACKNOWLEDGE_REQUEST 6 70 | /** Request for VBR (1 for on, 0 for off) */ 71 | #define SPEEX_INBAND_VBR_REQUEST 7 72 | 73 | /*These are 8-bit requests*/ 74 | /** Send a character in-band */ 75 | #define SPEEX_INBAND_CHAR 8 76 | /** Intensity stereo information */ 77 | #define SPEEX_INBAND_STEREO 9 78 | 79 | /*These are 16-bit requests*/ 80 | /** Transmit max bit-rate allowed */ 81 | #define SPEEX_INBAND_MAX_BITRATE 10 82 | 83 | /*These are 32-bit requests*/ 84 | /** Acknowledge packet reception */ 85 | #define SPEEX_INBAND_ACKNOWLEDGE 12 86 | 87 | /** Callback function type */ 88 | typedef int (*speex_callback_func)(SpeexBits *bits, void *state, void *data); 89 | 90 | /** Callback information */ 91 | typedef struct SpeexCallback { 92 | int callback_id; /**< ID associated to the callback */ 93 | speex_callback_func func; /**< Callback handler function */ 94 | void *data; /**< Data that will be sent to the handler */ 95 | void *reserved1; /**< Reserved for future use */ 96 | int reserved2; /**< Reserved for future use */ 97 | } SpeexCallback; 98 | 99 | /** Handle in-band request */ 100 | int speex_inband_handler(SpeexBits *bits, SpeexCallback *callback_list, void *state); 101 | 102 | /** Standard handler for mode request (change mode, no questions asked) */ 103 | int speex_std_mode_request_handler(SpeexBits *bits, void *state, void *data); 104 | 105 | /** Standard handler for high mode request (change high mode, no questions asked) */ 106 | int speex_std_high_mode_request_handler(SpeexBits *bits, void *state, void *data); 107 | 108 | /** Standard handler for in-band characters (write to stderr) */ 109 | int speex_std_char_handler(SpeexBits *bits, void *state, void *data); 110 | 111 | /** Default handler for user-defined requests: in this case, just ignore */ 112 | int speex_default_user_handler(SpeexBits *bits, void *state, void *data); 113 | 114 | 115 | 116 | /** Standard handler for low mode request (change low mode, no questions asked) */ 117 | int speex_std_low_mode_request_handler(SpeexBits *bits, void *state, void *data); 118 | 119 | /** Standard handler for VBR request (Set VBR, no questions asked) */ 120 | int speex_std_vbr_request_handler(SpeexBits *bits, void *state, void *data); 121 | 122 | /** Standard handler for enhancer request (Turn enhancer on/off, no questions asked) */ 123 | int speex_std_enh_request_handler(SpeexBits *bits, void *state, void *data); 124 | 125 | /** Standard handler for VBR quality request (Set VBR quality, no questions asked) */ 126 | int speex_std_vbr_quality_request_handler(SpeexBits *bits, void *state, void *data); 127 | 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | /** @} */ 134 | #endif 135 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_config_types.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPEEX_TYPES_H__ 2 | #define __SPEEX_TYPES_H__ 3 | typedef short spx_int16_t; 4 | typedef unsigned short spx_uint16_t; 5 | typedef int spx_int32_t; 6 | typedef unsigned int spx_uint32_t; 7 | #endif 8 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_echo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) Jean-Marc Valin */ 2 | /** 3 | @file speex_echo.h 4 | @brief Echo cancellation 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef SPEEX_ECHO_H 35 | #define SPEEX_ECHO_H 36 | /** @defgroup SpeexEchoState SpeexEchoState: Acoustic echo canceller 37 | * This is the acoustic echo canceller module. 38 | * @{ 39 | */ 40 | #include "speexdsp_types.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** Obtain frame size used by the AEC */ 47 | #define SPEEX_ECHO_GET_FRAME_SIZE 3 48 | 49 | /** Set sampling rate */ 50 | #define SPEEX_ECHO_SET_SAMPLING_RATE 24 51 | /** Get sampling rate */ 52 | #define SPEEX_ECHO_GET_SAMPLING_RATE 25 53 | 54 | /* Can't set window sizes */ 55 | /** Get size of impulse response (int32) */ 56 | #define SPEEX_ECHO_GET_IMPULSE_RESPONSE_SIZE 27 57 | 58 | /* Can't set window content */ 59 | /** Get impulse response (int32[]) */ 60 | #define SPEEX_ECHO_GET_IMPULSE_RESPONSE 29 61 | 62 | /** Internal echo canceller state. Should never be accessed directly. */ 63 | struct SpeexEchoState_; 64 | 65 | /** @class SpeexEchoState 66 | * This holds the state of the echo canceller. You need one per channel. 67 | */ 68 | 69 | /** Internal echo canceller state. Should never be accessed directly. */ 70 | typedef struct SpeexEchoState_ SpeexEchoState; 71 | 72 | /** Creates a new echo canceller state 73 | * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms) 74 | * @param filter_length Number of samples of echo to cancel (should generally correspond to 100-500 ms) 75 | * @return Newly-created echo canceller state 76 | */ 77 | SpeexEchoState *speex_echo_state_init(int frame_size, int filter_length); 78 | 79 | /** Creates a new multi-channel echo canceller state 80 | * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms) 81 | * @param filter_length Number of samples of echo to cancel (should generally correspond to 100-500 ms) 82 | * @param nb_mic Number of microphone channels 83 | * @param nb_speakers Number of speaker channels 84 | * @return Newly-created echo canceller state 85 | */ 86 | SpeexEchoState *speex_echo_state_init_mc(int frame_size, int filter_length, int nb_mic, int nb_speakers); 87 | 88 | /** Destroys an echo canceller state 89 | * @param st Echo canceller state 90 | */ 91 | void speex_echo_state_destroy(SpeexEchoState *st); 92 | 93 | /** Performs echo cancellation a frame, based on the audio sent to the speaker (no delay is added 94 | * to playback in this form) 95 | * 96 | * @param st Echo canceller state 97 | * @param rec Signal from the microphone (near end + far end echo) 98 | * @param play Signal played to the speaker (received from far end) 99 | * @param out Returns near-end signal with echo removed 100 | */ 101 | void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out); 102 | 103 | /** Performs echo cancellation a frame (deprecated) */ 104 | void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out, spx_int32_t *Yout); 105 | 106 | /** Perform echo cancellation using internal playback buffer, which is delayed by two frames 107 | * to account for the delay introduced by most soundcards (but it could be off!) 108 | * @param st Echo canceller state 109 | * @param rec Signal from the microphone (near end + far end echo) 110 | * @param out Returns near-end signal with echo removed 111 | */ 112 | void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out); 113 | 114 | /** Let the echo canceller know that a frame was just queued to the soundcard 115 | * @param st Echo canceller state 116 | * @param play Signal played to the speaker (received from far end) 117 | */ 118 | void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play); 119 | 120 | /** Reset the echo canceller to its original state 121 | * @param st Echo canceller state 122 | */ 123 | void speex_echo_state_reset(SpeexEchoState *st); 124 | 125 | /** Used like the ioctl function to control the echo canceller parameters 126 | * 127 | * @param st Echo canceller state 128 | * @param request ioctl-type request (one of the SPEEX_ECHO_* macros) 129 | * @param ptr Data exchanged to-from function 130 | * @return 0 if no error, -1 if request in unknown 131 | */ 132 | int speex_echo_ctl(SpeexEchoState *st, int request, void *ptr); 133 | 134 | 135 | 136 | struct SpeexDecorrState_; 137 | 138 | typedef struct SpeexDecorrState_ SpeexDecorrState; 139 | 140 | 141 | /** Create a state for the channel decorrelation algorithm 142 | This is useful for multi-channel echo cancellation only 143 | * @param rate Sampling rate 144 | * @param channels Number of channels (it's a bit pointless if you don't have at least 2) 145 | * @param frame_size Size of the frame to process at ones (counting samples *per* channel) 146 | */ 147 | SpeexDecorrState *speex_decorrelate_new(int rate, int channels, int frame_size); 148 | 149 | /** Remove correlation between the channels by modifying the phase and possibly 150 | adding noise in a way that is not (or little) perceptible. 151 | * @param st Decorrelator state 152 | * @param in Input audio in interleaved format 153 | * @param out Result of the decorrelation (out *may* alias in) 154 | * @param strength How much alteration of the audio to apply from 0 to 100. 155 | */ 156 | void speex_decorrelate(SpeexDecorrState *st, const spx_int16_t *in, spx_int16_t *out, int strength); 157 | 158 | /** Destroy a Decorrelation state 159 | * @param st State to destroy 160 | */ 161 | void speex_decorrelate_destroy(SpeexDecorrState *st); 162 | 163 | 164 | #ifdef __cplusplus 165 | } 166 | #endif 167 | 168 | 169 | /** @}*/ 170 | #endif 171 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_header.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin */ 2 | /** 3 | @file speex_header.h 4 | @brief Describes the Speex header 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | 37 | #ifndef SPEEX_HEADER_H 38 | #define SPEEX_HEADER_H 39 | /** @defgroup SpeexHeader SpeexHeader: Makes it easy to write/parse an Ogg/Speex header 40 | * This is the Speex header for the Ogg encapsulation. You don't need that if you just use RTP. 41 | * @{ 42 | */ 43 | 44 | #include "speex_types.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | struct SpeexMode; 51 | 52 | /** Length of the Speex header identifier */ 53 | #define SPEEX_HEADER_STRING_LENGTH 8 54 | 55 | /** Maximum number of characters for encoding the Speex version number in the header */ 56 | #define SPEEX_HEADER_VERSION_LENGTH 20 57 | 58 | /** Speex header info for file-based formats */ 59 | typedef struct SpeexHeader { 60 | char speex_string[SPEEX_HEADER_STRING_LENGTH]; /**< Identifies a Speex bit-stream, always set to "Speex " */ 61 | char speex_version[SPEEX_HEADER_VERSION_LENGTH]; /**< Speex version */ 62 | spx_int32_t speex_version_id; /**< Version for Speex (for checking compatibility) */ 63 | spx_int32_t header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */ 64 | spx_int32_t rate; /**< Sampling rate used */ 65 | spx_int32_t mode; /**< Mode used (0 for narrowband, 1 for wideband) */ 66 | spx_int32_t mode_bitstream_version; /**< Version ID of the bit-stream */ 67 | spx_int32_t nb_channels; /**< Number of channels encoded */ 68 | spx_int32_t bitrate; /**< Bit-rate used */ 69 | spx_int32_t frame_size; /**< Size of frames */ 70 | spx_int32_t vbr; /**< 1 for a VBR encoding, 0 otherwise */ 71 | spx_int32_t frames_per_packet; /**< Number of frames stored per Ogg packet */ 72 | spx_int32_t extra_headers; /**< Number of additional headers after the comments */ 73 | spx_int32_t reserved1; /**< Reserved for future use, must be zero */ 74 | spx_int32_t reserved2; /**< Reserved for future use, must be zero */ 75 | } SpeexHeader; 76 | 77 | /** Initializes a SpeexHeader using basic information */ 78 | void speex_init_header(SpeexHeader *header, int rate, int nb_channels, const struct SpeexMode *m); 79 | 80 | /** Creates the header packet from the header itself (mostly involves endianness conversion) */ 81 | char *speex_header_to_packet(SpeexHeader *header, int *size); 82 | 83 | /** Creates a SpeexHeader from a packet */ 84 | SpeexHeader *speex_packet_to_header(char *packet, int size); 85 | 86 | /** Frees the memory allocated by either speex_header_to_packet() or speex_packet_to_header() */ 87 | void speex_header_free(void *ptr); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | /** @} */ 94 | #endif 95 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_jitter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin */ 2 | /** 3 | @file speex_jitter.h 4 | @brief Adaptive jitter buffer for Speex 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #ifndef SPEEX_JITTER_H 37 | #define SPEEX_JITTER_H 38 | /** @defgroup JitterBuffer JitterBuffer: Adaptive jitter buffer 39 | * This is the jitter buffer that reorders UDP/RTP packets and adjusts the buffer size 40 | * to maintain good quality and low latency. 41 | * @{ 42 | */ 43 | 44 | #include "speexdsp_types.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | /** Generic adaptive jitter buffer state */ 51 | struct JitterBuffer_; 52 | 53 | /** Generic adaptive jitter buffer state */ 54 | typedef struct JitterBuffer_ JitterBuffer; 55 | 56 | /** Definition of an incoming packet */ 57 | typedef struct _JitterBufferPacket JitterBufferPacket; 58 | 59 | /** Definition of an incoming packet */ 60 | struct _JitterBufferPacket { 61 | char *data; /**< Data bytes contained in the packet */ 62 | spx_uint32_t len; /**< Length of the packet in bytes */ 63 | spx_uint32_t timestamp; /**< Timestamp for the packet */ 64 | spx_uint32_t span; /**< Time covered by the packet (same units as timestamp) */ 65 | spx_uint16_t sequence; /**< RTP Sequence number if available (0 otherwise) */ 66 | spx_uint32_t user_data; /**< Put whatever data you like here (it's ignored by the jitter buffer) */ 67 | }; 68 | 69 | /** Packet has been retrieved */ 70 | #define JITTER_BUFFER_OK 0 71 | /** Packet is lost or is late */ 72 | #define JITTER_BUFFER_MISSING 1 73 | /** A "fake" packet is meant to be inserted here to increase buffering */ 74 | #define JITTER_BUFFER_INSERTION 2 75 | /** There was an error in the jitter buffer */ 76 | #define JITTER_BUFFER_INTERNAL_ERROR -1 77 | /** Invalid argument */ 78 | #define JITTER_BUFFER_BAD_ARGUMENT -2 79 | 80 | 81 | /** Set minimum amount of extra buffering required (margin) */ 82 | #define JITTER_BUFFER_SET_MARGIN 0 83 | /** Get minimum amount of extra buffering required (margin) */ 84 | #define JITTER_BUFFER_GET_MARGIN 1 85 | /* JITTER_BUFFER_SET_AVAILABLE_COUNT wouldn't make sense */ 86 | 87 | /** Get the amount of available packets currently buffered */ 88 | #define JITTER_BUFFER_GET_AVAILABLE_COUNT 3 89 | /** Included because of an early misspelling (will remove in next release) */ 90 | #define JITTER_BUFFER_GET_AVALIABLE_COUNT 3 91 | 92 | /** Assign a function to destroy unused packet. When setting that, the jitter 93 | buffer no longer copies packet data. */ 94 | #define JITTER_BUFFER_SET_DESTROY_CALLBACK 4 95 | /** */ 96 | #define JITTER_BUFFER_GET_DESTROY_CALLBACK 5 97 | 98 | /** Tell the jitter buffer to only adjust the delay in multiples of the step parameter provided */ 99 | #define JITTER_BUFFER_SET_DELAY_STEP 6 100 | /** */ 101 | #define JITTER_BUFFER_GET_DELAY_STEP 7 102 | 103 | /** Tell the jitter buffer to only do concealment in multiples of the size parameter provided */ 104 | #define JITTER_BUFFER_SET_CONCEALMENT_SIZE 8 105 | #define JITTER_BUFFER_GET_CONCEALMENT_SIZE 9 106 | 107 | /** Absolute max amount of loss that can be tolerated regardless of the delay. Typical loss 108 | should be half of that or less. */ 109 | #define JITTER_BUFFER_SET_MAX_LATE_RATE 10 110 | #define JITTER_BUFFER_GET_MAX_LATE_RATE 11 111 | 112 | /** Equivalent cost of one percent late packet in timestamp units */ 113 | #define JITTER_BUFFER_SET_LATE_COST 12 114 | #define JITTER_BUFFER_GET_LATE_COST 13 115 | 116 | 117 | /** Initialises jitter buffer 118 | * 119 | * @param step_size Starting value for the size of concleanment packets and delay 120 | adjustment steps. Can be changed at any time using JITTER_BUFFER_SET_DELAY_STEP 121 | and JITTER_BUFFER_GET_CONCEALMENT_SIZE. 122 | * @return Newly created jitter buffer state 123 | */ 124 | JitterBuffer *jitter_buffer_init(int step_size); 125 | 126 | /** Restores jitter buffer to its original state 127 | * 128 | * @param jitter Jitter buffer state 129 | */ 130 | void jitter_buffer_reset(JitterBuffer *jitter); 131 | 132 | /** Destroys jitter buffer 133 | * 134 | * @param jitter Jitter buffer state 135 | */ 136 | void jitter_buffer_destroy(JitterBuffer *jitter); 137 | 138 | /** Put one packet into the jitter buffer 139 | * 140 | * @param jitter Jitter buffer state 141 | * @param packet Incoming packet 142 | */ 143 | void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet); 144 | 145 | /** Get one packet from the jitter buffer 146 | * 147 | * @param jitter Jitter buffer state 148 | * @param packet Returned packet 149 | * @param desired_span Number of samples (or units) we wish to get from the buffer (no guarantee) 150 | * @param current_timestamp Timestamp for the returned packet 151 | */ 152 | int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t desired_span, spx_int32_t *start_offset); 153 | 154 | /** Used right after jitter_buffer_get() to obtain another packet that would have the same timestamp. 155 | * This is mainly useful for media where a single "frame" can be split into several packets. 156 | * 157 | * @param jitter Jitter buffer state 158 | * @param packet Returned packet 159 | */ 160 | int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet); 161 | 162 | /** Get pointer timestamp of jitter buffer 163 | * 164 | * @param jitter Jitter buffer state 165 | */ 166 | int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter); 167 | 168 | /** Advance by one tick 169 | * 170 | * @param jitter Jitter buffer state 171 | */ 172 | void jitter_buffer_tick(JitterBuffer *jitter); 173 | 174 | /** Telling the jitter buffer about the remaining data in the application buffer 175 | * @param jitter Jitter buffer state 176 | * @param rem Amount of data buffered by the application (timestamp units) 177 | */ 178 | void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem); 179 | 180 | /** Used like the ioctl function to control the jitter buffer parameters 181 | * 182 | * @param jitter Jitter buffer state 183 | * @param request ioctl-type request (one of the JITTER_BUFFER_* macros) 184 | * @param ptr Data exchanged to-from function 185 | * @return 0 if no error, -1 if request in unknown 186 | */ 187 | int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr); 188 | 189 | int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset); 190 | 191 | /* @} */ 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | 197 | #endif 198 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_preprocess.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Epic Games 2 | Written by Jean-Marc Valin */ 3 | /** 4 | * @file speex_preprocess.h 5 | * @brief Speex preprocessor. The preprocess can do noise suppression, 6 | * residual echo suppression (after using the echo canceller), automatic 7 | * gain control (AGC) and voice activity detection (VAD). 8 | */ 9 | /* 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are 12 | met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, 15 | this list of conditions and the following disclaimer. 16 | 17 | 2. Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | 21 | 3. The name of the author may not be used to endorse or promote products 22 | derived from this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 28 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef SPEEX_PREPROCESS_H 38 | #define SPEEX_PREPROCESS_H 39 | /** @defgroup SpeexPreprocessState SpeexPreprocessState: The Speex preprocessor 40 | * This is the Speex preprocessor. The preprocess can do noise suppression, 41 | * residual echo suppression (after using the echo canceller), automatic 42 | * gain control (AGC) and voice activity detection (VAD). 43 | * @{ 44 | */ 45 | 46 | #include "speexdsp_types.h" 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | /** State of the preprocessor (one per channel). Should never be accessed directly. */ 53 | struct SpeexPreprocessState_; 54 | 55 | /** State of the preprocessor (one per channel). Should never be accessed directly. */ 56 | typedef struct SpeexPreprocessState_ SpeexPreprocessState; 57 | 58 | 59 | /** Creates a new preprocessing state. You MUST create one state per channel processed. 60 | * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms). Must be 61 | * the same value as that used for the echo canceller for residual echo cancellation to work. 62 | * @param sampling_rate Sampling rate used for the input. 63 | * @return Newly created preprocessor state 64 | */ 65 | SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_rate); 66 | 67 | /** Destroys a preprocessor state 68 | * @param st Preprocessor state to destroy 69 | */ 70 | void speex_preprocess_state_destroy(SpeexPreprocessState *st); 71 | 72 | /** Preprocess a frame 73 | * @param st Preprocessor state 74 | * @param x Audio sample vector (in and out). Must be same size as specified in speex_preprocess_state_init(). 75 | * @return Bool value for voice activity (1 for speech, 0 for noise/silence), ONLY if VAD turned on. 76 | */ 77 | int speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x); 78 | 79 | /** Preprocess a frame (deprecated, use speex_preprocess_run() instead)*/ 80 | int speex_preprocess(SpeexPreprocessState *st, spx_int16_t *x, spx_int32_t *echo); 81 | 82 | /** Update preprocessor state, but do not compute the output 83 | * @param st Preprocessor state 84 | * @param x Audio sample vector (in only). Must be same size as specified in speex_preprocess_state_init(). 85 | */ 86 | void speex_preprocess_estimate_update(SpeexPreprocessState *st, spx_int16_t *x); 87 | 88 | /** Used like the ioctl function to control the preprocessor parameters 89 | * @param st Preprocessor state 90 | * @param request ioctl-type request (one of the SPEEX_PREPROCESS_* macros) 91 | * @param ptr Data exchanged to-from function 92 | * @return 0 if no error, -1 if request in unknown 93 | */ 94 | int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr); 95 | 96 | 97 | 98 | /** Set preprocessor denoiser state */ 99 | #define SPEEX_PREPROCESS_SET_DENOISE 0 100 | /** Get preprocessor denoiser state */ 101 | #define SPEEX_PREPROCESS_GET_DENOISE 1 102 | 103 | /** Set preprocessor Automatic Gain Control state */ 104 | #define SPEEX_PREPROCESS_SET_AGC 2 105 | /** Get preprocessor Automatic Gain Control state */ 106 | #define SPEEX_PREPROCESS_GET_AGC 3 107 | 108 | /** Set preprocessor Voice Activity Detection state */ 109 | #define SPEEX_PREPROCESS_SET_VAD 4 110 | /** Get preprocessor Voice Activity Detection state */ 111 | #define SPEEX_PREPROCESS_GET_VAD 5 112 | 113 | /** Set preprocessor Automatic Gain Control level (float) */ 114 | #define SPEEX_PREPROCESS_SET_AGC_LEVEL 6 115 | /** Get preprocessor Automatic Gain Control level (float) */ 116 | #define SPEEX_PREPROCESS_GET_AGC_LEVEL 7 117 | 118 | /** Set preprocessor dereverb state */ 119 | #define SPEEX_PREPROCESS_SET_DEREVERB 8 120 | /** Get preprocessor dereverb state */ 121 | #define SPEEX_PREPROCESS_GET_DEREVERB 9 122 | 123 | /** Set preprocessor dereverb level */ 124 | #define SPEEX_PREPROCESS_SET_DEREVERB_LEVEL 10 125 | /** Get preprocessor dereverb level */ 126 | #define SPEEX_PREPROCESS_GET_DEREVERB_LEVEL 11 127 | 128 | /** Set preprocessor dereverb decay */ 129 | #define SPEEX_PREPROCESS_SET_DEREVERB_DECAY 12 130 | /** Get preprocessor dereverb decay */ 131 | #define SPEEX_PREPROCESS_GET_DEREVERB_DECAY 13 132 | 133 | /** Set probability required for the VAD to go from silence to voice */ 134 | #define SPEEX_PREPROCESS_SET_PROB_START 14 135 | /** Get probability required for the VAD to go from silence to voice */ 136 | #define SPEEX_PREPROCESS_GET_PROB_START 15 137 | 138 | /** Set probability required for the VAD to stay in the voice state (integer percent) */ 139 | #define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16 140 | /** Get probability required for the VAD to stay in the voice state (integer percent) */ 141 | #define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17 142 | 143 | /** Set maximum attenuation of the noise in dB (negative number) */ 144 | #define SPEEX_PREPROCESS_SET_NOISE_SUPPRESS 18 145 | /** Get maximum attenuation of the noise in dB (negative number) */ 146 | #define SPEEX_PREPROCESS_GET_NOISE_SUPPRESS 19 147 | 148 | /** Set maximum attenuation of the residual echo in dB (negative number) */ 149 | #define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS 20 150 | /** Get maximum attenuation of the residual echo in dB (negative number) */ 151 | #define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS 21 152 | 153 | /** Set maximum attenuation of the residual echo in dB when near end is active (negative number) */ 154 | #define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE 22 155 | /** Get maximum attenuation of the residual echo in dB when near end is active (negative number) */ 156 | #define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE 23 157 | 158 | /** Set the corresponding echo canceller state so that residual echo suppression can be performed (NULL for no residual echo suppression) */ 159 | #define SPEEX_PREPROCESS_SET_ECHO_STATE 24 160 | /** Get the corresponding echo canceller state */ 161 | #define SPEEX_PREPROCESS_GET_ECHO_STATE 25 162 | 163 | /** Set maximal gain increase in dB/second (int32) */ 164 | #define SPEEX_PREPROCESS_SET_AGC_INCREMENT 26 165 | 166 | /** Get maximal gain increase in dB/second (int32) */ 167 | #define SPEEX_PREPROCESS_GET_AGC_INCREMENT 27 168 | 169 | /** Set maximal gain decrease in dB/second (int32) */ 170 | #define SPEEX_PREPROCESS_SET_AGC_DECREMENT 28 171 | 172 | /** Get maximal gain decrease in dB/second (int32) */ 173 | #define SPEEX_PREPROCESS_GET_AGC_DECREMENT 29 174 | 175 | /** Set maximal gain in dB (int32) */ 176 | #define SPEEX_PREPROCESS_SET_AGC_MAX_GAIN 30 177 | 178 | /** Get maximal gain in dB (int32) */ 179 | #define SPEEX_PREPROCESS_GET_AGC_MAX_GAIN 31 180 | 181 | /* Can't set loudness */ 182 | /** Get loudness */ 183 | #define SPEEX_PREPROCESS_GET_AGC_LOUDNESS 33 184 | 185 | /* Can't set gain */ 186 | /** Get current gain (int32 percent) */ 187 | #define SPEEX_PREPROCESS_GET_AGC_GAIN 35 188 | 189 | /* Can't set spectrum size */ 190 | /** Get spectrum size for power spectrum (int32) */ 191 | #define SPEEX_PREPROCESS_GET_PSD_SIZE 37 192 | 193 | /* Can't set power spectrum */ 194 | /** Get power spectrum (int32[] of squared values) */ 195 | #define SPEEX_PREPROCESS_GET_PSD 39 196 | 197 | /* Can't set noise size */ 198 | /** Get spectrum size for noise estimate (int32) */ 199 | #define SPEEX_PREPROCESS_GET_NOISE_PSD_SIZE 41 200 | 201 | /* Can't set noise estimate */ 202 | /** Get noise estimate (int32[] of squared values) */ 203 | #define SPEEX_PREPROCESS_GET_NOISE_PSD 43 204 | 205 | /* Can't set speech probability */ 206 | /** Get speech probability in last frame (int32). */ 207 | #define SPEEX_PREPROCESS_GET_PROB 45 208 | 209 | /** Set preprocessor Automatic Gain Control level (int32) */ 210 | #define SPEEX_PREPROCESS_SET_AGC_TARGET 46 211 | /** Get preprocessor Automatic Gain Control level (int32) */ 212 | #define SPEEX_PREPROCESS_GET_AGC_TARGET 47 213 | 214 | #ifdef __cplusplus 215 | } 216 | #endif 217 | 218 | /** @}*/ 219 | #endif 220 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_resampler.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Jean-Marc Valin 2 | 3 | File: speex_resampler.h 4 | Resampling code 5 | 6 | The design goals of this code are: 7 | - Very fast algorithm 8 | - Low memory requirement 9 | - Good *perceptual* quality (and not best SNR) 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are 13 | met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | 3. The name of the author may not be used to endorse or promote products 23 | derived from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 29 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | 39 | #ifndef SPEEX_RESAMPLER_H 40 | #define SPEEX_RESAMPLER_H 41 | 42 | #ifdef OUTSIDE_SPEEX 43 | 44 | /********* WARNING: MENTAL SANITY ENDS HERE *************/ 45 | 46 | /* If the resampler is defined outside of Speex, we change the symbol names so that 47 | there won't be any clash if linking with Speex later on. */ 48 | 49 | /* #define RANDOM_PREFIX your software name here */ 50 | #ifndef RANDOM_PREFIX 51 | #error "Please define RANDOM_PREFIX (above) to something specific to your project to prevent symbol name clashes" 52 | #endif 53 | 54 | #define CAT_PREFIX2(a,b) a ## b 55 | #define CAT_PREFIX(a,b) CAT_PREFIX2(a, b) 56 | 57 | #define speex_resampler_init CAT_PREFIX(RANDOM_PREFIX,_resampler_init) 58 | #define speex_resampler_init_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac) 59 | #define speex_resampler_destroy CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy) 60 | #define speex_resampler_process_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float) 61 | #define speex_resampler_process_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int) 62 | #define speex_resampler_process_interleaved_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float) 63 | #define speex_resampler_process_interleaved_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int) 64 | #define speex_resampler_set_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate) 65 | #define speex_resampler_get_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_get_rate) 66 | #define speex_resampler_set_rate_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate_frac) 67 | #define speex_resampler_get_ratio CAT_PREFIX(RANDOM_PREFIX,_resampler_get_ratio) 68 | #define speex_resampler_set_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_set_quality) 69 | #define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality) 70 | #define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride) 71 | #define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride) 72 | #define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride) 73 | #define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride) 74 | #define speex_resampler_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency) 75 | #define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency) 76 | #define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros) 77 | #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem) 78 | #define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror) 79 | 80 | #define spx_int16_t short 81 | #define spx_int32_t int 82 | #define spx_uint16_t unsigned short 83 | #define spx_uint32_t unsigned int 84 | 85 | #else /* OUTSIDE_SPEEX */ 86 | 87 | #include "speexdsp_types.h" 88 | 89 | #endif /* OUTSIDE_SPEEX */ 90 | 91 | #ifdef __cplusplus 92 | extern "C" { 93 | #endif 94 | 95 | #define SPEEX_RESAMPLER_QUALITY_MAX 10 96 | #define SPEEX_RESAMPLER_QUALITY_MIN 0 97 | #define SPEEX_RESAMPLER_QUALITY_DEFAULT 4 98 | #define SPEEX_RESAMPLER_QUALITY_VOIP 3 99 | #define SPEEX_RESAMPLER_QUALITY_DESKTOP 5 100 | 101 | enum { 102 | RESAMPLER_ERR_SUCCESS = 0, 103 | RESAMPLER_ERR_ALLOC_FAILED = 1, 104 | RESAMPLER_ERR_BAD_STATE = 2, 105 | RESAMPLER_ERR_INVALID_ARG = 3, 106 | RESAMPLER_ERR_PTR_OVERLAP = 4, 107 | 108 | RESAMPLER_ERR_MAX_ERROR 109 | }; 110 | 111 | struct SpeexResamplerState_; 112 | typedef struct SpeexResamplerState_ SpeexResamplerState; 113 | 114 | /** Create a new resampler with integer input and output rates. 115 | * @param nb_channels Number of channels to be processed 116 | * @param in_rate Input sampling rate (integer number of Hz). 117 | * @param out_rate Output sampling rate (integer number of Hz). 118 | * @param quality Resampling quality between 0 and 10, where 0 has poor quality 119 | * and 10 has very high quality. 120 | * @return Newly created resampler state 121 | * @retval NULL Error: not enough memory 122 | */ 123 | SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, 124 | spx_uint32_t in_rate, 125 | spx_uint32_t out_rate, 126 | int quality, 127 | int *err); 128 | 129 | /** Create a new resampler with fractional input/output rates. The sampling 130 | * rate ratio is an arbitrary rational number with both the numerator and 131 | * denominator being 32-bit integers. 132 | * @param nb_channels Number of channels to be processed 133 | * @param ratio_num Numerator of the sampling rate ratio 134 | * @param ratio_den Denominator of the sampling rate ratio 135 | * @param in_rate Input sampling rate rounded to the nearest integer (in Hz). 136 | * @param out_rate Output sampling rate rounded to the nearest integer (in Hz). 137 | * @param quality Resampling quality between 0 and 10, where 0 has poor quality 138 | * and 10 has very high quality. 139 | * @return Newly created resampler state 140 | * @retval NULL Error: not enough memory 141 | */ 142 | SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, 143 | spx_uint32_t ratio_num, 144 | spx_uint32_t ratio_den, 145 | spx_uint32_t in_rate, 146 | spx_uint32_t out_rate, 147 | int quality, 148 | int *err); 149 | 150 | /** Destroy a resampler state. 151 | * @param st Resampler state 152 | */ 153 | void speex_resampler_destroy(SpeexResamplerState *st); 154 | 155 | /** Resample a float array. The input and output buffers must *not* overlap. 156 | * @param st Resampler state 157 | * @param channel_index Index of the channel to process for the multi-channel 158 | * base (0 otherwise) 159 | * @param in Input buffer 160 | * @param in_len Number of input samples in the input buffer. Returns the 161 | * number of samples processed 162 | * @param out Output buffer 163 | * @param out_len Size of the output buffer. Returns the number of samples written 164 | */ 165 | int speex_resampler_process_float(SpeexResamplerState *st, 166 | spx_uint32_t channel_index, 167 | const float *in, 168 | spx_uint32_t *in_len, 169 | float *out, 170 | spx_uint32_t *out_len); 171 | 172 | /** Resample an int array. The input and output buffers must *not* overlap. 173 | * @param st Resampler state 174 | * @param channel_index Index of the channel to process for the multi-channel 175 | * base (0 otherwise) 176 | * @param in Input buffer 177 | * @param in_len Number of input samples in the input buffer. Returns the number 178 | * of samples processed 179 | * @param out Output buffer 180 | * @param out_len Size of the output buffer. Returns the number of samples written 181 | */ 182 | int speex_resampler_process_int(SpeexResamplerState *st, 183 | spx_uint32_t channel_index, 184 | const spx_int16_t *in, 185 | spx_uint32_t *in_len, 186 | spx_int16_t *out, 187 | spx_uint32_t *out_len); 188 | 189 | /** Resample an interleaved float array. The input and output buffers must *not* overlap. 190 | * @param st Resampler state 191 | * @param in Input buffer 192 | * @param in_len Number of input samples in the input buffer. Returns the number 193 | * of samples processed. This is all per-channel. 194 | * @param out Output buffer 195 | * @param out_len Size of the output buffer. Returns the number of samples written. 196 | * This is all per-channel. 197 | */ 198 | int speex_resampler_process_interleaved_float(SpeexResamplerState *st, 199 | const float *in, 200 | spx_uint32_t *in_len, 201 | float *out, 202 | spx_uint32_t *out_len); 203 | 204 | /** Resample an interleaved int array. The input and output buffers must *not* overlap. 205 | * @param st Resampler state 206 | * @param in Input buffer 207 | * @param in_len Number of input samples in the input buffer. Returns the number 208 | * of samples processed. This is all per-channel. 209 | * @param out Output buffer 210 | * @param out_len Size of the output buffer. Returns the number of samples written. 211 | * This is all per-channel. 212 | */ 213 | int speex_resampler_process_interleaved_int(SpeexResamplerState *st, 214 | const spx_int16_t *in, 215 | spx_uint32_t *in_len, 216 | spx_int16_t *out, 217 | spx_uint32_t *out_len); 218 | 219 | /** Set (change) the input/output sampling rates (integer value). 220 | * @param st Resampler state 221 | * @param in_rate Input sampling rate (integer number of Hz). 222 | * @param out_rate Output sampling rate (integer number of Hz). 223 | */ 224 | int speex_resampler_set_rate(SpeexResamplerState *st, 225 | spx_uint32_t in_rate, 226 | spx_uint32_t out_rate); 227 | 228 | /** Get the current input/output sampling rates (integer value). 229 | * @param st Resampler state 230 | * @param in_rate Input sampling rate (integer number of Hz) copied. 231 | * @param out_rate Output sampling rate (integer number of Hz) copied. 232 | */ 233 | void speex_resampler_get_rate(SpeexResamplerState *st, 234 | spx_uint32_t *in_rate, 235 | spx_uint32_t *out_rate); 236 | 237 | /** Set (change) the input/output sampling rates and resampling ratio 238 | * (fractional values in Hz supported). 239 | * @param st Resampler state 240 | * @param ratio_num Numerator of the sampling rate ratio 241 | * @param ratio_den Denominator of the sampling rate ratio 242 | * @param in_rate Input sampling rate rounded to the nearest integer (in Hz). 243 | * @param out_rate Output sampling rate rounded to the nearest integer (in Hz). 244 | */ 245 | int speex_resampler_set_rate_frac(SpeexResamplerState *st, 246 | spx_uint32_t ratio_num, 247 | spx_uint32_t ratio_den, 248 | spx_uint32_t in_rate, 249 | spx_uint32_t out_rate); 250 | 251 | /** Get the current resampling ratio. This will be reduced to the least 252 | * common denominator. 253 | * @param st Resampler state 254 | * @param ratio_num Numerator of the sampling rate ratio copied 255 | * @param ratio_den Denominator of the sampling rate ratio copied 256 | */ 257 | void speex_resampler_get_ratio(SpeexResamplerState *st, 258 | spx_uint32_t *ratio_num, 259 | spx_uint32_t *ratio_den); 260 | 261 | /** Set (change) the conversion quality. 262 | * @param st Resampler state 263 | * @param quality Resampling quality between 0 and 10, where 0 has poor 264 | * quality and 10 has very high quality. 265 | */ 266 | int speex_resampler_set_quality(SpeexResamplerState *st, 267 | int quality); 268 | 269 | /** Get the conversion quality. 270 | * @param st Resampler state 271 | * @param quality Resampling quality between 0 and 10, where 0 has poor 272 | * quality and 10 has very high quality. 273 | */ 274 | void speex_resampler_get_quality(SpeexResamplerState *st, 275 | int *quality); 276 | 277 | /** Set (change) the input stride. 278 | * @param st Resampler state 279 | * @param stride Input stride 280 | */ 281 | void speex_resampler_set_input_stride(SpeexResamplerState *st, 282 | spx_uint32_t stride); 283 | 284 | /** Get the input stride. 285 | * @param st Resampler state 286 | * @param stride Input stride copied 287 | */ 288 | void speex_resampler_get_input_stride(SpeexResamplerState *st, 289 | spx_uint32_t *stride); 290 | 291 | /** Set (change) the output stride. 292 | * @param st Resampler state 293 | * @param stride Output stride 294 | */ 295 | void speex_resampler_set_output_stride(SpeexResamplerState *st, 296 | spx_uint32_t stride); 297 | 298 | /** Get the output stride. 299 | * @param st Resampler state copied 300 | * @param stride Output stride 301 | */ 302 | void speex_resampler_get_output_stride(SpeexResamplerState *st, 303 | spx_uint32_t *stride); 304 | 305 | /** Get the latency introduced by the resampler measured in input samples. 306 | * @param st Resampler state 307 | */ 308 | int speex_resampler_get_input_latency(SpeexResamplerState *st); 309 | 310 | /** Get the latency introduced by the resampler measured in output samples. 311 | * @param st Resampler state 312 | */ 313 | int speex_resampler_get_output_latency(SpeexResamplerState *st); 314 | 315 | /** Make sure that the first samples to go out of the resamplers don't have 316 | * leading zeros. This is only useful before starting to use a newly created 317 | * resampler. It is recommended to use that when resampling an audio file, as 318 | * it will generate a file with the same length. For real-time processing, 319 | * it is probably easier not to use this call (so that the output duration 320 | * is the same for the first frame). 321 | * @param st Resampler state 322 | */ 323 | int speex_resampler_skip_zeros(SpeexResamplerState *st); 324 | 325 | /** Reset a resampler so a new (unrelated) stream can be processed. 326 | * @param st Resampler state 327 | */ 328 | int speex_resampler_reset_mem(SpeexResamplerState *st); 329 | 330 | /** Returns the English meaning for an error code 331 | * @param err Error code 332 | * @return English string 333 | */ 334 | const char *speex_resampler_strerror(int err); 335 | 336 | #ifdef __cplusplus 337 | } 338 | #endif 339 | 340 | #endif 341 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_stereo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin*/ 2 | /** 3 | @file speex_stereo.h 4 | @brief Describes the handling for intensity stereo 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef STEREO_H 36 | #define STEREO_H 37 | /** @defgroup SpeexStereoState SpeexStereoState: Handling Speex stereo files 38 | * This describes the Speex intensity stereo encoding/decoding 39 | * @{ 40 | */ 41 | 42 | #include "speex_types.h" 43 | #include "speex_bits.h" 44 | 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | /** If you access any of these fields directly, I'll personally come and bite you */ 51 | typedef struct SpeexStereoState { 52 | float balance; /**< Left/right balance info */ 53 | float e_ratio; /**< Ratio of energies: E(left+right)/[E(left)+E(right)] */ 54 | float smooth_left; /**< Smoothed left channel gain */ 55 | float smooth_right; /**< Smoothed right channel gain */ 56 | float reserved1; /**< Reserved for future use */ 57 | float reserved2; /**< Reserved for future use */ 58 | } SpeexStereoState; 59 | 60 | /** Deprecated. Use speex_stereo_state_init() instead. */ 61 | #define SPEEX_STEREO_STATE_INIT {1,.5,1,1,0,0} 62 | 63 | /** Initialise/create a stereo stereo state */ 64 | SpeexStereoState *speex_stereo_state_init(); 65 | 66 | /** Reset/re-initialise an already allocated stereo state */ 67 | void speex_stereo_state_reset(SpeexStereoState *stereo); 68 | 69 | /** Destroy a stereo stereo state */ 70 | void speex_stereo_state_destroy(SpeexStereoState *stereo); 71 | 72 | /** Transforms a stereo frame into a mono frame and stores intensity stereo info in 'bits' */ 73 | void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits); 74 | 75 | /** Transforms a stereo frame into a mono frame and stores intensity stereo info in 'bits' */ 76 | void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits); 77 | 78 | /** Transforms a mono frame into a stereo frame using intensity stereo info */ 79 | void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo); 80 | 81 | /** Transforms a mono frame into a stereo frame using intensity stereo info */ 82 | void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexStereoState *stereo); 83 | 84 | /** Callback handler for intensity stereo info */ 85 | int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | /** @} */ 92 | #endif 93 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speex_types.h: -------------------------------------------------------------------------------- 1 | /* speex_types.h taken from libogg */ 2 | /******************************************************************** 3 | * * 4 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 8 | * * 9 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * 10 | * by the Xiph.Org Foundation http://www.xiph.org/ * 11 | * * 12 | ******************************************************************** 13 | 14 | function: #ifdef jail to whip a few platforms into the UNIX ideal. 15 | last mod: $Id: os_types.h 7524 2004-08-11 04:20:36Z conrad $ 16 | 17 | ********************************************************************/ 18 | /** 19 | @file speex_types.h 20 | @brief Speex types 21 | */ 22 | #ifndef _SPEEX_TYPES_H 23 | #define _SPEEX_TYPES_H 24 | 25 | #if defined(_WIN32) 26 | 27 | # if defined(__CYGWIN__) 28 | # include <_G_config.h> 29 | typedef _G_int32_t spx_int32_t; 30 | typedef _G_uint32_t spx_uint32_t; 31 | typedef _G_int16_t spx_int16_t; 32 | typedef _G_uint16_t spx_uint16_t; 33 | # elif defined(__MINGW32__) 34 | typedef short spx_int16_t; 35 | typedef unsigned short spx_uint16_t; 36 | typedef int spx_int32_t; 37 | typedef unsigned int spx_uint32_t; 38 | # elif defined(__MWERKS__) 39 | typedef int spx_int32_t; 40 | typedef unsigned int spx_uint32_t; 41 | typedef short spx_int16_t; 42 | typedef unsigned short spx_uint16_t; 43 | # else 44 | /* MSVC/Borland */ 45 | typedef __int32 spx_int32_t; 46 | typedef unsigned __int32 spx_uint32_t; 47 | typedef __int16 spx_int16_t; 48 | typedef unsigned __int16 spx_uint16_t; 49 | # endif 50 | 51 | #elif defined(__MACOS__) 52 | 53 | # include 54 | typedef SInt16 spx_int16_t; 55 | typedef UInt16 spx_uint16_t; 56 | typedef SInt32 spx_int32_t; 57 | typedef UInt32 spx_uint32_t; 58 | 59 | #elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ 60 | 61 | # include 62 | typedef int16_t spx_int16_t; 63 | typedef u_int16_t spx_uint16_t; 64 | typedef int32_t spx_int32_t; 65 | typedef u_int32_t spx_uint32_t; 66 | 67 | #elif defined(__BEOS__) 68 | 69 | /* Be */ 70 | # include 71 | typedef int16_t spx_int16_t; 72 | typedef u_int16_t spx_uint16_t; 73 | typedef int32_t spx_int32_t; 74 | typedef u_int32_t spx_uint32_t; 75 | 76 | #elif defined (__EMX__) 77 | 78 | /* OS/2 GCC */ 79 | typedef short spx_int16_t; 80 | typedef unsigned short spx_uint16_t; 81 | typedef int spx_int32_t; 82 | typedef unsigned int spx_uint32_t; 83 | 84 | #elif defined (DJGPP) 85 | 86 | /* DJGPP */ 87 | typedef short spx_int16_t; 88 | typedef int spx_int32_t; 89 | typedef unsigned int spx_uint32_t; 90 | 91 | #elif defined(R5900) 92 | 93 | /* PS2 EE */ 94 | typedef int spx_int32_t; 95 | typedef unsigned spx_uint32_t; 96 | typedef short spx_int16_t; 97 | 98 | #elif defined(__SYMBIAN32__) 99 | 100 | /* Symbian GCC */ 101 | typedef signed short spx_int16_t; 102 | typedef unsigned short spx_uint16_t; 103 | typedef signed int spx_int32_t; 104 | typedef unsigned int spx_uint32_t; 105 | 106 | #elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) 107 | 108 | typedef short spx_int16_t; 109 | typedef unsigned short spx_uint16_t; 110 | typedef long spx_int32_t; 111 | typedef unsigned long spx_uint32_t; 112 | 113 | #elif defined(CONFIG_TI_C6X) 114 | 115 | typedef short spx_int16_t; 116 | typedef unsigned short spx_uint16_t; 117 | typedef int spx_int32_t; 118 | typedef unsigned int spx_uint32_t; 119 | 120 | #else 121 | 122 | #include "speex_config_types.h" 123 | 124 | #endif 125 | 126 | #endif /* _SPEEX_TYPES_H */ 127 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speexdsp_config_types.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPEEX_TYPES_H__ 2 | #define __SPEEX_TYPES_H__ 3 | typedef short spx_int16_t; 4 | typedef unsigned short spx_uint16_t; 5 | typedef int spx_int32_t; 6 | typedef unsigned int spx_uint32_t; 7 | #endif -------------------------------------------------------------------------------- /app/src/main/jnilibs/speex_include/speexdsp_types.h: -------------------------------------------------------------------------------- 1 | /* speexdsp_types.h taken from libogg */ 2 | /******************************************************************** 3 | * * 4 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 8 | * * 9 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * 10 | * by the Xiph.Org Foundation http://www.xiph.org/ * 11 | * * 12 | ******************************************************************** 13 | 14 | function: #ifdef jail to whip a few platforms into the UNIX ideal. 15 | last mod: $Id: os_types.h 7524 2004-08-11 04:20:36Z conrad $ 16 | 17 | ********************************************************************/ 18 | /** 19 | @file speexdsp_types.h 20 | @brief Speex types 21 | */ 22 | #ifndef _SPEEX_TYPES_H 23 | #define _SPEEX_TYPES_H 24 | 25 | #if defined(_WIN32) 26 | 27 | # if defined(__CYGWIN__) 28 | # include <_G_config.h> 29 | typedef _G_int32_t spx_int32_t; 30 | typedef _G_uint32_t spx_uint32_t; 31 | typedef _G_int16_t spx_int16_t; 32 | typedef _G_uint16_t spx_uint16_t; 33 | # elif defined(__MINGW32__) 34 | typedef short spx_int16_t; 35 | typedef unsigned short spx_uint16_t; 36 | typedef int spx_int32_t; 37 | typedef unsigned int spx_uint32_t; 38 | # elif defined(__MWERKS__) 39 | typedef int spx_int32_t; 40 | typedef unsigned int spx_uint32_t; 41 | typedef short spx_int16_t; 42 | typedef unsigned short spx_uint16_t; 43 | # else 44 | /* MSVC/Borland */ 45 | typedef __int32 spx_int32_t; 46 | typedef unsigned __int32 spx_uint32_t; 47 | typedef __int16 spx_int16_t; 48 | typedef unsigned __int16 spx_uint16_t; 49 | # endif 50 | 51 | #elif defined(__MACOS__) 52 | 53 | # include 54 | typedef SInt16 spx_int16_t; 55 | typedef UInt16 spx_uint16_t; 56 | typedef SInt32 spx_int32_t; 57 | typedef UInt32 spx_uint32_t; 58 | 59 | #elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ 60 | 61 | # include 62 | typedef int16_t spx_int16_t; 63 | typedef u_int16_t spx_uint16_t; 64 | typedef int32_t spx_int32_t; 65 | typedef u_int32_t spx_uint32_t; 66 | 67 | #elif defined(__BEOS__) 68 | 69 | /* Be */ 70 | # include 71 | typedef int16_t spx_int16_t; 72 | typedef u_int16_t spx_uint16_t; 73 | typedef int32_t spx_int32_t; 74 | typedef u_int32_t spx_uint32_t; 75 | 76 | #elif defined (__EMX__) 77 | 78 | /* OS/2 GCC */ 79 | typedef short spx_int16_t; 80 | typedef unsigned short spx_uint16_t; 81 | typedef int spx_int32_t; 82 | typedef unsigned int spx_uint32_t; 83 | 84 | #elif defined (DJGPP) 85 | 86 | /* DJGPP */ 87 | typedef short spx_int16_t; 88 | typedef int spx_int32_t; 89 | typedef unsigned int spx_uint32_t; 90 | 91 | #elif defined(R5900) 92 | 93 | /* PS2 EE */ 94 | typedef int spx_int32_t; 95 | typedef unsigned spx_uint32_t; 96 | typedef short spx_int16_t; 97 | 98 | #elif defined(__SYMBIAN32__) 99 | 100 | /* Symbian GCC */ 101 | typedef signed short spx_int16_t; 102 | typedef unsigned short spx_uint16_t; 103 | typedef signed int spx_int32_t; 104 | typedef unsigned int spx_uint32_t; 105 | 106 | #elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) 107 | 108 | typedef short spx_int16_t; 109 | typedef unsigned short spx_uint16_t; 110 | typedef long spx_int32_t; 111 | typedef unsigned long spx_uint32_t; 112 | 113 | #elif defined(CONFIG_TI_C6X) 114 | 115 | typedef short spx_int16_t; 116 | typedef unsigned short spx_uint16_t; 117 | typedef int spx_int32_t; 118 | typedef unsigned int spx_uint32_t; 119 | 120 | #else 121 | 122 | #include "speexdsp_config_types.h" 123 | 124 | #endif 125 | 126 | #endif /* _SPEEX_TYPES_H */ 127 | -------------------------------------------------------------------------------- /app/src/main/jnilibs/x86/libspeex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-ma/Android-OpenSLES-Demo/65a67363d80e579e36be01703e42b26a216a9364/app/src/main/jnilibs/x86/libspeex.so -------------------------------------------------------------------------------- /app/src/main/jnilibs/x86/libspeexdsp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-ma/Android-OpenSLES-Demo/65a67363d80e579e36be01703e42b26a216a9364/app/src/main/jnilibs/x86/libspeexdsp.so -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 |