Files
ladybird/Libraries/LibMedia/Audio/SampleSpecification.h
Zaggy1024 19ccec2c10 LibMedia: Create a channel map for audio blocks from decoders
Audio blocks now contain a sample specification with the sample rate
and channel map for the audio data they contain. This will facilitate
conversion from one sample specification to another in order to allow
playback on devices with more or less speakers than the audio data
contains.
2025-12-13 08:58:26 +01:00

55 lines
1.3 KiB
C++

/*
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibMedia/Audio/ChannelMap.h>
namespace Audio {
class SampleSpecification {
public:
SampleSpecification() = default;
SampleSpecification(u32 sample_rate, ChannelMap channel_map)
: m_sample_rate(sample_rate)
, m_channel_map(channel_map)
{
}
bool is_valid() const
{
return m_sample_rate > 0 && m_channel_map.channel_count() > 0;
}
u32 sample_rate() const { return m_sample_rate; }
ChannelMap const& channel_map() const { return m_channel_map; }
u8 channel_count() const { return channel_map().channel_count(); }
[[nodiscard]] constexpr bool operator==(SampleSpecification const& other) const
{
return sample_rate() == other.sample_rate() && channel_map() == other.channel_map();
}
private:
u32 m_sample_rate { 0 };
ChannelMap m_channel_map;
};
}
namespace AK {
template<>
struct Formatter<Audio::SampleSpecification> : StandardFormatter {
static ErrorOr<void> format(FormatBuilder& builder, Audio::SampleSpecification sample_specification)
{
return builder.builder().try_appendff("{} Hz, {}", sample_specification.sample_rate(), sample_specification.channel_map());
}
};
}