Full Code of Baidu-AIP/speech-vad-demo for AI

master 8a9906246e6d cached
67 files
347.0 KB
103.9k tokens
213 symbols
1 requests
Download .txt
Showing preview only (371K chars total). Download the full file or copy to clipboard to get everything.
Repository: Baidu-AIP/speech-vad-demo
Branch: master
Commit: 8a9906246e6d
Files: 67
Total size: 347.0 KB

Directory structure:
gitextract_iq5s0_a2/

├── .gitignore
├── CMakeLists.txt
├── README.md
├── build_and_run.sh
├── src/
│   ├── common.h
│   ├── file_cut.c
│   ├── file_cut.h
│   ├── main.c
│   ├── period_format.c
│   ├── period_format.h
│   ├── simple_vad.c
│   └── simple_vad.h
├── thirdparty/
│   └── webrtc/
│       ├── BUILD.gn
│       ├── common_audio/
│       │   ├── rename.sh
│       │   ├── rename.sh~
│       │   ├── signal_processing/
│       │   │   ├── cross_correlation.c
│       │   │   ├── cross_correlation_mips.c.mips
│       │   │   ├── cross_correlation_neon.c.neon
│       │   │   ├── division_operations.c
│       │   │   ├── downsample_fast.c
│       │   │   ├── downsample_fast_mips.c.mips
│       │   │   ├── downsample_fast_neon.c.neon
│       │   │   ├── energy.c
│       │   │   ├── get_scaling_square.c
│       │   │   ├── include/
│       │   │   │   ├── real_fft.h
│       │   │   │   ├── signal_processing_library.h
│       │   │   │   ├── spl_inl.h
│       │   │   │   ├── spl_inl_armv7.h
│       │   │   │   └── spl_inl_mips.h
│       │   │   ├── min_max_operations.c
│       │   │   ├── min_max_operations_mips.c.mips
│       │   │   ├── min_max_operations_neon.c.neon
│       │   │   ├── resample_48khz.c
│       │   │   ├── resample_by_2_internal.c
│       │   │   ├── resample_by_2_internal.h
│       │   │   ├── resample_fractional.c
│       │   │   ├── spl_init.c
│       │   │   ├── vector_scaling_operations.c
│       │   │   └── vector_scaling_operations_mips.c.mips
│       │   └── vad/
│       │       ├── include/
│       │       │   ├── vad.h
│       │       │   └── webrtc_vad.h
│       │       ├── mock/
│       │       │   └── mock_vad.h
│       │       ├── vad.cc
│       │       ├── vad_core.c
│       │       ├── vad_core.h
│       │       ├── vad_core_unittest.cc
│       │       ├── vad_filterbank.c
│       │       ├── vad_filterbank.h
│       │       ├── vad_filterbank_unittest.cc
│       │       ├── vad_gmm.c
│       │       ├── vad_gmm.h
│       │       ├── vad_gmm_unittest.cc
│       │       ├── vad_sp.c
│       │       ├── vad_sp.h
│       │       ├── vad_sp_unittest.cc
│       │       ├── vad_unittest.cc
│       │       ├── vad_unittest.h
│       │       └── webrtc_vad.c
│       ├── rtc_base/
│       │   ├── checks.cc
│       │   ├── checks.h
│       │   ├── compile_assert_c.h
│       │   ├── numerics/
│       │   │   └── safe_compare.h
│       │   ├── sanitizer.h
│       │   └── type_traits.h
│       ├── system_wrappers/
│       │   └── include/
│       │       └── cpu_features_wrapper.h
│       └── typedefs.h
└── valgrind.sh

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
pcm/
build/
output_pcm/
.vscode/
vad-demo*

