Skip to content

Commit

Permalink
rename samples_per_frame and round its calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanelaf committed Aug 2, 2024
1 parent c54a434 commit 5bd53a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/probe/deep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub struct AudioDetails {
pub stream_index: i32,
pub stream_duration: Option<f32>,
pub sample_rate: i32,
pub nb_samples: i32,
pub samples_per_frame: i32,
}

#[derive(Default)]
Expand Down Expand Up @@ -467,13 +467,15 @@ impl DeepProbe {
deep_orders.audio_indexes.push(stream_index);
input_id = format!("audio_input_{}", stream_index);
if let Ok(stream) = Stream::new(context.get_stream(stream_index as isize)) {
let avg_pkt_duration = deep_orders.streams[stream_index as usize].total_packets_duration
/ deep_orders.streams[stream_index as usize].count_packets as i64;
let avg_pkt_duration = (deep_orders.streams[stream_index as usize].total_packets_duration
as f64
/ deep_orders.streams[stream_index as usize].count_packets as f64)
.ceil();
let audio_stream_details: AudioDetails = AudioDetails {
stream_index: stream_index as i32,
stream_duration: stream.get_duration(),
sample_rate: stream.get_sample_rate(),
nb_samples: avg_pkt_duration as i32,
samples_per_frame: avg_pkt_duration as i32,
};
deep_orders.audio_details.push(audio_stream_details);
}
Expand Down
4 changes: 3 additions & 1 deletion src/probe/dualmono_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ pub fn detect_dualmono<S: ::std::hash::BuildHasher>(
Some(duration) => ((duration - frame_duration) * 1000.0).round() as i64,
None => (((results.len() as f64 / audio_stream_qualif_number as f64) - 1.0)
/ (audio_stream_details.map(|d| d.sample_rate).unwrap_or(1) as f64
/ audio_stream_details.map(|d| d.nb_samples).unwrap_or(1) as f64)
/ audio_stream_details
.map(|d| d.samples_per_frame)
.unwrap_or(1) as f64)
* 1000.0)
.round() as i64,
};
Expand Down
8 changes: 6 additions & 2 deletions src/probe/silence_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ pub fn detect_silence<S: ::std::hash::BuildHasher>(
Some(duration) => ((duration - frame_duration) * 1000.0).round() as i64,
None => (((results.len() as f64 / audio_indexes.len() as f64) - 1.0)
/ (audio_stream_details.map(|d| d.sample_rate).unwrap_or(1) as f64
/ audio_stream_details.map(|d| d.nb_samples).unwrap_or(1) as f64)
/ audio_stream_details
.map(|d| d.samples_per_frame)
.unwrap_or(1) as f64)
* 1000.0)
.round() as i64,
};
Expand Down Expand Up @@ -164,7 +166,9 @@ pub fn detect_silence<S: ::std::hash::BuildHasher>(
Some(duration) => ((duration - frame_duration) * 1000.0).round() as i64,
None => (((results.len() as f64 / audio_indexes.len() as f64) - 1.0)
/ (audio_stream_details.map(|d| d.sample_rate).unwrap_or(1) as f64
/ audio_stream_details.map(|d| d.nb_samples).unwrap_or(1) as f64)
/ audio_stream_details
.map(|d| d.samples_per_frame)
.unwrap_or(1) as f64)
* 1000.0)
.round() as i64,
};
Expand Down
6 changes: 4 additions & 2 deletions src/probe/sine_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ pub fn detect_sine(
.iter()
.find(|d| d.stream_index == index as i32);
let sample_rate = audio_stream_details.map(|d| d.sample_rate).unwrap_or(1) as f64;
let nb_samples = audio_stream_details.map(|d| d.nb_samples).unwrap_or(1) as f64;
let time_base = sample_rate / nb_samples;
let samples_per_frame = audio_stream_details
.map(|d| d.samples_per_frame)
.unwrap_or(1) as f64;
let time_base = sample_rate / samples_per_frame; // time base => audio frames per second

let end_from_duration = match audio_stream_details.and_then(|d| d.stream_duration) {
Some(duration) => ((duration - frame_duration) * 1000.0).round() as i64,
Expand Down

0 comments on commit 5bd53a9

Please sign in to comment.