Skip to content

Commit

Permalink
Revert "add jitter buffer for voice"
Browse files Browse the repository at this point in the history
This reverts commit 3306edc.
  • Loading branch information
ouwou committed Apr 4, 2024
1 parent fda687e commit 72b6c3a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 110 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,10 @@ For example, memory_db would be set by adding `memory_db = true` under the line
#### voice
| Setting | Type | Default | Description |
|--------------------------|--------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| `vad` | string | rnnoise if enabled, gate otherwise | Method used for voice activity detection. Changeable in UI |
| `backends` | string | empty | Change backend priority when initializing miniaudio: `wasapi;dsound;winmm;coreaudio;sndio;audio4;oss;pulseaudio;alsa;jack` |
| `jitter_latency_desired` | int | 50 | Desired/Minimum latency for jitter buffer (in milliseconds) |
| `jitter_latency_maximum` | int | 200 | Maximum latency for jitter buffer before frames are discarded (in milliseconds) |
| Setting | Type | Default | Description |
|------------|--------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| `vad` | string | rnnoise if enabled, gate otherwise | Method used for voice activity detection. Changeable in UI |
| `backends` | string | empty | Change backend priority when initializing miniaudio: `wasapi;dsound;winmm;coreaudio;sndio;audio4;oss;pulseaudio;alsa;jack` |
#### windows
Expand Down
82 changes: 0 additions & 82 deletions src/audio/jitterbuffer.hpp

This file was deleted.

22 changes: 6 additions & 16 deletions src/audio/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const uint8_t *StripRTPExtensionHeader(const uint8_t *buf, int num_bytes, size_t
return buf;
}

// frameCount is configured to be 480 samples per channel
void data_callback(ma_device *pDevice, void *pOutput, const void *pInput, ma_uint32 frameCount) {
AudioManager *mgr = reinterpret_cast<AudioManager *>(pDevice->pUserData);
if (mgr == nullptr) return;
Expand All @@ -38,14 +37,12 @@ void data_callback(ma_device *pDevice, void *pOutput, const void *pInput, ma_uin
if (const auto vol_it = mgr->m_volume_ssrc.find(ssrc); vol_it != mgr->m_volume_ssrc.end()) {
volume = vol_it->second;
}

static std::array<int16_t, 480 * 2> buf;

if (!pair.first.PopSamples(buf.data(), 480 * 2)) continue;

for (size_t i = 0; i < 480 * 2; i++) {
auto &buf = pair.first;
const size_t n = std::min(static_cast<size_t>(buf.size()), static_cast<size_t>(frameCount * 2ULL));
for (size_t i = 0; i < n; i++) {
pOutputF32[i] += volume * buf[i] / 32768.F;
}
buf.erase(buf.begin(), buf.begin() + n);
}
}

Expand Down Expand Up @@ -205,14 +202,7 @@ void AudioManager::AddSSRC(uint32_t ssrc) {
int error;
if (m_sources.find(ssrc) == m_sources.end()) {
auto *decoder = opus_decoder_create(48000, 2, &error);
auto &s = Abaddon::Get().GetSettings();
m_sources.insert(std::make_pair(ssrc, std::make_pair(
JitterBuffer<int16_t>(
s.JitterDesiredLatency,
s.JitterMaximumLatency,
2,
48000),
decoder)));
m_sources.insert(std::make_pair(ssrc, std::make_pair(std::deque<int16_t> {}, decoder)));
}
}

Expand Down Expand Up @@ -252,7 +242,7 @@ void AudioManager::FeedMeOpus(uint32_t ssrc, const std::vector<uint8_t> &data) {
} else {
UpdateReceiveVolume(ssrc, pcm.data(), decoded);
auto &buf = it->second.first;
buf.PushSamples(pcm.data(), decoded * 2);
buf.insert(buf.end(), pcm.begin(), pcm.begin() + decoded * 2);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/audio/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#endif

#include "devices.hpp"
#include "jitterbuffer.hpp"
// clang-format on

class AudioManager {
Expand Down Expand Up @@ -137,7 +136,7 @@ class AudioManager {
mutable std::mutex m_rnn_mutex;
#endif

std::unordered_map<uint32_t, std::pair<JitterBuffer<int16_t>, OpusDecoder *>> m_sources;
std::unordered_map<uint32_t, std::pair<std::deque<int16_t>, OpusDecoder *>> m_sources;

OpusEncoder *m_encoder;

Expand Down
2 changes: 0 additions & 2 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ void SettingsManager::DefineSettings() {
AddSetting("voice", "vad", "gate"s, &Settings::VAD);
#endif
AddSetting("voice", "backends", ""s, &Settings::Backends);
AddSetting("voice", "jitter_latency_desired", 50, &Settings::JitterDesiredLatency);
AddSetting("voice", "jitter_latency_maximum", 200, &Settings::JitterMaximumLatency);
}

void SettingsManager::ReadSettings() {
Expand Down
2 changes: 0 additions & 2 deletions src/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class SettingsManager {
// [voice]
std::string VAD;
std::string Backends;
int JitterDesiredLatency;
int JitterMaximumLatency;

// [windows]
bool HideConsole;
Expand Down

0 comments on commit 72b6c3a

Please sign in to comment.