@@ -25,6 +25,7 @@ | |||
*/ | |||
#include "play_sd_raw.h" | |||
#include "spi_interrupt.h" | |||
void AudioPlaySdRaw::begin(void) | |||
@@ -38,6 +39,7 @@ void AudioPlaySdRaw::begin(void) | |||
bool AudioPlaySdRaw::play(const char *filename) | |||
{ | |||
stop(); | |||
AudioStartUsingSPI(); | |||
__disable_irq(); | |||
rawfile = SD.open(filename); | |||
__enable_irq(); | |||
@@ -59,6 +61,7 @@ void AudioPlaySdRaw::stop(void) | |||
playing = false; | |||
__enable_irq(); | |||
rawfile.close(); | |||
AudioStopUsingSPI(); | |||
} else { | |||
__enable_irq(); | |||
} | |||
@@ -87,6 +90,7 @@ void AudioPlaySdRaw::update(void) | |||
transmit(block); | |||
} else { | |||
rawfile.close(); | |||
AudioStopUsingSPI(); | |||
playing = false; | |||
} | |||
release(block); |
@@ -25,6 +25,7 @@ | |||
*/ | |||
#include "play_sd_wav.h" | |||
#include "spi_interrupt.h" | |||
#define STATE_DIRECT_8BIT_MONO 0 // playing mono at native sample rate | |||
#define STATE_DIRECT_8BIT_STEREO 1 // playing stereo at native sample rate | |||
@@ -59,6 +60,7 @@ void AudioPlaySdWav::begin(void) | |||
bool AudioPlaySdWav::play(const char *filename) | |||
{ | |||
stop(); | |||
AudioStartUsingSPI(); | |||
__disable_irq(); | |||
wavfile = SD.open(filename); | |||
__enable_irq(); | |||
@@ -85,6 +87,7 @@ void AudioPlaySdWav::stop(void) | |||
if (b1) release(b1); | |||
if (b2) release(b2); | |||
wavfile.close(); | |||
AudioStopUsingSPI(); | |||
} else { | |||
__enable_irq(); | |||
} | |||
@@ -140,6 +143,7 @@ void AudioPlaySdWav::update(void) | |||
} | |||
end: // end of file reached or other reason to stop | |||
wavfile.close(); | |||
AudioStopUsingSPI(); | |||
state_play = STATE_STOP; | |||
state = STATE_STOP; | |||
cleanup: |
@@ -43,7 +43,7 @@ static inline void AudioStartUsingSPI(void) { | |||
} | |||
static inline void AudioStopUsingSPI(void) { | |||
if (--AudioUsingSPICount == 0) | |||
if (AudioUsingSPICount == 0 || --AudioUsingSPICount == 0) | |||
SPI.notUsingInterrupt(IRQ_SOFTWARE); | |||
} | |||