================================================
FILE: CMakeLists.txt
================================================
cmake_minimum_required(VERSION 2.8)
set(CMAKE_VERBOSE_MAKEFILE on)
project(vad-demo)
set(CMAKE_BUILD_TYPE DEBUG)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set(CMAKE_C_STANDARD 99)
file(GLOB SRC_FILES src/*.c src/*.h thirdparty/webrtc/common_audio/*/*.c thirdparty/webrtc/rtc_base/*.c*)
include_directories(thirdparty/webrtc) #thirdparty/include/webrtc
add_executable(vad-demo ${SRC_FILES})
target_link_libraries(vad-demo pthread)

================================================
FILE: README.md
================================================
# speech-vad-demo


## 简介
### 简介

项目地址: https://github.com/Baidu-AIP/speech-vad-demo

集成 [webrtc](https://webrtc.org/) 开源项目,vad模块,具体算法*GMM*(Gaussian Mixture Model)。

由于百度rest api接口有60s的音频时长限制,使用此demo可以粗略地按照静音切分音频。

### 原理

一个FRAME时长默认10s,通过webrtc的vad计算这个FRAME是否是活动(ACTIVE: 有声音, INACTIVE,静音)。

这样可以获得音频的所有FRAME的活动值(ACTIVE或者INACTIVE)。从而在静音(INACTIVE)的音频段上的切分音频。

### 运行环境

- g++ 4.8以上,
- cmake 2.8 及 make 3.8 编译需要,可以跳过或者尝试使用低版本  
- 任意操作系统

如果没有g++ 4.8的版本,centos可以参考“Linux C++ SDK”的文档,进行g++ 4.8的安装。

由于webrtc项目vad模块依赖于rtc_base模块 进行运行时的参数检查,因此需要可以编译rtc_base的。
如果您无法升级到g++ 4.8 或者是只能编译C项目,可以自行修改源代码,删除rtc_bas目录,及其它文件对rtc_base中宏的依赖,,剩余文件均为C代码。去除后请详细测试。

## 运行及结果

### 运行命令

Linux:

```bash
# 确认g++ 和cmake 版本
sh build_and_run.sh

# 或
cmake . && make
```

Windows:

Windows 安装 cygwin,及cygwin 中 下载cmake make gcc g++等编译软件

```bat
sh build_and_run.sh

# 或
cmake . && make
```

### 结果
如果不修改代码的话,结果保存在 output_pcm 内。
文件名如下
```
16k_1.pcm_0-12989_A.pcm         // 第0-12989毫秒的音频, 
16k_1.pcm_33730-47389_A.pcm     // 第33730-47389毫秒的音频
16k_1.pcm_0-4049_A.pcm         // A 表示此段有声音,不是完全的静音
···
16k_1.pcm_114060-121689_I.pcm  // I 表示此段都是静音
```

## 参数设置

### common.h
```c
// MULTI = 1 2 3 webrtc vad可以设置分别为以10ms 20ms 30ms作为包
#define MULTI 1

// VAD 模式 Aggressiveness mode (0, 1, 2, or 3). 数值越大,判断越是粗略,连着的静音或者响声增多
#define WEBRTC_VAD_MODE 3

// 有声音的音频段,xxx 毫秒后,认为该音频段结束,不能为0
#define FILE_CUT_SILENCE_AFTER_ACTIVE_MS 500

// 静音的音频段,切分xxx毫秒给之后有声音的音频段
#define FILE_CUT_SILENCE_BEFORE_ACTIVE_MS 300

// 最小的音频切分长度,即每个切分后音频文件不少于这个时长,最后一个除外
#define FILE_CUT_MIN_MS  (10 * 1000)

// 最大的音频切分长度,即每个切分后音频文件不多于这个时长
#define FILE_CUT_MAX_MS  (60 * 1000)

/** 上述示例中音频文件尽可能依次满足如下条件
1. 最短10s,最长 60s。 
2. 每个音频文件的最后的静音500ms, 
2. 每个音频文件的开始的静300ms。
 */
```

### 切割逻辑修改

demo因为考虑到流式,采用了尽快切割的方法。如果您对这个切割算法不满意的话,可以对照periods_print的结果, 自行修改file_cut.c内的代码逻辑

```c
// [5150, 5220) [5230, 6380) [6520, 6970) [7000, 8040) [8080, 8670)
// 表示 [5150, 5220) 等区间内是有声音的,其它区间均为静音,
// 如果需要切割的话,应该在静音区间选择合适的位置切割
```

================================================
FILE: build_and_run.sh
================================================
#!/usr/bin/env bash
set -uex
check_version(){
    CMD=$1
    OPT=$2
    VERSION=$3

    #$CMD $OPT
    RES=$($CMD $OPT |head -1)
    echo $RES
   
}

check_version "gcc" "--version" "4.8.2"
check_version "cmake" "--version" "2.8"
sleep 2;
echo ""
mkdir -p build && \
mkdir -p output_pcm && \
rm -rf  output_pcm/* build/* && \
cd build && \
cmake .. && \
make -j4 && \
cp vad-demo .. && cd .. && \
echo "build success wait 3s to run" && \
sleep 3 && \
./vad-demo
 


================================================
FILE: src/common.h
================================================
//
// Created by fu on 3/7/18.
//

#ifndef VAD_DEMO_COMMON_H
#define VAD_DEMO_COMMON_H

#include <stdint.h>



// MULTI = 1 2 3 webrtc vad可以设置分别为以10ms 20ms 30ms作为包
#define MULTI 1

// VAD 模式 Aggressiveness mode (0, 1, 2, or 3). 数值越大,判断越是粗略,连着的静音或者响声增多
#define WEBRTC_VAD_MODE 3

//  有声音的音频段,xxx 毫秒后,认为该音频段结束,不能为0
#define FILE_CUT_SILENCE_AFTER_ACTIVE_MS 500

// 静音的音频段,切分xxx毫秒给之后有声音的音频段
#define FILE_CUT_SILENCE_BEFORE_ACTIVE_MS 300

// 最小的音频切分长度,即每个切分后音频文件不少于这个时长,最后一个除外
#define FILE_CUT_MIN_MS  (10 * 1000)

// 最大的音频切分长度,即每个切分后音频文件不多于这个时长
#define FILE_CUT_MAX_MS  (60 * 1000)

//16000 采样率固定
#define SAMPLE_RATE 16000

//  用于period_format.h
#define PERIODS_SIZE_INITIED 100

#define FRAME_SIZE (16 * MULTI * 10 )

#define CAL_TIME_BY_FRAME(frame) (MULTI * 10 * frame)

#define CAL_FRAME_BY_TIME(time) (time / (MULTI * 10))

/*`
uint64_t inline CAL_TIME_BY_FRAME(int frame){
    return MULTI * frame * 10;
};

int inline CAL_FRAME_BY_TIME(uint64_t time){
    return time / (MULTI * 10);
};
*/
#endif //VAD_DEMO_COMMON_H


================================================
FILE: src/file_cut.c
================================================
//
// Created by fu on 3/7/18.
//

#include <stdlib.h>
#include "file_cut.h"

// static size_t file_total = 0;

static inline int cut_write_file(struct cut_info *cut, int frames) {
    int size = frames * FRAME_SIZE ;
    uint16_t buffer[size];
    int readed = fread(buffer, sizeof(uint16_t), size, cut->fp);
    if (readed > 0) {
        FILE *res_file = fopen(cut->result_filename, "wb+");
        if (res_file == NULL) {
            fprintf(stderr, "file open failed, %s\n", cut->result_filename);
            return 3;
        }
        int written = fwrite(buffer, sizeof(uint16_t), readed, res_file);
        fclose(res_file);
        if (written != readed) {
            fprintf(stderr, "written is %d, readed is %d\n", written, readed);
            return 2;
        }
        // file_total += written;
        // printf("file write success, %s, written %d\n", cut->result_filename, written);
        return 0;

    } else {
        return 1;
    }

}

static inline int cut_frame(struct cut_info *cut, int last_frame, int force) {
    int frames = last_frame - cut->cut_begin_frame;
    if (force || (frames >= CAL_FRAME_BY_TIME(FILE_CUT_MIN_MS))) {
        if (last_frame == 109) {
            printf("%d", 109);
        }
        //printf("cut file at frame: %d\n", last_frame);
        snprintf(cut->result_filename, sizeof(cut->result_filename),
                 "%s/%s_%ld-%ld_%s.pcm", cut->output_file_dir,
                 cut->output_filename_prefix, CAL_TIME_BY_FRAME(cut->cut_begin_frame),
                 CAL_TIME_BY_FRAME(last_frame) - 1, cut->is_contain_active ? "A" : "I");
        cut_write_file(cut, frames);
        cut->is_pervious_active = 0;
        cut->is_contain_active = 0;
        cut->cut_begin_frame = last_frame;
        return 0;
    } else {
        return 1;
    }
}

static inline int add_continued(struct cut_info *cut, int is_active) {
    if (!is_active && cut->is_contain_active) {
        // 有响声,之后连续静音
        int diff = cut->previous_along_frames - CAL_FRAME_BY_TIME(FILE_CUT_SILENCE_AFTER_ACTIVE_MS);
        if (diff >= 0) {
            int res = cut_frame(cut, cut->current_frame, 0);
            if (res == 0) {
                int frame = -1 * (cut->current_frame);
                cut->previous_along_frames = 1;
                return frame;
            }
        }
    }
    cut->previous_along_frames++;
    return 0;
}


static inline int add_changed(struct cut_info *cut, int is_active) {
    int frame = 0;
    if (is_active) {
        // 连续静音,之后遇到响声
        if (cut->previous_along_frames > CAL_FRAME_BY_TIME(FILE_CUT_SILENCE_BEFORE_ACTIVE_MS)) {
            int c_frames =
                    cut->current_frame - CAL_FRAME_BY_TIME(FILE_CUT_SILENCE_BEFORE_ACTIVE_MS);
            int res = cut_frame(cut, c_frames, 0);
            if (res == 0) {
                frame = -1 * (c_frames);
            }
            // cut->previous_along_frames = FILE_CUT_SILENCE_AFTER_ACTIVE_MS;
        }
    }

    cut->previous_along_frames = 1;
    return frame;
}

struct cut_info *cut_info_create(FILE *fp) {
    struct cut_info *cut = calloc(1, sizeof(struct cut_info));
    cut->fp = fp;
    return cut;
}


int cut_add_vad_activity(struct cut_info *cut, int is_active, int is_last) {
    int res;
    if (is_last ||
        (cut->current_frame - cut->cut_begin_frame == CAL_FRAME_BY_TIME(FILE_CUT_MAX_MS))) {
        cut_frame(cut, cut->current_frame, is_last);
        res = -1 * cut->current_frame;
    } else if (cut->is_pervious_active == is_active) {
        res = add_continued(cut, is_active);
    } else {
        res = add_changed(cut, is_active);
        if (is_active) {
            cut->is_contain_active = 1;
        }
    }
    cut->is_pervious_active = is_active;
    cut->current_frame++;
    return res;
}

void cut_info_free(struct cut_info *cut) {
    free(cut);
}


void cut_info_print(struct cut_info *cut) {
    printf("%s, %s, %d, frame %d\n", cut->is_pervious_active ? "PA" : "PI",
           cut->is_contain_active ? "CA" : "CI", cut->previous_along_frames, cut->current_frame);
}


================================================
FILE: src/file_cut.h
================================================
//
// Created by fu on 3/7/18.
//

#ifndef VAD_DEMO_FILE_CUT_H
#define VAD_DEMO_FILE_CUT_H

#include <stdio.h>
#include "common.h"
#include "stdint.h"

struct cut_info {
    int is_pervious_active;
    int is_contain_active;
    int previous_along_frames;
    FILE *fp;
    int current_frame;
    int cut_begin_frame;
    char result_filename[200];
    char output_file_dir[100];
    char output_filename_prefix[100];

};

struct cut_info *cut_info_create(FILE *fp);

int cut_add_vad_activity(struct cut_info *cut, int is_active, int is_last);

void cut_info_free(struct cut_info *cut);

void cut_info_print(struct cut_info *cut);

#endif //VAD_DEMO_FILE_CUT_H
/**

    struct cut_info *cut = cut_create_info(NULL);
    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};
    int len = sizeof(acts) / sizeof(int);
    int is_cuts[len];
    printf(" acts length: %d\n", len);

    int j, k;
    for (k = 0; k < len; k++) {
        printf("%d ", acts[k]);
        is_cuts[k] = 0;
    }
    printf("\n");
    for (k = 0; k < len; k++) {

        printf("\n");
        int res = cut_add_vad_activity(cut, acts[k], k == len - 1);
        cut_info_print(cut);
        if (res < 0) {
            is_cuts[-1 * res] = 1;
        }
        for (j = 0; j <= k; j++) {
            if (is_cuts[j]) {
                printf("| ");
            }
            printf("%d ", acts[j]);

        }
    }
    printf("\n");
    for (j = 0; j <= k; j++) {
        if (is_cuts[j]) {
            printf("| ");
        }
        printf("%d ", acts[j]);

    }
    printf("\n");
    printf("PROGRAM FINISH\n");
 **/

================================================
FILE: src/main.c
================================================
#include <stdio.h>
#include <common_audio/vad/include/webrtc_vad.h>
#include <stdlib.h>
#include "simple_vad.h"
#include "period_format.h"
#include "file_cut.h"
// 16000 采样率 10ms,  大小 = 160 * 16bits/8 = 320字节 ,

int run(FILE *fp, simple_vad *vad, struct cut_info *cut);

int add_period_activity(struct periods *per, int is_active, int is_last);

//int add_cut_file_activity(struct cut_info *cut, int is_active, int is_last);

int main() {
    const char filename[] = "pcm/16k_1.pcm"; // 读取的文件
    const char output_filename_prefix[] = "16k_1.pcm"; // 保存的文件名
    const char output_dir[] = "output_pcm"; // 保存的目录
    FILE *fp = fopen(filename, "rb");
    if (fp == NULL) {
        fprintf(stderr, "%s does not exist\n", filename);
        return 3;
    }
    simple_vad *vad = simple_vad_create();
    if (vad == NULL) {
        return 4;
    }
    FILE *fp2 = fopen(filename, "rb");
    struct cut_info *cut = cut_info_create(fp2);
    snprintf(cut->output_filename_prefix, sizeof(cut->output_filename_prefix), "%s",
             output_filename_prefix);
    snprintf(cut->output_file_dir, sizeof(cut->output_file_dir), "%s",
             output_dir);
    int res = run(fp, vad, cut);

    fclose(fp);
    fclose(fp2);
    simple_vad_free(vad);
    cut_info_free(cut);
    printf("PROGRAM FINISH\n");
    return res;
}

int run(FILE *fp, simple_vad *vad, struct cut_info *cut) {

    int16_t data[FRAME_SIZE];
    int res = 0;
    struct periods *per = periods_create();

    while (res == 0) {
        res = read_int16_bytes(fp, data);
        if (res <= 1) {
            int is_last = (res == 1);
            int is_active = process_vad(vad, data);
            add_period_activity(per, is_active, is_last);
            int vad_file_res = cut_add_vad_activity(cut, is_active, is_last);
            if (vad_file_res < 0) {
                printf("file write success %s\n", cut->result_filename);
            }
        } else if (ferror(fp)) {
            printf("read failed  ferror result  : %d\n", ferror(fp));
        }

    }
    periods_free(per);

    if (res != 1) {
        fprintf(stderr, "read file error %d\n", res);
        return res;
    }
    return 0;
}


int add_period_activity(struct periods *per, int is_active, int is_last) {
    static int old_is_active = 0;
    static int count = 0;
    int res_add = period_add_vad_activity(per, is_active, is_last);
    if (res_add != 0) {
        return res_add;
    }
    if (is_active != old_is_active) {
        // printf("%s,%d \n", old_is_active ? "A" : "I", count);
        // I,1  表示之前的1个FRAME是 INACTIVE的;
        // I,1 A,10 表示之前的1个FRAME是 INACTIVE的;第2-10个FRAME是ACTIVE的
        // periods_print(per);
        old_is_active = is_active;
    }
    count += 1;
    if (is_last) {
        periods_print(per);
        printf("total frames %d\n", count);
    }
}

================================================
FILE: src/period_format.c
================================================
//
// Created by fu on 3/6/18.
//

#ifdef __APPLE__
#include <sys/malloc.h>
#else
#include <malloc.h>
#endif

#include "common.h"
#include "period_format.h"

static int add_period_start(struct periods *per) {
    per->size++;
    if (per->size > per->size_allocated) {
        size_t new_size = per->size_allocated * 2 * sizeof(uint64_t);
        per->period_start = realloc(per->period_start, new_size);
        if (per->period_start == NULL) {
            fprintf(stderr, "per->period_start allocated failed %ld", new_size);
            return 1;
        }
        per->period_end = realloc(per->period_end, new_size);
        if (per->period_end == NULL) {
            fprintf(stderr, "per->period_end allocated failed %ld", new_size);
            return 2;
        }
        per->size_allocated *= 2;
    }
    uint64_t start_time = CAL_TIME_BY_FRAME(per->current_frame);
    per->period_start[per->size - 1] = start_time;
    per->is_end_filled = 0;
    return 0;
}

static void add_period_end(struct periods *per) {
    size_t end_time = CAL_TIME_BY_FRAME(per->current_frame);
    per->period_end[per->size - 1] = end_time;
    per->is_end_filled = 1;
}

struct periods *periods_create() {
    struct periods *per = calloc(1, sizeof(struct periods));
    if (per == NULL) {
        fprintf(stderr, "per alloc failed");
        return NULL;
    }
    per->period_start = calloc(PERIODS_SIZE_INITIED, sizeof(uint64_t));
    if (per->period_start == NULL) {
        fprintf(stderr, "per->period_start alloc failed");
    } else {
        per->period_end = calloc(PERIODS_SIZE_INITIED, sizeof(uint64_t));
        if (per->period_end == NULL) {
            fprintf(stderr, "per->period_start alloc failed");
        } else {
            per->size_allocated = PERIODS_SIZE_INITIED;
            return per;
        }
    }
    return NULL;
}


void periods_print(struct periods *per) {
    int size = per->size;
    int is_ended_fill = per->is_end_filled;
    printf("PERIODS SIZE :%d, is_end_filled:%s ", size, is_ended_fill ? "true" : "false");

    int i;
    for (i = 0; i < size; i++) {
        if ((i != size - 1) || is_ended_fill) {
            printf("[%ld, %ld] ", per->period_start[i], per->period_end[i]);
        } else {
            printf("[%ld, N]", per->period_start[size]);
        }
    }

    // printf("size %ld allocated %ld", per->size, per->size_allocated);
    printf("\n");
}

int period_add_vad_activity(struct periods *per, int is_active, int is_last) {
    if (!per->is_pervious_active && is_active) {
        int res = add_period_start(per);
        if (res != 0) {
            return res;
        }
        per->is_pervious_active = is_active;
    } else if (per->is_pervious_active && (!is_active || is_last)) {
        add_period_end(per);
        per->is_pervious_active = is_active;
    }

    per->current_frame++;
    return 0;
}

void periods_free(struct periods *per) {
    free(per->period_start);
    free(per->period_end);
    free(per);
}

================================================
FILE: src/period_format.h
================================================
//
// 收集和打印非静音的声音段
// Created by fu on 3/6/18.
//

#ifndef VAD_DEMO_PERIOD_FORMAT_H
#define VAD_DEMO_PERIOD_FORMAT_H

#include "simple_vad.h"

struct periods {
    int is_pervious_active;
    size_t current_frame;
    uint64_t *period_start;
    uint64_t *period_end;
    int size;
    size_t size_allocated;
    int is_end_filled;

};

struct periods *periods_create();
/**
 * @brief
 * @param per
 * @param is_active 是否是有声音的FRAME
 * @param is_last 是否是最后一个FRAME
 * @return
 */
int period_add_vad_activity(struct periods *per, int is_active, int is_last);

void periods_free(struct periods *per);

void periods_print(struct periods *per);

/*
 * 测试例子
 * struct periods *per=periods_create();
    period_add_vad_activity(per,1,0);
    period_add_vad_activity(per,1,0);
    periods_print(per);
    period_add_vad_activity(per,0,0);
    periods_print(per);
    period_add_vad_activity(per,1,0);
    periods_print(per);
    period_add_vad_activity(per,0,0);
    period_add_vad_activity(per,0,0);
    period_add_vad_activity(per,0,0);
    periods_print(per);
    period_add_vad_activity(per,1,0);
    period_add_vad_activity(per,1,1);
    periods_print(per);
    periods_free(per);
 */


#endif //VAD_DEMO_PERIOD_FORMAT_H


================================================
FILE: src/simple_vad.c
================================================
//
// Created by fu on 3/6/18.
//

#include "simple_vad.h"
#include <string.h>

static int check_end_file(FILE *fp) {
    if (feof(fp)) {
        return 0;
    }
    return ferror(fp);
}

int read_int16_bytes(FILE *fp, int16_t *output) {
    if (feof(fp)) {
        return 1;
    }

    size_t readed = fread(output, sizeof(int16_t), FRAME_SIZE, fp);
    if (readed <= 0) {
        int res = check_end_file(fp);
        return (res == 0) ? 1 : 1000 + res;
    }
    if (readed < FRAME_SIZE) {
        memset(output + readed, 0, (FRAME_SIZE - readed) * sizeof(int16_t));
        // printf("only %ld bits, will refill to %ld\n", readed, length);
    }
    return 0;

}

simple_vad *simple_vad_create() {
    VadInst *inst = WebRtcVad_Create();
    int res = WebRtcVad_Init(inst);
    if (res != 0) {
        fprintf(stderr, "WebRtcVad_Init failed %d", res);
        return NULL;
    }
    res = WebRtcVad_set_mode(inst, WEBRTC_VAD_MODE);
    if (res != 0) {
        fprintf(stderr, "WebRtcVad_set_mode failed %d", res);
        WebRtcVad_Free(inst);
        return NULL;
    }
    return inst;
}

int process_vad(VadInst *inst, int16_t *data) {
    int res = WebRtcVad_Process(inst, SAMPLE_RATE, data, FRAME_SIZE);
    return res;
}

void simple_vad_free(simple_vad *inst) {
    WebRtcVad_Free(inst);
}


================================================
FILE: src/simple_vad.h
================================================
//
// 包装webrtc 的gmm vad算法
//
// Created by fu on 3/6/18.
//

#ifndef VAD_DEMO_FILE_READ_H
#define VAD_DEMO_FILE_READ_H

#include <stdio.h>
#include <stdint.h>
#include <common_audio/vad/include/webrtc_vad.h>
#include "common.h"

// 一个FRAME代表的时长。MULTI=1: 10ms;MULTI=2: 20ms;MULTI=3: 30ms;
// FRAME_SIZE = 160 * MULTI = SAMPLE_RATE  /1000 * MULTI ,


typedef VadInst simple_vad;

/**
 * @brief 读取int16_t的数组
 * @param fp
 * @param output
 * @return 0 正常 1 文件结束 , 1000+ferror : 文件错误
 */
int read_int16_bytes(FILE *fp, int16_t *output);

/**
 * @brief
 * @return NULL 创建失败
 */
simple_vad *simple_vad_create();

/**
 * @brief
 * @param inst
 * @param data 例如read_int16_bytes读取的数据
 * @return
 */
int process_vad(VadInst *inst, int16_t *data);

/**
 * @brief
 * @param inst
 */
void simple_vad_free(simple_vad *inst);

#endif //VAD_DEMO_FILE_READ_H


================================================
FILE: thirdparty/webrtc/BUILD.gn
================================================
# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS.  All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.

# This is the root build file for GN. GN will start processing by loading this
# file, and recursively load all dependencies until all dependencies are either
# resolved or known not to exist (which will cause the build to fail). So if
# you add a new build file, there must be some path of dependencies from this
# file to your new one or GN won't know about it.

import("//build/config/linux/pkg_config.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("webrtc.gni")
if (!build_with_mozilla) {
  import("//third_party/protobuf/proto_library.gni")
}
if (is_android) {
  import("//build/config/android/config.gni")
  import("//build/config/android/rules.gni")
}

if (!build_with_chromium) {
  # This target should (transitively) cause everything to be built; if you run
  # 'ninja default' and then 'ninja all', the second build should do no work.
  group("default") {
    testonly = true
    deps = [
      ":webrtc",
    ]
    if (rtc_build_examples) {
      deps += [ "examples" ]
    }
    if (rtc_build_tools) {
      deps += [ "rtc_tools" ]
    }
    if (rtc_include_tests) {
      deps += [
        ":rtc_unittests",
        ":video_engine_tests",
        ":webrtc_nonparallel_tests",
        ":webrtc_perf_tests",
        "common_audio:common_audio_unittests",
        "common_video:common_video_unittests",
        "media:rtc_media_unittests",
        "modules:modules_tests",
        "modules:modules_unittests",
        "modules/audio_coding:audio_coding_tests",
        "modules/audio_processing:audio_processing_tests",
        "modules/remote_bitrate_estimator:bwe_simulations_tests",
        "modules/rtp_rtcp:test_packet_masks_metrics",
        "modules/video_capture:video_capture_internal_impl",
        "ortc:ortc_unittests",
        "pc:peerconnection_unittests",
        "pc:rtc_pc_unittests",
        "rtc_base:rtc_base_tests_utils",
        "stats:rtc_stats_unittests",
        "system_wrappers:system_wrappers_unittests",
        "test",
        "video:screenshare_loopback",
        "video:sv_loopback",
        "video:video_loopback",
      ]
      if (is_android) {
        deps += [
          ":android_junit_tests",
          "sdk/android:libjingle_peerconnection_android_unittest",
        ]
      } else {
        deps += [ "modules/video_capture:video_capture_tests" ]
      }
      if (rtc_enable_protobuf) {
        deps += [
          "audio:low_bandwidth_audio_test",
          "logging:rtc_event_log2rtp_dump",
        ]
      }
    }
  }
}

# Contains the defines and includes in common.gypi that are duplicated both as
# target_defaults and direct_dependent_settings.
config("common_inherited_config") {
  defines = []
  cflags = []
  ldflags = []
  if (build_with_mozilla) {
    defines += [ "WEBRTC_MOZILLA_BUILD" ]
  }

  # Some tests need to declare their own trace event handlers. If this define is
  # not set, the first time TRACE_EVENT_* is called it will store the return
  # value for the current_frame handler in an static variable, so that subsequent
  # changes to the handler for that TRACE_EVENT_* will be ignored.
  # So when tests are included, we set this define, making it possible to use
  # different event handlers in different tests.
  if (rtc_include_tests) {
    defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1" ]
  } else {
    defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0" ]
  }
  if (build_with_chromium) {
    defines += [
      # TODO(kjellander): Cleanup unused ones and move defines closer to
      # the source when webrtc:4256 is completed.
      "GTEST_RELATIVE_PATH",
      "WEBRTC_CHROMIUM_BUILD",
    ]
    include_dirs = [
      # The overrides must be included first as that is the mechanism for
      # selecting the override headers in Chromium.
      "../webrtc_overrides",

      # Allow includes to be prefixed with webrtc/ in case it is not an
      # immediate subdirectory of the top-level.
      ".",
    ]
  }
  if (is_posix) {
    defines += [ "WEBRTC_POSIX" ]
  }
  if (is_ios) {
    defines += [
      "WEBRTC_MAC",
      "WEBRTC_IOS",
    ]
  }
  if (is_linux) {
    defines += [ "WEBRTC_LINUX" ]
  }
  if (is_mac) {
    defines += [ "WEBRTC_MAC" ]
  }
  if (is_fuchsia) {
    defines += [ "WEBRTC_FUCHSIA" ]
  }
  if (is_win) {
    defines += [
      "WEBRTC_WIN",
      "_CRT_SECURE_NO_WARNINGS",  # Suppress warnings about _vsnprinf
    ]
  }
  if (is_android) {
    defines += [
      "WEBRTC_LINUX",
      "WEBRTC_ANDROID",
    ]

    if (build_with_mozilla) {
      defines += [ "WEBRTC_ANDROID_OPENSLES" ]
    }
  }
  if (is_chromeos) {
    defines += [ "CHROMEOS" ]
  }

  if (rtc_sanitize_coverage != "") {
    assert(is_clang, "sanitizer coverage requires clang")
    cflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
    ldflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
  }

  if (is_ubsan) {
    cflags += [ "-fsanitize=float-cast-overflow" ]
  }
}

config("common_config") {
  cflags = []
  cflags_cc = []
  defines = []

  if (rtc_enable_protobuf) {
    defines += [ "WEBRTC_ENABLE_PROTOBUF=1" ]
  } else {
    defines += [ "WEBRTC_ENABLE_PROTOBUF=0" ]
  }

  if (rtc_include_internal_audio_device) {
    defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
  }

  if (!rtc_libvpx_build_vp9) {
    defines += [ "RTC_DISABLE_VP9" ]
  }

  if (rtc_enable_sctp) {
    defines += [ "HAVE_SCTP" ]
  }

  if (rtc_enable_external_auth) {
    defines += [ "ENABLE_EXTERNAL_AUTH" ]
  }

  if (rtc_use_builtin_sw_codecs) {
    defines += [ "USE_BUILTIN_SW_CODECS" ]
  }

  if (build_with_chromium) {
    defines += [
      # NOTICE: Since common_inherited_config is used in public_configs for our
      # targets, there's no point including the defines in that config here.
      # TODO(kjellander): Cleanup unused ones and move defines closer to the
      # source when webrtc:4256 is completed.
      "HAVE_WEBRTC_VIDEO",
      "HAVE_WEBRTC_VOICE",
      "LOGGING_INSIDE_WEBRTC",
    ]
  } else {
    if (is_posix) {
      # Enable more warnings: -Wextra is currently disabled in Chromium.
      cflags = [
        "-Wextra",

        # Repeat some flags that get overridden by -Wextra.
        "-Wno-unused-parameter",
        "-Wno-missing-field-initializers",
        "-Wno-strict-overflow",
      ]
      cflags_cc = [
        "-Wnon-virtual-dtor",

        # This is enabled for clang; enable for gcc as well.
        "-Woverloaded-virtual",
      ]
    }

    if (is_clang) {
      cflags += [
        "-Wc++11-narrowing",
        "-Wimplicit-fallthrough",
        "-Wthread-safety",
        "-Winconsistent-missing-override",
        "-Wundef",
      ]

      # use_xcode_clang only refers to the iOS toolchain, host binaries use
      # chromium's clang always.
      if (!is_nacl &&
          (!use_xcode_clang || current_toolchain == host_toolchain)) {
        # Flags NaCl (Clang 3.7) and Xcode 7.3 (Clang clang-703.0.31) do not
        # recognize.
        cflags += [ "-Wunused-lambda-capture" ]
      }
    }
  }

  if (current_cpu == "arm64") {
    defines += [ "WEBRTC_ARCH_ARM64" ]
    defines += [ "WEBRTC_HAS_NEON" ]
  }

  if (current_cpu == "arm") {
    defines += [ "WEBRTC_ARCH_ARM" ]
    if (arm_version >= 7) {
      defines += [ "WEBRTC_ARCH_ARM_V7" ]
      if (arm_use_neon) {
        defines += [ "WEBRTC_HAS_NEON" ]
      }
    }
  }

  if (current_cpu == "mipsel") {
    defines += [ "MIPS32_LE" ]
    if (mips_float_abi == "hard") {
      defines += [ "MIPS_FPU_LE" ]
    }
    if (mips_arch_variant == "r2") {
      defines += [ "MIPS32_R2_LE" ]
    }
    if (mips_dsp_rev == 1) {
      defines += [ "MIPS_DSP_R1_LE" ]
    } else if (mips_dsp_rev == 2) {
      defines += [
        "MIPS_DSP_R1_LE",
        "MIPS_DSP_R2_LE",
      ]
    }
  }

  if (is_android && !is_clang) {
    # The Android NDK doesn"t provide optimized versions of these
    # functions. Ensure they are disabled for all compilers.
    cflags += [
      "-fno-builtin-cos",
      "-fno-builtin-sin",
      "-fno-builtin-cosf",
      "-fno-builtin-sinf",
    ]
  }

  if (use_libfuzzer || use_drfuzz || use_afl) {
    # Used in Chromium's overrides to disable logging
    defines += [ "WEBRTC_UNSAFE_FUZZER_MODE" ]
  }
}

config("common_objc") {
  libs = [ "Foundation.framework" ]
}

if (!build_with_chromium) {
  # Target to build all the WebRTC production code.
  rtc_static_library("webrtc") {
    # Only the root target should depend on this.
    visibility = [ "//:default" ]

    sources = []
    complete_static_lib = true
    defines = []

    deps = [
      ":webrtc_common",
      "api:transport_api",
      "audio",
      "call",
      "common_audio",
      "common_video",
      "media",
      "modules",
      "modules/video_capture:video_capture_internal_impl",
      "ortc",
      "rtc_base",
      "sdk",
      "system_wrappers:system_wrappers_default",
      "video",
    ]

    if (build_with_mozilla) {
      deps += [
        "api:video_frame_api",
        "system_wrappers:field_trial_default",
        "system_wrappers:metrics_default",
      ]
    } else {
      deps += [
        "api",
        "logging",
        "p2p",
        "pc",
        "stats",
      ]
    }

    if (rtc_enable_protobuf) {
      defines += [ "ENABLE_RTC_EVENT_LOG" ]
      deps += [ "logging:rtc_event_log_proto" ]
    }
  }
}

rtc_source_set("typedefs") {
  sources = [
    "typedefs.h",
  ]
}

rtc_static_library("webrtc_common") {
  sources = [
    "common_types.cc",
    "common_types.h",
  ]
  deps = [
    ":typedefs",
    "api:array_view",
    "api:optional",
    "rtc_base:checks",
    "rtc_base:deprecation",
    "rtc_base:stringutils",
  ]

  if (!build_with_chromium && is_clang) {
    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
    suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
  }
}

if (use_libfuzzer || use_drfuzz || use_afl) {
  # This target is only here for gn to discover fuzzer build targets under
  # webrtc/test/fuzzers/.
  group("webrtc_fuzzers_dummy") {
    testonly = true
    deps = [
      "test/fuzzers:webrtc_fuzzer_main",
    ]
  }
}

if (rtc_include_tests) {
  config("rtc_unittests_config") {
    # GN orders flags on a target before flags from configs. The default config
    # adds -Wall, and this flag have to be after -Wall -- so they need to
    # come from a config and can"t be on the target directly.
    if (is_clang) {
      cflags = [
        "-Wno-sign-compare",
        "-Wno-unused-const-variable",
      ]
    }
  }

  rtc_test("rtc_unittests") {
    testonly = true

    deps = [
      ":webrtc_common",
      "api:rtc_api_unittests",
      "api/audio_codecs/test:audio_codecs_api_unittests",
      "p2p:libstunprober_unittests",
      "p2p:rtc_p2p_unittests",
      "rtc_base:rtc_base_approved_unittests",
      "rtc_base:rtc_base_tests_main",
      "rtc_base:rtc_base_tests_utils",
      "rtc_base:rtc_base_unittests",
      "rtc_base:rtc_numerics_unittests",
      "rtc_base:rtc_task_queue_unittests",
      "rtc_base:sequenced_task_checker_unittests",
      "rtc_base:weak_ptr_unittests",
      "system_wrappers:metrics_default",
      "system_wrappers:runtime_enabled_features_default",
    ]

    if (rtc_enable_protobuf) {
      deps += [ "logging:rtc_event_log_tests" ]
    }

    if (is_android) {
      # Do not use Chromium's launcher. native_unittests defines its own JNI_OnLoad.
      use_default_launcher = false

      deps += [
        "sdk/android:native_unittests",
        "sdk/android:native_unittests_java",
        "//testing/android/native_test:native_test_support",
      ]
      shard_timeout = 900
    }

    if (is_ios || is_mac) {
      deps += [ "sdk:sdk_unittests_objc" ]
    }
  }

  # TODO(pbos): Rename test suite, this is no longer "just" for video targets.
  video_engine_tests_resources = [
    "resources/foreman_cif_short.yuv",
    "resources/voice_engine/audio_long16.pcm",
  ]

  if (is_ios) {
    bundle_data("video_engine_tests_bundle_data") {
      testonly = true
      sources = video_engine_tests_resources
      outputs = [
        "{{bundle_resources_dir}}/{{source_file_part}}",
      ]
    }
  }

  rtc_test("video_engine_tests") {
    testonly = true
    deps = [
      "audio:audio_tests",

      # TODO(eladalon): call_tests aren't actually video-specific, so we
      # should move them to a more appropriate test suite.
      "call:call_tests",
      "modules/video_capture",
      "rtc_base:rtc_base_tests_utils",
      "test:test_common",
      "test:test_main",
      "test:video_test_common",
      "video:video_tests",
    ]
    data = video_engine_tests_resources
    if (!build_with_chromium && is_clang) {
      # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
      suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
    }
    if (is_android) {
      deps += [ "//testing/android/native_test:native_test_native_code" ]
      shard_timeout = 900
    }
    if (is_ios) {
      deps += [ ":video_engine_tests_bundle_data" ]
    }
  }

  webrtc_perf_tests_resources = [
    "resources/audio_coding/speech_mono_16kHz.pcm",
    "resources/audio_coding/speech_mono_32_48kHz.pcm",
    "resources/audio_coding/testfile32kHz.pcm",
    "resources/ConferenceMotion_1280_720_50.yuv",
    "resources/difficult_photo_1850_1110.yuv",
    "resources/foreman_cif.yuv",
    "resources/google-wifi-3mbps.rx",
    "resources/paris_qcif.yuv",
    "resources/photo_1850_1110.yuv",
    "resources/presentation_1850_1110.yuv",
    "resources/verizon4g-downlink.rx",
    "resources/voice_engine/audio_long16.pcm",
    "resources/web_screenshot_1850_1110.yuv",
  ]

  if (is_ios) {
    bundle_data("webrtc_perf_tests_bundle_data") {
      testonly = true
      sources = webrtc_perf_tests_resources
      outputs = [
        "{{bundle_resources_dir}}/{{source_file_part}}",
      ]
    }
  }

  rtc_test("webrtc_perf_tests") {
    testonly = true
    configs += [ ":rtc_unittests_config" ]

    deps = [
      "audio:audio_perf_tests",
      "call:call_perf_tests",
      "modules/audio_coding:audio_coding_perf_tests",
      "modules/audio_processing:audio_processing_perf_tests",
      "modules/remote_bitrate_estimator:remote_bitrate_estimator_perf_tests",
      "test:test_main",
      "video:video_full_stack_tests",
    ]

    data = webrtc_perf_tests_resources
    if (is_android) {
      deps += [ "//testing/android/native_test:native_test_native_code" ]
      shard_timeout = 2700
    }
    if (is_ios) {
      deps += [ ":webrtc_perf_tests_bundle_data" ]
    }
  }

  rtc_test("webrtc_nonparallel_tests") {
    testonly = true
    deps = [
      "rtc_base:rtc_base_nonparallel_tests",
    ]
    if (is_android) {
      deps += [ "//testing/android/native_test:native_test_support" ]
      shard_timeout = 900
    }
  }

  if (is_android) {
    junit_binary("android_junit_tests") {
      java_files = [
        "examples/androidjunit/src/org/appspot/apprtc/BluetoothManagerTest.java",
        "examples/androidjunit/src/org/appspot/apprtc/DirectRTCClientTest.java",
        "examples/androidjunit/src/org/appspot/apprtc/TCPChannelClientTest.java",
        "sdk/android/tests/src/org/webrtc/CameraEnumerationTest.java",
      ]

      deps = [
        "examples:AppRTCMobile_javalib",
        "sdk/android:libjingle_peerconnection_java",
        "//base:base_java_test_support",
      ]
    }
  }
}


================================================
FILE: thirdparty/webrtc/common_audio/rename.sh
================================================
#!/bin/sh 
rename 's/mips\.c$/mips\.c\.mips/' signal_processing/*.c
rename 's/neon\.c$/neon\.c\.neon/' signal_processing/*.c


================================================
FILE: thirdparty/webrtc/common_audio/rename.sh~
================================================
#!/bin/sh 
rename 's/mips\.c$/mips\.c\.mips/' signal_processing/*.c
rename 's/neon\.c$/neon\.c\.neon/' signal_processing/*.c


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/cross_correlation.c
================================================
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

/* C version of WebRtcSpl_CrossCorrelation() for generic platforms. */
void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
                                 const int16_t* seq1,
                                 const int16_t* seq2,
                                 size_t dim_seq,
                                 size_t dim_cross_correlation,
                                 int right_shifts,
                                 int step_seq2) {
  size_t i = 0, j = 0;

  for (i = 0; i < dim_cross_correlation; i++) {
    int32_t corr = 0;
    for (j = 0; j < dim_seq; j++)
      corr += (seq1[j] * seq2[j]) >> right_shifts;
    seq2 += step_seq2;
    *cross_correlation++ = corr;
  }
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/cross_correlation_mips.c.mips
================================================
/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
                                     const int16_t* seq1,
                                     const int16_t* seq2,
                                     size_t dim_seq,
                                     size_t dim_cross_correlation,
                                     int right_shifts,
                                     int step_seq2) {

  int32_t t0 = 0, t1 = 0, t2 = 0, t3 = 0, sum = 0;
  int16_t *pseq2 = NULL;
  int16_t *pseq1 = NULL;
  int16_t *pseq1_0 = (int16_t*)&seq1[0];
  int16_t *pseq2_0 = (int16_t*)&seq2[0];
  int k = 0;

  __asm __volatile (
    ".set        push                                           \n\t"
    ".set        noreorder                                      \n\t"
    "sll         %[step_seq2], %[step_seq2],   1                \n\t"
    "andi        %[t0],        %[dim_seq],     1                \n\t"
    "bgtz        %[t0],        3f                               \n\t"
    " nop                                                       \n\t"
   "1:                                                          \n\t"
    "move        %[pseq1],     %[pseq1_0]                       \n\t"
    "move        %[pseq2],     %[pseq2_0]                       \n\t"
    "sra         %[k],         %[dim_seq],     1                \n\t"
    "addiu       %[dim_cc],    %[dim_cc],      -1               \n\t"
    "xor         %[sum],       %[sum],         %[sum]           \n\t"
   "2:                                                          \n\t"
    "lh          %[t0],        0(%[pseq1])                      \n\t"
    "lh          %[t1],        0(%[pseq2])                      \n\t"
    "lh          %[t2],        2(%[pseq1])                      \n\t"
    "lh          %[t3],        2(%[pseq2])                      \n\t"
    "mul         %[t0],        %[t0],          %[t1]            \n\t"
    "addiu       %[k],         %[k],           -1               \n\t"
    "mul         %[t2],        %[t2],          %[t3]            \n\t"
    "addiu       %[pseq1],     %[pseq1],       4                \n\t"
    "addiu       %[pseq2],     %[pseq2],       4                \n\t"
    "srav        %[t0],        %[t0],          %[right_shifts]  \n\t"
    "addu        %[sum],       %[sum],         %[t0]            \n\t"
    "srav        %[t2],        %[t2],          %[right_shifts]  \n\t"
    "bgtz        %[k],         2b                               \n\t"
    " addu       %[sum],       %[sum],         %[t2]            \n\t"
    "addu        %[pseq2_0],   %[pseq2_0],     %[step_seq2]     \n\t"
    "sw          %[sum],       0(%[cc])                         \n\t"
    "bgtz        %[dim_cc],    1b                               \n\t"
    " addiu      %[cc],        %[cc],          4                \n\t"
    "b           6f                                             \n\t"
    " nop                                                       \n\t"
   "3:                                                          \n\t"
    "move        %[pseq1],     %[pseq1_0]                       \n\t"
    "move        %[pseq2],     %[pseq2_0]                       \n\t"
    "sra         %[k],         %[dim_seq],     1                \n\t"
    "addiu       %[dim_cc],    %[dim_cc],      -1               \n\t"
    "beqz        %[k],         5f                               \n\t"
    " xor        %[sum],       %[sum],         %[sum]           \n\t"
   "4:                                                          \n\t"
    "lh          %[t0],        0(%[pseq1])                      \n\t"
    "lh          %[t1],        0(%[pseq2])                      \n\t"
    "lh          %[t2],        2(%[pseq1])                      \n\t"
    "lh          %[t3],        2(%[pseq2])                      \n\t"
    "mul         %[t0],        %[t0],          %[t1]            \n\t"
    "addiu       %[k],         %[k],           -1               \n\t"
    "mul         %[t2],        %[t2],          %[t3]            \n\t"
    "addiu       %[pseq1],     %[pseq1],       4                \n\t"
    "addiu       %[pseq2],     %[pseq2],       4                \n\t"
    "srav        %[t0],        %[t0],          %[right_shifts]  \n\t"
    "addu        %[sum],       %[sum],         %[t0]            \n\t"
    "srav        %[t2],        %[t2],          %[right_shifts]  \n\t"
    "bgtz        %[k],         4b                               \n\t"
    " addu       %[sum],       %[sum],         %[t2]            \n\t"
   "5:                                                          \n\t"
    "lh          %[t0],        0(%[pseq1])                      \n\t"
    "lh          %[t1],        0(%[pseq2])                      \n\t"
    "mul         %[t0],        %[t0],          %[t1]            \n\t"
    "srav        %[t0],        %[t0],          %[right_shifts]  \n\t"
    "addu        %[sum],       %[sum],         %[t0]            \n\t"
    "addu        %[pseq2_0],   %[pseq2_0],     %[step_seq2]     \n\t"
    "sw          %[sum],       0(%[cc])                         \n\t"
    "bgtz        %[dim_cc],    3b                               \n\t"
    " addiu      %[cc],        %[cc],          4                \n\t"
   "6:                                                          \n\t"
    ".set        pop                                            \n\t"
    : [step_seq2] "+r" (step_seq2), [t0] "=&r" (t0), [t1] "=&r" (t1),
      [t2] "=&r" (t2), [t3] "=&r" (t3), [pseq1] "=&r" (pseq1),
      [pseq2] "=&r" (pseq2), [pseq1_0] "+r" (pseq1_0), [pseq2_0] "+r" (pseq2_0),
      [k] "=&r" (k), [dim_cc] "+r" (dim_cross_correlation), [sum] "=&r" (sum),
      [cc] "+r" (cross_correlation)
    : [dim_seq] "r" (dim_seq), [right_shifts] "r" (right_shifts)
    : "hi", "lo", "memory"
  );
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/cross_correlation_neon.c.neon
================================================
/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

#include <arm_neon.h>

static inline void DotProductWithScaleNeon(int32_t* cross_correlation,
                                           const int16_t* vector1,
                                           const int16_t* vector2,
                                           size_t length,
                                           int scaling) {
  size_t i = 0;
  size_t len1 = length >> 3;
  size_t len2 = length & 7;
  int64x2_t sum0 = vdupq_n_s64(0);
  int64x2_t sum1 = vdupq_n_s64(0);

  for (i = len1; i > 0; i -= 1) {
    int16x8_t seq1_16x8 = vld1q_s16(vector1);
    int16x8_t seq2_16x8 = vld1q_s16(vector2);
#if defined(WEBRTC_ARCH_ARM64)
    int32x4_t tmp0 = vmull_s16(vget_low_s16(seq1_16x8),
                               vget_low_s16(seq2_16x8));
    int32x4_t tmp1 = vmull_high_s16(seq1_16x8, seq2_16x8);
#else
    int32x4_t tmp0 = vmull_s16(vget_low_s16(seq1_16x8),
                               vget_low_s16(seq2_16x8));
    int32x4_t tmp1 = vmull_s16(vget_high_s16(seq1_16x8),
                               vget_high_s16(seq2_16x8));
#endif
    sum0 = vpadalq_s32(sum0, tmp0);
    sum1 = vpadalq_s32(sum1, tmp1);
    vector1 += 8;
    vector2 += 8;
  }

  // Calculate the rest of the samples.
  int64_t sum_res = 0;
  for (i = len2; i > 0; i -= 1) {
    sum_res += WEBRTC_SPL_MUL_16_16(*vector1, *vector2);
    vector1++;
    vector2++;
  }

  sum0 = vaddq_s64(sum0, sum1);
#if defined(WEBRTC_ARCH_ARM64)
  int64_t sum2 = vaddvq_s64(sum0);
  *cross_correlation = (int32_t)((sum2 + sum_res) >> scaling);
#else
  int64x1_t shift = vdup_n_s64(-scaling);
  int64x1_t sum2 = vadd_s64(vget_low_s64(sum0), vget_high_s64(sum0));
  sum2 = vadd_s64(sum2, vdup_n_s64(sum_res));
  sum2 = vshl_s64(sum2, shift);
  vst1_lane_s32(cross_correlation, vreinterpret_s32_s64(sum2), 0);
#endif
}

/* NEON version of WebRtcSpl_CrossCorrelation() for ARM32/64 platforms. */
void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
                                    const int16_t* seq1,
                                    const int16_t* seq2,
                                    size_t dim_seq,
                                    size_t dim_cross_correlation,
                                    int right_shifts,
                                    int step_seq2) {
  size_t i = 0;

  for (i = 0; i < dim_cross_correlation; i++) {
    const int16_t* seq1_ptr = seq1;
    const int16_t* seq2_ptr = seq2 + (step_seq2 * i);

    DotProductWithScaleNeon(cross_correlation,
                            seq1_ptr,
                            seq2_ptr,
                            dim_seq,
                            right_shifts);
    cross_correlation++;
  }
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/division_operations.c
================================================
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/*
 * This file contains implementations of the divisions
 * WebRtcSpl_DivU32U16()
 * WebRtcSpl_DivW32W16()
 * WebRtcSpl_DivW32W16ResW16()
 * WebRtcSpl_DivResultInQ31()
 * WebRtcSpl_DivW32HiLow()
 *
 * The description header can be found in signal_processing_library.h
 *
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"
#include "rtc_base/sanitizer.h"

uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den)
{
    // Guard against division with 0
    if (den != 0)
    {
        return (uint32_t)(num / den);
    } else
    {
        return (uint32_t)0xFFFFFFFF;
    }
}

int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den)
{
    // Guard against division with 0
    if (den != 0)
    {
        return (int32_t)(num / den);
    } else
    {
        return (int32_t)0x7FFFFFFF;
    }
}

int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den)
{
    // Guard against division with 0
    if (den != 0)
    {
        return (int16_t)(num / den);
    } else
    {
        return (int16_t)0x7FFF;
    }
}

int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den)
{
    int32_t L_num = num;
    int32_t L_den = den;
    int32_t div = 0;
    int k = 31;
    int change_sign = 0;

    if (num == 0)
        return 0;

    if (num < 0)
    {
        change_sign++;
        L_num = -num;
    }
    if (den < 0)
    {
        change_sign++;
        L_den = -den;
    }
    while (k--)
    {
        div <<= 1;
        L_num <<= 1;
        if (L_num >= L_den)
        {
            L_num -= L_den;
            div++;
        }
    }
    if (change_sign == 1)
    {
        div = -div;
    }
    return div;
}

int32_t RTC_NO_SANITIZE("signed-integer-overflow")  // bugs.webrtc.org/5486
WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
{
    int16_t approx, tmp_hi, tmp_low, num_hi, num_low;
    int32_t tmpW32;

    approx = (int16_t)WebRtcSpl_DivW32W16((int32_t)0x1FFFFFFF, den_hi);
    // result in Q14 (Note: 3FFFFFFF = 0.5 in Q30)

    // tmpW32 = 1/den = approx * (2.0 - den * approx) (in Q30)
    tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1);
    // tmpW32 = den * approx

    tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den*approx))
    // UBSan: 2147483647 - -2 cannot be represented in type 'int'

    // Store tmpW32 in hi and low format
    tmp_hi = (int16_t)(tmpW32 >> 16);
    tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1);

    // tmpW32 = 1/den in Q29
    tmpW32 = (tmp_hi * approx + (tmp_low * approx >> 15)) << 1;

    // 1/den in hi and low format
    tmp_hi = (int16_t)(tmpW32 >> 16);
    tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1);

    // Store num in hi and low format
    num_hi = (int16_t)(num >> 16);
    num_low = (int16_t)((num - ((int32_t)num_hi << 16)) >> 1);

    // num * (1/den) by 32 bit multiplication (result in Q28)

    tmpW32 = num_hi * tmp_hi + (num_hi * tmp_low >> 15) +
        (num_low * tmp_hi >> 15);

    // Put result in Q31 (convert from Q28)
    tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3);

    return tmpW32;
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/downsample_fast.c
================================================
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

#include "rtc_base/checks.h"
#include "rtc_base/sanitizer.h"

// TODO(Bjornv): Change the function parameter order to WebRTC code style.
// C version of WebRtcSpl_DownsampleFast() for generic platforms.
int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
                              size_t data_in_length,
                              int16_t* data_out,
                              size_t data_out_length,
                              const int16_t* __restrict coefficients,
                              size_t coefficients_length,
                              int factor,
                              size_t delay) {
  int16_t* const original_data_out = data_out;
  size_t i = 0;
  size_t j = 0;
  int32_t out_s32 = 0;
  size_t endpos = delay + factor * (data_out_length - 1) + 1;

  // Return error if any of the running conditions doesn't meet.
  if (data_out_length == 0 || coefficients_length == 0
                           || data_in_length < endpos) {
    return -1;
  }

  rtc_MsanCheckInitialized(coefficients, sizeof(coefficients[0]),
                           coefficients_length);

  for (i = delay; i < endpos; i += factor) {
    out_s32 = 2048;  // Round value, 0.5 in Q12.

    for (j = 0; j < coefficients_length; j++) {
      rtc_MsanCheckInitialized(&data_in[i - j], sizeof(data_in[0]), 1);
      out_s32 += coefficients[j] * data_in[i - j];  // Q12.
    }

    out_s32 >>= 12;  // Q0.

    // Saturate and store the output.
    *data_out++ = WebRtcSpl_SatW32ToW16(out_s32);
  }

  RTC_DCHECK_EQ(original_data_out + data_out_length, data_out);
  rtc_MsanCheckInitialized(original_data_out, sizeof(original_data_out[0]),
                           data_out_length);

  return 0;
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/downsample_fast_mips.c.mips
================================================
/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

// Version of WebRtcSpl_DownsampleFast() for MIPS platforms.
int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
                                  size_t data_in_length,
                                  int16_t* data_out,
                                  size_t data_out_length,
                                  const int16_t* __restrict coefficients,
                                  size_t coefficients_length,
                                  int factor,
                                  size_t delay) {
  int i;
  int j;
  int k;
  int32_t out_s32 = 0;
  size_t endpos = delay + factor * (data_out_length - 1) + 1;

  int32_t  tmp1, tmp2, tmp3, tmp4, factor_2;
  int16_t* p_coefficients;
  int16_t* p_data_in;
  int16_t* p_data_in_0 = (int16_t*)&data_in[delay];
  int16_t* p_coefficients_0 = (int16_t*)&coefficients[0];
#if !defined(MIPS_DSP_R1_LE)
  int32_t max_16 = 0x7FFF;
  int32_t min_16 = 0xFFFF8000;
#endif  // #if !defined(MIPS_DSP_R1_LE)

  // Return error if any of the running conditions doesn't meet.
  if (data_out_length == 0 || coefficients_length == 0
                           || data_in_length < endpos) {
    return -1;
  }
#if defined(MIPS_DSP_R2_LE)
  __asm __volatile (
    ".set        push                                                \n\t"
    ".set        noreorder                                           \n\t"
    "subu        %[i],            %[endpos],       %[delay]          \n\t"
    "sll         %[factor_2],     %[factor],       1                 \n\t"
   "1:                                                               \n\t"
    "move        %[p_data_in],    %[p_data_in_0]                     \n\t"
    "mult        $zero,           $zero                              \n\t"
    "move        %[p_coefs],      %[p_coefs_0]                       \n\t"
    "sra         %[j],            %[coef_length],  2                 \n\t"
    "beq         %[j],            $zero,           3f                \n\t"
    " andi       %[k],            %[coef_length],  3                 \n\t"
   "2:                                                               \n\t"
    "lwl         %[tmp1],         1(%[p_data_in])                    \n\t"
    "lwl         %[tmp2],         3(%[p_coefs])                      \n\t"
    "lwl         %[tmp3],         -3(%[p_data_in])                   \n\t"
    "lwl         %[tmp4],         7(%[p_coefs])                      \n\t"
    "lwr         %[tmp1],         -2(%[p_data_in])                   \n\t"
    "lwr         %[tmp2],         0(%[p_coefs])                      \n\t"
    "lwr         %[tmp3],         -6(%[p_data_in])                   \n\t"
    "lwr         %[tmp4],         4(%[p_coefs])                      \n\t"
    "packrl.ph   %[tmp1],         %[tmp1],         %[tmp1]           \n\t"
    "packrl.ph   %[tmp3],         %[tmp3],         %[tmp3]           \n\t"
    "dpa.w.ph    $ac0,            %[tmp1],         %[tmp2]           \n\t"
    "dpa.w.ph    $ac0,            %[tmp3],         %[tmp4]           \n\t"
    "addiu       %[j],            %[j],            -1                \n\t"
    "addiu       %[p_data_in],    %[p_data_in],    -8                \n\t"
    "bgtz        %[j],            2b                                 \n\t"
    " addiu      %[p_coefs],      %[p_coefs],      8                 \n\t"
   "3:                                                               \n\t"
    "beq         %[k],            $zero,           5f                \n\t"
    " nop                                                            \n\t"
   "4:                                                               \n\t"
    "lhu         %[tmp1],         0(%[p_data_in])                    \n\t"
    "lhu         %[tmp2],         0(%[p_coefs])                      \n\t"
    "addiu       %[p_data_in],    %[p_data_in],    -2                \n\t"
    "addiu       %[k],            %[k],            -1                \n\t"
    "dpa.w.ph    $ac0,            %[tmp1],         %[tmp2]           \n\t"
    "bgtz        %[k],            4b                                 \n\t"
    " addiu      %[p_coefs],      %[p_coefs],      2                 \n\t"
   "5:                                                               \n\t"
    "extr_r.w    %[out_s32],      $ac0,            12                \n\t"
    "addu        %[p_data_in_0],  %[p_data_in_0],  %[factor_2]       \n\t"
    "subu        %[i],            %[i],            %[factor]         \n\t"
    "shll_s.w    %[out_s32],      %[out_s32],      16                \n\t"
    "sra         %[out_s32],      %[out_s32],      16                \n\t"
    "sh          %[out_s32],      0(%[data_out])                     \n\t"
    "bgtz        %[i],            1b                                 \n\t"
    " addiu      %[data_out],     %[data_out],     2                 \n\t"
    ".set        pop                                                 \n\t"
    : [tmp1] "=&r" (tmp1), [tmp2] "=&r" (tmp2), [tmp3] "=&r" (tmp3),
      [tmp4] "=&r" (tmp4), [p_data_in] "=&r" (p_data_in),
      [p_data_in_0] "+r" (p_data_in_0), [p_coefs] "=&r" (p_coefficients),
      [j] "=&r" (j), [out_s32] "=&r" (out_s32), [factor_2] "=&r" (factor_2),
      [i] "=&r" (i), [k] "=&r" (k)
    : [coef_length] "r" (coefficients_length), [data_out] "r" (data_out),
      [p_coefs_0] "r" (p_coefficients_0), [endpos] "r" (endpos),
      [delay] "r" (delay), [factor] "r" (factor)
    : "memory", "hi", "lo"
 );
#else  // #if defined(MIPS_DSP_R2_LE)
  __asm __volatile (
    ".set        push                                                \n\t"
    ".set        noreorder                                           \n\t"
    "sll         %[factor_2],     %[factor],       1                 \n\t"
    "subu        %[i],            %[endpos],       %[delay]          \n\t"
   "1:                                                               \n\t"
    "move        %[p_data_in],    %[p_data_in_0]                     \n\t"
    "addiu       %[out_s32],      $zero,           2048              \n\t"
    "move        %[p_coefs],      %[p_coefs_0]                       \n\t"
    "sra         %[j],            %[coef_length],  1                 \n\t"
    "beq         %[j],            $zero,           3f                \n\t"
    " andi       %[k],            %[coef_length],  1                 \n\t"
   "2:                                                               \n\t"
    "lh          %[tmp1],         0(%[p_data_in])                    \n\t"
    "lh          %[tmp2],         0(%[p_coefs])                      \n\t"
    "lh          %[tmp3],         -2(%[p_data_in])                   \n\t"
    "lh          %[tmp4],         2(%[p_coefs])                      \n\t"
    "mul         %[tmp1],         %[tmp1],         %[tmp2]           \n\t"
    "addiu       %[p_coefs],      %[p_coefs],      4                 \n\t"
    "mul         %[tmp3],         %[tmp3],         %[tmp4]           \n\t"
    "addiu       %[j],            %[j],            -1                \n\t"
    "addiu       %[p_data_in],    %[p_data_in],    -4                \n\t"
    "addu        %[tmp1],         %[tmp1],         %[tmp3]           \n\t"
    "bgtz        %[j],            2b                                 \n\t"
    " addu       %[out_s32],      %[out_s32],      %[tmp1]           \n\t"
   "3:                                                               \n\t"
    "beq         %[k],            $zero,           4f                \n\t"
    " nop                                                            \n\t"
    "lh          %[tmp1],         0(%[p_data_in])                    \n\t"
    "lh          %[tmp2],         0(%[p_coefs])                      \n\t"
    "mul         %[tmp1],         %[tmp1],         %[tmp2]           \n\t"
    "addu        %[out_s32],      %[out_s32],      %[tmp1]           \n\t"
   "4:                                                               \n\t"
    "sra         %[out_s32],      %[out_s32],      12                \n\t"
    "addu        %[p_data_in_0],  %[p_data_in_0],  %[factor_2]       \n\t"
#if defined(MIPS_DSP_R1_LE)
    "shll_s.w    %[out_s32],      %[out_s32],      16                \n\t"
    "sra         %[out_s32],      %[out_s32],      16                \n\t"
#else  // #if defined(MIPS_DSP_R1_LE)
    "slt         %[tmp1],         %[max_16],       %[out_s32]        \n\t"
    "movn        %[out_s32],      %[max_16],       %[tmp1]           \n\t"
    "slt         %[tmp1],         %[out_s32],      %[min_16]         \n\t"
    "movn        %[out_s32],      %[min_16],       %[tmp1]           \n\t"
#endif  // #if defined(MIPS_DSP_R1_LE)
    "subu        %[i],            %[i],            %[factor]         \n\t"
    "sh          %[out_s32],      0(%[data_out])                     \n\t"
    "bgtz        %[i],            1b                                 \n\t"
    " addiu      %[data_out],     %[data_out],     2                 \n\t"
    ".set        pop                                                 \n\t"
    : [tmp1] "=&r" (tmp1), [tmp2] "=&r" (tmp2), [tmp3] "=&r" (tmp3),
      [tmp4] "=&r" (tmp4), [p_data_in] "=&r" (p_data_in), [k] "=&r" (k),
      [p_data_in_0] "+r" (p_data_in_0), [p_coefs] "=&r" (p_coefficients),
      [j] "=&r" (j), [out_s32] "=&r" (out_s32), [factor_2] "=&r" (factor_2),
      [i] "=&r" (i)
    : [coef_length] "r" (coefficients_length), [data_out] "r" (data_out),
      [p_coefs_0] "r" (p_coefficients_0), [endpos] "r" (endpos),
#if !defined(MIPS_DSP_R1_LE)
      [max_16] "r" (max_16), [min_16] "r" (min_16),
#endif  // #if !defined(MIPS_DSP_R1_LE)
      [delay] "r" (delay), [factor] "r" (factor)
    : "memory", "hi", "lo"
  );
#endif  // #if defined(MIPS_DSP_R2_LE)
  return 0;
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/downsample_fast_neon.c.neon
================================================
/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

#include <arm_neon.h>

// NEON intrinsics version of WebRtcSpl_DownsampleFast()
// for ARM 32-bit/64-bit platforms.
int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
                                 size_t data_in_length,
                                 int16_t* data_out,
                                 size_t data_out_length,
                                 const int16_t* __restrict coefficients,
                                 size_t coefficients_length,
                                 int factor,
                                 size_t delay) {
  size_t i = 0;
  size_t j = 0;
  int32_t out_s32 = 0;
  size_t endpos = delay + factor * (data_out_length - 1) + 1;
  size_t res = data_out_length & 0x7;
  size_t endpos1 = endpos - factor * res;

  // Return error if any of the running conditions doesn't meet.
  if (data_out_length == 0 || coefficients_length == 0
                           || data_in_length < endpos) {
    return -1;
  }

  // First part, unroll the loop 8 times, with 3 subcases
  // (factor == 2, 4, others).
  switch (factor) {
    case 2: {
      for (i = delay; i < endpos1; i += 16) {
        // Round value, 0.5 in Q12.
        int32x4_t out32x4_0 = vdupq_n_s32(2048);
        int32x4_t out32x4_1 = vdupq_n_s32(2048);

#if defined(WEBRTC_ARCH_ARM64)
        // Unroll the loop 2 times.
        for (j = 0; j < coefficients_length - 1; j += 2) {
          int32x2_t coeff32 = vld1_dup_s32((int32_t*)&coefficients[j]);
          int16x4_t coeff16x4 = vreinterpret_s16_s32(coeff32);
          int16x8x2_t in16x8x2 = vld2q_s16(&data_in[i - j - 1]);

          // Mul and accumulate low 64-bit data.
          int16x4_t in16x4_0 = vget_low_s16(in16x8x2.val[0]);
          int16x4_t in16x4_1 = vget_low_s16(in16x8x2.val[1]);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 1);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_1, coeff16x4, 0);

          // Mul and accumulate high 64-bit data.
          // TODO: vget_high_s16 need extra cost on ARM64. This could be
          // replaced by vmlal_high_lane_s16. But for the interface of
          // vmlal_high_lane_s16, there is a bug in gcc 4.9.
          // This issue need to be tracked in the future.
          int16x4_t in16x4_2 = vget_high_s16(in16x8x2.val[0]);
          int16x4_t in16x4_3 = vget_high_s16(in16x8x2.val[1]);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_2, coeff16x4, 1);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_3, coeff16x4, 0);
        }

        for (; j < coefficients_length; j++) {
          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);
          int16x8x2_t in16x8x2 = vld2q_s16(&data_in[i - j]);

          // Mul and accumulate low 64-bit data.
          int16x4_t in16x4_0 = vget_low_s16(in16x8x2.val[0]);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);

          // Mul and accumulate high 64-bit data.
          // TODO: vget_high_s16 need extra cost on ARM64. This could be
          // replaced by vmlal_high_lane_s16. But for the interface of
          // vmlal_high_lane_s16, there is a bug in gcc 4.9.
          // This issue need to be tracked in the future.
          int16x4_t in16x4_1 = vget_high_s16(in16x8x2.val[0]);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);
        }
#else
        // On ARMv7, the loop unrolling 2 times results in performance
        // regression.
        for (j = 0; j < coefficients_length; j++) {
          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);
          int16x8x2_t in16x8x2 = vld2q_s16(&data_in[i - j]);

          // Mul and accumulate.
          int16x4_t in16x4_0 = vget_low_s16(in16x8x2.val[0]);
          int16x4_t in16x4_1 = vget_high_s16(in16x8x2.val[0]);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);
        }
#endif

        // Saturate and store the output.
        int16x4_t out16x4_0 = vqshrn_n_s32(out32x4_0, 12);
        int16x4_t out16x4_1 = vqshrn_n_s32(out32x4_1, 12);
        vst1q_s16(data_out, vcombine_s16(out16x4_0, out16x4_1));
        data_out += 8;
      }
      break;
    }
    case 4: {
      for (i = delay; i < endpos1; i += 32) {
        // Round value, 0.5 in Q12.
        int32x4_t out32x4_0 = vdupq_n_s32(2048);
        int32x4_t out32x4_1 = vdupq_n_s32(2048);

        // Unroll the loop 4 times.
        for (j = 0; j < coefficients_length - 3; j += 4) {
          int16x4_t coeff16x4 = vld1_s16(&coefficients[j]);
          int16x8x4_t in16x8x4 = vld4q_s16(&data_in[i - j - 3]);

          // Mul and accumulate low 64-bit data.
          int16x4_t in16x4_0 = vget_low_s16(in16x8x4.val[0]);
          int16x4_t in16x4_2 = vget_low_s16(in16x8x4.val[1]);
          int16x4_t in16x4_4 = vget_low_s16(in16x8x4.val[2]);
          int16x4_t in16x4_6 = vget_low_s16(in16x8x4.val[3]);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 3);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_2, coeff16x4, 2);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_4, coeff16x4, 1);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_6, coeff16x4, 0);

          // Mul and accumulate high 64-bit data.
          // TODO: vget_high_s16 need extra cost on ARM64. This could be
          // replaced by vmlal_high_lane_s16. But for the interface of
          // vmlal_high_lane_s16, there is a bug in gcc 4.9.
          // This issue need to be tracked in the future.
          int16x4_t in16x4_1 = vget_high_s16(in16x8x4.val[0]);
          int16x4_t in16x4_3 = vget_high_s16(in16x8x4.val[1]);
          int16x4_t in16x4_5 = vget_high_s16(in16x8x4.val[2]);
          int16x4_t in16x4_7 = vget_high_s16(in16x8x4.val[3]);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 3);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_3, coeff16x4, 2);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_5, coeff16x4, 1);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_7, coeff16x4, 0);
        }

        for (; j < coefficients_length; j++) {
          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);
          int16x8x4_t in16x8x4 = vld4q_s16(&data_in[i - j]);

          // Mul and accumulate low 64-bit data.
          int16x4_t in16x4_0 = vget_low_s16(in16x8x4.val[0]);
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);

          // Mul and accumulate high 64-bit data.
          // TODO: vget_high_s16 need extra cost on ARM64. This could be
          // replaced by vmlal_high_lane_s16. But for the interface of
          // vmlal_high_lane_s16, there is a bug in gcc 4.9.
          // This issue need to be tracked in the future.
          int16x4_t in16x4_1 = vget_high_s16(in16x8x4.val[0]);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);
        }

        // Saturate and store the output.
        int16x4_t out16x4_0 = vqshrn_n_s32(out32x4_0, 12);
        int16x4_t out16x4_1 = vqshrn_n_s32(out32x4_1, 12);
        vst1q_s16(data_out, vcombine_s16(out16x4_0, out16x4_1));
        data_out += 8;
      }
      break;
    }
    default: {
      for (i = delay; i < endpos1; i += factor * 8) {
        // Round value, 0.5 in Q12.
        int32x4_t out32x4_0 = vdupq_n_s32(2048);
        int32x4_t out32x4_1 = vdupq_n_s32(2048);

        for (j = 0; j < coefficients_length; j++) {
          int16x4_t coeff16x4 = vld1_dup_s16(&coefficients[j]);
          int16x4_t in16x4_0 = vld1_dup_s16(&data_in[i - j]);
          in16x4_0 = vld1_lane_s16(&data_in[i + factor - j], in16x4_0, 1);
          in16x4_0 = vld1_lane_s16(&data_in[i + factor * 2 - j], in16x4_0, 2);
          in16x4_0 = vld1_lane_s16(&data_in[i + factor * 3 - j], in16x4_0, 3);
          int16x4_t in16x4_1 = vld1_dup_s16(&data_in[i + factor * 4 - j]);
          in16x4_1 = vld1_lane_s16(&data_in[i + factor * 5 - j], in16x4_1, 1);
          in16x4_1 = vld1_lane_s16(&data_in[i + factor * 6 - j], in16x4_1, 2);
          in16x4_1 = vld1_lane_s16(&data_in[i + factor * 7 - j], in16x4_1, 3);

          // Mul and accumulate.
          out32x4_0 = vmlal_lane_s16(out32x4_0, in16x4_0, coeff16x4, 0);
          out32x4_1 = vmlal_lane_s16(out32x4_1, in16x4_1, coeff16x4, 0);
        }

        // Saturate and store the output.
        int16x4_t out16x4_0 = vqshrn_n_s32(out32x4_0, 12);
        int16x4_t out16x4_1 = vqshrn_n_s32(out32x4_1, 12);
        vst1q_s16(data_out, vcombine_s16(out16x4_0, out16x4_1));
        data_out += 8;
      }
      break;
    }
  }

  // Second part, do the rest iterations (if any).
  for (; i < endpos; i += factor) {
    out_s32 = 2048;  // Round value, 0.5 in Q12.

    for (j = 0; j < coefficients_length; j++) {
      out_s32 = WebRtc_MulAccumW16(coefficients[j], data_in[i - j], out_s32);
    }

    // Saturate and store the output.
    out_s32 >>= 12;
    *data_out++ = WebRtcSpl_SatW32ToW16(out_s32);
  }

  return 0;
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/energy.c
================================================
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/*
 * This file contains the function WebRtcSpl_Energy().
 * The description header can be found in signal_processing_library.h
 *
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

int32_t WebRtcSpl_Energy(int16_t* vector,
                         size_t vector_length,
                         int* scale_factor)
{
    int32_t en = 0;
    size_t i;
    int scaling =
        WebRtcSpl_GetScalingSquare(vector, vector_length, vector_length);
    size_t looptimes = vector_length;
    int16_t *vectorptr = vector;

    for (i = 0; i < looptimes; i++)
    {
      en += (*vectorptr * *vectorptr) >> scaling;
      vectorptr++;
    }
    *scale_factor = scaling;

    return en;
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/get_scaling_square.c
================================================
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/*
 * This file contains the function WebRtcSpl_GetScalingSquare().
 * The description header can be found in signal_processing_library.h
 *
 */

#include "common_audio/signal_processing/include/signal_processing_library.h"

int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
                                   size_t in_vector_length,
                                   size_t times)
{
    int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times);
    size_t i;
    int16_t smax = -1;
    int16_t sabs;
    int16_t *sptr = in_vector;
    int16_t t;
    size_t looptimes = in_vector_length;

    for (i = looptimes; i > 0; i--)
    {
        sabs = (*sptr > 0 ? *sptr++ : -*sptr++);
        smax = (sabs > smax ? sabs : smax);
    }
    t = WebRtcSpl_NormW32(WEBRTC_SPL_MUL(smax, smax));

    if (smax == 0)
    {
        return 0; // Since norm(0) returns 0
    } else
    {
        return (t > nbits) ? 0 : nbits - t;
    }
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/include/real_fft.h
================================================
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_
#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_

#include "typedefs.h"  // NOLINT(build/include)

// For ComplexFFT(), the maximum fft order is 10;
// for OpenMax FFT in ARM, it is 12;
// WebRTC APM uses orders of only 7 and 8.
enum {kMaxFFTOrder = 10};

struct RealFFT;

#ifdef __cplusplus
extern "C" {
#endif

struct RealFFT* WebRtcSpl_CreateRealFFT(int order);
void WebRtcSpl_FreeRealFFT(struct RealFFT* self);

// Compute an FFT for a real-valued signal of length of 2^order,
// where 1 < order <= MAX_FFT_ORDER. Transform length is determined by the
// specification structure, which must be initialized prior to calling the FFT
// function with WebRtcSpl_CreateRealFFT().
// The relationship between the input and output sequences can
// be expressed in terms of the DFT, i.e.:
//     x[n] = (2^(-scalefactor)/N)  . SUM[k=0,...,N-1] X[k].e^(jnk.2.pi/N)
//     n=0,1,2,...N-1
//     N=2^order.
// The conjugate-symmetric output sequence is represented using a CCS vector,
// which is of length N+2, and is organized as follows:
//     Index:      0  1  2  3  4  5   . . .   N-2       N-1       N       N+1
//     Component:  R0 0  R1 I1 R2 I2  . . .   R[N/2-1]  I[N/2-1]  R[N/2]  0
// where R[n] and I[n], respectively, denote the real and imaginary components
// for FFT bin 'n'. Bins  are numbered from 0 to N/2, where N is the FFT length.
// Bin index 0 corresponds to the DC component, and bin index N/2 corresponds to
// the foldover frequency.
//
// Input Arguments:
//   self - pointer to preallocated and initialized FFT specification structure.
//   real_data_in - the input signal. For an ARM Neon platform, it must be
//                  aligned on a 32-byte boundary.
//
// Output Arguments:
//   complex_data_out - the output complex signal with (2^order + 2) 16-bit
//                      elements. For an ARM Neon platform, it must be different
//                      from real_data_in, and aligned on a 32-byte boundary.
//
// Return Value:
//   0  - FFT calculation is successful.
//   -1 - Error with bad arguments (null pointers).
int WebRtcSpl_RealForwardFFT(struct RealFFT* self,
                             const int16_t* real_data_in,
                             int16_t* complex_data_out);

// Compute the inverse FFT for a conjugate-symmetric input sequence of length of
// 2^order, where 1 < order <= MAX_FFT_ORDER. Transform length is determined by
// the specification structure, which must be initialized prior to calling the
// FFT function with WebRtcSpl_CreateRealFFT().
// For a transform of length M, the input sequence is represented using a packed
// CCS vector of length M+2, which is explained in the comments for
// WebRtcSpl_RealForwardFFTC above.
//
// Input Arguments:
//   self - pointer to preallocated and initialized FFT specification structure.
//   complex_data_in - the input complex signal with (2^order + 2) 16-bit
//                     elements. For an ARM Neon platform, it must be aligned on
//                     a 32-byte boundary.
//
// Output Arguments:
//   real_data_out - the output real signal. For an ARM Neon platform, it must
//                   be different to complex_data_in, and aligned on a 32-byte
//                   boundary.
//
// Return Value:
//   0 or a positive number - a value that the elements in the |real_data_out|
//                            should be shifted left with in order to get
//                            correct physical values.
//   -1 - Error with bad arguments (null pointers).
int WebRtcSpl_RealInverseFFT(struct RealFFT* self,
                             const int16_t* complex_data_in,
                             int16_t* real_data_out);

#ifdef __cplusplus
}
#endif

#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/include/signal_processing_library.h
================================================
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/*
 * This header file includes all of the fix point signal processing library (SPL) function
 * descriptions and declarations.
 * For specific function calls, see bottom of file.
 */

#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_
#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_

#include <string.h>
#include "typedefs.h"  // NOLINT(build/include)

// Macros specific for the fixed point implementation
#define WEBRTC_SPL_WORD16_MAX       32767
#define WEBRTC_SPL_WORD16_MIN       -32768
#define WEBRTC_SPL_WORD32_MAX       (int32_t)0x7fffffff
#define WEBRTC_SPL_WORD32_MIN       (int32_t)0x80000000
#define WEBRTC_SPL_MAX_LPC_ORDER    14
#define WEBRTC_SPL_MIN(A, B)        (A < B ? A : B)  // Get min value
#define WEBRTC_SPL_MAX(A, B)        (A > B ? A : B)  // Get max value
// TODO(kma/bjorn): For the next two macros, investigate how to correct the code
// for inputs of a = WEBRTC_SPL_WORD16_MIN or WEBRTC_SPL_WORD32_MIN.
#define WEBRTC_SPL_ABS_W16(a) \
    (((int16_t)a >= 0) ? ((int16_t)a) : -((int16_t)a))
#define WEBRTC_SPL_ABS_W32(a) \
    (((int32_t)a >= 0) ? ((int32_t)a) : -((int32_t)a))

#define WEBRTC_SPL_MUL(a, b) \
    ((int32_t) ((int32_t)(a) * (int32_t)(b)))
#define WEBRTC_SPL_UMUL(a, b) \
    ((uint32_t) ((uint32_t)(a) * (uint32_t)(b)))
#define WEBRTC_SPL_UMUL_32_16(a, b) \
    ((uint32_t) ((uint32_t)(a) * (uint16_t)(b)))
#define WEBRTC_SPL_MUL_16_U16(a, b) \
    ((int32_t)(int16_t)(a) * (uint16_t)(b))

#ifndef WEBRTC_ARCH_ARM_V7
// For ARMv7 platforms, these are inline functions in spl_inl_armv7.h
#ifndef MIPS32_LE
// For MIPS platforms, these are inline functions in spl_inl_mips.h
#define WEBRTC_SPL_MUL_16_16(a, b) \
    ((int32_t) (((int16_t)(a)) * ((int16_t)(b))))
#define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \
    (WEBRTC_SPL_MUL_16_16(a, b >> 16) \
     + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15))
