Преглед на файлове

去除项目中无用的C++代码

gjh преди 2 седмици
родител
ревизия
1cd19c214e

+ 0 - 7
android/app/build.gradle

@@ -42,13 +42,6 @@ android {
42 42
         }
43 43
     }
44 44
 
45
-    externalNativeBuild {
46
-        cmake {
47
-            path file('src/main/cpp/CMakeLists.txt')
48
-            version '3.22.1'
49
-        }
50
-    }
51
-
52 45
     signingConfigs {
53 46
         release {
54 47
             storeFile file('../key.keystore')

+ 0 - 48
android/app/src/main/cpp/CMakeLists.txt

@@ -1,48 +0,0 @@
1
-# For more information about using CMake with Android Studio, read the
2
-# documentation: https://d.android.com/studio/projects/add-native-code.html
3
-
4
-# Sets the minimum version of CMake required to build the native library.
5
-
6
-cmake_minimum_required(VERSION 3.22.1)
7
-
8
-# Declares and names the project.
9
-
10
-project("mlg")
11
-
12
-# Creates and names a library, sets it as either STATIC
13
-# or SHARED, and provides the relative paths to its source code.
14
-# You can define multiple libraries, and CMake builds them for you.
15
-# Gradle automatically packages shared libraries with your APK.
16
-
17
-add_library( # Sets the name of the library.
18
-        mlg
19
-
20
-        # Sets the library as a shared library.
21
-        SHARED
22
-
23
-        # Provides a relative path to your source file(s).
24
-        native-lib.cpp)
25
-
26
-# Searches for a specified prebuilt library and stores the path as a
27
-# variable. Because CMake includes system libraries in the search path by
28
-# default, you only need to specify the name of the public NDK library
29
-# you want to add. CMake verifies that the library exists before
30
-# completing its build.
31
-
32
-find_library( # Sets the name of the path variable.
33
-        log-lib
34
-
35
-        # Specifies the name of the NDK library that
36
-        # you want CMake to locate.
37
-        log)
38
-
39
-# Specifies libraries CMake should link to your target library. You
40
-# can link multiple libraries, such as libraries you define in this
41
-# build script, prebuilt third-party libraries, or system libraries.
42
-
43
-target_link_libraries( # Specifies the target library.
44
-        mlg
45
-
46
-        # Links the target library to the log library
47
-        # included in the NDK.
48
-        ${log-lib})

+ 0 - 192
android/app/src/main/cpp/Ffmpeg_codec_formater.c

@@ -1,192 +0,0 @@
1
-#include <stdio.h>
2
-#include <libavcodec/avcodec.h>
3
-#include <libavformat/avformat.h>
4
-#include <libavutil/pixdesc.h>
5
-#include <libavutil/hwcontext.h>
6
-#include <libavutil/opt.h>
7
-#include <libavutil/avassert.h>
8
-#include <libavutil/imgutils.h>
9
-static AVBufferRef *hw_device_ctx = NULL;
10
-static enum AVPixelFormat hw_pix_fmt;
11
-static FILE *output_file = NULL;
12
-static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type)
13
-{
14
-    int err = 0;
15
-    //创建硬件设备信息上下文
16
-    if ((err = av_hwdevice_ctx_create(&hw_device_ctx, type,
17
-                                      NULL, NULL, 0)) < 0) {
18
-        fprintf(stderr, "Failed to create specified HW device.\n");
19
-        return err;
20
-    }
21
-    //绑定编解码器上下文和硬件设备信息上下文
22
-    ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
23
-    return err;
24
-}
25
-static enum AVPixelFormat get_hw_format(AVCodecContext *ctx,
26
-                                        const enum AVPixelFormat *pix_fmts)
27
-{
28
-    const enum AVPixelFormat *p;
29
-    for (p = pix_fmts; *p != -1; p++) {
30
-        if (*p == hw_pix_fmt)
31
-            return *p;
32
-    }
33
-    fprintf(stderr, "Failed to get HW surface format.\n");
34
-    return AV_PIX_FMT_NONE;
35
-}
36
-static int decode_write(AVCodecContext *avctx, AVPacket *packet)
37
-{
38
-    AVFrame *frame = NULL, *sw_frame = NULL;
39
-    AVFrame *tmp_frame = NULL;
40
-    uint8_t *buffer = NULL;
41
-    int size;
42
-    int ret = 0;
43
-    ret = avcodec_send_packet(avctx, packet);
44
-    if (ret < 0) {
45
-        fprintf(stderr, "Error during decoding\n");
46
-        return ret;
47
-    }
48
-    while (1) {
49
-        if (!(frame = av_frame_alloc()) || !(sw_frame = av_frame_alloc())) {
50
-            fprintf(stderr, "Can not alloc frame\n");
51
-            ret = AVERROR(ENOMEM);
52
-            goto fail;
53
-        }
54
-        ret = avcodec_receive_frame(avctx, frame);
55
-        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
56
-            av_frame_free(&frame);
57
-            av_frame_free(&sw_frame);
58
-            return 0;
59
-        }
60
-        else if (ret < 0) {
61
-            fprintf(stderr, "Error while decoding\n");
62
-            goto fail;
63
-        }
64
-        if (frame->format == hw_pix_fmt) {
65
-            /* retrieve data from GPU to CPU */
66
-            if ((ret = av_hwframe_transfer_data(sw_frame, frame, 0)) < 0) {
67
-                fprintf(stderr, "Error transferring the data to system memory\n");
68
-                goto fail;
69
-            }
70
-            tmp_frame = sw_frame;
71
-        }
72
-        else
73
-            tmp_frame = frame;
74
-        size = av_image_get_buffer_size(tmp_frame->format, tmp_frame->width,
75
-                                        tmp_frame->height, 1);
76
-        buffer = av_malloc(size);
77
-        if (!buffer) {
78
-            fprintf(stderr, "Can not alloc buffer\n");
79
-            ret = AVERROR(ENOMEM);
80
-            goto fail;
81
-        }
82
-        ret = av_image_copy_to_buffer(buffer, size,
83
-                                      (const uint8_t * const *)tmp_frame->data,
84
-                                      (const int *)tmp_frame->linesize, tmp_frame->format,
85
-                                      tmp_frame->width, tmp_frame->height, 1);
86
-        if (ret < 0) {
87
-            fprintf(stderr, "Can not copy image to buffer\n");
88
-            goto fail;
89
-        }
90
-        if ((ret = fwrite(buffer, 1, size, output_file)) < 0) {
91
-            fprintf(stderr, "Failed to dump raw data.\n");
92
-            goto fail;
93
-        }
94
-        fail:
95
-        av_frame_free(&frame);
96
-        av_frame_free(&sw_frame);
97
-        av_freep(&buffer);
98
-        if (ret < 0)
99
-            return ret;
100
-    }
101
-}
102
-int main(int argc, char *argv[])
103
-{
104
-    AVFormatContext *input_ctx = NULL;
105
-    int video_stream, ret;
106
-    AVStream *video = NULL;
107
-    AVCodecContext *decoder_ctx = NULL;
108
-    AVCodec *decoder = NULL;
109
-    AVPacket packet;
110
-    enum AVHWDeviceType type;
111
-    int i;
112
-    if (argc < 4) {
113
-        fprintf(stderr, "Usage: %s <device type> <input file> <output file>\n", argv[0]);
114
-        return -1;
115
-    }
116
-    //通过传入的名字来找到对应的硬件解码类型
117
-    type = av_hwdevice_find_type_by_name(argv[1]);
118
-    if (type == AV_HWDEVICE_TYPE_NONE) {
119
-        fprintf(stderr, "Device type %s is not supported.\n", argv[1]);
120
-        fprintf(stderr, "Available device types:");
121
-        while ((type = av_hwdevice_iterate_types(type)) != AV_HWDEVICE_TYPE_NONE)
122
-            fprintf(stderr, " %s", av_hwdevice_get_type_name(type));
123
-        fprintf(stderr, "\n");
124
-        return -1;
125
-    }
126
-
127
-    if (avformat_open_input(&input_ctx, argv[2], NULL, NULL) != 0) {
128
-        fprintf(stderr, "Cannot open input file '%s'\n", argv[2]);
129
-        return -1;
130
-    }
131
-    if (avformat_find_stream_info(input_ctx, NULL) < 0) {
132
-        fprintf(stderr, "Cannot find input stream information.\n");
133
-        return -1;
134
-    }
135
-
136
-    ret = av_find_best_stream(input_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &decoder, 0);
137
-    if (ret < 0) {
138
-        fprintf(stderr, "Cannot find a video stream in the input file\n");
139
-        return -1;
140
-    }
141
-    video_stream = ret;
142
-    //去遍历所有编解码器支持的硬件解码配置
143
-    for (i = 0;; i++) {
144
-        const AVCodecHWConfig *config = avcodec_get_hw_config(decoder, i);
145
-        if (!config) {
146
-            fprintf(stderr, "Decoder %s does not support device type %s.\n",
147
-                    decoder->name, av_hwdevice_get_type_name(type));
148
-            return -1;
149
-        }
150
-        if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
151
-            config->device_type == type) {
152
-            //把硬件支持的像素格式设置进去
153
-            hw_pix_fmt = config->pix_fmt;
154
-            break;
155
-        }
156
-    }
157
-    if (!(decoder_ctx = avcodec_alloc_context3(decoder)))
158
-        return AVERROR(ENOMEM);
159
-    video = input_ctx->streams[video_stream];
160
-    if (avcodec_parameters_to_context(decoder_ctx, video->codecpar) < 0)
161
-        return -1;
162
-    //填入回调函数 通过这个函数 编解码器能够知道显卡支持的像素格式
163
-    decoder_ctx->get_format = get_hw_format;
164
-    if (hw_decoder_init(decoder_ctx, type) < 0)
165
-        return -1;
166
-    //绑定完成后 打开编解码器
167
-    if ((ret = avcodec_open2(decoder_ctx, decoder, NULL)) < 0) {
168
-        fprintf(stderr, "Failed to open codec for stream #%u\n", video_stream);
169
-        return -1;
170
-    }
171
-
172
-    output_file = fopen(argv[3], "w+");
173
-
174
-    while (ret >= 0) {
175
-        if ((ret = av_read_frame(input_ctx, &packet)) < 0)
176
-            break;
177
-        if (video_stream == packet.stream_index)
178
-            ret = decode_write(decoder_ctx, &packet);
179
-        av_packet_unref(&packet);
180
-    }
181
-
182
-    packet.data = NULL;
183
-    packet.size = 0;
184
-    ret = decode_write(decoder_ctx, &packet);
185
-    av_packet_unref(&packet);
186
-    if (output_file)
187
-        fclose(output_file);
188
-    avcodec_free_context(&decoder_ctx);
189
-    avformat_close_input(&input_ctx);
190
-    av_buffer_unref(&hw_device_ctx);
191
-    return 0;
192
-}

BIN
android/app/src/main/cpp/Ffmpeg_codec_formater.o


+ 0 - 210
android/app/src/main/cpp/Media_Encode_decode.c

