
Show HN: 19 Tone Equal Temperament Piano in Web Audio - outputchannel
https://academo.org/demos/19-tet-keyboard/
======
jarmitage
This library and web audio demo has 3000+ tuning systems:

[https://github.com/abbernie/tune](https://github.com/abbernie/tune)

It's part of the proceedings of the 2nd Web Audio conference which are now
available:

Abstract:
[https://smartech.gatech.edu/handle/1853/54580](https://smartech.gatech.edu/handle/1853/54580)

Proceedings:
[https://smartech.gatech.edu/handle/1853/54577/browse](https://smartech.gatech.edu/handle/1853/54577/browse)

------
amelius
Is there something that makes 12 special? I am no expert in music theory, but
I can imagine that it could be useful that 12 has many factors: 12 = 2x2x3.
Since 19 is prime, would that be a bad choice?

~~~
s-phi-nl
There are some mathematical reasons.

In particular, the two most consonant (best-sounding) intervals are the octave
and the fifth. The frequencies of the two pitches in an octave have a ratio of
2.0, and the frequencies of the two pitches in a pure fifth have a ratio of
1.5.

We would like the pitches we obtain from powers of these two ratios (stacking
these intervals on top of each other) to be the same. However, since the
integers are a unique factorization domain, they will never be (except for 2^0
= 1 = 1.5^0, of course). [1]

Thus, we pick powers of the two that are 'close enough' and call those the
same pitch. The following Python (3) code subtracts the log-base-two of the
powers of 1.5 from the integer they round to in order to find the closest
ones:

    
    
      from math import log
      
      fifth = log(3/2, 2.0)
      
      print(0, 0.0)
      
      minDist = 0.08
      for i in range(1,100):
          pow = i* fifth;
          dist = abs(pow - round(pow)) 
          if dist < minDist:
              minDist = dist
              print(i, pow, dist)
    

This has output:

    
    
      0 0.0
      5 2.924812503605781 0.07518749639421918
      12 7.019550008653875 0.019550008653874684
      41 23.983462529567404 0.01653747043259557
      53 31.003012538221277 0.003012538221277339
    

From this, you can see that 12 is the closest that the powers of 2.0 and of
1.5 come being equal until 41. This is a primary reason why we use a chromatic
scale with 12 notes.

(As an aside, a scale with 5 notes is also common around the world, called the
pentatonic scale [2])

[1] For an explanation of this, see
[http://blogs.scientificamerican.com/roots-of-unity/the-
sadde...](http://blogs.scientificamerican.com/roots-of-unity/the-saddest-
thing-i-know-about-the-integers/)

[2]
[https://en.wikipedia.org/wiki/Pentatonic_scale](https://en.wikipedia.org/wiki/Pentatonic_scale)

~~~
biot
The TED video on the pentatonic scale by Bobby McFerrin is worth watching.
Only 3 minutes long:
[http://youtu.be/ne6tB2KiZuk](http://youtu.be/ne6tB2KiZuk)

------
grncdr
Very cool. You might consider adding a short (a few ms is enough) fade in/out
when toggling notes to avoid clickiness.

~~~
Kristine1975
A few _samples_ is enough, actually. Just enough to prevent the sudden change
from high to low, which is what causes the click.

You don't even need to compute new samples. Merely repeat the last sample
while lowering its volume until you reach zero.

------
6stringmerc
Very clever and quite fun to poke around in, and educational with the whole
math breakdown. Nicely done and glad to be able to play around with it. I'm
tickled by the opportunities to play around with customary tones!

Z-R-V-Z-R-B-Z-R-N-Z-R-B-Z-R-V is a nifty little arrangement.

------
ableal
Another interesting page in the site: [https://academo.org/demos/perlin-
noise/](https://academo.org/demos/perlin-noise/)

Made me look it up:
[https://en.wikipedia.org/wiki/Perlin_noise](https://en.wikipedia.org/wiki/Perlin_noise)

Smooth.

------
bobajeff
I tried this on my phone (via Chrome for Android). The keys didn't do anything
when I pressed them.

~~~
moron4hire
If you just want to play around, I wrote a keyboard that works in Chrome as
well as Firefox on Android back in November.

[http://s.codepen.io/SeanMcBeth/debug/meaQvj](http://s.codepen.io/SeanMcBeth/debug/meaQvj)

------
mattmanser
There's a bug where if you mouse down and move the mouse out, the note plays
indefinitely.

~~~
abruzzi
is that a bug? I was using that to hear chord, until I got to the bottom and
saw I can also do it with my keyboard.

~~~
kencausey
I agree, seemed like a feature to me.

------
hatsunearu
The tones in the piano don't have a lot of harmonic content (at least what I
can hear from my ears), and if there are more harmonics the beating of the
harmonics can be more easily heard. Just a suggestion.

