eDSP  0.0.1
A cross-platform DSP library written in C++.
resampler.hpp
Go to the documentation of this file.
1 /*
2 * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3 * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, either version 3 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along width
16 * this program. If not, see <http://www.gnu.org/licenses/>
17 *
18 * Filename: resampler_impl.hpp
19 * Author: Mohammed Boujemaoui
20 * Date: 11/10/18
21 */
22 
23 #ifndef EDSP_RESAMPLER_HPP
24 #define EDSP_RESAMPLER_HPP
25 
26 #include <edsp/io/internal/resampler/resampler_impl.hpp>
27 
28 namespace edsp { namespace io {
29 
39  linear = 4,
40  };
41 
48  template <typename T>
49  struct resampler {
50  using value_type = T;
51  using size_type = long;
52  using error_type = int;
53 
60  resampler(size_type channels, resample_quality quality, value_type factor) : impl(channels, quality, factor) {}
61 
65  ~resampler() = default;
66 
87  template <typename InputIt, typename OutputIt>
88  inline size_type process(InputIt first, InputIt last, OutputIt d_first) {
89  return impl.process(first, last, d_first);
90  }
91 
97  return static_cast<resample_quality>(impl.quality());
98  }
99 
105  return impl.reset();
106  }
107 
112  error_type error() const {
113  return impl.error();
114  }
115 
120  const edsp::string_view error_string() const {
121  return impl.error_string();
122  }
123 
129  static bool valid_ratio(value_type ratio) {
130  return internal::resampler_impl<T>::valid_ratio(ratio);
131  }
132 
133  private:
134  internal::resampler_impl<T> impl;
135  };
136 
137 }} // namespace edsp::io
138 
139 #endif //EDSP_RESAMPLER_HPP
This class implements a resampler object to perform sample-rate conversion.
Definition: resampler.hpp:49
resample_quality
The resample_quality enum represents the different configurations that modifies the ressampling proce...
Definition: resampler.hpp:34
Definition: resampler.hpp:37
error_type error() const
Returns the internal error code.
Definition: resampler.hpp:112
size_type process(InputIt first, InputIt last, OutputIt d_first)
Resamples the input elements in the range [first, last) and stores the result in another range...
Definition: resampler.hpp:88
Definition: resampler.hpp:39
Definition: resampler.hpp:38
resample_quality quality() const
Returns the quality used in the resampling process.
Definition: resampler.hpp:96
static bool valid_ratio(value_type ratio)
Checks if a ratio is valid.
Definition: resampler.hpp:129
long size_type
Definition: resampler.hpp:51
const edsp::string_view error_string() const
Returns a description of the internal error code.
Definition: resampler.hpp:120
resampler(size_type channels, resample_quality quality, value_type factor)
Creates a resampler with the given configuration.
Definition: resampler.hpp:60
Definition: resampler.hpp:36
Definition: resampler.hpp:35
error_type reset()
Resets the internal buffers.
Definition: resampler.hpp:104
T value_type
Definition: resampler.hpp:50
Definition: amplifier.hpp:29
int error_type
Definition: resampler.hpp:52
~resampler()=default
Default destructor.