Auto Analog Audio v1.55.3
TMRh20 2020 - Automatic DAC, ADC & Timers on Arduino Due
Loading...
Searching...
No Matches
AutoAnalog Class Reference

#include <AutoAnalogAudio.h>

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)
 

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
 
bool manualI2S
 

Detailed Description

Definition at line 36 of file AutoAnalogAudio.h.

Constructor & Destructor Documentation

◆ AutoAnalog()

AutoAnalog::AutoAnalog ( )

Member Function Documentation

◆ begin()

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:

aaAudio.maxBufferSize = YOUR_AUDIO_BUFFER_SIZE;

Third option:

Parameters
enADC0 = Disabled, 1 = PDM input, 2 = I2S input, 3 = SAADC input
enDAC0 = Disabled, 1 = PWM output, 2 = I2S output
_useI2SThis is deprecated, use enADC and enDAC to control inputs/outputs

◆ triggerADC()

void AutoAnalog::triggerADC ( )
Note
This function is no longer required and does nothing

◆ getADC()

void AutoAnalog::getADC ( uint32_t samples = MAX_BUFFER_SIZE)

Load the current ADC data into the ADC Data Buffer

Parameters
samplesThe number of samples to retrieve from the ADC
Note
Changes to the number of samples will not take place until one buffer has been returned with the previous number of samples

◆ feedDAC()

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

Parameters
dacChannel0 for DAC0, 1 for DAC1, 2 for alternating DAC0/DAC1
samplesThe number of samples to send to the DAC
startInterruptsOnly used for the ESP32, this will enable an RTOS task to handle DAC

◆ setSampleRate()

void AutoAnalog::setSampleRate ( uint32_t sampRate = 0,
bool stereo = false )

Set sample rate. 0 enables the default rate specified in AutoAnalog_config.h

Parameters
sampRateThis sets the defined sample rate ie: 32000 is 32Khz
stereoOnly used for the ESP32 & NRF52840 this sets stereo or mono output and affects the sample rate

◆ dacHandler()

void AutoAnalog::dacHandler ( void )

Function called by DAC IRQ

◆ enableAdcChannel()

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

Note
Specify pins numerically: 0=A0, 1=A1, etc...

◆ disableAdcChannel()

void AutoAnalog::disableAdcChannel ( uint8_t pinAx)

Disable reads from the specified channel (pins A0-A6)

Note
Specify pins numerically: 0=A0, 1=A1, etc...

◆ disableDAC()

void AutoAnalog::disableDAC ( bool withinTask = false)

Disable the DAC

Parameters
withinTaskOnly used for ESP32, set to true if calling from within a task itself, see included example

◆ adcInterrupts()

void AutoAnalog::adcInterrupts ( bool enabled = true)

En/Disable the interrupt for the ADC

If enabled, the following function needs to be added:

void ADC_Handler(void){
-code here-
}

◆ dacInterrupts()

void AutoAnalog::dacInterrupts ( bool enabled = true,
bool withinTask = false )

◆ rampOut()

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

Parameters
sampleFor ESP32 only, provide the first or last sample to ramp the signal in/out

◆ rampIn()

void AutoAnalog::rampIn ( uint8_t sample)

Member Data Documentation

◆ dacBuffer

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()

See also
dacBitsPerSample

Definition at line 95 of file AutoAnalogAudio.h.

◆ adcBuffer

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()

See also
adcBitsPerSample

Definition at line 105 of file AutoAnalogAudio.h.

◆ dacBuffer16

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()

See also
dacBitsPerSample

Definition at line 117 of file AutoAnalogAudio.h.

◆ adcBuffer16

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()

See also
adcBitsPerSample

Definition at line 125 of file AutoAnalogAudio.h.

◆ autoAdjust

bool AutoAnalog::autoAdjust

Auto & Manual sample rates. En/Disables automatic adjustment of timers

Default: true

Definition at line 145 of file AutoAnalogAudio.h.

◆ adcBitsPerSample

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 156 of file AutoAnalogAudio.h.

◆ dacBitsPerSample

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 172 of file AutoAnalogAudio.h.

◆ dacTaskHandle

TaskHandle_t AutoAnalog::dacTaskHandle

Definition at line 215 of file AutoAnalogAudio.h.

◆ pwrPin

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 290 of file AutoAnalogAudio.h.

◆ dinPin

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 298 of file AutoAnalogAudio.h.

◆ clkPin

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 306 of file AutoAnalogAudio.h.

◆ gain

int8_t AutoAnalog::gain

Set the Gain for PDM By default this is set to 40 Configure this before calling begin()

Definition at line 313 of file AutoAnalogAudio.h.

◆ I2S_PIN_MCK

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 329 of file AutoAnalogAudio.h.

◆ I2S_PORT_MCK

uint8_t AutoAnalog::I2S_PORT_MCK

Definition at line 330 of file AutoAnalogAudio.h.

◆ I2S_PIN_SCK

uint16_t AutoAnalog::I2S_PIN_SCK

Definition at line 331 of file AutoAnalogAudio.h.

◆ I2S_PORT_SCK

uint8_t AutoAnalog::I2S_PORT_SCK

Definition at line 332 of file AutoAnalogAudio.h.

◆ I2S_PIN_LRCK

uint16_t AutoAnalog::I2S_PIN_LRCK

Definition at line 333 of file AutoAnalogAudio.h.

◆ I2S_PORT_LRCK

uint8_t AutoAnalog::I2S_PORT_LRCK

Definition at line 334 of file AutoAnalogAudio.h.

◆ I2S_PIN_SDOUT

uint16_t AutoAnalog::I2S_PIN_SDOUT

Definition at line 335 of file AutoAnalogAudio.h.

◆ I2S_PORT_SDOUT

uint8_t AutoAnalog::I2S_PORT_SDOUT

Definition at line 336 of file AutoAnalogAudio.h.

◆ I2S_PIN_SDIN

uint16_t AutoAnalog::I2S_PIN_SDIN

Definition at line 337 of file AutoAnalogAudio.h.

◆ I2S_PORT_SDIN

uint8_t AutoAnalog::I2S_PORT_SDIN

Definition at line 338 of file AutoAnalogAudio.h.

◆ maxBufferSize

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 346 of file AutoAnalogAudio.h.

◆ manualI2S

bool AutoAnalog::manualI2S

This setting allows a special configuration to work with I2S microphones like the SPH0645LM4H-1-8 which use a data format of 24-bit, 2's compliment, MSB first (18-bit precision) and need a 64-bit input signal To use this feature, set manualI2S = true; prior to calling begin(); Uses PWM to generate the I2S signals. Also need to set aaAudio.adcBitsPerSample = 24; and handle the 18-bit data accordingly It will work with either 16Khz or 32Khz sample rates Added for use with my custom Audio PCB found at https://github.com/TMRh20/FeatherAudio

Definition at line 356 of file AutoAnalogAudio.h.


The documentation for this class was generated from the following file: