Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
voct.hpp
Go to the documentation of this file.
1/**
2 * @file voct.hpp
3 * @brief V/Oct input convenience functions
4 * @ingroup hal
5 *
6 * Composes ADC driver reads with VoctInput update in a single call.
7 * Same pattern as sbl::cv::read<Driver>() and sbl::pot::read<Driver>().
8 *
9 * Usage:
10 * #include <sbl/hal/cv/voct.hpp>
11 *
12 * sbl::voct::read<sbl::driver::Adc>(voct, handle, SampleTime::Slow);
13 * float freq = voct.frequency();
14 */
15
16#ifndef SBL_HAL_CV_VOCT_HPP_
17#define SBL_HAL_CV_VOCT_HPP_
18
21
22namespace sbl {
23namespace voct {
24
27
28/**
29 * @brief Read ADC channel and feed into VoctInput
30 *
31 * Blocking read followed by VoctInput::update().
32 *
33 * @tparam Driver ADC driver type (e.g., sbl::driver::Adc)
34 * @param input VoctInput instance to update
35 * @param handle ADC channel handle
36 * @param sample_time Sampling duration (default: Slow for high-Z sources)
37 *
38 * @note Not ISR-safe — wraps blocking ADC polling read
39 */
40template<typename Driver>
41inline void read(VoctInput& input, const AdcHandle& handle,
42 adc::SampleTime sample_time = adc::SampleTime::Slow) {
43 uint16_t raw = adc::read<Driver>(handle, sample_time);
44 input.update(raw);
45}
46
47/**
48 * @brief Read from DMA scan buffer and feed into VoctInput
49 *
50 * For use with sbl::adc::start_scan(). Casts to volatile to ensure the
51 * compiler generates a real memory read (buffer updated by DMA hardware).
52 *
53 * @param input VoctInput instance to update
54 * @param buffer DMA scan buffer (from start_scan)
55 * @param channel_index Index of this channel in the scan sequence
56 *
57 * @note ISR-safe — volatile DMA buffer read, no blocking
58 */
59inline void read_dma(VoctInput& input, const uint16_t* buffer,
60 uint8_t channel_index) {
61 auto raw = static_cast<const volatile uint16_t*>(buffer)[channel_index];
62 input.update(raw);
63}
64
65} // namespace voct
66} // namespace sbl
67
68#endif // SBL_HAL_CV_VOCT_HPP_
V/Oct pitch CV input with smoothing and calibration.
Definition voct.hpp:88
void update(uint16_t raw)
Feed a new raw ADC sample.
Definition voct.hpp:95
V/Oct input component — calibrated pitch CV from ADC values.
ADC driver interface - canonical types for MCU driver implementations.
SampleTime
ADC sample time configuration.
Definition types.hpp:30
void read_dma(VoctInput &input, const uint16_t *buffer, uint8_t channel_index)
Read from DMA scan buffer and feed into VoctInput.
Definition voct.hpp:59
void read(VoctInput &input, const AdcHandle &handle, adc::SampleTime sample_time=adc::SampleTime::Slow)
Read ADC channel and feed into VoctInput.
Definition voct.hpp:41
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
ADC channel handle.
Definition handle.hpp:29
Linear calibration parameters for V/Oct conversion.
Definition voct.hpp:40