Fixed interrupt glitch in ATMlib.play()

Timer/counter 4 is enabled on Arduino init() and a Timer/counter 4 overflow may happen right after the timer/counter 4 interrupt is enabled. When this happens the channels have not been initialized yet causing random noise/sounds being played.
This has been fixed by moving the interrupt enable after the channels have been initialized.
This commit is contained in:
Mr.Blinky 2018-09-21 00:23:05 +02:00 committed by GitHub
parent 8bf0c707d6
commit 02aa13d078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 2 deletions

View File

@ -131,8 +131,6 @@ void ATMsynth::play(const byte *song) {
TCCR4C = 0b01000101;
OCR4D = 0x80;
#endif
TIMSK4 = 0b00000100;
// Load a melody stream and start grinding samples
// Read track count
@ -145,6 +143,7 @@ void ATMsynth::play(const byte *song) {
for (unsigned n = 0; n < 4; n++) {
channel[n].ptr = getTrackPointer(pgm_read_byte(song++));
}
TIMSK4 = 0b00000100;// enable interrupt as last
}
// Stop playing, unload melody