24-bit music streaming on 16-bit devices

General discussions.

Moderator: moderators

24-bit music streaming on 16-bit devices

Postby esh » Tue Oct 31, 2017 8:18 pm

What is the best solution for losslessly streaming from a library with both 24 and 16 bit music to devices limited to 16-bit and 44.1kHz, such as older Android devices?
Is it possible to get ffmpeg to only dither and/or resample (using SoXr) when necessary, or just pass the raw FLAC file through otherwise?

Until now, I have kept both the original and a redbook (16/44.1) transcode around for all my hi-def music, but since I started doing needle drops, and with more and more 24-bit music becoming available for purchase, this is getting out of hand.
I was thinking about writing a script to analyze the media file and pass it through SoXr if bits > 16 or kHz > 44.1 or else just output the raw file to stdout, but that would be a lot of work if ffmpeg can do the same.
esh
 
Posts: 2
Joined: Tue Oct 31, 2017 7:41 pm

Re: 24-bit music streaming on 16-bit devices

Postby jeffgt14 » Fri Nov 03, 2017 2:09 pm

sox %s -b 16 -r 44100 -t flac -

This is what I use. If the file is already 16/44.1 then it won't actually do anything but pass it through. I'm sure you can use ffmpeg in some way too but I prefer SoX for dithering. SoX is a damn good program and it actually dithers on it's own when deemed necessary (going from 24bit to 16bit) so it makes everything easy in that you don't have to worry about running different commands whether the files are 16bit or 24bit. There is no reason you should ever add the dither option into your SoX command unless you actually want to dither when going from, for example, 24/96 to 24/48 or 16/48 to 16/44.1 which would just be silly.

Per http://sox.sourceforge.net/sox.html :
In most cases, SoX can determine whether the selected processing requires dither and will add it during output formatting if appropriate.
Specifically, by default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true:
• bit-depth reduction has been specified explicitly using a command-line option
• the output file format supports only bit-depths lower than that of the input file format
• an effect has increased effective bit-depth within the internal processing chain

Essentially as long as you don't call anything out, SoX will do the correct processing. You would have to use the "−D, −−no−dither" flag if you want to prevent SoX from dithering when going from 24 to 16 bits.
jeffgt14
 
Posts: 34
Joined: Tue Nov 18, 2014 9:35 pm

Re: 24-bit music streaming on 16-bit devices

Postby esh » Thu Nov 16, 2017 10:51 pm

Thanks a lot, it works great! I never thought about using SoX directly. I was hoping to avoid ffmpeg in order to keep things simple, so this is brilliant.

Time to free up some disk space by deleting redbook conversions. :)
esh
 
Posts: 2
Joined: Tue Oct 31, 2017 7:41 pm

Re: 24-bit music streaming on 16-bit devices

Postby tom65 » Fri Mar 09, 2018 7:58 pm

I am using Subsonic with Sonos and like it very much. The only bummer is the 24/16 bit issue. The Sox solution does work and i tweaked it into a perl script which checks to see if the source should be transcoded.

The downside of this is that I can no longer seek (fast forward, rewind, etc) within the file since it is now being "transcoded" on the fly. This is true on 16bit/44.1khz files as well since the script is always sitting in the middle. Is there a way to get Subsonic to selectively run the script only on 24 bit and/or sample rates > 48khz?

Here's the script:

Code: Select all
#!/usr/bin/perl
use Audio::FLAC::Header;
use strict;

my $file = $ARGV[0];
my $flac = Audio::FLAC::Header->new($ARGV[0]);
my $info = $flac->info();

my $sample=$info->{"SAMPLERATE"};
my $bits = $info->{"BITSPERSAMPLE"};

if ($bits > 16 || $sample > 48000) {
        system("sox",$file,"-b","16","-r","48000","-t","flac","-");
} else {
        system("cat",$file);
}
tom65
 
Posts: 3
Joined: Fri Aug 04, 2017 9:47 pm


Return to General

Who is online

Users browsing this forum: No registered users and 9 guests