#endif
#endif

#define WEBRTC_SPL_MUL_16_32_RSFT11(a, b)          \
  (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 5) + \
    (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))
#define WEBRTC_SPL_MUL_16_32_RSFT14(a, b)          \
  (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 2) + \
    (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))
#define WEBRTC_SPL_MUL_16_32_RSFT15(a, b)            \
  ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 1)) + \
    (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))

#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
    (WEBRTC_SPL_MUL_16_16(a, b) >> (c))

#define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \
    ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) \
                                  (((int32_t)1) << ((c) - 1)))) >> (c))

// C + the 32 most significant bits of A * B
#define WEBRTC_SPL_SCALEDIFF32(A, B, C) \
    (C + (B >> 16) * A + (((uint32_t)(B & 0x0000FFFF) * A) >> 16))

#define WEBRTC_SPL_SAT(a, b, c)         (b > a ? a : b < c ? c : b)

// Shifting with negative numbers allowed
// Positive means left shift
#define WEBRTC_SPL_SHIFT_W32(x, c) ((c) >= 0 ? (x) * (1 << (c)) : (x) >> -(c))

// Shifting with negative numbers not allowed
// We cannot do casting here due to signed/unsigned problem
#define WEBRTC_SPL_LSHIFT_W32(x, c)     ((x) << (c))

