mp3 음원을 넣으면 간단하게
다음과 같은 melody 와 damper 형태로
추출해주는 audio proecessing and c
const int PIN = 15;
hw_timer_t* timer = NULL;
bool value = true;
int frequency = 20; // 20 to 20000
// music
int rest =0;
int melody[] = {294, 330, 392, 392, 392, 392, 392, 392, 392, 294, 330, 392, rest,
392, 392, 392, 392, 392, 294, 330, 392, rest,
392, 392, 392, 392, 392, 392, 392, 370, 370, rest};
int damper[] = {400, 400, 200, 200, 200, 100, 300, 100, 200, 200, 200, 100, 30,
200, 100, 300, 100, 200, 200, 200, 100, 30,
200, 100, 300, 100, 200, 200, 200, 200, 200, 3000};
void IRAM_ATTR onTimer() {
value = !value;
digitalWrite(PIN, value);
}
void setup() {
Serial.begin(115200);
pinMode(PIN, OUTPUT); // sets the digital pin as output
setupTimer();
}
void setupTimer() {
// Use 1st timer of 4 - 1 tick take 1/(80MHZ/80) = 1us so we set divider 80 and count up
timer = timerBegin(0, 80, true);//div 80
timerAttachInterrupt(timer, &onTimer, true);
}
void setFrequency(long frequencyHz){
timerAlarmDisable(timer);
timerAlarmWrite(timer, 1000000l / frequencyHz, true);
timerAlarmEnable(timer);
}
void tone(long frequencyHz, long durationMs){
setFrequency(frequencyHz);
delay(durationMs);
}
void loop() {
for(int a=0; a<32; a++) {
tone(melody[a],damper[a]);
delay(damper[a]+10);
}
}
https://www.codebug.org.uk/explore/codebug/15483/happy-birthday-tune/
'Engineering(SoC Design) > 프로젝트 등' 카테고리의 다른 글
아주 매우 간단함 (0) | 2022.05.30 |
---|---|
Xilinx Documentation Navigator (0) | 2022.05.22 |
통신과목의 필요성 (0) | 2022.05.18 |
공부해야함 (0) | 2022.05.18 |
극한계산과 cpu (0) | 2022.05.05 |