1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 9 апр. 2017 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef DSP_COMMON_RESAMPLING_H_
23 #define DSP_COMMON_RESAMPLING_H_
24 
25 #ifndef __DSP_DSP_DEFS
26     #error "This header should not be included directly"
27 #endif /* __DSP_DSP_DEFS */
28 
29 #define RESAMPLING_RESERVED_SAMPLES         64
30 
31 /** Resampling/oversampling funtion type.
32  * Remember that destination buffer must be times greater and have additional gap (>=64 samples) at
33  * the tail to contain complete convolution after resampling
34  *
35  * @param dst destination buffer
36  * @param src source buffer
37  * @param count number of samples to process
38  */
39 typedef void (* resampling_function_t)(float *dst, const float *src, size_t count);
40 
41 //-----------------------------------------------------------------------
42 // DSP resampling functions
43 namespace dsp
44 {
45     /** Perform lanczos resampling, destination buffer must be cleared and contain only
46      * resampling tail from previous resampling
47      *
48      * @param dst destination buffer of count*2 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
49      * @param src source buffer of count samples
50      * @param count number of samples
51      */
52     extern void (* lanczos_resample_2x2)(float *dst, const float *src, size_t count);
53 
54     /** Perform lanczos resampling, destination buffer must be cleared and contain only
55      * resampling tail from previous resampling
56      *
57      * @param dst destination buffer of count*2 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
58      * @param src source buffer of count samples
59      * @param count number of samples
60      */
61     extern void (* lanczos_resample_2x3)(float *dst, const float *src, size_t count);
62 
63     /** Perform lanczos resampling, destination buffer must be cleared and contain only
64      * resampling tail from previous resampling
65      *
66      * @param dst destination buffer of count*2 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
67      * @param src source buffer of count samples
68      * @param count number of samples
69      */
70     extern void (* lanczos_resample_2x4)(float *dst, const float *src, size_t count);
71 
72     /** Perform lanczos resampling, destination buffer must be cleared and contain only
73      * resampling tail from previous resampling
74      *
75      * @param dst destination buffer of count*3 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
76      * @param src source buffer of count samples
77      * @param count number of samples
78      */
79     extern void (* lanczos_resample_3x2)(float *dst, const float *src, size_t count);
80 
81     /** Perform lanczos resampling, destination buffer must be cleared and contain only
82      * resampling tail from previous resampling
83      *
84      * @param dst destination buffer of count*3 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
85      * @param src source buffer of count samples
86      * @param count number of samples
87      */
88     extern void (* lanczos_resample_3x3)(float *dst, const float *src, size_t count);
89 
90     /** Perform lanczos resampling, destination buffer must be cleared and contain only
91      * resampling tail from previous resampling
92      *
93      * @param dst destination buffer of count*3 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
94      * @param src source buffer of count samples
95      * @param count number of samples
96      */
97     extern void (* lanczos_resample_3x4)(float *dst, const float *src, size_t count);
98 
99     /** Perform lanczos resampling, destination buffer must be cleared and contain only
100      * resampling tail from previous resampling
101      *
102      * @param dst destination buffer of count*4 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
103      * @param src source buffer of count samples
104      * @param count number of samples
105      */
106     extern void (* lanczos_resample_4x2)(float *dst, const float *src, size_t count);
107 
108     /** Perform lanczos resampling, destination buffer must be cleared and contain only
109      * resampling tail from previous resampling
110      *
111      * @param dst destination buffer of count*4 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
112      * @param src source buffer of count samples
113      * @param count number of samples
114      */
115     extern void (* lanczos_resample_4x3)(float *dst, const float *src, size_t count);
116 
117     /** Perform lanczos resampling, destination buffer must be cleared and contain only
118      * resampling tail from previous resampling
119      *
120      * @param dst destination buffer of count*4 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
121      * @param src source buffer of count samples
122      * @param count number of samples
123      */
124     extern void (* lanczos_resample_4x4)(float *dst, const float *src, size_t count);
125 
126     /** Perform lanczos resampling, destination buffer must be cleared and contain only
127      * resampling tail from previous resampling
128      *
129      * @param dst destination buffer of count*6 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
130      * @param src source buffer of count samples
131      * @param count number of samples
132      */
133     extern void (* lanczos_resample_6x2)(float *dst, const float *src, size_t count);
134 
135     /** Perform lanczos resampling, destination buffer must be cleared and contain only
136      * resampling tail from previous resampling
137      *
138      * @param dst destination buffer of count*6 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
139      * @param src source buffer of count samples
140      * @param count number of samples
141      */
142     extern void (* lanczos_resample_6x3)(float *dst, const float *src, size_t count);
143 
144     /** Perform lanczos resampling, destination buffer must be cleared and contain only
145      * resampling tail from previous resampling
146      *
147      * @param dst destination buffer of count*6 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
148      * @param src source buffer of count samples
149      * @param count number of samples
150      */
151     extern void (* lanczos_resample_6x4)(float *dst, const float *src, size_t count);
152 
153     /** Perform lanczos resampling, destination buffer must be cleared and contain only
154      * resampling tail from previous resampling
155      *
156      * @param dst destination buffer of count*8 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
157      * @param src source buffer of count samples
158      * @param count number of samples
159      */
160     extern void (* lanczos_resample_8x2)(float *dst, const float *src, size_t count);
161 
162     /** Perform lanczos resampling, destination buffer must be cleared and contain only
163      * resampling tail from previous resampling
164      *
165      * @param dst destination buffer of count*8 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
166      * @param src source buffer of count samples
167      * @param count number of samples
168      */
169     extern void (* lanczos_resample_8x3)(float *dst, const float *src, size_t count);
170 
171     /** Perform lanczos resampling, destination buffer must be cleared and contain only
172      * resampling tail from previous resampling
173      *
174      * @param dst destination buffer of count*8 samples + RESAMPLING_RESERVED_SAMPLES samples for convolution tail
175      * @param src source buffer of count samples
176      * @param count number of samples
177      */
178     extern void (* lanczos_resample_8x4)(float *dst, const float *src, size_t count);
179 
180     /** Copy each even sample to output buffer
181      *
182      * @param dst destination buffer
183      * @param src source buffer
184      * @param count number of samples to process
185      */
186     extern void (* downsample_2x)(float *dst, const float *src, size_t count);
187 
188     /** Copy each 3rd sample to output buffer
189      *
190      * @param dst destination buffer
191      * @param src source buffer
192      * @param count number of samples to process
193      */
194     extern void (* downsample_3x)(float *dst, const float *src, size_t count);
195 
196     /** Copy each 4th sample to output buffer
197      *
198      * @param dst destination buffer
199      * @param src source buffer
200      * @param count number of samples to process
201      */
202     extern void (* downsample_4x)(float *dst, const float *src, size_t count);
203 
204     /** Copy each 6th sample to output buffer
205      *
206      * @param dst destination buffer
207      * @param src source buffer
208      * @param count number of samples to process
209      */
210     extern void (* downsample_6x)(float *dst, const float *src, size_t count);
211 
212     /** Copy each 8th sample to output buffer
213      *
214      * @param dst destination buffer
215      * @param src source buffer
216      * @param count number of samples to process
217      */
218     extern void (* downsample_8x)(float *dst, const float *src, size_t count);
219 }
220 
221 #endif /* DSP_COMMON_RESAMPLING_H_ */
222