From a35b6b0c4bcf93c7f261c6317a1a8e8eb141f33c Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Sun, 5 Apr 2026 19:58:00 +0300 Subject: [PATCH] bluez5: aac: use higher band limit for CBR mode FDK-AAC encoder uses band pass filter, which is automatically applied at all bitrates. For CBR encoding mode, its values are as follows (for stereo): * 0-12 kb/s: 5 kHz * 12-20 kb/s: 6.4 kHz * 20-28 kb/s: 9.6 kHz * 40-56 kb/s: 13 kHz * 56-72 kb/s: 16 kHz * 72-576 kb/s: 17 kHz VBR uses the following table (stereo): * Mode 1: 13 kHz * Mode 2: 13 kHz * Mode 3: 15.7 kHz * Mode 4: 16.5 kHz * Mode 5: 19.3 kHz 17 kHz for CBR is a limiting value for high bitrate. Assume >110 kbit/s as a "high bitrate" CBR and increase the band pass cutout up to 19.3 kHz (as in mode 5 VBR). Link: https://github.com/mstorsjo/fdk-aac/blob/d8e6b1a3aa606c450241632b64b703f21ea31ce3/libAACenc/src/bandwidth.cpp#L114-L160 --- spa/plugins/bluez5/a2dp-codec-aac.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spa/plugins/bluez5/a2dp-codec-aac.c b/spa/plugins/bluez5/a2dp-codec-aac.c index 689e26ba6..c426dc1db 100644 --- a/spa/plugins/bluez5/a2dp-codec-aac.c +++ b/spa/plugins/bluez5/a2dp-codec-aac.c @@ -395,6 +395,15 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags, if (res != AACENC_OK) goto error; + // Assume >110 kbit/s as a "high bitrate" CBR and increase the + // band pass cutout up to 19.3 kHz (as in mode 5 VBR). + if (!conf->vbr && this->cur_bitrate > 110000) { + res = aacEncoder_SetParam(this->aacenc, AACENC_BANDWIDTH, + 19293); + if (res != AACENC_OK) + goto error; + } + res = aacEncoder_SetParam(this->aacenc, AACENC_TRANSMUX, TT_MP4_LATM_MCP1); if (res != AACENC_OK) goto error;