Skip to content

Commit

Permalink
Add LFE to user_metadata_builder and related files.
Browse files Browse the repository at this point in the history
  - May prove to be useful to simplify setting up LFE only audio elements.

PiperOrigin-RevId: 706741782
  • Loading branch information
jwcullen committed Dec 16, 2024
1 parent 9144b07 commit 511e52c
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,17 @@ bool IsChannelBasedAndNotStereo(IamfInputLayout input_layout) {
case k7_1:
case k7_1_4:
case kBinaural:
case kLFE:
return true;
case kStereo:
case kAmbisonicsOrder1:
case kAmbisonicsOrder2:
case kAmbisonicsOrder3:
return false;
}
// The above switch is exhaustive.
LOG(FATAL) << "Unexpcected value for `IamfInputLayout`: "
<< static_cast<int>(input_layout);
}

} // namespace
Expand Down
37 changes: 36 additions & 1 deletion iamf/cli/user_metadata_builder/audio_element_metadata_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ absl::StatusOr<int32_t> LookupNumSubstreamsFromInputLayout(
{k7_1, 5},
{k7_1_4, 7},
{kBinaural, 1},
{kLFE, 1},
{kAmbisonicsOrder1, 4},
{kAmbisonicsOrder2, 9},
{kAmbisonicsOrder3, 16},
});

return LookupInMap(*kInputLayoutToNumSubstreams, input_layout,
"Number of channels for `IamfInputLayout`");
"Number of substreams for `IamfInputLayout`");
}

absl::StatusOr<int32_t> LookupCoupledSubstreamCountFromInputLayout(
Expand All @@ -68,6 +69,7 @@ absl::StatusOr<int32_t> LookupCoupledSubstreamCountFromInputLayout(
{k7_1, 3},
{k7_1_4, 5},
{kBinaural, 1},
{kLFE, 0},
});

return LookupInMap(*kInputLayoutToCoupledSubstreamCount, input_layout,
Expand All @@ -92,12 +94,30 @@ LookupLoudspeakerLayoutFromInputLayout(IamfInputLayout input_layout) {
{k7_1, LOUDSPEAKER_LAYOUT_7_1_CH},
{k7_1_4, LOUDSPEAKER_LAYOUT_7_1_4_CH},
{kBinaural, LOUDSPEAKER_LAYOUT_BINAURAL},
{kLFE, LOUDSPEAKER_LAYOUT_EXPANDED},
});

return LookupInMap(*KInputLayoutToLoudspeakerLayout, input_layout,
"Proto `LoudspeakerLayout` for `IamfInputLayout`");
}

absl::StatusOr<iamf_tools_cli_proto::ExpandedLoudspeakerLayout>
LookupExpandedLoudspeakerLayoutFromInputLayout(IamfInputLayout input_layout) {
using enum IamfInputLayout;
using enum iamf_tools_cli_proto::ExpandedLoudspeakerLayout;

// Map which holds the channel layout and the corresponding expanded
// loudspeaker layout in IAMF.
static const absl::NoDestructor<absl::flat_hash_map<
IamfInputLayout, iamf_tools_cli_proto::ExpandedLoudspeakerLayout>>
KInputLayoutToExpandedLoudspeakerLayout({
{kLFE, EXPANDED_LOUDSPEAKER_LAYOUT_LFE},
});

return LookupInMap(*KInputLayoutToExpandedLoudspeakerLayout, input_layout,
"Proto `ExpandedLoudspeakerLayout` for `IamfInputLayout`");
}