#define WEBRTC_SPL_RSHIFT_U32(x, c)     ((uint32_t)(x) >> (c))

#define WEBRTC_SPL_RAND(a) \
    ((int16_t)((((int16_t)a * 18816) >> 7) & 0x00007fff))

#ifdef __cplusplus
extern "C" {
#endif

#define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \
  memcpy(v1, v2, (length) * sizeof(int16_t))

// inline functions:
#include "common_audio/signal_processing/include/spl_inl.h"

// Initialize SPL. Currently it contains only function pointer initialization.
// If the underlying platform is known to be ARM-Neon (WEBRTC_HAS_NEON defined),
// the pointers will be assigned to code optimized for Neon; otherwise, generic
// C code will be assigned.
// Note that this function MUST be called in any application that uses SPL
// functions.
void WebRtcSpl_Init();

int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
                                   size_t in_vector_length,
                                   size_t times);

// Copy and set operations. Implementation in copy_set_operations.c.
// Descriptions at bottom of file.
void WebRtcSpl_MemSetW16(int16_t* vector,
                         int16_t set_value,
                         size_t vector_length);
void WebRtcSpl_MemSetW32(int32_t* vector,
                         int32_t set_value,
                         size_t vector_length);
void WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector,
                                   int16_t* in_vector,
                                   size_t vector_length);
void WebRtcSpl_CopyFromEndW16(const int16_t* in_vector,
                              size_t in_vector_length,
                              size_t samples,
                              int16_t* out_vector);
void WebRtcSpl_ZerosArrayW16(int16_t* vector,
                             size_t vector_length);
void WebRtcSpl_ZerosArrayW32(int32_t* vector,
                             size_t vector_length);
// End: Copy and set operations.


// Minimum and maximum operation functions and their pointers.
// Implementation in min_max_operations.c.

// Returns the largest absolute value in a signed 16-bit vector.
//
// Input:
//      - vector : 16-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Maximum absolute value in vector.
typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, size_t length);
extern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;
int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length);
#if defined(WEBRTC_HAS_NEON)
int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length);
#endif
#if defined(MIPS32_LE)
int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length);
#endif

// Returns the largest absolute value in a signed 32-bit vector.
//
// Input:
//      - vector : 32-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Maximum absolute value in vector.
typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, size_t length);
extern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;
int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length);
#if defined(WEBRTC_HAS_NEON)
int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length);
#endif
#if defined(MIPS_DSP_R1_LE)
int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length);
#endif

// Returns the maximum value of a 16-bit vector.
//
// Input:
//      - vector : 16-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Maximum sample value in |vector|.
typedef int16_t (*MaxValueW16)(const int16_t* vector, size_t length);
extern MaxValueW16 WebRtcSpl_MaxValueW16;
int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length);
#if defined(WEBRTC_HAS_NEON)
int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length);
#endif
#if defined(MIPS32_LE)
int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length);
#endif

// Returns the maximum value of a 32-bit vector.
//
// Input:
//      - vector : 32-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Maximum sample value in |vector|.
typedef int32_t (*MaxValueW32)(const int32_t* vector, size_t length);
extern MaxValueW32 WebRtcSpl_MaxValueW32;
int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length);
#if defined(WEBRTC_HAS_NEON)
int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length);
#endif
#if defined(MIPS32_LE)
int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length);
#endif

// Returns the minimum value of a 16-bit vector.
//
// Input:
//      - vector : 16-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Minimum sample value in |vector|.
typedef int16_t (*MinValueW16)(const int16_t* vector, size_t length);
extern MinValueW16 WebRtcSpl_MinValueW16;
int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length);
#if defined(WEBRTC_HAS_NEON)
int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length);
#endif
#if defined(MIPS32_LE)
int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length);
#endif

// Returns the minimum value of a 32-bit vector.
//
// Input:
//      - vector : 32-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Minimum sample value in |vector|.
typedef int32_t (*MinValueW32)(const int32_t* vector, size_t length);
extern MinValueW32 WebRtcSpl_MinValueW32;
int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length);
#if defined(WEBRTC_HAS_NEON)
int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length);
#endif
#if defined(MIPS32_LE)
int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length);
#endif

// Returns the vector index to the largest absolute value of a 16-bit vector.
//
// Input:
//      - vector : 16-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Index to the maximum absolute value in vector.
//                 If there are multiple equal maxima, return the index of the
//                 first. -32768 will always have precedence over 32767 (despite
//                 -32768 presenting an int16 absolute value of 32767).
size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length);

// Returns the vector index to the maximum sample value of a 16-bit vector.
//
// Input:
//      - vector : 16-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Index to the maximum value in vector (if multiple
//                 indexes have the maximum, return the first).
size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length);

// Returns the vector index to the maximum sample value of a 32-bit vector.
//
// Input:
//      - vector : 32-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Index to the maximum value in vector (if multiple
//                 indexes have the maximum, return the first).
size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length);

// Returns the vector index to the minimum sample value of a 16-bit vector.
//
// Input:
//      - vector : 16-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Index to the mimimum value in vector  (if multiple
//                 indexes have the minimum, return the first).
size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length);

// Returns the vector index to the minimum sample value of a 32-bit vector.
//
// Input:
//      - vector : 32-bit input vector.
//      - length : Number of samples in vector.
//
// Return value  : Index to the mimimum value in vector  (if multiple
//                 indexes have the minimum, return the first).
size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length);

// End: Minimum and maximum operations.


// Vector scaling operations. Implementation in vector_scaling_operations.c.
// Description at bottom of file.
void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector,
                                 size_t vector_length,
                                 const int16_t* in_vector,
                                 int16_t right_shifts);
void WebRtcSpl_VectorBitShiftW32(int32_t* out_vector,
                                 size_t vector_length,
                                 const int32_t* in_vector,
                                 int16_t right_shifts);
void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector,
                                      size_t vector_length,
                                      const int32_t* in_vector,
                                      int right_shifts);
void WebRtcSpl_ScaleVector(const int16_t* in_vector,
                           int16_t* out_vector,
                           int16_t gain,
                           size_t vector_length,
                           int16_t right_shifts);
void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector,
                                  int16_t* out_vector,
                                  int16_t gain,
                                  size_t vector_length,
                                  int16_t right_shifts);
void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1,
                                  int16_t gain1, int right_shifts1,
                                  const int16_t* in_vector2,
                                  int16_t gain2, int right_shifts2,
                                  int16_t* out_vector,
                                  size_t vector_length);

// The functions (with related pointer) perform the vector operation:
//   out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k])
//        + round_value) >> right_shifts,
//   where  round_value = (1 << right_shifts) >> 1.
//
// Input:
//      - in_vector1       : Input vector 1
//      - in_vector1_scale : Gain to be used for vector 1
//      - in_vector2       : Input vector 2
//      - in_vector2_scale : Gain to be used for vector 2
//      - right_shifts     : Number of right bit shifts to be applied
//      - length           : Number of elements in the input vectors
//
// Output:
//      - out_vector       : Output vector
// Return value            : 0 if OK, -1 if (in_vector1 == null
//                           || in_vector2 == null || out_vector == null
//                           || length <= 0 || right_shift < 0).
typedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1,
                                           int16_t in_vector1_scale,
                                           const int16_t* in_vector2,
                                           int16_t in_vector2_scale,
                                           int right_shifts,
                                           int16_t* out_vector,
                                           size_t length);
extern ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;
int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
                                           int16_t in_vector1_scale,
                                           const int16_t* in_vector2,
                                           int16_t in_vector2_scale,
                                           int right_shifts,
                                           int16_t* out_vector,
                                           size_t length);
#if defined(MIPS_DSP_R1_LE)
int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
                                               int16_t in_vector1_scale,
                                               const int16_t* in_vector2,
                                               int16_t in_vector2_scale,
                                               int right_shifts,
                                               int16_t* out_vector,
                                               size_t length);
#endif
// End: Vector scaling operations.

// iLBC specific functions. Implementations in ilbc_specific_functions.c.
// Description at bottom of file.
void WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector,
                                             const int16_t* in_vector,
                                             const int16_t* window,
                                             size_t vector_length,
                                             int16_t right_shifts);
void WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector,
                                     const int16_t* in_vector,
                                     const int16_t* window,
                                     size_t vector_length,
                                     int16_t right_shifts);
void WebRtcSpl_AddVectorsAndShift(int16_t* out_vector,
                                  const int16_t* in_vector1,
                                  const int16_t* in_vector2,
                                  size_t vector_length,
                                  int16_t right_shifts);
void WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector,
                                       int16_t* in_vector,
                                       int16_t gain,
                                       int32_t add_constant,
                                       int16_t right_shifts,
                                       size_t vector_length);
void WebRtcSpl_AffineTransformVector(int16_t* out_vector,
                                     int16_t* in_vector,
                                     int16_t gain,
                                     int32_t add_constant,
                                     int16_t right_shifts,
                                     size_t vector_length);
// End: iLBC specific functions.

// Signal processing operations.

// A 32-bit fix-point implementation of auto-correlation computation
//
// Input:
//      - in_vector        : Vector to calculate autocorrelation upon
//      - in_vector_length : Length (in samples) of |vector|
//      - order            : The order up to which the autocorrelation should be
//                           calculated
//
// Output:
//      - result           : auto-correlation values (values should be seen
//                           relative to each other since the absolute values
//                           might have been down shifted to avoid overflow)
//
//      - scale            : The number of left shifts required to obtain the
//                           auto-correlation in Q0
//
// Return value            : Number of samples in |result|, i.e. (order+1)
size_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
                                 size_t in_vector_length,
                                 size_t order,
                                 int32_t* result,
                                 int* scale);

// A 32-bit fix-point implementation of the Levinson-Durbin algorithm that
// does NOT use the 64 bit class
//
// Input:
//      - auto_corr : Vector with autocorrelation values of length >= |order|+1
//      - order     : The LPC filter order (support up to order 20)
//
// Output:
//      - lpc_coef  : lpc_coef[0..order] LPC coefficients in Q12
//      - refl_coef : refl_coef[0...order-1]| Reflection coefficients in Q15
//
// Return value     : 1 for stable 0 for unstable
int16_t WebRtcSpl_LevinsonDurbin(const int32_t* auto_corr,
                                 int16_t* lpc_coef,
                                 int16_t* refl_coef,
                                 size_t order);

// Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|.
// This version is a 16 bit operation.
//
// NOTE: The 16 bit refl_coef -> lpc_coef conversion might result in a
// "slightly unstable" filter (i.e., a pole just outside the unit circle) in
// "rare" cases even if the reflection coefficients are stable.
//
// Input:
//      - refl_coef : Reflection coefficients in Q15 that should be converted
//                    to LPC coefficients
//      - use_order : Number of coefficients in |refl_coef|
//
// Output:
//      - lpc_coef  : LPC coefficients in Q12
void WebRtcSpl_ReflCoefToLpc(const int16_t* refl_coef,
                             int use_order,
                             int16_t* lpc_coef);

// Converts LPC coefficients |lpc_coef| to reflection coefficients |refl_coef|.
// This version is a 16 bit operation.
// The conversion is implemented by the step-down algorithm.
//
// Input:
//      - lpc_coef  : LPC coefficients in Q12, that should be converted to
//                    reflection coefficients
//      - use_order : Number of coefficients in |lpc_coef|
//
// Output:
//      - refl_coef : Reflection coefficients in Q15.
void WebRtcSpl_LpcToReflCoef(int16_t* lpc_coef,
                             int use_order,
                             int16_t* refl_coef);

// Calculates reflection coefficients (16 bit) from auto-correlation values
//
// Input:
//      - auto_corr : Auto-correlation values
//      - use_order : Number of coefficients wanted be calculated
//
// Output:
//      - refl_coef : Reflection coefficients in Q15.
void WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr,
                                  int use_order,
                                  int16_t* refl_coef);

// The functions (with related pointer) calculate the cross-correlation between
// two sequences |seq1| and |seq2|.
// |seq1| is fixed and |seq2| slides as the pointer is increased with the
// amount |step_seq2|. Note the arguments should obey the relationship:
// |dim_seq| - 1 + |step_seq2| * (|dim_cross_correlation| - 1) <
//      buffer size of |seq2|
//
// Input:
//      - seq1           : First sequence (fixed throughout the correlation)
//      - seq2           : Second sequence (slides |step_vector2| for each
//                            new correlation)
//      - dim_seq        : Number of samples to use in the cross-correlation
//      - dim_cross_correlation : Number of cross-correlations to calculate (the
//                            start position for |vector2| is updated for each
//                            new one)
//      - right_shifts   : Number of right bit shifts to use. This will
//                            become the output Q-domain.
//      - step_seq2      : How many (positive or negative) steps the
//                            |vector2| pointer should be updated for each new
//                            cross-correlation value.
//
// Output:
//      - cross_correlation : The cross-correlation in Q(-right_shifts)
typedef void (*CrossCorrelation)(int32_t* cross_correlation,
                                 const int16_t* seq1,
                                 const int16_t* seq2,
                                 size_t dim_seq,
                                 size_t dim_cross_correlation,
                                 int right_shifts,
                                 int step_seq2);
extern CrossCorrelation WebRtcSpl_CrossCorrelation;
void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
                                 const int16_t* seq1,
                                 const int16_t* seq2,
                                 size_t dim_seq,
                                 size_t dim_cross_correlation,
                                 int right_shifts,
                                 int step_seq2);
#if defined(WEBRTC_HAS_NEON)
void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
                                    const int16_t* seq1,
                                    const int16_t* seq2,
                                    size_t dim_seq,
                                    size_t dim_cross_correlation,
                                    int right_shifts,
                                    int step_seq2);
#endif
#if defined(MIPS32_LE)
void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
                                     const int16_t* seq1,
                                     const int16_t* seq2,
                                     size_t dim_seq,
                                     size_t dim_cross_correlation,
                                     int right_shifts,
                                     int step_seq2);
#endif

// Creates (the first half of) a Hanning window. Size must be at least 1 and
// at most 512.
//
// Input:
//      - size      : Length of the requested Hanning window (1 to 512)
//
// Output:
//      - window    : Hanning vector in Q14.
void WebRtcSpl_GetHanningWindow(int16_t* window, size_t size);

// Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector
// |in_vector|. Input and output values are in Q15.
//
// Inputs:
//      - in_vector     : Values to calculate sqrt(1 - x^2) of
//      - vector_length : Length of vector |in_vector|
//
// Output:
//      - out_vector    : Output values in Q15
void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,
                                      size_t vector_length,
                                      int16_t* out_vector);
// End: Signal processing operations.

// Randomization functions. Implementations collected in
// randomization_functions.c and descriptions at bottom of this file.
int16_t WebRtcSpl_RandU(uint32_t* seed);
int16_t WebRtcSpl_RandN(uint32_t* seed);
int16_t WebRtcSpl_RandUArray(int16_t* vector,
                             int16_t vector_length,
                             uint32_t* seed);
// End: Randomization functions.

// Math functions
int32_t WebRtcSpl_Sqrt(int32_t value);
int32_t WebRtcSpl_SqrtFloor(int32_t value);

// Divisions. Implementations collected in division_operations.c and
// descriptions at bottom of this file.
uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den);
int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den);
int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den);
int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den);
int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low);
// End: Divisions.

int32_t WebRtcSpl_Energy(int16_t* vector,
                         size_t vector_length,
                         int* scale_factor);

// Filter operations.
size_t WebRtcSpl_FilterAR(const int16_t* ar_coef,
                          size_t ar_coef_length,
                          const int16_t* in_vector,
                          size_t in_vector_length,
                          int16_t* filter_state,
                          size_t filter_state_length,
                          int16_t* filter_state_low,
                          size_t filter_state_low_length,
                          int16_t* out_vector,
                          int16_t* out_vector_low,
                          size_t out_vector_low_length);

// WebRtcSpl_FilterMAFastQ12(...)
//
// Performs a MA filtering on a vector in Q12
//
// Input:
//      - in_vector         : Input samples (state in positions
//                            in_vector[-order] .. in_vector[-1])
//      - ma_coef           : Filter coefficients (in Q12)
//      - ma_coef_length    : Number of B coefficients (order+1)
//      - vector_length     : Number of samples to be filtered
//
// Output:
//      - out_vector        : Filtered samples
//
void WebRtcSpl_FilterMAFastQ12(const int16_t* in_vector,
                               int16_t* out_vector,
                               const int16_t* ma_coef,
                               size_t ma_coef_length,
                               size_t vector_length);

// Performs a AR filtering on a vector in Q12
// Input:
//      - data_in            : Input samples
//      - data_out           : State information in positions
//                               data_out[-order] .. data_out[-1]
//      - coefficients       : Filter coefficients (in Q12)
//      - coefficients_length: Number of coefficients (order+1)
//      - data_length        : Number of samples to be filtered
// Output:
//      - data_out           : Filtered samples
void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
                               int16_t* data_out,
                               const int16_t* __restrict coefficients,
                               size_t coefficients_length,
                               size_t data_length);

// The functions (with related pointer) perform a MA down sampling filter
// on a vector.
// Input:
//      - data_in            : Input samples (state in positions
//                               data_in[-order] .. data_in[-1])
//      - data_in_length     : Number of samples in |data_in| to be filtered.
//                               This must be at least
//                               |delay| + |factor|*(|out_vector_length|-1) + 1)
//      - data_out_length    : Number of down sampled samples desired
//      - coefficients       : Filter coefficients (in Q12)
//      - coefficients_length: Number of coefficients (order+1)
//      - factor             : Decimation factor
//      - delay              : Delay of filter (compensated for in out_vector)
// Output:
//      - data_out           : Filtered samples
// Return value              : 0 if OK, -1 if |in_vector| is too short
typedef int (*DownsampleFast)(const int16_t* data_in,
                              size_t data_in_length,
                              int16_t* data_out,
                              size_t data_out_length,
                              const int16_t* __restrict coefficients,
                              size_t coefficients_length,
                              int factor,
                              size_t delay);
extern DownsampleFast WebRtcSpl_DownsampleFast;
int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
                              size_t data_in_length,
                              int16_t* data_out,
                              size_t data_out_length,
                              const int16_t* __restrict coefficients,
                              size_t coefficients_length,
                              int factor,
                              size_t delay);
#if defined(WEBRTC_HAS_NEON)
int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
                                 size_t data_in_length,
                                 int16_t* data_out,
                                 size_t data_out_length,
                                 const int16_t* __restrict coefficients,
                                 size_t coefficients_length,
                                 int factor,
                                 size_t delay);
#endif
#if defined(MIPS32_LE)
int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
                                  size_t data_in_length,
                                  int16_t* data_out,
                                  size_t data_out_length,
                                  const int16_t* __restrict coefficients,
                                  size_t coefficients_length,
                                  int factor,
                                  size_t delay);
#endif

// End: Filter operations.

// FFT operations

int WebRtcSpl_ComplexFFT(int16_t vector[], int stages, int mode);
int WebRtcSpl_ComplexIFFT(int16_t vector[], int stages, int mode);

// Treat a 16-bit complex data buffer |complex_data| as an array of 32-bit
// values, and swap elements whose indexes are bit-reverses of each other.
//
// Input:
//      - complex_data  : Complex data buffer containing 2^|stages| real
//                        elements interleaved with 2^|stages| imaginary
//                        elements: [Re Im Re Im Re Im....]
//      - stages        : Number of FFT stages. Must be at least 3 and at most
//                        10, since the table WebRtcSpl_kSinTable1024[] is 1024
//                        elements long.
//
// Output:
//      - complex_data  : The complex data buffer.

void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages);

// End: FFT operations

/************************************************************
 *
 * RESAMPLING FUNCTIONS AND THEIR STRUCTS ARE DEFINED BELOW
 *
 ************************************************************/

/*******************************************************************
 * resample.c
 *
 * Includes the following resampling combinations
 * 22 kHz -> 16 kHz
 * 16 kHz -> 22 kHz
 * 22 kHz ->  8 kHz
 *  8 kHz -> 22 kHz
 *
 ******************************************************************/

// state structure for 22 -> 16 resampler
typedef struct {
  int32_t S_22_44[8];
  int32_t S_44_32[8];
  int32_t S_32_16[8];
} WebRtcSpl_State22khzTo16khz;

void WebRtcSpl_Resample22khzTo16khz(const int16_t* in,
                                    int16_t* out,
                                    WebRtcSpl_State22khzTo16khz* state,
                                    int32_t* tmpmem);

void WebRtcSpl_ResetResample22khzTo16khz(WebRtcSpl_State22khzTo16khz* state);

// state structure for 16 -> 22 resampler
typedef struct {
  int32_t S_16_32[8];
  int32_t S_32_22[8];
} WebRtcSpl_State16khzTo22khz;

void WebRtcSpl_Resample16khzTo22khz(const int16_t* in,
                                    int16_t* out,
                                    WebRtcSpl_State16khzTo22khz* state,
                                    int32_t* tmpmem);

void WebRtcSpl_ResetResample16khzTo22khz(WebRtcSpl_State16khzTo22khz* state);

// state structure for 22 -> 8 resampler
typedef struct {
  int32_t S_22_22[16];
  int32_t S_22_16[8];
  int32_t S_16_8[8];
} WebRtcSpl_State22khzTo8khz;

void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, int16_t* out,
                                   WebRtcSpl_State22khzTo8khz* state,
                                   int32_t* tmpmem);

void WebRtcSpl_ResetResample22khzTo8khz(WebRtcSpl_State22khzTo8khz* state);

// state structure for 8 -> 22 resampler
typedef struct {
  int32_t S_8_16[8];
  int32_t S_16_11[8];
  int32_t S_11_22[8];
} WebRtcSpl_State8khzTo22khz;

void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, int16_t* out,
                                   WebRtcSpl_State8khzTo22khz* state,
                                   int32_t* tmpmem);

void WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state);

/*******************************************************************
 * resample_fractional.c
 * Functions for internal use in the other resample functions
 *
 * Includes the following resampling combinations
 * 48 kHz -> 32 kHz
 * 32 kHz -> 24 kHz
 * 44 kHz -> 32 kHz
 *
 ******************************************************************/

void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out, size_t K);

void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out, size_t K);

void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out, size_t K);

/*******************************************************************
 * resample_48khz.c
 *
 * Includes the following resampling combinations
 * 48 kHz -> 16 kHz
 * 16 kHz -> 48 kHz
 * 48 kHz ->  8 kHz
 *  8 kHz -> 48 kHz
 *
 ******************************************************************/

typedef struct {
  int32_t S_48_48[16];
  int32_t S_48_32[8];
  int32_t S_32_16[8];
} WebRtcSpl_State48khzTo16khz;

void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
                                    WebRtcSpl_State48khzTo16khz* state,
                                    int32_t* tmpmem);

void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state);

typedef struct {
  int32_t S_16_32[8];
  int32_t S_32_24[8];
  int32_t S_24_48[8];
} WebRtcSpl_State16khzTo48khz;

void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
                                    WebRtcSpl_State16khzTo48khz* state,
                                    int32_t* tmpmem);

void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state);

