Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches

Detailed Description

Audio Engine Stream Class
Class that can be created by the addon in order to be able to transfer audiostream data processed on the addon to Kodi and output it audibly.

This can create individually several times and performed in different processes simultaneously.

It has the header #include <kodi/AudioEngine.h> be included to enjoy it.

Function Documentation

◆ CAEStream()

CAEStream ( AudioEngineFormat & format,
unsigned int options = 0 )
inline

Constructs new class to a Kodi IAEStream in the format specified.

Parameters
[in]formatThe data format the incoming audio will be in (e.g. AUDIOENGINE_FMT_S16LE)
[in]options[opt] A bit field of stream options (see: enum AudioEngineStreamOptions)

The following table contains values that can be set with class AudioEngineFormat :

Name Type Set call Get call
Data format, see AudioEngineDataFormat for available types enum SetDataFormat GetDataFormat
Sample rate unsigned int SetSampleRate GetSampleRate
Encoded rate unsigned int SetEncodedRate GetEncodedRate
Channel layout, see AudioEngineChannel for available types std::vector<enum AudioEngineChannel> SetChannelLayout GetChannelLayout
Frames amount unsigned int SetFramesAmount GetFramesAmount
Frame size unsigned int SetFrameSize GetFrameSize

Further is CompareFormat included to compare this class with another.


**Bit options to pass (on Kodi by IAE::MakeStream)**

enum AEStreamOptions Value: Description:
AUDIO_STREAM_FORCE_RESAMPLE 1 << 0 Force resample even if rates match
AUDIO_STREAM_PAUSED 1 << 1 Create the stream paused
AUDIO_STREAM_AUTOSTART 1 << 2 Autostart the stream when enough data is buffered

Example:

#include <kodi/AudioEngine.h>
...
kodi::audioengine::AudioEngineFormat format;
format.SetDataFormat(AUDIOENGINE_FMT_FLOATP); /* The stream's data format (eg, AUDIOENGINE_FMT_S16LE) *&zwj;/
format.SetChannelLayout(std::vector<AudioEngineChannel>(AUDIOENGINE_CH_FL, AUDIOENGINE_CH_FR)); /* The stream's channel layout *&zwj;/
format.SetSampleRate(48000); /* The stream's sample rate (eg, 48000) *&zwj;/
format.SetFrameSize(sizeof(float)*2); /* The size of one frame in bytes *&zwj;/
format.SetFramesAmount(882); /* The number of samples in one frame *&zwj;/
kodi::audioengine::CAEStream* stream = new kodi::audioengine::CAEStream(format, AUDIO_STREAM_AUTOSTART);
@ AUDIOENGINE_FMT_FLOATP
Definition audio_engine.h:217

◆ ~CAEStream()

~CAEStream ( )
inline

Class destructor.

◆ GetSpace()

unsigned int GetSpace ( )
inline

Returns the amount of space available in the stream.

Returns
The number of bytes AddData will consume

◆ AddData()

unsigned int AddData ( uint8_t *const * data,
unsigned int offset,
unsigned int frames,
double pts = 0,
bool hasDownmix = false,
double centerMixLevel = 1.0 )
inline

Add planar or interleaved PCM data to the stream.

Parameters
[in]dataarray of pointers to the planes
[in]offsetto frame in frames
[in]framesnumber of frames
[in]pts[opt] presentation timestamp, default is 0
[in]hasDownmix[opt] set true if downmix is present, default is false
[in]centerMixLevel[opt] level to mix left and right to center default is 1.0
Returns
The number of frames consumed

◆ GetDelay()

double GetDelay ( )
inline

Returns the time in seconds that it will take for the next added packet to be heard from the speakers.

Returns
seconds

◆ IsBuffering()

bool IsBuffering ( )
inline

Returns if the stream is buffering.

Returns
True if the stream is buffering

◆ GetCacheTime()

double GetCacheTime ( )
inline

Returns the time in seconds of the stream's cached audio samples. Engine buffers excluded.

Returns
seconds

◆ GetCacheTotal()

double GetCacheTotal ( )
inline

Returns the total time in seconds of the cache.

Returns
seconds

◆ Pause()

void Pause ( )
inline

Pauses the stream playback.

◆ Resume()

void Resume ( )
inline

Resumes the stream after pausing.

◆ Drain()

void Drain ( bool wait = true)
inline

Start draining the stream.

Parameters
[in]wait[opt] Wait until drain is finished if set to true, otherwise it returns direct
Note
Once called AddData will not consume more data.

◆ IsDraining()

bool IsDraining ( )
inline

Returns true if the is stream draining.

◆ IsDrained()

bool IsDrained ( )
inline

Returns true if the is stream has finished draining.

◆ Flush()

void Flush ( )
inline

Flush all buffers dropping the audio data.

◆ GetVolume()

float GetVolume ( )
inline

Return the stream's current volume level.

Returns
The volume level between 0.0 and 1.0

◆ SetVolume()

void SetVolume ( float volume)
inline

Set the stream's volume level.

Parameters
[in]volumeThe new volume level between 0.0 and 1.0

◆ GetAmplification()

float GetAmplification ( )
inline

Gets the stream's volume amplification in linear units.

Returns
The volume amplification factor between 1.0 and 1000.0

◆ SetAmplification()

void SetAmplification ( float amplify)
inline

Sets the stream's volume amplification in linear units.

Parameters
[in]amplifyThe volume amplification factor between 1.0 and 1000.0

◆ GetFrameSize()

unsigned int GetFrameSize ( ) const
inline

Returns the size of one audio frame in bytes (channelCount * resolution).

Returns
The size in bytes of one frame

◆ GetChannelCount()

unsigned int GetChannelCount ( ) const
inline

Returns the number of channels the stream is configured to accept.

Returns
The channel count

◆ GetSampleRate()

unsigned int GetSampleRate ( ) const
inline

Returns the stream's sample rate, if the stream is using a dynamic sample rate, this value will NOT reflect any changes made by calls to SetResampleRatio().

Returns
The stream's sample rate (eg, 48000)

◆ GetDataFormat()

AudioEngineDataFormat GetDataFormat ( ) const
inline

Return the data format the stream has been configured with.

Returns
The stream's data format (eg, AUDIOENGINE_FMT_S16LE)

◆ GetResampleRatio()

double GetResampleRatio ( )
inline

Return the resample ratio.

Note
This will return an undefined value if the stream is not resampling.
Returns
the current resample ratio or undefined if the stream is not resampling

◆ SetResampleRatio()

void SetResampleRatio ( double ratio)
inline

Sets the resample ratio.

Note
This function may return false if the stream is not resampling, if you wish to use this be sure to set the AESTREAM_FORCE_RESAMPLE option.
Parameters
[in]ratiothe new sample rate ratio, calculated by ((double)desiredRate / (double)GetSampleRate())