Skip to content

Commit

Permalink
feat: Made iteration_interval changeable. (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 authored Dec 9, 2023
1 parent 58424c3 commit 4eabe3b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
23 changes: 23 additions & 0 deletions include/dpp/discordvoiceclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,13 @@ class DPP_EXPORT discord_voice_client : public websocket_client
*/
dpp::utility::uptime get_uptime();

/**
* @brief The time (in milliseconds) between each interval when parsing audio.
*
* @warning You should only change this if you know what you're doing. It is set to 500ms by default.
*/
uint16_t iteration_interval{500};

/** Constructor takes shard id, max shards and token.
* @param _cluster The cluster which owns this voice connection, for related logging, REST requests etc
* @param _channel_id The channel id to identify the voice connection as
Expand Down Expand Up @@ -852,6 +859,22 @@ class DPP_EXPORT discord_voice_client : public websocket_client
*/
discord_voice_client& stop_audio();

/**
* @brief Change the iteration interval time.
*
* @param time The time (in milliseconds) between each interval when parsing audio.
*
* @return Reference to self.
*/
discord_voice_client& set_iteration_interval(uint16_t interval);

/**
* @brief Get the iteration interval time (in milliseconds).
*
* @return iteration_interval
*/
uint16_t get_iteration_interval();

/**
* @brief Returns true if we are playing audio
*
Expand Down
10 changes: 8 additions & 2 deletions src/dpp/discordvoiceclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ void discord_voice_client::voice_courier_loop(discord_voice_client& client, cour
#ifdef HAVE_VOICE
utility::set_thread_name(std::string("vcourier/") + std::to_string(client.server_id));
while (true) {
constexpr std::chrono::milliseconds iteration_interval(500);
std::this_thread::sleep_for(iteration_interval);
std::this_thread::sleep_for(std::chrono::milliseconds{client.iteration_interval});

struct flush_data_t {
snowflake user_id;
Expand Down Expand Up @@ -1353,6 +1352,13 @@ std::string discord_voice_client::discover_ip() {
return "";
}

discord_voice_client& discord_voice_client::set_iteration_interval(uint16_t interval) {
this->iteration_interval = interval;
return *this;
}

uint16_t discord_voice_client::get_iteration_interval() {
return this->iteration_interval;
}

} // namespace dpp

0 comments on commit 4eabe3b

Please sign in to comment.