typedef struct {
  int32_t S_48_24[8];
  int32_t S_24_24[16];
  int32_t S_24_16[8];
  int32_t S_16_8[8];
} WebRtcSpl_State48khzTo8khz;

void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
                                   WebRtcSpl_State48khzTo8khz* state,
                                   int32_t* tmpmem);

void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state);

typedef struct {
  int32_t S_8_16[8];
  int32_t S_16_12[8];
  int32_t S_12_24[8];
  int32_t S_24_48[8];
} WebRtcSpl_State8khzTo48khz;

void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
                                   WebRtcSpl_State8khzTo48khz* state,
                                   int32_t* tmpmem);

void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state);

/*******************************************************************
 * resample_by_2.c
 *
 * Includes down and up sampling by a factor of two.
 *
 ******************************************************************/

void WebRtcSpl_DownsampleBy2(const int16_t* in, size_t len,
                             int16_t* out, int32_t* filtState);

void WebRtcSpl_UpsampleBy2(const int16_t* in, size_t len,
                           int16_t* out, int32_t* filtState);

/************************************************************
 * END OF RESAMPLING FUNCTIONS
 ************************************************************/
void WebRtcSpl_AnalysisQMF(const int16_t* in_data,
                           size_t in_data_length,
                           int16_t* low_band,
                           int16_t* high_band,
                           int32_t* filter_state1,
                           int32_t* filter_state2);
void WebRtcSpl_SynthesisQMF(const int16_t* low_band,
                            const int16_t* high_band,
                            size_t band_length,
                            int16_t* out_data,
                            int32_t* filter_state1,
                            int32_t* filter_state2);

#ifdef __cplusplus
}
#endif  // __cplusplus
#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_

//
// WebRtcSpl_AddSatW16(...)
// WebRtcSpl_AddSatW32(...)
//
// Returns the result of a saturated 16-bit, respectively 32-bit, addition of
// the numbers specified by the |var1| and |var2| parameters.
//
// Input:
//      - var1      : Input variable 1
//      - var2      : Input variable 2
//
// Return value     : Added and saturated value
//

//
// WebRtcSpl_SubSatW16(...)
// WebRtcSpl_SubSatW32(...)
//
// Returns the result of a saturated 16-bit, respectively 32-bit, subtraction
// of the numbers specified by the |var1| and |var2| parameters.
//
// Input:
//      - var1      : Input variable 1
//      - var2      : Input variable 2
//
// Returned value   : Subtracted and saturated value
//

//
// WebRtcSpl_GetSizeInBits(...)
//
// Returns the # of bits that are needed at the most to represent the number
// specified by the |value| parameter.
//
// Input:
//      - value     : Input value
//
// Return value     : Number of bits needed to represent |value|
//

//
// WebRtcSpl_NormW32(...)
//
// Norm returns the # of left shifts required to 32-bit normalize the 32-bit
// signed number specified by the |value| parameter.
//
// Input:
//      - value     : Input value
//
// Return value     : Number of bit shifts needed to 32-bit normalize |value|
//

//
// WebRtcSpl_NormW16(...)
//
// Norm returns the # of left shifts required to 16-bit normalize the 16-bit
// signed number specified by the |value| parameter.
//
// Input:
//      - value     : Input value
//
// Return value     : Number of bit shifts needed to 32-bit normalize |value|
//

//
// WebRtcSpl_NormU32(...)
//
// Norm returns the # of left shifts required to 32-bit normalize the unsigned
// 32-bit number specified by the |value| parameter.
//
// Input:
//      - value     : Input value
//
// Return value     : Number of bit shifts needed to 32-bit normalize |value|
//

//
// WebRtcSpl_GetScalingSquare(...)
//
// Returns the # of bits required to scale the samples specified in the
// |in_vector| parameter so that, if the squares of the samples are added the
// # of times specified by the |times| parameter, the 32-bit addition will not
// overflow (result in int32_t).
//
// Input:
//      - in_vector         : Input vector to check scaling on
//      - in_vector_length  : Samples in |in_vector|
//      - times             : Number of additions to be performed
//
// Return value             : Number of right bit shifts needed to avoid
//                            overflow in the addition calculation
//

//
// WebRtcSpl_MemSetW16(...)
//
// Sets all the values in the int16_t vector |vector| of length
// |vector_length| to the specified value |set_value|
//
// Input:
//      - vector        : Pointer to the int16_t vector
//      - set_value     : Value specified
//      - vector_length : Length of vector
//

//
// WebRtcSpl_MemSetW32(...)
//
// Sets all the values in the int32_t vector |vector| of length
// |vector_length| to the specified value |set_value|
//
// Input:
//      - vector        : Pointer to the int16_t vector
//      - set_value     : Value specified
//      - vector_length : Length of vector
//

//
// WebRtcSpl_MemCpyReversedOrder(...)
//
// Copies all the values from the source int16_t vector |in_vector| to a
// destination int16_t vector |out_vector|. It is done in reversed order,
// meaning that the first sample of |in_vector| is copied to the last sample of
// the |out_vector|. The procedure continues until the last sample of
// |in_vector| has been copied to the first sample of |out_vector|. This
// creates a reversed vector. Used in e.g. prediction in iLBC.
//
// Input:
//      - in_vector     : Pointer to the first sample in a int16_t vector
//                        of length |length|
//      - vector_length : Number of elements to copy
//
// Output:
//      - out_vector    : Pointer to the last sample in a int16_t vector
//                        of length |length|
//

//
// WebRtcSpl_CopyFromEndW16(...)
//
// Copies the rightmost |samples| of |in_vector| (of length |in_vector_length|)
// to the vector |out_vector|.
//
// Input:
//      - in_vector         : Input vector
//      - in_vector_length  : Number of samples in |in_vector|
//      - samples           : Number of samples to extract (from right side)
//                            from |in_vector|
//
// Output:
//      - out_vector        : Vector with the requested samples
//

//
// WebRtcSpl_ZerosArrayW16(...)
// WebRtcSpl_ZerosArrayW32(...)
//
// Inserts the value "zero" in all positions of a w16 and a w32 vector
// respectively.
//
// Input:
//      - vector_length : Number of samples in vector
//
// Output:
//      - vector        : Vector containing all zeros
//

//
// WebRtcSpl_VectorBitShiftW16(...)
// WebRtcSpl_VectorBitShiftW32(...)
//
// Bit shifts all the values in a vector up or downwards. Different calls for
// int16_t and int32_t vectors respectively.
//
// Input:
//      - vector_length : Length of vector
//      - in_vector     : Pointer to the vector that should be bit shifted
//      - right_shifts  : Number of right bit shifts (negative value gives left
//                        shifts)
//
// Output:
//      - out_vector    : Pointer to the result vector (can be the same as
//                        |in_vector|)
//

//
// WebRtcSpl_VectorBitShiftW32ToW16(...)
//
// Bit shifts all the values in a int32_t vector up or downwards and
// stores the result as an int16_t vector. The function will saturate the
// signal if needed, before storing in the output vector.
//
// Input:
//      - vector_length : Length of vector
//      - in_vector     : Pointer to the vector that should be bit shifted
//      - right_shifts  : Number of right bit shifts (negative value gives left
//                        shifts)
//
// Output:
//      - out_vector    : Pointer to the result vector (can be the same as
//                        |in_vector|)
//

//
// WebRtcSpl_ScaleVector(...)
//
// Performs the vector operation:
//  out_vector[k] = (gain*in_vector[k])>>right_shifts
//
// Input:
//      - in_vector     : Input vector
//      - gain          : Scaling gain
//      - vector_length : Elements in the |in_vector|
//      - right_shifts  : Number of right bit shifts applied
//
// Output:
//      - out_vector    : Output vector (can be the same as |in_vector|)
//

//
// WebRtcSpl_ScaleVectorWithSat(...)
//
// Performs the vector operation:
//  out_vector[k] = SATURATE( (gain*in_vector[k])>>right_shifts )
//
// Input:
//      - in_vector     : Input vector
//      - gain          : Scaling gain
//      - vector_length : Elements in the |in_vector|
//      - right_shifts  : Number of right bit shifts applied
//
// Output:
//      - out_vector    : Output vector (can be the same as |in_vector|)
//

//
// WebRtcSpl_ScaleAndAddVectors(...)
//
// Performs the vector operation:
//  out_vector[k] = (gain1*in_vector1[k])>>right_shifts1
//                  + (gain2*in_vector2[k])>>right_shifts2
//
// Input:
//      - in_vector1    : Input vector 1
//      - gain1         : Gain to be used for vector 1
//      - right_shifts1 : Right bit shift to be used for vector 1
//      - in_vector2    : Input vector 2
//      - gain2         : Gain to be used for vector 2
//      - right_shifts2 : Right bit shift to be used for vector 2
//      - vector_length : Elements in the input vectors
//
// Output:
//      - out_vector    : Output vector
//

//
// WebRtcSpl_ReverseOrderMultArrayElements(...)
//
// Performs the vector operation:
//  out_vector[n] = (in_vector[n]*window[-n])>>right_shifts
//
// Input:
//      - in_vector     : Input vector
//      - window        : Window vector (should be reversed). The pointer
//                        should be set to the last value in the vector
//      - right_shifts  : Number of right bit shift to be applied after the
//                        multiplication
//      - vector_length : Number of elements in |in_vector|
//
// Output:
//      - out_vector    : Output vector (can be same as |in_vector|)
//

//
// WebRtcSpl_ElementwiseVectorMult(...)
//
// Performs the vector operation:
//  out_vector[n] = (in_vector[n]*window[n])>>right_shifts
//
// Input:
//      - in_vector     : Input vector
//      - window        : Window vector.
//      - right_shifts  : Number of right bit shift to be applied after the
//                        multiplication
//      - vector_length : Number of elements in |in_vector|
//
// Output:
//      - out_vector    : Output vector (can be same as |in_vector|)
//

//
// WebRtcSpl_AddVectorsAndShift(...)
//
// Performs the vector operation:
//  out_vector[k] = (in_vector1[k] + in_vector2[k])>>right_shifts
//
// Input:
//      - in_vector1    : Input vector 1
//      - in_vector2    : Input vector 2
//      - right_shifts  : Number of right bit shift to be applied after the
//                        multiplication
//      - vector_length : Number of elements in |in_vector1| and |in_vector2|
//
// Output:
//      - out_vector    : Output vector (can be same as |in_vector1|)
//

//
// WebRtcSpl_AddAffineVectorToVector(...)
//
// Adds an affine transformed vector to another vector |out_vector|, i.e,
// performs
//  out_vector[k] += (in_vector[k]*gain+add_constant)>>right_shifts
//
// Input:
//      - in_vector     : Input vector
//      - gain          : Gain value, used to multiply the in vector with
//      - add_constant  : Constant value to add (usually 1<<(right_shifts-1),
//                        but others can be used as well
//      - right_shifts  : Number of right bit shifts (0-16)
//      - vector_length : Number of samples in |in_vector| and |out_vector|
//
// Output:
//      - out_vector    : Vector with the output
//

//
// WebRtcSpl_AffineTransformVector(...)
//
// Affine transforms a vector, i.e, performs
//  out_vector[k] = (in_vector[k]*gain+add_constant)>>right_shifts
//
// Input:
//      - in_vector     : Input vector
//      - gain          : Gain value, used to multiply the in vector with
//      - add_constant  : Constant value to add (usually 1<<(right_shifts-1),
//                        but others can be used as well
//      - right_shifts  : Number of right bit shifts (0-16)
//      - vector_length : Number of samples in |in_vector| and |out_vector|
//
// Output:
//      - out_vector    : Vector with the output
//

//
// WebRtcSpl_IncreaseSeed(...)
//
// Increases the seed (and returns the new value)
//
// Input:
//      - seed      : Seed for random calculation
//
// Output:
//      - seed      : Updated seed value
//
// Return value     : The new seed value
//

//
// WebRtcSpl_RandU(...)
//
// Produces a uniformly distributed value in the int16_t range
//
// Input:
//      - seed      : Seed for random calculation
//
// Output:
//      - seed      : Updated seed value
//
// Return value     : Uniformly distributed value in the range
//                    [Word16_MIN...Word16_MAX]
//

//
// WebRtcSpl_RandN(...)
//
// Produces a normal distributed value in the int16_t range
//
// Input:
//      - seed      : Seed for random calculation
//
// Output:
//      - seed      : Updated seed value
//
// Return value     : N(0,1) value in the Q13 domain
//

//
// WebRtcSpl_RandUArray(...)
//
// Produces a uniformly distributed vector with elements in the int16_t
// range
//
// Input:
//      - vector_length : Samples wanted in the vector
//      - seed          : Seed for random calculation
//
// Output:
//      - vector        : Vector with the uniform values
//      - seed          : Updated seed value
//
// Return value         : Number of samples in vector, i.e., |vector_length|
//

//
// WebRtcSpl_Sqrt(...)
//
// Returns the square root of the input value |value|. The precision of this
// function is integer precision, i.e., sqrt(8) gives 2 as answer.
// If |value| is a negative number then 0 is returned.
//
// Algorithm:
//
// A sixth order Taylor Series expansion is used here to compute the square
// root of a number y^0.5 = (1+x)^0.5
// where
// x = y-1
//   = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5)
// 0.5 <= x < 1
//
// Input:
//      - value     : Value to calculate sqrt of
//
// Return value     : Result of the sqrt calculation
//

//
// WebRtcSpl_SqrtFloor(...)
//
// Returns the square root of the input value |value|. The precision of this
// function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer.
// If |value| is a negative number then 0 is returned.
//
// Algorithm:
//
// An iterative 4 cylce/bit routine
//
// Input:
//      - value     : Value to calculate sqrt of
//
// Return value     : Result of the sqrt calculation
//

//
// WebRtcSpl_DivU32U16(...)
//
// Divides a uint32_t |num| by a uint16_t |den|.
//
// If |den|==0, (uint32_t)0xFFFFFFFF is returned.
//
// Input:
//      - num       : Numerator
//      - den       : Denominator
//
// Return value     : Result of the division (as a uint32_t), i.e., the
//                    integer part of num/den.
//

//
// WebRtcSpl_DivW32W16(...)
//
// Divides a int32_t |num| by a int16_t |den|.
//
// If |den|==0, (int32_t)0x7FFFFFFF is returned.
//
// Input:
//      - num       : Numerator
//      - den       : Denominator
//
// Return value     : Result of the division (as a int32_t), i.e., the
//                    integer part of num/den.
//

//
// WebRtcSpl_DivW32W16ResW16(...)
//
// Divides a int32_t |num| by a int16_t |den|, assuming that the
// result is less than 32768, otherwise an unpredictable result will occur.
//
// If |den|==0, (int16_t)0x7FFF is returned.
//
// Input:
//      - num       : Numerator
//      - den       : Denominator
//
// Return value     : Result of the division (as a int16_t), i.e., the
//                    integer part of num/den.
//

//
// WebRtcSpl_DivResultInQ31(...)
//
// Divides a int32_t |num| by a int16_t |den|, assuming that the
// absolute value of the denominator is larger than the numerator, otherwise
// an unpredictable result will occur.
//
// Input:
//      - num       : Numerator
//      - den       : Denominator
//
// Return value     : Result of the division in Q31.
//

//
// WebRtcSpl_DivW32HiLow(...)
//
// Divides a int32_t |num| by a denominator in hi, low format. The
// absolute value of the denominator has to be larger (or equal to) the
// numerator.
//
// Input:
//      - num       : Numerator
//      - den_hi    : High part of denominator
//      - den_low   : Low part of denominator
//
// Return value     : Divided value in Q31
//

//
// WebRtcSpl_Energy(...)
//
// Calculates the energy of a vector
//
// Input:
//      - vector        : Vector which the energy should be calculated on
//      - vector_length : Number of samples in vector
//
// Output:
//      - scale_factor  : Number of left bit shifts needed to get the physical
//                        energy value, i.e, to get the Q0 value
//
// Return value         : Energy value in Q(-|scale_factor|)
//

//
// WebRtcSpl_FilterAR(...)
//
// Performs a 32-bit AR filtering on a vector in Q12
//
// Input:
//  - ar_coef                   : AR-coefficient vector (values in Q12),
//                                ar_coef[0] must be 4096.
//  - ar_coef_length            : Number of coefficients in |ar_coef|.
//  - in_vector                 : Vector to be filtered.
//  - in_vector_length          : Number of samples in |in_vector|.
//  - filter_state              : Current state (higher part) of the filter.
//  - filter_state_length       : Length (in samples) of |filter_state|.
//  - filter_state_low          : Current state (lower part) of the filter.
//  - filter_state_low_length   : Length (in samples) of |filter_state_low|.
//  - out_vector_low_length     : Maximum length (in samples) of
//                                |out_vector_low|.
//
// Output:
//  - filter_state              : Updated state (upper part) vector.
//  - filter_state_low          : Updated state (lower part) vector.
//  - out_vector                : Vector containing the upper part of the
//                                filtered values.
//  - out_vector_low            : Vector containing the lower part of the
//                                filtered values.
//
// Return value                 : Number of samples in the |out_vector|.
//

//
// WebRtcSpl_ComplexIFFT(...)
//
// Complex Inverse FFT
//
// Computes an inverse complex 2^|stages|-point FFT on the input vector, which
// is in bit-reversed order. The original content of the vector is destroyed in
// the process, since the input is overwritten by the output, normal-ordered,
// FFT vector. With X as the input complex vector, y as the output complex
// vector and with M = 2^|stages|, the following is computed:
//
//        M-1
// y(k) = sum[X(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
//        i=0
//
// The implementations are optimized for speed, not for code size. It uses the
// decimation-in-time algorithm with radix-2 butterfly technique.
//
// Input:
//      - vector    : In pointer to complex vector containing 2^|stages|
//                    real elements interleaved with 2^|stages| imaginary
//                    elements.
//                    [ReImReImReIm....]
//                    The elements are in Q(-scale) domain, see more on Return
//                    Value below.
//
//      - stages    : Number of FFT stages. Must be at least 3 and at most 10,
//                    since the table WebRtcSpl_kSinTable1024[] is 1024
//                    elements long.
//
//      - mode      : This parameter gives the user to choose how the FFT
//                    should work.
//                    mode==0: Low-complexity and Low-accuracy mode
//                    mode==1: High-complexity and High-accuracy mode
//
// Output:
//      - vector    : Out pointer to the FFT vector (the same as input).
//
// Return Value     : The scale value that tells the number of left bit shifts
//                    that the elements in the |vector| should be shifted with
//                    in order to get Q0 values, i.e. the physically correct
//                    values. The scale parameter is always 0 or positive,
//                    except if N>1024 (|stages|>10), which returns a scale
//                    value of -1, indicating error.
//

//
// WebRtcSpl_ComplexFFT(...)
//
// Complex FFT
//
// Computes a complex 2^|stages|-point FFT on the input vector, which is in
// bit-reversed order. The original content of the vector is destroyed in
// the process, since the input is overwritten by the output, normal-ordered,
// FFT vector. With x as the input complex vector, Y as the output complex
// vector and with M = 2^|stages|, the following is computed:
//
//              M-1
// Y(k) = 1/M * sum[x(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
//              i=0
//
// The implementations are optimized for speed, not for code size. It uses the
// decimation-in-time algorithm with radix-2 butterfly technique.
//
// This routine prevents overflow by scaling by 2 before each FFT stage. This is
// a fixed scaling, for proper normalization - there will be log2(n) passes, so
// this results in an overall factor of 1/n, distributed to maximize arithmetic
// accuracy.
//
// Input:
//      - vector    : In pointer to complex vector containing 2^|stages| real
//                    elements interleaved with 2^|stages| imaginary elements.
//                    [ReImReImReIm....]
//                    The output is in the Q0 domain.
//
//      - stages    : Number of FFT stages. Must be at least 3 and at most 10,
//                    since the table WebRtcSpl_kSinTable1024[] is 1024
//                    elements long.
//
//      - mode      : This parameter gives the user to choose how the FFT
//                    should work.
//                    mode==0: Low-complexity and Low-accuracy mode
//                    mode==1: High-complexity and High-accuracy mode
//
// Output:
//      - vector    : The output FFT vector is in the Q0 domain.
//
// Return value     : The scale parameter is always 0, except if N>1024,
//                    which returns a scale value of -1, indicating error.
//

//
// WebRtcSpl_AnalysisQMF(...)
//
// Splits a 0-2*F Hz signal into two sub bands: 0-F Hz and F-2*F Hz. The
// current version has F = 8000, therefore, a super-wideband audio signal is
// split to lower-band 0-8 kHz and upper-band 8-16 kHz.
//
// Input:
//      - in_data       : Wide band speech signal, 320 samples (10 ms)
//
// Input & Output:
//      - filter_state1 : Filter state for first All-pass filter
//      - filter_state2 : Filter state for second All-pass filter
//
// Output:
//      - low_band      : Lower-band signal 0-8 kHz band, 160 samples (10 ms)
//      - high_band     : Upper-band signal 8-16 kHz band (flipped in frequency
//                        domain), 160 samples (10 ms)
//

//
// WebRtcSpl_SynthesisQMF(...)
//
// Combines the two sub bands (0-F and F-2*F Hz) into a signal of 0-2*F
// Hz, (current version has F = 8000 Hz). So the filter combines lower-band
// (0-8 kHz) and upper-band (8-16 kHz) channels to obtain super-wideband 0-16
// kHz audio.
//
// Input:
//      - low_band      : The signal with the 0-8 kHz band, 160 samples (10 ms)
//      - high_band     : The signal with the 8-16 kHz band, 160 samples (10 ms)
//
// Input & Output:
//      - filter_state1 : Filter state for first All-pass filter
//      - filter_state2 : Filter state for second All-pass filter
//
// Output:
//      - out_data      : Super-wideband speech signal, 0-16 kHz
//

// int16_t WebRtcSpl_SatW32ToW16(...)
//
// This function saturates a 32-bit word into a 16-bit word.
//
// Input:
//      - value32   : The value of a 32-bit word.
//
// Output:
//      - out16     : the saturated 16-bit word.
//

// int32_t WebRtc_MulAccumW16(...)
//
// This function multiply a 16-bit word by a 16-bit word, and accumulate this
// value to a 32-bit integer.
//
// Input:
//      - a    : The value of the first 16-bit word.
//      - b    : The value of the second 16-bit word.
//      - c    : The value of an 32-bit integer.
//
// Return Value: The value of a * b + c.
//


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/include/spl_inl.h
================================================
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


// This header file includes the inline functions in
// the fix point signal processing library.

#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_
#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_

#include "rtc_base/compile_assert_c.h"

extern const int8_t kWebRtcSpl_CountLeadingZeros32_Table[64];

// Don't call this directly except in tests!
static __inline int WebRtcSpl_CountLeadingZeros32_NotBuiltin(uint32_t n) {
  // Normalize n by rounding up to the nearest number that is a sequence of 0
  // bits followed by a sequence of 1 bits. This number has the same number of
  // leading zeros as the original n. There are exactly 33 such values.
  n |= n >> 1;
  n |= n >> 2;
  n |= n >> 4;
  n |= n >> 8;
  n |= n >> 16;

  // Multiply the modified n with a constant selected (by exhaustive search)
  // such that each of the 33 possible values of n give a product whose 6 most
  // significant bits are unique. Then look up the answer in the table.
  return kWebRtcSpl_CountLeadingZeros32_Table[(n * 0x8c0b2891) >> 26];
}

// Don't call this directly except in tests!
static __inline int WebRtcSpl_CountLeadingZeros64_NotBuiltin(uint64_t n) {
  const int leading_zeros = n >> 32 == 0 ? 32 : 0;
  return leading_zeros + WebRtcSpl_CountLeadingZeros32_NotBuiltin(
                             (uint32_t)(n >> (32 - leading_zeros)));
}

// Returns the number of leading zero bits in the argument.
static __inline int WebRtcSpl_CountLeadingZeros32(uint32_t n) {
#ifdef __GNUC__
  RTC_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t));
  return n == 0 ? 32 : __builtin_clz(n);
#else
  return WebRtcSpl_CountLeadingZeros32_NotBuiltin(n);
#endif
}

// Returns the number of leading zero bits in the argument.
static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) {
#ifdef __GNUC__
  RTC_COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t));  // NOLINT
  return n == 0 ? 64 : __builtin_clzll(n);
#else
  return WebRtcSpl_CountLeadingZeros64_NotBuiltin(n);
#endif
}

#ifdef WEBRTC_ARCH_ARM_V7
#include "common_audio/signal_processing/include/spl_inl_armv7.h"
#else

#if defined(MIPS32_LE)
#include "common_audio/signal_processing/include/spl_inl_mips.h"
#endif

#if !defined(MIPS_DSP_R1_LE)
static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
  int16_t out16 = (int16_t) value32;

  if (value32 > 32767)
    out16 = 32767;
  else if (value32 < -32768)
    out16 = -32768;

  return out16;
}

static __inline int32_t WebRtcSpl_AddSatW32(int32_t a, int32_t b) {
  // Do the addition in unsigned numbers, since signed overflow is undefined
  // behavior.
  const int32_t sum = (int32_t)((uint32_t)a + (uint32_t)b);

  // a + b can't overflow if a and b have different signs. If they have the
  // same sign, a + b also has the same sign iff it didn't overflow.
  if ((a < 0) == (b < 0) && (a < 0) != (sum < 0)) {
    // The direction of the overflow is obvious from the sign of a + b.
    return sum < 0 ? INT32_MAX : INT32_MIN;
  }
  return sum;
}

static __inline int32_t WebRtcSpl_SubSatW32(int32_t a, int32_t b) {
  // Do the subtraction in unsigned numbers, since signed overflow is undefined
  // behavior.
  const int32_t diff = (int32_t)((uint32_t)a - (uint32_t)b);

  // a - b can't overflow if a and b have the same sign. If they have different
  // signs, a - b has the same sign as a iff it didn't overflow.
  if ((a < 0) != (b < 0) && (a < 0) != (diff < 0)) {
    // The direction of the overflow is obvious from the sign of a - b.
    return diff < 0 ? INT32_MAX : INT32_MIN;
  }
  return diff;
}

static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
  return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b);
}

static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
  return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2);
}
#endif  // #if !defined(MIPS_DSP_R1_LE)

#if !defined(MIPS32_LE)
static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
  return 32 - WebRtcSpl_CountLeadingZeros32(n);
}

// Return the number of steps a can be left-shifted without overflow,
// or 0 if a == 0.
static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
  return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a < 0 ? ~a : a) - 1;
}

// Return the number of steps a can be left-shifted without overflow,
// or 0 if a == 0.
static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
  return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a);
}

// Return the number of steps a can be left-shifted without overflow,
// or 0 if a == 0.
static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
  const int32_t a32 = a;
  return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a < 0 ? ~a32 : a32) - 17;
}

static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
  return (a * b + c);
}
#endif  // #if !defined(MIPS32_LE)

#endif  // WEBRTC_ARCH_ARM_V7

#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h
================================================
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/* This header file includes the inline functions for ARM processors in
 * the fix point signal processing library.
 */

#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_
#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_

/* TODO(kma): Replace some assembly code with GCC intrinsics
 * (e.g. __builtin_clz).
 */

/* This function produces result that is not bit exact with that by the generic
 * C version in some cases, although the former is at least as accurate as the
 * later.
 */
