mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-08 07:56:55 -04:00
refactor(sdk): Change waveform to be a list of values between 0 and 1
Most clients will probably work with values between 0 and 1 and need to convert it just to send it, so we can move that conversion into the SDK. This is also more forwards-compatible, because MSC3246 now has a different max value for the amplitude, so when this becomes stable, the only change needed will be in the SDK. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Damir Jelić
parent
eb1ee434b3
commit
bfc96181dd
@@ -424,7 +424,7 @@ impl Timeline {
|
||||
self: Arc<Self>,
|
||||
params: UploadParameters,
|
||||
audio_info: AudioInfo,
|
||||
waveform: Vec<u16>,
|
||||
waveform: Vec<f32>,
|
||||
) -> Result<Arc<SendAttachmentJoinHandle>, RoomError> {
|
||||
let mut info =
|
||||
BaseAudioInfo::try_from(&audio_info).map_err(|_| RoomError::InvalidAttachmentData)?;
|
||||
|
||||
@@ -67,7 +67,9 @@ pub struct BaseAudioInfo {
|
||||
/// The file size of the audio clip in bytes.
|
||||
pub size: Option<UInt>,
|
||||
/// The waveform of the audio clip.
|
||||
pub waveform: Option<Vec<u16>>,
|
||||
///
|
||||
/// Must only include values between 0 and 1.
|
||||
pub waveform: Option<Vec<f32>>,
|
||||
}
|
||||
|
||||
/// Base metadata about a file.
|
||||
|
||||
@@ -116,7 +116,7 @@ use ruma::{
|
||||
message::{
|
||||
AudioInfo, AudioMessageEventContent, FileInfo, FileMessageEventContent,
|
||||
ImageMessageEventContent, MessageType, RoomMessageEventContent,
|
||||
TextMessageEventContent, UnstableAudioDetailsContentBlock,
|
||||
TextMessageEventContent, UnstableAmplitude, UnstableAudioDetailsContentBlock,
|
||||
UnstableVoiceContentBlock, VideoInfo, VideoMessageEventContent,
|
||||
},
|
||||
name::RoomNameEventContent,
|
||||
@@ -326,7 +326,11 @@ macro_rules! make_media_type {
|
||||
|
||||
if let Some(AttachmentInfo::Audio(audio_info) | AttachmentInfo::Voice(audio_info)) = &$info &&
|
||||
let Some(duration) = audio_info.duration && let Some(waveform_vec) = &audio_info.waveform {
|
||||
let waveform = waveform_vec.iter().map(|v| (*v).into()).collect();
|
||||
let waveform = waveform_vec
|
||||
.iter()
|
||||
.map(|v| ((*v).clamp(0.0, 1.0) * UnstableAmplitude::MAX as f32) as u16)
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
content.audio =
|
||||
Some(UnstableAudioDetailsContentBlock::new(duration, waveform));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user