absl::StatusOr<iamf_tools_cli_proto::AudioElementType>
LookupAudioElementTypeFromInputLayout(IamfInputLayout input_layout) {
using enum IamfInputLayout;
Expand All @@ -116,6 +136,7 @@ LookupAudioElementTypeFromInputLayout(IamfInputLayout input_layout) {
{k7_1, AUDIO_ELEMENT_CHANNEL_BASED},
{k7_1_4, AUDIO_ELEMENT_CHANNEL_BASED},
{kBinaural, AUDIO_ELEMENT_CHANNEL_BASED},
{kLFE, AUDIO_ELEMENT_CHANNEL_BASED},
{kAmbisonicsOrder1, AUDIO_ELEMENT_SCENE_BASED},
{kAmbisonicsOrder2, AUDIO_ELEMENT_SCENE_BASED},
{kAmbisonicsOrder3, AUDIO_ELEMENT_SCENE_BASED},
Expand Down Expand Up @@ -158,6 +179,20 @@ absl::Status PopulateChannelBasedAudioElementMetadata(
}
channel_audio_layer_config->set_coupled_substream_count(
*coupled_substream_count);

// Set the specific 'expanded_loudspeaker_layout' field when it is relevant
// (e.g. LFE).
if (channel_audio_layer_config->loudspeaker_layout() ==
iamf_tools_cli_proto::LOUDSPEAKER_LAYOUT_EXPANDED) {
const auto expanded_loudspeaker_layout =
LookupExpandedLoudspeakerLayoutFromInputLayout(input_layout);
if (!expanded_loudspeaker_layout.ok()) {
return expanded_loudspeaker_layout.status();
}
channel_audio_layer_config->set_expanded_loudspeaker_layout(
*expanded_loudspeaker_layout);
}

return absl::OkStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ LookupLabelsFromInputLayout(IamfInputLayout input_layout) {
CHANNEL_LABEL_LRS_7, CHANNEL_LABEL_RRS_7, CHANNEL_LABEL_LTF_4,
CHANNEL_LABEL_RTF_4, CHANNEL_LABEL_LTB_4, CHANNEL_LABEL_RTB_4}},
{kBinaural, {CHANNEL_LABEL_L_2, CHANNEL_LABEL_R_2}},
{kLFE, {CHANNEL_LABEL_LFE}},
{kAmbisonicsOrder1,
{CHANNEL_LABEL_A_0, CHANNEL_LABEL_A_1, CHANNEL_LABEL_A_2,
CHANNEL_LABEL_A_3}},
Expand Down
1 change: 1 addition & 0 deletions iamf/cli/user_metadata_builder/iamf_input_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ absl::StatusOr<IamfInputLayout> LookupInputLayoutFromAudioPackFormatId(
{"AP_0001000f", IamfInputLayout::k7_1},
{"AP_00010017", IamfInputLayout::k7_1_4},
{"AP_00050001", IamfInputLayout::kBinaural},
{"AP_00011FFF", IamfInputLayout::kLFE},
{"AP_00040001", IamfInputLayout::kAmbisonicsOrder1},
{"AP_00040002", IamfInputLayout::kAmbisonicsOrder2},
{"AP_00040003", IamfInputLayout::kAmbisonicsOrder3},
Expand Down
1 change: 1 addition & 0 deletions iamf/cli/user_metadata_builder/iamf_input_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class IamfInputLayout {
k7_1,
k7_1_4,
kBinaural,
kLFE,
kAmbisonicsOrder1,
kAmbisonicsOrder2,
kAmbisonicsOrder3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,34 @@ TEST(PopulateAudioElementMetadata, ConfiguresLoudspeakerLayoutForBinaural) {
iamf_tools_cli_proto::LOUDSPEAKER_LAYOUT_BINAURAL);
}

TEST(PopulateAudioElementMetadata, ConfiguresLFE) {
iamf_tools_cli_proto::AudioElementObuMetadata audio_element_metadata;
AudioElementMetadataBuilder audio_element_metadata_builder;

EXPECT_THAT(audio_element_metadata_builder.PopulateAudioElementMetadata(
kAudioElementId, kCodecConfigId, IamfInputLayout::kLFE,
audio_element_metadata),
IsOk());

EXPECT_EQ(audio_element_metadata.num_substreams(), 1);
EXPECT_EQ(audio_element_metadata.audio_substream_ids().size(), 1);
EXPECT_EQ(audio_element_metadata.audio_substream_ids().at(0), 0);
ASSERT_TRUE(audio_element_metadata.has_scalable_channel_layout_config());
EXPECT_EQ(audio_element_metadata.scalable_channel_layout_config()
.channel_audio_layer_configs()
.size(),
1);
const auto& first_channel_audio_layer_config =
audio_element_metadata.scalable_channel_layout_config()
.channel_audio_layer_configs(0);
EXPECT_EQ(first_channel_audio_layer_config.loudspeaker_layout(),
iamf_tools_cli_proto::LOUDSPEAKER_LAYOUT_EXPANDED);
EXPECT_EQ(first_channel_audio_layer_config.expanded_loudspeaker_layout(),
iamf_tools_cli_proto::EXPANDED_LOUDSPEAKER_LAYOUT_LFE);
EXPECT_EQ(first_channel_audio_layer_config.substream_count(), 1);
EXPECT_EQ(first_channel_audio_layer_config.coupled_substream_count(), 0);
}

TEST(PopulateAudioElementMetadata, ConfiguresFirstOrderAmbisonics) {
iamf_tools_cli_proto::AudioElementObuMetadata audio_element_metadata;
AudioElementMetadataBuilder audio_element_metadata_builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ TEST(PopulateAudioFrameMetadata,
EXPECT_EQ(audio_frame_obu_metadata.channel_metadatas(1).channel_id(), 1);
}

TEST(PopulateAudioFrameMetadata, ConfiguresChannelIdsAndLabelsForLFEInput) {
const auto audio_frame_obu_metadata = GetAudioFrameMetadataExpectOk(
kWavFilename, IamfInputLayout::kLFE, kFirstAudioElementId);

ExpectLabelsAreConvertibleToChannelLabels(
audio_frame_obu_metadata.channel_metadatas(), {kLFE});
EXPECT_EQ(audio_frame_obu_metadata.channel_metadatas(0).channel_id(), 0);
}

TEST(PopulateAudioFrameMetadata,
ConfiguresChannelIdsAndLabelsForAmbisonicsOrder1Input) {
const auto audio_frame_obu_metadata = GetAudioFrameMetadataExpectOk(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ INSTANTIATE_TEST_SUITE_P(Binaural, SupportedAudioPackFormatId,
testing::ValuesIn<SupportedAudioPackFormatIdTestCase>(
{{"AP_00050001", IamfInputLayout::kBinaural}}));

INSTANTIATE_TEST_SUITE_P(LFE, SupportedAudioPackFormatId,
testing::ValuesIn<SupportedAudioPackFormatIdTestCase>(
{{"AP_00011FFF", IamfInputLayout::kLFE}}));

INSTANTIATE_TEST_SUITE_P(
Ambisonics, SupportedAudioPackFormatId,
testing::ValuesIn<SupportedAudioPackFormatIdTestCase>({
Expand Down

0 comments on commit 511e52c

Please sign in to comment.