1 /* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2009 Xiph.Org Foundation
3 Written by Jean-Marc Valin */
4 /**
5 @file pitch.h
6 @brief Pitch analysis
7 */
8
9 /*
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
13
14 - Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16
17 - Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef PITCH_H
35 #define PITCH_H
36
37 //#include "modes.h"
38 //#include "cpu_support.h"
39 #include "arch.h"
40
41 void pitch_downsample(celt_sig *x[], opus_val16 *x_lp,
42 int len, int C);
43
44 void pitch_search(const opus_val16 *x_lp, opus_val16 *y,
45 int len, int max_pitch, int *pitch);
46
47 opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
48 int N, int *T0, int prev_period, opus_val16 prev_gain);
49
50
51 /* OPT: This is the kernel you really want to optimize. It gets used a lot
52 by the prefilter and by the PLC. */
xcorr_kernel(const opus_val16 * x,const opus_val16 * y,opus_val32 sum[4],int len)53 static OPUS_INLINE void xcorr_kernel(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len)
54 {
55 int j;
56 opus_val16 y_0, y_1, y_2, y_3;
57 celt_assert(len>=3);
58 y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
59 y_0=*y++;
60 y_1=*y++;
61 y_2=*y++;
62 for (j=0;j<len-3;j+=4)
63 {
64 opus_val16 tmp;
65 tmp = *x++;
66 y_3=*y++;
67 sum[0] = MAC16_16(sum[0],tmp,y_0);
68 sum[1] = MAC16_16(sum[1],tmp,y_1);
69 sum[2] = MAC16_16(sum[2],tmp,y_2);
70 sum[3] = MAC16_16(sum[3],tmp,y_3);
71 tmp=*x++;
72 y_0=*y++;
73 sum[0] = MAC16_16(sum[0],tmp,y_1);
74 sum[1] = MAC16_16(sum[1],tmp,y_2);
75 sum[2] = MAC16_16(sum[2],tmp,y_3);
76 sum[3] = MAC16_16(sum[3],tmp,y_0);
77 tmp=*x++;
78 y_1=*y++;
79 sum[0] = MAC16_16(sum[0],tmp,y_2);
80 sum[1] = MAC16_16(sum[1],tmp,y_3);
81 sum[2] = MAC16_16(sum[2],tmp,y_0);
82 sum[3] = MAC16_16(sum[3],tmp,y_1);
83 tmp=*x++;
84 y_2=*y++;
85 sum[0] = MAC16_16(sum[0],tmp,y_3);
86 sum[1] = MAC16_16(sum[1],tmp,y_0);
87 sum[2] = MAC16_16(sum[2],tmp,y_1);
88 sum[3] = MAC16_16(sum[3],tmp,y_2);
89 }
90 if (j++<len)
91 {
92 opus_val16 tmp = *x++;
93 y_3=*y++;
94 sum[0] = MAC16_16(sum[0],tmp,y_0);
95 sum[1] = MAC16_16(sum[1],tmp,y_1);
96 sum[2] = MAC16_16(sum[2],tmp,y_2);
97 sum[3] = MAC16_16(sum[3],tmp,y_3);
98 }
99 if (j++<len)
100 {
101 opus_val16 tmp=*x++;
102 y_0=*y++;
103 sum[0] = MAC16_16(sum[0],tmp,y_1);
104 sum[1] = MAC16_16(sum[1],tmp,y_2);
105 sum[2] = MAC16_16(sum[2],tmp,y_3);
106 sum[3] = MAC16_16(sum[3],tmp,y_0);
107 }
108 if (j<len)
109 {
110 opus_val16 tmp=*x++;
111 y_1=*y++;
112 sum[0] = MAC16_16(sum[0],tmp,y_2);
113 sum[1] = MAC16_16(sum[1],tmp,y_3);
114 sum[2] = MAC16_16(sum[2],tmp,y_0);
115 sum[3] = MAC16_16(sum[3],tmp,y_1);
116 }
117 }
118
dual_inner_prod(const opus_val16 * x,const opus_val16 * y01,const opus_val16 * y02,int N,opus_val32 * xy1,opus_val32 * xy2)119 static OPUS_INLINE void dual_inner_prod(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
120 int N, opus_val32 *xy1, opus_val32 *xy2)
121 {
122 int i;
123 opus_val32 xy01=0;
124 opus_val32 xy02=0;
125 for (i=0;i<N;i++)
126 {
127 xy01 = MAC16_16(xy01, x[i], y01[i]);
128 xy02 = MAC16_16(xy02, x[i], y02[i]);
129 }
130 *xy1 = xy01;
131 *xy2 = xy02;
132 }
133
134 /*We make sure a C version is always available for cases where the overhead of
135 vectorization and passing around an arch flag aren't worth it.*/
celt_inner_prod(const opus_val16 * x,const opus_val16 * y,int N)136 static OPUS_INLINE opus_val32 celt_inner_prod(const opus_val16 *x,
137 const opus_val16 *y, int N)
138 {
139 int i;
140 opus_val32 xy=0;
141 for (i=0;i<N;i++)
142 xy = MAC16_16(xy, x[i], y[i]);
143 return xy;
144 }
145
146 void celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y,
147 opus_val32 *xcorr, int len, int max_pitch);
148
149 #endif
150