[
  {
    "path": ".gitignore",
    "content": "pcm/\nbuild/\noutput_pcm/\n.vscode/\nvad-demo*"
  },
  {
    "path": "CMakeLists.txt",
    "content": "cmake_minimum_required(VERSION 2.8)\nset(CMAKE_VERBOSE_MAKEFILE on)\nproject(vad-demo)\nset(CMAKE_BUILD_TYPE DEBUG)\n\nset(CMAKE_CXX_STANDARD 11)\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11\")\n#set(CMAKE_C_STANDARD 99)\nfile(GLOB SRC_FILES src/*.c src/*.h thirdparty/webrtc/common_audio/*/*.c thirdparty/webrtc/rtc_base/*.c*)\ninclude_directories(thirdparty/webrtc) #thirdparty/include/webrtc\nadd_executable(vad-demo ${SRC_FILES})\ntarget_link_libraries(vad-demo pthread)"
  },
  {
    "path": "README.md",
    "content": "# speech-vad-demo\n\n\n## 简介\n### 简介\n\n项目地址： https://github.com/Baidu-AIP/speech-vad-demo\n\n集成 [webrtc](https://webrtc.org/) 开源项目，vad模块，具体算法*GMM*(Gaussian Mixture Model)。\n\n由于百度rest api接口有60s的音频时长限制，使用此demo可以粗略地按照静音切分音频。\n\n### 原理\n\n一个FRAME时长默认10s，通过webrtc的vad计算这个FRAME是否是活动（ACTIVE: 有声音， INACTIVE，静音）。\n\n这样可以获得音频的所有FRAME的活动值（ACTIVE或者INACTIVE）。从而在静音（INACTIVE）的音频段上的切分音频。\n\n### 运行环境\n\n- g++ 4.8以上,\n- cmake 2.8 及 make 3.8 编译需要，可以跳过或者尝试使用低版本  \n- 任意操作系统\n\n如果没有g++ 4.8的版本，centos可以参考“Linux C++ SDK”的文档，进行g++ 4.8的安装。\n\n由于webrtc项目vad模块依赖于rtc_base模块 进行运行时的参数检查，因此需要可以编译rtc_base的。\n如果您无法升级到g++ 4.8 或者是只能编译C项目，可以自行修改源代码，删除rtc_bas目录，及其它文件对rtc_base中宏的依赖,，剩余文件均为C代码。去除后请详细测试。\n\n## 运行及结果\n\n### 运行命令\n\nLinux：\n\n```bash\n# 确认g++ 和cmake 版本\nsh build_and_run.sh\n\n# 或\ncmake . && make\n```\n\nWindows：\n\nWindows 安装 cygwin，及cygwin 中 下载cmake make gcc g++等编译软件\n\n```bat\nsh build_and_run.sh\n\n# 或\ncmake . && make\n```\n\n### 结果\n如果不修改代码的话，结果保存在 output_pcm 内。\n文件名如下\n```\n16k_1.pcm_0-12989_A.pcm         // 第0-12989毫秒的音频， \n16k_1.pcm_33730-47389_A.pcm     // 第33730-47389毫秒的音频\n16k_1.pcm_0-4049_A.pcm         // A 表示此段有声音，不是完全的静音\n···\n16k_1.pcm_114060-121689_I.pcm  // I 表示此段都是静音\n```\n\n## 参数设置\n\n### common.h\n```c\n// MULTI = 1 2 3 webrtc vad可以设置分别为以10ms 20ms 30ms作为包\n#define MULTI 1\n\n// VAD 模式 Aggressiveness mode (0, 1, 2, or 3). 数值越大，判断越是粗略，连着的静音或者响声增多\n#define WEBRTC_VAD_MODE 3\n\n// 有声音的音频段，xxx 毫秒后，认为该音频段结束，不能为0\n#define FILE_CUT_SILENCE_AFTER_ACTIVE_MS 500\n\n// 静音的音频段，切分xxx毫秒给之后有声音的音频段\n#define FILE_CUT_SILENCE_BEFORE_ACTIVE_MS 300\n\n// 最小的音频切分长度，即每个切分后音频文件不少于这个时长，最后一个除外\n#define FILE_CUT_MIN_MS  (10 * 1000)\n\n// 最大的音频切分长度，即每个切分后音频文件不多于这个时长\n#define FILE_CUT_MAX_MS  (60 * 1000)\n\n/** 上述示例中音频文件尽可能依次满足如下条件\n1. 最短10s，最长 60s。 \n2. 每个音频文件的最后的静音500ms， \n2. 每个音频文件的开始的静300ms。\n */\n```\n\n### 切割逻辑修改\n\ndemo因为考虑到流式，采用了尽快切割的方法。如果您对这个切割算法不满意的话，可以对照periods_print的结果, 自行修改file_cut.c内的代码逻辑\n\n```c\n// [5150, 5220) [5230, 6380) [6520, 6970) [7000, 8040) [8080, 8670)\n// 表示 [5150, 5220) 等区间内是有声音的，其它区间均为静音，\n// 如果需要切割的话，应该在静音区间选择合适的位置切割\n```"
  },
  {
    "path": "build_and_run.sh",
    "content": "#!/usr/bin/env bash\nset -uex\ncheck_version(){\n    CMD=$1\n    OPT=$2\n    VERSION=$3\n\n    #$CMD $OPT\n    RES=$($CMD $OPT |head -1)\n    echo $RES\n   \n}\n\ncheck_version \"gcc\" \"--version\" \"4.8.2\"\ncheck_version \"cmake\" \"--version\" \"2.8\"\nsleep 2;\necho \"\"\nmkdir -p build && \\\nmkdir -p output_pcm && \\\nrm -rf  output_pcm/* build/* && \\\ncd build && \\\ncmake .. && \\\nmake -j4 && \\\ncp vad-demo .. && cd .. && \\\necho \"build success wait 3s to run\" && \\\nsleep 3 && \\\n./vad-demo\n \n"
  },
  {
    "path": "src/common.h",
    "content": "//\n// Created by fu on 3/7/18.\n//\n\n#ifndef VAD_DEMO_COMMON_H\n#define VAD_DEMO_COMMON_H\n\n#include <stdint.h>\n\n\n\n// MULTI = 1 2 3 webrtc vad可以设置分别为以10ms 20ms 30ms作为包\n#define MULTI 1\n\n// VAD 模式 Aggressiveness mode (0, 1, 2, or 3). 数值越大，判断越是粗略，连着的静音或者响声增多\n#define WEBRTC_VAD_MODE 3\n\n//  有声音的音频段，xxx 毫秒后，认为该音频段结束，不能为0\n#define FILE_CUT_SILENCE_AFTER_ACTIVE_MS 500\n\n// 静音的音频段，切分xxx毫秒给之后有声音的音频段\n#define FILE_CUT_SILENCE_BEFORE_ACTIVE_MS 300\n\n// 最小的音频切分长度，即每个切分后音频文件不少于这个时长，最后一个除外\n#define FILE_CUT_MIN_MS  (10 * 1000)\n\n// 最大的音频切分长度，即每个切分后音频文件不多于这个时长\n#define FILE_CUT_MAX_MS  (60 * 1000)\n\n//16000 采样率固定\n#define SAMPLE_RATE 16000\n\n//  用于period_format.h\n#define PERIODS_SIZE_INITIED 100\n\n#define FRAME_SIZE (16 * MULTI * 10 )\n\n#define CAL_TIME_BY_FRAME(frame) (MULTI * 10 * frame)\n\n#define CAL_FRAME_BY_TIME(time) (time / (MULTI * 10))\n\n/*`\nuint64_t inline CAL_TIME_BY_FRAME(int frame){\n    return MULTI * frame * 10;\n};\n\nint inline CAL_FRAME_BY_TIME(uint64_t time){\n    return time / (MULTI * 10);\n};\n*/\n#endif //VAD_DEMO_COMMON_H\n"
  },
  {
    "path": "src/file_cut.c",
    "content": "//\n// Created by fu on 3/7/18.\n//\n\n#include <stdlib.h>\n#include \"file_cut.h\"\n\n// static size_t file_total = 0;\n\nstatic inline int cut_write_file(struct cut_info *cut, int frames) {\n    int size = frames * FRAME_SIZE ;\n    uint16_t buffer[size];\n    int readed = fread(buffer, sizeof(uint16_t), size, cut->fp);\n    if (readed > 0) {\n        FILE *res_file = fopen(cut->result_filename, \"wb+\");\n        if (res_file == NULL) {\n            fprintf(stderr, \"file open failed, %s\\n\", cut->result_filename);\n            return 3;\n        }\n        int written = fwrite(buffer, sizeof(uint16_t), readed, res_file);\n        fclose(res_file);\n        if (written != readed) {\n            fprintf(stderr, \"written is %d, readed is %d\\n\", written, readed);\n            return 2;\n        }\n        // file_total += written;\n        // printf(\"file write success, %s, written %d\\n\", cut->result_filename, written);\n        return 0;\n\n    } else {\n        return 1;\n    }\n\n}\n\nstatic inline int cut_frame(struct cut_info *cut, int last_frame, int force) {\n    int frames = last_frame - cut->cut_begin_frame;\n    if (force || (frames >= CAL_FRAME_BY_TIME(FILE_CUT_MIN_MS))) {\n        if (last_frame == 109) {\n            printf(\"%d\", 109);\n        }\n        //printf(\"cut file at frame: %d\\n\", last_frame);\n        snprintf(cut->result_filename, sizeof(cut->result_filename),\n                 \"%s/%s_%ld-%ld_%s.pcm\", cut->output_file_dir,\n                 cut->output_filename_prefix, CAL_TIME_BY_FRAME(cut->cut_begin_frame),\n                 CAL_TIME_BY_FRAME(last_frame) - 1, cut->is_contain_active ? \"A\" : \"I\");\n        cut_write_file(cut, frames);\n        cut->is_pervious_active = 0;\n        cut->is_contain_active = 0;\n        cut->cut_begin_frame = last_frame;\n        return 0;\n    } else {\n        return 1;\n    }\n}\n\nstatic inline int add_continued(struct cut_info *cut, int is_active) {\n    if (!is_active && cut->is_contain_active) {\n        // 有响声，之后连续静音\n        int diff = cut->previous_along_frames - CAL_FRAME_BY_TIME(FILE_CUT_SILENCE_AFTER_ACTIVE_MS);\n        if (diff >= 0) {\n            int res = cut_frame(cut, cut->current_frame, 0);\n            if (res == 0) {\n                int frame = -1 * (cut->current_frame);\n                cut->previous_along_frames = 1;\n                return frame;\n            }\n        }\n    }\n    cut->previous_along_frames++;\n    return 0;\n}\n\n\nstatic inline int add_changed(struct cut_info *cut, int is_active) {\n    int frame = 0;\n    if (is_active) {\n        // 连续静音，之后遇到响声\n        if (cut->previous_along_frames > CAL_FRAME_BY_TIME(FILE_CUT_SILENCE_BEFORE_ACTIVE_MS)) {\n            int c_frames =\n                    cut->current_frame - CAL_FRAME_BY_TIME(FILE_CUT_SILENCE_BEFORE_ACTIVE_MS);\n            int res = cut_frame(cut, c_frames, 0);\n            if (res == 0) {\n                frame = -1 * (c_frames);\n            }\n            // cut->previous_along_frames = FILE_CUT_SILENCE_AFTER_ACTIVE_MS;\n        }\n    }\n\n    cut->previous_along_frames = 1;\n    return frame;\n}\n\nstruct cut_info *cut_info_create(FILE *fp) {\n    struct cut_info *cut = calloc(1, sizeof(struct cut_info));\n    cut->fp = fp;\n    return cut;\n}\n\n\nint cut_add_vad_activity(struct cut_info *cut, int is_active, int is_last) {\n    int res;\n    if (is_last ||\n        (cut->current_frame - cut->cut_begin_frame == CAL_FRAME_BY_TIME(FILE_CUT_MAX_MS))) {\n        cut_frame(cut, cut->current_frame, is_last);\n        res = -1 * cut->current_frame;\n    } else if (cut->is_pervious_active == is_active) {\n        res = add_continued(cut, is_active);\n    } else {\n        res = add_changed(cut, is_active);\n        if (is_active) {\n            cut->is_contain_active = 1;\n        }\n    }\n    cut->is_pervious_active = is_active;\n    cut->current_frame++;\n    return res;\n}\n\nvoid cut_info_free(struct cut_info *cut) {\n    free(cut);\n}\n\n\nvoid cut_info_print(struct cut_info *cut) {\n    printf(\"%s, %s， %d, frame %d\\n\", cut->is_pervious_active ? \"PA\" : \"PI\",\n           cut->is_contain_active ? \"CA\" : \"CI\", cut->previous_along_frames, cut->current_frame);\n}\n"
  },
  {
    "path": "src/file_cut.h",
    "content": "//\n// Created by fu on 3/7/18.\n//\n\n#ifndef VAD_DEMO_FILE_CUT_H\n#define VAD_DEMO_FILE_CUT_H\n\n#include <stdio.h>\n#include \"common.h\"\n#include \"stdint.h\"\n\nstruct cut_info {\n    int is_pervious_active;\n    int is_contain_active;\n    int previous_along_frames;\n    FILE *fp;\n    int current_frame;\n    int cut_begin_frame;\n    char result_filename[200];\n    char output_file_dir[100];\n    char output_filename_prefix[100];\n\n};\n\nstruct cut_info *cut_info_create(FILE *fp);\n\nint cut_add_vad_activity(struct cut_info *cut, int is_active, int is_last);\n\nvoid cut_info_free(struct cut_info *cut);\n\nvoid cut_info_print(struct cut_info *cut);\n\n#endif //VAD_DEMO_FILE_CUT_H\n/**\n\n    struct cut_info *cut = cut_create_info(NULL);\n    int acts[] = {0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0};\n    int len = sizeof(acts) / sizeof(int);\n    int is_cuts[len];\n    printf(\" acts length: %d\\n\", len);\n\n    int j, k;\n    for (k = 0; k < len; k++) {\n        printf(\"%d \", acts[k]);\n        is_cuts[k] = 0;\n    }\n    printf(\"\\n\");\n    for (k = 0; k < len; k++) {\n\n        printf(\"\\n\");\n        int res = cut_add_vad_activity(cut, acts[k], k == len - 1);\n        cut_info_print(cut);\n        if (res < 0) {\n            is_cuts[-1 * res] = 1;\n        }\n        for (j = 0; j <= k; j++) {\n            if (is_cuts[j]) {\n                printf(\"| \");\n            }\n            printf(\"%d \", acts[j]);\n\n        }\n    }\n    printf(\"\\n\");\n    for (j = 0; j <= k; j++) {\n        if (is_cuts[j]) {\n            printf(\"| \");\n        }\n        printf(\"%d \", acts[j]);\n\n    }\n    printf(\"\\n\");\n    printf(\"PROGRAM FINISH\\n\");\n **/"
  },
  {
    "path": "src/main.c",
    "content": "#include <stdio.h>\n#include <common_audio/vad/include/webrtc_vad.h>\n#include <stdlib.h>\n#include \"simple_vad.h\"\n#include \"period_format.h\"\n#include \"file_cut.h\"\n// 16000 采样率 10ms，  大小 = 160 * 16bits/8 = 320字节 ,\n\nint run(FILE *fp, simple_vad *vad, struct cut_info *cut);\n\nint add_period_activity(struct periods *per, int is_active, int is_last);\n\n//int add_cut_file_activity(struct cut_info *cut, int is_active, int is_last);\n\nint main() {\n    const char filename[] = \"pcm/16k_1.pcm\"; // 读取的文件\n    const char output_filename_prefix[] = \"16k_1.pcm\"; // 保存的文件名\n    const char output_dir[] = \"output_pcm\"; // 保存的目录\n    FILE *fp = fopen(filename, \"rb\");\n    if (fp == NULL) {\n        fprintf(stderr, \"%s does not exist\\n\", filename);\n        return 3;\n    }\n    simple_vad *vad = simple_vad_create();\n    if (vad == NULL) {\n        return 4;\n    }\n    FILE *fp2 = fopen(filename, \"rb\");\n    struct cut_info *cut = cut_info_create(fp2);\n    snprintf(cut->output_filename_prefix, sizeof(cut->output_filename_prefix), \"%s\",\n             output_filename_prefix);\n    snprintf(cut->output_file_dir, sizeof(cut->output_file_dir), \"%s\",\n             output_dir);\n    int res = run(fp, vad, cut);\n\n    fclose(fp);\n    fclose(fp2);\n    simple_vad_free(vad);\n    cut_info_free(cut);\n    printf(\"PROGRAM FINISH\\n\");\n    return res;\n}\n\nint run(FILE *fp, simple_vad *vad, struct cut_info *cut) {\n\n    int16_t data[FRAME_SIZE];\n    int res = 0;\n    struct periods *per = periods_create();\n\n    while (res == 0) {\n        res = read_int16_bytes(fp, data);\n        if (res <= 1) {\n            int is_last = (res == 1);\n            int is_active = process_vad(vad, data);\n            add_period_activity(per, is_active, is_last);\n            int vad_file_res = cut_add_vad_activity(cut, is_active, is_last);\n            if (vad_file_res < 0) {\n                printf(\"file write success %s\\n\", cut->result_filename);\n            }\n        } else if (ferror(fp)) {\n            printf(\"read failed  ferror result  : %d\\n\", ferror(fp));\n        }\n\n    }\n    periods_free(per);\n\n    if (res != 1) {\n        fprintf(stderr, \"read file error %d\\n\", res);\n        return res;\n    }\n    return 0;\n}\n\n\nint add_period_activity(struct periods *per, int is_active, int is_last) {\n    static int old_is_active = 0;\n    static int count = 0;\n    int res_add = period_add_vad_activity(per, is_active, is_last);\n    if (res_add != 0) {\n        return res_add;\n    }\n    if (is_active != old_is_active) {\n        // printf(\"%s,%d \\n\", old_is_active ? \"A\" : \"I\", count);\n        // I,1  表示之前的1个FRAME是 INACTIVE的；\n        // I,1 A,10 表示之前的1个FRAME是 INACTIVE的；第2-10个FRAME是ACTIVE的\n        // periods_print(per);\n        old_is_active = is_active;\n    }\n    count += 1;\n    if (is_last) {\n        periods_print(per);\n        printf(\"total frames %d\\n\", count);\n    }\n}"
  },
  {
    "path": "src/period_format.c",
    "content": "//\n// Created by fu on 3/6/18.\n//\n\n#ifdef __APPLE__\n#include <sys/malloc.h>\n#else\n#include <malloc.h>\n#endif\n\n#include \"common.h\"\n#include \"period_format.h\"\n\nstatic int add_period_start(struct periods *per) {\n    per->size++;\n    if (per->size > per->size_allocated) {\n        size_t new_size = per->size_allocated * 2 * sizeof(uint64_t);\n        per->period_start = realloc(per->period_start, new_size);\n        if (per->period_start == NULL) {\n            fprintf(stderr, \"per->period_start allocated failed %ld\", new_size);\n            return 1;\n        }\n        per->period_end = realloc(per->period_end, new_size);\n        if (per->period_end == NULL) {\n            fprintf(stderr, \"per->period_end allocated failed %ld\", new_size);\n            return 2;\n        }\n        per->size_allocated *= 2;\n    }\n    uint64_t start_time = CAL_TIME_BY_FRAME(per->current_frame);\n    per->period_start[per->size - 1] = start_time;\n    per->is_end_filled = 0;\n    return 0;\n}\n\nstatic void add_period_end(struct periods *per) {\n    size_t end_time = CAL_TIME_BY_FRAME(per->current_frame);\n    per->period_end[per->size - 1] = end_time;\n    per->is_end_filled = 1;\n}\n\nstruct periods *periods_create() {\n    struct periods *per = calloc(1, sizeof(struct periods));\n    if (per == NULL) {\n        fprintf(stderr, \"per alloc failed\");\n        return NULL;\n    }\n    per->period_start = calloc(PERIODS_SIZE_INITIED, sizeof(uint64_t));\n    if (per->period_start == NULL) {\n        fprintf(stderr, \"per->period_start alloc failed\");\n    } else {\n        per->period_end = calloc(PERIODS_SIZE_INITIED, sizeof(uint64_t));\n        if (per->period_end == NULL) {\n            fprintf(stderr, \"per->period_start alloc failed\");\n        } else {\n            per->size_allocated = PERIODS_SIZE_INITIED;\n            return per;\n        }\n    }\n    return NULL;\n}\n\n\nvoid periods_print(struct periods *per) {\n    int size = per->size;\n    int is_ended_fill = per->is_end_filled;\n    printf(\"PERIODS SIZE :%d, is_end_filled:%s \", size, is_ended_fill ? \"true\" : \"false\");\n\n    int i;\n    for (i = 0; i < size; i++) {\n        if ((i != size - 1) || is_ended_fill) {\n            printf(\"[%ld, %ld] \", per->period_start[i], per->period_end[i]);\n        } else {\n            printf(\"[%ld, N]\", per->period_start[size]);\n        }\n    }\n\n    // printf(\"size %ld allocated %ld\", per->size, per->size_allocated);\n    printf(\"\\n\");\n}\n\nint period_add_vad_activity(struct periods *per, int is_active, int is_last) {\n    if (!per->is_pervious_active && is_active) {\n        int res = add_period_start(per);\n        if (res != 0) {\n            return res;\n        }\n        per->is_pervious_active = is_active;\n    } else if (per->is_pervious_active && (!is_active || is_last)) {\n        add_period_end(per);\n        per->is_pervious_active = is_active;\n    }\n\n    per->current_frame++;\n    return 0;\n}\n\nvoid periods_free(struct periods *per) {\n    free(per->period_start);\n    free(per->period_end);\n    free(per);\n}"
  },
  {
    "path": "src/period_format.h",
    "content": "//\n// 收集和打印非静音的声音段\n// Created by fu on 3/6/18.\n//\n\n#ifndef VAD_DEMO_PERIOD_FORMAT_H\n#define VAD_DEMO_PERIOD_FORMAT_H\n\n#include \"simple_vad.h\"\n\nstruct periods {\n    int is_pervious_active;\n    size_t current_frame;\n    uint64_t *period_start;\n    uint64_t *period_end;\n    int size;\n    size_t size_allocated;\n    int is_end_filled;\n\n};\n\nstruct periods *periods_create();\n/**\n * @brief\n * @param per\n * @param is_active 是否是有声音的FRAME\n * @param is_last 是否是最后一个FRAME\n * @return\n */\nint period_add_vad_activity(struct periods *per, int is_active, int is_last);\n\nvoid periods_free(struct periods *per);\n\nvoid periods_print(struct periods *per);\n\n/*\n * 测试例子\n * struct periods *per=periods_create();\n    period_add_vad_activity(per,1,0);\n    period_add_vad_activity(per,1,0);\n    periods_print(per);\n    period_add_vad_activity(per,0,0);\n    periods_print(per);\n    period_add_vad_activity(per,1,0);\n    periods_print(per);\n    period_add_vad_activity(per,0,0);\n    period_add_vad_activity(per,0,0);\n    period_add_vad_activity(per,0,0);\n    periods_print(per);\n    period_add_vad_activity(per,1,0);\n    period_add_vad_activity(per,1,1);\n    periods_print(per);\n    periods_free(per);\n */\n\n\n#endif //VAD_DEMO_PERIOD_FORMAT_H\n"
  },
  {
    "path": "src/simple_vad.c",
    "content": "//\n// Created by fu on 3/6/18.\n//\n\n#include \"simple_vad.h\"\n#include <string.h>\n\nstatic int check_end_file(FILE *fp) {\n    if (feof(fp)) {\n        return 0;\n    }\n    return ferror(fp);\n}\n\nint read_int16_bytes(FILE *fp, int16_t *output) {\n    if (feof(fp)) {\n        return 1;\n    }\n\n    size_t readed = fread(output, sizeof(int16_t), FRAME_SIZE, fp);\n    if (readed <= 0) {\n        int res = check_end_file(fp);\n        return (res == 0) ? 1 : 1000 + res;\n    }\n    if (readed < FRAME_SIZE) {\n        memset(output + readed, 0, (FRAME_SIZE - readed) * sizeof(int16_t));\n        // printf(\"only %ld bits, will refill to %ld\\n\", readed, length);\n    }\n    return 0;\n\n}\n\nsimple_vad *simple_vad_create() {\n    VadInst *inst = WebRtcVad_Create();\n    int res = WebRtcVad_Init(inst);\n    if (res != 0) {\n        fprintf(stderr, \"WebRtcVad_Init failed %d\", res);\n        return NULL;\n    }\n    res = WebRtcVad_set_mode(inst, WEBRTC_VAD_MODE);\n    if (res != 0) {\n        fprintf(stderr, \"WebRtcVad_set_mode failed %d\", res);\n        WebRtcVad_Free(inst);\n        return NULL;\n    }\n    return inst;\n}\n\nint process_vad(VadInst *inst, int16_t *data) {\n    int res = WebRtcVad_Process(inst, SAMPLE_RATE, data, FRAME_SIZE);\n    return res;\n}\n\nvoid simple_vad_free(simple_vad *inst) {\n    WebRtcVad_Free(inst);\n}\n"
  },
  {
    "path": "src/simple_vad.h",
    "content": "//\n// 包装webrtc 的gmm vad算法\n//\n// Created by fu on 3/6/18.\n//\n\n#ifndef VAD_DEMO_FILE_READ_H\n#define VAD_DEMO_FILE_READ_H\n\n#include <stdio.h>\n#include <stdint.h>\n#include <common_audio/vad/include/webrtc_vad.h>\n#include \"common.h\"\n\n// 一个FRAME代表的时长。MULTI=1： 10ms；MULTI=2： 20ms；MULTI=3： 30ms；\n// FRAME_SIZE = 160 * MULTI = SAMPLE_RATE  /1000 * MULTI ,\n\n\ntypedef VadInst simple_vad;\n\n/**\n * @brief 读取int16_t的数组\n * @param fp\n * @param output\n * @return 0 正常 1 文件结束 , 1000+ferror : 文件错误\n */\nint read_int16_bytes(FILE *fp, int16_t *output);\n\n/**\n * @brief\n * @return NULL 创建失败\n */\nsimple_vad *simple_vad_create();\n\n/**\n * @brief\n * @param inst\n * @param data 例如read_int16_bytes读取的数据\n * @return\n */\nint process_vad(VadInst *inst, int16_t *data);\n\n/**\n * @brief\n * @param inst\n */\nvoid simple_vad_free(simple_vad *inst);\n\n#endif //VAD_DEMO_FILE_READ_H\n"
  },
  {
    "path": "thirdparty/webrtc/BUILD.gn",
    "content": "# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n#\n# Use of this source code is governed by a BSD-style license\n# that can be found in the LICENSE file in the root of the source\n# tree. An additional intellectual property rights grant can be found\n# in the file PATENTS.  All contributing project authors may\n# be found in the AUTHORS file in the root of the source tree.\n\n# This is the root build file for GN. GN will start processing by loading this\n# file, and recursively load all dependencies until all dependencies are either\n# resolved or known not to exist (which will cause the build to fail). So if\n# you add a new build file, there must be some path of dependencies from this\n# file to your new one or GN won't know about it.\n\nimport(\"//build/config/linux/pkg_config.gni\")\nimport(\"//build/config/sanitizers/sanitizers.gni\")\nimport(\"webrtc.gni\")\nif (!build_with_mozilla) {\n  import(\"//third_party/protobuf/proto_library.gni\")\n}\nif (is_android) {\n  import(\"//build/config/android/config.gni\")\n  import(\"//build/config/android/rules.gni\")\n}\n\nif (!build_with_chromium) {\n  # This target should (transitively) cause everything to be built; if you run\n  # 'ninja default' and then 'ninja all', the second build should do no work.\n  group(\"default\") {\n    testonly = true\n    deps = [\n      \":webrtc\",\n    ]\n    if (rtc_build_examples) {\n      deps += [ \"examples\" ]\n    }\n    if (rtc_build_tools) {\n      deps += [ \"rtc_tools\" ]\n    }\n    if (rtc_include_tests) {\n      deps += [\n        \":rtc_unittests\",\n        \":video_engine_tests\",\n        \":webrtc_nonparallel_tests\",\n        \":webrtc_perf_tests\",\n        \"common_audio:common_audio_unittests\",\n        \"common_video:common_video_unittests\",\n        \"media:rtc_media_unittests\",\n        \"modules:modules_tests\",\n        \"modules:modules_unittests\",\n        \"modules/audio_coding:audio_coding_tests\",\n        \"modules/audio_processing:audio_processing_tests\",\n        \"modules/remote_bitrate_estimator:bwe_simulations_tests\",\n        \"modules/rtp_rtcp:test_packet_masks_metrics\",\n        \"modules/video_capture:video_capture_internal_impl\",\n        \"ortc:ortc_unittests\",\n        \"pc:peerconnection_unittests\",\n        \"pc:rtc_pc_unittests\",\n        \"rtc_base:rtc_base_tests_utils\",\n        \"stats:rtc_stats_unittests\",\n        \"system_wrappers:system_wrappers_unittests\",\n        \"test\",\n        \"video:screenshare_loopback\",\n        \"video:sv_loopback\",\n        \"video:video_loopback\",\n      ]\n      if (is_android) {\n        deps += [\n          \":android_junit_tests\",\n          \"sdk/android:libjingle_peerconnection_android_unittest\",\n        ]\n      } else {\n        deps += [ \"modules/video_capture:video_capture_tests\" ]\n      }\n      if (rtc_enable_protobuf) {\n        deps += [\n          \"audio:low_bandwidth_audio_test\",\n          \"logging:rtc_event_log2rtp_dump\",\n        ]\n      }\n    }\n  }\n}\n\n# Contains the defines and includes in common.gypi that are duplicated both as\n# target_defaults and direct_dependent_settings.\nconfig(\"common_inherited_config\") {\n  defines = []\n  cflags = []\n  ldflags = []\n  if (build_with_mozilla) {\n    defines += [ \"WEBRTC_MOZILLA_BUILD\" ]\n  }\n\n  # Some tests need to declare their own trace event handlers. If this define is\n  # not set, the first time TRACE_EVENT_* is called it will store the return\n  # value for the current_frame handler in an static variable, so that subsequent\n  # changes to the handler for that TRACE_EVENT_* will be ignored.\n  # So when tests are included, we set this define, making it possible to use\n  # different event handlers in different tests.\n  if (rtc_include_tests) {\n    defines += [ \"WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1\" ]\n  } else {\n    defines += [ \"WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0\" ]\n  }\n  if (build_with_chromium) {\n    defines += [\n      # TODO(kjellander): Cleanup unused ones and move defines closer to\n      # the source when webrtc:4256 is completed.\n      \"GTEST_RELATIVE_PATH\",\n      \"WEBRTC_CHROMIUM_BUILD\",\n    ]\n    include_dirs = [\n      # The overrides must be included first as that is the mechanism for\n      # selecting the override headers in Chromium.\n      \"../webrtc_overrides\",\n\n      # Allow includes to be prefixed with webrtc/ in case it is not an\n      # immediate subdirectory of the top-level.\n      \".\",\n    ]\n  }\n  if (is_posix) {\n    defines += [ \"WEBRTC_POSIX\" ]\n  }\n  if (is_ios) {\n    defines += [\n      \"WEBRTC_MAC\",\n      \"WEBRTC_IOS\",\n    ]\n  }\n  if (is_linux) {\n    defines += [ \"WEBRTC_LINUX\" ]\n  }\n  if (is_mac) {\n    defines += [ \"WEBRTC_MAC\" ]\n  }\n  if (is_fuchsia) {\n    defines += [ \"WEBRTC_FUCHSIA\" ]\n  }\n  if (is_win) {\n    defines += [\n      \"WEBRTC_WIN\",\n      \"_CRT_SECURE_NO_WARNINGS\",  # Suppress warnings about _vsnprinf\n    ]\n  }\n  if (is_android) {\n    defines += [\n      \"WEBRTC_LINUX\",\n      \"WEBRTC_ANDROID\",\n    ]\n\n    if (build_with_mozilla) {\n      defines += [ \"WEBRTC_ANDROID_OPENSLES\" ]\n    }\n  }\n  if (is_chromeos) {\n    defines += [ \"CHROMEOS\" ]\n  }\n\n  if (rtc_sanitize_coverage != \"\") {\n    assert(is_clang, \"sanitizer coverage requires clang\")\n    cflags += [ \"-fsanitize-coverage=${rtc_sanitize_coverage}\" ]\n    ldflags += [ \"-fsanitize-coverage=${rtc_sanitize_coverage}\" ]\n  }\n\n  if (is_ubsan) {\n    cflags += [ \"-fsanitize=float-cast-overflow\" ]\n  }\n}\n\nconfig(\"common_config\") {\n  cflags = []\n  cflags_cc = []\n  defines = []\n\n  if (rtc_enable_protobuf) {\n    defines += [ \"WEBRTC_ENABLE_PROTOBUF=1\" ]\n  } else {\n    defines += [ \"WEBRTC_ENABLE_PROTOBUF=0\" ]\n  }\n\n  if (rtc_include_internal_audio_device) {\n    defines += [ \"WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE\" ]\n  }\n\n  if (!rtc_libvpx_build_vp9) {\n    defines += [ \"RTC_DISABLE_VP9\" ]\n  }\n\n  if (rtc_enable_sctp) {\n    defines += [ \"HAVE_SCTP\" ]\n  }\n\n  if (rtc_enable_external_auth) {\n    defines += [ \"ENABLE_EXTERNAL_AUTH\" ]\n  }\n\n  if (rtc_use_builtin_sw_codecs) {\n    defines += [ \"USE_BUILTIN_SW_CODECS\" ]\n  }\n\n  if (build_with_chromium) {\n    defines += [\n      # NOTICE: Since common_inherited_config is used in public_configs for our\n      # targets, there's no point including the defines in that config here.\n      # TODO(kjellander): Cleanup unused ones and move defines closer to the\n      # source when webrtc:4256 is completed.\n      \"HAVE_WEBRTC_VIDEO\",\n      \"HAVE_WEBRTC_VOICE\",\n      \"LOGGING_INSIDE_WEBRTC\",\n    ]\n  } else {\n    if (is_posix) {\n      # Enable more warnings: -Wextra is currently disabled in Chromium.\n      cflags = [\n        \"-Wextra\",\n\n        # Repeat some flags that get overridden by -Wextra.\n        \"-Wno-unused-parameter\",\n        \"-Wno-missing-field-initializers\",\n        \"-Wno-strict-overflow\",\n      ]\n      cflags_cc = [\n        \"-Wnon-virtual-dtor\",\n\n        # This is enabled for clang; enable for gcc as well.\n        \"-Woverloaded-virtual\",\n      ]\n    }\n\n    if (is_clang) {\n      cflags += [\n        \"-Wc++11-narrowing\",\n        \"-Wimplicit-fallthrough\",\n        \"-Wthread-safety\",\n        \"-Winconsistent-missing-override\",\n        \"-Wundef\",\n      ]\n\n      # use_xcode_clang only refers to the iOS toolchain, host binaries use\n      # chromium's clang always.\n      if (!is_nacl &&\n          (!use_xcode_clang || current_toolchain == host_toolchain)) {\n        # Flags NaCl (Clang 3.7) and Xcode 7.3 (Clang clang-703.0.31) do not\n        # recognize.\n        cflags += [ \"-Wunused-lambda-capture\" ]\n      }\n    }\n  }\n\n  if (current_cpu == \"arm64\") {\n    defines += [ \"WEBRTC_ARCH_ARM64\" ]\n    defines += [ \"WEBRTC_HAS_NEON\" ]\n  }\n\n  if (current_cpu == \"arm\") {\n    defines += [ \"WEBRTC_ARCH_ARM\" ]\n    if (arm_version >= 7) {\n      defines += [ \"WEBRTC_ARCH_ARM_V7\" ]\n      if (arm_use_neon) {\n        defines += [ \"WEBRTC_HAS_NEON\" ]\n      }\n    }\n  }\n\n  if (current_cpu == \"mipsel\") {\n    defines += [ \"MIPS32_LE\" ]\n    if (mips_float_abi == \"hard\") {\n      defines += [ \"MIPS_FPU_LE\" ]\n    }\n    if (mips_arch_variant == \"r2\") {\n      defines += [ \"MIPS32_R2_LE\" ]\n    }\n    if (mips_dsp_rev == 1) {\n      defines += [ \"MIPS_DSP_R1_LE\" ]\n    } else if (mips_dsp_rev == 2) {\n      defines += [\n        \"MIPS_DSP_R1_LE\",\n        \"MIPS_DSP_R2_LE\",\n      ]\n    }\n  }\n\n  if (is_android && !is_clang) {\n    # The Android NDK doesn\"t provide optimized versions of these\n    # functions. Ensure they are disabled for all compilers.\n    cflags += [\n      \"-fno-builtin-cos\",\n      \"-fno-builtin-sin\",\n      \"-fno-builtin-cosf\",\n      \"-fno-builtin-sinf\",\n    ]\n  }\n\n  if (use_libfuzzer || use_drfuzz || use_afl) {\n    # Used in Chromium's overrides to disable logging\n    defines += [ \"WEBRTC_UNSAFE_FUZZER_MODE\" ]\n  }\n}\n\nconfig(\"common_objc\") {\n  libs = [ \"Foundation.framework\" ]\n}\n\nif (!build_with_chromium) {\n  # Target to build all the WebRTC production code.\n  rtc_static_library(\"webrtc\") {\n    # Only the root target should depend on this.\n    visibility = [ \"//:default\" ]\n\n    sources = []\n    complete_static_lib = true\n    defines = []\n\n    deps = [\n      \":webrtc_common\",\n      \"api:transport_api\",\n      \"audio\",\n      \"call\",\n      \"common_audio\",\n      \"common_video\",\n      \"media\",\n      \"modules\",\n      \"modules/video_capture:video_capture_internal_impl\",\n      \"ortc\",\n      \"rtc_base\",\n      \"sdk\",\n      \"system_wrappers:system_wrappers_default\",\n      \"video\",\n    ]\n\n    if (build_with_mozilla) {\n      deps += [\n        \"api:video_frame_api\",\n        \"system_wrappers:field_trial_default\",\n        \"system_wrappers:metrics_default\",\n      ]\n    } else {\n      deps += [\n        \"api\",\n        \"logging\",\n        \"p2p\",\n        \"pc\",\n        \"stats\",\n      ]\n    }\n\n    if (rtc_enable_protobuf) {\n      defines += [ \"ENABLE_RTC_EVENT_LOG\" ]\n      deps += [ \"logging:rtc_event_log_proto\" ]\n    }\n  }\n}\n\nrtc_source_set(\"typedefs\") {\n  sources = [\n    \"typedefs.h\",\n  ]\n}\n\nrtc_static_library(\"webrtc_common\") {\n  sources = [\n    \"common_types.cc\",\n    \"common_types.h\",\n  ]\n  deps = [\n    \":typedefs\",\n    \"api:array_view\",\n    \"api:optional\",\n    \"rtc_base:checks\",\n    \"rtc_base:deprecation\",\n    \"rtc_base:stringutils\",\n  ]\n\n  if (!build_with_chromium && is_clang) {\n    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).\n    suppressed_configs += [ \"//build/config/clang:find_bad_constructs\" ]\n  }\n}\n\nif (use_libfuzzer || use_drfuzz || use_afl) {\n  # This target is only here for gn to discover fuzzer build targets under\n  # webrtc/test/fuzzers/.\n  group(\"webrtc_fuzzers_dummy\") {\n    testonly = true\n    deps = [\n      \"test/fuzzers:webrtc_fuzzer_main\",\n    ]\n  }\n}\n\nif (rtc_include_tests) {\n  config(\"rtc_unittests_config\") {\n    # GN orders flags on a target before flags from configs. The default config\n    # adds -Wall, and this flag have to be after -Wall -- so they need to\n    # come from a config and can\"t be on the target directly.\n    if (is_clang) {\n      cflags = [\n        \"-Wno-sign-compare\",\n        \"-Wno-unused-const-variable\",\n      ]\n    }\n  }\n\n  rtc_test(\"rtc_unittests\") {\n    testonly = true\n\n    deps = [\n      \":webrtc_common\",\n      \"api:rtc_api_unittests\",\n      \"api/audio_codecs/test:audio_codecs_api_unittests\",\n      \"p2p:libstunprober_unittests\",\n      \"p2p:rtc_p2p_unittests\",\n      \"rtc_base:rtc_base_approved_unittests\",\n      \"rtc_base:rtc_base_tests_main\",\n      \"rtc_base:rtc_base_tests_utils\",\n      \"rtc_base:rtc_base_unittests\",\n      \"rtc_base:rtc_numerics_unittests\",\n      \"rtc_base:rtc_task_queue_unittests\",\n      \"rtc_base:sequenced_task_checker_unittests\",\n      \"rtc_base:weak_ptr_unittests\",\n      \"system_wrappers:metrics_default\",\n      \"system_wrappers:runtime_enabled_features_default\",\n    ]\n\n    if (rtc_enable_protobuf) {\n      deps += [ \"logging:rtc_event_log_tests\" ]\n    }\n\n    if (is_android) {\n      # Do not use Chromium's launcher. native_unittests defines its own JNI_OnLoad.\n      use_default_launcher = false\n\n      deps += [\n        \"sdk/android:native_unittests\",\n        \"sdk/android:native_unittests_java\",\n        \"//testing/android/native_test:native_test_support\",\n      ]\n      shard_timeout = 900\n    }\n\n    if (is_ios || is_mac) {\n      deps += [ \"sdk:sdk_unittests_objc\" ]\n    }\n  }\n\n  # TODO(pbos): Rename test suite, this is no longer \"just\" for video targets.\n  video_engine_tests_resources = [\n    \"resources/foreman_cif_short.yuv\",\n    \"resources/voice_engine/audio_long16.pcm\",\n  ]\n\n  if (is_ios) {\n    bundle_data(\"video_engine_tests_bundle_data\") {\n      testonly = true\n      sources = video_engine_tests_resources\n      outputs = [\n        \"{{bundle_resources_dir}}/{{source_file_part}}\",\n      ]\n    }\n  }\n\n  rtc_test(\"video_engine_tests\") {\n    testonly = true\n    deps = [\n      \"audio:audio_tests\",\n\n      # TODO(eladalon): call_tests aren't actually video-specific, so we\n      # should move them to a more appropriate test suite.\n      \"call:call_tests\",\n      \"modules/video_capture\",\n      \"rtc_base:rtc_base_tests_utils\",\n      \"test:test_common\",\n      \"test:test_main\",\n      \"test:video_test_common\",\n      \"video:video_tests\",\n    ]\n    data = video_engine_tests_resources\n    if (!build_with_chromium && is_clang) {\n      # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).\n      suppressed_configs += [ \"//build/config/clang:find_bad_constructs\" ]\n    }\n    if (is_android) {\n      deps += [ \"//testing/android/native_test:native_test_native_code\" ]\n      shard_timeout = 900\n    }\n    if (is_ios) {\n      deps += [ \":video_engine_tests_bundle_data\" ]\n    }\n  }\n\n  webrtc_perf_tests_resources = [\n    \"resources/audio_coding/speech_mono_16kHz.pcm\",\n    \"resources/audio_coding/speech_mono_32_48kHz.pcm\",\n    \"resources/audio_coding/testfile32kHz.pcm\",\n    \"resources/ConferenceMotion_1280_720_50.yuv\",\n    \"resources/difficult_photo_1850_1110.yuv\",\n    \"resources/foreman_cif.yuv\",\n    \"resources/google-wifi-3mbps.rx\",\n    \"resources/paris_qcif.yuv\",\n    \"resources/photo_1850_1110.yuv\",\n    \"resources/presentation_1850_1110.yuv\",\n    \"resources/verizon4g-downlink.rx\",\n    \"resources/voice_engine/audio_long16.pcm\",\n    \"resources/web_screenshot_1850_1110.yuv\",\n  ]\n\n  if (is_ios) {\n    bundle_data(\"webrtc_perf_tests_bundle_data\") {\n      testonly = true\n      sources = webrtc_perf_tests_resources\n      outputs = [\n        \"{{bundle_resources_dir}}/{{source_file_part}}\",\n      ]\n    }\n  }\n\n  rtc_test(\"webrtc_perf_tests\") {\n    testonly = true\n    configs += [ \":rtc_unittests_config\" ]\n\n    deps = [\n      \"audio:audio_perf_tests\",\n      \"call:call_perf_tests\",\n      \"modules/audio_coding:audio_coding_perf_tests\",\n      \"modules/audio_processing:audio_processing_perf_tests\",\n      \"modules/remote_bitrate_estimator:remote_bitrate_estimator_perf_tests\",\n      \"test:test_main\",\n      \"video:video_full_stack_tests\",\n    ]\n\n    data = webrtc_perf_tests_resources\n    if (is_android) {\n      deps += [ \"//testing/android/native_test:native_test_native_code\" ]\n      shard_timeout = 2700\n    }\n    if (is_ios) {\n      deps += [ \":webrtc_perf_tests_bundle_data\" ]\n    }\n  }\n\n  rtc_test(\"webrtc_nonparallel_tests\") {\n    testonly = true\n    deps = [\n      \"rtc_base:rtc_base_nonparallel_tests\",\n    ]\n    if (is_android) {\n      deps += [ \"//testing/android/native_test:native_test_support\" ]\n      shard_timeout = 900\n    }\n  }\n\n  if (is_android) {\n    junit_binary(\"android_junit_tests\") {\n      java_files = [\n        \"examples/androidjunit/src/org/appspot/apprtc/BluetoothManagerTest.java\",\n        \"examples/androidjunit/src/org/appspot/apprtc/DirectRTCClientTest.java\",\n        \"examples/androidjunit/src/org/appspot/apprtc/TCPChannelClientTest.java\",\n        \"sdk/android/tests/src/org/webrtc/CameraEnumerationTest.java\",\n      ]\n\n      deps = [\n        \"examples:AppRTCMobile_javalib\",\n        \"sdk/android:libjingle_peerconnection_java\",\n        \"//base:base_java_test_support\",\n      ]\n    }\n  }\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/rename.sh",
    "content": "#!/bin/sh \nrename 's/mips\\.c$/mips\\.c\\.mips/' signal_processing/*.c\nrename 's/neon\\.c$/neon\\.c\\.neon/' signal_processing/*.c\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/rename.sh~",
    "content": "#!/bin/sh \nrename 's/mips\\.c$/mips\\.c\\.mips/' signal_processing/*.c\nrename 's/neon\\.c$/neon\\.c\\.neon/' signal_processing/*.c\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/cross_correlation.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n/* C version of WebRtcSpl_CrossCorrelation() for generic platforms. */\nvoid WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,\n                                 const int16_t* seq1,\n                                 const int16_t* seq2,\n                                 size_t dim_seq,\n                                 size_t dim_cross_correlation,\n                                 int right_shifts,\n                                 int step_seq2) {\n  size_t i = 0, j = 0;\n\n  for (i = 0; i < dim_cross_correlation; i++) {\n    int32_t corr = 0;\n    for (j = 0; j < dim_seq; j++)\n      corr += (seq1[j] * seq2[j]) >> right_shifts;\n    seq2 += step_seq2;\n    *cross_correlation++ = corr;\n  }\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/cross_correlation_mips.c.mips",
    "content": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\nvoid WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,\n                                     const int16_t* seq1,\n                                     const int16_t* seq2,\n                                     size_t dim_seq,\n                                     size_t dim_cross_correlation,\n                                     int right_shifts,\n                                     int step_seq2) {\n\n  int32_t t0 = 0, t1 = 0, t2 = 0, t3 = 0, sum = 0;\n  int16_t *pseq2 = NULL;\n  int16_t *pseq1 = NULL;\n  int16_t *pseq1_0 = (int16_t*)&seq1[0];\n  int16_t *pseq2_0 = (int16_t*)&seq2[0];\n  int k = 0;\n\n  __asm __volatile (\n    \".set        push                                           \\n\\t\"\n    \".set        noreorder                                      \\n\\t\"\n    \"sll         %[step_seq2], %[step_seq2],   1                \\n\\t\"\n    \"andi        %[t0],        %[dim_seq],     1                \\n\\t\"\n    \"bgtz        %[t0],        3f                               \\n\\t\"\n    \" nop                                                       \\n\\t\"\n   \"1:                                                          \\n\\t\"\n    \"move        %[pseq1],     %[pseq1_0]                       \\n\\t\"\n    \"move        %[pseq2],     %[pseq2_0]                       \\n\\t\"\n    \"sra         %[k],         %[dim_seq],     1                \\n\\t\"\n    \"addiu       %[dim_cc],    %[dim_cc],      -1               \\n\\t\"\n    \"xor         %[sum],       %[sum],         %[sum]           \\n\\t\"\n   \"2:                                                          \\n\\t\"\n    \"lh          %[t0],        0(%[pseq1])                      \\n\\t\"\n    \"lh          %[t1],        0(%[pseq2])                      \\n\\t\"\n    \"lh          %[t2],        2(%[pseq1])                      \\n\\t\"\n    \"lh          %[t3],        2(%[pseq2])                      \\n\\t\"\n    \"mul         %[t0],        %[t0],          %[t1]            \\n\\t\"\n    \"addiu       %[k],         %[k],           -1               \\n\\t\"\n    \"mul         %[t2],        %[t2],          %[t3]            \\n\\t\"\n    \"addiu       %[pseq1],     %[pseq1],       4                \\n\\t\"\n    \"addiu       %[pseq2],     %[pseq2],       4                \\n\\t\"\n    \"srav        %[t0],        %[t0],          %[right_shifts]  \\n\\t\"\n    \"addu        %[sum],       %[sum],         %[t0]            \\n\\t\"\n    \"srav        %[t2],        %[t2],          %[right_shifts]  \\n\\t\"\n    \"bgtz        %[k],         2b                               \\n\\t\"\n    \" addu       %[sum],       %[sum],         %[t2]            \\n\\t\"\n    \"addu        %[pseq2_0],   %[pseq2_0],     %[step_seq2]     \\n\\t\"\n    \"sw          %[sum],       0(%[cc])                         \\n\\t\"\n    \"bgtz        %[dim_cc],    1b                               \\n\\t\"\n    \" addiu      %[cc],        %[cc],          4                \\n\\t\"\n    \"b           6f                                             \\n\\t\"\n    \" nop                                                       \\n\\t\"\n   \"3:                                                          \\n\\t\"\n    \"move        %[pseq1],     %[pseq1_0]                       \\n\\t\"\n    \"move        %[pseq2],     %[pseq2_0]                       \\n\\t\"\n    \"sra         %[k],         %[dim_seq],     1                \\n\\t\"\n    \"addiu       %[dim_cc],    %[dim_cc],      -1               \\n\\t\"\n    \"beqz        %[k],         5f                               \\n\\t\"\n    \" xor        %[sum],       %[sum],         %[sum]           \\n\\t\"\n   \"4:                                                          \\n\\t\"\n    \"lh          %[t0],        0(%[pseq1])                      \\n\\t\"\n    \"lh          %[t1],        0(%[pseq2])                      \\n\\t\"\n    \"lh          %[t2],        2(%[pseq1])                      \\n\\t\"\n    \"lh          %[t3],        2(%[pseq2])                      \\n\\t\"\n    \"mul         %[t0],        %[t0],          %[t1]            \\n\\t\"\n    \"addiu       %[k],         %[k],           -1               \\n\\t\"\n    \"mul         %[t2],        %[t2],          %[t3]            \\n\\t\"\n    \"addiu       %[pseq1],     %[pseq1],       4                \\n\\t\"\n    \"addiu       %[pseq2],     %[pseq2],       4                \\n\\t\"\n    \"srav        %[t0],        %[t0],          %[right_shifts]  \\n\\t\"\n    \"addu        %[sum],       %[sum],         %[t0]            \\n\\t\"\n    \"srav        %[t2],        %[t2],          %[right_shifts]  \\n\\t\"\n    \"bgtz        %[k],         4b                               \\n\\t\"\n    \" addu       %[sum],       %[sum],         %[t2]            \\n\\t\"\n   \"5:                                                          \\n\\t\"\n    \"lh          %[t0],        0(%[pseq1])                      \\n\\t\"\n    \"lh          %[t1],        0(%[pseq2])                      \\n\\t\"\n    \"mul         %[t0],        %[t0],          %[t1]            \\n\\t\"\n    \"srav        %[t0],        %[t0],          %[right_shifts]  \\n\\t\"\n    \"addu        %[sum],       %[sum],         %[t0]            \\n\\t\"\n    \"addu        %[pseq2_0],   %[pseq2_0],     %[step_seq2]     \\n\\t\"\n    \"sw          %[sum],       0(%[cc])                         \\n\\t\"\n    \"bgtz        %[dim_cc],    3b                               \\n\\t\"\n    \" addiu      %[cc],        %[cc],          4                \\n\\t\"\n   \"6:                                                          \\n\\t\"\n    \".set        pop                                            \\n\\t\"\n    : [step_seq2] \"+r\" (step_seq2), [t0] \"=&r\" (t0), [t1] \"=&r\" (t1),\n      [t2] \"=&r\" (t2), [t3] \"=&r\" (t3), [pseq1] \"=&r\" (pseq1),\n      [pseq2] \"=&r\" (pseq2), [pseq1_0] \"+r\" (pseq1_0), [pseq2_0] \"+r\" (pseq2_0),\n      [k] \"=&r\" (k), [dim_cc] \"+r\" (dim_cross_correlation), [sum] \"=&r\" (sum),\n      [cc] \"+r\" (cross_correlation)\n    : [dim_seq] \"r\" (dim_seq), [right_shifts] \"r\" (right_shifts)\n    : \"hi\", \"lo\", \"memory\"\n  );\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/cross_correlation_neon.c.neon",
    "content": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n#include <arm_neon.h>\n\nstatic inline void DotProductWithScaleNeon(int32_t* cross_correlation,\n                                           const int16_t* vector1,\n                                           const int16_t* vector2,\n                                           size_t length,\n                                           int scaling) {\n  size_t i = 0;\n  size_t len1 = length >> 3;\n  size_t len2 = length & 7;\n  int64x2_t sum0 = vdupq_n_s64(0);\n  int64x2_t sum1 = vdupq_n_s64(0);\n\n  for (i = len1; i > 0; i -= 1) {\n    int16x8_t seq1_16x8 = vld1q_s16(vector1);\n    int16x8_t seq2_16x8 = vld1q_s16(vector2);\n#if defined(WEBRTC_ARCH_ARM64)\n    int32x4_t tmp0 = vmull_s16(vget_low_s16(seq1_16x8),\n                               vget_low_s16(seq2_16x8));\n    int32x4_t tmp1 = vmull_high_s16(seq1_16x8, seq2_16x8);\n#else\n    int32x4_t tmp0 = vmull_s16(vget_low_s16(seq1_16x8),\n                               vget_low_s16(seq2_16x8));\n    int32x4_t tmp1 = vmull_s16(vget_high_s16(seq1_16x8),\n                               vget_high_s16(seq2_16x8));\n#endif\n    sum0 = vpadalq_s32(sum0, tmp0);\n    sum1 = vpadalq_s32(sum1, tmp1);\n    vector1 += 8;\n    vector2 += 8;\n  }\n\n  // Calculate the rest of the samples.\n  int64_t sum_res = 0;\n  for (i = len2; i > 0; i -= 1) {\n    sum_res += WEBRTC_SPL_MUL_16_16(*vector1, *vector2);\n    vector1++;\n    vector2++;\n  }\n\n  sum0 = vaddq_s64(sum0, sum1);\n#if defined(WEBRTC_ARCH_ARM64)\n  int64_t sum2 = vaddvq_s64(sum0);\n  *cross_correlation = (int32_t)((sum2 + sum_res) >> scaling);\n#else\n  int64x1_t shift = vdup_n_s64(-scaling);\n  int64x1_t sum2 = vadd_s64(vget_low_s64(sum0), vget_high_s64(sum0));\n  sum2 = vadd_s64(sum2, vdup_n_s64(sum_res));\n  sum2 = vshl_s64(sum2, shift);\n  vst1_lane_s32(cross_correlation, vreinterpret_s32_s64(sum2), 0);\n#endif\n}\n\n/* NEON version of WebRtcSpl_CrossCorrelation() for ARM32/64 platforms. */\nvoid WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,\n                                    const int16_t* seq1,\n                                    const int16_t* seq2,\n                                    size_t dim_seq,\n                                    size_t dim_cross_correlation,\n                                    int right_shifts,\n                                    int step_seq2) {\n  size_t i = 0;\n\n  for (i = 0; i < dim_cross_correlation; i++) {\n    const int16_t* seq1_ptr = seq1;\n    const int16_t* seq2_ptr = seq2 + (step_seq2 * i);\n\n    DotProductWithScaleNeon(cross_correlation,\n                            seq1_ptr,\n                            seq2_ptr,\n                            dim_seq,\n                            right_shifts);\n    cross_correlation++;\n  }\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/division_operations.c",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This file contains implementations of the divisions\n * WebRtcSpl_DivU32U16()\n * WebRtcSpl_DivW32W16()\n * WebRtcSpl_DivW32W16ResW16()\n * WebRtcSpl_DivResultInQ31()\n * WebRtcSpl_DivW32HiLow()\n *\n * The description header can be found in signal_processing_library.h\n *\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"rtc_base/sanitizer.h\"\n\nuint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den)\n{\n    // Guard against division with 0\n    if (den != 0)\n    {\n        return (uint32_t)(num / den);\n    } else\n    {\n        return (uint32_t)0xFFFFFFFF;\n    }\n}\n\nint32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den)\n{\n    // Guard against division with 0\n    if (den != 0)\n    {\n        return (int32_t)(num / den);\n    } else\n    {\n        return (int32_t)0x7FFFFFFF;\n    }\n}\n\nint16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den)\n{\n    // Guard against division with 0\n    if (den != 0)\n    {\n        return (int16_t)(num / den);\n    } else\n    {\n        return (int16_t)0x7FFF;\n    }\n}\n\nint32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den)\n{\n    int32_t L_num = num;\n    int32_t L_den = den;\n    int32_t div = 0;\n    int k = 31;\n    int change_sign = 0;\n\n    if (num == 0)\n        return 0;\n\n    if (num < 0)\n    {\n        change_sign++;\n        L_num = -num;\n    }\n    if (den < 0)\n    {\n        change_sign++;\n        L_den = -den;\n    }\n    while (k--)\n    {\n        div <<= 1;\n        L_num <<= 1;\n        if (L_num >= L_den)\n        {\n            L_num -= L_den;\n            div++;\n        }\n    }\n    if (change_sign == 1)\n    {\n        div = -div;\n    }\n    return div;\n}\n\nint32_t RTC_NO_SANITIZE(\"signed-integer-overflow\")  // bugs.webrtc.org/5486\nWebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)\n{\n    int16_t approx, tmp_hi, tmp_low, num_hi, num_low;\n    int32_t tmpW32;\n\n    approx = (int16_t)WebRtcSpl_DivW32W16((int32_t)0x1FFFFFFF, den_hi);\n    // result in Q14 (Note: 3FFFFFFF = 0.5 in Q30)\n\n    // tmpW32 = 1/den = approx * (2.0 - den * approx) (in Q30)\n    tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1);\n    // tmpW32 = den * approx\n\n    tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den*approx))\n    // UBSan: 2147483647 - -2 cannot be represented in type 'int'\n\n    // Store tmpW32 in hi and low format\n    tmp_hi = (int16_t)(tmpW32 >> 16);\n    tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1);\n\n    // tmpW32 = 1/den in Q29\n    tmpW32 = (tmp_hi * approx + (tmp_low * approx >> 15)) << 1;\n\n    // 1/den in hi and low format\n    tmp_hi = (int16_t)(tmpW32 >> 16);\n    tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1);\n\n    // Store num in hi and low format\n    num_hi = (int16_t)(num >> 16);\n    num_low = (int16_t)((num - ((int32_t)num_hi << 16)) >> 1);\n\n    // num * (1/den) by 32 bit multiplication (result in Q28)\n\n    tmpW32 = num_hi * tmp_hi + (num_hi * tmp_low >> 15) +\n        (num_low * tmp_hi >> 15);\n\n    // Put result in Q31 (convert from Q28)\n    tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3);\n\n    return tmpW32;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/downsample_fast.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n#include \"rtc_base/checks.h\"\n#include \"rtc_base/sanitizer.h\"\n\n// TODO(Bjornv): Change the function parameter order to WebRTC code style.\n// C version of WebRtcSpl_DownsampleFast() for generic platforms.\nint WebRtcSpl_DownsampleFastC(const int16_t* data_in,\n                              size_t data_in_length,\n                              int16_t* data_out,\n                              size_t data_out_length,\n                              const int16_t* __restrict coefficients,\n                              size_t coefficients_length,\n                              int factor,\n                              size_t delay) {\n  int16_t* const original_data_out = data_out;\n  size_t i = 0;\n  size_t j = 0;\n  int32_t out_s32 = 0;\n  size_t endpos = delay + factor * (data_out_length - 1) + 1;\n\n  // Return error if any of the running conditions doesn't meet.\n  if (data_out_length == 0 || coefficients_length == 0\n                           || data_in_length < endpos) {\n    return -1;\n  }\n\n  rtc_MsanCheckInitialized(coefficients, sizeof(coefficients[0]),\n                           coefficients_length);\n\n  for (i = delay; i < endpos; i += factor) {\n    out_s32 = 2048;  // Round value, 0.5 in Q12.\n\n    for (j = 0; j < coefficients_length; j++) {\n      rtc_MsanCheckInitialized(&data_in[i - j], sizeof(data_in[0]), 1);\n      out_s32 += coefficients[j] * data_in[i - j];  // Q12.\n    }\n\n    out_s32 >>= 12;  // Q0.\n\n    // Saturate and store the output.\n    *data_out++ = WebRtcSpl_SatW32ToW16(out_s32);\n  }\n\n  RTC_DCHECK_EQ(original_data_out + data_out_length, data_out);\n  rtc_MsanCheckInitialized(original_data_out, sizeof(original_data_out[0]),\n                           data_out_length);\n\n  return 0;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/downsample_fast_mips.c.mips",
    "content": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n// Version of WebRtcSpl_DownsampleFast() for MIPS platforms.\nint WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,\n                                  size_t data_in_length,\n                                  int16_t* data_out,\n                                  size_t data_out_length,\n                                  const int16_t* __restrict coefficients,\n                                  size_t coefficients_length,\n                                  int factor,\n                                  size_t delay) {\n  int i;\n  int j;\n  int k;\n  int32_t out_s32 = 0;\n  size_t endpos = delay + factor * (data_out_length - 1) + 1;\n\n  int32_t  tmp1, tmp2, tmp3, tmp4, factor_2;\n  int16_t* p_coefficients;\n  int16_t* p_data_in;\n  int16_t* p_data_in_0 = (int16_t*)&data_in[delay];\n  int16_t* p_coefficients_0 = (int16_t*)&coefficients[0];\n#if !defined(MIPS_DSP_R1_LE)\n  int32_t max_16 = 0x7FFF;\n  int32_t min_16 = 0xFFFF8000;\n#endif  // #if !defined(MIPS_DSP_R1_LE)\n\n  // Return error if any of the running conditions doesn't meet.\n  if (data_out_length == 0 || coefficients_length == 0\n                           || data_in_length < endpos) {\n    return -1;\n  }\n#if defined(MIPS_DSP_R2_LE)\n  __asm __volatile (\n    \".set        push                                                \\n\\t\"\n    \".set        noreorder                                           \\n\\t\"\n    \"subu        %[i],            %[endpos],       %[delay]          \\n\\t\"\n    \"sll         %[factor_2],     %[factor],       1                 \\n\\t\"\n   \"1:                                                               \\n\\t\"\n    \"move        %[p_data_in],    %[p_data_in_0]                     \\n\\t\"\n    \"mult        $zero,           $zero                              \\n\\t\"\n    \"move        %[p_coefs],      %[p_coefs_0]                       \\n\\t\"\n    \"sra         %[j],            %[coef_length],  2                 \\n\\t\"\n    \"beq         %[j],            $zero,           3f                \\n\\t\"\n    \" andi       %[k],            %[coef_length],  3                 \\n\\t\"\n   \"2:                                                               \\n\\t\"\n    \"lwl         %[tmp1],         1(%[p_data_in])                    \\n\\t\"\n    \"lwl         %[tmp2],         3(%[p_coefs])                      \\n\\t\"\n    \"lwl         %[tmp3],         -3(%[p_data_in])                   \\n\\t\"\n    \"lwl         %[tmp4],         7(%[p_coefs])                      \\n\\t\"\n    \"lwr         %[tmp1],         -2(%[p_data_in])                   \\n\\t\"\n    \"lwr         %[tmp2],         0(%[p_coefs])                      \\n\\t\"\n    \"lwr         %[tmp3],         -6(%[p_data_in])                   \\n\\t\"\n    \"lwr         %[tmp4],         4(%[p_coefs])                      \\n\\t\"\n    \"packrl.ph   %[tmp1],         %[tmp1],         %[tmp1]           \\n\\t\"\n    \"packrl.ph   %[tmp3],         %[tmp3],         %[tmp3]           \\n\\t\"\n    \"dpa.w.ph    $ac0,            %[tmp1],         %[tmp2]           \\n\\t\"\n    \"dpa.w.ph    $ac0,            %[tmp3],         %[tmp4]           \\n\\t\"\n    \"addiu       %[j],            %[j],            -1                \\n\\t\"\n    \"addiu       %[p_data_in],    %[p_data_in],    -8                \\n\\t\"\n    \"bgtz        %[j],            2b                                 \\n\\t\"\n    \" addiu      %[p_coefs],      %[p_coefs],      8                 \\n\\t\"\n   \"3:                                                               \\n\\t\"\n    \"beq         %[k],            $zero,           5f                \\n\\t\"\n    \" nop                                                            \\n\\t\"\n   \"4:                                                               \\n\\t\"\n    \"lhu         %[tmp1],         0(%[p_data_in])                    \\n\\t\"\n    \"lhu         %[tmp2],         0(%[p_coefs])                      \\n\\t\"\n    \"addiu       %[p_data_in],    %[p_data_in],    -2                \\n\\t\"\n    \"addiu       %[k],            %[k],            -1                \\n\\t\"\n    \"dpa.w.ph    $ac0,            %[tmp1],         %[tmp2]           \\n\\t\"\n    \"bgtz        %[k],            4b                                 \\n\\t\"\n    \" addiu      %[p_coefs],      %[p_coefs],      2                 \\n\\t\"\n   \"5:                                                               \\n\\t\"\n    \"extr_r.w    %[out_s32],      $ac0,            12                \\n\\t\"\n    \"addu        %[p_data_in_0],  %[p_data_in_0],  %[factor_2]       \\n\\t\"\n    \"subu        %[i],            %[i],            %[factor]         \\n\\t\"\n    \"shll_s.w    %[out_s32],      %[out_s32],      16                \\n\\t\"\n    \"sra         %[out_s32],      %[out_s32],      16                \\n\\t\"\n    \"sh          %[out_s32],      0(%[data_out])                     \\n\\t\"\n    \"bgtz        %[i],            1b                                 \\n\\t\"\n    \" addiu      %[data_out],     %[data_out],     2                 \\n\\t\"\n    \".set        pop                                                 \\n\\t\"\n    : [tmp1] \"=&r\" (tmp1), [tmp2] \"=&r\" (tmp2), [tmp3] \"=&r\" (tmp3),\n      [tmp4] \"=&r\" (tmp4), [p_data_in] \"=&r\" (p_data_in),\n      [p_data_in_0] \"+r\" (p_data_in_0), [p_coefs] \"=&r\" (p_coefficients),\n      [j] \"=&r\" (j), [out_s32] \"=&r\" (out_s32), [factor_2] \"=&r\" (factor_2),\n      [i] \"=&r\" (i), [k] \"=&r\" (k)\n    : [coef_length] \"r\" (coefficients_length), [data_out] \"r\" (data_out),\n      [p_coefs_0] \"r\" (p_coefficients_0), [endpos] \"r\" (endpos),\n      [delay] \"r\" (delay), [factor] \"r\" (factor)\n    : \"memory\", \"hi\", \"lo\"\n );\n#else  // #if defined(MIPS_DSP_R2_LE)\n  __asm __volatile (\n    \".set        push                                                \\n\\t\"\n    \".set        noreorder                                           \\n\\t\"\n    \"sll         %[factor_2],     %[factor],       1                 \\n\\t\"\n    \"subu        %[i],            %[endpos],       %[delay]          \\n\\t\"\n   \"1:                                                               \\n\\t\"\n    \"move        %[p_data_in],    %[p_data_in_0]                     \\n\\t\"\n    \"addiu       %[out_s32],      $zero,           2048              \\n\\t\"\n    \"move        %[p_coefs],      %[p_coefs_0]                       \\n\\t\"\n    \"sra         %[j],            %[coef_length],  1                 \\n\\t\"\n    \"beq         %[j],            $zero,           3f                \\n\\t\"\n    \" andi       %[k],            %[coef_length],  1                 \\n\\t\"\n   \"2:                                                               \\n\\t\"\n    \"lh          %[tmp1],         0(%[p_data_in])                    \\n\\t\"\n    \"lh          %[tmp2],         0(%[p_coefs])                      \\n\\t\"\n    \"lh          %[tmp3],         -2(%[p_data_in])                   \\n\\t\"\n    \"lh          %[tmp4],         2(%[p_coefs])                      \\n\\t\"\n    \"mul         %[tmp1],         %[tmp1],         %[tmp2]           \\n\\t\"\n    \"addiu       %[p_coefs],      %[p_coefs],      4                 \\n\\t\"\n    \"mul         %[tmp3],         %[tmp3],         %[tmp4]           \\n\\t\"\n    \"addiu       %[j],            %[j],            -1                \\n\\t\"\n    \"addiu       %[p_data_in],    %[p_data_in],    -4                \\n\\t\"\n    \"addu        %[tmp1],         %[tmp1],         %[tmp3]           \\n\\t\"\n    \"bgtz        %[j],            2b                                 \\n\\t\"\n    \" addu       %[out_s32],      %[out_s32],      %[tmp1]           \\n\\t\"\n   \"3:                                                               \\n\\t\"\n    \"beq         %[k],            $zero,           4f                \\n\\t\"\n    \" nop                                                            \\n\\t\"\n    \"lh          %[tmp1],         0(%[p_data_in])                    \\n\\t\"\n    \"lh          %[tmp2],         0(%[p_coefs])                      \\n\\t\"\n    \"mul         %[tmp1],         %[tmp1],         %[tmp2]           \\n\\t\"\n    \"addu        %[out_s32],      %[out_s32],      %[tmp1]           \\n\\t\"\n   \"4:                                                               \\n\\t\"\n    \"sra         %[out_s32],      %[out_s32],      12                \\n\\t\"\n    \"addu        %[p_data_in_0],  %[p_data_in_0],  %[factor_2]       \\n\\t\"\n#if defined(MIPS_DSP_R1_LE)\n    \"shll_s.w    %[out_s32],      %[out_s32],      16                \\n\\t\"\n    \"sra         %[out_s32],      %[out_s32],      16                \\n\\t\"\n#else  // #if defined(MIPS_DSP_R1_LE)\n    \"slt         %[tmp1],         %[max_16],       %[out_s32]        \\n\\t\"\n    \"movn        %[out_s32],      %[max_16],       %[tmp1]           \\n\\t\"\n    \"slt         %[tmp1],         %[out_s32],      %[min_16]         \\n\\t\"\n    \"movn        %[out_s32],      %[min_16],       %[tmp1]           \\n\\t\"\n#endif  // #if defined(MIPS_DSP_R1_LE)\n    \"subu        %[i],            %[i],            %[factor]         \\n\\t\"\n    \"sh          %[out_s32],      0(%[data_out])                     \\n\\t\"\n    \"bgtz        %[i],            1b                                 \\n\\t\"\n    \" addiu      %[data_out],     %[data_out],     2                 \\n\\t\"\n    \".set        pop                                                 \\n\\t\"\n    : [tmp1] \"=&r\" (tmp1), [tmp2] \"=&r\" (tmp2), [tmp3] \"=&r\" (tmp3),\n      [tmp4] \"=&r\" (tmp4), [p_data_in] \"=&r\" (p_data_in), [k] \"=&r\" (k),\n      [p_data_in_0] \"+r\" (p_data_in_0), [p_coefs] \"=&r\" (p_coefficients),\n      [j] \"=&r\" (j), [out_s32] \"=&r\" (out_s32), [factor_2] \"=&r\" (factor_2),\n      [i] \"=&r\" (i)\n    : [coef_length] \"r\" (coefficients_length), [data_out] \"r\" (data_out),\n      [p_coefs_0] \"r\" (p_coefficients_0), [endpos] \"r\" (endpos),\n#if !defined(MIPS_DSP_R1_LE)\n      [max_16] \"r\" (max_16), [min_16] \"r\" (min_16),\n#endif  // #if !defined(MIPS_DSP_R1_LE)\n      [delay] \"r\" (delay), [factor] \"r\" (factor)\n    : \"memory\", \"hi\", \"lo\"\n  );\n#endif  // #if defined(MIPS_DSP_R2_LE)\n  return 0;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/downsample_fast_neon.c.neon",
    "content": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n#include <arm_neon.h>\n\n// NEON intrinsics version of WebRtcSpl_DownsampleFast()\n// for ARM 32-bit/64-bit platforms.\nint WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,\n                                 size_t data_in_length,\n                                 int16_t* data_out,\n                                 size_t data_out_length,\n                                 const int16_t* __restrict coefficients,\n                                 size_t coefficients_length,\n                                 int factor,\n                                 size_t delay) {\n  size_t i = 0;\n  size_t j = 0;\n  int32_t out_s32 = 0;\n  size_t endpos = delay + factor * (data_out_length - 1) + 1;\n  size_t res = data_out_length & 0x7;\n  size_t endpos1 = endpos - factor * res;\n\n  // Return error if any of the running conditions doesn't meet.\n  if (data_out_length == 0 || coefficients_length == 0\n                           || data_in_length < endpos) {\n    return -1;\n  }\n\n  // First part, unroll the loop 8 times, with 3 subcases\n  // (factor == 2, 4, others).\n  switch (factor) {\n    case 2: {\n      for (i = delay; i < endpos1; i += 16) {\n        // Round value, 0.5 in Q12.\n        int32x4_t out32x4_0 = vdupq_n_s32(2048);\n        int32x4_t out32x4_1 = vdupq_n_s32(2048);\n\n#if defined(WEBRTC_ARCH_ARM64)\n        // Unroll the loop 2 times.\n        for (j = 0; j < coefficients_length - 1; j += 2) {\n          int32x2_t coeff32 = vld1_dup_s32((int32_t*)&coefficients[j]);\n          int16x4_t coeff16x4 = vreinterpret_s16_s32(coeff32);\n          int16x8x2_t in16x8x2 = vld2q_s16(&data_in[i - j - 1]);\n\n          // Mul and accumulate low 64-bit data.\n          int16x4_t in16x4_0 = vget_low_s16(in16x8x2.val[0]);\n          int16x4_t in16x4_1 = vget_low_s16(in16x8x2.val[1]);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 1);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_1, coeff16x4, 0);\n\n          // Mul and accumulate high 64-bit data.\n          // TODO: vget_high_s16 need extra cost on ARM64. This could be\n          // replaced by vmlal_high_lane_s16. But for the interface of\n          // vmlal_high_lane_s16, there is a bug in gcc 4.9.\n          // This issue need to be tracked in the future.\n          int16x4_t in16x4_2 = vget_high_s16(in16x8x2.val[0]);\n          int16x4_t in16x4_3 = vget_high_s16(in16x8x2.val[1]);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_2, coeff16x4, 1);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_3, coeff16x4, 0);\n        }\n\n        for (; j < coefficients_length; j++) {\n          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);\n          int16x8x2_t in16x8x2 = vld2q_s16(&data_in[i - j]);\n\n          // Mul and accumulate low 64-bit data.\n          int16x4_t in16x4_0 = vget_low_s16(in16x8x2.val[0]);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);\n\n          // Mul and accumulate high 64-bit data.\n          // TODO: vget_high_s16 need extra cost on ARM64. This could be\n          // replaced by vmlal_high_lane_s16. But for the interface of\n          // vmlal_high_lane_s16, there is a bug in gcc 4.9.\n          // This issue need to be tracked in the future.\n          int16x4_t in16x4_1 = vget_high_s16(in16x8x2.val[0]);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);\n        }\n#else\n        // On ARMv7, the loop unrolling 2 times results in performance\n        // regression.\n        for (j = 0; j < coefficients_length; j++) {\n          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);\n          int16x8x2_t in16x8x2 = vld2q_s16(&data_in[i - j]);\n\n          // Mul and accumulate.\n          int16x4_t in16x4_0 = vget_low_s16(in16x8x2.val[0]);\n          int16x4_t in16x4_1 = vget_high_s16(in16x8x2.val[0]);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);\n        }\n#endif\n\n        // Saturate and store the output.\n        int16x4_t out16x4_0 = vqshrn_n_s32(out32x4_0, 12);\n        int16x4_t out16x4_1 = vqshrn_n_s32(out32x4_1, 12);\n        vst1q_s16(data_out, vcombine_s16(out16x4_0, out16x4_1));\n        data_out += 8;\n      }\n      break;\n    }\n    case 4: {\n      for (i = delay; i < endpos1; i += 32) {\n        // Round value, 0.5 in Q12.\n        int32x4_t out32x4_0 = vdupq_n_s32(2048);\n        int32x4_t out32x4_1 = vdupq_n_s32(2048);\n\n        // Unroll the loop 4 times.\n        for (j = 0; j < coefficients_length - 3; j += 4) {\n          int16x4_t coeff16x4 = vld1_s16(&coefficients[j]);\n          int16x8x4_t in16x8x4 = vld4q_s16(&data_in[i - j - 3]);\n\n          // Mul and accumulate low 64-bit data.\n          int16x4_t in16x4_0 = vget_low_s16(in16x8x4.val[0]);\n          int16x4_t in16x4_2 = vget_low_s16(in16x8x4.val[1]);\n          int16x4_t in16x4_4 = vget_low_s16(in16x8x4.val[2]);\n          int16x4_t in16x4_6 = vget_low_s16(in16x8x4.val[3]);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 3);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_2, coeff16x4, 2);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_4, coeff16x4, 1);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_6, coeff16x4, 0);\n\n          // Mul and accumulate high 64-bit data.\n          // TODO: vget_high_s16 need extra cost on ARM64. This could be\n          // replaced by vmlal_high_lane_s16. But for the interface of\n          // vmlal_high_lane_s16, there is a bug in gcc 4.9.\n          // This issue need to be tracked in the future.\n          int16x4_t in16x4_1 = vget_high_s16(in16x8x4.val[0]);\n          int16x4_t in16x4_3 = vget_high_s16(in16x8x4.val[1]);\n          int16x4_t in16x4_5 = vget_high_s16(in16x8x4.val[2]);\n          int16x4_t in16x4_7 = vget_high_s16(in16x8x4.val[3]);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 3);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_3, coeff16x4, 2);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_5, coeff16x4, 1);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_7, coeff16x4, 0);\n        }\n\n        for (; j < coefficients_length; j++) {\n          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);\n          int16x8x4_t in16x8x4 = vld4q_s16(&data_in[i - j]);\n\n          // Mul and accumulate low 64-bit data.\n          int16x4_t in16x4_0 = vget_low_s16(in16x8x4.val[0]);\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);\n\n          // Mul and accumulate high 64-bit data.\n          // TODO: vget_high_s16 need extra cost on ARM64. This could be\n          // replaced by vmlal_high_lane_s16. But for the interface of\n          // vmlal_high_lane_s16, there is a bug in gcc 4.9.\n          // This issue need to be tracked in the future.\n          int16x4_t in16x4_1 = vget_high_s16(in16x8x4.val[0]);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);\n        }\n\n        // Saturate and store the output.\n        int16x4_t out16x4_0 = vqshrn_n_s32(out32x4_0, 12);\n        int16x4_t out16x4_1 = vqshrn_n_s32(out32x4_1, 12);\n        vst1q_s16(data_out, vcombine_s16(out16x4_0, out16x4_1));\n        data_out += 8;\n      }\n      break;\n    }\n    default: {\n      for (i = delay; i < endpos1; i += factor * 8) {\n        // Round value, 0.5 in Q12.\n        int32x4_t out32x4_0 = vdupq_n_s32(2048);\n        int32x4_t out32x4_1 = vdupq_n_s32(2048);\n\n        for (j = 0; j < coefficients_length; j++) {\n          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);\n          int16x4_t in16x4_0 = vld1_dup_s16(&data_in[i - j]);\n          in16x4_0 = vld1_lane_s16(&data_in[i + factor - j], in16x4_0, 1);\n          in16x4_0 = vld1_lane_s16(&data_in[i + factor * 2 - j], in16x4_0, 2);\n          in16x4_0 = vld1_lane_s16(&data_in[i + factor * 3 - j], in16x4_0, 3);\n          int16x4_t in16x4_1 = vld1_dup_s16(&data_in[i + factor * 4 - j]);\n          in16x4_1 = vld1_lane_s16(&data_in[i + factor * 5 - j], in16x4_1, 1);\n          in16x4_1 = vld1_lane_s16(&data_in[i + factor * 6 - j], in16x4_1, 2);\n          in16x4_1 = vld1_lane_s16(&data_in[i + factor * 7 - j], in16x4_1, 3);\n\n          // Mul and accumulate.\n          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);\n          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);\n        }\n\n        // Saturate and store the output.\n        int16x4_t out16x4_0 = vqshrn_n_s32(out32x4_0, 12);\n        int16x4_t out16x4_1 = vqshrn_n_s32(out32x4_1, 12);\n        vst1q_s16(data_out, vcombine_s16(out16x4_0, out16x4_1));\n        data_out += 8;\n      }\n      break;\n    }\n  }\n\n  // Second part, do the rest iterations (if any).\n  for (; i < endpos; i += factor) {\n    out_s32 = 2048;  // Round value, 0.5 in Q12.\n\n    for (j = 0; j < coefficients_length; j++) {\n      out_s32 = WebRtc_MulAccumW16(coefficients[j], data_in[i - j], out_s32);\n    }\n\n    // Saturate and store the output.\n    out_s32 >>= 12;\n    *data_out++ = WebRtcSpl_SatW32ToW16(out_s32);\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/energy.c",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This file contains the function WebRtcSpl_Energy().\n * The description header can be found in signal_processing_library.h\n *\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\nint32_t WebRtcSpl_Energy(int16_t* vector,\n                         size_t vector_length,\n                         int* scale_factor)\n{\n    int32_t en = 0;\n    size_t i;\n    int scaling =\n        WebRtcSpl_GetScalingSquare(vector, vector_length, vector_length);\n    size_t looptimes = vector_length;\n    int16_t *vectorptr = vector;\n\n    for (i = 0; i < looptimes; i++)\n    {\n      en += (*vectorptr * *vectorptr) >> scaling;\n      vectorptr++;\n    }\n    *scale_factor = scaling;\n\n    return en;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/get_scaling_square.c",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This file contains the function WebRtcSpl_GetScalingSquare().\n * The description header can be found in signal_processing_library.h\n *\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\nint16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,\n                                   size_t in_vector_length,\n                                   size_t times)\n{\n    int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times);\n    size_t i;\n    int16_t smax = -1;\n    int16_t sabs;\n    int16_t *sptr = in_vector;\n    int16_t t;\n    size_t looptimes = in_vector_length;\n\n    for (i = looptimes; i > 0; i--)\n    {\n        sabs = (*sptr > 0 ? *sptr++ : -*sptr++);\n        smax = (sabs > smax ? sabs : smax);\n    }\n    t = WebRtcSpl_NormW32(WEBRTC_SPL_MUL(smax, smax));\n\n    if (smax == 0)\n    {\n        return 0; // Since norm(0) returns 0\n    } else\n    {\n        return (t > nbits) ? 0 : nbits - t;\n    }\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/real_fft.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_\n#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_\n\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// For ComplexFFT(), the maximum fft order is 10;\n// for OpenMax FFT in ARM, it is 12;\n// WebRTC APM uses orders of only 7 and 8.\nenum {kMaxFFTOrder = 10};\n\nstruct RealFFT;\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nstruct RealFFT* WebRtcSpl_CreateRealFFT(int order);\nvoid WebRtcSpl_FreeRealFFT(struct RealFFT* self);\n\n// Compute an FFT for a real-valued signal of length of 2^order,\n// where 1 < order <= MAX_FFT_ORDER. Transform length is determined by the\n// specification structure, which must be initialized prior to calling the FFT\n// function with WebRtcSpl_CreateRealFFT().\n// The relationship between the input and output sequences can\n// be expressed in terms of the DFT, i.e.:\n//     x[n] = (2^(-scalefactor)/N)  . SUM[k=0,...,N-1] X[k].e^(jnk.2.pi/N)\n//     n=0,1,2,...N-1\n//     N=2^order.\n// The conjugate-symmetric output sequence is represented using a CCS vector,\n// which is of length N+2, and is organized as follows:\n//     Index:      0  1  2  3  4  5   . . .   N-2       N-1       N       N+1\n//     Component:  R0 0  R1 I1 R2 I2  . . .   R[N/2-1]  I[N/2-1]  R[N/2]  0\n// where R[n] and I[n], respectively, denote the real and imaginary components\n// for FFT bin 'n'. Bins  are numbered from 0 to N/2, where N is the FFT length.\n// Bin index 0 corresponds to the DC component, and bin index N/2 corresponds to\n// the foldover frequency.\n//\n// Input Arguments:\n//   self - pointer to preallocated and initialized FFT specification structure.\n//   real_data_in - the input signal. For an ARM Neon platform, it must be\n//                  aligned on a 32-byte boundary.\n//\n// Output Arguments:\n//   complex_data_out - the output complex signal with (2^order + 2) 16-bit\n//                      elements. For an ARM Neon platform, it must be different\n//                      from real_data_in, and aligned on a 32-byte boundary.\n//\n// Return Value:\n//   0  - FFT calculation is successful.\n//   -1 - Error with bad arguments (null pointers).\nint WebRtcSpl_RealForwardFFT(struct RealFFT* self,\n                             const int16_t* real_data_in,\n                             int16_t* complex_data_out);\n\n// Compute the inverse FFT for a conjugate-symmetric input sequence of length of\n// 2^order, where 1 < order <= MAX_FFT_ORDER. Transform length is determined by\n// the specification structure, which must be initialized prior to calling the\n// FFT function with WebRtcSpl_CreateRealFFT().\n// For a transform of length M, the input sequence is represented using a packed\n// CCS vector of length M+2, which is explained in the comments for\n// WebRtcSpl_RealForwardFFTC above.\n//\n// Input Arguments:\n//   self - pointer to preallocated and initialized FFT specification structure.\n//   complex_data_in - the input complex signal with (2^order + 2) 16-bit\n//                     elements. For an ARM Neon platform, it must be aligned on\n//                     a 32-byte boundary.\n//\n// Output Arguments:\n//   real_data_out - the output real signal. For an ARM Neon platform, it must\n//                   be different to complex_data_in, and aligned on a 32-byte\n//                   boundary.\n//\n// Return Value:\n//   0 or a positive number - a value that the elements in the |real_data_out|\n//                            should be shifted left with in order to get\n//                            correct physical values.\n//   -1 - Error with bad arguments (null pointers).\nint WebRtcSpl_RealInverseFFT(struct RealFFT* self,\n                             const int16_t* complex_data_in,\n                             int16_t* real_data_out);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/signal_processing_library.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This header file includes all of the fix point signal processing library (SPL) function\n * descriptions and declarations.\n * For specific function calls, see bottom of file.\n */\n\n#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_\n#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_\n\n#include <string.h>\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// Macros specific for the fixed point implementation\n#define WEBRTC_SPL_WORD16_MAX       32767\n#define WEBRTC_SPL_WORD16_MIN       -32768\n#define WEBRTC_SPL_WORD32_MAX       (int32_t)0x7fffffff\n#define WEBRTC_SPL_WORD32_MIN       (int32_t)0x80000000\n#define WEBRTC_SPL_MAX_LPC_ORDER    14\n#define WEBRTC_SPL_MIN(A, B)        (A < B ? A : B)  // Get min value\n#define WEBRTC_SPL_MAX(A, B)        (A > B ? A : B)  // Get max value\n// TODO(kma/bjorn): For the next two macros, investigate how to correct the code\n// for inputs of a = WEBRTC_SPL_WORD16_MIN or WEBRTC_SPL_WORD32_MIN.\n#define WEBRTC_SPL_ABS_W16(a) \\\n    (((int16_t)a >= 0) ? ((int16_t)a) : -((int16_t)a))\n#define WEBRTC_SPL_ABS_W32(a) \\\n    (((int32_t)a >= 0) ? ((int32_t)a) : -((int32_t)a))\n\n#define WEBRTC_SPL_MUL(a, b) \\\n    ((int32_t) ((int32_t)(a) * (int32_t)(b)))\n#define WEBRTC_SPL_UMUL(a, b) \\\n    ((uint32_t) ((uint32_t)(a) * (uint32_t)(b)))\n#define WEBRTC_SPL_UMUL_32_16(a, b) \\\n    ((uint32_t) ((uint32_t)(a) * (uint16_t)(b)))\n#define WEBRTC_SPL_MUL_16_U16(a, b) \\\n    ((int32_t)(int16_t)(a) * (uint16_t)(b))\n\n#ifndef WEBRTC_ARCH_ARM_V7\n// For ARMv7 platforms, these are inline functions in spl_inl_armv7.h\n#ifndef MIPS32_LE\n// For MIPS platforms, these are inline functions in spl_inl_mips.h\n#define WEBRTC_SPL_MUL_16_16(a, b) \\\n    ((int32_t) (((int16_t)(a)) * ((int16_t)(b))))\n#define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \\\n    (WEBRTC_SPL_MUL_16_16(a, b >> 16) \\\n     + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15))\n#endif\n#endif\n\n#define WEBRTC_SPL_MUL_16_32_RSFT11(a, b)          \\\n  (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 5) + \\\n    (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))\n#define WEBRTC_SPL_MUL_16_32_RSFT14(a, b)          \\\n  (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 2) + \\\n    (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))\n#define WEBRTC_SPL_MUL_16_32_RSFT15(a, b)            \\\n  ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 1)) + \\\n    (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))\n\n#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \\\n    (WEBRTC_SPL_MUL_16_16(a, b) >> (c))\n\n#define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \\\n    ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) \\\n                                  (((int32_t)1) << ((c) - 1)))) >> (c))\n\n// C + the 32 most significant bits of A * B\n#define WEBRTC_SPL_SCALEDIFF32(A, B, C) \\\n    (C + (B >> 16) * A + (((uint32_t)(B & 0x0000FFFF) * A) >> 16))\n\n#define WEBRTC_SPL_SAT(a, b, c)         (b > a ? a : b < c ? c : b)\n\n// Shifting with negative numbers allowed\n// Positive means left shift\n#define WEBRTC_SPL_SHIFT_W32(x, c) ((c) >= 0 ? (x) * (1 << (c)) : (x) >> -(c))\n\n// Shifting with negative numbers not allowed\n// We cannot do casting here due to signed/unsigned problem\n#define WEBRTC_SPL_LSHIFT_W32(x, c)     ((x) << (c))\n\n#define WEBRTC_SPL_RSHIFT_U32(x, c)     ((uint32_t)(x) >> (c))\n\n#define WEBRTC_SPL_RAND(a) \\\n    ((int16_t)((((int16_t)a * 18816) >> 7) & 0x00007fff))\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \\\n  memcpy(v1, v2, (length) * sizeof(int16_t))\n\n// inline functions:\n#include \"common_audio/signal_processing/include/spl_inl.h\"\n\n// Initialize SPL. Currently it contains only function pointer initialization.\n// If the underlying platform is known to be ARM-Neon (WEBRTC_HAS_NEON defined),\n// the pointers will be assigned to code optimized for Neon; otherwise, generic\n// C code will be assigned.\n// Note that this function MUST be called in any application that uses SPL\n// functions.\nvoid WebRtcSpl_Init();\n\nint16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,\n                                   size_t in_vector_length,\n                                   size_t times);\n\n// Copy and set operations. Implementation in copy_set_operations.c.\n// Descriptions at bottom of file.\nvoid WebRtcSpl_MemSetW16(int16_t* vector,\n                         int16_t set_value,\n                         size_t vector_length);\nvoid WebRtcSpl_MemSetW32(int32_t* vector,\n                         int32_t set_value,\n                         size_t vector_length);\nvoid WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector,\n                                   int16_t* in_vector,\n                                   size_t vector_length);\nvoid WebRtcSpl_CopyFromEndW16(const int16_t* in_vector,\n                              size_t in_vector_length,\n                              size_t samples,\n                              int16_t* out_vector);\nvoid WebRtcSpl_ZerosArrayW16(int16_t* vector,\n                             size_t vector_length);\nvoid WebRtcSpl_ZerosArrayW32(int32_t* vector,\n                             size_t vector_length);\n// End: Copy and set operations.\n\n\n// Minimum and maximum operation functions and their pointers.\n// Implementation in min_max_operations.c.\n\n// Returns the largest absolute value in a signed 16-bit vector.\n//\n// Input:\n//      - vector : 16-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Maximum absolute value in vector.\ntypedef int16_t (*MaxAbsValueW16)(const int16_t* vector, size_t length);\nextern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;\nint16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length);\n#if defined(WEBRTC_HAS_NEON)\nint16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length);\n#endif\n#if defined(MIPS32_LE)\nint16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length);\n#endif\n\n// Returns the largest absolute value in a signed 32-bit vector.\n//\n// Input:\n//      - vector : 32-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Maximum absolute value in vector.\ntypedef int32_t (*MaxAbsValueW32)(const int32_t* vector, size_t length);\nextern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;\nint32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length);\n#if defined(WEBRTC_HAS_NEON)\nint32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length);\n#endif\n#if defined(MIPS_DSP_R1_LE)\nint32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length);\n#endif\n\n// Returns the maximum value of a 16-bit vector.\n//\n// Input:\n//      - vector : 16-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Maximum sample value in |vector|.\ntypedef int16_t (*MaxValueW16)(const int16_t* vector, size_t length);\nextern MaxValueW16 WebRtcSpl_MaxValueW16;\nint16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length);\n#if defined(WEBRTC_HAS_NEON)\nint16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length);\n#endif\n#if defined(MIPS32_LE)\nint16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length);\n#endif\n\n// Returns the maximum value of a 32-bit vector.\n//\n// Input:\n//      - vector : 32-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Maximum sample value in |vector|.\ntypedef int32_t (*MaxValueW32)(const int32_t* vector, size_t length);\nextern MaxValueW32 WebRtcSpl_MaxValueW32;\nint32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length);\n#if defined(WEBRTC_HAS_NEON)\nint32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length);\n#endif\n#if defined(MIPS32_LE)\nint32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length);\n#endif\n\n// Returns the minimum value of a 16-bit vector.\n//\n// Input:\n//      - vector : 16-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Minimum sample value in |vector|.\ntypedef int16_t (*MinValueW16)(const int16_t* vector, size_t length);\nextern MinValueW16 WebRtcSpl_MinValueW16;\nint16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length);\n#if defined(WEBRTC_HAS_NEON)\nint16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length);\n#endif\n#if defined(MIPS32_LE)\nint16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length);\n#endif\n\n// Returns the minimum value of a 32-bit vector.\n//\n// Input:\n//      - vector : 32-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Minimum sample value in |vector|.\ntypedef int32_t (*MinValueW32)(const int32_t* vector, size_t length);\nextern MinValueW32 WebRtcSpl_MinValueW32;\nint32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length);\n#if defined(WEBRTC_HAS_NEON)\nint32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length);\n#endif\n#if defined(MIPS32_LE)\nint32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length);\n#endif\n\n// Returns the vector index to the largest absolute value of a 16-bit vector.\n//\n// Input:\n//      - vector : 16-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Index to the maximum absolute value in vector.\n//                 If there are multiple equal maxima, return the index of the\n//                 first. -32768 will always have precedence over 32767 (despite\n//                 -32768 presenting an int16 absolute value of 32767).\nsize_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length);\n\n// Returns the vector index to the maximum sample value of a 16-bit vector.\n//\n// Input:\n//      - vector : 16-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Index to the maximum value in vector (if multiple\n//                 indexes have the maximum, return the first).\nsize_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length);\n\n// Returns the vector index to the maximum sample value of a 32-bit vector.\n//\n// Input:\n//      - vector : 32-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Index to the maximum value in vector (if multiple\n//                 indexes have the maximum, return the first).\nsize_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length);\n\n// Returns the vector index to the minimum sample value of a 16-bit vector.\n//\n// Input:\n//      - vector : 16-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Index to the mimimum value in vector  (if multiple\n//                 indexes have the minimum, return the first).\nsize_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length);\n\n// Returns the vector index to the minimum sample value of a 32-bit vector.\n//\n// Input:\n//      - vector : 32-bit input vector.\n//      - length : Number of samples in vector.\n//\n// Return value  : Index to the mimimum value in vector  (if multiple\n//                 indexes have the minimum, return the first).\nsize_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length);\n\n// End: Minimum and maximum operations.\n\n\n// Vector scaling operations. Implementation in vector_scaling_operations.c.\n// Description at bottom of file.\nvoid WebRtcSpl_VectorBitShiftW16(int16_t* out_vector,\n                                 size_t vector_length,\n                                 const int16_t* in_vector,\n                                 int16_t right_shifts);\nvoid WebRtcSpl_VectorBitShiftW32(int32_t* out_vector,\n                                 size_t vector_length,\n                                 const int32_t* in_vector,\n                                 int16_t right_shifts);\nvoid WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector,\n                                      size_t vector_length,\n                                      const int32_t* in_vector,\n                                      int right_shifts);\nvoid WebRtcSpl_ScaleVector(const int16_t* in_vector,\n                           int16_t* out_vector,\n                           int16_t gain,\n                           size_t vector_length,\n                           int16_t right_shifts);\nvoid WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector,\n                                  int16_t* out_vector,\n                                  int16_t gain,\n                                  size_t vector_length,\n                                  int16_t right_shifts);\nvoid WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1,\n                                  int16_t gain1, int right_shifts1,\n                                  const int16_t* in_vector2,\n                                  int16_t gain2, int right_shifts2,\n                                  int16_t* out_vector,\n                                  size_t vector_length);\n\n// The functions (with related pointer) perform the vector operation:\n//   out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k])\n//        + round_value) >> right_shifts,\n//   where  round_value = (1 << right_shifts) >> 1.\n//\n// Input:\n//      - in_vector1       : Input vector 1\n//      - in_vector1_scale : Gain to be used for vector 1\n//      - in_vector2       : Input vector 2\n//      - in_vector2_scale : Gain to be used for vector 2\n//      - right_shifts     : Number of right bit shifts to be applied\n//      - length           : Number of elements in the input vectors\n//\n// Output:\n//      - out_vector       : Output vector\n// Return value            : 0 if OK, -1 if (in_vector1 == null\n//                           || in_vector2 == null || out_vector == null\n//                           || length <= 0 || right_shift < 0).\ntypedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1,\n                                           int16_t in_vector1_scale,\n                                           const int16_t* in_vector2,\n                                           int16_t in_vector2_scale,\n                                           int right_shifts,\n                                           int16_t* out_vector,\n                                           size_t length);\nextern ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;\nint WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,\n                                           int16_t in_vector1_scale,\n                                           const int16_t* in_vector2,\n                                           int16_t in_vector2_scale,\n                                           int right_shifts,\n                                           int16_t* out_vector,\n                                           size_t length);\n#if defined(MIPS_DSP_R1_LE)\nint WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,\n                                               int16_t in_vector1_scale,\n                                               const int16_t* in_vector2,\n                                               int16_t in_vector2_scale,\n                                               int right_shifts,\n                                               int16_t* out_vector,\n                                               size_t length);\n#endif\n// End: Vector scaling operations.\n\n// iLBC specific functions. Implementations in ilbc_specific_functions.c.\n// Description at bottom of file.\nvoid WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector,\n                                             const int16_t* in_vector,\n                                             const int16_t* window,\n                                             size_t vector_length,\n                                             int16_t right_shifts);\nvoid WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector,\n                                     const int16_t* in_vector,\n                                     const int16_t* window,\n                                     size_t vector_length,\n                                     int16_t right_shifts);\nvoid WebRtcSpl_AddVectorsAndShift(int16_t* out_vector,\n                                  const int16_t* in_vector1,\n                                  const int16_t* in_vector2,\n                                  size_t vector_length,\n                                  int16_t right_shifts);\nvoid WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector,\n                                       int16_t* in_vector,\n                                       int16_t gain,\n                                       int32_t add_constant,\n                                       int16_t right_shifts,\n                                       size_t vector_length);\nvoid WebRtcSpl_AffineTransformVector(int16_t* out_vector,\n                                     int16_t* in_vector,\n                                     int16_t gain,\n                                     int32_t add_constant,\n                                     int16_t right_shifts,\n                                     size_t vector_length);\n// End: iLBC specific functions.\n\n// Signal processing operations.\n\n// A 32-bit fix-point implementation of auto-correlation computation\n//\n// Input:\n//      - in_vector        : Vector to calculate autocorrelation upon\n//      - in_vector_length : Length (in samples) of |vector|\n//      - order            : The order up to which the autocorrelation should be\n//                           calculated\n//\n// Output:\n//      - result           : auto-correlation values (values should be seen\n//                           relative to each other since the absolute values\n//                           might have been down shifted to avoid overflow)\n//\n//      - scale            : The number of left shifts required to obtain the\n//                           auto-correlation in Q0\n//\n// Return value            : Number of samples in |result|, i.e. (order+1)\nsize_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector,\n                                 size_t in_vector_length,\n                                 size_t order,\n                                 int32_t* result,\n                                 int* scale);\n\n// A 32-bit fix-point implementation of the Levinson-Durbin algorithm that\n// does NOT use the 64 bit class\n//\n// Input:\n//      - auto_corr : Vector with autocorrelation values of length >= |order|+1\n//      - order     : The LPC filter order (support up to order 20)\n//\n// Output:\n//      - lpc_coef  : lpc_coef[0..order] LPC coefficients in Q12\n//      - refl_coef : refl_coef[0...order-1]| Reflection coefficients in Q15\n//\n// Return value     : 1 for stable 0 for unstable\nint16_t WebRtcSpl_LevinsonDurbin(const int32_t* auto_corr,\n                                 int16_t* lpc_coef,\n                                 int16_t* refl_coef,\n                                 size_t order);\n\n// Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|.\n// This version is a 16 bit operation.\n//\n// NOTE: The 16 bit refl_coef -> lpc_coef conversion might result in a\n// \"slightly unstable\" filter (i.e., a pole just outside the unit circle) in\n// \"rare\" cases even if the reflection coefficients are stable.\n//\n// Input:\n//      - refl_coef : Reflection coefficients in Q15 that should be converted\n//                    to LPC coefficients\n//      - use_order : Number of coefficients in |refl_coef|\n//\n// Output:\n//      - lpc_coef  : LPC coefficients in Q12\nvoid WebRtcSpl_ReflCoefToLpc(const int16_t* refl_coef,\n                             int use_order,\n                             int16_t* lpc_coef);\n\n// Converts LPC coefficients |lpc_coef| to reflection coefficients |refl_coef|.\n// This version is a 16 bit operation.\n// The conversion is implemented by the step-down algorithm.\n//\n// Input:\n//      - lpc_coef  : LPC coefficients in Q12, that should be converted to\n//                    reflection coefficients\n//      - use_order : Number of coefficients in |lpc_coef|\n//\n// Output:\n//      - refl_coef : Reflection coefficients in Q15.\nvoid WebRtcSpl_LpcToReflCoef(int16_t* lpc_coef,\n                             int use_order,\n                             int16_t* refl_coef);\n\n// Calculates reflection coefficients (16 bit) from auto-correlation values\n//\n// Input:\n//      - auto_corr : Auto-correlation values\n//      - use_order : Number of coefficients wanted be calculated\n//\n// Output:\n//      - refl_coef : Reflection coefficients in Q15.\nvoid WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr,\n                                  int use_order,\n                                  int16_t* refl_coef);\n\n// The functions (with related pointer) calculate the cross-correlation between\n// two sequences |seq1| and |seq2|.\n// |seq1| is fixed and |seq2| slides as the pointer is increased with the\n// amount |step_seq2|. Note the arguments should obey the relationship:\n// |dim_seq| - 1 + |step_seq2| * (|dim_cross_correlation| - 1) <\n//      buffer size of |seq2|\n//\n// Input:\n//      - seq1           : First sequence (fixed throughout the correlation)\n//      - seq2           : Second sequence (slides |step_vector2| for each\n//                            new correlation)\n//      - dim_seq        : Number of samples to use in the cross-correlation\n//      - dim_cross_correlation : Number of cross-correlations to calculate (the\n//                            start position for |vector2| is updated for each\n//                            new one)\n//      - right_shifts   : Number of right bit shifts to use. This will\n//                            become the output Q-domain.\n//      - step_seq2      : How many (positive or negative) steps the\n//                            |vector2| pointer should be updated for each new\n//                            cross-correlation value.\n//\n// Output:\n//      - cross_correlation : The cross-correlation in Q(-right_shifts)\ntypedef void (*CrossCorrelation)(int32_t* cross_correlation,\n                                 const int16_t* seq1,\n                                 const int16_t* seq2,\n                                 size_t dim_seq,\n                                 size_t dim_cross_correlation,\n                                 int right_shifts,\n                                 int step_seq2);\nextern CrossCorrelation WebRtcSpl_CrossCorrelation;\nvoid WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,\n                                 const int16_t* seq1,\n                                 const int16_t* seq2,\n                                 size_t dim_seq,\n                                 size_t dim_cross_correlation,\n                                 int right_shifts,\n                                 int step_seq2);\n#if defined(WEBRTC_HAS_NEON)\nvoid WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,\n                                    const int16_t* seq1,\n                                    const int16_t* seq2,\n                                    size_t dim_seq,\n                                    size_t dim_cross_correlation,\n                                    int right_shifts,\n                                    int step_seq2);\n#endif\n#if defined(MIPS32_LE)\nvoid WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,\n                                     const int16_t* seq1,\n                                     const int16_t* seq2,\n                                     size_t dim_seq,\n                                     size_t dim_cross_correlation,\n                                     int right_shifts,\n                                     int step_seq2);\n#endif\n\n// Creates (the first half of) a Hanning window. Size must be at least 1 and\n// at most 512.\n//\n// Input:\n//      - size      : Length of the requested Hanning window (1 to 512)\n//\n// Output:\n//      - window    : Hanning vector in Q14.\nvoid WebRtcSpl_GetHanningWindow(int16_t* window, size_t size);\n\n// Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector\n// |in_vector|. Input and output values are in Q15.\n//\n// Inputs:\n//      - in_vector     : Values to calculate sqrt(1 - x^2) of\n//      - vector_length : Length of vector |in_vector|\n//\n// Output:\n//      - out_vector    : Output values in Q15\nvoid WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,\n                                      size_t vector_length,\n                                      int16_t* out_vector);\n// End: Signal processing operations.\n\n// Randomization functions. Implementations collected in\n// randomization_functions.c and descriptions at bottom of this file.\nint16_t WebRtcSpl_RandU(uint32_t* seed);\nint16_t WebRtcSpl_RandN(uint32_t* seed);\nint16_t WebRtcSpl_RandUArray(int16_t* vector,\n                             int16_t vector_length,\n                             uint32_t* seed);\n// End: Randomization functions.\n\n// Math functions\nint32_t WebRtcSpl_Sqrt(int32_t value);\nint32_t WebRtcSpl_SqrtFloor(int32_t value);\n\n// Divisions. Implementations collected in division_operations.c and\n// descriptions at bottom of this file.\nuint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den);\nint32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den);\nint16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den);\nint32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den);\nint32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low);\n// End: Divisions.\n\nint32_t WebRtcSpl_Energy(int16_t* vector,\n                         size_t vector_length,\n                         int* scale_factor);\n\n// Filter operations.\nsize_t WebRtcSpl_FilterAR(const int16_t* ar_coef,\n                          size_t ar_coef_length,\n                          const int16_t* in_vector,\n                          size_t in_vector_length,\n                          int16_t* filter_state,\n                          size_t filter_state_length,\n                          int16_t* filter_state_low,\n                          size_t filter_state_low_length,\n                          int16_t* out_vector,\n                          int16_t* out_vector_low,\n                          size_t out_vector_low_length);\n\n// WebRtcSpl_FilterMAFastQ12(...)\n//\n// Performs a MA filtering on a vector in Q12\n//\n// Input:\n//      - in_vector         : Input samples (state in positions\n//                            in_vector[-order] .. in_vector[-1])\n//      - ma_coef           : Filter coefficients (in Q12)\n//      - ma_coef_length    : Number of B coefficients (order+1)\n//      - vector_length     : Number of samples to be filtered\n//\n// Output:\n//      - out_vector        : Filtered samples\n//\nvoid WebRtcSpl_FilterMAFastQ12(const int16_t* in_vector,\n                               int16_t* out_vector,\n                               const int16_t* ma_coef,\n                               size_t ma_coef_length,\n                               size_t vector_length);\n\n// Performs a AR filtering on a vector in Q12\n// Input:\n//      - data_in            : Input samples\n//      - data_out           : State information in positions\n//                               data_out[-order] .. data_out[-1]\n//      - coefficients       : Filter coefficients (in Q12)\n//      - coefficients_length: Number of coefficients (order+1)\n//      - data_length        : Number of samples to be filtered\n// Output:\n//      - data_out           : Filtered samples\nvoid WebRtcSpl_FilterARFastQ12(const int16_t* data_in,\n                               int16_t* data_out,\n                               const int16_t* __restrict coefficients,\n                               size_t coefficients_length,\n                               size_t data_length);\n\n// The functions (with related pointer) perform a MA down sampling filter\n// on a vector.\n// Input:\n//      - data_in            : Input samples (state in positions\n//                               data_in[-order] .. data_in[-1])\n//      - data_in_length     : Number of samples in |data_in| to be filtered.\n//                               This must be at least\n//                               |delay| + |factor|*(|out_vector_length|-1) + 1)\n//      - data_out_length    : Number of down sampled samples desired\n//      - coefficients       : Filter coefficients (in Q12)\n//      - coefficients_length: Number of coefficients (order+1)\n//      - factor             : Decimation factor\n//      - delay              : Delay of filter (compensated for in out_vector)\n// Output:\n//      - data_out           : Filtered samples\n// Return value              : 0 if OK, -1 if |in_vector| is too short\ntypedef int (*DownsampleFast)(const int16_t* data_in,\n                              size_t data_in_length,\n                              int16_t* data_out,\n                              size_t data_out_length,\n                              const int16_t* __restrict coefficients,\n                              size_t coefficients_length,\n                              int factor,\n                              size_t delay);\nextern DownsampleFast WebRtcSpl_DownsampleFast;\nint WebRtcSpl_DownsampleFastC(const int16_t* data_in,\n                              size_t data_in_length,\n                              int16_t* data_out,\n                              size_t data_out_length,\n                              const int16_t* __restrict coefficients,\n                              size_t coefficients_length,\n                              int factor,\n                              size_t delay);\n#if defined(WEBRTC_HAS_NEON)\nint WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,\n                                 size_t data_in_length,\n                                 int16_t* data_out,\n                                 size_t data_out_length,\n                                 const int16_t* __restrict coefficients,\n                                 size_t coefficients_length,\n                                 int factor,\n                                 size_t delay);\n#endif\n#if defined(MIPS32_LE)\nint WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,\n                                  size_t data_in_length,\n                                  int16_t* data_out,\n                                  size_t data_out_length,\n                                  const int16_t* __restrict coefficients,\n                                  size_t coefficients_length,\n                                  int factor,\n                                  size_t delay);\n#endif\n\n// End: Filter operations.\n\n// FFT operations\n\nint WebRtcSpl_ComplexFFT(int16_t vector[], int stages, int mode);\nint WebRtcSpl_ComplexIFFT(int16_t vector[], int stages, int mode);\n\n// Treat a 16-bit complex data buffer |complex_data| as an array of 32-bit\n// values, and swap elements whose indexes are bit-reverses of each other.\n//\n// Input:\n//      - complex_data  : Complex data buffer containing 2^|stages| real\n//                        elements interleaved with 2^|stages| imaginary\n//                        elements: [Re Im Re Im Re Im....]\n//      - stages        : Number of FFT stages. Must be at least 3 and at most\n//                        10, since the table WebRtcSpl_kSinTable1024[] is 1024\n//                        elements long.\n//\n// Output:\n//      - complex_data  : The complex data buffer.\n\nvoid WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages);\n\n// End: FFT operations\n\n/************************************************************\n *\n * RESAMPLING FUNCTIONS AND THEIR STRUCTS ARE DEFINED BELOW\n *\n ************************************************************/\n\n/*******************************************************************\n * resample.c\n *\n * Includes the following resampling combinations\n * 22 kHz -> 16 kHz\n * 16 kHz -> 22 kHz\n * 22 kHz ->  8 kHz\n *  8 kHz -> 22 kHz\n *\n ******************************************************************/\n\n// state structure for 22 -> 16 resampler\ntypedef struct {\n  int32_t S_22_44[8];\n  int32_t S_44_32[8];\n  int32_t S_32_16[8];\n} WebRtcSpl_State22khzTo16khz;\n\nvoid WebRtcSpl_Resample22khzTo16khz(const int16_t* in,\n                                    int16_t* out,\n                                    WebRtcSpl_State22khzTo16khz* state,\n                                    int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample22khzTo16khz(WebRtcSpl_State22khzTo16khz* state);\n\n// state structure for 16 -> 22 resampler\ntypedef struct {\n  int32_t S_16_32[8];\n  int32_t S_32_22[8];\n} WebRtcSpl_State16khzTo22khz;\n\nvoid WebRtcSpl_Resample16khzTo22khz(const int16_t* in,\n                                    int16_t* out,\n                                    WebRtcSpl_State16khzTo22khz* state,\n                                    int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample16khzTo22khz(WebRtcSpl_State16khzTo22khz* state);\n\n// state structure for 22 -> 8 resampler\ntypedef struct {\n  int32_t S_22_22[16];\n  int32_t S_22_16[8];\n  int32_t S_16_8[8];\n} WebRtcSpl_State22khzTo8khz;\n\nvoid WebRtcSpl_Resample22khzTo8khz(const int16_t* in, int16_t* out,\n                                   WebRtcSpl_State22khzTo8khz* state,\n                                   int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample22khzTo8khz(WebRtcSpl_State22khzTo8khz* state);\n\n// state structure for 8 -> 22 resampler\ntypedef struct {\n  int32_t S_8_16[8];\n  int32_t S_16_11[8];\n  int32_t S_11_22[8];\n} WebRtcSpl_State8khzTo22khz;\n\nvoid WebRtcSpl_Resample8khzTo22khz(const int16_t* in, int16_t* out,\n                                   WebRtcSpl_State8khzTo22khz* state,\n                                   int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state);\n\n/*******************************************************************\n * resample_fractional.c\n * Functions for internal use in the other resample functions\n *\n * Includes the following resampling combinations\n * 48 kHz -> 32 kHz\n * 32 kHz -> 24 kHz\n * 44 kHz -> 32 kHz\n *\n ******************************************************************/\n\nvoid WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out, size_t K);\n\nvoid WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out, size_t K);\n\nvoid WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out, size_t K);\n\n/*******************************************************************\n * resample_48khz.c\n *\n * Includes the following resampling combinations\n * 48 kHz -> 16 kHz\n * 16 kHz -> 48 kHz\n * 48 kHz ->  8 kHz\n *  8 kHz -> 48 kHz\n *\n ******************************************************************/\n\ntypedef struct {\n  int32_t S_48_48[16];\n  int32_t S_48_32[8];\n  int32_t S_32_16[8];\n} WebRtcSpl_State48khzTo16khz;\n\nvoid WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,\n                                    WebRtcSpl_State48khzTo16khz* state,\n                                    int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state);\n\ntypedef struct {\n  int32_t S_16_32[8];\n  int32_t S_32_24[8];\n  int32_t S_24_48[8];\n} WebRtcSpl_State16khzTo48khz;\n\nvoid WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,\n                                    WebRtcSpl_State16khzTo48khz* state,\n                                    int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state);\n\ntypedef struct {\n  int32_t S_48_24[8];\n  int32_t S_24_24[16];\n  int32_t S_24_16[8];\n  int32_t S_16_8[8];\n} WebRtcSpl_State48khzTo8khz;\n\nvoid WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,\n                                   WebRtcSpl_State48khzTo8khz* state,\n                                   int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state);\n\ntypedef struct {\n  int32_t S_8_16[8];\n  int32_t S_16_12[8];\n  int32_t S_12_24[8];\n  int32_t S_24_48[8];\n} WebRtcSpl_State8khzTo48khz;\n\nvoid WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,\n                                   WebRtcSpl_State8khzTo48khz* state,\n                                   int32_t* tmpmem);\n\nvoid WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state);\n\n/*******************************************************************\n * resample_by_2.c\n *\n * Includes down and up sampling by a factor of two.\n *\n ******************************************************************/\n\nvoid WebRtcSpl_DownsampleBy2(const int16_t* in, size_t len,\n                             int16_t* out, int32_t* filtState);\n\nvoid WebRtcSpl_UpsampleBy2(const int16_t* in, size_t len,\n                           int16_t* out, int32_t* filtState);\n\n/************************************************************\n * END OF RESAMPLING FUNCTIONS\n ************************************************************/\nvoid WebRtcSpl_AnalysisQMF(const int16_t* in_data,\n                           size_t in_data_length,\n                           int16_t* low_band,\n                           int16_t* high_band,\n                           int32_t* filter_state1,\n                           int32_t* filter_state2);\nvoid WebRtcSpl_SynthesisQMF(const int16_t* low_band,\n                            const int16_t* high_band,\n                            size_t band_length,\n                            int16_t* out_data,\n                            int32_t* filter_state1,\n                            int32_t* filter_state2);\n\n#ifdef __cplusplus\n}\n#endif  // __cplusplus\n#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_\n\n//\n// WebRtcSpl_AddSatW16(...)\n// WebRtcSpl_AddSatW32(...)\n//\n// Returns the result of a saturated 16-bit, respectively 32-bit, addition of\n// the numbers specified by the |var1| and |var2| parameters.\n//\n// Input:\n//      - var1      : Input variable 1\n//      - var2      : Input variable 2\n//\n// Return value     : Added and saturated value\n//\n\n//\n// WebRtcSpl_SubSatW16(...)\n// WebRtcSpl_SubSatW32(...)\n//\n// Returns the result of a saturated 16-bit, respectively 32-bit, subtraction\n// of the numbers specified by the |var1| and |var2| parameters.\n//\n// Input:\n//      - var1      : Input variable 1\n//      - var2      : Input variable 2\n//\n// Returned value   : Subtracted and saturated value\n//\n\n//\n// WebRtcSpl_GetSizeInBits(...)\n//\n// Returns the # of bits that are needed at the most to represent the number\n// specified by the |value| parameter.\n//\n// Input:\n//      - value     : Input value\n//\n// Return value     : Number of bits needed to represent |value|\n//\n\n//\n// WebRtcSpl_NormW32(...)\n//\n// Norm returns the # of left shifts required to 32-bit normalize the 32-bit\n// signed number specified by the |value| parameter.\n//\n// Input:\n//      - value     : Input value\n//\n// Return value     : Number of bit shifts needed to 32-bit normalize |value|\n//\n\n//\n// WebRtcSpl_NormW16(...)\n//\n// Norm returns the # of left shifts required to 16-bit normalize the 16-bit\n// signed number specified by the |value| parameter.\n//\n// Input:\n//      - value     : Input value\n//\n// Return value     : Number of bit shifts needed to 32-bit normalize |value|\n//\n\n//\n// WebRtcSpl_NormU32(...)\n//\n// Norm returns the # of left shifts required to 32-bit normalize the unsigned\n// 32-bit number specified by the |value| parameter.\n//\n// Input:\n//      - value     : Input value\n//\n// Return value     : Number of bit shifts needed to 32-bit normalize |value|\n//\n\n//\n// WebRtcSpl_GetScalingSquare(...)\n//\n// Returns the # of bits required to scale the samples specified in the\n// |in_vector| parameter so that, if the squares of the samples are added the\n// # of times specified by the |times| parameter, the 32-bit addition will not\n// overflow (result in int32_t).\n//\n// Input:\n//      - in_vector         : Input vector to check scaling on\n//      - in_vector_length  : Samples in |in_vector|\n//      - times             : Number of additions to be performed\n//\n// Return value             : Number of right bit shifts needed to avoid\n//                            overflow in the addition calculation\n//\n\n//\n// WebRtcSpl_MemSetW16(...)\n//\n// Sets all the values in the int16_t vector |vector| of length\n// |vector_length| to the specified value |set_value|\n//\n// Input:\n//      - vector        : Pointer to the int16_t vector\n//      - set_value     : Value specified\n//      - vector_length : Length of vector\n//\n\n//\n// WebRtcSpl_MemSetW32(...)\n//\n// Sets all the values in the int32_t vector |vector| of length\n// |vector_length| to the specified value |set_value|\n//\n// Input:\n//      - vector        : Pointer to the int16_t vector\n//      - set_value     : Value specified\n//      - vector_length : Length of vector\n//\n\n//\n// WebRtcSpl_MemCpyReversedOrder(...)\n//\n// Copies all the values from the source int16_t vector |in_vector| to a\n// destination int16_t vector |out_vector|. It is done in reversed order,\n// meaning that the first sample of |in_vector| is copied to the last sample of\n// the |out_vector|. The procedure continues until the last sample of\n// |in_vector| has been copied to the first sample of |out_vector|. This\n// creates a reversed vector. Used in e.g. prediction in iLBC.\n//\n// Input:\n//      - in_vector     : Pointer to the first sample in a int16_t vector\n//                        of length |length|\n//      - vector_length : Number of elements to copy\n//\n// Output:\n//      - out_vector    : Pointer to the last sample in a int16_t vector\n//                        of length |length|\n//\n\n//\n// WebRtcSpl_CopyFromEndW16(...)\n//\n// Copies the rightmost |samples| of |in_vector| (of length |in_vector_length|)\n// to the vector |out_vector|.\n//\n// Input:\n//      - in_vector         : Input vector\n//      - in_vector_length  : Number of samples in |in_vector|\n//      - samples           : Number of samples to extract (from right side)\n//                            from |in_vector|\n//\n// Output:\n//      - out_vector        : Vector with the requested samples\n//\n\n//\n// WebRtcSpl_ZerosArrayW16(...)\n// WebRtcSpl_ZerosArrayW32(...)\n//\n// Inserts the value \"zero\" in all positions of a w16 and a w32 vector\n// respectively.\n//\n// Input:\n//      - vector_length : Number of samples in vector\n//\n// Output:\n//      - vector        : Vector containing all zeros\n//\n\n//\n// WebRtcSpl_VectorBitShiftW16(...)\n// WebRtcSpl_VectorBitShiftW32(...)\n//\n// Bit shifts all the values in a vector up or downwards. Different calls for\n// int16_t and int32_t vectors respectively.\n//\n// Input:\n//      - vector_length : Length of vector\n//      - in_vector     : Pointer to the vector that should be bit shifted\n//      - right_shifts  : Number of right bit shifts (negative value gives left\n//                        shifts)\n//\n// Output:\n//      - out_vector    : Pointer to the result vector (can be the same as\n//                        |in_vector|)\n//\n\n//\n// WebRtcSpl_VectorBitShiftW32ToW16(...)\n//\n// Bit shifts all the values in a int32_t vector up or downwards and\n// stores the result as an int16_t vector. The function will saturate the\n// signal if needed, before storing in the output vector.\n//\n// Input:\n//      - vector_length : Length of vector\n//      - in_vector     : Pointer to the vector that should be bit shifted\n//      - right_shifts  : Number of right bit shifts (negative value gives left\n//                        shifts)\n//\n// Output:\n//      - out_vector    : Pointer to the result vector (can be the same as\n//                        |in_vector|)\n//\n\n//\n// WebRtcSpl_ScaleVector(...)\n//\n// Performs the vector operation:\n//  out_vector[k] = (gain*in_vector[k])>>right_shifts\n//\n// Input:\n//      - in_vector     : Input vector\n//      - gain          : Scaling gain\n//      - vector_length : Elements in the |in_vector|\n//      - right_shifts  : Number of right bit shifts applied\n//\n// Output:\n//      - out_vector    : Output vector (can be the same as |in_vector|)\n//\n\n//\n// WebRtcSpl_ScaleVectorWithSat(...)\n//\n// Performs the vector operation:\n//  out_vector[k] = SATURATE( (gain*in_vector[k])>>right_shifts )\n//\n// Input:\n//      - in_vector     : Input vector\n//      - gain          : Scaling gain\n//      - vector_length : Elements in the |in_vector|\n//      - right_shifts  : Number of right bit shifts applied\n//\n// Output:\n//      - out_vector    : Output vector (can be the same as |in_vector|)\n//\n\n//\n// WebRtcSpl_ScaleAndAddVectors(...)\n//\n// Performs the vector operation:\n//  out_vector[k] = (gain1*in_vector1[k])>>right_shifts1\n//                  + (gain2*in_vector2[k])>>right_shifts2\n//\n// Input:\n//      - in_vector1    : Input vector 1\n//      - gain1         : Gain to be used for vector 1\n//      - right_shifts1 : Right bit shift to be used for vector 1\n//      - in_vector2    : Input vector 2\n//      - gain2         : Gain to be used for vector 2\n//      - right_shifts2 : Right bit shift to be used for vector 2\n//      - vector_length : Elements in the input vectors\n//\n// Output:\n//      - out_vector    : Output vector\n//\n\n//\n// WebRtcSpl_ReverseOrderMultArrayElements(...)\n//\n// Performs the vector operation:\n//  out_vector[n] = (in_vector[n]*window[-n])>>right_shifts\n//\n// Input:\n//      - in_vector     : Input vector\n//      - window        : Window vector (should be reversed). The pointer\n//                        should be set to the last value in the vector\n//      - right_shifts  : Number of right bit shift to be applied after the\n//                        multiplication\n//      - vector_length : Number of elements in |in_vector|\n//\n// Output:\n//      - out_vector    : Output vector (can be same as |in_vector|)\n//\n\n//\n// WebRtcSpl_ElementwiseVectorMult(...)\n//\n// Performs the vector operation:\n//  out_vector[n] = (in_vector[n]*window[n])>>right_shifts\n//\n// Input:\n//      - in_vector     : Input vector\n//      - window        : Window vector.\n//      - right_shifts  : Number of right bit shift to be applied after the\n//                        multiplication\n//      - vector_length : Number of elements in |in_vector|\n//\n// Output:\n//      - out_vector    : Output vector (can be same as |in_vector|)\n//\n\n//\n// WebRtcSpl_AddVectorsAndShift(...)\n//\n// Performs the vector operation:\n//  out_vector[k] = (in_vector1[k] + in_vector2[k])>>right_shifts\n//\n// Input:\n//      - in_vector1    : Input vector 1\n//      - in_vector2    : Input vector 2\n//      - right_shifts  : Number of right bit shift to be applied after the\n//                        multiplication\n//      - vector_length : Number of elements in |in_vector1| and |in_vector2|\n//\n// Output:\n//      - out_vector    : Output vector (can be same as |in_vector1|)\n//\n\n//\n// WebRtcSpl_AddAffineVectorToVector(...)\n//\n// Adds an affine transformed vector to another vector |out_vector|, i.e,\n// performs\n//  out_vector[k] += (in_vector[k]*gain+add_constant)>>right_shifts\n//\n// Input:\n//      - in_vector     : Input vector\n//      - gain          : Gain value, used to multiply the in vector with\n//      - add_constant  : Constant value to add (usually 1<<(right_shifts-1),\n//                        but others can be used as well\n//      - right_shifts  : Number of right bit shifts (0-16)\n//      - vector_length : Number of samples in |in_vector| and |out_vector|\n//\n// Output:\n//      - out_vector    : Vector with the output\n//\n\n//\n// WebRtcSpl_AffineTransformVector(...)\n//\n// Affine transforms a vector, i.e, performs\n//  out_vector[k] = (in_vector[k]*gain+add_constant)>>right_shifts\n//\n// Input:\n//      - in_vector     : Input vector\n//      - gain          : Gain value, used to multiply the in vector with\n//      - add_constant  : Constant value to add (usually 1<<(right_shifts-1),\n//                        but others can be used as well\n//      - right_shifts  : Number of right bit shifts (0-16)\n//      - vector_length : Number of samples in |in_vector| and |out_vector|\n//\n// Output:\n//      - out_vector    : Vector with the output\n//\n\n//\n// WebRtcSpl_IncreaseSeed(...)\n//\n// Increases the seed (and returns the new value)\n//\n// Input:\n//      - seed      : Seed for random calculation\n//\n// Output:\n//      - seed      : Updated seed value\n//\n// Return value     : The new seed value\n//\n\n//\n// WebRtcSpl_RandU(...)\n//\n// Produces a uniformly distributed value in the int16_t range\n//\n// Input:\n//      - seed      : Seed for random calculation\n//\n// Output:\n//      - seed      : Updated seed value\n//\n// Return value     : Uniformly distributed value in the range\n//                    [Word16_MIN...Word16_MAX]\n//\n\n//\n// WebRtcSpl_RandN(...)\n//\n// Produces a normal distributed value in the int16_t range\n//\n// Input:\n//      - seed      : Seed for random calculation\n//\n// Output:\n//      - seed      : Updated seed value\n//\n// Return value     : N(0,1) value in the Q13 domain\n//\n\n//\n// WebRtcSpl_RandUArray(...)\n//\n// Produces a uniformly distributed vector with elements in the int16_t\n// range\n//\n// Input:\n//      - vector_length : Samples wanted in the vector\n//      - seed          : Seed for random calculation\n//\n// Output:\n//      - vector        : Vector with the uniform values\n//      - seed          : Updated seed value\n//\n// Return value         : Number of samples in vector, i.e., |vector_length|\n//\n\n//\n// WebRtcSpl_Sqrt(...)\n//\n// Returns the square root of the input value |value|. The precision of this\n// function is integer precision, i.e., sqrt(8) gives 2 as answer.\n// If |value| is a negative number then 0 is returned.\n//\n// Algorithm:\n//\n// A sixth order Taylor Series expansion is used here to compute the square\n// root of a number y^0.5 = (1+x)^0.5\n// where\n// x = y-1\n//   = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5)\n// 0.5 <= x < 1\n//\n// Input:\n//      - value     : Value to calculate sqrt of\n//\n// Return value     : Result of the sqrt calculation\n//\n\n//\n// WebRtcSpl_SqrtFloor(...)\n//\n// Returns the square root of the input value |value|. The precision of this\n// function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer.\n// If |value| is a negative number then 0 is returned.\n//\n// Algorithm:\n//\n// An iterative 4 cylce/bit routine\n//\n// Input:\n//      - value     : Value to calculate sqrt of\n//\n// Return value     : Result of the sqrt calculation\n//\n\n//\n// WebRtcSpl_DivU32U16(...)\n//\n// Divides a uint32_t |num| by a uint16_t |den|.\n//\n// If |den|==0, (uint32_t)0xFFFFFFFF is returned.\n//\n// Input:\n//      - num       : Numerator\n//      - den       : Denominator\n//\n// Return value     : Result of the division (as a uint32_t), i.e., the\n//                    integer part of num/den.\n//\n\n//\n// WebRtcSpl_DivW32W16(...)\n//\n// Divides a int32_t |num| by a int16_t |den|.\n//\n// If |den|==0, (int32_t)0x7FFFFFFF is returned.\n//\n// Input:\n//      - num       : Numerator\n//      - den       : Denominator\n//\n// Return value     : Result of the division (as a int32_t), i.e., the\n//                    integer part of num/den.\n//\n\n//\n// WebRtcSpl_DivW32W16ResW16(...)\n//\n// Divides a int32_t |num| by a int16_t |den|, assuming that the\n// result is less than 32768, otherwise an unpredictable result will occur.\n//\n// If |den|==0, (int16_t)0x7FFF is returned.\n//\n// Input:\n//      - num       : Numerator\n//      - den       : Denominator\n//\n// Return value     : Result of the division (as a int16_t), i.e., the\n//                    integer part of num/den.\n//\n\n//\n// WebRtcSpl_DivResultInQ31(...)\n//\n// Divides a int32_t |num| by a int16_t |den|, assuming that the\n// absolute value of the denominator is larger than the numerator, otherwise\n// an unpredictable result will occur.\n//\n// Input:\n//      - num       : Numerator\n//      - den       : Denominator\n//\n// Return value     : Result of the division in Q31.\n//\n\n//\n// WebRtcSpl_DivW32HiLow(...)\n//\n// Divides a int32_t |num| by a denominator in hi, low format. The\n// absolute value of the denominator has to be larger (or equal to) the\n// numerator.\n//\n// Input:\n//      - num       : Numerator\n//      - den_hi    : High part of denominator\n//      - den_low   : Low part of denominator\n//\n// Return value     : Divided value in Q31\n//\n\n//\n// WebRtcSpl_Energy(...)\n//\n// Calculates the energy of a vector\n//\n// Input:\n//      - vector        : Vector which the energy should be calculated on\n//      - vector_length : Number of samples in vector\n//\n// Output:\n//      - scale_factor  : Number of left bit shifts needed to get the physical\n//                        energy value, i.e, to get the Q0 value\n//\n// Return value         : Energy value in Q(-|scale_factor|)\n//\n\n//\n// WebRtcSpl_FilterAR(...)\n//\n// Performs a 32-bit AR filtering on a vector in Q12\n//\n// Input:\n//  - ar_coef                   : AR-coefficient vector (values in Q12),\n//                                ar_coef[0] must be 4096.\n//  - ar_coef_length            : Number of coefficients in |ar_coef|.\n//  - in_vector                 : Vector to be filtered.\n//  - in_vector_length          : Number of samples in |in_vector|.\n//  - filter_state              : Current state (higher part) of the filter.\n//  - filter_state_length       : Length (in samples) of |filter_state|.\n//  - filter_state_low          : Current state (lower part) of the filter.\n//  - filter_state_low_length   : Length (in samples) of |filter_state_low|.\n//  - out_vector_low_length     : Maximum length (in samples) of\n//                                |out_vector_low|.\n//\n// Output:\n//  - filter_state              : Updated state (upper part) vector.\n//  - filter_state_low          : Updated state (lower part) vector.\n//  - out_vector                : Vector containing the upper part of the\n//                                filtered values.\n//  - out_vector_low            : Vector containing the lower part of the\n//                                filtered values.\n//\n// Return value                 : Number of samples in the |out_vector|.\n//\n\n//\n// WebRtcSpl_ComplexIFFT(...)\n//\n// Complex Inverse FFT\n//\n// Computes an inverse complex 2^|stages|-point FFT on the input vector, which\n// is in bit-reversed order. The original content of the vector is destroyed in\n// the process, since the input is overwritten by the output, normal-ordered,\n// FFT vector. With X as the input complex vector, y as the output complex\n// vector and with M = 2^|stages|, the following is computed:\n//\n//        M-1\n// y(k) = sum[X(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]\n//        i=0\n//\n// The implementations are optimized for speed, not for code size. It uses the\n// decimation-in-time algorithm with radix-2 butterfly technique.\n//\n// Input:\n//      - vector    : In pointer to complex vector containing 2^|stages|\n//                    real elements interleaved with 2^|stages| imaginary\n//                    elements.\n//                    [ReImReImReIm....]\n//                    The elements are in Q(-scale) domain, see more on Return\n//                    Value below.\n//\n//      - stages    : Number of FFT stages. Must be at least 3 and at most 10,\n//                    since the table WebRtcSpl_kSinTable1024[] is 1024\n//                    elements long.\n//\n//      - mode      : This parameter gives the user to choose how the FFT\n//                    should work.\n//                    mode==0: Low-complexity and Low-accuracy mode\n//                    mode==1: High-complexity and High-accuracy mode\n//\n// Output:\n//      - vector    : Out pointer to the FFT vector (the same as input).\n//\n// Return Value     : The scale value that tells the number of left bit shifts\n//                    that the elements in the |vector| should be shifted with\n//                    in order to get Q0 values, i.e. the physically correct\n//                    values. The scale parameter is always 0 or positive,\n//                    except if N>1024 (|stages|>10), which returns a scale\n//                    value of -1, indicating error.\n//\n\n//\n// WebRtcSpl_ComplexFFT(...)\n//\n// Complex FFT\n//\n// Computes a complex 2^|stages|-point FFT on the input vector, which is in\n// bit-reversed order. The original content of the vector is destroyed in\n// the process, since the input is overwritten by the output, normal-ordered,\n// FFT vector. With x as the input complex vector, Y as the output complex\n// vector and with M = 2^|stages|, the following is computed:\n//\n//              M-1\n// Y(k) = 1/M * sum[x(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]\n//              i=0\n//\n// The implementations are optimized for speed, not for code size. It uses the\n// decimation-in-time algorithm with radix-2 butterfly technique.\n//\n// This routine prevents overflow by scaling by 2 before each FFT stage. This is\n// a fixed scaling, for proper normalization - there will be log2(n) passes, so\n// this results in an overall factor of 1/n, distributed to maximize arithmetic\n// accuracy.\n//\n// Input:\n//      - vector    : In pointer to complex vector containing 2^|stages| real\n//                    elements interleaved with 2^|stages| imaginary elements.\n//                    [ReImReImReIm....]\n//                    The output is in the Q0 domain.\n//\n//      - stages    : Number of FFT stages. Must be at least 3 and at most 10,\n//                    since the table WebRtcSpl_kSinTable1024[] is 1024\n//                    elements long.\n//\n//      - mode      : This parameter gives the user to choose how the FFT\n//                    should work.\n//                    mode==0: Low-complexity and Low-accuracy mode\n//                    mode==1: High-complexity and High-accuracy mode\n//\n// Output:\n//      - vector    : The output FFT vector is in the Q0 domain.\n//\n// Return value     : The scale parameter is always 0, except if N>1024,\n//                    which returns a scale value of -1, indicating error.\n//\n\n//\n// WebRtcSpl_AnalysisQMF(...)\n//\n// Splits a 0-2*F Hz signal into two sub bands: 0-F Hz and F-2*F Hz. The\n// current version has F = 8000, therefore, a super-wideband audio signal is\n// split to lower-band 0-8 kHz and upper-band 8-16 kHz.\n//\n// Input:\n//      - in_data       : Wide band speech signal, 320 samples (10 ms)\n//\n// Input & Output:\n//      - filter_state1 : Filter state for first All-pass filter\n//      - filter_state2 : Filter state for second All-pass filter\n//\n// Output:\n//      - low_band      : Lower-band signal 0-8 kHz band, 160 samples (10 ms)\n//      - high_band     : Upper-band signal 8-16 kHz band (flipped in frequency\n//                        domain), 160 samples (10 ms)\n//\n\n//\n// WebRtcSpl_SynthesisQMF(...)\n//\n// Combines the two sub bands (0-F and F-2*F Hz) into a signal of 0-2*F\n// Hz, (current version has F = 8000 Hz). So the filter combines lower-band\n// (0-8 kHz) and upper-band (8-16 kHz) channels to obtain super-wideband 0-16\n// kHz audio.\n//\n// Input:\n//      - low_band      : The signal with the 0-8 kHz band, 160 samples (10 ms)\n//      - high_band     : The signal with the 8-16 kHz band, 160 samples (10 ms)\n//\n// Input & Output:\n//      - filter_state1 : Filter state for first All-pass filter\n//      - filter_state2 : Filter state for second All-pass filter\n//\n// Output:\n//      - out_data      : Super-wideband speech signal, 0-16 kHz\n//\n\n// int16_t WebRtcSpl_SatW32ToW16(...)\n//\n// This function saturates a 32-bit word into a 16-bit word.\n//\n// Input:\n//      - value32   : The value of a 32-bit word.\n//\n// Output:\n//      - out16     : the saturated 16-bit word.\n//\n\n// int32_t WebRtc_MulAccumW16(...)\n//\n// This function multiply a 16-bit word by a 16-bit word, and accumulate this\n// value to a 32-bit integer.\n//\n// Input:\n//      - a    : The value of the first 16-bit word.\n//      - b    : The value of the second 16-bit word.\n//      - c    : The value of an 32-bit integer.\n//\n// Return Value: The value of a * b + c.\n//\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/spl_inl.h",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n// This header file includes the inline functions in\n// the fix point signal processing library.\n\n#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_\n#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_\n\n#include \"rtc_base/compile_assert_c.h\"\n\nextern const int8_t kWebRtcSpl_CountLeadingZeros32_Table[64];\n\n// Don't call this directly except in tests!\nstatic __inline int WebRtcSpl_CountLeadingZeros32_NotBuiltin(uint32_t n) {\n  // Normalize n by rounding up to the nearest number that is a sequence of 0\n  // bits followed by a sequence of 1 bits. This number has the same number of\n  // leading zeros as the original n. There are exactly 33 such values.\n  n |= n >> 1;\n  n |= n >> 2;\n  n |= n >> 4;\n  n |= n >> 8;\n  n |= n >> 16;\n\n  // Multiply the modified n with a constant selected (by exhaustive search)\n  // such that each of the 33 possible values of n give a product whose 6 most\n  // significant bits are unique. Then look up the answer in the table.\n  return kWebRtcSpl_CountLeadingZeros32_Table[(n * 0x8c0b2891) >> 26];\n}\n\n// Don't call this directly except in tests!\nstatic __inline int WebRtcSpl_CountLeadingZeros64_NotBuiltin(uint64_t n) {\n  const int leading_zeros = n >> 32 == 0 ? 32 : 0;\n  return leading_zeros + WebRtcSpl_CountLeadingZeros32_NotBuiltin(\n                             (uint32_t)(n >> (32 - leading_zeros)));\n}\n\n// Returns the number of leading zero bits in the argument.\nstatic __inline int WebRtcSpl_CountLeadingZeros32(uint32_t n) {\n#ifdef __GNUC__\n  RTC_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t));\n  return n == 0 ? 32 : __builtin_clz(n);\n#else\n  return WebRtcSpl_CountLeadingZeros32_NotBuiltin(n);\n#endif\n}\n\n// Returns the number of leading zero bits in the argument.\nstatic __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) {\n#ifdef __GNUC__\n  RTC_COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t));  // NOLINT\n  return n == 0 ? 64 : __builtin_clzll(n);\n#else\n  return WebRtcSpl_CountLeadingZeros64_NotBuiltin(n);\n#endif\n}\n\n#ifdef WEBRTC_ARCH_ARM_V7\n#include \"common_audio/signal_processing/include/spl_inl_armv7.h\"\n#else\n\n#if defined(MIPS32_LE)\n#include \"common_audio/signal_processing/include/spl_inl_mips.h\"\n#endif\n\n#if !defined(MIPS_DSP_R1_LE)\nstatic __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {\n  int16_t out16 = (int16_t) value32;\n\n  if (value32 > 32767)\n    out16 = 32767;\n  else if (value32 < -32768)\n    out16 = -32768;\n\n  return out16;\n}\n\nstatic __inline int32_t WebRtcSpl_AddSatW32(int32_t a, int32_t b) {\n  // Do the addition in unsigned numbers, since signed overflow is undefined\n  // behavior.\n  const int32_t sum = (int32_t)((uint32_t)a + (uint32_t)b);\n\n  // a + b can't overflow if a and b have different signs. If they have the\n  // same sign, a + b also has the same sign iff it didn't overflow.\n  if ((a < 0) == (b < 0) && (a < 0) != (sum < 0)) {\n    // The direction of the overflow is obvious from the sign of a + b.\n    return sum < 0 ? INT32_MAX : INT32_MIN;\n  }\n  return sum;\n}\n\nstatic __inline int32_t WebRtcSpl_SubSatW32(int32_t a, int32_t b) {\n  // Do the subtraction in unsigned numbers, since signed overflow is undefined\n  // behavior.\n  const int32_t diff = (int32_t)((uint32_t)a - (uint32_t)b);\n\n  // a - b can't overflow if a and b have the same sign. If they have different\n  // signs, a - b has the same sign as a iff it didn't overflow.\n  if ((a < 0) != (b < 0) && (a < 0) != (diff < 0)) {\n    // The direction of the overflow is obvious from the sign of a - b.\n    return diff < 0 ? INT32_MAX : INT32_MIN;\n  }\n  return diff;\n}\n\nstatic __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {\n  return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b);\n}\n\nstatic __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {\n  return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2);\n}\n#endif  // #if !defined(MIPS_DSP_R1_LE)\n\n#if !defined(MIPS32_LE)\nstatic __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {\n  return 32 - WebRtcSpl_CountLeadingZeros32(n);\n}\n\n// Return the number of steps a can be left-shifted without overflow,\n// or 0 if a == 0.\nstatic __inline int16_t WebRtcSpl_NormW32(int32_t a) {\n  return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a < 0 ? ~a : a) - 1;\n}\n\n// Return the number of steps a can be left-shifted without overflow,\n// or 0 if a == 0.\nstatic __inline int16_t WebRtcSpl_NormU32(uint32_t a) {\n  return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a);\n}\n\n// Return the number of steps a can be left-shifted without overflow,\n// or 0 if a == 0.\nstatic __inline int16_t WebRtcSpl_NormW16(int16_t a) {\n  const int32_t a32 = a;\n  return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a < 0 ? ~a32 : a32) - 17;\n}\n\nstatic __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {\n  return (a * b + c);\n}\n#endif  // #if !defined(MIPS32_LE)\n\n#endif  // WEBRTC_ARCH_ARM_V7\n\n#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/* This header file includes the inline functions for ARM processors in\n * the fix point signal processing library.\n */\n\n#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_\n#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_\n\n/* TODO(kma): Replace some assembly code with GCC intrinsics\n * (e.g. __builtin_clz).\n */\n\n/* This function produces result that is not bit exact with that by the generic\n * C version in some cases, although the former is at least as accurate as the\n * later.\n */\nstatic __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) {\n  int32_t tmp = 0;\n  __asm __volatile (\"smulwb %0, %1, %2\":\"=r\"(tmp):\"r\"(b), \"r\"(a));\n  return tmp;\n}\n\nstatic __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) {\n  int32_t tmp = 0;\n  __asm __volatile (\"smulbb %0, %1, %2\":\"=r\"(tmp):\"r\"(a), \"r\"(b));\n  return tmp;\n}\n\n// TODO(kma): add unit test.\nstatic __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {\n  int32_t tmp = 0;\n  __asm __volatile (\"smlabb %0, %1, %2, %3\":\"=r\"(tmp):\"r\"(a), \"r\"(b), \"r\"(c));\n  return tmp;\n}\n\nstatic __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {\n  int32_t s_sum = 0;\n\n  __asm __volatile (\"qadd16 %0, %1, %2\":\"=r\"(s_sum):\"r\"(a), \"r\"(b));\n\n  return (int16_t) s_sum;\n}\n\nstatic __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {\n  int32_t l_sum = 0;\n\n  __asm __volatile (\"qadd %0, %1, %2\":\"=r\"(l_sum):\"r\"(l_var1), \"r\"(l_var2));\n\n  return l_sum;\n}\n\nstatic __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {\n  int32_t l_sub = 0;\n\n  __asm __volatile (\"qsub %0, %1, %2\":\"=r\"(l_sub):\"r\"(l_var1), \"r\"(l_var2));\n\n  return l_sub;\n}\n\nstatic __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {\n  int32_t s_sub = 0;\n\n  __asm __volatile (\"qsub16 %0, %1, %2\":\"=r\"(s_sub):\"r\"(var1), \"r\"(var2));\n\n  return (int16_t)s_sub;\n}\n\nstatic __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {\n  int32_t tmp = 0;\n\n  __asm __volatile (\"clz %0, %1\":\"=r\"(tmp):\"r\"(n));\n\n  return (int16_t)(32 - tmp);\n}\n\nstatic __inline int16_t WebRtcSpl_NormW32(int32_t a) {\n  int32_t tmp = 0;\n\n  if (a == 0) {\n    return 0;\n  } else if (a < 0) {\n    a ^= 0xFFFFFFFF;\n  }\n\n  __asm __volatile (\"clz %0, %1\":\"=r\"(tmp):\"r\"(a));\n\n  return (int16_t)(tmp - 1);\n}\n\nstatic __inline int16_t WebRtcSpl_NormU32(uint32_t a) {\n  int tmp = 0;\n\n  if (a == 0) return 0;\n\n  __asm __volatile (\"clz %0, %1\":\"=r\"(tmp):\"r\"(a));\n\n  return (int16_t)tmp;\n}\n\nstatic __inline int16_t WebRtcSpl_NormW16(int16_t a) {\n  int32_t tmp = 0;\n  int32_t a_32 = a;\n\n  if (a_32 == 0) {\n    return 0;\n  } else if (a_32 < 0) {\n    a_32 ^= 0xFFFFFFFF;\n  }\n\n  __asm __volatile (\"clz %0, %1\":\"=r\"(tmp):\"r\"(a_32));\n\n  return (int16_t)(tmp - 17);\n}\n\n// TODO(kma): add unit test.\nstatic __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {\n  int32_t out = 0;\n\n  __asm __volatile (\"ssat %0, #16, %1\" : \"=r\"(out) : \"r\"(value32));\n\n  return (int16_t)out;\n}\n\n#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_mips.h",
    "content": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n// This header file includes the inline functions in\n// the fix point signal processing library.\n\n#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_\n#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_\n\nstatic __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a,\n                                             int32_t b) {\n  int32_t value32 = 0;\n  int32_t a1 = 0, b1 = 0;\n\n  __asm __volatile(\n#if defined(MIPS32_R2_LE)\n    \"seh    %[a1],          %[a]                \\n\\t\"\n    \"seh    %[b1],          %[b]                \\n\\t\"\n#else\n    \"sll    %[a1],          %[a],         16    \\n\\t\"\n    \"sll    %[b1],          %[b],         16    \\n\\t\"\n    \"sra    %[a1],          %[a1],        16    \\n\\t\"\n    \"sra    %[b1],          %[b1],        16    \\n\\t\"\n#endif\n    \"mul    %[value32],     %[a1],  %[b1]       \\n\\t\"\n    : [value32] \"=r\" (value32), [a1] \"=&r\" (a1), [b1] \"=&r\" (b1)\n    : [a] \"r\" (a), [b] \"r\" (b)\n    : \"hi\", \"lo\");\n  return value32;\n}\n\nstatic __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a,\n                                                    int32_t b) {\n  int32_t value32 = 0, b1 = 0, b2 = 0;\n  int32_t a1 = 0;\n\n  __asm __volatile(\n#if defined(MIPS32_R2_LE)\n    \"seh    %[a1],          %[a]                        \\n\\t\"\n#else\n    \"sll    %[a1],          %[a],           16          \\n\\t\"\n    \"sra    %[a1],          %[a1],          16          \\n\\t\"\n#endif\n    \"andi   %[b2],          %[b],           0xFFFF      \\n\\t\"\n    \"sra    %[b1],          %[b],           16          \\n\\t\"\n    \"sra    %[b2],          %[b2],          1           \\n\\t\"\n    \"mul    %[value32],     %[a1],          %[b1]       \\n\\t\"\n    \"mul    %[b2],          %[a1],          %[b2]       \\n\\t\"\n    \"addiu  %[b2],          %[b2],          0x4000      \\n\\t\"\n    \"sra    %[b2],          %[b2],          15          \\n\\t\"\n    \"addu   %[value32],     %[value32],     %[b2]       \\n\\t\"\n    : [value32] \"=&r\" (value32), [b1] \"=&r\" (b1), [b2] \"=&r\" (b2),\n      [a1] \"=&r\" (a1)\n    : [a] \"r\" (a), [b] \"r\" (b)\n    : \"hi\", \"lo\");\n  return value32;\n}\n\n#if defined(MIPS_DSP_R1_LE)\nstatic __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {\n  __asm __volatile(\n    \"shll_s.w   %[value32], %[value32], 16      \\n\\t\"\n    \"sra        %[value32], %[value32], 16      \\n\\t\"\n    : [value32] \"+r\" (value32)\n    :);\n  int16_t out16 = (int16_t)value32;\n  return out16;\n}\n\nstatic __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {\n  int32_t value32 = 0;\n\n  __asm __volatile(\n    \"addq_s.ph      %[value32],     %[a],   %[b]    \\n\\t\"\n    : [value32] \"=r\" (value32)\n    : [a] \"r\" (a), [b] \"r\" (b) );\n  return (int16_t)value32;\n}\n\nstatic __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {\n  int32_t l_sum;\n\n  __asm __volatile(\n    \"addq_s.w   %[l_sum],       %[l_var1],      %[l_var2]    \\n\\t\"\n    : [l_sum] \"=r\" (l_sum)\n    : [l_var1] \"r\" (l_var1), [l_var2] \"r\" (l_var2) );\n\n  return l_sum;\n}\n\nstatic __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {\n  int32_t value32;\n\n  __asm __volatile(\n    \"subq_s.ph  %[value32], %[var1],    %[var2]     \\n\\t\"\n    : [value32] \"=r\" (value32)\n    : [var1] \"r\" (var1), [var2] \"r\" (var2) );\n\n  return (int16_t)value32;\n}\n\nstatic __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {\n  int32_t l_diff;\n\n  __asm __volatile(\n    \"subq_s.w   %[l_diff],      %[l_var1],      %[l_var2]    \\n\\t\"\n    : [l_diff] \"=r\" (l_diff)\n    : [l_var1] \"r\" (l_var1), [l_var2] \"r\" (l_var2) );\n\n  return l_diff;\n}\n#endif\n\nstatic __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {\n  int bits = 0;\n  int i32 = 32;\n\n  __asm __volatile(\n    \"clz    %[bits],    %[n]                    \\n\\t\"\n    \"subu   %[bits],    %[i32],     %[bits]     \\n\\t\"\n    : [bits] \"=&r\" (bits)\n    : [n] \"r\" (n), [i32] \"r\" (i32) );\n\n  return (int16_t)bits;\n}\n\nstatic __inline int16_t WebRtcSpl_NormW32(int32_t a) {\n  int zeros = 0;\n\n  __asm __volatile(\n    \".set       push                                \\n\\t\"\n    \".set       noreorder                           \\n\\t\"\n    \"bnez       %[a],       1f                      \\n\\t\"\n    \" sra       %[zeros],   %[a],       31          \\n\\t\"\n    \"b          2f                                  \\n\\t\"\n    \" move      %[zeros],   $zero                   \\n\\t\"\n   \"1:                                              \\n\\t\"\n    \"xor        %[zeros],   %[a],       %[zeros]    \\n\\t\"\n    \"clz        %[zeros],   %[zeros]                \\n\\t\"\n    \"addiu      %[zeros],   %[zeros],   -1          \\n\\t\"\n   \"2:                                              \\n\\t\"\n    \".set       pop                                 \\n\\t\"\n    : [zeros]\"=&r\"(zeros)\n    : [a] \"r\" (a) );\n\n  return (int16_t)zeros;\n}\n\nstatic __inline int16_t WebRtcSpl_NormU32(uint32_t a) {\n  int zeros = 0;\n\n  __asm __volatile(\n    \"clz    %[zeros],   %[a]    \\n\\t\"\n    : [zeros] \"=r\" (zeros)\n    : [a] \"r\" (a) );\n\n  return (int16_t)(zeros & 0x1f);\n}\n\nstatic __inline int16_t WebRtcSpl_NormW16(int16_t a) {\n  int zeros = 0;\n  int a0 = a << 16;\n\n  __asm __volatile(\n    \".set       push                                \\n\\t\"\n    \".set       noreorder                           \\n\\t\"\n    \"bnez       %[a0],      1f                      \\n\\t\"\n    \" sra       %[zeros],   %[a0],      31          \\n\\t\"\n    \"b          2f                                  \\n\\t\"\n    \" move      %[zeros],   $zero                   \\n\\t\"\n   \"1:                                              \\n\\t\"\n    \"xor        %[zeros],   %[a0],      %[zeros]    \\n\\t\"\n    \"clz        %[zeros],   %[zeros]                \\n\\t\"\n    \"addiu      %[zeros],   %[zeros],   -1          \\n\\t\"\n   \"2:                                              \\n\\t\"\n    \".set       pop                                 \\n\\t\"\n    : [zeros]\"=&r\"(zeros)\n    : [a0] \"r\" (a0) );\n\n  return (int16_t)zeros;\n}\n\nstatic __inline int32_t WebRtc_MulAccumW16(int16_t a,\n                                           int16_t b,\n                                           int32_t c) {\n  int32_t res = 0, c1 = 0;\n  __asm __volatile(\n#if defined(MIPS32_R2_LE)\n    \"seh    %[a],       %[a]            \\n\\t\"\n    \"seh    %[b],       %[b]            \\n\\t\"\n#else\n    \"sll    %[a],       %[a],   16      \\n\\t\"\n    \"sll    %[b],       %[b],   16      \\n\\t\"\n    \"sra    %[a],       %[a],   16      \\n\\t\"\n    \"sra    %[b],       %[b],   16      \\n\\t\"\n#endif\n    \"mul    %[res],     %[a],   %[b]    \\n\\t\"\n    \"addu   %[c1],      %[c],   %[res]  \\n\\t\"\n    : [c1] \"=r\" (c1), [res] \"=&r\" (res)\n    : [a] \"r\" (a), [b] \"r\" (b), [c] \"r\" (c)\n    : \"hi\", \"lo\");\n  return (c1);\n}\n\n#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/min_max_operations.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n/*\n * This file contains the implementation of functions\n * WebRtcSpl_MaxAbsValueW16C()\n * WebRtcSpl_MaxAbsValueW32C()\n * WebRtcSpl_MaxValueW16C()\n * WebRtcSpl_MaxValueW32C()\n * WebRtcSpl_MinValueW16C()\n * WebRtcSpl_MinValueW32C()\n * WebRtcSpl_MaxAbsIndexW16()\n * WebRtcSpl_MaxIndexW16()\n * WebRtcSpl_MaxIndexW32()\n * WebRtcSpl_MinIndexW16()\n * WebRtcSpl_MinIndexW32()\n *\n */\n\n#include <stdlib.h>\n\n#include \"rtc_base/checks.h\"\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n// TODO(bjorn/kma): Consolidate function pairs (e.g. combine\n//   WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.)\n// TODO(kma): Move the next six functions into min_max_operations_c.c.\n\n// Maximum absolute value of word16 vector. C version for generic platforms.\nint16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) {\n  size_t i = 0;\n  int absolute = 0, maximum = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    absolute = abs((int)vector[i]);\n\n    if (absolute > maximum) {\n      maximum = absolute;\n    }\n  }\n\n  // Guard the case for abs(-32768).\n  if (maximum > WEBRTC_SPL_WORD16_MAX) {\n    maximum = WEBRTC_SPL_WORD16_MAX;\n  }\n\n  return (int16_t)maximum;\n}\n\n// Maximum absolute value of word32 vector. C version for generic platforms.\nint32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {\n  // Use uint32_t for the local variables, to accommodate the return value\n  // of abs(0x80000000), which is 0x80000000.\n\n  uint32_t absolute = 0, maximum = 0;\n  size_t i = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    absolute = abs((int)vector[i]);\n    if (absolute > maximum) {\n      maximum = absolute;\n    }\n  }\n\n  maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX);\n\n  return (int32_t)maximum;\n}\n\n// Maximum value of word16 vector. C version for generic platforms.\nint16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) {\n  int16_t maximum = WEBRTC_SPL_WORD16_MIN;\n  size_t i = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] > maximum)\n      maximum = vector[i];\n  }\n  return maximum;\n}\n\n// Maximum value of word32 vector. C version for generic platforms.\nint32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) {\n  int32_t maximum = WEBRTC_SPL_WORD32_MIN;\n  size_t i = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] > maximum)\n      maximum = vector[i];\n  }\n  return maximum;\n}\n\n// Minimum value of word16 vector. C version for generic platforms.\nint16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) {\n  int16_t minimum = WEBRTC_SPL_WORD16_MAX;\n  size_t i = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] < minimum)\n      minimum = vector[i];\n  }\n  return minimum;\n}\n\n// Minimum value of word32 vector. C version for generic platforms.\nint32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {\n  int32_t minimum = WEBRTC_SPL_WORD32_MAX;\n  size_t i = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] < minimum)\n      minimum = vector[i];\n  }\n  return minimum;\n}\n\n// Index of maximum absolute value in a word16 vector.\nsize_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {\n  // Use type int for local variables, to accomodate the value of abs(-32768).\n\n  size_t i = 0, index = 0;\n  int absolute = 0, maximum = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    absolute = abs((int)vector[i]);\n\n    if (absolute > maximum) {\n      maximum = absolute;\n      index = i;\n    }\n  }\n\n  return index;\n}\n\n// Index of maximum value in a word16 vector.\nsize_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {\n  size_t i = 0, index = 0;\n  int16_t maximum = WEBRTC_SPL_WORD16_MIN;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] > maximum) {\n      maximum = vector[i];\n      index = i;\n    }\n  }\n\n  return index;\n}\n\n// Index of maximum value in a word32 vector.\nsize_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {\n  size_t i = 0, index = 0;\n  int32_t maximum = WEBRTC_SPL_WORD32_MIN;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] > maximum) {\n      maximum = vector[i];\n      index = i;\n    }\n  }\n\n  return index;\n}\n\n// Index of minimum value in a word16 vector.\nsize_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {\n  size_t i = 0, index = 0;\n  int16_t minimum = WEBRTC_SPL_WORD16_MAX;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] < minimum) {\n      minimum = vector[i];\n      index = i;\n    }\n  }\n\n  return index;\n}\n\n// Index of minimum value in a word32 vector.\nsize_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {\n  size_t i = 0, index = 0;\n  int32_t minimum = WEBRTC_SPL_WORD32_MAX;\n\n  RTC_DCHECK_GT(length, 0);\n\n  for (i = 0; i < length; i++) {\n    if (vector[i] < minimum) {\n      minimum = vector[i];\n      index = i;\n    }\n  }\n\n  return index;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/min_max_operations_mips.c.mips",
    "content": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n/*\n * This file contains the implementation of function\n * WebRtcSpl_MaxAbsValueW16()\n *\n * The description header can be found in signal_processing_library.h.\n *\n */\n\n#include \"rtc_base/checks.h\"\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n// Maximum absolute value of word16 vector.\nint16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length) {\n  int32_t totMax = 0;\n  int32_t tmp32_0, tmp32_1, tmp32_2, tmp32_3;\n  size_t i, loop_size;\n\n  RTC_DCHECK_GT(length, 0);\n\n#if defined(MIPS_DSP_R1)\n  const int32_t* tmpvec32 = (int32_t*)vector;\n  loop_size = length >> 4;\n\n  for (i = 0; i < loop_size; i++) {\n    __asm__ volatile (\n      \"lw         %[tmp32_0],     0(%[tmpvec32])              \\n\\t\"\n      \"lw         %[tmp32_1],     4(%[tmpvec32])              \\n\\t\"\n      \"lw         %[tmp32_2],     8(%[tmpvec32])              \\n\\t\"\n      \"lw         %[tmp32_3],     12(%[tmpvec32])             \\n\\t\"\n\n      \"absq_s.ph  %[tmp32_0],     %[tmp32_0]                  \\n\\t\"\n      \"absq_s.ph  %[tmp32_1],     %[tmp32_1]                  \\n\\t\"\n      \"cmp.lt.ph  %[totMax],      %[tmp32_0]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_0],     %[totMax]   \\n\\t\"\n\n      \"lw         %[tmp32_0],     16(%[tmpvec32])             \\n\\t\"\n      \"absq_s.ph  %[tmp32_2],     %[tmp32_2]                  \\n\\t\"\n      \"cmp.lt.ph  %[totMax],      %[tmp32_1]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_1],     %[totMax]   \\n\\t\"\n\n      \"lw         %[tmp32_1],     20(%[tmpvec32])             \\n\\t\"\n      \"absq_s.ph  %[tmp32_3],     %[tmp32_3]                  \\n\\t\"\n      \"cmp.lt.ph  %[totMax],      %[tmp32_2]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_2],     %[totMax]   \\n\\t\"\n\n      \"lw         %[tmp32_2],     24(%[tmpvec32])             \\n\\t\"\n      \"cmp.lt.ph  %[totMax],      %[tmp32_3]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_3],     %[totMax]   \\n\\t\"\n\n      \"lw         %[tmp32_3],     28(%[tmpvec32])             \\n\\t\"\n      \"absq_s.ph  %[tmp32_0],     %[tmp32_0]                  \\n\\t\"\n      \"absq_s.ph  %[tmp32_1],     %[tmp32_1]                  \\n\\t\"\n      \"cmp.lt.ph  %[totMax],      %[tmp32_0]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_0],     %[totMax]   \\n\\t\"\n\n      \"absq_s.ph  %[tmp32_2],     %[tmp32_2]                  \\n\\t\"\n      \"cmp.lt.ph  %[totMax],      %[tmp32_1]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_1],     %[totMax]   \\n\\t\"\n      \"absq_s.ph  %[tmp32_3],     %[tmp32_3]                  \\n\\t\"\n      \"cmp.lt.ph  %[totMax],      %[tmp32_2]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_2],     %[totMax]   \\n\\t\"\n\n      \"cmp.lt.ph  %[totMax],      %[tmp32_3]                  \\n\\t\"\n      \"pick.ph    %[totMax],      %[tmp32_3],     %[totMax]   \\n\\t\"\n\n      \"addiu      %[tmpvec32],    %[tmpvec32],    32          \\n\\t\"\n      : [tmp32_0] \"=&r\" (tmp32_0), [tmp32_1] \"=&r\" (tmp32_1),\n        [tmp32_2] \"=&r\" (tmp32_2), [tmp32_3] \"=&r\" (tmp32_3),\n        [totMax] \"+r\" (totMax), [tmpvec32] \"+r\" (tmpvec32)\n      :\n      : \"memory\"\n    );\n  }\n  __asm__ volatile (\n    \"rotr       %[tmp32_0],     %[totMax],      16          \\n\\t\"\n    \"cmp.lt.ph  %[totMax],      %[tmp32_0]                  \\n\\t\"\n    \"pick.ph    %[totMax],      %[tmp32_0],     %[totMax]   \\n\\t\"\n    \"packrl.ph  %[totMax],      $0,             %[totMax]   \\n\\t\"\n    : [tmp32_0] \"=&r\" (tmp32_0), [totMax] \"+r\" (totMax)\n    :\n  );\n  loop_size = length & 0xf;\n  for (i = 0; i < loop_size; i++) {\n    __asm__ volatile (\n      \"lh         %[tmp32_0],     0(%[tmpvec32])              \\n\\t\"\n      \"addiu      %[tmpvec32],    %[tmpvec32],     2          \\n\\t\"\n      \"absq_s.w   %[tmp32_0],     %[tmp32_0]                  \\n\\t\"\n      \"slt        %[tmp32_1],     %[totMax],       %[tmp32_0] \\n\\t\"\n      \"movn       %[totMax],      %[tmp32_0],      %[tmp32_1] \\n\\t\"\n      : [tmp32_0] \"=&r\" (tmp32_0), [tmp32_1] \"=&r\" (tmp32_1),\n        [tmpvec32] \"+r\" (tmpvec32), [totMax] \"+r\" (totMax)\n      :\n      : \"memory\"\n    );\n  }\n#else  // #if defined(MIPS_DSP_R1)\n  int32_t v16MaxMax = WEBRTC_SPL_WORD16_MAX;\n  int32_t r, r1, r2, r3;\n  const int16_t* tmpvector = vector;\n  loop_size = length >> 4;\n  for (i = 0; i < loop_size; i++) {\n    __asm__ volatile (\n      \"lh     %[tmp32_0],     0(%[tmpvector])                 \\n\\t\"\n      \"lh     %[tmp32_1],     2(%[tmpvector])                 \\n\\t\"\n      \"lh     %[tmp32_2],     4(%[tmpvector])                 \\n\\t\"\n      \"lh     %[tmp32_3],     6(%[tmpvector])                 \\n\\t\"\n\n      \"abs    %[tmp32_0],     %[tmp32_0]                      \\n\\t\"\n      \"abs    %[tmp32_1],     %[tmp32_1]                      \\n\\t\"\n      \"abs    %[tmp32_2],     %[tmp32_2]                      \\n\\t\"\n      \"abs    %[tmp32_3],     %[tmp32_3]                      \\n\\t\"\n\n      \"slt    %[r],           %[totMax],      %[tmp32_0]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_0],     %[r]            \\n\\t\"\n      \"slt    %[r1],          %[totMax],      %[tmp32_1]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_1],     %[r1]           \\n\\t\"\n      \"slt    %[r2],          %[totMax],      %[tmp32_2]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_2],     %[r2]           \\n\\t\"\n      \"slt    %[r3],          %[totMax],      %[tmp32_3]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_3],     %[r3]           \\n\\t\"\n\n      \"lh     %[tmp32_0],     8(%[tmpvector])                 \\n\\t\"\n      \"lh     %[tmp32_1],     10(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_2],     12(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_3],     14(%[tmpvector])                \\n\\t\"\n\n      \"abs    %[tmp32_0],     %[tmp32_0]                      \\n\\t\"\n      \"abs    %[tmp32_1],     %[tmp32_1]                      \\n\\t\"\n      \"abs    %[tmp32_2],     %[tmp32_2]                      \\n\\t\"\n      \"abs    %[tmp32_3],     %[tmp32_3]                      \\n\\t\"\n\n      \"slt    %[r],           %[totMax],      %[tmp32_0]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_0],     %[r]            \\n\\t\"\n      \"slt    %[r1],          %[totMax],      %[tmp32_1]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_1],     %[r1]           \\n\\t\"\n      \"slt    %[r2],          %[totMax],      %[tmp32_2]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_2],     %[r2]           \\n\\t\"\n      \"slt    %[r3],          %[totMax],      %[tmp32_3]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_3],     %[r3]           \\n\\t\"\n\n      \"lh     %[tmp32_0],     16(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_1],     18(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_2],     20(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_3],     22(%[tmpvector])                \\n\\t\"\n\n      \"abs    %[tmp32_0],     %[tmp32_0]                      \\n\\t\"\n      \"abs    %[tmp32_1],     %[tmp32_1]                      \\n\\t\"\n      \"abs    %[tmp32_2],     %[tmp32_2]                      \\n\\t\"\n      \"abs    %[tmp32_3],     %[tmp32_3]                      \\n\\t\"\n\n      \"slt    %[r],           %[totMax],      %[tmp32_0]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_0],     %[r]            \\n\\t\"\n      \"slt    %[r1],          %[totMax],      %[tmp32_1]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_1],     %[r1]           \\n\\t\"\n      \"slt    %[r2],          %[totMax],      %[tmp32_2]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_2],     %[r2]           \\n\\t\"\n      \"slt    %[r3],          %[totMax],      %[tmp32_3]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_3],     %[r3]           \\n\\t\"\n\n      \"lh     %[tmp32_0],     24(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_1],     26(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_2],     28(%[tmpvector])                \\n\\t\"\n      \"lh     %[tmp32_3],     30(%[tmpvector])                \\n\\t\"\n\n      \"abs    %[tmp32_0],     %[tmp32_0]                      \\n\\t\"\n      \"abs    %[tmp32_1],     %[tmp32_1]                      \\n\\t\"\n      \"abs    %[tmp32_2],     %[tmp32_2]                      \\n\\t\"\n      \"abs    %[tmp32_3],     %[tmp32_3]                      \\n\\t\"\n\n      \"slt    %[r],           %[totMax],      %[tmp32_0]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_0],     %[r]            \\n\\t\"\n      \"slt    %[r1],          %[totMax],      %[tmp32_1]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_1],     %[r1]           \\n\\t\"\n      \"slt    %[r2],          %[totMax],      %[tmp32_2]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_2],     %[r2]           \\n\\t\"\n      \"slt    %[r3],          %[totMax],      %[tmp32_3]      \\n\\t\"\n      \"movn   %[totMax],      %[tmp32_3],     %[r3]           \\n\\t\"\n\n      \"addiu  %[tmpvector],   %[tmpvector],   32              \\n\\t\"\n      : [tmp32_0] \"=&r\" (tmp32_0), [tmp32_1] \"=&r\" (tmp32_1),\n        [tmp32_2] \"=&r\" (tmp32_2), [tmp32_3] \"=&r\" (tmp32_3),\n        [totMax] \"+r\" (totMax), [r] \"=&r\" (r), [tmpvector] \"+r\" (tmpvector),\n        [r1] \"=&r\" (r1), [r2] \"=&r\" (r2), [r3] \"=&r\" (r3)\n      :\n      : \"memory\"\n    );\n  }\n  loop_size = length & 0xf;\n  for (i = 0; i < loop_size; i++) {\n    __asm__ volatile (\n      \"lh         %[tmp32_0],     0(%[tmpvector])             \\n\\t\"\n      \"addiu      %[tmpvector],   %[tmpvector],    2          \\n\\t\"\n      \"abs        %[tmp32_0],     %[tmp32_0]                  \\n\\t\"\n      \"slt        %[tmp32_1],     %[totMax],       %[tmp32_0] \\n\\t\"\n      \"movn       %[totMax],      %[tmp32_0],      %[tmp32_1] \\n\\t\"\n      : [tmp32_0] \"=&r\" (tmp32_0), [tmp32_1] \"=&r\" (tmp32_1),\n        [tmpvector] \"+r\" (tmpvector), [totMax] \"+r\" (totMax)\n      :\n      : \"memory\"\n    );\n  }\n\n  __asm__ volatile (\n    \"slt    %[r],       %[v16MaxMax],   %[totMax]   \\n\\t\"\n    \"movn   %[totMax],  %[v16MaxMax],   %[r]        \\n\\t\"\n    : [totMax] \"+r\" (totMax), [r] \"=&r\" (r)\n    : [v16MaxMax] \"r\" (v16MaxMax)\n  );\n#endif  // #if defined(MIPS_DSP_R1)\n  return (int16_t)totMax;\n}\n\n#if defined(MIPS_DSP_R1_LE)\n// Maximum absolute value of word32 vector. Version for MIPS platform.\nint32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length) {\n  // Use uint32_t for the local variables, to accommodate the return value\n  // of abs(0x80000000), which is 0x80000000.\n\n  uint32_t absolute = 0, maximum = 0;\n  int tmp1 = 0, max_value = 0x7fffffff;\n\n  RTC_DCHECK_GT(length, 0);\n\n  __asm__ volatile (\n    \".set push                                                        \\n\\t\"\n    \".set noreorder                                                   \\n\\t\"\n\n   \"1:                                                                \\n\\t\"\n    \"lw         %[absolute],      0(%[vector])                        \\n\\t\"\n    \"absq_s.w   %[absolute],      %[absolute]                         \\n\\t\"\n    \"addiu      %[length],        %[length],          -1              \\n\\t\"\n    \"slt        %[tmp1],          %[maximum],         %[absolute]     \\n\\t\"\n    \"movn       %[maximum],       %[absolute],        %[tmp1]         \\n\\t\"\n    \"bgtz       %[length],        1b                                  \\n\\t\"\n    \" addiu     %[vector],        %[vector],          4               \\n\\t\"\n    \"slt        %[tmp1],          %[max_value],       %[maximum]      \\n\\t\"\n    \"movn       %[maximum],       %[max_value],       %[tmp1]         \\n\\t\"\n\n    \".set pop                                                         \\n\\t\"\n\n    : [tmp1] \"=&r\" (tmp1), [maximum] \"+r\" (maximum), [absolute] \"+r\" (absolute)\n    : [vector] \"r\" (vector), [length] \"r\" (length), [max_value] \"r\" (max_value)\n    : \"memory\"\n  );\n\n  return (int32_t)maximum;\n}\n#endif  // #if defined(MIPS_DSP_R1_LE)\n\n// Maximum value of word16 vector. Version for MIPS platform.\nint16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length) {\n  int16_t maximum = WEBRTC_SPL_WORD16_MIN;\n  int tmp1;\n  int16_t value;\n\n  RTC_DCHECK_GT(length, 0);\n\n  __asm__ volatile (\n    \".set push                                                        \\n\\t\"\n    \".set noreorder                                                   \\n\\t\"\n\n   \"1:                                                                \\n\\t\"\n    \"lh         %[value],         0(%[vector])                        \\n\\t\"\n    \"addiu      %[length],        %[length],          -1              \\n\\t\"\n    \"slt        %[tmp1],          %[maximum],         %[value]        \\n\\t\"\n    \"movn       %[maximum],       %[value],           %[tmp1]         \\n\\t\"\n    \"bgtz       %[length],        1b                                  \\n\\t\"\n    \" addiu     %[vector],        %[vector],          2               \\n\\t\"\n    \".set pop                                                         \\n\\t\"\n\n    : [tmp1] \"=&r\" (tmp1), [maximum] \"+r\" (maximum), [value] \"=&r\" (value)\n    : [vector] \"r\" (vector), [length] \"r\" (length)\n    : \"memory\"\n  );\n\n  return maximum;\n}\n\n// Maximum value of word32 vector. Version for MIPS platform.\nint32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length) {\n  int32_t maximum = WEBRTC_SPL_WORD32_MIN;\n  int tmp1, value;\n\n  RTC_DCHECK_GT(length, 0);\n\n  __asm__ volatile (\n    \".set push                                                        \\n\\t\"\n    \".set noreorder                                                   \\n\\t\"\n\n   \"1:                                                                \\n\\t\"\n    \"lw         %[value],         0(%[vector])                        \\n\\t\"\n    \"addiu      %[length],        %[length],          -1              \\n\\t\"\n    \"slt        %[tmp1],          %[maximum],         %[value]        \\n\\t\"\n    \"movn       %[maximum],       %[value],           %[tmp1]         \\n\\t\"\n    \"bgtz       %[length],        1b                                  \\n\\t\"\n    \" addiu     %[vector],        %[vector],          4               \\n\\t\"\n\n    \".set pop                                                         \\n\\t\"\n\n    : [tmp1] \"=&r\" (tmp1), [maximum] \"+r\" (maximum), [value] \"=&r\" (value)\n    : [vector] \"r\" (vector), [length] \"r\" (length)\n    : \"memory\"\n  );\n\n  return maximum;\n}\n\n// Minimum value of word16 vector. Version for MIPS platform.\nint16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length) {\n  int16_t minimum = WEBRTC_SPL_WORD16_MAX;\n  int tmp1;\n  int16_t value;\n\n  RTC_DCHECK_GT(length, 0);\n\n  __asm__ volatile (\n    \".set push                                                        \\n\\t\"\n    \".set noreorder                                                   \\n\\t\"\n\n   \"1:                                                                \\n\\t\"\n    \"lh         %[value],         0(%[vector])                        \\n\\t\"\n    \"addiu      %[length],        %[length],          -1              \\n\\t\"\n    \"slt        %[tmp1],          %[value],           %[minimum]      \\n\\t\"\n    \"movn       %[minimum],       %[value],           %[tmp1]         \\n\\t\"\n    \"bgtz       %[length],        1b                                  \\n\\t\"\n    \" addiu     %[vector],        %[vector],          2               \\n\\t\"\n\n    \".set pop                                                         \\n\\t\"\n\n    : [tmp1] \"=&r\" (tmp1), [minimum] \"+r\" (minimum), [value] \"=&r\" (value)\n    : [vector] \"r\" (vector), [length] \"r\" (length)\n    : \"memory\"\n  );\n\n  return minimum;\n}\n\n// Minimum value of word32 vector. Version for MIPS platform.\nint32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length) {\n  int32_t minimum = WEBRTC_SPL_WORD32_MAX;\n  int tmp1, value;\n\n  RTC_DCHECK_GT(length, 0);\n\n  __asm__ volatile (\n    \".set push                                                        \\n\\t\"\n    \".set noreorder                                                   \\n\\t\"\n\n   \"1:                                                                \\n\\t\"\n    \"lw         %[value],         0(%[vector])                        \\n\\t\"\n    \"addiu      %[length],        %[length],          -1              \\n\\t\"\n    \"slt        %[tmp1],          %[value],           %[minimum]      \\n\\t\"\n    \"movn       %[minimum],       %[value],           %[tmp1]         \\n\\t\"\n    \"bgtz       %[length],        1b                                  \\n\\t\"\n    \" addiu     %[vector],        %[vector],          4               \\n\\t\"\n\n    \".set pop                                                         \\n\\t\"\n\n    : [tmp1] \"=&r\" (tmp1), [minimum] \"+r\" (minimum), [value] \"=&r\" (value)\n    : [vector] \"r\" (vector), [length] \"r\" (length)\n    : \"memory\"\n  );\n\n  return minimum;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/min_max_operations_neon.c.neon",
    "content": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include <arm_neon.h>\n#include <stdlib.h>\n\n#include \"rtc_base/checks.h\"\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n// Maximum absolute value of word16 vector. C version for generic platforms.\nint16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length) {\n  int absolute = 0, maximum = 0;\n\n  RTC_DCHECK_GT(length, 0);\n\n  const int16_t* p_start = vector;\n  size_t rest = length & 7;\n  const int16_t* p_end = vector + length - rest;\n\n  int16x8_t v;\n  uint16x8_t max_qv;\n  max_qv = vdupq_n_u16(0);\n\n  while (p_start < p_end) {\n    v = vld1q_s16(p_start);\n    // Note vabs doesn't change the value of -32768.\n    v = vabsq_s16(v);\n    // Use u16 so we don't lose the value -32768.\n    max_qv = vmaxq_u16(max_qv, vreinterpretq_u16_s16(v));\n    p_start += 8;\n  }\n\n#ifdef WEBRTC_ARCH_ARM64\n  maximum = (int)vmaxvq_u16(max_qv);\n#else\n  uint16x4_t max_dv;\n  max_dv = vmax_u16(vget_low_u16(max_qv), vget_high_u16(max_qv));\n  max_dv = vpmax_u16(max_dv, max_dv);\n  max_dv = vpmax_u16(max_dv, max_dv);\n\n  maximum = (int)vget_lane_u16(max_dv, 0);\n#endif\n\n  p_end = vector + length;\n  while (p_start < p_end) {\n    absolute = abs((int)(*p_start));\n\n    if (absolute > maximum) {\n      maximum = absolute;\n    }\n    p_start++;\n  }\n\n  // Guard the case for abs(-32768).\n  if (maximum > WEBRTC_SPL_WORD16_MAX) {\n    maximum = WEBRTC_SPL_WORD16_MAX;\n  }\n\n  return (int16_t)maximum;\n}\n\n// Maximum absolute value of word32 vector. NEON intrinsics version for\n// ARM 32-bit/64-bit platforms.\nint32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length) {\n  // Use uint32_t for the local variables, to accommodate the return value\n  // of abs(0x80000000), which is 0x80000000.\n\n  uint32_t absolute = 0, maximum = 0;\n  size_t i = 0;\n  size_t residual = length & 0x7;\n\n  RTC_DCHECK_GT(length, 0);\n\n  const int32_t* p_start = vector;\n  uint32x4_t max32x4_0 = vdupq_n_u32(0);\n  uint32x4_t max32x4_1 = vdupq_n_u32(0);\n\n  // First part, unroll the loop 8 times.\n  for (i = 0; i < length - residual; i += 8) {\n    int32x4_t in32x4_0 = vld1q_s32(p_start);\n    p_start += 4;\n    int32x4_t in32x4_1 = vld1q_s32(p_start);\n    p_start += 4;\n    in32x4_0 = vabsq_s32(in32x4_0);\n    in32x4_1 = vabsq_s32(in32x4_1);\n    // vabs doesn't change the value of 0x80000000.\n    // Use u32 so we don't lose the value 0x80000000.\n    max32x4_0 = vmaxq_u32(max32x4_0, vreinterpretq_u32_s32(in32x4_0));\n    max32x4_1 = vmaxq_u32(max32x4_1, vreinterpretq_u32_s32(in32x4_1));\n  }\n\n  uint32x4_t max32x4 = vmaxq_u32(max32x4_0, max32x4_1);\n#if defined(WEBRTC_ARCH_ARM64)\n  maximum = vmaxvq_u32(max32x4);\n#else\n  uint32x2_t max32x2 = vmax_u32(vget_low_u32(max32x4), vget_high_u32(max32x4));\n  max32x2 = vpmax_u32(max32x2, max32x2);\n\n  maximum = vget_lane_u32(max32x2, 0);\n#endif\n\n  // Second part, do the remaining iterations (if any).\n  for (i = residual; i > 0; i--) {\n    absolute = abs((int)(*p_start));\n    if (absolute > maximum) {\n      maximum = absolute;\n    }\n    p_start++;\n  }\n\n  // Guard against the case for 0x80000000.\n  maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX);\n\n  return (int32_t)maximum;\n}\n\n// Maximum value of word16 vector. NEON intrinsics version for\n// ARM 32-bit/64-bit platforms.\nint16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length) {\n  int16_t maximum = WEBRTC_SPL_WORD16_MIN;\n  size_t i = 0;\n  size_t residual = length & 0x7;\n\n  RTC_DCHECK_GT(length, 0);\n\n  const int16_t* p_start = vector;\n  int16x8_t max16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MIN);\n\n  // First part, unroll the loop 8 times.\n  for (i = 0; i < length - residual; i += 8) {\n    int16x8_t in16x8 = vld1q_s16(p_start);\n    max16x8 = vmaxq_s16(max16x8, in16x8);\n    p_start += 8;\n  }\n\n#if defined(WEBRTC_ARCH_ARM64)\n  maximum = vmaxvq_s16(max16x8);\n#else\n  int16x4_t max16x4 = vmax_s16(vget_low_s16(max16x8), vget_high_s16(max16x8));\n  max16x4 = vpmax_s16(max16x4, max16x4);\n  max16x4 = vpmax_s16(max16x4, max16x4);\n\n  maximum = vget_lane_s16(max16x4, 0);\n#endif\n\n  // Second part, do the remaining iterations (if any).\n  for (i = residual; i > 0; i--) {\n    if (*p_start > maximum)\n      maximum = *p_start;\n    p_start++;\n  }\n  return maximum;\n}\n\n// Maximum value of word32 vector. NEON intrinsics version for\n// ARM 32-bit/64-bit platforms.\nint32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length) {\n  int32_t maximum = WEBRTC_SPL_WORD32_MIN;\n  size_t i = 0;\n  size_t residual = length & 0x7;\n\n  RTC_DCHECK_GT(length, 0);\n\n  const int32_t* p_start = vector;\n  int32x4_t max32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MIN);\n  int32x4_t max32x4_1 = vdupq_n_s32(WEBRTC_SPL_WORD32_MIN);\n\n  // First part, unroll the loop 8 times.\n  for (i = 0; i < length - residual; i += 8) {\n    int32x4_t in32x4_0 = vld1q_s32(p_start);\n    p_start += 4;\n    int32x4_t in32x4_1 = vld1q_s32(p_start);\n    p_start += 4;\n    max32x4_0 = vmaxq_s32(max32x4_0, in32x4_0);\n    max32x4_1 = vmaxq_s32(max32x4_1, in32x4_1);\n  }\n\n  int32x4_t max32x4 = vmaxq_s32(max32x4_0, max32x4_1);\n#if defined(WEBRTC_ARCH_ARM64)\n  maximum = vmaxvq_s32(max32x4);\n#else\n  int32x2_t max32x2 = vmax_s32(vget_low_s32(max32x4), vget_high_s32(max32x4));\n  max32x2 = vpmax_s32(max32x2, max32x2);\n\n  maximum = vget_lane_s32(max32x2, 0);\n#endif\n\n  // Second part, do the remaining iterations (if any).\n  for (i = residual; i > 0; i--) {\n    if (*p_start > maximum)\n      maximum = *p_start;\n    p_start++;\n  }\n  return maximum;\n}\n\n// Minimum value of word16 vector. NEON intrinsics version for\n// ARM 32-bit/64-bit platforms.\nint16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length) {\n  int16_t minimum = WEBRTC_SPL_WORD16_MAX;\n  size_t i = 0;\n  size_t residual = length & 0x7;\n\n  RTC_DCHECK_GT(length, 0);\n\n  const int16_t* p_start = vector;\n  int16x8_t min16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MAX);\n\n  // First part, unroll the loop 8 times.\n  for (i = 0; i < length - residual; i += 8) {\n    int16x8_t in16x8 = vld1q_s16(p_start);\n    min16x8 = vminq_s16(min16x8, in16x8);\n    p_start += 8;\n  }\n\n#if defined(WEBRTC_ARCH_ARM64)\n  minimum = vminvq_s16(min16x8);\n#else\n  int16x4_t min16x4 = vmin_s16(vget_low_s16(min16x8), vget_high_s16(min16x8));\n  min16x4 = vpmin_s16(min16x4, min16x4);\n  min16x4 = vpmin_s16(min16x4, min16x4);\n\n  minimum = vget_lane_s16(min16x4, 0);\n#endif\n\n  // Second part, do the remaining iterations (if any).\n  for (i = residual; i > 0; i--) {\n    if (*p_start < minimum)\n      minimum = *p_start;\n    p_start++;\n  }\n  return minimum;\n}\n\n// Minimum value of word32 vector. NEON intrinsics version for\n// ARM 32-bit/64-bit platforms.\nint32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length) {\n  int32_t minimum = WEBRTC_SPL_WORD32_MAX;\n  size_t i = 0;\n  size_t residual = length & 0x7;\n\n  RTC_DCHECK_GT(length, 0);\n\n  const int32_t* p_start = vector;\n  int32x4_t min32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MAX);\n  int32x4_t min32x4_1 = vdupq_n_s32(WEBRTC_SPL_WORD32_MAX);\n\n  // First part, unroll the loop 8 times.\n  for (i = 0; i < length - residual; i += 8) {\n    int32x4_t in32x4_0 = vld1q_s32(p_start);\n    p_start += 4;\n    int32x4_t in32x4_1 = vld1q_s32(p_start);\n    p_start += 4;\n    min32x4_0 = vminq_s32(min32x4_0, in32x4_0);\n    min32x4_1 = vminq_s32(min32x4_1, in32x4_1);\n  }\n\n  int32x4_t min32x4 = vminq_s32(min32x4_0, min32x4_1);\n#if defined(WEBRTC_ARCH_ARM64)\n  minimum = vminvq_s32(min32x4);\n#else\n  int32x2_t min32x2 = vmin_s32(vget_low_s32(min32x4), vget_high_s32(min32x4));\n  min32x2 = vpmin_s32(min32x2, min32x2);\n\n  minimum = vget_lane_s32(min32x2, 0);\n#endif\n\n  // Second part, do the remaining iterations (if any).\n  for (i = residual; i > 0; i--) {\n    if (*p_start < minimum)\n      minimum = *p_start;\n    p_start++;\n  }\n  return minimum;\n}\n\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_48khz.c",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This file contains resampling functions between 48 kHz and nb/wb.\n * The description header can be found in signal_processing_library.h\n *\n */\n\n#include <string.h>\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"common_audio/signal_processing/resample_by_2_internal.h\"\n\n////////////////////////////\n///// 48 kHz -> 16 kHz /////\n////////////////////////////\n\n// 48 -> 16 resampler\nvoid WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,\n                                    WebRtcSpl_State48khzTo16khz* state, int32_t* tmpmem)\n{\n    ///// 48 --> 48(LP) /////\n    // int16_t  in[480]\n    // int32_t out[480]\n    /////\n    WebRtcSpl_LPBy2ShortToInt(in, 480, tmpmem + 16, state->S_48_48);\n\n    ///// 48 --> 32 /////\n    // int32_t  in[480]\n    // int32_t out[320]\n    /////\n    // copy state to and from input array\n    memcpy(tmpmem + 8, state->S_48_32, 8 * sizeof(int32_t));\n    memcpy(state->S_48_32, tmpmem + 488, 8 * sizeof(int32_t));\n    WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 160);\n\n    ///// 32 --> 16 /////\n    // int32_t  in[320]\n    // int16_t out[160]\n    /////\n    WebRtcSpl_DownBy2IntToShort(tmpmem, 320, out, state->S_32_16);\n}\n\n// initialize state of 48 -> 16 resampler\nvoid WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state)\n{\n    memset(state->S_48_48, 0, 16 * sizeof(int32_t));\n    memset(state->S_48_32, 0, 8 * sizeof(int32_t));\n    memset(state->S_32_16, 0, 8 * sizeof(int32_t));\n}\n\n////////////////////////////\n///// 16 kHz -> 48 kHz /////\n////////////////////////////\n\n// 16 -> 48 resampler\nvoid WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,\n                                    WebRtcSpl_State16khzTo48khz* state, int32_t* tmpmem)\n{\n    ///// 16 --> 32 /////\n    // int16_t  in[160]\n    // int32_t out[320]\n    /////\n    WebRtcSpl_UpBy2ShortToInt(in, 160, tmpmem + 16, state->S_16_32);\n\n    ///// 32 --> 24 /////\n    // int32_t  in[320]\n    // int32_t out[240]\n    // copy state to and from input array\n    /////\n    memcpy(tmpmem + 8, state->S_32_24, 8 * sizeof(int32_t));\n    memcpy(state->S_32_24, tmpmem + 328, 8 * sizeof(int32_t));\n    WebRtcSpl_Resample32khzTo24khz(tmpmem + 8, tmpmem, 80);\n\n    ///// 24 --> 48 /////\n    // int32_t  in[240]\n    // int16_t out[480]\n    /////\n    WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);\n}\n\n// initialize state of 16 -> 48 resampler\nvoid WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state)\n{\n    memset(state->S_16_32, 0, 8 * sizeof(int32_t));\n    memset(state->S_32_24, 0, 8 * sizeof(int32_t));\n    memset(state->S_24_48, 0, 8 * sizeof(int32_t));\n}\n\n////////////////////////////\n///// 48 kHz ->  8 kHz /////\n////////////////////////////\n\n// 48 -> 8 resampler\nvoid WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,\n                                   WebRtcSpl_State48khzTo8khz* state, int32_t* tmpmem)\n{\n    ///// 48 --> 24 /////\n    // int16_t  in[480]\n    // int32_t out[240]\n    /////\n    WebRtcSpl_DownBy2ShortToInt(in, 480, tmpmem + 256, state->S_48_24);\n\n    ///// 24 --> 24(LP) /////\n    // int32_t  in[240]\n    // int32_t out[240]\n    /////\n    WebRtcSpl_LPBy2IntToInt(tmpmem + 256, 240, tmpmem + 16, state->S_24_24);\n\n    ///// 24 --> 16 /////\n    // int32_t  in[240]\n    // int32_t out[160]\n    /////\n    // copy state to and from input array\n    memcpy(tmpmem + 8, state->S_24_16, 8 * sizeof(int32_t));\n    memcpy(state->S_24_16, tmpmem + 248, 8 * sizeof(int32_t));\n    WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 80);\n\n    ///// 16 --> 8 /////\n    // int32_t  in[160]\n    // int16_t out[80]\n    /////\n    WebRtcSpl_DownBy2IntToShort(tmpmem, 160, out, state->S_16_8);\n}\n\n// initialize state of 48 -> 8 resampler\nvoid WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state)\n{\n    memset(state->S_48_24, 0, 8 * sizeof(int32_t));\n    memset(state->S_24_24, 0, 16 * sizeof(int32_t));\n    memset(state->S_24_16, 0, 8 * sizeof(int32_t));\n    memset(state->S_16_8, 0, 8 * sizeof(int32_t));\n}\n\n////////////////////////////\n/////  8 kHz -> 48 kHz /////\n////////////////////////////\n\n// 8 -> 48 resampler\nvoid WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,\n                                   WebRtcSpl_State8khzTo48khz* state, int32_t* tmpmem)\n{\n    ///// 8 --> 16 /////\n    // int16_t  in[80]\n    // int32_t out[160]\n    /////\n    WebRtcSpl_UpBy2ShortToInt(in, 80, tmpmem + 264, state->S_8_16);\n\n    ///// 16 --> 12 /////\n    // int32_t  in[160]\n    // int32_t out[120]\n    /////\n    // copy state to and from input array\n    memcpy(tmpmem + 256, state->S_16_12, 8 * sizeof(int32_t));\n    memcpy(state->S_16_12, tmpmem + 416, 8 * sizeof(int32_t));\n    WebRtcSpl_Resample32khzTo24khz(tmpmem + 256, tmpmem + 240, 40);\n\n    ///// 12 --> 24 /////\n    // int32_t  in[120]\n    // int16_t out[240]\n    /////\n    WebRtcSpl_UpBy2IntToInt(tmpmem + 240, 120, tmpmem, state->S_12_24);\n\n    ///// 24 --> 48 /////\n    // int32_t  in[240]\n    // int16_t out[480]\n    /////\n    WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);\n}\n\n// initialize state of 8 -> 48 resampler\nvoid WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state)\n{\n    memset(state->S_8_16, 0, 8 * sizeof(int32_t));\n    memset(state->S_16_12, 0, 8 * sizeof(int32_t));\n    memset(state->S_12_24, 0, 8 * sizeof(int32_t));\n    memset(state->S_24_48, 0, 8 * sizeof(int32_t));\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_by_2_internal.c",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This header file contains some internal resampling functions.\n *\n */\n\n#include \"common_audio/signal_processing/resample_by_2_internal.h\"\n#include \"rtc_base/sanitizer.h\"\n\n// allpass filter coefficients.\nstatic const int16_t kResampleAllpass[2][3] = {\n        {821, 6110, 12382},\n        {3050, 9368, 15063}\n};\n\n//\n//   decimator\n// input:  int32_t (shifted 15 positions to the left, + offset 16384) OVERWRITTEN!\n// output: int16_t (saturated) (of length len/2)\n// state:  filter state array; length = 8\n\nvoid RTC_NO_SANITIZE(\"signed-integer-overflow\")  // bugs.webrtc.org/5486\nWebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out,\n                            int32_t *state)\n{\n    int32_t tmp0, tmp1, diff;\n    int32_t i;\n\n    len >>= 1;\n\n    // lower allpass filter (operates on even input samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i << 1];\n        diff = tmp0 - state[1];\n        // UBSan: -1771017321 - 999586185 cannot be represented in type 'int'\n\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[0] + diff * kResampleAllpass[1][0];\n        state[0] = tmp0;\n        diff = tmp1 - state[2];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[1] + diff * kResampleAllpass[1][1];\n        state[1] = tmp1;\n        diff = tmp0 - state[3];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[3] = state[2] + diff * kResampleAllpass[1][2];\n        state[2] = tmp0;\n\n        // divide by two and store temporarily\n        in[i << 1] = (state[3] >> 1);\n    }\n\n    in++;\n\n    // upper allpass filter (operates on odd input samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i << 1];\n        diff = tmp0 - state[5];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[4] + diff * kResampleAllpass[0][0];\n        state[4] = tmp0;\n        diff = tmp1 - state[6];\n        // scale down and round\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[5] + diff * kResampleAllpass[0][1];\n        state[5] = tmp1;\n        diff = tmp0 - state[7];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[7] = state[6] + diff * kResampleAllpass[0][2];\n        state[6] = tmp0;\n\n        // divide by two and store temporarily\n        in[i << 1] = (state[7] >> 1);\n    }\n\n    in--;\n\n    // combine allpass outputs\n    for (i = 0; i < len; i += 2)\n    {\n        // divide by two, add both allpass outputs and round\n        tmp0 = (in[i << 1] + in[(i << 1) + 1]) >> 15;\n        tmp1 = (in[(i << 1) + 2] + in[(i << 1) + 3]) >> 15;\n        if (tmp0 > (int32_t)0x00007FFF)\n            tmp0 = 0x00007FFF;\n        if (tmp0 < (int32_t)0xFFFF8000)\n            tmp0 = 0xFFFF8000;\n        out[i] = (int16_t)tmp0;\n        if (tmp1 > (int32_t)0x00007FFF)\n            tmp1 = 0x00007FFF;\n        if (tmp1 < (int32_t)0xFFFF8000)\n            tmp1 = 0xFFFF8000;\n        out[i + 1] = (int16_t)tmp1;\n    }\n}\n\n//\n//   decimator\n// input:  int16_t\n// output: int32_t (shifted 15 positions to the left, + offset 16384) (of length len/2)\n// state:  filter state array; length = 8\n\nvoid RTC_NO_SANITIZE(\"signed-integer-overflow\")  // bugs.webrtc.org/5486\nWebRtcSpl_DownBy2ShortToInt(const int16_t *in,\n                            int32_t len,\n                            int32_t *out,\n                            int32_t *state)\n{\n    int32_t tmp0, tmp1, diff;\n    int32_t i;\n\n    len >>= 1;\n\n    // lower allpass filter (operates on even input samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);\n        diff = tmp0 - state[1];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[0] + diff * kResampleAllpass[1][0];\n        state[0] = tmp0;\n        diff = tmp1 - state[2];\n        // UBSan: -1379909682 - 834099714 cannot be represented in type 'int'\n\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[1] + diff * kResampleAllpass[1][1];\n        state[1] = tmp1;\n        diff = tmp0 - state[3];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[3] = state[2] + diff * kResampleAllpass[1][2];\n        state[2] = tmp0;\n\n        // divide by two and store temporarily\n        out[i] = (state[3] >> 1);\n    }\n\n    in++;\n\n    // upper allpass filter (operates on odd input samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);\n        diff = tmp0 - state[5];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[4] + diff * kResampleAllpass[0][0];\n        state[4] = tmp0;\n        diff = tmp1 - state[6];\n        // scale down and round\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[5] + diff * kResampleAllpass[0][1];\n        state[5] = tmp1;\n        diff = tmp0 - state[7];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[7] = state[6] + diff * kResampleAllpass[0][2];\n        state[6] = tmp0;\n\n        // divide by two and store temporarily\n        out[i] += (state[7] >> 1);\n    }\n\n    in--;\n}\n\n//\n//   interpolator\n// input:  int16_t\n// output: int32_t (normalized, not saturated) (of length len*2)\n// state:  filter state array; length = 8\nvoid WebRtcSpl_UpBy2ShortToInt(const int16_t *in, int32_t len, int32_t *out,\n                               int32_t *state)\n{\n    int32_t tmp0, tmp1, diff;\n    int32_t i;\n\n    // upper allpass filter (generates odd output samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = ((int32_t)in[i] << 15) + (1 << 14);\n        diff = tmp0 - state[5];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[4] + diff * kResampleAllpass[0][0];\n        state[4] = tmp0;\n        diff = tmp1 - state[6];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[5] + diff * kResampleAllpass[0][1];\n        state[5] = tmp1;\n        diff = tmp0 - state[7];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[7] = state[6] + diff * kResampleAllpass[0][2];\n        state[6] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[7] >> 15;\n    }\n\n    out++;\n\n    // lower allpass filter (generates even output samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = ((int32_t)in[i] << 15) + (1 << 14);\n        diff = tmp0 - state[1];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[0] + diff * kResampleAllpass[1][0];\n        state[0] = tmp0;\n        diff = tmp1 - state[2];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[1] + diff * kResampleAllpass[1][1];\n        state[1] = tmp1;\n        diff = tmp0 - state[3];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[3] = state[2] + diff * kResampleAllpass[1][2];\n        state[2] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[3] >> 15;\n    }\n}\n\n//\n//   interpolator\n// input:  int32_t (shifted 15 positions to the left, + offset 16384)\n// output: int32_t (shifted 15 positions to the left, + offset 16384) (of length len*2)\n// state:  filter state array; length = 8\nvoid WebRtcSpl_UpBy2IntToInt(const int32_t *in, int32_t len, int32_t *out,\n                             int32_t *state)\n{\n    int32_t tmp0, tmp1, diff;\n    int32_t i;\n\n    // upper allpass filter (generates odd output samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i];\n        diff = tmp0 - state[5];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[4] + diff * kResampleAllpass[0][0];\n        state[4] = tmp0;\n        diff = tmp1 - state[6];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[5] + diff * kResampleAllpass[0][1];\n        state[5] = tmp1;\n        diff = tmp0 - state[7];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[7] = state[6] + diff * kResampleAllpass[0][2];\n        state[6] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[7];\n    }\n\n    out++;\n\n    // lower allpass filter (generates even output samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i];\n        diff = tmp0 - state[1];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[0] + diff * kResampleAllpass[1][0];\n        state[0] = tmp0;\n        diff = tmp1 - state[2];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[1] + diff * kResampleAllpass[1][1];\n        state[1] = tmp1;\n        diff = tmp0 - state[3];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[3] = state[2] + diff * kResampleAllpass[1][2];\n        state[2] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[3];\n    }\n}\n\n//\n//   interpolator\n// input:  int32_t (shifted 15 positions to the left, + offset 16384)\n// output: int16_t (saturated) (of length len*2)\n// state:  filter state array; length = 8\nvoid WebRtcSpl_UpBy2IntToShort(const int32_t *in, int32_t len, int16_t *out,\n                               int32_t *state)\n{\n    int32_t tmp0, tmp1, diff;\n    int32_t i;\n\n    // upper allpass filter (generates odd output samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i];\n        diff = tmp0 - state[5];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[4] + diff * kResampleAllpass[0][0];\n        state[4] = tmp0;\n        diff = tmp1 - state[6];\n        // scale down and round\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[5] + diff * kResampleAllpass[0][1];\n        state[5] = tmp1;\n        diff = tmp0 - state[7];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[7] = state[6] + diff * kResampleAllpass[0][2];\n        state[6] = tmp0;\n\n        // scale down, saturate and store\n        tmp1 = state[7] >> 15;\n        if (tmp1 > (int32_t)0x00007FFF)\n            tmp1 = 0x00007FFF;\n        if (tmp1 < (int32_t)0xFFFF8000)\n            tmp1 = 0xFFFF8000;\n        out[i << 1] = (int16_t)tmp1;\n    }\n\n    out++;\n\n    // lower allpass filter (generates even output samples)\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i];\n        diff = tmp0 - state[1];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[0] + diff * kResampleAllpass[1][0];\n        state[0] = tmp0;\n        diff = tmp1 - state[2];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[1] + diff * kResampleAllpass[1][1];\n        state[1] = tmp1;\n        diff = tmp0 - state[3];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[3] = state[2] + diff * kResampleAllpass[1][2];\n        state[2] = tmp0;\n\n        // scale down, saturate and store\n        tmp1 = state[3] >> 15;\n        if (tmp1 > (int32_t)0x00007FFF)\n            tmp1 = 0x00007FFF;\n        if (tmp1 < (int32_t)0xFFFF8000)\n            tmp1 = 0xFFFF8000;\n        out[i << 1] = (int16_t)tmp1;\n    }\n}\n\n//   lowpass filter\n// input:  int16_t\n// output: int32_t (normalized, not saturated)\n// state:  filter state array; length = 8\nvoid WebRtcSpl_LPBy2ShortToInt(const int16_t* in, int32_t len, int32_t* out,\n                               int32_t* state)\n{\n    int32_t tmp0, tmp1, diff;\n    int32_t i;\n\n    len >>= 1;\n\n    // lower allpass filter: odd input -> even output samples\n    in++;\n    // initial state of polyphase delay element\n    tmp0 = state[12];\n    for (i = 0; i < len; i++)\n    {\n        diff = tmp0 - state[1];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[0] + diff * kResampleAllpass[1][0];\n        state[0] = tmp0;\n        diff = tmp1 - state[2];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[1] + diff * kResampleAllpass[1][1];\n        state[1] = tmp1;\n        diff = tmp0 - state[3];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[3] = state[2] + diff * kResampleAllpass[1][2];\n        state[2] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[3] >> 1;\n        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);\n    }\n    in--;\n\n    // upper allpass filter: even input -> even output samples\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);\n        diff = tmp0 - state[5];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[4] + diff * kResampleAllpass[0][0];\n        state[4] = tmp0;\n        diff = tmp1 - state[6];\n        // scale down and round\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[5] + diff * kResampleAllpass[0][1];\n        state[5] = tmp1;\n        diff = tmp0 - state[7];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[7] = state[6] + diff * kResampleAllpass[0][2];\n        state[6] = tmp0;\n\n        // average the two allpass outputs, scale down and store\n        out[i << 1] = (out[i << 1] + (state[7] >> 1)) >> 15;\n    }\n\n    // switch to odd output samples\n    out++;\n\n    // lower allpass filter: even input -> odd output samples\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);\n        diff = tmp0 - state[9];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[8] + diff * kResampleAllpass[1][0];\n        state[8] = tmp0;\n        diff = tmp1 - state[10];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[9] + diff * kResampleAllpass[1][1];\n        state[9] = tmp1;\n        diff = tmp0 - state[11];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[11] = state[10] + diff * kResampleAllpass[1][2];\n        state[10] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[11] >> 1;\n    }\n\n    // upper allpass filter: odd input -> odd output samples\n    in++;\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);\n        diff = tmp0 - state[13];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[12] + diff * kResampleAllpass[0][0];\n        state[12] = tmp0;\n        diff = tmp1 - state[14];\n        // scale down and round\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[13] + diff * kResampleAllpass[0][1];\n        state[13] = tmp1;\n        diff = tmp0 - state[15];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[15] = state[14] + diff * kResampleAllpass[0][2];\n        state[14] = tmp0;\n\n        // average the two allpass outputs, scale down and store\n        out[i << 1] = (out[i << 1] + (state[15] >> 1)) >> 15;\n    }\n}\n\n//   lowpass filter\n// input:  int32_t (shifted 15 positions to the left, + offset 16384)\n// output: int32_t (normalized, not saturated)\n// state:  filter state array; length = 8\nvoid RTC_NO_SANITIZE(\"signed-integer-overflow\")  // bugs.webrtc.org/5486\nWebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out,\n                        int32_t* state)\n{\n    int32_t tmp0, tmp1, diff;\n    int32_t i;\n\n    len >>= 1;\n\n    // lower allpass filter: odd input -> even output samples\n    in++;\n    // initial state of polyphase delay element\n    tmp0 = state[12];\n    for (i = 0; i < len; i++)\n    {\n        diff = tmp0 - state[1];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[0] + diff * kResampleAllpass[1][0];\n        state[0] = tmp0;\n        diff = tmp1 - state[2];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[1] + diff * kResampleAllpass[1][1];\n        state[1] = tmp1;\n        diff = tmp0 - state[3];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[3] = state[2] + diff * kResampleAllpass[1][2];\n        state[2] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[3] >> 1;\n        tmp0 = in[i << 1];\n    }\n    in--;\n\n    // upper allpass filter: even input -> even output samples\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i << 1];\n        diff = tmp0 - state[5];\n        // UBSan: -794814117 - 1566149201 cannot be represented in type 'int'\n\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[4] + diff * kResampleAllpass[0][0];\n        state[4] = tmp0;\n        diff = tmp1 - state[6];\n        // scale down and round\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[5] + diff * kResampleAllpass[0][1];\n        state[5] = tmp1;\n        diff = tmp0 - state[7];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[7] = state[6] + diff * kResampleAllpass[0][2];\n        state[6] = tmp0;\n\n        // average the two allpass outputs, scale down and store\n        out[i << 1] = (out[i << 1] + (state[7] >> 1)) >> 15;\n    }\n\n    // switch to odd output samples\n    out++;\n\n    // lower allpass filter: even input -> odd output samples\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i << 1];\n        diff = tmp0 - state[9];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[8] + diff * kResampleAllpass[1][0];\n        state[8] = tmp0;\n        diff = tmp1 - state[10];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[9] + diff * kResampleAllpass[1][1];\n        state[9] = tmp1;\n        diff = tmp0 - state[11];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[11] = state[10] + diff * kResampleAllpass[1][2];\n        state[10] = tmp0;\n\n        // scale down, round and store\n        out[i << 1] = state[11] >> 1;\n    }\n\n    // upper allpass filter: odd input -> odd output samples\n    in++;\n    for (i = 0; i < len; i++)\n    {\n        tmp0 = in[i << 1];\n        diff = tmp0 - state[13];\n        // scale down and round\n        diff = (diff + (1 << 13)) >> 14;\n        tmp1 = state[12] + diff * kResampleAllpass[0][0];\n        state[12] = tmp0;\n        diff = tmp1 - state[14];\n        // scale down and round\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        tmp0 = state[13] + diff * kResampleAllpass[0][1];\n        state[13] = tmp1;\n        diff = tmp0 - state[15];\n        // scale down and truncate\n        diff = diff >> 14;\n        if (diff < 0)\n            diff += 1;\n        state[15] = state[14] + diff * kResampleAllpass[0][2];\n        state[14] = tmp0;\n\n        // average the two allpass outputs, scale down and store\n        out[i << 1] = (out[i << 1] + (state[15] >> 1)) >> 15;\n    }\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_by_2_internal.h",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This header file contains some internal resampling functions.\n *\n */\n\n#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_\n#define COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_\n\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n/*******************************************************************\n * resample_by_2_fast.c\n * Functions for internal use in the other resample functions\n ******************************************************************/\nvoid WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out,\n                                 int32_t *state);\n\nvoid WebRtcSpl_DownBy2ShortToInt(const int16_t *in, int32_t len,\n                                 int32_t *out, int32_t *state);\n\nvoid WebRtcSpl_UpBy2ShortToInt(const int16_t *in, int32_t len,\n                               int32_t *out, int32_t *state);\n\nvoid WebRtcSpl_UpBy2IntToInt(const int32_t *in, int32_t len, int32_t *out,\n                             int32_t *state);\n\nvoid WebRtcSpl_UpBy2IntToShort(const int32_t *in, int32_t len,\n                               int16_t *out, int32_t *state);\n\nvoid WebRtcSpl_LPBy2ShortToInt(const int16_t* in, int32_t len,\n                               int32_t* out, int32_t* state);\n\nvoid WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out,\n                             int32_t* state);\n\n#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_fractional.c",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This file contains the resampling functions between 48, 44, 32 and 24 kHz.\n * The description headers can be found in signal_processing_library.h\n *\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\n// interpolation coefficients\nstatic const int16_t kCoefficients48To32[2][8] = {\n        {778, -2050, 1087, 23285, 12903, -3783, 441, 222},\n        {222, 441, -3783, 12903, 23285, 1087, -2050, 778}\n};\n\nstatic const int16_t kCoefficients32To24[3][8] = {\n        {767, -2362, 2434, 24406, 10620, -3838, 721, 90},\n        {386, -381, -2646, 19062, 19062, -2646, -381, 386},\n        {90, 721, -3838, 10620, 24406, 2434, -2362, 767}\n};\n\nstatic const int16_t kCoefficients44To32[4][9] = {\n        {117, -669, 2245, -6183, 26267, 13529, -3245, 845, -138},\n        {-101, 612, -2283, 8532, 29790, -5138, 1789, -524, 91},\n        {50, -292, 1016, -3064, 32010, 3933, -1147, 315, -53},\n        {-156, 974, -3863, 18603, 21691, -6246, 2353, -712, 126}\n};\n\n//   Resampling ratio: 2/3\n// input:  int32_t (normalized, not saturated) :: current_frame 3 * K\n// output: int32_t (shifted 15 positions to the left, + offset 16384) :: current_frame 2 * K\n//      K: number of blocks\n\nvoid WebRtcSpl_Resample48khzTo32khz(const int32_t *In, int32_t *Out, size_t K)\n{\n    /////////////////////////////////////////////////////////////\n    // Filter operation:\n    //\n    // Perform resampling (3 input samples -> 2 output samples);\n    // process in sub blocks of current_frame 3 samples.\n    int32_t tmp;\n    size_t m;\n\n    for (m = 0; m < K; m++)\n    {\n        tmp = 1 << 14;\n        tmp += kCoefficients48To32[0][0] * In[0];\n        tmp += kCoefficients48To32[0][1] * In[1];\n        tmp += kCoefficients48To32[0][2] * In[2];\n        tmp += kCoefficients48To32[0][3] * In[3];\n        tmp += kCoefficients48To32[0][4] * In[4];\n        tmp += kCoefficients48To32[0][5] * In[5];\n        tmp += kCoefficients48To32[0][6] * In[6];\n        tmp += kCoefficients48To32[0][7] * In[7];\n        Out[0] = tmp;\n\n        tmp = 1 << 14;\n        tmp += kCoefficients48To32[1][0] * In[1];\n        tmp += kCoefficients48To32[1][1] * In[2];\n        tmp += kCoefficients48To32[1][2] * In[3];\n        tmp += kCoefficients48To32[1][3] * In[4];\n        tmp += kCoefficients48To32[1][4] * In[5];\n        tmp += kCoefficients48To32[1][5] * In[6];\n        tmp += kCoefficients48To32[1][6] * In[7];\n        tmp += kCoefficients48To32[1][7] * In[8];\n        Out[1] = tmp;\n\n        // update pointers\n        In += 3;\n        Out += 2;\n    }\n}\n\n//   Resampling ratio: 3/4\n// input:  int32_t (normalized, not saturated) :: current_frame 4 * K\n// output: int32_t (shifted 15 positions to the left, + offset 16384) :: current_frame 3 * K\n//      K: number of blocks\n\nvoid WebRtcSpl_Resample32khzTo24khz(const int32_t *In, int32_t *Out, size_t K)\n{\n    /////////////////////////////////////////////////////////////\n    // Filter operation:\n    //\n    // Perform resampling (4 input samples -> 3 output samples);\n    // process in sub blocks of current_frame 4 samples.\n    size_t m;\n    int32_t tmp;\n\n    for (m = 0; m < K; m++)\n    {\n        tmp = 1 << 14;\n        tmp += kCoefficients32To24[0][0] * In[0];\n        tmp += kCoefficients32To24[0][1] * In[1];\n        tmp += kCoefficients32To24[0][2] * In[2];\n        tmp += kCoefficients32To24[0][3] * In[3];\n        tmp += kCoefficients32To24[0][4] * In[4];\n        tmp += kCoefficients32To24[0][5] * In[5];\n        tmp += kCoefficients32To24[0][6] * In[6];\n        tmp += kCoefficients32To24[0][7] * In[7];\n        Out[0] = tmp;\n\n        tmp = 1 << 14;\n        tmp += kCoefficients32To24[1][0] * In[1];\n        tmp += kCoefficients32To24[1][1] * In[2];\n        tmp += kCoefficients32To24[1][2] * In[3];\n        tmp += kCoefficients32To24[1][3] * In[4];\n        tmp += kCoefficients32To24[1][4] * In[5];\n        tmp += kCoefficients32To24[1][5] * In[6];\n        tmp += kCoefficients32To24[1][6] * In[7];\n        tmp += kCoefficients32To24[1][7] * In[8];\n        Out[1] = tmp;\n\n        tmp = 1 << 14;\n        tmp += kCoefficients32To24[2][0] * In[2];\n        tmp += kCoefficients32To24[2][1] * In[3];\n        tmp += kCoefficients32To24[2][2] * In[4];\n        tmp += kCoefficients32To24[2][3] * In[5];\n        tmp += kCoefficients32To24[2][4] * In[6];\n        tmp += kCoefficients32To24[2][5] * In[7];\n        tmp += kCoefficients32To24[2][6] * In[8];\n        tmp += kCoefficients32To24[2][7] * In[9];\n        Out[2] = tmp;\n\n        // update pointers\n        In += 4;\n        Out += 3;\n    }\n}\n\n//\n// fractional resampling filters\n//   Fout = 11/16 * Fin\n//   Fout =  8/11 * Fin\n//\n\n// compute two inner-products and store them to output array\nstatic void WebRtcSpl_ResampDotProduct(const int32_t *in1, const int32_t *in2,\n                                       const int16_t *coef_ptr, int32_t *out1,\n                                       int32_t *out2)\n{\n    int32_t tmp1 = 16384;\n    int32_t tmp2 = 16384;\n    int16_t coef;\n\n    coef = coef_ptr[0];\n    tmp1 += coef * in1[0];\n    tmp2 += coef * in2[-0];\n\n    coef = coef_ptr[1];\n    tmp1 += coef * in1[1];\n    tmp2 += coef * in2[-1];\n\n    coef = coef_ptr[2];\n    tmp1 += coef * in1[2];\n    tmp2 += coef * in2[-2];\n\n    coef = coef_ptr[3];\n    tmp1 += coef * in1[3];\n    tmp2 += coef * in2[-3];\n\n    coef = coef_ptr[4];\n    tmp1 += coef * in1[4];\n    tmp2 += coef * in2[-4];\n\n    coef = coef_ptr[5];\n    tmp1 += coef * in1[5];\n    tmp2 += coef * in2[-5];\n\n    coef = coef_ptr[6];\n    tmp1 += coef * in1[6];\n    tmp2 += coef * in2[-6];\n\n    coef = coef_ptr[7];\n    tmp1 += coef * in1[7];\n    tmp2 += coef * in2[-7];\n\n    coef = coef_ptr[8];\n    *out1 = tmp1 + coef * in1[8];\n    *out2 = tmp2 + coef * in2[-8];\n}\n\n//   Resampling ratio: 8/11\n// input:  int32_t (normalized, not saturated) :: current_frame 11 * K\n// output: int32_t (shifted 15 positions to the left, + offset 16384) :: current_frame  8 * K\n//      K: number of blocks\n\nvoid WebRtcSpl_Resample44khzTo32khz(const int32_t *In, int32_t *Out, size_t K)\n{\n    /////////////////////////////////////////////////////////////\n    // Filter operation:\n    //\n    // Perform resampling (11 input samples -> 8 output samples);\n    // process in sub blocks of current_frame 11 samples.\n    int32_t tmp;\n    size_t m;\n\n    for (m = 0; m < K; m++)\n    {\n        tmp = 1 << 14;\n\n        // first output sample\n        Out[0] = ((int32_t)In[3] << 15) + tmp;\n\n        // sum and accumulate filter coefficients and input samples\n        tmp += kCoefficients44To32[3][0] * In[5];\n        tmp += kCoefficients44To32[3][1] * In[6];\n        tmp += kCoefficients44To32[3][2] * In[7];\n        tmp += kCoefficients44To32[3][3] * In[8];\n        tmp += kCoefficients44To32[3][4] * In[9];\n        tmp += kCoefficients44To32[3][5] * In[10];\n        tmp += kCoefficients44To32[3][6] * In[11];\n        tmp += kCoefficients44To32[3][7] * In[12];\n        tmp += kCoefficients44To32[3][8] * In[13];\n        Out[4] = tmp;\n\n        // sum and accumulate filter coefficients and input samples\n        WebRtcSpl_ResampDotProduct(&In[0], &In[17], kCoefficients44To32[0], &Out[1], &Out[7]);\n\n        // sum and accumulate filter coefficients and input samples\n        WebRtcSpl_ResampDotProduct(&In[2], &In[15], kCoefficients44To32[1], &Out[2], &Out[6]);\n\n        // sum and accumulate filter coefficients and input samples\n        WebRtcSpl_ResampDotProduct(&In[3], &In[14], kCoefficients44To32[2], &Out[3], &Out[5]);\n\n        // update pointers\n        In += 11;\n        Out += 8;\n    }\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/spl_init.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n/* The global function contained in this file initializes SPL function\n * pointers, currently only for ARM platforms.\n *\n * Some code came from common/rtcd.c in the WebM project.\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"system_wrappers/include/cpu_features_wrapper.h\"\n\n/* Declare function pointers. */\nMaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;\nMaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;\nMaxValueW16 WebRtcSpl_MaxValueW16;\nMaxValueW32 WebRtcSpl_MaxValueW32;\nMinValueW16 WebRtcSpl_MinValueW16;\nMinValueW32 WebRtcSpl_MinValueW32;\nCrossCorrelation WebRtcSpl_CrossCorrelation;\nDownsampleFast WebRtcSpl_DownsampleFast;\nScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;\n\n#if (!defined(WEBRTC_HAS_NEON)) && !defined(MIPS32_LE)\n/* Initialize function pointers to the generic C version. */\nstatic void InitPointersToC() {\n  WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16C;\n  WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32C;\n  WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16C;\n  WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32C;\n  WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16C;\n  WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32C;\n  WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelationC;\n  WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFastC;\n  WebRtcSpl_ScaleAndAddVectorsWithRound =\n      WebRtcSpl_ScaleAndAddVectorsWithRoundC;\n}\n#endif\n\n#if defined(WEBRTC_HAS_NEON)\n/* Initialize function pointers to the Neon version. */\nstatic void InitPointersToNeon() {\n  WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16Neon;\n  WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32Neon;\n  WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16Neon;\n  WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32Neon;\n  WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16Neon;\n  WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32Neon;\n  WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelationNeon;\n  WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFastNeon;\n  WebRtcSpl_ScaleAndAddVectorsWithRound =\n      WebRtcSpl_ScaleAndAddVectorsWithRoundC;\n}\n#endif\n\n#if defined(MIPS32_LE)\n/* Initialize function pointers to the MIPS version. */\nstatic void InitPointersToMIPS() {\n  WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16_mips;\n  WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16_mips;\n  WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32_mips;\n  WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16_mips;\n  WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32_mips;\n  WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelation_mips;\n  WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFast_mips;\n#if defined(MIPS_DSP_R1_LE)\n  WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32_mips;\n  WebRtcSpl_ScaleAndAddVectorsWithRound =\n      WebRtcSpl_ScaleAndAddVectorsWithRound_mips;\n#else\n  WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32C;\n  WebRtcSpl_ScaleAndAddVectorsWithRound =\n      WebRtcSpl_ScaleAndAddVectorsWithRoundC;\n#endif\n}\n#endif\n\nstatic void InitFunctionPointers(void) {\n#if defined(WEBRTC_HAS_NEON)\n  InitPointersToNeon();\n#elif defined(MIPS32_LE)\n  InitPointersToMIPS();\n#else\n  InitPointersToC();\n#endif  /* WEBRTC_HAS_NEON */\n}\n\n#if defined(WEBRTC_POSIX)\n#include <pthread.h>\n\nstatic void once(void (*func)(void)) {\n  static pthread_once_t lock = PTHREAD_ONCE_INIT;\n  pthread_once(&lock, func);\n}\n\n#elif defined(_WIN32)\n#include <windows.h>\n\nstatic void once(void (*func)(void)) {\n  /* Didn't use InitializeCriticalSection() since there's no race-simple_vad_free context\n   * in which to execute it.\n   *\n   * TODO(kma): Change to different implementation (e.g.\n   * InterlockedCompareExchangePointer) to avoid issues similar to\n   * http://code.google.com/p/webm/issues/detail?id=467.\n   */\n  static CRITICAL_SECTION lock = {(void *)((size_t)-1), -1, 0, 0, 0, 0};\n  static int done = 0;\n\n  EnterCriticalSection(&lock);\n  if (!done) {\n    func();\n    done = 1;\n  }\n  LeaveCriticalSection(&lock);\n}\n\n/* There's no fallback version as an #else block here to ensure thread safety.\n * In case of neither pthread for WEBRTC_POSIX nor _WIN32 is present, build\n * system should pick it up.\n */\n#endif  /* WEBRTC_POSIX */\n\nvoid WebRtcSpl_Init() {\n  once(InitFunctionPointers);\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/vector_scaling_operations.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This file contains implementations of the functions\n * WebRtcSpl_VectorBitShiftW16()\n * WebRtcSpl_VectorBitShiftW32()\n * WebRtcSpl_VectorBitShiftW32ToW16()\n * WebRtcSpl_ScaleVector()\n * WebRtcSpl_ScaleVectorWithSat()\n * WebRtcSpl_ScaleAndAddVectors()\n * WebRtcSpl_ScaleAndAddVectorsWithRoundC()\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\nvoid WebRtcSpl_VectorBitShiftW16(int16_t *res, size_t length,\n                                 const int16_t *in, int16_t right_shifts)\n{\n    size_t i;\n\n    if (right_shifts > 0)\n    {\n        for (i = length; i > 0; i--)\n        {\n            (*res++) = ((*in++) >> right_shifts);\n        }\n    } else\n    {\n        for (i = length; i > 0; i--)\n        {\n            (*res++) = ((*in++) * (1 << (-right_shifts)));\n        }\n    }\n}\n\nvoid WebRtcSpl_VectorBitShiftW32(int32_t *out_vector,\n                                 size_t vector_length,\n                                 const int32_t *in_vector,\n                                 int16_t right_shifts)\n{\n    size_t i;\n\n    if (right_shifts > 0)\n    {\n        for (i = vector_length; i > 0; i--)\n        {\n            (*out_vector++) = ((*in_vector++) >> right_shifts);\n        }\n    } else\n    {\n        for (i = vector_length; i > 0; i--)\n        {\n            (*out_vector++) = ((*in_vector++) << (-right_shifts));\n        }\n    }\n}\n\nvoid WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out, size_t length,\n                                      const int32_t* in, int right_shifts) {\n  size_t i;\n  int32_t tmp_w32;\n\n  if (right_shifts >= 0) {\n    for (i = length; i > 0; i--) {\n      tmp_w32 = (*in++) >> right_shifts;\n      (*out++) = WebRtcSpl_SatW32ToW16(tmp_w32);\n    }\n  } else {\n    int left_shifts = -right_shifts;\n    for (i = length; i > 0; i--) {\n      tmp_w32 = (*in++) << left_shifts;\n      (*out++) = WebRtcSpl_SatW32ToW16(tmp_w32);\n    }\n  }\n}\n\nvoid WebRtcSpl_ScaleVector(const int16_t *in_vector, int16_t *out_vector,\n                           int16_t gain, size_t in_vector_length,\n                           int16_t right_shifts)\n{\n    // Performs vector operation: out_vector = (gain*in_vector)>>right_shifts\n    size_t i;\n    const int16_t *inptr;\n    int16_t *outptr;\n\n    inptr = in_vector;\n    outptr = out_vector;\n\n    for (i = 0; i < in_vector_length; i++)\n    {\n      *outptr++ = (int16_t)((*inptr++ * gain) >> right_shifts);\n    }\n}\n\nvoid WebRtcSpl_ScaleVectorWithSat(const int16_t *in_vector, int16_t *out_vector,\n                                 int16_t gain, size_t in_vector_length,\n                                 int16_t right_shifts)\n{\n    // Performs vector operation: out_vector = (gain*in_vector)>>right_shifts\n    size_t i;\n    const int16_t *inptr;\n    int16_t *outptr;\n\n    inptr = in_vector;\n    outptr = out_vector;\n\n    for (i = 0; i < in_vector_length; i++) {\n      *outptr++ = WebRtcSpl_SatW32ToW16((*inptr++ * gain) >> right_shifts);\n    }\n}\n\nvoid WebRtcSpl_ScaleAndAddVectors(const int16_t *in1, int16_t gain1, int shift1,\n                                  const int16_t *in2, int16_t gain2, int shift2,\n                                  int16_t *out, size_t vector_length)\n{\n    // Performs vector operation: out = (gain1*in1)>>shift1 + (gain2*in2)>>shift2\n    size_t i;\n    const int16_t *in1ptr;\n    const int16_t *in2ptr;\n    int16_t *outptr;\n\n    in1ptr = in1;\n    in2ptr = in2;\n    outptr = out;\n\n    for (i = 0; i < vector_length; i++)\n    {\n      *outptr++ = (int16_t)((gain1 * *in1ptr++) >> shift1) +\n          (int16_t)((gain2 * *in2ptr++) >> shift2);\n    }\n}\n\n// C version of WebRtcSpl_ScaleAndAddVectorsWithRound() for generic platforms.\nint WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,\n                                           int16_t in_vector1_scale,\n                                           const int16_t* in_vector2,\n                                           int16_t in_vector2_scale,\n                                           int right_shifts,\n                                           int16_t* out_vector,\n                                           size_t length) {\n  size_t i = 0;\n  int round_value = (1 << right_shifts) >> 1;\n\n  if (in_vector1 == NULL || in_vector2 == NULL || out_vector == NULL ||\n      length == 0 || right_shifts < 0) {\n    return -1;\n  }\n\n  for (i = 0; i < length; i++) {\n    out_vector[i] = (int16_t)((\n        in_vector1[i] * in_vector1_scale + in_vector2[i] * in_vector2_scale +\n        round_value) >> right_shifts);\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/vector_scaling_operations_mips.c.mips",
    "content": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This file contains implementations of the functions\n * WebRtcSpl_ScaleAndAddVectorsWithRound_mips()\n */\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n\nint WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,\n                                               int16_t in_vector1_scale,\n                                               const int16_t* in_vector2,\n                                               int16_t in_vector2_scale,\n                                               int right_shifts,\n                                               int16_t* out_vector,\n                                               size_t length) {\n  int16_t r0 = 0, r1 = 0;\n  int16_t *in1 = (int16_t*)in_vector1;\n  int16_t *in2 = (int16_t*)in_vector2;\n  int16_t *out = out_vector;\n  size_t i = 0;\n  int value32 = 0;\n\n  if (in_vector1 == NULL || in_vector2 == NULL || out_vector == NULL ||\n      length == 0 || right_shifts < 0) {\n    return -1;\n  }\n  for (i = 0; i < length; i++) {\n    __asm __volatile (\n      \"lh         %[r0],          0(%[in1])                               \\n\\t\"\n      \"lh         %[r1],          0(%[in2])                               \\n\\t\"\n      \"mult       %[r0],          %[in_vector1_scale]                     \\n\\t\"\n      \"madd       %[r1],          %[in_vector2_scale]                     \\n\\t\"\n      \"extrv_r.w  %[value32],     $ac0,               %[right_shifts]     \\n\\t\"\n      \"addiu      %[in1],         %[in1],             2                   \\n\\t\"\n      \"addiu      %[in2],         %[in2],             2                   \\n\\t\"\n      \"sh         %[value32],     0(%[out])                               \\n\\t\"\n      \"addiu      %[out],         %[out],             2                   \\n\\t\"\n      : [value32] \"=&r\" (value32), [out] \"+r\" (out), [in1] \"+r\" (in1),\n        [in2] \"+r\" (in2), [r0] \"=&r\" (r0), [r1] \"=&r\" (r1)\n      : [in_vector1_scale] \"r\" (in_vector1_scale),\n        [in_vector2_scale] \"r\" (in_vector2_scale),\n        [right_shifts] \"r\" (right_shifts)\n      : \"hi\", \"lo\", \"memory\"\n    );\n  }\n  return 0;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/include/vad.h",
    "content": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef COMMON_AUDIO_VAD_INCLUDE_VAD_H_\n#define COMMON_AUDIO_VAD_INCLUDE_VAD_H_\n\n#include <memory>\n\n#include \"common_audio/vad/include/webrtc_vad.h\"\n#include \"rtc_base/checks.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nnamespace webrtc {\n\nclass Vad {\n public:\n  enum Aggressiveness {\n    kVadNormal = 0,\n    kVadLowBitrate = 1,\n    kVadAggressive = 2,\n    kVadVeryAggressive = 3\n  };\n\n  enum Activity { kPassive = 0, kActive = 1, kError = -1 };\n\n  virtual ~Vad() = default;\n\n  // Calculates a VAD decision for the given audio frame. Valid sample rates\n  // are 8000, 16000, and 32000 Hz; the number of samples must be such that the\n  // frame is 10, 20, or 30 ms long.\n  virtual Activity VoiceActivity(const int16_t* audio,\n                                 size_t num_samples,\n                                 int sample_rate_hz) = 0;\n\n  // Resets VAD state.\n  virtual void Reset() = 0;\n};\n\n// Returns a Vad instance that's implemented on top of WebRtcVad.\nstd::unique_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness);\n\n}  // namespace webrtc\n\n#endif  // COMMON_AUDIO_VAD_INCLUDE_VAD_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/include/webrtc_vad.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This header file includes the VAD API calls. Specific function calls are given below.\n */\n\n#ifndef COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_  // NOLINT\n#define COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_\n\n#include <stddef.h>\n\n#include \"typedefs.h\"  // NOLINT(build/include)\n\ntypedef struct WebRtcVadInst VadInst;\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// Creates an instance to the VAD structure.\nVadInst* WebRtcVad_Create();\n\n// Frees the dynamic memory of a specified VAD instance.\n//\n// - handle [i] : Pointer to VAD instance that should be freed.\nvoid WebRtcVad_Free(VadInst* handle);\n\n// Initializes a VAD instance.\n//\n// - handle [i/o] : Instance that should be initialized.\n//\n// returns        : 0 - (OK),\n//                 -1 - (null pointer or Default mode could not be set).\nint WebRtcVad_Init(VadInst* handle);\n\n// Sets the VAD operating mode. A more aggressive (higher mode) VAD is more\n// restrictive in reporting speech. Put in other words the probability of being\n// speech when the VAD returns 1 is increased with increasing mode. As a\n// consequence also the missed detection rate goes up.\n//\n// - handle [i/o] : VAD instance.\n// - mode   [i]   : Aggressiveness mode (0, 1, 2, or 3).\n//\n// returns        : 0 - (OK),\n//                 -1 - (null pointer, mode could not be set or the VAD instance\n//                       has not been initialized).\nint WebRtcVad_set_mode(VadInst* handle, int mode);\n\n// Calculates a VAD decision for the |audio_frame|. For valid sampling rates\n// frame lengths, see the description of WebRtcVad_ValidRatesAndFrameLengths().\n//\n// - handle       [i/o] : VAD Instance. Needs to be initialized by\n//                        WebRtcVad_Init() before call.\n// - fs           [i]   : Sampling frequency (Hz): 8000, 16000, or 32000\n// - audio_frame  [i]   : Audio frame buffer.\n// - frame_length [i]   : Length of audio frame buffer in number of samples.\n//\n// returns              : 1 - (Active Voice),\n//                        0 - (Non-active Voice),\n//                       -1 - (Error)\nint WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,\n                      size_t frame_length);\n\n// Checks for valid combinations of |rate| and |frame_length|. We support 10,\n// 20 and 30 ms frames and the rates 8000, 16000 and 32000 Hz.\n//\n// - rate         [i] : Sampling frequency (Hz).\n// - frame_length [i] : Speech frame buffer length in number of samples.\n//\n// returns            : 0 - (valid combination), -1 - (invalid combination)\nint WebRtcVad_ValidRateAndFrameLength(int rate, size_t frame_length);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif  // COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_  // NOLINT\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/mock/mock_vad.h",
    "content": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef COMMON_AUDIO_VAD_MOCK_MOCK_VAD_H_\n#define COMMON_AUDIO_VAD_MOCK_MOCK_VAD_H_\n\n#include \"common_audio/vad/include/vad.h\"\n#include \"test/gmock.h\"\n\nnamespace webrtc {\n\nclass MockVad : public Vad {\n public:\n  virtual ~MockVad() { Die(); }\n  MOCK_METHOD0(Die, void());\n\n  MOCK_METHOD3(VoiceActivity,\n               enum Activity(const int16_t* audio,\n                             size_t num_samples,\n                             int sample_rate_hz));\n  MOCK_METHOD0(Reset, void());\n};\n\n}  // namespace webrtc\n\n#endif  // COMMON_AUDIO_VAD_MOCK_MOCK_VAD_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad.cc",
    "content": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/include/vad.h\"\n\n#include <memory>\n\n#include \"rtc_base/checks.h\"\n\nnamespace webrtc {\n\nnamespace {\n\nclass VadImpl final : public Vad {\n public:\n  explicit VadImpl(Aggressiveness aggressiveness)\n      : handle_(nullptr), aggressiveness_(aggressiveness) {\n    Reset();\n  }\n\n  ~VadImpl() override { WebRtcVad_Free(handle_); }\n\n  Activity VoiceActivity(const int16_t* audio,\n                         size_t num_samples,\n                         int sample_rate_hz) override {\n    int ret = WebRtcVad_Process(handle_, sample_rate_hz, audio, num_samples);\n    switch (ret) {\n      case 0:\n        return kPassive;\n      case 1:\n        return kActive;\n      default:\n        RTC_NOTREACHED() << \"WebRtcVad_Process returned an error.\";\n        return kError;\n    }\n  }\n\n  void Reset() override {\n    if (handle_)\n      WebRtcVad_Free(handle_);\n    handle_ = WebRtcVad_Create();\n    RTC_CHECK(handle_);\n    RTC_CHECK_EQ(WebRtcVad_Init(handle_), 0);\n    RTC_CHECK_EQ(WebRtcVad_set_mode(handle_, aggressiveness_), 0);\n  }\n\n private:\n  VadInst* handle_;\n  Aggressiveness aggressiveness_;\n};\n\n}  // namespace\n\nstd::unique_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness) {\n  return std::unique_ptr<Vad>(new VadImpl(aggressiveness));\n}\n\n}  // namespace webrtc\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_core.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/vad_core.h\"\n\n#include \"rtc_base/sanitizer.h\"\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"common_audio/vad/vad_filterbank.h\"\n#include \"common_audio/vad/vad_gmm.h\"\n#include \"common_audio/vad/vad_sp.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// Spectrum Weighting\nstatic const int16_t kSpectrumWeight[kNumChannels] = { 6, 8, 10, 12, 14, 16 };\nstatic const int16_t kNoiseUpdateConst = 655; // Q15\nstatic const int16_t kSpeechUpdateConst = 6554; // Q15\nstatic const int16_t kBackEta = 154; // Q8\n// Minimum difference between the two models, Q5\nstatic const int16_t kMinimumDifference[kNumChannels] = {\n    544, 544, 576, 576, 576, 576 };\n// Upper limit of mean value for speech model, Q7\nstatic const int16_t kMaximumSpeech[kNumChannels] = {\n    11392, 11392, 11520, 11520, 11520, 11520 };\n// Minimum value for mean value\nstatic const int16_t kMinimumMean[kNumGaussians] = { 640, 768 };\n// Upper limit of mean value for noise model, Q7\nstatic const int16_t kMaximumNoise[kNumChannels] = {\n    9216, 9088, 8960, 8832, 8704, 8576 };\n// Start values for the Gaussian models, Q7\n// Weights for the two Gaussians for the six channels (noise)\nstatic const int16_t kNoiseDataWeights[kTableSize] = {\n    34, 62, 72, 66, 53, 25, 94, 66, 56, 62, 75, 103 };\n// Weights for the two Gaussians for the six channels (speech)\nstatic const int16_t kSpeechDataWeights[kTableSize] = {\n    48, 82, 45, 87, 50, 47, 80, 46, 83, 41, 78, 81 };\n// Means for the two Gaussians for the six channels (noise)\nstatic const int16_t kNoiseDataMeans[kTableSize] = {\n    6738, 4892, 7065, 6715, 6771, 3369, 7646, 3863, 7820, 7266, 5020, 4362 };\n// Means for the two Gaussians for the six channels (speech)\nstatic const int16_t kSpeechDataMeans[kTableSize] = {\n    8306, 10085, 10078, 11823, 11843, 6309, 9473, 9571, 10879, 7581, 8180, 7483\n};\n// Stds for the two Gaussians for the six channels (noise)\nstatic const int16_t kNoiseDataStds[kTableSize] = {\n    378, 1064, 493, 582, 688, 593, 474, 697, 475, 688, 421, 455 };\n// Stds for the two Gaussians for the six channels (speech)\nstatic const int16_t kSpeechDataStds[kTableSize] = {\n    555, 505, 567, 524, 585, 1231, 509, 828, 492, 1540, 1079, 850 };\n\n// Constants used in GmmProbability().\n//\n// Maximum number of counted speech (VAD = 1) frames in a row.\nstatic const int16_t kMaxSpeechFrames = 6;\n// Minimum standard deviation for both speech and noise.\nstatic const int16_t kMinStd = 384;\n\n// Constants in WebRtcVad_InitCore().\n// Default aggressiveness mode.\nstatic const short kDefaultMode = 0;\nstatic const int kInitCheck = 42;\n\n// Constants used in WebRtcVad_set_mode_core().\n//\n// Thresholds for different frame lengths (10 ms, 20 ms and 30 ms).\n//\n// Mode 0, Quality.\nstatic const int16_t kOverHangMax1Q[3] = { 8, 4, 3 };\nstatic const int16_t kOverHangMax2Q[3] = { 14, 7, 5 };\nstatic const int16_t kLocalThresholdQ[3] = { 24, 21, 24 };\nstatic const int16_t kGlobalThresholdQ[3] = { 57, 48, 57 };\n// Mode 1, Low bitrate.\nstatic const int16_t kOverHangMax1LBR[3] = { 8, 4, 3 };\nstatic const int16_t kOverHangMax2LBR[3] = { 14, 7, 5 };\nstatic const int16_t kLocalThresholdLBR[3] = { 37, 32, 37 };\nstatic const int16_t kGlobalThresholdLBR[3] = { 100, 80, 100 };\n// Mode 2, Aggressive.\nstatic const int16_t kOverHangMax1AGG[3] = { 6, 3, 2 };\nstatic const int16_t kOverHangMax2AGG[3] = { 9, 5, 3 };\nstatic const int16_t kLocalThresholdAGG[3] = { 82, 78, 82 };\nstatic const int16_t kGlobalThresholdAGG[3] = { 285, 260, 285 };\n// Mode 3, Very aggressive.\nstatic const int16_t kOverHangMax1VAG[3] = { 6, 3, 2 };\nstatic const int16_t kOverHangMax2VAG[3] = { 9, 5, 3 };\nstatic const int16_t kLocalThresholdVAG[3] = { 94, 94, 94 };\nstatic const int16_t kGlobalThresholdVAG[3] = { 1100, 1050, 1100 };\n\n// Calculates the weighted average w.r.t. number of Gaussians. The |data| are\n// updated with an |offset| before averaging.\n//\n// - data     [i/o] : Data to average.\n// - offset   [i]   : An offset added to |data|.\n// - weights  [i]   : Weights used for averaging.\n//\n// returns          : The weighted average.\nstatic int32_t WeightedAverage(int16_t* data, int16_t offset,\n                               const int16_t* weights) {\n  int k;\n  int32_t weighted_average = 0;\n\n  for (k = 0; k < kNumGaussians; k++) {\n    data[k * kNumChannels] += offset;\n    weighted_average += data[k * kNumChannels] * weights[k * kNumChannels];\n  }\n  return weighted_average;\n}\n\n// An s16 x s32 -> s32 multiplication that's allowed to overflow. (It's still\n// undefined behavior, so not a good idea; this just makes UBSan ignore the\n// violation, so that our old code can continue to do what it's always been\n// doing.)\nstatic inline int32_t RTC_NO_SANITIZE(\"signed-integer-overflow\")\n    OverflowingMulS16ByS32ToS32(int16_t a, int32_t b) {\n  return a * b;\n}\n\n// Calculates the probabilities for both speech and background noise using\n// Gaussian Mixture Models (GMM). A hypothesis-test is performed to decide which\n// type of signal is most probable.\n//\n// - self           [i/o] : Pointer to VAD instance\n// - features       [i]   : Feature vector of length |kNumChannels|\n//                          = log10(energy in frequency band)\n// - total_power    [i]   : Total power in audio frame.\n// - frame_length   [i]   : Number of input samples\n//\n// - returns              : the VAD decision (0 - noise, 1 - speech).\nstatic int16_t GmmProbability(VadInstT* self, int16_t* features,\n                              int16_t total_power, size_t frame_length) {\n  int channel, k;\n  int16_t feature_minimum;\n  int16_t h0, h1;\n  int16_t log_likelihood_ratio;\n  int16_t vadflag = 0;\n  int16_t shifts_h0, shifts_h1;\n  int16_t tmp_s16, tmp1_s16, tmp2_s16;\n  int16_t diff;\n  int gaussian;\n  int16_t nmk, nmk2, nmk3, smk, smk2, nsk, ssk;\n  int16_t delt, ndelt;\n  int16_t maxspe, maxmu;\n  int16_t deltaN[kTableSize], deltaS[kTableSize];\n  int16_t ngprvec[kTableSize] = { 0 };  // Conditional probability = 0.\n  int16_t sgprvec[kTableSize] = { 0 };  // Conditional probability = 0.\n  int32_t h0_test, h1_test;\n  int32_t tmp1_s32, tmp2_s32;\n  int32_t sum_log_likelihood_ratios = 0;\n  int32_t noise_global_mean, speech_global_mean;\n  int32_t noise_probability[kNumGaussians], speech_probability[kNumGaussians];\n  int16_t overhead1, overhead2, individualTest, totalTest;\n\n  // Set various thresholds based on frame lengths (80, 160 or 240 samples).\n  if (frame_length == 80) {\n    overhead1 = self->over_hang_max_1[0];\n    overhead2 = self->over_hang_max_2[0];\n    individualTest = self->individual[0];\n    totalTest = self->total[0];\n  } else if (frame_length == 160) {\n    overhead1 = self->over_hang_max_1[1];\n    overhead2 = self->over_hang_max_2[1];\n    individualTest = self->individual[1];\n    totalTest = self->total[1];\n  } else {\n    overhead1 = self->over_hang_max_1[2];\n    overhead2 = self->over_hang_max_2[2];\n    individualTest = self->individual[2];\n    totalTest = self->total[2];\n  }\n\n  if (total_power > kMinEnergy) {\n    // The signal power of current_frame frame is large enough for processing. The\n    // processing consists of two parts:\n    // 1) Calculating the likelihood of speech and thereby a VAD decision.\n    // 2) Updating the underlying model, w.r.t., the decision made.\n\n    // The detection scheme is an LRT with hypothesis\n    // H0: Noise\n    // H1: Speech\n    //\n    // We combine a global LRT with local tests, for each frequency sub-band,\n    // here defined as |channel|.\n    for (channel = 0; channel < kNumChannels; channel++) {\n      // For each channel we model the probability with a GMM consisting of\n      // |kNumGaussians|, with different means and standard deviations depending\n      // on H0 or H1.\n      h0_test = 0;\n      h1_test = 0;\n      for (k = 0; k < kNumGaussians; k++) {\n        gaussian = channel + k * kNumChannels;\n        // Probability under H0, that is, probability of frame being noise.\n        // Value given in Q27 = Q7 * Q20.\n        tmp1_s32 = WebRtcVad_GaussianProbability(features[channel],\n                                                 self->noise_means[gaussian],\n                                                 self->noise_stds[gaussian],\n                                                 &deltaN[gaussian]);\n        noise_probability[k] = kNoiseDataWeights[gaussian] * tmp1_s32;\n        h0_test += noise_probability[k];  // Q27\n\n        // Probability under H1, that is, probability of frame being speech.\n        // Value given in Q27 = Q7 * Q20.\n        tmp1_s32 = WebRtcVad_GaussianProbability(features[channel],\n                                                 self->speech_means[gaussian],\n                                                 self->speech_stds[gaussian],\n                                                 &deltaS[gaussian]);\n        speech_probability[k] = kSpeechDataWeights[gaussian] * tmp1_s32;\n        h1_test += speech_probability[k];  // Q27\n      }\n\n      // Calculate the log likelihood ratio: log2(Pr{X|H1} / Pr{X|H1}).\n      // Approximation:\n      // log2(Pr{X|H1} / Pr{X|H1}) = log2(Pr{X|H1}*2^Q) - log2(Pr{X|H1}*2^Q)\n      //                           = log2(h1_test) - log2(h0_test)\n      //                           = log2(2^(31-shifts_h1)*(1+b1))\n      //                             - log2(2^(31-shifts_h0)*(1+b0))\n      //                           = shifts_h0 - shifts_h1\n      //                             + log2(1+b1) - log2(1+b0)\n      //                          ~= shifts_h0 - shifts_h1\n      //\n      // Note that b0 and b1 are values less than 1, hence, 0 <= log2(1+b0) < 1.\n      // Further, b0 and b1 are independent and on the average the two terms\n      // cancel.\n      shifts_h0 = WebRtcSpl_NormW32(h0_test);\n      shifts_h1 = WebRtcSpl_NormW32(h1_test);\n      if (h0_test == 0) {\n        shifts_h0 = 31;\n      }\n      if (h1_test == 0) {\n        shifts_h1 = 31;\n      }\n      log_likelihood_ratio = shifts_h0 - shifts_h1;\n\n      // Update |sum_log_likelihood_ratios| with spectrum weighting. This is\n      // used for the global VAD decision.\n      sum_log_likelihood_ratios +=\n          (int32_t) (log_likelihood_ratio * kSpectrumWeight[channel]);\n\n      // Local VAD decision.\n      if ((log_likelihood_ratio * 4) > individualTest) {\n        vadflag = 1;\n      }\n\n      // TODO(bjornv): The conditional probabilities below are applied on the\n      // hard coded number of Gaussians set to two. Find a way to generalize.\n      // Calculate local noise probabilities used later when updating the GMM.\n      h0 = (int16_t) (h0_test >> 12);  // Q15\n      if (h0 > 0) {\n        // High probability of noise. Assign conditional probabilities for each\n        // Gaussian in the GMM.\n        tmp1_s32 = (noise_probability[0] & 0xFFFFF000) << 2;  // Q29\n        ngprvec[channel] = (int16_t) WebRtcSpl_DivW32W16(tmp1_s32, h0);  // Q14\n        ngprvec[channel + kNumChannels] = 16384 - ngprvec[channel];\n      } else {\n        // Low noise probability. Assign conditional probability 1 to the first\n        // Gaussian and 0 to the rest (which is already set at initialization).\n        ngprvec[channel] = 16384;\n      }\n\n      // Calculate local speech probabilities used later when updating the GMM.\n      h1 = (int16_t) (h1_test >> 12);  // Q15\n      if (h1 > 0) {\n        // High probability of speech. Assign conditional probabilities for each\n        // Gaussian in the GMM. Otherwise use the initialized values, i.e., 0.\n        tmp1_s32 = (speech_probability[0] & 0xFFFFF000) << 2;  // Q29\n        sgprvec[channel] = (int16_t) WebRtcSpl_DivW32W16(tmp1_s32, h1);  // Q14\n        sgprvec[channel + kNumChannels] = 16384 - sgprvec[channel];\n      }\n    }\n\n    // Make a global VAD decision.\n    vadflag |= (sum_log_likelihood_ratios >= totalTest);\n\n    // Update the model parameters.\n    maxspe = 12800;\n    for (channel = 0; channel < kNumChannels; channel++) {\n\n      // Get minimum value in past which is used for long term correction in Q4.\n      feature_minimum = WebRtcVad_FindMinimum(self, features[channel], channel);\n\n      // Compute the \"global\" mean, that is the sum of the two means weighted.\n      noise_global_mean = WeightedAverage(&self->noise_means[channel], 0,\n                                          &kNoiseDataWeights[channel]);\n      tmp1_s16 = (int16_t) (noise_global_mean >> 6);  // Q8\n\n      for (k = 0; k < kNumGaussians; k++) {\n        gaussian = channel + k * kNumChannels;\n\n        nmk = self->noise_means[gaussian];\n        smk = self->speech_means[gaussian];\n        nsk = self->noise_stds[gaussian];\n        ssk = self->speech_stds[gaussian];\n\n        // Update noise mean vector if the frame consists of noise only.\n        nmk2 = nmk;\n        if (!vadflag) {\n          // deltaN = (x-mu)/sigma^2\n          // ngprvec[k] = |noise_probability[k]| /\n          //   (|noise_probability[0]| + |noise_probability[1]|)\n\n          // (Q14 * Q11 >> 11) = Q14.\n          delt = (int16_t)((ngprvec[gaussian] * deltaN[gaussian]) >> 11);\n          // Q7 + (Q14 * Q15 >> 22) = Q7.\n          nmk2 = nmk + (int16_t)((delt * kNoiseUpdateConst) >> 22);\n        }\n\n        // Long term correction of the noise mean.\n        // Q8 - Q8 = Q8.\n        ndelt = (feature_minimum << 4) - tmp1_s16;\n        // Q7 + (Q8 * Q8) >> 9 = Q7.\n        nmk3 = nmk2 + (int16_t)((ndelt * kBackEta) >> 9);\n\n        // Control that the noise mean does not drift to much.\n        tmp_s16 = (int16_t) ((k + 5) << 7);\n        if (nmk3 < tmp_s16) {\n          nmk3 = tmp_s16;\n        }\n        tmp_s16 = (int16_t) ((72 + k - channel) << 7);\n        if (nmk3 > tmp_s16) {\n          nmk3 = tmp_s16;\n        }\n        self->noise_means[gaussian] = nmk3;\n\n        if (vadflag) {\n          // Update speech mean vector:\n          // |deltaS| = (x-mu)/sigma^2\n          // sgprvec[k] = |speech_probability[k]| /\n          //   (|speech_probability[0]| + |speech_probability[1]|)\n\n          // (Q14 * Q11) >> 11 = Q14.\n          delt = (int16_t)((sgprvec[gaussian] * deltaS[gaussian]) >> 11);\n          // Q14 * Q15 >> 21 = Q8.\n          tmp_s16 = (int16_t)((delt * kSpeechUpdateConst) >> 21);\n          // Q7 + (Q8 >> 1) = Q7. With rounding.\n          smk2 = smk + ((tmp_s16 + 1) >> 1);\n\n          // Control that the speech mean does not drift to much.\n          maxmu = maxspe + 640;\n          if (smk2 < kMinimumMean[k]) {\n            smk2 = kMinimumMean[k];\n          }\n          if (smk2 > maxmu) {\n            smk2 = maxmu;\n          }\n          self->speech_means[gaussian] = smk2;  // Q7.\n\n          // (Q7 >> 3) = Q4. With rounding.\n          tmp_s16 = ((smk + 4) >> 3);\n\n          tmp_s16 = features[channel] - tmp_s16;  // Q4\n          // (Q11 * Q4 >> 3) = Q12.\n          tmp1_s32 = (deltaS[gaussian] * tmp_s16) >> 3;\n          tmp2_s32 = tmp1_s32 - 4096;\n          tmp_s16 = sgprvec[gaussian] >> 2;\n          // (Q14 >> 2) * Q12 = Q24.\n          tmp1_s32 = tmp_s16 * tmp2_s32;\n\n          tmp2_s32 = tmp1_s32 >> 4;  // Q20\n\n          // 0.1 * Q20 / Q7 = Q13.\n          if (tmp2_s32 > 0) {\n            tmp_s16 = (int16_t) WebRtcSpl_DivW32W16(tmp2_s32, ssk * 10);\n          } else {\n            tmp_s16 = (int16_t) WebRtcSpl_DivW32W16(-tmp2_s32, ssk * 10);\n            tmp_s16 = -tmp_s16;\n          }\n          // Divide by 4 giving an update factor of 0.025 (= 0.1 / 4).\n          // Note that division by 4 equals shift by 2, hence,\n          // (Q13 >> 8) = (Q13 >> 6) / 4 = Q7.\n          tmp_s16 += 128;  // Rounding.\n          ssk += (tmp_s16 >> 8);\n          if (ssk < kMinStd) {\n            ssk = kMinStd;\n          }\n          self->speech_stds[gaussian] = ssk;\n        } else {\n          // Update GMM variance vectors.\n          // deltaN * (features[channel] - nmk) - 1\n          // Q4 - (Q7 >> 3) = Q4.\n          tmp_s16 = features[channel] - (nmk >> 3);\n          // (Q11 * Q4 >> 3) = Q12.\n          tmp1_s32 = (deltaN[gaussian] * tmp_s16) >> 3;\n          tmp1_s32 -= 4096;\n\n          // (Q14 >> 2) * Q12 = Q24.\n          tmp_s16 = (ngprvec[gaussian] + 2) >> 2;\n          tmp2_s32 = OverflowingMulS16ByS32ToS32(tmp_s16, tmp1_s32);\n          // Q20  * approx 0.001 (2^-10=0.0009766), hence,\n          // (Q24 >> 14) = (Q24 >> 4) / 2^10 = Q20.\n          tmp1_s32 = tmp2_s32 >> 14;\n\n          // Q20 / Q7 = Q13.\n          if (tmp1_s32 > 0) {\n            tmp_s16 = (int16_t) WebRtcSpl_DivW32W16(tmp1_s32, nsk);\n          } else {\n            tmp_s16 = (int16_t) WebRtcSpl_DivW32W16(-tmp1_s32, nsk);\n            tmp_s16 = -tmp_s16;\n          }\n          tmp_s16 += 32;  // Rounding\n          nsk += tmp_s16 >> 6;  // Q13 >> 6 = Q7.\n          if (nsk < kMinStd) {\n            nsk = kMinStd;\n          }\n          self->noise_stds[gaussian] = nsk;\n        }\n      }\n\n      // Separate models if they are too close.\n      // |noise_global_mean| in Q14 (= Q7 * Q7).\n      noise_global_mean = WeightedAverage(&self->noise_means[channel], 0,\n                                          &kNoiseDataWeights[channel]);\n\n      // |speech_global_mean| in Q14 (= Q7 * Q7).\n      speech_global_mean = WeightedAverage(&self->speech_means[channel], 0,\n                                           &kSpeechDataWeights[channel]);\n\n      // |diff| = \"global\" speech mean - \"global\" noise mean.\n      // (Q14 >> 9) - (Q14 >> 9) = Q5.\n      diff = (int16_t) (speech_global_mean >> 9) -\n          (int16_t) (noise_global_mean >> 9);\n      if (diff < kMinimumDifference[channel]) {\n        tmp_s16 = kMinimumDifference[channel] - diff;\n\n        // |tmp1_s16| = ~0.8 * (kMinimumDifference - diff) in Q7.\n        // |tmp2_s16| = ~0.2 * (kMinimumDifference - diff) in Q7.\n        tmp1_s16 = (int16_t)((13 * tmp_s16) >> 2);\n        tmp2_s16 = (int16_t)((3 * tmp_s16) >> 2);\n\n        // Move Gaussian means for speech model by |tmp1_s16| and update\n        // |speech_global_mean|. Note that |self->speech_means[channel]| is\n        // changed after the call.\n        speech_global_mean = WeightedAverage(&self->speech_means[channel],\n                                             tmp1_s16,\n                                             &kSpeechDataWeights[channel]);\n\n        // Move Gaussian means for noise model by -|tmp2_s16| and update\n        // |noise_global_mean|. Note that |self->noise_means[channel]| is\n        // changed after the call.\n        noise_global_mean = WeightedAverage(&self->noise_means[channel],\n                                            -tmp2_s16,\n                                            &kNoiseDataWeights[channel]);\n      }\n\n      // Control that the speech & noise means do not drift to much.\n      maxspe = kMaximumSpeech[channel];\n      tmp2_s16 = (int16_t) (speech_global_mean >> 7);\n      if (tmp2_s16 > maxspe) {\n        // Upper limit of speech model.\n        tmp2_s16 -= maxspe;\n\n        for (k = 0; k < kNumGaussians; k++) {\n          self->speech_means[channel + k * kNumChannels] -= tmp2_s16;\n        }\n      }\n\n      tmp2_s16 = (int16_t) (noise_global_mean >> 7);\n      if (tmp2_s16 > kMaximumNoise[channel]) {\n        tmp2_s16 -= kMaximumNoise[channel];\n\n        for (k = 0; k < kNumGaussians; k++) {\n          self->noise_means[channel + k * kNumChannels] -= tmp2_s16;\n        }\n      }\n    }\n    self->frame_counter++;\n  }\n\n  // Smooth with respect to transition hysteresis.\n  if (!vadflag) {\n    if (self->over_hang > 0) {\n      vadflag = 2 + self->over_hang;\n      self->over_hang--;\n    }\n    self->num_of_speech = 0;\n  } else {\n    self->num_of_speech++;\n    if (self->num_of_speech > kMaxSpeechFrames) {\n      self->num_of_speech = kMaxSpeechFrames;\n      self->over_hang = overhead2;\n    } else {\n      self->over_hang = overhead1;\n    }\n  }\n  return vadflag;\n}\n\n// Initialize the VAD. Set aggressiveness mode to default value.\nint WebRtcVad_InitCore(VadInstT* self) {\n  int i;\n\n  if (self == NULL) {\n    return -1;\n  }\n\n  // Initialization of general struct variables.\n  self->vad = 1;  // Speech active (=1).\n  self->frame_counter = 0;\n  self->over_hang = 0;\n  self->num_of_speech = 0;\n\n  // Initialization of downsampling filter state.\n  memset(self->downsampling_filter_states, 0,\n         sizeof(self->downsampling_filter_states));\n\n  // Initialization of 48 to 8 kHz downsampling.\n  WebRtcSpl_ResetResample48khzTo8khz(&self->state_48_to_8);\n\n  // Read initial PDF parameters.\n  for (i = 0; i < kTableSize; i++) {\n    self->noise_means[i] = kNoiseDataMeans[i];\n    self->speech_means[i] = kSpeechDataMeans[i];\n    self->noise_stds[i] = kNoiseDataStds[i];\n    self->speech_stds[i] = kSpeechDataStds[i];\n  }\n\n  // Initialize Index and Minimum value vectors.\n  for (i = 0; i < 16 * kNumChannels; i++) {\n    self->low_value_vector[i] = 10000;\n    self->index_vector[i] = 0;\n  }\n\n  // Initialize splitting filter states.\n  memset(self->upper_state, 0, sizeof(self->upper_state));\n  memset(self->lower_state, 0, sizeof(self->lower_state));\n\n  // Initialize high pass filter states.\n  memset(self->hp_filter_state, 0, sizeof(self->hp_filter_state));\n\n  // Initialize mean value memory, for WebRtcVad_FindMinimum().\n  for (i = 0; i < kNumChannels; i++) {\n    self->mean_value[i] = 1600;\n  }\n\n  // Set aggressiveness mode to default (=|kDefaultMode|).\n  if (WebRtcVad_set_mode_core(self, kDefaultMode) != 0) {\n    return -1;\n  }\n\n  self->init_flag = kInitCheck;\n\n  return 0;\n}\n\n// Set aggressiveness mode\nint WebRtcVad_set_mode_core(VadInstT* self, int mode) {\n  int return_value = 0;\n\n  switch (mode) {\n    case 0:\n      // Quality mode.\n      memcpy(self->over_hang_max_1, kOverHangMax1Q,\n             sizeof(self->over_hang_max_1));\n      memcpy(self->over_hang_max_2, kOverHangMax2Q,\n             sizeof(self->over_hang_max_2));\n      memcpy(self->individual, kLocalThresholdQ,\n             sizeof(self->individual));\n      memcpy(self->total, kGlobalThresholdQ,\n             sizeof(self->total));\n      break;\n    case 1:\n      // Low bitrate mode.\n      memcpy(self->over_hang_max_1, kOverHangMax1LBR,\n             sizeof(self->over_hang_max_1));\n      memcpy(self->over_hang_max_2, kOverHangMax2LBR,\n             sizeof(self->over_hang_max_2));\n      memcpy(self->individual, kLocalThresholdLBR,\n             sizeof(self->individual));\n      memcpy(self->total, kGlobalThresholdLBR,\n             sizeof(self->total));\n      break;\n    case 2:\n      // Aggressive mode.\n      memcpy(self->over_hang_max_1, kOverHangMax1AGG,\n             sizeof(self->over_hang_max_1));\n      memcpy(self->over_hang_max_2, kOverHangMax2AGG,\n             sizeof(self->over_hang_max_2));\n      memcpy(self->individual, kLocalThresholdAGG,\n             sizeof(self->individual));\n      memcpy(self->total, kGlobalThresholdAGG,\n             sizeof(self->total));\n      break;\n    case 3:\n      // Very aggressive mode.\n      memcpy(self->over_hang_max_1, kOverHangMax1VAG,\n             sizeof(self->over_hang_max_1));\n      memcpy(self->over_hang_max_2, kOverHangMax2VAG,\n             sizeof(self->over_hang_max_2));\n      memcpy(self->individual, kLocalThresholdVAG,\n             sizeof(self->individual));\n      memcpy(self->total, kGlobalThresholdVAG,\n             sizeof(self->total));\n      break;\n    default:\n      return_value = -1;\n      break;\n  }\n\n  return return_value;\n}\n\n// Calculate VAD decision by first extracting feature values and then calculate\n// probability for both speech and background noise.\n\nint WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,\n                           size_t frame_length) {\n  int vad;\n  size_t i;\n  int16_t speech_nb[240];  // 30 ms in 8 kHz.\n  // |tmp_mem| is a temporary memory used by resample function, length is\n  // frame length in 10 ms (480 samples) + 256 extra.\n  int32_t tmp_mem[480 + 256] = { 0 };\n  const size_t kFrameLen10ms48khz = 480;\n  const size_t kFrameLen10ms8khz = 80;\n  size_t num_10ms_frames = frame_length / kFrameLen10ms48khz;\n\n  for (i = 0; i < num_10ms_frames; i++) {\n    WebRtcSpl_Resample48khzTo8khz(speech_frame,\n                                  &speech_nb[i * kFrameLen10ms8khz],\n                                  &inst->state_48_to_8,\n                                  tmp_mem);\n  }\n\n  // Do VAD on an 8 kHz signal\n  vad = WebRtcVad_CalcVad8khz(inst, speech_nb, frame_length / 6);\n\n  return vad;\n}\n\nint WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,\n                           size_t frame_length)\n{\n    size_t len;\n    int vad;\n    int16_t speechWB[480]; // Downsampled speech frame: 960 samples (30ms in SWB)\n    int16_t speechNB[240]; // Downsampled speech frame: 480 samples (30ms in WB)\n\n\n    // Downsample signal 32->16->8 before doing VAD\n    WebRtcVad_Downsampling(speech_frame, speechWB, &(inst->downsampling_filter_states[2]),\n                           frame_length);\n    len = frame_length / 2;\n\n    WebRtcVad_Downsampling(speechWB, speechNB, inst->downsampling_filter_states, len);\n    len /= 2;\n\n    // Do VAD on an 8 kHz signal\n    vad = WebRtcVad_CalcVad8khz(inst, speechNB, len);\n\n    return vad;\n}\n\nint WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,\n                           size_t frame_length)\n{\n    size_t len;\n    int vad;\n    int16_t speechNB[240]; // Downsampled speech frame: 480 samples (30ms in WB)\n\n    // Wideband: Downsample signal before doing VAD\n    WebRtcVad_Downsampling(speech_frame, speechNB, inst->downsampling_filter_states,\n                           frame_length);\n\n    len = frame_length / 2;\n    vad = WebRtcVad_CalcVad8khz(inst, speechNB, len);\n\n    return vad;\n}\n\nint WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame,\n                          size_t frame_length)\n{\n    int16_t feature_vector[kNumChannels], total_power;\n\n    // Get power in the bands\n    total_power = WebRtcVad_CalculateFeatures(inst, speech_frame, frame_length,\n                                              feature_vector);\n\n    // Make a VAD\n    inst->vad = GmmProbability(inst, feature_vector, total_power, frame_length);\n\n    return inst->vad;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_core.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n/*\n * This header file includes the descriptions of the core VAD calls.\n */\n\n#ifndef COMMON_AUDIO_VAD_VAD_CORE_H_\n#define COMMON_AUDIO_VAD_VAD_CORE_H_\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nenum { kNumChannels = 6 };  // Number of frequency bands (named channels).\nenum { kNumGaussians = 2 };  // Number of Gaussians per channel in the GMM.\nenum { kTableSize = kNumChannels * kNumGaussians };\nenum { kMinEnergy = 10 };  // Minimum energy required to trigger audio signal.\n\ntypedef struct VadInstT_ {\n    int vad;\n    int32_t downsampling_filter_states[4];\n    WebRtcSpl_State48khzTo8khz state_48_to_8;\n    int16_t noise_means[kTableSize];\n    int16_t speech_means[kTableSize];\n    int16_t noise_stds[kTableSize];\n    int16_t speech_stds[kTableSize];\n    // TODO(bjornv): Change to |frame_count|.\n    int32_t frame_counter;\n    int16_t over_hang;  // Over Hang\n    int16_t num_of_speech;\n    // TODO(bjornv): Change to |age_vector|.\n    int16_t index_vector[16 * kNumChannels];\n    int16_t low_value_vector[16 * kNumChannels];\n    // TODO(bjornv): Change to |median|.\n    int16_t mean_value[kNumChannels];\n    int16_t upper_state[5];\n    int16_t lower_state[5];\n    int16_t hp_filter_state[4];\n    int16_t over_hang_max_1[3];\n    int16_t over_hang_max_2[3];\n    int16_t individual[3];\n    int16_t total[3];\n\n    int init_flag;\n} VadInstT;\n\n// Initializes the core VAD component. The default aggressiveness mode is\n// controlled by |kDefaultMode| in vad_core.c.\n//\n// - self [i/o] : Instance that should be initialized\n//\n// returns      : 0 (OK), -1 (null pointer in or if the default mode can't be\n//                set)\nint WebRtcVad_InitCore(VadInstT* self);\n\n/****************************************************************************\n * WebRtcVad_set_mode_core(...)\n *\n * This function changes the VAD settings\n *\n * Input:\n *      - inst      : VAD instance\n *      - mode      : Aggressiveness degree\n *                    0 (High quality) - 3 (Highly aggressive)\n *\n * Output:\n *      - inst      : Changed  instance\n *\n * Return value     :  0 - Ok\n *                    -1 - Error\n */\n\nint WebRtcVad_set_mode_core(VadInstT* self, int mode);\n\n/****************************************************************************\n * WebRtcVad_CalcVad48khz(...)\n * WebRtcVad_CalcVad32khz(...)\n * WebRtcVad_CalcVad16khz(...)\n * WebRtcVad_CalcVad8khz(...)\n *\n * Calculate probability for active speech and make VAD decision.\n *\n * Input:\n *      - inst          : Instance that should be initialized\n *      - speech_frame  : Input speech frame\n *      - frame_length  : Number of input samples\n *\n * Output:\n *      - inst          : Updated filter states etc.\n *\n * Return value         : VAD decision\n *                        0 - No active speech\n *                        1-6 - Active speech\n */\nint WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,\n                           size_t frame_length);\nint WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,\n                           size_t frame_length);\nint WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,\n                           size_t frame_length);\nint WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame,\n                          size_t frame_length);\n\n#endif  // COMMON_AUDIO_VAD_VAD_CORE_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_core_unittest.cc",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include <stdlib.h>\n\n#include \"common_audio/vad/vad_unittest.h\"\n#include \"test/gtest.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nextern \"C\" {\n#include \"common_audio/vad/vad_core.h\"\n}\n\nnamespace webrtc {\nnamespace test {\n\nTEST_F(VadTest, InitCore) {\n  // Test WebRtcVad_InitCore().\n  VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));\n\n  // null pointer test.\n  EXPECT_EQ(-1, WebRtcVad_InitCore(nullptr));\n\n  // Verify return = 0 for non-null pointer.\n  EXPECT_EQ(0, WebRtcVad_InitCore(self));\n  // Verify init_flag is set.\n  EXPECT_EQ(42, self->init_flag);\n\n  free(self);\n}\n\nTEST_F(VadTest, set_mode_core) {\n  VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));\n\n  // TODO(bjornv): Add null pointer check if we take care of it in\n  // vad_core.c\n\n  ASSERT_EQ(0, WebRtcVad_InitCore(self));\n  // Test WebRtcVad_set_mode_core().\n  // Invalid modes should return -1.\n  EXPECT_EQ(-1, WebRtcVad_set_mode_core(self, -1));\n  EXPECT_EQ(-1, WebRtcVad_set_mode_core(self, 1000));\n  // Valid modes should return 0.\n  for (size_t j = 0; j < kModesSize; ++j) {\n    EXPECT_EQ(0, WebRtcVad_set_mode_core(self, kModes[j]));\n  }\n\n  free(self);\n}\n\nTEST_F(VadTest, CalcVad) {\n  VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));\n  int16_t speech[kMaxFrameLength];\n\n  // TODO(bjornv): Add null pointer check if we take care of it in\n  // vad_core.c\n\n  // Test WebRtcVad_CalcVadXXkhz()\n  // Verify that all zeros in gives VAD = 0 out.\n  memset(speech, 0, sizeof(speech));\n  ASSERT_EQ(0, WebRtcVad_InitCore(self));\n  for (size_t j = 0; j < kFrameLengthsSize; ++j) {\n    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {\n      EXPECT_EQ(0, WebRtcVad_CalcVad8khz(self, speech, kFrameLengths[j]));\n    }\n    if (ValidRatesAndFrameLengths(16000, kFrameLengths[j])) {\n      EXPECT_EQ(0, WebRtcVad_CalcVad16khz(self, speech, kFrameLengths[j]));\n    }\n    if (ValidRatesAndFrameLengths(32000, kFrameLengths[j])) {\n      EXPECT_EQ(0, WebRtcVad_CalcVad32khz(self, speech, kFrameLengths[j]));\n    }\n    if (ValidRatesAndFrameLengths(48000, kFrameLengths[j])) {\n      EXPECT_EQ(0, WebRtcVad_CalcVad48khz(self, speech, kFrameLengths[j]));\n    }\n  }\n\n  // Construct a speech signal that will trigger the VAD in all modes. It is\n  // known that (i * i) will wrap around, but that doesn't matter in this case.\n  for (size_t i = 0; i < kMaxFrameLength; ++i) {\n    speech[i] = static_cast<int16_t>(i * i);\n  }\n  for (size_t j = 0; j < kFrameLengthsSize; ++j) {\n    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {\n      EXPECT_EQ(1, WebRtcVad_CalcVad8khz(self, speech, kFrameLengths[j]));\n    }\n    if (ValidRatesAndFrameLengths(16000, kFrameLengths[j])) {\n      EXPECT_EQ(1, WebRtcVad_CalcVad16khz(self, speech, kFrameLengths[j]));\n    }\n    if (ValidRatesAndFrameLengths(32000, kFrameLengths[j])) {\n      EXPECT_EQ(1, WebRtcVad_CalcVad32khz(self, speech, kFrameLengths[j]));\n    }\n    if (ValidRatesAndFrameLengths(48000, kFrameLengths[j])) {\n      EXPECT_EQ(1, WebRtcVad_CalcVad48khz(self, speech, kFrameLengths[j]));\n    }\n  }\n\n  free(self);\n}\n}  // namespace test\n}  // namespace webrtc\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_filterbank.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/vad_filterbank.h\"\n\n#include \"rtc_base/checks.h\"\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// Constants used in LogOfEnergy().\nstatic const int16_t kLogConst = 24660;  // 160*log10(2) in Q9.\nstatic const int16_t kLogEnergyIntPart = 14336;  // 14 in Q10\n\n// Coefficients used by HighPassFilter, Q14.\nstatic const int16_t kHpZeroCoefs[3] = { 6631, -13262, 6631 };\nstatic const int16_t kHpPoleCoefs[3] = { 16384, -7756, 5620 };\n\n// Allpass filter coefficients, upper and lower, in Q15.\n// Upper: 0.64, Lower: 0.17\nstatic const int16_t kAllPassCoefsQ15[2] = { 20972, 5571 };\n\n// Adjustment for division with two in SplitFilter.\nstatic const int16_t kOffsetVector[6] = { 368, 368, 272, 176, 176, 176 };\n\n// High pass filtering, with a cut-off frequency at 80 Hz, if the |data_in| is\n// sampled at 500 Hz.\n//\n// - data_in      [i]   : Input audio data sampled at 500 Hz.\n// - data_length  [i]   : Length of input and output data.\n// - filter_state [i/o] : State of the filter.\n// - data_out     [o]   : Output audio data in the frequency interval\n//                        80 - 250 Hz.\nstatic void HighPassFilter(const int16_t* data_in, size_t data_length,\n                           int16_t* filter_state, int16_t* data_out) {\n  size_t i;\n  const int16_t* in_ptr = data_in;\n  int16_t* out_ptr = data_out;\n  int32_t tmp32 = 0;\n\n\n  // The sum of the absolute values of the impulse response:\n  // The zero/pole-filter has a max amplification of a single sample of: 1.4546\n  // Impulse response: 0.4047 -0.6179 -0.0266  0.1993  0.1035  -0.0194\n  // The all-zero section has a max amplification of a single sample of: 1.6189\n  // Impulse response: 0.4047 -0.8094  0.4047  0       0        0\n  // The all-pole section has a max amplification of a single sample of: 1.9931\n  // Impulse response: 1.0000  0.4734 -0.1189 -0.2187 -0.0627   0.04532\n\n  for (i = 0; i < data_length; i++) {\n    // All-zero section (filter coefficients in Q14).\n    tmp32 = kHpZeroCoefs[0] * *in_ptr;\n    tmp32 += kHpZeroCoefs[1] * filter_state[0];\n    tmp32 += kHpZeroCoefs[2] * filter_state[1];\n    filter_state[1] = filter_state[0];\n    filter_state[0] = *in_ptr++;\n\n    // All-pole section (filter coefficients in Q14).\n    tmp32 -= kHpPoleCoefs[1] * filter_state[2];\n    tmp32 -= kHpPoleCoefs[2] * filter_state[3];\n    filter_state[3] = filter_state[2];\n    filter_state[2] = (int16_t) (tmp32 >> 14);\n    *out_ptr++ = filter_state[2];\n  }\n}\n\n// All pass filtering of |data_in|, used before splitting the signal into two\n// frequency bands (low pass vs high pass).\n// Note that |data_in| and |data_out| can NOT correspond to the same address.\n//\n// - data_in            [i]   : Input audio signal given in Q0.\n// - data_length        [i]   : Length of input and output data.\n// - filter_coefficient [i]   : Given in Q15.\n// - filter_state       [i/o] : State of the filter given in Q(-1).\n// - data_out           [o]   : Output audio signal given in Q(-1).\nstatic void AllPassFilter(const int16_t* data_in, size_t data_length,\n                          int16_t filter_coefficient, int16_t* filter_state,\n                          int16_t* data_out) {\n  // The filter can only cause overflow (in the w16 output variable)\n  // if more than 4 consecutive input numbers are of maximum value and\n  // has the the same sign as the impulse responses first taps.\n  // First 6 taps of the impulse response:\n  // 0.6399 0.5905 -0.3779 0.2418 -0.1547 0.0990\n\n  size_t i;\n  int16_t tmp16 = 0;\n  int32_t tmp32 = 0;\n  int32_t state32 = ((int32_t) (*filter_state) * (1 << 16));  // Q15\n\n  for (i = 0; i < data_length; i++) {\n    tmp32 = state32 + filter_coefficient * *data_in;\n    tmp16 = (int16_t) (tmp32 >> 16);  // Q(-1)\n    *data_out++ = tmp16;\n    state32 = (*data_in * (1 << 14)) - filter_coefficient * tmp16;  // Q14\n    state32 *= 2;  // Q15.\n    data_in += 2;\n  }\n\n  *filter_state = (int16_t) (state32 >> 16);  // Q(-1)\n}\n\n// Splits |data_in| into |hp_data_out| and |lp_data_out| corresponding to\n// an upper (high pass) part and a lower (low pass) part respectively.\n//\n// - data_in      [i]   : Input audio data to be split into two frequency bands.\n// - data_length  [i]   : Length of |data_in|.\n// - upper_state  [i/o] : State of the upper filter, given in Q(-1).\n// - lower_state  [i/o] : State of the lower filter, given in Q(-1).\n// - hp_data_out  [o]   : Output audio data of the upper half of the spectrum.\n//                        The length is |data_length| / 2.\n// - lp_data_out  [o]   : Output audio data of the lower half of the spectrum.\n//                        The length is |data_length| / 2.\nstatic void SplitFilter(const int16_t* data_in, size_t data_length,\n                        int16_t* upper_state, int16_t* lower_state,\n                        int16_t* hp_data_out, int16_t* lp_data_out) {\n  size_t i;\n  size_t half_length = data_length >> 1;  // Downsampling by 2.\n  int16_t tmp_out;\n\n  // All-pass filtering upper branch.\n  AllPassFilter(&data_in[0], half_length, kAllPassCoefsQ15[0], upper_state,\n                hp_data_out);\n\n  // All-pass filtering lower branch.\n  AllPassFilter(&data_in[1], half_length, kAllPassCoefsQ15[1], lower_state,\n                lp_data_out);\n\n  // Make LP and HP signals.\n  for (i = 0; i < half_length; i++) {\n    tmp_out = *hp_data_out;\n    *hp_data_out++ -= *lp_data_out;\n    *lp_data_out++ += tmp_out;\n  }\n}\n\n// Calculates the energy of |data_in| in dB, and also updates an overall\n// |total_energy| if necessary.\n//\n// - data_in      [i]   : Input audio data for energy calculation.\n// - data_length  [i]   : Length of input data.\n// - offset       [i]   : Offset value added to |log_energy|.\n// - total_energy [i/o] : An external energy updated with the energy of\n//                        |data_in|.\n//                        NOTE: |total_energy| is only updated if\n//                        |total_energy| <= |kMinEnergy|.\n// - log_energy   [o]   : 10 * log10(\"energy of |data_in|\") given in Q4.\nstatic void LogOfEnergy(const int16_t* data_in, size_t data_length,\n                        int16_t offset, int16_t* total_energy,\n                        int16_t* log_energy) {\n  // |tot_rshifts| accumulates the number of right shifts performed on |energy|.\n  int tot_rshifts = 0;\n  // The |energy| will be normalized to 15 bits. We use unsigned integer because\n  // we eventually will mask out the fractional part.\n  uint32_t energy = 0;\n\n  RTC_DCHECK(data_in);\n  RTC_DCHECK_GT(data_length, 0);\n\n  energy = (uint32_t) WebRtcSpl_Energy((int16_t*) data_in, data_length,\n                                       &tot_rshifts);\n\n  if (energy != 0) {\n    // By construction, normalizing to 15 bits is equivalent with 17 leading\n    // zeros of an unsigned 32 bit value.\n    int normalizing_rshifts = 17 - WebRtcSpl_NormU32(energy);\n    // In a 15 bit representation the leading bit is 2^14. log2(2^14) in Q10 is\n    // (14 << 10), which is what we initialize |log2_energy| with. For a more\n    // detailed derivations, see below.\n    int16_t log2_energy = kLogEnergyIntPart;\n\n    tot_rshifts += normalizing_rshifts;\n    // Normalize |energy| to 15 bits.\n    // |tot_rshifts| is now the total number of right shifts performed on\n    // |energy| after normalization. This means that |energy| is in\n    // Q(-tot_rshifts).\n    if (normalizing_rshifts < 0) {\n      energy <<= -normalizing_rshifts;\n    } else {\n      energy >>= normalizing_rshifts;\n    }\n\n    // Calculate the energy of |data_in| in dB, in Q4.\n    //\n    // 10 * log10(\"true energy\") in Q4 = 2^4 * 10 * log10(\"true energy\") =\n    // 160 * log10(|energy| * 2^|tot_rshifts|) =\n    // 160 * log10(2) * log2(|energy| * 2^|tot_rshifts|) =\n    // 160 * log10(2) * (log2(|energy|) + log2(2^|tot_rshifts|)) =\n    // (160 * log10(2)) * (log2(|energy|) + |tot_rshifts|) =\n    // |kLogConst| * (|log2_energy| + |tot_rshifts|)\n    //\n    // We know by construction that |energy| is normalized to 15 bits. Hence,\n    // |energy| = 2^14 + frac_Q15, where frac_Q15 is a fractional part in Q15.\n    // Further, we'd like |log2_energy| in Q10\n    // log2(|energy|) in Q10 = 2^10 * log2(2^14 + frac_Q15) =\n    // 2^10 * log2(2^14 * (1 + frac_Q15 * 2^-14)) =\n    // 2^10 * (14 + log2(1 + frac_Q15 * 2^-14)) ~=\n    // (14 << 10) + 2^10 * (frac_Q15 * 2^-14) =\n    // (14 << 10) + (frac_Q15 * 2^-4) = (14 << 10) + (frac_Q15 >> 4)\n    //\n    // Note that frac_Q15 = (|energy| & 0x00003FFF)\n\n    // Calculate and add the fractional part to |log2_energy|.\n    log2_energy += (int16_t) ((energy & 0x00003FFF) >> 4);\n\n    // |kLogConst| is in Q9, |log2_energy| in Q10 and |tot_rshifts| in Q0.\n    // Note that we in our derivation above have accounted for an output in Q4.\n    *log_energy = (int16_t)(((kLogConst * log2_energy) >> 19) +\n        ((tot_rshifts * kLogConst) >> 9));\n\n    if (*log_energy < 0) {\n      *log_energy = 0;\n    }\n  } else {\n    *log_energy = offset;\n    return;\n  }\n\n  *log_energy += offset;\n\n  // Update the approximate |total_energy| with the energy of |data_in|, if\n  // |total_energy| has not exceeded |kMinEnergy|. |total_energy| is used as an\n  // energy indicator in WebRtcVad_GmmProbability() in vad_core.c.\n  if (*total_energy <= kMinEnergy) {\n    if (tot_rshifts >= 0) {\n      // We know by construction that the |energy| > |kMinEnergy| in Q0, so add\n      // an arbitrary value such that |total_energy| exceeds |kMinEnergy|.\n      *total_energy += kMinEnergy + 1;\n    } else {\n      // By construction |energy| is represented by 15 bits, hence any number of\n      // right shifted |energy| will fit in an int16_t. In addition, adding the\n      // value to |total_energy| is wrap around safe as long as\n      // |kMinEnergy| < 8192.\n      *total_energy += (int16_t) (energy >> -tot_rshifts);  // Q0.\n    }\n  }\n}\n\nint16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in,\n                                    size_t data_length, int16_t* features) {\n  int16_t total_energy = 0;\n  // We expect |data_length| to be 80, 160 or 240 samples, which corresponds to\n  // 10, 20 or 30 ms in 8 kHz. Therefore, the intermediate downsampled data will\n  // have at most 120 samples after the first split and at most 60 samples after\n  // the second split.\n  int16_t hp_120[120], lp_120[120];\n  int16_t hp_60[60], lp_60[60];\n  const size_t half_data_length = data_length >> 1;\n  size_t length = half_data_length;  // |data_length| / 2, corresponds to\n                                     // bandwidth = 2000 Hz after downsampling.\n\n  // Initialize variables for the first SplitFilter().\n  int frequency_band = 0;\n  const int16_t* in_ptr = data_in;  // [0 - 4000] Hz.\n  int16_t* hp_out_ptr = hp_120;  // [2000 - 4000] Hz.\n  int16_t* lp_out_ptr = lp_120;  // [0 - 2000] Hz.\n\n  RTC_DCHECK_LE(data_length, 240);\n  RTC_DCHECK_LT(4, kNumChannels - 1);  // Checking maximum |frequency_band|.\n\n  // Split at 2000 Hz and downsample.\n  SplitFilter(in_ptr, data_length, &self->upper_state[frequency_band],\n              &self->lower_state[frequency_band], hp_out_ptr, lp_out_ptr);\n\n  // For the upper band (2000 Hz - 4000 Hz) split at 3000 Hz and downsample.\n  frequency_band = 1;\n  in_ptr = hp_120;  // [2000 - 4000] Hz.\n  hp_out_ptr = hp_60;  // [3000 - 4000] Hz.\n  lp_out_ptr = lp_60;  // [2000 - 3000] Hz.\n  SplitFilter(in_ptr, length, &self->upper_state[frequency_band],\n              &self->lower_state[frequency_band], hp_out_ptr, lp_out_ptr);\n\n  // Energy in 3000 Hz - 4000 Hz.\n  length >>= 1;  // |data_length| / 4 <=> bandwidth = 1000 Hz.\n\n  LogOfEnergy(hp_60, length, kOffsetVector[5], &total_energy, &features[5]);\n\n  // Energy in 2000 Hz - 3000 Hz.\n  LogOfEnergy(lp_60, length, kOffsetVector[4], &total_energy, &features[4]);\n\n  // For the lower band (0 Hz - 2000 Hz) split at 1000 Hz and downsample.\n  frequency_band = 2;\n  in_ptr = lp_120;  // [0 - 2000] Hz.\n  hp_out_ptr = hp_60;  // [1000 - 2000] Hz.\n  lp_out_ptr = lp_60;  // [0 - 1000] Hz.\n  length = half_data_length;  // |data_length| / 2 <=> bandwidth = 2000 Hz.\n  SplitFilter(in_ptr, length, &self->upper_state[frequency_band],\n              &self->lower_state[frequency_band], hp_out_ptr, lp_out_ptr);\n\n  // Energy in 1000 Hz - 2000 Hz.\n  length >>= 1;  // |data_length| / 4 <=> bandwidth = 1000 Hz.\n  LogOfEnergy(hp_60, length, kOffsetVector[3], &total_energy, &features[3]);\n\n  // For the lower band (0 Hz - 1000 Hz) split at 500 Hz and downsample.\n  frequency_band = 3;\n  in_ptr = lp_60;  // [0 - 1000] Hz.\n  hp_out_ptr = hp_120;  // [500 - 1000] Hz.\n  lp_out_ptr = lp_120;  // [0 - 500] Hz.\n  SplitFilter(in_ptr, length, &self->upper_state[frequency_band],\n              &self->lower_state[frequency_band], hp_out_ptr, lp_out_ptr);\n\n  // Energy in 500 Hz - 1000 Hz.\n  length >>= 1;  // |data_length| / 8 <=> bandwidth = 500 Hz.\n  LogOfEnergy(hp_120, length, kOffsetVector[2], &total_energy, &features[2]);\n\n  // For the lower band (0 Hz - 500 Hz) split at 250 Hz and downsample.\n  frequency_band = 4;\n  in_ptr = lp_120;  // [0 - 500] Hz.\n  hp_out_ptr = hp_60;  // [250 - 500] Hz.\n  lp_out_ptr = lp_60;  // [0 - 250] Hz.\n  SplitFilter(in_ptr, length, &self->upper_state[frequency_band],\n              &self->lower_state[frequency_band], hp_out_ptr, lp_out_ptr);\n\n  // Energy in 250 Hz - 500 Hz.\n  length >>= 1;  // |data_length| / 16 <=> bandwidth = 250 Hz.\n  LogOfEnergy(hp_60, length, kOffsetVector[1], &total_energy, &features[1]);\n\n  // Remove 0 Hz - 80 Hz, by high pass filtering the lower band.\n  HighPassFilter(lp_60, length, self->hp_filter_state, hp_120);\n\n  // Energy in 80 Hz - 250 Hz.\n  LogOfEnergy(hp_120, length, kOffsetVector[0], &total_energy, &features[0]);\n\n  return total_energy;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_filterbank.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n/*\n * This file includes feature calculating functionality used in vad_core.c.\n */\n\n#ifndef COMMON_AUDIO_VAD_VAD_FILTERBANK_H_\n#define COMMON_AUDIO_VAD_VAD_FILTERBANK_H_\n\n#include \"common_audio/vad/vad_core.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// Takes |data_length| samples of |data_in| and calculates the logarithm of the\n// energy of each of the |kNumChannels| = 6 frequency bands used by the VAD:\n//        80 Hz - 250 Hz\n//        250 Hz - 500 Hz\n//        500 Hz - 1000 Hz\n//        1000 Hz - 2000 Hz\n//        2000 Hz - 3000 Hz\n//        3000 Hz - 4000 Hz\n//\n// The values are given in Q4 and written to |features|. Further, an approximate\n// overall energy is returned. The return value is used in\n// WebRtcVad_GmmProbability() as a signal indicator, hence it is arbitrary above\n// the threshold |kMinEnergy|.\n//\n// - self         [i/o] : State information of the VAD.\n// - data_in      [i]   : Input audio data, for feature extraction.\n// - data_length  [i]   : Audio data current_frame, in number of samples.\n// - features     [o]   : 10 * log10(energy in each frequency band), Q4.\n// - returns            : Total energy of the signal (NOTE! This value is not\n//                        exact. It is only used in a comparison.)\nint16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in,\n                                    size_t data_length, int16_t* features);\n\n#endif  // COMMON_AUDIO_VAD_VAD_FILTERBANK_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_filterbank_unittest.cc",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include <stdlib.h>\n\n#include \"common_audio/vad/vad_unittest.h\"\n#include \"test/gtest.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nextern \"C\" {\n#include \"common_audio/vad/vad_core.h\"\n#include \"common_audio/vad/vad_filterbank.h\"\n}\n\nnamespace webrtc {\nnamespace test {\n\nconst int kNumValidFrameLengths = 3;\n\nTEST_F(VadTest, vad_filterbank) {\n  VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));\n  static const int16_t kReference[kNumValidFrameLengths] = { 48, 11, 11 };\n  static const int16_t kFeatures[kNumValidFrameLengths * kNumChannels] = {\n      1213, 759, 587, 462, 434, 272,\n      1479, 1385, 1291, 1200, 1103, 1099,\n      1732, 1692, 1681, 1629, 1436, 1436\n  };\n  static const int16_t kOffsetVector[kNumChannels] = {\n      368, 368, 272, 176, 176, 176 };\n  int16_t features[kNumChannels];\n\n  // Construct a speech signal that will trigger the VAD in all modes. It is\n  // known that (i * i) will wrap around, but that doesn't matter in this case.\n  int16_t speech[kMaxFrameLength];\n  for (size_t i = 0; i < kMaxFrameLength; ++i) {\n    speech[i] = static_cast<int16_t>(i * i);\n  }\n\n  int frame_length_index = 0;\n  ASSERT_EQ(0, WebRtcVad_InitCore(self));\n  for (size_t j = 0; j < kFrameLengthsSize; ++j) {\n    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {\n      EXPECT_EQ(kReference[frame_length_index],\n                WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],\n                                            features));\n      for (int k = 0; k < kNumChannels; ++k) {\n        EXPECT_EQ(kFeatures[k + frame_length_index * kNumChannels],\n                  features[k]);\n      }\n      frame_length_index++;\n    }\n  }\n  EXPECT_EQ(kNumValidFrameLengths, frame_length_index);\n\n  // Verify that all zeros in gives kOffsetVector out.\n  memset(speech, 0, sizeof(speech));\n  ASSERT_EQ(0, WebRtcVad_InitCore(self));\n  for (size_t j = 0; j < kFrameLengthsSize; ++j) {\n    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {\n      EXPECT_EQ(0, WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],\n                                               features));\n      for (int k = 0; k < kNumChannels; ++k) {\n        EXPECT_EQ(kOffsetVector[k], features[k]);\n      }\n    }\n  }\n\n  // Verify that all ones in gives kOffsetVector out. Any other constant input\n  // will have a small impact in the sub bands.\n  for (size_t i = 0; i < kMaxFrameLength; ++i) {\n    speech[i] = 1;\n  }\n  for (size_t j = 0; j < kFrameLengthsSize; ++j) {\n    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {\n      ASSERT_EQ(0, WebRtcVad_InitCore(self));\n      EXPECT_EQ(0, WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],\n                                               features));\n      for (int k = 0; k < kNumChannels; ++k) {\n        EXPECT_EQ(kOffsetVector[k], features[k]);\n      }\n    }\n  }\n\n  free(self);\n}\n}  // namespace test\n}  // namespace webrtc\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_gmm.c",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/vad_gmm.h\"\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nstatic const int32_t kCompVar = 22005;\nstatic const int16_t kLog2Exp = 5909;  // log2(exp(1)) in Q12.\n\n// For a normal distribution, the probability of |input| is calculated and\n// returned (in Q20). The formula for normal distributed probability is\n//\n// 1 / s * exp(-(x - m)^2 / (2 * s^2))\n//\n// where the parameters are given in the following Q domains:\n// m = |mean| (Q7)\n// s = |std| (Q7)\n// x = |input| (Q4)\n// in addition to the probability we output |delta| (in Q11) used when updating\n// the noise/speech model.\nint32_t WebRtcVad_GaussianProbability(int16_t input,\n                                      int16_t mean,\n                                      int16_t std,\n                                      int16_t* delta) {\n  int16_t tmp16, inv_std, inv_std2, exp_value = 0;\n  int32_t tmp32;\n\n  // Calculate |inv_std| = 1 / s, in Q10.\n  // 131072 = 1 in Q17, and (|std| >> 1) is for rounding instead of truncation.\n  // Q-domain: Q17 / Q7 = Q10.\n  tmp32 = (int32_t) 131072 + (int32_t) (std >> 1);\n  inv_std = (int16_t) WebRtcSpl_DivW32W16(tmp32, std);\n\n  // Calculate |inv_std2| = 1 / s^2, in Q14.\n  tmp16 = (inv_std >> 2);  // Q10 -> Q8.\n  // Q-domain: (Q8 * Q8) >> 2 = Q14.\n  inv_std2 = (int16_t)((tmp16 * tmp16) >> 2);\n  // TODO(bjornv): Investigate if changing to\n  // inv_std2 = (int16_t)((inv_std * inv_std) >> 6);\n  // gives better accuracy.\n\n  tmp16 = (input << 3);  // Q4 -> Q7\n  tmp16 = tmp16 - mean;  // Q7 - Q7 = Q7\n\n  // To be used later, when updating noise/speech model.\n  // |delta| = (x - m) / s^2, in Q11.\n  // Q-domain: (Q14 * Q7) >> 10 = Q11.\n  *delta = (int16_t)((inv_std2 * tmp16) >> 10);\n\n  // Calculate the exponent |tmp32| = (x - m)^2 / (2 * s^2), in Q10. Replacing\n  // division by two with one shift.\n  // Q-domain: (Q11 * Q7) >> 8 = Q10.\n  tmp32 = (*delta * tmp16) >> 9;\n\n  // If the exponent is small enough to give a non-zero probability we calculate\n  // |exp_value| ~= exp(-(x - m)^2 / (2 * s^2))\n  //             ~= exp2(-log2(exp(1)) * |tmp32|).\n  if (tmp32 < kCompVar) {\n    // Calculate |tmp16| = log2(exp(1)) * |tmp32|, in Q10.\n    // Q-domain: (Q12 * Q10) >> 12 = Q10.\n    tmp16 = (int16_t)((kLog2Exp * tmp32) >> 12);\n    tmp16 = -tmp16;\n    exp_value = (0x0400 | (tmp16 & 0x03FF));\n    tmp16 ^= 0xFFFF;\n    tmp16 >>= 10;\n    tmp16 += 1;\n    // Get |exp_value| = exp(-|tmp32|) in Q10.\n    exp_value >>= tmp16;\n  }\n\n  // Calculate and return (1 / s) * exp(-(x - m)^2 / (2 * s^2)), in Q20.\n  // Q-domain: Q10 * Q10 = Q20.\n  return inv_std * exp_value;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_gmm.h",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n// Gaussian probability calculations internally used in vad_core.c.\n\n#ifndef COMMON_AUDIO_VAD_VAD_GMM_H_\n#define COMMON_AUDIO_VAD_VAD_GMM_H_\n\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// Calculates the probability for |input|, given that |input| comes from a\n// normal distribution with mean and standard deviation (|mean|, |std|).\n//\n// Inputs:\n//      - input         : input sample in Q4.\n//      - mean          : mean input in the statistical model, Q7.\n//      - std           : standard deviation, Q7.\n//\n// Output:\n//\n//      - delta         : input used when updating the model, Q11.\n//                        |delta| = (|input| - |mean|) / |std|^2.\n//\n// Return:\n//   (probability for |input|) =\n//    1 / |std| * exp(-(|input| - |mean|)^2 / (2 * |std|^2));\nint32_t WebRtcVad_GaussianProbability(int16_t input,\n                                      int16_t mean,\n                                      int16_t std,\n                                      int16_t* delta);\n\n#endif  // COMMON_AUDIO_VAD_VAD_GMM_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_gmm_unittest.cc",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/vad_unittest.h\"\n#include \"test/gtest.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nextern \"C\" {\n#include \"common_audio/vad/vad_gmm.h\"\n}\n\nnamespace webrtc {\nnamespace test {\n\nTEST_F(VadTest, vad_gmm) {\n  int16_t delta = 0;\n  // Input value at mean.\n  EXPECT_EQ(1048576, WebRtcVad_GaussianProbability(0, 0, 128, &delta));\n  EXPECT_EQ(0, delta);\n  EXPECT_EQ(1048576, WebRtcVad_GaussianProbability(16, 128, 128, &delta));\n  EXPECT_EQ(0, delta);\n  EXPECT_EQ(1048576, WebRtcVad_GaussianProbability(-16, -128, 128, &delta));\n  EXPECT_EQ(0, delta);\n\n  // Largest possible input to give non-zero probability.\n  EXPECT_EQ(1024, WebRtcVad_GaussianProbability(59, 0, 128, &delta));\n  EXPECT_EQ(7552, delta);\n  EXPECT_EQ(1024, WebRtcVad_GaussianProbability(75, 128, 128, &delta));\n  EXPECT_EQ(7552, delta);\n  EXPECT_EQ(1024, WebRtcVad_GaussianProbability(-75, -128, 128, &delta));\n  EXPECT_EQ(-7552, delta);\n\n  // Too large input, should give zero probability.\n  EXPECT_EQ(0, WebRtcVad_GaussianProbability(105, 0, 128, &delta));\n  EXPECT_EQ(13440, delta);\n}\n}  // namespace test\n}  // namespace webrtc\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_sp.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/vad_sp.h\"\n\n#include \"rtc_base/checks.h\"\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"common_audio/vad/vad_core.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// Allpass filter coefficients, upper and lower, in Q13.\n// Upper: 0.64, Lower: 0.17.\nstatic const int16_t kAllPassCoefsQ13[2] = { 5243, 1392 };  // Q13.\nstatic const int16_t kSmoothingDown = 6553;  // 0.2 in Q15.\nstatic const int16_t kSmoothingUp = 32439;  // 0.99 in Q15.\n\n// TODO(bjornv): Move this function to vad_filterbank.c.\n// Downsampling filter based on splitting filter and allpass functions.\nvoid WebRtcVad_Downsampling(const int16_t* signal_in,\n                            int16_t* signal_out,\n                            int32_t* filter_state,\n                            size_t in_length) {\n  int16_t tmp16_1 = 0, tmp16_2 = 0;\n  int32_t tmp32_1 = filter_state[0];\n  int32_t tmp32_2 = filter_state[1];\n  size_t n = 0;\n  // Downsampling by 2 gives half length.\n  size_t half_length = (in_length >> 1);\n\n  // Filter coefficients in Q13, filter state in Q0.\n  for (n = 0; n < half_length; n++) {\n    // All-pass filtering upper branch.\n    tmp16_1 = (int16_t) ((tmp32_1 >> 1) +\n        ((kAllPassCoefsQ13[0] * *signal_in) >> 14));\n    *signal_out = tmp16_1;\n    tmp32_1 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[0] * tmp16_1) >> 12);\n\n    // All-pass filtering lower branch.\n    tmp16_2 = (int16_t) ((tmp32_2 >> 1) +\n        ((kAllPassCoefsQ13[1] * *signal_in) >> 14));\n    *signal_out++ += tmp16_2;\n    tmp32_2 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[1] * tmp16_2) >> 12);\n  }\n  // Store the filter states.\n  filter_state[0] = tmp32_1;\n  filter_state[1] = tmp32_2;\n}\n\n// Inserts |feature_value| into |low_value_vector|, if it is one of the 16\n// smallest values the last 100 frames. Then calculates and returns the median\n// of the five smallest values.\nint16_t WebRtcVad_FindMinimum(VadInstT* self,\n                              int16_t feature_value,\n                              int channel) {\n  int i = 0, j = 0;\n  int position = -1;\n  // Offset to beginning of the 16 minimum values in memory.\n  const int offset = (channel << 4);\n  int16_t current_median = 1600;\n  int16_t alpha = 0;\n  int32_t tmp32 = 0;\n  // Pointer to memory for the 16 minimum values and the age of each value of\n  // the |channel|.\n  int16_t* age = &self->index_vector[offset];\n  int16_t* smallest_values = &self->low_value_vector[offset];\n\n  RTC_DCHECK_LT(channel, kNumChannels);\n\n  // Each value in |smallest_values| is getting 1 loop older. Update |age|, and\n  // remove old values.\n  for (i = 0; i < 16; i++) {\n    if (age[i] != 100) {\n      age[i]++;\n    } else {\n      // Too old value. Remove from memory and shift larger values downwards.\n      for (j = i; j < 16; j++) {\n        smallest_values[j] = smallest_values[j + 1];\n        age[j] = age[j + 1];\n      }\n      age[15] = 101;\n      smallest_values[15] = 10000;\n    }\n  }\n\n  // Check if |feature_value| is smaller than any of the values in\n  // |smallest_values|. If so, find the |position| where to insert the new value\n  // (|feature_value|).\n  if (feature_value < smallest_values[7]) {\n    if (feature_value < smallest_values[3]) {\n      if (feature_value < smallest_values[1]) {\n        if (feature_value < smallest_values[0]) {\n          position = 0;\n        } else {\n          position = 1;\n        }\n      } else if (feature_value < smallest_values[2]) {\n        position = 2;\n      } else {\n        position = 3;\n      }\n    } else if (feature_value < smallest_values[5]) {\n      if (feature_value < smallest_values[4]) {\n        position = 4;\n      } else {\n        position = 5;\n      }\n    } else if (feature_value < smallest_values[6]) {\n      position = 6;\n    } else {\n      position = 7;\n    }\n  } else if (feature_value < smallest_values[15]) {\n    if (feature_value < smallest_values[11]) {\n      if (feature_value < smallest_values[9]) {\n        if (feature_value < smallest_values[8]) {\n          position = 8;\n        } else {\n          position = 9;\n        }\n      } else if (feature_value < smallest_values[10]) {\n        position = 10;\n      } else {\n        position = 11;\n      }\n    } else if (feature_value < smallest_values[13]) {\n      if (feature_value < smallest_values[12]) {\n        position = 12;\n      } else {\n        position = 13;\n      }\n    } else if (feature_value < smallest_values[14]) {\n      position = 14;\n    } else {\n      position = 15;\n    }\n  }\n\n  // If we have detected a new small value, insert it at the correct position\n  // and shift larger values up.\n  if (position > -1) {\n    for (i = 15; i > position; i--) {\n      smallest_values[i] = smallest_values[i - 1];\n      age[i] = age[i - 1];\n    }\n    smallest_values[position] = feature_value;\n    age[position] = 1;\n  }\n\n  // Get |current_median|.\n  if (self->frame_counter > 2) {\n    current_median = smallest_values[2];\n  } else if (self->frame_counter > 0) {\n    current_median = smallest_values[0];\n  }\n\n  // Smooth the median value.\n  if (self->frame_counter > 0) {\n    if (current_median < self->mean_value[channel]) {\n      alpha = kSmoothingDown;  // 0.2 in Q15.\n    } else {\n      alpha = kSmoothingUp;  // 0.99 in Q15.\n    }\n  }\n  tmp32 = (alpha + 1) * self->mean_value[channel];\n  tmp32 += (WEBRTC_SPL_WORD16_MAX - alpha) * current_median;\n  tmp32 += 16384;\n  self->mean_value[channel] = (int16_t) (tmp32 >> 15);\n\n  return self->mean_value[channel];\n}\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_sp.h",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n\n// This file includes specific signal processing tools used in vad_core.c.\n\n#ifndef COMMON_AUDIO_VAD_VAD_SP_H_\n#define COMMON_AUDIO_VAD_VAD_SP_H_\n\n#include \"common_audio/vad/vad_core.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// Downsamples the signal by a factor 2, eg. 32->16 or 16->8.\n//\n// Inputs:\n//      - signal_in     : Input signal.\n//      - in_length     : Length of input signal in samples.\n//\n// Input & Output:\n//      - filter_state  : Current filter states of the two all-pass filters. The\n//                        |filter_state| is updated after all samples have been\n//                        processed.\n//\n// Output:\n//      - signal_out    : Downsampled signal (of length |in_length| / 2).\nvoid WebRtcVad_Downsampling(const int16_t* signal_in,\n                            int16_t* signal_out,\n                            int32_t* filter_state,\n                            size_t in_length);\n\n// Updates and returns the smoothed feature minimum. As minimum we use the\n// median of the five smallest feature values in a 100 frames long window.\n// As long as |handle->frame_counter| is zero, that is, we haven't received any\n// \"valid\" data, FindMinimum() outputs the default value of 1600.\n//\n// Inputs:\n//      - feature_value : New feature value to update with.\n//      - channel       : Channel number.\n//\n// Input & Output:\n//      - handle        : State information of the VAD.\n//\n// Returns:\n//                      : Smoothed minimum value for a moving window.\nint16_t WebRtcVad_FindMinimum(VadInstT* handle,\n                              int16_t feature_value,\n                              int channel);\n\n#endif  // COMMON_AUDIO_VAD_VAD_SP_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_sp_unittest.cc",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include <stdlib.h>\n\n#include \"common_audio/vad/vad_unittest.h\"\n#include \"test/gtest.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nextern \"C\" {\n#include \"common_audio/vad/vad_core.h\"\n#include \"common_audio/vad/vad_sp.h\"\n}\n\nnamespace webrtc {\nnamespace test {\n\nTEST_F(VadTest, vad_sp) {\n  VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));\n  const size_t kMaxFrameLenSp = 960;  // Maximum frame length in this unittest.\n  int16_t zeros[kMaxFrameLenSp] = { 0 };\n  int32_t state[2] = { 0 };\n  int16_t data_in[kMaxFrameLenSp];\n  int16_t data_out[kMaxFrameLenSp];\n\n  // We expect the first value to be 1600 as long as |frame_counter| is zero,\n  // which is true for the first iteration.\n  static const int16_t kReferenceMin[32] = {\n      1600, 720, 509, 512, 532, 552, 570, 588,\n       606, 624, 642, 659, 675, 691, 707, 723,\n      1600, 544, 502, 522, 542, 561, 579, 597,\n       615, 633, 651, 667, 683, 699, 715, 731\n  };\n\n  // Construct a speech signal that will trigger the VAD in all modes. It is\n  // known that (i * i) will wrap around, but that doesn't matter in this case.\n  for (size_t i = 0; i < kMaxFrameLenSp; ++i) {\n    data_in[i] = static_cast<int16_t>(i * i);\n  }\n  // Input values all zeros, expect all zeros out.\n  WebRtcVad_Downsampling(zeros, data_out, state, kMaxFrameLenSp);\n  EXPECT_EQ(0, state[0]);\n  EXPECT_EQ(0, state[1]);\n  for (size_t i = 0; i < kMaxFrameLenSp / 2; ++i) {\n    EXPECT_EQ(0, data_out[i]);\n  }\n  // Make a simple non-zero data test.\n  WebRtcVad_Downsampling(data_in, data_out, state, kMaxFrameLenSp);\n  EXPECT_EQ(207, state[0]);\n  EXPECT_EQ(2270, state[1]);\n\n  ASSERT_EQ(0, WebRtcVad_InitCore(self));\n  // TODO(bjornv): Replace this part of the test with taking values from an\n  // array and calculate the reference value here. Make sure the values are not\n  // ordered.\n  for (int16_t i = 0; i < 16; ++i) {\n    int16_t value = 500 * (i + 1);\n    for (int j = 0; j < kNumChannels; ++j) {\n      // Use values both above and below initialized value.\n      EXPECT_EQ(kReferenceMin[i], WebRtcVad_FindMinimum(self, value, j));\n      EXPECT_EQ(kReferenceMin[i + 16], WebRtcVad_FindMinimum(self, 12000, j));\n    }\n    self->frame_counter++;\n  }\n\n  free(self);\n}\n}  // namespace test\n}  // namespace webrtc\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_unittest.cc",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/vad_unittest.h\"\n\n#include <stdlib.h>\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"common_audio/vad/include/webrtc_vad.h\"\n#include \"rtc_base/arraysize.h\"\n#include \"rtc_base/checks.h\"\n#include \"test/gtest.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nVadTest::VadTest() {}\n\nvoid VadTest::SetUp() {}\n\nvoid VadTest::TearDown() {}\n\n// Returns true if the rate and frame length combination is valid.\nbool VadTest::ValidRatesAndFrameLengths(int rate, size_t frame_length) {\n  if (rate == 8000) {\n    if (frame_length == 80 || frame_length == 160 || frame_length == 240) {\n      return true;\n    }\n    return false;\n  } else if (rate == 16000) {\n    if (frame_length == 160 || frame_length == 320 || frame_length == 480) {\n      return true;\n    }\n    return false;\n  } else if (rate == 32000) {\n    if (frame_length == 320 || frame_length == 640 || frame_length == 960) {\n      return true;\n    }\n    return false;\n  } else if (rate == 48000) {\n    if (frame_length == 480 || frame_length == 960 || frame_length == 1440) {\n      return true;\n    }\n    return false;\n  }\n\n  return false;\n}\n\nnamespace webrtc {\nnamespace test {\n\nTEST_F(VadTest, ApiTest) {\n  // This API test runs through the APIs for all possible valid and invalid\n  // combinations.\n\n  VadInst* handle = WebRtcVad_Create();\n  int16_t zeros[kMaxFrameLength] = { 0 };\n\n  // Construct a speech signal that will trigger the VAD in all modes. It is\n  // known that (i * i) will wrap around, but that doesn't matter in this case.\n  int16_t speech[kMaxFrameLength];\n  for (size_t i = 0; i < kMaxFrameLength; i++) {\n    speech[i] = static_cast<int16_t>(i * i);\n  }\n\n  // nullptr instance tests\n  EXPECT_EQ(-1, WebRtcVad_Init(nullptr));\n  EXPECT_EQ(-1, WebRtcVad_set_mode(nullptr, kModes[0]));\n  EXPECT_EQ(-1,\n            WebRtcVad_Process(nullptr, kRates[0], speech, kFrameLengths[0]));\n\n  // WebRtcVad_Create()\n  RTC_CHECK(handle);\n\n  // Not initialized tests\n  EXPECT_EQ(-1, WebRtcVad_Process(handle, kRates[0], speech, kFrameLengths[0]));\n  EXPECT_EQ(-1, WebRtcVad_set_mode(handle, kModes[0]));\n\n  // WebRtcVad_Init() test\n  ASSERT_EQ(0, WebRtcVad_Init(handle));\n\n  // WebRtcVad_set_mode() invalid modes tests. Tries smallest supported value\n  // minus one and largest supported value plus one.\n  EXPECT_EQ(-1, WebRtcVad_set_mode(handle,\n                                   WebRtcSpl_MinValueW32(kModes,\n                                                         kModesSize) - 1));\n  EXPECT_EQ(-1, WebRtcVad_set_mode(handle,\n                                   WebRtcSpl_MaxValueW32(kModes,\n                                                         kModesSize) + 1));\n\n  // WebRtcVad_Process() tests\n  // nullptr as speech pointer\n  EXPECT_EQ(-1,\n            WebRtcVad_Process(handle, kRates[0], nullptr, kFrameLengths[0]));\n  // Invalid sampling rate\n  EXPECT_EQ(-1, WebRtcVad_Process(handle, 9999, speech, kFrameLengths[0]));\n  // All zeros as input should work\n  EXPECT_EQ(0, WebRtcVad_Process(handle, kRates[0], zeros, kFrameLengths[0]));\n  for (size_t k = 0; k < kModesSize; k++) {\n    // Test valid modes\n    EXPECT_EQ(0, WebRtcVad_set_mode(handle, kModes[k]));\n    // Loop through sampling rate and frame length combinations\n    for (size_t i = 0; i < kRatesSize; i++) {\n      for (size_t j = 0; j < kFrameLengthsSize; j++) {\n        if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) {\n          EXPECT_EQ(1, WebRtcVad_Process(handle,\n                                         kRates[i],\n                                         speech,\n                                         kFrameLengths[j]));\n        } else {\n          EXPECT_EQ(-1, WebRtcVad_Process(handle,\n                                          kRates[i],\n                                          speech,\n                                          kFrameLengths[j]));\n        }\n      }\n    }\n  }\n\n  WebRtcVad_Free(handle);\n}\n\nTEST_F(VadTest, ValidRatesFrameLengths) {\n  // This test verifies valid and invalid rate/frame_length combinations. We\n  // loop through some sampling rates and frame lengths from negative values to\n  // values larger than possible.\n  const int kRates[] = {\n    -8000, -4000, 0, 4000, 8000, 8001, 15999, 16000, 32000, 48000, 48001, 96000\n  };\n\n  const size_t kFrameLengths[] = {\n    0, 80, 81, 159, 160, 240, 320, 480, 640, 960, 1440, 2000\n  };\n\n  for (size_t i = 0; i < arraysize(kRates); i++) {\n    for (size_t j = 0; j < arraysize(kFrameLengths); j++) {\n      if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) {\n        EXPECT_EQ(0, WebRtcVad_ValidRateAndFrameLength(kRates[i],\n                                                       kFrameLengths[j]));\n      } else {\n        EXPECT_EQ(-1, WebRtcVad_ValidRateAndFrameLength(kRates[i],\n                                                        kFrameLengths[j]));\n      }\n    }\n  }\n}\n\n// TODO(bjornv): Add a process test, run on file.\n\n}  // namespace test\n}  // namespace webrtc\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_unittest.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef COMMON_AUDIO_VAD_VAD_UNITTEST_H_\n#define COMMON_AUDIO_VAD_VAD_UNITTEST_H_\n\n#include <stddef.h>  // size_t\n\n#include \"test/gtest.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nnamespace webrtc {\nnamespace test {\n\n// Modes we support\nconst int kModes[] = { 0, 1, 2, 3 };\nconst size_t kModesSize = sizeof(kModes) / sizeof(*kModes);\n\n// Rates we support.\nconst int kRates[] = { 8000, 12000, 16000, 24000, 32000, 48000 };\nconst size_t kRatesSize = sizeof(kRates) / sizeof(*kRates);\n\n// Frame lengths we support.\nconst size_t kMaxFrameLength = 1440;\nconst size_t kFrameLengths[] = { 80, 120, 160, 240, 320, 480, 640, 960,\n    kMaxFrameLength };\nconst size_t kFrameLengthsSize = sizeof(kFrameLengths) / sizeof(*kFrameLengths);\n\n}  // namespace test\n}  // namespace webrtc\n\nclass VadTest : public ::testing::Test {\n protected:\n  VadTest();\n  virtual void SetUp();\n  virtual void TearDown();\n\n  // Returns true if the rate and frame length combination is valid.\n  bool ValidRatesAndFrameLengths(int rate, size_t frame_length);\n};\n\n#endif  // COMMON_AUDIO_VAD_VAD_UNITTEST_H_\n"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/webrtc_vad.c",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#include \"common_audio/vad/include/webrtc_vad.h\"\n\n#include <stdlib.h>\n#include <string.h>\n\n#include \"common_audio/signal_processing/include/signal_processing_library.h\"\n#include \"common_audio/vad/vad_core.h\"\n#include \"typedefs.h\"  // NOLINT(build/include)\n\nstatic const int kInitCheck = 42;\nstatic const int kValidRates[] = { 8000, 16000, 32000, 48000 };\nstatic const size_t kRatesSize = sizeof(kValidRates) / sizeof(*kValidRates);\nstatic const int kMaxFrameLengthMs = 30;\n\nVadInst* WebRtcVad_Create() {\n  VadInstT* self = (VadInstT*)malloc(sizeof(VadInstT));\n\n  WebRtcSpl_Init();\n  self->init_flag = 0;\n\n  return (VadInst*)self;\n}\n\nvoid WebRtcVad_Free(VadInst* handle) {\n  free(handle);\n}\n\n// TODO(bjornv): Move WebRtcVad_InitCore() code here.\nint WebRtcVad_Init(VadInst* handle) {\n  // Initialize the core VAD component.\n  return WebRtcVad_InitCore((VadInstT*) handle);\n}\n\n// TODO(bjornv): Move WebRtcVad_set_mode_core() code here.\nint WebRtcVad_set_mode(VadInst* handle, int mode) {\n  VadInstT* self = (VadInstT*) handle;\n\n  if (handle == NULL) {\n    return -1;\n  }\n  if (self->init_flag != kInitCheck) {\n    return -1;\n  }\n\n  return WebRtcVad_set_mode_core(self, mode);\n}\n\nint WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,\n                      size_t frame_length) {\n  int vad = -1;\n  VadInstT* self = (VadInstT*) handle;\n\n  if (handle == NULL) {\n    return -1;\n  }\n\n  if (self->init_flag != kInitCheck) {\n    return -1;\n  }\n  if (audio_frame == NULL) {\n    return -1;\n  }\n  if (WebRtcVad_ValidRateAndFrameLength(fs, frame_length) != 0) {\n    return -1;\n  }\n\n  if (fs == 48000) {\n      vad = WebRtcVad_CalcVad48khz(self, audio_frame, frame_length);\n  } else if (fs == 32000) {\n    vad = WebRtcVad_CalcVad32khz(self, audio_frame, frame_length);\n  } else if (fs == 16000) {\n    vad = WebRtcVad_CalcVad16khz(self, audio_frame, frame_length);\n  } else if (fs == 8000) {\n    vad = WebRtcVad_CalcVad8khz(self, audio_frame, frame_length);\n  }\n\n  if (vad > 0) {\n    vad = 1;\n  }\n  return vad;\n}\n\nint WebRtcVad_ValidRateAndFrameLength(int rate, size_t frame_length) {\n  int return_value = -1;\n  size_t i;\n  int valid_length_ms;\n  size_t valid_length;\n\n  // We only allow 10, 20 or 30 ms frames. Loop through valid frame rates and\n  // see if we have a matching pair.\n  for (i = 0; i < kRatesSize; i++) {\n    if (kValidRates[i] == rate) {\n      for (valid_length_ms = 10; valid_length_ms <= kMaxFrameLengthMs;\n          valid_length_ms += 10) {\n        valid_length = (size_t)(kValidRates[i] / 1000 * valid_length_ms);\n        if (frame_length == valid_length) {\n          return_value = 0;\n          break;\n        }\n      }\n      break;\n    }\n  }\n\n  return return_value;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/checks.cc",
    "content": "/*\n *  Copyright 2006 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n// Most of this was borrowed (with minor modifications) from V8's and Chromium's\n// src/base/logging.cc.\n\n#include <cstdarg>\n#include <cstdio>\n#include <cstdlib>\n//added by me\n#include \"typedefs.h\"\n#if defined(WEBRTC_ANDROID)\n#define RTC_LOG_TAG_ANDROID \"rtc\"\n#include <android/log.h>  // NOLINT\n#endif\n\n#if defined(WEBRTC_WIN)\n#include <windows.h>\n#endif\n\n#if defined(WEBRTC_WIN)\n#define LAST_SYSTEM_ERROR (::GetLastError())\n#elif defined(__native_client__) && __native_client__\n#define LAST_SYSTEM_ERROR (0)\n#elif defined(WEBRTC_POSIX)\n#include <errno.h>\n#define LAST_SYSTEM_ERROR (errno)\n#endif  // WEBRTC_WIN\n\n#include \"rtc_base/checks.h\"\n#if defined(_MSC_VER)\n// Warning C4722: destructor never returns, potential memory leak.\n// FatalMessage's dtor very intentionally aborts.\n#pragma warning(disable:4722)\n#endif\n\nnamespace rtc {\nnamespace {\n\nvoid VPrintError(const char* format, va_list args) {\n#if defined(WEBRTC_ANDROID)\n  __android_log_vprint(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, format, args);\n#else\n  vfprintf(stderr, format, args);\n#endif\n}\n\n#if defined(__GNUC__)\nvoid PrintError(const char* format, ...)\n    __attribute__((__format__(__printf__, 1, 2)));\n#endif\n\nvoid PrintError(const char* format, ...) {\n  va_list args;\n  va_start(args, format);\n  VPrintError(format, args);\n  va_end(args);\n}\n\n}  // namespace\n\nFatalMessage::FatalMessage(const char* file, int line) {\n  Init(file, line);\n}\n\nFatalMessage::FatalMessage(const char* file, int line, std::string* result) {\n  Init(file, line);\n  stream_ << \"Check failed: \" << *result << std::endl << \"# \";\n  delete result;\n}\n\nNO_RETURN FatalMessage::~FatalMessage() {\n  fflush(stdout);\n  fflush(stderr);\n  stream_ << std::endl << \"#\" << std::endl;\n  PrintError(\"%s\", stream_.str().c_str());\n  fflush(stderr);\n  abort();\n}\n\nvoid FatalMessage::Init(const char* file, int line) {\n  stream_ << std::endl\n          << std::endl\n          << \"#\" << std::endl\n          << \"# Fatal error in \" << file << \", line \" << line << std::endl\n          << \"# last system error: \" << LAST_SYSTEM_ERROR << std::endl\n          << \"# \";\n}\n\n// MSVC doesn't like complex extern templates and DLLs.\n#if !defined(COMPILER_MSVC)\n// Explicit instantiations for commonly used comparisons.\ntemplate std::string* MakeCheckOpString<int, int>(\n    const int&, const int&, const char* names);\ntemplate std::string* MakeCheckOpString<unsigned long, unsigned long>(\n    const unsigned long&, const unsigned long&, const char* names);\ntemplate std::string* MakeCheckOpString<unsigned long, unsigned int>(\n    const unsigned long&, const unsigned int&, const char* names);\ntemplate std::string* MakeCheckOpString<unsigned int, unsigned long>(\n    const unsigned int&, const unsigned long&, const char* names);\ntemplate std::string* MakeCheckOpString<std::string, std::string>(\n    const std::string&, const std::string&, const char* name);\n#endif\n\n}  // namespace rtc\n\n// Function to call from the C version of the RTC_CHECK and RTC_DCHECK macros.\nNO_RETURN void rtc_FatalMessage(const char* file, int line, const char* msg) {\n  rtc::FatalMessage(file, line).stream() << msg;\n}\n"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/checks.h",
    "content": "/*\n *  Copyright 2006 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef RTC_BASE_CHECKS_H_\n#define RTC_BASE_CHECKS_H_\n\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// If you for some reson need to know if DCHECKs are on, test the value of\n// RTC_DCHECK_IS_ON. (Test its value, not if it's defined; it'll always be\n// defined, to either a true or a false value.)\n#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)\n#define RTC_DCHECK_IS_ON 1\n#else\n#define RTC_DCHECK_IS_ON 0\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\nNO_RETURN void rtc_FatalMessage(const char* file, int line, const char* msg);\n#ifdef __cplusplus\n}  // extern \"C\"\n#endif\n\n#ifdef __cplusplus\n// C++ version.\n\n#include <sstream>\n#include <string>\n\n#include \"rtc_base/numerics/safe_compare.h\"\n\n// The macros here print a message to stderr and abort under various\n// conditions. All will accept additional stream messages. For example:\n// RTC_DCHECK_EQ(foo, bar) << \"I'm printed when foo != bar.\";\n//\n// - RTC_CHECK(x) is an assertion that x is always true, and that if it isn't,\n//   it's better to terminate the process than to continue. During development,\n//   the reason that it's better to terminate might simply be that the error\n//   handling code isn't in place yet; in production, the reason might be that\n//   the author of the code truly believes that x will always be true, but that\n//   she recognizes that if she is wrong, abrupt and unpleasant process\n//   termination is still better than carrying on with the assumption violated.\n//\n//   RTC_CHECK always evaluates its argument, so it's OK for x to have side\n//   effects.\n//\n// - RTC_DCHECK(x) is the same as RTC_CHECK(x)---an assertion that x is always\n//   true---except that x will only be evaluated in debug builds; in production\n//   builds, x is simply assumed to be true. This is useful if evaluating x is\n//   expensive and the expected cost of failing to detect the violated\n//   assumption is acceptable. You should not handle cases where a production\n//   build fails to spot a violated condition, even those that would result in\n//   crashes. If the code needs to cope with the error, make it cope, but don't\n//   call RTC_DCHECK; if the condition really can't occur, but you'd sleep\n//   better at night knowing that the process will suicide instead of carrying\n//   on in case you were wrong, use RTC_CHECK instead of RTC_DCHECK.\n//\n//   RTC_DCHECK only evaluates its argument in debug builds, so if x has visible\n//   side effects, you need to write e.g.\n//     bool w = x; RTC_DCHECK(w);\n//\n// - RTC_CHECK_EQ, _NE, _GT, ..., and RTC_DCHECK_EQ, _NE, _GT, ... are\n//   specialized variants of RTC_CHECK and RTC_DCHECK that print prettier\n//   messages if the condition doesn't hold. Prefer them to raw RTC_CHECK and\n//   RTC_DCHECK.\n//\n// - FATAL() aborts unconditionally.\n//\n// TODO(ajm): Ideally, checks.h would be combined with logging.h, but\n// consolidation with system_wrappers/logging.h should happen first.\n\nnamespace rtc {\n\n// Helper macro which avoids evaluating the arguments to a stream if\n// the condition doesn't hold.\n#define RTC_LAZY_STREAM(stream, condition)                                    \\\n  !(condition) ? static_cast<void>(0) : rtc::FatalMessageVoidify() & (stream)\n\n// The actual stream used isn't important. We reference |ignored| in the code\n// but don't evaluate it; this is to avoid \"unused variable\" warnings (we do so\n// in a particularly convoluted way with an extra ?: because that appears to be\n// the simplest construct that keeps Visual Studio from complaining about\n// condition being unused).\n#define RTC_EAT_STREAM_PARAMETERS(ignored) \\\n  (true ? true : ((void)(ignored), true))  \\\n      ? static_cast<void>(0)               \\\n      : rtc::FatalMessageVoidify() & rtc::FatalMessage(\"\", 0).stream()\n\n// Call RTC_EAT_STREAM_PARAMETERS with an argument that fails to compile if\n// values of the same types as |a| and |b| can't be compared with the given\n// operation, and that would evaluate |a| and |b| if evaluated.\n#define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \\\n  RTC_EAT_STREAM_PARAMETERS(((void)rtc::Safe##op(a, b)))\n\n// RTC_CHECK dies with a fatal error if condition is not true. It is *not*\n// controlled by NDEBUG or anything else, so the check will be executed\n// regardless of compilation mode.\n//\n// We make sure RTC_CHECK et al. always evaluates their arguments, as\n// doing RTC_CHECK(FunctionWithSideEffect()) is a common idiom.\n#define RTC_CHECK(condition)                                      \\\n  RTC_LAZY_STREAM(rtc::FatalMessage(__FILE__, __LINE__).stream(), \\\n                  !(condition))                                   \\\n      << \"Check failed: \" #condition << std::endl << \"# \"\n\n// Helper macro for binary operators.\n// Don't use this macro directly in your code, use RTC_CHECK_EQ et al below.\n//\n// TODO(akalin): Rewrite this so that constructs like if (...)\n// RTC_CHECK_EQ(...) else { ... } work properly.\n#define RTC_CHECK_OP(name, op, val1, val2)                                 \\\n  if (std::string* _result =                                               \\\n          rtc::Check##name##Impl((val1), (val2), #val1 \" \" #op \" \" #val2)) \\\n    rtc::FatalMessage(__FILE__, __LINE__, _result).stream()\n\n// Build the error message string.  This is separate from the \"Impl\"\n// function template because it is not performance critical and so can\n// be out of line, while the \"Impl\" code should be inline.  Caller\n// takes ownership of the returned string.\ntemplate<class t1, class t2>\nstd::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) {\n  std::ostringstream ss;\n  ss << names << \" (\" << v1 << \" vs. \" << v2 << \")\";\n  std::string* msg = new std::string(ss.str());\n  return msg;\n}\n\n// MSVC doesn't like complex extern templates and DLLs.\n#if !defined(COMPILER_MSVC)\n// Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated\n// in logging.cc.\nextern template std::string* MakeCheckOpString<int, int>(\n    const int&, const int&, const char* names);\nextern template\nstd::string* MakeCheckOpString<unsigned long, unsigned long>(\n    const unsigned long&, const unsigned long&, const char* names);\nextern template\nstd::string* MakeCheckOpString<unsigned long, unsigned int>(\n    const unsigned long&, const unsigned int&, const char* names);\nextern template\nstd::string* MakeCheckOpString<unsigned int, unsigned long>(\n    const unsigned int&, const unsigned long&, const char* names);\nextern template\nstd::string* MakeCheckOpString<std::string, std::string>(\n    const std::string&, const std::string&, const char* name);\n#endif\n\n// Helper functions for RTC_CHECK_OP macro.\n// The (int, int) specialization works around the issue that the compiler\n// will not instantiate the template version of the function on values of\n// unnamed enum type - see comment below.\n#define DEFINE_RTC_CHECK_OP_IMPL(name)                                       \\\n  template <class t1, class t2>                                              \\\n  inline std::string* Check##name##Impl(const t1& v1, const t2& v2,          \\\n                                        const char* names) {                 \\\n    if (rtc::Safe##name(v1, v2))                                             \\\n      return nullptr;                                                        \\\n    else                                                                     \\\n      return rtc::MakeCheckOpString(v1, v2, names);                          \\\n  }                                                                          \\\n  inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \\\n    if (rtc::Safe##name(v1, v2))                                             \\\n      return nullptr;                                                        \\\n    else                                                                     \\\n      return rtc::MakeCheckOpString(v1, v2, names);                          \\\n  }\nDEFINE_RTC_CHECK_OP_IMPL(Eq)\nDEFINE_RTC_CHECK_OP_IMPL(Ne)\nDEFINE_RTC_CHECK_OP_IMPL(Le)\nDEFINE_RTC_CHECK_OP_IMPL(Lt)\nDEFINE_RTC_CHECK_OP_IMPL(Ge)\nDEFINE_RTC_CHECK_OP_IMPL(Gt)\n#undef DEFINE_RTC_CHECK_OP_IMPL\n\n#define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(Eq, ==, val1, val2)\n#define RTC_CHECK_NE(val1, val2) RTC_CHECK_OP(Ne, !=, val1, val2)\n#define RTC_CHECK_LE(val1, val2) RTC_CHECK_OP(Le, <=, val1, val2)\n#define RTC_CHECK_LT(val1, val2) RTC_CHECK_OP(Lt, <, val1, val2)\n#define RTC_CHECK_GE(val1, val2) RTC_CHECK_OP(Ge, >=, val1, val2)\n#define RTC_CHECK_GT(val1, val2) RTC_CHECK_OP(Gt, >, val1, val2)\n\n// The RTC_DCHECK macro is equivalent to RTC_CHECK except that it only generates\n// code in debug builds. It does reference the condition parameter in all cases,\n// though, so callers won't risk getting warnings about unused variables.\n#if RTC_DCHECK_IS_ON\n#define RTC_DCHECK(condition) RTC_CHECK(condition)\n#define RTC_DCHECK_EQ(v1, v2) RTC_CHECK_EQ(v1, v2)\n#define RTC_DCHECK_NE(v1, v2) RTC_CHECK_NE(v1, v2)\n#define RTC_DCHECK_LE(v1, v2) RTC_CHECK_LE(v1, v2)\n#define RTC_DCHECK_LT(v1, v2) RTC_CHECK_LT(v1, v2)\n#define RTC_DCHECK_GE(v1, v2) RTC_CHECK_GE(v1, v2)\n#define RTC_DCHECK_GT(v1, v2) RTC_CHECK_GT(v1, v2)\n#else\n#define RTC_DCHECK(condition) RTC_EAT_STREAM_PARAMETERS(condition)\n#define RTC_DCHECK_EQ(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Eq, v1, v2)\n#define RTC_DCHECK_NE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Ne, v1, v2)\n#define RTC_DCHECK_LE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Le, v1, v2)\n#define RTC_DCHECK_LT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Lt, v1, v2)\n#define RTC_DCHECK_GE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Ge, v1, v2)\n#define RTC_DCHECK_GT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Gt, v1, v2)\n#endif\n\n// This is identical to LogMessageVoidify but in name.\nclass FatalMessageVoidify {\n public:\n  FatalMessageVoidify() { }\n  // This has to be an operator with a precedence lower than << but\n  // higher than ?:\n  void operator&(std::ostream&) { }\n};\n\n#define RTC_UNREACHABLE_CODE_HIT false\n#define RTC_NOTREACHED() RTC_DCHECK(RTC_UNREACHABLE_CODE_HIT)\n\n// TODO(bugs.webrtc.org/8454): Add an RTC_ prefix or rename differently.\n#define FATAL() rtc::FatalMessage(__FILE__, __LINE__).stream()\n// TODO(ajm): Consider adding RTC_NOTIMPLEMENTED macro when\n// base/logging.h and system_wrappers/logging.h are consolidated such that we\n// can match the Chromium behavior.\n\n// Like a stripped-down LogMessage from logging.h, except that it aborts.\nclass FatalMessage {\n public:\n  FatalMessage(const char* file, int line);\n  // Used for RTC_CHECK_EQ(), etc. Takes ownership of the given string.\n  FatalMessage(const char* file, int line, std::string* result);\n  NO_RETURN ~FatalMessage();\n\n  std::ostream& stream() { return stream_; }\n\n private:\n  void Init(const char* file, int line);\n\n  std::ostringstream stream_;\n};\n\n// Performs the integer division a/b and returns the result. CHECKs that the\n// remainder is zero.\ntemplate <typename T>\ninline T CheckedDivExact(T a, T b) {\n  RTC_CHECK_EQ(a % b, 0) << a << \" is not evenly divisible by \" << b;\n  return a / b;\n}\n\n}  // namespace rtc\n\n#else  // __cplusplus not defined\n// C version. Lacks many features compared to the C++ version, but usage\n// guidelines are the same.\n\n#define RTC_CHECK(condition)                                             \\\n  do {                                                                   \\\n    if (!(condition)) {                                                  \\\n      rtc_FatalMessage(__FILE__, __LINE__, \"CHECK failed: \" #condition); \\\n    }                                                                    \\\n  } while (0)\n\n#define RTC_CHECK_EQ(a, b) RTC_CHECK((a) == (b))\n#define RTC_CHECK_NE(a, b) RTC_CHECK((a) != (b))\n#define RTC_CHECK_LE(a, b) RTC_CHECK((a) <= (b))\n#define RTC_CHECK_LT(a, b) RTC_CHECK((a) < (b))\n#define RTC_CHECK_GE(a, b) RTC_CHECK((a) >= (b))\n#define RTC_CHECK_GT(a, b) RTC_CHECK((a) > (b))\n\n#define RTC_DCHECK(condition)                                             \\\n  do {                                                                    \\\n    if (RTC_DCHECK_IS_ON && !(condition)) {                               \\\n      rtc_FatalMessage(__FILE__, __LINE__, \"DCHECK failed: \" #condition); \\\n    }                                                                     \\\n  } while (0)\n\n#define RTC_DCHECK_EQ(a, b) RTC_DCHECK((a) == (b))\n#define RTC_DCHECK_NE(a, b) RTC_DCHECK((a) != (b))\n#define RTC_DCHECK_LE(a, b) RTC_DCHECK((a) <= (b))\n#define RTC_DCHECK_LT(a, b) RTC_DCHECK((a) < (b))\n#define RTC_DCHECK_GE(a, b) RTC_DCHECK((a) >= (b))\n#define RTC_DCHECK_GT(a, b) RTC_DCHECK((a) > (b))\n\n#endif  // __cplusplus\n\n#endif  // RTC_BASE_CHECKS_H_\n"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/compile_assert_c.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef RTC_BASE_COMPILE_ASSERT_C_H_\n#define RTC_BASE_COMPILE_ASSERT_C_H_\n\n// Use this macro to verify at compile time that certain restrictions are met.\n// The argument is the boolean expression to evaluate.\n// Example:\n//   RTC_COMPILE_ASSERT(sizeof(foo) < 128);\n// Note: In C++, use static_assert instead!\n#define RTC_COMPILE_ASSERT(expression) switch (0) {case 0: case expression:;}\n\n#endif  // RTC_BASE_COMPILE_ASSERT_C_H_\n"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/numerics/safe_compare.h",
    "content": "/*\n *  Copyright 2016 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n// This file defines six constexpr functions:\n//\n//   rtc::SafeEq  // ==\n//   rtc::SafeNe  // !=\n//   rtc::SafeLt  // <\n//   rtc::SafeLe  // <=\n//   rtc::SafeGt  // >\n//   rtc::SafeGe  // >=\n//\n// They each accept two arguments of arbitrary types, and in almost all cases,\n// they simply call the appropriate comparison operator. However, if both\n// arguments are integers, they don't compare them using C++'s quirky rules,\n// but instead adhere to the true mathematical definitions. It is as if the\n// arguments were first converted to infinite-range signed integers, and then\n// compared, although of course nothing expensive like that actually takes\n// place. In practice, for signed/signed and unsigned/unsigned comparisons and\n// some mixed-signed comparisons with a compile-time constant, the overhead is\n// zero; in the remaining cases, it is just a few machine instructions (no\n// branches).\n\n#ifndef RTC_BASE_NUMERICS_SAFE_COMPARE_H_\n#define RTC_BASE_NUMERICS_SAFE_COMPARE_H_\n\n#include <stddef.h>\n#include <stdint.h>\n\n#include <type_traits>\n#include <utility>\n\n#include \"rtc_base/type_traits.h\"\n\nnamespace rtc {\n\nnamespace safe_cmp_impl {\n\ntemplate <size_t N>\nstruct LargerIntImpl : std::false_type {};\ntemplate <>\nstruct LargerIntImpl<sizeof(int8_t)> : std::true_type {\n  using type = int16_t;\n};\ntemplate <>\nstruct LargerIntImpl<sizeof(int16_t)> : std::true_type {\n  using type = int32_t;\n};\ntemplate <>\nstruct LargerIntImpl<sizeof(int32_t)> : std::true_type {\n  using type = int64_t;\n};\n\n// LargerInt<T1, T2>::value is true iff there's a signed type that's larger\n// than T1 (and no larger than the larger of T2 and int*, for performance\n// reasons); and if there is such a type, LargerInt<T1, T2>::type is an alias\n// for it.\ntemplate <typename T1, typename T2>\nstruct LargerInt\n    : LargerIntImpl<sizeof(T1) < sizeof(T2) || sizeof(T1) < sizeof(int*)\n                        ? sizeof(T1)\n                        : 0> {};\n\ntemplate <typename T>\nconstexpr typename std::make_unsigned<T>::type MakeUnsigned(T a) {\n  return static_cast<typename std::make_unsigned<T>::type>(a);\n}\n\n// Overload for when both T1 and T2 have the same signedness.\ntemplate <typename Op,\n          typename T1,\n          typename T2,\n          typename std::enable_if<std::is_signed<T1>::value ==\n                                  std::is_signed<T2>::value>::type* = nullptr>\nconstexpr bool Cmp(T1 a, T2 b) {\n  return Op::Op(a, b);\n}\n\n// Overload for signed - unsigned comparison that can be promoted to a bigger\n// signed type.\ntemplate <typename Op,\n          typename T1,\n          typename T2,\n          typename std::enable_if<std::is_signed<T1>::value &&\n                                  std::is_unsigned<T2>::value &&\n                                  LargerInt<T2, T1>::value>::type* = nullptr>\nconstexpr bool Cmp(T1 a, T2 b) {\n  return Op::Op(a, static_cast<typename LargerInt<T2, T1>::type>(b));\n}\n\n// Overload for unsigned - signed comparison that can be promoted to a bigger\n// signed type.\ntemplate <typename Op,\n          typename T1,\n          typename T2,\n          typename std::enable_if<std::is_unsigned<T1>::value &&\n                                  std::is_signed<T2>::value &&\n                                  LargerInt<T1, T2>::value>::type* = nullptr>\nconstexpr bool Cmp(T1 a, T2 b) {\n  return Op::Op(static_cast<typename LargerInt<T1, T2>::type>(a), b);\n}\n\n// Overload for signed - unsigned comparison that can't be promoted to a bigger\n// signed type.\ntemplate <typename Op,\n          typename T1,\n          typename T2,\n          typename std::enable_if<std::is_signed<T1>::value &&\n                                  std::is_unsigned<T2>::value &&\n                                  !LargerInt<T2, T1>::value>::type* = nullptr>\nconstexpr bool Cmp(T1 a, T2 b) {\n  return a < 0 ? Op::Op(-1, 0) : Op::Op(safe_cmp_impl::MakeUnsigned(a), b);\n}\n\n// Overload for unsigned - signed comparison that can't be promoted to a bigger\n// signed type.\ntemplate <typename Op,\n          typename T1,\n          typename T2,\n          typename std::enable_if<std::is_unsigned<T1>::value &&\n                                  std::is_signed<T2>::value &&\n                                  !LargerInt<T1, T2>::value>::type* = nullptr>\nconstexpr bool Cmp(T1 a, T2 b) {\n  return b < 0 ? Op::Op(0, -1) : Op::Op(a, safe_cmp_impl::MakeUnsigned(b));\n}\n\n#define RTC_SAFECMP_MAKE_OP(name, op)      \\\n  struct name {                            \\\n    template <typename T1, typename T2>    \\\n    static constexpr bool Op(T1 a, T2 b) { \\\n      return a op b;                       \\\n    }                                      \\\n  };\nRTC_SAFECMP_MAKE_OP(EqOp, ==)\nRTC_SAFECMP_MAKE_OP(NeOp, !=)\nRTC_SAFECMP_MAKE_OP(LtOp, <)\nRTC_SAFECMP_MAKE_OP(LeOp, <=)\nRTC_SAFECMP_MAKE_OP(GtOp, >)\nRTC_SAFECMP_MAKE_OP(GeOp, >=)\n#undef RTC_SAFECMP_MAKE_OP\n\n}  // namespace safe_cmp_impl\n\n#define RTC_SAFECMP_MAKE_FUN(name)                                            \\\n  template <typename T1, typename T2>                                         \\\n  constexpr                                                                   \\\n      typename std::enable_if<IsIntlike<T1>::value && IsIntlike<T2>::value,   \\\n                              bool>::type Safe##name(T1 a, T2 b) {            \\\n    /* Unary plus here turns enums into real integral types. */               \\\n    return safe_cmp_impl::Cmp<safe_cmp_impl::name##Op>(+a, +b);               \\\n  }                                                                           \\\n  template <typename T1, typename T2>                                         \\\n  constexpr                                                                   \\\n      typename std::enable_if<!IsIntlike<T1>::value || !IsIntlike<T2>::value, \\\n                              bool>::type Safe##name(const T1& a,             \\\n                                                     const T2& b) {           \\\n    return safe_cmp_impl::name##Op::Op(a, b);                                 \\\n  }\nRTC_SAFECMP_MAKE_FUN(Eq)\nRTC_SAFECMP_MAKE_FUN(Ne)\nRTC_SAFECMP_MAKE_FUN(Lt)\nRTC_SAFECMP_MAKE_FUN(Le)\nRTC_SAFECMP_MAKE_FUN(Gt)\nRTC_SAFECMP_MAKE_FUN(Ge)\n#undef RTC_SAFECMP_MAKE_FUN\n\n}  // namespace rtc\n\n#endif  // RTC_BASE_NUMERICS_SAFE_COMPARE_H_\n"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/sanitizer.h",
    "content": "/*\n *  Copyright 2016 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef RTC_BASE_SANITIZER_H_\n#define RTC_BASE_SANITIZER_H_\n\n#include <stddef.h>  // for size_t\n\n#if defined(__has_feature)\n#if __has_feature(address_sanitizer)\n#define RTC_HAS_ASAN 1\n#endif\n#if __has_feature(memory_sanitizer)\n#define RTC_HAS_MSAN 1\n#endif\n#endif\n#ifndef RTC_HAS_ASAN\n#define RTC_HAS_ASAN 0\n#endif\n#ifndef RTC_HAS_MSAN\n#define RTC_HAS_MSAN 0\n#endif\n\n#if RTC_HAS_ASAN\n#include <sanitizer/asan_interface.h>\n#endif\n#if RTC_HAS_MSAN\n#include <sanitizer/msan_interface.h>\n#endif\n\n#ifdef __has_attribute\n#if __has_attribute(no_sanitize)\n#define RTC_NO_SANITIZE(what) __attribute__((no_sanitize(what)))\n#endif\n#endif\n#ifndef RTC_NO_SANITIZE\n#define RTC_NO_SANITIZE(what)\n#endif\n\n// Ask ASan to mark the memory range [ptr, ptr + element_size * num_elements)\n// as being unaddressable, so that reads and writes are not allowed. ASan may\n// narrow the range to the nearest alignment boundaries.\nstatic inline void rtc_AsanPoison(const volatile void* ptr,\n                                  size_t element_size,\n                                  size_t num_elements) {\n#if RTC_HAS_ASAN\n  ASAN_POISON_MEMORY_REGION(ptr, element_size * num_elements);\n#endif\n}\n\n// Ask ASan to mark the memory range [ptr, ptr + element_size * num_elements)\n// as being addressable, so that reads and writes are allowed. ASan may widen\n// the range to the nearest alignment boundaries.\nstatic inline void rtc_AsanUnpoison(const volatile void* ptr,\n                                    size_t element_size,\n                                    size_t num_elements) {\n#if RTC_HAS_ASAN\n  ASAN_UNPOISON_MEMORY_REGION(ptr, element_size * num_elements);\n#endif\n}\n\n// Ask MSan to mark the memory range [ptr, ptr + element_size * num_elements)\n// as being uninitialized.\nstatic inline void rtc_MsanMarkUninitialized(const volatile void* ptr,\n                                             size_t element_size,\n                                             size_t num_elements) {\n#if RTC_HAS_MSAN\n  __msan_poison(ptr, element_size * num_elements);\n#endif\n}\n\n// Force an MSan check (if any bits in the memory range [ptr, ptr +\n// element_size * num_elements) are uninitialized the call will crash with an\n// MSan report).\nstatic inline void rtc_MsanCheckInitialized(const volatile void* ptr,\n                                            size_t element_size,\n                                            size_t num_elements) {\n#if RTC_HAS_MSAN\n  __msan_check_mem_is_initialized(ptr, element_size * num_elements);\n#endif\n}\n\n#ifdef __cplusplus\n\nnamespace rtc {\n\ntemplate <typename T>\ninline void AsanPoison(const T& mem) {\n  rtc_AsanPoison(mem.data(), sizeof(mem.data()[0]), mem.size());\n}\n\ntemplate <typename T>\ninline void AsanUnpoison(const T& mem) {\n  rtc_AsanUnpoison(mem.data(), sizeof(mem.data()[0]), mem.size());\n}\n\ntemplate <typename T>\ninline void MsanMarkUninitialized(const T& mem) {\n  rtc_MsanMarkUninitialized(mem.data(), sizeof(mem.data()[0]), mem.size());\n}\n\ntemplate <typename T>\ninline void MsanCheckInitialized(const T& mem) {\n  rtc_MsanCheckInitialized(mem.data(), sizeof(mem.data()[0]), mem.size());\n}\n\n}  // namespace rtc\n\n#endif  // __cplusplus\n\n#endif  // RTC_BASE_SANITIZER_H_\n"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/type_traits.h",
    "content": "/*\n *  Copyright 2016 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef RTC_BASE_TYPE_TRAITS_H_\n#define RTC_BASE_TYPE_TRAITS_H_\n\n#include <cstddef>\n#include <type_traits>\n\nnamespace rtc {\n\n// Determines if the given class has zero-argument .data() and .size() methods\n// whose return values are convertible to T* and size_t, respectively.\ntemplate <typename DS, typename T>\nclass HasDataAndSize {\n private:\n  template <\n      typename C,\n      typename std::enable_if<\n          std::is_convertible<decltype(std::declval<C>().data()), T*>::value &&\n          std::is_convertible<decltype(std::declval<C>().size()),\n                              std::size_t>::value>::type* = nullptr>\n  static int Test(int);\n\n  template <typename>\n  static char Test(...);\n\n public:\n  static constexpr bool value = std::is_same<decltype(Test<DS>(0)), int>::value;\n};\n\nnamespace test_has_data_and_size {\n\ntemplate <typename DR, typename SR>\nstruct Test1 {\n  DR data();\n  SR size();\n};\nstatic_assert(HasDataAndSize<Test1<int*, int>, int>::value, \"\");\nstatic_assert(HasDataAndSize<Test1<int*, int>, const int>::value, \"\");\nstatic_assert(HasDataAndSize<Test1<const int*, int>, const int>::value, \"\");\nstatic_assert(!HasDataAndSize<Test1<const int*, int>, int>::value,\n              \"implicit cast of const int* to int*\");\nstatic_assert(!HasDataAndSize<Test1<char*, size_t>, int>::value,\n              \"implicit cast of char* to int*\");\n\nstruct Test2 {\n  int* data;\n  size_t size;\n};\nstatic_assert(!HasDataAndSize<Test2, int>::value,\n              \".data and .size aren't functions\");\n\nstruct Test3 {\n  int* data();\n};\nstatic_assert(!HasDataAndSize<Test3, int>::value, \".size() is missing\");\n\nclass Test4 {\n  int* data();\n  size_t size();\n};\nstatic_assert(!HasDataAndSize<Test4, int>::value,\n              \".data() and .size() are private\");\n\n}  // namespace test_has_data_and_size\n\nnamespace type_traits_impl {\n\n// Determines if the given type is an enum that converts implicitly to\n// an integral type.\ntemplate <typename T>\nstruct IsIntEnum {\n private:\n  // This overload is used if the type is an enum, and unary plus\n  // compiles and turns it into an integral type.\n  template <typename X,\n            typename std::enable_if<\n                std::is_enum<X>::value &&\n                std::is_integral<decltype(+std::declval<X>())>::value>::type* =\n                nullptr>\n  static int Test(int);\n\n  // Otherwise, this overload is used.\n  template <typename>\n  static char Test(...);\n\n public:\n  static constexpr bool value =\n      std::is_same<decltype(Test<typename std::remove_reference<T>::type>(0)),\n                   int>::value;\n};\n\n}  // namespace type_traits_impl\n\n// Determines if the given type is integral, or an enum that\n// converts implicitly to an integral type.\ntemplate <typename T>\nstruct IsIntlike {\n private:\n  using X = typename std::remove_reference<T>::type;\n\n public:\n  static constexpr bool value =\n      std::is_integral<X>::value || type_traits_impl::IsIntEnum<X>::value;\n};\n\nnamespace test_enum_intlike {\n\nenum E1 { e1 };\nenum { e2 };\nenum class E3 { e3 };\nstruct S {};\n\nstatic_assert(type_traits_impl::IsIntEnum<E1>::value, \"\");\nstatic_assert(type_traits_impl::IsIntEnum<decltype(e2)>::value, \"\");\nstatic_assert(!type_traits_impl::IsIntEnum<E3>::value, \"\");\nstatic_assert(!type_traits_impl::IsIntEnum<int>::value, \"\");\nstatic_assert(!type_traits_impl::IsIntEnum<float>::value, \"\");\nstatic_assert(!type_traits_impl::IsIntEnum<S>::value, \"\");\n\nstatic_assert(IsIntlike<E1>::value, \"\");\nstatic_assert(IsIntlike<decltype(e2)>::value, \"\");\nstatic_assert(!IsIntlike<E3>::value, \"\");\nstatic_assert(IsIntlike<int>::value, \"\");\nstatic_assert(!IsIntlike<float>::value, \"\");\nstatic_assert(!IsIntlike<S>::value, \"\");\n\n}  // test_enum_intlike\n\n}  // namespace rtc\n\n#endif  // RTC_BASE_TYPE_TRAITS_H_\n"
  },
  {
    "path": "thirdparty/webrtc/system_wrappers/include/cpu_features_wrapper.h",
    "content": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n#ifndef SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_\n#define SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_\n\n#if defined(__cplusplus) || defined(c_plusplus)\nextern \"C\" {\n#endif\n\n#include \"typedefs.h\"  // NOLINT(build/include)\n\n// List of features in x86.\ntypedef enum { kSSE2, kSSE3 } CPUFeature;\n\n// List of features in ARM.\nenum {\n  kCPUFeatureARMv7 = (1 << 0),\n  kCPUFeatureVFPv3 = (1 << 1),\n  kCPUFeatureNEON = (1 << 2),\n  kCPUFeatureLDREXSTREX = (1 << 3)\n};\n\ntypedef int (*WebRtc_CPUInfo)(CPUFeature feature);\n\n// Returns true if the CPU supports the feature.\nextern WebRtc_CPUInfo WebRtc_GetCPUInfo;\n\n// No CPU feature is available => straight C path.\nextern WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM;\n\n// Return the features in an ARM device.\n// It detects the features in the hardware platform, and returns supported\n// values in the above enum definition as a bitmask.\nextern uint64_t WebRtc_GetCPUFeaturesARM(void);\n\n#if defined(__cplusplus) || defined(c_plusplus)\n}  // extern \"C\"\n#endif\n\n#endif  // SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_\n"
  },
  {
    "path": "thirdparty/webrtc/typedefs.h",
    "content": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by a BSD-style license\n *  that can be found in the LICENSE file in the root of the source\n *  tree. An additional intellectual property rights grant can be found\n *  in the file PATENTS.  All contributing project authors may\n *  be found in the AUTHORS file in the root of the source tree.\n */\n\n// This file contains platform-specific typedefs and defines.\n// Much of it is derived from Chromium's build/build_config.h.\n\n#ifndef TYPEDEFS_H_\n#define TYPEDEFS_H_\n\n// 参考BUILD.gn 以linux为例定义如下几个变量\n#define WEBRTC_POSIX\n#define WEBRTC_LINUX\n\n// Processor architecture detection.  For more info on what's defined, see:\n//   http://msdn.microsoft.com/en-us/library/b0084kay.aspx\n//   http://www.agner.org/optimize/calling_conventions.pdf\n//   or with gcc, run: \"echo | gcc -E -dM -\"\n#if defined(_M_X64) || defined(__x86_64__)\n#define WEBRTC_ARCH_X86_FAMILY\n#define WEBRTC_ARCH_X86_64\n#define WEBRTC_ARCH_64_BITS\n#define WEBRTC_ARCH_LITTLE_ENDIAN\n#elif defined(__aarch64__)\n#define WEBRTC_ARCH_ARM_FAMILY\n#define WEBRTC_ARCH_64_BITS\n#define WEBRTC_ARCH_LITTLE_ENDIAN\n#elif defined(_M_IX86) || defined(__i386__)\n#define WEBRTC_ARCH_X86_FAMILY\n#define WEBRTC_ARCH_X86\n#define WEBRTC_ARCH_32_BITS\n#define WEBRTC_ARCH_LITTLE_ENDIAN\n#elif defined(__ARMEL__)\n#define WEBRTC_ARCH_ARM_FAMILY\n#define WEBRTC_ARCH_32_BITS\n#define WEBRTC_ARCH_LITTLE_ENDIAN\n#elif defined(__MIPSEL__)\n#define WEBRTC_ARCH_MIPS_FAMILY\n#if defined(__LP64__)\n#define WEBRTC_ARCH_64_BITS\n#else\n#define WEBRTC_ARCH_32_BITS\n#endif\n#define WEBRTC_ARCH_LITTLE_ENDIAN\n#elif defined(__pnacl__)\n#define WEBRTC_ARCH_32_BITS\n#define WEBRTC_ARCH_LITTLE_ENDIAN\n#else\n#error Please add support for your architecture in typedefs.h\n#endif\n\n#if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN))\n#error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN\n#endif\n\n// TODO(zhongwei.yao): WEBRTC_CPU_DETECTION is only used in one place; we should\n// probably just remove it.\n#if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__))\n#define WEBRTC_CPU_DETECTION\n#endif\n\n#include <stdint.h>\n\n// Annotate a function indicating the caller must examine the return value.\n// Use like:\n//   int foo() RTC_WARN_UNUSED_RESULT;\n// To explicitly ignore a result, cast to void.\n// TODO(kwiberg): Remove when we can use [[nodiscard]] from C++17.\n#if defined(__clang__)\n#define RTC_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))\n#elif defined(__GNUC__)\n// gcc has a __warn_unused_result__ attribute, but you can't quiet it by\n// casting to void, so we don't use it.\n#define RTC_WARN_UNUSED_RESULT\n#else\n#define RTC_WARN_UNUSED_RESULT\n#endif\n\n// Put after a variable that might not be used, to prevent compiler warnings:\n//   int result ATTRIBUTE_UNUSED = DoSomething();\n//   assert(result == 17);\n// Deprecated since it only works with GCC & clang. See RTC_UNUSED below.\n// TODO(terelius): Remove.\n#ifndef ATTRIBUTE_UNUSED\n#if defined(__GNUC__) || defined(__clang__)\n#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))\n#else\n#define ATTRIBUTE_UNUSED\n#endif\n#endif\n\n#ifndef NO_RETURN\n// Annotate a function that will not return control flow to the caller.\n#if defined(_MSC_VER)\n#define NO_RETURN __declspec(noreturn)\n#elif defined(__GNUC__)\n#define NO_RETURN __attribute__ ((__noreturn__))\n#else\n#define NO_RETURN\n#endif\n#endif\n\n// Prevent the compiler from warning about an unused variable. For example:\n//   int result = DoSomething();\n//   assert(result == 17);\n//   RTC_UNUSED(result);\n// Note: In most cases it is better to remove the unused variable rather than\n// suppressing the compiler warning.\n#ifndef RTC_UNUSED\n#define RTC_UNUSED(x) static_cast<void>(x)\n#endif  // RTC_UNUSED\n\n#endif  // TYPEDEFS_H_\n"
  },
  {
    "path": "valgrind.sh",
    "content": "#!/usr/bin/env bash\nFILE=build/vad-demo\nvalgrind --leak-check=full --show-leak-kinds=all --show-reachable=no --track-origins=yes $FILE"
  }
]