feat: implement rendering

This commit is contained in:
2026-05-28 01:48:52 -04:00
parent 862a333131
commit 24ef5a67c4
11 changed files with 225 additions and 71 deletions

View File

@@ -1,7 +1,7 @@
use futures::TryStreamExt as _;
use snafu::{OptionExt as _, Report, ResultExt as _, Snafu};
use std::{collections::BTreeMap, sync::LazyLock};
use time::{UtcDateTime, format_description::well_known::Rfc3339};
use time::{Date, Time, UtcDateTime, format_description::well_known::Rfc3339};
use twilight_model::{
application::{
command::{Command, CommandOption, CommandOptionType, CommandType},
@@ -18,7 +18,11 @@ use twilight_util::builder::{
InteractionResponseDataBuilder, command::CommandBuilder, embed::EmbedBuilder,
};
use crate::command::State;
use crate::{
command::State,
recording_data::{Clip, Recording, RecordingData},
render_data::{Render, RenderData},
};
const NAME: &str = "render";
const DESCRIPTION: &str =
@@ -292,7 +296,7 @@ pub async fn handle(state: State, interaction: Interaction) {
let total_samples = (duration.whole_seconds() as u32 * sample_rate)
+ (duration.subsec_microseconds() as u32 * sample_rate / 1_000_000);
let samples = vec![0; total_samples as usize];
let mut composite = vec![0; total_samples as usize];
let mut recordings =
state
@@ -306,7 +310,66 @@ pub async fn handle(state: State, interaction: Interaction) {
.read(&recording)
.await
.expect("TODO");
tracing::debug!(?recording, ?recording_data);
let RecordingData {
channels,
sample_rate,
samples,
} = recording_data;
let Recording {
year,
month,
day,
hour,
minute,
clip,
} = recording;
let Clip {
second,
microsecond,
guild,
voice_channel,
user,
} = clip;
let date = Date::from_calendar_date(year, month, day).unwrap();
let time = Time::from_hms_micro(hour, minute, second, microsecond).unwrap();
let datetime = UtcDateTime::new(date, time);
let after_start = datetime - start;
let origin = (after_start.whole_seconds() as u32 * sample_rate)
+ (after_start.subsec_microseconds() as u32 * sample_rate / 1_000_000);
let origin = origin as usize;
for (i, sample) in samples.into_iter().enumerate() {
if let Some(composite_sample) = composite.get_mut(origin + i) {
*composite_sample += sample;
} else {
tracing::error!(origin, i, total_samples, "out of range");
}
}
}
let render = Render {
start,
end,
guild_id,
voice_channel_id,
};
let render_data = RenderData {
channels: state.audio_channels.into(),
sample_rate,
samples: composite,
};
state
.render_manager
.write(&render, render_data)
.await
.expect("TODO");
tracing::info!(%render, "written");
todo!();
}