Skip to content

Commit d0042d6

Browse files
TomasBarakNXPkartben
authored andcommitted
samples: drivers: i2s: Support sine wave playback in i2s_codec sample
- when not using DMIC, play a 16kHz stereo sine wave using codec Signed-off-by: Tomas Barak <tomas.barak@nxp.com>
1 parent 31fff08 commit d0042d6

File tree

3 files changed

+449
-11
lines changed

3 files changed

+449
-11
lines changed

samples/drivers/i2s/i2s_codec/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Overview
88
********
99

1010
This sample demonstrates how to use an I2S driver in a simple processing of
11-
an audio stream. It configures and starts from memory buffer or from DMIC to
11+
an audio stream. It configures and starts from memory buffer (sample sine wave) or from DMIC to
1212
record i2s data and send to codec with DMA.
1313

1414
Requirements
@@ -30,4 +30,4 @@ To build and flash the application:
3030
:compact:
3131

3232
To run you can connect earphones to the lineout connect and hear the sound
33-
from DMIC or from memory buffer.
33+
from DMIC or from memory buffer. Sample sine wave is included for reference.

samples/drivers/i2s/i2s_codec/src/main.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 NXP
2+
* Copyright 2024-2025 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -11,6 +11,9 @@
1111
#include <zephyr/audio/codec.h>
1212
#include <string.h>
1313

14+
#ifndef CONFIG_USE_DMIC
15+
#include "sine.h"
16+
#endif
1417

1518
#define I2S_CODEC_TX DT_ALIAS(i2s_codec_tx)
1619

@@ -171,19 +174,14 @@ int main(void)
171174

172175
for (i = 0; i < 2; i++) {
173176
#if CONFIG_USE_DMIC
174-
ret = dmic_read(dmic_dev, 0,
175-
&mem_block, &block_size, TIMEOUT);
177+
ret = dmic_read(dmic_dev, 0, &mem_block, &block_size, TIMEOUT);
176178
if (ret < 0) {
177179
printk("read failed: %d", ret);
178180
break;
179181
}
180182
#else
181-
ret = k_mem_slab_alloc(&mem_slab,
182-
&mem_block, Z_TIMEOUT_TICKS(TIMEOUT));
183-
if (ret < 0) {
184-
printk("Failed to allocate TX block\n");
185-
return 0;
186-
}
183+
/* If not using DMIC, play a sine wave 440Hz */
184+
mem_block = (void *)&__16kHz16bit_stereo_sine_pcm;
187185
#endif
188186
ret = i2s_write(i2s_dev_codec, mem_block, block_size);
189187
if (ret < 0) {

0 commit comments

Comments
 (0)