Libraries: Change enums to enum classes in LibAudio

This commit is contained in:
Lenny Maiorani 2022-03-17 14:38:24 -06:00 committed by Andreas Kling
parent be360db223
commit d3893a73fb
Notes: sideshowbarker 2024-07-17 17:10:11 +09:00
5 changed files with 22 additions and 22 deletions

View File

@ -169,7 +169,7 @@ MaybeLoaderError FlacLoaderPlugin::reset()
MaybeLoaderError FlacLoaderPlugin::seek(const int position)
{
if (m_stream->seek(position, Core::Stream::SeekMode::SetPosition).is_error())
return LoaderError { LoaderError::IO, m_loaded_samples, String::formatted("Invalid seek position {}", position) };
return LoaderError { LoaderError::Category::IO, m_loaded_samples, String::formatted("Invalid seek position {}", position) };
return {};
}
@ -232,7 +232,7 @@ MaybeLoaderError FlacLoaderPlugin::next_frame(Span<Sample> target_vector)
u32 frame_sample_rate = TRY(convert_sample_rate_code(LOADER_TRY(bit_stream->read_bits<u8>(4))));
u8 channel_type_num = LOADER_TRY(bit_stream->read_bits<u8>(4));
FLAC_VERIFY(channel_type_num < 0b1011, LoaderError::Format, "Channel assignment");
FLAC_VERIFY(channel_type_num < 0b1011, LoaderError::Category::Format, "Channel assignment");
FlacFrameChannelType channel_type = (FlacFrameChannelType)channel_type_num;
PcmSampleFormat bit_depth = TRY(convert_bit_depth_code(LOADER_TRY(bit_stream->read_bits<u8>(3))));
@ -440,8 +440,8 @@ ErrorOr<PcmSampleFormat, LoaderError> FlacLoaderPlugin::convert_bit_depth_code(u
u8 frame_channel_type_to_channel_count(FlacFrameChannelType channel_type)
{
if (channel_type <= 7)
return channel_type + 1;
if (channel_type <= FlacFrameChannelType::Surround7p1)
return to_underlying(channel_type) + 1;
return 2;
}
@ -451,13 +451,13 @@ ErrorOr<FlacSubframeHeader, LoaderError> FlacLoaderPlugin::next_subframe_header(
// For inter-channel correlation, the side channel needs an extra bit for its samples
switch (m_current_frame->channels) {
case LeftSideStereo:
case MidSideStereo:
case FlacFrameChannelType::LeftSideStereo:
case FlacFrameChannelType::MidSideStereo:
if (channel_index == 1) {
++bits_per_sample;
}
break;
case RightSideStereo:
case FlacFrameChannelType::RightSideStereo:
if (channel_index == 0) {
++bits_per_sample;
}
@ -675,7 +675,7 @@ ErrorOr<Vector<i32>, LoaderError> FlacLoaderPlugin::decode_fixed_lpc(FlacSubfram
// Decode the residual, the "error" between the function approximation and the actual audio data
MaybeLoaderError FlacLoaderPlugin::decode_residual(Vector<i32>& decoded, FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input)
{
u8 residual_mode = LOADER_TRY(bit_input.read_bits<u8>(2));
auto residual_mode = static_cast<FlacResidualMode>(LOADER_TRY(bit_input.read_bits<u8>(2)));
u8 partition_order = LOADER_TRY(bit_input.read_bits<u8>(4));
size_t partitions = 1 << partition_order;

View File

@ -21,7 +21,7 @@ namespace Audio {
#define FLAC_SAMPLERATE_AT_END_OF_HEADER_16X10 0xfffffffd
// Metadata block type, 7 bits.
enum FlacMetadataBlockType : u8 {
enum class FlacMetadataBlockType : u8 {
STREAMINFO = 0, // Important data about the audio format
PADDING = 1, // Non-data block to be ignored
APPLICATION = 2, // Ignored
@ -33,7 +33,7 @@ enum FlacMetadataBlockType : u8 {
};
// follows FLAC codes
enum FlacFrameChannelType : u8 {
enum class FlacFrameChannelType : u8 {
Mono = 0,
Stereo = 1,
StereoCenter = 2, // left, right, center
@ -49,7 +49,7 @@ enum FlacFrameChannelType : u8 {
};
// follows FLAC codes
enum FlacSubframeType : u8 {
enum class FlacSubframeType : u8 {
Constant = 0,
Verbatim = 1,
Fixed = 0b001000,
@ -58,7 +58,7 @@ enum FlacSubframeType : u8 {
};
// follows FLAC codes
enum FlacResidualMode : u8 {
enum class FlacResidualMode : u8 {
Rice4Bit = 0,
Rice5Bit = 1,
};

View File

@ -14,7 +14,7 @@ namespace Audio {
struct LoaderError {
enum Category : u32 {
enum class Category : u32 {
// The error category is unknown.
Unknown = 0,
IO,
@ -25,7 +25,7 @@ struct LoaderError {
// The loader encountered something in the format that is not yet implemented.
Unimplemented,
};
Category category { Unknown };
Category category { Category::Unknown };
// Binary index: where in the file the error occurred.
size_t index { 0 };
FlyString description { String::empty() };

View File

@ -11,16 +11,16 @@ namespace Audio {
u16 pcm_bits_per_sample(PcmSampleFormat format)
{
switch (format) {
case Uint8:
case PcmSampleFormat::Uint8:
return 8;
case Int16:
case PcmSampleFormat::Int16:
return 16;
case Int24:
case PcmSampleFormat::Int24:
return 24;
case Int32:
case Float32:
case PcmSampleFormat::Int32:
case PcmSampleFormat::Float32:
return 32;
case Float64:
case PcmSampleFormat::Float64:
return 64;
default:
VERIFY_NOT_REACHED();
@ -29,7 +29,7 @@ u16 pcm_bits_per_sample(PcmSampleFormat format)
String sample_format_name(PcmSampleFormat format)
{
bool is_float = format == Float32 || format == Float64;
bool is_float = format == PcmSampleFormat::Float32 || format == PcmSampleFormat::Float64;
return String::formatted("PCM {}bit {}", pcm_bits_per_sample(format), is_float ? "Float" : "LE");
}

View File

@ -12,7 +12,7 @@
namespace Audio {
// Supported PCM sample formats.
enum PcmSampleFormat : u8 {
enum class PcmSampleFormat : u8 {
Uint8,
Int16,
Int24,