├── .classpath ├── .cproject ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── LICENSE ├── README.md ├── bin ├── AndroidManifest.xml ├── classes │ └── com │ │ └── obteq │ │ └── android │ │ └── codec2 │ │ ├── BuildConfig.class │ │ └── Codec2.class └── codec2.jar ├── gen └── com │ └── obteq │ └── android │ └── codec2 │ └── BuildConfig.java ├── ic_launcher-web.png ├── jni ├── Android.mk ├── Application.mk ├── Codec2JNI.cpp └── codec2 │ ├── COPYING │ ├── _kiss_fft_guts.h │ ├── codebook.c │ ├── codebookd.c │ ├── codebookdt.c │ ├── codebookge.c │ ├── codebookjnd.c │ ├── codebookjvm.c │ ├── codebookvq.c │ ├── codebookvqanssi.c │ ├── codec2.c │ ├── codec2.h │ ├── codec2_fdmdv.h │ ├── codec2_internal.h │ ├── comp.c │ ├── comp.h │ ├── defines.h │ ├── dump.c │ ├── dump.h │ ├── fdmdv.c │ ├── fdmdv_internal.h │ ├── glottal.c │ ├── hanning.h │ ├── interp.c │ ├── interp.h │ ├── kiss_fft.c │ ├── kiss_fft.h │ ├── lpc.c │ ├── lpc.h │ ├── lsp.c │ ├── lsp.h │ ├── nlp.c │ ├── nlp.h │ ├── os.h │ ├── pack.c │ ├── phase.c │ ├── phase.h │ ├── pilot_coeff.h │ ├── postfilter.c │ ├── postfilter.h │ ├── quantise.c │ ├── quantise.h │ ├── rn.h │ ├── sine.c │ ├── sine.h │ ├── test_bits.h │ ├── varicode.c │ ├── varicode.h │ └── varicode_table.h ├── proguard-project.txt ├── project.properties └── src └── com └── obteq └── android └── codec2 └── Codec2.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Codec2 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | ?children? 14 | ?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\|| 15 | 16 | 17 | ?name? 18 | 19 | 20 | 21 | org.eclipse.cdt.make.core.append_environment 22 | true 23 | 24 | 25 | org.eclipse.cdt.make.core.buildArguments 26 | 27 | 28 | 29 | org.eclipse.cdt.make.core.buildCommand 30 | ndk-build 31 | 32 | 33 | org.eclipse.cdt.make.core.cleanBuildTarget 34 | clean 35 | 36 | 37 | org.eclipse.cdt.make.core.contents 38 | org.eclipse.cdt.make.core.activeConfigSettings 39 | 40 | 41 | org.eclipse.cdt.make.core.enableAutoBuild 42 | false 43 | 44 | 45 | org.eclipse.cdt.make.core.enableCleanBuild 46 | true 47 | 48 | 49 | org.eclipse.cdt.make.core.enableFullBuild 50 | true 51 | 52 | 53 | org.eclipse.cdt.make.core.stopOnError 54 | true 55 | 56 | 57 | org.eclipse.cdt.make.core.useDefaultBuildCmd 58 | true 59 | 60 | 61 | 62 | 63 | com.android.ide.eclipse.adt.ResourceManagerBuilder 64 | 65 | 66 | 67 | 68 | com.android.ide.eclipse.adt.PreCompilerBuilder 69 | 70 | 71 | 72 | 73 | org.eclipse.jdt.core.javabuilder 74 | 75 | 76 | 77 | 78 | com.android.ide.eclipse.adt.ApkBuilder 79 | 80 | 81 | 82 | 83 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 84 | full,incremental, 85 | 86 | 87 | 88 | 89 | 90 | com.android.ide.eclipse.adt.AndroidNature 91 | org.eclipse.jdt.core.javanature 92 | org.eclipse.cdt.core.cnature 93 | org.eclipse.cdt.core.ccnature 94 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 95 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 96 | 97 | 98 | 99 | jni/include 100 | 2 101 | D:/work/java/android/android-ndk-r9c/platforms/android-19/arch-arm/usr/include 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | codec2-android 2 | ============== 3 | 4 | codec2-android 5 | -------------------------------------------------------------------------------- /bin/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /bin/classes/com/obteq/android/codec2/BuildConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhmedObaidi/codec2-android/ff15c5172568342fb50d299454a8b51566048cd0/bin/classes/com/obteq/android/codec2/BuildConfig.class -------------------------------------------------------------------------------- /bin/classes/com/obteq/android/codec2/Codec2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhmedObaidi/codec2-android/ff15c5172568342fb50d299454a8b51566048cd0/bin/classes/com/obteq/android/codec2/Codec2.class -------------------------------------------------------------------------------- /bin/codec2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhmedObaidi/codec2-android/ff15c5172568342fb50d299454a8b51566048cd0/bin/codec2.jar -------------------------------------------------------------------------------- /gen/com/obteq/android/codec2/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package com.obteq.android.codec2; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhmedObaidi/codec2-android/ff15c5172568342fb50d299454a8b51566048cd0/ic_launcher-web.png -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := codec2 5 | LOCAL_LDLIBS := -llog 6 | LOCAL_CFLAGS := -O3 -ffast-math -DNDEBUG 7 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/codec2 8 | LOCAL_SRC_FILES := codec2/codebook.c codec2/codebookd.c codec2/codebookdt.c \ 9 | codec2/codebookge.c codec2/codebookjnd.c codec2/codebookjvm.c \ 10 | codec2/codebookvqanssi.c codec2/codebookvq.c codec2/codec2.c \ 11 | codec2/comp.c codec2/fdmdv.c codec2/interp.c codec2/kiss_fft.c \ 12 | codec2/lpc.c codec2/lsp.c codec2/nlp.c codec2/pack.c codec2/phase.c \ 13 | codec2/postfilter.c codec2/quantise.c codec2/sine.c codec2/varicode.c \ 14 | Codec2JNI.cpp 15 | include $(BUILD_SHARED_LIBRARY) 16 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-16 2 | APP_ABI := all 3 | -------------------------------------------------------------------------------- /jni/Codec2JNI.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "codec2/codec2_fdmdv.h" 4 | #include "codec2/codec2.h" 5 | #include "codec2/varicode.h" 6 | 7 | namespace com_obteq_android_codec2 { 8 | 9 | struct Context { 10 | struct CODEC2 *c2; 11 | short *buf; 12 | unsigned char *bits; 13 | short samples; 14 | short nbyte; 15 | }; 16 | 17 | static Context* getContext(jlong jp) { 18 | unsigned long p = (unsigned long) jp; 19 | Context *con; 20 | con = (Context*) p; 21 | return con; 22 | } 23 | 24 | static jlong create(JNIEnv *env, jclass clazz, int mode) { 25 | struct Context *con; 26 | con = (struct Context*) malloc(sizeof(struct Context)); 27 | struct CODEC2 *c; 28 | c = codec2_create(mode); 29 | con->c2 = c; 30 | con->samples = codec2_samples_per_frame(c); 31 | con->buf = (short*) malloc(2 * sizeof(short) * con->samples); 32 | int nbit = codec2_bits_per_frame(con->c2); 33 | con->nbyte = (nbit + 7) / 8; 34 | con->bits = (unsigned char*) malloc(con->nbyte * sizeof(char)); 35 | unsigned long pv = (unsigned long) con; 36 | return pv; 37 | } 38 | 39 | static jint c2spf(JNIEnv *env, jclass clazz, jlong n) { 40 | Context *con = getContext(n); 41 | return con->samples; 42 | } 43 | 44 | static jint c2bits(JNIEnv *env, jclass clazz, jlong n) { 45 | Context *con = getContext(n); 46 | return con->nbyte; 47 | } 48 | 49 | static jint destroy(JNIEnv *env, jclass clazz, jlong n) { 50 | Context *con = getContext(n); 51 | codec2_destroy(con->c2); 52 | free(con->bits); 53 | free(con->buf); 54 | free(con); 55 | return 0; 56 | } 57 | 58 | static jlong encode(JNIEnv *env, jclass clazz, jlong n, jshortArray inputBuffer, 59 | jcharArray outputBits) { 60 | Context *con = getContext(n); 61 | int i; 62 | jshort *jbuf = env->GetShortArrayElements(inputBuffer, 0); 63 | for (i = 0; i < con->samples; i++) { 64 | // Downsampling to F/2 65 | short v = (short) jbuf[i * 2]; 66 | con->buf[i] = v; 67 | } 68 | env->ReleaseShortArrayElements(inputBuffer, jbuf, 0); 69 | env->DeleteLocalRef(inputBuffer); 70 | codec2_encode(con->c2, con->bits, con->buf); 71 | jchar *jbits = env->GetCharArrayElements(outputBits, 0); 72 | for (i = 0; i < con->nbyte; i++) { 73 | jbits[i] = con->bits[i]; 74 | } 75 | env->ReleaseCharArrayElements(outputBits, jbits, 0); 76 | env->DeleteLocalRef(outputBits); 77 | return 0; 78 | } 79 | 80 | static jlong decode(JNIEnv *env, jclass clazz, jlong n, jshortArray inputBuffer, 81 | jcharArray outputBits) { 82 | int i; 83 | Context *con = getContext(n); 84 | 85 | jchar *jbits = env->GetCharArrayElements(outputBits, 0); 86 | for (i = 0; i < con->nbyte; i++) { 87 | con->bits[i] = jbits[i]; 88 | } 89 | env->ReleaseCharArrayElements(outputBits, jbits, 0); 90 | env->DeleteLocalRef(outputBits); 91 | 92 | codec2_decode(con->c2, con->buf, con->bits); 93 | 94 | jshort *jbuf = env->GetShortArrayElements(inputBuffer, 0); 95 | for (i = 0; i < con->samples; i++) { 96 | // Upsamling F*2 97 | jbuf[i * 2] = con->buf[i]; 98 | jbuf[i * 2 + 1] = con->buf[i]; 99 | } 100 | env->ReleaseShortArrayElements(inputBuffer, jbuf, 0); 101 | env->DeleteLocalRef(inputBuffer); 102 | return 0; 103 | } 104 | 105 | static JNINativeMethod method_table[] = { { "create", "(I)J", (void *) create }, 106 | { "getSamplesPerFrame", "(J)I", (void *) c2spf }, { "getBitsSize", 107 | "(J)I", (void *) c2bits }, 108 | { "destroy", "(J)I", (void *) destroy }, { "encode", "(J[S[C)J", 109 | (void *) encode }, { "decode", "(J[S[C)J", (void *) decode } }; 110 | 111 | } 112 | 113 | using namespace com_obteq_android_codec2; 114 | 115 | extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) { 116 | JNIEnv* env; 117 | if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { 118 | return JNI_ERR; 119 | } else { 120 | jclass clazz = env->FindClass("com/obteq/android/codec2/Codec2"); 121 | if (clazz) { 122 | jint ret = env->RegisterNatives(clazz, method_table, 123 | sizeof(method_table) / sizeof(method_table[0])); 124 | env->DeleteLocalRef(clazz); 125 | return ret == 0 ? JNI_VERSION_1_6 : JNI_ERR; 126 | } else { 127 | return JNI_ERR; 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /jni/codec2/_kiss_fft_guts.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2003-2010, Mark Borgerding 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | */ 14 | 15 | /* kiss_fft.h 16 | defines kiss_fft_scalar as either short or a float type 17 | and defines 18 | typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ 19 | #include "kiss_fft.h" 20 | #include 21 | 22 | #define MAXFACTORS 32 23 | /* e.g. an fft of length 128 has 4 factors 24 | as far as kissfft is concerned 25 | 4*4*4*2 26 | */ 27 | 28 | struct kiss_fft_state{ 29 | int nfft; 30 | int inverse; 31 | int factors[2*MAXFACTORS]; 32 | kiss_fft_cpx twiddles[1]; 33 | }; 34 | 35 | /* 36 | Explanation of macros dealing with complex math: 37 | 38 | C_MUL(m,a,b) : m = a*b 39 | C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise 40 | C_SUB( res, a,b) : res = a - b 41 | C_SUBFROM( res , a) : res -= a 42 | C_ADDTO( res , a) : res += a 43 | * */ 44 | #ifdef FIXED_POINT 45 | #if (FIXED_POINT==32) 46 | # define FRACBITS 31 47 | # define SAMPPROD int64_t 48 | #define SAMP_MAX 2147483647 49 | #else 50 | # define FRACBITS 15 51 | # define SAMPPROD int32_t 52 | #define SAMP_MAX 32767 53 | #endif 54 | 55 | #define SAMP_MIN -SAMP_MAX 56 | 57 | #if defined(CHECK_OVERFLOW) 58 | # define CHECK_OVERFLOW_OP(a,op,b) \ 59 | if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \ 60 | fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); } 61 | #endif 62 | 63 | 64 | # define smul(a,b) ( (SAMPPROD)(a)*(b) ) 65 | # define sround( x ) (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS ) 66 | 67 | # define S_MUL(a,b) sround( smul(a,b) ) 68 | 69 | # define C_MUL(m,a,b) \ 70 | do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \ 71 | (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0) 72 | 73 | # define DIVSCALAR(x,k) \ 74 | (x) = sround( smul( x, SAMP_MAX/k ) ) 75 | 76 | # define C_FIXDIV(c,div) \ 77 | do { DIVSCALAR( (c).r , div); \ 78 | DIVSCALAR( (c).i , div); }while (0) 79 | 80 | # define C_MULBYSCALAR( c, s ) \ 81 | do{ (c).r = sround( smul( (c).r , s ) ) ;\ 82 | (c).i = sround( smul( (c).i , s ) ) ; }while(0) 83 | 84 | #else /* not FIXED_POINT*/ 85 | 86 | # define S_MUL(a,b) ( (a)*(b) ) 87 | #define C_MUL(m,a,b) \ 88 | do{ (m).r = (a).r*(b).r - (a).i*(b).i;\ 89 | (m).i = (a).r*(b).i + (a).i*(b).r; }while(0) 90 | # define C_FIXDIV(c,div) /* NOOP */ 91 | # define C_MULBYSCALAR( c, s ) \ 92 | do{ (c).r *= (s);\ 93 | (c).i *= (s); }while(0) 94 | #endif 95 | 96 | #ifndef CHECK_OVERFLOW_OP 97 | # define CHECK_OVERFLOW_OP(a,op,b) /* noop */ 98 | #endif 99 | 100 | #define C_ADD( res, a,b)\ 101 | do { \ 102 | CHECK_OVERFLOW_OP((a).r,+,(b).r)\ 103 | CHECK_OVERFLOW_OP((a).i,+,(b).i)\ 104 | (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ 105 | }while(0) 106 | #define C_SUB( res, a,b)\ 107 | do { \ 108 | CHECK_OVERFLOW_OP((a).r,-,(b).r)\ 109 | CHECK_OVERFLOW_OP((a).i,-,(b).i)\ 110 | (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ 111 | }while(0) 112 | #define C_ADDTO( res , a)\ 113 | do { \ 114 | CHECK_OVERFLOW_OP((res).r,+,(a).r)\ 115 | CHECK_OVERFLOW_OP((res).i,+,(a).i)\ 116 | (res).r += (a).r; (res).i += (a).i;\ 117 | }while(0) 118 | 119 | #define C_SUBFROM( res , a)\ 120 | do {\ 121 | CHECK_OVERFLOW_OP((res).r,-,(a).r)\ 122 | CHECK_OVERFLOW_OP((res).i,-,(a).i)\ 123 | (res).r -= (a).r; (res).i -= (a).i; \ 124 | }while(0) 125 | 126 | 127 | #ifdef FIXED_POINT 128 | # define KISS_FFT_COS(phase) floor(.5+SAMP_MAX * cos (phase)) 129 | # define KISS_FFT_SIN(phase) floor(.5+SAMP_MAX * sin (phase)) 130 | # define HALF_OF(x) ((x)>>1) 131 | #elif defined(USE_SIMD) 132 | # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) ) 133 | # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) ) 134 | # define HALF_OF(x) ((x)*_mm_set1_ps(.5)) 135 | #else 136 | # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) 137 | # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) 138 | # define HALF_OF(x) ((x)*.5) 139 | #endif 140 | 141 | #define kf_cexp(x,phase) \ 142 | do{ \ 143 | (x)->r = KISS_FFT_COS(phase);\ 144 | (x)->i = KISS_FFT_SIN(phase);\ 145 | }while(0) 146 | 147 | 148 | /* a debugging function */ 149 | #define pcpx(c)\ 150 | fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) ) 151 | 152 | 153 | #ifdef KISS_FFT_USE_ALLOCA 154 | // define this to allow use of alloca instead of malloc for temporary buffers 155 | // Temporary buffers are used in two case: 156 | // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5 157 | // 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform. 158 | #include 159 | #define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes) 160 | #define KISS_FFT_TMP_FREE(ptr) 161 | #else 162 | #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) 163 | #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) 164 | #endif 165 | -------------------------------------------------------------------------------- /jni/codec2/codebook.c: -------------------------------------------------------------------------------- 1 | /* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */ 2 | 3 | /* 4 | * This intermediary file and the files that used to create it are under 5 | * The LGPL. See the file COPYING. 6 | */ 7 | 8 | #include "defines.h" 9 | 10 | /* codebook/lsp1.txt */ 11 | static const float codes0[] = { 12 | 225, 13 | 250, 14 | 275, 15 | 300, 16 | 325, 17 | 350, 18 | 375, 19 | 400, 20 | 425, 21 | 450, 22 | 475, 23 | 500, 24 | 525, 25 | 550, 26 | 575, 27 | 600 28 | }; 29 | /* codebook/lsp2.txt */ 30 | static const float codes1[] = { 31 | 325, 32 | 350, 33 | 375, 34 | 400, 35 | 425, 36 | 450, 37 | 475, 38 | 500, 39 | 525, 40 | 550, 41 | 575, 42 | 600, 43 | 625, 44 | 650, 45 | 675, 46 | 700 47 | }; 48 | /* codebook/lsp3.txt */ 49 | static const float codes2[] = { 50 | 500, 51 | 550, 52 | 600, 53 | 650, 54 | 700, 55 | 750, 56 | 800, 57 | 850, 58 | 900, 59 | 950, 60 | 1000, 61 | 1050, 62 | 1100, 63 | 1150, 64 | 1200, 65 | 1250 66 | }; 67 | /* codebook/lsp4.txt */ 68 | static const float codes3[] = { 69 | 700, 70 | 800, 71 | 900, 72 | 1000, 73 | 1100, 74 | 1200, 75 | 1300, 76 | 1400, 77 | 1500, 78 | 1600, 79 | 1700, 80 | 1800, 81 | 1900, 82 | 2000, 83 | 2100, 84 | 2200 85 | }; 86 | /* codebook/lsp5.txt */ 87 | static const float codes4[] = { 88 | 950, 89 | 1050, 90 | 1150, 91 | 1250, 92 | 1350, 93 | 1450, 94 | 1550, 95 | 1650, 96 | 1750, 97 | 1850, 98 | 1950, 99 | 2050, 100 | 2150, 101 | 2250, 102 | 2350, 103 | 2450 104 | }; 105 | /* codebook/lsp6.txt */ 106 | static const float codes5[] = { 107 | 1100, 108 | 1200, 109 | 1300, 110 | 1400, 111 | 1500, 112 | 1600, 113 | 1700, 114 | 1800, 115 | 1900, 116 | 2000, 117 | 2100, 118 | 2200, 119 | 2300, 120 | 2400, 121 | 2500, 122 | 2600 123 | }; 124 | /* codebook/lsp7.txt */ 125 | static const float codes6[] = { 126 | 1500, 127 | 1600, 128 | 1700, 129 | 1800, 130 | 1900, 131 | 2000, 132 | 2100, 133 | 2200, 134 | 2300, 135 | 2400, 136 | 2500, 137 | 2600, 138 | 2700, 139 | 2800, 140 | 2900, 141 | 3000 142 | }; 143 | /* codebook/lsp8.txt */ 144 | static const float codes7[] = { 145 | 2300, 146 | 2400, 147 | 2500, 148 | 2600, 149 | 2700, 150 | 2800, 151 | 2900, 152 | 3000 153 | }; 154 | /* codebook/lsp9.txt */ 155 | static const float codes8[] = { 156 | 2500, 157 | 2600, 158 | 2700, 159 | 2800, 160 | 2900, 161 | 3000, 162 | 3100, 163 | 3200 164 | }; 165 | /* codebook/lsp10.txt */ 166 | static const float codes9[] = { 167 | 2900, 168 | 3100, 169 | 3300, 170 | 3500 171 | }; 172 | 173 | const struct lsp_codebook lsp_cb[] = { 174 | /* codebook/lsp1.txt */ 175 | { 176 | 1, 177 | 4, 178 | 16, 179 | codes0 180 | }, 181 | /* codebook/lsp2.txt */ 182 | { 183 | 1, 184 | 4, 185 | 16, 186 | codes1 187 | }, 188 | /* codebook/lsp3.txt */ 189 | { 190 | 1, 191 | 4, 192 | 16, 193 | codes2 194 | }, 195 | /* codebook/lsp4.txt */ 196 | { 197 | 1, 198 | 4, 199 | 16, 200 | codes3 201 | }, 202 | /* codebook/lsp5.txt */ 203 | { 204 | 1, 205 | 4, 206 | 16, 207 | codes4 208 | }, 209 | /* codebook/lsp6.txt */ 210 | { 211 | 1, 212 | 4, 213 | 16, 214 | codes5 215 | }, 216 | /* codebook/lsp7.txt */ 217 | { 218 | 1, 219 | 4, 220 | 16, 221 | codes6 222 | }, 223 | /* codebook/lsp8.txt */ 224 | { 225 | 1, 226 | 3, 227 | 8, 228 | codes7 229 | }, 230 | /* codebook/lsp9.txt */ 231 | { 232 | 1, 233 | 3, 234 | 8, 235 | codes8 236 | }, 237 | /* codebook/lsp10.txt */ 238 | { 239 | 1, 240 | 2, 241 | 4, 242 | codes9 243 | }, 244 | { 0, 0, 0, 0 } 245 | }; 246 | -------------------------------------------------------------------------------- /jni/codec2/codebookd.c: -------------------------------------------------------------------------------- 1 | /* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */ 2 | 3 | /* 4 | * This intermediary file and the files that used to create it are under 5 | * The LGPL. See the file COPYING. 6 | */ 7 | 8 | #include "defines.h" 9 | 10 | /* codebook/dlsp1.txt */ 11 | static const float codes0[] = { 12 | 25, 13 | 50, 14 | 75, 15 | 100, 16 | 125, 17 | 150, 18 | 175, 19 | 200, 20 | 225, 21 | 250, 22 | 275, 23 | 300, 24 | 325, 25 | 350, 26 | 375, 27 | 400, 28 | 425, 29 | 450, 30 | 475, 31 | 500, 32 | 525, 33 | 550, 34 | 575, 35 | 600, 36 | 625, 37 | 650, 38 | 675, 39 | 700, 40 | 725, 41 | 750, 42 | 775, 43 | 800 44 | }; 45 | /* codebook/dlsp2.txt */ 46 | static const float codes1[] = { 47 | 25, 48 | 50, 49 | 75, 50 | 100, 51 | 125, 52 | 150, 53 | 175, 54 | 200, 55 | 225, 56 | 250, 57 | 275, 58 | 300, 59 | 325, 60 | 350, 61 | 375, 62 | 400, 63 | 425, 64 | 450, 65 | 475, 66 | 500, 67 | 525, 68 | 550, 69 | 575, 70 | 600, 71 | 625, 72 | 650, 73 | 675, 74 | 700, 75 | 725, 76 | 750, 77 | 775, 78 | 800 79 | }; 80 | /* codebook/dlsp3.txt */ 81 | static const float codes2[] = { 82 | 25, 83 | 50, 84 | 75, 85 | 100, 86 | 125, 87 | 150, 88 | 175, 89 | 200, 90 | 225, 91 | 250, 92 | 275, 93 | 300, 94 | 325, 95 | 350, 96 | 375, 97 | 400, 98 | 425, 99 | 450, 100 | 475, 101 | 500, 102 | 525, 103 | 550, 104 | 575, 105 | 600, 106 | 625, 107 | 650, 108 | 675, 109 | 700, 110 | 725, 111 | 750, 112 | 775, 113 | 800 114 | }; 115 | /* codebook/dlsp4.txt */ 116 | static const float codes3[] = { 117 | 25, 118 | 50, 119 | 75, 120 | 100, 121 | 125, 122 | 150, 123 | 175, 124 | 200, 125 | 250, 126 | 300, 127 | 350, 128 | 400, 129 | 450, 130 | 500, 131 | 550, 132 | 600, 133 | 650, 134 | 700, 135 | 750, 136 | 800, 137 | 850, 138 | 900, 139 | 950, 140 | 1000, 141 | 1050, 142 | 1100, 143 | 1150, 144 | 1200, 145 | 1250, 146 | 1300, 147 | 1350, 148 | 1400 149 | }; 150 | /* codebook/dlsp5.txt */ 151 | static const float codes4[] = { 152 | 25, 153 | 50, 154 | 75, 155 | 100, 156 | 125, 157 | 150, 158 | 175, 159 | 200, 160 | 250, 161 | 300, 162 | 350, 163 | 400, 164 | 450, 165 | 500, 166 | 550, 167 | 600, 168 | 650, 169 | 700, 170 | 750, 171 | 800, 172 | 850, 173 | 900, 174 | 950, 175 | 1000, 176 | 1050, 177 | 1100, 178 | 1150, 179 | 1200, 180 | 1250, 181 | 1300, 182 | 1350, 183 | 1400 184 | }; 185 | /* codebook/dlsp6.txt */ 186 | static const float codes5[] = { 187 | 25, 188 | 50, 189 | 75, 190 | 100, 191 | 125, 192 | 150, 193 | 175, 194 | 200, 195 | 250, 196 | 300, 197 | 350, 198 | 400, 199 | 450, 200 | 500, 201 | 550, 202 | 600, 203 | 650, 204 | 700, 205 | 750, 206 | 800, 207 | 850, 208 | 900, 209 | 950, 210 | 1000, 211 | 1050, 212 | 1100, 213 | 1150, 214 | 1200, 215 | 1250, 216 | 1300, 217 | 1350, 218 | 1400 219 | }; 220 | /* codebook/dlsp7.txt */ 221 | static const float codes6[] = { 222 | 25, 223 | 50, 224 | 75, 225 | 100, 226 | 125, 227 | 150, 228 | 175, 229 | 200, 230 | 225, 231 | 250, 232 | 275, 233 | 300, 234 | 325, 235 | 350, 236 | 375, 237 | 400, 238 | 425, 239 | 450, 240 | 475, 241 | 500, 242 | 525, 243 | 550, 244 | 575, 245 | 600, 246 | 625, 247 | 650, 248 | 675, 249 | 700, 250 | 725, 251 | 750, 252 | 775, 253 | 800 254 | }; 255 | /* codebook/dlsp8.txt */ 256 | static const float codes7[] = { 257 | 25, 258 | 50, 259 | 75, 260 | 100, 261 | 125, 262 | 150, 263 | 175, 264 | 200, 265 | 225, 266 | 250, 267 | 275, 268 | 300, 269 | 325, 270 | 350, 271 | 375, 272 | 400, 273 | 425, 274 | 450, 275 | 475, 276 | 500, 277 | 525, 278 | 550, 279 | 575, 280 | 600, 281 | 625, 282 | 650, 283 | 675, 284 | 700, 285 | 725, 286 | 750, 287 | 775, 288 | 800 289 | }; 290 | /* codebook/dlsp9.txt */ 291 | static const float codes8[] = { 292 | 25, 293 | 50, 294 | 75, 295 | 100, 296 | 125, 297 | 150, 298 | 175, 299 | 200, 300 | 225, 301 | 250, 302 | 275, 303 | 300, 304 | 325, 305 | 350, 306 | 375, 307 | 400, 308 | 425, 309 | 450, 310 | 475, 311 | 500, 312 | 525, 313 | 550, 314 | 575, 315 | 600, 316 | 625, 317 | 650, 318 | 675, 319 | 700, 320 | 725, 321 | 750, 322 | 775, 323 | 800 324 | }; 325 | /* codebook/dlsp10.txt */ 326 | static const float codes9[] = { 327 | 25, 328 | 50, 329 | 75, 330 | 100, 331 | 125, 332 | 150, 333 | 175, 334 | 200, 335 | 225, 336 | 250, 337 | 275, 338 | 300, 339 | 325, 340 | 350, 341 | 375, 342 | 400, 343 | 425, 344 | 450, 345 | 475, 346 | 500, 347 | 525, 348 | 550, 349 | 575, 350 | 600, 351 | 625, 352 | 650, 353 | 675, 354 | 700, 355 | 725, 356 | 750, 357 | 775, 358 | 800 359 | }; 360 | 361 | const struct lsp_codebook lsp_cbd[] = { 362 | /* codebook/dlsp1.txt */ 363 | { 364 | 1, 365 | 5, 366 | 32, 367 | codes0 368 | }, 369 | /* codebook/dlsp2.txt */ 370 | { 371 | 1, 372 | 5, 373 | 32, 374 | codes1 375 | }, 376 | /* codebook/dlsp3.txt */ 377 | { 378 | 1, 379 | 5, 380 | 32, 381 | codes2 382 | }, 383 | /* codebook/dlsp4.txt */ 384 | { 385 | 1, 386 | 5, 387 | 32, 388 | codes3 389 | }, 390 | /* codebook/dlsp5.txt */ 391 | { 392 | 1, 393 | 5, 394 | 32, 395 | codes4 396 | }, 397 | /* codebook/dlsp6.txt */ 398 | { 399 | 1, 400 | 5, 401 | 32, 402 | codes5 403 | }, 404 | /* codebook/dlsp7.txt */ 405 | { 406 | 1, 407 | 5, 408 | 32, 409 | codes6 410 | }, 411 | /* codebook/dlsp8.txt */ 412 | { 413 | 1, 414 | 5, 415 | 32, 416 | codes7 417 | }, 418 | /* codebook/dlsp9.txt */ 419 | { 420 | 1, 421 | 5, 422 | 32, 423 | codes8 424 | }, 425 | /* codebook/dlsp10.txt */ 426 | { 427 | 1, 428 | 5, 429 | 32, 430 | codes9 431 | }, 432 | { 0, 0, 0, 0 } 433 | }; 434 | -------------------------------------------------------------------------------- /jni/codec2/codebookdt.c: -------------------------------------------------------------------------------- 1 | /* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */ 2 | 3 | /* 4 | * This intermediary file and the files that used to create it are under 5 | * The LGPL. See the file COPYING. 6 | */ 7 | 8 | #include "defines.h" 9 | 10 | /* codebook/lspdt1.txt */ 11 | static const float codes0[] = { 12 | -75, 13 | -50, 14 | -25, 15 | 0, 16 | 25, 17 | 50, 18 | 75, 19 | 100 20 | }; 21 | /* codebook/lspdt2.txt */ 22 | static const float codes1[] = { 23 | -75, 24 | -50, 25 | -25, 26 | 0, 27 | 25, 28 | 50, 29 | 75, 30 | 100 31 | }; 32 | /* codebook/lspdt3.txt */ 33 | static const float codes2[] = { 34 | -50, 35 | 0, 36 | 50, 37 | 100 38 | }; 39 | /* codebook/lspdt4.txt */ 40 | static const float codes3[] = { 41 | -50, 42 | 0, 43 | 50, 44 | 100 45 | }; 46 | /* codebook/lspdt5.txt */ 47 | static const float codes4[] = { 48 | -50, 49 | 0, 50 | 50, 51 | 100 52 | }; 53 | /* codebook/lspdt6.txt */ 54 | static const float codes5[] = { 55 | -50, 56 | 0, 57 | 50, 58 | 100 59 | }; 60 | /* codebook/lspdt7.txt */ 61 | static const float codes6[] = { 62 | -50, 63 | 50 64 | }; 65 | /* codebook/lspdt8.txt */ 66 | static const float codes7[] = { 67 | -50, 68 | 50 69 | }; 70 | /* codebook/lspdt9.txt */ 71 | static const float codes8[] = { 72 | -50, 73 | 50 74 | }; 75 | /* codebook/lspdt10.txt */ 76 | static const float codes9[] = { 77 | -50, 78 | 50 79 | }; 80 | 81 | const struct lsp_codebook lsp_cbdt[] = { 82 | /* codebook/lspdt1.txt */ 83 | { 84 | 1, 85 | 3, 86 | 8, 87 | codes0 88 | }, 89 | /* codebook/lspdt2.txt */ 90 | { 91 | 1, 92 | 3, 93 | 8, 94 | codes1 95 | }, 96 | /* codebook/lspdt3.txt */ 97 | { 98 | 1, 99 | 2, 100 | 4, 101 | codes2 102 | }, 103 | /* codebook/lspdt4.txt */ 104 | { 105 | 1, 106 | 2, 107 | 4, 108 | codes3 109 | }, 110 | /* codebook/lspdt5.txt */ 111 | { 112 | 1, 113 | 2, 114 | 4, 115 | codes4 116 | }, 117 | /* codebook/lspdt6.txt */ 118 | { 119 | 1, 120 | 2, 121 | 4, 122 | codes5 123 | }, 124 | /* codebook/lspdt7.txt */ 125 | { 126 | 1, 127 | 1, 128 | 2, 129 | codes6 130 | }, 131 | /* codebook/lspdt8.txt */ 132 | { 133 | 1, 134 | 1, 135 | 2, 136 | codes7 137 | }, 138 | /* codebook/lspdt9.txt */ 139 | { 140 | 1, 141 | 1, 142 | 2, 143 | codes8 144 | }, 145 | /* codebook/lspdt10.txt */ 146 | { 147 | 1, 148 | 1, 149 | 2, 150 | codes9 151 | }, 152 | { 0, 0, 0, 0 } 153 | }; 154 | -------------------------------------------------------------------------------- /jni/codec2/codebookge.c: -------------------------------------------------------------------------------- 1 | /* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */ 2 | 3 | /* 4 | * This intermediary file and the files that used to create it are under 5 | * The LGPL. See the file COPYING. 6 | */ 7 | 8 | #include "defines.h" 9 | 10 | /* codebook/gecb.txt */ 11 | static const float codes0[] = { 12 | 2.71, 12.0184, 13 | 0.04675, -2.73881, 14 | 0.120993, 8.38895, 15 | -1.58028, -0.892307, 16 | 1.19307, -1.91561, 17 | 0.187101, -3.27679, 18 | 0.332251, -7.66455, 19 | -1.47944, 31.2461, 20 | 1.52761, 27.7095, 21 | -0.524379, 5.25012, 22 | 0.55333, 7.4388, 23 | -0.843451, -1.95299, 24 | 2.26389, 8.61029, 25 | 0.143143, 2.36549, 26 | 0.616506, 1.28427, 27 | -1.71133, 22.0967, 28 | 1.00813, 17.3965, 29 | -0.106718, 1.41891, 30 | -0.136246, 14.2736, 31 | -1.70909, -20.5319, 32 | 1.65787, -3.39107, 33 | 0.138049, -4.95785, 34 | 0.536729, -1.94375, 35 | 0.196307, 36.8519, 36 | 1.27248, 22.5565, 37 | -0.670219, -1.90604, 38 | 0.382092, 6.40113, 39 | -0.756911, -4.90102, 40 | 1.82931, 4.6138, 41 | 0.318794, 0.73683, 42 | 0.612815, -2.07505, 43 | -0.410151, 24.7871, 44 | 1.77602, 13.1909, 45 | 0.106457, -0.104492, 46 | 0.192206, 10.1838, 47 | -1.82442, -7.71565, 48 | 0.931346, 4.34835, 49 | 0.308813, -4.086, 50 | 0.397143, -11.8089, 51 | -0.048715, 41.2273, 52 | 0.877342, 35.8503, 53 | -0.759794, 0.476634, 54 | 0.978593, 7.67467, 55 | -1.19506, 3.03883, 56 | 2.63989, -3.41106, 57 | 0.191127, 3.60351, 58 | 0.402932, 1.0843, 59 | -2.15202, 18.1076, 60 | 1.5468, 8.32271, 61 | -0.143089, -4.07592, 62 | -0.150142, 5.86674, 63 | -1.40844, -3.2507, 64 | 1.56615, -10.4132, 65 | 0.178171, -10.2267, 66 | 0.362164, -0.028556, 67 | -0.070125, 24.3907, 68 | 0.594752, 17.4828, 69 | -0.28698, -6.90407, 70 | 0.464818, 10.2055, 71 | -1.00684, -14.3572, 72 | 2.32957, -3.69161, 73 | 0.335745, 2.40714, 74 | 1.01966, -3.15565, 75 | -1.25945, 7.9919, 76 | 2.38369, 19.6806, 77 | -0.094947, -2.41374, 78 | 0.20933, 6.66477, 79 | -2.22103, 1.37986, 80 | 1.29239, 2.04633, 81 | 0.243626, -0.890741, 82 | 0.428773, -7.19366, 83 | -1.11374, 41.3414, 84 | 2.6098, 31.1405, 85 | -0.446468, 2.53419, 86 | 0.490104, 4.62757, 87 | -1.11723, -3.24174, 88 | 1.79156, 8.41493, 89 | 0.156012, 0.183336, 90 | 0.532447, 3.15455, 91 | -0.764484, 18.514, 92 | 0.952395, 11.7713, 93 | -0.332567, 0.346987, 94 | 0.202165, 14.7168, 95 | -2.12924, -15.559, 96 | 1.35358, -1.92679, 97 | -0.010963, -16.3364, 98 | 0.399053, -2.79057, 99 | 0.750657, 31.1483, 100 | 0.655743, 24.4819, 101 | -0.45321, -0.735879, 102 | 0.2869, 6.5467, 103 | -0.715673, -12.3578, 104 | 1.54849, 3.87217, 105 | 0.271874, 0.802339, 106 | 0.502073, -4.85485, 107 | -0.497037, 17.7619, 108 | 1.19116, 13.9544, 109 | 0.01563, 1.33157, 110 | 0.341867, 8.93537, 111 | -2.31601, -5.39506, 112 | 0.75861, 1.9645, 113 | 0.24132, -3.23769, 114 | 0.267151, -11.2344, 115 | -0.273126, 32.6248, 116 | 1.75352, 40.432, 117 | -0.784011, 3.04576, 118 | 0.705987, 5.66118, 119 | -1.3864, 1.35356, 120 | 2.37646, 1.67485, 121 | 0.242973, 4.73218, 122 | 0.491227, 0.354061, 123 | -1.60676, 8.65895, 124 | 1.16711, 5.9871, 125 | -0.137601, -12.0417, 126 | -0.251375, 10.3972, 127 | -1.43151, -8.90411, 128 | 0.98828, -13.209, 129 | 0.261484, -6.35497, 130 | 0.395932, -0.702529, 131 | 0.283704, 26.8996, 132 | 0.420959, 15.4418, 133 | -0.355804, -13.7278, 134 | 0.527372, 12.3985, 135 | -1.16956, -15.9985, 136 | 1.90669, -5.81605, 137 | 0.354492, 3.85157, 138 | 0.82576, -4.16264, 139 | -0.49019, 13.0572, 140 | 2.25577, 13.5264, 141 | -0.004956, -3.23713, 142 | 0.026709, 7.86645, 143 | -1.81037, -0.451183, 144 | 1.08383, -0.18362, 145 | 0.135836, -2.26658, 146 | 0.375812, -5.51225, 147 | -1.96644, 38.6829, 148 | 1.97799, 24.5655, 149 | -0.704656, 6.35881, 150 | 0.480786, 7.05175, 151 | -0.976417, -2.42273, 152 | 2.50215, 6.75935, 153 | 0.083588, 3.2588, 154 | 0.543629, 0.910013, 155 | -1.23196, 23.0915, 156 | 0.785492, 14.807, 157 | -0.213554, 1.688, 158 | 0.004748, 18.1718, 159 | -1.54719, -16.1168, 160 | 1.50104, -3.28114, 161 | 0.080133, -4.63472, 162 | 0.476592, -2.18093, 163 | 0.44247, 40.304, 164 | 1.07277, 27.592, 165 | -0.594738, -4.16681, 166 | 0.42248, 7.61609, 167 | -0.927521, -7.27441, 168 | 1.99162, 1.29636, 169 | 0.291307, 2.39878, 170 | 0.721081, -1.95062, 171 | -0.804256, 24.9295, 172 | 1.64839, 19.1197, 173 | 0.060852, -0.590639, 174 | 0.266085, 9.10325, 175 | -1.9574, -2.88461, 176 | 1.11693, 2.6724, 177 | 0.35458, -2.74854, 178 | 0.330733, -14.1561, 179 | -0.527851, 39.5756, 180 | 0.991152, 43.195, 181 | -0.589619, 1.26919, 182 | 0.787401, 8.73071, 183 | -1.0138, 1.02507, 184 | 2.8254, 1.89538, 185 | 0.24089, 2.74557, 186 | 0.427195, 2.54446, 187 | -1.95311, 12.244, 188 | 1.44862, 12.0607, 189 | -0.210492, -3.37906, 190 | -0.056713, 10.204, 191 | -1.65237, -5.10274, 192 | 1.29475, -12.2708, 193 | 0.111608, -8.67592, 194 | 0.326634, -1.16763, 195 | 0.021781, 31.1258, 196 | 0.455335, 21.4684, 197 | -0.37544, -3.37121, 198 | 0.39362, 11.302, 199 | -0.851456, -19.4149, 200 | 2.10703, -2.22886, 201 | 0.373233, 1.92406, 202 | 0.884438, -1.72058, 203 | -0.975127, 9.84013, 204 | 2.0033, 17.3954, 205 | -0.036915, -1.11137, 206 | 0.148456, 5.39997, 207 | -1.91441, 4.77382, 208 | 1.44791, 0.537122, 209 | 0.194979, -1.03818, 210 | 0.495771, -9.95502, 211 | -1.05899, 32.9471, 212 | 2.01122, 32.4544, 213 | -0.30965, 4.71911, 214 | 0.436082, 4.63552, 215 | -1.23711, -1.25428, 216 | 2.02274, 9.42834, 217 | 0.190342, 1.46077, 218 | 0.479017, 2.48479, 219 | -1.07848, 16.2217, 220 | 1.20764, 9.65421, 221 | -0.258087, -1.67236, 222 | 0.071852, 13.416, 223 | -1.87723, -16.072, 224 | 1.28957, -4.87118, 225 | 0.067713, -13.4427, 226 | 0.435551, -4.1655, 227 | 0.46614, 30.5895, 228 | 0.904895, 21.598, 229 | -0.518369, -2.53205, 230 | 0.337363, 5.63726, 231 | -0.554975, -17.4005, 232 | 1.69188, 1.14574, 233 | 0.227934, 0.889297, 234 | 0.587303, -5.72973, 235 | -0.262133, 18.6666, 236 | 1.39505, 17.0029, 237 | -0.01909, 4.30838, 238 | 0.304235, 12.6699, 239 | -2.07406, -6.46084, 240 | 0.920546, 1.21296, 241 | 0.284927, -1.78547, 242 | 0.209724, -16.024, 243 | -0.636067, 31.5768, 244 | 1.34989, 34.6775, 245 | -0.971625, 5.30086, 246 | 0.590249, 4.44971, 247 | -1.56787, 3.60239, 248 | 2.1455, 4.51666, 249 | 0.296022, 4.12017, 250 | 0.445299, 0.868772, 251 | -1.44193, 14.1284, 252 | 1.35575, 6.0074, 253 | -0.012814, -7.49657, 254 | -0.43, 8.50012, 255 | -1.20469, -7.11326, 256 | 1.10102, -6.83682, 257 | 0.196463, -6.234, 258 | 0.436747, -1.12979, 259 | 0.141052, 22.8549, 260 | 0.290821, 18.8114, 261 | -0.529536, -7.73251, 262 | 0.63428, 10.7898, 263 | -1.33472, -20.3258, 264 | 1.81564, -1.90332, 265 | 0.394778, 3.79758, 266 | 0.732682, -8.18382, 267 | -0.741244, 11.7683 268 | }; 269 | 270 | const struct lsp_codebook ge_cb[] = { 271 | /* codebook/gecb.txt */ 272 | { 273 | 2, 274 | 8, 275 | 256, 276 | codes0 277 | }, 278 | { 0, 0, 0, 0 } 279 | }; 280 | -------------------------------------------------------------------------------- /jni/codec2/codec2.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: codec2.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 21 August 2010 6 | 7 | Codec 2 fully quantised encoder and decoder functions. If you want use 8 | Codec 2, these are the functions you need to call. 9 | 10 | \*---------------------------------------------------------------------------*/ 11 | 12 | /* 13 | Copyright (C) 2010 David Rowe 14 | 15 | All rights reserved. 16 | 17 | This program is free software; you can redistribute it and/or modify 18 | it under the terms of the GNU Lesser General Public License version 2.1, as 19 | published by the Free Software Foundation. This program is 20 | distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 23 | License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public License 26 | along with this program; if not, see . 27 | */ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifndef __CODEC2__ 34 | #define __CODEC2__ 35 | 36 | /* set up the calling convention for DLL function import/export for 37 | WIN32 cross compiling */ 38 | 39 | #ifdef __CODEC2_WIN32__ 40 | #ifdef __CODEC2_BUILDING_DLL__ 41 | #define CODEC2_WIN32SUPPORT __declspec(dllexport) __stdcall 42 | #else 43 | #define CODEC2_WIN32SUPPORT __declspec(dllimport) __stdcall 44 | #endif 45 | #else 46 | #define CODEC2_WIN32SUPPORT 47 | #endif 48 | 49 | #define CODEC2_MODE_3200 0 50 | #define CODEC2_MODE_2400 1 51 | #define CODEC2_MODE_1400 2 52 | #define CODEC2_MODE_1200 3 53 | 54 | struct CODEC2; 55 | 56 | struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode); 57 | void CODEC2_WIN32SUPPORT codec2_destroy(struct CODEC2 *codec2_state); 58 | void CODEC2_WIN32SUPPORT codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]); 59 | void CODEC2_WIN32SUPPORT codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits); 60 | int CODEC2_WIN32SUPPORT codec2_samples_per_frame(struct CODEC2 *codec2_state); 61 | int CODEC2_WIN32SUPPORT codec2_bits_per_frame(struct CODEC2 *codec2_state); 62 | 63 | void CODEC2_WIN32SUPPORT codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, int bass_boost, float beta, float gamma); 64 | int CODEC2_WIN32SUPPORT codec2_get_spare_bit_index(struct CODEC2 *codec2_state); 65 | int CODEC2_WIN32SUPPORT codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, int unpacked_bits[]); 66 | 67 | #endif 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /jni/codec2/codec2_fdmdv.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: codec2_fdmdv.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: April 14 2012 6 | 7 | A 1400 bit/s Frequency Division Multiplexed Digital Voice (FDMDV) 8 | modem. Used for digital audio over HF SSB. See README_fdmdv.txt for 9 | more information, and fdmdv_mod.c and fdmdv_demod.c for example 10 | usage. 11 | 12 | The name codec2_fdmdv.h is used to make it unique when "make 13 | installed". 14 | 15 | References: 16 | 17 | [1] http://n1su.com/fdmdv/FDMDV_Docs_Rel_1_4b.pdf 18 | 19 | \*---------------------------------------------------------------------------*/ 20 | 21 | /* 22 | Copyright (C) 2012 David Rowe 23 | 24 | All rights reserved. 25 | 26 | This program is free software; you can redistribute it and/or modify 27 | it under the terms of the GNU Lesser General Public License version 2.1, as 28 | published by the Free Software Foundation. This program is 29 | distributed in the hope that it will be useful, but WITHOUT ANY 30 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 31 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 32 | License for more details. 33 | 34 | You should have received a copy of the GNU Lesser General Public License 35 | along with this program; if not, see . 36 | */ 37 | 38 | #ifndef __FDMDV__ 39 | #define __FDMDV__ 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* set up the calling convention for DLL function import/export for 46 | WIN32 cross compiling */ 47 | 48 | #ifdef __CODEC2_WIN32__ 49 | #ifdef __CODEC2_BUILDING_DLL__ 50 | #define CODEC2_WIN32SUPPORT __declspec(dllexport) __stdcall 51 | #else 52 | #define CODEC2_WIN32SUPPORT __declspec(dllimport) __stdcall 53 | #endif 54 | #else 55 | #define CODEC2_WIN32SUPPORT 56 | #endif 57 | 58 | #include "comp.h" 59 | 60 | #define FDMDV_BITS_PER_FRAME 28 /* 20ms frames, 1400 bit/s */ 61 | #define FDMDV_NOM_SAMPLES_PER_FRAME 160 /* modulator output samples/frame and nominal demod samples/frame */ 62 | /* at 8000 Hz sample rate */ 63 | #define FDMDV_MAX_SAMPLES_PER_FRAME 200 /* max demod samples/frame, use this to allocate storage */ 64 | #define FDMDV_SCALE 1000 /* suggested scaling for 16 bit shorts */ 65 | #define FDMDV_NSYM 15 66 | #define FDMDV_FCENTRE 1500 /* Centre frequency, Nc/2 carriers below this, Nc/2 carriers above (Hz) */ 67 | 68 | /* 8 to 48 kHz sample rate conversion */ 69 | 70 | #define FDMDV_OS 6 /* oversampling rate */ 71 | #define FDMDV_OS_TAPS 48 /* number of OS filter taps */ 72 | 73 | /* FFT points */ 74 | 75 | #define FDMDV_NSPEC 512 76 | #define FDMDV_MAX_F_HZ 4000 77 | 78 | /* FDMDV states and stats structures */ 79 | 80 | struct FDMDV; 81 | 82 | struct FDMDV_STATS { 83 | float snr_est; /* estimated SNR of rx signal in dB (3 kHz noise BW) */ 84 | COMP rx_symbols[FDMDV_NSYM]; /* latest received symbols, for scatter plot */ 85 | int fest_coarse_fine; /* freq est state, 0-coarse 1-fine */ 86 | float foff; /* estimated freq offset in Hz */ 87 | float rx_timing; /* estimated optimum timing offset in samples */ 88 | float clock_offset; /* Estimated tx/rx sample clock offset in ppm */ 89 | }; 90 | 91 | struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void); 92 | void CODEC2_WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv_state); 93 | 94 | void CODEC2_WIN32SUPPORT fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync_bit); 95 | void CODEC2_WIN32SUPPORT fdmdv_demod(struct FDMDV *fdmdv_state, int rx_bits[], int *sync_bit, COMP rx_fdm[], int *nin); 96 | 97 | void CODEC2_WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *fdmdv_state, int tx_bits[]); 98 | void CODEC2_WIN32SUPPORT fdmdv_put_test_bits(struct FDMDV *f, int *sync, int *bit_errors, int *ntest_bits, int rx_bits[]); 99 | 100 | void CODEC2_WIN32SUPPORT fdmdv_get_demod_stats(struct FDMDV *fdmdv_state, struct FDMDV_STATS *fdmdv_stats); 101 | void CODEC2_WIN32SUPPORT fdmdv_get_rx_spectrum(struct FDMDV *fdmdv_state, float mag_dB[], COMP rx_fdm[], int nin); 102 | 103 | void CODEC2_WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n); 104 | void CODEC2_WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n); 105 | 106 | void CODEC2_WIN32SUPPORT fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_rect, COMP *foff_phase_rect, int nin); 107 | 108 | /* debug/development function(s) */ 109 | 110 | void CODEC2_WIN32SUPPORT fdmdv_dump_osc_mags(struct FDMDV *f); 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif 117 | 118 | -------------------------------------------------------------------------------- /jni/codec2/codec2_internal.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: codec2_internal.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: April 16 2012 6 | 7 | Header file for Codec2 internal states, exposed via this header 8 | file to assist in testing. 9 | 10 | \*---------------------------------------------------------------------------*/ 11 | 12 | /* 13 | Copyright (C) 2012 David Rowe 14 | 15 | All rights reserved. 16 | 17 | This program is free software; you can redistribute it and/or modify 18 | it under the terms of the GNU Lesser General Public License version 2.1, as 19 | published by the Free Software Foundation. This program is 20 | distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 23 | License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public License 26 | along with this program; if not, see . 27 | */ 28 | 29 | #ifndef __CODEC2_INTERNAL__ 30 | #define __CODEC2_INTERNAL__ 31 | 32 | struct CODEC2 { 33 | int mode; 34 | kiss_fft_cfg fft_fwd_cfg; /* forward FFT config */ 35 | float w[M]; /* time domain hamming window */ 36 | COMP W[FFT_ENC]; /* DFT of w[] */ 37 | float Pn[2*N]; /* trapezoidal synthesis window */ 38 | float Sn[M]; /* input speech */ 39 | float hpf_states[2]; /* high pass filter states */ 40 | void *nlp; /* pitch predictor states */ 41 | 42 | kiss_fft_cfg fft_inv_cfg; /* inverse FFT config */ 43 | float Sn_[2*N]; /* synthesised output speech */ 44 | float ex_phase; /* excitation model phase track */ 45 | float bg_est; /* background noise estimate for post filter */ 46 | float prev_Wo_enc; /* previous frame's pitch estimate */ 47 | MODEL prev_model_dec; /* previous frame's model parameters */ 48 | float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs */ 49 | float prev_e_dec; /* previous frame's LPC energy */ 50 | 51 | int lpc_pf; /* LPC post filter on */ 52 | int bass_boost; /* LPC post filter bass boost */ 53 | float beta; /* LPC post filter parameters */ 54 | float gamma; 55 | 56 | float xq_enc[2]; /* joint pitch and energy VQ states */ 57 | float xq_dec[2]; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /jni/codec2/comp.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: comp.h 4 | AUTHOR......: Markovtsev Vadim 5 | DATE CREATED: 19/11/12 6 | 7 | Complex number routines implementation. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not, see . 26 | */ 27 | 28 | #include "comp.h" 29 | #if defined(__ARM_NEON__) 30 | #include 31 | #endif 32 | #include 33 | 34 | void init_comp_array(COMP *ptr, int size) { 35 | assert(size > 0); 36 | int i; 37 | #if !defined(__ARM_NEON__) 38 | for(i=0; i. 26 | */ 27 | 28 | #ifndef __COMP__ 29 | #define __COMP__ 30 | 31 | /* Complex number */ 32 | 33 | typedef struct { 34 | float real; 35 | float imag; 36 | } COMP; 37 | 38 | void init_comp_array(COMP *ptr, int size); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /jni/codec2/defines.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: defines.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 23/4/93 6 | 7 | Defines and structures used throughout the codec. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not, see . 26 | */ 27 | 28 | #ifndef __DEFINES__ 29 | #define __DEFINES__ 30 | 31 | /*---------------------------------------------------------------------------*\ 32 | 33 | DEFINES 34 | 35 | \*---------------------------------------------------------------------------*/ 36 | 37 | /* General defines */ 38 | 39 | #define N 80 /* number of samples per frame */ 40 | #define MAX_AMP 80 /* maximum number of harmonics */ 41 | #define PI 3.141592654 /* mathematical constant */ 42 | #define TWO_PI 6.283185307 /* mathematical constant */ 43 | #define FS 8000 /* sample rate in Hz */ 44 | #define MAX_STR 256 /* maximum string size */ 45 | 46 | #define NW 279 /* analysis window size */ 47 | #define FFT_ENC 512 /* size of FFT used for encoder */ 48 | #define FFT_DEC 512 /* size of FFT used in decoder */ 49 | #define TW 40 /* Trapezoidal synthesis window overlap */ 50 | #define V_THRESH 6.0 /* voicing threshold in dB */ 51 | #define LPC_MAX 20 /* maximum LPC order */ 52 | #define LPC_ORD 10 /* phase modelling LPC order */ 53 | 54 | /* Pitch estimation defines */ 55 | 56 | #define M 320 /* pitch analysis frame size */ 57 | #define P_MIN 20 /* minimum pitch */ 58 | #define P_MAX 160 /* maximum pitch */ 59 | 60 | /*---------------------------------------------------------------------------*\ 61 | 62 | TYPEDEFS 63 | 64 | \*---------------------------------------------------------------------------*/ 65 | 66 | /* Structure to hold model parameters for one frame */ 67 | 68 | typedef struct { 69 | float Wo; /* fundamental frequency estimate in radians */ 70 | int L; /* number of harmonics */ 71 | float A[MAX_AMP+1]; /* amplitiude of each harmonic */ 72 | float phi[MAX_AMP+1]; /* phase of each harmonic */ 73 | int voiced; /* non-zero if this frame is voiced */ 74 | } MODEL; 75 | 76 | /* describes each codebook */ 77 | 78 | struct lsp_codebook { 79 | int k; /* dimension of vector */ 80 | int log2m; /* number of bits in m */ 81 | int m; /* elements in codebook */ 82 | const float * cb; /* The elements */ 83 | }; 84 | 85 | extern const struct lsp_codebook lsp_cb[]; 86 | extern const struct lsp_codebook lsp_cbd[]; 87 | extern const struct lsp_codebook lsp_cbvq[]; 88 | extern const struct lsp_codebook lsp_cbjnd[]; 89 | extern const struct lsp_codebook lsp_cbdt[]; 90 | extern const struct lsp_codebook lsp_cbjvm[]; 91 | extern const struct lsp_codebook lsp_cbvqanssi[]; 92 | extern const struct lsp_codebook ge_cb[]; 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /jni/codec2/dump.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: dump.c 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 25/8/09 6 | 7 | Routines to dump data to text files for Octave analysis. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | All rights reserved. 13 | 14 | This program is free software; you can redistribute it and/or modify 15 | it under the terms of the GNU Lesser General Public License version 2.1, as 16 | published by the Free Software Foundation. This program is 17 | distributed in the hope that it will be useful, but WITHOUT ANY 18 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public License 23 | along with this program; if not, see . 24 | */ 25 | 26 | #include "defines.h" 27 | #include "comp.h" 28 | #include "dump.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef DUMP 36 | static int dumpon = 0; 37 | 38 | static FILE *fsn = NULL; 39 | static FILE *fsw = NULL; 40 | static FILE *few = NULL; 41 | static FILE *fsw_ = NULL; 42 | static FILE *fmodel = NULL; 43 | static FILE *fqmodel = NULL; 44 | static FILE *fpwb = NULL; 45 | static FILE *fpw = NULL; 46 | static FILE *frw = NULL; 47 | static FILE *flsp = NULL; 48 | static FILE *fweights = NULL; 49 | static FILE *flsp_ = NULL; 50 | static FILE *fphase = NULL; 51 | static FILE *fphase_ = NULL; 52 | static FILE *ffw = NULL; 53 | static FILE *fe = NULL; 54 | static FILE *fsq = NULL; 55 | static FILE *fdec = NULL; 56 | static FILE *fsnr = NULL; 57 | static FILE *flpcsnr = NULL; 58 | static FILE *fak = NULL; 59 | static FILE *fak_ = NULL; 60 | static FILE *fbg = NULL; 61 | static FILE *fE = NULL; 62 | static FILE *frk = NULL; 63 | static FILE *fhephase = NULL; 64 | 65 | static char prefix[MAX_STR]; 66 | 67 | void dump_on(char p[]) { 68 | dumpon = 1; 69 | strcpy(prefix, p); 70 | } 71 | 72 | void dump_off(){ 73 | if (fsn != NULL) 74 | fclose(fsn); 75 | if (fsw != NULL) 76 | fclose(fsw); 77 | if (fsw_ != NULL) 78 | fclose(fsw_); 79 | if (few != NULL) 80 | fclose(few); 81 | if (fmodel != NULL) 82 | fclose(fmodel); 83 | if (fqmodel != NULL) 84 | fclose(fqmodel); 85 | if (fpwb != NULL) 86 | fclose(fpwb); 87 | if (fpw != NULL) 88 | fclose(fpw); 89 | if (frw != NULL) 90 | fclose(frw); 91 | if (flsp != NULL) 92 | fclose(flsp); 93 | if (fweights != NULL) 94 | fclose(fweights); 95 | if (flsp_ != NULL) 96 | fclose(flsp_); 97 | if (fphase != NULL) 98 | fclose(fphase); 99 | if (fphase_ != NULL) 100 | fclose(fphase_); 101 | if (ffw != NULL) 102 | fclose(ffw); 103 | if (fe != NULL) 104 | fclose(fe); 105 | if (fsq != NULL) 106 | fclose(fsq); 107 | if (fdec != NULL) 108 | fclose(fdec); 109 | if (fsnr != NULL) 110 | fclose(fsnr); 111 | if (flpcsnr != NULL) 112 | fclose(flpcsnr); 113 | if (fak != NULL) 114 | fclose(fak); 115 | if (fak_ != NULL) 116 | fclose(fak_); 117 | if (fbg != NULL) 118 | fclose(fbg); 119 | if (fE != NULL) 120 | fclose(fE); 121 | if (frk != NULL) 122 | fclose(frk); 123 | if (fhephase != NULL) 124 | fclose(fhephase); 125 | } 126 | 127 | void dump_Sn(float Sn[]) { 128 | int i; 129 | char s[MAX_STR]; 130 | 131 | if (!dumpon) return; 132 | 133 | if (fsn == NULL) { 134 | sprintf(s,"%s_sn.txt", prefix); 135 | fsn = fopen(s, "wt"); 136 | assert(fsn != NULL); 137 | } 138 | 139 | /* split across two lines to avoid max line length problems */ 140 | /* reconstruct in Octave */ 141 | 142 | for(i=0; iWo, model->L); 217 | for(l=1; l<=model->L; l++) 218 | fprintf(fmodel,"%f\t",model->A[l]); 219 | for(l=model->L+1; lvoiced); 222 | fprintf(fmodel,"\n"); 223 | } 224 | 225 | void dump_quantised_model(MODEL *model) { 226 | int l; 227 | char s[MAX_STR]; 228 | 229 | if (!dumpon) return; 230 | 231 | if (fqmodel == NULL) { 232 | sprintf(s,"%s_qmodel.txt", prefix); 233 | fqmodel = fopen(s, "wt"); 234 | assert(fqmodel != NULL); 235 | } 236 | 237 | fprintf(fqmodel,"%f\t%d\t", model->Wo, model->L); 238 | for(l=1; l<=model->L; l++) 239 | fprintf(fqmodel,"%f\t",model->A[l]); 240 | for(l=model->L+1; l. 24 | */ 25 | 26 | #ifndef __DUMP__ 27 | #define __DUMP__ 28 | 29 | #include "comp.h" 30 | 31 | void dump_on(char filename_prefix[]); 32 | void dump_off(); 33 | 34 | void dump_Sn(float Sn[]); 35 | void dump_Sw(COMP Sw[]); 36 | void dump_Sw_(COMP Sw_[]); 37 | void dump_Ew(COMP Ew[]); 38 | 39 | /* amplitude modelling */ 40 | 41 | void dump_model(MODEL *m); 42 | void dump_quantised_model(MODEL *m); 43 | void dump_Pwn(COMP Pw[]); 44 | void dump_Pw(COMP Pw[]); 45 | void dump_Rw(float Rw[]); 46 | void dump_lsp(float lsp[]); 47 | void dump_weights(float w[], int ndim); 48 | void dump_lsp_(float lsp_[]); 49 | void dump_ak(float ak[], int order); 50 | void dump_ak_(float ak[], int order); 51 | void dump_E(float E); 52 | void dump_lpc_snr(float snr); 53 | 54 | /* phase modelling */ 55 | 56 | void dump_snr(float snr); 57 | void dump_phase(float phase[], int L); 58 | void dump_phase_(float phase[], int L); 59 | void dump_hephase(int ind[], int dim); 60 | 61 | /* NLP states */ 62 | 63 | void dump_sq(float sq[]); 64 | void dump_dec(COMP Fw[]); 65 | void dump_Fw(COMP Fw[]); 66 | void dump_e(float e_hz[]); 67 | void dump_Rk(float Rk[]); 68 | 69 | /* post filter */ 70 | 71 | void dump_bg(float e, float bg_est, float percent_uv); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /jni/codec2/fdmdv_internal.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: fdmdv_internal.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: April 16 2012 6 | 7 | Header file for FDMDV internal functions, exposed via this header 8 | file for testing. 9 | 10 | \*---------------------------------------------------------------------------*/ 11 | 12 | /* 13 | Copyright (C) 2012 David Rowe 14 | 15 | All rights reserved. 16 | 17 | This program is free software; you can redistribute it and/or modify 18 | it under the terms of the GNU Lesser General Public License version 2.1, as 19 | published by the Free Software Foundation. This program is 20 | distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 23 | License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public License 26 | along with this program; if not, see . 27 | */ 28 | 29 | #ifndef __FDMDV_INTERNAL__ 30 | #define __FDMDV_INTERNAL__ 31 | 32 | #include "comp.h" 33 | #include "codec2_fdmdv.h" 34 | #include "kiss_fft.h" 35 | 36 | /*---------------------------------------------------------------------------*\ 37 | 38 | DEFINES 39 | 40 | \*---------------------------------------------------------------------------*/ 41 | 42 | #define PI 3.141592654 43 | #define FS 8000 /* sample rate in Hz */ 44 | #define T (1.0/FS) /* sample period in seconds */ 45 | #define RS 50 /* symbol rate in Hz */ 46 | #define NC 14 /* number of data carriers (plus one pilot in the centre) */ 47 | #define NB 2 /* Bits/symbol for QPSK modulation */ 48 | #define RB (NC*RS*NB) /* bit rate */ 49 | #define M (FS/RS) /* oversampling factor */ 50 | #define NSYM 6 /* number of symbols to filter over */ 51 | #define NFILTER (NSYM*M) /* size of tx/rx filters at sample rate M */ 52 | 53 | #define FSEP 75 /* Separation between carriers (Hz) */ 54 | 55 | #define NT 5 /* number of symbols we estimate timing over */ 56 | #define P 4 /* oversample factor used for initial rx symbol filtering */ 57 | #define NFILTERTIMING (M+NFILTER+M) /* filter memory used for resampling after timing estimation */ 58 | 59 | #define NTEST_BITS (NC*NB*4) /* length of test bit sequence */ 60 | 61 | #define NPILOT_LUT (4*M) /* number of pilot look up table samples */ 62 | #define NPILOTCOEFF 30 /* number of FIR filter coeffs in LP filter */ 63 | #define NPILOTBASEBAND (NPILOTCOEFF+M+M/P) /* number of pilot baseband samples reqd for pilot LPF */ 64 | #define NPILOTLPF (4*M) /* number of samples we DFT pilot over, pilot est window */ 65 | #define MPILOTFFT 256 66 | 67 | /* freq offset sestimation states */ 68 | 69 | #define COARSE 0 70 | #define FINE 1 71 | 72 | /* averaging filter coeffs */ 73 | 74 | #define TRACK_COEFF 0.5 75 | #define SNR_COEFF 0.9 /* SNR est averaging filter coeff */ 76 | 77 | /*---------------------------------------------------------------------------*\ 78 | 79 | STRUCT for States 80 | 81 | \*---------------------------------------------------------------------------*/ 82 | 83 | struct FDMDV { 84 | /* test data (test frame) states */ 85 | 86 | int current_test_bit; 87 | int rx_test_bits_mem[NTEST_BITS]; 88 | 89 | /* Modulator */ 90 | 91 | int tx_pilot_bit; 92 | COMP prev_tx_symbols[NC+1]; 93 | COMP tx_filter_memory[NC+1][NSYM]; 94 | COMP phase_tx[NC+1]; 95 | COMP freq[NC+1]; 96 | 97 | /* Pilot generation at demodulator */ 98 | 99 | COMP pilot_lut[NPILOT_LUT]; 100 | int pilot_lut_index; 101 | int prev_pilot_lut_index; 102 | 103 | /* freq offset estimation states */ 104 | 105 | kiss_fft_cfg fft_pilot_cfg; 106 | COMP pilot_baseband1[NPILOTBASEBAND]; 107 | COMP pilot_baseband2[NPILOTBASEBAND]; 108 | COMP pilot_lpf1[NPILOTLPF]; 109 | COMP pilot_lpf2[NPILOTLPF]; 110 | COMP S1[MPILOTFFT]; 111 | COMP S2[MPILOTFFT]; 112 | 113 | /* freq offset correction states */ 114 | 115 | float foff; 116 | COMP foff_rect; 117 | COMP foff_phase_rect; 118 | 119 | /* Demodulator */ 120 | 121 | COMP phase_rx[NC+1]; 122 | COMP rx_filter_memory[NC+1][NFILTER]; 123 | COMP rx_filter_mem_timing[NC+1][NT*P]; 124 | COMP rx_baseband_mem_timing[NC+1][NFILTERTIMING]; 125 | float rx_timing; 126 | COMP phase_difference[NC+1]; 127 | COMP prev_rx_symbols[NC+1]; 128 | 129 | /* freq est state machine */ 130 | 131 | int fest_state; 132 | int coarse_fine; 133 | 134 | /* SNR estimation states */ 135 | 136 | float sig_est[NC+1]; 137 | float noise_est[NC+1]; 138 | 139 | /* Buf for FFT/waterfall */ 140 | 141 | float fft_buf[2*FDMDV_NSPEC]; 142 | kiss_fft_cfg fft_cfg; 143 | }; 144 | 145 | /*---------------------------------------------------------------------------*\ 146 | 147 | FUNCTION PROTOTYPES 148 | 149 | \*---------------------------------------------------------------------------*/ 150 | 151 | void bits_to_dqpsk_symbols(COMP tx_symbols[], COMP prev_tx_symbols[], int tx_bits[], int *pilot_bit); 152 | void tx_filter(COMP tx_baseband[NC+1][M], COMP tx_symbols[], COMP tx_filter_memory[NC+1][NSYM]); 153 | void fdm_upconvert(COMP tx_fdm[], COMP tx_baseband[NC+1][M], COMP phase_tx[], COMP freq_tx[]); 154 | void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, float *filter_mem, COMP *phase, COMP *freq); 155 | void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq); 156 | float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin); 157 | void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin); 158 | void freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_rect, COMP *foff_phase_rect, int nin); 159 | void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin); 160 | void rx_filter(COMP rx_filt[NC+1][P+1], COMP rx_baseband[NC+1][M+M/P], COMP rx_filter_memory[NC+1][NFILTER], int nin); 161 | float rx_est_timing(COMP rx_symbols[], 162 | COMP rx_filt[NC+1][P+1], 163 | COMP rx_baseband[NC+1][M+M/P], 164 | COMP rx_filter_mem_timing[NC+1][NT*P], 165 | float env[], 166 | COMP rx_baseband_mem_timing[NC+1][NFILTERTIMING], 167 | int nin); 168 | float qpsk_to_bits(int rx_bits[], int *sync_bit, COMP phase_difference[], COMP prev_rx_symbols[], COMP rx_symbols[]); 169 | void snr_update(float sig_est[], float noise_est[], COMP phase_difference[]); 170 | int freq_state(int sync_bit, int *state); 171 | float calc_snr(float sig_est[], float noise_est[]); 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /jni/codec2/glottal.c: -------------------------------------------------------------------------------- 1 | const float glottal[]={ 2 | 0.000000, 3 | -0.057687, 4 | -0.115338, 5 | -0.172917, 6 | -0.230385, 7 | -0.287707, 8 | -0.344845, 9 | -0.401762, 10 | -0.458419, 11 | -0.514781, 12 | -0.570809, 13 | -0.626467, 14 | -0.681721, 15 | -0.736537, 16 | -0.790884, 17 | -0.844733, 18 | -0.898057, 19 | -0.950834, 20 | -1.003044, 21 | -1.054670, 22 | -1.105700, 23 | -1.156124, 24 | -1.205936, 25 | -1.255132, 26 | -1.303711, 27 | -1.351675, 28 | -1.399026, 29 | -1.445769, 30 | -1.491908, 31 | -1.537448, 32 | -1.582393, 33 | -1.626747, 34 | -1.670514, 35 | -1.713693, 36 | -1.756285, 37 | -1.798288, 38 | -1.839697, 39 | -1.880507, 40 | -1.920712, 41 | -1.960302, 42 | -1.999269, 43 | -2.037603, 44 | -2.075295, 45 | -2.112335, 46 | -2.148716, 47 | -2.184430, 48 | -2.219472, 49 | -2.253839, 50 | -2.287531, 51 | -2.320550, 52 | -2.352900, 53 | -2.384588, 54 | -2.415623, 55 | -2.446019, 56 | -2.475788, 57 | -2.504946, 58 | -2.533512, 59 | -2.561501, 60 | -2.588934, 61 | -2.615827, 62 | -2.642198, 63 | -2.668064, 64 | -2.693439, 65 | -2.718337, 66 | -2.742767, 67 | -2.766738, 68 | -2.790256, 69 | -2.813322, 70 | -2.835936, 71 | -2.858094, 72 | -2.879790, 73 | -2.901016, 74 | -2.921759, 75 | -2.942008, 76 | -2.961747, 77 | -2.980961, 78 | -2.999632, 79 | -3.017745, 80 | -3.035282, 81 | -3.052228, 82 | -3.068567, 83 | -3.084285, 84 | -3.099371, 85 | -3.113813, 86 | -3.127605, 87 | -3.140738, 88 | 3.129975, 89 | 3.118167, 90 | 3.107022, 91 | 3.096537, 92 | 3.086709, 93 | 3.077531, 94 | 3.068996, 95 | 3.061096, 96 | 3.053821, 97 | 3.047159, 98 | 3.041102, 99 | 3.035636, 100 | 3.030753, 101 | 3.026441, 102 | 3.022690, 103 | 3.019491, 104 | 3.016836, 105 | 3.014718, 106 | 3.013132, 107 | 3.012072, 108 | 3.011535, 109 | 3.011521, 110 | 3.012028, 111 | 3.013057, 112 | 3.014612, 113 | 3.016695, 114 | 3.019310, 115 | 3.022463, 116 | 3.026160, 117 | 3.030407, 118 | 3.035212, 119 | 3.040580, 120 | 3.046520, 121 | 3.053038, 122 | 3.060141, 123 | 3.067836, 124 | 3.076128, 125 | 3.085023, 126 | 3.094525, 127 | 3.104639, 128 | 3.115367, 129 | 3.126712, 130 | 3.138674, 131 | -3.131930, 132 | -3.118731, 133 | -3.104915, 134 | -3.090485, 135 | -3.075444, 136 | -3.059795, 137 | -3.043543, 138 | -3.026695, 139 | -3.009254, 140 | -2.991229, 141 | -2.972625, 142 | -2.953449, 143 | -2.933710, 144 | -2.913414, 145 | -2.892567, 146 | -2.871176, 147 | -2.849248, 148 | -2.826787, 149 | -2.803798, 150 | -2.780284, 151 | -2.756247, 152 | -2.731689, 153 | -2.706609, 154 | -2.681005, 155 | -2.654875, 156 | -2.628213, 157 | -2.601015, 158 | -2.573272, 159 | -2.544977, 160 | -2.516121, 161 | -2.486694, 162 | -2.456686, 163 | -2.426084, 164 | -2.394879, 165 | -2.363060, 166 | -2.330616, 167 | -2.297538, 168 | -2.263816, 169 | -2.229444, 170 | -2.194416, 171 | -2.158727, 172 | -2.122375, 173 | -2.085359, 174 | -2.047682, 175 | -2.009347, 176 | -1.970361, 177 | -1.930732, 178 | -1.890470, 179 | -1.849587, 180 | -1.808098, 181 | -1.766017, 182 | -1.723360, 183 | -1.680145, 184 | -1.636388, 185 | -1.592105, 186 | -1.547313, 187 | -1.502025, 188 | -1.456256, 189 | -1.410016, 190 | -1.363314, 191 | -1.316157, 192 | -1.268547, 193 | -1.220486, 194 | -1.171971, 195 | -1.122997, 196 | -1.073555, 197 | -1.023636, 198 | -0.973227, 199 | -0.922312, 200 | -0.870875, 201 | -0.818899, 202 | -0.766366, 203 | -0.713257, 204 | -0.659554, 205 | -0.605242, 206 | -0.550303, 207 | -0.494723, 208 | -0.438492, 209 | -0.381598, 210 | -0.324036, 211 | -0.265800, 212 | -0.206889, 213 | -0.147303, 214 | -0.087046, 215 | -0.026121, 216 | 0.035463, 217 | 0.097698, 218 | 0.160576, 219 | 0.224087, 220 | 0.288221, 221 | 0.352969, 222 | 0.418323, 223 | 0.484276, 224 | 0.550822, 225 | 0.617958, 226 | 0.685681, 227 | 0.753991, 228 | 0.822889, 229 | 0.892378, 230 | 0.962462, 231 | 1.033144, 232 | 1.104430, 233 | 1.176325, 234 | 1.248833, 235 | 1.321956, 236 | 1.395696, 237 | 1.470051, 238 | 1.545019, 239 | 1.620593, 240 | 1.696763, 241 | 1.773516, 242 | 1.850837, 243 | 1.928705, 244 | 2.007097, 245 | 2.085987, 246 | 2.165347, 247 | 2.245145, 248 | 2.325347, 249 | 2.405919, 250 | 2.486824, 251 | 2.568025, 252 | 2.649485, 253 | 2.731167, 254 | 2.813033, 255 | 2.895045, 256 | 2.977167, 257 | 3.059362}; 258 | -------------------------------------------------------------------------------- /jni/codec2/hanning.h: -------------------------------------------------------------------------------- 1 | /* Generated by hanning_file() Octave function */ 2 | 3 | const float hanning[]={ 4 | 0, 5 | 2.4171e-05, 6 | 9.66816e-05, 7 | 0.000217525, 8 | 0.000386689, 9 | 0.000604158, 10 | 0.00086991, 11 | 0.00118392, 12 | 0.00154616, 13 | 0.00195659, 14 | 0.00241517, 15 | 0.00292186, 16 | 0.00347661, 17 | 0.00407937, 18 | 0.00473008, 19 | 0.00542867, 20 | 0.00617507, 21 | 0.00696922, 22 | 0.00781104, 23 | 0.00870045, 24 | 0.00963736, 25 | 0.0106217, 26 | 0.0116533, 27 | 0.0127322, 28 | 0.0138581, 29 | 0.0150311, 30 | 0.0162509, 31 | 0.0175175, 32 | 0.0188308, 33 | 0.0201906, 34 | 0.0215968, 35 | 0.0230492, 36 | 0.0245478, 37 | 0.0260923, 38 | 0.0276826, 39 | 0.0293186, 40 | 0.0310001, 41 | 0.032727, 42 | 0.034499, 43 | 0.036316, 44 | 0.0381779, 45 | 0.0400844, 46 | 0.0420354, 47 | 0.0440307, 48 | 0.04607, 49 | 0.0481533, 50 | 0.0502802, 51 | 0.0524506, 52 | 0.0546643, 53 | 0.056921, 54 | 0.0592206, 55 | 0.0615627, 56 | 0.0639473, 57 | 0.0663741, 58 | 0.0688427, 59 | 0.0713531, 60 | 0.0739048, 61 | 0.0764978, 62 | 0.0791318, 63 | 0.0818064, 64 | 0.0845214, 65 | 0.0872767, 66 | 0.0900718, 67 | 0.0929066, 68 | 0.0957807, 69 | 0.0986939, 70 | 0.101646, 71 | 0.104636, 72 | 0.107665, 73 | 0.110732, 74 | 0.113836, 75 | 0.116978, 76 | 0.120156, 77 | 0.123372, 78 | 0.126624, 79 | 0.129912, 80 | 0.133235, 81 | 0.136594, 82 | 0.139989, 83 | 0.143418, 84 | 0.146881, 85 | 0.150379, 86 | 0.153911, 87 | 0.157476, 88 | 0.161074, 89 | 0.164705, 90 | 0.168368, 91 | 0.172063, 92 | 0.17579, 93 | 0.179549, 94 | 0.183338, 95 | 0.187158, 96 | 0.191008, 97 | 0.194888, 98 | 0.198798, 99 | 0.202737, 100 | 0.206704, 101 | 0.2107, 102 | 0.214724, 103 | 0.218775, 104 | 0.222854, 105 | 0.226959, 106 | 0.231091, 107 | 0.235249, 108 | 0.239432, 109 | 0.243641, 110 | 0.247874, 111 | 0.252132, 112 | 0.256414, 113 | 0.260719, 114 | 0.265047, 115 | 0.269398, 116 | 0.273772, 117 | 0.278167, 118 | 0.282584, 119 | 0.287021, 120 | 0.29148, 121 | 0.295958, 122 | 0.300456, 123 | 0.304974, 124 | 0.30951, 125 | 0.314065, 126 | 0.318638, 127 | 0.323228, 128 | 0.327835, 129 | 0.332459, 130 | 0.3371, 131 | 0.341756, 132 | 0.346427, 133 | 0.351113, 134 | 0.355814, 135 | 0.360528, 136 | 0.365256, 137 | 0.369997, 138 | 0.374751, 139 | 0.379516, 140 | 0.384293, 141 | 0.389082, 142 | 0.393881, 143 | 0.398691, 144 | 0.40351, 145 | 0.408338, 146 | 0.413176, 147 | 0.418022, 148 | 0.422876, 149 | 0.427737, 150 | 0.432605, 151 | 0.43748, 152 | 0.44236, 153 | 0.447247, 154 | 0.452138, 155 | 0.457034, 156 | 0.461935, 157 | 0.466839, 158 | 0.471746, 159 | 0.476655, 160 | 0.481568, 161 | 0.486481, 162 | 0.491397, 163 | 0.496313, 164 | 0.501229, 165 | 0.506145, 166 | 0.511061, 167 | 0.515976, 168 | 0.520889, 169 | 0.5258, 170 | 0.530708, 171 | 0.535614, 172 | 0.540516, 173 | 0.545414, 174 | 0.550308, 175 | 0.555197, 176 | 0.560081, 177 | 0.564958, 178 | 0.56983, 179 | 0.574695, 180 | 0.579552, 181 | 0.584402, 182 | 0.589244, 183 | 0.594077, 184 | 0.598901, 185 | 0.603715, 186 | 0.60852, 187 | 0.613314, 188 | 0.618097, 189 | 0.622868, 190 | 0.627628, 191 | 0.632375, 192 | 0.63711, 193 | 0.641831, 194 | 0.646538, 195 | 0.651232, 196 | 0.655911, 197 | 0.660574, 198 | 0.665222, 199 | 0.669855, 200 | 0.67447, 201 | 0.679069, 202 | 0.683651, 203 | 0.688215, 204 | 0.69276, 205 | 0.697287, 206 | 0.701795, 207 | 0.706284, 208 | 0.710752, 209 | 0.7152, 210 | 0.719627, 211 | 0.724033, 212 | 0.728418, 213 | 0.73278, 214 | 0.73712, 215 | 0.741437, 216 | 0.74573, 217 | 0.75, 218 | 0.754246, 219 | 0.758467, 220 | 0.762663, 221 | 0.766833, 222 | 0.770978, 223 | 0.775097, 224 | 0.779189, 225 | 0.783254, 226 | 0.787291, 227 | 0.791301, 228 | 0.795283, 229 | 0.799236, 230 | 0.80316, 231 | 0.807055, 232 | 0.810921, 233 | 0.814756, 234 | 0.81856, 235 | 0.822334, 236 | 0.826077, 237 | 0.829788, 238 | 0.833468, 239 | 0.837115, 240 | 0.840729, 241 | 0.844311, 242 | 0.847859, 243 | 0.851374, 244 | 0.854855, 245 | 0.858301, 246 | 0.861713, 247 | 0.86509, 248 | 0.868431, 249 | 0.871737, 250 | 0.875007, 251 | 0.87824, 252 | 0.881437, 253 | 0.884598, 254 | 0.887721, 255 | 0.890806, 256 | 0.893854, 257 | 0.896864, 258 | 0.899835, 259 | 0.902768, 260 | 0.905661, 261 | 0.908516, 262 | 0.911331, 263 | 0.914106, 264 | 0.916841, 265 | 0.919536, 266 | 0.92219, 267 | 0.924804, 268 | 0.927376, 269 | 0.929907, 270 | 0.932397, 271 | 0.934845, 272 | 0.93725, 273 | 0.939614, 274 | 0.941935, 275 | 0.944213, 276 | 0.946448, 277 | 0.94864, 278 | 0.950789, 279 | 0.952894, 280 | 0.954955, 281 | 0.956972, 282 | 0.958946, 283 | 0.960874, 284 | 0.962759, 285 | 0.964598, 286 | 0.966393, 287 | 0.968142, 288 | 0.969846, 289 | 0.971505, 290 | 0.973118, 291 | 0.974686, 292 | 0.976207, 293 | 0.977683, 294 | 0.979112, 295 | 0.980495, 296 | 0.981832, 297 | 0.983122, 298 | 0.984365, 299 | 0.985561, 300 | 0.986711, 301 | 0.987813, 302 | 0.988868, 303 | 0.989876, 304 | 0.990837, 305 | 0.99175, 306 | 0.992616, 307 | 0.993434, 308 | 0.994204, 309 | 0.994927, 310 | 0.995601, 311 | 0.996228, 312 | 0.996807, 313 | 0.997337, 314 | 0.99782, 315 | 0.998255, 316 | 0.998641, 317 | 0.998979, 318 | 0.999269, 319 | 0.999511, 320 | 0.999704, 321 | 0.999849, 322 | 0.999946, 323 | 0.999994, 324 | 0.999994, 325 | 0.999946, 326 | 0.999849, 327 | 0.999704, 328 | 0.999511, 329 | 0.999269, 330 | 0.998979, 331 | 0.998641, 332 | 0.998255, 333 | 0.99782, 334 | 0.997337, 335 | 0.996807, 336 | 0.996228, 337 | 0.995601, 338 | 0.994927, 339 | 0.994204, 340 | 0.993434, 341 | 0.992616, 342 | 0.99175, 343 | 0.990837, 344 | 0.989876, 345 | 0.988868, 346 | 0.987813, 347 | 0.986711, 348 | 0.985561, 349 | 0.984365, 350 | 0.983122, 351 | 0.981832, 352 | 0.980495, 353 | 0.979112, 354 | 0.977683, 355 | 0.976207, 356 | 0.974686, 357 | 0.973118, 358 | 0.971505, 359 | 0.969846, 360 | 0.968142, 361 | 0.966393, 362 | 0.964598, 363 | 0.962759, 364 | 0.960874, 365 | 0.958946, 366 | 0.956972, 367 | 0.954955, 368 | 0.952894, 369 | 0.950789, 370 | 0.94864, 371 | 0.946448, 372 | 0.944213, 373 | 0.941935, 374 | 0.939614, 375 | 0.93725, 376 | 0.934845, 377 | 0.932397, 378 | 0.929907, 379 | 0.927376, 380 | 0.924804, 381 | 0.92219, 382 | 0.919536, 383 | 0.916841, 384 | 0.914106, 385 | 0.911331, 386 | 0.908516, 387 | 0.905661, 388 | 0.902768, 389 | 0.899835, 390 | 0.896864, 391 | 0.893854, 392 | 0.890806, 393 | 0.887721, 394 | 0.884598, 395 | 0.881437, 396 | 0.87824, 397 | 0.875007, 398 | 0.871737, 399 | 0.868431, 400 | 0.86509, 401 | 0.861713, 402 | 0.858301, 403 | 0.854855, 404 | 0.851374, 405 | 0.847859, 406 | 0.844311, 407 | 0.840729, 408 | 0.837115, 409 | 0.833468, 410 | 0.829788, 411 | 0.826077, 412 | 0.822334, 413 | 0.81856, 414 | 0.814756, 415 | 0.810921, 416 | 0.807055, 417 | 0.80316, 418 | 0.799236, 419 | 0.795283, 420 | 0.791301, 421 | 0.787291, 422 | 0.783254, 423 | 0.779189, 424 | 0.775097, 425 | 0.770978, 426 | 0.766833, 427 | 0.762663, 428 | 0.758467, 429 | 0.754246, 430 | 0.75, 431 | 0.74573, 432 | 0.741437, 433 | 0.73712, 434 | 0.73278, 435 | 0.728418, 436 | 0.724033, 437 | 0.719627, 438 | 0.7152, 439 | 0.710752, 440 | 0.706284, 441 | 0.701795, 442 | 0.697287, 443 | 0.69276, 444 | 0.688215, 445 | 0.683651, 446 | 0.679069, 447 | 0.67447, 448 | 0.669855, 449 | 0.665222, 450 | 0.660574, 451 | 0.655911, 452 | 0.651232, 453 | 0.646538, 454 | 0.641831, 455 | 0.63711, 456 | 0.632375, 457 | 0.627628, 458 | 0.622868, 459 | 0.618097, 460 | 0.613314, 461 | 0.60852, 462 | 0.603715, 463 | 0.598901, 464 | 0.594077, 465 | 0.589244, 466 | 0.584402, 467 | 0.579552, 468 | 0.574695, 469 | 0.56983, 470 | 0.564958, 471 | 0.560081, 472 | 0.555197, 473 | 0.550308, 474 | 0.545414, 475 | 0.540516, 476 | 0.535614, 477 | 0.530708, 478 | 0.5258, 479 | 0.520889, 480 | 0.515976, 481 | 0.511061, 482 | 0.506145, 483 | 0.501229, 484 | 0.496313, 485 | 0.491397, 486 | 0.486481, 487 | 0.481568, 488 | 0.476655, 489 | 0.471746, 490 | 0.466839, 491 | 0.461935, 492 | 0.457034, 493 | 0.452138, 494 | 0.447247, 495 | 0.44236, 496 | 0.43748, 497 | 0.432605, 498 | 0.427737, 499 | 0.422876, 500 | 0.418022, 501 | 0.413176, 502 | 0.408338, 503 | 0.40351, 504 | 0.398691, 505 | 0.393881, 506 | 0.389082, 507 | 0.384293, 508 | 0.379516, 509 | 0.374751, 510 | 0.369997, 511 | 0.365256, 512 | 0.360528, 513 | 0.355814, 514 | 0.351113, 515 | 0.346427, 516 | 0.341756, 517 | 0.3371, 518 | 0.332459, 519 | 0.327835, 520 | 0.323228, 521 | 0.318638, 522 | 0.314065, 523 | 0.30951, 524 | 0.304974, 525 | 0.300456, 526 | 0.295958, 527 | 0.29148, 528 | 0.287021, 529 | 0.282584, 530 | 0.278167, 531 | 0.273772, 532 | 0.269398, 533 | 0.265047, 534 | 0.260719, 535 | 0.256414, 536 | 0.252132, 537 | 0.247874, 538 | 0.243641, 539 | 0.239432, 540 | 0.235249, 541 | 0.231091, 542 | 0.226959, 543 | 0.222854, 544 | 0.218775, 545 | 0.214724, 546 | 0.2107, 547 | 0.206704, 548 | 0.202737, 549 | 0.198798, 550 | 0.194888, 551 | 0.191008, 552 | 0.187158, 553 | 0.183338, 554 | 0.179549, 555 | 0.17579, 556 | 0.172063, 557 | 0.168368, 558 | 0.164705, 559 | 0.161074, 560 | 0.157476, 561 | 0.153911, 562 | 0.150379, 563 | 0.146881, 564 | 0.143418, 565 | 0.139989, 566 | 0.136594, 567 | 0.133235, 568 | 0.129912, 569 | 0.126624, 570 | 0.123372, 571 | 0.120156, 572 | 0.116978, 573 | 0.113836, 574 | 0.110732, 575 | 0.107665, 576 | 0.104636, 577 | 0.101646, 578 | 0.0986939, 579 | 0.0957807, 580 | 0.0929066, 581 | 0.0900718, 582 | 0.0872767, 583 | 0.0845214, 584 | 0.0818064, 585 | 0.0791318, 586 | 0.0764978, 587 | 0.0739048, 588 | 0.0713531, 589 | 0.0688427, 590 | 0.0663741, 591 | 0.0639473, 592 | 0.0615627, 593 | 0.0592206, 594 | 0.056921, 595 | 0.0546643, 596 | 0.0524506, 597 | 0.0502802, 598 | 0.0481533, 599 | 0.04607, 600 | 0.0440307, 601 | 0.0420354, 602 | 0.0400844, 603 | 0.0381779, 604 | 0.036316, 605 | 0.034499, 606 | 0.032727, 607 | 0.0310001, 608 | 0.0293186, 609 | 0.0276826, 610 | 0.0260923, 611 | 0.0245478, 612 | 0.0230492, 613 | 0.0215968, 614 | 0.0201906, 615 | 0.0188308, 616 | 0.0175175, 617 | 0.0162509, 618 | 0.0150311, 619 | 0.0138581, 620 | 0.0127322, 621 | 0.0116533, 622 | 0.0106217, 623 | 0.00963736, 624 | 0.00870045, 625 | 0.00781104, 626 | 0.00696922, 627 | 0.00617507, 628 | 0.00542867, 629 | 0.00473008, 630 | 0.00407937, 631 | 0.00347661, 632 | 0.00292186, 633 | 0.00241517, 634 | 0.00195659, 635 | 0.00154616, 636 | 0.00118392, 637 | 0.00086991, 638 | 0.000604158, 639 | 0.000386689, 640 | 0.000217525, 641 | 9.66816e-05, 642 | 2.4171e-05, 643 | 0 644 | }; 645 | -------------------------------------------------------------------------------- /jni/codec2/interp.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: interp.c 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 9/10/09 6 | 7 | Interpolation of 20ms frames to 10ms frames. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not, see . 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "defines.h" 34 | #include "interp.h" 35 | #include "lsp.h" 36 | #include "quantise.h" 37 | 38 | float sample_log_amp(MODEL *model, float w); 39 | 40 | /*---------------------------------------------------------------------------*\ 41 | 42 | FUNCTION....: interp() 43 | AUTHOR......: David Rowe 44 | DATE CREATED: 22/8/10 45 | 46 | Given two frames decribed by model parameters 20ms apart, determines 47 | the model parameters of the 10ms frame between them. Assumes 48 | voicing is available for middle (interpolated) frame. Outputs are 49 | amplitudes and Wo for the interpolated frame. 50 | 51 | This version can interpolate the amplitudes between two frames of 52 | different Wo and L. 53 | 54 | This version works by log linear interpolation, but listening tests 55 | showed it creates problems in background noise, e.g. hts2a and mmt1. 56 | When this function is used (--dec mode) bg noise appears to be 57 | amplitude modulated, and gets louder. The interp_lsp() function 58 | below seems to do a better job. 59 | 60 | \*---------------------------------------------------------------------------*/ 61 | 62 | void interpolate( 63 | MODEL *interp, /* interpolated model params */ 64 | MODEL *prev, /* previous frames model params */ 65 | MODEL *next /* next frames model params */ 66 | ) 67 | { 68 | int l; 69 | float w,log_amp; 70 | 71 | /* Wo depends on voicing of this and adjacent frames */ 72 | 73 | if (interp->voiced) { 74 | if (prev->voiced && next->voiced) 75 | interp->Wo = (prev->Wo + next->Wo)/2.0; 76 | if (!prev->voiced && next->voiced) 77 | interp->Wo = next->Wo; 78 | if (prev->voiced && !next->voiced) 79 | interp->Wo = prev->Wo; 80 | } 81 | else { 82 | interp->Wo = TWO_PI/P_MAX; 83 | } 84 | interp->L = PI/interp->Wo; 85 | 86 | /* Interpolate amplitudes using linear interpolation in log domain */ 87 | 88 | for(l=1; l<=interp->L; l++) { 89 | w = l*interp->Wo; 90 | log_amp = (sample_log_amp(prev, w) + sample_log_amp(next, w))/2.0; 91 | interp->A[l] = powf(10.0, log_amp); 92 | } 93 | } 94 | 95 | /*---------------------------------------------------------------------------*\ 96 | 97 | FUNCTION....: sample_log_amp() 98 | AUTHOR......: David Rowe 99 | DATE CREATED: 22/8/10 100 | 101 | Samples the amplitude envelope at an arbitrary frequency w. Uses 102 | linear interpolation in the log domain to sample between harmonic 103 | amplitudes. 104 | 105 | \*---------------------------------------------------------------------------*/ 106 | 107 | float sample_log_amp(MODEL *model, float w) 108 | { 109 | int m; 110 | float f, log_amp; 111 | 112 | assert(w > 0.0); assert (w <= PI); 113 | 114 | m = floorf(w/model->Wo + 0.5); 115 | f = (w - m*model->Wo)/w; 116 | assert(f <= 1.0); 117 | 118 | if (m < 1) { 119 | log_amp = f*log10f(model->A[1] + 1E-6); 120 | } 121 | else if ((m+1) > model->L) { 122 | log_amp = (1.0-f)*log10f(model->A[model->L] + 1E-6); 123 | } 124 | else { 125 | log_amp = (1.0-f)*log10f(model->A[m] + 1E-6) + 126 | f*log10f(model->A[m+1] + 1E-6); 127 | } 128 | 129 | return log_amp; 130 | } 131 | 132 | /*---------------------------------------------------------------------------*\ 133 | 134 | FUNCTION....: interp_lsp() 135 | AUTHOR......: David Rowe 136 | DATE CREATED: 10 Nov 2010 137 | 138 | Given two frames decribed by model parameters 20ms apart, determines 139 | the model parameters of the 10ms frame between them. Assumes 140 | voicing is available for middle (interpolated) frame. Outputs are 141 | amplitudes and Wo for the interpolated frame. 142 | 143 | This version uses interpolation of LSPs, seems to do a better job 144 | with bg noise. 145 | 146 | \*---------------------------------------------------------------------------*/ 147 | 148 | void interpolate_lsp( 149 | kiss_fft_cfg fft_fwd_cfg, 150 | MODEL *interp, /* interpolated model params */ 151 | MODEL *prev, /* previous frames model params */ 152 | MODEL *next, /* next frames model params */ 153 | float *prev_lsps, /* previous frames LSPs */ 154 | float prev_e, /* previous frames LPC energy */ 155 | float *next_lsps, /* next frames LSPs */ 156 | float next_e, /* next frames LPC energy */ 157 | float *ak_interp, /* interpolated aks for this frame */ 158 | float *lsps_interp/* interpolated lsps for this frame */ 159 | ) 160 | { 161 | int i; 162 | float e; 163 | float snr; 164 | 165 | /* trap corner case where V est is probably wrong */ 166 | 167 | if (interp->voiced && !prev->voiced && !next->voiced) { 168 | interp->voiced = 0; 169 | } 170 | 171 | /* Wo depends on voicing of this and adjacent frames */ 172 | 173 | if (interp->voiced) { 174 | if (prev->voiced && next->voiced) 175 | interp->Wo = (prev->Wo + next->Wo)/2.0; 176 | if (!prev->voiced && next->voiced) 177 | interp->Wo = next->Wo; 178 | if (prev->voiced && !next->voiced) 179 | interp->Wo = prev->Wo; 180 | } 181 | else { 182 | interp->Wo = TWO_PI/P_MAX; 183 | } 184 | interp->L = PI/interp->Wo; 185 | 186 | //printf(" interp: prev_v: %d next_v: %d prev_Wo: %f next_Wo: %f\n", 187 | // prev->voiced, next->voiced, prev->Wo, next->Wo); 188 | //printf(" interp: Wo: %1.5f L: %d\n", interp->Wo, interp->L); 189 | 190 | /* interpolate LSPs */ 191 | 192 | for(i=0; iA[1]); 206 | } 207 | 208 | 209 | /*---------------------------------------------------------------------------*\ 210 | 211 | FUNCTION....: interp_Wo() 212 | AUTHOR......: David Rowe 213 | DATE CREATED: 22 May 2012 214 | 215 | Interpolates centre 10ms sample of Wo and L samples given two 216 | samples 20ms apart. Assumes voicing is available for centre 217 | (interpolated) frame. 218 | 219 | \*---------------------------------------------------------------------------*/ 220 | 221 | void interp_Wo( 222 | MODEL *interp, /* interpolated model params */ 223 | MODEL *prev, /* previous frames model params */ 224 | MODEL *next /* next frames model params */ 225 | ) 226 | { 227 | /* trap corner case where voicing est is probably wrong */ 228 | 229 | if (interp->voiced && !prev->voiced && !next->voiced) { 230 | interp->voiced = 0; 231 | } 232 | 233 | /* Wo depends on voicing of this and adjacent frames */ 234 | 235 | if (interp->voiced) { 236 | if (prev->voiced && next->voiced) 237 | interp->Wo = (prev->Wo + next->Wo)/2.0; 238 | if (!prev->voiced && next->voiced) 239 | interp->Wo = next->Wo; 240 | if (prev->voiced && !next->voiced) 241 | interp->Wo = prev->Wo; 242 | } 243 | else { 244 | interp->Wo = TWO_PI/P_MAX; 245 | } 246 | interp->L = PI/interp->Wo; 247 | } 248 | 249 | 250 | /*---------------------------------------------------------------------------*\ 251 | 252 | FUNCTION....: interp_energy() 253 | AUTHOR......: David Rowe 254 | DATE CREATED: 22 May 2012 255 | 256 | Interpolates centre 10ms sample of energy given two samples 20ms 257 | apart. 258 | 259 | \*---------------------------------------------------------------------------*/ 260 | 261 | float interp_energy(float prev_e, float next_e) 262 | { 263 | return powf(10.0, (log10f(prev_e) + log10f(next_e))/2.0); 264 | 265 | } 266 | 267 | 268 | /*---------------------------------------------------------------------------*\ 269 | 270 | FUNCTION....: interpolate_lsp_ver2() 271 | AUTHOR......: David Rowe 272 | DATE CREATED: 22 May 2012 273 | 274 | Weighted interpolation of LSPs. 275 | 276 | \*---------------------------------------------------------------------------*/ 277 | 278 | void interpolate_lsp_ver2(float interp[], float prev[], float next[], float weight) 279 | { 280 | int i; 281 | 282 | for(i=0; i. 26 | */ 27 | 28 | #ifndef __INTERP__ 29 | #define __INTERP__ 30 | 31 | #include "kiss_fft.h" 32 | 33 | void interpolate(MODEL *interp, MODEL *prev, MODEL *next); 34 | void interpolate_lsp(kiss_fft_cfg fft_dec_cfg, 35 | MODEL *interp, MODEL *prev, MODEL *next, 36 | float *prev_lsps, float prev_e, 37 | float *next_lsps, float next_e, 38 | float *ak_interp, float *lsps_interp); 39 | void interp_Wo(MODEL *interp, MODEL *prev, MODEL *next); 40 | float interp_energy(float prev, float next); 41 | void interpolate_lsp_ver2(float interp[], float prev[], float next[], float weight); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /jni/codec2/kiss_fft.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2003-2010, Mark Borgerding 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | */ 14 | 15 | 16 | #include "_kiss_fft_guts.h" 17 | /* The guts header contains all the multiplication and addition macros that are defined for 18 | fixed or floating point complex numbers. It also delares the kf_ internal functions. 19 | */ 20 | 21 | static void kf_bfly2( 22 | kiss_fft_cpx * Fout, 23 | const size_t fstride, 24 | const kiss_fft_cfg st, 25 | int m 26 | ) 27 | { 28 | kiss_fft_cpx * Fout2; 29 | kiss_fft_cpx * tw1 = st->twiddles; 30 | kiss_fft_cpx t; 31 | Fout2 = Fout + m; 32 | do{ 33 | C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2); 34 | 35 | C_MUL (t, *Fout2 , *tw1); 36 | tw1 += fstride; 37 | C_SUB( *Fout2 , *Fout , t ); 38 | C_ADDTO( *Fout , t ); 39 | ++Fout2; 40 | ++Fout; 41 | }while (--m); 42 | } 43 | 44 | static void kf_bfly4( 45 | kiss_fft_cpx * Fout, 46 | const size_t fstride, 47 | const kiss_fft_cfg st, 48 | const size_t m 49 | ) 50 | { 51 | kiss_fft_cpx *tw1,*tw2,*tw3; 52 | kiss_fft_cpx scratch[6]; 53 | size_t k=m; 54 | const size_t m2=2*m; 55 | const size_t m3=3*m; 56 | 57 | 58 | tw3 = tw2 = tw1 = st->twiddles; 59 | 60 | do { 61 | C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4); 62 | 63 | C_MUL(scratch[0],Fout[m] , *tw1 ); 64 | C_MUL(scratch[1],Fout[m2] , *tw2 ); 65 | C_MUL(scratch[2],Fout[m3] , *tw3 ); 66 | 67 | C_SUB( scratch[5] , *Fout, scratch[1] ); 68 | C_ADDTO(*Fout, scratch[1]); 69 | C_ADD( scratch[3] , scratch[0] , scratch[2] ); 70 | C_SUB( scratch[4] , scratch[0] , scratch[2] ); 71 | C_SUB( Fout[m2], *Fout, scratch[3] ); 72 | tw1 += fstride; 73 | tw2 += fstride*2; 74 | tw3 += fstride*3; 75 | C_ADDTO( *Fout , scratch[3] ); 76 | 77 | if(st->inverse) { 78 | Fout[m].r = scratch[5].r - scratch[4].i; 79 | Fout[m].i = scratch[5].i + scratch[4].r; 80 | Fout[m3].r = scratch[5].r + scratch[4].i; 81 | Fout[m3].i = scratch[5].i - scratch[4].r; 82 | }else{ 83 | Fout[m].r = scratch[5].r + scratch[4].i; 84 | Fout[m].i = scratch[5].i - scratch[4].r; 85 | Fout[m3].r = scratch[5].r - scratch[4].i; 86 | Fout[m3].i = scratch[5].i + scratch[4].r; 87 | } 88 | ++Fout; 89 | }while(--k); 90 | } 91 | 92 | static void kf_bfly3( 93 | kiss_fft_cpx * Fout, 94 | const size_t fstride, 95 | const kiss_fft_cfg st, 96 | size_t m 97 | ) 98 | { 99 | size_t k=m; 100 | const size_t m2 = 2*m; 101 | kiss_fft_cpx *tw1,*tw2; 102 | kiss_fft_cpx scratch[5]; 103 | kiss_fft_cpx epi3; 104 | epi3 = st->twiddles[fstride*m]; 105 | 106 | tw1=tw2=st->twiddles; 107 | 108 | do{ 109 | C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3); 110 | 111 | C_MUL(scratch[1],Fout[m] , *tw1); 112 | C_MUL(scratch[2],Fout[m2] , *tw2); 113 | 114 | C_ADD(scratch[3],scratch[1],scratch[2]); 115 | C_SUB(scratch[0],scratch[1],scratch[2]); 116 | tw1 += fstride; 117 | tw2 += fstride*2; 118 | 119 | Fout[m].r = Fout->r - HALF_OF(scratch[3].r); 120 | Fout[m].i = Fout->i - HALF_OF(scratch[3].i); 121 | 122 | C_MULBYSCALAR( scratch[0] , epi3.i ); 123 | 124 | C_ADDTO(*Fout,scratch[3]); 125 | 126 | Fout[m2].r = Fout[m].r + scratch[0].i; 127 | Fout[m2].i = Fout[m].i - scratch[0].r; 128 | 129 | Fout[m].r -= scratch[0].i; 130 | Fout[m].i += scratch[0].r; 131 | 132 | ++Fout; 133 | }while(--k); 134 | } 135 | 136 | static void kf_bfly5( 137 | kiss_fft_cpx * Fout, 138 | const size_t fstride, 139 | const kiss_fft_cfg st, 140 | int m 141 | ) 142 | { 143 | kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4; 144 | int u; 145 | kiss_fft_cpx scratch[13]; 146 | kiss_fft_cpx * twiddles = st->twiddles; 147 | kiss_fft_cpx *tw; 148 | kiss_fft_cpx ya,yb; 149 | ya = twiddles[fstride*m]; 150 | yb = twiddles[fstride*2*m]; 151 | 152 | Fout0=Fout; 153 | Fout1=Fout0+m; 154 | Fout2=Fout0+2*m; 155 | Fout3=Fout0+3*m; 156 | Fout4=Fout0+4*m; 157 | 158 | tw=st->twiddles; 159 | for ( u=0; ur += scratch[7].r + scratch[8].r; 174 | Fout0->i += scratch[7].i + scratch[8].i; 175 | 176 | scratch[5].r = scratch[0].r + S_MUL(scratch[7].r,ya.r) + S_MUL(scratch[8].r,yb.r); 177 | scratch[5].i = scratch[0].i + S_MUL(scratch[7].i,ya.r) + S_MUL(scratch[8].i,yb.r); 178 | 179 | scratch[6].r = S_MUL(scratch[10].i,ya.i) + S_MUL(scratch[9].i,yb.i); 180 | scratch[6].i = -S_MUL(scratch[10].r,ya.i) - S_MUL(scratch[9].r,yb.i); 181 | 182 | C_SUB(*Fout1,scratch[5],scratch[6]); 183 | C_ADD(*Fout4,scratch[5],scratch[6]); 184 | 185 | scratch[11].r = scratch[0].r + S_MUL(scratch[7].r,yb.r) + S_MUL(scratch[8].r,ya.r); 186 | scratch[11].i = scratch[0].i + S_MUL(scratch[7].i,yb.r) + S_MUL(scratch[8].i,ya.r); 187 | scratch[12].r = - S_MUL(scratch[10].i,yb.i) + S_MUL(scratch[9].i,ya.i); 188 | scratch[12].i = S_MUL(scratch[10].r,yb.i) - S_MUL(scratch[9].r,ya.i); 189 | 190 | C_ADD(*Fout2,scratch[11],scratch[12]); 191 | C_SUB(*Fout3,scratch[11],scratch[12]); 192 | 193 | ++Fout0;++Fout1;++Fout2;++Fout3;++Fout4; 194 | } 195 | } 196 | 197 | /* perform the butterfly for one stage of a mixed radix FFT */ 198 | static void kf_bfly_generic( 199 | kiss_fft_cpx * Fout, 200 | const size_t fstride, 201 | const kiss_fft_cfg st, 202 | int m, 203 | int p 204 | ) 205 | { 206 | int u,k,q1,q; 207 | kiss_fft_cpx * twiddles = st->twiddles; 208 | kiss_fft_cpx t; 209 | int Norig = st->nfft; 210 | 211 | kiss_fft_cpx * scratch = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC(sizeof(kiss_fft_cpx)*p); 212 | 213 | for ( u=0; u=Norig) twidx-=Norig; 228 | C_MUL(t,scratch[q] , twiddles[twidx] ); 229 | C_ADDTO( Fout[ k ] ,t); 230 | } 231 | k += m; 232 | } 233 | } 234 | KISS_FFT_TMP_FREE(scratch); 235 | } 236 | 237 | static 238 | void kf_work( 239 | kiss_fft_cpx * Fout, 240 | const kiss_fft_cpx * f, 241 | const size_t fstride, 242 | int in_stride, 243 | int * factors, 244 | const kiss_fft_cfg st 245 | ) 246 | { 247 | kiss_fft_cpx * Fout_beg=Fout; 248 | const int p=*factors++; /* the radix */ 249 | const int m=*factors++; /* stage's fft length/p */ 250 | const kiss_fft_cpx * Fout_end = Fout + p*m; 251 | 252 | #ifdef _OPENMP 253 | // use openmp extensions at the 254 | // top-level (not recursive) 255 | if (fstride==1 && p<=5) 256 | { 257 | int k; 258 | 259 | // execute the p different work units in different threads 260 | # pragma omp parallel for 261 | for (k=0;k floor_sqrt) 324 | p = n; /* no more factors, skip to end */ 325 | } 326 | n /= p; 327 | *facbuf++ = p; 328 | *facbuf++ = n; 329 | } while (n > 1); 330 | } 331 | 332 | /* 333 | * 334 | * User-callable function to allocate all necessary storage space for the fft. 335 | * 336 | * The return value is a contiguous block of memory, allocated with malloc. As such, 337 | * It can be freed with free(), rather than a kiss_fft-specific function. 338 | * */ 339 | kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem ) 340 | { 341 | kiss_fft_cfg st=NULL; 342 | size_t memneeded = sizeof(struct kiss_fft_state) 343 | + sizeof(kiss_fft_cpx)*(nfft-1); /* twiddle factors*/ 344 | 345 | if ( lenmem==NULL ) { 346 | st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded ); 347 | }else{ 348 | if (mem != NULL && *lenmem >= memneeded) 349 | st = (kiss_fft_cfg)mem; 350 | *lenmem = memneeded; 351 | } 352 | if (st) { 353 | int i; 354 | st->nfft=nfft; 355 | st->inverse = inverse_fft; 356 | 357 | for (i=0;iinverse) 361 | phase *= -1; 362 | kf_cexp(st->twiddles+i, phase ); 363 | } 364 | 365 | kf_factor(nfft,st->factors); 366 | } 367 | return st; 368 | } 369 | 370 | 371 | void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride) 372 | { 373 | if (fin == fout) { 374 | //NOTE: this is not really an in-place FFT algorithm. 375 | //It just performs an out-of-place FFT into a temp buffer 376 | kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft); 377 | kf_work(tmpbuf,fin,1,in_stride, st->factors,st); 378 | memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft); 379 | KISS_FFT_TMP_FREE(tmpbuf); 380 | }else{ 381 | kf_work( fout, fin, 1,in_stride, st->factors,st ); 382 | } 383 | } 384 | 385 | void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout) 386 | { 387 | kiss_fft_stride(cfg,fin,fout,1); 388 | } 389 | 390 | 391 | void kiss_fft_cleanup(void) 392 | { 393 | // nothing needed any more 394 | } 395 | 396 | int kiss_fft_next_fast_size(int n) 397 | { 398 | while(1) { 399 | int m=n; 400 | while ( (m%2) == 0 ) m/=2; 401 | while ( (m%3) == 0 ) m/=3; 402 | while ( (m%5) == 0 ) m/=5; 403 | if (m<=1) 404 | break; /* n is completely factorable by twos, threes, and fives */ 405 | n++; 406 | } 407 | return n; 408 | } 409 | -------------------------------------------------------------------------------- /jni/codec2/kiss_fft.h: -------------------------------------------------------------------------------- 1 | #ifndef KISS_FFT_H 2 | #define KISS_FFT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* 14 | ATTENTION! 15 | If you would like a : 16 | -- a utility that will handle the caching of fft objects 17 | -- real-only (no imaginary time component ) FFT 18 | -- a multi-dimensional FFT 19 | -- a command-line utility to perform ffts 20 | -- a command-line utility to perform fast-convolution filtering 21 | 22 | Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c 23 | in the tools/ directory. 24 | */ 25 | 26 | #ifdef USE_SIMD 27 | # include 28 | # define kiss_fft_scalar __m128 29 | #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) 30 | #define KISS_FFT_FREE _mm_free 31 | #else 32 | #define KISS_FFT_MALLOC malloc 33 | #define KISS_FFT_FREE free 34 | #endif 35 | 36 | 37 | #ifdef FIXED_POINT 38 | #include 39 | # if (FIXED_POINT == 32) 40 | # define kiss_fft_scalar int32_t 41 | # else 42 | # define kiss_fft_scalar int16_t 43 | # endif 44 | #else 45 | # ifndef kiss_fft_scalar 46 | /* default is float */ 47 | # define kiss_fft_scalar float 48 | # endif 49 | #endif 50 | 51 | typedef struct { 52 | kiss_fft_scalar r; 53 | kiss_fft_scalar i; 54 | }kiss_fft_cpx; 55 | 56 | typedef struct kiss_fft_state* kiss_fft_cfg; 57 | 58 | /* 59 | * kiss_fft_alloc 60 | * 61 | * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 62 | * 63 | * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); 64 | * 65 | * The return value from fft_alloc is a cfg buffer used internally 66 | * by the fft routine or NULL. 67 | * 68 | * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. 69 | * The returned value should be free()d when done to avoid memory leaks. 70 | * 71 | * The state can be placed in a user supplied buffer 'mem': 72 | * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 73 | * then the function places the cfg in mem and the size used in *lenmem 74 | * and returns mem. 75 | * 76 | * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 77 | * then the function returns NULL and places the minimum cfg 78 | * buffer size in *lenmem. 79 | * */ 80 | 81 | kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 82 | 83 | /* 84 | * kiss_fft(cfg,in_out_buf) 85 | * 86 | * Perform an FFT on a complex input buffer. 87 | * for a forward FFT, 88 | * fin should be f[0] , f[1] , ... ,f[nfft-1] 89 | * fout will be F[0] , F[1] , ... ,F[nfft-1] 90 | * Note that each element is complex and can be accessed like 91 | f[k].r and f[k].i 92 | * */ 93 | void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); 94 | 95 | /* 96 | A more generic version of the above function. It reads its input from every Nth sample. 97 | * */ 98 | void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); 99 | 100 | /* If kiss_fft_alloc allocated a buffer, it is one contiguous 101 | buffer and can be simply free()d when no longer needed*/ 102 | #define kiss_fft_free free 103 | 104 | /* 105 | Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 106 | your compiler output to call this before you exit. 107 | */ 108 | void kiss_fft_cleanup(void); 109 | 110 | 111 | /* 112 | * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 113 | */ 114 | int kiss_fft_next_fast_size(int n); 115 | 116 | /* for real ffts, we need an even size */ 117 | #define kiss_fftr_next_fast_size_real(n) \ 118 | (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /jni/codec2/lpc.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: lpc.c 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 30 Sep 1990 (!) 6 | 7 | Linear Prediction functions written in C. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009-2012 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not, see . 26 | */ 27 | 28 | #define LPC_MAX_N 512 /* maximum no. of samples in frame */ 29 | #define PI 3.141592654 /* mathematical constant */ 30 | 31 | #define ALPHA 1.0 32 | #define BETA 0.94 33 | 34 | #include 35 | #include 36 | #include "defines.h" 37 | #include "lpc.h" 38 | 39 | /*---------------------------------------------------------------------------*\ 40 | 41 | pre_emp() 42 | 43 | Pre-emphasise (high pass filter with zero close to 0 Hz) a frame of 44 | speech samples. Helps reduce dynamic range of LPC spectrum, giving 45 | greater weight and hensea better match to low energy formants. 46 | 47 | Should be balanced by de-emphasis of the output speech. 48 | 49 | \*---------------------------------------------------------------------------*/ 50 | 51 | void pre_emp( 52 | float Sn_pre[], /* output frame of speech samples */ 53 | float Sn[], /* input frame of speech samples */ 54 | float *mem, /* Sn[-1]single sample memory */ 55 | int Nsam /* number of speech samples to use */ 56 | ) 57 | { 58 | int i; 59 | 60 | for(i=0; i 1.0) 173 | k[i] = 0.0; 174 | 175 | a[i][i] = k[i]; 176 | 177 | for(j=1; j<=i-1; j++) 178 | a[i][j] = a[i-1][j] + k[i]*a[i-1][i-j]; /* Equation 38c, Makhoul */ 179 | 180 | E[i] = (1-k[i]*k[i])*E[i-1]; /* Equation 38d, Makhoul */ 181 | } 182 | 183 | for(i=1; i<=order; i++) 184 | lpcs[i] = a[order][i]; 185 | lpcs[0] = 1.0; 186 | } 187 | 188 | /*---------------------------------------------------------------------------*\ 189 | 190 | inverse_filter() 191 | 192 | Inverse Filter, A(z). Produces an array of residual samples from an array 193 | of input samples and linear prediction coefficients. 194 | 195 | The filter memory is stored in the first order samples of the input array. 196 | 197 | \*---------------------------------------------------------------------------*/ 198 | 199 | void inverse_filter( 200 | float Sn[], /* Nsam input samples */ 201 | float a[], /* LPCs for this frame of samples */ 202 | int Nsam, /* number of samples */ 203 | float res[], /* Nsam residual samples */ 204 | int order /* order of LPC */ 205 | ) 206 | { 207 | int i,j; /* loop variables */ 208 | 209 | for(i=0; i. 26 | */ 27 | 28 | #ifndef __LPC__ 29 | #define __LPC__ 30 | 31 | #define LPC_MAX_ORDER 20 32 | 33 | void pre_emp(float Sn_pre[], float Sn[], float *mem, int Nsam); 34 | void de_emp(float Sn_se[], float Sn[], float *mem, int Nsam); 35 | void hanning_window(float Sn[], float Wn[], int Nsam); 36 | void autocorrelate(float Sn[], float Rn[], int Nsam, int order); 37 | void levinson_durbin(float R[], float lpcs[], int order); 38 | void inverse_filter(float Sn[], float a[], int Nsam, float res[], int order); 39 | void synthesis_filter(float res[], float a[], int Nsam, int order, float Sn_[]); 40 | void find_aks(float Sn[], float a[], int Nsam, int order, float *E); 41 | void weight(float ak[], float gamma, int order, float akw[]); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /jni/codec2/lsp.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: lsp.c 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 24/2/93 6 | 7 | 8 | This file contains functions for LPC to LSP conversion and LSP to 9 | LPC conversion. Note that the LSP coefficients are not in radians 10 | format but in the x domain of the unit circle. 11 | 12 | \*---------------------------------------------------------------------------*/ 13 | 14 | /* 15 | Copyright (C) 2009 David Rowe 16 | 17 | All rights reserved. 18 | 19 | This program is free software; you can redistribute it and/or modify 20 | it under the terms of the GNU Lesser General Public License version 2.1, as 21 | published by the Free Software Foundation. This program is 22 | distributed in the hope that it will be useful, but WITHOUT ANY 23 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 25 | License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public License 28 | along with this program; if not, see . 29 | */ 30 | 31 | #include "defines.h" 32 | #include "lsp.h" 33 | #include 34 | #include 35 | #include 36 | 37 | /* Only 10 gets used, so far. */ 38 | #define LSP_MAX_ORDER 20 39 | 40 | /*---------------------------------------------------------------------------*\ 41 | 42 | Introduction to Line Spectrum Pairs (LSPs) 43 | ------------------------------------------ 44 | 45 | LSPs are used to encode the LPC filter coefficients {ak} for 46 | transmission over the channel. LSPs have several properties (like 47 | less sensitivity to quantisation noise) that make them superior to 48 | direct quantisation of {ak}. 49 | 50 | A(z) is a polynomial of order lpcrdr with {ak} as the coefficients. 51 | 52 | A(z) is transformed to P(z) and Q(z) (using a substitution and some 53 | algebra), to obtain something like: 54 | 55 | A(z) = 0.5[P(z)(z+z^-1) + Q(z)(z-z^-1)] (1) 56 | 57 | As you can imagine A(z) has complex zeros all over the z-plane. P(z) 58 | and Q(z) have the very neat property of only having zeros _on_ the 59 | unit circle. So to find them we take a test point z=exp(jw) and 60 | evaluate P (exp(jw)) and Q(exp(jw)) using a grid of points between 0 61 | and pi. 62 | 63 | The zeros (roots) of P(z) also happen to alternate, which is why we 64 | swap coefficients as we find roots. So the process of finding the 65 | LSP frequencies is basically finding the roots of 5th order 66 | polynomials. 67 | 68 | The root so P(z) and Q(z) occur in symmetrical pairs at +/-w, hence 69 | the name Line Spectrum Pairs (LSPs). 70 | 71 | To convert back to ak we just evaluate (1), "clocking" an impulse 72 | thru it lpcrdr times gives us the impulse response of A(z) which is 73 | {ak}. 74 | 75 | \*---------------------------------------------------------------------------*/ 76 | 77 | /*---------------------------------------------------------------------------*\ 78 | 79 | FUNCTION....: cheb_poly_eva() 80 | AUTHOR......: David Rowe 81 | DATE CREATED: 24/2/93 82 | 83 | This function evalutes a series of chebyshev polynomials 84 | 85 | FIXME: performing memory allocation at run time is very inefficient, 86 | replace with stack variables of MAX_P size. 87 | 88 | \*---------------------------------------------------------------------------*/ 89 | 90 | 91 | static float 92 | cheb_poly_eva(float *coef,float x,int m) 93 | /* float coef[] coefficients of the polynomial to be evaluated */ 94 | /* float x the point where polynomial is to be evaluated */ 95 | /* int m order of the polynomial */ 96 | { 97 | int i; 98 | float *t,*u,*v,sum; 99 | float T[(LSP_MAX_ORDER / 2) + 1]; 100 | 101 | /* Initialise pointers */ 102 | 103 | t = T; /* T[i-2] */ 104 | *t++ = 1.0; 105 | u = t--; /* T[i-1] */ 106 | *u++ = x; 107 | v = u--; /* T[i] */ 108 | 109 | /* Evaluate chebyshev series formulation using iterative approach */ 110 | 111 | for(i=2;i<=m/2;i++) 112 | *v++ = (2*x)*(*u++) - *t++; /* T[i] = 2*x*T[i-1] - T[i-2] */ 113 | 114 | sum=0.0; /* initialise sum to zero */ 115 | t = T; /* reset pointer */ 116 | 117 | /* Evaluate polynomial and return value also free memory space */ 118 | 119 | for(i=0;i<=m/2;i++) 120 | sum+=coef[(m/2)-i]**t++; 121 | 122 | return sum; 123 | } 124 | 125 | 126 | /*---------------------------------------------------------------------------*\ 127 | 128 | FUNCTION....: lpc_to_lsp() 129 | AUTHOR......: David Rowe 130 | DATE CREATED: 24/2/93 131 | 132 | This function converts LPC coefficients to LSP coefficients. 133 | 134 | \*---------------------------------------------------------------------------*/ 135 | 136 | int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta) 137 | /* float *a lpc coefficients */ 138 | /* int lpcrdr order of LPC coefficients (10) */ 139 | /* float *freq LSP frequencies in radians */ 140 | /* int nb number of sub-intervals (4) */ 141 | /* float delta grid spacing interval (0.02) */ 142 | { 143 | float psuml,psumr,psumm,temp_xr,xl,xr,xm = 0; 144 | float temp_psumr; 145 | int i,j,m,flag,k; 146 | float *px; /* ptrs of respective P'(z) & Q'(z) */ 147 | float *qx; 148 | float *p; 149 | float *q; 150 | float *pt; /* ptr used for cheb_poly_eval() 151 | whether P' or Q' */ 152 | int roots=0; /* number of roots found */ 153 | float Q[LSP_MAX_ORDER + 1]; 154 | float P[LSP_MAX_ORDER + 1]; 155 | 156 | flag = 1; 157 | m = lpcrdr/2; /* order of P'(z) & Q'(z) polynimials */ 158 | 159 | /* Allocate memory space for polynomials */ 160 | 161 | /* determine P'(z)'s and Q'(z)'s coefficients where 162 | P'(z) = P(z)/(1 + z^(-1)) and Q'(z) = Q(z)/(1-z^(-1)) */ 163 | 164 | px = P; /* initilaise ptrs */ 165 | qx = Q; 166 | p = px; 167 | q = qx; 168 | *px++ = 1.0; 169 | *qx++ = 1.0; 170 | for(i=1;i<=m;i++){ 171 | *px++ = a[i]+a[lpcrdr+1-i]-*p++; 172 | *qx++ = a[i]-a[lpcrdr+1-i]+*q++; 173 | } 174 | px = P; 175 | qx = Q; 176 | for(i=0;i= -1.0)){ 201 | xr = xl - delta ; /* interval spacing */ 202 | psumr = cheb_poly_eva(pt,xr,lpcrdr);/* poly(xl-delta_x) */ 203 | temp_psumr = psumr; 204 | temp_xr = xr; 205 | 206 | /* if no sign change increment xr and re-evaluate 207 | poly(xr). Repeat til sign change. if a sign change has 208 | occurred the interval is bisected and then checked again 209 | for a sign change which determines in which interval the 210 | zero lies in. If there is no sign change between poly(xm) 211 | and poly(xl) set interval between xm and xr else set 212 | interval between xl and xr and repeat till root is located 213 | within the specified limits */ 214 | 215 | if((psumr*psuml)<0.0){ 216 | roots++; 217 | 218 | psumm=psuml; 219 | for(k=0;k<=nb;k++){ 220 | xm = (xl+xr)/2; /* bisect the interval */ 221 | psumm=cheb_poly_eva(pt,xm,lpcrdr); 222 | if(psumm*psuml>0.){ 223 | psuml=psumm; 224 | xl=xm; 225 | } 226 | else{ 227 | psumr=psumm; 228 | xr=xm; 229 | } 230 | } 231 | 232 | /* once zero is found, reset initial interval to xr */ 233 | freq[j] = (xm); 234 | xl = xm; 235 | flag = 0; /* reset flag for next search */ 236 | } 237 | else{ 238 | psuml=temp_psumr; 239 | xl=temp_xr; 240 | } 241 | } 242 | } 243 | 244 | /* convert from x domain to radians */ 245 | 246 | for(i=0; i. 29 | */ 30 | 31 | #ifndef __LSP__ 32 | #define __LSP__ 33 | 34 | int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta); 35 | void lsp_to_lpc(float *freq, float *ak, int lpcrdr); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /jni/codec2/nlp.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: nlp.c 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 23/3/93 6 | 7 | Non Linear Pitch (NLP) estimation functions. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not, see . 26 | */ 27 | 28 | #ifndef __NLP__ 29 | #define __NLP__ 30 | 31 | #include "comp.h" 32 | 33 | void *nlp_create(); 34 | void nlp_destroy(void *nlp_state); 35 | float nlp(void *nlp_state, float Sn[], int n, int m, int pmin, int pmax, 36 | float *pitch, COMP Sw[], COMP W[], float *prev_Wo); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /jni/codec2/os.h: -------------------------------------------------------------------------------- 1 | /* Generate using fir1(47,1/6) in Octave */ 2 | 3 | const float fdmdv_os_filter[]= { 4 | -3.55606818e-04, 5 | -8.98615286e-04, 6 | -1.40119781e-03, 7 | -1.71713852e-03, 8 | -1.56471179e-03, 9 | -6.28128960e-04, 10 | 1.24522223e-03, 11 | 3.83138676e-03, 12 | 6.41309478e-03, 13 | 7.85893186e-03, 14 | 6.93514929e-03, 15 | 2.79361991e-03, 16 | -4.51051400e-03, 17 | -1.36671853e-02, 18 | -2.21034939e-02, 19 | -2.64084653e-02, 20 | -2.31425052e-02, 21 | -9.84218694e-03, 22 | 1.40648474e-02, 23 | 4.67316298e-02, 24 | 8.39615986e-02, 25 | 1.19925275e-01, 26 | 1.48381174e-01, 27 | 1.64097819e-01, 28 | 1.64097819e-01, 29 | 1.48381174e-01, 30 | 1.19925275e-01, 31 | 8.39615986e-02, 32 | 4.67316298e-02, 33 | 1.40648474e-02, 34 | -9.84218694e-03, 35 | -2.31425052e-02, 36 | -2.64084653e-02, 37 | -2.21034939e-02, 38 | -1.36671853e-02, 39 | -4.51051400e-03, 40 | 2.79361991e-03, 41 | 6.93514929e-03, 42 | 7.85893186e-03, 43 | 6.41309478e-03, 44 | 3.83138676e-03, 45 | 1.24522223e-03, 46 | -6.28128960e-04, 47 | -1.56471179e-03, 48 | -1.71713852e-03, 49 | -1.40119781e-03, 50 | -8.98615286e-04, 51 | -3.55606818e-04 52 | }; 53 | 54 | -------------------------------------------------------------------------------- /jni/codec2/pack.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 Perens LLC 3 | 4 | All rights reserved. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License version 2.1, as 8 | published by the Free Software Foundation. This program is 9 | distributed in the hope that it will be useful, but WITHOUT ANY 10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 12 | License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program; if not, see . 16 | */ 17 | 18 | #include "defines.h" 19 | #include "quantise.h" 20 | #include 21 | 22 | /* Compile-time constants */ 23 | /* Size of unsigned char in bits. Assumes 8 bits-per-char. */ 24 | static const unsigned int WordSize = 8; 25 | 26 | /* Mask to pick the bit component out of bitIndex. */ 27 | static const unsigned int IndexMask = 0x7; 28 | 29 | /* Used to pick the word component out of bitIndex. */ 30 | static const unsigned int ShiftRight = 3; 31 | 32 | /** Pack a bit field into a bit string, encoding the field in Gray code. 33 | * 34 | * The output is an array of unsigned char data. The fields are efficiently 35 | * packed into the bit string. The Gray coding is a naive attempt to reduce 36 | * the effect of single-bit errors, we expect to do a better job as the 37 | * codec develops. 38 | * 39 | * This code would be simpler if it just set one bit at a time in the string, 40 | * but would hit the same cache line more often. I'm not sure the complexity 41 | * gains us anything here. 42 | * 43 | * Although field is currently of int type rather than unsigned for 44 | * compatibility with the rest of the code, indices are always expected to 45 | * be >= 0. 46 | */ 47 | void 48 | pack( 49 | unsigned char * bitArray, /* The output bit string. */ 50 | unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/ 51 | int field, /* The bit field to be packed. */ 52 | unsigned int fieldWidth/* Width of the field in BITS, not bytes. */ 53 | ) 54 | { 55 | /* Convert the field to Gray code */ 56 | field = (field >> 1) ^ field; 57 | 58 | do { 59 | unsigned int bI = *bitIndex; 60 | unsigned int bitsLeft = WordSize - (bI & IndexMask); 61 | unsigned int sliceWidth = 62 | bitsLeft < fieldWidth ? bitsLeft : fieldWidth; 63 | unsigned int wordIndex = bI >> ShiftRight; 64 | 65 | bitArray[wordIndex] |= 66 | ((unsigned char)((field >> (fieldWidth - sliceWidth)) 67 | << (bitsLeft - sliceWidth))); 68 | 69 | *bitIndex = bI + sliceWidth; 70 | fieldWidth -= sliceWidth; 71 | } while ( fieldWidth != 0 ); 72 | } 73 | 74 | /** Unpack a field from a bit string, converting from Gray code to binary. 75 | * 76 | */ 77 | int 78 | unpack( 79 | const unsigned char * bitArray, /* The input bit string. */ 80 | unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/ 81 | unsigned int fieldWidth/* Width of the field in BITS, not bytes. */ 82 | ) 83 | { 84 | unsigned int field = 0; 85 | unsigned int t; 86 | 87 | do { 88 | unsigned int bI = *bitIndex; 89 | unsigned int bitsLeft = WordSize - (bI & IndexMask); 90 | unsigned int sliceWidth = 91 | bitsLeft < fieldWidth ? bitsLeft : fieldWidth; 92 | 93 | field |= (((bitArray[bI >> ShiftRight] >> (bitsLeft - sliceWidth)) & ((1 << sliceWidth) - 1)) << (fieldWidth - sliceWidth)); 94 | 95 | *bitIndex = bI + sliceWidth; 96 | fieldWidth -= sliceWidth; 97 | } while ( fieldWidth != 0 ); 98 | 99 | /* Convert from Gray code to binary. Works for maximum 8-bit fields. */ 100 | t = field ^ (field >> 8); 101 | t ^= (t >> 4); 102 | t ^= (t >> 2); 103 | t ^= (t >> 1); 104 | return t; 105 | } 106 | -------------------------------------------------------------------------------- /jni/codec2/phase.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: phase.c 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 1/2/09 6 | 7 | Functions for modelling and synthesising phase. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not,see . 26 | */ 27 | 28 | #include "defines.h" 29 | #include "phase.h" 30 | #include "kiss_fft.h" 31 | #include "comp.h" 32 | #include "glottal.c" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #define GLOTTAL_FFT_SIZE 512 41 | 42 | /*---------------------------------------------------------------------------*\ 43 | 44 | aks_to_H() 45 | 46 | Samples the complex LPC synthesis filter spectrum at the harmonic 47 | frequencies. 48 | 49 | \*---------------------------------------------------------------------------*/ 50 | 51 | void aks_to_H( 52 | kiss_fft_cfg fft_fwd_cfg, 53 | MODEL *model, /* model parameters */ 54 | float aks[], /* LPC's */ 55 | float G, /* energy term */ 56 | COMP H[], /* complex LPC spectral samples */ 57 | int order 58 | ) 59 | { 60 | COMP pw[FFT_ENC]; /* power spectrum (input) */ 61 | COMP Pw[FFT_ENC]; /* power spectrum (output) */ 62 | int i,m; /* loop variables */ 63 | int am,bm; /* limits of current band */ 64 | float r; /* no. rads/bin */ 65 | float Em; /* energy in band */ 66 | float Am; /* spectral amplitude sample */ 67 | int b; /* centre bin of harmonic */ 68 | float phi_; /* phase of LPC spectra */ 69 | 70 | r = TWO_PI/(FFT_ENC); 71 | 72 | /* Determine DFT of A(exp(jw)) ------------------------------------------*/ 73 | 74 | init_comp_array(pw, FFT_ENC); 75 | 76 | for(i=0; i<=order; i++) 77 | pw[i].real = aks[i]; 78 | 79 | kiss_fft(fft_fwd_cfg, (kiss_fft_cpx *)pw, (kiss_fft_cpx *)Pw); 80 | 81 | /* Sample magnitude and phase at harmonics */ 82 | 83 | for(m=1; m<=model->L; m++) { 84 | am = floorf((m - 0.5)*model->Wo/r + 0.5); 85 | bm = floorf((m + 0.5)*model->Wo/r + 0.5); 86 | b = floorf(m*model->Wo/r + 0.5); 87 | 88 | Em = 0.0; 89 | for(i=am; iWo)*N/2; 218 | */ 219 | 220 | ex_phase[0] += (model->Wo)*N; 221 | ex_phase[0] -= TWO_PI*floorf(ex_phase[0]/TWO_PI + 0.5); 222 | r = TWO_PI/GLOTTAL_FFT_SIZE; 223 | 224 | for(m=1; m<=model->L; m++) { 225 | 226 | /* generate excitation */ 227 | 228 | if (model->voiced) { 229 | //float rnd; 230 | 231 | b = floorf(m*model->Wo/r + 0.5); 232 | if (b > ((GLOTTAL_FFT_SIZE/2)-1)) { 233 | b = (GLOTTAL_FFT_SIZE/2)-1; 234 | } 235 | 236 | /* I think adding a little jitter helps improve low pitch 237 | males like hts1a. This moves the onset of each harmonic 238 | over +/- 0.25 of a sample. 239 | */ 240 | //jitter = 0.25*(1.0 - 2.0*rand()/RAND_MAX); 241 | jitter = 0; 242 | 243 | //rnd = (PI/8)*(1.0 - 2.0*rand()/RAND_MAX); 244 | Ex[m].real = cosf(ex_phase[0]*m/* - jitter*model->Wo*m + glottal[b]*/); 245 | Ex[m].imag = sinf(ex_phase[0]*m/* - jitter*model->Wo*m + glottal[b]*/); 246 | } 247 | else { 248 | 249 | /* When a few samples were tested I found that LPC filter 250 | phase is not needed in the unvoiced case, but no harm in 251 | keeping it. 252 | */ 253 | float phi = TWO_PI*(float)rand()/RAND_MAX; 254 | Ex[m].real = cosf(phi); 255 | Ex[m].imag = sinf(phi); 256 | } 257 | 258 | /* filter using LPC filter */ 259 | 260 | A_[m].real = H[m].real*Ex[m].real - H[m].imag*Ex[m].imag; 261 | A_[m].imag = H[m].imag*Ex[m].real + H[m].real*Ex[m].imag; 262 | 263 | /* modify sinusoidal phase */ 264 | 265 | new_phi = atan2f(A_[m].imag, A_[m].real+1E-12); 266 | model->phi[m] = new_phi; 267 | } 268 | 269 | } 270 | 271 | -------------------------------------------------------------------------------- /jni/codec2/phase.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: phase.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 1/2/09 6 | 7 | Functions for modelling phase. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not, see . 26 | */ 27 | 28 | #ifndef __PHASE__ 29 | #define __PHASE__ 30 | 31 | #include "kiss_fft.h" 32 | 33 | void phase_synth_zero_order(kiss_fft_cfg fft_dec_cfg, 34 | MODEL *model, 35 | float aks[], 36 | float *ex_phase, 37 | int order); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /jni/codec2/pilot_coeff.h: -------------------------------------------------------------------------------- 1 | /* Generated by pilot_coeff_file() Octave function */ 2 | 3 | const float pilot_coeff[]={ 4 | 0.00204705, 5 | 0.00276339, 6 | 0.00432595, 7 | 0.00697042, 8 | 0.0108452, 9 | 0.0159865, 10 | 0.0223035, 11 | 0.029577, 12 | 0.0374709, 13 | 0.045557, 14 | 0.0533491, 15 | 0.0603458, 16 | 0.0660751, 17 | 0.070138, 18 | 0.0722452, 19 | 0.0722452, 20 | 0.070138, 21 | 0.0660751, 22 | 0.0603458, 23 | 0.0533491, 24 | 0.045557, 25 | 0.0374709, 26 | 0.029577, 27 | 0.0223035, 28 | 0.0159865, 29 | 0.0108452, 30 | 0.00697042, 31 | 0.00432595, 32 | 0.00276339, 33 | 0.00204705 34 | }; 35 | -------------------------------------------------------------------------------- /jni/codec2/postfilter.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: postfilter.c 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 13/09/09 6 | 7 | Postfilter to improve sound quality for speech with high levels of 8 | background noise. Unlike mixed-excitation models requires no bits 9 | to be transmitted to handle background noise. 10 | 11 | \*---------------------------------------------------------------------------*/ 12 | 13 | /* 14 | Copyright (C) 2009 David Rowe 15 | 16 | All rights reserved. 17 | 18 | This program is free software; you can redistribute it and/or modify 19 | it under the terms of the GNU Lesser General Public License version 2.1, as 20 | published by the Free Software Foundation. This program is 21 | distributed in the hope that it will be useful, but WITHOUT ANY 22 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | License for more details. 25 | 26 | You should have received a copy of the GNU Lesser General Public License 27 | along with this program; if not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "defines.h" 36 | #include "comp.h" 37 | #include "dump.h" 38 | #include "postfilter.h" 39 | 40 | /*---------------------------------------------------------------------------*\ 41 | 42 | DEFINES 43 | 44 | \*---------------------------------------------------------------------------*/ 45 | 46 | #define BG_THRESH 40.0 /* only consider low levels signals for bg_est */ 47 | #define BG_BETA 0.1 /* averaging filter constant */ 48 | #define BG_MARGIN 6.0 /* harmonics this far above BG noise are 49 | randomised. Helped make bg noise less 50 | spikey (impulsive) for mmt1, but speech was 51 | perhaps a little rougher. 52 | */ 53 | 54 | /*---------------------------------------------------------------------------*\ 55 | 56 | postfilter() 57 | 58 | The post filter is designed to help with speech corrupted by 59 | background noise. The zero phase model tends to make speech with 60 | background noise sound "clicky". With high levels of background 61 | noise the low level inter-formant parts of the spectrum will contain 62 | noise rather than speech harmonics, so modelling them as voiced 63 | (i.e. a continuous, non-random phase track) is inaccurate. 64 | 65 | Some codecs (like MBE) have a mixed voicing model that breaks the 66 | spectrum into voiced and unvoiced regions. Several bits/frame 67 | (5-12) are required to transmit the frequency selective voicing 68 | information. Mixed excitation also requires accurate voicing 69 | estimation (parameter estimators always break occasionally under 70 | exceptional conditions). 71 | 72 | In our case we use a post filter approach which requires no 73 | additional bits to be transmitted. The decoder measures the average 74 | level of the background noise during unvoiced frames. If a harmonic 75 | is less than this level it is made unvoiced by randomising it's 76 | phases. 77 | 78 | This idea is rather experimental. Some potential problems that may 79 | happen: 80 | 81 | 1/ If someone says "aaaaaaaahhhhhhhhh" will background estimator track 82 | up to speech level? This would be a bad thing. 83 | 84 | 2/ If background noise suddenly dissapears from the source speech does 85 | estimate drop quickly? What is noise suddenly re-appears? 86 | 87 | 3/ Background noise with a non-flat sepctrum. Current algorithm just 88 | comsiders scpetrum as a whole, but this could be broken up into 89 | bands, each with their own estimator. 90 | 91 | 4/ Males and females with the same level of background noise. Check 92 | performance the same. Changing Wo affects width of each band, may 93 | affect bg energy estimates. 94 | 95 | 5/ Not sure what happens during long periods of voiced speech 96 | e.g. "sshhhhhhh" 97 | 98 | \*---------------------------------------------------------------------------*/ 99 | 100 | void postfilter( 101 | MODEL *model, 102 | float *bg_est 103 | ) 104 | { 105 | int m, uv; 106 | float e; 107 | 108 | /* determine average energy across spectrum */ 109 | 110 | e = 0.0; 111 | for(m=1; m<=model->L; m++) 112 | e += model->A[m]*model->A[m]; 113 | 114 | assert(e > 0.0); 115 | e = 10.0*log10f(e/model->L); 116 | 117 | /* If beneath threhold, update bg estimate. The idea 118 | of the threshold is to prevent updating during high level 119 | speech. */ 120 | 121 | if ((e < BG_THRESH) && !model->voiced) 122 | *bg_est = *bg_est*(1.0 - BG_BETA) + e*BG_BETA; 123 | 124 | /* now mess with phases during voiced frames to make any harmonics 125 | less then our background estimate unvoiced. 126 | */ 127 | 128 | uv = 0; 129 | if (model->voiced) 130 | for(m=1; m<=model->L; m++) 131 | if (20.0*log10f(model->A[m]) < (*bg_est + BG_MARGIN)) { 132 | model->phi[m] = TWO_PI*(float)rand()/RAND_MAX; 133 | uv++; 134 | } 135 | 136 | #ifdef DUMP 137 | dump_bg(e, *bg_est, 100.0*uv/model->L); 138 | #endif 139 | 140 | } 141 | -------------------------------------------------------------------------------- /jni/codec2/postfilter.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: postfilter.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 13/09/09 6 | 7 | Postfilter header file. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | Copyright (C) 2009 David Rowe 13 | 14 | All rights reserved. 15 | 16 | This program is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU Lesser General Public License version 2.1, as 18 | published by the Free Software Foundation. This program is 19 | distributed in the hope that it will be useful, but WITHOUT ANY 20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | along with this program; if not, see . 26 | */ 27 | 28 | #ifndef __POSTFILTER__ 29 | #define __POSTFILTER__ 30 | 31 | void postfilter(MODEL *model, float *bg_est); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /jni/codec2/quantise.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | 3 | FILE........: quantise.h 4 | AUTHOR......: David Rowe 5 | DATE CREATED: 31/5/92 6 | 7 | Quantisation functions for the sinusoidal coder. 8 | 9 | \*---------------------------------------------------------------------------*/ 10 | 11 | /* 12 | All rights reserved. 13 | 14 | This program is free software; you can redistribute it and/or modify 15 | it under the terms of the GNU Lesser General Public License version 2.1, as 16 | published by the Free Software Foundation. This program is 17 | distributed in the hope that it will be useful, but WITHOUT ANY 18 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public License 23 | along with this program; if not, see . 24 | */ 25 | 26 | #ifndef __QUANTISE__ 27 | #define __QUANTISE__ 28 | 29 | #include "kiss_fft.h" 30 | 31 | #define WO_BITS 7 32 | #define WO_LEVELS (1<. 26 | */ 27 | 28 | #ifndef __SINE__ 29 | #define __SINE__ 30 | 31 | #include "defines.h" 32 | #include "comp.h" 33 | #include "kiss_fft.h" 34 | 35 | void make_analysis_window(kiss_fft_cfg fft_fwd_cfg, float w[], COMP W[]); 36 | float hpf(float x, float states[]); 37 | void dft_speech(kiss_fft_cfg fft_fwd_cfg, COMP Sw[], float Sn[], float w[]); 38 | void two_stage_pitch_refinement(MODEL *model, COMP Sw[]); 39 | void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[]); 40 | float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[], 41 | float prev_Wo); 42 | void make_synthesis_window(float Pn[]); 43 | void synthesise(kiss_fft_cfg fft_inv_cfg, float Sn_[], MODEL *model, float Pn[], int shift); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /jni/codec2/test_bits.h: -------------------------------------------------------------------------------- 1 | /* Generated by test_bits_file() Octave function */ 2 | 3 | const int test_bits[]={ 4 | 0, 5 | 1, 6 | 1, 7 | 0, 8 | 0, 9 | 0, 10 | 1, 11 | 1, 12 | 0, 13 | 0, 14 | 1, 15 | 0, 16 | 1, 17 | 0, 18 | 0, 19 | 1, 20 | 0, 21 | 1, 22 | 1, 23 | 0, 24 | 0, 25 | 1, 26 | 1, 27 | 0, 28 | 0, 29 | 0, 30 | 0, 31 | 0, 32 | 0, 33 | 0, 34 | 0, 35 | 0, 36 | 0, 37 | 0, 38 | 0, 39 | 0, 40 | 1, 41 | 1, 42 | 1, 43 | 0, 44 | 1, 45 | 1, 46 | 0, 47 | 0, 48 | 1, 49 | 1, 50 | 1, 51 | 0, 52 | 1, 53 | 1, 54 | 0, 55 | 1, 56 | 1, 57 | 1, 58 | 1, 59 | 1, 60 | 0, 61 | 0, 62 | 1, 63 | 0, 64 | 0, 65 | 1, 66 | 1, 67 | 1, 68 | 0, 69 | 0, 70 | 1, 71 | 1, 72 | 1, 73 | 0, 74 | 0, 75 | 0, 76 | 0, 77 | 1, 78 | 1, 79 | 1, 80 | 0, 81 | 0, 82 | 1, 83 | 1, 84 | 1, 85 | 1, 86 | 1, 87 | 0, 88 | 1, 89 | 1, 90 | 1, 91 | 0, 92 | 0, 93 | 1, 94 | 1, 95 | 0, 96 | 1, 97 | 1, 98 | 1, 99 | 1, 100 | 1, 101 | 1, 102 | 1, 103 | 0, 104 | 0, 105 | 1, 106 | 1, 107 | 0, 108 | 1, 109 | 0, 110 | 0, 111 | 0, 112 | 1, 113 | 1, 114 | 1, 115 | 0 116 | }; 117 | -------------------------------------------------------------------------------- /jni/codec2/varicode.c: -------------------------------------------------------------------------------- 1 | //========================================================================== 2 | // Name: varicode.h 3 | // Purpose: Varicode encoded and decode functions 4 | // Created: Nov 24, 2012 5 | // Authors: David Rowe 6 | // 7 | // To test: 8 | // $ gcc varicode.c -o varicode -DVARICODE_UNITTEST -Wall 9 | // $ ./varicode 10 | // 11 | // License: 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License version 2.1, 15 | // as published by the Free Software Foundation. This program is 16 | // distributed in the hope that it will be useful, but WITHOUT ANY 17 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | // License for more details. 20 | // 21 | // You should have received a copy of the GNU General Public License 22 | // along with this program; if not, see . 23 | // 24 | //========================================================================== 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "varicode.h" 31 | #include "varicode_table.h" 32 | 33 | 34 | /* 35 | output is an unpacked array of bits of maximum size max_out. Note 36 | unpacked arrays are a more suitable form for modulator input. 37 | */ 38 | 39 | int varicode_encode(short varicode_out[], char ascii_in[], int max_out, int n_in) { 40 | int n_out, index, n_zeros, v_len; 41 | unsigned short byte1, byte2, packed; 42 | 43 | n_out = 0; 44 | 45 | while(n_in && (n_out < max_out)) { 46 | 47 | assert((unsigned int)(*ascii_in) < 128); 48 | 49 | index = 2*(unsigned int)(*ascii_in); 50 | byte1 = varicode_table[index]; 51 | byte2 = varicode_table[index+1]; 52 | packed = (byte1 << 8) + byte2; 53 | //printf("n_in: %d ascii_in: %c index: %d packed 0x%x\n", n_in, *ascii_in, index, packed); 54 | ascii_in++; 55 | 56 | n_zeros = 0; 57 | v_len = 0; 58 | while ((n_zeros < 2) && (n_out < max_out) && (v_len <= VARICODE_MAX_BITS)) { 59 | if (packed & 0x8000) { 60 | *varicode_out = 1; 61 | n_zeros = 0; 62 | } 63 | else { 64 | *varicode_out = 0; 65 | n_zeros++; 66 | } 67 | //printf("packed: 0x%x *varicode_out: %d n_zeros: %d v_len: %d\n", packed, *varicode_out, n_zeros,v_len ); 68 | packed <<= 1; 69 | varicode_out++; 70 | 71 | n_out++; 72 | v_len++; 73 | } 74 | assert(v_len <= VARICODE_MAX_BITS); 75 | 76 | n_in--; 77 | 78 | } 79 | 80 | return n_out; 81 | } 82 | 83 | void varicode_decode_init(struct VARICODE_DEC *dec_states) 84 | { 85 | dec_states->state = 0; 86 | dec_states->n_zeros = 0; 87 | dec_states->v_len = 0; 88 | dec_states->packed = 0; 89 | } 90 | 91 | static int decode_one_bit(struct VARICODE_DEC *s, char *single_ascii, short varicode_in) 92 | { 93 | int found, i; 94 | unsigned short byte1, byte2; 95 | 96 | //printf("decode_one_bit : state: %d varicode_in: %d packed: 0x%x n_zeros: %d\n", 97 | // s->state, varicode_in, s->packed, s->n_zeros); 98 | 99 | if (s->state == 0) { 100 | if (!varicode_in) 101 | return 0; 102 | else 103 | s->state = 1; 104 | } 105 | 106 | if (s->state == 1) { 107 | if (varicode_in) { 108 | s->packed |= (0x8000 >> s->v_len); 109 | s->n_zeros = 0; 110 | } 111 | else { 112 | s->n_zeros++; 113 | } 114 | s->v_len++; 115 | 116 | found = 0; 117 | 118 | /* end of character code */ 119 | 120 | if (s->n_zeros == 2) { 121 | if (s->v_len) { 122 | byte1 = s->packed >> 8; 123 | byte2 = s->packed & 0xff; 124 | 125 | /* run thru table but note with bit errors means we might 126 | not actually find a match */ 127 | 128 | for(i=0; i<128; i++) { 129 | if ((byte1 == varicode_table[2*i]) && (byte2 == varicode_table[2*i+1])) { 130 | found = 1; 131 | *single_ascii = i; 132 | } 133 | } 134 | } 135 | varicode_decode_init(s); 136 | } 137 | 138 | /* code can run too long if we have a bit error */ 139 | 140 | if (s->v_len > VARICODE_MAX_BITS) 141 | varicode_decode_init(s); 142 | } 143 | 144 | return found; 145 | } 146 | 147 | int varicode_decode(struct VARICODE_DEC *dec_states, char ascii_out[], short varicode_in[], int max_out, int n_in) { 148 | int output, n_out; 149 | char single_ascii; 150 | 151 | n_out = 0; 152 | 153 | //printf("varicode_decode: n_in: %d\n", n_in); 154 | 155 | while(n_in && (n_out < max_out)) { 156 | output = decode_one_bit(dec_states, &single_ascii, *varicode_in); 157 | varicode_in++; 158 | n_in--; 159 | if (output) { 160 | *ascii_out++ = single_ascii; 161 | n_out++; 162 | } 163 | } 164 | 165 | return n_out; 166 | } 167 | 168 | 169 | #ifdef VARICODE_UNITTEST 170 | int main(void) { 171 | char *ascii_in; 172 | short *varicode; 173 | int i, n_varicode_bits_out, n_ascii_chars_out, length, half; 174 | char *ascii_out; 175 | struct VARICODE_DEC dec_states; 176 | 177 | length = sizeof(varicode_table)/2; 178 | 179 | ascii_in = (char*)malloc(length); 180 | varicode = (short*)malloc(VARICODE_MAX_BITS*sizeof(short)*length); 181 | ascii_out = (char*)malloc(length); 182 | 183 | // 1. test all Varicode codes ------------------------------------------------------------- 184 | 185 | for(i=0; i. 19 | // 20 | //========================================================================== 21 | 22 | #ifndef __VARICODE__ 23 | #define __VARICODE__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | 28 | #endif 29 | 30 | #define VARICODE_MAX_BITS (10+2) /* max varicode bits for each ascii character */ 31 | /* 10 bits for code plus 2 0 bits for inter-character space */ 32 | 33 | struct VARICODE_DEC { 34 | int state; 35 | int n_zeros; 36 | int v_len; 37 | unsigned short packed; 38 | }; 39 | 40 | int varicode_encode(short varicode_out[], char ascii_in[], int max_out, int n_in); 41 | void varicode_decode_init(struct VARICODE_DEC *dec_states); 42 | int varicode_decode(struct VARICODE_DEC *dec_states, char ascii_out[], short varicode_in[], int max_out, int n_in); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /jni/codec2/varicode_table.h: -------------------------------------------------------------------------------- 1 | //========================================================================== 2 | // Name: varicode_table.h 3 | // Purpose: Varicode look up table 4 | // Created: Nov 24, 2012 5 | // Authors: Clint Turner, KA7OEI, Peter Martinez, G3PLX 6 | // 7 | // License: 8 | // 9 | // This program is free software; you can redistribute it and/or modify 10 | // it under the terms of the GNU General Public License version 2.1, 11 | // as published by the Free Software Foundation. This program is 12 | // distributed in the hope that it will be useful, but WITHOUT ANY 13 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 15 | // License for more details. 16 | // 17 | // You should have received a copy of the GNU General Public License 18 | // along with this program; if not, see . 19 | // 20 | //========================================================================== 21 | 22 | /* The following table defines the PKS31 varicode. There are 128 entries, 23 | corresponding to ASCII characters 0-127 with two bytes for each entry. The bits 24 | for the varicode are to be shifted out MSB-first for both bytes, with the first byte 25 | in the table being the first one to be sent. 26 | 27 | More than one zero in sequence signifies the end of the character (i.e. 28 | two zeroes are the intercharacter sequence, so at least two zeroes should always be 29 | sent before the next character is sent. 30 | 31 | This file is constructed with information from the article "PSK31 Fundamentals" 32 | by Peter Martinez, G3PLX by Clint Turner, KA7OEI 33 | */ 34 | unsigned char const varicode_table[256] = { 35 | 0b10101010, 36 | 0b11000000, // 0 NUL 37 | 0b10110110, 38 | 0b11000000, // 1 SOH 39 | 0b10111011, 40 | 0b01000000, // 2 STX 41 | 0b11011101, 42 | 0b11000000, // 3 ETX 43 | 0b10111010, 44 | 0b11000000, // 4 EOT 45 | 0b11010111, 46 | 0b11000000, // 5 ENQ 47 | 0b10111011, 48 | 0b11000000, // 6 ACK 49 | 0b10111111, 50 | 0b01000000, // 7 BEL 51 | 0b10111111, 52 | 0b11000000, // 8 BS 53 | 0b11101111, 54 | 0b00000000, // 9 HT 55 | 0b11101000, 56 | 0b00000000, // 10 LF 57 | 0b11011011, 58 | 0b11000000, // 11 VT 59 | 0b10110111, 60 | 0b01000000, // 12 FF 61 | 0b11111000, 62 | 0b00000000, // 13 CR 63 | 0b11011101, 64 | 0b01000000, // 14 SO 65 | 0b11101010, 66 | 0b11000000, // 15 SI 67 | 0b10111101, 68 | 0b11000000, // 16 DLE 69 | 0b10111101, 70 | 0b01000000, // 17 DC1 71 | 0b11101011, 72 | 0b01000000, // 18 DC2 73 | 0b11101011, 74 | 0b11000000, // 19 DC3 75 | 0b11010110, 76 | 0b11000000, // 20 DC4 77 | 0b11011010, 78 | 0b11000000, // 21 NAK 79 | 0b11011011, 80 | 0b01000000, // 22 SYN 81 | 0b11010101, 82 | 0b11000000, // 23 ETB 83 | 0b11011110, 84 | 0b11000000, // 24 CAN 85 | 0b11011111, 86 | 0b01000000, // 25 EM 87 | 0b11101101, 88 | 0b11000000, // 26 SUB 89 | 0b11010101, 90 | 0b01000000, // 27 ESC 91 | 0b11010111, 92 | 0b01000000, // 28 FS 93 | 0b11101110, 94 | 0b11000000, // 29 GS 95 | 0b10111110, 96 | 0b11000000, // 30 RS 97 | 0b11011111, 98 | 0b11000000, // 31 US 99 | 0b10000000, 100 | 0b00000000, // 32 SP 101 | 0b11111111, 102 | 0b10000000, // 33 ! 103 | 0b10101111, 104 | 0b10000000, // 34 " 105 | 0b11111010, 106 | 0b10000000, // 35 # 107 | 0b11101101, 108 | 0b10000000, // 36 $ 109 | 0b10110101, 110 | 0b01000000, // 37 % 111 | 0b10101110, 112 | 0b11000000, // 38 & 113 | 0b10111111, 114 | 0b10000000, // 39 ' 115 | 0b11111011, 116 | 0b00000000, // 40 ( 117 | 0b11110111, 118 | 0b00000000, // 41 ) 119 | 0b10110111, 120 | 0b10000000, // 42 * 121 | 0b11101111, 122 | 0b10000000, // 43 + 123 | 0b11101010, 124 | 0b00000000, // 44 , 125 | 0b11010100, 126 | 0b00000000, // 45 - 127 | 0b10101110, 128 | 0b00000000, // 46 . 129 | 0b11010111, 130 | 0b10000000, // 47 / 131 | 0b10110111, 132 | 0b00000000, // 48 0 133 | 0b10111101, 134 | 0b00000000, // 49 1 135 | 0b11101101, 136 | 0b00000000, // 50 2 137 | 0b11111111, 138 | 0b00000000, // 51 3 139 | 0b10111011, 140 | 0b10000000, // 52 4 141 | 0b10101101, 142 | 0b10000000, // 53 5 143 | 0b10110101, 144 | 0b10000000, // 54 6 145 | 0b11010110, 146 | 0b10000000, // 55 7 147 | 0b11010101, 148 | 0b10000000, // 56 8 149 | 0b11011011, 150 | 0b10000000, // 57 9 151 | 0b11110101, 152 | 0b00000000, // 58 : 153 | 0b11011110, 154 | 0b10000000, // 59 ; 155 | 0b11110110, 156 | 0b10000000, // 60 < 157 | 0b10101010, 158 | 0b00000000, // 61 = 159 | 0b11101011, 160 | 0b10000000, // 62 > 161 | 0b10101011, 162 | 0b11000000, // 63 ? 163 | 0b10101111, 164 | 0b01000000, // 64 @ 165 | 0b11111010, 166 | 0b00000000, // 65 A 167 | 0b11101011, 168 | 0b00000000, // 66 B 169 | 0b10101101, 170 | 0b00000000, // 67 C 171 | 0b10110101, 172 | 0b00000000, // 68 D 173 | 0b11101110, 174 | 0b00000000, // 69 E 175 | 0b11011011, 176 | 0b00000000, // 70 F 177 | 0b11111101, 178 | 0b00000000, // 71 G 179 | 0b10101010, 180 | 0b10000000, // 72 H 181 | 0b11111110, 182 | 0b00000000, // 73 I 183 | 0b11111110, 184 | 0b10000000, // 74 J 185 | 0b10111110, 186 | 0b10000000, // 75 K 187 | 0b11010111, 188 | 0b00000000, // 76 L 189 | 0b10111011, 190 | 0b00000000, // 77 M 191 | 0b11011101, 192 | 0b00000000, // 78 N 193 | 0b10101011, 194 | 0b00000000, // 79 O 195 | 0b11010101, 196 | 0b00000000, // 80 P 197 | 0b11101110, 198 | 0b10000000, // 81 Q 199 | 0b10101111, 200 | 0b00000000, // 82 R 201 | 0b11011110, 202 | 0b00000000, // 83 S 203 | 0b11011010, 204 | 0b00000000, // 84 T 205 | 0b10101011, 206 | 0b10000000, // 85 U 207 | 0b11011010, 208 | 0b10000000, // 86 V 209 | 0b10101110, 210 | 0b10000000, // 87 W 211 | 0b10111010, 212 | 0b10000000, // 88 X 213 | 0b10111101, 214 | 0b10000000, // 89 Y 215 | 0b10101011, 216 | 0b01000000, // 90 Z 217 | 0b11111011, 218 | 0b10000000, // 91 [ 219 | 0b11110111, 220 | 0b10000000, // 92 "\" 221 | 0b11111101, 222 | 0b10000000, // 93 ] 223 | 0b10101111, 224 | 0b11000000, // 94 ^ 225 | 0b10110110, 226 | 0b10000000, // 95 _ (underline) 227 | 0b10110111, 228 | 0b11000000, // 96 ` 229 | 0b10110000, 230 | 0b00000000, // 97 a 231 | 0b10111110, 232 | 0b00000000, // 98 b 233 | 0b10111100, 234 | 0b00000000, // 99 c 235 | 0b10110100, 236 | 0b00000000, // 100 d 237 | 0b11000000, 238 | 0b00000000, // 101 e 239 | 0b11110100, 240 | 0b00000000, // 102 f 241 | 0b10110110, 242 | 0b00000000, // 103 g 243 | 0b10101100, 244 | 0b00000000, // 104 h 245 | 0b11010000, 246 | 0b00000000, // 105 i 247 | 0b11110101, 248 | 0b10000000, // 106 j 249 | 0b10111111, 250 | 0b00000000, // 107 k 251 | 0b11011000, 252 | 0b00000000, // 108 l 253 | 0b11101100, 254 | 0b00000000, // 109 m 255 | 0b11110000, 256 | 0b00000000, // 110 n 257 | 0b11100000, 258 | 0b00000000, // 111 o 259 | 0b11111100, 260 | 0b00000000, // 112 p 261 | 0b11011111, 262 | 0b10000000, // 113 q 263 | 0b10101000, 264 | 0b00000000, // 114 r 265 | 0b10111000, 266 | 0b00000000, // 115 s 267 | 0b10100000, 268 | 0b00000000, // 116 t 269 | 0b11011100, 270 | 0b00000000, // 117 u 271 | 0b11110110, 272 | 0b00000000, // 118 v 273 | 0b11010110, 274 | 0b00000000, // 119 w 275 | 0b11011111, 276 | 0b00000000, // 120 x 277 | 0b10111010, 278 | 0b00000000, // 121 y 279 | 0b11101010, 280 | 0b10000000, // 122 z 281 | 0b10101101, 282 | 0b11000000, // 123 { 283 | 0b11011101, 284 | 0b10000000, // 124 | 285 | 0b10101101, 286 | 0b01000000, // 125 } 287 | 0b10110101, 288 | 0b11000000, // 126 ~ 289 | 0b11101101, 290 | 0b01000000, // 127 (del) 291 | }; 292 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | android.library=true 16 | -------------------------------------------------------------------------------- /src/com/obteq/android/codec2/Codec2.java: -------------------------------------------------------------------------------- 1 | package com.obteq.android.codec2; 2 | 3 | public class Codec2 { 4 | static { 5 | System.loadLibrary("codec2"); 6 | } 7 | 8 | public final static int CODEC2_MODE_3200 = 0; 9 | public final static int CODEC2_MODE_2400 = 1; 10 | public final static int CODEC2_MODE_1400 = 2; 11 | public final static int CODEC2_MODE_1200 = 3; 12 | 13 | public native static long create(int mode); 14 | 15 | public native static int getSamplesPerFrame(long con); 16 | 17 | public native static int getBitsSize(long con); 18 | 19 | public native static int destroy(long con); 20 | 21 | public native static long encode(long con, short[] buf, char[] bits); 22 | 23 | public native static long decode(long con, short[] buf, char[] bits); 24 | } 25 | --------------------------------------------------------------------------------