8000 i2s can send now buffers by aguaviva · Pull Request #5349 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

i2s can send now buffers #5349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
using unsigned integers since we'll never be using negative numbers
  • Loading branch information
aguaviva committed Nov 24, 2018
commit 862411723dd8b9fbb9a5a89747c02a1de1a1d0a8
30 changes: 15 additions & 15 deletions cores/esp8266/core_esp8266_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ bool i2s_rx_is_empty() {
return _i2s_is_empty( rx );
}

static int16_t _i2s_available(const i2s_state_t *ch) {
static uint16_t _i2s_available(const i2s_state_t *ch) {
if (!ch) {
return 0;
}
return (SLC_BUF_CNT - ch->slc_queue_len) * SLC_BUF_LEN;
}

int16_t i2s_available(){
uint16_t i2s_available(){
return _i2s_available( tx );
}

int16_t i2s_rx_available(){
uint16_t i2s_rx_available(){
return _i2s_available( rx );
}

Expand Down Expand Up @@ -333,8 +333,8 @@ bool i2s_write_lr(int16_t left, int16_t right){

// writes a buffer of frames into the DMA memory, returns the amount of frames written
// A frame is just a int16_t for mono, for stereo a frame is two int16_t, one for each channel.
static int16_t _i2s_write_buffer(int16_t *frames, int16_t frame_count, bool mono, bool nb) {
int16_t frames_written=0;
static uint16_t _i2s_write_buffer(int16_t *frames, uint16_t frame_count, bool mono, bool nb) {
uint16_t frames_written=0;

while(frame_count>0) {

Expand Down Expand Up @@ -366,21 +366,21 @@ static int16_t _i2s_write_buffer(int16_t *frames, int16_t frame_count, bool mono
}

//space available in the current buffer
int16_t available = SLC_BUF_LEN - tx->curr_slc_buf_pos;
uint16_t available = SLC_BUF_LEN - tx->curr_slc_buf_pos;

int16_t fc = (available < frame_count) ? available : frame_count;
uint16_t fc = (available < frame_count) ? available : frame_count;

if (mono) {
for(int16_t i=0;i<fc;i++){
for(uint16_t i=0;i<fc;i++){
uint16_t v = (uint16_t)(*frames++);
tx->curr_slc_buf[tx->curr_slc_buf_pos++] = (v << 16) | v;
}
}
else
{
for(int16_t i=0;i<fc;i++){
uint16_t v1 = *frames++;
uint16_t v2 = *frames++;
for(uint16_t i=0;i<fc;i++){
uint16_t v1 = (uint16_t)(*frames++);
uint16_t v2 = (uint16_t)(*frames++);
tx->curr_slc_buf[tx->curr_slc_buf_pos++] = (v1 << 16) | v2;
}
}
Expand All @@ -391,13 +391,13 @@ static int16_t _i2s_write_buffer(int16_t *frames, int16_t frame_count, bool mono
return frames_written;
}

int16_t i2s_write_buffer_mono_nb(int16_t *frames, int16_t frame_count) { return _i2s_write_buffer(frames, frame_count, true, true); }
uint16_t i2s_write_buffer_mono_nb(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, true, true); }

int16_t i2s_write_buffer_mono(int16_t *frames, int16_t frame_count) { return _i2s_write_buffer(frames, frame_count, true, false); }
uint16_t i2s_write_buffer_mono(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, true, false); }

int16_t i2s_write_buffer_nb(int16_t *frames, int16_t frame_count) { return _i2s_write_buffer(frames, frame_count, false, true); }
uint16_t i2s_write_buffer_nb(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, false, true); }

int16_t i2s_write_buffer(int16_t *frames, int16_t frame_count) { return _i2s_write_buffer(frames, frame_count, false, false); }
uint16_t i2s_write_buffer(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, false, false); }

bool i2s_read_sample(int16_t *left, int16_t *right, bool blocking) {
if (!rx) {
Expand Down
12 changes: 6 additions & 6 deletions cores/esp8266/i2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ bool i2s_is_full();//returns true if DMA is full and can not take more bytes (ov
bool i2s_is_empty();//returns true if DMA is empty (underflow)
bool i2s_rx_is_full();
bool i2s_rx_is_empty();
int16_t i2s_available();// returns the number of samples than can be written before blocking
int16_t i2s_rx_available();// returns the number of samples than can be written before blocking
uint16_t i2s_available();// returns the number of samples than can be written before blocking
uint16_t i2s_rx_available();// returns the number of samples than can be written before blocking
void i2s_set_callback(void (*callback) (void));
void i2s_rx_set_callback(void (*callback) (void));

// writes a buffer of frames into the DMA memory, returns the amount of frames written
// A frame is just a int16_t for mono, for stereo a frame is two int16_t, one for each channel.
int16_t i2s_write_buffer_mono(int16_t *frames, int16_t frame_count);
int16_t i2s_write_buffer_mono_nb(int16_t *frames, int16_t frame_count);
int16_t i2s_write_buffer(int16_t *frames, int16_t frame_count);
int16_t i2s_write_buffer_nb(int16_t *frames, int16_t frame_count);
uint16_t i2s_write_buffer_mono(int16_t *frames, uint16_t frame_count);
uint16_t i2s_write_buffer_mono_nb(int16_t *frames, uint16_t frame_count);
uint16_t i2s_write_buffer(int16_t *frames, uint16_t frame_count);
uint16_t i2s_write_buffer_nb(int16_t *frames, uint16_t frame_count);

#ifdef __cplusplus
}
Expand Down
0