Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Realtime S/PDIF decoding on Teensy 4.0

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    5

    Realtime S/PDIF decoding on Teensy 4.0

    Hello,

    I work in a neuroscience lab studying the auditory system, and we use TTL trigger pulses to sync our audio stimuli with the EEG system. The way I do this is through simultaneous analog and S/PDIF audio from the same soundcard, with analog going to headphones and S/PDIF int values being split by a custom box into separate TTL bit lines. My current device requires a custom PCB to be made and populated, but I'm hoping the Teensy 4.0's S/PDIF input could replace it.

    Basically, every time a new S/PDIF sample arrives, the device would write its bits (or a subset of them) out to the GPIO. It would need to do this in real time, but I am hopeful it could work since that is all the system needs to do. It would need to work with 44.1 or 48 kHz and 16 or 24 bit audio.

    Is this possible? Is there any example code that reads the latest sample, perhaps triggered by an interrupt? Or perhaps the S/PDIF samples go to a register I can poll? I have read up on the audio library, but I don't believe there is a way to use that in real time since it's designed to do more than just pass samples through.

    Any guidance appreciated!

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    Well, first it would be needed to define what "realtime" is.

  3. #3
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    It needs to do the operation on every incoming sample (so 44.1k or 48k times per second). So no frames like in normal applications. Latency, as long as it's consistent (jitter < .05 ms), is not a concern, since it can be measured and compensated.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    IMXRT1060 Reference Manual Rev2, Page 2028 shows that it can gegerate an interrupt depending on the fill-state of the FIFO.

    Of course there is no example code to do that, as the audio library is used, normally...


    https://www.pjrc.com/teensy/IMXRT1060RM_rev2.pdf

  5. #5
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    Thanks. From reading it seems like it should be possible. I've never programmed at this level before, but I'll have a go at it. Time to read up on interrupts.

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    That's the easy part. attachInterrupt()
    Then, you can take a look at the audio-library SPDIF input and look at the code. Remove all the DMA stuff, and it is almost done..

  7. #7
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    This is probably a dumb question--but how do I access the specific interrupts and registers that are named in the manual? Since I'm sure this has been described a million times a link is fine.

    From the manual it looks as if the relevant interrupt is called "QChannelRxFull," but that doesn't show up anywhere in the code, nor does the name of the register "QChannelReceive" or maybe "UChannelReceive."

    I'll keep digging. Thanks for the help so far.

  8. #8
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    Ahhh those names aren't exactly how things are accessed in the code. For example the SPDIFRxLeft Register is read from SPDIF_SRL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •