geoffreybennett / scarlett-gen2

Linux kernel source tree with additional Focusrite Scarlett and Clarett support ("Scarlett2 USB Protocol Mixer Driver")
196 stars 6 forks source link

sample rate in clarett 8Pre USB defaults to 44.1kHz after restart #5

Closed alderking closed 9 months ago

alderking commented 10 months ago

If the device is switched off under a sample rate of 48kHz, it starts again with a sample rate of 44.1kHz. It can be set again to 48kHz, when e.g. Ardour (i haven't tested with a different programm) is started on that rate. The rate remains after Ardour is closed. Without Ardour, clocksource in gui shows status "locked" only when internal clocksource is chosen. On S/PDIF or ADAT it displays "unlocked", altough on these inputs lie valid signals. When Ardour ist started, S/PDIF also locks, but not ADAT.

geoffreybennett commented 10 months ago

With regards to the sample rate, I wrote this to someone recently who was asking about sample rate control in alsa-scarlett-gui:

The primary function of the Scarlett2 mixer driver (for which alsa-scarlett-gui is a front-end) is internal audio routing and mixing within the device, as well as managing settings on the device itself. It's important to note that the Scarlett2 driver doesn't handle the audio input/output to and from the device. Instead, this task is managed by the ALSA generic USB soundcard driver.

In Linux, the sample rate is chosen by the application that opens the soundcard using the ALSA API. That could be PulseAudio or JACK or PipeWire, or the end-user application if it's using the ALSA device directly (e.g. Ardour or Audacity).

Therefore, I'm trying to keep the sample rate setting outside the scope of this project. The best I could do would be to monitor /proc/asound/*/stream0 to see if some application has the soundcard open and read what sample rate it has requested. Otherwise this project would turn into a frontend for configuring PulseAudio/JACK/PipeWire/Ardour/Audacity.

If you haven't opened Ardour, how are you determining what sample rate the device is running at?

The only reason I can think of for S/PDIF to lock but not ADAT is if the device sample rate does not match the input ADAT sample rate. I did find an S/PDIF input source switch in Focusrite Control that can select between RCA and Optical inputs, but I implemented that in my driver to test and I could not make that cause ADAT to not lock, only S/PDIF. Can you reproduce this problem using the Focusrite Control software?

alderking commented 10 months ago

Hi @geoffreybennett ,

thanks for your quick reply. I didn't know that, so the application will be master, i expected the rate to be set by the connected devices.

I found (here, cardnr is 2) cat /proc/asound/card2/pcm0p/sub0/hw_params

which echoed access: MMAP_INTERLEAVED format: S32_LE subformat: STD channels: 20 rate: 48000 (48000/1) period_size: 64 buffer_size: 128 If that was the place to echo in the desired samplerate, i could write a udevrule for that. Is it possible to change the sample rate via this way?

To reproduce this behaviour, i don't have a windows machine right here. I will borough one during the next week and do a little research on this.

Thank you, i will drop a message here, when i know more.

regards alderking

geoffreybennett commented 10 months ago

Hi @alderking,

Rereading your message, thinking about this more, and doing a bit of experimenting, I have an explanation for what you're seeing.

hw_params will show "closed" when there is no app with the soundcard open, so check out what that app is. Try lsof /dev/snd/pcm*. I'm guessing PulseAudio? In my testing (on Mint), PulseAudio defaults to 44.1KHz. PipeWire (tested on Ubuntu) defaults to 48KHz.

If your S/PDIF and ADAT inputs are not running at 44.1KHz then the interface will never lock with those as the clock source until you select 48KHz like you are doing when you run Ardour.

As to why ADAT does not lock with a valid signal, I can only think that is because the ADAT is running at a different sample rate again, e.g. 96KHz.

My suggestion, if you're using PulseAudio: update its configuration to lock it to 48KHz. Check your ADAT input to make sure it's running at 48KHz.

Also, if you're using S/PDIF and ADAT inputs at the same time, and they are coming from different devices, then you need to clock one of them from the other. Otherwise you'll get clicking.

Regards, Geoffrey.