7#include "../utility/utility.hpp"
8#include "../macros.hpp"
9#include <hikocpu/hikocpu.hpp>
12hi_export_module(hikogui.audio.audio_sample_format);
14hi_export
namespace hi {
inline namespace v1 {
93 return {4, 8, 23,
true, std::endian::little};
96 [[nodiscard]]
constexpr static audio_sample_format float32_be() noexcept
98 return {4, 8, 23,
true, std::endian::big};
101 [[nodiscard]]
constexpr static audio_sample_format float32() noexcept
103 return {4, 8, 23,
true, std::endian::native};
106 [[nodiscard]]
constexpr static audio_sample_format int16_le() noexcept
108 return {2, 0, 15,
false, std::endian::little};
111 [[nodiscard]]
constexpr static audio_sample_format int16_be() noexcept
113 return {2, 0, 15,
false, std::endian::big};
116 [[nodiscard]]
constexpr static audio_sample_format int16() noexcept
118 return {2, 0, 15,
false, std::endian::native};
121 [[nodiscard]]
constexpr static audio_sample_format int20_le() noexcept
123 return {3, 0, 19,
false, std::endian::little};
126 [[nodiscard]]
constexpr static audio_sample_format int20_be() noexcept
128 return {3, 0, 19,
false, std::endian::big};
131 [[nodiscard]]
constexpr static audio_sample_format int20() noexcept
133 return {3, 0, 19,
false, std::endian::native};
136 [[nodiscard]]
constexpr static audio_sample_format int24_le() noexcept
138 return {3, 0, 23,
false, std::endian::little};
141 [[nodiscard]]
constexpr static audio_sample_format int24_be() noexcept
143 return {3, 0, 23,
false, std::endian::big};
146 [[nodiscard]]
constexpr static audio_sample_format int24() noexcept
148 return {3, 0, 23,
false, std::endian::native};
151 [[nodiscard]]
constexpr static audio_sample_format int32_le() noexcept
153 return {4, 0, 31,
false, std::endian::little};
156 [[nodiscard]]
constexpr static audio_sample_format int32_be() noexcept
158 return {4, 0, 31,
false, std::endian::big};
161 [[nodiscard]]
constexpr static audio_sample_format int32() noexcept
163 return {4, 0, 31,
false, std::endian::native};
166 [[nodiscard]]
constexpr static audio_sample_format fix8_23_le() noexcept
168 return {4, 8, 23,
false, std::endian::little};
171 [[nodiscard]]
constexpr static audio_sample_format fix8_23_be() noexcept
173 return {4, 8, 23,
false, std::endian::big};
176 [[nodiscard]]
constexpr static audio_sample_format fix8_23() noexcept
178 return {4, 8, 23,
false, std::endian::native};
181 constexpr explicit operator bool() const noexcept
195 auto max_value = (1_uz <<
num_bits) - 1;
201 return static_cast<float>(max_value);
217 auto r = narrow_cast<int>(std::bit_floor((((16u -
num_bytes) / stride) & 3) + 1));
218 hi_assert(r == 1 or r == 2 or r == 4);
240 auto const src_buffer_size = (num_samples - 1) * stride +
num_bytes;
241 if (src_buffer_size < 16) {
245 auto const num_chunks = (src_buffer_size - 16) /
chunk_stride(stride) + 1;
256 auto r = i8x16::broadcast(-1);
257 for (
int sample_nr = 0; sample_nr != num_samples; ++sample_nr) {
258 auto const sample_src_offset = sample_nr * stride;
264 auto const sample_dst_offset = (sample_nr + (4 - num_samples)) * 4;
267 for (
int byte_nr = 0; byte_nr !=
num_bytes; ++byte_nr) {
268 auto const src_offset = sample_src_offset + (
endian == std::endian::little ? byte_nr :
num_bytes - byte_nr - 1);
271 auto const dst_offset = sample_dst_offset + byte_nr + (4 -
num_bytes);
273 r[dst_offset] = narrow_cast<int8_t>(src_offset);
287 auto r = i8x16::broadcast(-1);
288 for (
int sample_nr = 0; sample_nr != num_samples; ++sample_nr) {
289 auto const sample_dst_offset = sample_nr * stride;
295 auto const sample_src_offset = sample_nr * 4;
298 for (
int byte_nr = 0; byte_nr !=
num_bytes; ++byte_nr) {
299 auto const dst_offset = sample_dst_offset + (
endian == std::endian::little ? byte_nr :
num_bytes - byte_nr - 1);
302 auto const src_offset = sample_src_offset + byte_nr + (4 -
num_bytes);
304 r[dst_offset] = narrow_cast<int8_t>(src_offset);
318 auto const byte_shift = (4 - num_samples) * 4;
320 return i8x16::byte_srl_shuffle_indices(narrow_cast<unsigned int>(byte_shift));
328 (
endian == std::endian::little ||
endian == std::endian::big);
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Audio sample format.
Definition audio_sample_format.hpp:30
uint8_t num_bytes
The number of bytes of the container.
Definition audio_sample_format.hpp:34
constexpr bool holds_invariant() const noexcept
Is the audio sample format valid.
Definition audio_sample_format.hpp:325
i8x16 load_shuffle_indices(std::size_t stride) const noexcept
Return a shuffle indices for loading samples into 32 bit integers.
Definition audio_sample_format.hpp:251
std::size_t num_chunks_per_quad(std::size_t stride) const noexcept
The number of chunks to load or store to handle 4 samples.
Definition audio_sample_format.hpp:231
bool is_float
The numeric type is floating point.
Definition audio_sample_format.hpp:56
std::size_t chunk_stride(std::size_t stride) const noexcept
The number of bytes to advance to the next chunk to be loaded or stored.
Definition audio_sample_format.hpp:224
std::size_t num_samples_per_chunk(std::size_t stride) const noexcept
The number of packed samples that are handled in a single 128 bit load or store.
Definition audio_sample_format.hpp:215
i8x16 store_shuffle_indices(std::size_t stride) const noexcept
Return a shuffle indices for storing 32 bit samples into packed samples.
Definition audio_sample_format.hpp:282
uint8_t num_bits
The number of significant bits of the sample format.
Definition audio_sample_format.hpp:51
std::endian endian
The endian order of the bytes in the container.
Definition audio_sample_format.hpp:60
uint8_t num_guard_bits
The number of bits used for the integer part of a fixed point number.
Definition audio_sample_format.hpp:39
i8x16 concat_shuffle_indices(std::size_t stride) const noexcept
Return a shuffle indices to shift previous loaded samples for concatenation.
Definition audio_sample_format.hpp:313
float pack_multiplier() const noexcept
How much to multiply float samples to create integer samples.
Definition audio_sample_format.hpp:188
float unpack_multiplier() const noexcept
How much to multiply integer samples to create float samples.
Definition audio_sample_format.hpp:207
std::size_t num_fast_quads(std::size_t stride, std::size_t num_samples) const noexcept
Calculate the number of 4 sample-quads can be handled as chunked loads and stores.
Definition audio_sample_format.hpp:238