|
|
@ -113,7 +113,9 @@ void Sound::play_task(void *pvParameter) { |
|
|
|
|
|
|
|
xTaskToNotify = xTaskGetCurrentTaskHandle(); |
|
|
|
|
|
|
|
File file = SDCard::open(path); |
|
|
|
// Serial.print("before SDCard::open(); free stack: "); Serial.println(uxTaskGetStackHighWaterMark( NULL ), DEC); // DEBUG
|
|
|
|
|
|
|
|
File file = SDCard::open(path); // ToDo: accessing static member function loads 1500 words onto stack!
|
|
|
|
if (!file) { |
|
|
|
xTaskToNotify = NULL; |
|
|
|
Serial.print("Failed to open file: "); Serial.println(path); |
|
|
@ -121,9 +123,11 @@ void Sound::play_task(void *pvParameter) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Serial.print("before new; free stack: "); Serial.println(uxTaskGetStackHighWaterMark( NULL ), DEC); // DEBUG
|
|
|
|
unsigned char* buf = new unsigned char[BUF_LENGTH]; |
|
|
|
unsigned int buf_pos; |
|
|
|
Serial.print("Allocated buffer at: "); Serial.println((int)buf,HEX); |
|
|
|
// Serial.print("after new; free stack: "); Serial.println(uxTaskGetStackHighWaterMark( NULL ), DEC); // DEBUG
|
|
|
|
|
|
|
|
i2s_start(i2s_num); |
|
|
|
|
|
|
@ -174,20 +178,3 @@ void Sound::play_task(void *pvParameter) { |
|
|
|
xSemaphoreGive( xPlayingSemaphore ); |
|
|
|
vTaskDelete( NULL ); |
|
|
|
} |
|
|
|
|
|
|
|
/* callback(?) for new audio data */ |
|
|
|
int Sound::render_sample_block(uint16_t *sample_buf_left, uint16_t *sample_buf_right, int num_samples) { |
|
|
|
TickType_t delay = 10 / portTICK_PERIOD_MS; // max delay: 10ms instead of portMAX_DELAY
|
|
|
|
int num_pushed_samples = 0; |
|
|
|
for (int i=0; i < num_samples; i++) { |
|
|
|
unsigned int sample = ((unsigned short) sample_buf_left[i] << 16 & 0xffff0000) | ((unsigned short) sample_buf_right[i]); |
|
|
|
int num_pushed_bytes = i2s_push_sample(i2s_num, (char *)&sample, delay); |
|
|
|
if (num_pushed_bytes > 0) { |
|
|
|
num_pushed_samples += num_pushed_bytes; |
|
|
|
} else { |
|
|
|
Serial.println("i2s buffer filled"); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return num_pushed_samples; |
|
|
|
} |
|
|
|