examples/device/audio_test_multi_rate/README.md
A single-channel USB microphone test example that supports multiple sample rates and adapts its descriptors to the negotiated USB bus speed — UAC1 at Full-Speed and UAC2 at High-Speed.
| Interface | Class driver |
|---|---|
| 0–1 | Audio (control + streaming), 1-channel microphone input — UAC1 at Full-Speed, UAC2 at High-Speed |
Notable tusb_config.h settings:
#define CFG_TUD_AUDIO 1
#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE 96000
#define CFG_TUD_AUDIO_FUNC_1_N_FORMATS 2
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX 2 // 16-bit in 16-bit slots
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX 16
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX 4 // 24-bit in 32-bit slots (UAC2 only)
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX 24
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN, TU_MAX(CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN))
CMake:
mkdir build && cd build
cmake -DBOARD=raspberry_pi_pico ..
cmake --build .
Make:
make BOARD=raspberry_pi_pico all
The device appears as a single-channel USB microphone. On Linux, list it with arecord -l and record at a chosen rate with arecord, e.g. arecord -D hw:CARD=MicNode -c 1 -f S16_LE -r 96000 test.wav, trying 32000/48000/96000 to exercise rate switching. On a High-Speed host you can also select the 24-bit format (-f S24_3LE / S32_LE depending on the host). The included src/plot_audio_samples.py records and plots the signal.