Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
driver.hpp
Go to the documentation of this file.
1/**
2 * @file driver.hpp
3 * @brief Audio driver interface - canonical types and convenience functions
4 * @ingroup hal
5 *
6 * This header provides the portable audio API for Sound Byte Libs.
7 *
8 * ## Audio Driver Contract
9 *
10 * Drivers implement the following static interface:
11 *
12 * static void init() - Configure with defaults
13 * static void init(const AudioConfig&) - Configure with custom settings
14 * static void set_callback(AudioCallback) - Register processing function
15 * static void start() - Begin streaming
16 * static void stop() - Stop streaming
17 *
18 * ## Convenience Functions
19 *
20 * sbl::audio::start<sbl::driver::Sai>(my_callback);
21 * sbl::audio::stop<sbl::driver::Sai>();
22 *
23 * Usage in application:
24 * #include <sbl/hal/audio/driver.hpp>
25 * #include <sbl/hw/driver/sai.hpp>
26 *
27 * sbl::audio::start<sbl::driver::Sai>(audio_callback);
28 */
29
30#ifndef SBL_HAL_AUDIO_DRIVER_HPP_
31#define SBL_HAL_AUDIO_DRIVER_HPP_
32
33#include "types.hpp"
34
35namespace sbl {
36
37namespace audio {
40
41 /**
42 * @brief Configure audio with defaults, set callback, and start streaming
43 *
44 * @tparam Driver Audio driver type (e.g., sbl::driver::Sai)
45 * @param cb Audio processing callback (called from ISR context)
46 *
47 * @note Not ISR-safe — init-time only (configures audio hardware + DMA)
48 */
49 template<typename Driver>
50 inline void start(AudioCallback cb) {
51 Driver::init();
52 Driver::set_callback(cb);
53 Driver::start();
54 }
55
56 /**
57 * @brief Configure with custom settings, set callback, and start streaming
58 *
59 * @tparam Driver Audio driver type (e.g., sbl::driver::Sai)
60 * @param config Audio configuration (sample rate, bit depth, block size)
61 * @param cb Audio processing callback (called from ISR context)
62 *
63 * @note Not ISR-safe — init-time only (configures audio hardware + DMA)
64 */
65 template<typename Driver>
66 inline void start(const AudioConfig& config, AudioCallback cb) {
67 Driver::init(config);
68 Driver::set_callback(cb);
69 Driver::start();
70 }
71
72 /**
73 * @brief Stop audio streaming
74 *
75 * @tparam Driver Audio driver type (e.g., sbl::driver::Sai)
76 *
77 * @note Not ISR-safe — tears down audio streaming hardware
78 */
79 template<typename Driver>
80 inline void stop() {
81 Driver::stop();
82 }
83
84} // namespace audio
85
86} // namespace sbl
87
88#endif // SBL_HAL_AUDIO_DRIVER_HPP_
void start(AudioCallback cb)
Configure audio with defaults, set callback, and start streaming.
Definition driver.hpp:50
void stop()
Stop audio streaming.
Definition driver.hpp:80
sbl::hal::audio::AudioCallback AudioCallback
Definition driver.hpp:39
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
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
Audio stream configuration.
Definition types.hpp:39
Common types for SBL hardware abstraction.