Skip to content

Instantly share code, notes, and snippets.

@YuxiUx
YuxiUx / midi-note-to-freq.md
Last active May 20, 2023 07:09
How to convert midi note to frequency in C, C++, Python, JS and PHP

JS

function noteToFreq(note) {
    let a = 440; //frequency of A (coomon value is 440Hz)
    return (a / 32) * (2 ** ((note - 9) / 12));
}

PHP

function noteToFreq($note) {
@YuxiUx
YuxiUx / midi_note_int.c
Created May 16, 2018 14:56
Midi note to frequency array (rounded to int) A = 440Hz
int midiNote[] = {8, 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 15, 16, 17, 18, 19, 21, 22, 23, 24, 26, 28, 29, 31, 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, 65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, 4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902, 8372, 8870, 9397, 9956, 10548, 11175, 11840, 12544};
@YuxiUx
YuxiUx / midi_note_float.c
Created May 16, 2018 14:51
Midi note to frequency array (2 decimals) A = 440Hz
float midiNote[] = {8.18, 8.66, 9.18, 9.72, 10.3, 10.91, 11.56, 12.25, 12.98, 13.75, 14.57, 15.43, 16.35, 17.32, 18.35, 19.45, 20.6, 21.83, 23.12, 24.5, 25.96, 27.5, 29.14, 30.87, 32.7, 34.65, 36.71, 38.89, 41.2, 43.65, 46.25, 49.0, 51.91, 55.0, 58.27, 61.74, 65.41, 69.3, 73.42, 77.78, 82.41, 87.31, 92.5, 98.0, 103.83, 110.0, 116.54, 123.47, 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.0, 196.0, 207.65, 220.0, 233.08, 246.94, 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.0, 415.3, 440.0, 466.16, 493.88, 523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880.0, 932.33, 987.77, 1046.5, 1108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760.0, 1864.66, 1975.53, 2093.0, 2217.46, 2349.32, 2489.02, 2637.02, 2793.83, 2959.96, 3135.96, 3322.44, 3520.0, 3729.31, 3951.07, 4186.01, 4434.92, 4698.64, 4978.03, 5274.04, 5587.65, 5919.91, 6271.93, 6644.88, 7040.0, 7458.62, 7902.13, 8372.02, 8869.84, 9397.27, 9956.06, 10548.08, 11175.3, 11839.82, 12543.85};
@YuxiUx
YuxiUx / midi_note_fullfloat.c
Last active May 16, 2018 14:52
Midi note to frequency array (15 decimals) A = 440Hz
float midiNote[] = {8.175798915643707, 8.661957218027252, 9.177023997418987, 9.722718241315029, 10.300861153527185, 10.913382232281371, 11.562325709738575, 12.249857374429665, 12.978271799373285, 13.75, 14.56761754744031, 15.433853164253879, 16.351597831287414, 17.323914436054505, 18.354047994837973, 19.445436482630058, 20.60172230705437, 21.826764464562743, 23.12465141947715, 24.49971474885933, 25.95654359874657, 27.5, 29.13523509488062, 30.867706328507758, 32.70319566257483, 34.64782887210901, 36.70809598967595, 38.890872965260115, 41.20344461410874, 43.653528929125486, 46.2493028389543, 48.99942949771866, 51.91308719749314, 55.0, 58.27047018976124, 61.7354126570155, 65.40639132514966, 69.29565774421802, 73.41619197935188, 77.78174593052023, 82.4068892282175, 87.30705785825097, 92.4986056779086, 97.99885899543733, 103.82617439498628, 110.0, 116.54094037952248, 123.470825314031, 130.8127826502993, 138.59131548843604, 146.83238395870376, 155.56349186104046, 164.813778456435, 174.61411571650194, 184.9972113558
@YuxiUx
YuxiUx / Set static IP on raspberry.md
Last active May 11, 2018 23:35
How to set static IP in Raspbian

Set static IP in Raspbian

It's work on all relases since 2016
Not edit /etc/network/interfaces !

Open /etc/dhcpcd.conf

sudo nano /etc/dhcpcd.conf 

Scroll to bottom of this file and add your config as is explained in example.

  • Interface values eth0 for lan(cable), wlan0 for wirless(wifi)
@YuxiUx
YuxiUx / sync_fork.sh
Last active April 21, 2018 20:21
Update forked repository from original
# First cd root of forked project.
git fetch upstream
git checkout master
git merge upstream/master
# if everything is ok
git push
# In normal situation you can simply run this file
#$ bash sync_fork.sh
# HELP: Before first use you must configure reference to original project
#$ git remote add upstream https://github.com/<original-author>/<repository>.git
@YuxiUx
YuxiUx / RGB_colors.txt
Created April 20, 2018 11:16
List of 746 common colors and RGB codes. Simpe parsable to another format like json, py etc. (divided by "\t ").
Air Force blue (93, 138, 168)
Alice blue (240, 248, 255)
Alizarin crimson (227, 38, 54)
Almond (239, 222, 205)
Amaranth (229, 43, 80)
Amber (255, 191, 0)
American rose (255, 3, 62)
Amethyst (153, 102, 204)
Android Green (164, 198, 57)
Anti-flash white (242, 243, 244)