LibAudio: Add integer sample format-specific support

This allows us to better handle specifically integer sample formats.
This commit is contained in:
kleines Filmröllchen 2023-06-30 20:07:18 +02:00 committed by Andrew Kaster
parent e45a666419
commit 7bb128e1ed
Notes: sideshowbarker 2024-07-17 07:43:44 +09:00
2 changed files with 23 additions and 0 deletions

View file

@ -27,6 +27,27 @@ u16 pcm_bits_per_sample(PcmSampleFormat format)
}
}
bool is_integer_format(PcmSampleFormat format)
{
return format == PcmSampleFormat::Uint8 || format == PcmSampleFormat::Int16 || format == PcmSampleFormat::Int24 || format == PcmSampleFormat::Int32;
}
Optional<PcmSampleFormat> integer_sample_format_for(u16 bits_per_sample)
{
switch (bits_per_sample) {
case 8:
return PcmSampleFormat::Uint8;
case 16:
return PcmSampleFormat::Int16;
case 24:
return PcmSampleFormat::Int24;
case 32:
return PcmSampleFormat::Int32;
default:
return {};
}
}
DeprecatedString sample_format_name(PcmSampleFormat format)
{
bool is_float = format == PcmSampleFormat::Float32 || format == PcmSampleFormat::Float64;

View file

@ -23,5 +23,7 @@ enum class PcmSampleFormat : u8 {
// Most of the read code only cares about how many bits to read or write
u16 pcm_bits_per_sample(PcmSampleFormat format);
bool is_integer_format(PcmSampleFormat format);
Optional<PcmSampleFormat> integer_sample_format_for(u16 bits_per_sample);
DeprecatedString sample_format_name(PcmSampleFormat format);
}