Browse Source

register SPI interrupt when playing WAV & RAW files

dds
PaulStoffregen 10 years ago
parent
commit
fe2286932b
3 changed files with 9 additions and 1 deletions
  1. +4
    -0
      play_sd_raw.cpp
  2. +4
    -0
      play_sd_wav.cpp
  3. +1
    -1
      spi_interrupt.h

+ 4
- 0
play_sd_raw.cpp View File

*/ */


#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);

+ 4
- 0
play_sd_wav.cpp View File

*/ */


#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:

+ 1
- 1
spi_interrupt.h View File

} }


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);
} }



Loading…
Cancel
Save