---
title: "I²S Tone"
description: "Play a 1 kHz test tone (a 48-sample-period triangle approximation) at 48 kHz, s16 stereo, on BOARDI2SAUDIO — ALPE1MI2S0 on the E1M EVK, ALPE1MX_I2S0 on the E1M-X EVK — as 4 blocks of 256 frames. The minimal demo for ``."
source: https://docs.alplab.ai/sdk/examples/i2s-tone
---

# `i2s-tone`

Play a 1 kHz test tone (a 48-sample-period triangle approximation) at 48 kHz, s16 stereo, on `BOARD_I2S_AUDIO` — `ALP_E1M_I2S0` on the E1M EVK, `ALP_E1M_X_I2S0` on the E1M-X EVK — as 4 blocks of 256 frames. The minimal demo for [`<alp/i2s.h>`](https://docs.alplab.ai/sdk/api/i2s).

Source: [`examples/audio/i2s-tone/`](https://github.com/alplabai/alp-sdk/tree/main/examples/audio/i2s-tone).

## `board.yaml`

```yaml
som:
  sku: E1M-AEN801

preset: e1m-evk

cores:
  m55_hp:
    app: ./src
    peripherals: [i2s]

diagnostics:
  log_level: info
```

## Source (abbreviated)

```c
#include "alp/i2s.h"
#include "alp/board.h"   /* BOARD_I2S_AUDIO */

#define SR             48000u
#define BLOCK_FRAMES   256u
#define BLOCKS_TO_SEND 4u

int main(void)
{
    if (!alp_has(ALP_CAP_ID_HW_I2S)) { /* prints a skip line and "[i2s] done" */ return 0; }

    printf("[i2s] open BOARD_I2S_AUDIO @ 48 kHz s16 stereo TX\n");

    alp_i2s_t *i2s = alp_i2s_open(&(alp_i2s_config_t){
        .bus_id         = BOARD_I2S_AUDIO, /* E1M EVK: ALP_E1M_I2S0; E1M-X EVK: ALP_E1M_X_I2S0 */
        .sample_rate_hz = SR,
        .word_bits      = 16,
        .channels       = 2,
        .format         = ALP_I2S_FMT_I2S,
        .direction      = ALP_I2S_DIR_TX,
        .block_frames   = BLOCK_FRAMES,
    });
    if (i2s == NULL) { /* prints the error and "[i2s] done" */ return 0; }

    alp_status_t s = alp_i2s_start(i2s);
    printf("[i2s] start -> %d\n", (int)s);

    /* One block of a 1 kHz test tone: a 48-sample-period triangle
     * approximation at half amplitude, same on L and R. */
    static int16_t block[BLOCK_FRAMES * 2];
    enum { PERIOD = 48, AMP = 16384 };
    for (uint32_t i = 0; i < BLOCK_FRAMES; i++) {
        uint32_t p = i % PERIOD;
        int32_t  v = (p < PERIOD / 2) ? ((int32_t)p * (4 * AMP) / PERIOD - AMP)
                                      : (3 * AMP - (int32_t)p * (4 * AMP) / PERIOD);
        block[i * 2 + 0] = (int16_t)v;
        block[i * 2 + 1] = (int16_t)v;
    }

    /* alp_i2s_write takes a BYTE count, not a frame count. */
    for (uint32_t b = 0; b < BLOCKS_TO_SEND; b++) {
        s = alp_i2s_write(i2s, block, sizeof block, 100);
        printf("[i2s] write block %u -> %d\n", b, (int)s);
        if (s != ALP_OK) break;
    }

    alp_i2s_stop(i2s);
    alp_i2s_close(i2s);
    printf("[i2s] done\n");
    return 0;
}
```

## See also

- [`<alp/i2s.h>` reference](https://docs.alplab.ai/sdk/api/i2s)
- [`<alp/audio.h>`](https://docs.alplab.ai/sdk/api/audio) — higher-level audio API
- [`audio-loopback`](https://docs.alplab.ai/sdk/examples/audio-loopback) — PDM in → I²S out
- [Examples overview](https://docs.alplab.ai/sdk/examples/overview)
