Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem]: Sample rate ignored #1925

Closed
2 tasks done
lucianoiam opened this issue Oct 27, 2024 · 6 comments
Closed
2 tasks done

[Problem]: Sample rate ignored #1925

lucianoiam opened this issue Oct 27, 2024 · 6 comments

Comments

@lucianoiam
Copy link

lucianoiam commented Oct 27, 2024

What happened?

  • Configure JACK and shairport-sync at 176400 Hz
  • Start JACK then shairport-sync
  • shairport-sync correctly reads JACK sample rate right but gets confused about its own sample rate setting
  • Reproducible with 88200 Hz
  • Everything works as expected for 44100 Hz, or when omitting rate and output_rate from conf.

Note for the Sound Server checkbox below: system has also PulseAudio installed but it outputs to JACK.

Relevant log output

$ shairport-sync 
fatal error: The JACK server is running at the wrong sample rate (176400) for Shairport Sync. Must be 44100 Hz.

System Information.

Linux raspberrypi 6.1.77-v8-16k+ #1730 SMP PREEMPT Thu Feb  8 15:30:42 GMT 2024 aarch64 GNU/Linux

Model		: Raspberry Pi 5 Model B Rev 1.0
Revision	: d04170

card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0 [HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0]

Configuration Information.

>> Display Config Start.

From "uname -a":
 Linux raspberrypi 6.1.77-v8-16k+ #1730 SMP PREEMPT Thu Feb  8 15:30:42 GMT 2024 aarch64 GNU/Linux

From /etc/os-release:
 Debian GNU/Linux 12 (bookworm)

From /sys/firmware/devicetree/base/model:
 Raspberry Pi 5 Model B Rev 1.0

Shairport Sync Version String:
 4.3.4-AirPlay2-smi10-alac-OpenSSL-Avahi-ALSA-jack-soxr-sysconfdir:/etc

Command Line:
 shairport-sync --displayConfig

Configuration File:
 /etc/shairport-sync.conf

Configuration File Settings:
 general : 
 {
   name = " (hidden) ";
   output_backend = "jack";
   output_rate = "176400";
   rate = "176400";
   audio_backend_buffer_desired_length_in_seconds = 0.05;
   resync_threshold_in_seconds = 0.01;
   volume_control_profile = "dasl_tapered";
   ignore_volume_control = "yes";
 };
 pw : 
 {
 };

>> Display Config End.
>> Goodbye!

PulseAudio or PipeWire installed?

  • Check if your system uses a Sound Server.

How did you install Shairport Sync?

Built from source

Check previous issues

  • Confirm
@mikebrady
Copy link
Owner

Thanks for the report.

Just looking at the configuration, please note that there are no output_rate or rate settings in the general section of the configuration file. That means that those settings have no effect.

If you have done a full install, a file /etc/shairport-sync.conf.sample is installed and you can get some hints there.

@lucianoiam
Copy link
Author

lucianoiam commented Oct 27, 2024

Thanks, that's right.

Looking at the source code, It seems the JACK backend is hardcoded to expect 44100 Hz

if (sample_rate != 44100) {

If that is correct, what changes are needed to make the sample rate configurable for JACK? particularly, I don't understand the rationale behind this comment (why hardcoded 44k1):

static void jack_start(int i_sample_rate, __attribute__((unused)) int i_sample_format) {
  // Nothing to do, JACK client has already been set up at jack_init().
  // Also, we have no say over the sample rate or sample format of JACK,
  // We convert the 16bit samples to float, and die if the sample rate is != 44k1 without soxr.
...

@mikebrady
Copy link
Owner

Thanks. It is the AirPlay audio that is fixed to 44100/S16/2.

The sample_rate is in fact configured by the jackd server.

@lucianoiam
Copy link
Author

The sample_rate is in fact configured by the jackd server.

Correct

Thanks. It is the AirPlay audio that is fixed to 44100/S16/2.

Now I understand, I made the assumption that AirPlay is capable of handling hi-res audio when it is not the case. Bummer.

So in practice there is no benefit in trying to increase the system sample rate.

However if for some reason JACK is running > 44100 Hz, for example a Pi handling multiple audio sources all connected to JACK. That would be an unsupported configuration? there seems to be some code related to SOX for resampling in audio_jack.c, but the 44100 check always takes place no matter SOX is enabled or not.

@mikebrady
Copy link
Owner

Indeed — there is no advantage to increasing the sample rate.
The SOX code is there to convert from AirPlay’s 44100/S16/2 to the format being used by the jackd server, e.g. 48000.

@lucianoiam
Copy link
Author

Perfect, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants