|
|
|
|
|
|
|
|
#define STATE_PARSE4 11 // ignoring unknown chunk |
|
|
#define STATE_PARSE4 11 // ignoring unknown chunk |
|
|
#define STATE_STOP 12 |
|
|
#define STATE_STOP 12 |
|
|
|
|
|
|
|
|
void AudioPlaySDcardWAV::begin(void) |
|
|
|
|
|
|
|
|
void AudioPlaySdWav::begin(void) |
|
|
{ |
|
|
{ |
|
|
state = STATE_STOP; |
|
|
state = STATE_STOP; |
|
|
state_play = STATE_STOP; |
|
|
state_play = STATE_STOP; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AudioPlaySDcardWAV::play(const char *filename) |
|
|
|
|
|
|
|
|
bool AudioPlaySdWav::play(const char *filename) |
|
|
{ |
|
|
{ |
|
|
stop(); |
|
|
stop(); |
|
|
wavfile = SD.open(filename); |
|
|
wavfile = SD.open(filename); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioPlaySDcardWAV::stop(void) |
|
|
|
|
|
|
|
|
void AudioPlaySdWav::stop(void) |
|
|
{ |
|
|
{ |
|
|
__disable_irq(); |
|
|
__disable_irq(); |
|
|
if (state != STATE_STOP) { |
|
|
if (state != STATE_STOP) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool AudioPlaySDcardWAV::start(void) |
|
|
|
|
|
|
|
|
bool AudioPlaySdWav::start(void) |
|
|
{ |
|
|
{ |
|
|
__disable_irq(); |
|
|
__disable_irq(); |
|
|
if (state == STATE_STOP) { |
|
|
if (state == STATE_STOP) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AudioPlaySDcardWAV::update(void) |
|
|
|
|
|
|
|
|
void AudioPlaySdWav::update(void) |
|
|
{ |
|
|
{ |
|
|
// only update if we're playing |
|
|
// only update if we're playing |
|
|
if (state == STATE_STOP) return; |
|
|
if (state == STATE_STOP) return; |
|
|
|
|
|
|
|
|
// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ |
|
|
// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ |
|
|
|
|
|
|
|
|
// Consume already buffered data. Returns true if audio transmitted. |
|
|
// Consume already buffered data. Returns true if audio transmitted. |
|
|
bool AudioPlaySDcardWAV::consume(void) |
|
|
|
|
|
|
|
|
bool AudioPlaySdWav::consume(void) |
|
|
{ |
|
|
{ |
|
|
uint32_t len, size; |
|
|
uint32_t len, size; |
|
|
uint8_t lsb, msb; |
|
|
uint8_t lsb, msb; |
|
|
|
|
|
|
|
|
p = buffer + 512 - size; |
|
|
p = buffer + 512 - size; |
|
|
start: |
|
|
start: |
|
|
if (size == 0) return false; |
|
|
if (size == 0) return false; |
|
|
//Serial.print("AudioPlaySDcardWAV write, size = "); |
|
|
|
|
|
|
|
|
//Serial.print("AudioPlaySdWav write, size = "); |
|
|
//Serial.print(size); |
|
|
//Serial.print(size); |
|
|
//Serial.print(", data_length = "); |
|
|
//Serial.print(", data_length = "); |
|
|
//Serial.print(data_length); |
|
|
//Serial.print(data_length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this is not supposed to happen! |
|
|
// this is not supposed to happen! |
|
|
//default: |
|
|
//default: |
|
|
//Serial.println("AudioPlaySDcardWAV, unknown state"); |
|
|
|
|
|
|
|
|
//Serial.println("AudioPlaySdWav, unknown state"); |
|
|
} |
|
|
} |
|
|
state_play = STATE_STOP; |
|
|
state_play = STATE_STOP; |
|
|
state = STATE_STOP; |
|
|
state = STATE_STOP; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AudioPlaySDcardWAV::parse_format(void) |
|
|
|
|
|
|
|
|
bool AudioPlaySdWav::parse_format(void) |
|
|
{ |
|
|
{ |
|
|
uint8_t num = 0; |
|
|
uint8_t num = 0; |
|
|
uint16_t format; |
|
|
uint16_t format; |