LMMS
Loading...
Searching...
No Matches
AudioResampler.h
Go to the documentation of this file.
1/*
2 * AudioResampler.h
3 *
4 * Copyright (c) 2025 saker <sakertooth@gmail.com>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program 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 GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_AUDIO_RESAMPLER_H
26#define LMMS_AUDIO_RESAMPLER_H
27
28#include <memory>
29#include "AudioBufferView.h"
30#include "lmms_export.h"
31
32namespace lmms {
33
40class LMMS_EXPORT AudioResampler
41{
42public:
47 enum class Mode
48 {
49 ZOH,
50 Linear,
51 SincFastest,
52 SincMedium,
53 SincBest
54 };
55
65
72
88
93 void reset();
94
99 void setRatio(double ratio) { m_ratio = ratio; }
100
106 void setRatio(sample_rate_t input, sample_rate_t output) { m_ratio = static_cast<double>(output) / input; }
107
109 auto ratio() const -> double { return m_ratio; }
110
112 auto channels() const -> ch_cnt_t { return m_channels; }
113
115 auto mode() const -> Mode { return m_mode; }
116
117private:
118 struct LMMS_EXPORT StateDeleter { void operator()(void* state); };
119 std::unique_ptr<void, StateDeleter> m_state;
122 double m_ratio = 1.0;
123 int m_error = 0;
124};
125
126} // namespace lmms
127
128#endif // LMMS_AUDIO_RESAMPLER_H
void process(Alg_seq_ptr seq, bool tempo_flag, double tempo, bool flatten_flag)
Definition allegroconvert.cpp:42
Mode m_mode
Definition AudioResampler.h:120
void setRatio(double ratio)
Sets the resampling ratio to ratio.
Definition AudioResampler.h:99
Mode
Defines the resampling method to use.
Definition AudioResampler.h:48
double m_ratio
Definition AudioResampler.h:122
AudioResampler(Mode mode, ch_cnt_t channels=2)
Constructs an AudioResampler instance.
Definition AudioResampler.cpp:54
auto mode() const -> Mode
Definition AudioResampler.h:115
auto channels() const -> ch_cnt_t
Definition AudioResampler.h:112
void setRatio(sample_rate_t input, sample_rate_t output)
Sets the resampling ratio to output / input.
Definition AudioResampler.h:106
std::unique_ptr< void, StateDeleter > m_state
Definition AudioResampler.h:119
ch_cnt_t m_channels
Definition AudioResampler.h:121
void reset()
Resets the internal resampler state. Useful when working with unreleated pieces of audio.
Definition AudioResampler.cpp:89
auto ratio() const -> double
Definition AudioResampler.h:109
int m_error
Definition AudioResampler.h:123
Definition AudioBufferView.h:291
Definition AudioAlsa.cpp:35
std::uint16_t ch_cnt_t
Definition LmmsTypes.h:44
std::uint32_t sample_rate_t
Definition LmmsTypes.h:42
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
Result of a resampling operation.
Definition AudioResampler.h:61
f_cnt_t inputFramesUsed
The number of input frames used during processing.
Definition AudioResampler.h:62
f_cnt_t outputFramesGenerated
The number of output frames generated during processing.
Definition AudioResampler.h:63
Definition AudioResampler.h:118
void operator()(void *state)
Definition AudioResampler.cpp:97
#define const
Definition zconf.h:137