static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) {
  int32_t tmp = 0;
  __asm __volatile ("smulwb %0, %1, %2":"=r"(tmp):"r"(b), "r"(a));
  return tmp;
}

static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) {
  int32_t tmp = 0;
  __asm __volatile ("smulbb %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
  return tmp;
}

// TODO(kma): add unit test.
static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
  int32_t tmp = 0;
  __asm __volatile ("smlabb %0, %1, %2, %3":"=r"(tmp):"r"(a), "r"(b), "r"(c));
  return tmp;
}

static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
  int32_t s_sum = 0;

  __asm __volatile ("qadd16 %0, %1, %2":"=r"(s_sum):"r"(a), "r"(b));

  return (int16_t) s_sum;
}

static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
  int32_t l_sum = 0;

  __asm __volatile ("qadd %0, %1, %2":"=r"(l_sum):"r"(l_var1), "r"(l_var2));

  return l_sum;
}

static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
  int32_t l_sub = 0;

  __asm __volatile ("qsub %0, %1, %2":"=r"(l_sub):"r"(l_var1), "r"(l_var2));

  return l_sub;
}

static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
  int32_t s_sub = 0;

  __asm __volatile ("qsub16 %0, %1, %2":"=r"(s_sub):"r"(var1), "r"(var2));

  return (int16_t)s_sub;
}

static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
  int32_t tmp = 0;

  __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(n));

  return (int16_t)(32 - tmp);
}

static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
  int32_t tmp = 0;

  if (a == 0) {
    return 0;
  } else if (a < 0) {
    a ^= 0xFFFFFFFF;
  }

  __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));

  return (int16_t)(tmp - 1);
}

static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
  int tmp = 0;

  if (a == 0) return 0;

  __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));

  return (int16_t)tmp;
}

static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
  int32_t tmp = 0;
  int32_t a_32 = a;

  if (a_32 == 0) {
    return 0;
  } else if (a_32 < 0) {
    a_32 ^= 0xFFFFFFFF;
  }

  __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a_32));

  return (int16_t)(tmp - 17);
}

// TODO(kma): add unit test.
static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
  int32_t out = 0;

  __asm __volatile ("ssat %0, #16, %1" : "=r"(out) : "r"(value32));

  return (int16_t)out;
}

#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_mips.h
================================================
/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


// This header file includes the inline functions in
// the fix point signal processing library.

#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_
#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_

static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a,
                                             int32_t b) {
  int32_t value32 = 0;
  int32_t a1 = 0, b1 = 0;

  __asm __volatile(
#if defined(MIPS32_R2_LE)
    "seh    %[a1],          %[a]                \n\t"
    "seh    %[b1],          %[b]                \n\t"
#else
    "sll    %[a1],          %[a],         16    \n\t"
    "sll    %[b1],          %[b],         16    \n\t"
    "sra    %[a1],          %[a1],        16    \n\t"
    "sra    %[b1],          %[b1],        16    \n\t"
#endif
    "mul    %[value32],     %[a1],  %[b1]       \n\t"
    : [value32] "=r" (value32), [a1] "=&r" (a1), [b1] "=&r" (b1)
    : [a] "r" (a), [b] "r" (b)
    : "hi", "lo");
  return value32;
}

static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a,
                                                    int32_t b) {
  int32_t value32 = 0, b1 = 0, b2 = 0;
  int32_t a1 = 0;

  __asm __volatile(
#if defined(MIPS32_R2_LE)
    "seh    %[a1],          %[a]                        \n\t"
#else
    "sll    %[a1],          %[a],           16          \n\t"
    "sra    %[a1],          %[a1],          16          \n\t"
#endif
    "andi   %[b2],          %[b],           0xFFFF      \n\t"
    "sra    %[b1],          %[b],           16          \n\t"
    "sra    %[b2],          %[b2],          1           \n\t"
    "mul    %[value32],     %[a1],          %[b1]       \n\t"
    "mul    %[b2],          %[a1],          %[b2]       \n\t"
    "addiu  %[b2],          %[b2],          0x4000      \n\t"
    "sra    %[b2],          %[b2],          15          \n\t"
    "addu   %[value32],     %[value32],     %[b2]       \n\t"
    : [value32] "=&r" (value32), [b1] "=&r" (b1), [b2] "=&r" (b2),
      [a1] "=&r" (a1)
    : [a] "r" (a), [b] "r" (b)
    : "hi", "lo");
  return value32;
}

#if defined(MIPS_DSP_R1_LE)
static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
  __asm __volatile(
    "shll_s.w   %[value32], %[value32], 16      \n\t"
    "sra        %[value32], %[value32], 16      \n\t"
    : [value32] "+r" (value32)
    :);
  int16_t out16 = (int16_t)value32;
  return out16;
}

static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
  int32_t value32 = 0;

  __asm __volatile(
    "addq_s.ph      %[value32],     %[a],   %[b]    \n\t"
    : [value32] "=r" (value32)
    : [a] "r" (a), [b] "r" (b) );
  return (int16_t)value32;
}

static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
  int32_t l_sum;

  __asm __volatile(
    "addq_s.w   %[l_sum],       %[l_var1],      %[l_var2]    \n\t"
    : [l_sum] "=r" (l_sum)
    : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) );

  return l_sum;
}

static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
  int32_t value32;

  __asm __volatile(
    "subq_s.ph  %[value32], %[var1],    %[var2]     \n\t"
    : [value32] "=r" (value32)
    : [var1] "r" (var1), [var2] "r" (var2) );

  return (int16_t)value32;
}

static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
  int32_t l_diff;

  __asm __volatile(
    "subq_s.w   %[l_diff],      %[l_var1],      %[l_var2]    \n\t"
    : [l_diff] "=r" (l_diff)
    : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) );

  return l_diff;
}
#endif

static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
  int bits = 0;
  int i32 = 32;

  __asm __volatile(
    "clz    %[bits],    %[n]                    \n\t"
    "subu   %[bits],    %[i32],     %[bits]     \n\t"
    : [bits] "=&r" (bits)
    : [n] "r" (n), [i32] "r" (i32) );

  return (int16_t)bits;
}

static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
  int zeros = 0;

  __asm __volatile(
    ".set       push                                \n\t"
    ".set       noreorder                           \n\t"
    "bnez       %[a],       1f                      \n\t"
    " sra       %[zeros],   %[a],       31          \n\t"
    "b          2f                                  \n\t"
    " move      %[zeros],   $zero                   \n\t"
   "1:                                              \n\t"
    "xor        %[zeros],   %[a],       %[zeros]    \n\t"
    "clz        %[zeros],   %[zeros]                \n\t"
    "addiu      %[zeros],   %[zeros],   -1          \n\t"
   "2:                                              \n\t"
    ".set       pop                                 \n\t"
    : [zeros]"=&r"(zeros)
    : [a] "r" (a) );

  return (int16_t)zeros;
}

static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
  int zeros = 0;

  __asm __volatile(
    "clz    %[zeros],   %[a]    \n\t"
    : [zeros] "=r" (zeros)
    : [a] "r" (a) );

  return (int16_t)(zeros & 0x1f);
}

static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
  int zeros = 0;
  int a0 = a << 16;

  __asm __volatile(
    ".set       push                                \n\t"
    ".set       noreorder                           \n\t"
    "bnez       %[a0],      1f                      \n\t"
    " sra       %[zeros],   %[a0],      31          \n\t"
    "b          2f                                  \n\t"
    " move      %[zeros],   $zero                   \n\t"
   "1:                                              \n\t"
    "xor        %[zeros],   %[a0],      %[zeros]    \n\t"
    "clz        %[zeros],   %[zeros]                \n\t"
    "addiu      %[zeros],   %[zeros],   -1          \n\t"
   "2:                                              \n\t"
    ".set       pop                                 \n\t"
    : [zeros]"=&r"(zeros)
    : [a0] "r" (a0) );

  return (int16_t)zeros;
}

static __inline int32_t WebRtc_MulAccumW16(int16_t a,
                                           int16_t b,
                                           int32_t c) {
  int32_t res = 0, c1 = 0;
  __asm __volatile(
#if defined(MIPS32_R2_LE)
    "seh    %[a],       %[a]            \n\t"
    "seh    %[b],       %[b]            \n\t"
#else
    "sll    %[a],       %[a],   16      \n\t"
    "sll    %[b],       %[b],   16      \n\t"
    "sra    %[a],       %[a],   16      \n\t"
    "sra    %[b],       %[b],   16      \n\t"
#endif
    "mul    %[res],     %[a],   %[b]    \n\t"
    "addu   %[c1],      %[c],   %[res]  \n\t"
    : [c1] "=r" (c1), [res] "=&r" (res)
    : [a] "r" (a), [b] "r" (b), [c] "r" (c)
    : "hi", "lo");
  return (c1);
}

#endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/min_max_operations.c
================================================
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

/*
 * This file contains the implementation of functions
 * WebRtcSpl_MaxAbsValueW16C()
 * WebRtcSpl_MaxAbsValueW32C()
 * WebRtcSpl_MaxValueW16C()
 * WebRtcSpl_MaxValueW32C()
 * WebRtcSpl_MinValueW16C()
 * WebRtcSpl_MinValueW32C()
 * WebRtcSpl_MaxAbsIndexW16()
 * WebRtcSpl_MaxIndexW16()
 * WebRtcSpl_MaxIndexW32()
 * WebRtcSpl_MinIndexW16()
 * WebRtcSpl_MinIndexW32()
 *
 */

#include <stdlib.h>

#include "rtc_base/checks.h"
#include "common_audio/signal_processing/include/signal_processing_library.h"

// TODO(bjorn/kma): Consolidate function pairs (e.g. combine
//   WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.)
// TODO(kma): Move the next six functions into min_max_operations_c.c.

// Maximum absolute value of word16 vector. C version for generic platforms.
int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) {
  size_t i = 0;
  int absolute = 0, maximum = 0;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    absolute = abs((int)vector[i]);

    if (absolute > maximum) {
      maximum = absolute;
    }
  }

  // Guard the case for abs(-32768).
  if (maximum > WEBRTC_SPL_WORD16_MAX) {
    maximum = WEBRTC_SPL_WORD16_MAX;
  }

  return (int16_t)maximum;
}

// Maximum absolute value of word32 vector. C version for generic platforms.
int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {
  // Use uint32_t for the local variables, to accommodate the return value
  // of abs(0x80000000), which is 0x80000000.

  uint32_t absolute = 0, maximum = 0;
  size_t i = 0;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    absolute = abs((int)vector[i]);
    if (absolute > maximum) {
      maximum = absolute;
    }
  }

  maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX);

  return (int32_t)maximum;
}

// Maximum value of word16 vector. C version for generic platforms.
int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) {
  int16_t maximum = WEBRTC_SPL_WORD16_MIN;
  size_t i = 0;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] > maximum)
      maximum = vector[i];
  }
  return maximum;
}

// Maximum value of word32 vector. C version for generic platforms.
int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) {
  int32_t maximum = WEBRTC_SPL_WORD32_MIN;
  size_t i = 0;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] > maximum)
      maximum = vector[i];
  }
  return maximum;
}

// Minimum value of word16 vector. C version for generic platforms.
int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) {
  int16_t minimum = WEBRTC_SPL_WORD16_MAX;
  size_t i = 0;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] < minimum)
      minimum = vector[i];
  }
  return minimum;
}

// Minimum value of word32 vector. C version for generic platforms.
int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {
  int32_t minimum = WEBRTC_SPL_WORD32_MAX;
  size_t i = 0;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] < minimum)
      minimum = vector[i];
  }
  return minimum;
}

// Index of maximum absolute value in a word16 vector.
size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
  // Use type int for local variables, to accomodate the value of abs(-32768).

  size_t i = 0, index = 0;
  int absolute = 0, maximum = 0;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    absolute = abs((int)vector[i]);

    if (absolute > maximum) {
      maximum = absolute;
      index = i;
    }
  }

  return index;
}

// Index of maximum value in a word16 vector.
size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
  size_t i = 0, index = 0;
  int16_t maximum = WEBRTC_SPL_WORD16_MIN;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] > maximum) {
      maximum = vector[i];
      index = i;
    }
  }

  return index;
}

// Index of maximum value in a word32 vector.
size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
  size_t i = 0, index = 0;
  int32_t maximum = WEBRTC_SPL_WORD32_MIN;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] > maximum) {
      maximum = vector[i];
      index = i;
    }
  }

  return index;
}

// Index of minimum value in a word16 vector.
size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
  size_t i = 0, index = 0;
  int16_t minimum = WEBRTC_SPL_WORD16_MAX;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] < minimum) {
      minimum = vector[i];
      index = i;
    }
  }

  return index;
}

// Index of minimum value in a word32 vector.
size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {
  size_t i = 0, index = 0;
  int32_t minimum = WEBRTC_SPL_WORD32_MAX;

  RTC_DCHECK_GT(length, 0);

  for (i = 0; i < length; i++) {
    if (vector[i] < minimum) {
      minimum = vector[i];
      index = i;
    }
  }

  return index;
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/min_max_operations_mips.c.mips
================================================
/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

/*
 * This file contains the implementation of function
 * WebRtcSpl_MaxAbsValueW16()
 *
 * The description header can be found in signal_processing_library.h.
 *
 */

#include "rtc_base/checks.h"
#include "common_audio/signal_processing/include/signal_processing_library.h"

// Maximum absolute value of word16 vector.
int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length) {
  int32_t totMax = 0;
  int32_t tmp32_0, tmp32_1, tmp32_2, tmp32_3;
  size_t i, loop_size;

  RTC_DCHECK_GT(length, 0);

#if defined(MIPS_DSP_R1)
  const int32_t* tmpvec32 = (int32_t*)vector;
  loop_size = length >> 4;

  for (i = 0; i < loop_size; i++) {
    __asm__ volatile (
      "lw         %[tmp32_0],     0(%[tmpvec32])              \n\t"
      "lw         %[tmp32_1],     4(%[tmpvec32])              \n\t"
      "lw         %[tmp32_2],     8(%[tmpvec32])              \n\t"
      "lw         %[tmp32_3],     12(%[tmpvec32])             \n\t"

      "absq_s.ph  %[tmp32_0],     %[tmp32_0]                  \n\t"
      "absq_s.ph  %[tmp32_1],     %[tmp32_1]                  \n\t"
      "cmp.lt.ph  %[totMax],      %[tmp32_0]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_0],     %[totMax]   \n\t"

      "lw         %[tmp32_0],     16(%[tmpvec32])             \n\t"
      "absq_s.ph  %[tmp32_2],     %[tmp32_2]                  \n\t"
      "cmp.lt.ph  %[totMax],      %[tmp32_1]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_1],     %[totMax]   \n\t"

      "lw         %[tmp32_1],     20(%[tmpvec32])             \n\t"
      "absq_s.ph  %[tmp32_3],     %[tmp32_3]                  \n\t"
      "cmp.lt.ph  %[totMax],      %[tmp32_2]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_2],     %[totMax]   \n\t"

      "lw         %[tmp32_2],     24(%[tmpvec32])             \n\t"
      "cmp.lt.ph  %[totMax],      %[tmp32_3]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_3],     %[totMax]   \n\t"

      "lw         %[tmp32_3],     28(%[tmpvec32])             \n\t"
      "absq_s.ph  %[tmp32_0],     %[tmp32_0]                  \n\t"
      "absq_s.ph  %[tmp32_1],     %[tmp32_1]                  \n\t"
      "cmp.lt.ph  %[totMax],      %[tmp32_0]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_0],     %[totMax]   \n\t"

      "absq_s.ph  %[tmp32_2],     %[tmp32_2]                  \n\t"
      "cmp.lt.ph  %[totMax],      %[tmp32_1]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_1],     %[totMax]   \n\t"
      "absq_s.ph  %[tmp32_3],     %[tmp32_3]                  \n\t"
      "cmp.lt.ph  %[totMax],      %[tmp32_2]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_2],     %[totMax]   \n\t"

      "cmp.lt.ph  %[totMax],      %[tmp32_3]                  \n\t"
      "pick.ph    %[totMax],      %[tmp32_3],     %[totMax]   \n\t"

      "addiu      %[tmpvec32],    %[tmpvec32],    32          \n\t"
      : [tmp32_0] "=&r" (tmp32_0), [tmp32_1] "=&r" (tmp32_1),
        [tmp32_2] "=&r" (tmp32_2), [tmp32_3] "=&r" (tmp32_3),
        [totMax] "+r" (totMax), [tmpvec32] "+r" (tmpvec32)
      :
      : "memory"
    );
  }
  __asm__ volatile (
    "rotr       %[tmp32_0],     %[totMax],      16          \n\t"
    "cmp.lt.ph  %[totMax],      %[tmp32_0]                  \n\t"
    "pick.ph    %[totMax],      %[tmp32_0],     %[totMax]   \n\t"
    "packrl.ph  %[totMax],      $0,             %[totMax]   \n\t"
    : [tmp32_0] "=&r" (tmp32_0), [totMax] "+r" (totMax)
    :
  );
  loop_size = length & 0xf;
  for (i = 0; i < loop_size; i++) {
    __asm__ volatile (
      "lh         %[tmp32_0],     0(%[tmpvec32])              \n\t"
      "addiu      %[tmpvec32],    %[tmpvec32],     2          \n\t"
      "absq_s.w   %[tmp32_0],     %[tmp32_0]                  \n\t"
      "slt        %[tmp32_1],     %[totMax],       %[tmp32_0] \n\t"
      "movn       %[totMax],      %[tmp32_0],      %[tmp32_1] \n\t"
      : [tmp32_0] "=&r" (tmp32_0), [tmp32_1] "=&r" (tmp32_1),
        [tmpvec32] "+r" (tmpvec32), [totMax] "+r" (totMax)
      :
      : "memory"
    );
  }
#else  // #if defined(MIPS_DSP_R1)
  int32_t v16MaxMax = WEBRTC_SPL_WORD16_MAX;
  int32_t r, r1, r2, r3;
  const int16_t* tmpvector = vector;
  loop_size = length >> 4;
  for (i = 0; i < loop_size; i++) {
    __asm__ volatile (
      "lh     %[tmp32_0],     0(%[tmpvector])                 \n\t"
      "lh     %[tmp32_1],     2(%[tmpvector])                 \n\t"
      "lh     %[tmp32_2],     4(%[tmpvector])                 \n\t"
      "lh     %[tmp32_3],     6(%[tmpvector])                 \n\t"

      "abs    %[tmp32_0],     %[tmp32_0]                      \n\t"
      "abs    %[tmp32_1],     %[tmp32_1]                      \n\t"
      "abs    %[tmp32_2],     %[tmp32_2]                      \n\t"
      "abs    %[tmp32_3],     %[tmp32_3]                      \n\t"

      "slt    %[r],           %[totMax],      %[tmp32_0]      \n\t"
      "movn   %[totMax],      %[tmp32_0],     %[r]            \n\t"
      "slt    %[r1],          %[totMax],      %[tmp32_1]      \n\t"
      "movn   %[totMax],      %[tmp32_1],     %[r1]           \n\t"
      "slt    %[r2],          %[totMax],      %[tmp32_2]      \n\t"
      "movn   %[totMax],      %[tmp32_2],     %[r2]           \n\t"
      "slt    %[r3],          %[totMax],      %[tmp32_3]      \n\t"
      "movn   %[totMax],      %[tmp32_3],     %[r3]           \n\t"

      "lh     %[tmp32_0],     8(%[tmpvector])                 \n\t"
      "lh     %[tmp32_1],     10(%[tmpvector])                \n\t"
      "lh     %[tmp32_2],     12(%[tmpvector])                \n\t"
      "lh     %[tmp32_3],     14(%[tmpvector])                \n\t"

      "abs    %[tmp32_0],     %[tmp32_0]                      \n\t"
      "abs    %[tmp32_1],     %[tmp32_1]                      \n\t"
      "abs    %[tmp32_2],     %[tmp32_2]                      \n\t"
      "abs    %[tmp32_3],     %[tmp32_3]                      \n\t"

      "slt    %[r],           %[totMax],      %[tmp32_0]      \n\t"
      "movn   %[totMax],      %[tmp32_0],     %[r]            \n\t"
      "slt    %[r1],          %[totMax],      %[tmp32_1]      \n\t"
      "movn   %[totMax],      %[tmp32_1],     %[r1]           \n\t"
      "slt    %[r2],          %[totMax],      %[tmp32_2]      \n\t"
      "movn   %[totMax],      %[tmp32_2],     %[r2]           \n\t"
      "slt    %[r3],          %[totMax],      %[tmp32_3]      \n\t"
      "movn   %[totMax],      %[tmp32_3],     %[r3]           \n\t"

      "lh     %[tmp32_0],     16(%[tmpvector])                \n\t"
      "lh     %[tmp32_1],     18(%[tmpvector])                \n\t"
      "lh     %[tmp32_2],     20(%[tmpvector])                \n\t"
      "lh     %[tmp32_3],     22(%[tmpvector])                \n\t"

      "abs    %[tmp32_0],     %[tmp32_0]                      \n\t"
      "abs    %[tmp32_1],     %[tmp32_1]                      \n\t"
      "abs    %[tmp32_2],     %[tmp32_2]                      \n\t"
      "abs    %[tmp32_3],     %[tmp32_3]                      \n\t"

      "slt    %[r],           %[totMax],      %[tmp32_0]      \n\t"
      "movn   %[totMax],      %[tmp32_0],     %[r]            \n\t"
      "slt    %[r1],          %[totMax],      %[tmp32_1]      \n\t"
      "movn   %[totMax],      %[tmp32_1],     %[r1]           \n\t"
      "slt    %[r2],          %[totMax],      %[tmp32_2]      \n\t"
      "movn   %[totMax],      %[tmp32_2],     %[r2]           \n\t"
      "slt    %[r3],          %[totMax],      %[tmp32_3]      \n\t"
      "movn   %[totMax],      %[tmp32_3],     %[r3]           \n\t"

      "lh     %[tmp32_0],     24(%[tmpvector])                \n\t"
      "lh     %[tmp32_1],     26(%[tmpvector])                \n\t"
      "lh     %[tmp32_2],     28(%[tmpvector])                \n\t"
      "lh     %[tmp32_3],     30(%[tmpvector])                \n\t"

      "abs    %[tmp32_0],     %[tmp32_0]                      \n\t"
      "abs    %[tmp32_1],     %[tmp32_1]                      \n\t"
      "abs    %[tmp32_2],     %[tmp32_2]                      \n\t"
      "abs    %[tmp32_3],     %[tmp32_3]                      \n\t"

      "slt    %[r],           %[totMax],      %[tmp32_0]      \n\t"
      "movn   %[totMax],      %[tmp32_0],     %[r]            \n\t"
      "slt    %[r1],          %[totMax],      %[tmp32_1]      \n\t"
      "movn   %[totMax],      %[tmp32_1],     %[r1]           \n\t"
      "slt    %[r2],          %[totMax],      %[tmp32_2]      \n\t"
      "movn   %[totMax],      %[tmp32_2],     %[r2]           \n\t"
      "slt    %[r3],          %[totMax],      %[tmp32_3]      \n\t"
      "movn   %[totMax],      %[tmp32_3],     %[r3]           \n\t"

      "addiu  %[tmpvector],   %[tmpvector],   32              \n\t"
      : [tmp32_0] "=&r" (tmp32_0), [tmp32_1] "=&r" (tmp32_1),
        [tmp32_2] "=&r" (tmp32_2), [tmp32_3] "=&r" (tmp32_3),
        [totMax] "+r" (totMax), [r] "=&r" (r), [tmpvector] "+r" (tmpvector),
        [r1] "=&r" (r1), [r2] "=&r" (r2), [r3] "=&r" (r3)
      :
      : "memory"
    );
  }
  loop_size = length & 0xf;
  for (i = 0; i < loop_size; i++) {
    __asm__ volatile (
      "lh         %[tmp32_0],     0(%[tmpvector])             \n\t"
      "addiu      %[tmpvector],   %[tmpvector],    2          \n\t"
      "abs        %[tmp32_0],     %[tmp32_0]                  \n\t"
      "slt        %[tmp32_1],     %[totMax],       %[tmp32_0] \n\t"
      "movn       %[totMax],      %[tmp32_0],      %[tmp32_1] \n\t"
      : [tmp32_0] "=&r" (tmp32_0), [tmp32_1] "=&r" (tmp32_1),
        [tmpvector] "+r" (tmpvector), [totMax] "+r" (totMax)
      :
      : "memory"
    );
  }

  __asm__ volatile (
    "slt    %[r],       %[v16MaxMax],   %[totMax]   \n\t"
    "movn   %[totMax],  %[v16MaxMax],   %[r]        \n\t"
    : [totMax] "+r" (totMax), [r] "=&r" (r)
    : [v16MaxMax] "r" (v16MaxMax)
  );
#endif  // #if defined(MIPS_DSP_R1)
  return (int16_t)totMax;
}

#if defined(MIPS_DSP_R1_LE)
// Maximum absolute value of word32 vector. Version for MIPS platform.
int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length) {
  // Use uint32_t for the local variables, to accommodate the return value
  // of abs(0x80000000), which is 0x80000000.

  uint32_t absolute = 0, maximum = 0;
  int tmp1 = 0, max_value = 0x7fffffff;

  RTC_DCHECK_GT(length, 0);

  __asm__ volatile (
    ".set push                                                        \n\t"
    ".set noreorder                                                   \n\t"

   "1:                                                                \n\t"
    "lw         %[absolute],      0(%[vector])                        \n\t"
    "absq_s.w   %[absolute],      %[absolute]                         \n\t"
    "addiu      %[length],        %[length],          -1              \n\t"
    "slt        %[tmp1],          %[maximum],         %[absolute]     \n\t"
    "movn       %[maximum],       %[absolute],        %[tmp1]         \n\t"
    "bgtz       %[length],        1b                                  \n\t"
    " addiu     %[vector],        %[vector],          4               \n\t"
    "slt        %[tmp1],          %[max_value],       %[maximum]      \n\t"
    "movn       %[maximum],       %[max_value],       %[tmp1]         \n\t"

    ".set pop                                                         \n\t"

    : [tmp1] "=&r" (tmp1), [maximum] "+r" (maximum), [absolute] "+r" (absolute)
    : [vector] "r" (vector), [length] "r" (length), [max_value] "r" (max_value)
    : "memory"
  );

  return (int32_t)maximum;
}
#endif  // #if defined(MIPS_DSP_R1_LE)

// Maximum value of word16 vector. Version for MIPS platform.
int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length) {
  int16_t maximum = WEBRTC_SPL_WORD16_MIN;
  int tmp1;
  int16_t value;

  RTC_DCHECK_GT(length, 0);

  __asm__ volatile (
    ".set push                                                        \n\t"
    ".set noreorder                                                   \n\t"

   "1:                                                                \n\t"
    "lh         %[value],         0(%[vector])                        \n\t"
    "addiu      %[length],        %[length],          -1              \n\t"
    "slt        %[tmp1],          %[maximum],         %[value]        \n\t"
    "movn       %[maximum],       %[value],           %[tmp1]         \n\t"
    "bgtz       %[length],        1b                                  \n\t"
    " addiu     %[vector],        %[vector],          2               \n\t"
    ".set pop                                                         \n\t"

    : [tmp1] "=&r" (tmp1), [maximum] "+r" (maximum), [value] "=&r" (value)
    : [vector] "r" (vector), [length] "r" (length)
    : "memory"
  );

  return maximum;
}

