arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
I2SCodecStream Class Reference

I2S Stream which also sets up a codec chip and i2s. More...

#include <I2SCodecStream.h>

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

Public Member Functions

 I2SCodecStream ()=default
 Default Constructor (w/o codec)
 
 I2SCodecStream (AudioBoard &board)
 Default constructor: for available AudioBoard values check 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.
 
 I2SCodecStream (AudioBoard *board)
 Provide board via pointer.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int available () override
 Provides the available audio data.
 
virtual int availableForWrite () override
 Provides the available audio data.
 
bool begin ()
 
virtual bool begin (I2SCodecConfig cfg)
 Starts the I2S interface.
 
AudioBoardboard ()
 Provides the board.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
I2SCodecConfig defaultConfig (RxTxMode mode=TX_MODE)
 Provides the default configuration.
 
bool digitalRead (int pin)
 get value of digital pin
 
void digitalWrite (int pin, bool value)
 set value of digital pin
 
I2SDriverdriver ()
 Provides the i2s driver.
 
void end ()
 Stops the I2S interface.
 
virtual void flush () override
 
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.
 
DriverPinsgetPins ()
 Provides access to the pin information.
 
float getVolume ()
 legacy: same as volume()
 
bool hasBoard ()
 checks if a board has been defined
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
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.
 
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.
 
bool setVolume (float vol) override
 sets the volume (range 0.0f - 1.0f)
 
void setWriteBufferSize (int size)
 
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).
 

Protected Member Functions

bool begin1 ()
 
bool beginCodec (I2SCodecConfig info)
 
audio_driver_local::Optional< PinsI2SgetI2SPins ()
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()
 
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
 
I2SCodecConfig cfg
 
CodecConfig codec_cfg
 
I2SStream i2s
 
AudioInfo info
 
bool is_active = false
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
AudioBoardp_board = nullptr
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
float volume_value = 1.0f
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

I2S Stream which also sets up a codec chip and i2s.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ I2SCodecStream() [1/3]

I2SCodecStream ( )
default

Default Constructor (w/o codec)

◆ I2SCodecStream() [2/3]

I2SCodecStream ( AudioBoard board)
inline

Default constructor: for available AudioBoard values check 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.

◆ I2SCodecStream() [3/3]

I2SCodecStream ( AudioBoard board)
inline

Provide board via pointer.

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

virtual int available ( )
inlineoverridevirtual

Provides the available audio data.

Reimplemented from BaseStream.

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtual

Provides the available audio data.

Reimplemented from BaseStream.

◆ begin() [1/2]

bool begin ( )
inlinevirtual

Reimplemented from BaseStream.

◆ begin() [2/2]

virtual bool begin ( I2SCodecConfig  cfg)
inlinevirtual

Starts the I2S interface.

Reimplemented in AudioBoardStream.

◆ begin1()

bool begin1 ( )
inlineprotected

◆ beginCodec()

bool beginCodec ( I2SCodecConfig  info)
inlineprotected

◆ board()

AudioBoard & board ( )
inline

Provides the board.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ defaultConfig()

I2SCodecConfig defaultConfig ( RxTxMode  mode = TX_MODE)
inline

Provides the default configuration.

◆ digitalRead()

bool digitalRead ( int  pin)
inline

get value of digital pin

◆ digitalWrite()

void digitalWrite ( int  pin,
bool  value 
)
inline

set value of digital pin

◆ driver()

I2SDriver * driver ( )
inline

Provides the i2s driver.

◆ end()

void end ( )
inlinevirtual

Stops the I2S interface.

Reimplemented from BaseStream.

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ getI2SPins()

audio_driver_local::Optional< PinsI2S > getI2SPins ( )
inlineprotected

◆ getKey()

GpioPin getKey ( int  pos)
inline

Provides the gpio for the indicated key pos.

◆ getPinID() [1/2]

GpioPin getPinID ( PinFunction  function)
inline

Provides the gpio for the indicated function.

◆ getPinID() [2/2]

GpioPin getPinID ( PinFunction  function,
int  pos 
)
inline

Provides the gpio for the indicated function.

◆ getPins()

DriverPins & getPins ( )
inline

Provides access to the pin information.

◆ getVolume()

float getVolume ( )
inline

legacy: same as volume()

◆ hasBoard()

bool hasBoard ( )
inline

checks if a board has been defined

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ not_supported()

virtual int not_supported ( int  out,
const char msg = "" 
)
inlineprotectedvirtualinherited

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ readBytes()

virtual size_t readBytes ( uint8_t data,
size_t  len 
)
inlineoverridevirtual

Reads the audio data.

Reimplemented from AudioStream.

◆ readSilence()

virtual size_t readSilence ( uint8_t buffer,
size_t  length 
)
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ refillReadBuffer()

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlinevirtual

updates the sample rate dynamically

Reimplemented from AudioStream.

◆ setBoard() [1/2]

void setBoard ( AudioBoard board)
inline

(re)defines the board

◆ setBoard() [2/2]

void setBoard ( AudioBoard board)
inline

(re)defines the board

◆ setInputVolume()

bool setInputVolume ( float  vol)
inline

Sets the volume of the microphone (if available)

◆ setMute() [1/2]

bool setMute ( bool  mute)
inline

Mute / unmote.

◆ setMute() [2/2]

bool setMute ( bool  mute,
int  line 
)
inline

Mute / unmute of an individual line (codec)

◆ setNotifyActive()

void setNotifyActive ( bool  flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active)

◆ setPAPower()

bool setPAPower ( bool  active)
inline

Sets the output of the PA Power Pin.

◆ setupI2SFunction()

void setupI2SFunction ( )
inlineprotected

if the cfg.i2s_function was not defined we determine the "correct" default value

◆ setupI2SPins()

void setupI2SPins ( )
inlineprotected

We use the board pins if they are available.

◆ setVolume()

bool setVolume ( float  vol)
inlineoverridevirtual

sets the volume (range 0.0f - 1.0f)

Reimplemented from VolumeSupport.

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ toCodecBits()

sample_bits_t toCodecBits ( int  bits)
inlineprotected

◆ toFormat()

i2s_format_t toFormat ( I2SFormat  fmt)
inlineprotected

◆ toRate()

samplerate_t toRate ( int  rate)
inlineprotected

◆ volume()

float volume ( )
inlineoverridevirtual

Provides the actual volume (0.0f - 1.0f)

Reimplemented from VolumeSupport.

◆ write() [1/2]

virtual size_t write ( const uint8_t data,
size_t  len 
)
inlinevirtual

Writes the audio data to I2S.

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

◆ writeSilence()

virtual void writeSilence ( size_t  len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ cfg

I2SCodecConfig cfg
protected

◆ codec_cfg

CodecConfig codec_cfg
protected

◆ i2s

I2SStream i2s
protected

◆ info

AudioInfo info
protectedinherited

◆ is_active

bool is_active = false
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ p_board

AudioBoard* p_board = nullptr
protected

◆ tmp_in

RingBuffer<uint8_t> tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer<uint8_t> tmp_out {0}
protectedinherited

◆ volume_value

float volume_value = 1.0f
protectedinherited

◆ write_buffer_size

int write_buffer_size = MAX_SINGLE_CHARS
protectedinherited

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