Debian Codegraph @

src/libs/mt32/srchelper/srctools/include/ResamplerModel.h

raw
1 /* Copyright (C) 2015-2022 Sergey V. Mikayev
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation, either version 2.1 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #ifndef SRCTOOLS_RESAMPLER_MODEL_H
18 #define SRCTOOLS_RESAMPLER_MODEL_H
19
20 #include "FloatSampleProvider.h"
21
22 namespace SRCTools {
23
24 class ResamplerStage;
25
26 /** Model consists of one or more ResampleStage instances connected in a cascade. */
27 namespace ResamplerModel {
28
29 // Seems to be a good choice for 16-bit integer samples.
30 static const double DEFAULT_DB_SNR = 106;
31
32 // When using linear interpolation, oversampling factor necessary to achieve the DEFAULT_DB_SNR is about 256.
33 // This figure is the upper estimation, and it can be found by analysing the frequency response of the linear interpolator.
34 // When less SNR is desired, this value should also decrease in accordance.
35 static const unsigned int DEFAULT_WINDOWED_SINC_MAX_DOWNSAMPLE_FACTOR = 256;
36
37 // In the default resampler model, the input to the windowed sinc filter is always at least 2x oversampled during upsampling,
38 // so oversampling factor of 128 should be sufficient to achieve the DEFAULT_DB_SNR with linear interpolation.
39 static const unsigned int DEFAULT_WINDOWED_SINC_MAX_UPSAMPLE_FACTOR = DEFAULT_WINDOWED_SINC_MAX_DOWNSAMPLE_FACTOR / 2;
40
41
42 enum Quality {
43 // Use when the speed is more important than the audio quality.
44 FASTEST,
45 // Use FAST quality setting of the IIR stage (50% of passband retained).
46 FAST,
47 // Use GOOD quality setting of the IIR stage (77% of passband retained).
48 GOOD,
49 // Use BEST quality setting of the IIR stage (95% of passband retained).
50 BEST
51 };
52
53 FloatSampleProvider &createResamplerModel(FloatSampleProvider &source, double sourceSampleRate, double targetSampleRate, Quality quality);
54 FloatSampleProvider &createResamplerModel(FloatSampleProvider &source, ResamplerStage **stages, unsigned int stageCount);
55 FloatSampleProvider &createResamplerModel(FloatSampleProvider &source, ResamplerStage &stage);
56
57 void freeResamplerModel(FloatSampleProvider &model, FloatSampleProvider &source);
58
59 } // namespace ResamplerModel
60
61 } // namespace SRCTools
62
63 #endif // SRCTOOLS_RESAMPLER_MODEL_H