*/ | */ | ||||
#include "play_sd_raw.h" | #include "play_sd_raw.h" | ||||
#include "spi_interrupt.h" | |||||
void AudioPlaySdRaw::begin(void) | void AudioPlaySdRaw::begin(void) | ||||
bool AudioPlaySdRaw::play(const char *filename) | bool AudioPlaySdRaw::play(const char *filename) | ||||
{ | { | ||||
stop(); | stop(); | ||||
AudioStartUsingSPI(); | |||||
__disable_irq(); | __disable_irq(); | ||||
rawfile = SD.open(filename); | rawfile = SD.open(filename); | ||||
__enable_irq(); | __enable_irq(); | ||||
playing = false; | playing = false; | ||||
__enable_irq(); | __enable_irq(); | ||||
rawfile.close(); | rawfile.close(); | ||||
AudioStopUsingSPI(); | |||||
} else { | } else { | ||||
__enable_irq(); | __enable_irq(); | ||||
} | } | ||||
transmit(block); | transmit(block); | ||||
} else { | } else { | ||||
rawfile.close(); | rawfile.close(); | ||||
AudioStopUsingSPI(); | |||||
playing = false; | playing = false; | ||||
} | } | ||||
release(block); | release(block); |
*/ | */ | ||||
#include "play_sd_wav.h" | #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_MONO 0 // playing mono at native sample rate | ||||
#define STATE_DIRECT_8BIT_STEREO 1 // playing stereo at native sample rate | #define STATE_DIRECT_8BIT_STEREO 1 // playing stereo at native sample rate | ||||
bool AudioPlaySdWav::play(const char *filename) | bool AudioPlaySdWav::play(const char *filename) | ||||
{ | { | ||||
stop(); | stop(); | ||||
AudioStartUsingSPI(); | |||||
__disable_irq(); | __disable_irq(); | ||||
wavfile = SD.open(filename); | wavfile = SD.open(filename); | ||||
__enable_irq(); | __enable_irq(); | ||||
if (b1) release(b1); | if (b1) release(b1); | ||||
if (b2) release(b2); | if (b2) release(b2); | ||||
wavfile.close(); | wavfile.close(); | ||||
AudioStopUsingSPI(); | |||||
} else { | } else { | ||||
__enable_irq(); | __enable_irq(); | ||||
} | } | ||||
} | } | ||||
end: // end of file reached or other reason to stop | end: // end of file reached or other reason to stop | ||||
wavfile.close(); | wavfile.close(); | ||||
AudioStopUsingSPI(); | |||||
state_play = STATE_STOP; | state_play = STATE_STOP; | ||||
state = STATE_STOP; | state = STATE_STOP; | ||||
cleanup: | cleanup: |
} | } | ||||
static inline void AudioStopUsingSPI(void) { | static inline void AudioStopUsingSPI(void) { | ||||
if (--AudioUsingSPICount == 0) | |||||
if (AudioUsingSPICount == 0 || --AudioUsingSPICount == 0) | |||||
SPI.notUsingInterrupt(IRQ_SOFTWARE); | SPI.notUsingInterrupt(IRQ_SOFTWARE); | ||||
} | } | ||||