arduino_midi_player/Midi/music-box-arduino-master/MusicBox.cpp
2025-03-24 14:30:56 +08:00

44 lines
846 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "MusicBox.h"
Player *pMainPlayer;
MusicBox::MusicBox()
{
needHwInit = false;
pMainPlayer = &this->mainPlayer;
PlayerInit(&this->mainPlayer, &synthForAsm);
}
void MusicBox::play(const unsigned char *score)
{
needHwInit = true;
PlayerPlay(&this->mainPlayer, score);
}
void MusicBox::stop()
{
cli();
TIMSK2 &= ~(1 << OCIE2A); //Enable timer interrupt
sei();
}
void MusicBox::process()
{
if (needHwInit && mainPlayer.status == STATUS_PLAYING)
{
DDRB |= 0b000111;
TCCR1A = 0b10100001;
//ICNC1 ICES1 WGM13 WGM12 CS12 CS11 CS10 ; Fast PWM pclk/1
TCCR1B = 0b00001001;
TCCR2A = 0b00000010;
TCCR2B = 0b00000010; //pclk/8
TIMSK2 = 1 << OCIE2A; //Enable timer interrupt
OCR2A = 62; //Initalize TC0 in 32 kHz interval timer ( pclk=16M )
needHwInit = false;
sei();
}
PlayerProcess(&this->mainPlayer);
}