forked from nostar/imbe_vocoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode.cc
99 lines (85 loc) · 2.55 KB
/
encode.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Project 25 IMBE Encoder/Decoder Fixed-Point implementation
* Developed by Pavel Yazev E-mail: [email protected]
* Version 1.0 (c) Copyright 2009
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* The software is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Boston, MA
* 02110-1301, USA.
*/
#include "typedef.h"
#include "globals.h"
#include "imbe.h"
#include "basic_op.h"
#include "dsp_sub.h"
#include "aux_sub.h"
#include "tbls.h"
#include "encode.h"
#include "dc_rmv.h"
#include "pe_lpf.h"
#include "pitch_est.h"
#include "pitch_ref.h"
#include "v_uv_det.h"
#include "sa_encode.h"
#include "ch_encode.h"
#include "imbe_vocoder_impl.h"
void imbe_vocoder_impl::encode_init(void)
{
v_zap(pitch_est_buf, PITCH_EST_BUF_SIZE);
v_zap(pitch_ref_buf, PITCH_EST_BUF_SIZE);
v_zap(pe_lpf_mem, PE_LPF_ORD);
pitch_est_init();
fft_init();
dc_rmv_mem = 0;
sa_encode_init();
pitch_ref_init();
}
void imbe_vocoder_impl::encode(IMBE_PARAM *imbe_param, Word16 *frame_vector, Word16 *snd)
{
Word16 i;
Word16 *wr_ptr, *sig_ptr;
for(i = 0; i < PITCH_EST_BUF_SIZE - FRAME; i++)
{
pitch_est_buf[i] = pitch_est_buf[i + FRAME];
pitch_ref_buf[i] = pitch_ref_buf[i + FRAME];
}
dc_rmv(snd, &pitch_ref_buf[PITCH_EST_BUF_SIZE - FRAME], &dc_rmv_mem, FRAME);
pe_lpf(&pitch_ref_buf[PITCH_EST_BUF_SIZE - FRAME], &pitch_est_buf[PITCH_EST_BUF_SIZE - FRAME], pe_lpf_mem, FRAME);
pitch_est(imbe_param, pitch_est_buf);
//
// Speech windowing and FFT calculation
//
wr_ptr = (Word16 *)wr;
sig_ptr = &pitch_ref_buf[40];
for(i = 146; i < 256; i++)
{
fft_buf[i].re = mult(*sig_ptr++, *wr_ptr++);
fft_buf[i].im = 0;
}
fft_buf[0].re = *sig_ptr++;
fft_buf[0].im = 0;
wr_ptr--;
for(i = 1; i < 111; i++)
{
fft_buf[i].re = mult(*sig_ptr++, *wr_ptr--);
fft_buf[i].im = 0;
}
for(i = 111; i < 146; i++)
fft_buf[i].re = fft_buf[i].im = 0;
fft((Word16 *)&fft_buf, FFTLENGTH, 1);
pitch_ref(imbe_param, fft_buf);
v_uv_det(imbe_param, fft_buf);
sa_encode(imbe_param);
encode_frame_vector(imbe_param, frame_vector);
}