diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 426a652a4c10da1337c8231a53b0c98cea918f3f..4ed8f8f0ae82e48835da8b709d5852c0d637b7f9 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -1178,13 +1178,14 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
         if (aot == AOT_ER_AAC_LD || aot == AOT_ER_AAC_ELD) {
             ics->swb_offset        =     ff_swb_offset_512[ac->oc[1].m4ac.sampling_index];
             ics->num_swb           =    ff_aac_num_swb_512[ac->oc[1].m4ac.sampling_index];
+            ics->tns_max_bands     =  ff_tns_max_bands_512[ac->oc[1].m4ac.sampling_index];
             if (!ics->num_swb || !ics->swb_offset)
                 return AVERROR_BUG;
         } else {
             ics->swb_offset        =    ff_swb_offset_1024[ac->oc[1].m4ac.sampling_index];
             ics->num_swb           =   ff_aac_num_swb_1024[ac->oc[1].m4ac.sampling_index];
+            ics->tns_max_bands     = ff_tns_max_bands_1024[ac->oc[1].m4ac.sampling_index];
         }
-        ics->tns_max_bands         = ff_tns_max_bands_1024[ac->oc[1].m4ac.sampling_index];
         if (aot != AOT_ER_AAC_ELD) {
             ics->predictor_present     = get_bits1(gb);
             ics->predictor_reset_group = 0;
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index 77cbc2d460d2b9bdc46595d70e2076ad97fd2678..46aa10a70ed53b695311fb2718597e800f4a9550 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -1237,6 +1237,10 @@ const uint8_t ff_tns_max_bands_1024[] = {
     31, 31, 34, 40, 42, 51, 46, 46, 42, 42, 42, 39, 39
 };
 
+const uint8_t ff_tns_max_bands_512[] = {
+    0, 0, 0, 31, 32, 37, 31, 31, 0, 0, 0, 0, 0
+};
+
 const uint8_t ff_tns_max_bands_128[] = {
     9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14
 };
diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h
index a2dc46b81437111b2e90531781b725e894504170..adf2e2c2b83feec6511121108f229c54281aa6ad 100644
--- a/libavcodec/aactab.h
+++ b/libavcodec/aactab.h
@@ -76,6 +76,7 @@ extern const uint16_t * const ff_swb_offset_512 [13];
 extern const uint16_t * const ff_swb_offset_128 [13];
 
 extern const uint8_t ff_tns_max_bands_1024[13];
+extern const uint8_t ff_tns_max_bands_512 [13];
 extern const uint8_t ff_tns_max_bands_128 [13];
 
 #endif /* AVCODEC_AACTAB_H */