Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions cxx/AudioFrameObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ bool AudioFrameObserver::onPlaybackAudioFrameBeforeMixing(

bool AudioFrameObserver::onRecordAudioFrame(const char *channelId,
AudioFrame &audioFrame) {
auto *buffer = (char *) audioFrame.buffer;
for (int i = 0; i < audioFrame.bytesPerSample * audioFrame.channels
* audioFrame.samplesPerChannel;
i += audioFrame.bytesPerSample) {
// set the audio frame to noise, if you set the audio frame to silence, you can remove this if statement
if (i % 2 == 0) { buffer[i] = 0; }
static std::random_device rd;
static std::mt19937 gen(rd());

auto *buffer = static_cast<int16_t *>(audioFrame.buffer);
int totalSamples = audioFrame.channels * audioFrame.samplesPerChannel;

// Generate white noise: fill audio buffer with random values
// Noise amplitude can be adjusted via noiseAmplitude (0.0 - 1.0)
constexpr float noiseAmplitude = 0.3f;
std::uniform_int_distribution<int16_t> dist(
static_cast<int16_t>(-32768 * noiseAmplitude),
static_cast<int16_t>(32767 * noiseAmplitude));

for (int i = 0; i < totalSamples; ++i) {
buffer[i] = dist(gen);
}

return true;
}

Expand Down
5,983 changes: 3,842 additions & 2,141 deletions include/AgoraBase.h

Large diffs are not rendered by default.

Loading
Loading