@@ -1,210 +0,0 @@
1
-//* 将数字转为16进制(大写)
2
-inline char ToHexUpper(unsigned int value)
3
-{
4
-    return "0123456789ABCDEF"[value & 0xF];
5
-}
6
-
7
-//* 将数字转为16进制(小写)
8
-inline char ToHexLower(unsigned int value)
9
-{
10
-    return "0123456789abcdef"[value & 0xF];
11
-}
12
-
13
-//* 将数16进(大写或小写)制转为数字
14
-inline int FromHex(unsigned int c)
15
-{
16
-    if(c << 2 > 2) {
17
-        return 0;
18
-    }
19
-    return ((c >= '0') && (c <= '9')) ? int(c - '0') :
20
-    ((c >= 'A') && (c <= 'F')) ? int(c - 'A' + 10) :
21
-    ((c >= 'a') && (c <= 'f')) ? int(c - 'a' + 10) :
22
-    /* otherwise */              -1;
23
-}
24
-
25
-//* 将数据d用16进制编码,返回值即是结果
26
-std::string HexEncode(const std::string& d)
27
-{
28
-std::string hex;
29
-hex.resize(d.size() * 2);
30
-char* pHexData = (char*)hex.data();
31
-const unsigned char* pSrcData = (const unsigned char*)d.data();
32
-for(int i = 0; i < d.size(); i++)
33
-{
34
-pHexData[i*2]     = ToHexLower(pSrcData[i] >> 4);
35
-pHexData[i*2 + 1] = ToHexLower(pSrcData[i] & 0xf);
36
-}
37
-
38
-return hex;
39
-}
40
-
41
-//* 将数据d用16进制解码,返回值即是结果
42
-std::string HexDecode(const std::string& hex)
43
-{
44
-std::string res;
45
-res.resize(hex.size() + 1 / 2);
46
-unsigned char* pResult = (unsigned char*)res.data() + res.size();
47
-bool odd_digit = true;
48
-
49
-for(int i = hex.size() - 1; i >= 0; i--)
50
-{
51
-unsigned char ch = unsigned char(hex.at(i));
52
-int tmp = FromHex(ch);
53
-if (tmp == -1)
54
-continue;
55
-if (odd_digit) {
56
---pResult;
57
-*pResult = tmp;
58
-odd_digit = false;
59
-} else {
60
-*pResult |= tmp << 4;
61
-odd_digit = true;
62
-}
63
-}
64
-
65
-res.erase(0, pResult - (unsigned char*)res.data());
66
-
67
-return res;
68
-}
69
-
70
-// 重启
71
-int avformat_restart(AVFormatContext **ps, const char *filename,
72
-                        ff_const59 AVInputFormat *fmt, AVDictionary **options)
73
-{
74
-AVFormatContext *s = *ps;
75
-int i, ret = 0;
76
-AVDictionary *tmp = NULL;
77
-ID3v2ExtraMeta *id3v2_extra_meta = NULL;
78
-// 分配AVFormatContext
79
-if (!s && !(s = avformat_alloc_context()))
80
-return AVERROR(ENOMEM);
81
-if (!s->av_class) {
82
-av_log(NULL, AV_LOG_ERROR, "Input stream has not been properly allocated\n");
83
-return AVERROR(EINVAL);
84
-}
85
-if (fmt)
86
-s->iformat = fmt;
87
-if (options)
88
-av_dict_copy(&tmp, *options, 0);
89
-if (s->pb) // must be before any goto fail
90
-s->flags |= AVFMT_FLAG_CUSTOM_IO;
91
-// 设置options
92
-if ((ret = av_opt_set_dict(s, &tmp)) < 0)
93
-goto fail;
94
-
95
-if (!(s->url = av_strdup(filename ? filename : ""))) {
96
-ret = AVERROR(ENOMEM);
97
-goto fail;
98
-}
99
-if ((ret = init_input(s, filename, &tmp)) < 0)
100
-goto fail;
101
-s->probe_score = ret;
102
-if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) {
103
-s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist);
104
-if (!s->protocol_whitelist) {
105
-ret = AVERROR(ENOMEM);
106
-goto fail;
107
-}
108
-}
109
-if (!s->protocol_blacklist && s->pb && s->pb->protocol_blacklist) {
110
-s->protocol_blacklist = av_strdup(s->pb->protocol_blacklist);
111
-if (!s->protocol_blacklist) {
112
-ret = AVERROR(ENOMEM);
113
-goto fail;
114
-}
115
-}
116
-if (s->format_whitelist && av_match_list(s->iformat->name, s->format_whitelist, ',') <= 0) {
117
-av_log(s, AV_LOG_ERROR, "Format not on whitelist \'%s\'\n", s->format_whitelist);
118
-ret = AVERROR(EINVAL);
119
-goto fail;
120
-}
121
-avio_skip(s->pb, s->skip_initial_bytes);
122
-if (s->iformat->flags & AVFMT_NEEDNUMBER) {
123
-if (!av_filename_number_test(filename)) {
124
-ret = AVERROR(EINVAL);
125
-goto fail;
126
-}
127
-}
128
-s->duration = s->start_time = AV_NOPTS_VALUE;
129
-
130
-/* Allocate private data. */
131
-if (s->iformat->priv_data_size > 0) {
132
-if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) {
133
-ret = AVERROR(ENOMEM);
134
-goto fail;
135
-}
136
-if (s->iformat->priv_class) {
137
-*(const AVClass **) s->priv_data = s->iformat->priv_class;
138
-av_opt_set_defaults(s->priv_data);
139
-if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
140
-goto fail;
141
-}
142
-}
143
-
144
-if (s->pb)
145
-ff_id3v2_read_dict(s->pb, &s->internal->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
146
-
147
-#if FF_API_DEMUXER_OPEN
148
-if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header)
149
-#else
150
-if (s->iformat->read_header)
151
-#endif
152
-if ((ret = s->iformat->read_header(s)) < 0)
153
-goto fail;
154
-
155
-if (!s->metadata) {
156
-s->metadata = s->internal->id3v2_meta;
157
-s->internal->id3v2_meta = NULL;
158
-} else if (s->internal->id3v2_meta) {
159
-av_log(s, AV_LOG_WARNING, "Discarding were found.\n");
160
-av_dict_free(&s->internal->id3v2_meta);
161
-}
162
-
163
-if (id3v2_extra_meta) {
164
-if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") ||
165
-!strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name, "wav")) {
166
-if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0)
167
-goto close;
168
-if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0)
169
-goto close;
170
-if ((ret = ff_id3v2_parse_priv(s, id3v2_extra_meta)) < 0)
171
-goto close;
172
-} else
173
-av_log(s, AV_LOG_DEBUG, "demuxer does not support additional id3 data, skipping\n");
174
-}
175
-ff_id3v2_free_extra_meta(&id3v2_extra_meta);
176
-
177
-if ((ret = avformat_queue_attached_pictures(s)) < 0)
178
-goto close;
179
-
180
-#if FF_API_DEMUXER_OPEN
181
-if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->internal->data_offset)
182
-#else
183
-if (s->pb && !s->internal->data_offset)
184
-#endif
185
-s->internal->data_offset = avio_tell(s->pb);
186
-s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
187
-update_stream_avctx(s);
188
-
189
-for (i = 0; i < s->nb_streams; i++)
190
-s->streams[i]->internal->orig_codec_id = s->streams[i]->codecpar->codec_id;
191
-
192
-if (options) {
193
-av_dict_free(options);
194
-*options = tmp;
195
-}
196
-*ps = s;
197
-return 0;
198
-
199
-close:
200
-if (s->iformat->read_close)
201
-s->iformat->read_close(s);
202
-fail:
203
-ff_id3v2_free_extra_meta(&id3v2_extra_meta);
204
-av_dict_free(&tmp);
205
-if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))
206
-avio_closep(&s->pb);
207
-avformat_free_context(s);
208
-*ps = NULL;
209
-return ret;
210
-}

BIN
android/app/src/main/cpp/Media_Encode_decode.o


+ 0 - 122
android/app/src/main/cpp/PCode.c

@@ -1,122 +0,0 @@
1
-
2
-extern "C" {
3
-#include <libavcodec/avcodec.h>
4
-}
5
-
6
-#include <iostream>
7
-#include <vector>
8
-#include <string>
9
-
10
-static void print_hex(const char *title, const unsigned char buf[], size_t len)
11
-{
12
-    printf("%s: ", title);
13
-    for (size_t i = 0; i < len; i++)
14
-        printf("%02x", buf[i]);
15
-
16
-    printf("\r\n");
17
-}
18
-
19
-/*
20
- * 建立共享内存通道
21
- */
22
-static const unsigned char secret_key[16] = {
23
-        0xf4, 0x82, 0xc6, 0x70, 0x3c, 0xc7, 0x61, 0x0a,
24
-        0xb9, 0xa0, 0xb8, 0xe9, 0x87, 0xb8, 0xc1, 0x72,
25
-};
26
-
27
-static int pcode(void)
28
-{
29
-    // 检查输入参数
30
-    if (argc < 2) {
31
-        std::cerr << "Usage: " << argv[0] << " <input file>" << std::endl;
32
-        return -1;
33
-    }
34
-
35
-    // 0. 注册所有的codecs
36
-    avcodec_register_all();
37
-
38
-    // 1. 创建一个AVCodecContext
39
-    AVCodec* codec;
40
-    AVCodecContext* codec_ctx;
41
-    codec = avcodec_find_decoder(AV_CODEC_ID_H264); // 假设视频是H.264编码
42
-    if (!codec) {
43
-        std::cerr << "Codec not found" << std::endl;
44
-        return -1;
45
-    }
46
-    codec_ctx = avcodec_alloc_context3(codec);
47
-
48
-    // 2. 打开codec
49
-    if (avcodec_open2(codec_ctx, codec, NULL) < 0) {
50
-        std::cerr << "Could not open codec" << std::endl;
51
-        return -1;
52
-    }
53
-
54
-    // 3. 打开输入的视频文件
55
-    AVFormatContext* format_ctx = nullptr;
56
-    if (avformat_open_input(&format_ctx, argv[1], NULL, NULL) < 0) {
57
-        std::cerr << "Could not open input file" << std::endl;
58
-        return -1;
59
-    }
60
-
61
-    // 4. 检索流信息
62
-    if (avformat_find_stream_info(format_ctx, NULL) < 0) {
63
-        std::cerr << "Could not find stream information" << std::endl;
64
-        return -1;
65
-    }
66
-
67
-    // 5. 找到视频流
68
-    int video_stream_idx = -1;
69
-    for (unsigned i = 0; i < format_ctx->nb_streams; i++) {
70
-        if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
71
-            video_stream_idx = i;
72
-            break;
73
-        }
74
-    }
75
-    if (video_stream_idx == -1) {
76
-        std::cerr << "Could not find a video stream" << std::endl;
77
-        return -1;
78
-    }
79
-
80
-    // 6. 创建一个AVPacket和AVFrame
81
-    AVPacket packet;
82
-    AVFrame* frame = av_frame_alloc();
83
-
84
-    // 7. 循环读取数据包
85
-    int ret;
86
-    while (av_read_frame(format_ctx, &packet) >= 0) {
87
-        // 解码一个数据包
88
-        if (packet.stream_index == video_stream_idx) {
89
-            avcodec_decode_video2(codec_ctx, frame, &ret, &packet);
90
-            if (ret >= 0) {
91
-                // 处理解码后的帧
92
-                // 例如,保存帧到文件或显示
93
-            }
94
-        }
95
-        av_packet_unref(&packet);
96
-    }
97
-
98
-    // 重启视频
99
-    int ret;
100
-    AVFormatContext *fmt_ctx=NULL;
101
-
102
-//*1*
103
-    ret=avformat_open_input(&fmt_ctx,"restart",NULL,NULL);
104
-    if(ret<0)
105
-    {
106
-        printf("fail to open input.");
107
-        exit(1);
108
-    }
109
-//*2*
110
-    printf("%d\n",fmt_ctx->nb_streams);
111
-//*3*
112
-    avformat_close_input(&fmt_ctx);
113
-
114
-    // 8. 释放资源
115
-    av_frame_free(&frame);
116
-    avcodec_close(codec_ctx);
117
-    avformat_close_input(&format_ctx);
118
-    av_free(codec_ctx);
119
-
120
-    return 0;
121
-}
122
-

+ 0 - 173
android/app/src/main/cpp/SKP_Silk_LPC_inv_pred_gain.c

