Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1/**
2 * @file types.hpp
3 * @brief Audio common types and configuration
4 * @ingroup hal
5 *
6 * Platform-agnostic audio types shared across the HAL layer.
7 * These types are used by both the HAL interface and platform implementations.
8 *
9 * Audio drivers (SAI, I2S, etc.) include this header and use these types
10 * in their public interface, ensuring a consistent contract across platforms.
11 */
12
13#ifndef SBL_HAL_AUDIO_TYPES_HPP_
14#define SBL_HAL_AUDIO_TYPES_HPP_
15
16#include <cstdint>
17
18namespace sbl {
19namespace hal {
20namespace audio {
21
22/**
23 * @brief SAI block direction layout
24 *
25 * Determines which SAI block is TX (to DAC) and which is RX (from ADC).
26 * This is board-level configuration — the codec wiring determines the mapping.
27 */
28enum class SaiLayout {
29 A_TX_B_RX, ///< Block A = Master TX, Block B = Slave RX (Daisy Seed / AK4556)
30 A_RX_B_TX ///< Block A = Slave RX, Block B = Master TX (Patch SM / PCM3060)
31};
32
33/**
34 * @brief Audio stream configuration
35 *
36 * Describes the audio format for streaming. Drivers may ignore fields
37 * that are fixed by hardware (e.g., sample_rate when set by PLL).
38 */
40 uint32_t sample_rate = 48000; ///< Sample rate in Hz
41 uint8_t bit_depth = 24; ///< Bits per sample
42 uint16_t block_size = 48; ///< Stereo frames per callback
43 SaiLayout layout = SaiLayout::A_TX_B_RX; ///< SAI block direction
44};
45
46/**
47 * @brief Audio processing callback (called from ISR context)
48 *
49 * Audio samples are int32_t in 24-bit signed range (±8,388,607).
50 * Saturation is the caller's responsibility — use sbl::dsp::saturate_24()
51 * from <sbl/dsp/fixed.hpp> before writing to tx_buf. The SAI driver outputs
52 * raw values with no implicit clamping.
53 *
54 * @param tx_buf Interleaved output [L0,R0,L1,R1,...] - fill these
55 * @param rx_buf Interleaved input [L0,R0,L1,R1,...] - read-only
56 * @param frames Number of stereo frames (= block_size from AudioConfig)
57 */
58using AudioCallback = void(*)(int32_t* tx_buf, const int32_t* rx_buf, uint16_t frames);
59
60} // namespace audio
61} // namespace hal
62} // namespace sbl
63
64#endif // SBL_HAL_AUDIO_TYPES_HPP_
void(*)(int32_t *tx_buf, const int32_t *rx_buf, uint16_t frames) AudioCallback
Audio processing callback (called from ISR context)
Definition types.hpp:58
SaiLayout
SAI block direction layout.
Definition types.hpp:28
@ A_TX_B_RX
Block A = Master TX, Block B = Slave RX (Daisy Seed / AK4556)
@ A_RX_B_TX
Block A = Slave RX, Block B = Master TX (Patch SM / PCM3060)
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
Audio stream configuration.
Definition types.hpp:39
uint8_t bit_depth
Bits per sample.
Definition types.hpp:41
SaiLayout layout
SAI block direction.
Definition types.hpp:43
uint16_t block_size
Stereo frames per callback.
Definition types.hpp:42
uint32_t sample_rate
Sample rate in Hz.
Definition types.hpp:40