mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-06-27 20:59:36 +00:00
music
This commit is contained in:
144
Core/Inc/Sound.h
144
Core/Inc/Sound.h
@ -13,8 +13,6 @@
|
||||
// Define default timer and channels
|
||||
#define SOUND_TIMER TIM4
|
||||
#define SOUND_TIMER_RCC RCC_APB1ENR_TIM4EN
|
||||
#define SOUND_CHANNEL_1 3 // TIM4 Channel 3
|
||||
#define SOUND_CHANNEL_2 4 // TIM4 Channel 4
|
||||
|
||||
// Define the Note structure
|
||||
typedef struct {
|
||||
@ -25,34 +23,142 @@ typedef struct {
|
||||
|
||||
// Enum for musical notes
|
||||
typedef enum {
|
||||
NOTE_C4 = 261,
|
||||
NOTE_D4 = 293,
|
||||
NOTE_E4 = 329,
|
||||
NOTE_F4 = 349,
|
||||
NOTE_G4 = 392,
|
||||
NOTE_A4 = 440,
|
||||
NOTE_B4 = 493,
|
||||
NOTE_C5 = 523,
|
||||
// Add more notes as needed
|
||||
NOTE_REST = 0
|
||||
C0 = 16,
|
||||
C0_sharp = 17,
|
||||
D0 = 18,
|
||||
D0_sharp = 19,
|
||||
E0 = 21,
|
||||
F0 = 22,
|
||||
F0_sharp = 23,
|
||||
G0 = 25,
|
||||
G0_sharp = 26,
|
||||
A0 = 28,
|
||||
A0_sharp = 29,
|
||||
B0 = 31,
|
||||
|
||||
C1 = 33,
|
||||
C1_sharp = 35,
|
||||
D1 = 37,
|
||||
D1_sharp = 39,
|
||||
E1 = 41,
|
||||
F1 = 44,
|
||||
F1_sharp = 46,
|
||||
G1 = 49,
|
||||
G1_sharp = 52,
|
||||
A1 = 55,
|
||||
A1_sharp = 58,
|
||||
B1 = 62,
|
||||
|
||||
C2 = 65,
|
||||
C2_sharp = 69,
|
||||
D2 = 73,
|
||||
D2_sharp = 78,
|
||||
E2 = 82,
|
||||
F2 = 87,
|
||||
F2_sharp = 92,
|
||||
G2 = 98,
|
||||
G2_sharp = 104,
|
||||
A2 = 110,
|
||||
A2_sharp = 117,
|
||||
B2 = 123,
|
||||
|
||||
C3 = 130,
|
||||
C3_sharp = 138,
|
||||
D3 = 146,
|
||||
D3_sharp = 155,
|
||||
E3 = 164,
|
||||
F3 = 174,
|
||||
F3_sharp = 185,
|
||||
G3 = 196,
|
||||
G3_sharp = 207,
|
||||
A3 = 220,
|
||||
A3_sharp = 233,
|
||||
B3 = 246,
|
||||
|
||||
C4 = 261,
|
||||
C4_sharp = 277,
|
||||
D4 = 293,
|
||||
D4_sharp = 311,
|
||||
E4 = 329,
|
||||
F4 = 349,
|
||||
F4_sharp = 369,
|
||||
G4 = 392,
|
||||
G4_sharp = 415,
|
||||
A4 = 440,
|
||||
A4_sharp = 466,
|
||||
B4 = 493,
|
||||
|
||||
C5 = 523,
|
||||
C5_sharp = 554,
|
||||
D5 = 587,
|
||||
D5_sharp = 622,
|
||||
E5 = 659,
|
||||
F5 = 698,
|
||||
F5_sharp = 740,
|
||||
G5 = 784,
|
||||
G5_sharp = 830,
|
||||
A5 = 880,
|
||||
A5_sharp = 932,
|
||||
B5 = 987,
|
||||
|
||||
C6 = 1046,
|
||||
C6_sharp = 1108,
|
||||
D6 = 1174,
|
||||
D6_sharp = 1244,
|
||||
E6 = 1318,
|
||||
F6 = 1396,
|
||||
F6_sharp = 1480,
|
||||
G6 = 1568,
|
||||
G6_sharp = 1661,
|
||||
A6 = 1760,
|
||||
A6_sharp = 1864,
|
||||
B6 = 1975,
|
||||
|
||||
C7 = 2093,
|
||||
C7_sharp = 2217,
|
||||
D7 = 2349,
|
||||
D7_sharp = 2489,
|
||||
E7 = 2637,
|
||||
F7 = 2793,
|
||||
F7_sharp = 2960,
|
||||
G7 = 3136,
|
||||
G7_sharp = 3322,
|
||||
A7 = 3520,
|
||||
A7_sharp = 3729,
|
||||
B7 = 3951,
|
||||
|
||||
C8 = 4186,
|
||||
C8_sharp = 4435,
|
||||
D8 = 4699,
|
||||
D8_sharp = 4978
|
||||
} MusicalNote_t;
|
||||
|
||||
|
||||
// Enum for note durations (in fractions of a whole note)
|
||||
typedef enum {
|
||||
DURATION_WHOLE = 1,
|
||||
DURATION_HALF = 2,
|
||||
DURATION_QUARTER = 4,
|
||||
DURATION_EIGHTH = 8,
|
||||
DURATION_SIXTEENTH = 16
|
||||
// Add more durations as needed
|
||||
T0 = 0, // Infinite
|
||||
T1 = 1, // Whole note
|
||||
T2 = 2, // Half note
|
||||
T4 = 4, // Quarter note
|
||||
T8 = 8, // Eighth note
|
||||
T16 = 16 // Sixteenth note
|
||||
} NoteDuration_t;
|
||||
|
||||
// Structure for melody playback
|
||||
typedef struct {
|
||||
Note_t* notes; // Pointer to an array of notes
|
||||
uint32_t size; // Number of notes in the melody
|
||||
uint32_t current_note; // Index of the current note
|
||||
uint32_t repeat_count; // Total repeat count
|
||||
uint32_t repeat_left; // Repeats left
|
||||
} Melody_t;
|
||||
|
||||
// Function declarations
|
||||
void sound_init(void);
|
||||
void sound_set_bpm(uint32_t bpm);
|
||||
void sound_play_note(Note_t note, uint8_t channel);
|
||||
void sound_play_melody(Note_t* melody, uint32_t size, uint8_t channel, uint32_t repeat_count);
|
||||
void sound_tick(void);
|
||||
Note_t sound_create_note(MusicalNote_t note, NoteDuration_t duration, uint8_t duty_cycle);
|
||||
|
||||
|
||||
#endif /* INC_SOUND_H_ */
|
||||
|
Reference in New Issue
Block a user