Raw Audio Data
Introduction
During real-time communications, you can pre- and post-process the audio data and modify it for desired playback effects
The Video SDK for C++ uses the IAudioFrameObserver
class to provide raw data functions. You can pre-process the data before sending it to the encoder and modify the captured audio frames. You can also post-process the data after sending it to the decoder and modify the received audio frames.
This article describes how to use raw audio data with the IAudioFrameObserver
class.
Sample project
Refer to the sample project on GitHub to learn how to use raw audio data in your project.
Implementation
Before using the raw data functions, ensure that you have implemented the basic real-time communication functions in your project. For details, see Start a Call or Start Live Interactive Streaming.
Follow these steps to implement the raw data functions in your project:
- Before joining the channel, call
registerAudioFrameObserver
to register an audio frame observer. - After successful registration, the SDK sends the raw audio data via
onRecordAudioFrame
,onPlaybackAudioFrame
,onPlaybackAudioFrameBeforeMixing
, oronMixedAudioFrame
. - After acquiring the raw data, you can process the data based on your scenario and send the processed data to the SDK via the callbacks mentioned in step 2.
API call sequence
The following diagram shows how to implement the raw data functions in your project:
Data transfer
The following diagram shows the data transfer with the IAudioFrameObserver
class:
With onRecordAudioFrame
, onPlaybackAudioFrame
, onPlaybackAudioFrameBeforeMixing
, or onMixedAudioFrame
, you can:
- Get raw audio frames from
AudioFrame
. - Process the raw frames from
AudioFrame
and return to the SDK or the custom renderer.
Sample code
- Call
registerAudioFrameObserver
to register an audio frame observer.
-
Once you obtain the raw audio data, you can pre-process or post-process it.
Get the recorded raw audio data, amplify the volume, and send the audio data to the SDK
Get the playback raw audio data
Get the mixed recorded and playback audio frame
Get the audio frame of a specified user before mixing
API reference
To update the sampling rate of the audio data in the callbacks, you can call the following methods: