34 assert(std::size(out) == std::size(in) * 2);
36 auto out_it = std::begin(out);
37 for (
const std::byte &value : in) {
38 if constexpr (std::endian::native != std::endian::little) {
40 *out_it++ = std::byte{0};
42 *out_it++ = std::byte{0};
51 std::vector<std::byte> &data = *sound.data;
53 std::vector<std::byte> tmp;
54 if (sound.bits_per_sample == 16) {
59 tmp.resize(std::size(data) *
sizeof(int16_t));
61 sound.bits_per_sample = 16;
65 uint align = sound.channels * sound.bits_per_sample / 8;
66 data.resize(
Align(std::size(tmp) * play_rate / sound.rate, align));
68 soxr_error_t error = soxr_oneshot(sound.rate, play_rate, sound.channels,
69 std::data(tmp), std::size(tmp) / align,
nullptr,
70 std::data(data), std::size(data) / align,
nullptr,
71 &this->io, &this->quality, &this->runtime);
73 if (error !=
nullptr) {
78 sound.rate = play_rate;
87 const soxr_io_spec_t
io = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I);
88 const soxr_quality_spec_t
quality = soxr_quality_spec(SOXR_VHQ, 0);
89 const soxr_runtime_spec_t
runtime = soxr_runtime_spec(1);
Soxr SoundResampler implementation.
const soxr_quality_spec_t quality
Quality settings.
SoundResampler_Soxr()
Create this SoundResample_Soxr instance.
static SoundResampler_Soxr instance
Instance of this SoundResampler.
const soxr_runtime_spec_t runtime
Runtime settings.
static void ConvertInt8toInt16(std::span< const std::byte > in, std::span< std::byte > out)
Convert samples from 8 bits to 16 bits.
bool Resample(SoundEntry &sound, uint32_t play_rate) const override
Resample a loaded sound.
const soxr_io_spec_t io
Input/output settings.
SoundResampler(std::string_view name, std::string_view description, int priority)
Create the provider.
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
@ Misc
Misc message facility.
@ Critical
Critical, user should know about this.
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
A number of safeguards to prevent using unsafe methods.
Types related to sound resamplers.
Definition of base types and functions in a cross-platform compatible way.