Explorar el Código

Improve interrupt handling for simultaneous WAV file playing

dds
PaulStoffregen hace 4 años
padre
commit
6369a6ae1f
Se han modificado 1 ficheros con 25 adiciones y 17 borrados
  1. +25
    -17
      play_sd_wav.cpp

+ 25
- 17
play_sd_wav.cpp Ver fichero

@@ -28,6 +28,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
#define STATE_DIRECT_16BIT_MONO 2 // playing mono at native sample rate
@@ -62,20 +63,24 @@ void AudioPlaySdWav::begin(void)
bool AudioPlaySdWav::play(const char *filename)
{
stop();
#if defined(HAS_KINETIS_SDHC)
bool irq = false;
if (NVIC_IS_ENABLED(IRQ_SOFTWARE)) {
NVIC_DISABLE_IRQ(IRQ_SOFTWARE);
irq = true;
}
#if defined(HAS_KINETIS_SDHC)
if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStartUsingSPI();
#else
#else
AudioStartUsingSPI();
#endif
__disable_irq();
wavfile = SD.open(filename);
__enable_irq();
if (!wavfile) {
#if defined(HAS_KINETIS_SDHC)
#if defined(HAS_KINETIS_SDHC)
if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStopUsingSPI();
#else
#else
AudioStopUsingSPI();
#endif
#endif
if (irq) NVIC_ENABLE_IRQ(IRQ_SOFTWARE);
return false;
}
buffer_length = 0;
@@ -84,30 +89,33 @@ bool AudioPlaySdWav::play(const char *filename)
data_length = 20;
header_offset = 0;
state = STATE_PARSE1;
if (irq) NVIC_ENABLE_IRQ(IRQ_SOFTWARE);
return true;
}

void AudioPlaySdWav::stop(void)
{
__disable_irq();
bool irq = false;
if (NVIC_IS_ENABLED(IRQ_SOFTWARE)) {
NVIC_DISABLE_IRQ(IRQ_SOFTWARE);
irq = true;
}
if (state != STATE_STOP) {
audio_block_t *b1 = block_left;
block_left = NULL;
audio_block_t *b2 = block_right;
block_right = NULL;
state = STATE_STOP;
__enable_irq();
if (b1) release(b1);
if (b2) release(b2);
wavfile.close();
#if defined(HAS_KINETIS_SDHC)
#if defined(HAS_KINETIS_SDHC)
if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStopUsingSPI();
#else
#else
AudioStopUsingSPI();
#endif
} else {
__enable_irq();
#endif
}
if (irq) NVIC_ENABLE_IRQ(IRQ_SOFTWARE);
}


@@ -165,11 +173,11 @@ void AudioPlaySdWav::update(void)
}
end: // end of file reached or other reason to stop
wavfile.close();
#if defined(HAS_KINETIS_SDHC)
#if defined(HAS_KINETIS_SDHC)
if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStopUsingSPI();
#else
#else
AudioStopUsingSPI();
#endif
#endif
state_play = STATE_STOP;
state = STATE_STOP;
cleanup:

Cargando…
Cancelar
Guardar