mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Added pcspk.h for PC Speaker and notes.h that contains notes and their frequencies
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
#ifndef NOTES_H
|
||||
#define NOTES_H
|
||||
|
||||
/*
|
||||
|
||||
0 1 2 3 4 5 6 7 8
|
||||
C 16.35 32.7 65.41 130.81 261.63 523.25 1046.5 2093 4186
|
||||
C# 17.32 34.65 69.3 138.59 277.18 554.37 1108.73 2217.46 4434.92
|
||||
D 18.35 36.71 73.42 146.83 293.66 587.33 1174.66 2349.32 4698.63
|
||||
D# 19.45 38.89 77.78 155.56 311.13 622.25 1244.51 2489 4978
|
||||
E 20.6 41.2 82.41 164.81 329.63 659.25 1318.51 2637 5274
|
||||
F 21.83 43.65 87.31 174.61 349.23 698.46 1396.91 2793.83 5587.65
|
||||
F# 23.12 46.25 92.5 185 369.99 739.99 1479.98 2959.96 5919.91
|
||||
G 24.5 49 98 196 392 783.99 1567.98 3135.96 6271.93
|
||||
G# 25.96 51.91 103.83 207.65 415.3 830.61 1661.22 3322.44 6644.88
|
||||
A 27.5 55 110 220 440 880 1760 3520 7040
|
||||
A# 29.14 58.27 116.54 233.08 466.16 932.33 1864.66 3729.31 7458.62
|
||||
B 30.87 61.74 123.47 246.94 493.88 987.77 1975.53 3951 7902.13
|
||||
*/
|
||||
|
||||
// Note frequencies in Hz (rounded down)
|
||||
// b - Flat
|
||||
// s - Sharp (#)
|
||||
typedef enum {
|
||||
// 2nd Octave
|
||||
C2 = 65,
|
||||
Cs2 = 69,
|
||||
Db2 = Cs2,
|
||||
D2 = 73,
|
||||
Ds2 = 77,
|
||||
Eb2 = Ds2,
|
||||
E2 = 82,
|
||||
F2 = 87,
|
||||
Fs2 = 92,
|
||||
Gb2 = Fs2,
|
||||
G2 = 98,
|
||||
Gs2 = 103,
|
||||
Ab2 = Gs2,
|
||||
A2 = 110,
|
||||
As2 = 116,
|
||||
Hb2 = As2,
|
||||
H2 = 123,
|
||||
// 3rd Octave
|
||||
C3 = 130,
|
||||
Cs3 = 138,
|
||||
Db3 = Cs3,
|
||||
D3 = 146,
|
||||
Ds3 = 155,
|
||||
Eb3 = Ds3,
|
||||
E3 = 164,
|
||||
F3 = 174,
|
||||
Fs3 = 185,
|
||||
Gb3 = Fs3,
|
||||
G3 = 196,
|
||||
Gs3 = 207,
|
||||
Ab3 = Gs3,
|
||||
A3 = 220,
|
||||
As3 = 233,
|
||||
Hb3 = As3,
|
||||
H3 = 246,
|
||||
// 4th Octave
|
||||
C4 = 261,
|
||||
Cs4 = 277,
|
||||
Db4 = Cs4,
|
||||
D4 = 293,
|
||||
Ds4 = 311,
|
||||
Eb4 = Ds4,
|
||||
E4 = 329,
|
||||
F4 = 349,
|
||||
Fs4 = 370,
|
||||
Gb4 = Fs4,
|
||||
G4 = 392,
|
||||
Gs4 = 415,
|
||||
Ab4 = Gs4,
|
||||
A4 = 440, // Standard A, 440Hz
|
||||
As4 = 466,
|
||||
Hb4 = As4,
|
||||
H4 = 493,
|
||||
// 5th Octave
|
||||
C5 = 523,
|
||||
Cs5 = 554,
|
||||
Db5 = Cs5,
|
||||
D5 = 587,
|
||||
Ds5 = 622,
|
||||
Eb5 = Ds5,
|
||||
E5 = 659,
|
||||
F5 = 698,
|
||||
Fs5 = 739,
|
||||
Gb5 = Fs5,
|
||||
G5 = 783,
|
||||
Gs5 = 830,
|
||||
Ab5 = Gs5,
|
||||
A5 = 880,
|
||||
As5 = 932,
|
||||
Hb5 = As5,
|
||||
H5 = 987,
|
||||
} note_t;
|
||||
|
||||
typedef enum {
|
||||
WHOLE = 1,
|
||||
HALF = 2,
|
||||
QUARTER = 4,
|
||||
EIGHT = 8,
|
||||
SIXTEENTH = 16,
|
||||
THIRTYSECONDTH = 32,
|
||||
} beatType_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef PCSPK_H
|
||||
#define PCSPK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sound/notes.h>
|
||||
#include <interrupt/pit.h>
|
||||
#include <ports/io.h>
|
||||
#include <time.h>
|
||||
|
||||
#define PC_SPEAKER 0x61
|
||||
|
||||
void enableSpeaker() {
|
||||
uint8_t temp = inb(PC_SPEAKER);
|
||||
outb(PC_SPEAKER, temp | 0x03); // Set first 2 bits
|
||||
}
|
||||
|
||||
void disableSpeaker() {
|
||||
uint8_t temp = inb(PC_SPEAKER);
|
||||
outb(PC_SPEAKER, temp & 0xfc); // Set first 2 bits
|
||||
}
|
||||
|
||||
void playNote(note_t note, uint32_t ms) {
|
||||
setPitPhase(2, 3, note);
|
||||
sleep(ms);
|
||||
}
|
||||
|
||||
void rest(uint32_t ms) {
|
||||
setPitPhase(2, 3, 30000); // Unhearable noise
|
||||
sleep(ms);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user