Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Made iteration_interval changeable. #1040

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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