arduino-audio-tools
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AudioBoardStream Class Reference

New functionality which replaces the AudioKitStream that is based on the legacy AudioKit library. This functionality uses the new arduino-audio-driver library! It is the same as I2SCodecStream extended by some AudioActions and some method calls to determine defined pin values. See https://github.com/pschatzmann/arduino-audio-driver. More...

#include <AudioBoardStream.h>

Inheritance diagram for AudioBoardStream:
I2SCodecStream AudioStream VolumeSupport BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 AudioBoardStream (audio_driver::AudioBoard &board)
 Default constructor: for available AudioBoard values check the audioboard variables in https://pschatzmann.github.io/arduino-audio-driver/html/group__audio__driver.html Further information can be found in https://github.com/pschatzmann/arduino-audio-driver/wiki.
 
float actionVolumeIncrementValue ()
 
void addAction (AudioDriverKey key, void(*action)(bool, int, void *), void *ref=nullptr)
 Defines a new action that is executed when the Button is pressed.
 
void addAction (AudioDriverKey key, void(*actionOn)(bool, int, void *), void(*actionOff)(bool, int, void *), void *ref=nullptr)
 Defines a new action that is executed when the Button is pressed and released.
 
void addAction (int pin, void(*action)(bool, int, void *), AudioActions::ActiveLogic activeLogic, void *ref=nullptr)
 Defines a new action that is executed when the indicated pin is active. More...
 
void addAction (int pin, void(*action)(bool, int, void *), void *ref=nullptr)
 Defines a new action that is executed when the indicated pin is active. More...
 
void addDefaultActions ()
 Setup the supported default actions (volume, start/stop, headphone detection)
 
void addHeadphoneDetectionAction ()
 Adds headphone determination.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
void addStartStopAction ()
 add start/stop on inputMode
 
void addVolumeActions ()
 add volume up and volume down action
 
AudioActionsaudioActions ()
 Provides access to the AudioActions.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
 
virtual int available () override
 Provides the available audio data.
 
virtual int availableForWrite () override
 Provides the available audio data.
 
bool begin () override
 
bool begin (I2SCodecConfig cfg) override
 Starts the I2S interface.
 
AudioBoard & board ()
 Provides the board.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
I2SCodecConfig defaultConfig (RxTxMode mode=TX_MODE)
 Provides the default configuration.
 
I2SDriverdriver ()
 Provides the i2s driver.
 
void end ()
 Stops the I2S interface.
 
virtual void flush () override
 
AudioActionsgetActions ()
 
GpioPin getKey (int pos)
 Provides the gpio for the indicated key pos.
 
GpioPin getPinID (PinFunction function)
 Provides the gpio for the indicated function.
 
GpioPin getPinID (PinFunction function, int pos)
 Provides the gpio for the indicated function.
 
DriverPins & getPins ()
 Provides access to the pin information.
 
float getVolume ()
 legacy: same as volume()
 
bool hasBoard ()
 checks if a board has been defined
 
bool headphoneStatus ()
 Returns true if the headphone was detected. More...
 
void incrementVolume (float inc)
 Relative volume control. More...
 
bool isKeyPressed (int key)
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
GpioPin pinAuxin ()
 Get the gpio number for auxin detection. More...
 
GpioPin pinHeadphoneDetect ()
 Get the gpio number for headphone detection. More...
 
GpioPin pinInputMode ()
 Get the number for mode-button. More...
 
GpioPin pinInputPlay ()
 Get number for play function. More...
 
GpioPin pinInputRec ()
 Get the record-button id for adc-button. More...
 
GpioPin pinInputSet ()
 Get number for set function. More...
 
GpioPin pinLed (int idx)
 Get LED pin. More...
 
GpioPin pinPaEnable ()
 Get the gpio number for PA enable. More...
 
GpioPin pinVolumeDown ()
 Get number for volume down function. More...
 
GpioPin pinVolumeUp ()
 number for volume up function More...
 
void processActions ()
 Process input keys and pins.
 
virtual size_t readBytes (uint8_t *data, size_t len) override
 Reads the audio data.
 
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
void setActionVolumeIncrementValue (float value)
 Defines the increment value used by actionVolumeDown/actionVolumeUp.
 
void setActive (bool active)
 The oposite of setMute(): setActive(true) calls setMute(false)
 
virtual void setAudioInfo (AudioInfo info)
 updates the sample rate dynamically
 
void setBoard (AudioBoard &board)
 (re)defines the board
 
void setBoard (AudioBoard *board)
 (re)defines the board
 
bool setInputVolume (float vol)
 Sets the volume of the microphone (if available)
 
bool setMute (bool mute)
 Mute / unmote.
 
