PCM Stream Channel Modifier

PCM Stream Channel Modifier library enables users to split pulse-code modulation (PCM) streams from stereo to mono or combine mono streams to form a stereo stream. For more information, see API documentation.

Configuration

To enable the library, set the CONFIG_PSCM Kconfig option to y in the project configuration file prj.conf.

API documentation

Header file: include/pcm_stream_channel_modifier.h
Source file: lib/pcm_stream_channel_modifier/pcm_stream_channel_modifier.c
group pscm

Enables splitting of pulse-code modulation (PCM) streams from stereo to mono or combine mono streams to form a stereo stream.

Functions

int pscm_zero_pad(void const *const input, size_t input_size, enum audio_channel channel, uint8_t pcm_bit_depth, void *output, size_t *output_size)

Adds a 0 after every sample from *input and writes it to *output.

Note

Use to create stereo stream from a mono source where one channel is silent.

Parameters:
  • input[in] Pointer to the input buffer.

  • input_size[in] Number of bytes in input.

  • channel[in] Channel to contain the audio data.

  • pcm_bit_depth[in] Bit depth of PCM samples (16, 24, or 32).

  • output[out] Pointer to the output buffer.

  • output_size[out] Number of bytes written to the output.

Returns:

0 if success.

int pscm_copy_pad(void const *const input, size_t input_size, uint8_t pcm_bit_depth, void *output, size_t *output_size)

Adds a copy of every sample from *input and writes it to both channels in *output.

Note

Use to create stereo stream from a mono source where both channels are identical.

Parameters:
  • input[in] Pointer to the input buffer.

  • input_size[in] Number of bytes in input.

  • pcm_bit_depth[in] Bit depth of PCM samples (16, 24, or 32).

  • output[out] Pointer to the output buffer.

  • output_size[out] Number of bytes written to output.

Returns:

0 if success.

int pscm_combine(void const *const input_left, void const *const input_right, size_t input_size, uint8_t pcm_bit_depth, void *output, size_t *output_size)

Combines two mono streams into one stereo stream.

Parameters:
  • input_left[in] Pointer to the input buffer for the left channel.

  • input_right[in] Pointer to the input buffer for the right channel.

  • input_size[in] Number of bytes in the input. Same for both channels.

  • pcm_bit_depth[in] Bit depth of PCM samples (16, 24, or 32).

  • output[out] Pointer to the output buffer.

  • output_size[out] Number of bytes written to the output.

Returns:

0 if success.

int pscm_one_channel_split(void const *const input, size_t input_size, enum audio_channel channel, uint8_t pcm_bit_depth, void *output, size_t *output_size)

Removes every second sample from *input and writes it to *output.

Note

Use to split stereo audio stream to single channel.

Parameters:
  • input[in] Pointer to the input buffer.

  • input_size[in] Number of bytes in the input. Must be divisible by two.

  • channel[in] Channel to keep the audio data from.

  • pcm_bit_depth[in] Bit depth of PCM samples (16, 24, or 32).

  • output[out] Pointer to the output buffer.

  • output_size[out] Number of bytes written to the output.

Returns:

0 if success.

int pscm_two_channel_split(void const *const input, size_t input_size, uint8_t pcm_bit_depth, void *output_left, void *output_right, size_t *output_size)

Splits a stereo stream to two separate mono streams.

Note

Use to split stereo audio stream to two separate channels.

Parameters:
  • input[in] Pointer to the input buffer.

  • input_size[in] Number of bytes in input. Must be divisible by two.

  • pcm_bit_depth[in] Bit depth of PCM samples (16, 24, or 32).

  • output_left[out] Pointer to the output buffer containing the left channel.

  • output_right[out] Pointer to the output buffer containing the right channel.

  • output_size[out] Number of bytes written to the output, same for both channels.

Returns:

0 if success.