i2s-tone
Generate a 440 Hz sine tone and play it out on E1M_I2S0. The minimal demo for <alp/i2s.h>.
Source: examples/i2s-tone/.
board.yaml
schema_version: 2
som:
sku: E1M-AEN701
carrier:
name: E1M-EVK
cores:
m55_hp:
os: zephyr
app: ./src
peripherals: [i2s]
diagnostics:
log_level: info
Source (abbreviated)
#include <alp/i2s.h>
#include <alp/e1m_pinout.h>
#include <math.h>
#define SAMPLE_RATE 44100
#define FRAMES 1024
static int16_t pcm[FRAMES * 2]; /* stereo */
int main(void) {
alp_i2s_t *i2s = alp_i2s_open(&(alp_i2s_config_t){
.bus_id = E1M_I2S0,
.mode = ALP_I2S_MODE_MASTER,
.sample_rate_hz = SAMPLE_RATE,
.channels = 2,
.bit_depth = 16,
.direction = ALP_I2S_DIR_TX,
});
if (i2s == NULL) return -1;
for (size_t i = 0; i < FRAMES; i++) {
double t = (double)i / SAMPLE_RATE;
int16_t s = (int16_t)(sin(2.0 * M_PI * 440.0 * t) * 16384);
pcm[i*2 + 0] = s;
pcm[i*2 + 1] = s;
}
for (int loop = 0; loop < 100; loop++) {
alp_i2s_write(i2s, pcm, FRAMES);
}
alp_i2s_close(i2s);
return 0;
}
See also
<alp/i2s.h>reference<alp/audio.h>— higher-level audio APIaudio-loopback— PDM in → I²S out- Examples overview
Questions about this page? Discuss in Community Forum