// Maximum value of word32 vector. Version for MIPS platform.
int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length) {
  int32_t maximum = WEBRTC_SPL_WORD32_MIN;
  int tmp1, value;

  RTC_DCHECK_GT(length, 0);

  __asm__ volatile (
    ".set push                                                        \n\t"
    ".set noreorder                                                   \n\t"

   "1:                                                                \n\t"
    "lw         %[value],         0(%[vector])                        \n\t"
    "addiu      %[length],        %[length],          -1              \n\t"
    "slt        %[tmp1],          %[maximum],         %[value]        \n\t"
    "movn       %[maximum],       %[value],           %[tmp1]         \n\t"
    "bgtz       %[length],        1b                                  \n\t"
    " addiu     %[vector],        %[vector],          4               \n\t"

    ".set pop                                                         \n\t"

    : [tmp1] "=&r" (tmp1), [maximum] "+r" (maximum), [value] "=&r" (value)
    : [vector] "r" (vector), [length] "r" (length)
    : "memory"
  );

  return maximum;
}

// Minimum value of word16 vector. Version for MIPS platform.
int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length) {
  int16_t minimum = WEBRTC_SPL_WORD16_MAX;
  int tmp1;
  int16_t value;

  RTC_DCHECK_GT(length, 0);

  __asm__ volatile (
    ".set push                                                        \n\t"
    ".set noreorder                                                   \n\t"

   "1:                                                                \n\t"
    "lh         %[value],         0(%[vector])                        \n\t"
    "addiu      %[length],        %[length],          -1              \n\t"
    "slt        %[tmp1],          %[value],           %[minimum]      \n\t"
    "movn       %[minimum],       %[value],           %[tmp1]         \n\t"
    "bgtz       %[length],        1b                                  \n\t"
    " addiu     %[vector],        %[vector],          2               \n\t"

    ".set pop                                                         \n\t"

    : [tmp1] "=&r" (tmp1), [minimum] "+r" (minimum), [value] "=&r" (value)
    : [vector] "r" (vector), [length] "r" (length)
    : "memory"
  );

  return minimum;
}

// Minimum value of word32 vector. Version for MIPS platform.
int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length) {
  int32_t minimum = WEBRTC_SPL_WORD32_MAX;
  int tmp1, value;

  RTC_DCHECK_GT(length, 0);

  __asm__ volatile (
    ".set push                                                        \n\t"
    ".set noreorder                                                   \n\t"

   "1:                                                                \n\t"
    "lw         %[value],         0(%[vector])                        \n\t"
    "addiu      %[length],        %[length],          -1              \n\t"
    "slt        %[tmp1],          %[value],           %[minimum]      \n\t"
    "movn       %[minimum],       %[value],           %[tmp1]         \n\t"
    "bgtz       %[length],        1b                                  \n\t"
    " addiu     %[vector],        %[vector],          4               \n\t"

    ".set pop                                                         \n\t"

    : [tmp1] "=&r" (tmp1), [minimum] "+r" (minimum), [value] "=&r" (value)
    : [vector] "r" (vector), [length] "r" (length)
    : "memory"
  );

  return minimum;
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/min_max_operations_neon.c.neon
================================================
/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <arm_neon.h>
#include <stdlib.h>

#include "rtc_base/checks.h"
#include "common_audio/signal_processing/include/signal_processing_library.h"

// Maximum absolute value of word16 vector. C version for generic platforms.
int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length) {
  int absolute = 0, maximum = 0;

  RTC_DCHECK_GT(length, 0);

  const int16_t* p_start = vector;
  size_t rest = length & 7;
  const int16_t* p_end = vector + length - rest;

  int16x8_t v;
  uint16x8_t max_qv;
  max_qv = vdupq_n_u16(0);

  while (p_start < p_end) {
    v = vld1q_s16(p_start);
    // Note vabs doesn't change the value of -32768.
    v = vabsq_s16(v);
    // Use u16 so we don't lose the value -32768.
    max_qv = vmaxq_u16(max_qv, vreinterpretq_u16_s16(v));
    p_start += 8;
  }

#ifdef WEBRTC_ARCH_ARM64
  maximum = (int)vmaxvq_u16(max_qv);
#else
  uint16x4_t max_dv;
  max_dv = vmax_u16(vget_low_u16(max_qv), vget_high_u16(max_qv));
  max_dv = vpmax_u16(max_dv, max_dv);
  max_dv = vpmax_u16(max_dv, max_dv);

  maximum = (int)vget_lane_u16(max_dv, 0);
#endif

  p_end = vector + length;
  while (p_start < p_end) {
    absolute = abs((int)(*p_start));

    if (absolute > maximum) {
      maximum = absolute;
    }
    p_start++;
  }

  // Guard the case for abs(-32768).
  if (maximum > WEBRTC_SPL_WORD16_MAX) {
    maximum = WEBRTC_SPL_WORD16_MAX;
  }

  return (int16_t)maximum;
}

// Maximum absolute value of word32 vector. NEON intrinsics version for
// ARM 32-bit/64-bit platforms.
int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length) {
  // Use uint32_t for the local variables, to accommodate the return value
  // of abs(0x80000000), which is 0x80000000.

  uint32_t absolute = 0, maximum = 0;
  size_t i = 0;
  size_t residual = length & 0x7;

  RTC_DCHECK_GT(length, 0);

  const int32_t* p_start = vector;
  uint32x4_t max32x4_0 = vdupq_n_u32(0);
  uint32x4_t max32x4_1 = vdupq_n_u32(0);

  // First part, unroll the loop 8 times.
  for (i = 0; i < length - residual; i += 8) {
    int32x4_t in32x4_0 = vld1q_s32(p_start);
    p_start += 4;
    int32x4_t in32x4_1 = vld1q_s32(p_start);
    p_start += 4;
    in32x4_0 = vabsq_s32(in32x4_0);
    in32x4_1 = vabsq_s32(in32x4_1);
    // vabs doesn't change the value of 0x80000000.
    // Use u32 so we don't lose the value 0x80000000.
    max32x4_0 = vmaxq_u32(max32x4_0, vreinterpretq_u32_s32(in32x4_0));
    max32x4_1 = vmaxq_u32(max32x4_1, vreinterpretq_u32_s32(in32x4_1));
  }

  uint32x4_t max32x4 = vmaxq_u32(max32x4_0, max32x4_1);
#if defined(WEBRTC_ARCH_ARM64)
  maximum = vmaxvq_u32(max32x4);
#else
  uint32x2_t max32x2 = vmax_u32(vget_low_u32(max32x4), vget_high_u32(max32x4));
  max32x2 = vpmax_u32(max32x2, max32x2);

  maximum = vget_lane_u32(max32x2, 0);
#endif

  // Second part, do the remaining iterations (if any).
  for (i = residual; i > 0; i--) {
    absolute = abs((int)(*p_start));
    if (absolute > maximum) {
      maximum = absolute;
    }
    p_start++;
  }

  // Guard against the case for 0x80000000.
  maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX);

  return (int32_t)maximum;
}

// Maximum value of word16 vector. NEON intrinsics version for
// ARM 32-bit/64-bit platforms.
int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length) {
  int16_t maximum = WEBRTC_SPL_WORD16_MIN;
  size_t i = 0;
  size_t residual = length & 0x7;

  RTC_DCHECK_GT(length, 0);

  const int16_t* p_start = vector;
  int16x8_t max16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MIN);

  // First part, unroll the loop 8 times.
  for (i = 0; i < length - residual; i += 8) {
    int16x8_t in16x8 = vld1q_s16(p_start);
    max16x8 = vmaxq_s16(max16x8, in16x8);
    p_start += 8;
  }

#if defined(WEBRTC_ARCH_ARM64)
  maximum = vmaxvq_s16(max16x8);
#else
  int16x4_t max16x4 = vmax_s16(vget_low_s16(max16x8), vget_high_s16(max16x8));
  max16x4 = vpmax_s16(max16x4, max16x4);
  max16x4 = vpmax_s16(max16x4, max16x4);

  maximum = vget_lane_s16(max16x4, 0);
#endif

  // Second part, do the remaining iterations (if any).
  for (i = residual; i > 0; i--) {
    if (*p_start > maximum)
      maximum = *p_start;
    p_start++;
  }
  return maximum;
}

// Maximum value of word32 vector. NEON intrinsics version for
// ARM 32-bit/64-bit platforms.
int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length) {
  int32_t maximum = WEBRTC_SPL_WORD32_MIN;
  size_t i = 0;
  size_t residual = length & 0x7;

  RTC_DCHECK_GT(length, 0);

  const int32_t* p_start = vector;
  int32x4_t max32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MIN);
  int32x4_t max32x4_1 = vdupq_n_s32(WEBRTC_SPL_WORD32_MIN);

  // First part, unroll the loop 8 times.
  for (i = 0; i < length - residual; i += 8) {
    int32x4_t in32x4_0 = vld1q_s32(p_start);
    p_start += 4;
    int32x4_t in32x4_1 = vld1q_s32(p_start);
    p_start += 4;
    max32x4_0 = vmaxq_s32(max32x4_0, in32x4_0);
    max32x4_1 = vmaxq_s32(max32x4_1, in32x4_1);
  }

  int32x4_t max32x4 = vmaxq_s32(max32x4_0, max32x4_1);
#if defined(WEBRTC_ARCH_ARM64)
  maximum = vmaxvq_s32(max32x4);
#else
  int32x2_t max32x2 = vmax_s32(vget_low_s32(max32x4), vget_high_s32(max32x4));
  max32x2 = vpmax_s32(max32x2, max32x2);

  maximum = vget_lane_s32(max32x2, 0);
#endif

  // Second part, do the remaining iterations (if any).
  for (i = residual; i > 0; i--) {
    if (*p_start > maximum)
      maximum = *p_start;
    p_start++;
  }
  return maximum;
}

// Minimum value of word16 vector. NEON intrinsics version for
// ARM 32-bit/64-bit platforms.
int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length) {
  int16_t minimum = WEBRTC_SPL_WORD16_MAX;
  size_t i = 0;
  size_t residual = length & 0x7;

  RTC_DCHECK_GT(length, 0);

  const int16_t* p_start = vector;
  int16x8_t min16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MAX);

  // First part, unroll the loop 8 times.
  for (i = 0; i < length - residual; i += 8) {
    int16x8_t in16x8 = vld1q_s16(p_start);
    min16x8 = vminq_s16(min16x8, in16x8);
    p_start += 8;
  }

#if defined(WEBRTC_ARCH_ARM64)
  minimum = vminvq_s16(min16x8);
#else
  int16x4_t min16x4 = vmin_s16(vget_low_s16(min16x8), vget_high_s16(min16x8));
  min16x4 = vpmin_s16(min16x4, min16x4);
  min16x4 = vpmin_s16(min16x4, min16x4);

  minimum = vget_lane_s16(min16x4, 0);
#endif

  // Second part, do the remaining iterations (if any).
  for (i = residual; i > 0; i--) {
    if (*p_start < minimum)
      minimum = *p_start;
    p_start++;
  }
  return minimum;
}

// Minimum value of word32 vector. NEON intrinsics version for
// ARM 32-bit/64-bit platforms.
int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length) {
  int32_t minimum = WEBRTC_SPL_WORD32_MAX;
  size_t i = 0;
  size_t residual = length & 0x7;

  RTC_DCHECK_GT(length, 0);

  const int32_t* p_start = vector;
  int32x4_t min32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MAX);
  int32x4_t min32x4_1 = vdupq_n_s32(WEBRTC_SPL_WORD32_MAX);

  // First part, unroll the loop 8 times.
  for (i = 0; i < length - residual; i += 8) {
    int32x4_t in32x4_0 = vld1q_s32(p_start);
    p_start += 4;
    int32x4_t in32x4_1 = vld1q_s32(p_start);
    p_start += 4;
    min32x4_0 = vminq_s32(min32x4_0, in32x4_0);
    min32x4_1 = vminq_s32(min32x4_1, in32x4_1);
  }

  int32x4_t min32x4 = vminq_s32(min32x4_0, min32x4_1);
#if defined(WEBRTC_ARCH_ARM64)
  minimum = vminvq_s32(min32x4);
#else
  int32x2_t min32x2 = vmin_s32(vget_low_s32(min32x4), vget_high_s32(min32x4));
  min32x2 = vpmin_s32(min32x2, min32x2);

  minimum = vget_lane_s32(min32x2, 0);
#endif

  // Second part, do the remaining iterations (if any).
  for (i = residual; i > 0; i--) {
    if (*p_start < minimum)
      minimum = *p_start;
    p_start++;
  }
  return minimum;
}



================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/resample_48khz.c
================================================
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/*
 * This file contains resampling functions between 48 kHz and nb/wb.
 * The description header can be found in signal_processing_library.h
 *
 */

#include <string.h>
#include "common_audio/signal_processing/include/signal_processing_library.h"
#include "common_audio/signal_processing/resample_by_2_internal.h"

////////////////////////////
///// 48 kHz -> 16 kHz /////
////////////////////////////

// 48 -> 16 resampler
void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
                                    WebRtcSpl_State48khzTo16khz* state, int32_t* tmpmem)
{
    ///// 48 --> 48(LP) /////
    // int16_t  in[480]
    // int32_t out[480]
    /////
    WebRtcSpl_LPBy2ShortToInt(in, 480, tmpmem + 16, state->S_48_48);

    ///// 48 --> 32 /////
    // int32_t  in[480]
    // int32_t out[320]
    /////
    // copy state to and from input array
    memcpy(tmpmem + 8, state->S_48_32, 8 * sizeof(int32_t));
    memcpy(state->S_48_32, tmpmem + 488, 8 * sizeof(int32_t));
    WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 160);

    ///// 32 --> 16 /////
    // int32_t  in[320]
    // int16_t out[160]
    /////
    WebRtcSpl_DownBy2IntToShort(tmpmem, 320, out, state->S_32_16);
}

// initialize state of 48 -> 16 resampler
void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state)
{
    memset(state->S_48_48, 0, 16 * sizeof(int32_t));
    memset(state->S_48_32, 0, 8 * sizeof(int32_t));
    memset(state->S_32_16, 0, 8 * sizeof(int32_t));
}

////////////////////////////
///// 16 kHz -> 48 kHz /////
////////////////////////////

// 16 -> 48 resampler
void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
                                    WebRtcSpl_State16khzTo48khz* state, int32_t* tmpmem)
{
    ///// 16 --> 32 /////
    // int16_t  in[160]
    // int32_t out[320]
    /////
    WebRtcSpl_UpBy2ShortToInt(in, 160, tmpmem + 16, state->S_16_32);

    ///// 32 --> 24 /////
    // int32_t  in[320]
    // int32_t out[240]
    // copy state to and from input array
    /////
    memcpy(tmpmem + 8, state->S_32_24, 8 * sizeof(int32_t));
    memcpy(state->S_32_24, tmpmem + 328, 8 * sizeof(int32_t));
    WebRtcSpl_Resample32khzTo24khz(tmpmem + 8, tmpmem, 80);

    ///// 24 --> 48 /////
    // int32_t  in[240]
    // int16_t out[480]
    /////
    WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);
}

// initialize state of 16 -> 48 resampler
void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state)
{
    memset(state->S_16_32, 0, 8 * sizeof(int32_t));
    memset(state->S_32_24, 0, 8 * sizeof(int32_t));
    memset(state->S_24_48, 0, 8 * sizeof(int32_t));
}

////////////////////////////
///// 48 kHz ->  8 kHz /////
////////////////////////////

// 48 -> 8 resampler
void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
                                   WebRtcSpl_State48khzTo8khz* state, int32_t* tmpmem)
{
    ///// 48 --> 24 /////
    // int16_t  in[480]
    // int32_t out[240]
    /////
    WebRtcSpl_DownBy2ShortToInt(in, 480, tmpmem + 256, state->S_48_24);

    ///// 24 --> 24(LP) /////
    // int32_t  in[240]
    // int32_t out[240]
    /////
    WebRtcSpl_LPBy2IntToInt(tmpmem + 256, 240, tmpmem + 16, state->S_24_24);

    ///// 24 --> 16 /////
    // int32_t  in[240]
    // int32_t out[160]
    /////
    // copy state to and from input array
    memcpy(tmpmem + 8, state->S_24_16, 8 * sizeof(int32_t));
    memcpy(state->S_24_16, tmpmem + 248, 8 * sizeof(int32_t));
    WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 80);

    ///// 16 --> 8 /////
    // int32_t  in[160]
    // int16_t out[80]
    /////
    WebRtcSpl_DownBy2IntToShort(tmpmem, 160, out, state->S_16_8);
}

// initialize state of 48 -> 8 resampler
void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state)
{
    memset(state->S_48_24, 0, 8 * sizeof(int32_t));
    memset(state->S_24_24, 0, 16 * sizeof(int32_t));
    memset(state->S_24_16, 0, 8 * sizeof(int32_t));
    memset(state->S_16_8, 0, 8 * sizeof(int32_t));
}

////////////////////////////
/////  8 kHz -> 48 kHz /////
////////////////////////////

// 8 -> 48 resampler
void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
                                   WebRtcSpl_State8khzTo48khz* state, int32_t* tmpmem)
{
    ///// 8 --> 16 /////
    // int16_t  in[80]
    // int32_t out[160]
    /////
    WebRtcSpl_UpBy2ShortToInt(in, 80, tmpmem + 264, state->S_8_16);

    ///// 16 --> 12 /////
    // int32_t  in[160]
    // int32_t out[120]
    /////
    // copy state to and from input array
    memcpy(tmpmem + 256, state->S_16_12, 8 * sizeof(int32_t));
    memcpy(state->S_16_12, tmpmem + 416, 8 * sizeof(int32_t));
    WebRtcSpl_Resample32khzTo24khz(tmpmem + 256, tmpmem + 240, 40);

    ///// 12 --> 24 /////
    // int32_t  in[120]
    // int16_t out[240]
    /////
    WebRtcSpl_UpBy2IntToInt(tmpmem + 240, 120, tmpmem, state->S_12_24);

    ///// 24 --> 48 /////
    // int32_t  in[240]
    // int16_t out[480]
    /////
    WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);
}

// initialize state of 8 -> 48 resampler
void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state)
{
    memset(state->S_8_16, 0, 8 * sizeof(int32_t));
    memset(state->S_16_12, 0, 8 * sizeof(int32_t));
    memset(state->S_12_24, 0, 8 * sizeof(int32_t));
    memset(state->S_24_48, 0, 8 * sizeof(int32_t));
}


================================================
FILE: thirdparty/webrtc/common_audio/signal_processing/resample_by_2_internal.c
================================================
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/*
 * This header file contains some internal resampling functions.
 *
 */

#include "common_audio/signal_processing/resample_by_2_internal.h"
#include "rtc_base/sanitizer.h"

// allpass filter coefficients.
static const int16_t kResampleAllpass[2][3] = {
        {821, 6110, 12382},
        {3050, 9368, 15063}
};

//
//   decimator
// input:  int32_t (shifted 15 positions to the left, + offset 16384) OVERWRITTEN!
// output: int16_t (saturated) (of length len/2)
// state:  filter state array; length = 8

void RTC_NO_SANITIZE("signed-integer-overflow")  // bugs.webrtc.org/5486
WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out,
                            int32_t *state)
{
    int32_t tmp0, tmp1, diff;
    int32_t i;

    len >>= 1;

    // lower allpass filter (operates on even input samples)
    for (i = 0; i < len; i++)
    {
        tmp0 = in[i << 1];
        diff = tmp0 - state[1];
        // UBSan: -1771017321 - 999586185 cannot be represented in type 'int'

        // scale down and round
        diff = (diff + (1 << 13)) >> 14;
        tmp1 = state[0] + diff * kResampleAllpass[1][0];
        state[0] = tmp0;
        diff = tmp1 - state[2];
        // scale down and truncate
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        tmp0 = state[1] + diff * kResampleAllpass[1][1];
        state[1] = tmp1;
        diff = tmp0 - state[3];
        // scale down and truncate
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        state[3] = state[2] + diff * kResampleAllpass[1][2];
        state[2] = tmp0;

        // divide by two and store temporarily
        in[i << 1] = (state[3] >> 1);
    }

    in++;

    // upper allpass filter (operates on odd input samples)
    for (i = 0; i < len; i++)
    {
        tmp0 = in[i << 1];
        diff = tmp0 - state[5];
        // scale down and round
        diff = (diff + (1 << 13)) >> 14;
        tmp1 = state[4] + diff * kResampleAllpass[0][0];
        state[4] = tmp0;
        diff = tmp1 - state[6];
        // scale down and round
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        tmp0 = state[5] + diff * kResampleAllpass[0][1];
        state[5] = tmp1;
        diff = tmp0 - state[7];
        // scale down and truncate
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        state[7] = state[6] + diff * kResampleAllpass[0][2];
        state[6] = tmp0;

        // divide by two and store temporarily
        in[i << 1] = (state[7] >> 1);
    }

    in--;

    // combine allpass outputs
    for (i = 0; i < len; i += 2)
    {
        // divide by two, add both allpass outputs and round
        tmp0 = (in[i << 1] + in[(i << 1) + 1]) >> 15;
        tmp1 = (in[(i << 1) + 2] + in[(i << 1) + 3]) >> 15;
        if (tmp0 > (int32_t)0x00007FFF)
            tmp0 = 0x00007FFF;
        if (tmp0 < (int32_t)0xFFFF8000)
            tmp0 = 0xFFFF8000;
        out[i] = (int16_t)tmp0;
        if (tmp1 > (int32_t)0x00007FFF)
            tmp1 = 0x00007FFF;
        if (tmp1 < (int32_t)0xFFFF8000)
            tmp1 = 0xFFFF8000;
        out[i + 1] = (int16_t)tmp1;
    }
}

//
//   decimator
// input:  int16_t
// output: int32_t (shifted 15 positions to the left, + offset 16384) (of length len/2)
// state:  filter state array; length = 8

