Skip to content

Instantly share code, notes, and snippets.

@StartAutomating
Created July 11, 2026 20:42
Show Gist options
  • Select an option

  • Save StartAutomating/2d34b2ffd4116b0ce9cb601512d9ca82 to your computer and use it in GitHub Desktop.

Select an option

Save StartAutomating/2d34b2ffd4116b0ce9cb601512d9ca82 to your computer and use it in GitHub Desktop.
Gist tell me the musical note frequency
<#
.SYNOPSIS
The Note Frequencys
.DESCRIPTION
The frequencies for musical notes.
.NOTES
Adapted from the [Web Audio API Keyboard Synth](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Simple_synth)
.LINK
https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Simple_synth
#>
param(
[byte]
$MaxOctave = 7
)
# We hard code the first octave and below
$noteFrequency = [Ordered]@{
A0 = 27.5
"A0#" = 29.13523509488062
B0 = 30.867706328507754
C1 = 32.70319566257483
"C1#" = 34.64782887210901
D1 = 36.70809598967595
"D1#" = 38.89087296526011
E1 = 41.20344461410874
F1 = 43.65352892912549
"F1#" = 46.2493028389543
"G1" = 48.99942949771866
"G1#" = 51.91308719749314
"A1" = 55
"A1#" = 58.27047018976124
"B1" = 61.73541265701551
}
# For every additional octave
for ($octave = 2; $octave -le $MaxOctave; $octave++) {
# get our notes in order
$lastOctaveKeys = @($noteFrequency.Keys -match $($octave - 1))
# go over each last note
foreach ($lastOctave in $lastOctaveKeys) {
# map the next note as double
$noteFrequency["$($lastOctave -replace $(
$octave - 1
), $octave)"] = $noteFrequency[$lastOctave] * 2
}
}
# Add one more note for the final C
$noteFrequency["C$($MaxOctave + 1)"] = $noteFrequency."C$($MaxOctave)" * 2
return $noteFrequency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment