tinkeros / TinkerOS

Home of TinkerOS a fork of TempleOS
http://tinkeros.github.io
The Unlicense
213 stars 18 forks source link

Psalmody key frequencies #6

Closed 8dcc closed 1 year ago

8dcc commented 1 year ago

Hello, first of all I wanted to thank you for making suck a great fork of TempleOS.

I am making my own operative system (not related to TempleOS or HolyC, but still inspired by it) and I just finished adding my own piano app. It's pretty simple but it is able to play frequencies using my own keyboard and pc speaker functions. I was trying to read through your psalmody source code trying to find the pc speaker frequencies being used, but I could not find it since it's hard for me to understand how the program works.

Could you tell me where they are, or if it's more complicated, how it works?

Thank you.

tinkeros commented 1 year ago

The code isn't mine, Terry wrote it. I'll tell you what I know, hopefully it will help you find what you need. Every note corresponds to an 8-bit value he calls an "ona." There are two functions that convert between his ona values and frequencies Ona2Freq and Freq2Ona. As far as how the songs work, you would want to look at his Play function where he parses the strings of song notes and converts them into ona values to play.

8dcc commented 1 year ago

I know Terry wrote the original program, but I didn't know if you made any changes to it.

Looks like Ona2Freq and Freq2Ona is what I was looking for. I had a look at this switch statement, but I didn't know what "ona" meant.

Thank you for the quick reply and keep up the good work.

8dcc commented 1 year ago

I have been messing with the functions and looking at the code and, if I haven't missed anything, these are the psalmody keys, note names, ona values and frequencies:

Key:
      +---+---+---+   +---+---+   +---+---+---+
      | E | R | T |   | U | I |   | P | [ | ] |
+---+---+---+---+---+---+---+---+---+---+---+-+
| A | S | D | F | G | H | J | K | L | ; | ' |
+---+---+---+---+---+---+---+---+---+---+---+

Note:
        +----+----+----+    +----+----+    +----+----+----+
        | F# | G# | A# |    | C# | D# |    | F# | G# | A# |
+----+----+----+----+----+----+----+----+----+----+----+--+
| E  | F  | G  | A  | B  | C  | D  | E  | F  | G  | A  |
+----+----+----+----+----+----+----+----+----+----+----+

Ona:
        +----+----+----+    +----+----+    +----+----+----+
        | 45 | 47 | 49 |    | 52 | 54 |    | 57 | 59 | 61 |
+----+----+----+----+----+----+----+----+----+----+----+--+
| 43 | 44 | 46 | 48 | 50 | 51 | 53 | 55 | 56 | 58 | 60 |
+----+----+----+----+----+----+----+----+----+----+----+

Freq:
         +-----+-----+-----+     +-----+-----+     +-----+-----+-----+
         |184.9|207.6|233.0|     |277.1|311.1|     |369.9|415.3|466.1|
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--+
|164.8|174.6|195.9|220.0|246.9|261.6|293.6|329.6|349.2|391.9|440.0|
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
tinkeros commented 1 year ago

These are correct assuming you set octave 3. The default is octave 4 so for the default condition the app starts in all the ona values above should have 12 added to them and all the frequencies should be double what they are.

8dcc commented 1 year ago

I thought the default octave was 3, thank you. I am also making my own shell and I just finished argument support, so I will probably make it so my piano app gets the user's octave from there.