1 #ifndef CPPAPE_RESAMPLING_H
2 #define CPPAPE_RESAMPLING_H
28 class MatrixImpl :
public Impl
33 : source(matrix), position{}
41 for (std::size_t f = 0; f < frames; ++f)
43 const auto x0 = static_cast<std::size_t>(position);
46 if (x1 >= source.samples())
47 x1 -= source.samples();
50 const auto weight = position - x0;
52 for (std::size_t c = 0; c < source.channels(); ++c)
54 const auto y0 = source[c][x0];
55 const auto y1 = source[c][x1];
57 output.
channels[c][f] = y0 * (1 - weight) + weight * y1;
63 while (position >= source.samples())
64 position -= source.samples();
78 : channels(data.channels())
80 impl = std::make_unique<MatrixImpl>(data);
94 buffer.resize(channels, frames);
95 impl->produce(buffer, frames, factor);
103 template<
typename Func>
104 auto produce(std::size_t frames, Func && f,
double factor = 1)
106 const auto matrix =
produce(frames, factor);
108 for (std::size_t frame = 0; frame < frames; ++frame)
110 for (std::size_t c = 0; c < channelBuffer.size(); ++c)
111 channelBuffer[c] = matrix[c][frame];
113 f(frame, channelBuffer);
118 std::size_t channels;
119 std::vector<T> channelBuffer;
121 std::unique_ptr<Impl> impl;