FLAC: Conditionally increase MAX_BLOCKSIZE to 8KB

High-frequency files increasingly use a block size of over 4608B, which
means we need larger buffers to decode them.  However, larger buffers no
longer fit in IRAM on less-capable devices, hurting performance for
"normal" file playback.

On our slowest devices (M68K and PP-based devices), this is not worth
the tradeoff as they will likely not have enough CPU oomph to decode and
downmix these files in realtime.

S5L87xx-based devices have the raw performance to do this, so we decided
to err on the side of wider file compatibility at the cost of some
performance.

All other devices are unaffected.

Change-Id: I7344cf4c8c6b7b5c14f1ea67381160665d6ece5b
This commit is contained in:
Solomon Peachy 2025-09-08 21:09:12 -04:00
parent ebe961a2a8
commit a98a8ce131
4 changed files with 18 additions and 14 deletions

View file

@ -25,8 +25,10 @@ In order to minimise memory usage, a small number of hard-coded limits
are present in decoder.h - mainly limiting the supported blocksize are present in decoder.h - mainly limiting the supported blocksize
(number of samples in a frame) to 4608. This is the default value (number of samples in a frame) to 4608. This is the default value
used by the reference FLAC encoder at all standard compression used by the reference FLAC encoder at all standard compression
settings. settings. However, it is increasingly common for high-resolution/freq
files to use 8K block sizes, so on devices that can play back such
files natively and/or have sufficient processor oomph to downmix in
realtime, we use that larger limit.
TESTING TESTING

View file

@ -19,22 +19,13 @@
#endif #endif
#if (CONFIG_CPU == MCF5250) || (CONFIG_CPU == PP5022) || \ #if (CONFIG_CPU == MCF5250) || (CONFIG_CPU == PP5022) || \
(CONFIG_CPU == PP5024) || (CONFIG_CPU == S5L8702) (CONFIG_CPU == PP5024)
#define ICODE_ATTR_FLAC ICODE_ATTR #define ICODE_ATTR_FLAC ICODE_ATTR
#define IBSS_ATTR_FLAC IBSS_ATTR #define IBSS_ATTR_FLAC IBSS_ATTR
/* Enough IRAM to move additional data to it. */ /* Enough IRAM to move additional data to it. */
#define IBSS_ATTR_FLAC_LARGE_IRAM IBSS_ATTR #define IBSS_ATTR_FLAC_LARGE_IRAM IBSS_ATTR
#define IBSS_ATTR_FLAC_XLARGE_IRAM #define IBSS_ATTR_FLAC_XLARGE_IRAM
#define IBSS_ATTR_FLAC_XXLARGE_IRAM #define IBSS_ATTR_FLAC_XXLARGE_IRAM
#elif (CONFIG_CPU == S5L8700) || (CONFIG_CPU == S5L8701)
#define ICODE_ATTR_FLAC ICODE_ATTR
#define IBSS_ATTR_FLAC IBSS_ATTR
/* Enough IRAM to move even more additional data to it. */
#define IBSS_ATTR_FLAC_LARGE_IRAM IBSS_ATTR
#define IBSS_ATTR_FLAC_XLARGE_IRAM IBSS_ATTR
#define IBSS_ATTR_FLAC_XXLARGE_IRAM
#else #else
#define ICODE_ATTR_FLAC ICODE_ATTR #define ICODE_ATTR_FLAC ICODE_ATTR
#define IBSS_ATTR_FLAC IBSS_ATTR #define IBSS_ATTR_FLAC IBSS_ATTR
@ -44,6 +35,12 @@
#define IBSS_ATTR_FLAC_XXLARGE_IRAM #define IBSS_ATTR_FLAC_XXLARGE_IRAM
#endif #endif
#if (ARCH == ARCH_M68K) || defined(CPU_PP) || MEMORYSIZE <= 2
#define MAX_BLOCKSIZE 4608
#else
#define MAX_BLOCKSIZE 8192
#endif
/* Endian conversion routines for standalone compilation */ /* Endian conversion routines for standalone compilation */
#ifdef BUILD_STANDALONE #ifdef BUILD_STANDALONE
#ifdef BUILD_BIGENDIAN #ifdef BUILD_BIGENDIAN

View file

@ -4,7 +4,9 @@
#include "bitstream.h" #include "bitstream.h"
#define MAX_CHANNELS 7 /* Maximum supported channels, only left/right will be played back */ #define MAX_CHANNELS 7 /* Maximum supported channels, only left/right will be played back */
#ifndef MAX_BLOCKSIZE
#define MAX_BLOCKSIZE 4608 /* Maxsize in samples of one uncompressed frame */ #define MAX_BLOCKSIZE 4608 /* Maxsize in samples of one uncompressed frame */
#endif
#define MAX_FRAMESIZE 65536 /* Maxsize in bytes of one compressed frame */ #define MAX_FRAMESIZE 65536 /* Maxsize in bytes of one compressed frame */
#define MIN_FRAME_SIZE 11 /* smallest valid FLAC frame possible */ #define MIN_FRAME_SIZE 11 /* smallest valid FLAC frame possible */

View file

@ -146,7 +146,10 @@
& Linear PCM 8/16/24/32 bit, IEEE float 32/64 bit, ITU-T G.711 a-law/$\mu$-law\\ & Linear PCM 8/16/24/32 bit, IEEE float 32/64 bit, ITU-T G.711 a-law/$\mu$-law\\
Free Lossless Audio Free Lossless Audio
& \fname{.flac} & \fname{.flac}
& Supports multichannel playback including downmixing to stereo.\\ & Multichannel and/or high-resolution files will be downmixed to 16-bit stereo.
\opt{ipod,iriverh10,sansaclip,sansam200v4,sansac200v2,iriverh100,iriverh300,iaudiox5,iaudiom5,iaudiom3,mpiohd200,mpiphd300}{
\nopt{ipodnano2g,ipod6g}{Due to resource constraints, files with large block sizes are not supported, and realtime playback may not be possible where downmixing is necessary.}}
\\
Apple Lossless Apple Lossless
& \fname{.m4a}, \fname{.mp4} & \fname{.m4a}, \fname{.mp4}
& \\ & \\