GstAudio.AudioConverter

Fields

None

Methods

class

new (flags, in_info, out_info, config)

convert (flags, in_)

free ()

get_config ()

get_in_frames (out_frames)

get_max_latency ()

get_out_frames (in_frames)

is_passthrough ()

reset ()

samples (flags, in_, in_frames, out, out_frames)

supports_inplace ()

update_config (in_rate, out_rate, config)

Details

class GstAudio.AudioConverter

This object is used to convert audio samples from one format to another. The object can perform conversion of:

  • audio format with optional dithering and noise shaping

  • audio samplerate

  • audio channels and channel layout

New in version 1.8.

classmethod new(flags, in_info, out_info, config)
Parameters:
Returns:

a GstAudio.AudioConverter or None if conversion is not possible.

Return type:

GstAudio.AudioConverter or None

Create a new GstAudio.AudioConverter that is able to convert between in and out audio formats.

config contains extra configuration options, see GST_AUDIO_CONVERTER_OPT_* parameters for details about the options and values.

convert(flags, in_)
Parameters:
Returns:

True is the conversion could be performed.

out:

a pointer where the output data will be written

Return type:

(bool, out: bytes)

Convenience wrapper around GstAudio.AudioConverter.samples(), which will perform allocation of the output buffer based on the result from GstAudio.AudioConverter.get_out_frames().

New in version 1.14.

free()

Free a previously allocated self instance.

get_config()
Returns:

a Gst.Structure that remains valid for as long as self is valid or until GstAudio.AudioConverter.update_config() is called.

in_rate:

result input rate

out_rate:

result output rate

Return type:

(Gst.Structure, in_rate: int, out_rate: int)

Get the current configuration of self.

get_in_frames(out_frames)
Parameters:

out_frames (int) – number of output frames

Returns:

the number of input frames

Return type:

int

Calculate how many input frames are currently needed by self to produce out_frames of output frames.

get_max_latency()
Returns:

the latency of self as expressed in the number of frames.

Return type:

int

Get the maximum number of input frames that the converter would need before producing output.

get_out_frames(in_frames)
Parameters:

in_frames (int) – number of input frames

Returns:

the number of output frames

Return type:

int

Calculate how many output frames can be produced when in_frames input frames are given to self.

is_passthrough()
Returns:

True when no conversion will actually occur.

Return type:

bool

Returns whether the audio converter will operate in passthrough mode. The return value would be typically input to GstBase.BaseTransform.set_passthrough()

New in version 1.16.

reset()

Reset self to the state it was when it was first created, clearing any history it might currently have.

samples(flags, in_, in_frames, out, out_frames)
Parameters:
Returns:

True is the conversion could be performed.

Return type:

bool

Perform the conversion with in_frames in in to out_frames in out using self.

In case the samples are interleaved, in and out must point to an array with a single element pointing to a block of interleaved samples.

If non-interleaved samples are used, in and out must point to an array with pointers to memory blocks, one for each channel.

in may be None, in which case in_frames of silence samples are processed by the converter.

This function always produces out_frames of output and consumes in_frames of input. Use GstAudio.AudioConverter.get_out_frames() and GstAudio.AudioConverter.get_in_frames() to make sure in_frames and out_frames are matching and in and out point to enough memory.

supports_inplace()
Returns:

True when the conversion can be done in place.

Return type:

bool

Returns whether the audio converter can perform the conversion in-place. The return value would be typically input to GstBase.BaseTransform.set_in_place()

New in version 1.12.

update_config(in_rate, out_rate, config)
Parameters:
Returns:

True when the new parameters could be set

Return type:

bool

Set in_rate, out_rate and config as extra configuration for self.

in_rate and out_rate specify the new sample rates of input and output formats. A value of 0 leaves the sample rate unchanged.

config can be None, in which case, the current configuration is not changed.

If the parameters in config can not be set exactly, this function returns False and will try to update as much state as possible. The new state can then be retrieved and refined with GstAudio.AudioConverter.get_config().

Look at the GST_AUDIO_CONVERTER_OPT_* fields to check valid configuration option and values.