MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / adapt_audio

Function adapt_audio

src/framework/audio/mixing.cpp:65–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65std::vector<float> adapt_audio(
66 const WavData & input,
67 int target_rate,
68 int target_channels,
69 int64_t target_frames) {
70 if (input.sample_rate <= 0 || target_rate <= 0 || target_channels <= 0) {
71 throw std::runtime_error("audio mix received invalid sample rate or channel count");
72 }
73 std::vector<float> samples = resample_interleaved_to_rate(
74 input.samples,
75 input.sample_rate,
76 input.channels,
77 target_rate);
78 int channels = input.channels;
79 if (channels != target_channels) {
80 if (target_channels == 1) {
81 samples = mixdown_interleaved_to_mono_average(samples, channels);
82 } else if (channels == 1) {
83 samples = duplicate_mono_to_interleaved_channels(samples, target_channels);
84 } else {
85 auto mono = mixdown_interleaved_to_mono_average(samples, channels);
86 samples = duplicate_mono_to_interleaved_channels(mono, target_channels);
87 }
88 channels = target_channels;
89 }
90 const size_t target_samples = static_cast<size_t>(target_frames * target_channels);
91 if (samples.size() < target_samples) {
92 samples.resize(target_samples, 0.0F);
93 } else if (samples.size() > target_samples) {
94 samples.resize(target_samples);
95 }
96 return samples;
97}
98
99void apply_activity_gate_in_place(
100 std::vector<float> & samples,

Callers 1

Calls 5

sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected