Skip to content

Instantly share code, notes, and snippets.

@bryc
bryc / YamahaFM.md
Last active April 13, 2024 09:03
Collecting info on Yamaha FM soundchips

DX7

image

Note: One of the algorithms is incorrect due to a missing operator. Need to update the image. Will have to get on that soon.

These are the original 32 algorithms as used in Yamaha DX7.

The later Yamaha FS1R and Yamaha SY77 may have compatibility with these algorithms, but that's beyond the current scope. The FS1R contains 88 algorithms, while the SY77 contains 45 algorithms.

@bryc
bryc / Adler-32.js
Last active March 10, 2024 07:03
legit checksums
// Adler-32
// Appears simpler than Fletcher, yet even better (possibly due to a = 1).
function adler32(data) {
var a = 1, b = 0;
for (var i = 0; i < data.length; i++) {
a = (a + data[i]) % 65521;
b = (b + a) % 65521;
}
return a | (b << 16);
}
@bryc
bryc / arrstr.js
Last active February 27, 2024 09:29
Various useful js JavaScript snippets I use often - Credit = bryc.github.io
// #### ARRAY <-> STRING CONVERSION ####
// b62 - reversible base62 encoder/decoder in two lines.
function b62(n,c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"){var r="",l=c.length,i=0;
if(n.trim)while(i<n.length)r=l*r+c.indexOf(n[i++]);else while(n>0)r=c[n%l]+r,n=Math.floor(n/l);return r}
// arst is a reversible string<>array utility in one line. It converts a string to an array of integers and back.
// ES6 (shorter)
arst=a=>{return a.trim?[...a].map(a=>a.charCodeAt()):String.fromCharCode.apply(0,a)}
@bryc
bryc / st.txt
Created November 20, 2019 22:47
Scream Tracker Manual (1990)
Scream Tracker
<<<<< USERS MANUAL >>>>>
(C) 1990 Sami Tammilehto
==============================================================================
@bryc
bryc / links.xml
Last active October 15, 2023 14:44
Text stuff - Online code editors, chiptunes etc
@bryc
bryc / crc16.js
Last active May 8, 2023 03:15
Optimized CRC implementations in JavaScript
/*
Optimized CRC-16 for 0x1021 (unreflected)
----
With this code, (5) CRC-16 variants can be modelled:
crc=0x0000, xorout=0x0000 = CRC-16/XMODEM (default)
crc=0xFFFF, xorout=0x0000 = CRC-16/IBM-3740
crc=0xFFFF, xorout=0xFFFF = CRC-16/GENIBUS
crc=0x0000, xorout=0xFFFF = CRC-16/GSM
@bryc
bryc / checksums.js
Last active December 15, 2022 09:03
CHECKSUMS!
// BSD-16
// From: en.wikipedia.org/wiki/BSD_checksum
function bsd16(data) {
for(var i = 0, c = 0; i < data.length; i++) {
c = (c>>1) + ((c&1) << 15);
c += data[i];
c &= 0xffff;
}
return c;
}
@bryc
bryc / crc.js
Last active July 18, 2022 13:13
CRC
/*
Cyclic redundancy check (CRC-4, CRC-8, CRC-16, CRC-32)
Common CRC implementation supporting wide range of configurations:
http://reveng.sourceforge.net/crc-catalogue/all.htm
NOTE: These common polynomials are likely suboptimal.
In the future I should make a page of Koopman's best general purpose polynomials.
http://github.com/bryc
@bryc
bryc / alea.js
Last active March 15, 2022 12:01
PRNGs
/*
Optimized Alea
----------------------
Based on Alea by Johannes Baagøe (2010) which is based on MWC by George Marsaglia and Arif Zaman (1991).
Should be fast and pass BigCrush statistical test suite. It's quite fast but the quality is unverified.
Used like so:
var rand = Alea("test123");
rand(); // 0.7390809920616448
rand(); // 0.3916741746943444