├── MODULE_LICENSE_BSD_LIKE ├── TEST_MAPPING ├── PREUPLOAD.cfg ├── README.version ├── OWNERS ├── README ├── tests ├── Android.bp └── test_floor0.cpp ├── NOTICE ├── Android.bp ├── Tremolo ├── config_types.h ├── floor1LARM.s ├── floor1ARM.s ├── mdct.h ├── os.h ├── codebook.h ├── os_types.h ├── ivorbiscodec.h ├── lsp_lookup.h ├── ivorbisfile.h ├── floor_lookup.c ├── misc.h ├── misc.c ├── asm_arm.h ├── codec_internal.h ├── mapping0.c ├── ogg.h ├── res012.c ├── dsp.c ├── floor1.c ├── bitwiseARM.s ├── treminfo.c ├── dpen.s ├── floor0.c └── mdct.c └── CleanSpec.mk /MODULE_LICENSE_BSD_LIKE: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /TEST_MAPPING: -------------------------------------------------------------------------------- 1 | { 2 | "presubmit": [ 3 | { "name": "oob_oggpack_look" } 4 | ] 5 | } 6 | 7 | -------------------------------------------------------------------------------- /PREUPLOAD.cfg: -------------------------------------------------------------------------------- 1 | [Hook Scripts] 2 | mainline_hook = ${REPO_ROOT}/frameworks/av/tools/mainline_hook_project.sh 3 | -------------------------------------------------------------------------------- /README.version: -------------------------------------------------------------------------------- 1 | URL: http://wss.co.uk/pinknoise/tremolo/Tremolo007.zip 2 | Version: 0.07 3 | BugComponent: 99142 4 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # Default code reviewers picked from top 3 or more developers. 2 | # Please update this list if you find better candidates. 3 | marcone@google.com 4 | dwkang@google.com 5 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This version of Tremolo is derived from Tremolo library version 2 | 0.07. It has been patched against publicly known vulnerabilities 3 | with sample files available here: 4 | 5 | http://static.dataspill.org/releases/ogg/examples/ 6 | 7 | When syncing with svn, please ensure that these defects are not 8 | reintroduced. 9 | -------------------------------------------------------------------------------- /tests/Android.bp: -------------------------------------------------------------------------------- 1 | cc_test { 2 | name: "oob_oggpack_look", 3 | gtest: true, 4 | test_suites: ["device-tests"], 5 | 6 | srcs: ["test_floor0.cpp"], 7 | 8 | // compile_multilib: "64", 9 | 10 | static_libs: [ 11 | "libvorbisidec", 12 | "liblog", 13 | ], 14 | 15 | shared_libs: [ 16 | "libutils", 17 | "liblog", 18 | ], 19 | 20 | cflags: [ 21 | "-Wall", 22 | "-Werror", 23 | ], 24 | 25 | sanitize: { 26 | integer_overflow: true, 27 | misc_undefined: ["bounds"], 28 | diag: { 29 | integer_overflow: true, 30 | undefined: true, 31 | misc_undefined: ["bounds"], 32 | }, 33 | }, 34 | } 35 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2002-2009, Xiph.org Foundation 2 | Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | * Neither the names of the Xiph.org Foundation nor Pinknoise 16 | Productions Ltd nor the names of its contributors may be used to 17 | endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /Android.bp: -------------------------------------------------------------------------------- 1 | cc_library { 2 | name: "libvorbisidec", 3 | vendor_available: true, 4 | 5 | srcs: [ 6 | "Tremolo/bitwise.c", 7 | "Tremolo/codebook.c", 8 | "Tremolo/dsp.c", 9 | "Tremolo/floor0.c", 10 | "Tremolo/floor1.c", 11 | "Tremolo/floor_lookup.c", 12 | "Tremolo/framing.c", 13 | "Tremolo/mapping0.c", 14 | "Tremolo/mdct.c", 15 | "Tremolo/misc.c", 16 | "Tremolo/res012.c", 17 | "Tremolo/treminfo.c", 18 | "Tremolo/vorbisfile.c", 19 | ], 20 | 21 | arch: { 22 | arm: { 23 | srcs: [ 24 | "Tremolo/bitwiseARM.s", 25 | "Tremolo/dpen.s", 26 | "Tremolo/floor1ARM.s", 27 | "Tremolo/mdctARM.s", 28 | ], 29 | cflags: ["-D_ARM_ASSEM_"], 30 | // Assembly code in asm_arm.h does not compile with Clang. 31 | clang_asflags: ["-no-integrated-as"], 32 | 33 | instruction_set: "arm", 34 | }, 35 | arm64: { 36 | cflags: ["-DONLY_C"], 37 | }, 38 | mips: { 39 | cflags: ["-DONLY_C"], 40 | }, 41 | mips64: { 42 | cflags: ["-DONLY_C"], 43 | }, 44 | x86: { 45 | cflags: ["-DONLY_C"], 46 | }, 47 | x86_64: { 48 | cflags: ["-DONLY_C"], 49 | }, 50 | }, 51 | 52 | cflags: [ 53 | "-O2", 54 | "-D_GNU_SOURCE", 55 | "-funsigned-char", 56 | "-Wall", 57 | "-Werror", 58 | "-Wno-unused-variable", 59 | ], 60 | 61 | local_include_dirs: ["Tremolo"], 62 | export_include_dirs: ["."], 63 | 64 | shared_libs: ["liblog"], 65 | 66 | sanitize: { 67 | integer_overflow: true, 68 | misc_undefined: ["bounds"], 69 | }, 70 | 71 | min_sdk_version: "29", 72 | } 73 | -------------------------------------------------------------------------------- /Tremolo/config_types.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: #ifdef jail to whip a few platforms into the UNIX ideal. 35 | 36 | ************************************************************************/ 37 | #ifndef _OS_CVTYPES_H 38 | #define _OS_CVTYPES_H 39 | 40 | typedef long long ogg_int64_t; 41 | typedef int ogg_int32_t; 42 | typedef unsigned int ogg_uint32_t; 43 | typedef short ogg_int16_t; 44 | typedef unsigned short ogg_uint16_t; 45 | typedef unsigned char ogg_uint8_t; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | 47 | # ************************************************ 48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 49 | # ************************************************ 50 | -------------------------------------------------------------------------------- /Tremolo/floor1LARM.s: -------------------------------------------------------------------------------- 1 | @ Tremolo library 2 | @----------------------------------------------------------------------- 3 | @ Copyright (C) 2002-2009, Xiph.org Foundation 4 | @ Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 5 | @ All rights reserved. 6 | 7 | @ Redistribution and use in source and binary forms, with or without 8 | @ modification, are permitted provided that the following conditions 9 | @ are met: 10 | 11 | @ * Redistributions of source code must retain the above copyright 12 | @ notice, this list of conditions and the following disclaimer. 13 | @ * Redistributions in binary form must reproduce the above 14 | @ copyright notice, this list of conditions and the following disclaimer 15 | @ in the documentation and/or other materials provided with the 16 | @ distribution. 17 | @ * Neither the names of the Xiph.org Foundation nor Pinknoise 18 | @ Productions Ltd nor the names of its contributors may be used to 19 | @ endorse or promote products derived from this software without 20 | @ specific prior written permission. 21 | @ 22 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | @ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | @ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | @ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | @ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | @ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | @ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | @ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | @ ---------------------------------------------------------------------- 34 | 35 | .text 36 | 37 | .global render_lineARM 38 | 39 | render_lineARM: 40 | @ r0 = n 41 | @ r1 = d 42 | @ r2 = floor 43 | @ r3 = base 44 | @ <> = err 45 | @ <> = adx 46 | @ <> = ady 47 | MOV r12,r13 48 | STMFD r13!,{r4-r6,r11,r14} 49 | LDMFD r12,{r11,r12,r14} @ r11 = err 50 | @ r12 = adx 51 | @ r14 = ady 52 | rl_loop: 53 | LDR r4, [r1] @ r4 = *d 54 | LDR r5, [r2], r3,LSL #2 @ r5 = *floor r2 = floor+base 55 | SUBS r11,r11,r14 @ err -= ady 56 | MOV r4, r4, ASR #6 57 | MUL r5, r4, r5 @ r5 = MULT31_SHIFT15 58 | ADDLT r11,r11,r12 @ if (err < 0) err+=adx 59 | ADDLT r2, r2, #4 @ floor+=1 60 | SUBS r0, r0, #1 61 | STR r5, [r1], #4 62 | BGT rl_loop 63 | 64 | LDMFD r13!,{r4-r6,r11,PC} 65 | 66 | @ END 67 | -------------------------------------------------------------------------------- /Tremolo/floor1ARM.s: -------------------------------------------------------------------------------- 1 | @ Tremolo library 2 | @----------------------------------------------------------------------- 3 | @ Copyright (C) 2002-2009, Xiph.org Foundation 4 | @ Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 5 | @ All rights reserved. 6 | 7 | @ Redistribution and use in source and binary forms, with or without 8 | @ modification, are permitted provided that the following conditions 9 | @ are met: 10 | 11 | @ * Redistributions of source code must retain the above copyright 12 | @ notice, this list of conditions and the following disclaimer. 13 | @ * Redistributions in binary form must reproduce the above 14 | @ copyright notice, this list of conditions and the following disclaimer 15 | @ in the documentation and/or other materials provided with the 16 | @ distribution. 17 | @ * Neither the names of the Xiph.org Foundation nor Pinknoise 18 | @ Productions Ltd nor the names of its contributors may be used to 19 | @ endorse or promote products derived from this software without 20 | @ specific prior written permission. 21 | @ 22 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | @ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | @ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | @ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | @ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | @ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | @ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | @ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | @ ---------------------------------------------------------------------- 34 | 35 | .text 36 | 37 | .global render_lineARM 38 | 39 | render_lineARM: 40 | @ r0 = n 41 | @ r1 = d 42 | @ r2 = floor 43 | @ r3 = base 44 | @ <> = err 45 | @ <> = adx 46 | @ <> = ady 47 | MOV r12,r13 48 | STMFD r13!,{r4-r6,r11,r14} 49 | LDMFD r12,{r11,r12,r14} @ r11 = err 50 | @ r12 = adx 51 | @ r14 = ady 52 | rl_loop: 53 | LDR r4,[r1] @ r4 = *d 54 | LDR r5,[r2],r3,LSL #2 @ r5 = *floor r2 = floor+base 55 | SUBS r11,r11,r14 @ err -= ady 56 | ADDLT r11,r11,r12 @ if (err < 0) err+=adx 57 | SMULL r6, r5, r4, r5 @ (r6,r5) = *d * *floor 58 | ADDLT r2, r2, #4 @ floor+=1 59 | MOVS r6, r6, LSR #15 60 | ADC r5, r6, r5, LSL #17 @ r5 = MULT31_SHIFT15 61 | STR r5,[r1],#4 62 | SUBS r0, r0, #1 63 | BGT rl_loop 64 | 65 | LDMFD r13!,{r4-r6,r11,PC} 66 | 67 | @ END 68 | -------------------------------------------------------------------------------- /Tremolo/mdct.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: modified discrete cosine transform prototypes 35 | 36 | ************************************************************************/ 37 | 38 | #ifndef _OGG_mdct_H_ 39 | #define _OGG_mdct_H_ 40 | 41 | #include "ivorbiscodec.h" 42 | #include "misc.h" 43 | 44 | #define DATA_TYPE ogg_int32_t 45 | #define REG_TYPE register ogg_int32_t 46 | 47 | #ifdef _LOW_ACCURACY_ 48 | #define cPI3_8 (0x0062) 49 | #define cPI2_8 (0x00b5) 50 | #define cPI1_8 (0x00ed) 51 | #else 52 | #define cPI3_8 (0x30fbc54d) 53 | #define cPI2_8 (0x5a82799a) 54 | #define cPI1_8 (0x7641af3d) 55 | #endif 56 | 57 | extern void mdct_backward(int n, DATA_TYPE *in); 58 | extern void mdct_shift_right(int n, DATA_TYPE *in, DATA_TYPE *right); 59 | extern void mdct_unroll_lap(int n0,int n1, 60 | int lW,int W, 61 | DATA_TYPE *in,DATA_TYPE *right, 62 | LOOKUP_T *w0,LOOKUP_T *w1, 63 | ogg_int16_t *out, 64 | int step, 65 | int start,int end /* samples, this frame */); 66 | 67 | #endif 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /Tremolo/os.h: -------------------------------------------------------------------------------- 1 | #ifndef _OS_H 2 | #define _OS_H 3 | /************************************************************************ 4 | * Copyright (C) 2002-2009, Xiph.org Foundation 5 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above 15 | * copyright notice, this list of conditions and the following disclaimer 16 | * in the documentation and/or other materials provided with the 17 | * distribution. 18 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 19 | * Productions Ltd nor the names of its contributors may be used to 20 | * endorse or promote products derived from this software without 21 | * specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | ************************************************************************ 35 | 36 | function: #ifdef jail to whip a few platforms into the UNIX ideal. 37 | 38 | ************************************************************************/ 39 | 40 | #include 41 | #include "os_types.h" 42 | 43 | #ifndef _V_IFDEFJAIL_H_ 44 | # define _V_IFDEFJAIL_H_ 45 | 46 | # ifdef __GNUC__ 47 | # define STIN static __inline__ 48 | # elif _WIN32 49 | # define STIN static __inline 50 | # endif 51 | #else 52 | # define STIN static 53 | #endif 54 | 55 | #ifndef M_PI 56 | # define M_PI (3.1415926536f) 57 | #endif 58 | 59 | #ifdef _WIN32 60 | # include 61 | # define rint(x) (floor((x)+0.5f)) 62 | # define NO_FLOAT_MATH_LIB 63 | # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b)) 64 | #endif 65 | 66 | #ifdef HAVE_ALLOCA_H 67 | # include 68 | #endif 69 | 70 | #ifdef USE_MEMORY_H 71 | # include 72 | #endif 73 | 74 | #ifndef min 75 | # define min(x,y) ((x)>(y)?(y):(x)) 76 | #endif 77 | 78 | #ifndef max 79 | # define max(x,y) ((x)<(y)?(y):(x)) 80 | #endif 81 | 82 | #endif /* _OS_H */ 83 | -------------------------------------------------------------------------------- /Tremolo/codebook.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: basic shared codebook operations 35 | 36 | ************************************************************************/ 37 | 38 | #ifndef _V_CODEBOOK_H_ 39 | #define _V_CODEBOOK_H_ 40 | 41 | #include "ogg.h" 42 | 43 | typedef struct codebook{ 44 | /* Top 15 used in ARM code */ 45 | int dec_maxlength; 46 | void *dec_table; 47 | int dec_method; 48 | int dec_type; /* 0 = entry number 49 | 1 = packed vector of values 50 | 2 = packed vector of column offsets, maptype 1 51 | 3 = scalar offset into value array, maptype 2 */ 52 | int q_bits; 53 | long dim; /* codebook dimensions (elements per vector) */ 54 | int q_delp; 55 | int q_minp; 56 | ogg_int32_t q_del; 57 | ogg_int32_t q_min; 58 | int q_seq; 59 | int q_pack; 60 | void *q_val; 61 | long used_entries; /* populated codebook entries */ 62 | ogg_int32_t *dec_buf; 63 | 64 | /* C only */ 65 | int dec_nodeb; 66 | int dec_leafw; 67 | 68 | long entries; /* codebook entries */ 69 | 70 | } codebook; 71 | 72 | extern void vorbis_book_clear(codebook *b); 73 | extern int vorbis_book_unpack(oggpack_buffer *b,codebook *c); 74 | 75 | extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); 76 | extern long vorbis_book_decodevs_add(codebook *book, ogg_int32_t *a, 77 | oggpack_buffer *b,int n,int point); 78 | extern long vorbis_book_decodev_set(codebook *book, ogg_int32_t *a, 79 | oggpack_buffer *b,int n,int point); 80 | extern long vorbis_book_decodev_add(codebook *book, ogg_int32_t *a, 81 | oggpack_buffer *b,int n,int point); 82 | extern long vorbis_book_decodevv_add(codebook *book, ogg_int32_t **a, 83 | long off,int ch, 84 | oggpack_buffer *b,int n,int point); 85 | 86 | extern int _ilog(unsigned int v); 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /tests/test_floor0.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test case not really written for gtest, but wrapped so it'll cooperate. 3 | */ 4 | 5 | //#define LOG_NDEBUG 0 6 | #define LOG_TAG "Utils_test" 7 | 8 | #include 9 | 10 | #include 11 | #define REF_COUNT 1 12 | #define DECODE_PACKET 1 13 | 14 | extern "C" { 15 | #include 16 | 17 | int _vorbis_unpack_books(vorbis_info *vi, oggpack_buffer *opb); 18 | int _vorbis_unpack_info(vorbis_info *vi, oggpack_buffer *opb); 19 | int _vorbis_unpack_comment(vorbis_comment *vc, oggpack_buffer *opb); 20 | } 21 | 22 | const uint8_t packInfoData[] = { 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0xBB, 0x00, 23 | 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 24 | 0x00, 0xBB, 0x01, 0xFF, 0xFF, 0xFF, 0xFF }; 25 | 26 | unsigned char unpackBookData[] = { 0x00, 0x42, 0x43, 0x56, 0x1E, 0x00, 0x10, 27 | 0x00, 0x00, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x10, 0x0A, 0xFF, 0x00, 0x00, 28 | 0x00, 0x06, 0xD0, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x1D, 0x00, 0x00, 0x00, 29 | 0x2C, 0x00, 0x03, 0x3C, 0x51, 0x04, 0x34, 0x4F, 0x04, 0x00, 0x40, 0x00, 30 | 0x00, 0x00, 0x00, 0x00, 0xCB, 0x00, 0x40, 0x00, 0x00, 0x01, 0x4F, 0xF4, 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xFF, 0xFF, 0xFF, 0xFF }; 35 | 36 | unsigned char bufData[] = { 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xE7, 37 | 0x00, 0x00, 0xE9, 0x00 }; 38 | 39 | static void makeBitReader(const void *data, size_t size, ogg_buffer *buf, 40 | ogg_reference *ref, oggpack_buffer *bits) { 41 | buf->data = (uint8_t *) data; 42 | buf->size = size; 43 | buf->refcount = REF_COUNT; 44 | 45 | ref->buffer = buf; 46 | ref->length = size; 47 | oggpack_readinit(bits, ref); 48 | } 49 | 50 | // below here is where we're trying to bridge the gtest and non-gtest world 51 | 52 | namespace android { 53 | 54 | class Floor0Test : public ::testing::Test { 55 | }; 56 | 57 | // 58 | // the test, since it compiles with ubsan, should fault and die if the patch 59 | // is not in place. at least that's the idea. 60 | TEST_F(Floor0Test, Test1) { 61 | 62 | ogg_buffer buf; 63 | ogg_reference ref; 64 | oggpack_buffer bits; 65 | 66 | memset(&buf, 0, sizeof(ogg_buffer)); 67 | memset(&ref, 0, sizeof(ogg_reference)); 68 | memset(&bits, 0, sizeof(oggpack_buffer)); 69 | 70 | makeBitReader(packInfoData, sizeof(packInfoData), &buf, &ref, &bits); 71 | 72 | vorbis_info *mVi = new vorbis_info; 73 | vorbis_info_init(mVi); 74 | 75 | int ret = _vorbis_unpack_info(mVi, &bits); 76 | if (!ret) { 77 | memset(&buf, 0, sizeof(ogg_buffer)); 78 | memset(&ref, 0, sizeof(ogg_reference)); 79 | memset(&bits, 0, sizeof(oggpack_buffer)); 80 | 81 | makeBitReader(unpackBookData, sizeof(unpackBookData), &buf, &ref, 82 | &bits); 83 | 84 | ret = _vorbis_unpack_books(mVi, &bits); 85 | if (!ret) { 86 | ogg_packet pack; 87 | memset(&pack, 0, sizeof(ogg_packet)); 88 | memset(&buf, 0, sizeof(ogg_buffer)); 89 | memset(&ref, 0, sizeof(ogg_reference)); 90 | 91 | vorbis_dsp_state *mState = new vorbis_dsp_state; 92 | vorbis_dsp_init(mState, mVi); 93 | 94 | buf.data = bufData; 95 | buf.size = sizeof(bufData); 96 | buf.refcount = REF_COUNT; 97 | 98 | ref.buffer = &buf; 99 | ref.length = buf.size; 100 | 101 | pack.packet = &ref; 102 | pack.bytes = ref.length; 103 | 104 | vorbis_dsp_synthesis(mState, &pack, DECODE_PACKET); 105 | } 106 | } 107 | } 108 | 109 | } // namespace android 110 | -------------------------------------------------------------------------------- /Tremolo/os_types.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: #ifdef jail to whip a few platforms into the UNIX ideal. 35 | 36 | ************************************************************************/ 37 | #ifndef _OS_TYPES_H 38 | #define _OS_TYPES_H 39 | 40 | #ifdef _LOW_ACCURACY_ 41 | # define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9)) 42 | # define LOOKUP_T const unsigned char 43 | #else 44 | # define X(n) (n) 45 | # define LOOKUP_T const ogg_int32_t 46 | #endif 47 | 48 | /* make it easy on the folks that want to compile the libs with a 49 | different malloc than stdlib */ 50 | #define _ogg_malloc malloc 51 | #define _ogg_calloc calloc 52 | #define _ogg_realloc realloc 53 | #define _ogg_free free 54 | 55 | #if defined (_WIN32_WCE) 56 | 57 | typedef unsigned short ogg_uint16_t; 58 | typedef short ogg_int16_t; 59 | typedef int ogg_int32_t; 60 | typedef unsigned int ogg_uint32_t; 61 | typedef __int64 ogg_int64_t; 62 | 63 | #define inline 64 | 65 | #elif defined(_WIN32) 66 | 67 | # ifndef __GNUC__ 68 | /* MSVC/Borland */ 69 | typedef __int64 ogg_int64_t; 70 | typedef __int32 ogg_int32_t; 71 | typedef unsigned __int32 ogg_uint32_t; 72 | typedef __int16 ogg_int16_t; 73 | typedef unsigned __int16 ogg_uint16_t; 74 | # else 75 | /* Cygwin */ 76 | #include <_G_config.h> 77 | typedef _G_int64_t ogg_int64_t; 78 | typedef _G_int32_t ogg_int32_t; 79 | typedef _G_uint32_t ogg_uint32_t; 80 | typedef _G_int16_t ogg_int16_t; 81 | typedef _G_uint16_t ogg_uint16_t; 82 | # endif 83 | 84 | #elif defined(__MACOS__) 85 | 86 | # include 87 | typedef SInt16 ogg_int16_t; 88 | typedef UInt16 ogg_uint16_t; 89 | typedef SInt32 ogg_int32_t; 90 | typedef UInt32 ogg_uint32_t; 91 | typedef SInt64 ogg_int64_t; 92 | 93 | #elif defined(__MACOSX__) /* MacOS X Framework build */ 94 | 95 | # include 96 | typedef int16_t ogg_int16_t; 97 | typedef u_int16_t ogg_uint16_t; 98 | typedef int32_t ogg_int32_t; 99 | typedef u_int32_t ogg_uint32_t; 100 | typedef int64_t ogg_int64_t; 101 | 102 | #elif defined(__BEOS__) 103 | 104 | /* Be */ 105 | # include 106 | 107 | #elif defined (__EMX__) 108 | 109 | /* OS/2 GCC */ 110 | typedef short ogg_int16_t; 111 | typedef unsigned short ogg_uint16_t; 112 | typedef int ogg_int32_t; 113 | typedef unsigned int ogg_uint32_t; 114 | typedef long long ogg_int64_t; 115 | 116 | #else 117 | 118 | # include 119 | # include "config_types.h" 120 | # include 121 | 122 | #endif 123 | 124 | #endif /* _OS_TYPES_H */ 125 | -------------------------------------------------------------------------------- /Tremolo/ivorbiscodec.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: libvorbis codec headers 35 | 36 | ************************************************************************/ 37 | 38 | #ifndef _vorbis_codec_h_ 39 | #define _vorbis_codec_h_ 40 | 41 | #ifdef __cplusplus 42 | extern "C" 43 | { 44 | #endif /* __cplusplus */ 45 | 46 | #include "ogg.h" 47 | 48 | struct vorbis_dsp_state; 49 | typedef struct vorbis_dsp_state vorbis_dsp_state; 50 | 51 | typedef struct vorbis_info{ 52 | int version; 53 | int channels; 54 | long rate; 55 | 56 | /* The below bitrate declarations are *hints*. 57 | Combinations of the three values carry the following implications: 58 | 59 | all three set to the same value: 60 | implies a fixed rate bitstream 61 | only nominal set: 62 | implies a VBR stream that averages the nominal bitrate. No hard 63 | upper/lower limit 64 | upper and or lower set: 65 | implies a VBR bitstream that obeys the bitrate limits. nominal 66 | may also be set to give a nominal rate. 67 | none set: 68 | the coder does not care to speculate. 69 | */ 70 | 71 | long bitrate_upper; 72 | long bitrate_nominal; 73 | long bitrate_lower; 74 | long bitrate_window; 75 | 76 | void *codec_setup; 77 | } vorbis_info; 78 | 79 | typedef struct vorbis_comment{ 80 | char **user_comments; 81 | int *comment_lengths; 82 | int comments; 83 | char *vendor; 84 | 85 | } vorbis_comment; 86 | 87 | 88 | /* Vorbis PRIMITIVES: general ***************************************/ 89 | 90 | extern void vorbis_info_init(vorbis_info *vi); 91 | extern void vorbis_info_clear(vorbis_info *vi); 92 | extern int vorbis_info_blocksize(vorbis_info *vi,int zo); 93 | extern void vorbis_comment_init(vorbis_comment *vc); 94 | extern void vorbis_comment_add(vorbis_comment *vc, char *comment); 95 | extern void vorbis_comment_add_tag(vorbis_comment *vc, 96 | char *tag, char *contents); 97 | extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count); 98 | extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag); 99 | extern void vorbis_comment_clear(vorbis_comment *vc); 100 | 101 | /* Vorbis ERRORS and return codes ***********************************/ 102 | 103 | #define OV_FALSE -1 104 | #define OV_EOF -2 105 | #define OV_HOLE -3 106 | 107 | #define OV_EREAD -128 108 | #define OV_EFAULT -129 109 | #define OV_EIMPL -130 110 | #define OV_EINVAL -131 111 | #define OV_ENOTVORBIS -132 112 | #define OV_EBADHEADER -133 113 | #define OV_EVERSION -134 114 | #define OV_ENOTAUDIO -135 115 | #define OV_EBADPACKET -136 116 | #define OV_EBADLINK -137 117 | #define OV_ENOSEEK -138 118 | 119 | #ifdef __cplusplus 120 | } 121 | #endif /* __cplusplus */ 122 | 123 | #endif 124 | 125 | -------------------------------------------------------------------------------- /Tremolo/lsp_lookup.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: lookup data 35 | 36 | ************************************************************************/ 37 | 38 | #ifndef _V_LOOKUP_DATA_H_ 39 | #define _V_LOOKUP_DATA_H_ 40 | 41 | #include "os_types.h" 42 | 43 | #define INVSQ_LOOKUP_I_SHIFT 10 44 | #define INVSQ_LOOKUP_I_MASK 1023 45 | static const long INVSQ_LOOKUP_I[64+1]={ 46 | 92682, 91966, 91267, 90583, 47 | 89915, 89261, 88621, 87995, 48 | 87381, 86781, 86192, 85616, 49 | 85051, 84497, 83953, 83420, 50 | 82897, 82384, 81880, 81385, 51 | 80899, 80422, 79953, 79492, 52 | 79039, 78594, 78156, 77726, 53 | 77302, 76885, 76475, 76072, 54 | 75674, 75283, 74898, 74519, 55 | 74146, 73778, 73415, 73058, 56 | 72706, 72359, 72016, 71679, 57 | 71347, 71019, 70695, 70376, 58 | 70061, 69750, 69444, 69141, 59 | 68842, 68548, 68256, 67969, 60 | 67685, 67405, 67128, 66855, 61 | 66585, 66318, 66054, 65794, 62 | 65536, 63 | }; 64 | 65 | static const long INVSQ_LOOKUP_IDel[64]={ 66 | 716, 699, 684, 668, 67 | 654, 640, 626, 614, 68 | 600, 589, 576, 565, 69 | 554, 544, 533, 523, 70 | 513, 504, 495, 486, 71 | 477, 469, 461, 453, 72 | 445, 438, 430, 424, 73 | 417, 410, 403, 398, 74 | 391, 385, 379, 373, 75 | 368, 363, 357, 352, 76 | 347, 343, 337, 332, 77 | 328, 324, 319, 315, 78 | 311, 306, 303, 299, 79 | 294, 292, 287, 284, 80 | 280, 277, 273, 270, 81 | 267, 264, 260, 258, 82 | }; 83 | 84 | #define COS_LOOKUP_I_SHIFT 9 85 | #define COS_LOOKUP_I_MASK 511 86 | #define COS_LOOKUP_I_SZ 128 87 | static const ogg_int32_t COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={ 88 | 16384, 16379, 16364, 16340, 89 | 16305, 16261, 16207, 16143, 90 | 16069, 15986, 15893, 15791, 91 | 15679, 15557, 15426, 15286, 92 | 15137, 14978, 14811, 14635, 93 | 14449, 14256, 14053, 13842, 94 | 13623, 13395, 13160, 12916, 95 | 12665, 12406, 12140, 11866, 96 | 11585, 11297, 11003, 10702, 97 | 10394, 10080, 9760, 9434, 98 | 9102, 8765, 8423, 8076, 99 | 7723, 7366, 7005, 6639, 100 | 6270, 5897, 5520, 5139, 101 | 4756, 4370, 3981, 3590, 102 | 3196, 2801, 2404, 2006, 103 | 1606, 1205, 804, 402, 104 | 0, -401, -803, -1204, 105 | -1605, -2005, -2403, -2800, 106 | -3195, -3589, -3980, -4369, 107 | -4755, -5138, -5519, -5896, 108 | -6269, -6638, -7004, -7365, 109 | -7722, -8075, -8422, -8764, 110 | -9101, -9433, -9759, -10079, 111 | -10393, -10701, -11002, -11296, 112 | -11584, -11865, -12139, -12405, 113 | -12664, -12915, -13159, -13394, 114 | -13622, -13841, -14052, -14255, 115 | -14448, -14634, -14810, -14977, 116 | -15136, -15285, -15425, -15556, 117 | -15678, -15790, -15892, -15985, 118 | -16068, -16142, -16206, -16260, 119 | -16304, -16339, -16363, -16378, 120 | -16383, 121 | }; 122 | 123 | #endif 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /Tremolo/ivorbisfile.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: stdio-based convenience library for opening/seeking/decoding 35 | 36 | ************************************************************************/ 37 | 38 | #ifndef _OV_FILE_H_ 39 | #define _OV_FILE_H_ 40 | 41 | #ifdef __cplusplus 42 | extern "C" 43 | { 44 | #endif /* __cplusplus */ 45 | 46 | #include 47 | #include "ivorbiscodec.h" 48 | 49 | /* The function prototypes for the callbacks are basically the same as for 50 | * the stdio functions fread, fseek, fclose, ftell. 51 | * The one difference is that the FILE * arguments have been replaced with 52 | * a void * - this is to be used as a pointer to whatever internal data these 53 | * functions might need. In the stdio case, it's just a FILE * cast to a void * 54 | * 55 | * If you use other functions, check the docs for these functions and return 56 | * the right values. For seek_func(), you *MUST* return -1 if the stream is 57 | * unseekable 58 | */ 59 | typedef struct { 60 | size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource); 61 | int (*seek_func) (void *datasource, ogg_int64_t offset, int whence); 62 | int (*close_func) (void *datasource); 63 | long (*tell_func) (void *datasource); 64 | } ov_callbacks; 65 | 66 | typedef struct OggVorbis_File { 67 | void *datasource; /* Pointer to a FILE *, etc. */ 68 | int seekable; 69 | ogg_int64_t offset; 70 | ogg_int64_t end; 71 | ogg_sync_state *oy; 72 | 73 | /* If the FILE handle isn't seekable (eg, a pipe), only the current 74 | stream appears */ 75 | int links; 76 | ogg_int64_t *offsets; 77 | ogg_int64_t *dataoffsets; 78 | ogg_uint32_t *serialnos; 79 | ogg_int64_t *pcmlengths; 80 | vorbis_info vi; 81 | vorbis_comment vc; 82 | 83 | /* Decoding working state local storage */ 84 | ogg_int64_t pcm_offset; 85 | int ready_state; 86 | ogg_uint32_t current_serialno; 87 | int current_link; 88 | 89 | ogg_int64_t bittrack; 90 | ogg_int64_t samptrack; 91 | 92 | ogg_stream_state *os; /* take physical pages, weld into a logical 93 | stream of packets */ 94 | vorbis_dsp_state *vd; /* central working state for the packet->PCM decoder */ 95 | 96 | ov_callbacks callbacks; 97 | 98 | } OggVorbis_File; 99 | 100 | extern int ov_clear(OggVorbis_File *vf); 101 | extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes); 102 | extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf, 103 | char *initial, long ibytes, ov_callbacks callbacks); 104 | 105 | extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes); 106 | extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf, 107 | char *initial, long ibytes, ov_callbacks callbacks); 108 | extern int ov_test_open(OggVorbis_File *vf); 109 | 110 | extern long ov_bitrate(OggVorbis_File *vf,int i); 111 | extern long ov_bitrate_instant(OggVorbis_File *vf); 112 | extern long ov_streams(OggVorbis_File *vf); 113 | extern long ov_seekable(OggVorbis_File *vf); 114 | extern long ov_serialnumber(OggVorbis_File *vf,int i); 115 | 116 | extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i); 117 | extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i); 118 | extern ogg_int64_t ov_time_total(OggVorbis_File *vf,int i); 119 | 120 | extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos); 121 | extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos); 122 | extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos); 123 | extern int ov_time_seek(OggVorbis_File *vf,ogg_int64_t pos); 124 | extern int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t pos); 125 | 126 | extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf); 127 | extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf); 128 | extern ogg_int64_t ov_time_tell(OggVorbis_File *vf); 129 | 130 | extern vorbis_info *ov_info(OggVorbis_File *vf,int link); 131 | extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link); 132 | 133 | extern long ov_read(OggVorbis_File *vf,void *buffer,int length, 134 | int *bitstream); 135 | 136 | #ifdef __cplusplus 137 | } 138 | #endif /* __cplusplus */ 139 | 140 | #endif 141 | 142 | 143 | -------------------------------------------------------------------------------- /Tremolo/floor_lookup.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: floor dB lookup 35 | 36 | ************************************************************************/ 37 | 38 | #include "os.h" 39 | 40 | #ifdef _LOW_ACCURACY_ 41 | # define XdB(n) ((((n)>>8)+1)>>1) 42 | #else 43 | # define XdB(n) (n) 44 | #endif 45 | 46 | const ogg_int32_t FLOOR_fromdB_LOOKUP[256]={ 47 | XdB(0x000000e5), XdB(0x000000f4), XdB(0x00000103), XdB(0x00000114), 48 | XdB(0x00000126), XdB(0x00000139), XdB(0x0000014e), XdB(0x00000163), 49 | XdB(0x0000017a), XdB(0x00000193), XdB(0x000001ad), XdB(0x000001c9), 50 | XdB(0x000001e7), XdB(0x00000206), XdB(0x00000228), XdB(0x0000024c), 51 | XdB(0x00000272), XdB(0x0000029b), XdB(0x000002c6), XdB(0x000002f4), 52 | XdB(0x00000326), XdB(0x0000035a), XdB(0x00000392), XdB(0x000003cd), 53 | XdB(0x0000040c), XdB(0x00000450), XdB(0x00000497), XdB(0x000004e4), 54 | XdB(0x00000535), XdB(0x0000058c), XdB(0x000005e8), XdB(0x0000064a), 55 | XdB(0x000006b3), XdB(0x00000722), XdB(0x00000799), XdB(0x00000818), 56 | XdB(0x0000089e), XdB(0x0000092e), XdB(0x000009c6), XdB(0x00000a69), 57 | XdB(0x00000b16), XdB(0x00000bcf), XdB(0x00000c93), XdB(0x00000d64), 58 | XdB(0x00000e43), XdB(0x00000f30), XdB(0x0000102d), XdB(0x0000113a), 59 | XdB(0x00001258), XdB(0x0000138a), XdB(0x000014cf), XdB(0x00001629), 60 | XdB(0x0000179a), XdB(0x00001922), XdB(0x00001ac4), XdB(0x00001c82), 61 | XdB(0x00001e5c), XdB(0x00002055), XdB(0x0000226f), XdB(0x000024ac), 62 | XdB(0x0000270e), XdB(0x00002997), XdB(0x00002c4b), XdB(0x00002f2c), 63 | XdB(0x0000323d), XdB(0x00003581), XdB(0x000038fb), XdB(0x00003caf), 64 | XdB(0x000040a0), XdB(0x000044d3), XdB(0x0000494c), XdB(0x00004e10), 65 | XdB(0x00005323), XdB(0x0000588a), XdB(0x00005e4b), XdB(0x0000646b), 66 | XdB(0x00006af2), XdB(0x000071e5), XdB(0x0000794c), XdB(0x0000812e), 67 | XdB(0x00008993), XdB(0x00009283), XdB(0x00009c09), XdB(0x0000a62d), 68 | XdB(0x0000b0f9), XdB(0x0000bc79), XdB(0x0000c8b9), XdB(0x0000d5c4), 69 | XdB(0x0000e3a9), XdB(0x0000f274), XdB(0x00010235), XdB(0x000112fd), 70 | XdB(0x000124dc), XdB(0x000137e4), XdB(0x00014c29), XdB(0x000161bf), 71 | XdB(0x000178bc), XdB(0x00019137), XdB(0x0001ab4a), XdB(0x0001c70e), 72 | XdB(0x0001e4a1), XdB(0x0002041f), XdB(0x000225aa), XdB(0x00024962), 73 | XdB(0x00026f6d), XdB(0x000297f0), XdB(0x0002c316), XdB(0x0002f109), 74 | XdB(0x000321f9), XdB(0x00035616), XdB(0x00038d97), XdB(0x0003c8b4), 75 | XdB(0x000407a7), XdB(0x00044ab2), XdB(0x00049218), XdB(0x0004de23), 76 | XdB(0x00052f1e), XdB(0x0005855c), XdB(0x0005e135), XdB(0x00064306), 77 | XdB(0x0006ab33), XdB(0x00071a24), XdB(0x0007904b), XdB(0x00080e20), 78 | XdB(0x00089422), XdB(0x000922da), XdB(0x0009bad8), XdB(0x000a5cb6), 79 | XdB(0x000b091a), XdB(0x000bc0b1), XdB(0x000c8436), XdB(0x000d5471), 80 | XdB(0x000e3233), XdB(0x000f1e5f), XdB(0x001019e4), XdB(0x001125c1), 81 | XdB(0x00124306), XdB(0x001372d5), XdB(0x0014b663), XdB(0x00160ef7), 82 | XdB(0x00177df0), XdB(0x001904c1), XdB(0x001aa4f9), XdB(0x001c603d), 83 | XdB(0x001e384f), XdB(0x00202f0f), XdB(0x0022467a), XdB(0x002480b1), 84 | XdB(0x0026dff7), XdB(0x002966b3), XdB(0x002c1776), XdB(0x002ef4fc), 85 | XdB(0x0032022d), XdB(0x00354222), XdB(0x0038b828), XdB(0x003c67c2), 86 | XdB(0x004054ae), XdB(0x004482e8), XdB(0x0048f6af), XdB(0x004db488), 87 | XdB(0x0052c142), XdB(0x005821ff), XdB(0x005ddc33), XdB(0x0063f5b0), 88 | XdB(0x006a74a7), XdB(0x00715faf), XdB(0x0078bdce), XdB(0x0080967f), 89 | XdB(0x0088f1ba), XdB(0x0091d7f9), XdB(0x009b5247), XdB(0x00a56a41), 90 | XdB(0x00b02a27), XdB(0x00bb9ce2), XdB(0x00c7ce12), XdB(0x00d4ca17), 91 | XdB(0x00e29e20), XdB(0x00f15835), XdB(0x0101074b), XdB(0x0111bb4e), 92 | XdB(0x01238531), XdB(0x01367704), XdB(0x014aa402), XdB(0x016020a7), 93 | XdB(0x017702c3), XdB(0x018f6190), XdB(0x01a955cb), XdB(0x01c4f9cf), 94 | XdB(0x01e269a8), XdB(0x0201c33b), XdB(0x0223265a), XdB(0x0246b4ea), 95 | XdB(0x026c9302), XdB(0x0294e716), XdB(0x02bfda13), XdB(0x02ed9793), 96 | XdB(0x031e4e09), XdB(0x03522ee4), XdB(0x03896ed0), XdB(0x03c445e2), 97 | XdB(0x0402efd6), XdB(0x0445ac4b), XdB(0x048cbefc), XdB(0x04d87013), 98 | XdB(0x05290c67), XdB(0x057ee5ca), XdB(0x05da5364), XdB(0x063bb204), 99 | XdB(0x06a36485), XdB(0x0711d42b), XdB(0x0787710e), XdB(0x0804b299), 100 | XdB(0x088a17ef), XdB(0x0918287e), XdB(0x09af747c), XdB(0x0a50957e), 101 | XdB(0x0afc2f19), XdB(0x0bb2ef7f), XdB(0x0c759034), XdB(0x0d44d6ca), 102 | XdB(0x0e2195bc), XdB(0x0f0cad0d), XdB(0x10070b62), XdB(0x1111aeea), 103 | XdB(0x122da66c), XdB(0x135c120f), XdB(0x149e24d9), XdB(0x15f525b1), 104 | XdB(0x176270e3), XdB(0x18e7794b), XdB(0x1a85c9ae), XdB(0x1c3f06d1), 105 | XdB(0x1e14f07d), XdB(0x200963d7), XdB(0x221e5ccd), XdB(0x2455f870), 106 | XdB(0x26b2770b), XdB(0x29363e2b), XdB(0x2be3db5c), XdB(0x2ebe06b6), 107 | XdB(0x31c7a55b), XdB(0x3503ccd4), XdB(0x3875c5aa), XdB(0x3c210f44), 108 | XdB(0x4009632b), XdB(0x4432b8cf), XdB(0x48a149bc), XdB(0x4d59959e), 109 | XdB(0x52606733), XdB(0x57bad899), XdB(0x5d6e593a), XdB(0x6380b298), 110 | XdB(0x69f80e9a), XdB(0x70dafda8), XdB(0x78307d76), XdB(0x7fffffff), 111 | }; 112 | 113 | -------------------------------------------------------------------------------- /Tremolo/misc.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: miscellaneous math and prototypes 35 | 36 | ************************************************************************/ 37 | 38 | #ifndef _V_RANDOM_H_ 39 | #define _V_RANDOM_H_ 40 | #include "ivorbiscodec.h" 41 | #include "os_types.h" 42 | 43 | /*#define _VDBG_GRAPHFILE "_0.m"*/ 44 | 45 | 46 | #ifdef _VDBG_GRAPHFILE 47 | extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line); 48 | extern void _VDBG_free(void *ptr); 49 | 50 | #undef _ogg_malloc 51 | #undef _ogg_calloc 52 | #undef _ogg_realloc 53 | #undef _ogg_free 54 | 55 | #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__) 56 | #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__) 57 | #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__) 58 | #define _ogg_free(x) _VDBG_free((x)) 59 | #endif 60 | 61 | #include "asm_arm.h" 62 | 63 | #ifndef _V_WIDE_MATH 64 | #define _V_WIDE_MATH 65 | 66 | #ifndef _LOW_ACCURACY_ 67 | /* 64 bit multiply */ 68 | 69 | #include 70 | #include 71 | 72 | #if BYTE_ORDER==LITTLE_ENDIAN 73 | union magic { 74 | struct { 75 | ogg_int32_t lo; 76 | ogg_int32_t hi; 77 | } halves; 78 | ogg_int64_t whole; 79 | }; 80 | #endif 81 | 82 | #if BYTE_ORDER==BIG_ENDIAN 83 | union magic { 84 | struct { 85 | ogg_int32_t hi; 86 | ogg_int32_t lo; 87 | } halves; 88 | ogg_int64_t whole; 89 | }; 90 | #endif 91 | 92 | static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { 93 | union magic magic; 94 | magic.whole = (ogg_int64_t)x * y; 95 | return magic.halves.hi; 96 | } 97 | 98 | static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { 99 | return MULT32(x,y)<<1; 100 | } 101 | 102 | static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { 103 | union magic magic; 104 | magic.whole = (ogg_int64_t)x * y; 105 | return ((ogg_uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17); 106 | } 107 | 108 | #else 109 | /* 32 bit multiply, more portable but less accurate */ 110 | 111 | /* 112 | * Note: Precision is biased towards the first argument therefore ordering 113 | * is important. Shift values were chosen for the best sound quality after 114 | * many listening tests. 115 | */ 116 | 117 | /* 118 | * For MULT32 and MULT31: The second argument is always a lookup table 119 | * value already preshifted from 31 to 8 bits. We therefore take the 120 | * opportunity to save on text space and use unsigned char for those 121 | * tables in this case. 122 | */ 123 | 124 | static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { 125 | return (x >> 9) * y; /* y preshifted >>23 */ 126 | } 127 | 128 | static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { 129 | return (x >> 8) * y; /* y preshifted >>23 */ 130 | } 131 | 132 | static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { 133 | return (x >> 6) * y; /* y preshifted >>9 */ 134 | } 135 | 136 | #endif 137 | 138 | /* 139 | * This should be used as a memory barrier, forcing all cached values in 140 | * registers to wr writen back to memory. Might or might not be beneficial 141 | * depending on the architecture and compiler. 142 | */ 143 | #define MB() 144 | 145 | /* 146 | * The XPROD functions are meant to optimize the cross products found all 147 | * over the place in mdct.c by forcing memory operation ordering to avoid 148 | * unnecessary register reloads as soon as memory is being written to. 149 | * However this is only beneficial on CPUs with a sane number of general 150 | * purpose registers which exclude the Intel x86. On Intel, better let the 151 | * compiler actually reload registers directly from original memory by using 152 | * macros. 153 | */ 154 | 155 | #ifdef __i386__ 156 | 157 | #define XPROD32(_a, _b, _t, _v, _x, _y) \ 158 | { *(_x)=MULT32(_a,_t)+MULT32(_b,_v); \ 159 | *(_y)=MULT32(_b,_t)-MULT32(_a,_v); } 160 | #define XPROD31(_a, _b, _t, _v, _x, _y) \ 161 | { *(_x)=MULT31(_a,_t)+MULT31(_b,_v); \ 162 | *(_y)=MULT31(_b,_t)-MULT31(_a,_v); } 163 | #define XNPROD31(_a, _b, _t, _v, _x, _y) \ 164 | { *(_x)=MULT31(_a,_t)-MULT31(_b,_v); \ 165 | *(_y)=MULT31(_b,_t)+MULT31(_a,_v); } 166 | 167 | #else 168 | 169 | static inline void XPROD32(ogg_int32_t a, ogg_int32_t b, 170 | ogg_int32_t t, ogg_int32_t v, 171 | ogg_int32_t *x, ogg_int32_t *y) 172 | { 173 | *x = MULT32(a, t) + MULT32(b, v); 174 | *y = MULT32(b, t) - MULT32(a, v); 175 | } 176 | 177 | static inline void XPROD31(ogg_int32_t a, ogg_int32_t b, 178 | ogg_int32_t t, ogg_int32_t v, 179 | ogg_int32_t *x, ogg_int32_t *y) 180 | { 181 | *x = MULT31(a, t) + MULT31(b, v); 182 | *y = MULT31(b, t) - MULT31(a, v); 183 | } 184 | 185 | static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b, 186 | ogg_int32_t t, ogg_int32_t v, 187 | ogg_int32_t *x, ogg_int32_t *y) 188 | { 189 | *x = MULT31(a, t) - MULT31(b, v); 190 | *y = MULT31(b, t) + MULT31(a, v); 191 | } 192 | 193 | #endif 194 | 195 | #endif 196 | 197 | #ifndef _V_CLIP_MATH 198 | #define _V_CLIP_MATH 199 | 200 | static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) { 201 | int ret=x; 202 | ret-= ((x<=32767)-1)&(x-32767); 203 | ret-= ((x>=-32768)-1)&(x+32768); 204 | return(ret); 205 | } 206 | 207 | #endif 208 | 209 | #endif 210 | 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /Tremolo/misc.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************/ 33 | 34 | #define HEAD_ALIGN 64 35 | #include 36 | #include 37 | #include 38 | #define MISC_C 39 | #include "misc.h" 40 | //#include 41 | 42 | static void **pointers=NULL; 43 | static long *insertlist=NULL; /* We can't embed this in the pointer list; 44 | a pointer can have any value... */ 45 | 46 | static char **files=NULL; 47 | static long *file_bytes=NULL; 48 | static int filecount=0; 49 | 50 | static int ptop=0; 51 | static int palloced=0; 52 | static int pinsert=0; 53 | 54 | typedef struct { 55 | char *file; 56 | long line; 57 | long ptr; 58 | long bytes; 59 | } head; 60 | 61 | long global_bytes=0; 62 | long start_time=-1; 63 | 64 | static void *_insert(void *ptr,long bytes,char *file,long line){ 65 | ((head *)ptr)->file=file; 66 | ((head *)ptr)->line=line; 67 | ((head *)ptr)->ptr=pinsert; 68 | ((head *)ptr)->bytes=bytes-HEAD_ALIGN; 69 | 70 | if(pinsert>=palloced){ 71 | palloced+=64; 72 | if(pointers){ 73 | pointers=(void **)realloc(pointers,sizeof(void **)*palloced); 74 | insertlist=(long *)realloc(insertlist,sizeof(long *)*palloced); 75 | }else{ 76 | pointers=(void **)malloc(sizeof(void **)*palloced); 77 | insertlist=(long *)malloc(sizeof(long *)*palloced); 78 | } 79 | } 80 | 81 | pointers[pinsert]=ptr; 82 | 83 | if(pinsert==ptop) 84 | pinsert=++ptop; 85 | else 86 | pinsert=insertlist[pinsert]; 87 | 88 | #ifdef _VDBG_GRAPHFILE 89 | { 90 | FILE *out; 91 | struct timeval tv; 92 | static struct timezone tz; 93 | int i; 94 | char buffer[80]; 95 | gettimeofday(&tv,&tz); 96 | 97 | for(i=0;ifile; 152 | long bytes =((head *)ptr)->bytes; 153 | int i; 154 | 155 | gettimeofday(&tv,&tz); 156 | fprintf(out,"%ld, %ld\n",-start_time+(tv.tv_sec*1000)+(tv.tv_usec/1000), 157 | global_bytes); 158 | fprintf(out,"%ld, %ld\n",-start_time+(tv.tv_sec*1000)+(tv.tv_usec/1000), 159 | global_bytes-((head *)ptr)->bytes); 160 | fclose(out); 161 | 162 | for(i=0;ibytes; 181 | 182 | insert=((head *)ptr)->ptr; 183 | insertlist[insert]=pinsert; 184 | pinsert=insert; 185 | 186 | if(pointers[insert]==NULL){ 187 | fprintf(stderr,"DEBUGGING MALLOC ERROR: freeing previously freed memory\n"); 188 | fprintf(stderr,"\t%s %ld\n",((head *)ptr)->file,((head *)ptr)->line); 189 | } 190 | 191 | if(global_bytes<0){ 192 | fprintf(stderr,"DEBUGGING MALLOC ERROR: freeing unmalloced memory\n"); 193 | } 194 | 195 | pointers[insert]=NULL; 196 | } 197 | 198 | void _VDBG_dump(void){ 199 | int i; 200 | for(i=0;ifile,ptr->line); 205 | } 206 | 207 | } 208 | 209 | extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line){ 210 | bytes+=HEAD_ALIGN; 211 | if(ptr){ 212 | ptr=(void *)(((char *)ptr)-HEAD_ALIGN); 213 | _ripremove(ptr); 214 | ptr=realloc(ptr,bytes); 215 | }else{ 216 | ptr=malloc(bytes); 217 | memset(ptr,0,bytes); 218 | } 219 | return _insert(ptr,bytes,file,line); 220 | } 221 | 222 | extern void _VDBG_free(void *ptr){ 223 | if(ptr){ 224 | ptr=(void *)(((char *)ptr)-HEAD_ALIGN); 225 | _ripremove(ptr); 226 | free(ptr); 227 | } 228 | } 229 | 230 | -------------------------------------------------------------------------------- /Tremolo/asm_arm.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: arm7 and later wide math functions 35 | 36 | ************************************************************************/ 37 | 38 | #ifdef _ARM_ASSEM_ 39 | 40 | #if !defined(_V_WIDE_MATH) && !defined(_LOW_ACCURACY_) 41 | #define _V_WIDE_MATH 42 | 43 | static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { 44 | int lo,hi; 45 | asm volatile("smull\t%0, %1, %2, %3" 46 | : "=&r"(lo),"=&r"(hi) 47 | : "%r"(x),"r"(y) 48 | : "cc"); 49 | return(hi); 50 | } 51 | 52 | static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { 53 | return MULT32(x,y)<<1; 54 | } 55 | 56 | static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { 57 | int lo,hi; 58 | asm volatile("smull %0, %1, %2, %3\n\t" 59 | "movs %0, %0, lsr #15\n\t" 60 | "adc %1, %0, %1, lsl #17\n\t" 61 | : "=&r"(lo),"=&r"(hi) 62 | : "%r"(x),"r"(y) 63 | : "cc"); 64 | return(hi); 65 | } 66 | 67 | #define MB() asm volatile ("" : : : "memory") 68 | 69 | static inline void XPROD32(ogg_int32_t a, ogg_int32_t b, 70 | ogg_int32_t t, ogg_int32_t v, 71 | ogg_int32_t *x, ogg_int32_t *y) 72 | { 73 | int x1, y1, l; 74 | asm( "smull %0, %1, %4, %6\n\t" 75 | "smlal %0, %1, %5, %7\n\t" 76 | "rsb %3, %4, #0\n\t" 77 | "smull %0, %2, %5, %6\n\t" 78 | "smlal %0, %2, %3, %7" 79 | : "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a) 80 | : "3" (a), "r" (b), "r" (t), "r" (v) 81 | : "cc" ); 82 | *x = x1; 83 | MB(); 84 | *y = y1; 85 | } 86 | 87 | /* x = (a*t + b*v)>>31, y = (b*t - a*v)>>31 */ 88 | static inline void XPROD31(ogg_int32_t a, ogg_int32_t b, 89 | ogg_int32_t t, ogg_int32_t v, 90 | ogg_int32_t *x, ogg_int32_t *y) 91 | { 92 | int x1, y1, l; 93 | asm( "smull %0, %1, %4, %6\n\t" 94 | "smlal %0, %1, %5, %7\n\t" 95 | "rsb %3, %4, #0\n\t" 96 | "smull %0, %2, %5, %6\n\t" 97 | "smlal %0, %2, %3, %7" 98 | : "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a) 99 | : "3" (a), "r" (b), "r" (t), "r" (v) 100 | : "cc" ); 101 | *x = x1 << 1; 102 | MB(); 103 | *y = y1 << 1; 104 | } 105 | 106 | /* x = (a*t - b*v)>>31, y = (b*t + a*v)>>31 */ 107 | static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b, 108 | ogg_int32_t t, ogg_int32_t v, 109 | ogg_int32_t *x, ogg_int32_t *y) 110 | { 111 | int x1, y1, l; 112 | asm( "rsb %2, %4, #0\n\t" 113 | "smull %0, %1, %3, %5\n\t" 114 | "smlal %0, %1, %2, %6\n\t" 115 | "smull %0, %2, %4, %5\n\t" 116 | "smlal %0, %2, %3, %6" 117 | : "=&r" (l), "=&r" (x1), "=&r" (y1) 118 | : "r" (a), "r" (b), "r" (t), "r" (v) 119 | : "cc" ); 120 | *x = x1 << 1; 121 | MB(); 122 | *y = y1 << 1; 123 | } 124 | 125 | #endif 126 | 127 | #ifndef _V_CLIP_MATH 128 | #define _V_CLIP_MATH 129 | 130 | static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) { 131 | int tmp; 132 | asm volatile("subs %1, %0, #32768\n\t" 133 | "movpl %0, #0x7f00\n\t" 134 | "orrpl %0, %0, #0xff\n" 135 | "adds %1, %0, #32768\n\t" 136 | "movmi %0, #0x8000" 137 | : "+r"(x),"=r"(tmp) 138 | : 139 | : "cc"); 140 | return(x); 141 | } 142 | 143 | #endif 144 | 145 | #ifndef _V_LSP_MATH_ASM 146 | #define _V_LSP_MATH_ASM 147 | 148 | static inline void lsp_loop_asm(ogg_uint32_t *qip,ogg_uint32_t *pip, 149 | ogg_int32_t *qexpp, 150 | ogg_int32_t *ilsp,ogg_int32_t wi, 151 | ogg_int32_t m){ 152 | 153 | ogg_uint32_t qi=*qip,pi=*pip; 154 | ogg_int32_t qexp=*qexpp; 155 | 156 | asm("mov r0,%3;" 157 | "mov r1,%5,asr#1;" 158 | "add r0,r0,r1,lsl#3;" 159 | "1:" 160 | 161 | "ldmdb r0!,{r1,r3};" 162 | "subs r1,r1,%4;" //ilsp[j]-wi 163 | "rsbmi r1,r1,#0;" //labs(ilsp[j]-wi) 164 | "umull %0,r2,r1,%0;" //qi*=labs(ilsp[j]-wi) 165 | 166 | "subs r1,r3,%4;" //ilsp[j+1]-wi 167 | "rsbmi r1,r1,#0;" //labs(ilsp[j+1]-wi) 168 | "umull %1,r3,r1,%1;" //pi*=labs(ilsp[j+1]-wi) 169 | 170 | "cmn r2,r3;" // shift down 16? 171 | "beq 0f;" 172 | "add %2,%2,#16;" 173 | "mov %0,%0,lsr #16;" 174 | "orr %0,%0,r2,lsl #16;" 175 | "mov %1,%1,lsr #16;" 176 | "orr %1,%1,r3,lsl #16;" 177 | "0:" 178 | "cmp r0,%3;\n" 179 | "bhi 1b;\n" 180 | 181 | // odd filter assymetry 182 | "ands r0,%5,#1;\n" 183 | "beq 2f;\n" 184 | "add r0,%3,%5,lsl#2;\n" 185 | 186 | "ldr r1,[r0,#-4];\n" 187 | "mov r0,#0x4000;\n" 188 | 189 | "subs r1,r1,%4;\n" //ilsp[j]-wi 190 | "rsbmi r1,r1,#0;\n" //labs(ilsp[j]-wi) 191 | "umull %0,r2,r1,%0;\n" //qi*=labs(ilsp[j]-wi) 192 | "umull %1,r3,r0,%1;\n" //pi*=labs(ilsp[j+1]-wi) 193 | 194 | "cmn r2,r3;\n" // shift down 16? 195 | "beq 2f;\n" 196 | "add %2,%2,#16;\n" 197 | "mov %0,%0,lsr #16;\n" 198 | "orr %0,%0,r2,lsl #16;\n" 199 | "mov %1,%1,lsr #16;\n" 200 | "orr %1,%1,r3,lsl #16;\n" 201 | 202 | //qi=(pi>>shift)*labs(ilsp[j]-wi); 203 | //pi=(qi>>shift)*labs(ilsp[j+1]-wi); 204 | //qexp+=shift; 205 | 206 | //} 207 | 208 | /* normalize to max 16 sig figs */ 209 | "2:" 210 | "mov r2,#0;" 211 | "orr r1,%0,%1;" 212 | "tst r1,#0xff000000;" 213 | "addne r2,r2,#8;" 214 | "movne r1,r1,lsr #8;" 215 | "tst r1,#0x00f00000;" 216 | "addne r2,r2,#4;" 217 | "movne r1,r1,lsr #4;" 218 | "tst r1,#0x000c0000;" 219 | "addne r2,r2,#2;" 220 | "movne r1,r1,lsr #2;" 221 | "tst r1,#0x00020000;" 222 | "addne r2,r2,#1;" 223 | "movne r1,r1,lsr #1;" 224 | "tst r1,#0x00010000;" 225 | "addne r2,r2,#1;" 226 | "mov %0,%0,lsr r2;" 227 | "mov %1,%1,lsr r2;" 228 | "add %2,%2,r2;" 229 | 230 | : "+r"(qi),"+r"(pi),"+r"(qexp) 231 | : "r"(ilsp),"r"(wi),"r"(m) 232 | : "r0","r1","r2","r3","cc"); 233 | 234 | *qip=qi; 235 | *pip=pi; 236 | *qexpp=qexp; 237 | } 238 | 239 | static inline void lsp_norm_asm(ogg_uint32_t *qip,ogg_int32_t *qexpp){ 240 | 241 | ogg_uint32_t qi=*qip; 242 | ogg_int32_t qexp=*qexpp; 243 | 244 | asm("tst %0,#0x0000ff00;" 245 | "moveq %0,%0,lsl #8;" 246 | "subeq %1,%1,#8;" 247 | "tst %0,#0x0000f000;" 248 | "moveq %0,%0,lsl #4;" 249 | "subeq %1,%1,#4;" 250 | "tst %0,#0x0000c000;" 251 | "moveq %0,%0,lsl #2;" 252 | "subeq %1,%1,#2;" 253 | "tst %0,#0x00008000;" 254 | "moveq %0,%0,lsl #1;" 255 | "subeq %1,%1,#1;" 256 | : "+r"(qi),"+r"(qexp) 257 | : 258 | : "cc"); 259 | *qip=qi; 260 | *qexpp=qexp; 261 | } 262 | 263 | #endif 264 | #endif 265 | 266 | -------------------------------------------------------------------------------- /Tremolo/codec_internal.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: libvorbis codec headers 35 | 36 | ************************************************************************/ 37 | 38 | #ifndef _V_CODECI_H_ 39 | #define _V_CODECI_H_ 40 | 41 | #define CHUNKSIZE 1024 42 | 43 | #include "codebook.h" 44 | #include "ivorbiscodec.h" 45 | 46 | #define VI_TRANSFORMB 1 47 | #define VI_WINDOWB 1 48 | #define VI_TIMEB 1 49 | #define VI_FLOORB 2 50 | #define VI_RESB 3 51 | #define VI_MAPB 1 52 | 53 | typedef void vorbis_info_floor; 54 | 55 | /* vorbis_dsp_state buffers the current vorbis audio 56 | analysis/synthesis state. The DSP state belongs to a specific 57 | logical bitstream ****************************************************/ 58 | struct vorbis_dsp_state{ 59 | vorbis_info *vi; 60 | oggpack_buffer opb; 61 | 62 | ogg_int32_t **work; 63 | ogg_int32_t **mdctright; 64 | int out_begin; 65 | int out_end; 66 | 67 | long lW; 68 | long W; 69 | 70 | ogg_int64_t granulepos; 71 | ogg_int64_t sequence; 72 | ogg_int64_t sample_count; 73 | 74 | }; 75 | 76 | 77 | /* Floor backend generic *****************************************/ 78 | 79 | extern vorbis_info_floor *floor0_info_unpack(vorbis_info *,oggpack_buffer *); 80 | extern void floor0_free_info(vorbis_info_floor *); 81 | extern int floor0_memosize(vorbis_info_floor *); 82 | extern ogg_int32_t *floor0_inverse1(struct vorbis_dsp_state *, 83 | vorbis_info_floor *,ogg_int32_t *); 84 | extern int floor0_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *, 85 | ogg_int32_t *buffer,ogg_int32_t *); 86 | 87 | extern vorbis_info_floor *floor1_info_unpack(vorbis_info *,oggpack_buffer *); 88 | extern void floor1_free_info(vorbis_info_floor *); 89 | extern int floor1_memosize(vorbis_info_floor *); 90 | extern ogg_int32_t *floor1_inverse1(struct vorbis_dsp_state *, 91 | vorbis_info_floor *,ogg_int32_t *); 92 | extern int floor1_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *, 93 | ogg_int32_t *buffer,ogg_int32_t *); 94 | 95 | typedef struct{ 96 | int order; 97 | long rate; 98 | long barkmap; 99 | 100 | int ampbits; 101 | int ampdB; 102 | 103 | int numbooks; /* <= 16 */ 104 | char books[16]; 105 | 106 | } vorbis_info_floor0; 107 | 108 | typedef struct{ 109 | char class_dim; /* 1 to 8 */ 110 | char class_subs; /* 0,1,2,3 (bits: 1< 39 | #include 40 | #include 41 | #include 42 | #include "ogg.h" 43 | #include "os.h" 44 | #include "ivorbiscodec.h" 45 | #include "mdct.h" 46 | #include "codec_internal.h" 47 | #include "codebook.h" 48 | #include "misc.h" 49 | 50 | void mapping_clear_info(vorbis_info_mapping *info){ 51 | if(info){ 52 | if(info->chmuxlist)_ogg_free(info->chmuxlist); 53 | if(info->submaplist)_ogg_free(info->submaplist); 54 | if(info->coupling)_ogg_free(info->coupling); 55 | memset(info,0,sizeof(*info)); 56 | } 57 | } 58 | 59 | static int ilog(unsigned int v){ 60 | int ret=0; 61 | if(v)--v; 62 | while(v){ 63 | ret++; 64 | v>>=1; 65 | } 66 | return(ret); 67 | } 68 | 69 | /* also responsible for range checking */ 70 | int mapping_info_unpack(vorbis_info_mapping *info,vorbis_info *vi, 71 | oggpack_buffer *opb){ 72 | int i; 73 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 74 | memset(info,0,sizeof(*info)); 75 | 76 | if(oggpack_read(opb,1)) 77 | info->submaps=oggpack_read(opb,4)+1; 78 | else 79 | info->submaps=1; 80 | 81 | if(oggpack_read(opb,1)){ 82 | info->coupling_steps=oggpack_read(opb,8)+1; 83 | info->coupling= 84 | _ogg_malloc(info->coupling_steps*sizeof(*info->coupling)); 85 | 86 | for(i=0;icoupling_steps;i++){ 87 | int testM=info->coupling[i].mag=(unsigned char)(oggpack_read(opb,ilog(vi->channels))); 88 | int testA=info->coupling[i].ang=(unsigned char)(oggpack_read(opb,ilog(vi->channels))); 89 | 90 | if(testM<0 || 91 | testA<0 || 92 | testM==testA || 93 | testM>=vi->channels || 94 | testA>=vi->channels) goto err_out; 95 | } 96 | 97 | } 98 | 99 | if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */ 100 | 101 | if(info->submaps>1){ 102 | info->chmuxlist=_ogg_malloc(sizeof(*info->chmuxlist)*vi->channels); 103 | for(i=0;ichannels;i++){ 104 | info->chmuxlist[i]=(unsigned char)(oggpack_read(opb,4)); 105 | if(info->chmuxlist[i]>=info->submaps)goto err_out; 106 | } 107 | } 108 | 109 | info->submaplist=_ogg_malloc(sizeof(*info->submaplist)*info->submaps); 110 | for(i=0;isubmaps;i++){ 111 | int temp=oggpack_read(opb,8); 112 | info->submaplist[i].floor=(char)oggpack_read(opb,8); 113 | if(info->submaplist[i].floor>=ci->floors)goto err_out; 114 | info->submaplist[i].residue=(char)oggpack_read(opb,8); 115 | if(info->submaplist[i].residue>=ci->residues)goto err_out; 116 | } 117 | 118 | return 0; 119 | 120 | err_out: 121 | mapping_clear_info(info); 122 | return -1; 123 | } 124 | 125 | int mapping_inverse(vorbis_dsp_state *vd,vorbis_info_mapping *info){ 126 | vorbis_info *vi=vd->vi; 127 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 128 | 129 | int i,j; 130 | long n=ci->blocksizes[vd->W]; 131 | 132 | ogg_int32_t **pcmbundle= 133 | alloca(sizeof(*pcmbundle)*vi->channels); 134 | int *zerobundle= 135 | alloca(sizeof(*zerobundle)*vi->channels); 136 | int *nonzero= 137 | alloca(sizeof(*nonzero)*vi->channels); 138 | ogg_int32_t **floormemo= 139 | alloca(sizeof(*floormemo)*vi->channels); 140 | 141 | /* recover the spectral envelope; store it in the PCM vector for now */ 142 | for(i=0;ichannels;i++){ 143 | int submap=0; 144 | int floorno; 145 | 146 | if(info->submaps>1) 147 | submap=info->chmuxlist[i]; 148 | floorno=info->submaplist[submap].floor; 149 | 150 | if(ci->floor_type[floorno]){ 151 | /* floor 1 */ 152 | floormemo[i]=alloca(sizeof(*floormemo[i])* 153 | floor1_memosize(ci->floor_param[floorno])); 154 | floormemo[i]=floor1_inverse1(vd,ci->floor_param[floorno],floormemo[i]); 155 | }else{ 156 | /* floor 0 */ 157 | floormemo[i]=alloca(sizeof(*floormemo[i])* 158 | floor0_memosize(ci->floor_param[floorno])); 159 | floormemo[i]=floor0_inverse1(vd,ci->floor_param[floorno],floormemo[i]); 160 | } 161 | 162 | if(floormemo[i]) 163 | nonzero[i]=1; 164 | else 165 | nonzero[i]=0; 166 | memset(vd->work[i],0,sizeof(*vd->work[i])*n/2); 167 | } 168 | 169 | /* channel coupling can 'dirty' the nonzero listing */ 170 | for(i=0;icoupling_steps;i++){ 171 | if(nonzero[info->coupling[i].mag] || 172 | nonzero[info->coupling[i].ang]){ 173 | nonzero[info->coupling[i].mag]=1; 174 | nonzero[info->coupling[i].ang]=1; 175 | } 176 | } 177 | 178 | /* recover the residue into our working vectors */ 179 | for(i=0;isubmaps;i++){ 180 | int ch_in_bundle=0; 181 | for(j=0;jchannels;j++){ 182 | if(!info->chmuxlist || info->chmuxlist[j]==i){ 183 | if(nonzero[j]) 184 | zerobundle[ch_in_bundle]=1; 185 | else 186 | zerobundle[ch_in_bundle]=0; 187 | pcmbundle[ch_in_bundle++]=vd->work[j]; 188 | } 189 | } 190 | 191 | res_inverse(vd,ci->residue_param+info->submaplist[i].residue, 192 | pcmbundle,zerobundle,ch_in_bundle); 193 | } 194 | 195 | //for(j=0;jchannels;j++) 196 | //_analysis_output("coupled",seq+j,vb->pcm[j],-8,n/2,0,0); 197 | 198 | /* channel coupling */ 199 | for(i=info->coupling_steps-1;i>=0;i--){ 200 | ogg_int32_t *pcmM=vd->work[info->coupling[i].mag]; 201 | ogg_int32_t *pcmA=vd->work[info->coupling[i].ang]; 202 | 203 | for(j=0;j0) 208 | if(ang>0){ 209 | pcmM[j]=mag; 210 | pcmA[j]=mag-ang; 211 | }else{ 212 | pcmA[j]=mag; 213 | pcmM[j]=mag+ang; 214 | } 215 | else 216 | if(ang>0){ 217 | pcmM[j]=mag; 218 | pcmA[j]=mag+ang; 219 | }else{ 220 | pcmA[j]=mag; 221 | pcmM[j]=mag-ang; 222 | } 223 | } 224 | } 225 | 226 | //for(j=0;jchannels;j++) 227 | //_analysis_output("residue",seq+j,vb->pcm[j],-8,n/2,0,0); 228 | 229 | /* compute and apply spectral envelope */ 230 | for(i=0;ichannels;i++){ 231 | ogg_int32_t *pcm=vd->work[i]; 232 | int submap=0; 233 | int floorno; 234 | 235 | if(info->submaps>1) 236 | submap=info->chmuxlist[i]; 237 | floorno=info->submaplist[submap].floor; 238 | 239 | if(ci->floor_type[floorno]){ 240 | /* floor 1 */ 241 | floor1_inverse2(vd,ci->floor_param[floorno],floormemo[i],pcm); 242 | }else{ 243 | /* floor 0 */ 244 | floor0_inverse2(vd,ci->floor_param[floorno],floormemo[i],pcm); 245 | } 246 | } 247 | 248 | //for(j=0;jchannels;j++) 249 | //_analysis_output("mdct",seq+j,vb->pcm[j],-24,n/2,0,1); 250 | 251 | /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */ 252 | /* only MDCT right now.... */ 253 | for(i=0;ichannels;i++) 254 | mdct_backward(n,vd->work[i]); 255 | 256 | //for(j=0;jchannels;j++) 257 | //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0); 258 | 259 | /* all done! */ 260 | return(0); 261 | } 262 | -------------------------------------------------------------------------------- /Tremolo/ogg.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: subsumed libogg includes 35 | 36 | ************************************************************************/ 37 | #ifndef _OGG_H 38 | #define _OGG_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include "os_types.h" 45 | 46 | #ifndef ONLY_C 47 | #define ARM_LITTLE_ENDIAN 48 | #endif 49 | 50 | typedef struct ogg_buffer_state{ 51 | struct ogg_buffer *unused_buffers; 52 | struct ogg_reference *unused_references; 53 | int outstanding; 54 | int shutdown; 55 | } ogg_buffer_state; 56 | 57 | typedef struct ogg_buffer { 58 | unsigned char *data; 59 | long size; 60 | int refcount; 61 | 62 | union { 63 | ogg_buffer_state *owner; 64 | struct ogg_buffer *next; 65 | } ptr; 66 | } ogg_buffer; 67 | 68 | typedef struct ogg_reference { 69 | ogg_buffer *buffer; 70 | long begin; 71 | long length; 72 | 73 | struct ogg_reference *next; 74 | } ogg_reference; 75 | 76 | typedef struct oggpack_buffer { 77 | #ifdef ARM_LITTLE_ENDIAN 78 | int bitsLeftInSegment; 79 | ogg_uint32_t *ptr; 80 | long bitsLeftInWord; 81 | #else 82 | int headbit; 83 | unsigned char *headptr; 84 | long headend; 85 | #endif /* ARM_LITTLE_ENDIAN */ 86 | /* memory management */ 87 | ogg_reference *head; 88 | ogg_reference *tail; 89 | 90 | /* render the byte/bit counter API constant time */ 91 | long count; /* doesn't count the tail */ 92 | } oggpack_buffer; 93 | 94 | typedef struct oggbyte_buffer { 95 | ogg_reference *baseref; 96 | 97 | ogg_reference *ref; 98 | unsigned char *ptr; 99 | long pos; 100 | long end; 101 | } oggbyte_buffer; 102 | 103 | typedef struct ogg_sync_state { 104 | /* decode memory management pool */ 105 | ogg_buffer_state *bufferpool; 106 | 107 | /* stream buffers */ 108 | ogg_reference *fifo_head; 109 | ogg_reference *fifo_tail; 110 | long fifo_fill; 111 | 112 | /* stream sync management */ 113 | int unsynced; 114 | int headerbytes; 115 | int bodybytes; 116 | 117 | } ogg_sync_state; 118 | 119 | typedef struct ogg_stream_state { 120 | ogg_reference *header_head; 121 | ogg_reference *header_tail; 122 | ogg_reference *body_head; 123 | ogg_reference *body_tail; 124 | 125 | int e_o_s; /* set when we have buffered the last 126 | packet in the logical bitstream */ 127 | int b_o_s; /* set after we've written the initial page 128 | of a logical bitstream */ 129 | long serialno; 130 | long pageno; 131 | ogg_int64_t packetno; /* sequence number for decode; the framing 132 | knows where there's a hole in the data, 133 | but we need coupling so that the codec 134 | (which is in a seperate abstraction 135 | layer) also knows about the gap */ 136 | ogg_int64_t granulepos; 137 | 138 | int lacing_fill; 139 | ogg_uint32_t body_fill; 140 | 141 | /* decode-side state data */ 142 | int holeflag; 143 | int spanflag; 144 | int clearflag; 145 | int laceptr; 146 | ogg_uint32_t body_fill_next; 147 | 148 | } ogg_stream_state; 149 | 150 | typedef struct { 151 | ogg_reference *packet; 152 | long bytes; 153 | long b_o_s; 154 | long e_o_s; 155 | ogg_int64_t granulepos; 156 | ogg_int64_t packetno; /* sequence number for decode; the framing 157 | knows where there's a hole in the data, 158 | but we need coupling so that the codec 159 | (which is in a seperate abstraction 160 | layer) also knows about the gap */ 161 | } ogg_packet; 162 | 163 | typedef struct { 164 | ogg_reference *header; 165 | int header_len; 166 | ogg_reference *body; 167 | long body_len; 168 | } ogg_page; 169 | 170 | /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ 171 | 172 | extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); 173 | extern long oggpack_look(oggpack_buffer *b,int bits); 174 | extern void oggpack_adv(oggpack_buffer *b,int bits); 175 | extern long oggpack_read(oggpack_buffer *b,int bits); 176 | extern long oggpack_bytes(oggpack_buffer *b); 177 | extern long oggpack_bits(oggpack_buffer *b); 178 | extern int oggpack_eop(oggpack_buffer *b); 179 | 180 | // Quick hack 181 | #define oggpack_bytesleft(B) (((B)->bitsLeftInSegment+7)/8) 182 | 183 | /* Ogg BITSTREAM PRIMITIVES: decoding **************************/ 184 | 185 | extern void ogg_sync_init(ogg_sync_state *oy); 186 | extern ogg_sync_state *ogg_sync_create(void); 187 | extern int ogg_sync_clear(ogg_sync_state *oy); 188 | extern int ogg_sync_destroy(ogg_sync_state *oy); 189 | extern int ogg_sync_reset(ogg_sync_state *oy); 190 | 191 | extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size); 192 | extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); 193 | extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); 194 | extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og); 195 | extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); 196 | extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); 197 | extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); 198 | 199 | /* Ogg BITSTREAM PRIMITIVES: general ***************************/ 200 | 201 | extern void ogg_stream_init(ogg_stream_state *os, int serialno); 202 | extern ogg_stream_state *ogg_stream_create(int serialno); 203 | extern int ogg_stream_destroy(ogg_stream_state *os); 204 | extern int ogg_stream_clear(ogg_stream_state *os); 205 | extern int ogg_stream_reset(ogg_stream_state *os); 206 | extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno); 207 | extern int ogg_stream_eos(ogg_stream_state *os); 208 | 209 | extern int ogg_page_checksum_set(ogg_page *og); 210 | 211 | extern int ogg_page_version(ogg_page *og); 212 | extern int ogg_page_continued(ogg_page *og); 213 | extern int ogg_page_bos(ogg_page *og); 214 | extern int ogg_page_eos(ogg_page *og); 215 | extern ogg_int64_t ogg_page_granulepos(ogg_page *og); 216 | extern ogg_uint32_t ogg_page_serialno(ogg_page *og); 217 | extern ogg_uint32_t ogg_page_pageno(ogg_page *og); 218 | extern int ogg_page_packets(ogg_page *og); 219 | extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer); 220 | 221 | extern int ogg_packet_release(ogg_packet *op); 222 | extern int ogg_page_release(ogg_page *og); 223 | 224 | extern void ogg_page_dup(ogg_page *d, ogg_page *s); 225 | 226 | /* Ogg BITSTREAM PRIMITIVES: return codes ***************************/ 227 | 228 | #define OGG_SUCCESS 0 229 | 230 | #define OGG_HOLE -10 231 | #define OGG_SPAN -11 232 | #define OGG_EVERSION -12 233 | #define OGG_ESERIAL -13 234 | #define OGG_EINVAL -14 235 | #define OGG_EEOS -15 236 | 237 | 238 | #ifdef __cplusplus 239 | } 240 | #endif 241 | 242 | #endif /* _OGG_H */ 243 | -------------------------------------------------------------------------------- /Tremolo/res012.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: residue backend 0, 1 and 2 implementation 35 | 36 | ************************************************************************/ 37 | 38 | #include 39 | #include 40 | #include 41 | #include "ogg.h" 42 | #include "ivorbiscodec.h" 43 | #include "codec_internal.h" 44 | #include "codebook.h" 45 | #include "misc.h" 46 | #include "os.h" 47 | 48 | void res_clear_info(vorbis_info_residue *info){ 49 | if(info){ 50 | if(info->stagemasks)_ogg_free(info->stagemasks); 51 | if(info->stagebooks)_ogg_free(info->stagebooks); 52 | memset(info,0,sizeof(*info)); 53 | } 54 | } 55 | 56 | 57 | /* vorbis_info is for range checking */ 58 | int res_unpack(vorbis_info_residue *info, 59 | vorbis_info *vi,oggpack_buffer *opb){ 60 | int j,k; 61 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 62 | memset(info,0,sizeof(*info)); 63 | 64 | info->type=oggpack_read(opb,16); 65 | if(info->type>2 || info->type<0)goto errout; 66 | info->begin=oggpack_read(opb,24); 67 | info->end=oggpack_read(opb,24); 68 | info->grouping=oggpack_read(opb,24)+1; // "partition size" in spec 69 | info->partitions=(char)(oggpack_read(opb,6)+1); // "classification" in spec 70 | info->groupbook=(unsigned char)oggpack_read(opb,8); // "classbook" in spec 71 | if(info->groupbook>=ci->books)goto errout; 72 | 73 | info->stagemasks=_ogg_malloc(info->partitions*sizeof(*info->stagemasks)); 74 | info->stagebooks=_ogg_malloc(info->partitions*8*sizeof(*info->stagebooks)); 75 | 76 | for(j=0;jpartitions;j++){ 77 | int cascade=oggpack_read(opb,3); 78 | if(oggpack_read(opb,1)) 79 | cascade|=(oggpack_read(opb,5)<<3); 80 | info->stagemasks[j]=cascade; 81 | } 82 | 83 | for(j=0;jpartitions;j++){ 84 | for(k=0;k<8;k++){ 85 | if((info->stagemasks[j]>>k)&1){ 86 | unsigned char book=(unsigned char)oggpack_read(opb,8); 87 | if(book>=ci->books)goto errout; 88 | info->stagebooks[j*8+k]=book; 89 | if(k+1>info->stages)info->stages=k+1; 90 | }else 91 | info->stagebooks[j*8+k]=0xff; 92 | } 93 | } 94 | 95 | if(oggpack_eop(opb))goto errout; 96 | 97 | // According to the Vorbis spec (paragraph 8.6.2 "packet decode"), residue 98 | // begin and end should be limited to the maximum possible vector size in 99 | // case they exceed it. However doing that makes the decoder crash further 100 | // down, so we return an error instead. 101 | int limit = (info->type == 2 ? vi->channels : 1) * ci->blocksizes[1] / 2; 102 | if (info->begin > info->end || 103 | info->end > limit) { 104 | goto errout; 105 | } 106 | return 0; 107 | errout: 108 | res_clear_info(info); 109 | return 1; 110 | } 111 | 112 | int res_inverse(vorbis_dsp_state *vd,vorbis_info_residue *info, 113 | ogg_int32_t **in,int *nonzero,int ch){ 114 | 115 | int i,j,k,s,used=0; 116 | codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; 117 | codebook *phrasebook=ci->book_param+info->groupbook; 118 | int samples_per_partition=info->grouping; 119 | int partitions_per_word=phrasebook->dim; 120 | int pcmend=ci->blocksizes[vd->W]; 121 | 122 | if(info->type<2){ 123 | int max=pcmend>>1; 124 | int end=(info->endend:max); 125 | int n=end-info->begin; 126 | 127 | if(n>0){ 128 | int partvals=n/samples_per_partition; 129 | int partwords=(partvals+partitions_per_word-1)/partitions_per_word; 130 | 131 | for(i=0;istages;s++){ 147 | 148 | for(i=0;i=0;k--) 154 | partword[0][i+k]=partword[0][i+k+1]*info->partitions; 155 | 156 | for(j=1;j=0;k--) 158 | partword[j][i+k]=partword[j-1][i+k]; 159 | 160 | for(j=0;jopb); 162 | if(temp==-1)goto cleanup1; 163 | 164 | /* this can be done quickly in assembly due to the quotient 165 | always being at most six bits */ 166 | for(k=0;kbegin+i*samples_per_partition; 179 | int idx = (int)partword[j][i]; 180 | if(idx < info->partitions && info->stagemasks[idx]&(1<book_param+ 182 | info->stagebooks[(partword[j][i]<<3)+s]; 183 | if(info->type){ 184 | if(vorbis_book_decodev_add(stagebook,in[j]+offset,&vd->opb, 185 | samples_per_partition,-8)==-1) 186 | goto cleanup1; 187 | }else{ 188 | if(vorbis_book_decodevs_add(stagebook,in[j]+offset,&vd->opb, 189 | samples_per_partition,-8)==-1) 190 | goto cleanup1; 191 | } 192 | } 193 | } 194 | } 195 | } 196 | cleanup1: 197 | if(partword){ 198 | for(j=0;j>1; 207 | int end=(info->endend:max); 208 | int n=end-info->begin; 209 | 210 | if(n>0){ 211 | int partvals=n/samples_per_partition; 212 | int partwords=(partvals+partitions_per_word-1)/partitions_per_word; 213 | 214 | char *partword= 215 | (char *)_ogg_malloc(partwords*partitions_per_word*sizeof(*partword)); 216 | if(partword==NULL)goto cleanup2; 217 | int beginoff=info->begin/ch; 218 | 219 | for(i=0;istages;s++){ 225 | for(i=0;i=0;k--) 231 | partword[i+k]=partword[i+k+1]*info->partitions; 232 | 233 | /* fetch the partition word */ 234 | temp=vorbis_book_decode(phrasebook,&vd->opb); 235 | if(temp==-1)goto cleanup2; 236 | 237 | /* this can be done quickly in assembly due to the quotient 238 | always being at most six bits */ 239 | for(k=0;k= 0 && partword[i] < info->partitions && 249 | (info->stagemasks[(int)partword[i]] & (1 << s))){ 250 | codebook *stagebook=ci->book_param+ 251 | info->stagebooks[(partword[i]<<3)+s]; 252 | if(vorbis_book_decodevv_add(stagebook,in, 253 | i*samples_per_partition+beginoff,ch, 254 | &vd->opb, 255 | samples_per_partition,-8)==-1) 256 | goto cleanup2; 257 | } 258 | } 259 | } 260 | } 261 | cleanup2: 262 | if(partword)_ogg_free(partword); 263 | } 264 | } 265 | 266 | return 0; 267 | } 268 | 269 | -------------------------------------------------------------------------------- /Tremolo/dsp.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: PCM data vector blocking, windowing and dis/reassembly 35 | 36 | ************************************************************************/ 37 | 38 | #include 39 | #include "ogg.h" 40 | #include "mdct.h" 41 | #include "ivorbiscodec.h" 42 | #include "codec_internal.h" 43 | #include "misc.h" 44 | #include "window_lookup.h" 45 | 46 | int vorbis_dsp_restart(vorbis_dsp_state *v){ 47 | if(!v)return -1; 48 | { 49 | vorbis_info *vi=v->vi; 50 | codec_setup_info *ci; 51 | 52 | if(!vi)return -1; 53 | ci=vi->codec_setup; 54 | if(!ci)return -1; 55 | 56 | v->out_end=-1; 57 | v->out_begin=-1; 58 | 59 | v->granulepos=-1; 60 | v->sequence=-1; 61 | v->sample_count=-1; 62 | } 63 | return 0; 64 | } 65 | 66 | int vorbis_dsp_init(vorbis_dsp_state *v,vorbis_info *vi){ 67 | int i; 68 | 69 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 70 | 71 | v->vi=vi; 72 | 73 | v->work=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->work)); 74 | v->mdctright=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->mdctright)); 75 | for(i=0;ichannels;i++){ 76 | v->work[i]=(ogg_int32_t *)_ogg_calloc(1,(ci->blocksizes[1]>>1)* 77 | sizeof(*v->work[i])); 78 | v->mdctright[i]=(ogg_int32_t *)_ogg_calloc(1,(ci->blocksizes[1]>>2)* 79 | sizeof(*v->mdctright[i])); 80 | } 81 | 82 | v->lW=0; /* previous window size */ 83 | v->W=0; /* current window size */ 84 | 85 | vorbis_dsp_restart(v); 86 | return 0; 87 | } 88 | 89 | vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi){ 90 | vorbis_dsp_state *v=_ogg_calloc(1,sizeof(*v)); 91 | vorbis_dsp_init(v,vi); 92 | return v; 93 | } 94 | 95 | void vorbis_dsp_clear(vorbis_dsp_state *v){ 96 | int i; 97 | if(v){ 98 | vorbis_info *vi=v->vi; 99 | 100 | if(v->work){ 101 | for(i=0;ichannels;i++) 102 | if(v->work[i])_ogg_free(v->work[i]); 103 | _ogg_free(v->work); 104 | } 105 | if(v->mdctright){ 106 | for(i=0;ichannels;i++) 107 | if(v->mdctright[i])_ogg_free(v->mdctright[i]); 108 | _ogg_free(v->mdctright); 109 | } 110 | } 111 | } 112 | 113 | void vorbis_dsp_destroy(vorbis_dsp_state *v){ 114 | vorbis_dsp_clear(v); 115 | _ogg_free(v); 116 | } 117 | 118 | static LOOKUP_T *_vorbis_window(int left){ 119 | switch(left){ 120 | case 32: 121 | return vwin64; 122 | case 64: 123 | return vwin128; 124 | case 128: 125 | return vwin256; 126 | case 256: 127 | return vwin512; 128 | case 512: 129 | return vwin1024; 130 | case 1024: 131 | return vwin2048; 132 | case 2048: 133 | return vwin4096; 134 | #ifndef LIMIT_TO_64kHz 135 | case 4096: 136 | return vwin8192; 137 | #endif 138 | default: 139 | return(0); 140 | } 141 | } 142 | 143 | /* pcm==0 indicates we just want the pending samples, no more */ 144 | int vorbis_dsp_pcmout(vorbis_dsp_state *v,ogg_int16_t *pcm,int samples){ 145 | vorbis_info *vi=v->vi; 146 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 147 | if(v->out_begin>-1 && v->out_beginout_end){ 148 | int n=v->out_end-v->out_begin; 149 | if(pcm){ 150 | int i; 151 | if(n>samples)n=samples; 152 | for(i=0;ichannels;i++) 153 | mdct_unroll_lap(ci->blocksizes[0],ci->blocksizes[1], 154 | v->lW,v->W,v->work[i],v->mdctright[i], 155 | _vorbis_window(ci->blocksizes[0]>>1), 156 | _vorbis_window(ci->blocksizes[1]>>1), 157 | pcm+i,vi->channels, 158 | v->out_begin,v->out_begin+n); 159 | } 160 | return(n); 161 | } 162 | return(0); 163 | } 164 | 165 | int vorbis_dsp_read(vorbis_dsp_state *v,int s){ 166 | if(s && v->out_begin+s>v->out_end)return(OV_EINVAL); 167 | v->out_begin+=s; 168 | return(0); 169 | } 170 | 171 | long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){ 172 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 173 | oggpack_buffer opb; 174 | int mode; 175 | int modebits=0; 176 | int v=ci->modes; 177 | 178 | oggpack_readinit(&opb,op->packet); 179 | 180 | /* Check the packet type */ 181 | if(oggpack_read(&opb,1)!=0){ 182 | /* Oops. This is not an audio data packet */ 183 | return(OV_ENOTAUDIO); 184 | } 185 | 186 | while(v>1){ 187 | modebits++; 188 | v>>=1; 189 | } 190 | 191 | /* read our mode and pre/post windowsize */ 192 | mode=oggpack_read(&opb,modebits); 193 | if(mode==-1)return(OV_EBADPACKET); 194 | return(ci->blocksizes[ci->mode_param[mode].blockflag]); 195 | } 196 | 197 | 198 | static int ilog(ogg_uint32_t v){ 199 | int ret=0; 200 | if(v)--v; 201 | while(v){ 202 | ret++; 203 | v>>=1; 204 | } 205 | return(ret); 206 | } 207 | 208 | int vorbis_dsp_synthesis(vorbis_dsp_state *vd,ogg_packet *op,int decodep){ 209 | vorbis_info *vi=vd->vi; 210 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 211 | int mode,i; 212 | 213 | oggpack_readinit(&vd->opb,op->packet); 214 | 215 | /* Check the packet type */ 216 | if(oggpack_read(&vd->opb,1)!=0){ 217 | /* Oops. This is not an audio data packet */ 218 | return OV_ENOTAUDIO ; 219 | } 220 | 221 | /* read our mode and pre/post windowsize */ 222 | mode=oggpack_read(&vd->opb,ilog(ci->modes)); 223 | if(mode==-1 || mode>=ci->modes) return OV_EBADPACKET; 224 | 225 | /* shift information we still need from last window */ 226 | vd->lW=vd->W; 227 | vd->W=ci->mode_param[mode].blockflag; 228 | for(i=0;ichannels;i++) 229 | mdct_shift_right(ci->blocksizes[vd->lW],vd->work[i],vd->mdctright[i]); 230 | 231 | if(vd->W){ 232 | int temp; 233 | oggpack_read(&vd->opb,1); 234 | temp=oggpack_read(&vd->opb,1); 235 | if(temp==-1) return OV_EBADPACKET; 236 | } 237 | 238 | /* packet decode and portions of synthesis that rely on only this block */ 239 | if(decodep){ 240 | mapping_inverse(vd,ci->map_param+ci->mode_param[mode].mapping); 241 | 242 | if(vd->out_begin==-1){ 243 | vd->out_begin=0; 244 | vd->out_end=0; 245 | }else{ 246 | vd->out_begin=0; 247 | vd->out_end=ci->blocksizes[vd->lW]/4+ci->blocksizes[vd->W]/4; 248 | } 249 | } 250 | 251 | /* track the frame number... This is for convenience, but also 252 | making sure our last packet doesn't end with added padding. 253 | 254 | This is not foolproof! It will be confused if we begin 255 | decoding at the last page after a seek or hole. In that case, 256 | we don't have a starting point to judge where the last frame 257 | is. For this reason, vorbisfile will always try to make sure 258 | it reads the last two marked pages in proper sequence */ 259 | 260 | /* if we're out of sequence, dump granpos tracking until we sync back up */ 261 | if(vd->sequence==-1 || vd->sequence+1 != op->packetno-3){ 262 | /* out of sequence; lose count */ 263 | vd->granulepos=-1; 264 | vd->sample_count=-1; 265 | } 266 | 267 | vd->sequence=op->packetno; 268 | vd->sequence=vd->sequence-3; 269 | 270 | if(vd->sample_count==-1){ 271 | vd->sample_count=0; 272 | }else{ 273 | vd->sample_count+= 274 | ci->blocksizes[vd->lW]/4+ci->blocksizes[vd->W]/4; 275 | } 276 | 277 | if(vd->granulepos==-1){ 278 | if(op->granulepos!=-1){ /* only set if we have a 279 | position to set to */ 280 | 281 | vd->granulepos=op->granulepos; 282 | 283 | /* is this a short page? */ 284 | if(vd->sample_count>vd->granulepos){ 285 | /* corner case; if this is both the first and last audio page, 286 | then spec says the end is cut, not beginning */ 287 | if(op->e_o_s){ 288 | /* trim the end */ 289 | /* no preceeding granulepos; assume we started at zero (we'd 290 | have to in a short single-page stream) */ 291 | /* granulepos could be -1 due to a seek, but that would result 292 | in a long coun t, not short count */ 293 | 294 | vd->out_end-=(int)(vd->sample_count-vd->granulepos); 295 | }else{ 296 | /* trim the beginning */ 297 | vd->out_begin+=(int)(vd->sample_count-vd->granulepos); 298 | if(vd->out_begin>vd->out_end) 299 | vd->out_begin=vd->out_end; 300 | } 301 | 302 | } 303 | 304 | } 305 | }else{ 306 | vd->granulepos+= 307 | ci->blocksizes[vd->lW]/4+ci->blocksizes[vd->W]/4; 308 | if(op->granulepos!=-1 && vd->granulepos!=op->granulepos){ 309 | 310 | if(vd->granulepos>op->granulepos){ 311 | long extra=(long)(vd->granulepos-op->granulepos); 312 | 313 | if(extra) 314 | if(op->e_o_s){ 315 | /* partial last frame. Strip the extra samples off */ 316 | vd->out_end-=extra; 317 | } /* else {Shouldn't happen *unless* the bitstream is out of 318 | spec. Either way, believe the bitstream } */ 319 | } /* else {Shouldn't happen *unless* the bitstream is out of 320 | spec. Either way, believe the bitstream } */ 321 | vd->granulepos=op->granulepos; 322 | } 323 | } 324 | 325 | return(0); 326 | } 327 | -------------------------------------------------------------------------------- /Tremolo/floor1.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: floor backend 1 implementation 35 | 36 | ************************************************************************/ 37 | 38 | #include 39 | #include 40 | #include 41 | #include "ogg.h" 42 | #include "ivorbiscodec.h" 43 | #include "codec_internal.h" 44 | #include "codebook.h" 45 | #include "misc.h" 46 | 47 | extern const ogg_int32_t FLOOR_fromdB_LOOKUP[]; 48 | #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */ 49 | #define VIF_POSIT 63 50 | 51 | /***********************************************/ 52 | 53 | void floor1_free_info(vorbis_info_floor *i){ 54 | vorbis_info_floor1 *info=(vorbis_info_floor1 *)i; 55 | if(info){ 56 | if(info->klass)_ogg_free(info->klass); 57 | if(info->partitionclass)_ogg_free(info->partitionclass); 58 | if(info->postlist)_ogg_free(info->postlist); 59 | if(info->forward_index)_ogg_free(info->forward_index); 60 | if(info->hineighbor)_ogg_free(info->hineighbor); 61 | if(info->loneighbor)_ogg_free(info->loneighbor); 62 | memset(info,0,sizeof(*info)); 63 | _ogg_free(info); 64 | } 65 | } 66 | 67 | static int ilog(unsigned int v){ 68 | int ret=0; 69 | while(v){ 70 | ret++; 71 | v>>=1; 72 | } 73 | return(ret); 74 | } 75 | 76 | static void mergesort(ogg_uint8_t *index,ogg_uint16_t *vals,ogg_uint16_t n){ 77 | ogg_uint16_t i,j; 78 | ogg_uint8_t *temp,*A=index,*B=_ogg_malloc(n*sizeof(*B)); 79 | 80 | for(i=1;icodec_setup; 109 | int j,k,count=0,maxclass=-1,rangebits; 110 | 111 | vorbis_info_floor1 *info=(vorbis_info_floor1 *)_ogg_calloc(1,sizeof(*info)); 112 | /* read partitions */ 113 | info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */ 114 | info->partitionclass= 115 | (ogg_uint8_t *)_ogg_malloc(info->partitions*sizeof(*info->partitionclass)); 116 | for(j=0;jpartitions;j++){ 117 | info->partitionclass[j]=(char)oggpack_read(opb,4); /* only 0 to 15 legal */ 118 | if(maxclasspartitionclass[j])maxclass=info->partitionclass[j]; 119 | } 120 | 121 | /* read partition classes */ 122 | info->klass= 123 | (floor1class *)_ogg_malloc((maxclass+1)*sizeof(*info->klass)); 124 | for(j=0;jklass[j].class_dim=(char)oggpack_read(opb,3)+1; /* 1 to 8 */ 126 | info->klass[j].class_subs=(char)oggpack_read(opb,2); /* 0,1,2,3 bits */ 127 | if(oggpack_eop(opb)<0) goto err_out; 128 | if(info->klass[j].class_subs) 129 | info->klass[j].class_book=(unsigned char)oggpack_read(opb,8); 130 | else 131 | info->klass[j].class_book=0; 132 | if(info->klass[j].class_book>=ci->books)goto err_out; 133 | for(k=0;k<(1<klass[j].class_subs);k++){ 134 | info->klass[j].class_subbook[k]=(unsigned char)(oggpack_read(opb,8)-1); 135 | if(info->klass[j].class_subbook[k]>=ci->books && 136 | info->klass[j].class_subbook[k]!=0xff)goto err_out; 137 | } 138 | } 139 | 140 | /* read the post list */ 141 | info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */ 142 | rangebits=oggpack_read(opb,4); 143 | if(rangebits < 0) goto err_out; 144 | 145 | for(j=0,k=0;jpartitions;j++) 146 | count+=info->klass[info->partitionclass[j]].class_dim; 147 | info->postlist= 148 | (ogg_uint16_t *)_ogg_malloc((count+2)*sizeof(*info->postlist)); 149 | info->forward_index= 150 | (ogg_uint8_t *)_ogg_malloc((count+2)*sizeof(*info->forward_index)); 151 | info->loneighbor= 152 | (ogg_uint8_t *)_ogg_malloc(count*sizeof(*info->loneighbor)); 153 | info->hineighbor= 154 | (ogg_uint8_t *)_ogg_malloc(count*sizeof(*info->hineighbor)); 155 | 156 | count=0; 157 | for(j=0,k=0;jpartitions;j++){ 158 | count+=info->klass[info->partitionclass[j]].class_dim; 159 | for(;kpostlist[k+2]=(ogg_uint16_t)oggpack_read(opb,rangebits); 161 | if(t>=(1<postlist[0]=0; 166 | info->postlist[1]=1<posts=count+2; 168 | 169 | /* also store a sorted position index */ 170 | for(j=0;jposts;j++)info->forward_index[j]=j; 171 | mergesort(info->forward_index,info->postlist,info->posts); 172 | 173 | /* discover our neighbors for decode where we don't use fit flags 174 | (that would push the neighbors outward) */ 175 | for(j=0;jposts-2;j++){ 176 | int lo=0; 177 | int hi=1; 178 | int lx=0; 179 | int hx=info->postlist[1]; 180 | int currentx=info->postlist[j+2]; 181 | for(k=0;kpostlist[k]; 183 | if(x>lx && xcurrentx){ 188 | hi=k; 189 | hx=x; 190 | } 191 | } 192 | info->loneighbor[j]=lo; 193 | info->hineighbor[j]=hi; 194 | } 195 | 196 | return(info); 197 | 198 | err_out: 199 | floor1_free_info(info); 200 | return(NULL); 201 | } 202 | 203 | #ifdef ONLY_C 204 | static 205 | #endif 206 | int render_point(int x0,int x1,int y0,int y1,int x){ 207 | y0&=0x7fff; /* mask off flag */ 208 | y1&=0x7fff; 209 | 210 | { 211 | int dy=y1-y0; 212 | int adx=x1-x0; 213 | int ady=abs(dy); 214 | int err=ady*(x-x0); 215 | 216 | int off=err/adx; 217 | if(dy<0)return(y0-off); 218 | return(y0+off); 219 | } 220 | } 221 | 222 | #ifndef ONLY_C 223 | void render_lineARM(int n, ogg_int32_t *d,const ogg_int32_t *floor, int base, int err, int adx, int ady); 224 | #endif 225 | 226 | static void render_line(int n,int x0,int x1,int y0,int y1,ogg_int32_t *d){ 227 | int dy; 228 | int adx; 229 | int ady; 230 | int base; 231 | int err; 232 | const ogg_int32_t *floor; 233 | 234 | if(n>x1)n=x1; 235 | n -= x0; 236 | if (n <= 0 || y0 < 0 || y0 > 255 || y1 < 0 || y1 > 255) { 237 | return; 238 | } 239 | dy=y1-y0; 240 | adx=x1-x0; 241 | ady=abs(dy); 242 | base=dy/adx; 243 | err=adx-1; 244 | floor=&FLOOR_fromdB_LOOKUP[y0]; 245 | d += x0; 246 | ady-=abs(base*adx); 247 | 248 | /* We should add base each time, and then: 249 | * if dy >=0 we occasionally add 1 250 | * else occasionally subtract 1. 251 | * As an optimisation we say that if dy <0 we make base 1 smaller. 252 | * Then we need to add 1 occassionally, rather than subtract 1 - but we 253 | * need to add 1 in all the cases when we wouldn't have done so before. 254 | * Previously we'd have added 1 (100*ady/adx)% of the time. Now we want 255 | * to do so (100*(adx-ady)/adx)% of the time. 256 | */ 257 | if (dy < 0){ 258 | base--; 259 | ady = adx-ady; 260 | err = 0; 261 | } 262 | 263 | //if(x0); 278 | #else 279 | render_lineARM(n,d,floor,base,err,adx,ady); 280 | #endif 281 | } 282 | 283 | int floor1_memosize(vorbis_info_floor *i){ 284 | vorbis_info_floor1 *info=(vorbis_info_floor1 *)i; 285 | return info->posts; 286 | } 287 | 288 | static int quant_look[4]={256,128,86,64}; 289 | 290 | ogg_int32_t *floor1_inverse1(vorbis_dsp_state *vd,vorbis_info_floor *in, 291 | ogg_int32_t *fit_value){ 292 | vorbis_info_floor1 *info=(vorbis_info_floor1 *)in; 293 | codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; 294 | 295 | int i,j,k; 296 | codebook *books=ci->book_param; 297 | int quant_q=quant_look[info->mult-1]; 298 | 299 | /* unpack wrapped/predicted values from stream */ 300 | if(oggpack_read(&vd->opb,1)==1){ 301 | fit_value[0]=oggpack_read(&vd->opb,ilog(quant_q-1)); 302 | fit_value[1]=oggpack_read(&vd->opb,ilog(quant_q-1)); 303 | 304 | /* partition by partition */ 305 | /* partition by partition */ 306 | for(i=0,j=2;ipartitions;i++){ 307 | int classv=info->partitionclass[i]; 308 | int cdim=info->klass[classv].class_dim; 309 | int csubbits=info->klass[classv].class_subs; 310 | int csub=1<klass[classv].class_book,&vd->opb); 316 | 317 | if(cval==-1)goto eop; 318 | } 319 | 320 | for(k=0;kklass[classv].class_subbook[cval&(csub-1)]; 322 | cval>>=csubbits; 323 | if(book!=0xff){ 324 | if((fit_value[j+k]=vorbis_book_decode(books+book,&vd->opb))==-1) 325 | goto eop; 326 | }else{ 327 | fit_value[j+k]=0; 328 | } 329 | } 330 | j+=cdim; 331 | } 332 | 333 | /* unwrap positive values and reconsitute via linear interpolation */ 334 | for(i=2;iposts;i++){ 335 | int predicted=render_point(info->postlist[info->loneighbor[i-2]], 336 | info->postlist[info->hineighbor[i-2]], 337 | fit_value[info->loneighbor[i-2]], 338 | fit_value[info->hineighbor[i-2]], 339 | info->postlist[i]); 340 | int hiroom=quant_q-predicted; 341 | int loroom=predicted; 342 | int room=(hiroom=room){ 347 | if(hiroom>loroom){ 348 | val = val-loroom; 349 | }else{ 350 | val = -1-(val-hiroom); 351 | } 352 | }else{ 353 | if(val&1){ 354 | val= -((val+1)>>1); 355 | }else{ 356 | val>>=1; 357 | } 358 | } 359 | 360 | fit_value[i]=val+predicted; 361 | fit_value[info->loneighbor[i-2]]&=0x7fff; 362 | fit_value[info->hineighbor[i-2]]&=0x7fff; 363 | 364 | }else{ 365 | fit_value[i]=predicted|0x8000; 366 | } 367 | 368 | } 369 | 370 | return(fit_value); 371 | } 372 | eop: 373 | return(NULL); 374 | } 375 | 376 | int floor1_inverse2(vorbis_dsp_state *vd,vorbis_info_floor *in, 377 | ogg_int32_t *fit_value,ogg_int32_t *out){ 378 | vorbis_info_floor1 *info=(vorbis_info_floor1 *)in; 379 | 380 | codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; 381 | int n=ci->blocksizes[vd->W]/2; 382 | int j; 383 | 384 | if(fit_value){ 385 | /* render the lines */ 386 | int hx=0; 387 | int lx=0; 388 | int ly=fit_value[0]*info->mult; 389 | for(j=1;jposts;j++){ 390 | int current=info->forward_index[j]; 391 | int hy=fit_value[current]&0x7fff; 392 | if(hy==fit_value[current]){ 393 | 394 | hy*=info->mult; 395 | hx=info->postlist[current]; 396 | 397 | render_line(n,lx,hx,ly,hy,out); 398 | 399 | lx=hx; 400 | ly=hy; 401 | } 402 | } 403 | for(j=hx;j>(32-bitsLeftInWord) 58 | ADDLE r12,r12,#32 @ r12= bitsLeftInWord += 32 59 | RSB r14,r14,#32 @ r14= 32-bitsLeftInWord 60 | ORRLT r10,r10,r11,LSL r14 @ r10= Next 32 bits. 61 | MOV r14,#1 62 | RSB r14,r14,r14,LSL r1 63 | AND r0,r10,r14 64 | LDMFD r13!,{r10,r11,PC} 65 | 66 | look_slow: 67 | STMFD r13!,{r5,r6} 68 | ADDS r10,r2,r1 @ r10= bitsLeftInSegment + bits (i.e. 69 | @ the initial value of bitsLeftInSeg) 70 | @ r10 = bitsLeftInSegment (initial) 71 | @ r12 = bitsLeftInWord 72 | RSB r14,r12,#32 @ r14= 32-bitsLeftInWord 73 | MOV r5,r10 @ r5 = bitsLeftInSegment (initial) 74 | BLT look_overrun 75 | BEQ look_next_segment @ r10= r12 = 0, if we branch 76 | CMP r12,r10 @ If bitsLeftInWord < bitsLeftInSeg 77 | @ there must be more in the next word 78 | LDR r10,[r3],#4 @ r10= ptr[0] 79 | LDRLT r6,[r3] @ r6 = ptr[1] 80 | MOV r11,#1 81 | MOV r10,r10,LSR r14 @ r10= first bitsLeftInWord bits 82 | ORRLT r10,r10,r6,LSL r12 @ r10= first bitsLeftInSeg bits+crap 83 | RSB r11,r11,r11,LSL r5 @ r11= mask 84 | AND r10,r10,r11 @ r10= first r5 bits 85 | @ Load the next segments data 86 | look_next_segment: 87 | @ At this point, r10 contains the first r5 bits of the result 88 | LDR r11,[r0,#12] @ r11= head = b->head 89 | @ Stall 90 | @ Stall 91 | look_next_segment_2: 92 | LDR r11,[r11,#12] @ r11= head = head->next 93 | @ Stall 94 | @ Stall 95 | CMP r11,#0 96 | BEQ look_out_of_data 97 | LDMIA r11,{r6,r12,r14} @ r6 = buffer 98 | @ r12= begin 99 | @ r14= length 100 | LDR r6,[r6] @ r6 = buffer->data 101 | CMP r14,#0 102 | BEQ look_next_segment_2 103 | ADD r6,r6,r12 @ r6 = buffer->data+begin 104 | look_slow_loop: 105 | LDRB r12,[r6],#1 @ r12= *buffer 106 | SUBS r14,r14,#1 @ r14= length 107 | @ Stall 108 | ORR r10,r10,r12,LSL r5 @ r10= first r5+8 bits 109 | ADD r5,r5,#8 110 | BLE look_really_slow 111 | CMP r5,r1 112 | BLT look_slow_loop 113 | MOV r14,#1 114 | RSB r14,r14,r14,LSL r1 115 | AND r0,r10,r14 116 | LDMFD r13!,{r5,r6,r10,r11,PC} 117 | 118 | 119 | look_really_slow: 120 | CMP r5,r1 121 | BLT look_next_segment_2 122 | MOV r14,#1 123 | RSB r14,r14,r14,LSL r1 124 | AND r0,r10,r14 125 | LDMFD r13!,{r5,r6,r10,r11,PC} 126 | 127 | look_out_of_data: 128 | @MVN r0,#0 ; return -1 129 | MOV r0,#0 130 | LDMFD r13!,{r5,r6,r10,r11,PC} 131 | 132 | look_overrun: 133 | @ We had overrun when we started, so we need to skip -r10 bits. 134 | LDR r11,[r0,#12] @ r11 = head = b->head 135 | @ stall 136 | @ stall 137 | look_overrun_next_segment: 138 | LDR r11,[r11,#12] @ r11 = head->next 139 | @ stall 140 | @ stall 141 | CMP r11,#0 142 | BEQ look_out_of_data 143 | LDMIA r11,{r6,r7,r14} @ r6 = buffer 144 | @ r7 = begin 145 | @ r14= length 146 | LDR r6,[r6] @ r6 = buffer->data 147 | @ stall 148 | @ stall 149 | ADD r6,r6,r7 @ r6 = buffer->data+begin 150 | MOV r14,r14,LSL #3 @ r14= length in bits 151 | ADDS r14,r14,r10 @ r14= length in bits-bits to skip 152 | MOVLE r10,r14 153 | BLE look_overrun_next_segment 154 | RSB r10,r10,#0 @ r10= bits to skip 155 | ADD r6,r10,r10,LSR #3 @ r6 = pointer to data 156 | MOV r10,#0 157 | B look_slow_loop 158 | 159 | oggpack_adv: 160 | @ r0 = oggpack_buffer *b 161 | @ r1 = bits 162 | LDMIA r0,{r2,r3,r12} 163 | @ r2 = bitsLeftInSegment 164 | @ r3 = ptr 165 | @ r12= bitsLeftInWord 166 | SUBS r2,r2,r1 @ Does this run us out of bits in the 167 | BLE adv_slow @ segment? If so, do it slowly 168 | SUBS r12,r12,r1 169 | ADDLE r12,r12,#32 170 | ADDLE r3,r3,#4 171 | STMIA r0,{r2,r3,r12} 172 | BX LR 173 | adv_slow: 174 | STMFD r13!,{r10,r14} 175 | 176 | LDR r14,[r0,#12] @ r14= head 177 | @ stall 178 | adv_slow_loop: 179 | LDR r1,[r0,#20] @ r1 = count 180 | LDR r10,[r14,#8] @ r10= head->length 181 | LDR r14,[r14,#12] @ r14= head->next 182 | @ stall 183 | ADD r1,r1,r10 @ r1 = count += head->length 184 | CMP r14,#0 185 | BEQ adv_end 186 | STR r1,[r0,#20] @ b->count = count 187 | STR r14,[r0,#12] @ b->head = head 188 | LDMIA r14,{r3,r10,r12} @ r3 = buffer 189 | @ r10= begin 190 | @ r12= length 191 | LDR r3,[r3] @ r3 = buffer->data 192 | ADD r3,r3,r10 @ r3 = Pointer to start (byte) 193 | AND r10,r3,#3 @ r10= bytes to backtrk to word align 194 | MOV r10,r10,LSL #3 @ r10= bits to backtrk to word align 195 | RSB r10,r10,#32 @ r10= bits left in word 196 | ADDS r10,r10,r2 @ r10= bits left in word after skip 197 | ADDLE r10,r10,#32 198 | ADDLE r3,r3,#4 199 | BIC r3,r3,#3 @ r3 = Pointer to start (word) 200 | ADDS r2,r2,r12,LSL #3 @ r2 = length in bits after advance 201 | BLE adv_slow_loop 202 | STMIA r0,{r2,r3,r10} 203 | 204 | LDMFD r13!,{r10,PC} 205 | adv_end: 206 | MOV r2, #0 207 | MOV r12,#0 208 | STMIA r0,{r2,r3,r12} 209 | 210 | LDMFD r13!,{r10,PC} 211 | 212 | oggpack_readinit: 213 | @ r0 = oggpack_buffer *b 214 | @ r1 = oggreference *r 215 | STR r1,[r0,#12] @ b->head = r1 216 | STR r1,[r0,#16] @ b->tail = r1 217 | LDMIA r1,{r2,r3,r12} @ r2 = b->head->buffer 218 | @ r3 = b->head->begin 219 | @ r12= b->head->length 220 | LDR r2,[r2] @ r2 = b->head->buffer->data 221 | MOV r1,r12,LSL #3 @ r1 = BitsInSegment 222 | MOV r12,#0 223 | ADD r3,r2,r3 @ r3 = r2+b->head->begin 224 | BIC r2,r3,#3 @ r2 = b->headptr (word) 225 | AND r3,r3,#3 226 | MOV r3,r3,LSL #3 227 | RSB r3,r3,#32 @ r3 = BitsInWord 228 | STMIA r0,{r1,r2,r3} 229 | STR r12,[r0,#20] 230 | BX LR 231 | 232 | oggpack_read: 233 | @ r0 = oggpack_buffer *b 234 | @ r1 = int bits 235 | STMFD r13!,{r10,r11,r14} 236 | LDMIA r0,{r2,r3,r12} 237 | @ r2 = bitsLeftInSegment 238 | @ r3 = ptr 239 | @ r12= bitsLeftInWord 240 | SUBS r2,r2,r1 @ bitsLeftinSegment -= bits 241 | BLT read_slow @ Not enough bits in this segment for 242 | @ this request. Do it slowly. 243 | LDR r10,[r3] @ r10= ptr[0] 244 | RSB r14,r12,#32 @ r14= 32-bitsLeftInWord 245 | SUBS r12,r12,r1 @ r12= bitsLeftInWord -= bits 246 | ADDLE r3,r3,#4 247 | LDRLT r11,[r3] @ r11= ptr[1] 248 | MOV r10,r10,LSR r14 @ r10= ptr[0]>>(32-bitsLeftInWord) 249 | ADDLE r12,r12,#32 @ r12= bitsLeftInWord += 32 250 | RSB r14,r14,#32 @ r14= 32-bitsLeftInWord 251 | ORRLT r10,r10,r11,LSL r14 @ r10= Next 32 bits. 252 | STMIA r0,{r2,r3,r12} 253 | MOV r14,#1 254 | RSB r14,r14,r14,LSL r1 255 | AND r0,r10,r14 256 | LDMFD r13!,{r10,r11,PC} 257 | 258 | read_slow: 259 | STMFD r13!,{r5,r6} 260 | ADDS r10,r2,r1 @ r10= bitsLeftInSegment + bits (i.e. 261 | @ the initial value of bitsLeftInSeg) 262 | @ r10 = bitsLeftInSegment (initial) 263 | @ r12 = bitsLeftInWord 264 | RSB r14,r12,#32 @ r14= 32-bitsLeftInWord 265 | MOV r5,r10 @ r5 = bitsLeftInSegment (initial) 266 | BLT read_overrun 267 | BEQ read_next_segment @ r10= r12 = 0, if we branch 268 | CMP r12,r10 @ If bitsLeftInWord < bitsLeftInSeg 269 | @ there must be more in the next word 270 | LDR r10,[r3],#4 @ r10= ptr[0] 271 | LDRLT r6,[r3] @ r6 = ptr[1] 272 | MOV r11,#1 273 | MOV r10,r10,LSR r14 @ r10= first bitsLeftInWord bits 274 | ORRLT r10,r10,r6,LSL r12 @ r10= first bitsLeftInSeg bits+crap 275 | RSB r11,r11,r11,LSL r5 @ r11= mask 276 | AND r10,r10,r11 @ r10= first r5 bits 277 | @ Load the next segments data 278 | read_next_segment: 279 | @ At this point, r10 contains the first r5 bits of the result 280 | LDR r11,[r0,#12] @ r11= head = b->head 281 | @ Stall 282 | read_next_segment_2: 283 | @ r11 = head 284 | LDR r6,[r0,#20] @ r6 = count 285 | LDR r12,[r11,#8] @ r12= length 286 | LDR r11,[r11,#12] @ r11= head = head->next 287 | @ Stall 288 | ADD r6,r6,r12 @ count += length 289 | CMP r11,#0 290 | BEQ read_out_of_data 291 | STR r11,[r0,#12] 292 | STR r6,[r0,#20] @ b->count = count 293 | LDMIA r11,{r6,r12,r14} @ r6 = buffer 294 | @ r12= begin 295 | @ r14= length 296 | LDR r6,[r6] @ r6 = buffer->data 297 | CMP r14,#0 298 | BEQ read_next_segment_2 299 | ADD r6,r6,r12 @ r6 = buffer->data+begin 300 | read_slow_loop: 301 | LDRB r12,[r6],#1 @ r12= *buffer 302 | SUBS r14,r14,#1 @ r14= length 303 | @ Stall 304 | ORR r10,r10,r12,LSL r5 @ r10= first r5+8 bits 305 | ADD r5,r5,#8 306 | BLE read_really_slow 307 | CMP r5,r1 308 | BLT read_slow_loop 309 | read_end: 310 | MOV r12,#1 311 | RSB r12,r12,r12,LSL r1 312 | 313 | @ Store back the new position 314 | @ r2 = -number of bits to go from this segment 315 | @ r6 = ptr 316 | @ r14= bytesLeftInSegment 317 | @ r11= New head value 318 | LDMIA r11,{r3,r6,r14} @ r3 = buffer 319 | @ r6 = begin 320 | @ r14= length 321 | LDR r3,[r3] @ r3 = buffer->data 322 | ADD r1,r2,r14,LSL #3 @ r1 = bitsLeftInSegment 323 | @ stall 324 | ADD r6,r3,r6 @ r6 = pointer 325 | AND r3,r6,#3 @ r3 = bytes used in first word 326 | RSB r3,r2,r3,LSL #3 @ r3 = bits used in first word 327 | BIC r2,r6,#3 @ r2 = word ptr 328 | RSBS r3,r3,#32 @ r3 = bitsLeftInWord 329 | ADDLE r3,r3,#32 330 | ADDLE r2,r2,#4 331 | STMIA r0,{r1,r2,r3} 332 | 333 | AND r0,r10,r12 334 | LDMFD r13!,{r5,r6,r10,r11,PC} 335 | 336 | 337 | read_really_slow: 338 | CMP r5,r1 339 | BGE read_end 340 | LDR r14,[r11,#8] @ r14= length of segment just done 341 | @ stall 342 | @ stall 343 | ADD r2,r2,r14,LSL #3 @ r2 = -bits to use from next seg 344 | B read_next_segment_2 345 | 346 | read_out_of_data: 347 | @ Store back the new position 348 | @ r2 = -number of bits to go from this segment 349 | @ r6 = ptr 350 | @ r14= bytesLeftInSegment 351 | @ RJW: This may be overkill - we leave the buffer empty, with -1 352 | @ bits left in it. We might get away with just storing the 353 | @ bitsLeftInSegment as -1. 354 | LDR r11,[r0,#12] @ r11=head 355 | 356 | LDMIA r11,{r3,r6,r14} @ r3 = buffer 357 | @ r6 = begin 358 | @ r14= length 359 | LDR r3,[r3] @ r3 = buffer->data 360 | ADD r6,r3,r6 @ r6 = pointer 361 | ADD r6,r6,r14 362 | AND r3,r6,#3 @ r3 = bytes used in first word 363 | MOV r3,r3,LSL #3 @ r3 = bits used in first word 364 | BIC r2,r6,#3 @ r2 = word ptr 365 | RSBS r3,r3,#32 @ r3 = bitsLeftInWord 366 | MVN r1,#0 @ r1 = -1 = bitsLeftInSegment 367 | STMIA r0,{r1,r2,r3} 368 | @MVN r0,#0 ; return -1 369 | MOV r0,#0 370 | LDMFD r13!,{r5,r6,r10,r11,PC} 371 | 372 | read_overrun: 373 | @ We had overrun when we started, so we need to skip -r10 bits. 374 | LDR r11,[r0,#12] @ r11 = head = b->head 375 | @ stall 376 | @ stall 377 | read_overrun_next_segment: 378 | LDR r11,[r11,#12] @ r11 = head->next 379 | @ stall 380 | @ stall 381 | CMP r11,#0 382 | BEQ read_out_of_data 383 | LDMIA r11,{r6,r7,r14} @ r6 = buffer 384 | @ r7 = begin 385 | @ r14= length 386 | LDR r6,[r6] @ r6 = buffer->data 387 | @ stall 388 | @ stall 389 | ADD r6,r6,r7 @ r6 = buffer->data+begin 390 | MOV r14,r14,LSL #3 @ r14= length in bits 391 | ADDS r14,r14,r10 @ r14= length in bits-bits to skip 392 | MOVLE r10,r14 393 | BLE read_overrun_next_segment 394 | RSB r10,r10,#0 @ r10= bits to skip 395 | ADD r6,r10,r10,LSR #3 @ r6 = pointer to data 396 | MOV r10,#0 397 | B read_slow_loop 398 | 399 | @ END 400 | -------------------------------------------------------------------------------- /Tremolo/treminfo.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: maintain the info structure, info <-> header packets 35 | 36 | ************************************************************************/ 37 | 38 | /* general handling of the header and the vorbis_info structure (and 39 | substructures) */ 40 | 41 | #include 42 | #include 43 | #include 44 | #include "ogg.h" 45 | #include "ivorbiscodec.h" 46 | #include "codec_internal.h" 47 | #include "codebook.h" 48 | #include "misc.h" 49 | #include "os.h" 50 | 51 | /* helpers */ 52 | static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){ 53 | while(bytes--){ 54 | *buf++=(char)oggpack_read(o,8); 55 | } 56 | } 57 | 58 | void vorbis_comment_init(vorbis_comment *vc){ 59 | memset(vc,0,sizeof(*vc)); 60 | } 61 | 62 | /* This is more or less the same as strncasecmp - but that doesn't exist 63 | * everywhere, and this is a fairly trivial function, so we include it */ 64 | static int tagcompare(const char *s1, const char *s2, int n){ 65 | int c=0; 66 | while(c < n){ 67 | if(toupper(s1[c]) != toupper(s2[c])) 68 | return !0; 69 | c++; 70 | } 71 | return 0; 72 | } 73 | 74 | char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ 75 | long i; 76 | int found = 0; 77 | int taglen = strlen(tag)+1; /* +1 for the = we append */ 78 | char *fulltag = (char *)alloca(taglen+ 1); 79 | 80 | strcpy(fulltag, tag); 81 | strcat(fulltag, "="); 82 | 83 | for(i=0;icomments;i++){ 84 | if(!tagcompare(vc->user_comments[i], fulltag, taglen)){ 85 | if(count == found) 86 | /* We return a pointer to the data, not a copy */ 87 | return vc->user_comments[i] + taglen; 88 | else 89 | found++; 90 | } 91 | } 92 | return NULL; /* didn't find anything */ 93 | } 94 | 95 | int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ 96 | int i,count=0; 97 | int taglen = strlen(tag)+1; /* +1 for the = we append */ 98 | char *fulltag = (char *)alloca(taglen+1); 99 | strcpy(fulltag,tag); 100 | strcat(fulltag, "="); 101 | 102 | for(i=0;icomments;i++){ 103 | if(!tagcompare(vc->user_comments[i], fulltag, taglen)) 104 | count++; 105 | } 106 | 107 | return count; 108 | } 109 | 110 | void vorbis_comment_clear(vorbis_comment *vc){ 111 | if(vc){ 112 | long i; 113 | for(i=0;icomments;i++) 114 | if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); 115 | if(vc->user_comments)_ogg_free(vc->user_comments); 116 | if(vc->comment_lengths)_ogg_free(vc->comment_lengths); 117 | if(vc->vendor)_ogg_free(vc->vendor); 118 | } 119 | memset(vc,0,sizeof(*vc)); 120 | } 121 | 122 | /* blocksize 0 is guaranteed to be short, 1 is guarantted to be long. 123 | They may be equal, but short will never ge greater than long */ 124 | int vorbis_info_blocksize(vorbis_info *vi,int zo){ 125 | codec_setup_info *ci = (codec_setup_info *)vi->codec_setup; 126 | return ci ? ci->blocksizes[zo] : -1; 127 | } 128 | 129 | /* used by synthesis, which has a full, alloced vi */ 130 | void vorbis_info_init(vorbis_info *vi){ 131 | memset(vi,0,sizeof(*vi)); 132 | vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info)); 133 | } 134 | 135 | void vorbis_info_clear(vorbis_info *vi){ 136 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 137 | int i; 138 | 139 | if(ci){ 140 | 141 | if(ci->mode_param)_ogg_free(ci->mode_param); 142 | 143 | if(ci->map_param){ 144 | for(i=0;imaps;i++) /* unpack does the range checking */ 145 | mapping_clear_info(ci->map_param+i); 146 | _ogg_free(ci->map_param); 147 | } 148 | 149 | if(ci->floor_param){ 150 | for(i=0;ifloors;i++) /* unpack does the range checking */ 151 | if(ci->floor_type[i]) 152 | floor1_free_info(ci->floor_param[i]); 153 | else 154 | floor0_free_info(ci->floor_param[i]); 155 | _ogg_free(ci->floor_param); 156 | _ogg_free(ci->floor_type); 157 | } 158 | 159 | if(ci->residue_param){ 160 | for(i=0;iresidues;i++) /* unpack does the range checking */ 161 | res_clear_info(ci->residue_param+i); 162 | _ogg_free(ci->residue_param); 163 | } 164 | 165 | if(ci->book_param){ 166 | for(i=0;ibooks;i++) 167 | vorbis_book_clear(ci->book_param+i); 168 | _ogg_free(ci->book_param); 169 | } 170 | 171 | _ogg_free(ci); 172 | } 173 | 174 | memset(vi,0,sizeof(*vi)); 175 | } 176 | 177 | /* Header packing/unpacking ********************************************/ 178 | 179 | int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){ 180 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 181 | if(!ci)return(OV_EFAULT); 182 | 183 | vi->version=oggpack_read(opb,32); 184 | if(vi->version!=0)return(OV_EVERSION); 185 | 186 | vi->channels=oggpack_read(opb,8); 187 | vi->rate=oggpack_read(opb,32); 188 | 189 | vi->bitrate_upper=oggpack_read(opb,32); 190 | vi->bitrate_nominal=oggpack_read(opb,32); 191 | vi->bitrate_lower=oggpack_read(opb,32); 192 | 193 | ci->blocksizes[0]=1<blocksizes[1]=1<rate>=64000 || ci->blocksizes[1]>4096)goto err_out; 198 | #else 199 | if(vi->rate<64000 && ci->blocksizes[1]>4096)goto err_out; 200 | #endif 201 | 202 | if(vi->rate<1)goto err_out; 203 | if(vi->channels<1)goto err_out; 204 | if(ci->blocksizes[0]<64)goto err_out; 205 | if(ci->blocksizes[1]blocksizes[0])goto err_out; 206 | if(ci->blocksizes[1]>8192)goto err_out; 207 | 208 | if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ 209 | 210 | return(0); 211 | err_out: 212 | vorbis_info_clear(vi); 213 | return(OV_EBADHEADER); 214 | } 215 | 216 | int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ 217 | int i; 218 | int vendorlen=oggpack_read(opb,32); 219 | if(vendorlen<0)goto err_out; 220 | vc->vendor=(char *)_ogg_calloc(vendorlen+1,1); 221 | if(!vc->vendor)goto err_out; 222 | _v_readstring(opb,vc->vendor,vendorlen); 223 | vc->comments=oggpack_read(opb,32); 224 | if(vc->comments<0)goto err_out; 225 | vc->user_comments=(char **)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments)); 226 | if (!vc->user_comments){ 227 | vc->comments=0; 228 | goto err_out; 229 | } 230 | vc->comment_lengths=(int *)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths)); 231 | if (!vc->comment_lengths)goto err_out; 232 | 233 | for(i=0;icomments;i++){ 234 | int len=oggpack_read(opb,32); 235 | if(len<0)goto err_out; 236 | vc->comment_lengths[i]=len; 237 | vc->user_comments[i]=(char *)_ogg_calloc(len+1,1); 238 | if(!vc->user_comments[i])goto err_out; 239 | _v_readstring(opb,vc->user_comments[i],len); 240 | } 241 | if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ 242 | 243 | return(0); 244 | err_out: 245 | vorbis_comment_clear(vc); 246 | return(OV_EBADHEADER); 247 | } 248 | 249 | /* all of the real encoding details are here. The modes, books, 250 | everything */ 251 | int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ 252 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 253 | int i; 254 | if(!ci)return(OV_EFAULT); 255 | 256 | /* codebooks */ 257 | ci->books=oggpack_read(opb,8)+1; 258 | ci->book_param=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->book_param)); 259 | if(!ci->book_param){ 260 | ci->books=0; 261 | goto err_out; 262 | } 263 | for(i=0;ibooks;i++) 264 | if(vorbis_book_unpack(opb,ci->book_param+i))goto err_out; 265 | 266 | /* time backend settings, not actually used */ 267 | i=oggpack_read(opb,6); 268 | for(;i>=0;i--) 269 | if(oggpack_read(opb,16)!=0)goto err_out; 270 | 271 | /* floor backend settings */ 272 | ci->floors=oggpack_read(opb,6)+1; 273 | ci->floor_param=_ogg_calloc(ci->floors, sizeof(*ci->floor_param)); 274 | ci->floor_type=_ogg_calloc(ci->floors, sizeof(*ci->floor_type)); 275 | if(!ci->floor_param || !ci->floor_type){ 276 | ci->floors=0; 277 | goto err_out; 278 | } 279 | for(i=0;ifloors;i++){ 280 | ci->floor_type[i]=(char)oggpack_read(opb,16); 281 | if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out; 282 | if(ci->floor_type[i]) 283 | ci->floor_param[i]=floor1_info_unpack(vi,opb); 284 | else 285 | ci->floor_param[i]=floor0_info_unpack(vi,opb); 286 | if(!ci->floor_param[i])goto err_out; 287 | } 288 | 289 | /* residue backend settings */ 290 | ci->residues=oggpack_read(opb,6)+1; 291 | ci->residue_param=_ogg_calloc(ci->residues, sizeof(*ci->residue_param)); 292 | if (!ci->residue_param){ 293 | ci->residues=0; 294 | goto err_out; 295 | } 296 | for(i=0;iresidues;i++) 297 | if(res_unpack(ci->residue_param+i,vi,opb))goto err_out; 298 | 299 | /* map backend settings */ 300 | ci->maps=oggpack_read(opb,6)+1; 301 | ci->map_param=_ogg_calloc(ci->maps, sizeof(*ci->map_param)); 302 | if (!ci->map_param){ 303 | ci->maps=0; 304 | goto err_out; 305 | } 306 | for(i=0;imaps;i++){ 307 | if(oggpack_read(opb,16)!=0)goto err_out; 308 | if(mapping_info_unpack(ci->map_param+i,vi,opb))goto err_out; 309 | } 310 | 311 | /* mode settings */ 312 | ci->modes=oggpack_read(opb,6)+1; 313 | ci->mode_param= 314 | (vorbis_info_mode *)_ogg_calloc(ci->modes, sizeof(*ci->mode_param)); 315 | if (!ci->mode_param){ 316 | ci->modes=0; 317 | goto err_out; 318 | } 319 | for(i=0;imodes;i++){ 320 | ci->mode_param[i].blockflag=(unsigned char)oggpack_read(opb,1); 321 | if(oggpack_read(opb,16))goto err_out; 322 | if(oggpack_read(opb,16))goto err_out; 323 | ci->mode_param[i].mapping=(unsigned char)oggpack_read(opb,8); 324 | if(ci->mode_param[i].mapping>=ci->maps)goto err_out; 325 | } 326 | 327 | if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */ 328 | 329 | return(0); 330 | err_out: 331 | vorbis_info_clear(vi); 332 | return(OV_EBADHEADER); 333 | } 334 | 335 | /* The Vorbis header is in three packets; the initial small packet in 336 | the first page that identifies basic parameters, a second packet 337 | with bitstream comments and a third packet that holds the 338 | codebook. */ 339 | 340 | int vorbis_dsp_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){ 341 | oggpack_buffer opb; 342 | 343 | if(op){ 344 | oggpack_readinit(&opb,op->packet); 345 | 346 | /* Which of the three types of header is this? */ 347 | /* Also verify header-ness, vorbis */ 348 | { 349 | char buffer[6]; 350 | int packtype=oggpack_read(&opb,8); 351 | memset(buffer,0,6); 352 | _v_readstring(&opb,buffer,6); 353 | if(memcmp(buffer,"vorbis",6)){ 354 | /* not a vorbis header */ 355 | return(OV_ENOTVORBIS); 356 | } 357 | switch(packtype){ 358 | case 0x01: /* least significant *bit* is read first */ 359 | if(!op->b_o_s){ 360 | /* Not the initial packet */ 361 | return(OV_EBADHEADER); 362 | } 363 | if(vi->rate!=0){ 364 | /* previously initialized info header */ 365 | return(OV_EBADHEADER); 366 | } 367 | 368 | return(_vorbis_unpack_info(vi,&opb)); 369 | 370 | case 0x03: /* least significant *bit* is read first */ 371 | if(vi->rate==0){ 372 | /* um... we didn't get the initial header */ 373 | return(OV_EBADHEADER); 374 | } 375 | 376 | return(_vorbis_unpack_comment(vc,&opb)); 377 | 378 | case 0x05: /* least significant *bit* is read first */ 379 | if(vi->rate==0 || vc->vendor==NULL){ 380 | /* um... we didn;t get the initial header or comments yet */ 381 | return(OV_EBADHEADER); 382 | } 383 | 384 | return(_vorbis_unpack_books(vi,&opb)); 385 | 386 | default: 387 | /* Not a valid vorbis header type */ 388 | return(OV_EBADHEADER); 389 | break; 390 | } 391 | } 392 | } 393 | return(OV_EBADHEADER); 394 | } 395 | 396 | -------------------------------------------------------------------------------- /Tremolo/dpen.s: -------------------------------------------------------------------------------- 1 | @ Tremolo library 2 | @----------------------------------------------------------------------- 3 | @ Copyright (C) 2002-2009, Xiph.org Foundation 4 | @ Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 5 | @ All rights reserved. 6 | 7 | @ Redistribution and use in source and binary forms, with or without 8 | @ modification, are permitted provided that the following conditions 9 | @ are met: 10 | 11 | @ * Redistributions of source code must retain the above copyright 12 | @ notice, this list of conditions and the following disclaimer. 13 | @ * Redistributions in binary form must reproduce the above 14 | @ copyright notice, this list of conditions and the following disclaimer 15 | @ in the documentation and/or other materials provided with the 16 | @ distribution. 17 | @ * Neither the names of the Xiph.org Foundation nor Pinknoise 18 | @ Productions Ltd nor the names of its contributors may be used to 19 | @ endorse or promote products derived from this software without 20 | @ specific prior written permission. 21 | @ 22 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | @ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | @ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | @ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | @ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | @ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | @ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | @ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | @ ---------------------------------------------------------------------- 34 | 35 | .text 36 | 37 | .global decode_packed_entry_number 38 | .global decode_packed_entry_number_REALSTART 39 | .global decode_map 40 | .global vorbis_book_decodevv_add 41 | .global _checksum 42 | 43 | .extern oggpack_adv 44 | .extern oggpack_look 45 | .extern oggpack_eop 46 | .extern crc_lookup 47 | .hidden crc_lookup 48 | 49 | decode_packed_entry_number_REALSTART: 50 | dpen_nobits: 51 | MOV r0,r5 @ r0 = b 52 | MOV r1,#1 @ r1 = 1 53 | BL oggpack_adv @ oggpack_adv(b,1) /* Force eop */ 54 | duff: 55 | MVN r0,#0 @ return -1 56 | LDMFD r13!,{r4-r8,r10,PC} 57 | 58 | dpen_readfailed: 59 | SUBS r4,r4,#1 @ r4 = --read 60 | BEQ dpen_nobits 61 | MOV r0,r5 @ r0 = b 62 | MOV r1,r4 @ r1 = read 63 | ADR r14,dpen_read_return 64 | B oggpack_look 65 | 66 | decode_packed_entry_number: 67 | @ r0 = codebook *book 68 | @ r1 = oggpack_buffer *b 69 | STMFD r13!,{r4-r8,r10,r14} 70 | 71 | LDMIA r0,{r4,r6,r7} @ r4 = read = book->max_length 72 | @ r6 = book->dec_table 73 | @ r7 = book->dec_method 74 | MOV r5,r1 @ r5 = b 75 | 76 | MOV r0,r5 @ r0 = b 77 | MOV r1,r4 @ r1 = read 78 | BL oggpack_look 79 | dpen_read_return: 80 | CMP r0,#0 81 | BLT dpen_readfailed 82 | 83 | @ r0 = lok 84 | @ r4 = read 85 | @ r5 = b 86 | @ r6 = dec_table 87 | @ r7 = dec_method 88 | 89 | CMP r7, #3 90 | BGT meth4 91 | BEQ meth3 92 | CMP r7, #1 93 | BGT meth2 94 | BEQ meth1 95 | meth0: 96 | RSB r1, r4, #0 @ r1 = i-read = 0-read 97 | MOV r7, #0 @ r7 = chase 98 | m0_loop: 99 | MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit 100 | ADC r2, r6, r7, LSL #1 @ r8 = &t[chase*2+C] 101 | LDRB r7, [r2] 102 | ADDS r1, r1, #1 @ r1 = i-read++ (i-read<0 => i= 0) === (i >= read) 108 | MVNGT r7, #0 @ if (i >= read) value to return = -1 109 | ADD r1, r1, r4 @ r1 = i-read+read+1 = i +1 110 | MOV r0, r5 @ r0 = b 111 | BL oggpack_adv @ oggpack_adv(b, i+1); 112 | MOV r0, r7 @ return chase 113 | LDMFD r13!,{r4-r8,r10,PC} 114 | 115 | meth1: 116 | @ r0 = lok 117 | @ r4 = read 118 | @ r5 = b 119 | @ r6 = dec_table 120 | RSB r1, r4, #0 @ r1 = i = -read 121 | MOV r10,#0 @ r10= next = 0 122 | m1_loop: 123 | MOV r7, r10 @ r7 = chase=next 124 | MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit 125 | ADC r8, r6, r7 @ r8 = t+chase+bit 126 | LDRB r10,[r8], -r6 @ r10= next=t[chase+bit] r8=chase+bit 127 | ADDS r1, r1, #1 @ r1 = i++ 128 | @ stall Xscale 129 | CMPLT r10,#0x80 @ if (next & 0x80) == 0 130 | BLT m1_loop 131 | 132 | ADD r1, r1, r4 @ r1 = i+read 133 | MOV r0, r5 @ r0 = b 134 | BL oggpack_adv @ oggpack_adv(b, i) 135 | 136 | CMP r10,#0x80 137 | BLT duff 138 | 139 | CMP r8, r7 @ if bit==0 (chase+bit==chase) (sets C) 140 | LDRNEB r14,[r6, r7] @ r14= t[chase] 141 | MOVEQ r14,#128 142 | ADC r12,r8, r6 @ r12= chase+bit+1+t 143 | LDRB r14,[r12,r14,LSR #7] @ r14= t[chase+bit+1+(!bit || t[chase]0x0x80)] 144 | BIC r10,r10,#0x80 @ r3 = next &= ~0x80 145 | @ stall Xscale 146 | ORR r0, r14,r10,LSL #8 @ r7 = chase = (next<<8) | r14 147 | 148 | LDMFD r13!,{r4-r8,r10,PC} 149 | 150 | 151 | meth2: 152 | RSB r1, r4, #0 @ r1 = i-read = 0-read 153 | MOV r7, #0 @ r7 = chase 154 | MOV r6, r6, LSR #1 155 | m2_loop: 156 | MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit 157 | ADC r2, r6, r7, LSL #1 @ r8 = &t[chase*2+C] 158 | LDRH r7, [r2, r2] 159 | ADDS r1, r1, #1 @ r1 = i-read++ (i-read<0 => i= 0) === (i >= read) 165 | MVNGT r7, #0 @ if (i >= read) value to return = -1 166 | ADD r1, r1, r4 @ r1 = i-read+read+1 = i +1 167 | MOV r0, r5 @ r0 = b 168 | BL oggpack_adv @ oggpack_adv(b, i+1); 169 | MOV r0, r7 @ return chase 170 | LDMFD r13!,{r4-r8,r10,PC} 171 | 172 | meth3: 173 | @ r0 = lok 174 | @ r4 = read 175 | @ r5 = b 176 | @ r6 = dec_table 177 | RSB r1, r4, #0 @ r1 = i = -read 178 | MOV r10,#0 @ r10= next = 0 179 | m3_loop: 180 | MOV r7, r10 @ r7 = chase=next 181 | MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit 182 | ADC r8, r7, #0 @ r8 = chase+bit 183 | MOV r8, r8, LSL #1 @ r8 = (chase+bit)<<1 184 | LDRH r10,[r6, r8] @ r10= next=t[chase+bit] 185 | ADDS r1, r1, #1 @ r1 = i++ 186 | @ stall Xscale 187 | CMPLT r10,#0x8000 @ if (next & 0x8000) == 0 188 | BLT m3_loop 189 | 190 | ADD r1, r1, r4 @ r1 = i+read 191 | MOV r0, r5 @ r0 = b 192 | BL oggpack_adv @ oggpack_adv(b, i) 193 | 194 | CMP r10,#0x8000 195 | BLT duff 196 | 197 | MOV r7, r7, LSL #1 198 | CMP r8, r7 @ if bit==0 (chase+bit==chase) sets C 199 | LDRNEH r14,[r6, r7] @ r14= t[chase] 200 | MOVEQ r14,#0x8000 201 | ADC r12,r8, r14,LSR #15 @ r12= 1+((chase+bit)<<1)+(!bit || t[chase]0x0x8000) 202 | ADC r12,r12,r14,LSR #15 @ r12= t + (1+chase+bit+(!bit || t[chase]0x0x8000))<<1 203 | LDRH r14,[r6, r12] @ r14= t[chase+bit+1 204 | BIC r10,r10,#0x8000 @ r3 = next &= ~0x8000 205 | @ stall Xscale 206 | ORR r0, r14,r10,LSL #16 @ r7 = chase = (next<<16) | r14 207 | 208 | LDMFD r13!,{r4-r8,r10,PC} 209 | 210 | meth4: 211 | RSB r1, r4, #0 @ r1 = i-read = 0-read 212 | MOV r7, #0 @ r7 = chase 213 | m4_loop: 214 | MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit 215 | ADC r2, r7, r7 @ r8 = chase*2+C 216 | LDR r7, [r6, r2, LSL #2] 217 | ADDS r1, r1, #1 @ r1 = i-read++ (i-read<0 => i= 0) === (i >= read) 223 | MVNGT r7, #0 @ if (i >= read) value to return = -1 224 | ADD r1, r1, r4 @ r1 = i-read+read+1 = i +1 225 | MOV r0, r5 @ r0 = b 226 | BL oggpack_adv @ oggpack_adv(b, i+1); 227 | MOV r0, r7 @ return chase 228 | LDMFD r13!,{r4-r8,r10,PC} 229 | 230 | decode_map: 231 | @ r0 = codebook *s 232 | @ r1 = oggpack_buffer *b 233 | @ r2 = int v 234 | @ r3 = int point 235 | STMFD r13!,{r4-r11,r14} 236 | 237 | MOV r4, r0 @ r4 = s 238 | MOV r5, r1 @ r5 = b 239 | MOV r6, r2 @ r6 = v 240 | MOV r7, r3 @ r7 = point 241 | BL decode_packed_entry_number 242 | MOV r8, r0 243 | 244 | MOV r0, r5 245 | BL oggpack_eop 246 | CMP r0, #0 247 | BNE dm_duff 248 | 249 | @ r4 = s 250 | @ r5 = b 251 | @ r6 = v 252 | @ r7 = point 253 | @ r8 = entry 254 | 255 | LDR r1, [r4,#12] @ r1 = s->dec_type 256 | LDR r2, [r4,#16] @ r2 = s->q_bits 257 | LDR r3, [r4,#20] @ r3 = s->dim 258 | LDR r5, [r4,#24] @ r5 = s->q_delp 259 | LDR r11,[r4,#28] @ r11= s->q_minp 260 | LDR r12,[r4,#32] @ r12= s->q_del = mul 261 | LDR r14,[r4,#36] @ r14= s->q_min 262 | SUBS r11,r7, r11 @ r11= add = point - s->q_minp 263 | 264 | MOVGT r14,r14,ASR r11 @ r14= add = s->q_min >> add (if add >0) 265 | RSBLT r11,r11,#0 266 | MOVLT r14,r14,LSL r11 @ r14= add = s->q_min << -add (if add < 0) 267 | 268 | SUBS r5, r7, r5 @ r5 = shiftM = point - s->q_delp 269 | LDR r7, [r4,#40] @ r7 = s->q_seq 270 | RSBLT r5, r5, #0 @ if (shiftM<0) r5 =-shiftM 271 | MOVLT r12,r12,LSL r5 @ r12=mul<<-shiftM 272 | MOVLT r5, #0 @ r5 =shiftM = 0 273 | MOVGT r14,r14,LSL r5 @ add <<= shiftM 274 | 275 | CMP r7,#0 @ seqMask = (s->q_seq?-1:0) 276 | MVNNE r7,#0 277 | 278 | CMP r1, #2 279 | BEQ dm2 280 | BGT dm3 281 | CMP r1,#0 @ probably never happens 282 | BLE dm_duff 283 | dm1: 284 | @ r1 = s->dec_type 285 | @ r2 = s->q_bits 286 | @ r3 = s->dim 287 | @ r5 = shiftM 288 | @ r6 = v 289 | @ r7 = seqMask 290 | @ r8 = entry 291 | @ r12= mul 292 | @ r14= add 293 | MOV r0, #1 294 | RSB r0, r0, r0, LSL r2 @ r0 = mask = (1<q_bits)-1 295 | MOV r11,#0 @ r11= prev = 0 296 | dm1_loop: 297 | AND r1, r8, r0 @ r1 = v = entry & mask 298 | MLA r1, r12, r1, r14 @ r1 = (add + mul*v) 299 | MOV r8, r8, LSR r2 @ r8 = entry>>s->q_bits 300 | SUBS r3, r3, #1 301 | ADD r1, r11,r1, ASR r5 @ r1 = v = prev+((add+mul*v)>>shiftM) 302 | AND r11,r1, r7 @ r11= prev = seqMask & v 303 | STR r1, [r6], #4 @ *v++ = v 304 | BGT dm1_loop 305 | 306 | MOV r0, #0 307 | LDMFD r13!,{r4-r11,PC} 308 | dm2: 309 | @ r1 = s->dec_type 310 | @ r2 = s->q_bits 311 | @ r3 = s->dim 312 | @ r4 = s 313 | @ r5 = shiftM 314 | @ r6 = v 315 | @ r7 = seqMask 316 | @ r8 = entry 317 | @ r12= mul 318 | @ r14= add 319 | LDR r1, [r4,#44] @ r1 = s->q_pack 320 | LDR r4, [r4,#48] @ r4 = s->q_val 321 | MOV r11,#0 @ r11= prev 322 | MOV r0, #1 323 | RSB r0, r0, r0, LSL r1 @ r8 = mask = (1<q_pack)-1 324 | CMP r2,#8 325 | BGT dm2_hword 326 | dm2_loop: 327 | AND r2, r8, r0 @ r2 = entry & mask 328 | LDRB r2, [r4, r2] @ r2 = v = q->val[entry & mask] 329 | MOV r8, r8, LSR r1 @ r8 = entry>>q_pack 330 | MLA r2, r12,r2, r14 @ r2 = (add+mul*v) 331 | SUBS r3, r3, #1 332 | ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM 333 | AND r11,r2, r7 @ r11= prev = seqMask & v 334 | STR r2, [r6], #4 @ *v++ = v 335 | BGT dm2_loop 336 | MOV r0, #0 337 | LDMFD r13!,{r4-r11,PC} 338 | 339 | dm2_hword: 340 | AND r2, r8, r0 @ r2 = entry & mask 341 | MOV r2, r2, LSL #1 @ r2 = 2*r2 342 | LDRH r2, [r4, r2] @ r2 = v = q->val[entry & mask] 343 | MOV r8, r8, LSR r1 @ r8 = entry>>q_pack 344 | MLA r2, r12,r2, r14 @ r2 = (add+mul*v) 345 | SUBS r3, r3, #1 346 | ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM 347 | AND r11,r2, r7 @ r11= prev = seqMask & v 348 | STR r2, [r6], #4 @ *v++ = v 349 | BGT dm2_hword 350 | MOV r0, #0 351 | LDMFD r13!,{r4-r11,PC} 352 | 353 | dm3: 354 | @ r1 = s->dec_type 355 | @ r2 = s->q_bits 356 | @ r3 = s->dim 357 | @ r4 = s 358 | @ r5 = shiftM 359 | @ r6 = v 360 | @ r7 = seqMask 361 | @ r8 = entry 362 | @ r12= mul 363 | @ r14= add 364 | LDR r1, [r4,#44] @ r1 = s->q_pack 365 | LDR r4, [r4,#48] @ r4 = s->q_val 366 | CMP r2,#8 367 | MOV r11,#0 @ r11= prev 368 | MLA r4,r1,r8,r4 @ r4 = ptr = s->q_val+entry*s->q_pack 369 | 370 | BGT dm3_hword 371 | dm3_loop: 372 | LDRB r2, [r4], #1 @ r2 = v = *ptr++ 373 | SUBS r3, r3, #1 374 | MLA r2, r12,r2, r14 @ r2 = (add+mul*v) 375 | ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM 376 | AND r11,r2, r7 @ r11= prev = seqMask & v 377 | STR r2, [r6], #4 @ *v++ = v 378 | BGT dm3_loop 379 | MOV r0, #0 380 | LDMFD r13!,{r4-r11,PC} 381 | 382 | dm3_hword: 383 | LDRH r2, [r4], #2 @ r2 = *ptr++ 384 | SUBS r3, r3, #1 385 | MLA r2, r12,r2, r14 @ r2 = (add+mul*v) 386 | ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM 387 | AND r11,r2, r7 @ r11= prev = seqMask & v 388 | STR r2, [r6], #4 @ *v++ = v 389 | BGT dm3_hword 390 | MOV r0, #0 391 | LDMFD r13!,{r4-r11,PC} 392 | 393 | dm_duff: 394 | MVN r0,#0 395 | LDMFD r13!,{r4-r11,PC} 396 | 397 | vorbis_book_decodevv_add: 398 | @ r0 = codebook *book 399 | @ r1 = ogg_int32_t **a 400 | @ r2 = long offset 401 | @ r3 = int ch 402 | @ <> = b 403 | @ <> = n 404 | @ <> = point 405 | STMFD r13!,{r4-r11,R14} 406 | LDR r7, [r0, #13*4] @ r7 = used_entries 407 | MOV r9, r0 @ r9 = book 408 | MOV r10,r1 @ r10= 0xa[chptr] chptr=0 409 | MOV r6, r3 @ r6 = ch 410 | ADD r8, r10,r3, LSL #2 @ r8 = 0xa[ch] 411 | MOV r11,r2 @ r11= offset 412 | CMP r7, #0 @ if (used_entries <= 0) 413 | BLE vbdvva_exit @ exit 414 | LDR r5, [r13,#10*4] @ r5 = n 415 | vbdvva_loop1: 416 | @ r5 = n 417 | @ r6 = ch 418 | @ r8 = 0xa[ch] 419 | @ r9 = book 420 | @ r10= 0xa[chptr] 421 | @ r11= offset 422 | MOV r0, r9 @ r0 = book 423 | LDR r1, [r13,# 9*4] @ r1 = b 424 | LDR r2, [r9, #14*4] @ r2 = v = dec_buf 425 | LDR r3, [r13,#11*4] @ r3 = point 426 | BL decode_map 427 | CMP r0, #0 428 | BNE vbdvva_fail 429 | 430 | LDR r0, [r9, # 5*4] @ r0 = book->dim 431 | LDR r1, [r9, #14*4] @ r1 = v = dec_buf 432 | vbdvva_loop2: 433 | CMP r5,#0 434 | BLE vbdvva_exit 435 | LDR r2, [r10],#4 @ r2 = a[chptr++] 436 | LDR r12,[r1], #4 @ r1 = v[j++] 437 | CMP r10,r8 @ if (chptr == ch) 438 | SUBEQ r10,r10,r6, LSL #2 @ chptr = 0 439 | LDR r14,[r2, r11,LSL #2]! @ r2 = 0xa[chptr++][i] r14=[r12] 440 | ADDEQ r11,r11,#1 @ i++ 441 | SUBEQ r5, r5, #1 @ n-- 442 | SUBS r0, r0, #1 @ r0-- 443 | ADD r12,r12,r14 @ r12= a[chptr++][i]+ v[j] 444 | STR r12,[r2] @ r12= a[chptr++][i]+=v[j] 445 | BGT vbdvva_loop2 446 | CMP r5,#0 447 | BGT vbdvva_loop1 448 | vbdvva_exit: 449 | MOV r0, #0 @ return 0 450 | LDMFD r13!,{r4-r11,PC} 451 | vbdvva_fail: 452 | MVN r0, #0 @ return -1 453 | LDMFD r13!,{r4-r11,PC} 454 | 455 | _checksum: 456 | @ r0 = ogg_reference *or 457 | @ r1 = bytes 458 | STMFD r13!,{r5-r6,r14} 459 | 460 | ADR r6,.Lcrc_lookup 461 | LDR r5,[r6] 462 | ADD r5,r6 463 | MOV r14,#0 @ r14= crc_reg = 0 464 | MOVS r12,r0 465 | BEQ _cs_end 466 | _cs_loop1: 467 | LDMIA r12,{r0,r2,r3,r12} @ r0 = or->buffer 468 | @ r2 = or->begin 469 | @ r3 = or->length 470 | @ r12= or->next 471 | LDR r0,[r0] @ r0 = or->buffer->data 472 | CMP r1,r3 @ r3 = post = (bytes < or->length ? 473 | MOVLT r3,r1 @ bytes : or->length) 474 | MOVS r6,r3 @ r6 = j = post 475 | BEQ _cs_no_bytes 476 | ADD r0,r0,r2 @ r0 = or->buffer->data + or->begin 477 | _cs_loop2: 478 | LDRB r2, [r0],#1 @ r2 = data[j] 479 | @ stall 480 | @ stall Xscale 481 | EOR r2, r2, r14,LSR #24 @ r2 = (crc_reg>>24)^data[j] 482 | LDR r2, [r5, r2, LSL #2] @ r2 = crc_lkp[(crc_reg>>24)^data[j]] 483 | SUBS r6, r6, #1 @ j-- 484 | @ stall Xscale 485 | EOR r14,r2, r14,LSL #8 @ r14= crc_reg = (crc_reg<<8)^r2 486 | BGT _cs_loop2 487 | _cs_no_bytes: 488 | SUBS r1, r1, r3 489 | CMPNE r12,#0 490 | BNE _cs_loop1 491 | _cs_end: 492 | MOV r0,r14 493 | LDMFD r13!,{r5-r6,PC} 494 | 495 | .Lcrc_lookup: 496 | .WORD crc_lookup-.Lcrc_lookup 497 | 498 | @ END 499 | -------------------------------------------------------------------------------- /Tremolo/floor0.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: floor backend 0 implementation 35 | 36 | ************************************************************************/ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include "ogg.h" 43 | #include "ivorbiscodec.h" 44 | #include "codec_internal.h" 45 | #include "codebook.h" 46 | #include "misc.h" 47 | #include "os.h" 48 | 49 | #define LSP_FRACBITS 14 50 | extern const ogg_int32_t FLOOR_fromdB_LOOKUP[]; 51 | 52 | /*************** LSP decode ********************/ 53 | 54 | #include "lsp_lookup.h" 55 | 56 | /* interpolated 1./sqrt(p) where .5 <= a < 1. (.100000... to .111111...) in 57 | 16.16 format 58 | returns in m.8 format */ 59 | 60 | static long ADJUST_SQRT2[2]={8192,5792}; 61 | static inline ogg_int32_t vorbis_invsqlook_i(long a,long e){ 62 | long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1); 63 | long d=a&INVSQ_LOOKUP_I_MASK; /* 0.10 */ 64 | long val=INVSQ_LOOKUP_I[i]- /* 1.16 */ 65 | ((INVSQ_LOOKUP_IDel[i]*d)>>INVSQ_LOOKUP_I_SHIFT); /* result 1.16 */ 66 | val*=ADJUST_SQRT2[e&1]; 67 | e=(e>>1)+21; 68 | return(val>>e); 69 | } 70 | 71 | /* interpolated lookup based fromdB function, domain -140dB to 0dB only */ 72 | /* a is in n.12 format */ 73 | #ifdef _LOW_ACCURACY_ 74 | static inline ogg_int32_t vorbis_fromdBlook_i(long a){ 75 | if(a>0) return 0x7fffffff; 76 | if(a<(int)(((unsigned)-140)<<12)) return 0; 77 | return FLOOR_fromdB_LOOKUP[((a+140)*467)>>20]<<9; 78 | } 79 | #else 80 | static inline ogg_int32_t vorbis_fromdBlook_i(long a){ 81 | if(a>0) return 0x7fffffff; 82 | if(a<(int)(((unsigned)-140)<<12)) return 0; 83 | return FLOOR_fromdB_LOOKUP[((a+(140<<12))*467)>>20]; 84 | } 85 | #endif 86 | 87 | /* interpolated lookup based cos function, domain 0 to PI only */ 88 | /* a is in 0.16 format, where 0==0, 2^^16-1==PI, return 0.14 */ 89 | static inline ogg_int32_t vorbis_coslook_i(long a){ 90 | int i=a>>COS_LOOKUP_I_SHIFT; 91 | int d=a&COS_LOOKUP_I_MASK; 92 | return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>> 93 | COS_LOOKUP_I_SHIFT); 94 | } 95 | 96 | /* interpolated half-wave lookup based cos function */ 97 | /* a is in 0.16 format, where 0==0, 2^^16==PI, return .LSP_FRACBITS */ 98 | static inline ogg_int32_t vorbis_coslook2_i(long a){ 99 | int i=a>>COS_LOOKUP_I_SHIFT; 100 | int d=a&COS_LOOKUP_I_MASK; 101 | return ((COS_LOOKUP_I[i]<> 103 | (COS_LOOKUP_I_SHIFT-LSP_FRACBITS+14); 104 | } 105 | 106 | static const ogg_uint16_t barklook[54]={ 107 | 0,51,102,154, 206,258,311,365, 108 | 420,477,535,594, 656,719,785,854, 109 | 926,1002,1082,1166, 1256,1352,1454,1564, 110 | 1683,1812,1953,2107, 2276,2463,2670,2900, 111 | 3155,3440,3756,4106, 4493,4919,5387,5901, 112 | 6466,7094,7798,8599, 9528,10623,11935,13524, 113 | 15453,17775,20517,23667, 27183,31004 114 | }; 115 | 116 | /* used in init only; interpolate the long way */ 117 | static inline ogg_int32_t toBARK(int n){ 118 | int i; 119 | for(i=0;i<54;i++) 120 | if(n>=barklook[i] && n>17); 127 | } 128 | } 129 | 130 | static const unsigned char MLOOP_1[64]={ 131 | 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13, 132 | 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14, 133 | 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15, 134 | 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15, 135 | }; 136 | 137 | static const unsigned char MLOOP_2[64]={ 138 | 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7, 139 | 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 140 | 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9, 141 | 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9, 142 | }; 143 | 144 | static const unsigned char MLOOP_3[8]={0,1,2,2,3,3,3,3}; 145 | 146 | void vorbis_lsp_to_curve(ogg_int32_t *curve,int n,int ln, 147 | ogg_int32_t *lsp,int m, 148 | ogg_int32_t amp, 149 | ogg_int32_t ampoffset, 150 | ogg_int32_t nyq){ 151 | 152 | /* 0 <= m < 256 */ 153 | 154 | /* set up for using all int later */ 155 | int i; 156 | int ampoffseti=ampoffset*4096; 157 | int ampi=amp; 158 | ogg_int32_t *ilsp=(ogg_int32_t *)alloca(m*sizeof(*ilsp)); 159 | 160 | ogg_uint32_t inyq= (1UL<<31) / toBARK(nyq); 161 | ogg_uint32_t imap= (1UL<<31) / ln; 162 | ogg_uint32_t tBnyq1 = toBARK(nyq)<<1; 163 | 164 | /* Besenham for frequency scale to avoid a division */ 165 | int f=0; 166 | int fdx=n; 167 | int fbase=nyq/fdx; 168 | int ferr=0; 169 | int fdy=nyq-fbase*fdx; 170 | int map=0; 171 | 172 | #ifdef _LOW_ACCURACY_ 173 | ogg_uint32_t nextbark=((tBnyq1<<11)/ln)>>12; 174 | #else 175 | ogg_uint32_t nextbark=MULT31(imap>>1,tBnyq1); 176 | #endif 177 | int nextf=barklook[nextbark>>14]+(((nextbark&0x3fff)* 178 | (barklook[(nextbark>>14)+1]-barklook[nextbark>>14]))>>14); 179 | 180 | /* lsp is in 8.24, range 0 to PI; coslook wants it in .16 0 to 1*/ 181 | for(i=0;i>10)*0x517d)>>14; 186 | #endif 187 | 188 | /* safeguard against a malicious stream */ 189 | if(val<0 || (val>>COS_LOOKUP_I_SHIFT)>=COS_LOOKUP_I_SZ){ 190 | memset(curve,0,sizeof(*curve)*n); 191 | return; 192 | } 193 | 194 | ilsp[i]=vorbis_coslook_i(val); 195 | } 196 | 197 | i=0; 198 | while(i>15); 206 | 207 | 208 | #ifdef _V_LSP_MATH_ASM 209 | lsp_loop_asm(&qi,&pi,&qexp,ilsp,wi,m); 210 | 211 | pi=((pi*pi)>>16); 212 | qi=((qi*qi)>>16); 213 | 214 | if(m&1){ 215 | qexp= qexp*2-28*((m+1)>>1)+m; 216 | pi*=(1<<14)-((wi*wi)>>14); 217 | qi+=pi>>14; 218 | }else{ 219 | qexp= qexp*2-13*m; 220 | 221 | pi*=(1<<14)-wi; 222 | qi*=(1<<14)+wi; 223 | 224 | qi=(qi+pi)>>14; 225 | } 226 | 227 | if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */ 228 | qi>>=1; qexp++; 229 | }else 230 | lsp_norm_asm(&qi,&qexp); 231 | 232 | #else 233 | 234 | qi*=labs(ilsp[0]-wi); 235 | pi*=labs(ilsp[1]-wi); 236 | 237 | for(j=3;j>25])) 239 | if(!(shift=MLOOP_2[(pi|qi)>>19])) 240 | shift=MLOOP_3[(pi|qi)>>16]; 241 | 242 | qi=(qi>>shift)*labs(ilsp[j-1]-wi); 243 | pi=(pi>>shift)*labs(ilsp[j]-wi); 244 | qexp+=shift; 245 | } 246 | if(!(shift=MLOOP_1[(pi|qi)>>25])) 247 | if(!(shift=MLOOP_2[(pi|qi)>>19])) 248 | shift=MLOOP_3[(pi|qi)>>16]; 249 | 250 | /* pi,qi normalized collectively, both tracked using qexp */ 251 | 252 | if(m&1){ 253 | /* odd order filter; slightly assymetric */ 254 | /* the last coefficient */ 255 | qi=(qi>>shift)*labs(ilsp[j-1]-wi); 256 | pi=(pi>>shift)<<14; 257 | qexp+=shift; 258 | 259 | if(!(shift=MLOOP_1[(pi|qi)>>25])) 260 | if(!(shift=MLOOP_2[(pi|qi)>>19])) 261 | shift=MLOOP_3[(pi|qi)>>16]; 262 | 263 | pi>>=shift; 264 | qi>>=shift; 265 | qexp+=shift-14*((m+1)>>1); 266 | 267 | pi=((pi*pi)>>16); 268 | qi=((qi*qi)>>16); 269 | qexp=qexp*2+m; 270 | 271 | pi*=(1<<14)-((wi*wi)>>14); 272 | qi+=pi>>14; 273 | 274 | }else{ 275 | /* even order filter; still symmetric */ 276 | 277 | /* p*=p(1-w), q*=q(1+w), let normalization drift because it isn't 278 | worth tracking step by step */ 279 | 280 | pi>>=shift; 281 | qi>>=shift; 282 | qexp+=shift-7*m; 283 | 284 | pi=((pi*pi)>>16); 285 | qi=((qi*qi)>>16); 286 | qexp=qexp*2+m; 287 | 288 | pi*=(1<<14)-wi; 289 | qi*=(1<<14)+wi; 290 | qi=(qi+pi)>>14; 291 | 292 | } 293 | 294 | 295 | /* we've let the normalization drift because it wasn't important; 296 | however, for the lookup, things must be normalized again. We 297 | need at most one right shift or a number of left shifts */ 298 | 299 | if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */ 300 | qi>>=1; qexp++; 301 | }else 302 | while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/ 303 | qi<<=1; qexp--; 304 | } 305 | 306 | #endif 307 | 308 | amp=vorbis_fromdBlook_i(ampi* /* n.4 */ 309 | vorbis_invsqlook_i(qi,qexp)- 310 | /* m.8, m+n<=8 */ 311 | ampoffseti); /* 8.12[0] */ 312 | 313 | #ifdef _LOW_ACCURACY_ 314 | amp>>=9; 315 | #endif 316 | curve[i]= MULT31_SHIFT15(curve[i],amp); 317 | 318 | while(++i=fdx){ 323 | ferr-=fdx; 324 | f++; 325 | } 326 | f+=fbase; 327 | 328 | if(f>=nextf)break; 329 | 330 | curve[i]= MULT31_SHIFT15(curve[i],amp); 331 | } 332 | 333 | while(1){ 334 | map++; 335 | 336 | if(map+1>12; 340 | #else 341 | nextbark=MULT31((map+1)*(imap>>1),tBnyq1); 342 | #endif 343 | nextf=barklook[nextbark>>14]+ 344 | (((nextbark&0x3fff)* 345 | (barklook[(nextbark>>14)+1]-barklook[nextbark>>14]))>>14); 346 | if(f<=nextf)break; 347 | 348 | }else{ 349 | nextf=9999999; 350 | break; 351 | } 352 | } 353 | if(map>=ln){ 354 | map=ln-1; /* guard against the approximation */ 355 | nextf=9999999; 356 | } 357 | } 358 | } 359 | 360 | /*************** vorbis decode glue ************/ 361 | 362 | void floor0_free_info(vorbis_info_floor *i){ 363 | vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; 364 | if(info)_ogg_free(info); 365 | } 366 | 367 | vorbis_info_floor *floor0_info_unpack (vorbis_info *vi,oggpack_buffer *opb){ 368 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 369 | int j; 370 | 371 | vorbis_info_floor0 *info=(vorbis_info_floor0 *)_ogg_malloc(sizeof(*info)); 372 | info->order=oggpack_read(opb,8); 373 | info->rate=oggpack_read(opb,16); 374 | info->barkmap=oggpack_read(opb,16); 375 | info->ampbits=oggpack_read(opb,6); 376 | info->ampdB=oggpack_read(opb,8); 377 | info->numbooks=oggpack_read(opb,4)+1; 378 | 379 | if(info->order<1)goto err_out; 380 | if(info->rate<1)goto err_out; 381 | if(info->barkmap<1)goto err_out; 382 | 383 | for(j=0;jnumbooks;j++){ 384 | info->books[j]=(char)oggpack_read(opb,8); 385 | if(info->books[j]>=ci->books)goto err_out; 386 | } 387 | 388 | if(oggpack_eop(opb))goto err_out; 389 | return(info); 390 | 391 | err_out: 392 | floor0_free_info(info); 393 | return(NULL); 394 | } 395 | 396 | int floor0_memosize(vorbis_info_floor *i){ 397 | vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; 398 | return info->order+1; 399 | } 400 | 401 | ogg_int32_t *floor0_inverse1(vorbis_dsp_state *vd,vorbis_info_floor *i, 402 | ogg_int32_t *lsp){ 403 | vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; 404 | int j,k; 405 | uint64_t ampraw; 406 | if(info->ampbits<=32){ 407 | ampraw=oggpack_read(&vd->opb,info->ampbits); 408 | }else{ 409 | //max value possible for info->ampbits is 63 410 | ampraw=oggpack_read(&vd->opb,info->ampbits-32); 411 | ampraw<<=32; 412 | ampraw|=oggpack_read(&vd->opb,32); 413 | } 414 | if(ampraw>0){ /* also handles the -1 out of data case */ 415 | uint64_t maxval=(1<ampbits)-1; 416 | float ampRatio=(float)ampraw/maxval; 417 | int amp=ampRatio*(info->ampdB<<4); 418 | int booknum=oggpack_read(&vd->opb,_ilog(info->numbooks)); 419 | if(booknum!=-1 && booknumnumbooks){ /* be paranoid */ 420 | codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; 421 | codebook *b=ci->book_param+info->books[booknum]; 422 | int sz = floor0_memosize(i); 423 | if (sz < b->dim) { 424 | ALOGE("lsp too small: %d < %ld", sz, b->dim); 425 | return NULL; 426 | } 427 | ogg_int32_t last=0; 428 | 429 | if(vorbis_book_decodev_set(b,lsp,&vd->opb,info->order,-24)==-1)goto eop; 430 | for(j=0;jorder;){ 431 | for(k=0;kdim && jorder;k++,j++)lsp[j]+=last; 432 | last=lsp[j-1]; 433 | } 434 | 435 | lsp[info->order]=amp; 436 | return(lsp); 437 | } 438 | } 439 | eop: 440 | return(NULL); 441 | } 442 | 443 | int floor0_inverse2(vorbis_dsp_state *vd,vorbis_info_floor *i, 444 | ogg_int32_t *lsp,ogg_int32_t *out){ 445 | vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; 446 | codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; 447 | 448 | if(lsp){ 449 | ogg_int32_t amp=lsp[info->order]; 450 | 451 | /* take the coefficients back to a spectral envelope curve */ 452 | vorbis_lsp_to_curve(out,ci->blocksizes[vd->W]/2,info->barkmap, 453 | lsp,info->order,amp,info->ampdB, 454 | info->rate>>1); 455 | return(1); 456 | } 457 | memset(out,0,sizeof(*out)*ci->blocksizes[vd->W]/2); 458 | return(0); 459 | } 460 | 461 | -------------------------------------------------------------------------------- /Tremolo/mdct.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * Copyright (C) 2002-2009, Xiph.org Foundation 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the names of the Xiph.org Foundation nor Pinknoise 17 | * Productions Ltd nor the names of its contributors may be used to 18 | * endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | ************************************************************************ 33 | 34 | function: normalized modified discrete cosine transform 35 | power of two length transform only [64 <= n ] 36 | last mod: $Id: mdct.c,v 1.9.6.5 2003/04/29 04:03:27 xiphmont Exp $ 37 | 38 | Original algorithm adapted long ago from _The use of multirate filter 39 | banks for coding of high quality digital audio_, by T. Sporer, 40 | K. Brandenburg and B. Edler, collection of the European Signal 41 | Processing Conference (EUSIPCO), Amsterdam, June 1992, Vol.1, pp 42 | 211-214 43 | 44 | The below code implements an algorithm that no longer looks much like 45 | that presented in the paper, but the basic structure remains if you 46 | dig deep enough to see it. 47 | 48 | This module DOES NOT INCLUDE code to generate/apply the window 49 | function. Everybody has their own weird favorite including me... I 50 | happen to like the properties of y=sin(.5PI*sin^2(x)), but others may 51 | vehemently disagree. 52 | 53 | ************************************************************************/ 54 | 55 | #include "ivorbiscodec.h" 56 | #include "os.h" 57 | #include "misc.h" 58 | #include "mdct.h" 59 | #include "mdct_lookup.h" 60 | 61 | #include 62 | 63 | #if defined(ONLY_C) 64 | STIN void presymmetry(DATA_TYPE *in,int n2,int step){ 65 | DATA_TYPE *aX; 66 | DATA_TYPE *bX; 67 | LOOKUP_T *T; 68 | int n4=n2>>1; 69 | 70 | aX = in+n2-3; 71 | T = sincos_lookup0; 72 | 73 | do{ 74 | REG_TYPE s0= aX[0]; 75 | REG_TYPE s2= aX[2]; 76 | XPROD31( s0, s2, T[0], T[1], &aX[0], &aX[2] ); T+=step; 77 | aX-=4; 78 | }while(aX>=in+n4); 79 | do{ 80 | REG_TYPE s0= aX[0]; 81 | REG_TYPE s2= aX[2]; 82 | XPROD31( s0, s2, T[1], T[0], &aX[0], &aX[2] ); T-=step; 83 | aX-=4; 84 | }while(aX>=in); 85 | 86 | aX = in+n2-4; 87 | bX = in; 88 | T = sincos_lookup0; 89 | do{ 90 | REG_TYPE ri0= aX[0]; 91 | REG_TYPE ri2= aX[2]; 92 | REG_TYPE ro0= bX[0]; 93 | REG_TYPE ro2= bX[2]; 94 | 95 | XNPROD31( ro2, ro0, T[1], T[0], &aX[0], &aX[2] ); T+=step; 96 | XNPROD31( ri2, ri0, T[0], T[1], &bX[0], &bX[2] ); 97 | 98 | aX-=4; 99 | bX+=4; 100 | }while(aX>=bX); 101 | } 102 | 103 | /* 8 point butterfly (in place) */ 104 | STIN void mdct_butterfly_8(DATA_TYPE *x){ 105 | 106 | REG_TYPE s0 = x[0] + x[1]; 107 | REG_TYPE s1 = x[0] - x[1]; 108 | REG_TYPE s2 = x[2] + x[3]; 109 | REG_TYPE s3 = x[2] - x[3]; 110 | REG_TYPE s4 = x[4] + x[5]; 111 | REG_TYPE s5 = x[4] - x[5]; 112 | REG_TYPE s6 = x[6] + x[7]; 113 | REG_TYPE s7 = x[6] - x[7]; 114 | 115 | x[0] = s5 + s3; 116 | x[1] = s7 - s1; 117 | x[2] = s5 - s3; 118 | x[3] = s7 + s1; 119 | x[4] = s4 - s0; 120 | x[5] = s6 - s2; 121 | x[6] = s4 + s0; 122 | x[7] = s6 + s2; 123 | MB(); 124 | } 125 | 126 | /* 16 point butterfly (in place, 4 register) */ 127 | STIN void mdct_butterfly_16(DATA_TYPE *x){ 128 | 129 | REG_TYPE s0, s1, s2, s3; 130 | 131 | s0 = x[ 8] - x[ 9]; x[ 8] += x[ 9]; 132 | s1 = x[10] - x[11]; x[10] += x[11]; 133 | s2 = x[ 1] - x[ 0]; x[ 9] = x[ 1] + x[0]; 134 | s3 = x[ 3] - x[ 2]; x[11] = x[ 3] + x[2]; 135 | x[ 0] = MULT31((s0 - s1) , cPI2_8); 136 | x[ 1] = MULT31((s2 + s3) , cPI2_8); 137 | x[ 2] = MULT31((s0 + s1) , cPI2_8); 138 | x[ 3] = MULT31((s3 - s2) , cPI2_8); 139 | MB(); 140 | 141 | s2 = x[12] - x[13]; x[12] += x[13]; 142 | s3 = x[14] - x[15]; x[14] += x[15]; 143 | s0 = x[ 4] - x[ 5]; x[13] = x[ 5] + x[ 4]; 144 | s1 = x[ 7] - x[ 6]; x[15] = x[ 7] + x[ 6]; 145 | x[ 4] = s2; x[ 5] = s1; 146 | x[ 6] = s3; x[ 7] = s0; 147 | MB(); 148 | 149 | mdct_butterfly_8(x); 150 | mdct_butterfly_8(x+8); 151 | } 152 | 153 | /* 32 point butterfly (in place, 4 register) */ 154 | STIN void mdct_butterfly_32(DATA_TYPE *x){ 155 | 156 | REG_TYPE s0, s1, s2, s3; 157 | 158 | s0 = x[16] - x[17]; x[16] += x[17]; 159 | s1 = x[18] - x[19]; x[18] += x[19]; 160 | s2 = x[ 1] - x[ 0]; x[17] = x[ 1] + x[ 0]; 161 | s3 = x[ 3] - x[ 2]; x[19] = x[ 3] + x[ 2]; 162 | XNPROD31( s0, s1, cPI3_8, cPI1_8, &x[ 0], &x[ 2] ); 163 | XPROD31 ( s2, s3, cPI1_8, cPI3_8, &x[ 1], &x[ 3] ); 164 | MB(); 165 | 166 | s0 = x[20] - x[21]; x[20] += x[21]; 167 | s1 = x[22] - x[23]; x[22] += x[23]; 168 | s2 = x[ 5] - x[ 4]; x[21] = x[ 5] + x[ 4]; 169 | s3 = x[ 7] - x[ 6]; x[23] = x[ 7] + x[ 6]; 170 | x[ 4] = MULT31((s0 - s1) , cPI2_8); 171 | x[ 5] = MULT31((s3 + s2) , cPI2_8); 172 | x[ 6] = MULT31((s0 + s1) , cPI2_8); 173 | x[ 7] = MULT31((s3 - s2) , cPI2_8); 174 | MB(); 175 | 176 | s0 = x[24] - x[25]; x[24] += x[25]; 177 | s1 = x[26] - x[27]; x[26] += x[27]; 178 | s2 = x[ 9] - x[ 8]; x[25] = x[ 9] + x[ 8]; 179 | s3 = x[11] - x[10]; x[27] = x[11] + x[10]; 180 | XNPROD31( s0, s1, cPI1_8, cPI3_8, &x[ 8], &x[10] ); 181 | XPROD31 ( s2, s3, cPI3_8, cPI1_8, &x[ 9], &x[11] ); 182 | MB(); 183 | 184 | s0 = x[28] - x[29]; x[28] += x[29]; 185 | s1 = x[30] - x[31]; x[30] += x[31]; 186 | s2 = x[12] - x[13]; x[29] = x[13] + x[12]; 187 | s3 = x[15] - x[14]; x[31] = x[15] + x[14]; 188 | x[12] = s0; x[13] = s3; 189 | x[14] = s1; x[15] = s2; 190 | MB(); 191 | 192 | mdct_butterfly_16(x); 193 | mdct_butterfly_16(x+16); 194 | } 195 | 196 | /* N/stage point generic N stage butterfly (in place, 2 register) */ 197 | STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){ 198 | LOOKUP_T *T = sincos_lookup0; 199 | DATA_TYPE *x1 = x + points - 4; 200 | DATA_TYPE *x2 = x + (points>>1) - 4; 201 | REG_TYPE s0, s1, s2, s3; 202 | 203 | do{ 204 | s0 = x1[0] - x1[1]; x1[0] += x1[1]; 205 | s1 = x1[3] - x1[2]; x1[2] += x1[3]; 206 | s2 = x2[1] - x2[0]; x1[1] = x2[1] + x2[0]; 207 | s3 = x2[3] - x2[2]; x1[3] = x2[3] + x2[2]; 208 | XPROD31( s1, s0, T[0], T[1], &x2[0], &x2[2] ); 209 | XPROD31( s2, s3, T[0], T[1], &x2[1], &x2[3] ); T+=step; 210 | x1-=4; 211 | x2-=4; 212 | }while(T>1) + (points>>2) - 4; 214 | x2 = x + (points>>2) - 4; 215 | T = sincos_lookup0+1024; 216 | do{ 217 | s0 = x1[0] - x1[1]; x1[0] += x1[1]; 218 | s1 = x1[2] - x1[3]; x1[2] += x1[3]; 219 | s2 = x2[0] - x2[1]; x1[1] = x2[1] + x2[0]; 220 | s3 = x2[3] - x2[2]; x1[3] = x2[3] + x2[2]; 221 | XNPROD31( s0, s1, T[0], T[1], &x2[0], &x2[2] ); 222 | XNPROD31( s3, s2, T[0], T[1], &x2[1], &x2[3] ); T-=step; 223 | x1-=4; 224 | x2-=4; 225 | }while(T>sincos_lookup0); 226 | } 227 | 228 | STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){ 229 | 230 | int stages=7-shift; 231 | int i,j; 232 | 233 | for(i=0;--stages>=0;i++){ 234 | for(j=0;j<(1<>i)*j,points>>i,4<<(i+shift)); 237 | } 238 | } 239 | 240 | for(j=0;j>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8); 248 | } 249 | 250 | STIN void mdct_bitreverse(DATA_TYPE *x,int n,int shift){ 251 | int bit = 0; 252 | DATA_TYPE *w = x+(n>>1); 253 | 254 | do{ 255 | DATA_TYPE b = bitrev12(bit++); 256 | DATA_TYPE *xx = x + (b>>shift); 257 | REG_TYPE r; 258 | 259 | w -= 2; 260 | 261 | if(w>xx){ 262 | 263 | r = xx[0]; 264 | xx[0] = w[0]; 265 | w[0] = r; 266 | 267 | r = xx[1]; 268 | xx[1] = w[1]; 269 | w[1] = r; 270 | } 271 | }while(w>x); 272 | } 273 | 274 | STIN void mdct_step7(DATA_TYPE *x,int n,int step){ 275 | DATA_TYPE *w0 = x; 276 | DATA_TYPE *w1 = x+(n>>1); 277 | LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; 278 | LOOKUP_T *Ttop = T+1024; 279 | REG_TYPE s0, s1, s2, s3; 280 | 281 | do{ 282 | w1 -= 2; 283 | 284 | s0 = w0[0] + w1[0]; 285 | s1 = w1[1] - w0[1]; 286 | s2 = MULT32(s0, T[1]) + MULT32(s1, T[0]); 287 | s3 = MULT32(s1, T[1]) - MULT32(s0, T[0]); 288 | T+=step; 289 | 290 | s0 = (w0[1] + w1[1])>>1; 291 | s1 = (w0[0] - w1[0])>>1; 292 | w0[0] = s0 + s2; 293 | w0[1] = s1 + s3; 294 | w1[0] = s0 - s2; 295 | w1[1] = s3 - s1; 296 | 297 | w0 += 2; 298 | }while(T>1; 309 | s1 = (w0[0] - w1[0])>>1; 310 | w0[0] = s0 + s2; 311 | w0[1] = s1 + s3; 312 | w1[0] = s0 - s2; 313 | w1[1] = s3 - s1; 314 | 315 | w0 += 2; 316 | }while(w0>1); 324 | 325 | switch(step) { 326 | #if defined(ONLY_C) 327 | default: 328 | T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; 329 | do{ 330 | REG_TYPE s0 = x[0]; 331 | REG_TYPE s1 = -x[1]; 332 | XPROD31( s0, s1, T[0], T[1], x, x+1); T+=step; 333 | x +=2; 334 | }while(x>1; 345 | t1 = (*T++)>>1; 346 | do{ 347 | s0 = x[0]; 348 | s1 = -x[1]; 349 | t0 += (v0 = (*V++)>>1); 350 | t1 += (v1 = (*V++)>>1); 351 | XPROD31( s0, s1, t0, t1, x, x+1 ); 352 | 353 | s0 = x[2]; 354 | s1 = -x[3]; 355 | v0 += (t0 = (*T++)>>1); 356 | v1 += (t1 = (*T++)>>1); 357 | XPROD31( s0, s1, v0, v1, x+2, x+3 ); 358 | 359 | x += 4; 360 | }while(x>2); 378 | t1 += (q1 = (v1-t1)>>2); 379 | s0 = x[0]; 380 | s1 = -x[1]; 381 | XPROD31( s0, s1, t0, t1, x, x+1 ); 382 | t0 = v0-q0; 383 | t1 = v1-q1; 384 | s0 = x[2]; 385 | s1 = -x[3]; 386 | XPROD31( s0, s1, t0, t1, x+2, x+3 ); 387 | 388 | t0 = *T++; 389 | t1 = *T++; 390 | v0 += (q0 = (t0-v0)>>2); 391 | v1 += (q1 = (t1-v1)>>2); 392 | s0 = x[4]; 393 | s1 = -x[5]; 394 | XPROD31( s0, s1, v0, v1, x+4, x+5 ); 395 | v0 = t0-q0; 396 | v1 = t1-q1; 397 | s0 = x[6]; 398 | s1 = -x[7]; 399 | XPROD31( s0, s1, v0, v1, x+5, x+6 ); 400 | 401 | x+=8; 402 | }while(x>1,step); 423 | mdct_butterflies(in,n>>1,shift); 424 | mdct_bitreverse(in,n,shift); 425 | mdct_step7(in,n,step); 426 | mdct_step8(in,n,step>>2); 427 | #else 428 | step = mdct_backwardARM(n, in); 429 | if (step <= 1) 430 | mdct_step8(in,n,step); 431 | #endif 432 | } 433 | 434 | #if defined(ONLY_C) 435 | void mdct_shift_right(int n, DATA_TYPE *in, DATA_TYPE *right){ 436 | int i; 437 | n>>=2; 438 | in+=1; 439 | 440 | for(i=0;i>1 : n0>>1); 480 | DATA_TYPE *r=right+(lW ? n1>>2 : n0>>2); 481 | DATA_TYPE *post; 482 | LOOKUP_T *wR=(W && lW ? w1+(n1>>1) : w0+(n0>>1)); 483 | LOOKUP_T *wL=(W && lW ? w1 : w0 ); 484 | 485 | int preLap=(lW && !W ? (n1>>2)-(n0>>2) : 0 ); 486 | int halfLap=(lW && W ? (n1>>2) : (n0>>2) ); 487 | int postLap=(!lW && W ? (n1>>2)-(n0>>2) : 0 ); 488 | int n,off; 489 | 490 | /* preceeding direct-copy lapping from previous frame, if any */ 491 | if(preLap){ 492 | n = (endpost){ 500 | *out = CLIP_TO_15((*--r)>>9); 501 | out+=step; 502 | } 503 | #else 504 | out = mdct_unroll_prelap(out,post,r,step); 505 | n -= off; 506 | if (n < 0) 507 | n = 0; 508 | r -= n; 509 | #endif 510 | } 511 | 512 | /* cross-lap; two halves due to wrap-around */ 513 | n = (endpost){ 524 | l-=2; 525 | *out = CLIP_TO_15((MULT31(*--r,*--wR) + MULT31(*l,*wL++))>>9); 526 | out+=step; 527 | } 528 | #else 529 | out = mdct_unroll_part2(out, post, l, r, step, wL, wR); 530 | n -= off; 531 | if (n < 0) 532 | n = 0; 533 | l -= 2*n; 534 | r -= n; 535 | wR -= n; 536 | wL += n; 537 | #endif 538 | 539 | n = (end>9); 551 | out+=step; 552 | l+=2; 553 | } 554 | #else 555 | out = mdct_unroll_part3(out, post, l, r, step, wL, wR); 556 | n -= off; 557 | if (n < 0) 558 | n = 0; 559 | l += 2*n; 560 | r += n; 561 | wR -= n; 562 | wL += n; 563 | #endif 564 | 565 | /* preceeding direct-copy lapping from previous frame, if any */ 566 | if(postLap){ 567 | n = (end>9); 574 | out+=step; 575 | l+=2; 576 | } 577 | #else 578 | out = mdct_unroll_postlap(out,post,l,step); 579 | #endif 580 | } 581 | } 582 | 583 | --------------------------------------------------------------------------------