Auto Analog Audio v1.53.0
TMRh20 2020 - Automatic DAC, ADC & Timers on Arduino Due
|
#include <AutoAnalogAudio.h>
Public Attributes | |
Section for nRF52 Devices Only | |
This section is for nRF52 devices only | |
int | pwrPin |
int | dinPin |
int | clkPin |
int8_t | gain |
uint16_t | I2S_PIN_MCK |
uint8_t | I2S_PORT_MCK |
uint16_t | I2S_PIN_SCK |
uint8_t | I2S_PORT_SCK |
uint16_t | I2S_PIN_LRCK |
uint8_t | I2S_PORT_LRCK |
uint16_t | I2S_PIN_SDOUT |
uint8_t | I2S_PORT_SDOUT |
uint16_t | I2S_PIN_SDIN |
uint8_t | I2S_PORT_SDIN |
uint32_t | maxBufferSize |
User Interface | |
Main methods to drive the library | |
uint8_t | dacBuffer [MAX_BUFFER_SIZE] |
uint8_t | adcBuffer [MAX_BUFFER_SIZE] |
uint16_t | dacBuffer16 [MAX_BUFFER_SIZE] |
uint16_t | adcBuffer16 [MAX_BUFFER_SIZE] |
bool | autoAdjust |
uint8_t | adcBitsPerSample |
uint8_t | dacBitsPerSample |
TaskHandle_t | dacTaskHandle |
AutoAnalog () | |
void | begin (uint8_t enADC, uint8_t enDAC, uint8_t _useI2S=0) |
void | triggerADC () |
void | getADC (uint32_t samples=MAX_BUFFER_SIZE) |
void | feedDAC (uint8_t dacChannel=0, uint32_t samples=MAX_BUFFER_SIZE, bool startInterrupts=false) |
void | setSampleRate (uint32_t sampRate=0, bool stereo=false) |
void | dacHandler (void) |
void | enableAdcChannel (uint8_t pinAx) |
void | disableAdcChannel (uint8_t pinAx) |
void | disableDAC (bool withinTask=false) |
void | adcInterrupts (bool enabled=true) |
void | dacInterrupts (bool enabled=true, bool withinTask=false) |
void | rampOut (uint8_t sample) |
void | rampIn (uint8_t sample) |
Definition at line 37 of file AutoAnalogAudio.h.
AutoAnalog::AutoAnalog | ( | ) |
void AutoAnalog::begin | ( | uint8_t | enADC, |
uint8_t | enDAC, | ||
uint8_t | _useI2S = 0 |
||
) |
Setup the timer(s)
Make sure to define your chosen pins before calling begin();
NRF52 Only: Call the below code prior to begin() to limit memory usage/buffer sizes:
Third option:
enADC | 0 = Disabled, 1 = PDM input, 2 = I2S input, 3 = SAADC input |
enDAC | 0 = Disabled, 1 = PWM output, 2 = I2S output |
_useI2S | This is deprecated, use enADC and enDAC to control inputs/outputs |
void AutoAnalog::triggerADC | ( | ) |
void AutoAnalog::getADC | ( | uint32_t | samples = MAX_BUFFER_SIZE | ) |
Load the current ADC data into the ADC Data Buffer
samples | The number of samples to retrieve from the ADC |
void AutoAnalog::feedDAC | ( | uint8_t | dacChannel = 0 , |
uint32_t | samples = MAX_BUFFER_SIZE , |
||
bool | startInterrupts = false |
||
) |
Feed the current PCM/WAV data into the DAC for playback
dacChannel | 0 for DAC0, 1 for DAC1, 2 for alternating DAC0/DAC1 |
samples | The number of samples to send to the DAC |
startInterrupts | Only used for the ESP32, this will enable an RTOS task to handle DAC |
void AutoAnalog::setSampleRate | ( | uint32_t | sampRate = 0 , |
bool | stereo = false |
||
) |
Set sample rate. 0 enables the default rate specified in AutoAnalog_config.h
sampRate | This sets the defined sample rate ie: 32000 is 32Khz |
stereo | Only used for the ESP32 & NRF52840 this sets stereo or mono output and affects the sample rate |
void AutoAnalog::dacHandler | ( | void | ) |
Function called by DAC IRQ
void AutoAnalog::enableAdcChannel | ( | uint8_t | pinAx | ) |
Enable reads from the specified channel (pins A0-A6)
Active ADC Channels will be read in numeric order, high to low
void AutoAnalog::disableAdcChannel | ( | uint8_t | pinAx | ) |
Disable reads from the specified channel (pins A0-A6)
void AutoAnalog::disableDAC | ( | bool | withinTask = false | ) |
Disable the DAC
withinTask | Only used for ESP32, set to true if calling from within a task itself, see included example |
void AutoAnalog::adcInterrupts | ( | bool | enabled = true | ) |
En/Disable the interrupt for the ADC
If enabled, the following function needs to be added:
void AutoAnalog::dacInterrupts | ( | bool | enabled = true , |
bool | withinTask = false |
||
) |
void AutoAnalog::rampOut | ( | uint8_t | sample | ) |
Rampout and RampIn functions ramp the signal in/out to minimize 'pop' sound made when en/disabling the DAC
sample | For ESP32 only, provide the first or last sample to ramp the signal in/out |
void AutoAnalog::rampIn | ( | uint8_t | sample | ) |
uint8_t AutoAnalog::dacBuffer[MAX_BUFFER_SIZE] |
DAC data buffer for 8-bit samples
8-bit user samples are loaded directly into this buffer before calling feedDAC()
Definition at line 95 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::adcBuffer[MAX_BUFFER_SIZE] |
ADC Data buffer for 8-bit samples
8-bit samples are read directly from this buffer after calling getADC()
Definition at line 102 of file AutoAnalogAudio.h.
uint16_t AutoAnalog::dacBuffer16[MAX_BUFFER_SIZE] |
DAC data buffer for 10 or 12-bit samples
10 or 12-bit user samples are loaded directly into this buffer before calling feedDAC()
Definition at line 109 of file AutoAnalogAudio.h.
uint16_t AutoAnalog::adcBuffer16[MAX_BUFFER_SIZE] |
ADC Data buffer for 10 or 12-bit samples
10 or 12-bit samples are read directly from this buffer after calling getADC()
Definition at line 117 of file AutoAnalogAudio.h.
bool AutoAnalog::autoAdjust |
Auto & Manual sample rates. En/Disables automatic adjustment of timers
Default: true
Definition at line 137 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::adcBitsPerSample |
ADC (Analog to Digital Converter)
Select the bits-per-sample for incoming data
Default: 8:8-bit, 10:10-bit, 12:12-bit
There are two separate data buffers for the ADC,selected by setting this variable.
adcBuffer[] is an 8-bit buffer used solely for your 8-bit samples
adcBuffer16[] is a 16-bit buffer used solely for placing your 10 and 12-bit samples
Definition at line 148 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::dacBitsPerSample |
DAC (Digital to Analog Converter)
Select the bits-per-sample for incoming data
Default: 8:8-bit, 10:10-bit, 12:12-bit
There are two separate data buffers for the DAC, selected by setting this variable.
dacBuffer[] is an 8-bit buffer used solely for your 8-bit samples
dacBuffer16[] is a 16-bit buffer used solely for placing your 10 and 12-bit samples
Definition at line 159 of file AutoAnalogAudio.h.
TaskHandle_t AutoAnalog::dacTaskHandle |
Definition at line 202 of file AutoAnalogAudio.h.
int AutoAnalog::pwrPin |
Set the Power Pin for PDM
By default this is PIN_PDM_PWR
If PIN_PDM_PWR is not defined, it is set to -1 by default
Configure this before calling begin()
Definition at line 258 of file AutoAnalogAudio.h.
int AutoAnalog::dinPin |
Set the Input Pin for PDM or SAADC. With SAADC AIN0 is 1, AIN1 is 2 etc. By default this is PIN_PDM_DIN
If PIN_PDM_DIN is not defined, it is set to 35 by default
Configure this before calling begin()
Definition at line 266 of file AutoAnalogAudio.h.
int AutoAnalog::clkPin |
Set the Clock Pin for PDM
By default this is PIN_PDM_CLK
If PIN_PDM_CLK is not defined, it is set to 36 by default
Configure this before calling begin()
Definition at line 274 of file AutoAnalogAudio.h.
int8_t AutoAnalog::gain |
Set the Gain for PDM
By default this is set to 40
Configure this before calling begin()
Definition at line 281 of file AutoAnalogAudio.h.
uint16_t AutoAnalog::I2S_PIN_MCK |
Configure the pins and ports for nRF52 using GPIO numbers before calling begin()
Defaults:
I2S_PIN_MCK = 2;
I2S_PORT_MCK = 0;
I2S_PIN_SCK = 3;
I2S_PORT_SCK = 0;
I2S_PIN_LRCK = 29;
I2S_PORT_LRCK = 0;
I2S_PIN_SDOUT = 5;
I2S_PORT_SDOUT = 0;
I2S_PIN_SDIN = 4;
I2S_PORT_SDIN = 0;
Definition at line 297 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::I2S_PORT_MCK |
Definition at line 298 of file AutoAnalogAudio.h.
uint16_t AutoAnalog::I2S_PIN_SCK |
Definition at line 299 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::I2S_PORT_SCK |
Definition at line 300 of file AutoAnalogAudio.h.
uint16_t AutoAnalog::I2S_PIN_LRCK |
Definition at line 301 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::I2S_PORT_LRCK |
Definition at line 302 of file AutoAnalogAudio.h.
uint16_t AutoAnalog::I2S_PIN_SDOUT |
Definition at line 303 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::I2S_PORT_SDOUT |
Definition at line 304 of file AutoAnalogAudio.h.
uint16_t AutoAnalog::I2S_PIN_SDIN |
Definition at line 305 of file AutoAnalogAudio.h.
uint8_t AutoAnalog::I2S_PORT_SDIN |
Definition at line 306 of file AutoAnalogAudio.h.
uint32_t AutoAnalog::maxBufferSize |
Set the maximum buffer size for nRF52
The internal buffers are all allocated dynamically.
By default the MAX_BUFFER_SIZE is defined in AutoAnalogAudio_config.h
Override that value for internal buffers by setting this before calling begin()
Definition at line 314 of file AutoAnalogAudio.h.