{"article":{"slug":"why-this-obscure-audio-codec-is-a-perfect-fit-for-the-n64","title":"Why this Obscure Audio Codec is a Perfect Fit for the N64","subtitle":null,"summary":"Dominic Szablewski (phoboslab) explains why the ULC transform codec suits the Nintendo 64, delivering 44.1 kHz stereo at near-Opus bitrates using about 4% of the console's CPU time, after surveying earlier N64 audio options.","content_type":"blog_post","language":"en","canonical_url":"https://phoboslab.org/log/2026/11/n64-ulc-codec","author":{"name":"Dominic Szablewski","url":"https://phoboslab.org/","person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"PhobosLab","url":"https://phoboslab.org/","listing_slug":null,"listing":null},"topics":[{"name":"Programming","slug":"programming","url":"https://listedarticles.com/topics/programming"},{"name":"Audio","slug":"audio","url":"https://listedarticles.com/topics/audio"},{"name":"Retro Computing","slug":"retro-computing","url":"https://listedarticles.com/topics/retro-computing"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":1893,"reading_minutes":8,"published_at":"2026-11-03T00:00:00.000Z","added_at":"2026-11-05T17:12:53.960Z","updated_at":"2026-11-05T17:12:53.960Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/why-this-obscure-audio-codec-is-a-perfect-fit-for-the-n64","markdown_url":"https://listedarticles.com/articles/why-this-obscure-audio-codec-is-a-perfect-fit-for-the-n64.md","example":false,"citation":"Dominic Szablewski, PhobosLab. \"Why this Obscure Audio Codec is a Perfect Fit for the N64.\" 3 Nov 2026. https://phoboslab.org/log/2026/11/n64-ulc-codec (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://phoboslab.org/log/2026/11/n64-ulc-codec"},"body_markdown":"# Why this Obscure Audio Codec is a Perfect Fit for the N64\n\nSorry for the clickbait title. I promise this post delivers: 44100 Hz stereo with near-Opus bitrates using about 4% of the N64’s CPU time.\n\nBut first, some history: The options for playing and storing audio data on the N64 were dire. The PlayStation could just stream uncompressed redbook audio straight from the CD. On the N64, cartridge space was at a premium and time on the 93 MHz CPU was limited.\n\nWorse, access to the vector co-processor, the RSP, was guarded by Nintendo for the longest time. Nintendo's own platform library, Libultra, internally used the RSP for various graphics and sound-related tasks, but Nintendo didn't allow third-party developers to directly write code for it.\n\nLibultra provided some functions to transparently play back compressed audio using an ADPCM scheme (adaptive differential pulse code modulation). The RSP handled decompression on the fly, just before the audio was sent to the output buffer.\n\nThis works well enough and cuts the space needed for a sample by a factor of 4. Still, a 5-minute stereo audio track at 44100 Hz will land at about 12MB – way too much for an N64 cartridge, even when you cut the sample rate in half. The whole Mario 64 ROM is just 8MB in total. The biggest N64 games were 64MB.\n\nSo N64 games produced music similarly to a tracker: short samples were scheduled and played back with some limited effects at the right time. With the space constraints on the cartridge, fully “recorded” audio was pretty much out of the question.\n\nLater in the N64's life, some blessed developers were allowed by Nintendo to directly access the RSP. Most famously, Conker's Bad Fur Day used this to decompress MP3 audio for the myriad of speech samples in the game. Decoding MP3 is quite expensive and the frame rate of the game suffered. It was good enough for cutscenes, but just too much for continuous background music or sound effects during gameplay.\n\n## Audio in the Open Source Libdragon\n\nSimilar to Nintendo's\nLibultra, [Libdragon](https://github.com/n64brew/libdragon), the open source\nalternative, has a real-time ADPCM decoder running on the RSP. So with ROM space\nbeing cheaper these days, I just compressed all music for [Xibalba\n64](/log/2026/08/xibalba64-making-of) with ADPCM. About 31MB of the 32MB ROM\nare used for sound and music. Remember that Mario 64 just used an 8MB ROM and\nXibalba 64 is a much simpler game with only 15 minutes of music. It worked,\nbut storing music this way is a gratuitous waste of space.\n\nNow, Libdragon also has a real-time, RSP-accelerated Opus decoder. It's a marvel\nin itself. The Opus format was published 16 years after the N64 and yet\nGiovanni Bajo managed to make it work on this *“obsolete”* hardware. Compression\nand audio quality are excellent, but again – it's too slow to be used during\ngameplay.\n\nWhat's the alternative then? We could build an RSP-accelerated MP3 decoder, but the performance gain over Opus would be marginal, and quality and compression would be worse.\n\n[QOA](/log/2023/02/qoa-time-domain-audio-compression) would be a slight \nimprovement over ADPCM, but it's just a poor fit for the vector co-processor: \neach sample relies on the previous decoded sample. Hard to vectorize.\n\nA simple transform codec, something *like* MP3, but without all the \ndesign-by-consortium baggage, may work…\n\n## The Ultra Low Complexity Codec\n\nDuring some late-night *“research”*, I stumbled across an old Game Boy\nAdvance demo that plays recorded music at just 70kbps. That's less than a\ntypical MP3, but at comparable quality. I repeat: On a GBA. With a 16 MHz ARM CPU. With no\nvector instructions and, according to the GitHub page, some\nheadroom to spare.\n\n[ulcplayer-gba](https://github.com/Aikku93/ulcplayer-gba)by Aikku93, recorded in a Game Boy Advance emulator\nTime-domain codecs (such as ADPCM) need significantly higher bitrates for this\nquality. Subband codecs, such as MP2, have much worse quality at comparable\nbitrates, and more “modern” transform codecs, such as MP3, usually\n[need at least an 80–100 MHz CPU](https://www.youtube.com/watch?v=b0zZpzxHSeM). For\nthis GBA demo, no existing codec would fit the bill.\n\nSo [Aikku93](https://github.com/Aikku93) not only wrote a decoder in ARM assembly, \nbut also created a whole new codec: The \n[Ultra Low Complexity Codec](https://github.com/Aikku93/ulc-codec) (ULC).\n\nULC *is* a transform codec and somewhat similar to MP3. ULC transforms slices of \nPCM data into the frequency domain. Like MP3, it uses the Modified Discrete Cosine\nTransform (MDCT) to do so. But unlike MP3, it does not split the signal\ninto multiple bands (ULC's MDCT is “full-band”). Where MP3 uses classic\nentropy encoding (Huffman specifically), ULC does… not. Instead, transformed\ncoefficients are stored with a very simple nibble-based syntax.\n\nIn short: ULC is what MP3 could have been. The same core idea, but without the cruft around it. The “ultra low complexity” does not come from a different algorithm, but by carefully applying and packaging it.\n\nThe nibble-based packaging is maybe the most elegant idea of ULC. Each coefficient is stored in just 4 bits, interpreted as a signed integer. Some values are reserved to indicate zero fill, noise fill, or a quantizer change:\n\n- `-7 … -2` ,`2 … 7` - coefficient value\n- `0` - zero run, run length (`1 … 16` ) follows in the next nibble\n- `1` - long zero run, run length (`17 … 288` ) follows in the next two nibbles\n- `-1` - quantizer change, value follows in the next nibble\n- `-8` - noise fill, length and amplitude follow in the next three nibbles\n\nEverything is nibble aligned. This means the whole codec works without any\narbitrary bit reads or entropy decoding. Reading and\nunpacking a block of coefficients takes just [~150 lines of C](https://github.com/Aikku93/ulc-codec/blob/b47df8d50c2ef2d765e5dbec0bf567b5e558173a/libulc/ulcDecoder.c#L99-L197).\n\nAlso note that noise fill is a valuable addition. Cymbals, hi-hats and snare\ndrums greatly benefit from that. MP3 does not have anything similar and \nneeds to encode quasi-random coefficients *as is*. \n\nULC can produce *usable* results even at 16kbps. Quality of course suffers, but\nit might still be good enough for some applications.\n\nAikku93 has been working on ULC since 2019 and has steadily improved the encoding quality. All code is permissively licensed. Time to try this on the N64 then!\n\n## ULC on the N64\n\nI spent an evening in pre-LLM days compiling the ULC reference decoder for the N64 and producing a small demo. It worked without a hitch.\n\nThe only problem: it was keeping the CPU very busy. Nothing was offloaded to the \nRSP. As a proof of concept, it wasn't doing much: we already knew the 93 MHz CPU\nwas enough to decode a transform-based codec, but we don't need a “music player”\nthat does nothing else. We need this for background music and spoken dialog\nduring gameplay. It *cannot* hog the CPU.\n\n### Float to 16-bit Fixed Point\n\nObviously the IMDCT needs to be moved to the RSP coprocessor instead. We could just DMA one block of decoded coefficients to the RSP's memory, do the transform and DMA the completed samples back to RDRAM into the output buffer.\n\nThat's easier said than done, though. The RSP has only 4096 bytes of data memory (DMEM) and another 4096 bytes for instructions (IMEM). The vector instructions work in 16-bit or 32-bit fixed point, with no floats. The IMDCT will only be efficient if all the data for a transform fits into the RSP's DMEM at once. We also need some of the DMEM for temporary values and – if possible – the lapping buffer: half of the previously decoded block. So with the default 2048-sample block size of ULC, we're out of luck, even with 16-bit fixed point.\n\nWhile ULC can work with smaller MDCT block sizes, it was optimized for 2048, so\nwe should keep it as large as possible. On top of that, the ULC reference \nencoder/decoder uses floats, so the obvious choice would be 32-bit fixed point to\nmaintain quality, but 16-bit *may* work. So we have two options, both arriving\nat `3072 bytes`:\n\n1. 32-bit values, a 512-sample block size (256-sample lap buffer): `(512 + 256) * 4 bytes`\n2. 16-bit values, a 1024-sample block size (512-sample lap buffer): `(1024 + 512) * 2 bytes`\n\nUsing 16-bit fixed point would not only reduce the DMA traffic, but also speed up computation on the RSP. The trade-off would be a higher noise floor. How high? No idea. So I carefully refactored the reference decoder, still running on the N64 CPU, to work in 16-bit fixed point (Q1.14).\n\nAfter almost blowing my ears off a bunch of times, I got it working and could only hear (or imagine?) the faintest white noise when cranking it up. Case settled: 16-bit it is.\n\n### Cramming it into the RSP\n\nNow I *just* needed to port this C code to the RSP. My knowledge of MIPS\nassembly is very basic, and writing an RSP decoder would be a serious endeavor.\n\nThis is where I took a hiatus from this project – I had a \n[game](/log/2026/08/xibalba64-making-of) to finish. When I returned earlier this \nyear LLMs have improved quite a bit. Still, I didn't\nexactly trust GPT-5 with it. In some previous experiments it did a very\nbad job, often ignoring delay slots and other intricacies of the RSP, never\nfinishing the job.\n\n*(Aside: GPT-6 or Opus-5 would probably one-shot this now)*\n\nSo instead I opted for a more iterative approach. Max Bebök created a small\nC-like language to write code for the RSP, aptly named \n[RSPL](https://github.com/HailToDodongo/rspl). Armed with the language \ndocumentation, I asked Codex to translate the C code to RSPL piece by piece,\nalways verifying the result. It took a few days to port and land on an API \ndesign that made sense. Then in subsequent steps Codex further optimized the \nRSPL assembly output by first rewriting some parts (directly in assembly this time),\nthen minimizing pipeline stalls by [adapting](https://github.com/phoboslab/rspopt)\nthe RSPL's optimizer.\n\nThe end result is [~1400 lines of MIPS assembly](https://github.com/n64brew/libdragon/blob/preview/src/audio/rsp_ulc.S)\nhandling the IMDCT, lapping, stereo interleaving and output scaling. It barely\nfits into the 4096 byte IMEM of the RSP.\n\nThe [C side of the decoder](https://github.com/n64brew/libdragon/blob/preview/src/audio/wav64_ulc.c) \nis still handwritten, but only because LLMs have no taste. The whole process\ntook me a few weeks, but I'm still amazed that it worked at all.\n\n*My*\n\n[ulc64 demo](https://github.com/phoboslab/ulc64/)demonstrating quality at various bitrates\nTo make ULC easily seekable, I added a sparse table at the end of the file that contains the byte offset of every eighth frame. The decoder quickly skips ahead from the nearest frame to the desired one. This adds about 20 bytes per second – manageable even for 16kbps audio.\n\nULC proved to be a *very* viable alternative to ADPCM and Opus on the N64. \nQuality and bitrate are close to those of Opus, but complexity is only 4x that of ADPCM. A\nsingle 44100 Hz stereo track costs about 4% of CPU time and 5% of RSP time.\nPerfectly usable for background music, speech, ambience and longer sound effects.\n\nThe decoder works transparently in Libdragon, just like all other audio codecs. \nIt has been merged into the [preview branch](https://github.com/n64brew/libdragon/tree/preview) a while ago.\n\n## Addendum\n\nA few days ago an excellent port of Half-Life for the N64 was published. \nThe `README` states:\n\n[...] libdragon's ULC audio codec for the 2,500 sounds and 27 music tracks, is what makes everything fit in one 64 MB cartridge image.\n\n~ [github.com/ToxyCola/Half-Life-Nintendo-64-Port](https://github.com/ToxyCola/Half-Life-Nintendo-64-Port)\n\nMany thanks to [Aikku93](https://github.com/Aikku93) for creating ULC. It's a \nwonderful codec. I merely found and adapted it. I seek simplicity and elegance\nin everything I do and ULC is something I can truly adore. Kudos!","body_html":"<h1 id=\"why-this-obscure-audio-codec-is-a-perfect-fit-for-the-n64\">Why this Obscure Audio Codec is a Perfect Fit for the N64</h1>\n<p>Sorry for the clickbait title. I promise this post delivers: 44100 Hz stereo with near-Opus bitrates using about 4% of the N64’s CPU time.</p>\n<p>But first, some history: The options for playing and storing audio data on the N64 were dire. The PlayStation could just stream uncompressed redbook audio straight from the CD. On the N64, cartridge space was at a premium and time on the 93 MHz CPU was limited.</p>\n<p>Worse, access to the vector co-processor, the RSP, was guarded by Nintendo for the longest time. Nintendo&#39;s own platform library, Libultra, internally used the RSP for various graphics and sound-related tasks, but Nintendo didn&#39;t allow third-party developers to directly write code for it.</p>\n<p>Libultra provided some functions to transparently play back compressed audio using an ADPCM scheme (adaptive differential pulse code modulation). The RSP handled decompression on the fly, just before the audio was sent to the output buffer.</p>\n<p>This works well enough and cuts the space needed for a sample by a factor of 4. Still, a 5-minute stereo audio track at 44100 Hz will land at about 12MB – way too much for an N64 cartridge, even when you cut the sample rate in half. The whole Mario 64 ROM is just 8MB in total. The biggest N64 games were 64MB.</p>\n<p>So N64 games produced music similarly to a tracker: short samples were scheduled and played back with some limited effects at the right time. With the space constraints on the cartridge, fully “recorded” audio was pretty much out of the question.</p>\n<p>Later in the N64&#39;s life, some blessed developers were allowed by Nintendo to directly access the RSP. Most famously, Conker&#39;s Bad Fur Day used this to decompress MP3 audio for the myriad of speech samples in the game. Decoding MP3 is quite expensive and the frame rate of the game suffered. It was good enough for cutscenes, but just too much for continuous background music or sound effects during gameplay.</p>\n<h2 id=\"audio-in-the-open-source-libdragon\">Audio in the Open Source Libdragon</h2>\n<p>Similar to Nintendo&#39;s\nLibultra, <a href=\"https://github.com/n64brew/libdragon\" rel=\"nofollow ugc noopener\">Libdragon</a>, the open source\nalternative, has a real-time ADPCM decoder running on the RSP. So with ROM space\nbeing cheaper these days, I just compressed all music for <a href=\"/log/2026/08/xibalba64-making-of\">Xibalba\n64</a> with ADPCM. About 31MB of the 32MB ROM\nare used for sound and music. Remember that Mario 64 just used an 8MB ROM and\nXibalba 64 is a much simpler game with only 15 minutes of music. It worked,\nbut storing music this way is a gratuitous waste of space.</p>\n<p>Now, Libdragon also has a real-time, RSP-accelerated Opus decoder. It&#39;s a marvel\nin itself. The Opus format was published 16 years after the N64 and yet\nGiovanni Bajo managed to make it work on this <em>“obsolete”</em> hardware. Compression\nand audio quality are excellent, but again – it&#39;s too slow to be used during\ngameplay.</p>\n<p>What&#39;s the alternative then? We could build an RSP-accelerated MP3 decoder, but the performance gain over Opus would be marginal, and quality and compression would be worse.</p>\n<p><a href=\"/log/2023/02/qoa-time-domain-audio-compression\">QOA</a> would be a slight \nimprovement over ADPCM, but it&#39;s just a poor fit for the vector co-processor: \neach sample relies on the previous decoded sample. Hard to vectorize.</p>\n<p>A simple transform codec, something <em>like</em> MP3, but without all the \ndesign-by-consortium baggage, may work…</p>\n<h2 id=\"the-ultra-low-complexity-codec\">The Ultra Low Complexity Codec</h2>\n<p>During some late-night <em>“research”</em>, I stumbled across an old Game Boy\nAdvance demo that plays recorded music at just 70kbps. That&#39;s less than a\ntypical MP3, but at comparable quality. I repeat: On a GBA. With a 16 MHz ARM CPU. With no\nvector instructions and, according to the GitHub page, some\nheadroom to spare.</p>\n<p><a href=\"https://github.com/Aikku93/ulcplayer-gba\" rel=\"nofollow ugc noopener\">ulcplayer-gba</a>by Aikku93, recorded in a Game Boy Advance emulator\nTime-domain codecs (such as ADPCM) need significantly higher bitrates for this\nquality. Subband codecs, such as MP2, have much worse quality at comparable\nbitrates, and more “modern” transform codecs, such as MP3, usually\n<a href=\"https://www.youtube.com/watch?v=b0zZpzxHSeM\" rel=\"nofollow ugc noopener\">need at least an 80–100 MHz CPU</a>. For\nthis GBA demo, no existing codec would fit the bill.</p>\n<p>So <a href=\"https://github.com/Aikku93\" rel=\"nofollow ugc noopener\">Aikku93</a> not only wrote a decoder in ARM assembly, \nbut also created a whole new codec: The \n<a href=\"https://github.com/Aikku93/ulc-codec\" rel=\"nofollow ugc noopener\">Ultra Low Complexity Codec</a> (ULC).</p>\n<p>ULC <em>is</em> a transform codec and somewhat similar to MP3. ULC transforms slices of \nPCM data into the frequency domain. Like MP3, it uses the Modified Discrete Cosine\nTransform (MDCT) to do so. But unlike MP3, it does not split the signal\ninto multiple bands (ULC&#39;s MDCT is “full-band”). Where MP3 uses classic\nentropy encoding (Huffman specifically), ULC does… not. Instead, transformed\ncoefficients are stored with a very simple nibble-based syntax.</p>\n<p>In short: ULC is what MP3 could have been. The same core idea, but without the cruft around it. The “ultra low complexity” does not come from a different algorithm, but by carefully applying and packaging it.</p>\n<p>The nibble-based packaging is maybe the most elegant idea of ULC. Each coefficient is stored in just 4 bits, interpreted as a signed integer. Some values are reserved to indicate zero fill, noise fill, or a quantizer change:</p>\n<ul><li><code>-7 … -2</code> ,<code>2 … 7</code> - coefficient value</li><li><code>0</code> - zero run, run length (<code>1 … 16</code> ) follows in the next nibble</li><li><code>1</code> - long zero run, run length (<code>17 … 288</code> ) follows in the next two nibbles</li><li><code>-1</code> - quantizer change, value follows in the next nibble</li><li><code>-8</code> - noise fill, length and amplitude follow in the next three nibbles</li></ul>\n<p>Everything is nibble aligned. This means the whole codec works without any\narbitrary bit reads or entropy decoding. Reading and\nunpacking a block of coefficients takes just <a href=\"https://github.com/Aikku93/ulc-codec/blob/b47df8d50c2ef2d765e5dbec0bf567b5e558173a/libulc/ulcDecoder.c#L99-L197\" rel=\"nofollow ugc noopener\">~150 lines of C</a>.</p>\n<p>Also note that noise fill is a valuable addition. Cymbals, hi-hats and snare\ndrums greatly benefit from that. MP3 does not have anything similar and \nneeds to encode quasi-random coefficients <em>as is</em>. </p>\n<p>ULC can produce <em>usable</em> results even at 16kbps. Quality of course suffers, but\nit might still be good enough for some applications.</p>\n<p>Aikku93 has been working on ULC since 2019 and has steadily improved the encoding quality. All code is permissively licensed. Time to try this on the N64 then!</p>\n<h2 id=\"ulc-on-the-n64\">ULC on the N64</h2>\n<p>I spent an evening in pre-LLM days compiling the ULC reference decoder for the N64 and producing a small demo. It worked without a hitch.</p>\n<p>The only problem: it was keeping the CPU very busy. Nothing was offloaded to the \nRSP. As a proof of concept, it wasn&#39;t doing much: we already knew the 93 MHz CPU\nwas enough to decode a transform-based codec, but we don&#39;t need a “music player”\nthat does nothing else. We need this for background music and spoken dialog\nduring gameplay. It <em>cannot</em> hog the CPU.</p>\n<h3 id=\"float-to-16-bit-fixed-point\">Float to 16-bit Fixed Point</h3>\n<p>Obviously the IMDCT needs to be moved to the RSP coprocessor instead. We could just DMA one block of decoded coefficients to the RSP&#39;s memory, do the transform and DMA the completed samples back to RDRAM into the output buffer.</p>\n<p>That&#39;s easier said than done, though. The RSP has only 4096 bytes of data memory (DMEM) and another 4096 bytes for instructions (IMEM). The vector instructions work in 16-bit or 32-bit fixed point, with no floats. The IMDCT will only be efficient if all the data for a transform fits into the RSP&#39;s DMEM at once. We also need some of the DMEM for temporary values and – if possible – the lapping buffer: half of the previously decoded block. So with the default 2048-sample block size of ULC, we&#39;re out of luck, even with 16-bit fixed point.</p>\n<p>While ULC can work with smaller MDCT block sizes, it was optimized for 2048, so\nwe should keep it as large as possible. On top of that, the ULC reference \nencoder/decoder uses floats, so the obvious choice would be 32-bit fixed point to\nmaintain quality, but 16-bit <em>may</em> work. So we have two options, both arriving\nat <code>3072 bytes</code>:</p>\n<ol><li>32-bit values, a 512-sample block size (256-sample lap buffer): <code>(512 + 256) * 4 bytes</code></li><li>16-bit values, a 1024-sample block size (512-sample lap buffer): <code>(1024 + 512) * 2 bytes</code></li></ol>\n<p>Using 16-bit fixed point would not only reduce the DMA traffic, but also speed up computation on the RSP. The trade-off would be a higher noise floor. How high? No idea. So I carefully refactored the reference decoder, still running on the N64 CPU, to work in 16-bit fixed point (Q1.14).</p>\n<p>After almost blowing my ears off a bunch of times, I got it working and could only hear (or imagine?) the faintest white noise when cranking it up. Case settled: 16-bit it is.</p>\n<h3 id=\"cramming-it-into-the-rsp\">Cramming it into the RSP</h3>\n<p>Now I <em>just</em> needed to port this C code to the RSP. My knowledge of MIPS\nassembly is very basic, and writing an RSP decoder would be a serious endeavor.</p>\n<p>This is where I took a hiatus from this project – I had a \n<a href=\"/log/2026/08/xibalba64-making-of\">game</a> to finish. When I returned earlier this \nyear LLMs have improved quite a bit. Still, I didn&#39;t\nexactly trust GPT-5 with it. In some previous experiments it did a very\nbad job, often ignoring delay slots and other intricacies of the RSP, never\nfinishing the job.</p>\n<p><em>(Aside: GPT-6 or Opus-5 would probably one-shot this now)</em></p>\n<p>So instead I opted for a more iterative approach. Max Bebök created a small\nC-like language to write code for the RSP, aptly named \n<a href=\"https://github.com/HailToDodongo/rspl\" rel=\"nofollow ugc noopener\">RSPL</a>. Armed with the language \ndocumentation, I asked Codex to translate the C code to RSPL piece by piece,\nalways verifying the result. It took a few days to port and land on an API \ndesign that made sense. Then in subsequent steps Codex further optimized the \nRSPL assembly output by first rewriting some parts (directly in assembly this time),\nthen minimizing pipeline stalls by <a href=\"https://github.com/phoboslab/rspopt\" rel=\"nofollow ugc noopener\">adapting</a>\nthe RSPL&#39;s optimizer.</p>\n<p>The end result is <a href=\"https://github.com/n64brew/libdragon/blob/preview/src/audio/rsp_ulc.S\" rel=\"nofollow ugc noopener\">~1400 lines of MIPS assembly</a>\nhandling the IMDCT, lapping, stereo interleaving and output scaling. It barely\nfits into the 4096 byte IMEM of the RSP.</p>\n<p>The <a href=\"https://github.com/n64brew/libdragon/blob/preview/src/audio/wav64_ulc.c\" rel=\"nofollow ugc noopener\">C side of the decoder</a> \nis still handwritten, but only because LLMs have no taste. The whole process\ntook me a few weeks, but I&#39;m still amazed that it worked at all.</p>\n<p><em>My</em></p>\n<p><a href=\"https://github.com/phoboslab/ulc64/\" rel=\"nofollow ugc noopener\">ulc64 demo</a>demonstrating quality at various bitrates\nTo make ULC easily seekable, I added a sparse table at the end of the file that contains the byte offset of every eighth frame. The decoder quickly skips ahead from the nearest frame to the desired one. This adds about 20 bytes per second – manageable even for 16kbps audio.</p>\n<p>ULC proved to be a <em>very</em> viable alternative to ADPCM and Opus on the N64. \nQuality and bitrate are close to those of Opus, but complexity is only 4x that of ADPCM. A\nsingle 44100 Hz stereo track costs about 4% of CPU time and 5% of RSP time.\nPerfectly usable for background music, speech, ambience and longer sound effects.</p>\n<p>The decoder works transparently in Libdragon, just like all other audio codecs. \nIt has been merged into the <a href=\"https://github.com/n64brew/libdragon/tree/preview\" rel=\"nofollow ugc noopener\">preview branch</a> a while ago.</p>\n<h2 id=\"addendum\">Addendum</h2>\n<p>A few days ago an excellent port of Half-Life for the N64 was published. \nThe <code>README</code> states:</p>\n<p>[...] libdragon&#39;s ULC audio codec for the 2,500 sounds and 27 music tracks, is what makes everything fit in one 64 MB cartridge image.</p>\n<p>~ <a href=\"https://github.com/ToxyCola/Half-Life-Nintendo-64-Port\" rel=\"nofollow ugc noopener\">github.com/ToxyCola/Half-Life-Nintendo-64-Port</a></p>\n<p>Many thanks to <a href=\"https://github.com/Aikku93\" rel=\"nofollow ugc noopener\">Aikku93</a> for creating ULC. It&#39;s a \nwonderful codec. I merely found and adapted it. I seek simplicity and elegance\nin everything I do and ULC is something I can truly adore. Kudos!</p>","headings":[{"level":1,"text":"Why this Obscure Audio Codec is a Perfect Fit for the N64","id":"why-this-obscure-audio-codec-is-a-perfect-fit-for-the-n64"},{"level":2,"text":"Audio in the Open Source Libdragon","id":"audio-in-the-open-source-libdragon"},{"level":2,"text":"The Ultra Low Complexity Codec","id":"the-ultra-low-complexity-codec"},{"level":2,"text":"ULC on the N64","id":"ulc-on-the-n64"},{"level":3,"text":"Float to 16-bit Fixed Point","id":"float-to-16-bit-fixed-point"},{"level":3,"text":"Cramming it into the RSP","id":"cramming-it-into-the-rsp"},{"level":2,"text":"Addendum","id":"addendum"}]}}