Progress. A simple hack to allow bitrates above 655350 seemed to work
fine for encoding, and the standard reference decoder library decoded
it fine. I'm not sure then in the documentation why it says "the
maximum sample rate is limited by the structure of frame headers to
655350Hz". Perhaps this breaks something elsewhere but the attached
simple patch is working perfectly fine for my use case here! Can
anyone see a reason this might break something elsewhere and couldn't
be incorporated?

Thanks,
Con


On Fri, 26 Jun 2020 at 08:33, Con Kolivas <ker...@kolivas.org> wrote:
>
> On Fri, 26 Jun 2020 at 00:37, Martijn van Beurden <mva...@gmail.com> wrote:
> >
> > Op do 25 jun. 2020 om 16:02 schreef Con Kolivas <ker...@kolivas.org>:
> >>
> >> The idea is to actually use it for playback, not just storage, and
> >> nothing else has the nice asymmetrical fast decompression with such
> >> effective compression (wavpack supports 705/768 but is woefully slow
> >> on decompression and poorly supported). Mostly the sample rates would
> >> be multiples of the common 44.1/48 sample rates so I expect
> >> compression to be equally good with simple extrapolation to bigger
> >> equivalent sized windows.
> >
> >
> > In what setting are you thinking about playback? If this is a lab setting, 
> > creating a small batch script to fetch the samplerate tag and passing it to 
> > a playback program like ffplay doesn't seem a very big deal? If you want 
> > playback on current existing, available hardware, augmenting the spec is 
> > not going to work.
>
> Definitely not a lab setting I'm afraid, I'm just experimenting at
> home with my regular hi-fi gear. I'm just using clementine and roon
> for playback and both load libFLAC so I guess I could create a custom
> flac library to support a bastardised flac container.
>
> Thanks,
> Con
diff --git a/include/FLAC/format.h b/include/FLAC/format.h
index 769ab8af..cf5c25aa 100644
--- a/include/FLAC/format.h
+++ b/include/FLAC/format.h
@@ -125,7 +125,7 @@ extern "C" {
  *  ((2 ^ 16) - 1) * 10; see <A HREF="../format.html">FLAC format</A>
  *  as to why.
  */
-#define FLAC__MAX_SAMPLE_RATE (655350u)
+#define FLAC__MAX_SAMPLE_RATE (1048575u)
 
 /** The maximum LPC order permitted by the format. */
 #define FLAC__MAX_LPC_ORDER (32u)
diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c
index 74387ec3..fb9c78ba 100644
--- a/src/libFLAC/stream_encoder.c
+++ b/src/libFLAC/stream_encoder.c
@@ -853,10 +853,10 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
 	encoder->private_->loose_mid_side_stereo_frames = (uint32_t)((double)encoder->protected_->sample_rate * 0.4 / (double)encoder->protected_->blocksize + 0.5);
 #else
 	/* 26214 is the approximate fixed-point equivalent to 0.4 (0.4 * 2^16) */
-	/* sample rate can be up to 655350 Hz, and thus use 20 bits, so we do the multiply&divide by hand */
-	FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
+	/* sample rate can be up to 1048575 Hz, and thus use 20 bits, so we do the multiply&divide by hand */
+	FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 1048575);
 	FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
-	FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
+	FLAC__ASSERT(encoder->protected_->sample_rate <= 1048575);
 	FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
 	encoder->private_->loose_mid_side_stereo_frames = (uint32_t)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
 #endif
diff --git a/src/libFLAC/stream_encoder_framing.c b/src/libFLAC/stream_encoder_framing.c
index 2c78916d..11ab72ed 100644
--- a/src/libFLAC/stream_encoder_framing.c
+++ b/src/libFLAC/stream_encoder_framing.c
@@ -276,7 +276,9 @@ FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWrit
 		case  48000: u = 10; break;
 		case  96000: u = 11; break;
 		default:
-			if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
+			if(header->sample_rate > 655350)
+				u = 0;
+			else if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
 				sample_rate_hint = u = 12;
 			else if(header->sample_rate % 10 == 0)
 				sample_rate_hint = u = 14;
_______________________________________________
flac-dev mailing list
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev

Reply via email to