summaryrefslogtreecommitdiff
path: root/src/audio/include/resample.hpp
blob: a9464cb19e3f65be1b093f4016be80754e0f8190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once

#include <cstdint>
#include <vector>

#include "span.hpp"
#include "speex/speex_resampler.h"

#include "sample.hpp"

namespace audio {

class Resampler {
 public:
  Resampler(uint32_t source_sample_rate,
            uint32_t target_sample_rate,
            uint8_t num_channels);

  ~Resampler();

  auto Process(cpp::span<sample::Sample> input,
               cpp::span<sample::Sample> output,
               bool end_of_data) -> std::pair<size_t, size_t>;

 private:
  int err_;
  SpeexResamplerState* resampler_;
  uint8_t num_channels_;
};

}  // namespace audio