Sound Byte Libs 0.5.1-121-g3358a44
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 * Every block the driver clocks out advances SampleClock by its frame count
19 * (sample_clock.hpp), after the callback returns — the elapsed-samples
20 * source for control code.
21 *
22 * ## Convenience Functions
23 *
24 * sbl::audio::start<sbl::driver::Sai>(my_callback);
25 * sbl::audio::stop<sbl::driver::Sai>();
26 *
27 * Usage in application:
28 * \#include <sbl/hw/hal/audio/driver.hpp>
29 * \#include <sbl/hw/driver/sai.hpp>
30 *
31 * sbl::audio::start<sbl::driver::Sai>(audio_callback);
32 */
33
34#ifndef SBL_HW_HAL_AUDIO_DRIVER_HPP_
35#define SBL_HW_HAL_AUDIO_DRIVER_HPP_
36
37#include "types.hpp"
38
39namespace sbl {
40
41namespace audio {
44
45 /**
46 * @brief Configure audio with defaults, set callback, and start streaming
47 *
48 * @tparam Driver Audio driver type (e.g., sbl::driver::Sai)
49 * @param cb Audio processing callback (called from ISR context)
50 *
51 * @note Not ISR-safe — init-time only (configures audio hardware + DMA)
52 */
53 template<typename Driver>
54 inline void start(AudioCallback cb) {
55 Driver::init();
56 Driver::set_callback(cb);
57 Driver::start();
58 }
59
60 /**
61 * @brief Configure with custom settings, set callback, and start streaming
62 *
63 * @tparam Driver Audio driver type (e.g., sbl::driver::Sai)
64 * @param config Audio configuration (sample rate, bit depth, block size)
65 * @param cb Audio processing callback (called from ISR context)
66 *
67 * @note Not ISR-safe — init-time only (configures audio hardware + DMA)
68 */
69 template<typename Driver>
70 inline void start(const AudioConfig& config, AudioCallback cb) {
71 Driver::init(config);
72 Driver::set_callback(cb);
73 Driver::start();
74 }
75
76 /**
77 * @brief Stop audio streaming
78 *
79 * @tparam Driver Audio driver type (e.g., sbl::driver::Sai)
80 *
81 * @note Not ISR-safe — tears down audio streaming hardware
82 */
83 template<typename Driver>
84 inline void stop() {
85 Driver::stop();
86 }
87
88} // namespace audio
89
90} // namespace sbl
91
92#endif // SBL_HW_HAL_AUDIO_DRIVER_HPP_
void start(AudioCallback cb)
Configure audio with defaults, set callback, and start streaming.
Definition driver.hpp:54
void stop()
Stop audio streaming.
Definition driver.hpp:84
sbl::hal::audio::AudioCallback AudioCallback
Definition driver.hpp:43
void(*)(int32_t *tx_buf, const int32_t *rx_buf, uint16_t frames) AudioCallback
Audio processing callback (called from ISR context)
Definition types.hpp:63
Root namespace for all Sound Byte Libs code.
Definition assert.hpp:51
Audio stream configuration.
Definition types.hpp:39
Common types for SBL hardware abstraction.