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
(number of samples in a frame) to 4608. This is the default value
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
@ -39,7 +41,7 @@ called "test.wav" in the current directory. This has been tested with
This can be used to test the accuracy of the decoder by comparing the
md5sum of the WAV file produced by this decoder with a WAV file
produced by the official libFLAC decoder.
produced by the official libFLAC decoder.
This test program could be extended to perform an internal md5sum
calculation and comparing that against the md5sum stored in the FLAC

View file

@ -19,22 +19,13 @@
#endif
#if (CONFIG_CPU == MCF5250) || (CONFIG_CPU == PP5022) || \
(CONFIG_CPU == PP5024) || (CONFIG_CPU == S5L8702)
(CONFIG_CPU == PP5024)
#define ICODE_ATTR_FLAC ICODE_ATTR
#define IBSS_ATTR_FLAC IBSS_ATTR
/* Enough IRAM to move additional data to it. */
#define IBSS_ATTR_FLAC_LARGE_IRAM IBSS_ATTR
#define IBSS_ATTR_FLAC_XLARGE_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
#define ICODE_ATTR_FLAC ICODE_ATTR
#define IBSS_ATTR_FLAC IBSS_ATTR
@ -44,6 +35,12 @@
#define IBSS_ATTR_FLAC_XXLARGE_IRAM
#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 */
#ifdef BUILD_STANDALONE
#ifdef BUILD_BIGENDIAN

View file

@ -4,7 +4,9 @@
#include "bitstream.h"
#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 */
#endif
#define MAX_FRAMESIZE 65536 /* Maxsize in bytes of one compressed frame */
#define MIN_FRAME_SIZE 11 /* smallest valid FLAC frame possible */