<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/something-isn-t-right--g30o2x7is" -->

---
title: Something isn't right... | daily.dev
description: A live-coding stream follows an attempt to build a virtual piano by parsing WAV files and playing audio through PipeWire in Zig. The host writes a RIFF/WAV...
canonical: https://daily.dev/posts/something-isn-t-right--g30o2x7is
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Something isn't right... | daily.dev
og:description: A live-coding stream follows an attempt to build a virtual piano by parsing WAV files and playing audio through PipeWire in Zig. The host writes a RIFF/WAV...
og:url: https://daily.dev/posts/something-isn-t-right--g30o2x7is
og:image: https://api.daily.dev/og/posts/g30O2X7iS.png
og:image:alt: Something isn't right...
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Something isn't right...

**[sphaerophoria](https://daily.dev/sources/sphaerophoria)** · 95 min read · 0 upvotes · 0 comments

## Summary

A live-coding stream follows an attempt to build a virtual piano by parsing WAV files and playing audio through PipeWire in Zig. The host writes a RIFF/WAV chunk parser from scratch, reads format and data chunks, then hits a maddening, intermittent circular-buffer corruption bug when trying to play back sampled audio. After extensive debugging with logging, thread-ID checks, and backtraces, the root cause turns out to be PipeWire's real-time thread flag being set unnecessarily (copy-pasted from a tutorial), causing callbacks to fire from a different thread than expected. Once removed, playback works correctly, and the stream ends with a plan to tackle Fourier transforms and visualization in a future session.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=gxs5sJQiIlo>

## Questions this post answers

### Why would audio playback via a PipeWire stream crackle or corrupt a circular buffer intermittently?

Intermittent circular buffer corruption during PipeWire playback can be caused by unnecessarily setting the real-time thread flag (RT_PROCESS) when connecting a stream, which causes PipeWire's process callback to run on a different thread than the one calling the service/iterate loop. Removing that flag, so the loop runs entirely on one thread, eliminates the thread-safety violation and fixes both the crackling and the crashes.

_Developers chasing elusive PipeWire threading bugs can find similar war stories and fixes curated on daily.dev._

### What is the basic structure of a WAV (RIFF) file that I need to parse to read audio samples?

A WAV file starts with a 4-byte 'RIFF' identifier, followed by a 4-byte file size field and a 4-byte 'WAVE' format identifier, after which a series of chunks follow, each with a 4-byte chunk ID and 4-byte chunk size. The 'fmt ' chunk holds audio format, channel count, sample rate, byte rate, block align, and bits per sample; the 'data' chunk holds the raw little-endian PCM samples themselves.

_Anyone writing a binary file parser from scratch can track practical format breakdowns like this on daily.dev._

## Similar posts on daily.dev

- [A Live Chiptune Synthesizer in Erlang](https://daily.dev/posts/a-live-chiptune-synthesizer-in-erlang-ymojxunnn) · Erlang Solutions · 0 upvotes · 0 comments

---

Tags: [#linux](https://daily.dev/tags/linux), [#zig](https://daily.dev/tags/zig)

[View this post on daily.dev](https://daily.dev/posts/something-isn-t-right--g30o2x7is)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Something isn't right...","url":"https://daily.dev/posts/something-isn-t-right--g30o2x7is","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/something-isn-t-right--g30o2x7is"},"datePublished":"2026-10-03T22:25:40.084Z","dateModified":"2026-10-03T22:26:09.428Z","description":"A live-coding stream follows an attempt to build a virtual piano by parsing WAV files and playing audio through PipeWire in Zig. The host writes a RIFF/WAV...","image":"https://i.ytimg.com/vi/gxs5sJQiIlo/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/gxs5sJQiIlo/sddefault.jpg","isAccessibleForFree":true,"articleSection":"sphaerophoria","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"sphaerophoria","logo":"https://media.daily.dev/image/upload/s--dgPUg2T7--/f_auto/v1728806109/logos/sphaerophoria","url":"https://daily.dev/sources/sphaerophoria"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/something-isn-t-right--g30o2x7is","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"linux,zig","timeRequired":"PT95M","video":{"@type":"VideoObject","name":"Something isn't right...","description":"A live-coding stream follows an attempt to build a virtual piano by parsing WAV files and playing audio through PipeWire in Zig. The host writes a RIFF/WAV...","thumbnailUrl":"https://i.ytimg.com/vi/gxs5sJQiIlo/sddefault.jpg","uploadDate":"2026-10-03T22:25:40.084Z","duration":"PT95M","url":"https://api.daily.dev/r/g30O2X7iS","embedUrl":"https://www.youtube.com/embed/gxs5sJQiIlo"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"sphaerophoria","item":"https://daily.dev/sources/sphaerophoria"},{"@type":"ListItem","position":3,"name":"Something isn't right..."}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/something-isn-t-right--g30o2x7is#faq","mainEntity":[{"@type":"Question","name":"Why would audio playback via a PipeWire stream crackle or corrupt a circular buffer intermittently?","acceptedAnswer":{"@type":"Answer","text":"Intermittent circular buffer corruption during PipeWire playback can be caused by unnecessarily setting the real-time thread flag (RT_PROCESS) when connecting a stream, which causes PipeWire's process callback to run on a different thread than the one calling the service/iterate loop. Removing that flag, so the loop runs entirely on one thread, eliminates the thread-safety violation and fixes both the crackling and the crashes. Developers chasing elusive PipeWire threading bugs can find similar war stories and fixes curated on daily.dev."}},{"@type":"Question","name":"What is the basic structure of a WAV (RIFF) file that I need to parse to read audio samples?","acceptedAnswer":{"@type":"Answer","text":"A WAV file starts with a 4-byte 'RIFF' identifier, followed by a 4-byte file size field and a 4-byte 'WAVE' format identifier, after which a series of chunks follow, each with a 4-byte chunk ID and 4-byte chunk size. The 'fmt ' chunk holds audio format, channel count, sample rate, byte rate, block align, and bits per sample; the 'data' chunk holds the raw little-endian PCM samples themselves. Anyone writing a binary file parser from scratch can track practical format breakdowns like this on daily.dev."}}]}
```

