fork/rust-sdks

git clone https://git.julia.blue/fork/rust-sdks

Théo Monnomuse audio resampler on the write_to_disk example (#68)2cad45c

livekit/livekit-ffi@0.13.0
1.6 KiB47 linesraw
1/*
2 * Copyright 2023 LiveKit
3 *
4 * Licensed under the Apache License, Version 2.0 (the “License”);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an “AS IS” BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "livekit/audio_resampler.h"
18
19#include <memory>
20
21#include "audio/remix_resample.h"
22
23namespace livekit {
24
25size_t AudioResampler::remix_and_resample(const int16_t* src,
26                                          size_t samples_per_channel,
27                                          size_t num_channels,
28                                          int sample_rate,
29                                          size_t dest_num_channels,
30                                          int dest_sample_rate) {
31  frame_.num_channels_ = dest_num_channels;
32  frame_.sample_rate_hz_ = dest_sample_rate;
33  webrtc::voe::RemixAndResample(src, samples_per_channel, num_channels,
34                                sample_rate, &resampler_, &frame_);
35
36  return frame_.num_channels() * frame_.samples_per_channel() * sizeof(int16_t);
37}
38
39const int16_t* AudioResampler::data() const {
40  return frame_.data();
41}
42
43std::unique_ptr<AudioResampler> create_audio_resampler() {
44  return std::make_unique<AudioResampler>();
45}
46
47}  // namespace livekit