├── .gitignore ├── COPYING ├── ChangeLog ├── Makefile.am ├── NOTICE ├── README ├── amrwb-enc.c ├── amrwbenc ├── Android.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── SampleCode │ ├── AMRWB_E_SAMPLE.c │ ├── Android.mk │ ├── MODULE_LICENSE_APACHE2 │ └── NOTICE ├── SoftAMRWBEncoder.cpp ├── SoftAMRWBEncoder.h ├── doc │ └── voAMRWBEncoderSDK.pdf ├── inc │ ├── acelp.h │ ├── basic_op.h │ ├── bits.h │ ├── cnst.h │ ├── cod_main.h │ ├── dtx.h │ ├── grid100.tab │ ├── ham_wind.tab │ ├── homing.tab │ ├── isp_isf.tab │ ├── lag_wind.tab │ ├── log2.h │ ├── log2_tab.h │ ├── main.h │ ├── math_op.h │ ├── mem_align.h │ ├── mime_io.tab │ ├── oper_32b.h │ ├── p_med_o.h │ ├── p_med_ol.tab │ ├── q_gain2.tab │ ├── q_pulse.h │ ├── qisf_ns.tab │ ├── qpisf_2s.tab │ ├── stream.h │ ├── typedef.h │ ├── typedefs.h │ ├── wb_vad.h │ └── wb_vad_c.h ├── patent_disclaimer.txt └── src │ ├── asm │ ├── ARMV5E │ │ ├── Deemph_32_opt.s │ │ ├── Dot_p_opt.s │ │ ├── Filt_6k_7k_opt.s │ │ ├── Norm_Corr_opt.s │ │ ├── Syn_filt_32_opt.s │ │ ├── convolve_opt.s │ │ ├── cor_h_vec_opt.s │ │ ├── pred_lt4_1_opt.s │ │ ├── residu_asm_opt.s │ │ ├── scale_sig_opt.s │ │ └── syn_filt_opt.s │ └── ARMV7 │ │ ├── Deemph_32_neon.s │ │ ├── Dot_p_neon.s │ │ ├── Filt_6k_7k_neon.s │ │ ├── Norm_Corr_neon.s │ │ ├── Syn_filt_32_neon.s │ │ ├── convolve_neon.s │ │ ├── cor_h_vec_neon.s │ │ ├── pred_lt4_1_neon.s │ │ ├── residu_asm_neon.s │ │ ├── scale_sig_neon.s │ │ └── syn_filt_neon.s │ ├── autocorr.c │ ├── az_isp.c │ ├── bits.c │ ├── c2t64fx.c │ ├── c4t64fx.c │ ├── convolve.c │ ├── cor_h_x.c │ ├── decim54.c │ ├── deemph.c │ ├── dtx.c │ ├── g_pitch.c │ ├── gpclip.c │ ├── homing.c │ ├── hp400.c │ ├── hp50.c │ ├── hp6k.c │ ├── hp_wsp.c │ ├── int_lpc.c │ ├── isp_az.c │ ├── isp_isf.c │ ├── lag_wind.c │ ├── levinson.c │ ├── log2.c │ ├── lp_dec2.c │ ├── math_op.c │ ├── mem_align.c │ ├── oper_32b.c │ ├── p_med_ol.c │ ├── pit_shrp.c │ ├── pitch_f4.c │ ├── pred_lt4.c │ ├── preemph.c │ ├── q_gain2.c │ ├── q_pulse.c │ ├── qisf_ns.c │ ├── qpisf_2s.c │ ├── random.c │ ├── residu.c │ ├── scale.c │ ├── stream.c │ ├── syn_filt.c │ ├── updt_tar.c │ ├── util.c │ ├── voAMRWBEnc.c │ ├── voicefac.c │ ├── wb_vad.c │ └── weight_a.c ├── common ├── Android.mk ├── Config.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── cmnMemory.c └── include │ ├── cmnMemory.h │ ├── voAAC.h │ ├── voAMRWB.h │ ├── voAudio.h │ ├── voIndex.h │ ├── voMem.h │ └── voType.h ├── configure.ac ├── enc_if.h ├── m4 └── .gitkeep ├── vo-amrwbenc.pc.in ├── vo-amrwbenc.sym ├── wavreader.c ├── wavreader.h └── wrapper.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | *.la 4 | *.pc 5 | Makefile 6 | amrwb-enc 7 | Makefile.in 8 | aclocal.m4 9 | autom4te.cache 10 | configure 11 | .deps 12 | .libs 13 | config.guess 14 | config.log 15 | config.status 16 | config.sub 17 | depcomp 18 | install-sh 19 | libtool 20 | ltmain.sh 21 | m4/libtool.m4 22 | m4/ltoptions.m4 23 | m4/ltsugar.m4 24 | m4/ltversion.m4 25 | m4/lt~obsolete.m4 26 | missing 27 | stamp-h1 28 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 0.1.3 2 | - Unify the code with upstream, after local changes have been merged upstream 3 | - Update source files to the latest version upstream (no functional changes) 4 | - Avoid text relocations in arm assembly 5 | - Clean up the autotools project files 6 | - Minor warning fixes when building with certain warning flags 7 | - Fix a bug in the wav reader, making it compatible with more wav files 8 | 9 | 0.1.2 10 | - Update source files to the latest version upstream (no functional changes) 11 | - Hide internal symbols in shared libraries 12 | - Whitespace cleanup in the codec code 13 | - Minor tweaks 14 | 15 | 0.1.1 16 | - Fix building for windows 17 | 18 | 0.1.0 19 | - Initial release of vo-amrwbenc 20 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | VO_COMMON = common 2 | ENC_SRC = amrwbenc/src 3 | 4 | ACLOCAL_AMFLAGS = -I m4 5 | 6 | AM_CFLAGS = -I$(top_srcdir)/amrwbenc/inc -I$(top_srcdir)/common/include 7 | 8 | if ARMV7NEON 9 | AM_CFLAGS += -DARM -DARMV7 -DASM_OPT 10 | else 11 | if ARMV5E 12 | AM_CFLAGS += -DARM -DASM_OPT 13 | endif 14 | endif 15 | 16 | amrwbencincludedir = $(includedir)/vo-amrwbenc 17 | amrwbencinclude_HEADERS = enc_if.h 18 | 19 | pkgconfigdir = $(libdir)/pkgconfig 20 | pkgconfig_DATA = vo-amrwbenc.pc 21 | 22 | lib_LTLIBRARIES = libvo-amrwbenc.la 23 | 24 | libvo_amrwbenc_la_LDFLAGS = -version-info @VO_AMRWBENC_VERSION@ -no-undefined -export-symbols $(top_srcdir)/vo-amrwbenc.sym 25 | 26 | libvo_amrwbenc_la_SOURCES = \ 27 | wrapper.c \ 28 | $(VO_COMMON)/cmnMemory.c \ 29 | $(ENC_SRC)/autocorr.c \ 30 | $(ENC_SRC)/az_isp.c \ 31 | $(ENC_SRC)/bits.c \ 32 | $(ENC_SRC)/c2t64fx.c \ 33 | $(ENC_SRC)/c4t64fx.c \ 34 | $(ENC_SRC)/convolve.c \ 35 | $(ENC_SRC)/cor_h_x.c \ 36 | $(ENC_SRC)/decim54.c \ 37 | $(ENC_SRC)/deemph.c \ 38 | $(ENC_SRC)/dtx.c \ 39 | $(ENC_SRC)/g_pitch.c \ 40 | $(ENC_SRC)/gpclip.c \ 41 | $(ENC_SRC)/homing.c \ 42 | $(ENC_SRC)/hp400.c \ 43 | $(ENC_SRC)/hp50.c \ 44 | $(ENC_SRC)/hp6k.c \ 45 | $(ENC_SRC)/hp_wsp.c \ 46 | $(ENC_SRC)/int_lpc.c \ 47 | $(ENC_SRC)/isp_az.c \ 48 | $(ENC_SRC)/isp_isf.c \ 49 | $(ENC_SRC)/lag_wind.c \ 50 | $(ENC_SRC)/levinson.c \ 51 | $(ENC_SRC)/log2.c \ 52 | $(ENC_SRC)/lp_dec2.c \ 53 | $(ENC_SRC)/math_op.c \ 54 | $(ENC_SRC)/mem_align.c \ 55 | $(ENC_SRC)/oper_32b.c \ 56 | $(ENC_SRC)/p_med_ol.c \ 57 | $(ENC_SRC)/pit_shrp.c \ 58 | $(ENC_SRC)/pitch_f4.c \ 59 | $(ENC_SRC)/pred_lt4.c \ 60 | $(ENC_SRC)/preemph.c \ 61 | $(ENC_SRC)/q_gain2.c \ 62 | $(ENC_SRC)/q_pulse.c \ 63 | $(ENC_SRC)/qisf_ns.c \ 64 | $(ENC_SRC)/qpisf_2s.c \ 65 | $(ENC_SRC)/random.c \ 66 | $(ENC_SRC)/residu.c \ 67 | $(ENC_SRC)/scale.c \ 68 | $(ENC_SRC)/stream.c \ 69 | $(ENC_SRC)/syn_filt.c \ 70 | $(ENC_SRC)/updt_tar.c \ 71 | $(ENC_SRC)/util.c \ 72 | $(ENC_SRC)/voAMRWBEnc.c \ 73 | $(ENC_SRC)/voicefac.c \ 74 | $(ENC_SRC)/wb_vad.c \ 75 | $(ENC_SRC)/weight_a.c 76 | 77 | if ARMV7NEON 78 | libvo_amrwbenc_la_SOURCES += \ 79 | $(ENC_SRC)/asm/ARMV7/convolve_neon.s \ 80 | $(ENC_SRC)/asm/ARMV7/cor_h_vec_neon.s \ 81 | $(ENC_SRC)/asm/ARMV7/Deemph_32_neon.s \ 82 | $(ENC_SRC)/asm/ARMV7/Dot_p_neon.s \ 83 | $(ENC_SRC)/asm/ARMV7/Filt_6k_7k_neon.s \ 84 | $(ENC_SRC)/asm/ARMV7/Norm_Corr_neon.s \ 85 | $(ENC_SRC)/asm/ARMV7/pred_lt4_1_neon.s \ 86 | $(ENC_SRC)/asm/ARMV7/residu_asm_neon.s \ 87 | $(ENC_SRC)/asm/ARMV7/scale_sig_neon.s \ 88 | $(ENC_SRC)/asm/ARMV7/Syn_filt_32_neon.s \ 89 | $(ENC_SRC)/asm/ARMV7/syn_filt_neon.s 90 | else 91 | if ARMV5E 92 | libvo_amrwbenc_la_SOURCES += \ 93 | $(ENC_SRC)/asm/ARMV5E/convolve_opt.s \ 94 | $(ENC_SRC)/asm/ARMV5E/cor_h_vec_opt.s \ 95 | $(ENC_SRC)/asm/ARMV5E/Deemph_32_opt.s \ 96 | $(ENC_SRC)/asm/ARMV5E/Dot_p_opt.s \ 97 | $(ENC_SRC)/asm/ARMV5E/Filt_6k_7k_opt.s \ 98 | $(ENC_SRC)/asm/ARMV5E/Norm_Corr_opt.s \ 99 | $(ENC_SRC)/asm/ARMV5E/pred_lt4_1_opt.s \ 100 | $(ENC_SRC)/asm/ARMV5E/residu_asm_opt.s \ 101 | $(ENC_SRC)/asm/ARMV5E/scale_sig_opt.s \ 102 | $(ENC_SRC)/asm/ARMV5E/Syn_filt_32_opt.s \ 103 | $(ENC_SRC)/asm/ARMV5E/syn_filt_opt.s 104 | endif 105 | endif 106 | 107 | noinst_HEADERS = $(top_srcdir)/amrwbenc/inc/*.h \ 108 | $(top_srcdir)/amrwbenc/inc/*.tab \ 109 | $(top_srcdir)/common/include/*.h 110 | 111 | if EXAMPLE 112 | bin_PROGRAMS = amrwb-enc$(EXEEXT) 113 | 114 | amrwb_enc_LDADD = libvo-amrwbenc.la 115 | amrwb_enc_SOURCES = amrwb-enc.c wavreader.c 116 | 117 | noinst_HEADERS += wavreader.h 118 | endif 119 | 120 | 121 | EXTRA_DIST = $(top_srcdir)/NOTICE \ 122 | $(top_srcdir)/vo-amrwbenc.sym \ 123 | $(top_srcdir)/amrwbenc/*.cpp $(top_srcdir)/amrwbenc/*.h \ 124 | $(top_srcdir)/amrwbenc/*.mk \ 125 | $(top_srcdir)/amrwbenc/NOTICE \ 126 | $(top_srcdir)/amrwbenc/MODULE_LICENSE_APACHE2 \ 127 | $(top_srcdir)/amrwbenc/SampleCode \ 128 | $(top_srcdir)/amrwbenc/doc $(top_srcdir)/amrwbenc/*.txt \ 129 | $(top_srcdir)/common/*.mk \ 130 | $(top_srcdir)/common/NOTICE \ 131 | $(top_srcdir)/common/MODULE_LICENSE_APACHE2 132 | 133 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | VisualOn AMR-WB encoder library 2 | 3 | This library contains an encoder implementation of the Adaptive Multi 4 | Rate Wideband (AMR-WB) audio codec. The library is based on a codec 5 | implementation by VisualOn as part of the Stagefright framework from 6 | the Google Android project. 7 | 8 | -------------------------------------------------------------------------------- /amrwb-enc.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ 2 | * Copyright (C) 2009 Martin Storsjo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 | * express or implied. 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * ------------------------------------------------------------------- 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "wavreader.h" 25 | 26 | void usage(const char* name) { 27 | fprintf(stderr, "%s [-r bitrate] [-d] in.wav out.amr\n", name); 28 | } 29 | 30 | int findMode(const char* str) { 31 | struct { 32 | int mode; 33 | int rate; 34 | } modes[] = { 35 | { 0, 6600 }, 36 | { 1, 8850 }, 37 | { 2, 12650 }, 38 | { 3, 14250 }, 39 | { 4, 15850 }, 40 | { 5, 18250 }, 41 | { 6, 19850 }, 42 | { 7, 23050 }, 43 | { 8, 23850 } 44 | }; 45 | int rate = atoi(str); 46 | int closest = -1; 47 | int closestdiff = 0; 48 | unsigned int i; 49 | for (i = 0; i < sizeof(modes)/sizeof(modes[0]); i++) { 50 | if (modes[i].rate == rate) 51 | return modes[i].mode; 52 | if (closest < 0 || closestdiff > abs(modes[i].rate - rate)) { 53 | closest = i; 54 | closestdiff = abs(modes[i].rate - rate); 55 | } 56 | } 57 | fprintf(stderr, "Using bitrate %d\n", modes[closest].rate); 58 | return modes[closest].mode; 59 | } 60 | 61 | int main(int argc, char *argv[]) { 62 | int mode = 8; 63 | int ch, dtx = 0; 64 | const char *infile, *outfile; 65 | FILE* out; 66 | void *wav, *amr; 67 | int format, sampleRate, channels, bitsPerSample; 68 | int inputSize; 69 | uint8_t* inputBuf; 70 | while ((ch = getopt(argc, argv, "r:d")) != -1) { 71 | switch (ch) { 72 | case 'r': 73 | mode = findMode(optarg); 74 | break; 75 | case 'd': 76 | dtx = 1; 77 | break; 78 | case '?': 79 | default: 80 | usage(argv[0]); 81 | return 1; 82 | } 83 | } 84 | if (argc - optind < 2) { 85 | usage(argv[0]); 86 | return 1; 87 | } 88 | infile = argv[optind]; 89 | outfile = argv[optind + 1]; 90 | 91 | 92 | wav = wav_read_open(infile); 93 | if (!wav) { 94 | fprintf(stderr, "Unable to open wav file %s\n", infile); 95 | return 1; 96 | } 97 | if (!wav_get_header(wav, &format, &channels, &sampleRate, &bitsPerSample, NULL)) { 98 | fprintf(stderr, "Bad wav file %s\n", infile); 99 | return 1; 100 | } 101 | if (format != 1) { 102 | fprintf(stderr, "Unsupported WAV format %d\n", format); 103 | return 1; 104 | } 105 | if (bitsPerSample != 16) { 106 | fprintf(stderr, "Unsupported WAV sample depth %d\n", bitsPerSample); 107 | return 1; 108 | } 109 | if (channels != 1) 110 | fprintf(stderr, "Warning, only compressing one audio channel\n"); 111 | if (sampleRate != 16000) 112 | fprintf(stderr, "Warning, AMR-WB uses 16000 Hz sample rate (WAV file has %d Hz)\n", sampleRate); 113 | inputSize = channels*2*320; 114 | inputBuf = (uint8_t*) malloc(inputSize); 115 | 116 | amr = E_IF_init(); 117 | out = fopen(outfile, "wb"); 118 | if (!out) { 119 | perror(outfile); 120 | return 1; 121 | } 122 | 123 | fwrite("#!AMR-WB\n", 1, 9, out); 124 | while (1) { 125 | int read, i, n; 126 | short buf[320]; 127 | uint8_t outbuf[500]; 128 | 129 | read = wav_read_data(wav, inputBuf, inputSize); 130 | read /= channels; 131 | read /= 2; 132 | if (read < 320) 133 | break; 134 | for (i = 0; i < 320; i++) { 135 | const uint8_t* in = &inputBuf[2*channels*i]; 136 | buf[i] = in[0] | (in[1] << 8); 137 | } 138 | n = E_IF_encode(amr, mode, buf, outbuf, dtx); 139 | fwrite(outbuf, 1, n, out); 140 | } 141 | free(inputBuf); 142 | fclose(out); 143 | E_IF_exit(amr); 144 | wav_read_close(wav); 145 | 146 | return 0; 147 | } 148 | 149 | -------------------------------------------------------------------------------- /amrwbenc/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | include $(CLEAR_VARS) 3 | include frameworks/av/media/libstagefright/codecs/common/Config.mk 4 | 5 | 6 | 7 | LOCAL_SRC_FILES := \ 8 | src/autocorr.c \ 9 | src/az_isp.c \ 10 | src/bits.c \ 11 | src/c2t64fx.c \ 12 | src/c4t64fx.c \ 13 | src/convolve.c \ 14 | src/cor_h_x.c \ 15 | src/decim54.c \ 16 | src/deemph.c \ 17 | src/dtx.c \ 18 | src/g_pitch.c \ 19 | src/gpclip.c \ 20 | src/homing.c \ 21 | src/hp400.c \ 22 | src/hp50.c \ 23 | src/hp6k.c \ 24 | src/hp_wsp.c \ 25 | src/int_lpc.c \ 26 | src/isp_az.c \ 27 | src/isp_isf.c \ 28 | src/lag_wind.c \ 29 | src/levinson.c \ 30 | src/log2.c \ 31 | src/lp_dec2.c \ 32 | src/math_op.c \ 33 | src/oper_32b.c \ 34 | src/p_med_ol.c \ 35 | src/pit_shrp.c \ 36 | src/pitch_f4.c \ 37 | src/pred_lt4.c \ 38 | src/preemph.c \ 39 | src/q_gain2.c \ 40 | src/q_pulse.c \ 41 | src/qisf_ns.c \ 42 | src/qpisf_2s.c \ 43 | src/random.c \ 44 | src/residu.c \ 45 | src/scale.c \ 46 | src/stream.c \ 47 | src/syn_filt.c \ 48 | src/updt_tar.c \ 49 | src/util.c \ 50 | src/voAMRWBEnc.c \ 51 | src/voicefac.c \ 52 | src/wb_vad.c \ 53 | src/weight_a.c \ 54 | src/mem_align.c 55 | 56 | 57 | ifeq ($(VOTT), v5) 58 | LOCAL_SRC_FILES += \ 59 | src/asm/ARMV5E/convolve_opt.s \ 60 | src/asm/ARMV5E/cor_h_vec_opt.s \ 61 | src/asm/ARMV5E/Deemph_32_opt.s \ 62 | src/asm/ARMV5E/Dot_p_opt.s \ 63 | src/asm/ARMV5E/Filt_6k_7k_opt.s \ 64 | src/asm/ARMV5E/Norm_Corr_opt.s \ 65 | src/asm/ARMV5E/pred_lt4_1_opt.s \ 66 | src/asm/ARMV5E/residu_asm_opt.s \ 67 | src/asm/ARMV5E/scale_sig_opt.s \ 68 | src/asm/ARMV5E/Syn_filt_32_opt.s \ 69 | src/asm/ARMV5E/syn_filt_opt.s 70 | 71 | endif 72 | 73 | ifeq ($(VOTT), v7) 74 | LOCAL_SRC_FILES += \ 75 | src/asm/ARMV7/convolve_neon.s \ 76 | src/asm/ARMV7/cor_h_vec_neon.s \ 77 | src/asm/ARMV7/Deemph_32_neon.s \ 78 | src/asm/ARMV7/Dot_p_neon.s \ 79 | src/asm/ARMV7/Filt_6k_7k_neon.s \ 80 | src/asm/ARMV7/Norm_Corr_neon.s \ 81 | src/asm/ARMV7/pred_lt4_1_neon.s \ 82 | src/asm/ARMV7/residu_asm_neon.s \ 83 | src/asm/ARMV7/scale_sig_neon.s \ 84 | src/asm/ARMV7/Syn_filt_32_neon.s \ 85 | src/asm/ARMV7/syn_filt_neon.s 86 | 87 | endif 88 | 89 | # ARMV5E/Filt_6k_7k_opt.s does not compile with Clang. 90 | LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as 91 | 92 | LOCAL_MODULE := libstagefright_amrwbenc 93 | 94 | LOCAL_ARM_MODE := arm 95 | 96 | LOCAL_STATIC_LIBRARIES := 97 | 98 | LOCAL_SHARED_LIBRARIES := 99 | 100 | LOCAL_C_INCLUDES := \ 101 | frameworks/av/include \ 102 | frameworks/av/media/libstagefright/include \ 103 | frameworks/av/media/libstagefright/codecs/common/include \ 104 | $(LOCAL_PATH)/src \ 105 | $(LOCAL_PATH)/inc 106 | 107 | ifeq ($(VOTT), v5) 108 | LOCAL_CFLAGS += -DARM -DASM_OPT 109 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV5E 110 | endif 111 | 112 | ifeq ($(VOTT), v7) 113 | LOCAL_CFLAGS += -DARM -DARMV7 -DASM_OPT 114 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV5E 115 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV7 116 | endif 117 | 118 | LOCAL_CFLAGS += -Werror 119 | 120 | include $(BUILD_STATIC_LIBRARY) 121 | 122 | ################################################################################ 123 | 124 | include $(CLEAR_VARS) 125 | 126 | LOCAL_SRC_FILES := \ 127 | SoftAMRWBEncoder.cpp 128 | 129 | LOCAL_C_INCLUDES := \ 130 | frameworks/av/media/libstagefright/include \ 131 | frameworks/av/media/libstagefright/codecs/common/include \ 132 | frameworks/native/include/media/openmax 133 | 134 | LOCAL_CFLAGS += -Werror 135 | 136 | LOCAL_STATIC_LIBRARIES := \ 137 | libstagefright_amrwbenc 138 | 139 | LOCAL_SHARED_LIBRARIES := \ 140 | libstagefright_omx libstagefright_foundation libutils liblog \ 141 | libstagefright_enc_common 142 | 143 | LOCAL_MODULE := libstagefright_soft_amrwbenc 144 | LOCAL_MODULE_TAGS := optional 145 | 146 | include $(BUILD_SHARED_LIBRARY) 147 | -------------------------------------------------------------------------------- /amrwbenc/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mstorsjo/vo-amrwbenc/884dd247dbeb6b2bd2cd3291c4872de95700291f/amrwbenc/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /amrwbenc/SampleCode/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES := \ 5 | AMRWB_E_SAMPLE.c \ 6 | ../../common/cmnMemory.c 7 | 8 | LOCAL_MODULE_TAGS := optional 9 | LOCAL_MODULE := AMRWBEncTest 10 | 11 | LOCAL_ARM_MODE := arm 12 | 13 | LOCAL_CFLAGS := -DLINUX 14 | 15 | LOCAL_SHARED_LIBRARIES := \ 16 | libstagefright \ 17 | libdl 18 | 19 | LOCAL_C_INCLUDES := \ 20 | $(LOCAL_PATH)/ \ 21 | $(LOCAL_PATH)/../../common \ 22 | $(LOCAL_PATH)/../../common/include 23 | 24 | include $(BUILD_EXECUTABLE) 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /amrwbenc/SampleCode/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mstorsjo/vo-amrwbenc/884dd247dbeb6b2bd2cd3291c4872de95700291f/amrwbenc/SampleCode/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /amrwbenc/SoftAMRWBEncoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef SOFT_AMRWB_ENCODER_H_ 18 | 19 | #define SOFT_AMRWB_ENCODER_H_ 20 | 21 | #include "SimpleSoftOMXComponent.h" 22 | 23 | #include "voAMRWB.h" 24 | 25 | struct VO_AUDIO_CODECAPI; 26 | struct VO_MEM_OPERATOR; 27 | 28 | namespace android { 29 | 30 | struct SoftAMRWBEncoder : public SimpleSoftOMXComponent { 31 | SoftAMRWBEncoder( 32 | const char *name, 33 | const OMX_CALLBACKTYPE *callbacks, 34 | OMX_PTR appData, 35 | OMX_COMPONENTTYPE **component); 36 | 37 | protected: 38 | virtual ~SoftAMRWBEncoder(); 39 | 40 | virtual OMX_ERRORTYPE internalGetParameter( 41 | OMX_INDEXTYPE index, OMX_PTR params); 42 | 43 | virtual OMX_ERRORTYPE internalSetParameter( 44 | OMX_INDEXTYPE index, const OMX_PTR params); 45 | 46 | virtual void onQueueFilled(OMX_U32 portIndex); 47 | 48 | private: 49 | enum { 50 | kNumBuffers = 4, 51 | kNumSamplesPerFrame = 320, 52 | }; 53 | 54 | void *mEncoderHandle; 55 | VO_AUDIO_CODECAPI *mApiHandle; 56 | VO_MEM_OPERATOR *mMemOperator; 57 | 58 | OMX_U32 mBitRate; 59 | VOAMRWBMODE mMode; 60 | 61 | size_t mInputSize; 62 | int16_t mInputFrame[kNumSamplesPerFrame]; 63 | int64_t mInputTimeUs; 64 | 65 | bool mSawInputEOS; 66 | bool mSignalledError; 67 | 68 | void initPorts(); 69 | status_t initEncoder(); 70 | 71 | DISALLOW_EVIL_CONSTRUCTORS(SoftAMRWBEncoder); 72 | }; 73 | 74 | } // namespace android 75 | 76 | #endif // SOFT_AMRWB_ENCODER_H_ 77 | -------------------------------------------------------------------------------- /amrwbenc/doc/voAMRWBEncoderSDK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mstorsjo/vo-amrwbenc/884dd247dbeb6b2bd2cd3291c4872de95700291f/amrwbenc/doc/voAMRWBEncoderSDK.pdf -------------------------------------------------------------------------------- /amrwbenc/inc/bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*--------------------------------------------------------------------------* 19 | * BITS.H * 20 | *--------------------------------------------------------------------------* 21 | * Number of bits for different modes * 22 | *--------------------------------------------------------------------------*/ 23 | 24 | #ifndef __BITS_H__ 25 | #define __BITS_H__ 26 | 27 | #include 28 | #include "typedef.h" 29 | #include "cnst.h" 30 | #include "cod_main.h" 31 | 32 | #define NBBITS_7k 132 /* 6.60k */ 33 | #define NBBITS_9k 177 /* 8.85k */ 34 | #define NBBITS_12k 253 /* 12.65k */ 35 | #define NBBITS_14k 285 /* 14.25k */ 36 | #define NBBITS_16k 317 /* 15.85k */ 37 | #define NBBITS_18k 365 /* 18.25k */ 38 | #define NBBITS_20k 397 /* 19.85k */ 39 | #define NBBITS_23k 461 /* 23.05k */ 40 | #define NBBITS_24k 477 /* 23.85k */ 41 | 42 | #define NBBITS_SID 35 43 | #define NB_BITS_MAX NBBITS_24k 44 | 45 | #define BIT_0 (Word16)-127 46 | #define BIT_1 (Word16)127 47 | #define BIT_0_ITU (Word16)0x007F 48 | #define BIT_1_ITU (Word16)0x0081 49 | 50 | #define SIZE_MAX1 (3+NB_BITS_MAX) /* serial size max */ 51 | #define TX_FRAME_TYPE (Word16)0x6b21 52 | #define RX_FRAME_TYPE (Word16)0x6b20 53 | 54 | static const Word16 nb_of_bits[NUM_OF_MODES] = { 55 | NBBITS_7k, 56 | NBBITS_9k, 57 | NBBITS_12k, 58 | NBBITS_14k, 59 | NBBITS_16k, 60 | NBBITS_18k, 61 | NBBITS_20k, 62 | NBBITS_23k, 63 | NBBITS_24k, 64 | NBBITS_SID 65 | }; 66 | 67 | /*typedef struct 68 | { 69 | Word16 sid_update_counter; 70 | Word16 sid_handover_debt; 71 | Word16 prev_ft; 72 | } TX_State; 73 | */ 74 | 75 | //typedef struct 76 | //{ 77 | // Word16 prev_ft; 78 | // Word16 prev_mode; 79 | //} RX_State; 80 | 81 | int PackBits(Word16 prms[], Word16 coding_mode, Word16 mode, Coder_State *st); 82 | 83 | 84 | void Parm_serial( 85 | Word16 value, /* input : parameter value */ 86 | Word16 no_of_bits, /* input : number of bits */ 87 | Word16 ** prms 88 | ); 89 | 90 | 91 | #endif //__BITS_H__ 92 | 93 | -------------------------------------------------------------------------------- /amrwbenc/inc/cnst.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*--------------------------------------------------------------------------* 19 | * CNST.H * 20 | *--------------------------------------------------------------------------* 21 | * Codec constant parameters (coder and decoder) * 22 | *--------------------------------------------------------------------------*/ 23 | 24 | #ifndef __CNST_H__ 25 | #define __CNST_H__ 26 | 27 | #define L_FRAME16k 320 /* Frame size at 16kHz */ 28 | #define L_FRAME 256 /* Frame size */ 29 | #define L_SUBFR16k 80 /* Subframe size at 16kHz */ 30 | 31 | #define L_SUBFR 64 /* Subframe size */ 32 | #define NB_SUBFR 4 /* Number of subframe per frame */ 33 | 34 | #define L_NEXT 64 /* Overhead in LP analysis */ 35 | #define L_WINDOW 384 /* window size in LP analysis */ 36 | #define L_TOTAL 384 /* Total size of speech buffer. */ 37 | #define M 16 /* Order of LP filter */ 38 | #define M16k 20 39 | 40 | #define L_FILT16k 15 /* Delay of down-sampling filter */ 41 | #define L_FILT 12 /* Delay of up-sampling filter */ 42 | 43 | #define GP_CLIP 15565 /* Pitch gain clipping = 0.95 Q14 */ 44 | #define PIT_SHARP 27853 /* pitch sharpening factor = 0.85 Q15 */ 45 | 46 | #define PIT_MIN 34 /* Minimum pitch lag with resolution 1/4 */ 47 | #define PIT_FR2 128 /* Minimum pitch lag with resolution 1/2 */ 48 | #define PIT_FR1_9b 160 /* Minimum pitch lag with resolution 1 */ 49 | #define PIT_FR1_8b 92 /* Minimum pitch lag with resolution 1 */ 50 | #define PIT_MAX 231 /* Maximum pitch lag */ 51 | #define L_INTERPOL (16+1) /* Length of filter for interpolation */ 52 | 53 | #define OPL_DECIM 2 /* Decimation in open-loop pitch analysis */ 54 | 55 | #define PREEMPH_FAC 22282 /* preemphasis factor (0.68 in Q15) */ 56 | #define GAMMA1 30147 /* Weighting factor (numerator) (0.92 in Q15) */ 57 | #define TILT_FAC 22282 /* tilt factor (denominator) (0.68 in Q15) */ 58 | 59 | #define Q_MAX 8 /* scaling max for signal (see syn_filt_32) */ 60 | 61 | #define RANDOM_INITSEED 21845 /* own random init value */ 62 | 63 | #define L_MEANBUF 3 64 | #define ONE_PER_MEANBUF 10923 65 | 66 | #define MODE_7k 0 67 | #define MODE_9k 1 68 | #define MODE_12k 2 69 | #define MODE_14k 3 70 | #define MODE_16k 4 71 | #define MODE_18k 5 72 | #define MODE_20k 6 73 | #define MODE_23k 7 74 | #define MODE_24k 8 75 | #define MRDTX 9 76 | #define NUM_OF_MODES 10 /* see bits.h for bits definition */ 77 | 78 | #define EHF_MASK (Word16)0x0008 /* homing frame pattern */ 79 | 80 | #endif //__CNST_H__ 81 | 82 | -------------------------------------------------------------------------------- /amrwbenc/inc/cod_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*--------------------------------------------------------------------------* 19 | * COD_MAIN.H * 20 | *--------------------------------------------------------------------------* 21 | * Static memory in the encoder * 22 | *--------------------------------------------------------------------------*/ 23 | #ifndef __COD_MAIN_H__ 24 | #define __COD_MAIN_H__ 25 | 26 | #include "cnst.h" /* coder constant parameters */ 27 | 28 | #include "wb_vad.h" 29 | #include "dtx.h" 30 | #include "stream.h" 31 | #include "voAMRWB.h" 32 | 33 | typedef struct 34 | { 35 | Word16 mem_decim[2 * L_FILT16k]; /* speech decimated filter memory */ 36 | Word16 mem_sig_in[6]; /* hp50 filter memory */ 37 | Word16 mem_preemph; /* speech preemph filter memory */ 38 | Word16 old_speech[L_TOTAL - L_FRAME]; /* old speech vector at 12.8kHz */ 39 | Word16 old_wsp[PIT_MAX / OPL_DECIM]; /* old decimated weighted speech vector */ 40 | Word16 old_exc[PIT_MAX + L_INTERPOL]; /* old excitation vector */ 41 | Word16 mem_levinson[M + 2]; /* levinson routine memory */ 42 | Word16 ispold[M]; /* old isp (immittance spectral pairs) */ 43 | Word16 ispold_q[M]; /* quantized old isp */ 44 | Word16 past_isfq[M]; /* past isf quantizer */ 45 | Word16 mem_wsp; /* wsp vector memory */ 46 | Word16 mem_decim2[3]; /* wsp decimation filter memory */ 47 | Word16 mem_w0; /* target vector memory */ 48 | Word16 mem_syn[M]; /* synthesis memory */ 49 | Word16 tilt_code; /* tilt of code */ 50 | Word16 old_wsp_max; /* old wsp maximum value */ 51 | Word16 old_wsp_shift; /* old wsp shift */ 52 | Word16 Q_old; /* old scaling factor */ 53 | Word16 Q_max[2]; /* old maximum scaling factor */ 54 | Word16 gp_clip[2]; /* gain of pitch clipping memory */ 55 | Word16 qua_gain[4]; /* gain quantizer memory */ 56 | 57 | Word16 old_T0_med; 58 | Word16 ol_gain; 59 | Word16 ada_w; 60 | Word16 ol_wght_flg; 61 | Word16 old_ol_lag[5]; 62 | Word16 hp_wsp_mem[9]; 63 | Word16 old_hp_wsp[L_FRAME / OPL_DECIM + (PIT_MAX / OPL_DECIM)]; 64 | VadVars *vadSt; 65 | dtx_encState *dtx_encSt; 66 | Word16 first_frame; 67 | Word16 isfold[M]; /* old isf (frequency domain) */ 68 | Word32 L_gc_thres; /* threshold for noise enhancer */ 69 | Word16 mem_syn_hi[M]; /* modified synthesis memory (MSB) */ 70 | Word16 mem_syn_lo[M]; /* modified synthesis memory (LSB) */ 71 | Word16 mem_deemph; /* speech deemph filter memory */ 72 | Word16 mem_sig_out[6]; /* hp50 filter memory for synthesis */ 73 | Word16 mem_hp400[6]; /* hp400 filter memory for synthesis */ 74 | Word16 mem_oversamp[2 * L_FILT]; /* synthesis oversampled filter memory */ 75 | Word16 mem_syn_hf[M]; /* HF synthesis memory */ 76 | Word16 mem_hf[2 * L_FILT16k]; /* HF band-pass filter memory */ 77 | Word16 mem_hf2[2 * L_FILT16k]; /* HF band-pass filter memory */ 78 | Word16 seed2; /* random memory for HF generation */ 79 | Word16 vad_hist; 80 | Word16 gain_alpha; 81 | /* TX_State structure */ 82 | Word16 sid_update_counter; 83 | Word16 sid_handover_debt; 84 | Word16 prev_ft; 85 | Word16 allow_dtx; 86 | /*some input/output buffer parameters */ 87 | unsigned char *inputStream; 88 | int inputSize; 89 | VOAMRWBMODE mode; 90 | VOAMRWBFRAMETYPE frameType; 91 | unsigned short *outputStream; 92 | int outputSize; 93 | FrameStream *stream; 94 | VO_MEM_OPERATOR *pvoMemop; 95 | VO_MEM_OPERATOR voMemoprator; 96 | VO_PTR hCheck; 97 | } Coder_State; 98 | 99 | typedef void* HAMRENC; 100 | 101 | #endif //__COD_MAIN_H__ 102 | 103 | 104 | -------------------------------------------------------------------------------- /amrwbenc/inc/dtx.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*--------------------------------------------------------------------------* 19 | * DTX.H * 20 | *--------------------------------------------------------------------------* 21 | * Static memory, constants and frametypes for the DTX * 22 | *--------------------------------------------------------------------------*/ 23 | 24 | #ifndef __DTX_H__ 25 | #define __DTX_H__ 26 | 27 | #define DTX_MAX_EMPTY_THRESH 50 28 | #define DTX_HIST_SIZE 8 29 | #define DTX_HIST_SIZE_MIN_ONE 7 30 | #define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1) 31 | #define DTX_HANG_CONST 7 /* yields eight frames of SP HANGOVER */ 32 | #define INV_MED_THRESH 14564 33 | #define ISF_GAP 128 /* 50 */ 34 | #define ONE_MINUS_ISF_GAP 16384 - ISF_GAP 35 | #define ISF_GAP 128 36 | #define ISF_DITH_GAP 448 37 | #define ISF_FACTOR_LOW 256 38 | #define ISF_FACTOR_STEP 2 39 | #define GAIN_THR 180 40 | #define GAIN_FACTOR 75 41 | 42 | typedef struct 43 | { 44 | Word16 isf_hist[M * DTX_HIST_SIZE]; 45 | Word16 log_en_hist[DTX_HIST_SIZE]; 46 | Word16 hist_ptr; 47 | Word16 log_en_index; 48 | Word16 cng_seed; 49 | /* DTX handler stuff */ 50 | Word16 dtxHangoverCount; 51 | Word16 decAnaElapsedCount; 52 | Word32 D[28]; 53 | Word32 sumD[DTX_HIST_SIZE]; 54 | } dtx_encState; 55 | 56 | #define SPEECH 0 57 | #define DTX 1 58 | #define DTX_MUTE 2 59 | 60 | #define TX_SPEECH 0 61 | #define TX_SID_FIRST 1 62 | #define TX_SID_UPDATE 2 63 | #define TX_NO_DATA 3 64 | 65 | #define RX_SPEECH_GOOD 0 66 | #define RX_SPEECH_PROBABLY_DEGRADED 1 67 | #define RX_SPEECH_LOST 2 68 | #define RX_SPEECH_BAD 3 69 | #define RX_SID_FIRST 4 70 | #define RX_SID_UPDATE 5 71 | #define RX_SID_BAD 6 72 | #define RX_NO_DATA 7 73 | 74 | /***************************************************************************** 75 | * 76 | * DEFINITION OF DATA TYPES 77 | *****************************************************************************/ 78 | 79 | Word16 dtx_enc_init(dtx_encState ** st, Word16 isf_init[], VO_MEM_OPERATOR *pMemOP); 80 | Word16 dtx_enc_reset(dtx_encState * st, Word16 isf_init[]); 81 | void dtx_enc_exit(dtx_encState ** st, VO_MEM_OPERATOR *pMemOP); 82 | 83 | Word16 dtx_enc( 84 | dtx_encState * st, /* i/o : State struct */ 85 | Word16 isf[M], /* o : CN ISF vector */ 86 | Word16 * exc2, /* o : CN excitation */ 87 | Word16 ** prms 88 | ); 89 | 90 | Word16 dtx_buffer( 91 | dtx_encState * st, /* i/o : State struct */ 92 | Word16 isf_new[], /* i : isf vector */ 93 | Word32 enr, /* i : residual energy (in L_FRAME) */ 94 | Word16 codec_mode 95 | ); 96 | 97 | void tx_dtx_handler(dtx_encState * st, /* i/o : State struct */ 98 | Word16 vad_flag, /* i : vad decision */ 99 | Word16 * usedMode /* i/o : mode changed or not */ 100 | ); 101 | 102 | void Qisf_ns( 103 | Word16 * isf1, /* input : ISF in the frequency domain (0..0.5) */ 104 | Word16 * isf_q, /* output: quantized ISF */ 105 | Word16 * indice /* output: quantization indices */ 106 | ); 107 | 108 | 109 | void Disf_ns( 110 | Word16 * indice, /* input: quantization indices */ 111 | Word16 * isf_q /* input : ISF in the frequency domain (0..0.5) */ 112 | ); 113 | 114 | #endif //__DTX_H__ 115 | 116 | -------------------------------------------------------------------------------- /amrwbenc/inc/grid100.tab: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | 19 | /*-------------------------------------------------------------* 20 | * Table for az_isp() * 21 | * * 22 | * Vector grid[] is in Q15 * 23 | * * 24 | * grid[0] = 1.0; * 25 | * grid[grid_points+1] = -1.0; * 26 | * for (i = 1; i < grid_points; i++) * 27 | * grid[i] = cos((6.283185307*i)/(2.0*grid_points)); * 28 | * * 29 | *-------------------------------------------------------------*/ 30 | 31 | /* Version 101 points */ 32 | 33 | #define GRID_POINTS 100 34 | 35 | const Word16 vogrid[GRID_POINTS+1] ={ 36 | 32767, 32751, 32703, 32622, 32509, 32364, 37 | 32187, 31978, 31738, 31466, 31164, 30830, 38 | 30466, 30072, 29649, 29196, 28714, 28204, 39 | 27666, 27101, 26509, 25891, 25248, 24579, 40 | 23886, 23170, 22431, 21669, 20887, 20083, 41 | 19260, 18418, 17557, 16680, 15786, 14876, 42 | 13951, 13013, 12062, 11099, 10125, 9141, 43 | 8149, 7148, 6140, 5126, 4106, 3083, 44 | 2057, 1029, 0, -1029, -2057, -3083, 45 | -4106, -5126, -6140, -7148, -8149, -9141, 46 | -10125, -11099, -12062, -13013, -13951, -14876, 47 | -15786, -16680, -17557, -18418, -19260, -20083, 48 | -20887, -21669, -22431, -23170, -23886, -24579, 49 | -25248, -25891, -26509, -27101, -27666, -28204, 50 | -28714, -29196, -29649, -30072, -30466, -30830, 51 | -31164, -31466, -31738, -31978, -32187, -32364, 52 | -32509, -32622, -32703, -32751, -32760}; 53 | 54 | -------------------------------------------------------------------------------- /amrwbenc/inc/ham_wind.tab: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /* Hamming_cos window for LPC analysis. */ 19 | /* Create with function hamm_cos(window,384-128,128) */ 20 | 21 | #define L_WINDOW 384 22 | 23 | const Word16 vo_window[L_WINDOW] = { 24 | 2621, 2622, 2626, 2632, 2640, 2650, 2662, 2677, 25 | 2694, 2714, 2735, 2759, 2785, 2814, 2844, 2877, 26 | 2912, 2949, 2989, 3031, 3075, 3121, 3169, 3220, 27 | 3273, 3328, 3385, 3444, 3506, 3569, 3635, 3703, 28 | 3773, 3845, 3919, 3996, 4074, 4155, 4237, 4321, 29 | 4408, 4496, 4587, 4680, 4774, 4870, 4969, 5069, 30 | 5171, 5275, 5381, 5489, 5599, 5710, 5824, 5939, 31 | 6056, 6174, 6295, 6417, 6541, 6666, 6793, 6922, 32 | 7052, 7185, 7318, 7453, 7590, 7728, 7868, 8009, 33 | 8152, 8296, 8442, 8589, 8737, 8887, 9038, 9191, 34 | 9344, 9499, 9655, 9813, 9971, 10131, 10292, 10454, 35 | 10617, 10781, 10946, 11113, 11280, 11448, 11617, 11787, 36 | 11958, 12130, 12303, 12476, 12650, 12825, 13001, 13178, 37 | 13355, 13533, 13711, 13890, 14070, 14250, 14431, 14612, 38 | 14793, 14975, 15158, 15341, 15524, 15708, 15891, 16076, 39 | 16260, 16445, 16629, 16814, 16999, 17185, 17370, 17555, 40 | 17740, 17926, 18111, 18296, 18481, 18666, 18851, 19036, 41 | 19221, 19405, 19589, 19773, 19956, 20139, 20322, 20504, 42 | 20686, 20867, 21048, 21229, 21408, 21588, 21767, 21945, 43 | 22122, 22299, 22475, 22651, 22825, 22999, 23172, 23344, 44 | 23516, 23686, 23856, 24025, 24192, 24359, 24525, 24689, 45 | 24853, 25016, 25177, 25337, 25496, 25654, 25811, 25967, 46 | 26121, 26274, 26426, 26576, 26725, 26873, 27019, 27164, 47 | 27308, 27450, 27590, 27729, 27867, 28003, 28137, 28270, 48 | 28401, 28531, 28659, 28785, 28910, 29033, 29154, 29274, 49 | 29391, 29507, 29622, 29734, 29845, 29953, 30060, 30165, 50 | 30268, 30370, 30469, 30566, 30662, 30755, 30847, 30936, 51 | 31024, 31109, 31193, 31274, 31354, 31431, 31506, 31579, 52 | 31651, 31719, 31786, 31851, 31914, 31974, 32032, 32088, 53 | 32142, 32194, 32243, 32291, 32336, 32379, 32419, 32458, 54 | 32494, 32528, 32560, 32589, 32617, 32642, 32664, 32685, 55 | 32703, 32719, 32733, 32744, 32753, 32760, 32764, 32767, 56 | 32767, 32765, 32757, 32745, 32727, 32705, 32678, 32646, 57 | 32609, 32567, 32520, 32468, 32411, 32349, 32283, 32211, 58 | 32135, 32054, 31968, 31877, 31781, 31681, 31575, 31465, 59 | 31351, 31231, 31107, 30978, 30844, 30706, 30563, 30415, 60 | 30263, 30106, 29945, 29779, 29609, 29434, 29255, 29071, 61 | 28883, 28691, 28494, 28293, 28087, 27878, 27664, 27446, 62 | 27224, 26997, 26767, 26533, 26294, 26052, 25806, 25555, 63 | 25301, 25043, 24782, 24516, 24247, 23974, 23698, 23418, 64 | 23134, 22847, 22557, 22263, 21965, 21665, 21361, 21054, 65 | 20743, 20430, 20113, 19794, 19471, 19146, 18817, 18486, 66 | 18152, 17815, 17476, 17134, 16789, 16442, 16092, 15740, 67 | 15385, 15028, 14669, 14308, 13944, 13579, 13211, 12841, 68 | 12470, 12096, 11721, 11344, 10965, 10584, 10202, 9819, 69 | 9433, 9047, 8659, 8270, 7879, 7488, 7095, 6701, 70 | 6306, 5910, 5514, 5116, 4718, 4319, 3919, 3519, 71 | 3118, 2716, 2315, 1913, 1510, 1108, 705, 302}; 72 | 73 | 74 | -------------------------------------------------------------------------------- /amrwbenc/inc/homing.tab: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ** Copyright 2003-2010, VisualOn, Inc. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | 19 | 20 | #define DHF_PARMS_MAX 32 /* homing frame pattern */ 21 | #define NUM_OF_SPMODES 9 22 | 23 | #define PRML 15 24 | #define PRMN_7k NBBITS_7k/PRML + 1 25 | #define PRMN_9k NBBITS_9k/PRML + 1 26 | #define PRMN_12k NBBITS_12k/PRML + 1 27 | #define PRMN_14k NBBITS_14k/PRML + 1 28 | #define PRMN_16k NBBITS_16k/PRML + 1 29 | #define PRMN_18k NBBITS_18k/PRML + 1 30 | #define PRMN_20k NBBITS_20k/PRML + 1 31 | #define PRMN_23k NBBITS_23k/PRML + 1 32 | #define PRMN_24k NBBITS_24k/PRML + 1 33 | 34 | static const Word16 dfh_M7k[PRMN_7k] = 35 | { 36 | 3168, 29954, 29213, 16121, 37 | 64, 13440, 30624, 16430, 38 | 19008 39 | }; 40 | 41 | static const Word16 dfh_M9k[PRMN_9k] = 42 | { 43 | 3168, 31665, 9943, 9123, 44 | 15599, 4358, 20248, 2048, 45 | 17040, 27787, 16816, 13888 46 | }; 47 | 48 | static const Word16 dfh_M12k[PRMN_12k] = 49 | { 50 | 3168, 31665, 9943, 9128, 51 | 3647, 8129, 30930, 27926, 52 | 18880, 12319, 496, 1042, 53 | 4061, 20446, 25629, 28069, 54 | 13948 55 | }; 56 | 57 | static const Word16 dfh_M14k[PRMN_14k] = 58 | { 59 | 3168, 31665, 9943, 9131, 60 | 24815, 655, 26616, 26764, 61 | 7238, 19136, 6144, 88, 62 | 4158, 25733, 30567, 30494, 63 | 221, 20321, 17823 64 | }; 65 | 66 | static const Word16 dfh_M16k[PRMN_16k] = 67 | { 68 | 3168, 31665, 9943, 9131, 69 | 24815, 700, 3824, 7271, 70 | 26400, 9528, 6594, 26112, 71 | 108, 2068, 12867, 16317, 72 | 23035, 24632, 7528, 1752, 73 | 6759, 24576 74 | }; 75 | 76 | static const Word16 dfh_M18k[PRMN_18k] = 77 | { 78 | 3168, 31665, 9943, 9135, 79 | 14787, 14423, 30477, 24927, 80 | 25345, 30154, 916, 5728, 81 | 18978, 2048, 528, 16449, 82 | 2436, 3581, 23527, 29479, 83 | 8237, 16810, 27091, 19052, 84 | 0 85 | }; 86 | 87 | static const Word16 dfh_M20k[PRMN_20k] = 88 | { 89 | 3168, 31665, 9943, 9129, 90 | 8637, 31807, 24646, 736, 91 | 28643, 2977, 2566, 25564, 92 | 12930, 13960, 2048, 834, 93 | 3270, 4100, 26920, 16237, 94 | 31227, 17667, 15059, 20589, 95 | 30249, 29123, 0 96 | }; 97 | 98 | static const Word16 dfh_M23k[PRMN_23k] = 99 | { 100 | 3168, 31665, 9943, 9132, 101 | 16748, 3202, 28179, 16317, 102 | 30590, 15857, 19960, 8818, 103 | 21711, 21538, 4260, 16690, 104 | 20224, 3666, 4194, 9497, 105 | 16320, 15388, 5755, 31551, 106 | 14080, 3574, 15932, 50, 107 | 23392, 26053, 31216 108 | }; 109 | 110 | static const Word16 dfh_M24k[PRMN_24k] = 111 | { 112 | 3168, 31665, 9943, 9134, 113 | 24776, 5857, 18475, 28535, 114 | 29662, 14321, 16725, 4396, 115 | 29353, 10003, 17068, 20504, 116 | 720, 0, 8465, 12581, 117 | 28863, 24774, 9709, 26043, 118 | 7941, 27649, 13965, 15236, 119 | 18026, 22047, 16681, 3968 120 | }; 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /amrwbenc/inc/isp_isf.tab: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*-----------------------------------------------------* 19 | | Tables for function Isf_isp() and Isp_isf() | 20 | *-----------------------------------------------------*/ 21 | 22 | /* table of cos(x) in Q15 */ 23 | 24 | static const Word16 table[129] = { 25 | 32767, 26 | 32758, 32729, 32679, 32610, 32522, 32413, 32286, 32138, 27 | 31972, 31786, 31581, 31357, 31114, 30853, 30572, 30274, 28 | 29957, 29622, 29269, 28899, 28511, 28106, 27684, 27246, 29 | 26791, 26320, 25833, 25330, 24812, 24279, 23732, 23170, 30 | 22595, 22006, 21403, 20788, 20160, 19520, 18868, 18205, 31 | 17531, 16846, 16151, 15447, 14733, 14010, 13279, 12540, 32 | 11793, 11039, 10279, 9512, 8740, 7962, 7180, 6393, 33 | 5602, 4808, 4011, 3212, 2411, 1608, 804, 0, 34 | -804, -1608, -2411, -3212, -4011, -4808, -5602, -6393, 35 | -7180, -7962, -8740, -9512, -10279, -11039, -11793, -12540, 36 | -13279, -14010, -14733, -15447, -16151, -16846, -17531, -18205, 37 | -18868, -19520, -20160, -20788, -21403, -22006, -22595, -23170, 38 | -23732, -24279, -24812, -25330, -25833, -26320, -26791, -27246, 39 | -27684, -28106, -28511, -28899, -29269, -29622, -29957, -30274, 40 | -30572, -30853, -31114, -31357, -31581, -31786, -31972, -32138, 41 | -32286, -32413, -32522, -32610, -32679, -32729, -32758, -32768}; 42 | 43 | /* slope in Q11 used to compute y = acos(x) */ 44 | 45 | static const Word16 slope[128] = { 46 | -26214, -9039, -5243, -3799, -2979, -2405, -2064, -1771, 47 | -1579, -1409, -1279, -1170, -1079, -1004, -933, -880, 48 | -827, -783, -743, -708, -676, -647, -621, -599, 49 | -576, -557, -538, -521, -506, -492, -479, -466, 50 | -456, -445, -435, -426, -417, -410, -402, -395, 51 | -389, -383, -377, -372, -367, -363, -359, -355, 52 | -351, -348, -345, -342, -340, -337, -335, -333, 53 | -331, -330, -329, -328, -327, -326, -326, -326, 54 | -326, -326, -326, -327, -328, -329, -330, -331, 55 | -333, -335, -337, -340, -342, -345, -348, -351, 56 | -355, -359, -363, -367, -372, -377, -383, -389, 57 | -395, -402, -410, -417, -426, -435, -445, -456, 58 | -466, -479, -492, -506, -521, -538, -557, -576, 59 | -599, -621, -647, -676, -708, -743, -783, -827, 60 | -880, -933, -1004, -1079, -1170, -1279, -1409, -1579, 61 | -1771, -2064, -2405, -2979, -3799, -5243, -9039, -26214}; 62 | 63 | -------------------------------------------------------------------------------- /amrwbenc/inc/lag_wind.tab: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*-----------------------------------------------------* 19 | | Table of lag_window for autocorrelation. | 20 | | noise floor = 1.0001 = (0.9999 on r[1] ..r[16]) | 21 | | Bandwidth expansion = 60 Hz | 22 | | Sampling frequency = 12800 Hz | 23 | | | 24 | | Special double precision format. See "math_op.c" | 25 | | | 26 | | lag_wind[0] = 1.00000000 (not stored) | 27 | | lag_wind[1] = 0.99946642 | 28 | | lag_wind[2] = 0.99816680 | 29 | | lag_wind[3] = 0.99600452 | 30 | | lag_wind[4] = 0.99298513 | 31 | | lag_wind[5] = 0.98911655 | 32 | | lag_wind[6] = 0.98440880 | 33 | | lag_wind[7] = 0.97887397 | 34 | | lag_wind[8] = 0.97252619 | 35 | | lag_wind[9] = 0.96538186 | 36 | | lag_wind[10]= 0.95745903 | 37 | | lag_wind[11]= 0.94877797 | 38 | | lag_wind[12]= 0.93936038 | 39 | | lag_wind[13]= 0.92922986 | 40 | | lag_wind[14]= 0.91841155 | 41 | | lag_wind[15]= 0.90693212 | 42 | | lag_wind[16]= 0.89481968 | 43 | ------------------------------------------------------*/ 44 | 45 | #define M 16 46 | 47 | static Word16 volag_h[M] = { 48 | 32750, 49 | 32707, 50 | 32637, 51 | 32538, 52 | 32411, 53 | 32257, 54 | 32075, 55 | 31867, 56 | 31633, 57 | 31374, 58 | 31089, 59 | 30780, 60 | 30449, 61 | 30094, 62 | 29718, 63 | 29321}; 64 | 65 | static Word16 volag_l[M] = { 66 | 16896, 67 | 30464, 68 | 2496, 69 | 4480, 70 | 12160, 71 | 3520, 72 | 24320, 73 | 24192, 74 | 20736, 75 | 576, 76 | 18240, 77 | 31488, 78 | 128, 79 | 16704, 80 | 11520, 81 | 14784}; 82 | -------------------------------------------------------------------------------- /amrwbenc/inc/log2.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ** Copyright 2003-2010, VisualOn, Inc. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | 19 | /******************************************************************************** 20 | * 21 | * File : log2.h 22 | * Purpose : Computes log2(L_x) 23 | * 24 | ******************************************************************************** 25 | */ 26 | #ifndef __LOG2_H__ 27 | #define __LOG2_H__ 28 | 29 | /* 30 | ******************************************************************************** 31 | * INCLUDE FILES 32 | ******************************************************************************** 33 | */ 34 | #include "typedef.h" 35 | 36 | /* 37 | ******************************************************************************** 38 | * DEFINITION OF DATA TYPES 39 | ******************************************************************************** 40 | */ 41 | 42 | /* 43 | ******************************************************************************** 44 | * DECLARATION OF PROTOTYPES 45 | ******************************************************************************** 46 | */ 47 | void Log2 ( 48 | Word32 L_x, /* (i) : input value */ 49 | Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */ 50 | Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1)*/ 51 | ); 52 | 53 | void Log2_norm ( 54 | Word32 L_x, /* (i) : input value (normalized) */ 55 | Word16 exp, /* (i) : norm_l (L_x) */ 56 | Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */ 57 | Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */ 58 | ); 59 | 60 | #endif //__LOG2_H__ 61 | 62 | 63 | -------------------------------------------------------------------------------- /amrwbenc/inc/log2_tab.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ** Copyright 2003-2010, VisualOn, Inc. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | 19 | 20 | /******************************************************************************* 21 | * 22 | * File : log2.tab 23 | * Purpose : Table for routine Log2(). 24 | * $Id $ 25 | * 26 | ******************************************************************************** 27 | */ 28 | static const Word16 table[33] = 29 | { 30 | 0, 1455, 2866, 4236, 5568, 6863, 8124, 9352, 10549, 11716, 31 | 12855, 13967, 15054, 16117, 17156, 18172, 19167, 20142, 21097, 22033, 32 | 22951, 23852, 24735, 25603, 26455, 27291, 28113, 28922, 29716, 30497, 33 | 31266, 32023, 32767 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /amrwbenc/inc/main.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ** Copyright 2003-2010, VisualOn, Inc. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | 19 | /*--------------------------------------------------------------------------* 20 | * MAIN.H * 21 | *--------------------------------------------------------------------------* 22 | * Main functions * 23 | *--------------------------------------------------------------------------*/ 24 | 25 | #ifndef __MAIN_H__ 26 | #define __MAIN_H__ 27 | 28 | void coder( 29 | Word16 * mode, /* input : used mode */ 30 | Word16 speech16k[], /* input : 320 new speech samples (at 16 kHz) */ 31 | Word16 prms[], /* output: output parameters */ 32 | Word16 * ser_size, /* output: bit rate of the used mode */ 33 | void *spe_state, /* i/o : State structure */ 34 | Word16 allow_dtx /* input : DTX ON/OFF */ 35 | ); 36 | 37 | 38 | 39 | void Reset_encoder(void *st, Word16 reset_all); 40 | 41 | 42 | Word16 encoder_homing_frame_test(Word16 input_frame[]); 43 | 44 | #endif //__MAIN_H__ 45 | 46 | -------------------------------------------------------------------------------- /amrwbenc/inc/math_op.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*--------------------------------------------------------------------------* 19 | * MATH_OP.H * 20 | *--------------------------------------------------------------------------* 21 | * Mathematical operations * 22 | *--------------------------------------------------------------------------*/ 23 | 24 | #ifndef __MATH_OP_H__ 25 | #define __MATH_OP_H__ 26 | 27 | Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */ 28 | Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ 29 | ); 30 | 31 | void Isqrt_n( 32 | Word32 * frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */ 33 | Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */ 34 | ); 35 | 36 | Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ 37 | Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ 38 | Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ 39 | ); 40 | 41 | Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ 42 | Word16 x[], /* (i) 12bits: x vector */ 43 | Word16 y[], /* (i) 12bits: y vector */ 44 | Word16 lg, /* (i) : vector length */ 45 | Word16 * exp /* (o) : exponent of result (0..+30) */ 46 | ); 47 | 48 | Word32 Dot_product12_asm( /* (o) Q31: normalized result (1 < val <= -1) */ 49 | Word16 x[], /* (i) 12bits: x vector */ 50 | Word16 y[], /* (i) 12bits: y vector */ 51 | Word16 lg, /* (i) : vector length */ 52 | Word16 * exp /* (o) : exponent of result (0..+30) */ 53 | ); 54 | #endif //__MATH_OP_H__ 55 | 56 | -------------------------------------------------------------------------------- /amrwbenc/inc/mem_align.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: mem_align.h 18 | 19 | Content: Memory alloc alignments functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __VO_MEM_ALIGN_H__ 24 | #define __VO_MEM_ALIGN_H__ 25 | 26 | #include "voMem.h" 27 | #include "typedef.h" 28 | 29 | extern void *mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID); 30 | extern void mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID); 31 | 32 | #endif /* __VO_MEM_ALIGN_H__ */ 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /amrwbenc/inc/oper_32b.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /* Double precision operations */ 19 | /* $Id$ */ 20 | 21 | #ifndef __OPER_32B_H__ 22 | #define __OPER_32B_H__ 23 | 24 | void VO_L_Extract (Word32 L_32, Word16 *hi, Word16 *lo); 25 | Word32 L_Comp (Word16 hi, Word16 lo); 26 | Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2); 27 | Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n); 28 | Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo); 29 | 30 | #endif //__OPER_32B_H__ 31 | 32 | -------------------------------------------------------------------------------- /amrwbenc/inc/p_med_o.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*--------------------------------------------------------------------------* 18 | * P_MED_O.H * 19 | *--------------------------------------------------------------------------* 20 | * Median open-loop lag search * 21 | *--------------------------------------------------------------------------*/ 22 | 23 | #ifndef __P_MED_O_H__ 24 | #define __P_MED_O_H__ 25 | 26 | Word16 Pitch_med_ol( /* output: open loop pitch lag */ 27 | Word16 wsp[], /* input : signal used to compute the open loop pitch */ 28 | /* wsp[-pit_max] to wsp[-1] should be known */ 29 | Word16 L_min, /* input : minimum pitch lag */ 30 | Word16 L_max, /* input : maximum pitch lag */ 31 | Word16 L_frame, /* input : length of frame to compute pitch */ 32 | Word16 L_0, /* input : old_ open-loop pitch */ 33 | Word16 * gain, /* output: normalize correlation of hp_wsp for the Lag */ 34 | Word16 * hp_wsp_mem, /* i:o : memory of the hypass filter for hp_wsp[] (lg=9) */ 35 | Word16 * old_hp_wsp, /* i:o : hypass wsp[] */ 36 | Word16 wght_flg /* input : is weighting function used */ 37 | ); 38 | 39 | Word16 Med_olag( /* output : median of 5 previous open-loop lags */ 40 | Word16 prev_ol_lag, /* input : previous open-loop lag */ 41 | Word16 old_ol_lag[5] 42 | ); 43 | 44 | void Hp_wsp( 45 | Word16 wsp[], /* i : wsp[] signal */ 46 | Word16 hp_wsp[], /* o : hypass wsp[] */ 47 | Word16 lg, /* i : lenght of signal */ 48 | Word16 mem[] /* i/o : filter memory [9] */ 49 | ); 50 | 51 | #endif //__P_MED_O_H__ 52 | 53 | -------------------------------------------------------------------------------- /amrwbenc/inc/p_med_ol.tab: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ** Copyright 2003-2010, VisualOn, Inc. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | 19 | /*-----------------------------------------------------* 20 | | Table for function Pitch_med_ol() | 21 | *-----------------------------------------------------*/ 22 | 23 | static Word16 corrweight[199]= { 24 | 25 | 10772, 10794, 10816, 10839, 10862, 10885, 10908, 10932, 10955, 10980, 26 | 11004, 11029, 11054, 11079, 11105, 11131, 11157, 11183, 11210, 11238, 27 | 11265, 11293, 11322, 11350, 11379, 11409, 11439, 11469, 11500, 11531, 28 | 11563, 11595, 11628, 11661, 11694, 11728, 11763, 11798, 11834, 11870, 29 | 11907, 11945, 11983, 12022, 12061, 12101, 12142, 12184, 12226, 12270, 30 | 12314, 12358, 12404, 12451, 12498, 12547, 12596, 12647, 12699, 12751, 31 | 12805, 12861, 12917, 12975, 13034, 13095, 13157, 13221, 13286, 13353, 32 | 13422, 13493, 13566, 13641, 13719, 13798, 13880, 13965, 14053, 14143, 33 | 14237, 14334, 14435, 14539, 14648, 14761, 14879, 15002, 15130, 15265, 34 | 15406, 15554, 15710, 15874, 16056, 16384, 16384, 16384, 16384, 16384, 35 | 16384, 16384, 16056, 15874, 15710, 15554, 15406, 15265, 15130, 15002, 36 | 14879, 14761, 14648, 14539, 14435, 14334, 14237, 14143, 14053, 13965, 37 | 13880, 13798, 13719, 13641, 13566, 13493, 13422, 13353, 13286, 13221, 38 | 13157, 13095, 13034, 12975, 12917, 12861, 12805, 12751, 12699, 12647, 39 | 12596, 12547, 12498, 12451, 12404, 12358, 12314, 12270, 12226, 12184, 40 | 12142, 12101, 12061, 12022, 11983, 11945, 11907, 11870, 11834, 11798, 41 | 11763, 11728, 11694, 11661, 11628, 11595, 11563, 11531, 11500, 11469, 42 | 11439, 11409, 11379, 11350, 11322, 11293, 11265, 11238, 11210, 11183, 43 | 11157, 11131, 11105, 11079, 11054, 11029, 11004, 10980, 10955, 10932, 44 | 10908, 10885, 10862, 10839, 10816, 10794, 10772, 10750, 10728}; 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /amrwbenc/inc/q_pulse.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ** Copyright 2003-2010, VisualOn, Inc. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | 19 | /*--------------------------------------------------------------------------* 20 | * Q_PULSE.H * 21 | *--------------------------------------------------------------------------* 22 | * Coding and decoding of algebraic codebook * 23 | *--------------------------------------------------------------------------*/ 24 | 25 | #ifndef __Q_PULSE_H__ 26 | #define __Q_PULSE_H__ 27 | 28 | #include "typedef.h" 29 | 30 | Word32 quant_1p_N1( /* (o) return (N+1) bits */ 31 | Word16 pos, /* (i) position of the pulse */ 32 | Word16 N); /* (i) number of bits for position */ 33 | 34 | Word32 quant_2p_2N1( /* (o) return (2*N)+1 bits */ 35 | Word16 pos1, /* (i) position of the pulse 1 */ 36 | Word16 pos2, /* (i) position of the pulse 2 */ 37 | Word16 N); /* (i) number of bits for position */ 38 | 39 | Word32 quant_3p_3N1( /* (o) return (3*N)+1 bits */ 40 | Word16 pos1, /* (i) position of the pulse 1 */ 41 | Word16 pos2, /* (i) position of the pulse 2 */ 42 | Word16 pos3, /* (i) position of the pulse 3 */ 43 | Word16 N); /* (i) number of bits for position */ 44 | 45 | Word32 quant_4p_4N1( /* (o) return (4*N)+1 bits */ 46 | Word16 pos1, /* (i) position of the pulse 1 */ 47 | Word16 pos2, /* (i) position of the pulse 2 */ 48 | Word16 pos3, /* (i) position of the pulse 3 */ 49 | Word16 pos4, /* (i) position of the pulse 4 */ 50 | Word16 N); /* (i) number of bits for position */ 51 | 52 | Word32 quant_4p_4N( /* (o) return 4*N bits */ 53 | Word16 pos[], /* (i) position of the pulse 1..4 */ 54 | Word16 N); /* (i) number of bits for position */ 55 | 56 | Word32 quant_5p_5N( /* (o) return 5*N bits */ 57 | Word16 pos[], /* (i) position of the pulse 1..5 */ 58 | Word16 N); /* (i) number of bits for position */ 59 | 60 | Word32 quant_6p_6N_2( /* (o) return (6*N)-2 bits */ 61 | Word16 pos[], /* (i) position of the pulse 1..6 */ 62 | Word16 N); /* (i) number of bits for position */ 63 | 64 | 65 | #endif //__Q_PULSE_H__ 66 | 67 | -------------------------------------------------------------------------------- /amrwbenc/inc/stream.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ** Copyright 2003-2010, VisualOn, Inc. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | 19 | /*********************************************************************** 20 | File: stream.h 21 | 22 | Contains: VOME API Buffer Operator Implement Header 23 | 24 | ************************************************************************/ 25 | #ifndef __STREAM_H__ 26 | #define __STREAM_H__ 27 | 28 | #include "voMem.h" 29 | #define Frame_Maxsize 1024 * 2 //Work Buffer 10K 30 | #define Frame_MaxByte 640 //AMR_WB Encoder one frame 320 samples = 640 Bytes 31 | #define MIN(a,b) ((a) < (b)? (a) : (b)) 32 | 33 | typedef struct{ 34 | unsigned char *set_ptr; 35 | unsigned char *frame_ptr; 36 | unsigned char *frame_ptr_bk; 37 | int set_len; 38 | int framebuffer_len; 39 | int frame_storelen; 40 | int used_len; 41 | }FrameStream; 42 | 43 | void voAWB_UpdateFrameBuffer(FrameStream *stream, VO_MEM_OPERATOR *pMemOP); 44 | void voAWB_InitFrameBuffer(FrameStream *stream); 45 | void voAWB_FlushFrameBuffer(FrameStream *stream); 46 | #endif //__STREAM_H__ 47 | 48 | -------------------------------------------------------------------------------- /amrwbenc/inc/typedef.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * 19 | * File : typedef.c 20 | * Purpose : Basic types. 21 | * 22 | ************************************************************************/ 23 | 24 | #ifndef __TYPEDEF_H__ 25 | #define __TYPEDEF_H__ 26 | 27 | #undef ORIGINAL_TYPEDEF_H /* define to get "original" ETSI version 28 | of typedef.h */ 29 | 30 | #ifdef ORIGINAL_TYPEDEF_H 31 | /* 32 | * this is the original code from the ETSI file typedef.h 33 | */ 34 | 35 | #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(_MSC_VER) || defined(__ZTC__) 36 | typedef signed char Word8; 37 | typedef short Word16; 38 | typedef long Word32; 39 | typedef int Flag; 40 | 41 | #elif defined(__sun) 42 | typedef signed char Word8; 43 | typedef short Word16; 44 | typedef long Word32; 45 | typedef int Flag; 46 | 47 | #elif defined(__unix__) || defined(__unix) 48 | typedef signed char Word8; 49 | typedef short Word16; 50 | typedef int Word32; 51 | typedef int Flag; 52 | 53 | #endif 54 | #else /* not original typedef.h */ 55 | 56 | /* 57 | * use (improved) type definition file typdefs.h and add a "Flag" type 58 | */ 59 | #include "typedefs.h" 60 | typedef int Flag; 61 | 62 | #endif 63 | 64 | #endif //__TYPEDEF_H__ 65 | 66 | -------------------------------------------------------------------------------- /amrwbenc/inc/wb_vad.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*-------------------------------------------------------------------* 19 | * WB_VAD.H * 20 | *-------------------------------------------------------------------* 21 | * Functions and static memory for Voice Activity Detection. * 22 | *-------------------------------------------------------------------*/ 23 | 24 | #ifndef __WB_VAD_H__ 25 | #define __WB_VAD_H__ 26 | 27 | /****************************************************************************** 28 | * INCLUDE FILES 29 | ******************************************************************************/ 30 | #include "typedef.h" 31 | #include "wb_vad_c.h" 32 | #include "voMem.h" 33 | 34 | /****************************************************************************** 35 | * DEFINITION OF DATA TYPES 36 | ******************************************************************************/ 37 | 38 | typedef struct 39 | { 40 | Word16 bckr_est[COMPLEN]; /* background noise estimate */ 41 | Word16 ave_level[COMPLEN]; /* averaged input components for stationary */ 42 | /* estimation */ 43 | Word16 old_level[COMPLEN]; /* input levels of the previous frame */ 44 | Word16 sub_level[COMPLEN]; /* input levels calculated at the end of a frame (lookahead) */ 45 | Word16 a_data5[F_5TH_CNT][2]; /* memory for the filter bank */ 46 | Word16 a_data3[F_3TH_CNT]; /* memory for the filter bank */ 47 | 48 | Word16 burst_count; /* counts length of a speech burst */ 49 | Word16 hang_count; /* hangover counter */ 50 | Word16 stat_count; /* stationary counter */ 51 | 52 | /* Note that each of the following two variables holds 15 flags. Each flag reserves 1 bit of the 53 | * variable. The newest flag is in the bit 15 (assuming that LSB is bit 1 and MSB is bit 16). */ 54 | Word16 vadreg; /* flags for intermediate VAD decisions */ 55 | Word16 tone_flag; /* tone detection flags */ 56 | 57 | Word16 sp_est_cnt; /* counter for speech level estimation */ 58 | Word16 sp_max; /* maximum level */ 59 | Word16 sp_max_cnt; /* counts frames that contains speech */ 60 | Word16 speech_level; /* estimated speech level */ 61 | Word32 prev_pow_sum; /* power of previous frame */ 62 | 63 | } VadVars; 64 | 65 | /******************************************************************************** 66 | * 67 | * DECLARATION OF PROTOTYPES 68 | ********************************************************************************/ 69 | 70 | Word16 wb_vad_init(VadVars ** st, VO_MEM_OPERATOR *pMemOP); 71 | Word16 wb_vad_reset(VadVars * st); 72 | void wb_vad_exit(VadVars ** st, VO_MEM_OPERATOR *pMemOP); 73 | void wb_vad_tone_detection(VadVars * st, Word16 p_gain); 74 | Word16 wb_vad(VadVars * st, Word16 in_buf[]); 75 | 76 | #endif //__WB_VAD_H__ 77 | 78 | 79 | -------------------------------------------------------------------------------- /amrwbenc/patent_disclaimer.txt: -------------------------------------------------------------------------------- 1 | 2 | THIS IS NOT A GRANT OF PATENT RIGHTS. 3 | 4 | Google makes no representation or warranty that the codecs for which 5 | source code is made available hereunder are unencumbered by 6 | third-party patents. Those intending to use this source code in 7 | hardware or software products are advised that implementations of 8 | these codecs, including in open source software or shareware, may 9 | require patent licenses from the relevant patent holders. 10 | -------------------------------------------------------------------------------- /amrwbenc/src/asm/ARMV5E/Deemph_32_opt.s: -------------------------------------------------------------------------------- 1 | @/* 2 | @ ** Copyright 2003-2010, VisualOn, Inc. 3 | @ ** 4 | @ ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | @ ** you may not use this file except in compliance with the License. 6 | @ ** You may obtain a copy of the License at 7 | @ ** 8 | @ ** http://www.apache.org/licenses/LICENSE-2.0 9 | @ ** 10 | @ ** Unless required by applicable law or agreed to in writing, software 11 | @ ** distributed under the License is distributed on an "AS IS" BASIS, 12 | @ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @ ** See the License for the specific language governing permissions and 14 | @ ** limitations under the License. 15 | @ */ 16 | 17 | @void Deemph_32( 18 | @ Word16 x_hi[], /* (i) : input signal (bit31..16) */ 19 | @ Word16 x_lo[], /* (i) : input signal (bit15..4) */ 20 | @ Word16 y[], /* (o) : output signal (x16) */ 21 | @ Word16 mu, /* (i) Q15 : deemphasis factor */ 22 | @ Word16 L, /* (i) : vector size */ 23 | @ Word16 * mem /* (i/o) : memory (y[-1]) */ 24 | @ ) 25 | 26 | @x_hi RN R0 27 | @x_lo RN R1 28 | @y[] RN R2 29 | @*mem RN R3 30 | 31 | .section .text 32 | .global Deemph_32_asm 33 | 34 | Deemph_32_asm: 35 | 36 | STMFD r13!, {r4 - r12, r14} 37 | MOV r4, #2 @i=0 38 | LDRSH r6, [r0], #2 @load x_hi[0] 39 | LDRSH r7, [r1], #2 @load x_lo[0] 40 | LDR r5, =22282 @r5---mu 41 | MOV r11, #0x8000 42 | 43 | @y[0] 44 | MOV r10, r6, LSL #16 @L_tmp = x_hi[0]<<16 45 | MOV r8, r5, ASR #1 @fac = mu >> 1 46 | LDR r5, [r3] 47 | ADD r12, r10, r7, LSL #4 @L_tmp += x_lo[0] << 4 48 | MOV r10, r12, LSL #3 @L_tmp <<= 3 49 | MUL r9, r5, r8 50 | LDRSH r6, [r0], #2 @load x_hi[1] 51 | QDADD r10, r10, r9 52 | LDRSH r7, [r1], #2 @load x_lo[1] 53 | MOV r12, r10, LSL #1 @L_tmp = L_mac(L_tmp, *mem, fac) 54 | QADD r10, r12, r11 55 | MOV r14, r10, ASR #16 @y[0] = round(L_tmp) 56 | 57 | 58 | MOV r10, r6, LSL #16 59 | ADD r12, r10, r7, LSL #4 60 | STRH r14, [r2], #2 @update y[0] 61 | MOV r10, r12, LSL #3 62 | MUL r9, r14, r8 63 | QDADD r10, r10, r9 64 | MOV r12, r10, LSL #1 65 | QADD r10, r12, r11 66 | MOV r14, r10, ASR #16 @y[1] = round(L_tmp) 67 | 68 | LOOP: 69 | LDRSH r6, [r0], #2 @load x_hi[] 70 | LDRSH r7, [r1], #2 71 | STRH r14, [r2], #2 72 | MOV r10, r6, LSL #16 73 | ADD r12, r10, r7, LSL #4 74 | MUL r9, r14, r8 75 | MOV r10, r12, LSL #3 76 | QDADD r10, r10, r9 77 | LDRSH r6, [r0], #2 @load x_hi[] 78 | MOV r12, r10, LSL #1 79 | QADD r10, r12, r11 80 | LDRSH r7, [r1], #2 81 | MOV r14, r10, ASR #16 82 | 83 | MOV r10, r6, LSL #16 84 | ADD r12, r10, r7, LSL #4 85 | STRH r14, [r2], #2 86 | MUL r9, r14, r8 87 | MOV r10, r12, LSL #3 88 | QDADD r10, r10, r9 89 | ADD r4, r4, #2 90 | MOV r12, r10, LSL #1 91 | QADD r10, r12, r11 92 | CMP r4, #64 93 | MOV r14, r10, ASR #16 94 | 95 | BLT LOOP 96 | STR r14, [r3] 97 | STRH r14, [r2] 98 | 99 | LDMFD r13!, {r4 - r12, r15} 100 | 101 | @ENDP 102 | .END 103 | 104 | 105 | -------------------------------------------------------------------------------- /amrwbenc/src/asm/ARMV5E/Dot_p_opt.s: -------------------------------------------------------------------------------- 1 | @/* 2 | @ ** Copyright 2003-2010, VisualOn, Inc. 3 | @ ** 4 | @ ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | @ ** you may not use this file except in compliance with the License. 6 | @ ** You may obtain a copy of the License at 7 | @ ** 8 | @ ** http://www.apache.org/licenses/LICENSE-2.0 9 | @ ** 10 | @ ** Unless required by applicable law or agreed to in writing, software 11 | @ ** distributed under the License is distributed on an "AS IS" BASIS, 12 | @ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @ ** See the License for the specific language governing permissions and 14 | @ ** limitations under the License. 15 | @ */ 16 | @ 17 | @Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ 18 | @ Word16 x[], /* (i) 12bits: x vector */ 19 | @ Word16 y[], /* (i) 12bits: y vector */ 20 | @ Word16 lg, /* (i) : vector length */ 21 | @ Word16 * exp /* (o) : exponent of result (0..+30) */ 22 | @) 23 | @**************************************************************** 24 | @ x[] --- r0 25 | @ y[] --- r1 26 | @ lg --- r2 27 | @ *exp --- r3 28 | 29 | .section .text 30 | .global Dot_product12_asm 31 | 32 | Dot_product12_asm: 33 | 34 | STMFD r13!, {r4 - r12, r14} 35 | MOV r4, #0 @ L_sum = 0 36 | MOV r5, #0 @ i = 0 37 | 38 | LOOP: 39 | LDR r6, [r0], #4 40 | LDR r7, [r1], #4 41 | LDR r8, [r0], #4 42 | SMLABB r4, r6, r7, r4 43 | LDR r9, [r1], #4 44 | SMLATT r4, r6, r7, r4 45 | 46 | LDR r6, [r0], #4 47 | SMLABB r4, r8, r9, r4 48 | 49 | LDR r7, [r1], #4 50 | SMLATT r4, r8, r9, r4 51 | LDR r8, [r0], #4 52 | 53 | SMLABB r4, r6, r7, r4 54 | LDR r9, [r1], #4 55 | SMLATT r4, r6, r7, r4 56 | ADD r5, r5, #8 57 | SMLABB r4, r8, r9, r4 58 | CMP r5, r2 59 | SMLATT r4, r8, r9, r4 60 | BLT LOOP 61 | 62 | MOV r12, r4, LSL #1 63 | ADD r12, r12, #1 @ L_sum = (L_sum << 1) + 1 64 | MOV r4, r12 65 | 66 | CMP r12, #0 67 | RSBLT r4, r12, #0 68 | CLZ r10, r4 69 | SUB r10, r10, #1 @ sft = norm_l(L_sum) 70 | MOV r0, r12, LSL r10 @ L_sum = L_sum << sft 71 | RSB r11, r10, #30 @ *exp = 30 - sft 72 | STRH r11, [r3] 73 | 74 | Dot_product12_end: 75 | 76 | LDMFD r13!, {r4 - r12, r15} 77 | @ENDFUNC 78 | .END 79 | 80 | 81 | -------------------------------------------------------------------------------- /amrwbenc/src/asm/ARMV5E/scale_sig_opt.s: -------------------------------------------------------------------------------- 1 | @/* 2 | @ ** Copyright 2003-2010, VisualOn, Inc. 3 | @ ** 4 | @ ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | @ ** you may not use this file except in compliance with the License. 6 | @ ** You may obtain a copy of the License at 7 | @ ** 8 | @ ** http://www.apache.org/licenses/LICENSE-2.0 9 | @ ** 10 | @ ** Unless required by applicable law or agreed to in writing, software 11 | @ ** distributed under the License is distributed on an "AS IS" BASIS, 12 | @ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @ ** See the License for the specific language governing permissions and 14 | @ ** limitations under the License. 15 | @ */ 16 | @ 17 | @void Scale_sig( 18 | @ Word16 x[], /* (i/o) : signal to scale */ 19 | @ Word16 lg, /* (i) : size of x[] */ 20 | @ Word16 exp /* (i) : exponent: x = round(x << exp) */ 21 | @ ) 22 | @ 23 | @r0 --- x[] 24 | @r1 --- lg 25 | @r2 --- exp 26 | 27 | .section .text 28 | .global Scale_sig_opt 29 | 30 | Scale_sig_opt: 31 | 32 | STMFD r13!, {r4 - r12, r14} 33 | SUB r3, r1, #1 @i = lg - 1 34 | CMP r2, #0 @Compare exp and 0 35 | RSB r7, r2, #0 @exp = -exp 36 | ADD r10, r2, #16 @16 + exp 37 | ADD r4, r0, r3, LSL #1 @x[i] address 38 | MOV r8, #0x7fffffff 39 | MOV r9, #0x8000 40 | BLE LOOP2 41 | 42 | LOOP1: 43 | 44 | LDRSH r5, [r4] @load x[i] 45 | MOV r12, r5, LSL r10 46 | TEQ r5, r12, ASR r10 47 | EORNE r12, r8, r5, ASR #31 48 | SUBS r3, r3, #1 49 | QADD r11, r12, r9 50 | MOV r12, r11, ASR #16 51 | STRH r12, [r4], #-2 52 | BGE LOOP1 53 | BL The_end 54 | 55 | LOOP2: 56 | 57 | LDRSH r5, [r4] @load x[i] 58 | MOV r6, r5, LSL #16 @L_tmp = x[i] << 16 59 | MOV r5, r6, ASR r7 @L_tmp >>= exp 60 | QADD r11, r5, r9 61 | MOV r12, r11, ASR #16 62 | SUBS r3, r3, #1 63 | STRH r12, [r4], #-2 64 | BGE LOOP2 65 | 66 | The_end: 67 | LDMFD r13!, {r4 - r12, r15} 68 | 69 | @ENDFUNC 70 | .END 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /amrwbenc/src/asm/ARMV7/Deemph_32_neon.s: -------------------------------------------------------------------------------- 1 | @/* 2 | @ ** Copyright 2003-2010, VisualOn, Inc. 3 | @ ** 4 | @ ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | @ ** you may not use this file except in compliance with the License. 6 | @ ** You may obtain a copy of the License at 7 | @ ** 8 | @ ** http://www.apache.org/licenses/LICENSE-2.0 9 | @ ** 10 | @ ** Unless required by applicable law or agreed to in writing, software 11 | @ ** distributed under the License is distributed on an "AS IS" BASIS, 12 | @ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @ ** See the License for the specific language governing permissions and 14 | @ ** limitations under the License. 15 | @ */ 16 | @ 17 | @void Deemph_32( 18 | @ Word16 x_hi[], /* (i) : input signal (bit31..16) */ 19 | @ Word16 x_lo[], /* (i) : input signal (bit15..4) */ 20 | @ Word16 y[], /* (o) : output signal (x16) */ 21 | @ Word16 mu, /* (i) Q15 : deemphasis factor */ 22 | @ Word16 L, /* (i) : vector size */ 23 | @ Word16 * mem /* (i/o) : memory (y[-1]) */ 24 | @ ) 25 | 26 | @x_hi RN R0 27 | @x_lo RN R1 28 | @y[] RN R2 29 | @*mem RN R3 30 | 31 | .section .text 32 | .global Deemph_32_asm 33 | 34 | Deemph_32_asm: 35 | 36 | STMFD r13!, {r4 - r12, r14} 37 | MOV r4, #2 @i=0 38 | LDRSH r6, [r0], #2 @load x_hi[0] 39 | LDRSH r7, [r1], #2 @load x_lo[0] 40 | LDR r5, =22282 @r5---mu 41 | MOV r11, #0x8000 42 | 43 | @y[0] 44 | MOV r10, r6, LSL #16 @L_tmp = x_hi[0]<<16 45 | MOV r8, r5, ASR #1 @fac = mu >> 1 46 | LDR r5, [r3] 47 | ADD r12, r10, r7, LSL #4 @L_tmp += x_lo[0] << 4 48 | MOV r10, r12, LSL #3 @L_tmp <<= 3 49 | MUL r9, r5, r8 50 | LDRSH r6, [r0], #2 @load x_hi[1] 51 | QDADD r10, r10, r9 52 | LDRSH r7, [r1], #2 @load x_lo[1] 53 | MOV r12, r10, LSL #1 @L_tmp = L_mac(L_tmp, *mem, fac) 54 | QADD r10, r12, r11 55 | MOV r14, r10, ASR #16 @y[0] = round(L_tmp) 56 | 57 | 58 | MOV r10, r6, LSL #16 59 | ADD r12, r10, r7, LSL #4 60 | STRH r14, [r2], #2 @update y[0] 61 | MOV r10, r12, LSL #3 62 | MUL r9, r14, r8 63 | QDADD r10, r10, r9 64 | MOV r12, r10, LSL #1 65 | QADD r10, r12, r11 66 | MOV r14, r10, ASR #16 @y[1] = round(L_tmp) 67 | 68 | LOOP: 69 | LDRSH r6, [r0], #2 @load x_hi[] 70 | LDRSH r7, [r1], #2 71 | STRH r14, [r2], #2 72 | MOV r10, r6, LSL #16 73 | ADD r12, r10, r7, LSL #4 74 | MUL r9, r14, r8 75 | MOV r10, r12, LSL #3 76 | QDADD r10, r10, r9 77 | LDRSH r6, [r0], #2 @load x_hi[] 78 | MOV r12, r10, LSL #1 79 | QADD r10, r12, r11 80 | LDRSH r7, [r1], #2 81 | MOV r14, r10, ASR #16 82 | 83 | MOV r10, r6, LSL #16 84 | ADD r12, r10, r7, LSL #4 85 | STRH r14, [r2], #2 86 | MUL r9, r14, r8 87 | MOV r10, r12, LSL #3 88 | QDADD r10, r10, r9 89 | ADD r4, r4, #2 90 | MOV r12, r10, LSL #1 91 | QADD r10, r12, r11 92 | CMP r4, #64 93 | MOV r14, r10, ASR #16 94 | 95 | BLT LOOP 96 | STR r14, [r3] 97 | STRH r14, [r2] 98 | 99 | LDMFD r13!, {r4 - r12, r15} 100 | 101 | .END 102 | 103 | -------------------------------------------------------------------------------- /amrwbenc/src/asm/ARMV7/pred_lt4_1_neon.s: -------------------------------------------------------------------------------- 1 | @/* 2 | @ ** Copyright 2003-2010, VisualOn, Inc. 3 | @ ** 4 | @ ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | @ ** you may not use this file except in compliance with the License. 6 | @ ** You may obtain a copy of the License at 7 | @ ** 8 | @ ** http://www.apache.org/licenses/LICENSE-2.0 9 | @ ** 10 | @ ** Unless required by applicable law or agreed to in writing, software 11 | @ ** distributed under the License is distributed on an "AS IS" BASIS, 12 | @ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @ ** See the License for the specific language governing permissions and 14 | @ ** limitations under the License. 15 | @ */ 16 | @ 17 | @void Pred_lt4( 18 | @ Word16 exc[], /* in/out: excitation buffer */ 19 | @ Word16 T0, /* input : integer pitch lag */ 20 | @ Word16 frac, /* input : fraction of lag */ 21 | @ Word16 L_subfr /* input : subframe size */ 22 | @) 23 | @*********************************************************************** 24 | @ r0 --- exc[] 25 | @ r1 --- T0 26 | @ r2 --- frac 27 | @ r3 --- L_subfr 28 | 29 | .section .text 30 | .global pred_lt4_asm 31 | .extern voAWB_inter4_2 32 | .hidden voAWB_inter4_2 33 | 34 | pred_lt4_asm: 35 | 36 | STMFD r13!, {r4 - r12, r14} 37 | SUB r4, r0, r1, LSL #1 @ x = exc - T0 38 | RSB r2, r2, #0 @ frac = - frac 39 | SUB r4, r4, #30 @ x -= L_INTERPOL2 - 1 40 | CMP r2, #0 41 | ADDLT r2, r2, #4 @ frac += UP_SAMP 42 | SUBLT r4, r4, #2 @ x-- 43 | 44 | ADR r8, Lable1 45 | LDR r11, [r8] 46 | ADD r11, r8 47 | RSB r2, r2, #3 @ k = UP_SAMP - 1 - frac 48 | MOV r8, #0 @ j = 0 49 | ADD r11, r11, r2, LSL #6 @ get inter4_2[k][] 50 | 51 | VLD1.S16 {Q0, Q1}, [r11]! 52 | VLD1.S16 {Q2, Q3}, [r11]! 53 | 54 | MOV r6, #0x8000 55 | 56 | VLD1.S16 {Q4, Q5}, [r4]! @load 16 x[] 57 | VLD1.S16 {Q6, Q7}, [r4]! @load 16 x[] 58 | 59 | LOOP: 60 | VQDMULL.S16 Q15, D8, D0 61 | VQDMLAL.S16 Q15, D9, D1 62 | VQDMLAL.S16 Q15, D10, D2 63 | VQDMLAL.S16 Q15, D11, D3 64 | 65 | VQDMLAL.S16 Q15, D12, D4 66 | VQDMLAL.S16 Q15, D13, D5 67 | VQDMLAL.S16 Q15, D14, D6 68 | VQDMLAL.S16 Q15, D15, D7 69 | 70 | LDRSH r12, [r4], #2 71 | 72 | VEXT.S16 D8, D8, D9, #1 73 | VEXT.S16 D9, D9, D10, #1 74 | VEXT.S16 D10, D10, D11, #1 75 | VEXT.S16 D11, D11, D12, #1 76 | VDUP.S16 D24, r12 77 | VEXT.S16 D12, D12, D13, #1 78 | VEXT.S16 D13, D13, D14, #1 79 | 80 | VQADD.S32 D30, D30, D31 81 | MOV r11, #0x8000 82 | VPADD.S32 D30, D30, D30 83 | ADD r8, r8, #1 84 | VMOV.S32 r12, D30[0] 85 | VEXT.S16 D14, D14, D15, #1 86 | 87 | QADD r1, r12, r12 @ L_sum = (L_sum << 2) 88 | VEXT.S16 D15, D15, D24, #1 89 | QADD r5, r1, r6 90 | MOV r1, r5, ASR #16 91 | CMP r8, r3 92 | STRH r1, [r0], #2 @ exc[j] = (L_sum + 0x8000) >> 16 93 | BLT LOOP 94 | 95 | pred_lt4_end: 96 | 97 | LDMFD r13!, {r4 - r12, r15} 98 | 99 | Lable1: 100 | .word voAWB_inter4_2-Lable1 101 | @ENDFUNC 102 | .END 103 | 104 | -------------------------------------------------------------------------------- /amrwbenc/src/asm/ARMV7/residu_asm_neon.s: -------------------------------------------------------------------------------- 1 | @/* 2 | @ ** Copyright 2003-2010, VisualOn, Inc. 3 | @ ** 4 | @ ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | @ ** you may not use this file except in compliance with the License. 6 | @ ** You may obtain a copy of the License at 7 | @ ** 8 | @ ** http://www.apache.org/licenses/LICENSE-2.0 9 | @ ** 10 | @ ** Unless required by applicable law or agreed to in writing, software 11 | @ ** distributed under the License is distributed on an "AS IS" BASIS, 12 | @ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @ ** See the License for the specific language governing permissions and 14 | @ ** limitations under the License. 15 | @ */ 16 | @ 17 | @void Residu ( 18 | @ Word16 a[], /* (i) : prediction coefficients */ 19 | @ Word16 x[], /* (i) : speech signal */ 20 | @ Word16 y[], /* (o) : residual signal */ 21 | @ Word16 lg /* (i) : size of filtering */ 22 | @) 23 | @a[] RN r0 24 | @x[] RN r1 25 | @y[] RN r2 26 | @lg RN r3 27 | 28 | .section .text 29 | .global Residu_opt 30 | 31 | Residu_opt: 32 | 33 | STMFD r13!, {r4 - r12, r14} 34 | SUB r7, r3, #4 @i = lg - 4 35 | 36 | VLD1.S16 {D0, D1, D2, D3}, [r0]! @get all a[] 37 | VLD1.S16 {D4}, [r0]! 38 | VMOV.S32 Q8, #0x8000 39 | 40 | LOOP1: 41 | ADD r9, r1, r7, LSL #1 @copy the address 42 | ADD r10, r2, r7, LSL #1 43 | MOV r8, r9 44 | VLD1.S16 D5, [r8]! @get x[i], x[i+1], x[i+2], x[i+3] 45 | VQDMULL.S16 Q10, D5, D0[0] @finish the first L_mult 46 | 47 | SUB r8, r9, #2 @get the x[i-1] address 48 | VLD1.S16 D5, [r8]! 49 | VQDMLAL.S16 Q10, D5, D0[1] 50 | 51 | SUB r8, r9, #4 @load the x[i-2] address 52 | VLD1.S16 D5, [r8]! 53 | VQDMLAL.S16 Q10, D5, D0[2] 54 | 55 | SUB r8, r9, #6 @load the x[i-3] address 56 | VLD1.S16 D5, [r8]! 57 | VQDMLAL.S16 Q10, D5, D0[3] 58 | 59 | SUB r8, r9, #8 @load the x[i-4] address 60 | VLD1.S16 D5, [r8]! 61 | VQDMLAL.S16 Q10, D5, D1[0] 62 | 63 | SUB r8, r9, #10 @load the x[i-5] address 64 | VLD1.S16 D5, [r8]! 65 | VQDMLAL.S16 Q10, D5, D1[1] 66 | 67 | SUB r8, r9, #12 @load the x[i-6] address 68 | VLD1.S16 D5, [r8]! 69 | VQDMLAL.S16 Q10, D5, D1[2] 70 | 71 | SUB r8, r9, #14 @load the x[i-7] address 72 | VLD1.S16 D5, [r8]! 73 | VQDMLAL.S16 Q10, D5, D1[3] 74 | 75 | SUB r8, r9, #16 @load the x[i-8] address 76 | VLD1.S16 D5, [r8]! 77 | VQDMLAL.S16 Q10, D5, D2[0] 78 | 79 | SUB r8, r9, #18 @load the x[i-9] address 80 | VLD1.S16 D5, [r8]! 81 | VQDMLAL.S16 Q10, D5, D2[1] 82 | 83 | SUB r8, r9, #20 @load the x[i-10] address 84 | VLD1.S16 D5, [r8]! 85 | VQDMLAL.S16 Q10, D5, D2[2] 86 | 87 | SUB r8, r9, #22 @load the x[i-11] address 88 | VLD1.S16 D5, [r8]! 89 | VQDMLAL.S16 Q10, D5, D2[3] 90 | 91 | SUB r8, r9, #24 @load the x[i-12] address 92 | VLD1.S16 D5, [r8]! 93 | VQDMLAL.S16 Q10, D5, D3[0] 94 | 95 | SUB r8, r9, #26 @load the x[i-13] address 96 | VLD1.S16 D5, [r8]! 97 | VQDMLAL.S16 Q10, D5, D3[1] 98 | 99 | SUB r8, r9, #28 @load the x[i-14] address 100 | VLD1.S16 D5, [r8]! 101 | VQDMLAL.S16 Q10, D5, D3[2] 102 | 103 | SUB r8, r9, #30 @load the x[i-15] address 104 | VLD1.S16 D5, [r8]! 105 | VQDMLAL.S16 Q10, D5, D3[3] 106 | 107 | SUB r8, r9, #32 @load the x[i-16] address 108 | VLD1.S16 D5, [r8]! 109 | VQDMLAL.S16 Q10, D5, D4[0] 110 | 111 | SUB r7, r7, #4 @i-=4 112 | VQSHL.S32 Q10, Q10, #4 113 | VQADD.S32 Q10, Q10, Q8 114 | VSHRN.S32 D5, Q10, #16 115 | VST1.S16 D5, [r10]! 116 | CMP r7, #0 117 | 118 | BGE LOOP1 119 | 120 | Residu_asm_end: 121 | 122 | LDMFD r13!, {r4 - r12, r15} 123 | 124 | @ENDFUNC 125 | .END 126 | 127 | 128 | -------------------------------------------------------------------------------- /amrwbenc/src/asm/ARMV7/syn_filt_neon.s: -------------------------------------------------------------------------------- 1 | @/* 2 | @ ** Copyright 2003-2010, VisualOn, Inc. 3 | @ ** 4 | @ ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | @ ** you may not use this file except in compliance with the License. 6 | @ ** You may obtain a copy of the License at 7 | @ ** 8 | @ ** http://www.apache.org/licenses/LICENSE-2.0 9 | @ ** 10 | @ ** Unless required by applicable law or agreed to in writing, software 11 | @ ** distributed under the License is distributed on an "AS IS" BASIS, 12 | @ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @ ** See the License for the specific language governing permissions and 14 | @ ** limitations under the License. 15 | @ */ 16 | @ 17 | @void Syn_filt( 18 | @ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */ 19 | @ Word16 x[], /* (i) : input signal */ 20 | @ Word16 y[], /* (o) : output signal */ 21 | @ Word16 mem[], /* (i/o) : memory associated with this filtering. */ 22 | @) 23 | @*********************************************************************** 24 | @ a[] --- r0 25 | @ x[] --- r1 26 | @ y[] --- r2 27 | @ mem[] --- r3 28 | @ m --- 16 lg --- 80 update --- 1 29 | 30 | .section .text 31 | .global Syn_filt_asm 32 | 33 | Syn_filt_asm: 34 | 35 | STMFD r13!, {r4 - r12, r14} 36 | SUB r13, r13, #700 @ y_buf[L_FRAME16k + M16k] 37 | 38 | MOV r4, r3 @ copy mem[] address 39 | MOV r5, r13 @ copy yy = y_buf address 40 | 41 | @ for(i = 0@ i < m@ i++) 42 | @{ 43 | @ *yy++ = mem[i]@ 44 | @} 45 | VLD1.S16 {D0, D1, D2, D3}, [r4]! @load 16 mems 46 | VST1.S16 {D0, D1, D2, D3}, [r5]! @store 16 mem[] to *yy 47 | 48 | LDRSH r5, [r0], #2 @ load a[0] 49 | MOV r8, #0 @ i = 0 50 | MOV r5, r5, ASR #1 @ a0 = a[0] >> 1 51 | VMOV.S16 D8[0], r5 52 | @ load all a[] 53 | VLD1.S16 {D0, D1, D2, D3}, [r0]! @ load a[1] ~ a[16] 54 | VREV64.16 D0, D0 55 | VREV64.16 D1, D1 56 | VREV64.16 D2, D2 57 | VREV64.16 D3, D3 58 | MOV r8, #0 @ loop times 59 | MOV r10, r13 @ temp = y_buf 60 | ADD r4, r13, #32 @ yy[i] address 61 | 62 | VLD1.S16 {D4, D5, D6, D7}, [r10]! @ first 16 temp_p 63 | 64 | SYN_LOOP: 65 | 66 | LDRSH r6, [r1], #2 @ load x[i] 67 | MUL r12, r6, r5 @ L_tmp = x[i] * a0 68 | ADD r10, r4, r8, LSL #1 @ y[i], yy[i] address 69 | 70 | VDUP.S32 Q10, r12 71 | VMULL.S16 Q5, D3, D4 72 | VMLAL.S16 Q5, D2, D5 73 | VMLAL.S16 Q5, D1, D6 74 | VMLAL.S16 Q5, D0, D7 75 | VEXT.8 D4, D4, D5, #2 76 | VEXT.8 D5, D5, D6, #2 77 | VEXT.8 D6, D6, D7, #2 78 | VPADD.S32 D12, D10, D11 79 | ADD r8, r8, #1 80 | VPADD.S32 D10, D12, D12 81 | 82 | VDUP.S32 Q7, D10[0] 83 | 84 | VSUB.S32 Q9, Q10, Q7 85 | VQRSHRN.S32 D20, Q9, #12 86 | VMOV.S16 r9, D20[0] 87 | VEXT.8 D7, D7, D20, #2 88 | CMP r8, #80 89 | STRH r9, [r10] @ yy[i] 90 | STRH r9, [r2], #2 @ y[i] 91 | 92 | BLT SYN_LOOP 93 | 94 | @ update mem[] 95 | ADD r5, r13, #160 @ yy[64] address 96 | VLD1.S16 {D0, D1, D2, D3}, [r5]! 97 | VST1.S16 {D0, D1, D2, D3}, [r3]! 98 | 99 | Syn_filt_asm_end: 100 | 101 | ADD r13, r13, #700 102 | LDMFD r13!, {r4 - r12, r15} 103 | @ENDFUNC 104 | .END 105 | 106 | 107 | -------------------------------------------------------------------------------- /amrwbenc/src/autocorr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | 18 | /*********************************************************************** 19 | * File: autocorr.c * 20 | * * 21 | * Description:Compute autocorrelations of signal with windowing * 22 | * * 23 | ************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | #include "oper_32b.h" 28 | #include "acelp.h" 29 | #include "ham_wind.tab" 30 | 31 | #define UNUSED(x) (void)(x) 32 | 33 | void Autocorr( 34 | Word16 x[], /* (i) : Input signal */ 35 | Word16 m, /* (i) : LPC order */ 36 | Word16 r_h[], /* (o) Q15: Autocorrelations (msb) */ 37 | Word16 r_l[] /* (o) : Autocorrelations (lsb) */ 38 | ) 39 | { 40 | Word32 i, norm, shift; 41 | Word16 y[L_WINDOW]; 42 | Word32 L_sum, L_sum1, L_tmp, F_LEN; 43 | Word16 *p1,*p2,*p3; 44 | const Word16 *p4; 45 | UNUSED(m); 46 | 47 | /* Windowing of signal */ 48 | p1 = x; 49 | p4 = vo_window; 50 | p3 = y; 51 | 52 | for (i = 0; i < L_WINDOW; i+=4) 53 | { 54 | *p3++ = vo_mult_r((*p1++), (*p4++)); 55 | *p3++ = vo_mult_r((*p1++), (*p4++)); 56 | *p3++ = vo_mult_r((*p1++), (*p4++)); 57 | *p3++ = vo_mult_r((*p1++), (*p4++)); 58 | } 59 | 60 | /* calculate energy of signal */ 61 | L_sum = vo_L_deposit_h(16); /* sqrt(256), avoid overflow after rounding */ 62 | for (i = 0; i < L_WINDOW; i++) 63 | { 64 | L_tmp = vo_L_mult(y[i], y[i]); 65 | L_tmp = (L_tmp >> 8); 66 | L_sum += L_tmp; 67 | } 68 | 69 | /* scale signal to avoid overflow in autocorrelation */ 70 | norm = norm_l(L_sum); 71 | shift = 4 - (norm >> 1); 72 | if(shift > 0) 73 | { 74 | p1 = y; 75 | for (i = 0; i < L_WINDOW; i+=4) 76 | { 77 | *p1 = vo_shr_r(*p1, shift); 78 | p1++; 79 | *p1 = vo_shr_r(*p1, shift); 80 | p1++; 81 | *p1 = vo_shr_r(*p1, shift); 82 | p1++; 83 | *p1 = vo_shr_r(*p1, shift); 84 | p1++; 85 | } 86 | } 87 | 88 | /* Compute and normalize r[0] */ 89 | L_sum = 1; 90 | for (i = 0; i < L_WINDOW; i+=4) 91 | { 92 | L_sum += vo_L_mult(y[i], y[i]); 93 | L_sum += vo_L_mult(y[i+1], y[i+1]); 94 | L_sum += vo_L_mult(y[i+2], y[i+2]); 95 | L_sum += vo_L_mult(y[i+3], y[i+3]); 96 | } 97 | 98 | norm = norm_l(L_sum); 99 | L_sum = (L_sum << norm); 100 | 101 | r_h[0] = L_sum >> 16; 102 | r_l[0] = (L_sum & 0xffff)>>1; 103 | 104 | /* Compute r[1] to r[m] */ 105 | for (i = 1; i <= 8; i++) 106 | { 107 | L_sum1 = 0; 108 | L_sum = 0; 109 | F_LEN = (Word32)(L_WINDOW - 2*i); 110 | p1 = y; 111 | p2 = y + (2*i)-1; 112 | do{ 113 | L_sum1 += *p1 * *p2++; 114 | L_sum += *p1++ * *p2; 115 | }while(--F_LEN!=0); 116 | 117 | L_sum1 += *p1 * *p2++; 118 | 119 | L_sum1 = L_sum1<> 15; 123 | r_l[(2*i)-1] = L_sum1 & 0x00007fff; 124 | r_h[(2*i)] = L_sum >> 15; 125 | r_l[(2*i)] = L_sum & 0x00007fff; 126 | } 127 | return; 128 | } 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /amrwbenc/src/convolve.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | File: convolve.c 19 | 20 | Description:Perform the convolution between two vectors x[] and h[] 21 | and write the result in the vector y[] 22 | 23 | ************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | 28 | #define UNUSED(x) (void)(x) 29 | 30 | void Convolve ( 31 | Word16 x[], /* (i) : input vector */ 32 | Word16 h[], /* (i) : impulse response */ 33 | Word16 y[], /* (o) : output vector */ 34 | Word16 L /* (i) : vector size */ 35 | ) 36 | { 37 | Word32 i, n; 38 | Word16 *tmpH,*tmpX; 39 | Word32 s; 40 | UNUSED(L); 41 | 42 | for (n = 0; n < 64;) 43 | { 44 | tmpH = h+n; 45 | tmpX = x; 46 | i=n+1; 47 | s = vo_mult32((*tmpX++), (*tmpH--));i--; 48 | while(i>0) 49 | { 50 | s += vo_mult32((*tmpX++), (*tmpH--)); 51 | s += vo_mult32((*tmpX++), (*tmpH--)); 52 | s += vo_mult32((*tmpX++), (*tmpH--)); 53 | s += vo_mult32((*tmpX++), (*tmpH--)); 54 | i -= 4; 55 | } 56 | y[n] = ((s<<1) + 0x8000)>>16; 57 | n++; 58 | 59 | tmpH = h+n; 60 | tmpX = x; 61 | i=n+1; 62 | s = vo_mult32((*tmpX++), (*tmpH--));i--; 63 | s += vo_mult32((*tmpX++), (*tmpH--));i--; 64 | 65 | while(i>0) 66 | { 67 | s += vo_mult32((*tmpX++), (*tmpH--)); 68 | s += vo_mult32((*tmpX++), (*tmpH--)); 69 | s += vo_mult32((*tmpX++), (*tmpH--)); 70 | s += vo_mult32((*tmpX++), (*tmpH--)); 71 | i -= 4; 72 | } 73 | y[n] = ((s<<1) + 0x8000)>>16; 74 | n++; 75 | 76 | tmpH = h+n; 77 | tmpX = x; 78 | i=n+1; 79 | s = vo_mult32((*tmpX++), (*tmpH--));i--; 80 | s += vo_mult32((*tmpX++), (*tmpH--));i--; 81 | s += vo_mult32((*tmpX++), (*tmpH--));i--; 82 | 83 | while(i>0) 84 | { 85 | s += vo_mult32((*tmpX++), (*tmpH--)); 86 | s += vo_mult32((*tmpX++), (*tmpH--)); 87 | s += vo_mult32((*tmpX++), (*tmpH--)); 88 | s += vo_mult32((*tmpX++), (*tmpH--)); 89 | i -= 4; 90 | } 91 | y[n] = ((s<<1) + 0x8000)>>16; 92 | n++; 93 | 94 | s = 0; 95 | tmpH = h+n; 96 | tmpX = x; 97 | i=n+1; 98 | while(i>0) 99 | { 100 | s += vo_mult32((*tmpX++), (*tmpH--)); 101 | s += vo_mult32((*tmpX++), (*tmpH--)); 102 | s += vo_mult32((*tmpX++), (*tmpH--)); 103 | s += vo_mult32((*tmpX++), (*tmpH--)); 104 | i -= 4; 105 | } 106 | y[n] = ((s<<1) + 0x8000)>>16; 107 | n++; 108 | } 109 | return; 110 | } 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /amrwbenc/src/cor_h_x.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: cor_h_x.c * 19 | * * 20 | * Description:Compute correlation between target "x[]" and "h[]" * 21 | * Designed for codebook search (24 pulses, 4 tracks, * 22 | * 4 pulses per track, 16 positions in each track) to * 23 | * avoid saturation. * 24 | * * 25 | ************************************************************************/ 26 | 27 | #include "typedef.h" 28 | #include "basic_op.h" 29 | #include "math_op.h" 30 | 31 | #define L_SUBFR 64 32 | #define NB_TRACK 4 33 | #define STEP 4 34 | 35 | void cor_h_x( 36 | Word16 h[], /* (i) Q12 : impulse response of weighted synthesis filter */ 37 | Word16 x[], /* (i) Q0 : target vector */ 38 | Word16 dn[] /* (o) <12bit : correlation between target and h[] */ 39 | ) 40 | { 41 | Word32 i, j; 42 | Word32 L_tmp, y32[L_SUBFR], L_tot; 43 | Word16 *p1, *p2; 44 | Word32 *p3; 45 | Word32 L_max, L_max1, L_max2, L_max3; 46 | /* first keep the result on 32 bits and find absolute maximum */ 47 | L_tot = 1; 48 | L_max = 0; 49 | L_max1 = 0; 50 | L_max2 = 0; 51 | L_max3 = 0; 52 | for (i = 0; i < L_SUBFR; i += STEP) 53 | { 54 | L_tmp = 1; /* 1 -> to avoid null dn[] */ 55 | p1 = &x[i]; 56 | p2 = &h[0]; 57 | for (j = i; j < L_SUBFR; j++) 58 | L_tmp += vo_L_mult(*p1++, *p2++); 59 | 60 | y32[i] = L_tmp; 61 | L_tmp = (L_tmp > 0)? L_tmp:-L_tmp; 62 | if(L_tmp > L_max) 63 | { 64 | L_max = L_tmp; 65 | } 66 | 67 | L_tmp = 1L; 68 | p1 = &x[i+1]; 69 | p2 = &h[0]; 70 | for (j = i+1; j < L_SUBFR; j++) 71 | L_tmp += vo_L_mult(*p1++, *p2++); 72 | 73 | y32[i+1] = L_tmp; 74 | L_tmp = (L_tmp > 0)? L_tmp:-L_tmp; 75 | if(L_tmp > L_max1) 76 | { 77 | L_max1 = L_tmp; 78 | } 79 | 80 | L_tmp = 1; 81 | p1 = &x[i+2]; 82 | p2 = &h[0]; 83 | for (j = i+2; j < L_SUBFR; j++) 84 | L_tmp += vo_L_mult(*p1++, *p2++); 85 | 86 | y32[i+2] = L_tmp; 87 | L_tmp = (L_tmp > 0)? L_tmp:-L_tmp; 88 | if(L_tmp > L_max2) 89 | { 90 | L_max2 = L_tmp; 91 | } 92 | 93 | L_tmp = 1; 94 | p1 = &x[i+3]; 95 | p2 = &h[0]; 96 | for (j = i+3; j < L_SUBFR; j++) 97 | L_tmp += vo_L_mult(*p1++, *p2++); 98 | 99 | y32[i+3] = L_tmp; 100 | L_tmp = (L_tmp > 0)? L_tmp:-L_tmp; 101 | if(L_tmp > L_max3) 102 | { 103 | L_max3 = L_tmp; 104 | } 105 | } 106 | /* tot += 3*max / 8 */ 107 | L_max = ((L_max + L_max1 + L_max2 + L_max3) >> 2); 108 | L_tot = vo_L_add(L_tot, L_max); /* +max/4 */ 109 | L_tot = vo_L_add(L_tot, (L_max >> 1)); /* +max/8 */ 110 | 111 | /* Find the number of right shifts to do on y32[] so that */ 112 | /* 6.0 x sumation of max of dn[] in each track not saturate. */ 113 | j = norm_l(L_tot) - 4; /* 4 -> 16 x tot */ 114 | p1 = dn; 115 | p3 = y32; 116 | for (i = 0; i < L_SUBFR; i+=4) 117 | { 118 | *p1++ = vo_round(L_shl(*p3++, j)); 119 | *p1++ = vo_round(L_shl(*p3++, j)); 120 | *p1++ = vo_round(L_shl(*p3++, j)); 121 | *p1++ = vo_round(L_shl(*p3++, j)); 122 | } 123 | return; 124 | } 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /amrwbenc/src/deemph.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: deemph.c * 19 | * * 20 | * Description:filtering through 1/(1-mu z^ -1) * 21 | * Deemph2 --> signal is divided by 2 * 22 | * Deemph_32 --> for 32 bits signal. * 23 | * * 24 | ************************************************************************/ 25 | 26 | #include "typedef.h" 27 | #include "basic_op.h" 28 | #include "math_op.h" 29 | 30 | void Deemph( 31 | Word16 x[], /* (i/o) : input signal overwritten by the output */ 32 | Word16 mu, /* (i) Q15 : deemphasis factor */ 33 | Word16 L, /* (i) : vector size */ 34 | Word16 * mem /* (i/o) : memory (y[-1]) */ 35 | ) 36 | { 37 | Word32 i; 38 | Word32 L_tmp; 39 | 40 | L_tmp = L_deposit_h(x[0]); 41 | L_tmp = L_mac(L_tmp, *mem, mu); 42 | x[0] = vo_round(L_tmp); 43 | 44 | for (i = 1; i < L; i++) 45 | { 46 | L_tmp = L_deposit_h(x[i]); 47 | L_tmp = L_mac(L_tmp, x[i - 1], mu); 48 | x[i] = voround(L_tmp); 49 | } 50 | 51 | *mem = x[L - 1]; 52 | 53 | return; 54 | } 55 | 56 | 57 | void Deemph2( 58 | Word16 x[], /* (i/o) : input signal overwritten by the output */ 59 | Word16 mu, /* (i) Q15 : deemphasis factor */ 60 | Word16 L, /* (i) : vector size */ 61 | Word16 * mem /* (i/o) : memory (y[-1]) */ 62 | ) 63 | { 64 | Word32 i; 65 | Word32 L_tmp; 66 | L_tmp = x[0] << 15; 67 | L_tmp += ((*mem) * mu)<<1; 68 | x[0] = (L_tmp + 0x8000)>>16; 69 | for (i = 1; i < L; i++) 70 | { 71 | L_tmp = x[i] << 15; 72 | L_tmp += (x[i - 1] * mu)<<1; 73 | x[i] = (L_tmp + 0x8000)>>16; 74 | } 75 | *mem = x[L - 1]; 76 | return; 77 | } 78 | 79 | 80 | void Deemph_32( 81 | Word16 x_hi[], /* (i) : input signal (bit31..16) */ 82 | Word16 x_lo[], /* (i) : input signal (bit15..4) */ 83 | Word16 y[], /* (o) : output signal (x16) */ 84 | Word16 mu, /* (i) Q15 : deemphasis factor */ 85 | Word16 L, /* (i) : vector size */ 86 | Word16 * mem /* (i/o) : memory (y[-1]) */ 87 | ) 88 | { 89 | Word16 fac; 90 | Word32 i, L_tmp; 91 | 92 | fac = mu >> 1; /* Q15 --> Q14 */ 93 | 94 | L_tmp = L_deposit_h(x_hi[0]); 95 | L_tmp += (x_lo[0] * 8)<<1; 96 | L_tmp = (L_tmp << 3); 97 | L_tmp += ((*mem) * fac)<<1; 98 | L_tmp = (L_tmp << 1); 99 | y[0] = (L_tmp + 0x8000)>>16; 100 | 101 | for (i = 1; i < L; i++) 102 | { 103 | L_tmp = L_deposit_h(x_hi[i]); 104 | L_tmp += (x_lo[i] * 8)<<1; 105 | L_tmp = (L_tmp << 3); 106 | L_tmp += (y[i - 1] * fac)<<1; 107 | L_tmp = (L_tmp << 1); 108 | y[i] = (L_tmp + 0x8000)>>16; 109 | } 110 | 111 | *mem = y[L - 1]; 112 | 113 | return; 114 | } 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /amrwbenc/src/g_pitch.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: g_pitch.c * 19 | * * 20 | * Description:Compute the gain of pitch. Result in Q12 * 21 | * if(gain < 0) gain = 0 * 22 | * if(gain > 1.2) gain = 1.2 * 23 | ************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | #include "math_op.h" 28 | 29 | Word16 G_pitch( /* (o) Q14 : Gain of pitch lag saturated to 1.2 */ 30 | Word16 xn[], /* (i) : Pitch target. */ 31 | Word16 y1[], /* (i) : filtered adaptive codebook. */ 32 | Word16 g_coeff[], /* : Correlations need for gain quantization. */ 33 | Word16 L_subfr /* : Length of subframe. */ 34 | ) 35 | { 36 | Word32 i; 37 | Word16 xy, yy, exp_xy, exp_yy, gain; 38 | /* Compute scalar product */ 39 | #ifdef ASM_OPT /* asm optimization branch */ 40 | /* Compute scalar product */ 41 | xy = extract_h(Dot_product12_asm(xn, y1, L_subfr, &exp_xy)); 42 | yy = extract_h(Dot_product12_asm(y1, y1, L_subfr, &exp_yy)); 43 | 44 | #else 45 | /* Compute scalar product */ 46 | xy = extract_h(Dot_product12(xn, y1, L_subfr, &exp_xy)); 47 | yy = extract_h(Dot_product12(y1, y1, L_subfr, &exp_yy)); 48 | 49 | #endif 50 | 51 | g_coeff[0] = yy; 52 | g_coeff[1] = exp_yy; 53 | g_coeff[2] = xy; 54 | g_coeff[3] = exp_xy; 55 | 56 | /* If (xy < 0) gain = 0 */ 57 | if (xy < 0) 58 | return ((Word16) 0); 59 | 60 | /* compute gain = xy/yy */ 61 | 62 | xy >>= 1; /* Be sure xy < yy */ 63 | gain = div_s(xy, yy); 64 | 65 | i = exp_xy; 66 | i -= exp_yy; 67 | 68 | gain = shl(gain, i); 69 | 70 | /* if (gain > 1.2) gain = 1.2 in Q14 */ 71 | if(gain > 19661) 72 | { 73 | gain = 19661; 74 | } 75 | return (gain); 76 | } 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /amrwbenc/src/gpclip.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /************************************************************************** 18 | * File: gpclip.c * 19 | * * 20 | * Description:To avoid unstable synthesis on frame erasure, the gain * 21 | * need to be limited(gain pitch < 1.0) when the following * 22 | * case occurs * 23 | * a resonance on LPC filter(lp_disp < 60Hz) * 24 | * a good pitch prediction (lp_gp > 0.95) * 25 | * * 26 | ***************************************************************************/ 27 | #include "typedef.h" 28 | #include "basic_op.h" 29 | 30 | #define DIST_ISF_MAX 307 /* 120 Hz (6400Hz=16384) */ 31 | #define DIST_ISF_THRES 154 /* 60 (6400Hz=16384) */ 32 | #define GAIN_PIT_THRES 14746 /* 0.9 in Q14 */ 33 | #define GAIN_PIT_MIN 9830 /* 0.6 in Q14 */ 34 | #define M 16 35 | 36 | 37 | void Init_gp_clip( 38 | Word16 mem[] /* (o) : memory of gain of pitch clipping algorithm */ 39 | ) 40 | { 41 | mem[0] = DIST_ISF_MAX; 42 | mem[1] = GAIN_PIT_MIN; 43 | } 44 | 45 | 46 | Word16 Gp_clip( 47 | Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */ 48 | ) 49 | { 50 | Word16 clip = 0; 51 | if ((mem[0] < DIST_ISF_THRES) && (mem[1] > GAIN_PIT_THRES)) 52 | clip = 1; 53 | 54 | return (clip); 55 | } 56 | 57 | 58 | void Gp_clip_test_isf( 59 | Word16 isf[], /* (i) : isf values (in frequency domain) */ 60 | Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */ 61 | ) 62 | { 63 | Word16 dist, dist_min; 64 | Word32 i; 65 | 66 | dist_min = vo_sub(isf[1], isf[0]); 67 | 68 | for (i = 2; i < M - 1; i++) 69 | { 70 | dist = vo_sub(isf[i], isf[i - 1]); 71 | if(dist < dist_min) 72 | { 73 | dist_min = dist; 74 | } 75 | } 76 | 77 | dist = extract_h(L_mac(vo_L_mult(26214, mem[0]), 6554, dist_min)); 78 | 79 | if (dist > DIST_ISF_MAX) 80 | { 81 | dist = DIST_ISF_MAX; 82 | } 83 | mem[0] = dist; 84 | 85 | return; 86 | } 87 | 88 | 89 | void Gp_clip_test_gain_pit( 90 | Word16 gain_pit, /* (i) Q14 : gain of quantized pitch */ 91 | Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */ 92 | ) 93 | { 94 | Word16 gain; 95 | Word32 L_tmp; 96 | L_tmp = (29491 * mem[1])<<1; 97 | L_tmp += (3277 * gain_pit)<<1; 98 | 99 | gain = extract_h(L_tmp); 100 | 101 | if(gain < GAIN_PIT_MIN) 102 | { 103 | gain = GAIN_PIT_MIN; 104 | } 105 | mem[1] = gain; 106 | return; 107 | } 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /amrwbenc/src/homing.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: homing.c * 19 | * * 20 | * Description:Performs the homing routines * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "cnst.h" 26 | #include "basic_op.h" 27 | #include "bits.h" 28 | #include "homing.tab" 29 | 30 | Word16 encoder_homing_frame_test(Word16 input_frame[]) 31 | { 32 | Word32 i; 33 | Word16 j = 0; 34 | 35 | /* check 320 input samples for matching EHF_MASK: defined in e_homing.h */ 36 | for (i = 0; i < L_FRAME16k; i++) 37 | { 38 | j = (Word16) (input_frame[i] ^ EHF_MASK); 39 | 40 | if (j) 41 | break; 42 | } 43 | 44 | return (Word16) (!j); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /amrwbenc/src/hp400.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: hp400.c * 19 | * * 20 | * Description: * 21 | * 2nd order high pass filter with cut off frequency at 400 Hz. * 22 | * Designed with cheby2 function in MATLAB. * 23 | * Optimized for fixed-point to get the following frequency response: * 24 | * * 25 | * frequency: 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz * 26 | * dB loss: -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB * 27 | * * 28 | * Algorithm: * 29 | * * 30 | * y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] * 31 | * + a[1]*y[i-1] + a[2]*y[i-2]; * 32 | * * 33 | * Word16 b[3] = {3660, -7320, 3660}; in Q12 * 34 | * Word16 a[3] = {4096, 7320, -3540}; in Q12 * 35 | * * 36 | * float --> b[3] = {0.893554687, -1.787109375, 0.893554687}; * 37 | * a[3] = {1.000000000, 1.787109375, -0.864257812}; * 38 | * * 39 | ************************************************************************/ 40 | 41 | #include "typedef.h" 42 | #include "basic_op.h" 43 | #include "oper_32b.h" 44 | #include "acelp.h" 45 | 46 | /* filter coefficients */ 47 | static Word16 b[3] = {915, -1830, 915}; /* Q12 (/4) */ 48 | static Word16 a[3] = {16384, 29280, -14160}; /* Q12 (x4) */ 49 | /* Initialization of static values */ 50 | 51 | void Init_HP400_12k8(Word16 mem[]) 52 | { 53 | Set_zero(mem, 6); 54 | } 55 | 56 | 57 | void HP400_12k8( 58 | Word16 signal[], /* input signal / output is divided by 16 */ 59 | Word16 lg, /* lenght of signal */ 60 | Word16 mem[] /* filter memory [6] */ 61 | ) 62 | { 63 | Word16 x2; 64 | Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1; 65 | Word32 L_tmp; 66 | Word32 num; 67 | y2_hi = *mem++; 68 | y2_lo = *mem++; 69 | y1_hi = *mem++; 70 | y1_lo = *mem++; 71 | x0 = *mem++; 72 | x1 = *mem; 73 | num = (Word32)lg; 74 | do 75 | { 76 | x2 = x1; 77 | x1 = x0; 78 | x0 = *signal; 79 | /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2] */ 80 | /* + a[1]*y[i-1] + a[2] * y[i-2]; */ 81 | L_tmp = 8192L; /* rounding to maximise precision */ 82 | L_tmp += y1_lo * a[1]; 83 | L_tmp += y2_lo * a[2]; 84 | L_tmp = L_tmp >> 14; 85 | L_tmp += (y1_hi * a[1] + y2_hi * a[2] + (x0 + x2)* b[0] + x1 * b[1]) << 1; 86 | L_tmp <<= 1; /* coeff Q12 --> Q13 */ 87 | y2_hi = y1_hi; 88 | y2_lo = y1_lo; 89 | y1_hi = (Word16)(L_tmp>>16); 90 | y1_lo = (Word16)((L_tmp & 0xffff)>>1); 91 | 92 | /* signal is divided by 16 to avoid overflow in energy computation */ 93 | *signal++ = (L_tmp + 0x8000) >> 16; 94 | }while(--num !=0); 95 | 96 | *mem-- = x1; 97 | *mem-- = x0; 98 | *mem-- = y1_lo; 99 | *mem-- = y1_hi; 100 | *mem-- = y2_lo; 101 | *mem = y2_hi; 102 | return; 103 | } 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /amrwbenc/src/hp50.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: hp50.c * 19 | * * 20 | * Description: * 21 | * 2nd order high pass filter with cut off frequency at 31 Hz. * 22 | * Designed with cheby2 function in MATLAB. * 23 | * Optimized for fixed-point to get the following frequency response: * 24 | * * 25 | * frequency: 0Hz 14Hz 24Hz 31Hz 37Hz 41Hz 47Hz * 26 | * dB loss: -infdB -15dB -6dB -3dB -1.5dB -1dB -0.5dB * 27 | * * 28 | * Algorithm: * 29 | * * 30 | * y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] * 31 | * + a[1]*y[i-1] + a[2]*y[i-2]; * 32 | * * 33 | * Word16 b[3] = {4053, -8106, 4053}; in Q12 * 34 | * Word16 a[3] = {8192, 16211, -8021}; in Q12 * 35 | * * 36 | * float --> b[3] = {0.989501953, -1.979003906, 0.989501953}; * 37 | * a[3] = {1.000000000, 1.978881836, -0.979125977}; * 38 | ************************************************************************/ 39 | 40 | #include "typedef.h" 41 | #include "basic_op.h" 42 | #include "oper_32b.h" 43 | #include "cnst.h" 44 | #include "acelp.h" 45 | 46 | /* filter coefficients */ 47 | static Word16 b[3] = {4053, -8106, 4053}; /* Q12 */ 48 | static Word16 a[3] = {8192, 16211, -8021}; /* Q12 (x2) */ 49 | 50 | /* Initialization of static values */ 51 | 52 | void Init_HP50_12k8(Word16 mem[]) 53 | { 54 | Set_zero(mem, 6); 55 | } 56 | 57 | 58 | void HP50_12k8( 59 | Word16 signal[], /* input/output signal */ 60 | Word16 lg, /* lenght of signal */ 61 | Word16 mem[] /* filter memory [6] */ 62 | ) 63 | { 64 | Word16 x2; 65 | Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1; 66 | Word32 L_tmp; 67 | Word32 num; 68 | 69 | y2_hi = *mem++; 70 | y2_lo = *mem++; 71 | y1_hi = *mem++; 72 | y1_lo = *mem++; 73 | x0 = *mem++; 74 | x1 = *mem; 75 | num = (Word32)lg; 76 | do 77 | { 78 | x2 = x1; 79 | x1 = x0; 80 | x0 = *signal; 81 | /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2] */ 82 | /* + a[1]*y[i-1] + a[2] * y[i-2]; */ 83 | L_tmp = 8192 ; /* rounding to maximise precision */ 84 | L_tmp += y1_lo * a[1]; 85 | L_tmp += y2_lo * a[2]; 86 | L_tmp = L_shr(L_tmp, 14); 87 | L_tmp += (y1_hi * a[1] + y2_hi * a[2] + (x0 + x2) * b[0] + x1 * b[1]) << 1; 88 | L_tmp = L_shl(L_tmp, 2); /* coeff Q12 --> Q13 */ 89 | y2_hi = y1_hi; 90 | y2_lo = y1_lo; 91 | y1_hi = (Word16)(L_tmp>>16); 92 | y1_lo = (Word16)((L_tmp & 0xffff)>>1); 93 | L_tmp = L_shl(L_tmp, 1); 94 | *signal++ = extract_h((L_add(L_tmp, 0x8000))); 95 | }while(--num !=0); 96 | 97 | *mem-- = x1; 98 | *mem-- = x0; 99 | *mem-- = y1_lo; 100 | *mem-- = y1_hi; 101 | *mem-- = y2_lo; 102 | *mem-- = y2_hi; 103 | 104 | return; 105 | } 106 | 107 | 108 | -------------------------------------------------------------------------------- /amrwbenc/src/hp6k.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: hp6k.c * 19 | * * 20 | * Description:15th order band pass 6kHz to 7kHz FIR filter * 21 | * frequency: 4kHz 5kHz 5.5kHz 6kHz 6.5kHz 7kHz 7.5kHz 8kHz * 22 | * dB loss: -60dB -45dB -13dB -3dB 0dB -3dB -13dB -45dB * 23 | * * 24 | ************************************************************************/ 25 | 26 | #include "typedef.h" 27 | #include "basic_op.h" 28 | #include "acelp.h" 29 | #include "cnst.h" 30 | 31 | #define L_FIR 31 32 | 33 | /* filter coefficients (gain=4.0) */ 34 | 35 | Word16 fir_6k_7k[L_FIR] = 36 | { 37 | -32, 47, 32, -27, -369, 38 | 1122, -1421, 0, 3798, -8880, 39 | 12349, -10984, 3548, 7766, -18001, 40 | 22118, -18001, 7766, 3548, -10984, 41 | 12349, -8880, 3798, 0, -1421, 42 | 1122, -369, -27, 32, 47, 43 | -32 44 | }; 45 | 46 | 47 | void Init_Filt_6k_7k(Word16 mem[]) /* mem[30] */ 48 | { 49 | Set_zero(mem, L_FIR - 1); 50 | return; 51 | } 52 | 53 | void Filt_6k_7k( 54 | Word16 signal[], /* input: signal */ 55 | Word16 lg, /* input: length of input */ 56 | Word16 mem[] /* in/out: memory (size=30) */ 57 | ) 58 | { 59 | Word16 x[L_SUBFR16k + (L_FIR - 1)]; 60 | Word32 i, L_tmp; 61 | 62 | Copy(mem, x, L_FIR - 1); 63 | for (i = lg - 1; i >= 0; i--) 64 | { 65 | x[i + L_FIR - 1] = signal[i] >> 2; /* gain of filter = 4 */ 66 | } 67 | for (i = 0; i < lg; i++) 68 | { 69 | L_tmp = (x[i] + x[i+ 30]) * fir_6k_7k[0]; 70 | L_tmp += (x[i+1] + x[i + 29]) * fir_6k_7k[1]; 71 | L_tmp += (x[i+2] + x[i + 28]) * fir_6k_7k[2]; 72 | L_tmp += (x[i+3] + x[i + 27]) * fir_6k_7k[3]; 73 | L_tmp += (x[i+4] + x[i + 26]) * fir_6k_7k[4]; 74 | L_tmp += (x[i+5] + x[i + 25]) * fir_6k_7k[5]; 75 | L_tmp += (x[i+6] + x[i + 24]) * fir_6k_7k[6]; 76 | L_tmp += (x[i+7] + x[i + 23]) * fir_6k_7k[7]; 77 | L_tmp += (x[i+8] + x[i + 22]) * fir_6k_7k[8]; 78 | L_tmp += (x[i+9] + x[i + 21]) * fir_6k_7k[9]; 79 | L_tmp += (x[i+10] + x[i + 20]) * fir_6k_7k[10]; 80 | L_tmp += (x[i+11] + x[i + 19]) * fir_6k_7k[11]; 81 | L_tmp += (x[i+12] + x[i + 18]) * fir_6k_7k[12]; 82 | L_tmp += (x[i+13] + x[i + 17]) * fir_6k_7k[13]; 83 | L_tmp += (x[i+14] + x[i + 16]) * fir_6k_7k[14]; 84 | L_tmp += (x[i+15]) * fir_6k_7k[15]; 85 | signal[i] = (L_tmp + 0x4000) >> 15; 86 | } 87 | 88 | Copy(x + lg, mem, L_FIR - 1); 89 | 90 | } 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /amrwbenc/src/hp_wsp.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: hp_wsp.c * 19 | * Description: * 20 | * 3nd order high pass filter with cut off frequency at 180Hz * 21 | * Algorithm: * 22 | * * 23 | * y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] + b[3]*x[i-3] * 24 | * + a[1]*y[i-1] + a[2]*y[i-2] + a[3]*y[i-3]; * 25 | * * 26 | * float a_coef[HP_ORDER]= { * 27 | * -2.64436711600664f, * 28 | * 2.35087386625360f, * 29 | * -0.70001156927424f}; * 30 | * * 31 | * float b_coef[HP_ORDER+1]= { * 32 | * -0.83787057505665f, * 33 | * 2.50975570071058f, * 34 | * -2.50975570071058f, * 35 | * 0.83787057505665f}; * 36 | * * 37 | *************************************************************************/ 38 | 39 | #include "typedef.h" 40 | #include "basic_op.h" 41 | #include "oper_32b.h" 42 | #include "acelp.h" 43 | 44 | /* filter coefficients in Q12 */ 45 | static Word16 a[4] = {8192, 21663, -19258, 5734}; 46 | static Word16 b[4] = {-3432, +10280, -10280, +3432}; 47 | 48 | /* Initialization of static values */ 49 | void Init_Hp_wsp(Word16 mem[]) 50 | { 51 | Set_zero(mem, 9); 52 | 53 | return; 54 | } 55 | 56 | void scale_mem_Hp_wsp(Word16 mem[], Word16 exp) 57 | { 58 | Word32 i; 59 | Word32 L_tmp; 60 | 61 | for (i = 0; i < 6; i += 2) 62 | { 63 | L_tmp = ((mem[i] << 16) + (mem[i + 1]<<1)); 64 | L_tmp = L_shl(L_tmp, exp); 65 | mem[i] = L_tmp >> 16; 66 | mem[i + 1] = (L_tmp & 0xffff)>>1; 67 | } 68 | 69 | for (i = 6; i < 9; i++) 70 | { 71 | L_tmp = L_deposit_h(mem[i]); /* x[i] */ 72 | L_tmp = L_shl(L_tmp, exp); 73 | mem[i] = vo_round(L_tmp); 74 | } 75 | 76 | return; 77 | } 78 | 79 | 80 | void Hp_wsp( 81 | Word16 wsp[], /* i : wsp[] signal */ 82 | Word16 hp_wsp[], /* o : hypass wsp[] */ 83 | Word16 lg, /* i : lenght of signal */ 84 | Word16 mem[] /* i/o : filter memory [9] */ 85 | ) 86 | { 87 | Word16 x0, x1, x2, x3; 88 | Word16 y3_hi, y3_lo, y2_hi, y2_lo, y1_hi, y1_lo; 89 | Word32 i, L_tmp; 90 | 91 | y3_hi = mem[0]; 92 | y3_lo = mem[1]; 93 | y2_hi = mem[2]; 94 | y2_lo = mem[3]; 95 | y1_hi = mem[4]; 96 | y1_lo = mem[5]; 97 | x0 = mem[6]; 98 | x1 = mem[7]; 99 | x2 = mem[8]; 100 | 101 | for (i = 0; i < lg; i++) 102 | { 103 | x3 = x2; 104 | x2 = x1; 105 | x1 = x0; 106 | x0 = wsp[i]; 107 | /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2] + b[3]*x[i-3] */ 108 | /* + a[1]*y[i-1] + a[2] * y[i-2] + a[3]*y[i-3] */ 109 | 110 | L_tmp = 16384L; /* rounding to maximise precision */ 111 | L_tmp += (y1_lo * a[1])<<1; 112 | L_tmp += (y2_lo * a[2])<<1; 113 | L_tmp += (y3_lo * a[3])<<1; 114 | L_tmp = L_tmp >> 15; 115 | L_tmp += (y1_hi * a[1])<<1; 116 | L_tmp += (y2_hi * a[2])<<1; 117 | L_tmp += (y3_hi * a[3])<<1; 118 | L_tmp += (x0 * b[0])<<1; 119 | L_tmp += (x1 * b[1])<<1; 120 | L_tmp += (x2 * b[2])<<1; 121 | L_tmp += (x3 * b[3])<<1; 122 | 123 | L_tmp = L_tmp << 2; 124 | 125 | y3_hi = y2_hi; 126 | y3_lo = y2_lo; 127 | y2_hi = y1_hi; 128 | y2_lo = y1_lo; 129 | y1_hi = L_tmp >> 16; 130 | y1_lo = (L_tmp & 0xffff) >>1; 131 | 132 | hp_wsp[i] = (L_tmp + 0x4000)>>15; 133 | } 134 | 135 | mem[0] = y3_hi; 136 | mem[1] = y3_lo; 137 | mem[2] = y2_hi; 138 | mem[3] = y2_lo; 139 | mem[4] = y1_hi; 140 | mem[5] = y1_lo; 141 | mem[6] = x0; 142 | mem[7] = x1; 143 | mem[8] = x2; 144 | 145 | return; 146 | } 147 | 148 | 149 | -------------------------------------------------------------------------------- /amrwbenc/src/int_lpc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: int_lpc.c * 19 | * * 20 | * Description:Interpolation of the LP parameters in 4 subframes. * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | #include "cnst.h" 27 | #include "acelp.h" 28 | 29 | #define MP1 (M+1) 30 | 31 | 32 | void Int_isp( 33 | Word16 isp_old[], /* input : isps from past frame */ 34 | Word16 isp_new[], /* input : isps from present frame */ 35 | Word16 frac[], /* input : fraction for 3 first subfr (Q15) */ 36 | Word16 Az[] /* output: LP coefficients in 4 subframes */ 37 | ) 38 | { 39 | Word32 i, k; 40 | Word16 fac_old, fac_new; 41 | Word16 isp[M]; 42 | Word32 L_tmp; 43 | 44 | for (k = 0; k < 3; k++) 45 | { 46 | fac_new = frac[k]; 47 | fac_old = (32767 - fac_new) + 1; /* 1.0 - fac_new */ 48 | 49 | for (i = 0; i < M; i++) 50 | { 51 | L_tmp = (isp_old[i] * fac_old)<<1; 52 | L_tmp += (isp_new[i] * fac_new)<<1; 53 | isp[i] = (L_tmp + 0x8000)>>16; 54 | } 55 | Isp_Az(isp, Az, M, 0); 56 | Az += MP1; 57 | } 58 | 59 | /* 4th subframe: isp_new (frac=1.0) */ 60 | Isp_Az(isp_new, Az, M, 0); 61 | 62 | return; 63 | } 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /amrwbenc/src/isp_isf.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: isp_isf.c * 19 | * * 20 | * Description: * 21 | * Isp_isf Transformation isp to isf * 22 | * Isf_isp Transformation isf to isp * 23 | * * 24 | * The transformation from isp[i] to isf[i] and isf[i] to isp[i] * 25 | * are approximated by a look-up table and interpolation * 26 | * * 27 | ************************************************************************/ 28 | 29 | #include "typedef.h" 30 | #include "basic_op.h" 31 | #include "isp_isf.tab" /* Look-up table for transformations */ 32 | 33 | void Isp_isf( 34 | Word16 isp[], /* (i) Q15 : isp[m] (range: -1<=val<1) */ 35 | Word16 isf[], /* (o) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */ 36 | Word16 m /* (i) : LPC order */ 37 | ) 38 | { 39 | Word32 i, ind; 40 | Word32 L_tmp; 41 | ind = 127; /* beging at end of table -1 */ 42 | for (i = (m - 1); i >= 0; i--) 43 | { 44 | if (i >= (m - 2)) 45 | { /* m-2 is a constant */ 46 | ind = 127; /* beging at end of table -1 */ 47 | } 48 | /* find value in table that is just greater than isp[i] */ 49 | while (table[ind] < isp[i]) 50 | ind--; 51 | /* acos(isp[i])= ind*128 + ( ( isp[i]-table[ind] ) * slope[ind] )/2048 */ 52 | L_tmp = vo_L_mult(vo_sub(isp[i], table[ind]), slope[ind]); 53 | isf[i] = vo_round((L_tmp << 4)); /* (isp[i]-table[ind])*slope[ind])>>11 */ 54 | isf[i] = add1(isf[i], (ind << 7)); 55 | } 56 | isf[m - 1] = (isf[m - 1] >> 1); 57 | return; 58 | } 59 | 60 | 61 | void Isf_isp( 62 | Word16 isf[], /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */ 63 | Word16 isp[], /* (o) Q15 : isp[m] (range: -1<=val<1) */ 64 | Word16 m /* (i) : LPC order */ 65 | ) 66 | { 67 | Word16 offset; 68 | Word32 i, ind, L_tmp; 69 | 70 | for (i = 0; i < m - 1; i++) 71 | { 72 | isp[i] = isf[i]; 73 | } 74 | isp[m - 1] = (isf[m - 1] << 1); 75 | 76 | for (i = 0; i < m; i++) 77 | { 78 | ind = (isp[i] >> 7); /* ind = b7-b15 of isf[i] */ 79 | offset = (Word16) (isp[i] & 0x007f); /* offset = b0-b6 of isf[i] */ 80 | 81 | /* isp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 128 */ 82 | L_tmp = vo_L_mult(vo_sub(table[ind + 1], table[ind]), offset); 83 | isp[i] = add1(table[ind], (Word16)((L_tmp >> 8))); 84 | } 85 | 86 | return; 87 | } 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /amrwbenc/src/lag_wind.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: lag_wind.c * 19 | * * 20 | * Description: Lag_windows on autocorrelations * 21 | * r[i] *= lag_wind[i] * 22 | * * 23 | ************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | #include "oper_32b.h" 28 | #include "lag_wind.tab" 29 | 30 | 31 | void Lag_window( 32 | Word16 r_h[], /* (i/o) : Autocorrelations (msb) */ 33 | Word16 r_l[] /* (i/o) : Autocorrelations (lsb) */ 34 | ) 35 | { 36 | Word32 i; 37 | Word32 x; 38 | 39 | for (i = 1; i <= M; i++) 40 | { 41 | x = Mpy_32(r_h[i], r_l[i], volag_h[i - 1], volag_l[i - 1]); 42 | r_h[i] = x >> 16; 43 | r_l[i] = (x & 0xffff)>>1; 44 | } 45 | return; 46 | } 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /amrwbenc/src/log2.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * * 19 | * File : log2.c * 20 | * Purpose : Computes log2(L_x) * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "log2.h" 25 | /******************************************************************************** 26 | * INCLUDE FILES 27 | *********************************************************************************/ 28 | #include "typedef.h" 29 | #include "basic_op.h" 30 | 31 | /********************************************************************************* 32 | * LOCAL VARIABLES AND TABLES 33 | **********************************************************************************/ 34 | #include "log2_tab.h" /* Table for Log2() */ 35 | 36 | /************************************************************************* 37 | * 38 | * FUNCTION: Log2_norm() 39 | * 40 | * PURPOSE: Computes log2(L_x, exp), where L_x is positive and 41 | * normalized, and exp is the normalisation exponent 42 | * If L_x is negative or zero, the result is 0. 43 | * 44 | * DESCRIPTION: 45 | * The function Log2(L_x) is approximated by a table and linear 46 | * interpolation. The following steps are used to compute Log2(L_x) 47 | * 48 | * 1- exponent = 30-norm_exponent 49 | * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization). 50 | * 3- a = bit10-b24 51 | * 4- i -=32 52 | * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 53 | * 54 | *************************************************************************/ 55 | 56 | void Log2_norm ( 57 | Word32 L_x, /* (i) : input value (normalized) */ 58 | Word16 exp, /* (i) : norm_l (L_x) */ 59 | Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */ 60 | Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */ 61 | ) 62 | { 63 | Word16 i, a, tmp; 64 | Word32 L_y; 65 | if (L_x <= (Word32) 0) 66 | { 67 | *exponent = 0; 68 | *fraction = 0; 69 | return; 70 | } 71 | *exponent = (30 - exp); 72 | L_x = (L_x >> 9); 73 | i = extract_h (L_x); /* Extract b25-b31 */ 74 | L_x = (L_x >> 1); 75 | a = (Word16)(L_x); /* Extract b10-b24 of fraction */ 76 | a = (Word16)(a & (Word16)0x7fff); 77 | i -= 32; 78 | L_y = L_deposit_h (table[i]); /* table[i] << 16 */ 79 | tmp = vo_sub(table[i], table[i + 1]); /* table[i] - table[i+1] */ 80 | L_y = vo_L_msu (L_y, tmp, a); /* L_y -= tmp*a*2 */ 81 | *fraction = extract_h (L_y); 82 | 83 | return; 84 | } 85 | 86 | /************************************************************************* 87 | * 88 | * FUNCTION: Log2() 89 | * 90 | * PURPOSE: Computes log2(L_x), where L_x is positive. 91 | * If L_x is negative or zero, the result is 0. 92 | * 93 | * DESCRIPTION: 94 | * normalizes L_x and then calls Log2_norm(). 95 | * 96 | *************************************************************************/ 97 | 98 | void Log2 ( 99 | Word32 L_x, /* (i) : input value */ 100 | Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */ 101 | Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */ 102 | ) 103 | { 104 | Word16 exp; 105 | 106 | exp = norm_l(L_x); 107 | Log2_norm ((L_x << exp), exp, exponent, fraction); 108 | } 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /amrwbenc/src/lp_dec2.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: lp_dec2.c * 19 | * * 20 | * Description:Decimate a vector by 2 with 2nd order fir filter * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | #include "cnst.h" 27 | 28 | #define L_FIR 5 29 | #define L_MEM (L_FIR-2) 30 | 31 | /* static float h_fir[L_FIR] = {0.13, 0.23, 0.28, 0.23, 0.13}; */ 32 | /* fixed-point: sum of coef = 32767 to avoid overflow on DC */ 33 | static Word16 h_fir[L_FIR] = {4260, 7536, 9175, 7536, 4260}; 34 | 35 | void LP_Decim2( 36 | Word16 x[], /* in/out: signal to process */ 37 | Word16 l, /* input : size of filtering */ 38 | Word16 mem[] /* in/out: memory (size=3) */ 39 | ) 40 | { 41 | Word16 *p_x, x_buf[L_FRAME + L_MEM]; 42 | Word32 i, j; 43 | Word32 L_tmp; 44 | /* copy initial filter states into buffer */ 45 | p_x = x_buf; 46 | for (i = 0; i < L_MEM; i++) 47 | { 48 | *p_x++ = mem[i]; 49 | mem[i] = x[l - L_MEM + i]; 50 | } 51 | for (i = 0; i < l; i++) 52 | { 53 | *p_x++ = x[i]; 54 | } 55 | for (i = 0, j = 0; i < l; i += 2, j++) 56 | { 57 | p_x = &x_buf[i]; 58 | L_tmp = ((*p_x++) * h_fir[0]); 59 | L_tmp += ((*p_x++) * h_fir[1]); 60 | L_tmp += ((*p_x++) * h_fir[2]); 61 | L_tmp += ((*p_x++) * h_fir[3]); 62 | L_tmp += ((*p_x++) * h_fir[4]); 63 | x[j] = (L_tmp + 0x4000)>>15; 64 | } 65 | return; 66 | } 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /amrwbenc/src/mem_align.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /******************************************************************************* 18 | File: mem_align.c 19 | 20 | Content: Memory alloc alignments functions 21 | 22 | *******************************************************************************/ 23 | 24 | 25 | #include "mem_align.h" 26 | #ifdef _MSC_VER 27 | #include 28 | #else 29 | #include 30 | #endif 31 | 32 | /***************************************************************************** 33 | * 34 | * function name: mem_malloc 35 | * description: malloc the alignments memory 36 | * returns: the point of the memory 37 | * 38 | **********************************************************************************/ 39 | void * 40 | mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID) 41 | { 42 | int ret; 43 | unsigned char *mem_ptr; 44 | VO_MEM_INFO MemInfo; 45 | 46 | if (!alignment) { 47 | 48 | MemInfo.Flag = 0; 49 | MemInfo.Size = size + 1; 50 | ret = pMemop->Alloc(CodecID, &MemInfo); 51 | if(ret != 0) 52 | return 0; 53 | mem_ptr = (unsigned char *)MemInfo.VBuffer; 54 | 55 | pMemop->Set(CodecID, mem_ptr, 0, size + 1); 56 | 57 | *mem_ptr = (unsigned char)1; 58 | 59 | return ((void *)(mem_ptr+1)); 60 | } else { 61 | unsigned char *tmp; 62 | 63 | MemInfo.Flag = 0; 64 | MemInfo.Size = size + alignment; 65 | ret = pMemop->Alloc(CodecID, &MemInfo); 66 | if(ret != 0) 67 | return 0; 68 | 69 | tmp = (unsigned char *)MemInfo.VBuffer; 70 | 71 | pMemop->Set(CodecID, tmp, 0, size + alignment); 72 | 73 | mem_ptr = 74 | (unsigned char *) ((intptr_t) (tmp + alignment - 1) & 75 | (~((intptr_t) (alignment - 1)))); 76 | 77 | if (mem_ptr == tmp) 78 | mem_ptr += alignment; 79 | 80 | *(mem_ptr - 1) = (unsigned char) (mem_ptr - tmp); 81 | 82 | return ((void *)mem_ptr); 83 | } 84 | 85 | return(0); 86 | } 87 | 88 | 89 | /***************************************************************************** 90 | * 91 | * function name: mem_free 92 | * description: free the memory 93 | * 94 | *******************************************************************************/ 95 | void 96 | mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID) 97 | { 98 | 99 | unsigned char *ptr; 100 | 101 | if (mem_ptr == 0) 102 | return; 103 | 104 | ptr = mem_ptr; 105 | 106 | ptr -= *(ptr - 1); 107 | 108 | pMemop->Free(CodecID, ptr); 109 | } 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /amrwbenc/src/pit_shrp.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: pit_shrp.c * 19 | * * 20 | * Description: Performs Pitch sharpening routine * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | 27 | void Pit_shrp( 28 | Word16 * x, /* in/out: impulse response (or algebraic code) */ 29 | Word16 pit_lag, /* input : pitch lag */ 30 | Word16 sharp, /* input : pitch sharpening factor (Q15) */ 31 | Word16 L_subfr /* input : subframe size */ 32 | ) 33 | { 34 | Word32 i; 35 | Word32 L_tmp; 36 | Word16 *x_ptr = x + pit_lag; 37 | 38 | for (i = pit_lag; i < L_subfr; i++) 39 | { 40 | L_tmp = (*x_ptr << 15); 41 | L_tmp += *x++ * sharp; 42 | *x_ptr++ = ((L_tmp + 0x4000)>>15); 43 | } 44 | 45 | return; 46 | } 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /amrwbenc/src/pred_lt4.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: pred_lt4.c * 19 | * * 20 | * Description: Compute the result of long term prediction with * 21 | * fractional interpolation of resolution 1/4 * 22 | * on return exc[0..L_subr-1] contains the interpolated signal * 23 | * (adaptive codebook excitation) * 24 | * * 25 | ************************************************************************/ 26 | 27 | #include "typedef.h" 28 | #include "basic_op.h" 29 | 30 | #define UP_SAMP 4 31 | #define L_INTERPOL2 16 32 | 33 | /* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) in Q14 */ 34 | 35 | Word16 inter4_2[4][32] = 36 | { 37 | {0,-2,4,-2,-10,38,-88,165,-275,424,-619,871,-1207,1699,-2598,5531,14031,-2147,780,-249, 38 | -16,153,-213,226,-209,175,-133,91,-55,28,-10,2}, 39 | 40 | {1,-7,19,-33,47,-52,43,-9,-60,175,-355,626,-1044,1749,-3267,10359,10359,-3267,1749,-1044, 41 | 626,-355,175,-60,-9,43,-52,47,-33,19, -7, 1}, 42 | 43 | {2,-10,28,-55,91,-133,175,-209,226,-213,153,-16,-249,780,-2147,14031,5531,-2598,1699,-1207, 44 | 871,-619,424,-275,165,-88,38,-10,-2,4,-2,0}, 45 | 46 | {1,-7,22,-49,92,-153,231,-325,431,-544,656,-762,853,-923,968,15401,968,-923,853,-762, 47 | 656,-544,431,-325,231,-153,92,-49,22,-7, 1, 0} 48 | 49 | }; 50 | 51 | void Pred_lt4( 52 | Word16 exc[], /* in/out: excitation buffer */ 53 | Word16 T0, /* input : integer pitch lag */ 54 | Word16 frac, /* input : fraction of lag */ 55 | Word16 L_subfr /* input : subframe size */ 56 | ) 57 | { 58 | Word16 j, k, *x; 59 | Word32 L_sum; 60 | Word16 *ptr, *ptr1; 61 | Word16 *ptr2; 62 | 63 | x = exc - T0; 64 | frac = -frac; 65 | if (frac < 0) 66 | { 67 | frac += UP_SAMP; 68 | x--; 69 | } 70 | x -= 15; /* x = L_INTERPOL2 - 1 */ 71 | k = 3 - frac; /* k = UP_SAMP - 1 - frac */ 72 | 73 | ptr2 = &(inter4_2[k][0]); 74 | for (j = 0; j < L_subfr; j++) 75 | { 76 | ptr = ptr2; 77 | ptr1 = x; 78 | L_sum = vo_mult32((*ptr1++), (*ptr++)); 79 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 80 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 81 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 82 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 83 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 84 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 85 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 86 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 87 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 88 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 89 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 90 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 91 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 92 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 93 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 94 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 95 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 96 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 97 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 98 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 99 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 100 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 101 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 102 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 103 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 104 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 105 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 106 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 107 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 108 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 109 | L_sum += vo_mult32((*ptr1++), (*ptr++)); 110 | 111 | L_sum = L_shl2(L_sum, 2); 112 | exc[j] = extract_h(L_add(L_sum, 0x8000)); 113 | x++; 114 | } 115 | 116 | return; 117 | } 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /amrwbenc/src/preemph.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: preemph.c * 19 | * * 20 | * Description: Preemphasis: filtering through 1 - g z^-1 * 21 | * Preemph2 --> signal is multiplied by 2 * 22 | * * 23 | ************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | 28 | void Preemph( 29 | Word16 x[], /* (i/o) : input signal overwritten by the output */ 30 | Word16 mu, /* (i) Q15 : preemphasis coefficient */ 31 | Word16 lg, /* (i) : lenght of filtering */ 32 | Word16 * mem /* (i/o) : memory (x[-1]) */ 33 | ) 34 | { 35 | Word16 temp; 36 | Word32 i, L_tmp; 37 | 38 | temp = x[lg - 1]; 39 | 40 | for (i = lg - 1; i > 0; i--) 41 | { 42 | L_tmp = L_deposit_h(x[i]); 43 | L_tmp -= (x[i - 1] * mu)<<1; 44 | x[i] = (L_tmp + 0x8000)>>16; 45 | } 46 | 47 | L_tmp = L_deposit_h(x[0]); 48 | L_tmp -= ((*mem) * mu)<<1; 49 | x[0] = (L_tmp + 0x8000)>>16; 50 | 51 | *mem = temp; 52 | 53 | return; 54 | } 55 | 56 | 57 | void Preemph2( 58 | Word16 x[], /* (i/o) : input signal overwritten by the output */ 59 | Word16 mu, /* (i) Q15 : preemphasis coefficient */ 60 | Word16 lg, /* (i) : lenght of filtering */ 61 | Word16 * mem /* (i/o) : memory (x[-1]) */ 62 | ) 63 | { 64 | Word16 temp; 65 | Word32 i, L_tmp; 66 | 67 | temp = x[lg - 1]; 68 | 69 | for (i = (Word16) (lg - 1); i > 0; i--) 70 | { 71 | L_tmp = L_deposit_h(x[i]); 72 | L_tmp -= (x[i - 1] * mu)<<1; 73 | L_tmp = (L_tmp << 1); 74 | x[i] = (L_tmp + 0x8000)>>16; 75 | } 76 | 77 | L_tmp = L_deposit_h(x[0]); 78 | L_tmp -= ((*mem) * mu)<<1; 79 | L_tmp = (L_tmp << 1); 80 | x[0] = (L_tmp + 0x8000)>>16; 81 | 82 | *mem = temp; 83 | 84 | return; 85 | } 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /amrwbenc/src/qisf_ns.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*************************************************************************** 18 | * File: qisf_ns.c * 19 | * * 20 | * Description: Coding/Decoding of ISF parameters for background noise.* 21 | * The ISF vector is quantized using VQ with split-by-5 * 22 | * * 23 | ****************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | #include "acelp.h" 28 | #include "qisf_ns.tab" /* Codebooks of ISFs */ 29 | 30 | /*------------------------------------------------------------------* 31 | * routine: Qisf_ns() * 32 | * ~~~~~~~~~ * 33 | *------------------------------------------------------------------*/ 34 | 35 | void Qisf_ns( 36 | Word16 * isf1, /* input : ISF in the frequency domain (0..0.5) */ 37 | Word16 * isf_q, /* output: quantized ISF */ 38 | Word16 * indice /* output: quantization indices */ 39 | ) 40 | { 41 | Word16 i; 42 | Word32 tmp; 43 | 44 | for (i = 0; i < ORDER; i++) 45 | { 46 | isf_q[i] = sub(isf1[i], mean_isf_noise[i]); 47 | } 48 | 49 | indice[0] = Sub_VQ(&isf_q[0], dico1_isf_noise, 2, SIZE_BK_NOISE1, &tmp); 50 | indice[1] = Sub_VQ(&isf_q[2], dico2_isf_noise, 3, SIZE_BK_NOISE2, &tmp); 51 | indice[2] = Sub_VQ(&isf_q[5], dico3_isf_noise, 3, SIZE_BK_NOISE3, &tmp); 52 | indice[3] = Sub_VQ(&isf_q[8], dico4_isf_noise, 4, SIZE_BK_NOISE4, &tmp); 53 | indice[4] = Sub_VQ(&isf_q[12], dico5_isf_noise, 4, SIZE_BK_NOISE5, &tmp); 54 | 55 | /* decoding the ISFs */ 56 | 57 | Disf_ns(indice, isf_q); 58 | 59 | return; 60 | } 61 | 62 | /******************************************************************** 63 | * Function: Disf_ns() * 64 | * ~~~~~~~~~ * 65 | * Decoding of ISF parameters * 66 | *-------------------------------------------------------------------* 67 | * Arguments: * 68 | * indice[] : indices of the selected codebook entries * 69 | * isf[] : quantized ISFs (in frequency domain) * 70 | *********************************************************************/ 71 | 72 | void Disf_ns( 73 | Word16 * indice, /* input: quantization indices */ 74 | Word16 * isf_q /* input : ISF in the frequency domain (0..0.5) */ 75 | ) 76 | { 77 | Word16 i; 78 | 79 | for (i = 0; i < 2; i++) 80 | { 81 | isf_q[i] = dico1_isf_noise[indice[0] * 2 + i]; 82 | } 83 | for (i = 0; i < 3; i++) 84 | { 85 | isf_q[i + 2] = dico2_isf_noise[indice[1] * 3 + i]; 86 | } 87 | for (i = 0; i < 3; i++) 88 | { 89 | isf_q[i + 5] = dico3_isf_noise[indice[2] * 3 + i]; 90 | } 91 | for (i = 0; i < 4; i++) 92 | { 93 | isf_q[i + 8] = dico4_isf_noise[indice[3] * 4 + i]; 94 | } 95 | for (i = 0; i < 4; i++) 96 | { 97 | isf_q[i + 12] = dico5_isf_noise[indice[4] * 4 + i]; 98 | } 99 | 100 | for (i = 0; i < ORDER; i++) 101 | { 102 | isf_q[i] = add(isf_q[i], mean_isf_noise[i]); 103 | } 104 | 105 | Reorder_isf(isf_q, ISF_GAP, ORDER); 106 | 107 | return; 108 | } 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /amrwbenc/src/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: random.c * 19 | * * 20 | * Description: Signed 16 bits random generator * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | 27 | Word16 Random(Word16 * seed) 28 | { 29 | /* static Word16 seed = 21845; */ 30 | *seed = (Word16)(L_add((L_mult(*seed, 31821) >> 1), 13849L)); 31 | return (*seed); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /amrwbenc/src/residu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: residu.c * 19 | * * 20 | * Description: Compute the LPC residual by filtering * 21 | * the input speech through A(z) * 22 | * * 23 | ************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | 28 | void Residu( 29 | Word16 a[], /* (i) Q12 : prediction coefficients */ 30 | Word16 x[], /* (i) : speech (values x[-m..-1] are needed */ 31 | Word16 y[], /* (o) x2 : residual signal */ 32 | Word16 lg /* (i) : size of filtering */ 33 | ) 34 | { 35 | Word16 i,*p1, *p2; 36 | Word32 s; 37 | for (i = 0; i < lg; i++) 38 | { 39 | p1 = a; 40 | p2 = &x[i]; 41 | s = vo_mult32((*p1++), (*p2--)); 42 | s += vo_mult32((*p1++), (*p2--)); 43 | s += vo_mult32((*p1++), (*p2--)); 44 | s += vo_mult32((*p1++), (*p2--)); 45 | s += vo_mult32((*p1++), (*p2--)); 46 | s += vo_mult32((*p1++), (*p2--)); 47 | s += vo_mult32((*p1++), (*p2--)); 48 | s += vo_mult32((*p1++), (*p2--)); 49 | s += vo_mult32((*p1++), (*p2--)); 50 | s += vo_mult32((*p1++), (*p2--)); 51 | s += vo_mult32((*p1++), (*p2--)); 52 | s += vo_mult32((*p1++), (*p2--)); 53 | s += vo_mult32((*p1++), (*p2--)); 54 | s += vo_mult32((*p1++), (*p2--)); 55 | s += vo_mult32((*p1++), (*p2--)); 56 | s += vo_mult32((*p1++), (*p2--)); 57 | s += vo_mult32((*p1), (*p2)); 58 | 59 | s = L_shl2(s, 5); 60 | y[i] = extract_h(L_add(s, 0x8000)); 61 | } 62 | 63 | return; 64 | } 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /amrwbenc/src/scale.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: scale.c * 19 | * * 20 | * Description: Scale signal to get maximum of dynamic * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | 27 | void Scale_sig( 28 | Word16 x[], /* (i/o) : signal to scale */ 29 | Word16 lg, /* (i) : size of x[] */ 30 | Word16 exp /* (i) : exponent: x = round(x << exp) */ 31 | ) 32 | { 33 | Word32 i; 34 | Word32 L_tmp; 35 | if(exp > 0) 36 | { 37 | for (i = lg - 1 ; i >= 0; i--) 38 | { 39 | L_tmp = L_shl2(x[i], 16 + exp); 40 | x[i] = extract_h(L_add(L_tmp, 0x8000)); 41 | } 42 | } 43 | else 44 | { 45 | exp = -exp; 46 | for (i = lg - 1; i >= 0; i--) 47 | { 48 | L_tmp = x[i] << 16; 49 | L_tmp >>= exp; 50 | x[i] = (L_tmp + 0x8000)>>16; 51 | } 52 | } 53 | return; 54 | } 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /amrwbenc/src/stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: stream.c * 19 | * * 20 | * Description: VOME API Buffer Operator Implement Code * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "stream.h" 25 | 26 | void voAWB_InitFrameBuffer(FrameStream *stream) 27 | { 28 | stream->set_ptr = NULL; 29 | stream->frame_ptr_bk = stream->frame_ptr; 30 | stream->set_len = 0; 31 | stream->framebuffer_len = 0; 32 | stream->frame_storelen = 0; 33 | } 34 | 35 | void voAWB_UpdateFrameBuffer( 36 | FrameStream *stream, 37 | VO_MEM_OPERATOR *pMemOP 38 | ) 39 | { 40 | int len; 41 | len = MIN(Frame_Maxsize - stream->frame_storelen, stream->set_len); 42 | pMemOP->Copy(VO_INDEX_ENC_AMRWB, stream->frame_ptr_bk + stream->frame_storelen , stream->set_ptr, len); 43 | stream->set_len -= len; 44 | stream->set_ptr += len; 45 | stream->framebuffer_len = stream->frame_storelen + len; 46 | stream->frame_ptr = stream->frame_ptr_bk; 47 | stream->used_len += len; 48 | } 49 | 50 | void voAWB_FlushFrameBuffer(FrameStream *stream) 51 | { 52 | stream->set_ptr = NULL; 53 | stream->frame_ptr_bk = stream->frame_ptr; 54 | stream->set_len = 0; 55 | stream->framebuffer_len = 0; 56 | stream->frame_storelen = 0; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /amrwbenc/src/updt_tar.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: updt_tar.c * 19 | * * 20 | * Description: Update the target vector for codebook search * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | 27 | void Updt_tar( 28 | Word16 * x, /* (i) Q0 : old target (for pitch search) */ 29 | Word16 * x2, /* (o) Q0 : new target (for codebook search) */ 30 | Word16 * y, /* (i) Q0 : filtered adaptive codebook vector */ 31 | Word16 gain, /* (i) Q14 : adaptive codebook gain */ 32 | Word16 L /* (i) : subframe size */ 33 | ) 34 | { 35 | Word32 i; 36 | Word32 L_tmp; 37 | 38 | for (i = 0; i < L; i++) 39 | { 40 | L_tmp = x[i] << 15; 41 | L_tmp -= (y[i] * gain)<<1; 42 | x2[i] = extract_h(L_shl2(L_tmp, 1)); 43 | } 44 | 45 | return; 46 | } 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /amrwbenc/src/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: util.c * 19 | * * 20 | * Description: Reset and Copy buffer * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | 27 | /*********************************************************************** 28 | * Function: Set_zero() * 29 | * Description: Set vector x[] to zero * 30 | ************************************************************************/ 31 | 32 | void Set_zero( 33 | Word16 x[], /* (o) : vector to clear */ 34 | Word16 L /* (i) : length of vector */ 35 | ) 36 | { 37 | Word32 num = (Word32)L; 38 | do{ 39 | *x++ = 0; 40 | }while(--num !=0); 41 | } 42 | 43 | 44 | /********************************************************************* 45 | * Function: Copy() * 46 | * * 47 | * Description: Copy vector x[] to y[] * 48 | *********************************************************************/ 49 | 50 | void Copy( 51 | Word16 x[], /* (i) : input vector */ 52 | Word16 y[], /* (o) : output vector */ 53 | Word16 L /* (i) : vector length */ 54 | ) 55 | { 56 | Word32 temp1,temp2,num; 57 | if(L&1) 58 | { 59 | temp1 = *x++; 60 | *y++ = temp1; 61 | } 62 | num = (Word32)(L>>1); 63 | temp1 = *x++; 64 | temp2 = *x++; 65 | do{ 66 | *y++ = temp1; 67 | *y++ = temp2; 68 | temp1 = *x++; 69 | temp2 = *x++; 70 | }while(--num!=0); 71 | } 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /amrwbenc/src/voicefac.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: voicefac.c * 19 | * * 20 | * Description: Find the voicing factors (1 = voice to -1 = unvoiced) * 21 | * * 22 | ************************************************************************/ 23 | 24 | #include "typedef.h" 25 | #include "basic_op.h" 26 | #include "math_op.h" 27 | 28 | Word16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */ 29 | Word16 exc[], /* (i) Q_exc : pitch excitation */ 30 | Word16 Q_exc, /* (i) : exc format */ 31 | Word16 gain_pit, /* (i) Q14 : gain of pitch */ 32 | Word16 code[], /* (i) Q9 : Fixed codebook excitation */ 33 | Word16 gain_code, /* (i) Q0 : gain of code */ 34 | Word16 L_subfr /* (i) : subframe length */ 35 | ) 36 | { 37 | Word16 tmp, exp, ener1, exp1, ener2, exp2; 38 | Word32 i, L_tmp; 39 | 40 | #ifdef ASM_OPT /* asm optimization branch */ 41 | ener1 = extract_h(Dot_product12_asm(exc, exc, L_subfr, &exp1)); 42 | #else 43 | ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1)); 44 | #endif 45 | exp1 = exp1 - (Q_exc + Q_exc); 46 | L_tmp = vo_L_mult(gain_pit, gain_pit); 47 | exp = norm_l(L_tmp); 48 | tmp = extract_h(L_tmp << exp); 49 | ener1 = vo_mult(ener1, tmp); 50 | exp1 = exp1 - exp - 10; /* 10 -> gain_pit Q14 to Q9 */ 51 | 52 | #ifdef ASM_OPT /* asm optimization branch */ 53 | ener2 = extract_h(Dot_product12_asm(code, code, L_subfr, &exp2)); 54 | #else 55 | ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2)); 56 | #endif 57 | 58 | exp = norm_s(gain_code); 59 | tmp = gain_code << exp; 60 | tmp = vo_mult(tmp, tmp); 61 | ener2 = vo_mult(ener2, tmp); 62 | exp2 = exp2 - (exp + exp); 63 | 64 | i = exp1 - exp2; 65 | 66 | if (i >= 0) 67 | { 68 | ener1 = ener1 >> 1; 69 | ener2 = ener2 >> (i + 1); 70 | } else 71 | { 72 | ener1 = ener1 >> (1 - i); 73 | ener2 = ener2 >> 1; 74 | } 75 | 76 | tmp = vo_sub(ener1, ener2); 77 | ener1 = add1(add1(ener1, ener2), 1); 78 | 79 | if (tmp >= 0) 80 | { 81 | tmp = div_s(tmp, ener1); 82 | } else 83 | { 84 | tmp = vo_negate(div_s(vo_negate(tmp), ener1)); 85 | } 86 | 87 | return (tmp); 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /amrwbenc/src/weight_a.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /*********************************************************************** 18 | * File: weight_a.c * 19 | * * 20 | * Description:Weighting of LPC coefficients * 21 | * ap[i] = a[i] * (gamma ** i) * 22 | * * 23 | ************************************************************************/ 24 | 25 | #include "typedef.h" 26 | #include "basic_op.h" 27 | 28 | void Weight_a( 29 | Word16 a[], /* (i) Q12 : a[m+1] LPC coefficients */ 30 | Word16 ap[], /* (o) Q12 : Spectral expanded LPC coefficients */ 31 | Word16 gamma, /* (i) Q15 : Spectral expansion factor. */ 32 | Word16 m /* (i) : LPC order. */ 33 | ) 34 | { 35 | Word32 num = m - 1, fac; 36 | *ap++ = *a++; 37 | fac = gamma; 38 | do{ 39 | *ap++ =(Word16)(((vo_L_mult((*a++), fac)) + 0x8000) >> 16); 40 | fac = (vo_L_mult(fac, gamma) + 0x8000) >> 16; 41 | }while(--num != 0); 42 | 43 | *ap++ = (Word16)(((vo_L_mult((*a++), fac)) + 0x8000) >> 16); 44 | return; 45 | } 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /common/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | 5 | 6 | LOCAL_SRC_FILES := cmnMemory.c 7 | 8 | LOCAL_MODULE := libstagefright_enc_common 9 | 10 | LOCAL_ARM_MODE := arm 11 | 12 | LOCAL_STATIC_LIBRARIES := 13 | 14 | LOCAL_C_INCLUDES := \ 15 | $(LOCAL_PATH)/include 16 | 17 | LOCAL_CFLAGS += -Werror 18 | 19 | include $(BUILD_SHARED_LIBRARY) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /common/Config.mk: -------------------------------------------------------------------------------- 1 | # 2 | # This configure file is just for Linux projects against Android 3 | # 4 | 5 | VOPRJ := 6 | VONJ := 7 | 8 | # WARNING: 9 | # Using v7 breaks generic build 10 | ifeq ($(TARGET_ARCH),arm) 11 | VOTT := v5 12 | else 13 | VOTT := pc 14 | endif 15 | 16 | # Do we also need to check on ARCH_ARM_HAVE_ARMV7A? - probably not 17 | ifeq ($(TARGET_ARCH),arm) 18 | ifeq ($(ARCH_ARM_HAVE_NEON),true) 19 | VOTT := v7 20 | endif 21 | endif 22 | 23 | VOTEST := 0 24 | 25 | -------------------------------------------------------------------------------- /common/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mstorsjo/vo-amrwbenc/884dd247dbeb6b2bd2cd3291c4872de95700291f/common/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /common/cmnMemory.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: cmnMemory.c 18 | 19 | Content: sample code for memory operator implementation 20 | 21 | *******************************************************************************/ 22 | #include "cmnMemory.h" 23 | 24 | #include 25 | #include 26 | 27 | //VO_MEM_OPERATOR g_memOP; 28 | 29 | #define UNUSED(x) (void)(x) 30 | 31 | VO_U32 cmnMemAlloc (VO_S32 uID, VO_MEM_INFO * pMemInfo) 32 | { 33 | UNUSED(uID); 34 | 35 | if (!pMemInfo) 36 | return VO_ERR_INVALID_ARG; 37 | 38 | pMemInfo->VBuffer = malloc (pMemInfo->Size); 39 | return 0; 40 | } 41 | 42 | VO_U32 cmnMemFree (VO_S32 uID, VO_PTR pMem) 43 | { 44 | UNUSED(uID); 45 | 46 | free (pMem); 47 | return 0; 48 | } 49 | 50 | VO_U32 cmnMemSet (VO_S32 uID, VO_PTR pBuff, VO_U8 uValue, VO_U32 uSize) 51 | { 52 | UNUSED(uID); 53 | 54 | memset (pBuff, uValue, uSize); 55 | return 0; 56 | } 57 | 58 | VO_U32 cmnMemCopy (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize) 59 | { 60 | UNUSED(uID); 61 | 62 | memcpy (pDest, pSource, uSize); 63 | return 0; 64 | } 65 | 66 | VO_U32 cmnMemCheck (VO_S32 uID, VO_PTR pBuffer, VO_U32 uSize) 67 | { 68 | UNUSED(uID); 69 | UNUSED(pBuffer); 70 | UNUSED(uSize); 71 | 72 | return 0; 73 | } 74 | 75 | VO_S32 cmnMemCompare (VO_S32 uID, VO_PTR pBuffer1, VO_PTR pBuffer2, VO_U32 uSize) 76 | { 77 | UNUSED(uID); 78 | 79 | return memcmp(pBuffer1, pBuffer2, uSize); 80 | } 81 | 82 | VO_U32 cmnMemMove (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize) 83 | { 84 | UNUSED(uID); 85 | 86 | memmove (pDest, pSource, uSize); 87 | return 0; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /common/include/cmnMemory.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: cmnMemory.h 18 | 19 | Content: memory operator implementation header file 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __cmnMemory_H__ 24 | #define __cmnMemory_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | #include 31 | 32 | //extern VO_MEM_OPERATOR g_memOP; 33 | 34 | /** 35 | * Allocate memory 36 | * \param uID [in] module ID 37 | * \param uSize [in] size of memory 38 | * \return value is the allocated memory address. NULL is failed. 39 | */ 40 | VO_U32 cmnMemAlloc (VO_S32 uID, VO_MEM_INFO * pMemInfo); 41 | 42 | /** 43 | * Free up memory 44 | * \param uID [in] module ID 45 | * \param pMem [in] address of memory 46 | * \return value 0, if succeeded. 47 | */ 48 | VO_U32 cmnMemFree (VO_S32 uID, VO_PTR pBuffer); 49 | 50 | /** 51 | * memory set function 52 | * \param uID [in] module ID 53 | * \param pBuff [in/out] address of memory 54 | * \param uValue [in] the value to be set 55 | * \param uSize [in] the size to be set 56 | * \return value 0, if succeeded. 57 | */ 58 | VO_U32 cmnMemSet (VO_S32 uID, VO_PTR pBuff, VO_U8 uValue, VO_U32 uSize); 59 | 60 | /** 61 | * memory copy function 62 | * \param uID [in] module ID 63 | * \param pDest [in/out] address of destination memory 64 | * \param pSource [in] address of source memory 65 | * \param uSize [in] the size to be copied 66 | * \return value 0, if succeeded. 67 | */ 68 | VO_U32 cmnMemCopy (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 69 | 70 | /** 71 | * memory check function 72 | * \param uID [in] module ID 73 | * \param pBuff [in] address of buffer to be checked 74 | * \param uSize [in] the size to be checked 75 | * \return value 0, if succeeded. 76 | */ 77 | VO_U32 cmnMemCheck (VO_S32 uID, VO_PTR pBuffer, VO_U32 uSize); 78 | 79 | /** 80 | * memory compare function 81 | * \param uID [in] module ID 82 | * \param pBuffer1 [in] address of buffer 1 to be compared 83 | * \param pBuffer2 [in] address of buffer 2 to be compared 84 | * \param uSize [in] the size to be compared 85 | * \return value: same as standard C run-time memcmp() function. 86 | */ 87 | VO_S32 cmnMemCompare (VO_S32 uID, VO_PTR pBuffer1, VO_PTR pBuffer2, VO_U32 uSize); 88 | 89 | /** 90 | * memory move function 91 | * \param uID [in] module ID 92 | * \param pDest [in/out] address of destination memory 93 | * \param pSource [in] address of source memory 94 | * \param uSize [in] the size to be moved 95 | * \return value 0, if succeeded. 96 | */ 97 | VO_U32 cmnMemMove (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 98 | 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif /* __cplusplus */ 103 | 104 | #endif // __cmnMemory_H__ 105 | 106 | 107 | -------------------------------------------------------------------------------- /common/include/voAAC.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: voAAC.h 18 | 19 | Content: AAC codec APIs & data types 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __voAAC_H__ 24 | #define __voAAC_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | #include "voAudio.h" 31 | 32 | /*! 33 | * the frame type that the decoder supports 34 | */ 35 | typedef enum { 36 | VOAAC_RAWDATA = 0, /*! */ 43 | VOAMRWB_N_MODES = 9, /*!< Invalid mode */ 44 | VOAMRWB_MODE_MAX = VO_MAX_ENUM_VALUE 45 | 46 | }VOAMRWBMODE; 47 | 48 | /*!* the frame format the codec supports*/ 49 | typedef enum { 50 | VOAMRWB_DEFAULT = 0, /*!< the frame type is the header (defined in RFC3267) + rawdata*/ 51 | /*One word (2-byte) for sync word (0x6b21)*/ 52 | /*One word (2-byte) for frame length N.*/ 53 | /*N words (2-byte) containing N bits (bit 0 = 0x007f, bit 1 = 0x0081).*/ 54 | VOAMRWB_ITU = 1, 55 | /*One word (2-byte) for sync word (0x6b21).*/ 56 | /*One word (2-byte) to indicate the frame type.*/ 57 | /*One word (2-byte) to indicate the mode.*/ 58 | /*N words (2-byte) containing N bits (bit 0 = 0xff81, bit 1 = 0x007f).*/ 59 | VOAMRWB_RFC3267 = 2, /* see RFC 3267 */ 60 | VOAMRWB_TMAX = VO_MAX_ENUM_VALUE 61 | }VOAMRWBFRAMETYPE; 62 | 63 | 64 | #define VO_PID_AMRWB_Module 0x42261000 65 | #define VO_PID_AMRWB_FORMAT (VO_PID_AMRWB_Module | 0x0002) 66 | #define VO_PID_AMRWB_CHANNELS (VO_PID_AMRWB_Module | 0x0003) 67 | #define VO_PID_AMRWB_SAMPLERATE (VO_PID_AMRWB_Module | 0x0004) 68 | #define VO_PID_AMRWB_FRAMETYPE (VO_PID_AMRWB_Module | 0x0005) 69 | #define VO_PID_AMRWB_MODE (VO_PID_AMRWB_Module | 0x0006) 70 | #define VO_PID_AMRWB_DTX (VO_PID_AMRWB_Module | 0x0007) 71 | 72 | /** 73 | * Get audio codec API interface 74 | * \param pEncHandle [out] Return the AMRWB Encoder handle. 75 | * \retval VO_ERR_OK Succeeded. 76 | */ 77 | VO_S32 VO_API voGetAMRWBEncAPI(VO_AUDIO_CODECAPI *pEncHandle); 78 | 79 | 80 | #pragma pack(pop) 81 | #ifdef __cplusplus 82 | } /* extern "C" */ 83 | #endif /* __cplusplus */ 84 | 85 | 86 | #endif //__VOAMRWB_H__ 87 | 88 | -------------------------------------------------------------------------------- /common/include/voMem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: voMem.h 18 | 19 | Content: memory functions & data structures 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __voMem_H__ 24 | #define __voMem_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | #include "voIndex.h" 31 | 32 | typedef struct 33 | { 34 | VO_S32 Size; /*!< Buffer stride */ 35 | VO_S32 Flag; 36 | VO_PTR VBuffer; /*!< user data pointer */ 37 | VO_PTR PBuffer; /*!< user data pointer */ 38 | } 39 | VO_MEM_INFO; 40 | 41 | typedef struct VO_MEM_OPERATOR 42 | { 43 | VO_U32 (VO_API * Alloc) (VO_S32 uID, VO_MEM_INFO * pMemInfo); 44 | VO_U32 (VO_API * Free) (VO_S32 uID, VO_PTR pBuff); 45 | VO_U32 (VO_API * Set) (VO_S32 uID, VO_PTR pBuff, VO_U8 uValue, VO_U32 uSize); 46 | VO_U32 (VO_API * Copy) (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 47 | VO_U32 (VO_API * Check) (VO_S32 uID, VO_PTR pBuffer, VO_U32 uSize); 48 | VO_S32 (VO_API * Compare) (VO_S32 uID, VO_PTR pBuffer1, VO_PTR pBuffer2, VO_U32 uSize); 49 | VO_U32 (VO_API * Move) (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 50 | } VO_MEM_OPERATOR; 51 | 52 | #define voMemAlloc(pBuff, pMemOP, ID, nSize) \ 53 | { \ 54 | VO_MEM_INFO voMemInfo; \ 55 | voMemInfo.Size=nSize; \ 56 | pMemOP->Alloc(ID, &voMemInfo); \ 57 | pBuff=(VO_PBYTE)voMemInfo.VBuffer; \ 58 | } 59 | 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif /* __cplusplus */ 64 | 65 | #endif // __voMem_H__ 66 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl -*- Autoconf -*- 2 | dnl Process this file with autoconf to produce a configure script. 3 | 4 | AC_INIT([vo-amrwbenc], [0.1.3], [http://sourceforge.net/projects/opencore-amr/]) 5 | AC_CONFIG_AUX_DIR(.) 6 | AC_CONFIG_MACRO_DIR([m4]) 7 | AM_INIT_AUTOMAKE([tar-ustar foreign]) 8 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 9 | AM_MAINTAINER_MODE 10 | 11 | dnl Various options for configure 12 | AC_ARG_ENABLE([armv5e], 13 | [AS_HELP_STRING([--enable-armv5e], 14 | [enable ARMV5E assembler (default is no)])], 15 | [armv5e=$enableval], [armv5e=no]) 16 | AC_ARG_ENABLE([armv7neon], 17 | [AS_HELP_STRING([--enable-armv7neon], 18 | [enable ARMV7 neon assembler (default is no)])], 19 | [armv7neon=$enableval], [armv7neon=no]) 20 | AC_ARG_ENABLE([example], 21 | [AS_HELP_STRING([--enable-example], 22 | [enable example encoding program (default is no)])], 23 | [example=$enableval], [example=no]) 24 | 25 | dnl Automake conditionals to set 26 | AM_CONDITIONAL(ARMV5E, test x$armv5e = xyes) 27 | AM_CONDITIONAL(ARMV7NEON, test x$armv7neon = xyes) 28 | AM_CONDITIONAL(EXAMPLE, test x$example = xyes) 29 | 30 | dnl Checks for programs. 31 | AM_PROG_AS 32 | AC_PROG_CC_C99 33 | 34 | dnl Setup for libtool 35 | LT_INIT 36 | 37 | dnl soname version to use 38 | dnl goes by ‘current[:revision[:age]]’ with the soname ending up as 39 | dnl current.age.revision. 40 | VO_AMRWBENC_VERSION=0:4:0 41 | AC_SUBST(VO_AMRWBENC_VERSION) 42 | 43 | AC_CONFIG_FILES([Makefile 44 | vo-amrwbenc.pc]) 45 | AC_OUTPUT 46 | -------------------------------------------------------------------------------- /enc_if.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ 2 | * Copyright (C) 2010 Martin Storsjo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 | * express or implied. 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * ------------------------------------------------------------------- 17 | */ 18 | 19 | #ifndef VO_AMRWBENC_ENC_IF_H 20 | #define VO_AMRWBENC_ENC_IF_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | void* E_IF_init(void); 27 | int E_IF_encode(void* state, int mode, const short* speech, unsigned char* out, int dtx); 28 | void E_IF_exit(void* state); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /m4/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mstorsjo/vo-amrwbenc/884dd247dbeb6b2bd2cd3291c4872de95700291f/m4/.gitkeep -------------------------------------------------------------------------------- /vo-amrwbenc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: VisualOn AMR-WB encoder 7 | Description: Adaptive Multi-Rate Wideband speech codec library 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -lvo-amrwbenc 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /vo-amrwbenc.sym: -------------------------------------------------------------------------------- 1 | E_IF_init 2 | E_IF_encode 3 | E_IF_exit 4 | -------------------------------------------------------------------------------- /wavreader.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ 2 | * Copyright (C) 2009 Martin Storsjo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 | * express or implied. 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * ------------------------------------------------------------------- 17 | */ 18 | 19 | #include "wavreader.h" 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define TAG(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) 26 | 27 | struct wav_reader { 28 | FILE *wav; 29 | uint32_t data_length; 30 | 31 | int format; 32 | int sample_rate; 33 | int bits_per_sample; 34 | int channels; 35 | int byte_rate; 36 | int block_align; 37 | }; 38 | 39 | static uint32_t read_tag(struct wav_reader* wr) { 40 | uint32_t tag = 0; 41 | tag = (tag << 8) | fgetc(wr->wav); 42 | tag = (tag << 8) | fgetc(wr->wav); 43 | tag = (tag << 8) | fgetc(wr->wav); 44 | tag = (tag << 8) | fgetc(wr->wav); 45 | return tag; 46 | } 47 | 48 | static uint32_t read_int32(struct wav_reader* wr) { 49 | uint32_t value = 0; 50 | value |= fgetc(wr->wav) << 0; 51 | value |= fgetc(wr->wav) << 8; 52 | value |= fgetc(wr->wav) << 16; 53 | value |= fgetc(wr->wav) << 24; 54 | return value; 55 | } 56 | 57 | static uint16_t read_int16(struct wav_reader* wr) { 58 | uint16_t value = 0; 59 | value |= fgetc(wr->wav) << 0; 60 | value |= fgetc(wr->wav) << 8; 61 | return value; 62 | } 63 | 64 | void* wav_read_open(const char *filename) { 65 | struct wav_reader* wr = (struct wav_reader*) malloc(sizeof(*wr)); 66 | long data_pos = 0; 67 | memset(wr, 0, sizeof(*wr)); 68 | 69 | wr->wav = fopen(filename, "rb"); 70 | if (wr->wav == NULL) { 71 | free(wr); 72 | return NULL; 73 | } 74 | 75 | while (1) { 76 | uint32_t tag, tag2, length; 77 | tag = read_tag(wr); 78 | if (feof(wr->wav)) 79 | break; 80 | length = read_int32(wr); 81 | if (tag != TAG('R', 'I', 'F', 'F') || length < 4) { 82 | fseek(wr->wav, length, SEEK_CUR); 83 | continue; 84 | } 85 | tag2 = read_tag(wr); 86 | length -= 4; 87 | if (tag2 != TAG('W', 'A', 'V', 'E')) { 88 | fseek(wr->wav, length, SEEK_CUR); 89 | continue; 90 | } 91 | // RIFF chunk found, iterate through it 92 | while (length >= 8) { 93 | uint32_t subtag, sublength; 94 | subtag = read_tag(wr); 95 | if (feof(wr->wav)) 96 | break; 97 | sublength = read_int32(wr); 98 | length -= 8; 99 | if (length < sublength) 100 | break; 101 | if (subtag == TAG('f', 'm', 't', ' ')) { 102 | if (sublength < 16) { 103 | // Insufficient data for 'fmt ' 104 | break; 105 | } 106 | wr->format = read_int16(wr); 107 | wr->channels = read_int16(wr); 108 | wr->sample_rate = read_int32(wr); 109 | wr->byte_rate = read_int32(wr); 110 | wr->block_align = read_int16(wr); 111 | wr->bits_per_sample = read_int16(wr); 112 | fseek(wr->wav, sublength - 16, SEEK_CUR); 113 | } else if (subtag == TAG('d', 'a', 't', 'a')) { 114 | data_pos = ftell(wr->wav); 115 | wr->data_length = sublength; 116 | fseek(wr->wav, sublength, SEEK_CUR); 117 | } else { 118 | fseek(wr->wav, sublength, SEEK_CUR); 119 | } 120 | length -= sublength; 121 | } 122 | if (length > 0) { 123 | // Bad chunk? 124 | fseek(wr->wav, length, SEEK_CUR); 125 | } 126 | } 127 | fseek(wr->wav, data_pos, SEEK_SET); 128 | return wr; 129 | } 130 | 131 | void wav_read_close(void* obj) { 132 | struct wav_reader* wr = (struct wav_reader*) obj; 133 | fclose(wr->wav); 134 | free(wr); 135 | } 136 | 137 | int wav_get_header(void* obj, int* format, int* channels, int* sample_rate, int* bits_per_sample, unsigned int* data_length) { 138 | struct wav_reader* wr = (struct wav_reader*) obj; 139 | if (format) 140 | *format = wr->format; 141 | if (channels) 142 | *channels = wr->channels; 143 | if (sample_rate) 144 | *sample_rate = wr->sample_rate; 145 | if (bits_per_sample) 146 | *bits_per_sample = wr->bits_per_sample; 147 | if (data_length) 148 | *data_length = wr->data_length; 149 | return wr->format && wr->sample_rate; 150 | } 151 | 152 | int wav_read_data(void* obj, unsigned char* data, unsigned int length) { 153 | struct wav_reader* wr = (struct wav_reader*) obj; 154 | int n; 155 | if (wr->wav == NULL) 156 | return -1; 157 | if (length > wr->data_length) 158 | length = wr->data_length; 159 | n = fread(data, 1, length, wr->wav); 160 | wr->data_length -= length; 161 | return n; 162 | } 163 | 164 | -------------------------------------------------------------------------------- /wavreader.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ 2 | * Copyright (C) 2009 Martin Storsjo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 | * express or implied. 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * ------------------------------------------------------------------- 17 | */ 18 | 19 | #ifndef WAVREADER_H 20 | #define WAVREADER_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | void* wav_read_open(const char *filename); 27 | void wav_read_close(void* obj); 28 | 29 | int wav_get_header(void* obj, int* format, int* channels, int* sample_rate, int* bits_per_sample, unsigned int* data_length); 30 | int wav_read_data(void* obj, unsigned char* data, unsigned int length); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /wrapper.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ 2 | * Copyright (C) 2010 Martin Storsjo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 | * express or implied. 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * ------------------------------------------------------------------- 17 | */ 18 | 19 | #include "enc_if.h" 20 | #include 21 | #include 22 | #include 23 | 24 | struct encoder_state { 25 | VO_AUDIO_CODECAPI audioApi; 26 | VO_HANDLE handle; 27 | VO_MEM_OPERATOR memOperator; 28 | VO_CODEC_INIT_USERDATA userData; 29 | }; 30 | 31 | void* E_IF_init(void) { 32 | struct encoder_state* state = (struct encoder_state*) malloc(sizeof(struct encoder_state)); 33 | int frameType = VOAMRWB_RFC3267; 34 | voGetAMRWBEncAPI(&state->audioApi); 35 | state->memOperator.Alloc = cmnMemAlloc; 36 | state->memOperator.Copy = cmnMemCopy; 37 | state->memOperator.Free = cmnMemFree; 38 | state->memOperator.Set = cmnMemSet; 39 | state->memOperator.Check = cmnMemCheck; 40 | state->userData.memflag = VO_IMF_USERMEMOPERATOR; 41 | state->userData.memData = (VO_PTR)&state->memOperator; 42 | state->audioApi.Init(&state->handle, VO_AUDIO_CodingAMRWB, &state->userData); 43 | state->audioApi.SetParam(state->handle, VO_PID_AMRWB_FRAMETYPE, &frameType); 44 | return state; 45 | } 46 | 47 | void E_IF_exit(void* s) { 48 | struct encoder_state* state = (struct encoder_state*) s; 49 | state->audioApi.Uninit(state->handle); 50 | free(state); 51 | } 52 | 53 | int E_IF_encode(void* s, int mode, const short* speech, unsigned char* out, int dtx) { 54 | VO_CODECBUFFER inData, outData; 55 | VO_AUDIO_OUTPUTINFO outFormat; 56 | struct encoder_state* state = (struct encoder_state*) s; 57 | 58 | state->audioApi.SetParam(state->handle, VO_PID_AMRWB_MODE, &mode); 59 | state->audioApi.SetParam(state->handle, VO_PID_AMRWB_DTX, &dtx); 60 | inData.Buffer = (unsigned char*) speech; 61 | inData.Length = 640; 62 | outData.Buffer = out; 63 | state->audioApi.SetInputData(state->handle, &inData); 64 | state->audioApi.GetOutputData(state->handle, &outData, &outFormat); 65 | return outData.Length; 66 | } 67 | 68 | --------------------------------------------------------------------------------