{"id":41697990,"url":"https://github.com/mill1000/raspdif","last_synced_at":"2026-01-24T20:53:03.560Z","repository":{"id":117385800,"uuid":"258868225","full_name":"mill1000/raspdif","owner":"mill1000","description":"Raspberry Pi S/PDIF digital audio without a HAT.","archived":false,"fork":false,"pushed_at":"2025-12-20T20:29:19.000Z","size":121,"stargazers_count":76,"open_issues_count":5,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-12-22T20:13:41.357Z","etag":null,"topics":["audio","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mill1000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-25T20:31:27.000Z","updated_at":"2025-12-20T20:29:20.000Z","dependencies_parsed_at":"2023-12-07T03:39:10.808Z","dependency_job_id":null,"html_url":"https://github.com/mill1000/raspdif","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mill1000/raspdif","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mill1000%2Fraspdif","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mill1000%2Fraspdif/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mill1000%2Fraspdif/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mill1000%2Fraspdif/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mill1000","download_url":"https://codeload.github.com/mill1000/raspdif/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mill1000%2Fraspdif/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28736791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T19:23:36.361Z","status":"ssl_error","status_checked_at":"2026-01-24T19:23:28.966Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","raspberry-pi"],"created_at":"2026-01-24T20:53:02.780Z","updated_at":"2026-01-24T20:53:03.551Z","avatar_url":"https://github.com/mill1000.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# raspdif - Raspberry Pi S/PDIF\nS/PDIF audio output on Raspberry Pi without a HAT.\n\nraspdif accepts 16 or 24 bit PCM samples from stdin, a file, or a FIFO (named pipe). Samples are encoded and transmitted as S/PDIF data on GPIO21 (Pin 40 on J8). For older boards without a 40-pin header, see [here](#Alternate-GPIO).\n\n**Table Of Contents**\n- [Building](#building)\n- [Arguments](#arguments)\n- [ALSA Configuration](#alsa-configuration)\n- [Manual Usage](#manual-usage)\n- [Signal Levels](#signal-levels)\n- [Alternate GPIO](#alternate-gpio)\n- [TOSLINK Optical Output](#toslink-optical-output)\n\n## Building\n### Prerequisites\n* clang - Tested against `clang version 3.8.1-24+rpi1` and `clang version 11.0.1-2+rpi1`.\n* 32-bit Raspberry Pi OS (64-bit support is experimental).\n\nInstall necessary packages\n```\nsudo apt-get install build-essential clang git\n```\n\nJust run make. No configuration right now.\n```\nmake\n```\nInstall to default location (`/usr/local/bin`)\n```\nsudo make install\n```\n\n## ALSA Configuration\nALSA can be configured to use raspdif in a seamless manner. Any application that supports ALSA will output via raspdif. It also allows access to other ALSA plugins like `softvol`. \n\nFirst, a PCM device is defined that outputs raw samples to a FIFO. This [example configuration](asound.conf) can be used in either `/etc/asound.conf` for system wide configuration or `~/.asoundrc` for user configuration.\n```\npcm.!default {\n  type plug\n  slave.pcm \"raspdif\"\n}\n\npcm.raspdif {\n  type plug\n  slave {\n    pcm {\n      type file\n      file \"/tmp/spdif_fifo\"\n      format \"raw\"\n      slave.pcm null\n    }\n    rate 44100\n    format S16_LE\n    channels 2\n  }\n  hint {\n    description \"S/PDIF output via raspdif FIFO\"\n  }\n}\n```\n\nA raspdif device should now be visible with `aplay -L`.\n```\n$ aplay -L\nnull\n    Discard all samples (playback) or generate zero samples (capture)\ndefault\nraspdif\n    S/PDIF output via raspdif FIFO\n```\n\nNext, create a raspdif service that monitors the FIFO. This minimal [systemd service](raspdif.service) does a decent job.\n```\n[Unit]\nDescription=raspdif\nAfter=syslog.service\n\n[Service]\nExecStartPre=/usr/bin/rm -f /tmp/spdif_fifo\nExecStartPre=/usr/bin/mkfifo /tmp/spdif_fifo -m 777\nExecStart=/usr/local/bin/raspdif --input /tmp/spdif_fifo\nStandardOutput=journal\nStandardError=journal\nSyslogIdentifier=raspdif\n\n[Install]\nWantedBy=multi-user.target\n```\n\nCopy `raspdif.service` to `/etc/systemd/system` and run the following.\n```\nsudo systemctl daemon-reload\nsudo systemctl enable raspdif.service\nsudo systemctl start raspdif.service\n```\n\nPlayback is now as simple as `aplay some_wav_file.wav` or `gst-play-1.0 some_media_file.flac`.\n\n## Optional Arguments\nCheck `raspdif --help` for additional optional arguments to tweak behavior.\n```\nUsage: raspdif [OPTION...]\n\n  -d, --disable-pcm-on-idle  Disable PCM during underrun.\n  -f, --format=FORMAT        Set audio sample format to s16le or s24le.\n                             Default: s16le\n  -i, --input=INPUT_FILE     Read data from file instead of stdin.\n  -k, --no-keep-alive        Don't send silent noise during underrun.\n  -r, --rate=RATE            Set audio sample rate. Default: 44.1 kHz\n  -v, --verbose              Enable debug messages.\n  -?, --help                 Give this help list\n      --usage                Give a short usage message\n  -V, --version              Print program version\n\nMandatory or optional arguments to long options are also mandatory or optional\nfor any corresponding short options.\n\nReport bugs to https://github.com/mill1000/raspdif/issues.\n```\n\n## Manual Usage\n### Monitor a FIFO\nraspdif can monitor a FIFO and transmit samples written to it. Silence is output if there is no data in the FIFO.\n\n```\nmkfifo /tmp/spdif_fifo\nsudo raspdif --input /tmp/spdif_fifo\n```\n\nNow provide PCM data to to the FIFO in some matter.\n\n#### Examples\nConfigure [gmrender-resurrect](https://github.com/hzeller/gmrender-resurrect) to output to the FIFO.\n```\ngmediarender --gstout-audiopipe 'audioresample ! audio/x-raw, rate=44100,format=S16LE ! filesink location=/tmp/spdif_fifo'\n```\n\nor construct a gstreamer pipeline manually that outputs to the FIFO.\n```\ngst-launch-1.0 uridecodebin uri=\"file://some_audio_file.flac\" ! audioconvert ! audioresample ! audio/x-raw, rate=441\n00,format=S16LE ! filesink location=/tmp/spdif_fifo\n```\n\nFFMPEG can also write directly to the FIFO.\n```\nffmpeg -i some_audio_file.flac -f s16le -acodec pcm_s16le -ar 44100 /tmp/spdif_fifo\n```\n\n### Play a file directly\nraspdif can play a file directly. Files must be raw PCM in S16LE or S24LE format.\n```\nsudo raspdif --input ~/some_pcm_file.pcm\n```\n\n### Pipe data via stdin\n```\nffmpeg -i some_audio_file.flac -f s16le -acodec pcm_s16le -ar 44100 - | sudo raspdif\n```\n\n### Set the sample rate\nraspdif defaults to a sample rate of 44.1 kHz. Alternate sample rates can be specified on the command line with the `--rate` option. Rates up to 192 kHz have been tested successfully.\n\n### Set the sample format\nraspdif supports 16 or 24 bit PCM samples. Use the `--format` option to select between `s16le` and `s24le`.\n\n## Signal Levels\nS/PDIF specification calls for .5 V Vpp when 75 Ohm is connected across the output. To achieve these level from the Raspberry Pi's nominal 3.3 V signaling a simple resistive divider can be build with a 390 Ohm resister is series with the output.\n\n![Resistive Divider](raspdif_divider.png)\n\nHowever, my DAC and receiver have not had an issue receiving the full 3.3 V signal. Use at your own risk.\n\n## Alternate GPIO\nraspdif can be reconfigured to output on GPIO31 instead of the default GPIO21. For Rev 2 boards, GPIO31 is located on the P5 header.\n\nTo reconfigure for GPIO31 the following changes need to be made.\n```diff\n  gpio_configuration_t gpioConfig;\n  gpioConfig.eventDetect = gpio_event_detect_none;\n-  gpioConfig.function = gpio_function_af0;\n+  gpioConfig.function = gpio_function_af2;\n  gpioConfig.pull = gpio_pull_no_change;\n-  gpioConfigureMask(1 \u003c\u003c 21 , \u0026gpioConfig);\n+  gpioConfigureMask(1 \u003c\u003c 31 , \u0026gpioConfig);\n```\n\nThanks to @marcoalexcampos0 for digging into this and testing.\n\n## TOSLINK Optical Output\nThanks to @tlalexander.\n\u003e I have discovered that if you hook up a red LED and a resistor (I used about 600 ohms) to the output pin and ground, this works for optical audio output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmill1000%2Fraspdif","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmill1000%2Fraspdif","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmill1000%2Fraspdif/lists"}