bool setMute (bool mute, int line)
 Mute / unmute of an individual line (codec)
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
bool setPAPower (bool active)
 Sets the output of the PA Power Pin.
 
void setSpeakerActive (bool active)
 the same as setPAPower()
 
bool setVolume (float vol) override
 sets the volume (range 0.0f - 1.0f)
 
float volume () override
 Provides the actual volume (0.0f - 1.0f)
 
virtual size_t write (const uint8_t *data, size_t len)
 Writes the audio data to I2S.
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Static Public Member Functions

static void actionHeadphoneDetection (bool, int, void *ref)
 Switch off the PA if the headphone in plugged in and switch it on again if the headphone is unplugged. This method complies with the.
 
static void actionStart (bool, int, void *ref)
 Start.
 
static void actionStartStop (bool, int, void *ref)
 Toggle start stop.
 
static void actionStop (bool, int, void *ref)
 Stop.
 
static void actionVolumeDown (bool, int, void *ref)
 Decrease the volume.
 
static void actionVolumeUp (bool, int, void *ref)
 Increase the volume.
 

Protected Member Functions

bool begin1 ()
 
bool beginCodec (I2SCodecConfig info)
 
AudioActions::ActiveLogic getActionLogic (int pin)
 Determines the action logic (ActiveLow or ActiveTouch) for the pin.
 
audio_driver_local::Optional< PinsI2S > getI2SPins ()
 
int getSdCsPin ()
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 
void setupI2SFunction ()
 if the cfg.i2s_function was not defined we determine the "correct" default value
 
void setupI2SPins ()
 We use the board pins if they are available.
 
sample_bits_t toCodecBits (int bits)
 
i2s_format_t toFormat (I2SFormat fmt)
 
samplerate_t toRate (int rate)
 

Protected Attributes

int _timeout = 10
 
float action_increment_value = 0.02
 
AudioActions actions
 
bool active = true
 
I2SCodecConfig cfg
 
CodecConfig codec_cfg
 
bool headphoneIsConnected = false
 
I2SStream i2s
 
AudioInfo info
 
bool is_active = false
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
AudioBoard * p_board = nullptr
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
float volume_value = 1.0f
 

Detailed Description

New functionality which replaces the AudioKitStream that is based on the legacy AudioKit library. This functionality uses the new arduino-audio-driver library! It is the same as I2SCodecStream extended by some AudioActions and some method calls to determine defined pin values. See https://github.com/pschatzmann/arduino-audio-driver.

Author
Phil Schatzmann

Member Function Documentation

◆ addAction() [1/2]

void addAction ( int  pin,
void(*)(bool, int, void *)  action,
AudioActions::ActiveLogic  activeLogic,
void *  ref = nullptr 
)
inline

Defines a new action that is executed when the indicated pin is active.

Parameters
pin
action
activeLogic
ref

◆ addAction() [2/2]

void addAction ( int  pin,
void(*)(bool, int, void *)  action,
void *  ref = nullptr 
)
inline

Defines a new action that is executed when the indicated pin is active.

Parameters
pin
action
ref

◆ headphoneStatus()

bool headphoneStatus ( )
inline

Returns true if the headphone was detected.

Returns
true
false

◆ incrementVolume()

void incrementVolume ( float  inc)
inline

Relative volume control.

Parameters
vol

◆ pinAuxin()

GpioPin pinAuxin ( )
inline

Get the gpio number for auxin detection.

Returns
-1 non-existent Others gpio number

◆ pinHeadphoneDetect()

GpioPin pinHeadphoneDetect ( )
inline

Get the gpio number for headphone detection.

Returns
-1 non-existent Others gpio number

◆ pinInputMode()

GpioPin pinInputMode ( )
inline

Get the number for mode-button.

Returns
-1 non-existent Others number

◆ pinInputPlay()

GpioPin pinInputPlay ( )
inline

Get number for play function.

Returns
-1 non-existent Others number

◆ pinInputRec()

GpioPin pinInputRec ( )
inline

Get the record-button id for adc-button.

Returns
-1 non-existent Others button id

◆ pinInputSet()

GpioPin pinInputSet ( )
inline

Get number for set function.

Returns
-1 non-existent Others number

◆ pinLed()

GpioPin pinLed ( int  idx)
inline

Get LED pin.

Returns
-1 non-existent Others gpio number

◆ pinPaEnable()

GpioPin pinPaEnable ( )
inline

Get the gpio number for PA enable.

Returns
-1 non-existent Others gpio number

◆ pinVolumeDown()

GpioPin pinVolumeDown ( )
inline

Get number for volume down function.

Returns
-1 non-existent Others number

◆ pinVolumeUp()

GpioPin pinVolumeUp ( )
inline

number for volume up function

Returns
-1 non-existent Others number

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