Skip to content

Enable 352k8 and 384k sample rates for I2S connected boards/HATs that support those rates #1460

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

Closed

Conversation

clivem
Copy link

@clivem clivem commented May 7, 2016

This is another RFC, please do not pull!

I have tested original HiFiBerry DAC (PCM5102) on a PiB and HiFiBerry DAC+ (PCM5122 slave) on a Pi2B @ 352k8 and 384k.
I have tested first gen IQAudio DAC on a PiB, IQAudio DAC+ on a Pi3B, IQAudio Zero DAC on a PIZero @ 352k8/384k.

What I cannot test right now is HB DAC+ Pro (BCLK master / LRCK master) audio playback at 352k8 and 384k. (I lent my DAC+Pro to someone who doesn't appear to comprehend there is a difference between "loan" and "gift"!) @bonezuk @hifiberry don't know if you need to modify your driver for master mode (MCLK divider for BCLK?????), but it might be worth your while testing now rather than later. As I already said, your slave mode, works "out of the box" with this patch set.

Their is still chatter going on in DIY circles about over/upsampling (externally) to 8x on the TI PCM5 series, to bypass the TI OSF. (Can't switch it off, but by up/oversampling to 8x data rates in software and sending to the DAC, internal OS filter is bypass or 1x mode.) Me thinks that if 384k support isn't added via downstream first, at some point it will trickle down from upstream.......

@clivem
Copy link
Author

clivem commented May 7, 2016

I'll re-post the image (I generated when testing upstream i2s/dma backport code) showing the clock frequencies generated from PLLD parent, for 352k8@32/64 bit frame size and 384k@32/64 bit frame size.

pi_i2s_backport_clk

Anyway, as I already said, PCM5xxx slave is fine. It's the HB DAC+Pro board that needs testing in master mode @352k8/384k.

@hifiberry
Copy link

@clivem Send me a message with your email that we can send you a new DAC+ Pro. We test this. In general it should be possible to get this running even if I'm not sure why anybody would really need 384kHz sampling rate. But that's another question.

@clivem
Copy link
Author

clivem commented May 8, 2016

Send me a message with your email that we can send you a new DAC+ Pro.

Will do.

In general it should be possible to get this running even if I'm not sure why anybody would really need 384kHz sampling rate.

@hifiberry Well, for the majority of your customers it is not necessary. We both know that! ;)
But wanting to oversample in software and bypass the TI hardware FIR is a good enough reason as far as I am concerned, not that I'm buying into any of the usual high-res BS.

@HiassofT
Copy link
Contributor

ALSA already supports arbitrary samplerates via SNDRV_PCM_RATE_KNOT. No need to add SNDRV_PCM_RATE_384000 etc to the core ALSA headers, these are just shortcuts for frequently used rates.

@clivem
Copy link
Author

clivem commented May 10, 2016

ALSA already supports arbitrary samplerates via SNDRV_PCM_RATE_KNOT.

Yes, I'm aware of that. The problem with using KNOT is the "arbitrary", rather than actual "predefined" rates the hardware can support. ;)

@HiassofT
Copy link
Contributor

Non-constrained rates would be SNDRV_PCM_RATE_CONTINUOUS - I think we could use that in bcm2835-i2s (would need testing though).

When using KNOT you call snd_pcm_hw_constraint_list in .startup and pass it an array of available rates. ALSA intersects all the parameters&constraints of DAIs and CODECs and only allows configurations allowed by the whole chain.

So if you have CONTINUOUS (or a constraint including 384000) in I2S and a constraint including 384000 in the codec you'll be able to use 384kHz.

@clivem
Copy link
Author

clivem commented May 10, 2016

When using KNOT you call snd_pcm_hw_constraint_list in .startup and pass it an array of available rates. ALSA intersects all the parameters&constraints of DAIs and CODECs and only allows configurations allowed by the whole chain.

Yes, I know how it works. But that means adding methods and more lines of code, (to drivers that don't already use constraints), than adding a couple of defines to ALSA headers and changing SNDRV_PCM_RATE_8000_192000 to SNDRV_PCM_RATE_8000_384000. Not saying that it can't be done the way you suggest, it's the way I was doing it for over a year.....

@HiassofT
Copy link
Contributor

If you want SNDRV_PCM_RATE_384000 included it's best to post on the alsa-devel list and convince the ALSA people to add it.

There was a request for that a few months ago but it wasn't accepted, looks like the submitter didn't present convincing arguments:
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-January/103497.html

Having such patches only in the downstream RPi kernel doesn't make much sense and only complicates things when there are upstream changes.

@clivem
Copy link
Author

clivem commented May 11, 2016

LOL.....

So without needing to convince upstream ALSA, something like this for bcm2835-i2s and the codecs actually nailing down specific supported rates by constraint rather than ALSA define.

@@ -626,7 +626,9 @@
.playback = {
.channels_min = 2,
.channels_max = 2,

  •           .rates =        SNDRV_PCM_RATE_8000_192000,
    
  •           .rates =        SNDRV_PCM_RATE_CONTINUOUS,
    
  •           .rate_min =     8000,
    
  •           .rate_max =     384000,
              .formats =      SNDRV_PCM_FMTBIT_S16_LE
                              | SNDRV_PCM_FMTBIT_S24_LE
                              | SNDRV_PCM_FMTBIT_S32_LE
    

@clivem clivem force-pushed the rpi-4.4.y-384k branch 7 times, most recently from b381cb8 to 11a12b3 Compare May 12, 2016 12:53
@clivem clivem changed the title ALSA 384k support Enable 352k8 and 384k sample rates for I2S connected boards/HATs that support those rates May 12, 2016
@clivem
Copy link
Author

clivem commented May 12, 2016

NB: The "Add rate defines for 352k8 and 384k" is not required by the other patches. (All driver code has been changed to use CONTINUOUS/KNOT and constrants lists for 352k8/384k and tested to be working as expected.) It's just been added back as a "placeholder" so I don't forget to submit it to ALSA mailing list.

@clivem clivem force-pushed the rpi-4.4.y-384k branch 3 times, most recently from 74a0de7 to 8c5db3a Compare May 13, 2016 07:41
@clivem clivem force-pushed the rpi-4.4.y-384k branch 9 times, most recently from 2c8679b to de231e5 Compare May 30, 2016 08:27
@clivem
Copy link
Author

clivem commented Jun 17, 2016

@pelwell OK, I'll submit patches 1 (384k: bcm2835-i2s: Support 384k sample rate), 2 (384k: pcm512x: Add 352k8 sample rate support), and 3 (384k: pcm5102a: Support 352k8 and 384k sample rates) upstream. Patch 4 (384k: pcm5102a: Add dt mechanism to limit rate support, which has been split from the original patch 3, to limit pcm5102a sample rate support back to 192k for hifiberry_dac support of es9023 and have to specify 384k dt param to enable 384k MAX support), is going to have to be a downstream patch, I think. I don't have a hope in hell of selling that to upstream, by explaining it's needed by a downstream machine driver, which is using the pcm5102a codec driver for es9023 hardware..... ;) Patch 5, (384k: hifiberry_dacplus: Support 352k8 sample rate), to hifiberry_dacplus machine driver, that's for downstream.

@clivem
Copy link
Author

clivem commented Jun 17, 2016

@pelwell Patches in the right order now. Do you agree with what I proposed?

@clivem
Copy link
Author

clivem commented Jun 19, 2016

@pelwell I just fired-off those first 3 patches to the relevant mailing lists.

@clivem
Copy link
Author

clivem commented Jun 25, 2016

I have neither the time or the will, to play the upstream game. I have tried. I will continue maintaining the patch sets outside of the RPi kernel tree. It is a shame that only a limited number of people will benefit from functionality that is possible with many of the 3rd party hardware DAC boards that are being made available for the Pi, because it is not made available by the "official" RPi kernel sources.

Add support for sample rates up to 384k to bcm2835-i2s driver,
with SNDRV_PCM_RATE_CONTINUOUS and specifying 8k min and 384k max,
for both playback and capture.

Signed-off-by: DigitalDreamtime <[email protected]>
Add 352k8 sample rate to the slave constraint list.

Signed-off-by: DigitalDreamtime <[email protected]>
Add support for 352k8 and 384k samples rates to pcm5102a codec
driver, with SNDRV_PCM_RATE_KNOT and a constraint list.

Signed-off-by: DigitalDreamtime <[email protected]>
Provide dt param mechanism to limit sample rate support to 192k MAX.

hifiberry-dac overlay is used by both their 1st gen 'B' PCM5102 boards
and the later gen DAC+ Light ES9023. (As well as being used by several
other third party ES9023 boards.)

The PCM5102a is most certainly 352k8/384k capable.
The ES9023 datasheet states 192k PCM MAX, but we know that most chips
are 384k capable. (ES9023 OSC is the other factor. Datasheet requirement
is >= 192xFS. Most ES9023 DAC HAT manufacturers use 50MHz OSC.)
So we default to supporting 8k-192k MAX, unless dt param, '384k', is
specified, in which case, the 8k-384k constraint is used.

NB: ES9023 patch series provides migration path for HB DAC+ Light users

"dtoverlay=hifiberry-dac", continues to work as before for 'B' DAC and
DAC+ Light users with 192k max sample rate default.

'B' DAC users should add dt param '384k' for 384k support. ie.
"dtoverlay=hifiberry-dac,384k"

Ideally, DAC+ Light users should be encouraged to migrate to es9023
overlay variant, "dtoverlay=hifiberry-dacpluslight-es9023-audio".

At some point in the future the pcm5102a codec should have the
artificial 192k max default removed and default to 384k max.

Signed-off-by: DigitalDreamtime <[email protected]>
Use CLK44EN for 352k8 sample rate support.

Set (initial) the clk rate to CLK_48EN_RATE in the init method.
Set (reset) the clk rate to CLK_48EN_RATE in the shutdown method.
(Otherwise codec pcm512x_dai_startup_master method can call
 snd_pcm_hw_constraint_ratnums based on CLK_44EN, which will
 result in loss of 384k sample rate, even though we are
 capable of it with CLK_48EN, because 22579200/64=352800.)

Signed-off-by: DigitalDreamtime <[email protected]>
Add support for 384k max sample rate to dionaudio-loco overlay.

Signed-off-by: DigitalDreamtime <[email protected]>
@shawaj
Copy link

shawaj commented Sep 11, 2016

@clivem where are your patch sets located? Do you have a branch specifically for them?

@clivem
Copy link
Author

clivem commented Sep 11, 2016

The 384k on its own, https://github.com/DigitalDreamtimeLtd/linux/commits/rpi-4.4.y-384k

The audio distributions and a'phool forum guys building their own kernels are running what is referred to as the complete simple audio patchset.... which includes the clockmgr/i2s backport to rpi-4.4.y, es9023, 384k, regulator, simple-framework (for the 40/80 and 50/100 bclk_ratio via simple card).... https://github.com/DigitalDreamtimeLtd/linux/commits/rpi-4.4.y-simple

@clivem
Copy link
Author

clivem commented Sep 11, 2016

@shawaj There is also a private tree, which I cannot make public, which on top of "simple" contains the "other" audio stuff.... The driver I'm not allowed to release as an Open Source driver, an AK4xxx driver, and also bundled into it, the Wolfson/Cirrus card support, which still isn't downstream. I don't think you'd have any interest or need for this anyway, if you are using TI PCM5xxx for the DAC's and WM8804 for Digi....

@kittybuttontin
Copy link

I have a HiFiBerry DAC+Pro but I can't get 384k to work in master mode (I only get 352k). I do get 384k in slave mode.

I was under the impression from some of the posts above that it should work in master mode?

@clivem
Copy link
Author

clivem commented Sep 29, 2016

HiFiBerry DAC+ Pro works @ 352k8 and 384k, in both master and slave modes with this patchset applied.

@kittybuttontin
Copy link

Thanks. I am using this patchset, but for some reason 384k is not working in master mode:

cat /proc/asound/card0/pcm0p/sub0/hw_params

access: RW_INTERLEAVED
format: S32_LE
subformat: STD
channels: 2
rate: 352800 (352800/1)
period_size: 2048
buffer_size: 65536

@clivem
Copy link
Author

clivem commented Sep 29, 2016

All that shows me is that your audio playback software is actually opening the device at 352k8. Show me the error from your playback software when it tries to open the device at 384k, please? Show me the output from alsacap where it will display the min and max supported sample rates. eg.

$ alsacap
Card 1, ID `sndrpihifiberry', name `snd_rpi_hifiberry_dacplus'
  Device 0, ID `HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0', name `', 1 subdevices (1 available)
    2 channels, sampling rate 8000..384000 Hz
    Sample formats: S16_LE, S24_LE, S32_LE
      Subdevice 0, name `subdevice #0'

This log shows the device initially opened at 44k1, then closed and re-opened at 384k.
384k.txt

@clivem
Copy link
Author

clivem commented Sep 29, 2016

Also, for the benefit of anyone else trying to enable 384k support on the TI chipset boards, make sure you are using the latest version of the 384k patch set from rpi-4.4.y-384k which I try to keep current with Foundation rpi-4.4.y.

@kittybuttontin
Copy link

Master mode output of alsacap:

Card 0, ID sndrpihifiberry', namesnd_rpi_hifiberry_dacplus'
Device 0, ID HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0', name', 1 subdevices (1 available)
2 channels, sampling rate 8000..352800 Hz
Sample formats: S16_LE, S24_LE, S32_LE
Subdevice 0, name `subdevice #0'

Master mode output of mpd:

Sep 29 16:21 : decoder_thread: probing plugin flac
Sep 29 16:21 : decoder: audio_format=192000:24:2, seekable=true
Sep 29 16:21 : decoder: converting to 384000:32:2
Sep 29 16:21 : alsa_output: opened hw:0,0 type=HW
Sep 29 16:21 : alsa_output: format=S32_LE (Signed 32 bit Little Endian)
Sep 29 16:21 : alsa_output: buffer: size=64..65536 time=181..185760
Sep 29 16:21 : alsa_output: period: size=32..32768 time=90..92880
Sep 29 16:21 : alsa_output: buffer_size=65536 period_size=2048
Sep 29 16:21 : output: opened plugin=alsa name="Software Volume" audio_format=352800:32:2
Sep 29 16:21 : output: converting from 384000:32:2

Slave mode output of alsacap:

Card 0, ID sndrpihifiberry', namesnd_rpi_hifiberry_dacplus'
Device 0, ID HiFiBerry DAC+ HiFi pcm512x-hifi-0', name', 1 subdevices (1 available)
2 channels, sampling rate 8000..384000 Hz
Sample formats: S16_LE, S24_LE, S32_LE
Subdevice 0, name `subdevice #0'

@clivem
Copy link
Author

clivem commented Sep 29, 2016

I'd suggest you read the commit log for DigitalDreamtimeLtd@3f7f2bb and make sure you have actually applied it along with other patches. ;)

You need to apply all 6 patches (the last 6 patches) from the rpi-4.4.y-384k tree to your build.

@jayt0808
Copy link

the links are not working... can you direct me to the new location of where these patches for 384Khz are residing?

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

Successfully merging this pull request may close these issues.

8 participants