Now the new release is out. The macOS DMG includes a hqp5-set-input-rate.sh script that one can place for example in home folder or somewhere else. And then add it to the LosslessSwitcher. Also remember to install hqp5-control in your Applications folder.
Thx so much @Vincent_Neo & @jussi_laako for making this adaptive sample rate switching possible on MacOS! I just tried it and it works. There is some minor garbled audio when the sample rate switches, but I suppose this is unavoidable.
@jussi_laako I suppose the content source URI, āaudio:default/44100/2ā, is gratuitous at this point at it picks up the sample rate from LosslessSwitcher.
I wonder if there is a way to short and tiny mute somewhere to avoid this
Depends which order you start things. LosslessSwitcher will call the rate handler at some point. and at that point HQPlayer needs to be listening. I usually start HQPlayer playback first and then later Apple Music. To start playback in HQPlayer, you need to have some rate.
hi Jussi,
any luck tracking down the cause of the following errors reported by f_taudio2 kernel module? i recently tried HQPlayer Embeded 5.3.0 (x64)+ NAA 4.5.0 (rPi 4), and syslog is flooded with the following error, and UAC2 input fails when sample rate changes
kernel: f_taudio2: ua2f_iso_complete_playback: request failed with -61
kernel: f_taudio2: ua2f_iso_complete_playback: request failed with -61
kernel: f_taudio2: ua2f_iso_complete_playback: request failed with -61
using UAC2Gadget as input, i cantā get NAA daemon (running on rPI 4 / RaspiOS Bookworkm) to react to the input-rate change, even so i can see with amix that capture rate changed; my hqplayer / networkaudiod config entries below:
- hqplayer (i also tried with samplerate 0, and didnāt work):
<input address="HQPnaa-UAC2" ipv6="1" name="USB Audio IN (NAA)" device="hw:CARD=UAC2Gadget,DEV=0" format="pcm" channels="2" channel_offset="0" samplerate="44100" pack_sdm="0" period_time="100" type="network"/>
- networkaudiod:
<input name="USB Audio IN (NAA)" device="hw:CARD=UAC2Gadget,DEV=0" format="pcm" channels="2" channel_offset="0" samplerate="0" pack_sdm="0" period_time="100" rate_element="Capture Rate"/>
when you have time, can you please take a look at the following post by mevang (the author of camilladsp_setrate tool) and see if could explain why networkaudiod doesnāt receive / react to sample rate change events:
Thanks.
edit: link to camilladsp-setrate project - GitHub - marcoevang/camilladsp-setrate: Automatic sample rate switcher for CamillaDSP
This support has been discontinued and is being removed from everywhere.
You can configure HQPlayer / NAA to work like that using the stock Linux kernel module. But what you are referring to above is something totally different. You need to modify the networkaudiod input-element to use the stock USB Audio Gadget device instead.
Already tried on Raspberry Pi OS bookworm (with kernel 6.1) as input NAA & HQPlayer Emebeded image running on a mini-PC (input config entries from both in my previous post).
I configured UAC2Gadget with support for 44.1, 48, 88.2, 96, 176.4, 192 kHz capture rates & 32 bits per sample, added rate_element=āCapture Rateā to my NAAās input config entry but networkaudiod doesnāt react to any sample rate change. Am i wrong to assume that i should use ārate_elementā config directive; should i use sync_element / sync_hctl instead?
Running āhqp5-control -set-transport-rate ā on the NAA, didnāt help either.
ALSA control device status:
- nothing playing:
budha@HQPnaa-UAC2:~ $ amixer -c UAC2Gadget cget "iface=PCM,name='Capture Rate'"
numid=4,iface=PCM,name='Capture Rate'
; type=INTEGER,access=r--v----,values=1,min=44100,max=192000,step=0
: values=0
budha@HQPnaa-UAC2:~ $
- FLAC 44.1 kHz 24 bit playing (in VOX.app on iPhone 8):
budha@HQPnaa-UAC2:~ $ amixer -c UAC2Gadget cget "iface=PCM,name='Capture Rate'"
numid=4,iface=PCM,name='Capture Rate'
; type=INTEGER,access=r--v----,values=1,min=44100,max=192000,step=0
: values=44100
budha@HQPnaa-UAC2:~ $
- FLAC 192 kHz 24 bit playing
budha@HQPnaa-UAC2:~ $ amixer -c UAC2Gadget cget "iface=PCM,name='Capture Rate'"
numid=4,iface=PCM,name='Capture Rate'
; type=INTEGER,access=r--v----,values=1,min=44100,max=192000,step=0
: values=192000
budha@HQPnaa-UAC2:~ $
ārate_elementā is element that lists possible active rates as enumeration and itās set value will define sampling rate of the hardware. So it is mixer element that need to be changed to change sampling rate of the hardware. It is used for example with RME HDSPe series.
āsync_elementā is the element that indicates currently active rate as value (not through enumeration). And sync_hctl can be ā1ā when the sync_element is ALSA hctl or ā0ā when it is not ALSA hctl item.
So in this case you would use sync_element=āCapture Rateā sync_hctl=ā1ā
Also define samplerate=ā0ā
Here is example for RME ADI-2 Pro from sample hqplayerd.xml:
<input channel_offset="2" channels="2" device="hw:CARD=Pro,DEV=0" format="auto" name="ADI-2 Pro (AES)" pack_sdm="1" period_time="100" samplerate="0" sync_element="AES Rate" sync_hctl="1"/>
Above allows both PCM, and DSD as well over DoP.
thanks for the detailed explanation of the 2 config parameters
testing was hit & miss, but mostly miss ā¦
- samplerate=0 in both hqplayerd.xml & networkaudiod.xml - no sound, but sample rate reported by amixer was correct
- samplerate=44100 in networkaudiod.xml & 0 in hqplayerd.xml - same as above
- samplerate=0 in networkaudiod.xml & 44100 in hqplayerd.xml - 44.1 kHz playing fine, 48 kHz a little off but could still recongnize the melody, anything else playing really slooowww (like wrong turntable speed); amixer reports the correct sample rate; networkaudiod & hqplayerd thought that input sample rate was 44100 all the time
- samplerate=44100 in both networkaudiod.xml & hqplayerd.xml - same as above
note: switching between last 2 scenarios without restarting input NAA or disconnecting iPhone (and/or stopping music player) confused ALSA because amixer reported 96 k for 88.2 & 96 k songs, but correct sample rate for all the other rates in 44100 - 192000 range
if the last played song had a sample rate other than 44100 (in my test scenarios), hqplayer failed to select UAC2 Input with the following error
2023/12/14 22:09:19 Audio transport: rate=44100 channels=2 format=auto buffer=100 (normal)
# 2023/12/14 22:09:19 clReadAudio::Open(): clAudioEngine::SetSampleRate(): requested rate not available
& 2023/12/14 22:09:19 Play
# 2023/12/14 22:09:19 clPlayerDaemon::SwitchInput(): clHQPlayerEngine::Play(): Transport == NULL
after i configure UAC2 Gadget and my phone is not connected or music player app is not running, āarecord --dump-hw-paramsā reports a sample rate of 44100; as soon as i start my music app, the sample rate of the last played song is reported, which explains above failure; if no song is playing, amixer always reports 0
This is the one that should be used. Works at least with ADI-2 Pro.
In such case, HQPlayer will fail to start playback. This is incorrect as the USB Audio Class will have some rate defined always as long as a device is connected.
In this case, HQPlayer should start playing fine at 44100 from the source if you defined samplerate=ā0ā. Assuming the gadget driver correctly provides silence at that rate when there is no actual audio being played.
I have not done much testing on the stock gadget driver for ages, because before the custom UAC2 driver the stock kernel gadget driver was so horribly broken in many ways that it was useless. For example if it worked at all depended on the USB host device OS (Windows, macOS or Linux). It was mostly working only with Linux sources.
i know many of us would be happier if you would invest your time researching if HQPlayer could leverage the compute power of the NPUs included in the newer Intel / AMD CPUs and improve the engine or implement new filters/modulators, but if you could allocate a little time to this topic as well it would be great; iād love to have cheaper options to feed (almost) any source into HQPlayer
BTW, any way to increase log verbosity (enable debug mode) for networkaudiod & hqplayerd apps?
NPUās are units for processing very low precision computations, like āhalf precisionā 16-bit floating point numbers, and doing computations with 8-bit and 4-bit values. Those are not useful for computations done by HQPlayer.
I will keep looking into these as well, the recent support for interoperation with LosslessSwitcher as an example.
Development of the kernelās UAC2 gadget is not very active. In 2023 it has got one small bug fix. In 2022 it got the variable rate support. But it is still rather immature implementation, regarding compatibility with other OS and it is also affected by the bugs in various USB device mode hardware drivers (such as dwc2, dwc3, etc). So Iām not super optimistic about it being really general purpose useful.
Some initial testing results, I have HQPlayer Embedded 5.3.0 running on UP Gateway, Ubuntu Server 22.04 LTS, running my custom 6.1 kernel. UAC2Gadget driver loaded and configured. And HQPlayer input set to this:
<input name="USB Audio" device="hw:CARD=UAC2Gadget,DEV=0" samplerate="0" channels="2" format="pcm" period_time="100" sync_element="Capture Rate" sync_hctl="1"/>
And it seems to be workingā¦
Now I have also automatic rate changes working with the current version of UAC2Gadget⦠I needed to make some changes to the audio input backend code, since this is yet another case handled slightly differently than the other onesā¦
Can you tell me the steps ⦠I tried few time ⦠but the auto switch of sampling rate does not work.
I need to change the sample rate manually.
I have installed the latest HQP and lossless swithcer
Thank
Did you also add the HQPlayer rate switch script to LosslessSwitcher? And you also installed hqp5-control to Applications folder?
Now the UAC2 input works also through NAA with automatic rate changes. This required more changes, on both NAA and HQPlayer sides.
Next releases of NAA and HQPlayer will bring in this functionality.
Thank you, I know the reason, I dragged the hqp5-control to one a new folder inside the Application. What I need is to drag it out ⦠now workingā¦
Now new Embedded and NAA releases are out with refreshed UAC2 support. With UP Gateway it works out of the box with HQPlayer OS. And with RPi4 it works out of the box after changing the dwc2 driver mode from host to peripheral in config.txt
HQPlayer Desktop will need an update to work with the new NAA release and this feature. I will release an update for Desktop shortly that will include this.
Just to make sure.
I do not have (see) the need to upgrade either Embedded or NAA, as it works fine and no need for extra functionality today.
However, if e.g. Embedded would be upgraded, do i need to upgrade NAA as well? Again, not using UAC2 .
Thanks for your advice.