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