Browse Source

callback for new audio data

main
Hendrik Langer 8 years ago
parent
commit
1731a8b1db
  1. 12
      src/sound.cpp
  2. 1
      src/sound.h

12
src/sound.cpp

@ -85,3 +85,15 @@ void Sound::stop() {
void Sound::end() { void Sound::end() {
i2s_driver_uninstall(i2s_num); //stop & destroy i2s driver i2s_driver_uninstall(i2s_num); //stop & destroy i2s driver
} }
/* callback(?) for new audio data */
int Sound::render_sample_block(uint16_t *sample_buf_left, uint16_t *sample_buf_right, int num_samples) {
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;
}
return num_pushed_samples;
}

1
src/sound.h

@ -25,6 +25,7 @@ class Sound {
void play(); void play();
// void pause(); // void pause();
void stop(); void stop();
int render_sample_block(uint16_t *sample_buf_left, uint16_t *sample_buf_right, int num_samples);
private: private:
i2sbuffer_t buffer; i2sbuffer_t buffer;
const i2s_port_t i2s_num = (i2s_port_t)I2S_NUM; const i2s_port_t i2s_num = (i2s_port_t)I2S_NUM;

Loading…
Cancel
Save