<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq" -->

---
title: Making a virtual piano &#x27;cause I heard a noise I like
description: A live-coded stream builds a simple virtual piano GUI in Zig, using a custom GUI/rendering library and a pipewire-based audio library. The session covers...
canonical: https://daily.dev/posts/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Making a virtual piano &#x27;cause I heard a noise I like | daily.dev
og:description: A live-coded stream builds a simple virtual piano GUI in Zig, using a custom GUI/rendering library and a pipewire-based audio library. The session covers...
og:url: https://daily.dev/posts/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq
og:image: https://api.daily.dev/og/posts/XIbJlMOUQ.png
og:image:alt: Making a virtual piano &#x27;cause I heard a noise I like
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.

# Making a virtual piano 'cause I heard a noise I like

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

## Summary

A live-coded stream builds a simple virtual piano GUI in Zig, using a custom GUI/rendering library and a pipewire-based audio library. The session covers setting up the Zig build system, rendering white and black piano keys with transform math, handling mouse input to detect key presses, and finally generating sine-wave tones mapped to note frequencies using the twelfth-root-of-two equal temperament formula. The stream ends with a working, if buzzy and pop-prone, piano synthesizer, setting up future work on ADSR envelopes and Fourier-based timbre shaping to make it sound like a real piano.

## Full article

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

## Questions this post answers

### How do you calculate the frequency of each piano key using equal temperament?

Each semitone's frequency is the base frequency multiplied by two raised to the power of one-twelfth, applied once per key step above the base. Starting from 440 Hz (A), successive keys come out to roughly 466.16 Hz and 493.88 Hz, matching the twelve-tone equal temperament formula where twelve steps double the frequency to reach the next octave.

_Developers exploring audio synthesis math can find implementation walkthroughs like this one on daily.dev._

### How do I find the first set bit in a bitmask in Zig to detect which key is pressed?

Use count trailing zeros (CTZ) on the bitmask, which returns the position of the first set bit starting from the least significant bit. If the value is zero (no bits set), CTZ returns the bit width of the integer type, so checking for that case tells you nothing is pressed before indexing into a lookup table.

_Anyone wiring up bitmask-based input handling in Zig can compare approaches like this on daily.dev._

### Why does a synthesized piano note produce a popping sound when a key is pressed or released?

Popping occurs because a raw sine wave is switched abruptly on or off rather than starting and ending at a zero crossing, creating a sudden discontinuity in the waveform that the speaker reproduces as a click. Fixes include offsetting playback to the next zero crossing at press time or applying an ADSR envelope (attack, decay, sustain, release) to shape the amplitude smoothly.

_Developers debugging audio glitches in synthesizers can dig into envelope shaping techniques 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
- [Medium](https://daily.dev/posts/medium-eyv3bfnto) · Medium · 0 upvotes · 0 comments

---

Tags: [#zig](https://daily.dev/tags/zig), [#signal-processing](https://daily.dev/tags/signal-processing), [#desktop-development](https://daily.dev/tags/desktop-development)

[View this post on daily.dev](https://daily.dev/posts/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq)

```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":"Making a virtual piano 'cause I heard a noise I like","url":"https://daily.dev/posts/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq"},"datePublished":"2026-09-30T22:11:57.208Z","dateModified":"2026-09-30T23:59:07.726Z","description":"A live-coded stream builds a simple virtual piano GUI in Zig, using a custom GUI/rendering library and a pipewire-based audio library. The session covers...","image":"https://i.ytimg.com/vi/gLphM2D2bm4/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/gLphM2D2bm4/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/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"zig,signal-processing,desktop-development","timeRequired":"PT96M","video":{"@type":"VideoObject","name":"Making a virtual piano 'cause I heard a noise I like","description":"A live-coded stream builds a simple virtual piano GUI in Zig, using a custom GUI/rendering library and a pipewire-based audio library. The session covers...","thumbnailUrl":"https://i.ytimg.com/vi/gLphM2D2bm4/sddefault.jpg","uploadDate":"2026-09-30T22:11:57.208Z","duration":"PT96M","url":"https://api.daily.dev/r/XIbJlMOUQ","embedUrl":"https://www.youtube.com/embed/gLphM2D2bm4"}}
{"@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":"Making a virtual piano 'cause I heard a noise I like"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/making-a-virtual-piano-cause-i-heard-a-noise-i-like-xibjlmouq#faq","mainEntity":[{"@type":"Question","name":"How do you calculate the frequency of each piano key using equal temperament?","acceptedAnswer":{"@type":"Answer","text":"Each semitone's frequency is the base frequency multiplied by two raised to the power of one-twelfth, applied once per key step above the base. Starting from 440 Hz (A), successive keys come out to roughly 466.16 Hz and 493.88 Hz, matching the twelve-tone equal temperament formula where twelve steps double the frequency to reach the next octave. Developers exploring audio synthesis math can find implementation walkthroughs like this one on daily.dev."}},{"@type":"Question","name":"How do I find the first set bit in a bitmask in Zig to detect which key is pressed?","acceptedAnswer":{"@type":"Answer","text":"Use count trailing zeros (CTZ) on the bitmask, which returns the position of the first set bit starting from the least significant bit. If the value is zero (no bits set), CTZ returns the bit width of the integer type, so checking for that case tells you nothing is pressed before indexing into a lookup table. Anyone wiring up bitmask-based input handling in Zig can compare approaches like this on daily.dev."}},{"@type":"Question","name":"Why does a synthesized piano note produce a popping sound when a key is pressed or released?","acceptedAnswer":{"@type":"Answer","text":"Popping occurs because a raw sine wave is switched abruptly on or off rather than starting and ending at a zero crossing, creating a sudden discontinuity in the waveform that the speaker reproduces as a click. Fixes include offsetting playback to the next zero crossing at press time or applying an ADSR envelope (attack, decay, sustain, release) to shape the amplitude smoothly. Developers debugging audio glitches in synthesizers can dig into envelope shaping techniques on daily.dev."}}]}
```

