postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
876 stars 95 forks source link

Respect audio properties provided by receiver and transcode input audio to match #1067

Closed postlund closed 3 years ago

postlund commented 3 years ago

Short feature/function description I realize that I currently don't deal with audio properties, e.g. sample rate, channel count, correctly. I basically try to output in the same format as the input file, which won't work as the receiver tells us what it supports and we need to match that. It is done via zeroconf properties and I believe the following are of interest:

Property Type Typical value Description
ch int 2 Number of channels, e.g. 2 is stero
cn int 0,1,2 Audio codecs supported: 0=PCM, 1=ALAC, 2=AAC, 3=AAC ELD
sr int 44100 Sample rate
ss int 16 Sample size in bits

Currently, only ALAC output is supported (not sure how to format PCM and what to send in ANNOUNCE for it). So maybe give an error if it is not supported by receiver. Would be surprised if not all receivers supports it.

All properties are already present in the service config, so should be pretty easy to do.

What needs to be done?

Is this a breaking change? No

Anything else worth knowing? Relates to #1059

postlund commented 3 years ago

Interesting observation is that the python miniaudio library automatically decodes any input to 44100/2/16 when loading a file, so that make things kinda just work. What I need to do is to store values from zeroconf and use them as input to decode_file (i.e. make sure input file is decoded to the format the receiver expects). Later versions of AirPlay (2?) doesn't seem to include these properties in Zeroconf at all. So I assume it's safe to default to 44100/2/16 in these cases. Looks like owntone is doing that.