BackgroundAudio 1.3.3
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
BackgroundAudioMixerInput Class Reference

Implements an emulated AudioOutputBase and feeds resampled data from it up to an input of an AudioOutputMixer object. More...

#include <BackgroundAudioMixer.h>

Inheritance diagram for BackgroundAudioMixerInput:
Inheritance graph
[legend]
Collaboration diagram for BackgroundAudioMixerInput:
Collaboration graph
[legend]

Public Member Functions

 BackgroundAudioMixerInput (int outputRate, size_t outputBufferWords)
 Create a mixer with a defined sample rate and buffer size.
 
virtual bool setBuffers (size_t buffers, size_t bufferWords, int32_t silenceSample=0) override
 Set the size and number of the resample buffers before begin
 
virtual bool setBitsPerSample (int bps) override
 Set the bits per sample for the emulated output. Only 16-bit supported.
 
virtual bool setFrequency (int freq) override
 Set the sample rate (LRCLK/WS) of the emulated interface. Can be called while running.
 
virtual bool setStereo (bool stereo=true) override
 Set mono or stereo mode. Only stereo supported.
 
virtual bool begin () override
 Start the emulated interface.
 
virtual bool end () override
 Stop the mixer input leg, not implemented.
 
virtual bool getUnderflow () override
 Determine if there was an underflow since the last time this was called. Cleared on read.
 
virtual void onTransmit (void(*cb)(void *), void *cbData) override
 Set the callback function to be called every mixer buffer completion.
 
virtual size_t write (uint8_t)
 Write single byte to I2S buffers. Not supported.
 
virtual size_t write (const uint8_t *buffer, size_t size) override
 Write data to the input leg interface. Will not block and may write less than requested.
 
virtual int availableForWrite () override
 Determine the number of bytes we can write to the resample buffers at this instant.
 

Friends

template<size_t >
class BackgroundAudioMixer
 

Detailed Description

Implements an emulated AudioOutputBase and feeds resampled data from it up to an input of an AudioOutputMixer object.

The mixer input will buffer output from one audio source and resample to the mixer frequency so it can be summed up and output.

Each input will have a buffer ready to be summed with the others. The mixer will take the pointers to this and do the sum operation w/o actually copying it out. As data is read from the mixerInputBuffer, it will be repopulated with (resampled) data from the source buffers. Every time the a full source buffer is read a CB will be fired, just like in the AudioBufferManager. (i.e. the mixedrinput will behave like the ABM for simplicity.)

In general an end user never need use this class directly and can just treat the input leg of the mixer as an ordinary audio output.

Member Function Documentation

◆ availableForWrite()

virtual int BackgroundAudioMixerInput::availableForWrite ( )
inlineoverridevirtual

Determine the number of bytes we can write to the resample buffers at this instant.

Returns
Number of bytes available. May not be completely accurate

◆ begin()

virtual bool BackgroundAudioMixerInput::begin ( )
inlineoverridevirtual

Start the emulated interface.

Doesn't actually start any hardware or interfaces (the AudioMixer owns the hardware device and combines multiple input legs. Does set up the resampling audio buffer for use by the mixer as needed.

Returns
True on success

◆ end()

virtual bool BackgroundAudioMixerInput::end ( )
inlineoverridevirtual

Stop the mixer input leg, not implemented.

Returns
False on failure

◆ getUnderflow()

virtual bool BackgroundAudioMixerInput::getUnderflow ( )
inlineoverridevirtual

Determine if there was an underflow since the last time this was called. Cleared on read.

Returns
True if an underflow occurred.

◆ onTransmit()

virtual void BackgroundAudioMixerInput::onTransmit ( void(*)(void *)  cb,
void *  cbData 
)
inlineoverridevirtual

Set the callback function to be called every mixer buffer completion.

Parameters
[in]cbCallback function
[in]cbDataData to be passed to the callback function

◆ setBitsPerSample()

virtual bool BackgroundAudioMixerInput::setBitsPerSample ( int  bps)
inlineoverridevirtual

Set the bits per sample for the emulated output. Only 16-bit supported.

Parameters
[in]bpsBits per sample, only 16-bit supported
Returns
True if successful

◆ setBuffers()

virtual bool BackgroundAudioMixerInput::setBuffers ( size_t  buffers,
size_t  bufferWords,
int32_t  silenceSample = 0 
)
inlineoverridevirtual

Set the size and number of the resample buffers before begin

Parameters
[in]buffersNumber of I2S DMA buffers
[in]bufferWordsNumber of 32-bit words (i.e. a single stereo 16-bit sample) per each DMA buffer
[in]silenceSampleOptional 32-bit value to send out in case of underflow, normally 0
Returns
True if parameters were successful

◆ setFrequency()

virtual bool BackgroundAudioMixerInput::setFrequency ( int  freq)
inlineoverridevirtual

Set the sample rate (LRCLK/WS) of the emulated interface. Can be called while running.

This setting does not affect the actual resample rate of data sent up the chain to the mixer owner. This is only to allow a decoder to indicate whatever sample rate is required for incoming data.

Parameters
[in]freqNew sampling frequency in hertz
Returns
True if succeeded

◆ setStereo()

virtual bool BackgroundAudioMixerInput::setStereo ( bool  stereo = true)
inlineoverridevirtual

Set mono or stereo mode. Only stereo supported.

Parameters
[in]stereoSet to true for stereo (L/R) output
Returns
True if success

◆ write() [1/2]

virtual size_t BackgroundAudioMixerInput::write ( const uint8_t *  buffer,
size_t  size 
)
inlineoverridevirtual

Write data to the input leg interface. Will not block and may write less than requested.

Parameters
[in]bufferData to be written
[in]sizeNumber of bytes to write.
Returns
Number of bytes actually written to the resample buffer

◆ write() [2/2]

virtual size_t BackgroundAudioMixerInput::write ( uint8_t  )
inlinevirtual

Write single byte to I2S buffers. Not supported.

Returns
0 always

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