рефакторинг мелодий и добавление звуковых эффектов (не проверены)
This commit is contained in:
@@ -39,8 +39,7 @@ void Melody_Init(MelodyHandle* mh, TIM_HandleTypeDef* htim, uint32_t channel, ui
|
|||||||
mh->htim = htim;
|
mh->htim = htim;
|
||||||
mh->channel = channel;
|
mh->channel = channel;
|
||||||
mh->timer_clock_hz = timer_clock_hz;
|
mh->timer_clock_hz = timer_clock_hz;
|
||||||
mh->sequence = NULL;
|
mh->melody = NULL;
|
||||||
mh->length = 0;
|
|
||||||
mh->current_index = 0;
|
mh->current_index = 0;
|
||||||
mh->note_start_time = 0;
|
mh->note_start_time = 0;
|
||||||
mh->is_playing = 0;
|
mh->is_playing = 0;
|
||||||
@@ -57,20 +56,19 @@ void Melody_SetBPM(MelodyHandle* mh, uint16_t bpm) {
|
|||||||
mh->bpm = bpm;
|
mh->bpm = bpm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Melody_Play(MelodyHandle* mh, const Note* sequence, uint16_t length, uint16_t bpm) {
|
void Melody_Play(MelodyHandle* mh, Melody_t *melody, uint16_t bpm) {
|
||||||
if (mh->is_playing) {
|
if (mh->is_playing) {
|
||||||
_set_freq(mh, 0);
|
_set_freq(mh, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
mh->sequence = sequence;
|
mh->melody = melody;
|
||||||
mh->length = length;
|
|
||||||
mh->current_index = 0;
|
mh->current_index = 0;
|
||||||
mh->is_playing = 1;
|
mh->is_playing = 1;
|
||||||
mh->note_start_time = HAL_GetTick();
|
mh->note_start_time = HAL_GetTick();
|
||||||
mh->bpm = bpm;
|
mh->bpm = bpm;
|
||||||
|
|
||||||
if (length > 0 && sequence[0].freq != 0) {
|
if (melody->length > 0 && melody->sequence[0].freq != 0) {
|
||||||
_set_freq(mh, sequence[0].freq);
|
_set_freq(mh, melody->sequence[0].freq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,22 +81,22 @@ void Melody_Update(MelodyHandle* mh) {
|
|||||||
if (!mh->is_playing) return;
|
if (!mh->is_playing) return;
|
||||||
|
|
||||||
uint32_t now = HAL_GetTick();
|
uint32_t now = HAL_GetTick();
|
||||||
uint32_t dur_ms = _duration_to_ms(mh, mh->sequence[mh->current_index].duration);
|
uint32_t dur_ms = _duration_to_ms(mh, mh->melody->sequence[mh->current_index].duration);
|
||||||
|
|
||||||
if (now - mh->note_start_time >= dur_ms) {
|
if (now - mh->note_start_time >= dur_ms) {
|
||||||
mh->current_index++;
|
mh->current_index++;
|
||||||
|
|
||||||
if (mh->current_index >= mh->length) {
|
if (mh->current_index >= mh->melody->length) {
|
||||||
Melody_Stop(mh);
|
Melody_Stop(mh);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mh->note_start_time = now;
|
mh->note_start_time = now;
|
||||||
|
|
||||||
if (mh->sequence[mh->current_index].freq == NOTE_REST) {
|
if (mh->melody->sequence[mh->current_index].freq == NOTE_REST) {
|
||||||
__HAL_TIM_SET_COMPARE(mh->htim, mh->channel, 0);
|
__HAL_TIM_SET_COMPARE(mh->htim, mh->channel, 0);
|
||||||
} else {
|
} else {
|
||||||
_set_freq(mh, mh->sequence[mh->current_index].freq);
|
_set_freq(mh, mh->melody->sequence[mh->current_index].freq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,14 @@
|
|||||||
#define MELODY_H
|
#define MELODY_H
|
||||||
|
|
||||||
#include "stm32f1xx_hal.h"
|
#include "stm32f1xx_hal.h"
|
||||||
|
#include "songs.h"
|
||||||
typedef struct {
|
//#include "sounds.h"
|
||||||
uint16_t freq; // частота в Гц или NOTE_REST
|
|
||||||
float duration; // длительность в долях (0.25 = четверть)
|
|
||||||
} Note;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TIM_HandleTypeDef* htim;
|
TIM_HandleTypeDef* htim;
|
||||||
uint32_t channel;
|
uint32_t channel;
|
||||||
uint32_t timer_clock_hz; // частота тактирования таймера в Гц
|
uint32_t timer_clock_hz; // частота тактирования таймера в Гц
|
||||||
const Note* sequence;
|
Melody_t *melody;
|
||||||
uint16_t length;
|
|
||||||
uint16_t current_index;
|
uint16_t current_index;
|
||||||
uint32_t note_start_time;
|
uint32_t note_start_time;
|
||||||
uint8_t is_playing;
|
uint8_t is_playing;
|
||||||
@@ -22,154 +18,9 @@ typedef struct {
|
|||||||
|
|
||||||
void Melody_Init(MelodyHandle* mh, TIM_HandleTypeDef* htim, uint32_t channel, uint32_t timer_clock_hz);
|
void Melody_Init(MelodyHandle* mh, TIM_HandleTypeDef* htim, uint32_t channel, uint32_t timer_clock_hz);
|
||||||
void Melody_SetBPM(MelodyHandle* mh, uint16_t bpm);
|
void Melody_SetBPM(MelodyHandle* mh, uint16_t bpm);
|
||||||
void Melody_Play(MelodyHandle* mh, const Note* sequence, uint16_t length, uint16_t bpm);
|
void Melody_Play(MelodyHandle* mh, Melody_t* melody, uint16_t bpm);
|
||||||
void Melody_Stop(MelodyHandle* mh);
|
void Melody_Stop(MelodyHandle* mh);
|
||||||
void Melody_Update(MelodyHandle* mh);
|
void Melody_Update(MelodyHandle* mh);
|
||||||
uint8_t Melody_IsPlaying(MelodyHandle* mh);
|
uint8_t Melody_IsPlaying(MelodyHandle* mh);
|
||||||
|
|
||||||
// Длительности (в долях от целой ноты)
|
|
||||||
#define NOTE_WHOLE 1.0
|
|
||||||
#define NOTE_HALF 0.5
|
|
||||||
#define NOTE_QUARTER 0.25
|
|
||||||
#define NOTE_EIGHTH 0.125
|
|
||||||
#define NOTE_SIXTEENTH 0.0625
|
|
||||||
#define NOTE_THIRTYSECOND 0.03125
|
|
||||||
|
|
||||||
#define NOTE_WHOLE_DOT 1.5
|
|
||||||
#define NOTE_HALF_DOT 0.75
|
|
||||||
#define NOTE_QUARTER_DOT 0.375
|
|
||||||
#define NOTE_EIGHTH_DOT 0.1875
|
|
||||||
#define NOTE_SIXTEENTH_DOT 0.09375
|
|
||||||
|
|
||||||
// Ноты (частота, Гц) - диапазон 700-8000 Гц для SCS-17-S
|
|
||||||
// Октавы смещены: старая 4-я = новая 0-я, старая 5-я = новая 1-я и т.д.
|
|
||||||
|
|
||||||
// 0-я октава (бывшая 4-я)
|
|
||||||
#define NOTE_B0 494
|
|
||||||
#define NOTE_C1 523
|
|
||||||
#define NOTE_CS1 554
|
|
||||||
#define NOTE_D1 587
|
|
||||||
#define NOTE_DS1 622
|
|
||||||
#define NOTE_E1 659
|
|
||||||
#define NOTE_F1 698
|
|
||||||
#define NOTE_FS1 740
|
|
||||||
#define NOTE_G1 784
|
|
||||||
#define NOTE_GS1 831
|
|
||||||
#define NOTE_A1 880
|
|
||||||
#define NOTE_AS1 932
|
|
||||||
#define NOTE_B1 988
|
|
||||||
|
|
||||||
// 2-я октава (бывшая 6-я)
|
|
||||||
#define NOTE_C2 1047
|
|
||||||
#define NOTE_CS2 1109
|
|
||||||
#define NOTE_D2 1175
|
|
||||||
#define NOTE_DS2 1245
|
|
||||||
#define NOTE_E2 1319
|
|
||||||
#define NOTE_F2 1397
|
|
||||||
#define NOTE_FS2 1480
|
|
||||||
#define NOTE_G2 1568
|
|
||||||
#define NOTE_GS2 1661
|
|
||||||
#define NOTE_A2 1760
|
|
||||||
#define NOTE_AS2 1865
|
|
||||||
#define NOTE_B2 1976
|
|
||||||
|
|
||||||
// 3-я октава (бывшая 7-я)
|
|
||||||
#define NOTE_C3 2093
|
|
||||||
#define NOTE_CS3 2217
|
|
||||||
#define NOTE_D3 2349
|
|
||||||
#define NOTE_DS3 2489
|
|
||||||
#define NOTE_E3 2637
|
|
||||||
#define NOTE_F3 2794
|
|
||||||
#define NOTE_FS3 2960
|
|
||||||
#define NOTE_G3 3136
|
|
||||||
#define NOTE_GS3 3322
|
|
||||||
#define NOTE_A3 3520
|
|
||||||
#define NOTE_AS3 3729
|
|
||||||
#define NOTE_B3 3951
|
|
||||||
|
|
||||||
// 4-я октава (бывшая 8-я)
|
|
||||||
#define NOTE_C4 4186
|
|
||||||
#define NOTE_CS4 4435
|
|
||||||
#define NOTE_D4 4699
|
|
||||||
#define NOTE_DS4 4978
|
|
||||||
#define NOTE_E4 5274
|
|
||||||
#define NOTE_F4 5588
|
|
||||||
#define NOTE_FS4 5920
|
|
||||||
#define NOTE_G4 6272
|
|
||||||
#define NOTE_GS4 6645
|
|
||||||
#define NOTE_A4 7040
|
|
||||||
#define NOTE_AS4 7459
|
|
||||||
#define NOTE_B4 7902
|
|
||||||
|
|
||||||
// Сольфеджио с новыми октавами
|
|
||||||
// 0-я октава
|
|
||||||
#define SI0 NOTE_B0 // 494 Hz
|
|
||||||
|
|
||||||
// 1-я октава
|
|
||||||
#define DO1 NOTE_C1 // 523 Hz
|
|
||||||
#define RE1 NOTE_D1 // 587 Hz
|
|
||||||
#define MI1 NOTE_E1 // 659 Hz
|
|
||||||
#define FA1 NOTE_F1 // 698 Hz
|
|
||||||
#define SOL1 NOTE_G1 // 784 Hz
|
|
||||||
#define LA1 NOTE_A1 // 880 Hz
|
|
||||||
#define SI1 NOTE_B1 // 988 Hz
|
|
||||||
|
|
||||||
// 2-я октава
|
|
||||||
#define DO2 NOTE_C2 // 1047 Hz
|
|
||||||
#define RE2 NOTE_D2 // 1175 Hz
|
|
||||||
#define MI2 NOTE_E2 // 1319 Hz
|
|
||||||
#define FA2 NOTE_F2 // 1397 Hz
|
|
||||||
#define SOL2 NOTE_G2 // 1568 Hz
|
|
||||||
#define LA2 NOTE_A2 // 1760 Hz
|
|
||||||
#define SI2 NOTE_B2 // 1976 Hz
|
|
||||||
|
|
||||||
// 3-я октава
|
|
||||||
#define DO3 NOTE_C3 // 2093 Hz
|
|
||||||
#define RE3 NOTE_D3 // 2349 Hz
|
|
||||||
#define MI3 NOTE_E3 // 2637 Hz
|
|
||||||
#define FA3 NOTE_F3 // 2794 Hz
|
|
||||||
#define SOL3 NOTE_G3 // 3136 Hz
|
|
||||||
#define LA3 NOTE_A3 // 3520 Hz
|
|
||||||
#define SI3 NOTE_B3 // 3951 Hz
|
|
||||||
|
|
||||||
// 4-я октава
|
|
||||||
#define DO4 NOTE_C4 // 4186 Hz
|
|
||||||
#define RE4 NOTE_D4 // 4699 Hz
|
|
||||||
#define MI4 NOTE_E4 // 5274 Hz
|
|
||||||
#define FA4 NOTE_F4 // 5588 Hz
|
|
||||||
#define SOL4 NOTE_G4 // 6272 Hz
|
|
||||||
#define LA4 NOTE_A4 // 7040 Hz
|
|
||||||
#define SI4 NOTE_B4 // 7902 Hz
|
|
||||||
|
|
||||||
// Диезы для 1-й октавы
|
|
||||||
#define DO1s NOTE_CS1 // 554 Hz
|
|
||||||
#define RE1s NOTE_DS1 // 622 Hz
|
|
||||||
#define FA1s NOTE_FS1 // 740 Hz
|
|
||||||
#define SOL1s NOTE_GS1 // 831 Hz
|
|
||||||
#define LA1s NOTE_AS1 // 932 Hz
|
|
||||||
|
|
||||||
// Диезы для 2-й октавы
|
|
||||||
#define DO2s NOTE_CS2 // 1109 Hz
|
|
||||||
#define RE2s NOTE_DS2 // 1245 Hz
|
|
||||||
#define FA2s NOTE_FS2 // 1480 Hz
|
|
||||||
#define SOL2s NOTE_GS2 // 1661 Hz
|
|
||||||
#define LA2s NOTE_AS2 // 1865 Hz
|
|
||||||
|
|
||||||
// Диезы для 3-й октавы
|
|
||||||
#define DO3s NOTE_CS3 // 2217 Hz
|
|
||||||
#define RE3s NOTE_DS3 // 2489 Hz
|
|
||||||
#define FA3s NOTE_FS3 // 2960 Hz
|
|
||||||
#define SOL3s NOTE_GS3 // 3322 Hz
|
|
||||||
#define LA3s NOTE_AS3 // 3729 Hz
|
|
||||||
|
|
||||||
// Диезы для 4-й октавы
|
|
||||||
#define DO4s NOTE_CS4 // 4435 Hz
|
|
||||||
#define RE4s NOTE_DS4 // 4978 Hz
|
|
||||||
#define FA4s NOTE_FS4 // 5920 Hz
|
|
||||||
#define SOL4s NOTE_GS4 // 6645 Hz
|
|
||||||
#define LA4s NOTE_AS4 // 7459 Hz
|
|
||||||
|
|
||||||
#define NOTE_REST 0
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
161
Core/Clock/notes.h
Normal file
161
Core/Clock/notes.h
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
#ifndef NOTES_H
|
||||||
|
#define NOTES_H
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t freq; // частота в Гц или NOTE_REST
|
||||||
|
float duration; // длительность в долях (0.25 = четверть)
|
||||||
|
} Note_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float length; // длительность мелодии в количестве нот
|
||||||
|
const Note_t *sequence; // последовательность нот
|
||||||
|
} Melody_t;
|
||||||
|
|
||||||
|
|
||||||
|
// Длительности (в долях от целой ноты)
|
||||||
|
#define NOTE_WHOLE 1.0
|
||||||
|
#define NOTE_HALF 0.5
|
||||||
|
#define NOTE_QUARTER 0.25
|
||||||
|
#define NOTE_EIGHTH 0.125
|
||||||
|
#define NOTE_SIXTEENTH 0.0625
|
||||||
|
#define NOTE_THIRTYSECOND 0.03125
|
||||||
|
|
||||||
|
#define NOTE_WHOLE_DOT 1.5
|
||||||
|
#define NOTE_HALF_DOT 0.75
|
||||||
|
#define NOTE_QUARTER_DOT 0.375
|
||||||
|
#define NOTE_EIGHTH_DOT 0.1875
|
||||||
|
#define NOTE_SIXTEENTH_DOT 0.09375
|
||||||
|
|
||||||
|
// Ноты (частота, Гц) - диапазон 700-8000 Гц для SCS-17-S
|
||||||
|
// Октавы смещены: старая 4-я = новая 0-я, старая 5-я = новая 1-я и т.д.
|
||||||
|
|
||||||
|
// 0-я октава (бывшая 4-я)
|
||||||
|
#define NOTE_B0 494
|
||||||
|
#define NOTE_C1 523
|
||||||
|
#define NOTE_CS1 554
|
||||||
|
#define NOTE_D1 587
|
||||||
|
#define NOTE_DS1 622
|
||||||
|
#define NOTE_E1 659
|
||||||
|
#define NOTE_F1 698
|
||||||
|
#define NOTE_FS1 740
|
||||||
|
#define NOTE_G1 784
|
||||||
|
#define NOTE_GS1 831
|
||||||
|
#define NOTE_A1 880
|
||||||
|
#define NOTE_AS1 932
|
||||||
|
#define NOTE_B1 988
|
||||||
|
|
||||||
|
// 2-я октава (бывшая 6-я)
|
||||||
|
#define NOTE_C2 1047
|
||||||
|
#define NOTE_CS2 1109
|
||||||
|
#define NOTE_D2 1175
|
||||||
|
#define NOTE_DS2 1245
|
||||||
|
#define NOTE_E2 1319
|
||||||
|
#define NOTE_F2 1397
|
||||||
|
#define NOTE_FS2 1480
|
||||||
|
#define NOTE_G2 1568
|
||||||
|
#define NOTE_GS2 1661
|
||||||
|
#define NOTE_A2 1760
|
||||||
|
#define NOTE_AS2 1865
|
||||||
|
#define NOTE_B2 1976
|
||||||
|
|
||||||
|
// 3-я октава (бывшая 7-я)
|
||||||
|
#define NOTE_C3 2093
|
||||||
|
#define NOTE_CS3 2217
|
||||||
|
#define NOTE_D3 2349
|
||||||
|
#define NOTE_DS3 2489
|
||||||
|
#define NOTE_E3 2637
|
||||||
|
#define NOTE_F3 2794
|
||||||
|
#define NOTE_FS3 2960
|
||||||
|
#define NOTE_G3 3136
|
||||||
|
#define NOTE_GS3 3322
|
||||||
|
#define NOTE_A3 3520
|
||||||
|
#define NOTE_AS3 3729
|
||||||
|
#define NOTE_B3 3951
|
||||||
|
|
||||||
|
// 4-я октава (бывшая 8-я)
|
||||||
|
#define NOTE_C4 4186
|
||||||
|
#define NOTE_CS4 4435
|
||||||
|
#define NOTE_D4 4699
|
||||||
|
#define NOTE_DS4 4978
|
||||||
|
#define NOTE_E4 5274
|
||||||
|
#define NOTE_F4 5588
|
||||||
|
#define NOTE_FS4 5920
|
||||||
|
#define NOTE_G4 6272
|
||||||
|
#define NOTE_GS4 6645
|
||||||
|
#define NOTE_A4 7040
|
||||||
|
#define NOTE_AS4 7459
|
||||||
|
#define NOTE_B4 7902
|
||||||
|
|
||||||
|
// Сольфеджио с новыми октавами
|
||||||
|
// 0-я октава
|
||||||
|
#define SI0 NOTE_B0 // 494 Hz
|
||||||
|
|
||||||
|
// 1-я октава
|
||||||
|
#define DO1 NOTE_C1 // 523 Hz
|
||||||
|
#define RE1 NOTE_D1 // 587 Hz
|
||||||
|
#define MI1 NOTE_E1 // 659 Hz
|
||||||
|
#define FA1 NOTE_F1 // 698 Hz
|
||||||
|
#define SOL1 NOTE_G1 // 784 Hz
|
||||||
|
#define LA1 NOTE_A1 // 880 Hz
|
||||||
|
#define SI1 NOTE_B1 // 988 Hz
|
||||||
|
|
||||||
|
// 2-я октава
|
||||||
|
#define DO2 NOTE_C2 // 1047 Hz
|
||||||
|
#define RE2 NOTE_D2 // 1175 Hz
|
||||||
|
#define MI2 NOTE_E2 // 1319 Hz
|
||||||
|
#define FA2 NOTE_F2 // 1397 Hz
|
||||||
|
#define SOL2 NOTE_G2 // 1568 Hz
|
||||||
|
#define LA2 NOTE_A2 // 1760 Hz
|
||||||
|
#define SI2 NOTE_B2 // 1976 Hz
|
||||||
|
|
||||||
|
// 3-я октава
|
||||||
|
#define DO3 NOTE_C3 // 2093 Hz
|
||||||
|
#define RE3 NOTE_D3 // 2349 Hz
|
||||||
|
#define MI3 NOTE_E3 // 2637 Hz
|
||||||
|
#define FA3 NOTE_F3 // 2794 Hz
|
||||||
|
#define SOL3 NOTE_G3 // 3136 Hz
|
||||||
|
#define LA3 NOTE_A3 // 3520 Hz
|
||||||
|
#define SI3 NOTE_B3 // 3951 Hz
|
||||||
|
|
||||||
|
// 4-я октава
|
||||||
|
#define DO4 NOTE_C4 // 4186 Hz
|
||||||
|
#define RE4 NOTE_D4 // 4699 Hz
|
||||||
|
#define MI4 NOTE_E4 // 5274 Hz
|
||||||
|
#define FA4 NOTE_F4 // 5588 Hz
|
||||||
|
#define SOL4 NOTE_G4 // 6272 Hz
|
||||||
|
#define LA4 NOTE_A4 // 7040 Hz
|
||||||
|
#define SI4 NOTE_B4 // 7902 Hz
|
||||||
|
|
||||||
|
// Диезы для 1-й октавы
|
||||||
|
#define DO1s NOTE_CS1 // 554 Hz
|
||||||
|
#define RE1s NOTE_DS1 // 622 Hz
|
||||||
|
#define FA1s NOTE_FS1 // 740 Hz
|
||||||
|
#define SOL1s NOTE_GS1 // 831 Hz
|
||||||
|
#define LA1s NOTE_AS1 // 932 Hz
|
||||||
|
|
||||||
|
// Диезы для 2-й октавы
|
||||||
|
#define DO2s NOTE_CS2 // 1109 Hz
|
||||||
|
#define RE2s NOTE_DS2 // 1245 Hz
|
||||||
|
#define FA2s NOTE_FS2 // 1480 Hz
|
||||||
|
#define SOL2s NOTE_GS2 // 1661 Hz
|
||||||
|
#define LA2s NOTE_AS2 // 1865 Hz
|
||||||
|
|
||||||
|
// Диезы для 3-й октавы
|
||||||
|
#define DO3s NOTE_CS3 // 2217 Hz
|
||||||
|
#define RE3s NOTE_DS3 // 2489 Hz
|
||||||
|
#define FA3s NOTE_FS3 // 2960 Hz
|
||||||
|
#define SOL3s NOTE_GS3 // 3322 Hz
|
||||||
|
#define LA3s NOTE_AS3 // 3729 Hz
|
||||||
|
|
||||||
|
// Диезы для 4-й октавы
|
||||||
|
#define DO4s NOTE_CS4 // 4435 Hz
|
||||||
|
#define RE4s NOTE_DS4 // 4978 Hz
|
||||||
|
#define FA4s NOTE_FS4 // 5920 Hz
|
||||||
|
#define SOL4s NOTE_GS4 // 6645 Hz
|
||||||
|
#define LA4s NOTE_AS4 // 7459 Hz
|
||||||
|
|
||||||
|
#define NOTE_REST 0
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "melody.h"
|
#include "notes.h"
|
||||||
|
|
||||||
#define song_length(song_arr) sizeof(song_arr)/sizeof(song_arr[0]);
|
#define song_length(song_arr) sizeof(song_arr)/sizeof(song_arr[0])
|
||||||
|
|
||||||
const Note Polyphia_OD[] = {
|
static const Note_t Polyphia_OD_Notes[] = {
|
||||||
//1 ТАКТ
|
//1 ТАКТ
|
||||||
{FA1s, NOTE_SIXTEENTH},
|
{FA1s, NOTE_SIXTEENTH},
|
||||||
{LA1, NOTE_SIXTEENTH},
|
{LA1, NOTE_SIXTEENTH},
|
||||||
@@ -77,10 +77,11 @@ const Note Polyphia_OD[] = {
|
|||||||
{FA2s, NOTE_SIXTEENTH},
|
{FA2s, NOTE_SIXTEENTH},
|
||||||
{SI2, NOTE_SIXTEENTH}
|
{SI2, NOTE_SIXTEENTH}
|
||||||
};
|
};
|
||||||
|
static Melody_t Polyphia_OD = {song_length(Polyphia_OD_Notes), Polyphia_OD_Notes};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Note Polyphia_PlayingGod[] = {
|
static const Note_t Polyphia_PlayingGod_Notes[] = {
|
||||||
//1 ТАКТ
|
//1 ТАКТ
|
||||||
{SOL2, NOTE_QUARTER},
|
{SOL2, NOTE_QUARTER},
|
||||||
{MI3, NOTE_EIGHTH},
|
{MI3, NOTE_EIGHTH},
|
||||||
@@ -122,3 +123,4 @@ const Note Polyphia_PlayingGod[] = {
|
|||||||
{SI2, NOTE_SIXTEENTH},
|
{SI2, NOTE_SIXTEENTH},
|
||||||
{MI3, NOTE_SIXTEENTH},
|
{MI3, NOTE_SIXTEENTH},
|
||||||
};
|
};
|
||||||
|
static Melody_t Polyphia_PlayingGod = {song_length(Polyphia_PlayingGod_Notes), Polyphia_PlayingGod_Notes};
|
||||||
54
Core/Clock/sounds.h
Normal file
54
Core/Clock/sounds.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "notes.h"
|
||||||
|
|
||||||
|
#define song_length(song_arr) sizeof(song_arr)/sizeof(song_arr[0])
|
||||||
|
#define SFX_BPM 480 // 480 BPM для звуковых эффектов
|
||||||
|
|
||||||
|
// ==================== ЗВУКОВЫЕ ЭФФЕКТЫ ====================
|
||||||
|
|
||||||
|
// Короткий писк
|
||||||
|
static const Note_t SFX_Beep_Notes[] = {
|
||||||
|
{DO4, NOTE_SIXTEENTH}
|
||||||
|
};
|
||||||
|
static Melody_t SFX_Beep = {song_length(SFX_Beep_Notes), SFX_Beep_Notes};
|
||||||
|
|
||||||
|
// Двойной писк
|
||||||
|
static const Note_t SFX_DoubleBeep_Notes[] = {
|
||||||
|
{DO4, NOTE_SIXTEENTH},
|
||||||
|
{NOTE_REST, NOTE_SIXTEENTH},
|
||||||
|
{DO4, NOTE_SIXTEENTH}
|
||||||
|
};
|
||||||
|
static Melody_t SFX_DoubleBeep = {song_length(SFX_DoubleBeep_Notes), SFX_DoubleBeep_Notes};
|
||||||
|
|
||||||
|
// Ошибка
|
||||||
|
static const Note_t SFX_Error_Notes[] = {
|
||||||
|
{DO4, NOTE_EIGHTH},
|
||||||
|
{NOTE_REST, NOTE_EIGHTH},
|
||||||
|
{DO4, NOTE_EIGHTH}
|
||||||
|
};
|
||||||
|
static Melody_t SFX_Error = {song_length(SFX_Error_Notes), SFX_Error_Notes};
|
||||||
|
|
||||||
|
// Успех
|
||||||
|
static const Note_t SFX_Success_Notes[] = {
|
||||||
|
{DO4, NOTE_SIXTEENTH},
|
||||||
|
{MI4, NOTE_SIXTEENTH},
|
||||||
|
{SOL4, NOTE_QUARTER}
|
||||||
|
};
|
||||||
|
static Melody_t SFX_Success = {song_length(SFX_Success_Notes), SFX_Success_Notes};
|
||||||
|
|
||||||
|
// Нажатие кнопки
|
||||||
|
static const Note_t SFX_Click_Notes[] = {
|
||||||
|
{DO4, NOTE_THIRTYSECOND}
|
||||||
|
};
|
||||||
|
static Melody_t SFX_Click = {song_length(SFX_Click_Notes), SFX_Click_Notes};
|
||||||
|
|
||||||
|
// Тревога
|
||||||
|
static const Note_t SFX_Alarm_Notes[] = {
|
||||||
|
{LA4, NOTE_EIGHTH},
|
||||||
|
{NOTE_REST, NOTE_EIGHTH},
|
||||||
|
{LA4, NOTE_EIGHTH},
|
||||||
|
{NOTE_REST, NOTE_EIGHTH},
|
||||||
|
{LA4, NOTE_EIGHTH}
|
||||||
|
};
|
||||||
|
static Melody_t SFX_Alarm = {song_length(SFX_Alarm_Notes), SFX_Alarm_Notes};
|
||||||
@@ -83,8 +83,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
|||||||
|
|
||||||
MelodyHandle melody;
|
MelodyHandle melody;
|
||||||
#define curr_song Polyphia_OD
|
#define curr_song Polyphia_OD
|
||||||
Note *mySong = (Note *)curr_song;
|
Melody_t *mySong = &curr_song;
|
||||||
int mySong_length = song_length(curr_song);
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ int main(void)
|
|||||||
HAL_TIM_Base_Start_IT(&htim2);
|
HAL_TIM_Base_Start_IT(&htim2);
|
||||||
Melody_Init(&melody, &htim1, TIM_CHANNEL_1, 72000000);
|
Melody_Init(&melody, &htim1, TIM_CHANNEL_1, 72000000);
|
||||||
|
|
||||||
Melody_Play(&melody, mySong, mySong_length, 134);
|
Melody_Play(&melody, mySong, 134);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
Menu_Process();
|
Menu_Process();
|
||||||
|
|||||||
@@ -675,6 +675,18 @@
|
|||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
<bShared>0</bShared>
|
<bShared>0</bShared>
|
||||||
</File>
|
</File>
|
||||||
|
<File>
|
||||||
|
<GroupNumber>5</GroupNumber>
|
||||||
|
<FileNumber>34</FileNumber>
|
||||||
|
<FileType>5</FileType>
|
||||||
|
<tvExp>0</tvExp>
|
||||||
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
|
<bDave2>0</bDave2>
|
||||||
|
<PathWithFileName>..\Core\Clock\notes.h</PathWithFileName>
|
||||||
|
<FilenameWithoutPath>notes.h</FilenameWithoutPath>
|
||||||
|
<RteFlg>0</RteFlg>
|
||||||
|
<bShared>0</bShared>
|
||||||
|
</File>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
|
|||||||
@@ -812,6 +812,11 @@
|
|||||||
<FileType>5</FileType>
|
<FileType>5</FileType>
|
||||||
<FilePath>..\Core\Clock\songs.h</FilePath>
|
<FilePath>..\Core\Clock\songs.h</FilePath>
|
||||||
</File>
|
</File>
|
||||||
|
<File>
|
||||||
|
<FileName>notes.h</FileName>
|
||||||
|
<FileType>5</FileType>
|
||||||
|
<FilePath>..\Core\Clock\notes.h</FilePath>
|
||||||
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
<Group>
|
<Group>
|
||||||
|
|||||||
Reference in New Issue
Block a user