Skip to content

Commit

Permalink
2 * sample_rate
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-- committed Jun 5, 2024
1 parent 7a070df commit a99494a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions examples/playogg_from_disk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,28 @@ async fn main() -> Result<(), Box<dyn Error>> {
tokio::spawn({
let room = room.clone();
async move {
const FRAME_DURATION: Duration = Duration::from_millis(1000); // Write 1s of audio at a time
let ms = FRAME_DURATION.as_millis() as u32;
let num_samples = (header.sample_rate / 1000 * ms) as usize;


log::info!("sample_rate: {}", header.sample_rate);
log::info!("num_channels: {}", header.channels);
log::info!("chunk size: {}ms - {} samples", ms, num_samples);

let mut last_granule: u64 = 0;

while let Ok((page_data, page_header)) = reader.parse_next_page() {
let sample_count = page_header.granule_position - last_granule;
let frame_size = page_data.len();
last_granule = page_header.granule_position;

let frame_size = page_data.len();
let mut audio_frame = AudioFrame_u8 {
data: vec![0u8; 0].into(),
num_channels: header.channels as u32,
sample_rate: header.sample_rate,
samples_per_channel: sample_count as u32,
samples_per_channel: (frame_size / header.channels as usize) as u32,
};

let mut bytes = 0;
for d in page_data.iter() {
bytes += 1;
audio_frame.data.push(*d);
}

log::info!("samples_per_channel: {}, bytes: {}, frame_size: {}",
audio_frame.samples_per_channel, bytes, frame_size);

source.capture_frame(&audio_frame).await.unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion webrtc-sys/src/audio_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void AudioTrackSource::InternalSource::on_captured_frame_u8(
size_t number_of_frames) {
webrtc::MutexLock lock(&mutex_);
for (auto sink : sinks_) {
sink->OnData(data.data(), 16, sample_rate, number_of_channels,
sink->OnData(data.data(), 8, 2 * sample_rate, number_of_channels,
number_of_frames);
}
}
Expand Down

0 comments on commit a99494a

Please sign in to comment.