|
|
@ -17,7 +17,7 @@ |
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
|
|
#define SAMPLE_RATE (36000) |
|
|
|
#define SAMPLE_RATE (11025) |
|
|
|
#define WAVE_FREQ_HZ (100) |
|
|
|
//#define PI 3.14159265
|
|
|
|
|
|
|
@ -88,12 +88,17 @@ void Sound::end() { |
|
|
|
|
|
|
|
/* 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, portMAX_DELAY); |
|
|
|
if (num_pushed_bytes > 0) num_pushed_samples += num_pushed_bytes; |
|
|
|
else break; |
|
|
|
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; |
|
|
|
} |
|
|
|