Skip to content

Add support for outputting SPDIF compatible bitstream #14

@humppe

Description

@humppe

Add support for SND_SOC_DAIFMT_LEFT_J and create a codec for outputting 32bit samples into it.

The magic (half_frame=40) will break the SPDIF compatible output, but apparently bit rates used by SPDIF do not fit into the 8000Hz divisibility rule.

I'm still undecided on the PCM format that the SPDIF should use. IEC958 has a PCM format, but that contains non-BMC coded data. Perhaps SNDRV_PCM_FMTBIT_SPECIAL is a safe bet in order to not accidentally mix that with normal audio. Though, I made the test by using SNDRV_PCM_FMTBIT_S32, 96kHz stereo.

Here is an example hack I did on top of tda1541a drivers which seem to output usable signal, at least looks like that on oscilloscope. (still need to verify with real data and real AV receiver)

diff --git a/sound/soc/bcm2708/bcm2708-i2s.c b/sound/soc/bcm2708/bcm2708-i2s.c
index ba41ef4..63562f5 100644
--- a/sound/soc/bcm2708/bcm2708-i2s.c
+++ b/sound/soc/bcm2708/bcm2708-i2s.c
@@ -530,6 +530,9 @@ static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
        case SND_SOC_DAIFMT_I2S:
                data_delay = 1;
                break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               data_delay = 0;
+               break;
        default:
                /* TODO
                 * Others are possible but are not implemented at the moment.
diff --git a/sound/soc/bcm2708/rpi-tda1541a.c b/sound/soc/bcm2708/rpi-tda1541a.c
index 06f993d..2367f41 100644
--- a/sound/soc/bcm2708/rpi-tda1541a.c
+++ b/sound/soc/bcm2708/rpi-tda1541a.c
@@ -37,12 +37,12 @@ static struct snd_soc_ops snd_rpi_tda1541a_ops = {
 static struct snd_soc_dai_link snd_rpi_tda1541a_dai[] = {
 {
        .name           = "TDA1541A",
-       .stream_name    = "TDA1541A HiFi",
+       .stream_name    = "TDA1541A SPDIF HiFi",
        .cpu_dai_name   = "bcm2708-i2s.0",
        .codec_dai_name = "tda1541a-hifi",
        .platform_name  = "bcm2708-pcm-audio.0",
        .codec_name     = "tda1541a-codec",
-       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+       .dai_fmt        = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF |
                                SND_SOC_DAIFMT_CBS_CFS,
        .ops            = &snd_rpi_tda1541a_ops,
        .init           = snd_rpi_tda1541a_init,
diff --git a/sound/soc/codecs/tda1541a.c b/sound/soc/codecs/tda1541a.c
index b848624..23ff4c9 100644
--- a/sound/soc/codecs/tda1541a.c
+++ b/sound/soc/codecs/tda1541a.c
@@ -20,8 +20,8 @@ static struct snd_soc_dai_driver tda1541a_dai = {
        .playback = {
                .channels_min = 2,
                .channels_max = 2,
-               .rates = SNDRV_PCM_RATE_8000_96000,
-               .formats = SNDRV_PCM_FMTBIT_S16_LE,
+                .rates = SNDRV_PCM_RATE_8000_192000,
+                .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_SPECIAL
        },
 };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions