---
title: "Audio Loopback"
description: "PDM microphone in → I²S speaker out. Demonstrates the audio capture-and-playback path from ``."
source: https://docs.alplab.ai/sdk/examples/audio-loopback
---

# `audio-loopback`

PDM microphone in → I²S speaker out. Demonstrates the audio capture-and-playback path from [`<alp/audio.h>`](https://docs.alplab.ai/sdk/api/audio).

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

## `board.yaml`

```yaml
som:
  sku: E1M-AEN801

preset: e1m-evk

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

diagnostics:
  log_level: info
```

PDM RX support (`CONFIG_AUDIO_DMIC=y`) lives under Zephyr's audio subsystem rather than as a standalone `peripherals:` entry — `testcase.yaml`'s extra args wire it on. The application code uses the unified `<alp/audio.h>` surface.

## Source (abbreviated)

```c
#include "alp/audio.h"
#include "alp/e1m_pinout.h"
#include "alp/board.h"

#define FRAMES 256
static int16_t g_pcm[FRAMES];

int main(void) {
    alp_audio_config_t cfg = {
        .peripheral_id    = ALP_E1M_PDM0,
        .sample_rate_hz   = 16000,
        .channels         = 1,
        .format           = ALP_AUDIO_FMT_S16_LE,
        .frames_per_block = FRAMES,
    };
    alp_audio_in_t *mic = alp_audio_in_open(&cfg);       /* PDM microphones */
    if (mic == NULL) return 0;

    cfg.peripheral_id = BOARD_I2S_AUDIO;                 /* I2S to the amplifiers */
    alp_audio_out_t *spk = alp_audio_out_open(&cfg);
    if (spk == NULL) { alp_audio_in_close(mic); return 0; }

    alp_audio_in_start(mic);
    alp_audio_out_start(spk);

    for (int b = 0; b < 50; ++b) {
        size_t got = 0, pushed = 0;
        if (alp_audio_in_read(mic, g_pcm, FRAMES, &got, 1000) != ALP_OK || got == 0) {
            break;
        }
        alp_audio_out_write(spk, g_pcm, got, &pushed, 1000);
    }

    alp_audio_out_stop(spk);
    alp_audio_in_stop(mic);
    alp_audio_out_close(spk);
    alp_audio_in_close(mic);
    return 0;
}
```

Both directions take the same `alp_audio_config_t`, and both must be started with `alp_audio_in_start()` / `alp_audio_out_start()` before any data moves.

## See also

- [`<alp/audio.h>` reference](https://docs.alplab.ai/sdk/api/audio)
- [`i2s-tone`](https://docs.alplab.ai/sdk/examples/i2s-tone) — pure I²S output
- [Examples overview](https://docs.alplab.ai/sdk/examples/overview)
