Engineering(SoC Design)/프로젝트 등
musicSimplifier
무말랭이
2022. 5. 18. 20:03
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/
CodeBug – happy birthday tune
This, the CodeBug emulator, allows you to test and debug your code quickly. It simulates what would happen on a real, physical CodeBug.
www.codebug.org.uk