├── pitchandroid ├── libs │ ├── armeabi │ │ ├── libstdc++.a │ │ ├── silk.a │ │ ├── libcodecsilk.so │ │ └── lib_pitchandroid_soundtouch_jni_gyp.so │ └── android-support-v4.jar ├── .DS_Store ├── jni │ ├── silk.a │ ├── codecDll_Tester │ │ ├── silk.a │ │ ├── 16k_mono.pcm │ │ ├── Decoded_备份.pcm │ │ ├── Encoded_备份.Silk │ │ ├── codecDll_Tester.h │ │ ├── silkactivity.c │ │ ├── CodecDll.h │ │ └── codecDll_Tester.cpp │ ├── com_example_soundtouchdemo_NativeSoundTouch.cpp │ ├── log.h │ ├── soundtouch-jni.cpp │ ├── com_example_soundtouchdemo_NativeSoundTouch.h │ └── silkactivity.c ├── build-jni.sh ├── ic_launcher-web.png ├── res │ ├── drawable-mdpi │ │ ├── play.png │ │ ├── record.png │ │ ├── stop.png │ │ └── ic_launcher.png │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── values │ │ ├── strings.xml │ │ └── styles.xml │ ├── menu │ │ └── activity_main.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── layout │ │ └── activity_main.xml ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── project.properties ├── soundtouch-jni.gyp ├── proguard-project.txt ├── AndroidManifest.xml ├── src │ └── com │ │ └── example │ │ └── soundtouchdemo │ │ ├── NativeSoundTouch.java │ │ ├── SilkDecoder.java │ │ ├── MainActivity.java │ │ └── SoundTouchRecorder.java ├── build.gradle ├── gradlew.bat └── gradlew └── README.md /pitchandroid/libs/armeabi/libstdc++.a: -------------------------------------------------------------------------------- 1 | ! 2 | -------------------------------------------------------------------------------- /pitchandroid/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/.DS_Store -------------------------------------------------------------------------------- /pitchandroid/jni/silk.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/jni/silk.a -------------------------------------------------------------------------------- /pitchandroid/build-jni.sh: -------------------------------------------------------------------------------- 1 | ROOT=$(dirname $0)/.. 2 | 3 | ${ROOT}/build/gyp_android 4 | 5 | ndk-build -j4 -------------------------------------------------------------------------------- /pitchandroid/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/ic_launcher-web.png -------------------------------------------------------------------------------- /pitchandroid/libs/armeabi/silk.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/libs/armeabi/silk.a -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/silk.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/jni/codecDll_Tester/silk.a -------------------------------------------------------------------------------- /pitchandroid/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/libs/android-support-v4.jar -------------------------------------------------------------------------------- /pitchandroid/libs/armeabi/libcodecsilk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/libs/armeabi/libcodecsilk.so -------------------------------------------------------------------------------- /pitchandroid/res/drawable-mdpi/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/res/drawable-mdpi/play.png -------------------------------------------------------------------------------- /pitchandroid/res/drawable-mdpi/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/res/drawable-mdpi/record.png -------------------------------------------------------------------------------- /pitchandroid/res/drawable-mdpi/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/res/drawable-mdpi/stop.png -------------------------------------------------------------------------------- /pitchandroid/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/16k_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/jni/codecDll_Tester/16k_mono.pcm -------------------------------------------------------------------------------- /pitchandroid/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /pitchandroid/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /pitchandroid/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/Decoded_备份.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/jni/codecDll_Tester/Decoded_备份.pcm -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/Encoded_备份.Silk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/jni/codecDll_Tester/Encoded_备份.Silk -------------------------------------------------------------------------------- /pitchandroid/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /pitchandroid/jni/com_example_soundtouchdemo_NativeSoundTouch.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/jni/com_example_soundtouchdemo_NativeSoundTouch.cpp -------------------------------------------------------------------------------- /pitchandroid/libs/armeabi/lib_pitchandroid_soundtouch_jni_gyp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tujiu/SoundTouchDemo/HEAD/pitchandroid/libs/armeabi/lib_pitchandroid_soundtouch_jni_gyp.so -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/codecDll_Tester.h: -------------------------------------------------------------------------------- 1 | 2 | #ifdef __cplusplus 3 | extern "C" { 4 | #endif 5 | int silkdemo(char* input, char* output1, char* output2); 6 | 7 | #ifdef __cplusplus 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SoundTouchDemo 2 | soundtouch 变声demo,可以实时看到变声效果,添加了silk编解码,对比音效。 3 | 4 | 基于https://github.com/caojianhua1741/soundtouchdemo 5 | 修改了demo的逻辑,可以直接调节音调,速度,直接看到结果。 6 | 加入了silk编解码,模拟网络端发送语音压缩解压后的效果。 7 | 8 | silk和soundtouch库的编译没弄,可以在别处找到。 9 | -------------------------------------------------------------------------------- /pitchandroid/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | soundtouchdemo 5 | Hello world! 6 | Settings 7 | 8 | -------------------------------------------------------------------------------- /pitchandroid/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip 7 | -------------------------------------------------------------------------------- /pitchandroid/res/menu/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /pitchandroid/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /pitchandroid/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /pitchandroid/jni/log.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define LOGV(...) __android_log_print((int)ANDROID_LOG_VERBOSE, "SOUNDTOUCH", __VA_ARGS__) 4 | #define LOGD(...) __android_log_print((int)ANDROID_LOG_DEBUG, "SOUNDTOUCH", __VA_ARGS__) 5 | #define LOGI(...) __android_log_print((int)ANDROID_LOG_INFO, "SOUNDTOUCH", __VA_ARGS__) 6 | #define LOGW(...) __android_log_print((int)ANDROID_LOG_WARN, "SOUNDTOUCH", __VA_ARGS__) 7 | #define LOGE(...) __android_log_print((int)ANDROID_LOG_ERROR, "SOUNDTOUCH", __VA_ARGS__) 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /pitchandroid/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /pitchandroid/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /pitchandroid/soundtouch-jni.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [ 3 | { 4 | 'target_name': 'soundtouch-jni', 5 | 'type':'shared_library', 6 | 7 | 'include_dir':[ 8 | './jni', 9 | ], 10 | 11 | 12 | 'direct_dependent_settings':{ 13 | 'include_dirs':[ 14 | 15 | ], 16 | }, 17 | 18 | 'export_dependent_settings':[ 19 | ], 20 | 21 | 'dependencies':[ 22 | '<(DEPTH)/soundtouch/soundtouch.gyp:*', 23 | ], 24 | 25 | 'sources':[ 26 | './jni/com_example_soundtouchdemo_NativeSoundTouch.cpp', 27 | ], 28 | 29 | 30 | 'link_settings': { 31 | 'ldflags': [ 32 | '-llog', 33 | ] 34 | }, 35 | } 36 | 37 | ], 38 | 39 | } -------------------------------------------------------------------------------- /pitchandroid/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /pitchandroid/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 13 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /pitchandroid/src/com/example/soundtouchdemo/NativeSoundTouch.java: -------------------------------------------------------------------------------- 1 | package com.example.soundtouchdemo; 2 | 3 | public final class NativeSoundTouch { 4 | 5 | private static NativeSoundTouch instance = null; 6 | 7 | private long nativeSoundTouch; 8 | 9 | public synchronized static NativeSoundTouch getSoundTouch() { 10 | if (null == instance) { 11 | instance = new NativeSoundTouch(); 12 | } 13 | 14 | return instance; 15 | } 16 | 17 | private NativeSoundTouch() { 18 | nativeSoundTouch = soundTouchCreate(); 19 | } 20 | 21 | public native long soundTouchCreate(); 22 | 23 | public native void soundTouchDestory(); 24 | 25 | public native String soundTouchgethVersion(); 26 | 27 | public native void setPitchSemiTones(float pitch); 28 | 29 | public native void setTempoChange(float newTempo); 30 | 31 | public native void shiftingPitch(byte[] pcmData, int offset, int length); 32 | 33 | public native int receiveSamples(byte[] pitchData, int bufferLenght); 34 | 35 | public native void soundTouchFlushLastSamples(); 36 | 37 | @Override 38 | protected void finalize() throws Throwable { 39 | 40 | soundTouchDestory(); 41 | 42 | super.finalize(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pitchandroid/jni/soundtouch-jni.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | /// 3 | /// Example Interface class for SoundTouch native compilation 4 | /// 5 | /// Author : Copyright (c) Olli Parviainen 6 | /// Author e-mail : oparviai 'at' iki.fi 7 | /// WWW : http://www.surina.net 8 | /// 9 | //////////////////////////////////////////////////////////////////////////////// 10 | // 11 | // $Id: soundtouch-jni.cpp 165 2012-12-28 19:55:23Z oparviai $ 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | 15 | #include 16 | #include 17 | //#include 18 | //#include 19 | //#include 20 | 21 | #include "SoundTouch.h" 22 | //#include "TimeShiftEffect.h" 23 | 24 | #define LOGV(...) __android_log_print((int)ANDROID_LOG_INFO, "SOUNDTOUCH", __VA_ARGS__) 25 | //#define LOGV(...) 26 | 27 | 28 | #define DLL_PUBLIC __attribute__ ((visibility ("default"))) 29 | 30 | using namespace soundtouch; 31 | 32 | extern "C" DLL_PUBLIC jstring Java_net_surina_soundtouch_getVersionString(JNIEnv *env, jobject thiz) 33 | { 34 | const char *verStr; 35 | 36 | LOGV("JNI call soundtouch.getVersionString"); 37 | 38 | // Call example SoundTouch routine 39 | verStr = SoundTouch::getVersionString(); 40 | 41 | // return version as string 42 | return env->NewStringUTF(verStr); 43 | } 44 | -------------------------------------------------------------------------------- /pitchandroid/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:0.8.+' 7 | } 8 | } 9 | apply plugin: 'android' 10 | 11 | dependencies { 12 | compile fileTree(dir: 'libs', include: '*.jar') 13 | } 14 | 15 | android { 16 | compileSdkVersion 19 17 | buildToolsVersion "19.0.3" 18 | 19 | sourceSets { 20 | main { 21 | manifest.srcFile 'AndroidManifest.xml' 22 | java.srcDirs = ['src'] 23 | resources.srcDirs = ['src'] 24 | aidl.srcDirs = ['src'] 25 | renderscript.srcDirs = ['src'] 26 | res.srcDirs = ['res'] 27 | assets.srcDirs = ['assets'] 28 | } 29 | 30 | // Move the tests to tests/java, tests/res, etc... 31 | instrumentTest.setRoot('tests') 32 | 33 | // Move the build types to build-types/ 34 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 35 | // This moves them out of them default location under src//... which would 36 | // conflict with src/ being used by the main source set. 37 | // Adding new build types or product flavors should be accompanied 38 | // by a similar customization. 39 | debug.setRoot('build-types/debug') 40 | release.setRoot('build-types/release') 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pitchandroid/src/com/example/soundtouchdemo/SilkDecoder.java: -------------------------------------------------------------------------------- 1 | package com.example.soundtouchdemo; 2 | 3 | import android.content.Context; 4 | import android.media.AudioManager; 5 | 6 | public class SilkDecoder extends Thread { 7 | 8 | public static final String OUT1 = "temp_"; 9 | public static final String OUT2 = "encode_decode_"; 10 | private String file; 11 | private String inputFile; 12 | private String outFile1; 13 | private String outFile2; 14 | private EncodeDecodeNotifier notifier; 15 | 16 | public interface EncodeDecodeNotifier { 17 | public void encodeDecodeFinished(); 18 | } 19 | 20 | public SilkDecoder(Context context, String fileName, EncodeDecodeNotifier notifier) { 21 | this.file = fileName; 22 | this.inputFile = /*context.getFilesDir().getPath() + */"/data/data/com.example.soundtouchdemo/files/" + fileName; 23 | this.outFile1 = "/data/data/com.example.soundtouchdemo/files/" + OUT1 + fileName; 24 | this.outFile2 = "/data/data/com.example.soundtouchdemo/files/" + OUT2 + fileName; 25 | this.notifier = notifier; 26 | init(context); 27 | } 28 | 29 | private void init(Context context) { 30 | AudioManager audiMgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 31 | String sEc = "NULL"; 32 | String sNs = "NULL"; 33 | String sGc = "NULL"; 34 | sEc = audiMgr.getParameters("ec_supported"); 35 | sNs = audiMgr.getParameters("ns_supported"); 36 | sGc = audiMgr.getParameters("gc_supported"); 37 | // objTextViewS.setText("[INFO] ec: " + sEc + ", ns: " + sNs + ", gc: " 38 | // + sGc); 39 | // tv.setText("[INFO] ec: " + sEc + ", ns: " + sNs + ", gc: " + sGc); 40 | } 41 | 42 | /* A native method that is implemented by the 43 | * 'helloneon' native library, which is packaged 44 | * with this application. 45 | */ 46 | public native String stringFromJNI(String input, String output1, String output2); 47 | 48 | /* this is used to load the 'helloneon' library on application 49 | * startup. The library has already been unpacked into 50 | * /data/data/com.example.neon/lib/libhelloneon.so at 51 | * installation time by the package manager. 52 | */ 53 | static { 54 | System.loadLibrary("codecsilk"); 55 | } 56 | 57 | public void run() { 58 | stringFromJNI(inputFile, outFile1, outFile2); 59 | notifier.encodeDecodeFinished(); 60 | } 61 | 62 | public String getDecodedFile() { 63 | return OUT2 + file; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pitchandroid/jni/com_example_soundtouchdemo_NativeSoundTouch.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_example_soundtouchdemo_NativeSoundTouch */ 4 | 5 | #ifndef _Included_com_example_soundtouchdemo_NativeSoundTouch 6 | #define _Included_com_example_soundtouchdemo_NativeSoundTouch 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_example_soundtouchdemo_NativeSoundTouch 12 | * Method: soundTouchCreate 13 | * Signature: ()J 14 | */ 15 | JNIEXPORT jlong JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_soundTouchCreate( 16 | JNIEnv *, jobject); 17 | 18 | /* 19 | * Class: com_example_soundtouchdemo_NativeSoundTouch 20 | * Method: soundTouchDestory 21 | * Signature: ()V 22 | */ 23 | JNIEXPORT void JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_soundTouchDestory 24 | (JNIEnv *, jobject); 25 | 26 | /* 27 | * Class: com_example_soundtouchdemo_NativeSoundTouch 28 | * Method: soundTouchgethVersion 29 | * Signature: ()Ljava/lang/String; 30 | */ 31 | JNIEXPORT jstring JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_soundTouchgethVersion( 32 | JNIEnv *, jobject); 33 | 34 | /* 35 | * Class: com_example_soundtouchdemo_NativeSoundTouch 36 | * Method: setPitchSemiTones 37 | * Signature: (D)V 38 | */ 39 | JNIEXPORT void JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_setPitchSemiTones 40 | (JNIEnv *, jobject, jfloat); 41 | 42 | /* 43 | * Class: com_example_soundtouchdemo_NativeSoundTouch 44 | * Method: setTempoChange 45 | * Signature: (F)V 46 | */ 47 | JNIEXPORT void JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_setTempoChange 48 | (JNIEnv *, jobject, jfloat); 49 | 50 | /* 51 | * Class: com_example_soundtouchdemo_NativeSoundTouch 52 | * Method: shiftingPitch 53 | * Signature: ([BII)V 54 | */ 55 | JNIEXPORT void JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_shiftingPitch 56 | (JNIEnv *, jobject, jbyteArray, jint, jint); 57 | 58 | /* 59 | * Class: com_example_soundtouchdemo_NativeSoundTouch 60 | * Method: receiveSamples 61 | * Signature: ([BI)I 62 | */ 63 | JNIEXPORT jint JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_receiveSamples 64 | (JNIEnv *, jobject, jbyteArray, jint); 65 | 66 | /* 67 | * Class: com_example_soundtouchdemo_NativeSoundTouch 68 | * Method: soundTouchFlushLastSamples 69 | * Signature: ()V 70 | */ 71 | JNIEXPORT void JNICALL Java_com_example_soundtouchdemo_NativeSoundTouch_soundTouchFlushLastSamples 72 | (JNIEnv *, jobject); 73 | 74 | 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | #endif 80 | -------------------------------------------------------------------------------- /pitchandroid/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/silkactivity.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "codecDll_Tester/codecDll_Tester.h" 23 | #include 24 | 25 | 26 | #define DEBUG 0 27 | 28 | #if DEBUG 29 | #include 30 | # define D(x...) __android_log_print(ANDROID_LOG_INFO,"helloneon",x) 31 | #else 32 | # define D(...) do {} while (0) 33 | #endif 34 | 35 | /* return current time in milliseconds */ 36 | static double 37 | now_ms(void) 38 | { 39 | struct timespec res; 40 | clock_gettime(CLOCK_REALTIME, &res); 41 | return 1000.0*res.tv_sec + (double)res.tv_nsec/1e6; 42 | } 43 | 44 | #define LOOP_CNT (10000 ) 45 | 46 | /* This is a trivial JNI example where we use a native method 47 | * to return a new VM String. See the corresponding Java source 48 | * file located at: 49 | * 50 | * apps/samples/hello-neon/project/src/com/example/neon/HelloNeon.java 51 | */ 52 | 53 | jstring Java_com_silkandroid_silkactivity_stringFromJNI( JNIEnv* env, jobject thiz , jstring inputName, jstring outputName1, jstring outputName2) 54 | { 55 | char* str; 56 | uint64_t features; 57 | char buffer[512]; 58 | char tryNeon = 0; 59 | double t0, t1, time_c, time_neon; 60 | const char* input; 61 | input = env->GetStringUTFChars(inputName, false); 62 | const char* output1; 63 | output1 = env->GetStringUTFChars(outputName1, false); 64 | const char* output2; 65 | output2 = env->GetStringUTFChars(outputName2, false); 66 | 67 | time_c = 0.0; 68 | 69 | __android_log_print(ANDROID_LOG_INFO, "silk", "before silkdemo...\r\n"); 70 | silkdemo(input, output1, output2); 71 | __android_log_print(ANDROID_LOG_INFO, "silk", "after sikldemo... \r\n "); 72 | 73 | asprintf(&str, "FIR Filter benchmark:\nC version : %g ms\n", time_c); 74 | strlcpy(buffer, str, sizeof buffer); 75 | free(str); 76 | 77 | strlcat(buffer, "Neon version : ", sizeof buffer); 78 | 79 | 80 | 81 | EXIT: 82 | return (*env)->NewStringUTF(env, buffer); 83 | 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /pitchandroid/jni/silkactivity.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "codecDll_Tester/codecDll_Tester.h" 23 | #include 24 | 25 | 26 | #define DEBUG 0 27 | 28 | #if DEBUG 29 | #include 30 | # define D(x...) __android_log_print(ANDROID_LOG_INFO,"helloneon",x) 31 | #else 32 | # define D(...) do {} while (0) 33 | #endif 34 | 35 | /* return current time in milliseconds */ 36 | static double 37 | now_ms(void) 38 | { 39 | struct timespec res; 40 | clock_gettime(CLOCK_REALTIME, &res); 41 | return 1000.0*res.tv_sec + (double)res.tv_nsec/1e6; 42 | } 43 | 44 | #define LOOP_CNT (10000 ) 45 | 46 | /* This is a trivial JNI example where we use a native method 47 | * to return a new VM String. See the corresponding Java source 48 | * file located at: 49 | * 50 | * apps/samples/hello-neon/project/src/com/example/neon/HelloNeon.java 51 | */ 52 | 53 | jstring Java_com_example_soundtouchdemo_SilkDecoder_stringFromJNI( JNIEnv* env, jobject thiz , jstring inputName, jstring outputName1, jstring outputName2) 54 | { 55 | char* str; 56 | uint64_t features; 57 | char buffer[512]; 58 | char tryNeon = 0; 59 | double t0, t1, time_c, time_neon; 60 | char* input; 61 | input = (char*)(*env)->GetStringUTFChars(env,inputName, NULL); 62 | char* output1; 63 | output1 = (char*)(*env)->GetStringUTFChars(env,outputName1, NULL); 64 | char* output2; 65 | output2 = (char*)(*env)->GetStringUTFChars(env,outputName2, NULL); 66 | 67 | time_c = 0.0; 68 | 69 | __android_log_print(ANDROID_LOG_INFO, "silk", "before silkdemo...\r\n"); 70 | silkdemo(input, output1, output2); 71 | __android_log_print(ANDROID_LOG_INFO, "silk", "after sikldemo... \r\n "); 72 | 73 | asprintf(&str, "FIR Filter benchmark:\nC version : %g ms\n", time_c); 74 | strlcpy(buffer, str, sizeof buffer); 75 | free(str); 76 | 77 | strlcat(buffer, "Neon version : ", sizeof buffer); 78 | 79 | 80 | 81 | EXIT: 82 | return (*env)->NewStringUTF(env, buffer); 83 | 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/CodecDll.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef LIB_CODEC_H 3 | #define LIB_CODEC_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #define EncodeSampleRate 0x0001 /* Int, KeyValue Must be in 8000,12000,16000,24000,32000,44100,48000 */ 10 | #define EncodeBitRate 0x0002 /* Int, KeyValue Must be in 5000~100000 */ 11 | /********************************/ 12 | /* SampleRate| avg BitRate(kpbs)*/ 13 | /*------------------------- ----*/ 14 | /* 8000 | 5 - 20 */ 15 | /* 12000 | 7 - 25 */ 16 | /* 16000 | 8 - 30 */ 17 | /* 24000 | 20 - 40 */ 18 | /********************************/ 19 | #define EncodeMaxInternalSampleRate 0x0004 /* Int, KeyValue Must be in 8000,12000,16000,24000 */ 20 | #define EncodeComplexity 0x0008 /* Int, KeyValue Must be in 0,1,2 */ 21 | #define EncodePacketSize 0x0010 /* Int, KeyValue Must be 20ms,40ms,60ms,80ms,100ms samples of SampleRate*/ 22 | /* eg 16000 , 20ms PacketSize, keyvalue is 16000 * 20 / 1000 = 320 */ 23 | #define EncodePacketLossPercentage 0x0020 /* Int, KeyValue Must be in 0~100 */ 24 | #define EncodeEnableInBandFEC 0x0040 /* Int, KeyValue Must be in 0, 1 */ 25 | #define EncodeEnableDTX 0x0080 /* Int, KeyValue Must be in 0, 1 */ 26 | 27 | #define DecodeSampleRate 0x0001 /* Int, KeyValue Must be in 8000,12000,16000,24000,32000,44100,48000 */ 28 | 29 | //silk default 30 | /* 31 | void *enc = CreateCodecInstance(eEncode); 32 | int res = SetValue(enc,EncodeSampleRate,8000); 33 | 34 | */ 35 | // Encode 36 | // SampleRate 16000 37 | // BitRate 40000 38 | // MaxInternalSampleRate 24000 39 | // Complexity 2 40 | // PacketSize 16000 * 20 / 1000 41 | // PacketLossPercentage 0 42 | // EnableInBandFEC 0 43 | // EnableDTX 0 44 | 45 | //Decode 46 | // SampleRate 16000 47 | 48 | 49 | typedef enum 50 | { 51 | ERR_SUCCESS = 0, // no error 52 | ERR_CODEC_INTERNAL_ERROR = -1, // codec internal error 53 | ERR_INVALID_ARG = -2, // invalid arg 54 | ERR_OUT_OF_MEMROY = -3, // memroy error 55 | ERR_INVALID_KEY = -4, // invalid key, not in keyvaluemacros.h 56 | ERR_INVALID_KEY_VALUE = -5, // invalid keyvalue, not in range 57 | 58 | ERR_ENC_INPUT_LEN = -6, // encode input length error 59 | ERR_ENC_PAYLOAD_BUF_TOO_SHORT = -7, // encode output len error 60 | ERR_ENC_INVALID_CODEC_NAME = -8, // codec not support 61 | 62 | ERR_DEC_PAYLOAD_TOO_LARGE = -9, // decode input length error 63 | ERR_DEC_OUTPUT_LEN = -10 // decode output len error 64 | 65 | 66 | }ERROR_CODE; 67 | 68 | 69 | typedef enum 70 | { 71 | eEncode = 0, 72 | eDecode = 1 73 | }EMask; 74 | 75 | void* CreateCodecInstance(const char* codecName,int flag); 76 | int DestroyCodecInstance(void* pCodecInstance); 77 | int SetValue(void* pCodecInstance,int key,void* keyValue,int keyBytesSize); 78 | int GetValue(void* pCodecInstance,int key,void* keyValue,int keyBytesSize); 79 | int Encode(void* pCodecInstance,char* pPcmInputBuf,int pcmBufBytesSize,char* pEncodedBuf,int* pEncodedBufBytesSize); 80 | int Decode(void* pCodecInstance,char* pEncodedBuf,int EncodedBufBytesSize,char* pPcmDecodedBuf,int* pcmBufBytesSize); 81 | 82 | 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | #endif 88 | -------------------------------------------------------------------------------- /pitchandroid/jni/codecDll_Tester/codecDll_Tester.cpp: -------------------------------------------------------------------------------- 1 | // codecDll_Tester.cpp : Defines the entry point for the console application. 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include "codecDll_Tester.h" 8 | #include "CodecDll.h" 9 | 10 | 11 | #define tag "siklandroiddemo" 12 | 13 | int testCodecDllEncode(char* input, char* output1, char* output2); 14 | int testCodecDllDecode(char* input, char* output1, char* output2); 15 | 16 | int silkdemo(char* input, char* output1, char* output2) 17 | { 18 | __android_log_print(ANDROID_LOG_INFO, tag, "Encode..."); 19 | testCodecDllEncode(input, output1, output2); 20 | 21 | __android_log_print(ANDROID_LOG_INFO, tag, "Decode...\r\n"); 22 | testCodecDllDecode(input, output1, output2); 23 | 24 | __android_log_print(ANDROID_LOG_INFO, tag, "over...\r\n"); 25 | 26 | return 0; 27 | 28 | } 29 | 30 | int testCodecDllEncode(char* input, char* output1, char* output2) 31 | { 32 | FILE* pfPcmFile = NULL; 33 | FILE* pfEncodedFile = NULL ; 34 | void* pEncodec = NULL ; 35 | pfPcmFile = fopen( input, "rb" ); 36 | pfEncodedFile = fopen( output1, "wb" ); 37 | pEncodec = CreateCodecInstance( "silk", eEncode ); 38 | int nSampleRate = 16000 ; 39 | int nBitRate = 40000 ; 40 | SetValue(pEncodec,EncodeSampleRate,(void*)&nSampleRate,sizeof(int)); 41 | //SetValue(pEncodec,EncodeBitRate,(void*)&nBitRate,sizeof(int)); 42 | char ppcmBuf[16000*80*2*20/1000] = {0}; 43 | int pcmbufLen = 16000*20*2/1000; 44 | char pencodedBuf[16000*80*2*20/1000] = {0}; 45 | int encodebufLen = 16000*20*2/1000; 46 | char* pcmBuf = ppcmBuf; 47 | char* encodedBuf = pencodedBuf; 48 | int count = 0; 49 | if( pfPcmFile && pfEncodedFile ) 50 | { 51 | while( fread( pcmBuf,pcmbufLen,1,pfPcmFile) == 1 ) 52 | { 53 | int ret = Encode( pEncodec,(char*)pcmBuf,pcmbufLen,encodedBuf,&encodebufLen); 54 | if( ret ) 55 | { 56 | //printf("Encode Error\n"); 57 | __android_log_print(ANDROID_LOG_INFO, tag, "Encode Error:%d \r\n", ret); 58 | break; 59 | } 60 | count++; 61 | fwrite(&encodebufLen,sizeof(encodebufLen),1,pfEncodedFile); 62 | fwrite(encodedBuf,encodebufLen,1,pfEncodedFile); 63 | encodebufLen = pcmbufLen; 64 | } 65 | __android_log_print(ANDROID_LOG_INFO, tag, "count = %d\r\n", count); 66 | } 67 | 68 | 69 | DestroyCodecInstance(pEncodec); 70 | fclose( pfPcmFile ); 71 | fclose( pfEncodedFile ); 72 | __android_log_print(ANDROID_LOG_INFO, tag, "encoded file = %s\r\n", output1); 73 | return 0; 74 | 75 | } 76 | 77 | int testCodecDllDecode(char* input, char* output1, char* output2) 78 | { 79 | FILE* pfPcmFile = NULL; 80 | FILE* pfEncodedFile = NULL ; 81 | void* pDecodec = NULL ; 82 | pfEncodedFile = fopen( output1, "rb" ); 83 | pfPcmFile = fopen( output2, "wb" ); 84 | 85 | pDecodec = CreateCodecInstance( "silk", eDecode ); 86 | 87 | char pencodedBuf[16000*80*2*20/1000] = {0}; 88 | int encodebufLen = 0; 89 | 90 | char ppcmBuf[16000*80*2*20/1000] = {0}; 91 | int pcmbufLen = 16000*20*2/1000; 92 | 93 | char* pcmBuf = ppcmBuf; 94 | char* encodedBuf = pencodedBuf; 95 | if( pfPcmFile && pfPcmFile ) 96 | { 97 | while( fread( &encodebufLen,sizeof(encodebufLen),1,pfEncodedFile) == 1 ) 98 | { 99 | if( fread( encodedBuf,encodebufLen,1,pfEncodedFile) == 1 ) 100 | { 101 | int ret = Decode( pDecodec, encodedBuf,encodebufLen,pcmBuf,&pcmbufLen); 102 | if ( ret ) 103 | { 104 | //printf("Deocode Error\n"); 105 | __android_log_print(ANDROID_LOG_INFO, tag, "Deocode Error: %d\r\n", ret); 106 | break; 107 | } 108 | fwrite(pcmBuf,pcmbufLen,1,pfPcmFile); 109 | } 110 | else 111 | break; 112 | 113 | } 114 | 115 | } 116 | 117 | 118 | DestroyCodecInstance(pDecodec); 119 | fclose( pfPcmFile ); 120 | fclose( pfEncodedFile ); 121 | 122 | __android_log_print(ANDROID_LOG_INFO, tag, "decoded file = %s\r\n", output2); 123 | return 0; 124 | 125 | } 126 | -------------------------------------------------------------------------------- /pitchandroid/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 12 | 13 | 19 | 20 | 25 | 26 | 34 | 35 | 36 | 40 | 41 | 47 | 48 | 53 | 54 | 62 | 63 | 64 | 68 | 69 | 76 | 77 | 82 | 83 | 90 | 91 |