You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2021/06/21 19:32:37 UTC

[mynewt-core] 01/02: hw/drivers/i2s: Fix i2s_write

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 9f9b731c0d1eaa5fb04553a0debd48d9ca47e1f5
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Jun 14 11:59:17 2021 +0200

    hw/drivers/i2s: Fix i2s_write
    
    Synchronous function for easy write to i2s base speaker
    was not setting up sample_count field.
    If this filed was not setup in other way (as it could
    potentially be) i2s drivers would just drop empty
    buffers and no sound would emitted.
---
 hw/drivers/i2s/src/i2s.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/drivers/i2s/src/i2s.c b/hw/drivers/i2s/src/i2s.c
index 3a78a83..7930c56 100644
--- a/hw/drivers/i2s/src/i2s.c
+++ b/hw/drivers/i2s/src/i2s.c
@@ -180,7 +180,6 @@ i2s_close(struct i2s *i2s)
 int
 i2s_write(struct i2s *i2s, void *samples, uint32_t sample_buffer_size)
 {
-    uint32_t sample_pair_size = (i2s->sample_size_in_bytes * 2);
     size_t sample_count;
     struct i2s_sample_buffer *buffer;
 
@@ -193,15 +192,16 @@ i2s_write(struct i2s *i2s, void *samples, uint32_t sample_buffer_size)
     }
 
     /* Calculate buffer size */
-    sample_count = sample_buffer_size / sample_pair_size;
+    sample_count = sample_buffer_size / i2s->sample_size_in_bytes;
     if (buffer->capacity < sample_count) {
         sample_count = buffer->capacity;
     }
 
-    sample_buffer_size = sample_count * sample_pair_size;
+    sample_buffer_size = sample_count * i2s->sample_size_in_bytes;
 
     /* Move data to buffer */
     memcpy(buffer->sample_data, samples, sample_buffer_size);
+    buffer->sample_count = sample_count;
 
     /* Pass buffer to output device */
     i2s_buffer_put(i2s, buffer);