void RTC_NO_SANITIZE("signed-integer-overflow")  // bugs.webrtc.org/5486
WebRtcSpl_DownBy2ShortToInt(const int16_t *in,
                            int32_t len,
                            int32_t *out,
                            int32_t *state)
{
    int32_t tmp0, tmp1, diff;
    int32_t i;

    len >>= 1;

    // lower allpass filter (operates on even input samples)
    for (i = 0; i < len; i++)
    {
        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);
        diff = tmp0 - state[1];
        // scale down and round
        diff = (diff + (1 << 13)) >> 14;
        tmp1 = state[0] + diff * kResampleAllpass[1][0];
        state[0] = tmp0;
        diff = tmp1 - state[2];
        // UBSan: -1379909682 - 834099714 cannot be represented in type 'int'

        // scale down and truncate
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        tmp0 = state[1] + diff * kResampleAllpass[1][1];
        state[1] = tmp1;
        diff = tmp0 - state[3];
        // scale down and truncate
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        state[3] = state[2] + diff * kResampleAllpass[1][2];
        state[2] = tmp0;

        // divide by two and store temporarily
        out[i] = (state[3] >> 1);
    }

    in++;

    // upper allpass filter (operates on odd input samples)
    for (i = 0; i < len; i++)
    {
        tmp0 = ((int32_t)in[i << 1] << 15) + (1 << 14);
        diff = tmp0 - state[5];
        // scale down and round
        diff = (diff + (1 << 13)) >> 14;
        tmp1 = state[4] + diff * kResampleAllpass[0][0];
        state[4] = tmp0;
        diff = tmp1 - state[6];
        // scale down and round
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        tmp0 = state[5] + diff * kResampleAllpass[0][1];
        state[5] = tmp1;
        diff = tmp0 - state[7];
        // scale down and truncate
        diff = diff >> 14;
        if (diff < 0)
            diff += 1;
        sta
Download .txt
gitextract_iq5s0_a2/

├── .gitignore
├── CMakeLists.txt
├── README.md
├── build_and_run.sh
├── src/
│   ├── common.h
│   ├── file_cut.c
│   ├── file_cut.h
│   ├── main.c
│   ├── period_format.c
│   ├── period_format.h
│   ├── simple_vad.c
│   └── simple_vad.h
├── thirdparty/
│   └── webrtc/
│       ├── BUILD.gn
│       ├── common_audio/
│       │   ├── rename.sh
│       │   ├── rename.sh~
│       │   ├── signal_processing/
│       │   │   ├── cross_correlation.c
│       │   │   ├── cross_correlation_mips.c.mips
│       │   │   ├── cross_correlation_neon.c.neon
│       │   │   ├── division_operations.c
│       │   │   ├── downsample_fast.c
│       │   │   ├── downsample_fast_mips.c.mips
│       │   │   ├── downsample_fast_neon.c.neon
│       │   │   ├── energy.c
│       │   │   ├── get_scaling_square.c
│       │   │   ├── include/
│       │   │   │   ├── real_fft.h
│       │   │   │   ├── signal_processing_library.h
│       │   │   │   ├── spl_inl.h
│       │   │   │   ├── spl_inl_armv7.h
│       │   │   │   └── spl_inl_mips.h
│       │   │   ├── min_max_operations.c
│       │   │   ├── min_max_operations_mips.c.mips
│       │   │   ├── min_max_operations_neon.c.neon
│       │   │   ├── resample_48khz.c
│       │   │   ├── resample_by_2_internal.c
│       │   │   ├── resample_by_2_internal.h
│       │   │   ├── resample_fractional.c
│       │   │   ├── spl_init.c
│       │   │   ├── vector_scaling_operations.c
│       │   │   └── vector_scaling_operations_mips.c.mips
│       │   └── vad/
│       │       ├── include/
│       │       │   ├── vad.h
│       │       │   └── webrtc_vad.h
│       │       ├── mock/
│       │       │   └── mock_vad.h
│       │       ├── vad.cc
│       │       ├── vad_core.c
│       │       ├── vad_core.h
│       │       ├── vad_core_unittest.cc
│       │       ├── vad_filterbank.c
│       │       ├── vad_filterbank.h
│       │       ├── vad_filterbank_unittest.cc
│       │       ├── vad_gmm.c
│       │       ├── vad_gmm.h
│       │       ├── vad_gmm_unittest.cc
│       │       ├── vad_sp.c
│       │       ├── vad_sp.h
│       │       ├── vad_sp_unittest.cc
│       │       ├── vad_unittest.cc
│       │       ├── vad_unittest.h
│       │       └── webrtc_vad.c
│       ├── rtc_base/
│       │   ├── checks.cc
│       │   ├── checks.h
│       │   ├── compile_assert_c.h
│       │   ├── numerics/
│       │   │   └── safe_compare.h
│       │   ├── sanitizer.h
│       │   └── type_traits.h
│       ├── system_wrappers/
│       │   └── include/
│       │       └── cpu_features_wrapper.h
│       └── typedefs.h
└── valgrind.sh
Download .txt
SYMBOL INDEX (213 symbols across 45 files)

FILE: src/file_cut.c
  function cut_write_file (line 10) | static inline int cut_write_file(struct cut_info *cut, int frames) {
  function cut_frame (line 36) | static inline int cut_frame(struct cut_info *cut, int last_frame, int fo...
  function add_continued (line 57) | static inline int add_continued(struct cut_info *cut, int is_active) {
  function add_changed (line 75) | static inline int add_changed(struct cut_info *cut, int is_active) {
  type cut_info (line 94) | struct cut_info
  type cut_info (line 95) | struct cut_info
  type cut_info (line 95) | struct cut_info
  function cut_add_vad_activity (line 101) | int cut_add_vad_activity(struct cut_info *cut, int is_active, int is_las...
  function cut_info_free (line 120) | void cut_info_free(struct cut_info *cut) {
  function cut_info_print (line 125) | void cut_info_print(struct cut_info *cut) {

FILE: src/file_cut.h
  type cut_info (line 12) | struct cut_info {
  type cut_info (line 25) | struct cut_info
  type cut_info (line 27) | struct cut_info
  type cut_info (line 29) | struct cut_info
  type cut_info (line 31) | struct cut_info

FILE: src/main.c
  type cut_info (line 9) | struct cut_info
  type periods (line 11) | struct periods
  function main (line 15) | int main() {
  function run (line 44) | int run(FILE *fp, simple_vad *vad, struct cut_info *cut) {
  function add_period_activity (line 75) | int add_period_activity(struct periods *per, int is_active, int is_last) {

FILE: src/period_format.c
  function add_period_start (line 14) | static int add_period_start(struct periods *per) {
  function add_period_end (line 36) | static void add_period_end(struct periods *per) {
  type periods (line 42) | struct periods
  type periods (line 43) | struct periods
  type periods (line 43) | struct periods
  function periods_print (line 64) | void periods_print(struct periods *per) {
  function period_add_vad_activity (line 82) | int period_add_vad_activity(struct periods *per, int is_active, int is_l...
  function periods_free (line 98) | void periods_free(struct periods *per) {

FILE: src/period_format.h
  type periods (line 11) | struct periods {
  type periods (line 22) | struct periods
  type periods (line 30) | struct periods
  type periods (line 32) | struct periods
  type periods (line 34) | struct periods

FILE: src/simple_vad.c
  function check_end_file (line 8) | static int check_end_file(FILE *fp) {
  function read_int16_bytes (line 15) | int read_int16_bytes(FILE *fp, int16_t *output) {
  function simple_vad (line 33) | simple_vad *simple_vad_create() {
  function process_vad (line 49) | int process_vad(VadInst *inst, int16_t *data) {
  function simple_vad_free (line 54) | void simple_vad_free(simple_vad *inst) {

FILE: src/simple_vad.h
  type VadInst (line 19) | typedef VadInst simple_vad;

FILE: thirdparty/webrtc/common_audio/signal_processing/cross_correlation.c
  function WebRtcSpl_CrossCorrelationC (line 14) | void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,

FILE: thirdparty/webrtc/common_audio/signal_processing/division_operations.c
  function WebRtcSpl_DivU32U16 (line 27) | uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den)
  function WebRtcSpl_DivW32W16 (line 39) | int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den)
  function WebRtcSpl_DivW32W16ResW16 (line 51) | int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den)
  function WebRtcSpl_DivResultInQ31 (line 63) | int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den)

FILE: thirdparty/webrtc/common_audio/signal_processing/downsample_fast.c
  function WebRtcSpl_DownsampleFastC (line 18) | int WebRtcSpl_DownsampleFastC(const int16_t* data_in,

FILE: thirdparty/webrtc/common_audio/signal_processing/energy.c
  function WebRtcSpl_Energy (line 20) | int32_t WebRtcSpl_Energy(int16_t* vector,

FILE: thirdparty/webrtc/common_audio/signal_processing/get_scaling_square.c
  function WebRtcSpl_GetScalingSquare (line 20) | int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,

FILE: thirdparty/webrtc/common_audio/signal_processing/include/real_fft.h
  type RealFFT (line 21) | struct RealFFT
  type RealFFT (line 27) | struct RealFFT
  type RealFFT (line 28) | struct RealFFT
  type RealFFT (line 61) | struct RealFFT
  type RealFFT (line 89) | struct RealFFT

FILE: thirdparty/webrtc/common_audio/signal_processing/include/signal_processing_library.h
  type WebRtcSpl_State22khzTo16khz (line 746) | typedef struct {
  type WebRtcSpl_State16khzTo22khz (line 760) | typedef struct {
  type WebRtcSpl_State22khzTo8khz (line 773) | typedef struct {
  type WebRtcSpl_State8khzTo22khz (line 786) | typedef struct {
  type WebRtcSpl_State48khzTo16khz (line 826) | typedef struct {
  type WebRtcSpl_State16khzTo48khz (line 838) | typedef struct {
  type WebRtcSpl_State48khzTo8khz (line 850) | typedef struct {
  type WebRtcSpl_State8khzTo48khz (line 863) | typedef struct {

FILE: thirdparty/webrtc/common_audio/signal_processing/include/spl_inl.h
  function WebRtcSpl_CountLeadingZeros32_NotBuiltin (line 23) | static __inline int WebRtcSpl_CountLeadingZeros32_NotBuiltin(uint32_t n) {
  function WebRtcSpl_CountLeadingZeros64_NotBuiltin (line 40) | static __inline int WebRtcSpl_CountLeadingZeros64_NotBuiltin(uint64_t n) {
  function WebRtcSpl_CountLeadingZeros32 (line 47) | static __inline int WebRtcSpl_CountLeadingZeros32(uint32_t n) {
  function WebRtcSpl_CountLeadingZeros64 (line 57) | static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) {
  function WebRtcSpl_SatW32ToW16 (line 75) | static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
  function WebRtcSpl_AddSatW32 (line 86) | static __inline int32_t WebRtcSpl_AddSatW32(int32_t a, int32_t b) {
  function WebRtcSpl_SubSatW32 (line 100) | static __inline int32_t WebRtcSpl_SubSatW32(int32_t a, int32_t b) {
  function WebRtcSpl_AddSatW16 (line 114) | static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
  function WebRtcSpl_SubSatW16 (line 118) | static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
  function WebRtcSpl_GetSizeInBits (line 124) | static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
  function WebRtcSpl_NormW32 (line 130) | static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
  function WebRtcSpl_NormU32 (line 136) | static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
  function WebRtcSpl_NormW16 (line 142) | static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
  function WebRtc_MulAccumW16 (line 147) | static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t...

FILE: thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h
  function WEBRTC_SPL_MUL_16_32_RSFT16 (line 27) | static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) {
  function WEBRTC_SPL_MUL_16_16 (line 33) | static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) {
  function WebRtc_MulAccumW16 (line 40) | static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t...
  function WebRtcSpl_AddSatW16 (line 46) | static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
  function WebRtcSpl_AddSatW32 (line 54) | static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_va...
  function WebRtcSpl_SubSatW32 (line 62) | static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_va...
  function WebRtcSpl_SubSatW16 (line 70) | static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
  function WebRtcSpl_GetSizeInBits (line 78) | static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
  function WebRtcSpl_NormW32 (line 86) | static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
  function WebRtcSpl_NormU32 (line 100) | static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
  function WebRtcSpl_NormW16 (line 110) | static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
  function WebRtcSpl_SatW32ToW16 (line 126) | static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {

FILE: thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_mips.h
  function WEBRTC_SPL_MUL_16_16 (line 18) | static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a,
  function WEBRTC_SPL_MUL_16_32_RSFT16 (line 40) | static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a,
  function WebRtcSpl_SatW32ToW16 (line 68) | static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
  function WebRtcSpl_AddSatW32 (line 88) | static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_va...
  function WebRtcSpl_SubSatW32 (line 110) | static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_va...
  function WebRtcSpl_GetSizeInBits (line 122) | static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
  function WebRtcSpl_NormW32 (line 135) | static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
  function WebRtcSpl_NormU32 (line 157) | static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
  function WebRtcSpl_NormW16 (line 168) | static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
  function WebRtc_MulAccumW16 (line 191) | static __inline int32_t WebRtc_MulAccumW16(int16_t a,

FILE: thirdparty/webrtc/common_audio/signal_processing/min_max_operations.c
  function WebRtcSpl_MaxAbsValueW16C (line 37) | int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) {
  function WebRtcSpl_MaxAbsValueW32C (line 60) | int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {
  function WebRtcSpl_MaxValueW16C (line 82) | int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) {
  function WebRtcSpl_MaxValueW32C (line 96) | int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) {
  function WebRtcSpl_MinValueW16C (line 110) | int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) {
  function WebRtcSpl_MinValueW32C (line 124) | int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {
  function WebRtcSpl_MaxAbsIndexW16 (line 138) | size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
  function WebRtcSpl_MaxIndexW16 (line 159) | size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
  function WebRtcSpl_MaxIndexW32 (line 176) | size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
  function WebRtcSpl_MinIndexW16 (line 193) | size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
  function WebRtcSpl_MinIndexW32 (line 210) | size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {

FILE: thirdparty/webrtc/common_audio/signal_processing/resample_48khz.c
  function WebRtcSpl_Resample48khzTo16khz (line 27) | void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
  function WebRtcSpl_ResetResample48khzTo16khz (line 53) | void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* st...
  function WebRtcSpl_Resample16khzTo48khz (line 65) | void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
  function WebRtcSpl_ResetResample16khzTo48khz (line 91) | void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* st...
  function WebRtcSpl_Resample48khzTo8khz (line 103) | void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
  function WebRtcSpl_ResetResample48khzTo8khz (line 135) | void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state)
  function WebRtcSpl_Resample8khzTo48khz (line 148) | void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
  function WebRtcSpl_ResetResample8khzTo48khz (line 180) | void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state)

FILE: thirdparty/webrtc/common_audio/signal_processing/resample_by_2_internal.c
  function WebRtcSpl_UpBy2ShortToInt (line 207) | void WebRtcSpl_UpBy2ShortToInt(const int16_t *in, int32_t len, int32_t *...
  function WebRtcSpl_UpBy2IntToInt (line 277) | void WebRtcSpl_UpBy2IntToInt(const int32_t *in, int32_t len, int32_t *out,
  function WebRtcSpl_UpBy2IntToShort (line 347) | void WebRtcSpl_UpBy2IntToShort(const int32_t *in, int32_t len, int16_t *...
  function WebRtcSpl_LPBy2ShortToInt (line 426) | void WebRtcSpl_LPBy2ShortToInt(const int16_t* in, int32_t len, int32_t* ...

FILE: thirdparty/webrtc/common_audio/signal_processing/resample_fractional.c
  function WebRtcSpl_Resample48khzTo32khz (line 44) | void WebRtcSpl_Resample48khzTo32khz(const int32_t *In, int32_t *Out, siz...
  function WebRtcSpl_Resample32khzTo24khz (line 89) | void WebRtcSpl_Resample32khzTo24khz(const int32_t *In, int32_t *Out, siz...
  function WebRtcSpl_ResampDotProduct (line 147) | static void WebRtcSpl_ResampDotProduct(const int32_t *in1, const int32_t...
  function WebRtcSpl_Resample44khzTo32khz (line 197) | void WebRtcSpl_Resample44khzTo32khz(const int32_t *In, int32_t *Out, siz...

FILE: thirdparty/webrtc/common_audio/signal_processing/spl_init.c
  function InitPointersToC (line 33) | static void InitPointersToC() {
  function InitPointersToNeon (line 49) | static void InitPointersToNeon() {
  function InitPointersToMIPS (line 65) | static void InitPointersToMIPS() {
  function InitFunctionPointers (line 85) | static void InitFunctionPointers(void) {
  function once (line 98) | static void once(void (*func)(void)) {
  function once (line 106) | static void once(void (*func)(void)) {
  function WebRtcSpl_Init (line 131) | void WebRtcSpl_Init() {

FILE: thirdparty/webrtc/common_audio/signal_processing/vector_scaling_operations.c
  function WebRtcSpl_VectorBitShiftW16 (line 25) | void WebRtcSpl_VectorBitShiftW16(int16_t *res, size_t length,
  function WebRtcSpl_VectorBitShiftW32 (line 45) | void WebRtcSpl_VectorBitShiftW32(int32_t *out_vector,
  function WebRtcSpl_VectorBitShiftW32ToW16 (line 67) | void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out, size_t length,
  function WebRtcSpl_ScaleVector (line 86) | void WebRtcSpl_ScaleVector(const int16_t *in_vector, int16_t *out_vector,
  function WebRtcSpl_ScaleVectorWithSat (line 104) | void WebRtcSpl_ScaleVectorWithSat(const int16_t *in_vector, int16_t *out...
  function WebRtcSpl_ScaleAndAddVectors (line 121) | void WebRtcSpl_ScaleAndAddVectors(const int16_t *in1, int16_t gain1, int...
  function WebRtcSpl_ScaleAndAddVectorsWithRoundC (line 143) | int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,

FILE: thirdparty/webrtc/common_audio/vad/include/vad.h
  function namespace (line 20) | namespace webrtc {

FILE: thirdparty/webrtc/common_audio/vad/include/webrtc_vad.h
  type VadInst (line 23) | typedef struct WebRtcVadInst VadInst;

FILE: thirdparty/webrtc/common_audio/vad/mock/mock_vad.h
  function namespace (line 17) | namespace webrtc {

FILE: thirdparty/webrtc/common_audio/vad/vad.cc
  type webrtc (line 17) | namespace webrtc {
    class VadImpl (line 21) | class VadImpl final : public Vad {
      method VadImpl (line 23) | explicit VadImpl(Aggressiveness aggressiveness)
      method Activity (line 30) | Activity VoiceActivity(const int16_t* audio,
      method Reset (line 45) | void Reset() override {
    function CreateVad (line 61) | std::unique_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness) {

FILE: thirdparty/webrtc/common_audio/vad/vad_core.c
  function WeightedAverage (line 102) | static int32_t WeightedAverage(int16_t* data, int16_t offset,
  function GmmProbability (line 134) | static int16_t GmmProbability(VadInstT* self, int16_t* features,
  function WebRtcVad_InitCore (line 492) | int WebRtcVad_InitCore(VadInstT* self) {
  function WebRtcVad_set_mode_core (line 549) | int WebRtcVad_set_mode_core(VadInstT* self, int mode) {
  function WebRtcVad_CalcVad48khz (line 608) | int WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,
  function WebRtcVad_CalcVad32khz (line 633) | int WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,
  function WebRtcVad_CalcVad16khz (line 656) | int WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,
  function WebRtcVad_CalcVad8khz (line 673) | int WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame,

FILE: thirdparty/webrtc/common_audio/vad/vad_core.h
  type VadInstT (line 27) | typedef struct VadInstT_ {

FILE: thirdparty/webrtc/common_audio/vad/vad_core_unittest.cc
  type webrtc (line 21) | namespace webrtc {
    type test (line 22) | namespace test {
      function TEST_F (line 24) | TEST_F(VadTest, InitCore) {
      function TEST_F (line 39) | TEST_F(VadTest, set_mode_core) {
      function TEST_F (line 58) | TEST_F(VadTest, CalcVad) {

FILE: thirdparty/webrtc/common_audio/vad/vad_filterbank.c
  function HighPassFilter (line 40) | static void HighPassFilter(const int16_t* data_in, size_t data_length,
  function AllPassFilter (line 82) | static void AllPassFilter(const int16_t* data_in, size_t data_length,
  function SplitFilter (line 119) | static void SplitFilter(const int16_t* data_in, size_t data_length,
  function LogOfEnergy (line 153) | static void LogOfEnergy(const int16_t* data_in, size_t data_length,
  function WebRtcVad_CalculateFeatures (line 244) | int16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in,

FILE: thirdparty/webrtc/common_audio/vad/vad_filterbank_unittest.cc
  type webrtc (line 22) | namespace webrtc {
    type test (line 23) | namespace test {
      function TEST_F (line 27) | TEST_F(VadTest, vad_filterbank) {

FILE: thirdparty/webrtc/common_audio/vad/vad_gmm.c
  function WebRtcVad_GaussianProbability (line 30) | int32_t WebRtcVad_GaussianProbability(int16_t input,

FILE: thirdparty/webrtc/common_audio/vad/vad_gmm_unittest.cc
  type webrtc (line 19) | namespace webrtc {
    type test (line 20) | namespace test {
      function TEST_F (line 22) | TEST_F(VadTest, vad_gmm) {

FILE: thirdparty/webrtc/common_audio/vad/vad_sp.c
  function WebRtcVad_Downsampling (line 26) | void WebRtcVad_Downsampling(const int16_t* signal_in,
  function WebRtcVad_FindMinimum (line 59) | int16_t WebRtcVad_FindMinimum(VadInstT* self,

FILE: thirdparty/webrtc/common_audio/vad/vad_sp_unittest.cc
  type webrtc (line 22) | namespace webrtc {
    type test (line 23) | namespace test {
      function TEST_F (line 25) | TEST_F(VadTest, vad_sp) {

FILE: thirdparty/webrtc/common_audio/vad/vad_unittest.cc
  type webrtc (line 55) | namespace webrtc {
    type test (line 56) | namespace test {
      function TEST_F (line 58) | TEST_F(VadTest, ApiTest) {
      function TEST_F (line 129) | TEST_F(VadTest, ValidRatesFrameLengths) {

FILE: thirdparty/webrtc/common_audio/vad/vad_unittest.h
  function namespace (line 19) | namespace webrtc {
  function class (line 39) | class VadTest : public ::testing::Test {

FILE: thirdparty/webrtc/common_audio/vad/webrtc_vad.c
  function VadInst (line 25) | VadInst* WebRtcVad_Create() {
  function WebRtcVad_Free (line 34) | void WebRtcVad_Free(VadInst* handle) {
  function WebRtcVad_Init (line 39) | int WebRtcVad_Init(VadInst* handle) {
  function WebRtcVad_set_mode (line 45) | int WebRtcVad_set_mode(VadInst* handle, int mode) {
  function WebRtcVad_Process (line 58) | int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
  function WebRtcVad_ValidRateAndFrameLength (line 93) | int WebRtcVad_ValidRateAndFrameLength(int rate, size_t frame_length) {

FILE: thirdparty/webrtc/rtc_base/checks.cc
  type rtc (line 44) | namespace rtc {
    function VPrintError (line 47) | void VPrintError(const char* format, va_list args) {
    function PrintError (line 60) | void PrintError(const char* format, ...) {
    function NO_RETURN (line 79) | NO_RETURN FatalMessage::~FatalMessage() {
  function NO_RETURN (line 115) | NO_RETURN void rtc_FatalMessage(const char* file, int line, const char* ...

FILE: thirdparty/webrtc/rtc_base/checks.h
  function namespace (line 81) | namespace rtc {

FILE: thirdparty/webrtc/rtc_base/numerics/safe_compare.h
  type LargerIntImpl (line 49) | struct LargerIntImpl
  type LargerIntImpl (line 53) | struct LargerIntImpl
  type LargerIntImpl (line 57) | struct LargerIntImpl
  function typename (line 72) | typename std::make_unsigned<T>::type MakeUnsigned(T a) {
  function Cmp (line 82) | bool Cmp(T1 a, T2 b) {
  function Cmp (line 94) | bool Cmp(T1 a, T2 b) {
  function Cmp (line 106) | bool Cmp(T1 a, T2 b) {
  function Cmp (line 118) | bool Cmp(T1 a, T2 b) {
  function Cmp (line 130) | bool Cmp(T1 a, T2 b) {

FILE: thirdparty/webrtc/rtc_base/sanitizer.h
  function rtc_AsanPoison (line 50) | static inline void rtc_AsanPoison(const volatile void* ptr,
  function rtc_AsanUnpoison (line 61) | static inline void rtc_AsanUnpoison(const volatile void* ptr,
  function rtc_MsanMarkUninitialized (line 71) | static inline void rtc_MsanMarkUninitialized(const volatile void* ptr,
  function rtc_MsanCheckInitialized (line 82) | static inline void rtc_MsanCheckInitialized(const volatile void* ptr,
  function namespace (line 92) | namespace rtc {

FILE: thirdparty/webrtc/rtc_base/type_traits.h
  function namespace (line 39) | namespace test_has_data_and_size {
  function namespace (line 75) | namespace type_traits_impl {
  function namespace (line 115) | namespace test_enum_intlike {

FILE: thirdparty/webrtc/system_wrappers/include/cpu_features_wrapper.h
  type CPUFeature (line 21) | typedef enum { kSSE2, kSSE3 } CPUFeature;
Condensed preview — 67 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (376K chars).
[
  {
    "path": ".gitignore",
    "chars": 42,
    "preview": "pcm/\nbuild/\noutput_pcm/\n.vscode/\nvad-demo*"
  },
  {
    "path": "CMakeLists.txt",
    "chars": 469,
    "preview": "cmake_minimum_required(VERSION 2.8)\nset(CMAKE_VERBOSE_MAKEFILE on)\nproject(vad-demo)\nset(CMAKE_BUILD_TYPE DEBUG)\n\nset(CM"
  },
  {
    "path": "README.md",
    "chars": 1950,
    "preview": "# speech-vad-demo\n\n\n## 简介\n### 简介\n\n项目地址: https://github.com/Baidu-AIP/speech-vad-demo\n\n集成 [webrtc](https://webrtc.org/) 开"
  },
  {
    "path": "build_and_run.sh",
    "chars": 464,
    "preview": "#!/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 |"
  },
  {
    "path": "src/common.h",
    "chars": 1020,
    "preview": "//\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 "
  },
  {
    "path": "src/file_cut.c",
    "chars": 4063,
    "preview": "//\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 i"
  },
  {
    "path": "src/file_cut.h",
    "chars": 1623,
    "preview": "//\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 "
  },
  {
    "path": "src/main.c",
    "chars": 2822,
    "preview": "#include <stdio.h>\n#include <common_audio/vad/include/webrtc_vad.h>\n#include <stdlib.h>\n#include \"simple_vad.h\"\n#include"
  },
  {
    "path": "src/period_format.c",
    "chars": 2979,
    "preview": "//\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 \""
  },
  {
    "path": "src/period_format.h",
    "chars": 1217,
    "preview": "//\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#i"
  },
  {
    "path": "src/simple_vad.c",
    "chars": 1301,
    "preview": "//\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  "
  },
  {
    "path": "src/simple_vad.h",
    "chars": 841,
    "preview": "//\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"
  },
  {
    "path": "thirdparty/webrtc/BUILD.gn",
    "chars": 15744,
    "preview": "# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n#\n# Use of this source code is governed by a BSD-s"
  },
  {
    "path": "thirdparty/webrtc/common_audio/rename.sh",
    "chars": 125,
    "preview": "#!/bin/sh \nrename 's/mips\\.c$/mips\\.c\\.mips/' signal_processing/*.c\nrename 's/neon\\.c$/neon\\.c\\.neon/' signal_processing"
  },
  {
    "path": "thirdparty/webrtc/common_audio/rename.sh~",
    "chars": 125,
    "preview": "#!/bin/sh \nrename 's/mips\\.c$/mips\\.c\\.mips/' signal_processing/*.c\nrename 's/neon\\.c$/neon\\.c\\.neon/' signal_processing"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/cross_correlation.c",
    "chars": 1187,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/cross_correlation_mips.c.mips",
    "chars": 6240,
    "preview": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/cross_correlation_neon.c.neon",
    "chars": 3155,
    "preview": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/division_operations.c",
    "chars": 3507,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/downsample_fast.c",
    "chars": 2204,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/downsample_fast_mips.c.mips",
    "chars": 10155,
    "preview": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/downsample_fast_neon.c.neon",
    "chars": 9455,
    "preview": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/energy.c",
    "chars": 1127,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/get_scaling_square.c",
    "chars": 1347,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/real_fft.h",
    "chars": 4234,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/signal_processing_library.h",
    "chars": 59695,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/spl_inl.h",
    "chars": 5328,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h",
    "chars": 3414,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/include/spl_inl_mips.h",
    "chars": 6993,
    "preview": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/min_max_operations.c",
    "chars": 5483,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/min_max_operations_mips.c.mips",
    "chars": 16736,
    "preview": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/min_max_operations_neon.c.neon",
    "chars": 8126,
    "preview": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_48khz.c",
    "chars": 5827,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_by_2_internal.c",
    "chars": 20609,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_by_2_internal.h",
    "chars": 1839,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/resample_fractional.c",
    "chars": 7915,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/spl_init.c",
    "chars": 4594,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/vector_scaling_operations.c",
    "chars": 4909,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/signal_processing/vector_scaling_operations_mips.c.mips",
    "chars": 2501,
    "preview": "/*\n *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/include/vad.h",
    "chars": 1515,
    "preview": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/include/webrtc_vad.h",
    "chars": 3078,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/mock/mock_vad.h",
    "chars": 971,
    "preview": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad.cc",
    "chars": 1692,
    "preview": "/*\n *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_core.c",
    "chars": 26239,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_core.h",
    "chars": 3826,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_core_unittest.cc",
    "chars": 3551,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_filterbank.c",
    "chars": 14087,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_filterbank.h",
    "chars": 1865,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_filterbank_unittest.cc",
    "chars": 3313,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_gmm.c",
    "chars": 3079,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_gmm.h",
    "chars": 1440,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_gmm_unittest.cc",
    "chars": 1536,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_sp.c",
    "chars": 5885,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_sp.h",
    "chars": 2096,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_sp_unittest.cc",
    "chars": 2677,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_unittest.cc",
    "chars": 5384,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/vad_unittest.h",
    "chars": 1493,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/common_audio/vad/webrtc_vad.c",
    "chars": 3109,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/checks.cc",
    "chars": 3518,
    "preview": "/*\n *  Copyright 2006 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a B"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/checks.h",
    "chars": 12949,
    "preview": "/*\n *  Copyright 2006 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a B"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/compile_assert_c.h",
    "chars": 842,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/numerics/safe_compare.h",
    "chars": 6632,
    "preview": "/*\n *  Copyright 2016 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a B"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/sanitizer.h",
    "chars": 3576,
    "preview": "/*\n *  Copyright 2016 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a B"
  },
  {
    "path": "thirdparty/webrtc/rtc_base/type_traits.h",
    "chars": 4148,
    "preview": "/*\n *  Copyright 2016 The WebRTC Project Authors. All rights reserved.\n *\n *  Use of this source code is governed by a B"
  },
  {
    "path": "thirdparty/webrtc/system_wrappers/include/cpu_features_wrapper.h",
    "chars": 1473,
    "preview": "/*\n *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "thirdparty/webrtc/typedefs.h",
    "chars": 3808,
    "preview": "/*\n *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.\n *\n *  Use of this source code is governed by"
  },
  {
    "path": "valgrind.sh",
    "chars": 134,
    "preview": "#!/usr/bin/env bash\nFILE=build/vad-demo\nvalgrind --leak-check=full --show-leak-kinds=all --show-reachable=no --track-ori"
  }
]

About this extraction

This page contains the full source code of the Baidu-AIP/speech-vad-demo GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 67 files (347.0 KB), approximately 103.9k tokens, and a symbol index with 213 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!