Skip to content

Commit

Permalink
Fix ISO 14496-3 table to use 24kHz for AAC instead of 23kHz.
Browse files Browse the repository at this point in the history
  - 23kHz must have been incorrectly copied and propagated. The source ISO 14496-3 table uses 24kHz in this slot.
  - The old value is simply wrong, and the enums map directly to the table (offset by 1). Force rename the typos to represent the correct value.

PiperOrigin-RevId: 713774201
  • Loading branch information
jwcullen committed Jan 9, 2025
1 parent 810dc05 commit d4fcda0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
annotations.
- Fix compliance with ISO 14496-1:2010 when writing AAC Codec Config OBUs
(AOMediaCodec/libiamf#119).
- Fix issues when using AAC with a 24 kHz sample rate.
- Permit one fully trimmed audio frame at the end of a substream.

## [1.0.0] - 2024-01-26
Expand Down
2 changes: 1 addition & 1 deletion iamf/cli/lookup_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class LookupTables {
{AAC_SAMPLE_FREQUENCY_INDEX_48000, k48000},
{AAC_SAMPLE_FREQUENCY_INDEX_44100, k44100},
{AAC_SAMPLE_FREQUENCY_INDEX_32000, k32000},
{AAC_SAMPLE_FREQUENCY_INDEX_23000, k23000},
{AAC_SAMPLE_FREQUENCY_INDEX_24000, k24000},
{AAC_SAMPLE_FREQUENCY_INDEX_22050, k22050},
{AAC_SAMPLE_FREQUENCY_INDEX_16000, k16000},
{AAC_SAMPLE_FREQUENCY_INDEX_12000, k12000},
Expand Down
2 changes: 1 addition & 1 deletion iamf/cli/proto/codec_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ enum SampleFrequencyIndex {
AAC_SAMPLE_FREQUENCY_INDEX_48000 = 4;
AAC_SAMPLE_FREQUENCY_INDEX_44100 = 5;
AAC_SAMPLE_FREQUENCY_INDEX_32000 = 6;
AAC_SAMPLE_FREQUENCY_INDEX_23000 = 7;
AAC_SAMPLE_FREQUENCY_INDEX_24000 = 7;
AAC_SAMPLE_FREQUENCY_INDEX_22050 = 8;
AAC_SAMPLE_FREQUENCY_INDEX_16000 = 9;
AAC_SAMPLE_FREQUENCY_INDEX_12000 = 10;
Expand Down
20 changes: 20 additions & 0 deletions iamf/cli/proto_to_obu/tests/codec_config_generator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,26 @@ TEST_F(CodecConfigGeneratorTest, InvalidUnknownSamplingFrequencyIndex) {
EXPECT_FALSE(InitAndGenerate().ok());
}

TEST_F(CodecConfigGeneratorTest, ConfiguresAacWithImplicitSamplingFrequency) {
InitMetadataForAac(codec_config_metadata_);
codec_config_metadata_.at(0)
.mutable_codec_config()
->mutable_decoder_config_aac()
->mutable_decoder_specific_info()
->set_sample_frequency_index(
iamf_tools_cli_proto::AAC_SAMPLE_FREQUENCY_INDEX_24000);

const auto output_obus = InitAndGenerate();
ASSERT_THAT(output_obus, IsOk());

const auto& audio_specific_config =
std::get<AacDecoderConfig>(
output_obus->at(kCodecConfigId).GetCodecConfig().decoder_config)
.decoder_specific_info_.audio_specific_config;
EXPECT_EQ(audio_specific_config.sample_frequency_index_,
AudioSpecificConfig::SampleFrequencyIndex::k24000);
}

TEST_F(CodecConfigGeneratorTest, ConfiguresAacWithExplicitSamplingFrequency) {
InitMetadataForAac(codec_config_metadata_);
codec_config_metadata_.at(0)
Expand Down
2 changes: 1 addition & 1 deletion iamf/obu/decoder_config/aac_decoder_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ absl::Status AacDecoderConfig::GetOutputSampleRate(
{k48000, 48000},
{k44100, 44100},
{k32000, 32000},
{k23000, 23000},
{k24000, 24000},
{k22050, 22050},
{k16000, 16000},
{k12000, 12000},
Expand Down
2 changes: 1 addition & 1 deletion iamf/obu/decoder_config/aac_decoder_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AudioSpecificConfig {
k48000 = 3,
k44100 = 4,
k32000 = 5,
k23000 = 6,
k24000 = 6,
k22050 = 7,
k16000 = 8,
k12000 = 9,
Expand Down
41 changes: 39 additions & 2 deletions iamf/obu/decoder_config/tests/aac_decoder_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ constexpr uint8_t kUpperByteSerializedSamplingFrequencyIndex64000 =
constexpr uint8_t kLowerByteSerializedSamplingFrequencyIndex64000 =
(static_cast<uint8_t>(SampleFrequencyIndex::k64000) & 0x01) << 7;

// Despite being represented in 4-bits the AAC Sampling Frequency Index 24000 is
// serialized across a byte boundary.
constexpr uint8_t kUpperByteSerializedSamplingFrequencyIndex24000 =
(static_cast<uint8_t>(SampleFrequencyIndex::k24000) & 0x0e) >> 1;
constexpr uint8_t kLowerByteSerializedSamplingFrequencyIndex24000 =
(static_cast<uint8_t>(SampleFrequencyIndex::k24000) & 0x01) << 7;

constexpr uint8_t kUpperByteSerializedSamplingFrequencyIndexEscape =
(static_cast<uint8_t>(SampleFrequencyIndex::kEscapeValue) & 0x0e) >> 1;
constexpr uint8_t kLowerByteSerializedSamplingFrequencyIndexEscape =
Expand Down Expand Up @@ -185,7 +192,7 @@ TEST(AacDecoderConfig, ValidatesExtensionFlag) {
EXPECT_FALSE(aac_decoder_config.Validate().ok());
}

TEST(AudioSpecificConfig, ReadsWithImplicitSampleFrequency) {
TEST(AudioSpecificConfig, ReadsWithImplicitSampleFrequency64000) {
std::vector<uint8_t> data = {
// `audio_object_type`, upper 3 bits of `sample_frequency_index`.
AudioSpecificConfig::kAudioObjectType << 3 |
Expand Down Expand Up @@ -215,6 +222,25 @@ TEST(AudioSpecificConfig, ReadsWithImplicitSampleFrequency) {
AudioSpecificConfig::GaSpecificConfig::kExtensionFlag);
}

TEST(AudioSpecificConfig, ReadsWithImplicitSampleFrequency24000) {
const std::vector<uint8_t> data = {
// `audio_object_type`, upper 3 bits of `sample_frequency_index`.
AudioSpecificConfig::kAudioObjectType << 3 |
kUpperByteSerializedSamplingFrequencyIndex24000,
// lower bit of `sample_frequency_index`,
// `channel_configuration`, `frame_length_flag`,
// `depends_on_core_coder`, `extension_flag`.
kLowerByteSerializedSamplingFrequencyIndex24000 |
kChannelConfigurationAndGaSpecificConfigMask};
AudioSpecificConfig audio_specific_config;
auto rb = MemoryBasedReadBitBuffer::CreateFromSpan(1024, data);

EXPECT_THAT(audio_specific_config.Read(*rb), IsOk());

EXPECT_EQ(audio_specific_config.sample_frequency_index_,
SampleFrequencyIndex::k24000);
}

TEST(AudioSpecificConfig, ReadsWithExplicitSampleFrequency) {
constexpr uint32_t kSampleFrequency = 48000;
std::vector<uint8_t> data = {
Expand Down Expand Up @@ -688,7 +714,7 @@ TEST_F(AacTest, OverflowBufferSizeDbOver24Bits) {
TestWriteDecoderConfig();
}

TEST_F(AacTest, GetImplicitSampleRate) {
TEST_F(AacTest, GetImplicitSampleRate64000) {
aac_decoder_config_.decoder_specific_info_.audio_specific_config
.sample_frequency_index_ = SampleFrequencyIndex::k64000;

Expand All @@ -699,6 +725,17 @@ TEST_F(AacTest, GetImplicitSampleRate) {
EXPECT_EQ(output_sample_rate, 64000);
}

TEST_F(AacTest, GetImplicitSampleRate24000) {
aac_decoder_config_.decoder_specific_info_.audio_specific_config
.sample_frequency_index_ = SampleFrequencyIndex::k24000;

uint32_t output_sample_rate;
EXPECT_THAT(aac_decoder_config_.GetOutputSampleRate(output_sample_rate),
IsOk());

EXPECT_EQ(output_sample_rate, 24000);
}

TEST_F(AacTest, GetExplicitSampleRate) {
aac_decoder_config_.decoder_specific_info_.audio_specific_config
.sample_frequency_index_ = SampleFrequencyIndex::kEscapeValue;
Expand Down

0 comments on commit d4fcda0

Please sign in to comment.