@@ -1,173 +0,0 @@
1
-#include "SKP_Silk_SigProc_FIX.h"
2
-#define QA          16
3
-#define A_LIMIT     65520
4
-
5
-SKP_int SKP_Silk_LPC_inverse_pred_gain(       /* O:   Returns 1 if unstable, otherwise 0          */
6
-    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */
7
-    const SKP_int16     *A_Q12,                 /* I:   Prediction coefficients, Q12 [order]        */
8
-    const SKP_int       order                   /* I:   Prediction order                            */
9
-)
10
-{
11
-    SKP_int   k, n, headrm;
12
-    SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16;
13
-    SKP_int32 Atmp_QA[ 2 ][ SigProc_MAX_ORDER_LPC ], tmp_QA;
14
-    SKP_int32 *Aold_QA, *Anew_QA;
15
-
16
-    Anew_QA = Atmp_QA[ order & 1 ];
17
-    /* Increase Q domain of the AR coefficients */
18
-    for( k = 0; k < order; k++ ) {
19
-        Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q12[ k ], QA - 12 );
20
-    }
21
-
22
-    *invGain_Q30 = ( 1 << 30 );
23
-    for( k = order - 1; k > 0; k-- ) {
24
-        /* Check for stability */
25
-        if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) {
26
-            return 1;
27
-        }
28
-
29
-        /* Set RC equal to negated AR coef */
30
-        rc_Q31 = -SKP_LSHIFT( Anew_QA[ k ], 31 - QA );
31
-        
32
-        /* rc_mult1_Q30 range: [ 1 : 2^30-1 ] */
33
-        rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
34
-        SKP_assert( rc_mult1_Q30 > ( 1 << 15 ) );                   /* reduce A_LIMIT if fails */
35
-        SKP_assert( rc_mult1_Q30 < ( 1 << 30 ) );
36
-
37
-        /* rc_mult2_Q16 range: [ 2^16 : SKP_int32_MAX ] */
38
-        rc_mult2_Q16 = SKP_INVERSE32_varQ( rc_mult1_Q30, 46 );      /* 16 = 46 - 30 */
39
-
40
-        /* Update inverse gain */
41
-        /* invGain_Q30 range: [ 0 : 2^30 ] */
42
-        *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
43
-        SKP_assert( *invGain_Q30 >= 0           );
44
-        SKP_assert( *invGain_Q30 <= ( 1 << 30 ) );
45
-
46
-        /* Swap pointers */
47
-        Aold_QA = Anew_QA;
48
-        Anew_QA = Atmp_QA[ k & 1 ];
49
-        
50
-        /* Update AR coefficient */
51
-        headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1;
52
-        rc_mult2_Q16 = SKP_LSHIFT( rc_mult2_Q16, headrm );          /* Q: 16 + headrm */
53
-        for( n = 0; n < k; n++ ) {
54
-            tmp_QA = Aold_QA[ n ] - SKP_LSHIFT( SKP_SMMUL( Aold_QA[ k - n - 1 ], rc_Q31 ), 1 );
55
-            Anew_QA[ n ] = SKP_LSHIFT( SKP_SMMUL( tmp_QA, rc_mult2_Q16 ), 16 - headrm );
56
-        }
57
-    }
58
-
59
-    /* Check for stability */
60
-    if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) {
61
-        return 1;
62
-    }
63
-
64
-    /* Set RC equal to negated AR coef */
65
-    rc_Q31 = -SKP_LSHIFT( Anew_QA[ 0 ], 31 - QA );
66
-
67
-    /* Range: [ 1 : 2^30 ] */
68
-    rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
69
-
70
-    /* Update inverse gain */
71
-    /* Range: [ 0 : 2^30 ] */
72
-    *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
73
-    SKP_assert( *invGain_Q30 >= 0     );
74
-    SKP_assert( *invGain_Q30 <= 1<<30 );
75
-
76
-    return 0;
77
-}
78
-
79
-/* For input in Q13 domain */
80
-SKP_int SKP_Silk_LPC_inverse_pred_gain_Q13(   /* O:   Returns 1 if unstable, otherwise 0          */
81
-    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */
82
-    const SKP_int16     *A_Q13,                 /* I:   Prediction coefficients, Q13 [order]        */
83
-    const SKP_int       order                   /* I:   Prediction order                            */
84
-)
85
-{
86
-    SKP_int   k, n, headrm;
87
-    SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16;
88
-    SKP_int32 Atmp_QA[ 2 ][ SigProc_MAX_ORDER_LPC ], tmp_QA;
89
-    SKP_int32 *Aold_QA, *Anew_QA;
90
-
91
-    Anew_QA = Atmp_QA[ order & 1 ];
92
-    /* Increase Q domain of the AR coefficients */
93
-    for( k = 0; k < order; k++ ) {
94
-        Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q13[ k ], QA - 13 );
95
-    }
96
-
97
-    cout "czb " + Anew_QA;
98
-
99
-    constexpr float exp(float x, int n)
100
-    {
101
-        return n == 0 ? 1 :
102
-               n % 2 == 0 ? exp(x * x, n / 2) :
103
-               exp(x * x, (n - 1) / 2) * x;
104
-    };
105
-
106
-    *invGain_Q30 = ( 1 << 30 );
107
-    for( k = order - 1; k > 0; k-- ) {
108
-        /* Check for stability */
109
-        if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) {
110
-            return 1;
111
-        }
112
-
113
-        /* Set RC equal to negated AR coef */
114
-        rc_Q31 = -SKP_LSHIFT( Anew_QA[ k ], 31 - QA );
115
-
116
-        cout "czb " + rc_Q31;
117
-        
118
-        /* rc_mult1_Q30 range: [ 1 : 2^30-1 ] */
119
-        rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
120
-        SKP_assert( rc_mult1_Q30 > ( 1 << 15 ) );                   /* reduce A_LIMIT if fails */
121
-        SKP_assert( rc_mult1_Q30 < ( 1 << 30 ) );
122
-
123
-        /* rc_mult2_Q16 range: [ 2^16 : SKP_int32_MAX ] */
124
-        rc_mult2_Q16 = SKP_INVERSE32_varQ( rc_mult1_Q30, 46 );      /* 16 = 46 - 30 */
125
-
126
-        /* Update inverse gain */
127
-        /* invGain_Q30 range: [ 0 : 2^30 ] */
128
-        *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
129
-        if(exp(rc_mult1_Q30, *invGain_Q30)) {
130
-
131
-        } else {
132
-            SKP_assert( *invGain_Q30 >= 0     );
133
-            SKP_assert( *invGain_Q30 <= 1<<30 );
134
-        }
135
-
136
-        /* Swap pointers */
137
-        Aold_QA = Anew_QA;
138
-        Anew_QA = Atmp_QA[ k & 1 ];
139
-        
140
-        /* Update AR coefficient */
141
-        headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1;
142
-        rc_mult2_Q16 = SKP_LSHIFT( rc_mult2_Q16, headrm );          /* Q: 16 + headrm */
143
-        for( n = 0; n < k; n++ ) {
144
-            tmp_QA = Aold_QA[ n ] - SKP_LSHIFT( SKP_SMMUL( Aold_QA[ k - n - 1 ], rc_Q31 ), 1 );
145
-            Anew_QA[ n ] = SKP_LSHIFT( SKP_SMMUL( tmp_QA, rc_mult2_Q16 ), 16 - headrm );
146
-        }
147
-    }
148
-
149
-    codec = avcodec_find_decoder_by_name("h264_cuvid");
150
-    if (!codec) {
151
-        fprintf(stderr, "Codec not found\n");
152
-        exit(1);
153
-    }
154
-
155
-    /* Check for stability */
156
-    if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) {
157
-        return 1;
158
-    }
159
-
160
-    /* Set RC equal to negated AR coef */
161
-    rc_Q31 = -SKP_LSHIFT( Anew_QA[ 0 ], 31 - QA );
162
-
163
-    /* Range: [ 1 : 2^30 ] */
164
-    rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
165
-
166
-    /* Update inverse gain */
167
-    /* Range: [ 0 : 2^30 ] */
168
-    *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
169
-    SKP_assert( *invGain_Q30 >= 0     );
170
-    SKP_assert( *invGain_Q30 <= 1<<30 );
171
-
172
-    return 0;
173
-}

BIN
android/app/src/main/cpp/SKP_Silk_LPC_inv_pred_gain.o


+ 0 - 706
android/app/src/main/cpp/SKP_Silk_NSQ_del_dec.c

