<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0" -->

---
title: QWERTY Keyboard as a Musical Instrument | daily.dev
description: A live coding session building a digital music looper in the Jai programming language. The developer adds square wave and sawtooth wave instruments alongside...
canonical: https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: QWERTY Keyboard as a Musical Instrument | daily.dev
og:description: A live coding session building a digital music looper in the Jai programming language. The developer adds square wave and sawtooth wave instruments alongside...
og:url: https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0
og:image: https://api.daily.dev/og/posts/yfQGt38c0.png
og:image:alt: QWERTY Keyboard as a Musical Instrument
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.

# QWERTY Keyboard as a Musical Instrument

**[Tsoding Daily](https://daily.dev/sources/tsoding_daily)** · 79 min read · 0 upvotes · 0 comments

## Summary

A live coding session building a digital music looper in the Jai programming language. The developer adds square wave and sawtooth wave instruments alongside the existing sine wave, designing a pluggable instrument interface using function pointers and void* data for parameterization. Key topics include standardizing periodic functions to period-1 (using 'turns'), handling floating-point precision loss for long-running notes by switching to 64-bit arithmetic, implementing pulse-width control for square waves, and mapping a gamepad analog stick axis to real-time instrument parameter modulation. The session also covers Jai-specific type system challenges around covariance when assigning parameterized instrument structs to void-typed pointers, and touches on Jai's #as keyword for implicit struct pointer casting.

## Full article

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

## Questions this post answers

### Why does a long-running sine wave note sound distorted or 'deep fried' over time in audio programming?

Floating-point precision degrades as the frame counter grows large. The bigger the float value fed into sine, the fewer bits remain for the fractional part, making the waveform increasingly choppy. The fix is to perform all audio computations in 64-bit floats, which postpones the precision breakdown far into the future — analogous to Minecraft's Farlands bug caused by the same float precision loss at large coordinates.

_Audio programmers chasing precision bugs like this one share findings on daily.dev._

### How do you implement a square wave instrument with adjustable pulse width in C-like audio code?

Take the fractional part of the input x (normalized to period 1), then compare it to a pulse-width parameter P (0–1). Return 1.0 if x < P, otherwise return -1.0. Storing P as a float pointer in a void* data field lets you adjust it at runtime — for example, by mapping a gamepad analog axis (range -1 to 1, remapped to 0 to 1) to P while a note is held.

_Developers building synthesizers or chip-tune tools find implementation patterns like this on daily.dev._

## Similar posts on daily.dev

- [A Keyboard With No Keys](https://daily.dev/posts/a-keyboard-with-no-keys-u7ispwar2) · Hackaday · 0 upvotes · 0 comments

---

[View this post on daily.dev](https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0)

```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":"QWERTY Keyboard as a Musical Instrument","url":"https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0"},"datePublished":"2026-08-10T21:11:05.539Z","dateModified":"2026-08-10T21:16:44.422Z","description":"A live coding session building a digital music looper in the Jai programming language. The developer adds square wave and sawtooth wave instruments alongside...","image":"https://i.ytimg.com/vi/im2rlDgNlrQ/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/im2rlDgNlrQ/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Tsoding Daily","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":"Tsoding Daily","logo":"https://media.daily.dev/image/upload/s--6msWm9pp--/f_auto/v1728806157/logos/tsoding_daily","url":"https://daily.dev/sources/tsoding_daily"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"","timeRequired":"PT79M","video":{"@type":"VideoObject","name":"QWERTY Keyboard as a Musical Instrument","description":"A live coding session building a digital music looper in the Jai programming language. The developer adds square wave and sawtooth wave instruments alongside...","thumbnailUrl":"https://i.ytimg.com/vi/im2rlDgNlrQ/sddefault.jpg","uploadDate":"2026-08-10T21:11:05.539Z","duration":"PT79M","url":"https://api.daily.dev/r/yfQGt38c0","embedUrl":"https://www.youtube.com/embed/im2rlDgNlrQ"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Tsoding Daily","item":"https://daily.dev/sources/tsoding_daily"},{"@type":"ListItem","position":3,"name":"QWERTY Keyboard as a Musical Instrument"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/qwerty-keyboard-as-a-musical-instrument-yfqgt38c0#faq","mainEntity":[{"@type":"Question","name":"Why does a long-running sine wave note sound distorted or 'deep fried' over time in audio programming?","acceptedAnswer":{"@type":"Answer","text":"Floating-point precision degrades as the frame counter grows large. The bigger the float value fed into sine, the fewer bits remain for the fractional part, making the waveform increasingly choppy. The fix is to perform all audio computations in 64-bit floats, which postpones the precision breakdown far into the future — analogous to Minecraft's Farlands bug caused by the same float precision loss at large coordinates. Audio programmers chasing precision bugs like this one share findings on daily.dev."}},{"@type":"Question","name":"How do you implement a square wave instrument with adjustable pulse width in C-like audio code?","acceptedAnswer":{"@type":"Answer","text":"Take the fractional part of the input x (normalized to period 1), then compare it to a pulse-width parameter P (0–1). Return 1.0 if x < P, otherwise return -1.0. Storing P as a float pointer in a void* data field lets you adjust it at runtime — for example, by mapping a gamepad analog axis (range -1 to 1, remapped to 0 to 1) to P while a note is held. Developers building synthesizers or chip-tune tools find implementation patterns like this on daily.dev."}}]}
```

