|
|
@ -28,7 +28,7 @@ |
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
bool Sound::playing = false; |
|
|
|
volatile bool Sound::playing = false; |
|
|
|
|
|
|
|
Sound::Sound() { |
|
|
|
} |
|
|
@ -82,13 +82,15 @@ void Sound::init() { |
|
|
|
} |
|
|
|
|
|
|
|
void Sound::play() { |
|
|
|
Serial.println("Sound::play()"); |
|
|
|
i2s_start(i2s_num); |
|
|
|
playing = true; |
|
|
|
Sound::playing = true; |
|
|
|
} |
|
|
|
|
|
|
|
void Sound::stop() { |
|
|
|
Serial.println("Sound::stop()"); |
|
|
|
i2s_stop(i2s_num); |
|
|
|
playing = false; |
|
|
|
Sound::playing = false; |
|
|
|
} |
|
|
|
|
|
|
|
void Sound::end() { |
|
|
@ -96,22 +98,25 @@ void Sound::end() { |
|
|
|
} |
|
|
|
|
|
|
|
void Sound::buffer_refill_task(void *pvParameter) { |
|
|
|
// Serial.print("initial free stack: "); Serial.println(uxTaskGetStackHighWaterMark( NULL ), DEC); // DEBUG
|
|
|
|
char *path = (char *) pvParameter; |
|
|
|
Serial.println("sdcard: opening File"); |
|
|
|
SDCard::open(path); |
|
|
|
|
|
|
|
Sound::play(); |
|
|
|
while (SDCard::available()) { |
|
|
|
// Serial.print("chunk free stack: "); Serial.println(uxTaskGetStackHighWaterMark( NULL ), DEC); // DEBUG
|
|
|
|
// get chunk of data
|
|
|
|
SDCard::read(); // overwrite buffer
|
|
|
|
DataSource::buf_pos = 0; |
|
|
|
|
|
|
|
while (DataSource::buf_pos < BUF_LENGTH) { |
|
|
|
// Serial.print("i2s_push free stack: "); Serial.println(uxTaskGetStackHighWaterMark( NULL ), DEC); // DEBUG
|
|
|
|
uint16_t *buf = (uint16_t *) DataSource::buffer; |
|
|
|
int buf_pos = (DataSource::buf_pos)/4; |
|
|
|
// convert data
|
|
|
|
//unsigned int sample = ((unsigned short) DataSource::buffer[DataSource::buf_pos] << 16 & 0xffff0000) | ((unsigned short) DataSource::buffer[DataSource::buf_pos]);
|
|
|
|
unsigned int sample = ((unsigned short) buf[buf_pos] << 16 & 0xffff0000) | ((unsigned short) DataSource::buffer[buf_pos]); |
|
|
|
unsigned int sample = ((unsigned short) buf[buf_pos] << 16 & 0xffff0000) | ((unsigned short) buf[buf_pos]); |
|
|
|
// push samples
|
|
|
|
int num_pushed_bytes = i2s_push_sample(Sound::i2s_num, (char *)&sample, 0); |
|
|
|
if (num_pushed_bytes == 0) { |
|
|
@ -127,6 +132,7 @@ void Sound::buffer_refill_task(void *pvParameter) { |
|
|
|
Serial.println("sdcard: EOF"); |
|
|
|
SDCard::close(); |
|
|
|
Sound::stop(); |
|
|
|
Serial.println("task exiting"); |
|
|
|
vTaskDelete( NULL ); |
|
|
|
} |
|
|
|
|
|
|
|