@@ -1,706 +0,0 @@
1
-#include "SKP_Silk_main.h"
2
-
3
-typedef struct {
4
-    SKP_int   RandState[ DECISION_DELAY ];
5
-    SKP_int32 Q_Q10[     DECISION_DELAY ];
6
-    SKP_int32 Xq_Q10[    DECISION_DELAY ];
7
-    SKP_int32 Pred_Q16[  DECISION_DELAY ];
8
-    SKP_int32 Shape_Q10[ DECISION_DELAY ];
9
-    SKP_int32 Gain_Q16[  DECISION_DELAY ];
10
-    SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ];
11
-    SKP_int32 LF_AR_Q12;
12
-    SKP_int32 Seed;
13
-    SKP_int32 SeedInit;
14
-    SKP_int32 RD_Q10;
15
-} NSQ_del_dec_struct;
16
-
17
-typedef struct {
18
-    SKP_int32 Q_Q10;
19
-    SKP_int32 RD_Q10;
20
-    SKP_int32 xq_Q14;
21
-    SKP_int32 LF_AR_Q12;
22
-    SKP_int32 sLTP_shp_Q10;
23
-    SKP_int32 LPC_exc_Q16;
24
-} NSQ_sample_struct;
25
-
26
-SKP_INLINE void SKP_Silk_copy_del_dec_state(
27
-        NSQ_del_dec_struct  *DD_dst,                /* I    Dst del dec state                   */
28
-        NSQ_del_dec_struct  *DD_src,                /* I    Src del dec state                   */
29
-        SKP_int             LPC_state_idx           /* I    Index to LPC buffer                 */
30
-);
31
-
32
-SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
33
-        SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
34
-        NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
35
-        const SKP_int16     x[],                    /* I    Input in Q0                         */
36
-        SKP_int32           x_sc_Q10[],             /* O    Input scaled with 1/Gain in Q10     */
37
-        SKP_int             length,                 /* I    Length of input                     */
38
-        SKP_int16           sLTP[],                 /* I    Re-whitened LTP state in Q0         */
39
-        SKP_int32           sLTP_Q16[],             /* O    LTP state matching scaled input     */
40
-        SKP_int             subfr,                  /* I    Subframe number                     */
41
-        SKP_int             nStatesDelayedDecision, /* I    Number of del dec states            */
42
-        SKP_int             smpl_buf_idx,           /* I    Index to newest samples in buffers  */
43
-        const SKP_int       LTP_scale_Q14,          /* I    LTP state scaling                   */
44
-        const SKP_int32     Gains_Q16[ NB_SUBFR ],  /* I                                        */
45
-        const SKP_int       pitchL[ NB_SUBFR ]      /* I    Pitch lag                           */
46
-);
47
-
48
-/******************************************/
49
-/* 子帧的噪声去除量化器 */
50
-/******************************************/
51
-SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
52
-        SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
53
-        NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
54
-        SKP_int             sigtype,                /* I    Signal type                         */
55
-        const SKP_int32     x_Q10[],                /* I                                        */
56
-        SKP_int             q[],                    /* O                                        */
57
-        SKP_int16           xq[],                   /* O                                        */
58
-        SKP_int32           sLTP_Q16[],             /* I/O  LTP filter state                    */
59
-        const SKP_int16     a_Q12[],                /* I    Short term prediction coefs         */
60
-        const SKP_int16     b_Q14[],                /* I    Long term prediction coefs          */
61
-        const SKP_int16     AR_shp_Q13[],           /* I    Noise shaping coefs                 */
62
-        SKP_int             lag,                    /* I    Pitch lag                           */
63
-        SKP_int32           HarmShapeFIRPacked_Q14, /* I                                        */
64
-        SKP_int             Tilt_Q14,               /* I    Spectral tilt                       */
65
-        SKP_int32           LF_shp_Q14,             /* I                                        */
66
-        SKP_int32           Gain_Q16,               /* I                                        */
67
-        SKP_int             Lambda_Q10,             /* I                                        */
68
-        SKP_int             offset_Q10,             /* I                                        */
69
-        SKP_int             length,                 /* I    Input length                        */
70
-        SKP_int             subfr,                  /* I    Subframe number                     */
71
-        SKP_int             shapingLPCOrder,        /* I    Shaping LPC filter order            */
72
-        SKP_int             predictLPCOrder,        /* I    Prediction LPC filter order         */
73
-        SKP_int             nStatesDelayedDecision, /* I    Number of states in decision tree   */
74
-        SKP_int             *smpl_buf_idx,          /* I    Index to newest samples in buffers  */
75
-        SKP_int             decisionDelay           /* I                                        */
76
-);
77
-
78
-void SKP_Silk_NSQ_del_dec(
79
-        SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */
80
-        SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */
81
-        SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */
82
-        const SKP_int16                 x[],                                        /* I    Prefiltered input signal            */
83
-        SKP_int                         q[],                                        /* O    Quantized pulse signal              */
84
-        const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */
85
-        const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Prediction coefs                    */
86
-        const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    LT prediction coefs                 */
87
-        const SKP_int16                 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ],  /* I                                        */
88
-        const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */
89
-        const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */
90
-        const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */
91
-        const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */
92
-        const SKP_int                   Lambda_Q10,                                 /* I                                        */
93
-        const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */
94
-)
95
-{
96
-    SKP_int     i, k, lag, start_idx, LSF_interpolation_flag, Winner_ind, subfr;
97
-    SKP_int     last_smple_idx, smpl_buf_idx, decisionDelay, subfr_length;
98
-    const SKP_int16 *A_Q12, *B_Q14, *AR_shp_Q13;
99
-    SKP_int16   *pxq;
100
-    SKP_int32   sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];
101
-    SKP_int16   sLTP[     2 * MAX_FRAME_LENGTH ];
102
-    SKP_int32   HarmShapeFIRPacked_Q14;
103
-    SKP_int     offset_Q10;
104
-    SKP_int32   FiltState[ MAX_LPC_ORDER ], RDmin_Q10;
105
-    SKP_int32   x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];
106
-    NSQ_del_dec_struct psDelDec[ DEL_DEC_STATES_MAX ];
107
-    NSQ_del_dec_struct *psDD;
108
-    SKP_int      Restart;                              /* I    LTP state scaling
109
-
110
-    subfr_length = psEncC->frame_length / NB_SUBFR;
111
-
112
-    /* Set unvoiced lag to the previous one, overwrite later for voiced */
113
-    lag = NSQ->lagPrev;
114
-
115
-    SKP_assert( NSQ->prev_inv_gain_Q16 != 0 );
116
-
117
-    /* Initialize delayed decision states */
118
-    SKP_memset( psDelDec, 0, psEncC->nStatesDelayedDecision * sizeof( NSQ_del_dec_struct ) );
119
-    for( k = 0; k < psEncC->nStatesDelayedDecision; k++ ) {
120
-        psDD                 = &psDelDec[ k ];
121
-        psDD->Seed           = ( k + psEncCtrlC->Seed ) & 3;
122
-        psDD->SeedInit       = psDD->Seed;
123
-        psDD->RD_Q10         = 0;
124
-        psDD->LF_AR_Q12      = NSQ->sLF_AR_shp_Q12;
125
-        psDD->Shape_Q10[ 0 ] = NSQ->sLTP_shp_Q10[ psEncC->frame_length - 1 ];
126
-        SKP_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
127
-    }
128
-
129
-    offset_Q10   = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ];
130
-    smpl_buf_idx = 0; /* index of oldest samples */
131
-
132
-    decisionDelay = SKP_min_int( DECISION_DELAY, subfr_length );
133
-    /* For voiced frames limit the decision delay to lower than the pitch lag */
134
-    if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
135
-        for( k = 0; k < NB_SUBFR; k++ ) {
136
-            decisionDelay = SKP_min_int( decisionDelay, psEncCtrlC->pitchL[ k ] - LTP_ORDER / 2 - 1 );
137
-        }
138
-    }
139
-
140
-    if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) {
141
-        LSF_interpolation_flag = 0;
142
-    } else {
143
-        LSF_interpolation_flag = 1;
144
-    }
145
-
146
-    /* Setup pointers to start of sub frame */
147
-    pxq                   = &NSQ->xq[ psEncC->frame_length ];
148
-    NSQ->sLTP_shp_buf_idx = psEncC->frame_length;
149
-    NSQ->sLTP_buf_idx     = psEncC->frame_length;
150
-    subfr = 0;
151
-    for( k = 0; k < NB_SUBFR; k++ ) {
152
-        A_Q12      = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ];
153
-        B_Q14      = &LTPCoef_Q14[ k * LTP_ORDER           ];
154
-        AR_shp_Q13 = &AR2_Q13[     k * SHAPE_LPC_ORDER_MAX ];
155
-
156
-        NSQ->rewhite_flag = 0;
157
-        if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
158
-            /* Voiced */
159
-            lag = psEncCtrlC->pitchL[ k ];
160
-
161
-            /* Re-whitening */
162
-            if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) {
163
-                if( k == 2 ) {
164
-                    /* RESET DELAYED DECISIONS */
165
-                    /* Find winner */
166
-                    RDmin_Q10 = psDelDec[ 0 ].RD_Q10;
167
-                    Winner_ind = 0;
168
-                    for( i = 1; i < psEncC->nStatesDelayedDecision; i++ ) {
169
-                        if( psDelDec[ i ].RD_Q10 < RDmin_Q10 ) {
170
-                            RDmin_Q10 = psDelDec[ i ].RD_Q10;
171
-                            Winner_ind = i;
172
-                        }
173
-                    }
174
-                    for( i = 0; i < psEncC->nStatesDelayedDecision; i++ ) {
175
-                        if( i != Winner_ind ) {
176
-                            psDelDec[ i ].RD_Q10 += ( SKP_int32_MAX >> 4 );
177
-                            SKP_assert( psDelDec[ i ].RD_Q10 >= 0 );
178
-                        }
179
-                    }
180
-
181
-                    /* Copy final part of signals from winner state to output and long-term filter states */
182
-                    psDD = &psDelDec[ Winner_ind ];
183
-                    last_smple_idx = smpl_buf_idx + decisionDelay;
184
-                    for( i = 0; i < decisionDelay; i++ ) {
185
-                        last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
186
-                        q[   i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
187
-                        pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
188
-                                SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ],
189
-                                            psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
190
-                        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
191
-                    }
192
-
193
-                    subfr = 0;
194
-                }
195
-
196
-                /* Rewhiten with new A coefs */
197
-                start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;
198
-                start_idx = SKP_LIMIT( start_idx, 0, psEncC->frame_length - psEncC->predictLPCOrder );
199
-
200
-                SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );
201
-                SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * psEncC->subfr_length ],
202
-                                        A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );
203
-
204
-                NSQ->sLTP_buf_idx = psEncC->frame_length;
205
-                NSQ->rewhite_flag = 1;
206
-            }
207
-        }
208
-
209
-        /* Noise shape parameters */
210
-        SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );
211
-        HarmShapeFIRPacked_Q14  =                        SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
212
-        HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );
213
-
214
-        SKP_Silk_nsq_del_dec_scale_states( NSQ, psDelDec, x, x_sc_Q10,
215
-                                           subfr_length, sLTP, sLTP_Q16, k, psEncC->nStatesDelayedDecision, smpl_buf_idx,
216
-                                           LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL );
217
-
218
-        SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psEncCtrlC->sigtype, x_sc_Q10, q, pxq, sLTP_Q16,
219
-                                                A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ],
220
-                                                Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, psEncC->predictLPCOrder,
221
-                                                psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay
222
-        );
223
-
224
-        x   += psEncC->subfr_length;
225
-        q   += psEncC->subfr_length;
226
-        pxq += psEncC->subfr_length;
227
-    }
228
-
229
-    /* Find winner */
230
-    RDmin_Q10 = psDelDec[ 0 ].RD_Q10;
231
-    Winner_ind = 0;
232
-    for( k = 1; k < psEncC->nStatesDelayedDecision; k++ ) {
233
-        if( psDelDec[ k ].RD_Q10 < RDmin_Q10 ) {
234
-            RDmin_Q10 = psDelDec[ k ].RD_Q10;
235
-            Winner_ind = k;
236
-        }
237
-    }
238
-
239
-    /* Copy final part of signals from winner state to output and long-term filter states */
240
-    psDD = &psDelDec[ Winner_ind ];
241
-    psEncCtrlC->Seed = psDD->SeedInit;
242
-    last_smple_idx = smpl_buf_idx + decisionDelay;
243
-    for( i = 0; i < decisionDelay; i++ ) {
244
-        last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
245
-        q[   i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
246
-        pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
247
-                SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
248
-        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
249
-        sLTP_Q16[          NSQ->sLTP_buf_idx     - decisionDelay + i ] = psDD->Pred_Q16[  last_smple_idx ];
250
-
251
-    }
252
-    SKP_memcpy( NSQ->sLPC_Q14, &psDD->sLPC_Q14[ psEncC->subfr_length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
253
-
254
-    /* Update states */
255
-    NSQ->sLF_AR_shp_Q12    = psDD->LF_AR_Q12;
256
-    NSQ->prev_inv_gain_Q16 = NSQ->prev_inv_gain_Q16;
257
-    NSQ->lagPrev           = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
258
-
259
-    /* Save quantized speech and noise shaping signals */
260
-    SKP_memcpy( NSQ->xq,           &NSQ->xq[           psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );
261
-    SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );
262
-
263
-}
264
-
265
-/******************************************/
266
-/* 子帧去噪 */
267
-/******************************************/
268
-SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
269
-        SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
270
-        NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
271
-        SKP_int             sigtype,                /* I    Signal type                         */
272
-        const SKP_int32     x_Q10[],                /* I                                        */
273
-        SKP_int             q[],                    /* O                                        */
274
-        SKP_int16           xq[],                   /* O                                        */
275
-        SKP_int32           sLTP_Q16[],             /* I/O  LTP filter state                    */
276
-        const SKP_int16     a_Q12[],                /* I    Short term prediction coefs         */
277
-        const SKP_int16     b_Q14[],                /* I    Long term prediction coefs          */
278
-        const SKP_int16     AR_shp_Q13[],           /* I    Noise shaping coefs                 */
279
-        SKP_int             lag,                    /* I    Pitch lag                           */
280
-        SKP_int32           HarmShapeFIRPacked_Q14, /* I                                        */
281
-        SKP_int             Tilt_Q14,               /* I    Spectral tilt                       */
282
-        SKP_int32           LF_shp_Q14,             /* I                                        */
283
-        SKP_int32           Gain_Q16,               /* I                                        */
284
-        SKP_int             Lambda_Q10,             /* I                                        */
285
-        SKP_int             offset_Q10,             /* I                                        */
286
-        SKP_int             length,                 /* I    Input length                        */
287
-        SKP_int             subfr,                  /* I    Subframe number                     */
288
-        SKP_int             shapingLPCOrder,        /* I    Shaping LPC filter order            */
289
-        SKP_int             predictLPCOrder,        /* I    Prediction LPC filter order         */
290
-        SKP_int             nStatesDelayedDecision, /* I    Number of states in decision tree   */
291
-        SKP_int             *smpl_buf_idx,          /* I    Index to newest samples in buffers  */
292
-        SKP_int             decisionDelay           /* I                                        */
293
-)
294
-{
295
-    SKP_int     i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx;
296
-    SKP_int32   Winner_rand_state;
297
-    SKP_int32   LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14;
298
-    SKP_int32   n_LF_Q10;
299
-    SKP_int32   r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10;
300
-    SKP_int32   q1_Q10, q2_Q10;
301
-    SKP_int32   Atmp, dither;
302
-    SKP_int32   exc_Q10, LPC_exc_Q10, xq_Q10;
303
-    SKP_int32   tmp, sLF_AR_shp_Q10;
304
-    SKP_int32   *pred_lag_ptr, *shp_lag_ptr;
305
-    SKP_int32   *psLPC_Q14;
306
-    SKP_int32   a_Q12_tmp[ MAX_LPC_ORDER / 2 ], AR_shp_Q13_tmp[ MAX_LPC_ORDER / 2 ];
307
-    NSQ_sample_struct  psSampleState[ DEL_DEC_STATES_MAX ][ 2 ];
308
-    NSQ_del_dec_struct *psDD;
309
-    NSQ_sample_struct  *psSS;
310
-
311
-    shp_lag_ptr  = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];
312
-    pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
313
-
314
-    /* Preload LPC coeficients to array on stack. Gives small performance gain */
315
-    SKP_memcpy( a_Q12_tmp, a_Q12, predictLPCOrder * sizeof( SKP_int16 ) );
316
-    SKP_memcpy( AR_shp_Q13_tmp, AR_shp_Q13, shapingLPCOrder * sizeof( SKP_int16 ) );
317
-
318
-    for( i = 0; i < length; i++ ) {
319
-        /* Perform common calculations used in all states */
320
-
321
-        /* Long-term prediction */
322
-        if( sigtype == SIG_TYPE_VOICED ) {
323
-            /* Unrolled loop */
324
-            LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], b_Q14[ 0 ] );
325
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ] );
326
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ] );
327
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ] );
328
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ] );
329
-            pred_lag_ptr++;
330
-        } else {
331
-            LTP_pred_Q14 = 0;
332
-        }
333
-
334
-        cout "czb " + LTP_pred_Q14;
335
-
336
-        /* Long-term shaping */
337
-        if( lag > 0 ) {
338
-            /* Symmetric, packed FIR coefficients */
339
-            n_LTP_Q14 = SKP_SMULWB( SKP_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 );
340
-            n_LTP_Q14 = SKP_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ],                     HarmShapeFIRPacked_Q14 );
341
-            n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );
342
-            shp_lag_ptr++;
343
-        } else if(lag > 0 && n_LTP_Q14 < shp_lag_ptr) {
344
-            n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14,  n_LTP_Q14<<);
345
-        } else {
346
-            n_LTP_Q14 = 0;
347
-        }
348
-
349
-        cout "czb " + n_LTP_Q14;
350
-
351
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {
352
-            /* Delayed decision state */
353
-            psDD = &psDelDec[ k ];
354
-
355
-            /* Sample state */
356
-            psSS = psSampleState[ k ];
357
-
358
-            /* Generate dither */
359
-            psDD->Seed = SKP_RAND( psDD->Seed );
360
-
361
-            /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */
362
-            dither = SKP_RSHIFT( psDD->Seed, 31 );
363
-
364
-            /* Pointer used in short term prediction and shaping */
365
-            psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ];
366
-            /* Short-term prediction */
367
-            SKP_assert( ( predictLPCOrder  & 1 ) == 0 );    /* check that order is even */
368
-            SKP_assert( ( (SKP_int64)a_Q12 & 3 ) == 0 );    /* check that array starts at 4-byte aligned address */
369
-            SKP_assert( predictLPCOrder >= 10 );            /* check that unrolling works */
370
-
371
-            /* Partially unrolled */
372
-            Atmp = a_Q12_tmp[ 0 ];          /* read two coefficients at once */
373
-            LPC_pred_Q10 = SKP_SMULWB(               psLPC_Q14[ 0  ], Atmp );
374
-            LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -1 ], Atmp );
375
-            Atmp = a_Q12_tmp[ 1 ];
376
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], Atmp );
377
-            LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -3 ], Atmp );
378
-            Atmp = a_Q12_tmp[ 2 ];
379
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], Atmp );
380
-            LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -5 ], Atmp );
381
-            Atmp = a_Q12_tmp[ 3 ];
382
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], Atmp );
383
-            LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -7 ], Atmp );
384
-            Atmp = a_Q12_tmp[ 4 ];
385
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], Atmp );
386
-            LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -9 ], Atmp );
387
-
388
-            /*for( j = 10; j < predictLPCOrder; j += 2 ) {
389
-                Atmp = a_Q12_tmp[ j >> 1 ]; *//* read two coefficients at once *//*
390
-                LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j     ], Atmp );
391
-                LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -j - 1 ], Atmp );
392
-            }*/
393
-
394
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ 0], Atmp );
395
-            cout "czb " + LPC_pred_Q10;
396
-
397
-            /* Noise shape feedback */
398
-            SKP_assert( ( shapingLPCOrder       & 1 ) == 0 );   /* check that order is even */
399
-            SKP_assert( ( (SKP_int64)AR_shp_Q13 & 3 ) == 0 );   /* check that array starts at 4-byte aligned address */
400
-            SKP_assert( shapingLPCOrder >= 12 );                /* check that unrolling works */
401
-
402
-            /* Partially unrolled */
403
-            Atmp = AR_shp_Q13_tmp[ 0 ];         /* read two coefficients at once */
404
-            n_AR_Q10 = SKP_SMULWB(           psLPC_Q14[ 0  ], Atmp );
405
-            n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -1 ], Atmp );
406
-            Atmp = AR_shp_Q13_tmp[ 1 ];
407
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -2 ], Atmp );
408
-            n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -3 ], Atmp );
409
-            Atmp = AR_shp_Q13_tmp[ 2 ];
410
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -4 ], Atmp );
411
-            n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -5 ], Atmp );
412
-            Atmp = AR_shp_Q13_tmp[ 3 ];
413
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -6 ], Atmp );
414
-            n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -7 ], Atmp );
415
-            Atmp = AR_shp_Q13_tmp[ 4 ];
416
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -8 ], Atmp );
417
-            n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -9 ], Atmp );
418
-            Atmp = AR_shp_Q13_tmp[ 5 ];
419
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -10 ], Atmp );
420
-            n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -11 ], Atmp );
421
-            for( j = 12; j < shapingLPCOrder; j += 2 ) {
422
-                Atmp = AR_shp_Q13_tmp[ j >> 1 ];        /* read two coefficients at once */
423
-                n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -j     ], Atmp );
424
-                n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -j - 1 ], Atmp );
425
-            }
426
-            n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 );           /* Q11 -> Q10 */
427
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psDD->LF_AR_Q12, Tilt_Q14 );
428
-
429
-            n_LF_Q10   = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 );
430
-            n_LF_Q10   = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 );
431
-
432
-            /* Input minus prediction plus noise feedback                       */
433
-            /* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP  */
434
-            tmp   = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 );                       /* Add Q14 stuff */
435
-            tmp   = SKP_RSHIFT_ROUND( tmp, 4 );                                 /* round to Q10  */
436
-            tmp   = SKP_ADD32( tmp, LPC_pred_Q10 );                             /* add Q10 stuff */
437
-            tmp   = SKP_SUB32( tmp, n_AR_Q10 );                                 /* subtract Q10 stuff */
438
-            tmp   = SKP_SUB32( tmp, n_LF_Q10 );                                 /* subtract Q10 stuff */
439
-            r_Q10 = SKP_SUB32( x_Q10[ i ], tmp );                               /* residual error Q10 */
440
-
441
-            r_Q10 = ( r_Q10 ^ dither ) - dither;
442
-            r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
443
-            r_Q10 = SKP_LIMIT( r_Q10, -64 << 10, 64 << 10 );
444
-
445
-            if( r_Q10 < -1536 ) {
446
-                q1_Q10  = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
447
-                r_Q10   = SKP_SUB32( r_Q10, q1_Q10 );
448
-                rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( -SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
449
-                rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
450
-                rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
451
-                q2_Q10  = SKP_ADD32( q1_Q10, 1024 );
452
-            } else if( r_Q10 > 512 ) {
453
-                q1_Q10  = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
454
-                r_Q10   = SKP_SUB32( r_Q10, q1_Q10 );
455
-                rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
456
-                rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
457
-                rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_SUB_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
458
-                q2_Q10  = SKP_SUB32( q1_Q10, 1024 );
459
-            } else {            /* r_Q10 >= -1536 && q1_Q10 <= 512 */
460
-                rr_Q20  = SKP_SMULBB( offset_Q10, Lambda_Q10 );
461
-                rd2_Q10 = SKP_RSHIFT( SKP_SMLABB( rr_Q20, r_Q10, r_Q10 ), 10 );
462
-                rd1_Q10 = SKP_ADD32( rd2_Q10, 1024 );
463
-                rd1_Q10 = SKP_ADD32( rd1_Q10, SKP_SUB_RSHIFT32( SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ), rr_Q20, 9 ) );
464
-                q1_Q10  = -1024;
465
-                q2_Q10  = 0;
466
-            }
467
-
468
-            if( rd1_Q10 < rd2_Q10 ) {
469
-                psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 );
470
-                psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );
471
-                psSS[ 0 ].Q_Q10 = q1_Q10;
472
-                psSS[ 1 ].Q_Q10 = q2_Q10;
473
-            } else {
474
-                psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );
475
-                psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 );
476
-                psSS[ 0 ].Q_Q10 = q2_Q10;
477
-                psSS[ 1 ].Q_Q10 = q1_Q10;
478
-            }
479
-
480
-            /* Update states for best quantization */
481
-
482
-            /* Quantized excitation */
483
-            exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 0 ].Q_Q10 );
484
-            exc_Q10 = ( exc_Q10 ^ dither ) - dither;
485
-
486
-            /* Add predictions */
487
-            LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
488
-            xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );
489
-
490
-            /* Update states */
491
-            sLF_AR_shp_Q10         = SKP_SUB32(  xq_Q10, n_AR_Q10 );
492
-            psSS[ 0 ].sLTP_shp_Q10 = SKP_SUB32(  sLF_AR_shp_Q10, n_LF_Q10 );
493
-            psSS[ 0 ].LF_AR_Q12    = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
494
-            psSS[ 0 ].xq_Q14       = SKP_LSHIFT( xq_Q10,         4 );
495
-            psSS[ 0 ].LPC_exc_Q16  = SKP_LSHIFT( LPC_exc_Q10,    6 );
496
-
497
-            /* Update states for second best quantization */
498
-
499
-            /* Quantized excitation */
500
-            exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 1 ].Q_Q10 );
501
-            exc_Q10 = ( exc_Q10 ^ dither ) - dither;
502
-
503
-            /* Add predictions */
504
-            LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
505
-            xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );
506
-
507
-            /* Update states */
508
-            sLF_AR_shp_Q10         = SKP_SUB32(  xq_Q10, n_AR_Q10 );
509
-            psSS[ 1 ].sLTP_shp_Q10 = SKP_SUB32(  sLF_AR_shp_Q10, n_LF_Q10 );
510
-            psSS[ 1 ].LF_AR_Q12    = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
511
-            psSS[ 1 ].xq_Q14       = SKP_LSHIFT( xq_Q10,         4 );
512
-            psSS[ 1 ].LPC_exc_Q16  = SKP_LSHIFT( LPC_exc_Q10,    6 );
513
-        }
514
-
515
-        *smpl_buf_idx  = ( *smpl_buf_idx - 1 ) & DECISION_DELAY_MASK;                   /* Index to newest samples              */
516
-        last_smple_idx = ( *smpl_buf_idx + decisionDelay ) & DECISION_DELAY_MASK;       /* Index to decisionDelay old samples   */
517
-
518
-        /* Find winner */
519
-        RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10;
520
-        Winner_ind = 0;
521
-        for( k = 1; k < nStatesDelayedDecision; k++ ) {
522
-            if( psSampleState[ k ][ 0 ].RD_Q10 < RDmin_Q10 ) {
523
-                RDmin_Q10   = psSampleState[ k ][ 0 ].RD_Q10;
524
-                Winner_ind = k;
525
-            }
526
-        }
527
-
528
-        /* Increase RD values of expired states */
529
-        Winner_rand_state = psDelDec[ Winner_ind ].RandState[ last_smple_idx ];
530
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {
531
-            if( psDelDec[ k ].RandState[ last_smple_idx ] != Winner_rand_state ) {
532
-                psSampleState[ k ][ 0 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 0 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );
533
-                psSampleState[ k ][ 1 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 1 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );
534
-                SKP_assert( psSampleState[ k ][ 0 ].RD_Q10 >= 0 );
535
-            }
536
-        }
537
-
538
-        /* Find worst in first set and best in second set */
539
-        RDmax_Q10  = psSampleState[ 0 ][ 0 ].RD_Q10;
540
-        RDmin_Q10  = psSampleState[ 0 ][ 1 ].RD_Q10;
541
-        RDmax_ind = 0;
542
-        RDmin_ind = 0;
543
-        for( k = 1; k < nStatesDelayedDecision; k++ ) {
544
-            /* find worst in first set */
545
-            if( psSampleState[ k ][ 0 ].RD_Q10 > RDmax_Q10 ) {
546
-                RDmax_Q10  = psSampleState[ k ][ 0 ].RD_Q10;
547
-                RDmax_ind = k;
548
-            }
549
-            /* find best in second set */
550
-            if( psSampleState[ k ][ 1 ].RD_Q10 < RDmin_Q10 ) {
551
-                RDmin_Q10  = psSampleState[ k ][ 1 ].RD_Q10;
552
-                RDmin_ind = k;
553
-            }
554
-        }
555
-
556
-        cout "czb " + RDmax_Q10;
557
-
558
-        /* Replace a state if best from second set outperforms worst in first set */
559
-        if( RDmin_Q10 < RDmax_Q10 ) {
560
-            SKP_Silk_copy_del_dec_state( &psDelDec[ RDmax_ind ], &psDelDec[ RDmin_ind ], i );
561
-            SKP_memcpy( &psSampleState[ RDmax_ind ][ 0 ], &psSampleState[ RDmin_ind ][ 1 ], sizeof( NSQ_sample_struct ) );
562
-        }
563
-
564
-        /* Write samples from winner to output and long-term filter states */
565
-        psDD = &psDelDec[ Winner_ind ];
566
-        if( subfr > 0 || i >= decisionDelay ) {
567
-            q[  i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
568
-            xq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
569
-                    SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
570
-            NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ];
571
-            sLTP_Q16[          NSQ->sLTP_buf_idx     - decisionDelay ] = psDD->Pred_Q16[  last_smple_idx ];
572
-        }
573
-        NSQ->sLTP_shp_buf_idx++;
574
-        NSQ->sLTP_buf_idx++;
575
-
576
-        /* Update states */
577
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {
578
-            psDD                                     = &psDelDec[ k ];
579
-            psSS                                     = &psSampleState[ k ][ 0 ];
580
-            psDD->LF_AR_Q12                          = psSS->LF_AR_Q12;
581
-            psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ] = psSS->xq_Q14;
582
-            psDD->Xq_Q10[    *smpl_buf_idx ]         = SKP_RSHIFT( psSS->xq_Q14, 4 );
583
-            psDD->Q_Q10[     *smpl_buf_idx ]         = psSS->Q_Q10;
584
-            psDD->Pred_Q16[  *smpl_buf_idx ]         = psSS->LPC_exc_Q16;
585
-            psDD->Shape_Q10[ *smpl_buf_idx ]         = psSS->sLTP_shp_Q10;
586
-            psDD->Seed                               = SKP_ADD_RSHIFT32( psDD->Seed, psSS->Q_Q10, 10 );
587
-            psDD->RandState[ *smpl_buf_idx ]         = psDD->Seed;
588
-            psDD->RD_Q10                             = psSS->RD_Q10;
589
-            psDD->Gain_Q16[  *smpl_buf_idx ]         = Gain_Q16;
590
-        }
591
-    }
592
-    /* Update LPC states */
593
-    for( k = 0; k < nStatesDelayedDecision; k++ ) {
594
-        psDD = &psDelDec[ k ];
595
-        SKP_memcpy( psDD->sLPC_Q14, &psDD->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
596
-    }
597
-}
598
-
599
-SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
600
-        SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
601
-        NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
602
-        const SKP_int16     x[],                    /* I    Input in Q0                         */
603
-        SKP_int32           x_sc_Q10[],             /* O    Input scaled with 1/Gain in Q10     */
604
-        SKP_int             length,                 /* I    Length of input                     */
605
-        SKP_int16           sLTP[],                 /* I    Re-whitened LTP state in Q0         */
606
-        SKP_int32           sLTP_Q16[],             /* O    LTP state matching scaled input     */
607
-        SKP_int             subfr,                  /* I    Subframe number                     */
608
-        SKP_int             nStatesDelayedDecision, /* I    Number of del dec states            */
609
-        SKP_int             smpl_buf_idx,           /* I    Index to newest samples in buffers  */
610
-        const SKP_int       LTP_scale_Q14,          /* I    LTP state scaling                   */
611
-        const SKP_int32     Gains_Q16[ NB_SUBFR ],  /* I                                        */
612
-        const SKP_int       pitchL[ NB_SUBFR ]      /* I    Pitch lag                           */
613
-)
614
-{
615
-    SKP_int            i, k, scale_length, lag;
616
-    SKP_int32          inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;
617
-    NSQ_del_dec_struct *psDD;
618
-
619
-    inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gains_Q16[ subfr ], 1 ) );
620
-    inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
621
-    lag          = pitchL[ subfr ];
622
-    /* After rewhitening the LTP state is un-scaled. So scale with inv_gain_Q16 */
623
-    if( NSQ->rewhite_flag ) {
624
-        inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );
625
-        if( subfr == 0 ) {
626
-            /* Do LTP downscaling */
627
-            inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, LTP_scale_Q14 ), 2 );
628
-        }
629
-        for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
630
-            SKP_assert( i < MAX_FRAME_LENGTH );
631
-            sLTP_Q16[ i ] = SKP_SMULWB( inv_gain_Q32, sLTP[ i ] );
632
-        }
633
-    }
634
-
635
-    /* Adjust for changing gain */
636
-    if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {
637
-        gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );
638
-
639
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {
640
-            psDD = &psDelDec[ k ];
641
-
642
-            /* Scale scalar states */
643
-            psDD->LF_AR_Q12 = SKP_SMULWW( gain_adj_Q16, psDD->LF_AR_Q12 );
644
-
645
-            /* scale short term state */
646
-            for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
647
-                psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] );
648
-            }
649
-            for( i = 0; i < DECISION_DELAY; i++ ) {
650
-                psDD->Pred_Q16[  i ] = SKP_SMULWW( gain_adj_Q16, psDD->Pred_Q16[  i ] );
651
-                psDD->Shape_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Shape_Q10[ i ] );
652
-            }
653
-        }
654
-
655
-        ostream& operator<<(ostream& psDD);
656
-
657
-        /* Scale long term shaping state */
658
-
659
-        /* Calculate length to be scaled, Worst case: Next frame is voiced with max lag */
660
-        scale_length = length * NB_SUBFR;                                               /* aprox max lag */
661
-        scale_length = scale_length - SKP_SMULBB( NB_SUBFR - ( subfr + 1 ), length );   /* subtract samples that will be too old in next frame */
662
-        scale_length = SKP_max_int( scale_length, lag + LTP_ORDER );                    /* make sure to scale whole pitch period if voiced */
663
-
664
-        for( i = NSQ->sLTP_shp_buf_idx - scale_length; i < NSQ->sLTP_shp_buf_idx; i++ ) {
665
-            NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );
666
-        }
667
-
668
-        /* Scale LTP predict state */
669
-        if( NSQ->rewhite_flag == 0 ) {
670
-            for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
671
-                sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );
672
-            }
673
-        }
674
-    }
675
-
676
-    /* Scale input */
677
-    for( i = 0; i < length; i++ ) {
678
-        x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );
679
-    }
680
-
681
-    /* save inv_gain */
682
-    SKP_assert( inv_gain_Q16 != 0 );
683
-    NSQ->prev_inv_gain_Q16 = inv_gain_Q16;
684
-}
685
-
686
-SKP_INLINE void SKP_Silk_copy_del_dec_state(
687
-        NSQ_del_dec_struct  *DD_dst, // 目标
688
-        NSQ_del_dec_struct  *DD_src, // 源
689
-        SKP_int             LPC_state_idx
690
-)
691
-{
692
-    SKP_memcpy( DD_dst->RandState, DD_src->RandState,   DECISION_DELAY * sizeof( SKP_int   ) );
693
-    SKP_memcpy( DD_dst->Q_Q10,     DD_src->Q_Q10,       DECISION_DELAY * sizeof( SKP_int32 ) );
694
-    SKP_memcpy( DD_dst->Pred_Q16,  DD_src->Pred_Q16,    DECISION_DELAY * sizeof( SKP_int32 ) );
695
-    SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10,   DECISION_DELAY * sizeof( SKP_int32 ) );
696
-    SKP_memcpy( DD_dst->Xq_Q10,    DD_src->Xq_Q10,      DECISION_DELAY * sizeof( SKP_int32 ) );
697
-
698
-    SKP_memcpy( &DD_dst->sLPC_Q14[ LPC_state_idx ], &DD_src->sLPC_Q14[ LPC_state_idx ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
699
-    DD_dst->LF_AR_Q12 = DD_src->LF_AR_Q12;
700
-    DD_dst->Seed      = DD_src->Seed;
701
-    DD_dst->SeedInit  = DD_src->SeedInit;
702
-    DD_dst->RD_Q10    = DD_src->RD_Q10;
703
-
704
-    // TODO
705
-    // 释放源资源
706
-}

BIN
android/app/src/main/cpp/SKP_Silk_NSQ_del_dec.o


+ 0 - 13
android/app/src/main/cpp/common/coomon_utils.h

@@ -1,13 +0,0 @@
1
-#ifndef ANDROIDRECORDER_COOMON_UTILS_H
2
-#define ANDROIDRECORDER_COOMON_UTILS_H
3
-
4
-#include <sys/time.h>
5
-
6
-static inline long getCurrentTime()
7
-{
8
-    struct timeval tv;
9
-    gettimeofday(&tv, NULL);
10
-    return tv.tv_sec * 1000 + tv.tv_usec/1000;
11
-}
12
-
13
-#endif //ANDROIDRECORDER_COOMON_UTILS_H

+ 0 - 18
android/app/src/main/cpp/common/message_handler.cpp

@@ -1,18 +0,0 @@
1
-#include "message_handler.h"
2
-
3
-Handler::Handler(MessageQueue *queue) {
4
-    this->mQueue = queue;
5
-}
6
-
7
-Handler::~Handler() {
8
-
9
-}
10
-
11
-int Handler::postMessage(Message *msg) {
12
-    msg->handler = this;
13
-    return mQueue->enqueueMessage(msg);
14
-}
15
-
16
-int Handler::getQueueSize() {
17
-    return mQueue->size();
18
-}

+ 0 - 23
android/app/src/main/cpp/common/message_handler.h

@@ -1,23 +0,0 @@
1
-
2
-#ifndef ANDROIDRECORDER_HANDLER_H
3
-#define ANDROIDRECORDER_HANDLER_H
4
-
5
-#include "message_queue.h"
6
-class Message;
7
-class MessageQueue;
8
-
9
-class Handler{
10
-private:
11
-    MessageQueue* mQueue;
12
-
13
-public:
14
-    Handler(MessageQueue* mQueue);
15
-    ~Handler();
16
-
17
-    int postMessage(Message* msg);
18
-    int getQueueSize();
19
-    virtual void handleMessage(Message* msg){};
20
-
21
-};
22
-
23
-#endif //ANDROIDRECORDER_HANDLER_H

+ 0 - 154
android/app/src/main/cpp/common/message_queue.cpp

@@ -1,154 +0,0 @@
1
-
2
-#include "message_queue.h"
3
-#include "message_handler.h"
4
-
5
-MessageQueue::MessageQueue() {
6
-    init();
7
-}
8
-
9
-MessageQueue::MessageQueue(const char* queueNameParam){
10
-    init();
11
-    queueName = queueNameParam;
12
-}
13
-
14
-void MessageQueue::init(){
15
-    pthread_mutex_init(&mLock, NULL);
16
-    pthread_cond_init(&mCondition, NULL);
17
-    mNbPackets = 0;
18
-    mFirst = NULL;
19
-    mLast = NULL;
20
-    mAbortRequest = false;
21
-}
22
-
23
-MessageQueue::~MessageQueue() {
24
-    flush();
25
-    pthread_mutex_destroy(&mLock);
26
-    pthread_cond_destroy(&mCondition);
27
-}
28
-
29
-int MessageQueue::size() {
30
-    pthread_mutex_destroy(&mLock);
31
-    int size = mNbPackets;
32
-    pthread_mutex_unlock(&mLock);
33
-    return size;
34
-}
35
-
36
-void MessageQueue::flush() {
37
-    MessageNode *curNode, *nextNode;
38
-    Message *msg;
39
-    pthread_mutex_lock(&mLock);
40
-    for(curNode = mFirst; curNode != NULL; curNode = nextNode){
41
-        nextNode = curNode->next;
42
-        msg = curNode->msg;
43
-        if(NULL != msg){
44
-            delete msg;
45
-        }
46
-        delete curNode;
47
-        curNode = NULL;
48
-    }
49
-    mLast = NULL;
50
-    mFirst = NULL;
51
-    pthread_mutex_unlock(&mLock);
52
-}
53
-
54
-int MessageQueue::enqueueMessage(Message *msg) {
55
-    if(mAbortRequest){
56
-        delete msg;
57
-        return -1;
58
-    }
59
-
60
-    MessageNode *node = new MessageNode();
61
-    node->msg = msg;
62
-    node->next = NULL;
63
-
64
-    if(mLast == NULL){
65
-        mFirst = node;
66
-    }else{
67
-        mLast->next = node;
68
-    }
69
-    mLast = node;
70
-    mNbPackets++;
71
-    pthread_cond_signal(&mCondition);
72
-    pthread_mutex_unlock(&mLock);
73
-    return 0;
74
-}
75
-
76
-int MessageQueue::dequeueMessage(Message **msg, bool block) {
77
-    MessageNode *node;
78
-    int ret;
79
-    pthread_mutex_lock(&mLock);
80
-    for (;;) {
81
-        if (mAbortRequest) {
82
-            ret = -1;
83
-            break;
84
-        }
85
-        node = mFirst;
86
-        if (node) {
87
-            mFirst = node->next;
88
-            if (!mFirst)
89
-                mLast = NULL;
90
-            mNbPackets--;
91
-            *msg = node->msg;
92
-            delete node;
93
-            node = NULL;
94
-            ret = 1;
95
-            break;
96
-        } else if (!block) {
97
-            ret = 0;
98
-            break;
99
-        } else {
100
-            pthread_cond_wait(&mCondition, &mLock);
101
-        }
102
-    }
103
-    pthread_mutex_unlock(&mLock);
104
-    return ret;
105
-}
106
-
107
-void MessageQueue::abort() {
108
-    pthread_mutex_lock(&mLock);
109
-    mAbortRequest = true;
110
-    pthread_cond_signal(&mCondition);
111
-    pthread_mutex_unlock(&mLock);
112
-}
113
-
114
-
115
-/******************* Message class *******************/
116
-Message::Message() {
117
-    handler = NULL;
118
-}
119
-
120
-Message::Message(int what){
121
-    handler = NULL;
122
-    this->what = what;
123
-}
124
-Message::Message(int what, int arg1, int arg2) {
125
-    handler = NULL;
126
-    this->what = what;
127
-    this->arg1 = arg1;
128
-    this->arg2 = arg2;
129
-}
130
-Message::Message(int what, void* obj) {
131
-    handler = NULL;
132
-    this->what = what;
133
-    this->obj = obj;
134
-}
135
-Message::Message(int what, int arg1, int arg2, void* obj) {
136
-    handler = NULL;
137
-    this->what = what;
138
-    this->arg1 = arg1;
139
-    this->arg2 = arg2;
140
-    this->obj = obj;
141
-}
142
-Message::~Message() {
143
-}
144
-
145
-int Message::execute(){
146
-    if (MESSAGE_QUEUE_LOOP_QUIT_FLAG == what) {
147
-        return MESSAGE_QUEUE_LOOP_QUIT_FLAG;
148
-    } else if (handler) {
149
-        handler->handleMessage(this);
150
-        return 1;
151
-    }
152
-    return 0;
153
-};
154
-

+ 0 - 81
android/app/src/main/cpp/common/message_queue.h

@@ -1,81 +0,0 @@
1
-
2
-#ifndef ANDROIDRECORDER_MESSAGE_QUEUE_H
3
-#define ANDROIDRECORDER_MESSAGE_QUEUE_H
4
-
5
-#include <pthread.h>
6
-#include <sys/types.h>
7
-#include "message_handler.h"
8
-#include "../log_utils.h"
9
-
10
-#define MESSAGE_QUEUE_LOOP_QUIT_FLAG        19900909
11
-
12
-class Handler;
13
-
14
-class Message{
15
-private:
16
-    int what;
17
-    int arg1;
18
-    int arg2;
19
-    void *obj;
20
-
21
-public:
22
-    Message();
23
-    Message(int what);
24
-    Message(int what, int arg1, int arg2);
25
-    Message(int what, void *obj);
26
-    Message(int what, int arg1, int arg2, void *obj);
27
-    ~Message();
28
-
29
-    int execute();
30
-    int getWhat(){
31
-        return what;
32
-    }
33
-
34
-    int getArg1(){
35
-        return arg1;
36
-    }
37
-
38
-    int getArg2(){
39
-        return arg2;
40
-    }
41
-
42
-    void* getObj(){
43
-        return obj;
44
-    }
45
-
46
-    Handler *handler;
47
-};
48
-
49
-typedef struct MessageNode{
50
-    Message *msg;
51
-    struct MessageNode *next;
52
-    MessageNode(){
53
-        msg = NULL;
54
-        next = NULL;
55
-    }
56
-} MessageNode;
57
-
58
-class MessageQueue{
59
-private :
60
-    MessageNode* mFirst;
61
-    MessageNode* mLast;
62
-    int mNbPackets;
63
-    bool mAbortRequest;
64
-    pthread_mutex_t mLock;
65
-    pthread_cond_t mCondition;
66
-    const char * queueName;
67
-
68
-public:
69
-    MessageQueue();
70
-    MessageQueue(const char* queueNameParam);
71
-    ~MessageQueue();
72
-
73
-    void init();
74
-    void flush();
75
-    int enqueueMessage(Message* msg);
76
-    int dequeueMessage(Message **msg, bool block);
77
-    int size();
78
-    void abort();
79
-};
80
-
81
-#endif //ANDROIDRECORDER_MESSAGE_QUEUE_H

+ 0 - 340
android/app/src/main/cpp/controller.cpp

@@ -1,340 +0,0 @@
1
-#include "controller.h"
2
-#include "log_utils.h"
3
-
4
-Controller::Controller() {
5
-    facingId = CAMERA_FACING_FRONT;
6
-
7
-    startTime = -1;
8
-    eglCore= NULL;
9
-    _window = NULL;
10
-    isThreadCreateSucceed = false;
11
-    previewSurface = EGL_NO_SURFACE;
12
-    isEncoding = false;
13
-    queue = new MessageQueue("controller message queue");
14
-    handler = new PreviewHandler(this,queue);
15
-}
16
-
17
-Controller::~Controller() {
18
-
19
-}
20
-
21
-bool Controller::init() {
22
-    LOGI("Controller::init start!");
23
-
24
-    eglCore = new EGLCore();
25
-    eglCore->init();
26
-    createPreviewSurface();
27
-    buildRenderInstance();
28
-    configCamera();
29
-    render->init(degress, facingId == CAMERA_FACING_FRONT, textureWidth, textureHeight, cameraWidth, cameraHeight);
30
-    startCameraPreview();
31
-
32
-    isInSwitchingCamera = false;
33
-
34
-    LOGI("Controller::init finish!");
35
-    return true;
36
-}
37
-
38
-void Controller::destroyEGLContext()
39
-{
40
-    if(handler){
41
-        handler->postMessage(new Message(MSG_EGL_THREAD_EXIT));
42
-        handler->postMessage(new Message(MESSAGE_QUEUE_LOOP_QUIT_FLAG));
43
-    }
44
-
45
-    if(isThreadCreateSucceed){
46
-        pthread_join(_threadId, 0);
47
-    }
48
-
49
-    if(queue){
50
-        queue->abort();
51
-        delete queue;
52
-        queue = NULL;
53
-    }
54
-    if(handler){
55
-        delete handler;
56
-        handler = NULL;
57
-    }
58
-}
59
-
60
-void Controller::destroy(){
61
-    destroyPreviewSurface();
62
-    if(render){
63
-        render->dealloc();
64
-        delete render;
65
-        render = NULL;
66
-    }
67
-    releaseCamera();
68
-    eglCore->release();
69
-    delete eglCore;
70
-    eglCore = NULL;
71
-}
72
-
73
-void Controller::createPreviewSurface() {
74
-    previewSurface = eglCore->createWindowSurface(_window);
75
-    if(previewSurface != NULL){
76
-        eglCore->makeCurrent(previewSurface);
77
-    }
78
-}
79
-
80
-void Controller::destroyPreviewSurface(){
81
-
82
-}
83
-
84
-void Controller::switchCamera(){
85
-    isInSwitchingCamera = true;
86
-    if(facingId == CAMERA_FACING_BACK){
87
-        facingId = CAMERA_FACING_FRONT;
88
-    } else {
89
-        facingId = CAMERA_FACING_BACK;
90
-    }
91
-
92
-    if(handler){
93
-        handler->postMessage(new Message(MSG_SWITCH_CAMERA));
94
-    }
95
-}
96
-
97
-void Controller::switchCameraFromMessage()
98
-{
99
-    releaseCamera();
100
-    configCamera();
101
-    render->setDegress(degress, facingId == CAMERA_FACING_FRONT);
102
-    startCameraPreview();
103
-    isInSwitchingCamera = false;
104
-}
105
-
106
-void Controller::releaseCamera(){
107
-    JNIEnv *env;
108
-
109
-    if(jvm->AttachCurrentThread(&env, NULL) != JNI_OK){
110
-        return;
111
-    }
112
-
113
-    if(env == NULL){
114
-        return;
115
-    }
116
-
117
-    jclass jcls = env->GetObjectClass(obj);
118
-    if(NULL != jcls){
119
-        jmethodID  releaseCameraCallback = env->GetMethodID(jcls, "releaseCameraFromNative","()V");
120
-        if(NULL != releaseCameraCallback){
121
-            env->CallVoidMethod(obj, releaseCameraCallback);
122
-        }
123
-    }
124
-
125
-    jvm->DetachCurrentThread();
126
-}
127
-
128
-void Controller::startRecording(){
129
-
130
-}
131
-
132
-void Controller::stopRecording(){
133
-
134
-}
135
-
136
-void Controller::prepareEGLContext(ANativeWindow *window, JavaVM *jvm, jobject obj, int screenWidth,
137
-                                   int screenHeight, int cameraFacingId) {
138
-
139
-    LOGI("Controller::prepare start!");
140
-    this->jvm = jvm;
141
-    this->obj = obj;
142
-    this->_window = window;
143
-    this->screenWidth = screenWidth;
144
-    this->screenHeight = screenHeight;
145
-    this->facingId = cameraFacingId;
146
-
147
-    handler->postMessage(new Message(MSG_EGL_THREAD_CREATE));
148
-    int res_code = pthread_create(&_threadId, 0, threadStartCallBack, this);
149
-    if(res_code == 0){
150
-        isThreadCreateSucceed = true;
151
-    }
152
-
153
-    LOGI("Controller::prepare finish!");
154
-}
155
-
156
-void *Controller::threadStartCallBack(void *myself) {
157
-    LOGI("Controller::threadStartCallBack start");
158
-    Controller *controller = (Controller *) myself;
159
-    controller->processMessage();
160
-    pthread_exit(0);
161
-    LOGI("Controller::threadStartCallBack finish");
162
-}
163
-
164
-void Controller::processMessage() {
165
-    bool renderingEnabled = true;
166
-    while(renderingEnabled){
167
-        Message *msg = NULL;
168
-        if(queue->dequeueMessage(&msg, true) > 0){
169
-            if(MESSAGE_QUEUE_LOOP_QUIT_FLAG == msg->execute()){
170
-                renderingEnabled = false;
171
-            }
172
-            delete msg;
173
-        }
174
-    }
175
-}
176
-
177
-void Controller::configCamera() {
178
-    LOGI("Controller::configCamera enter");
179
-    JNIEnv *env;
180
-
181
-    if(env == NULL){
182
-        LOGE("getJNIEnv failed");
183
-        return;
184
-    }
185
-
186
-    if(jvm->AttachCurrentThread(&env, NULL) != JNI_OK){
187
-        LOGE("AttachCurrentThread failed");
188
-        return;
189
-    }
190
-
191
-    jclass jcls = env->GetObjectClass(obj);
192
-    if(NULL == jcls){
193
-        return;
194
-    }
195
-
196
-    //(I)Lcom/yeliang/recorder/CameraConfigInfo") ---> (I)是形参,后面的是返回值
197
-    jmethodID configCameraCallback = env->GetMethodID(jcls, "configCameraFromNative", "(I)Lcom/yeliang/recorder/CameraConfigInfo;");
198
-    if(configCameraCallback == NULL){
199
-        return;
200
-    }
201
-
202
-    //1 调用PreviewScheduler类中的configCameraFromNative方法 返回CameraConfigInfo对象
203
-    jobject  cameraConfigInfo = env->CallObjectMethod(obj, configCameraCallback, facingId);
204
-
205
-    //2 根据CameraConfigInfo对象,获取CameraConfigInfo类
206
-    jclass CameraConfigInfo_cls = env->GetObjectClass(cameraConfigInfo);
207
-
208
-    //3 通过CameraConfigInfo_cls 获取 CameraConfigInfo中的getDegress方法
209
-    jmethodID getDegress_method = env->GetMethodID(CameraConfigInfo_cls, "getDegress","()I");
210
-    degress = env->CallIntMethod(cameraConfigInfo, getDegress_method);
211
-
212
-    jmethodID getCamereFacingId_method = env->GetMethodID(CameraConfigInfo_cls, "getCameraFacingId","()I");
213
-    facingId = env->CallIntMethod(cameraConfigInfo, getCamereFacingId_method);
214
-    
215
-    jmethodID getTextureWidth_method = env->GetMethodID(CameraConfigInfo_cls, "getTextureWidth","()I");
216
-    int previewWidth = env->CallIntMethod(cameraConfigInfo, getTextureWidth_method);
217
-    cameraWidth = previewWidth;
218
-
219
-    jmethodID getTextureHeight_method = env->GetMethodID(CameraConfigInfo_cls, "getTextureHeight","()I");
220
-    int previewHeight = env->CallIntMethod(cameraConfigInfo, getTextureHeight_method);
221
-    cameraHeight = previewHeight;
222
-
223
-    cameraWidth = 1280;
224
-    cameraHeight = 720;
225
-
226
-    textureWidth = 720;
227
-    textureHeight = 1280;
228
-
229
-    LOGI("camera:{previewWidth = %d, previewHeight = %d}", cameraWidth, cameraHeight);
230
-    LOGI("Texture: {textureWidth = %d, textureHeight = %d}",textureWidth, textureHeight);
231
-
232
-    jvm->DetachCurrentThread();
233
-    LOGI("Controller::configCamera leave");
234
-}
235
-
236
-void Controller::startCameraPreview() {
237
-    JNIEnv *env;
238
-    if(jvm->AttachCurrentThread(&env, NULL) != JNI_OK){
239
-        return;
240
-    }
241
-
242
-    if(env == NULL){
243
-        return;
244
-    }
245
-
246
-    jclass jcls = env->GetObjectClass(obj);
247
-
248
-    if(NULL != jcls){
249
-        jmethodID  startPreviewMethod = env->GetMethodID(jcls, "startPreviewFromNative", "(I)V");
250
-        if(NULL != startPreviewMethod){
251
-            env->CallVoidMethod(obj, startPreviewMethod, render->getCameraTexId());
252
-        }
253
-    }
254
-
255
-    if(jvm->DetachCurrentThread() != JNI_OK){
256
-        LOGE("DetachCurrentThread Error!");
257
-        return;
258
-    }
259
-}
260
-
261
-void Controller::createWindowSurface(ANativeWindow *window) {
262
-    if(_window == NULL){
263
-        _window = window;
264
-        if(handler){
265
-            handler->postMessage(new Message(MSG_EGL_CREATE_PREVIEW_SURFACE));
266
-        }
267
-    }
268
-}
269
-
270
-void Controller::notifyFrameAvaliable()
271
-{
272
-        if(handler && !isInSwitchingCamera){
273
-            handler->postMessage(new Message(MSG_RENDER_FRAME));
274
-        }
275
-}
276
-
277
-void Controller::renderFrame()
278
-{
279
-        if(NULL != eglCore && !isInSwitchingCamera){
280
-                if(startTime == -1){
281
-                    startTime = getCurrentTime();
282
-                }
283
-
284
-            float position = ((float)(getCurrentTime() - startTime)) / 1000.0f;
285
-            processVideoFrame(position);
286
-            if(previewSurface != EGL_NO_SURFACE){
287
-                draw();
288
-            }
289
-
290
-            if(isEncoding){
291
-            }
292
-        }
293
-}
294
-
295
-void Controller::processVideoFrame(float position)
296
-{
297
-    updateTexImage();
298
-    render->processFrame(position);
299
-}
300
-
301
-void Controller::updateTexImage()
302
-{
303
-    JNIEnv *env;
304
-    if(jvm->AttachCurrentThread(&env, NULL) != JNI_OK){
305
-        return;
306
-    }
307
-
308
-    if(env == NULL){
309
-        return;
310
-    }
311
-
312
-    jclass jcls = env->GetObjectClass(obj);
313
-
314
-    printf("Controller::updateTexImage &jcls = %p", &jcls);
315
-    if(NULL != jcls){
316
-        jmethodID updateTexImageCallback = env->GetMethodID(jcls, "updateTexImageFromNative", "()V");
317
-        if(NULL != updateTexImageCallback){
318
-            env->CallVoidMethod(obj, updateTexImageCallback);
319
-        }
320
-    }
321
-
322
-    if(jvm->DetachCurrentThread() != JNI_OK){
323
-        LOGE("%s: DetachCurrentThread failed", __FUNCTION__);
324
-    }
325
-}
326
-
327
-void Controller::draw()
328
-{
329
-    eglCore->makeCurrent(previewSurface);
330
-    render->drawToViewWithAutofit(screenWidth, screenHeight, textureWidth, textureHeight);
331
-    if(!eglCore -> swapBuffers(previewSurface)){
332
-        LOGE("(eglCore -> swapBuffers(previewSurface) Error!");
333
-    }
334
-}
335
-
336
-void Controller::buildRenderInstance() {
337
-    render = new PreviewRender();
338
-}
339
-
340
-

+ 0 - 156
android/app/src/main/cpp/controller.h

@@ -1,156 +0,0 @@
1
-#ifndef ANDROIDRECORDER_CONTROLLER_H
2
-#define ANDROIDRECORDER_CONTROLLER_H
3
-
4
-#include <jni.h>
5
-#include <android/native_window_jni.h>
6
-#include <android/native_window_jni.h>
7
-#include <sys/types.h>
8
-#include "common/message_handler.h"
9
-#include "egl/egl_core.h"
10
-#include "opengl/opengl_render.h"
11
-#include "opengl/preview_render.h"
12
-#include "common/coomon_utils.h"
13
-
14
-#define CAMERA_FACING_BACK   0
15
-#define CAMERA_FACING_FRONT  1
16
-
17
-enum RenderThreadMessage {
18
-    MSG_RENDER_FRAME = 0,
19
-    MSG_EGL_THREAD_CREATE,
20
-    MSG_EGL_CREATE_PREVIEW_SURFACE,
21
-    MSG_SWITCH_CAMERA,
22
-    MSG_START_RECORDING,
23
-    MSG_STOP_RECORDING,
24
-    MSG_EGL_DESTROY_PREVIEW_SURFACE,
25
-    MSG_EGL_THREAD_EXIT
26
-};
27
-
28
-class Controller{
29
-public:
30
-
31
-    Controller();
32
-
33
-    virtual ~Controller();
34
-
35
-    void prepareEGLContext(ANativeWindow *window, JavaVM *jvm, jobject obj,
36
-                           int screenWidth, int screenHeight, int cameraFacingId);
37
-
38
-    void notifyFrameAvaliable();
39
-
40
-    void createWindowSurface(ANativeWindow *window);
41
-
42
-    virtual bool init();
43
-
44
-    virtual void destroy();
45
-
46
-    void createPreviewSurface();
47
-
48
-    void destroyEGLContext();
49
-
50
-    void destroyPreviewSurface();
51
-
52
-    void switchCamera();
53
-    void switchCameraFromMessage();
54
-
55
-    void startRecording();
56
-
57
-    void stopRecording();
58
-
59
-    void renderFrame();
60
-
61
-    void draw();
62
-
63
-
64
-protected:
65
-    ANativeWindow *_window;
66
-    JavaVM *jvm;
67
-    jobject  obj;
68
-    int screenWidth;
69
-    int screenHeight;
70
-
71
-    bool isInSwitchingCamera;
72
-
73
-    int64_t  startTime;
74
-
75
-    int facingId;
76
-    int degress;
77
-    int textureWidth;
78
-    int textureHeight;
79
-
80
-    int cameraWidth;
81
-    int cameraHeight;
82
-
83
-    Handler *handler;
84
-    MessageQueue *queue;
85
-    pthread_t _threadId;
86
-
87
-    static void *threadStartCallBack(void *myself);
88
-
89
-    void processMessage();
90
-
91
-    EGLCore *eglCore;
92
-    EGLSurface previewSurface;
93
-
94
-    PreviewRender *render;
95
-
96
-    virtual void buildRenderInstance();
97
-
98
-    virtual void processVideoFrame(float position);
99
-
100
-    void configCamera();
101
-
102
-    void startCameraPreview();
103
-
104
-    void updateTexImage();
105
-
106
-    void releaseCamera();
107
-
108
-    bool isThreadCreateSucceed;
109
-    bool isEncoding;
110
-};
111
-
112
-class PreviewHandler:public Handler{
113
-
114
-private:
115
-    Controller *controller;
116
-
117
-public:
118
-    PreviewHandler(Controller *controller,MessageQueue *queue):Handler(queue){
119
-        this->controller = controller;
120
-    };
121
-
122
-    void handleMessage(Message *msg){
123
-        int what = msg->getWhat();
124
-        switch (what) {
125
-            case MSG_EGL_THREAD_CREATE:
126
-                controller->init();
127
-                break;
128
-            case MSG_EGL_CREATE_PREVIEW_SURFACE:
129
-                controller->createPreviewSurface();
130
-                break;
131
-            case MSG_START_RECORDING:
132
-                controller->startRecording();
133
-                break;
134
-            case MSG_STOP_RECORDING:
135
-                controller->stopRecording();
136
-                break;
137
-            case MSG_EGL_DESTROY_PREVIEW_SURFACE:
138
-                controller->destroyPreviewSurface();
139
-                break;
140
-            case MSG_EGL_THREAD_EXIT:
141
-                controller->destroy();
142
-                break;
143
-            case MSG_RENDER_FRAME:
144
-                controller->renderFrame();
145
-                break;
146
-            case MSG_SWITCH_CAMERA:
147
-                controller->switchCameraFromMessage();
148
-                break;
149
-        }
150
-    }
151
-
152
-
153
-};
154
-
155
-
156
-#endif //ANDROIDRECORDER_CONTROLLER_H

+ 0 - 10
android/app/src/main/cpp/native-lib.cpp

@@ -1,10 +0,0 @@
1
-#include <jni.h>
2
-#include <string>
3
-
4
-extern "C" JNIEXPORT jstring JNICALL
5
-Java_com_cfmlg_mlg_MainActivity_stringFromJNI(
6
-        JNIEnv* env,
7
-        jobject /* this */) {
8
-    std::string hello = "口腔扫描仪";
9
-    return env->NewStringUTF(hello.c_str());
10
-}

+ 0 - 1
android/app/src/main/java/com/eitchsyh/instrument/Video.java

@@ -11,7 +11,6 @@ public class Video
11 11
 {
12 12
     static
13 13
     {
14
-        System.loadLibrary("mlg");
15 14
         System.loadLibrary("iMVR");
16 15
     }
17 16