Skip to content

Commit

Permalink
Add another example.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMazare committed Aug 29, 2024
1 parent c679849 commit 489c65a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
26 changes: 26 additions & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use anyhow::Result;
use ogg_table::OggVorbisReader;

fn main() -> Result<()> {
let ogg_filename = "foo.ogg";
let start_time_sec = 314.15;
let duration_sec = 60.;
let (all_data, sample_rate) = {
let file = std::fs::File::open(ogg_filename)?;
let rdr = std::io::BufReader::new(file);
let mut ovr = OggVorbisReader::new(rdr)?;
let data = ovr.decode(0, 1000000000000)?;
(data, ovr.sample_rate())
};
let (selected_data, _sr) =
ogg_table::read_ogg_vorbis_sample(ogg_filename, start_time_sec, duration_sec)?;
let mut out_file = std::fs::File::create("foo1.wav")?;
ogg_table::wav::write_wav(&mut out_file, &selected_data[0], sample_rate)?;

let start_in_samples = (start_time_sec * sample_rate as f64) as usize;
let len_in_samples = (duration_sec * sample_rate as f64) as usize;
let data = &all_data[0][start_in_samples..start_in_samples + len_in_samples];
let mut out_file = std::fs::File::create("foo2.wav")?;
ogg_table::wav::write_wav(&mut out_file, &data, sample_rate)?;
Ok(())
}
6 changes: 0 additions & 6 deletions examples/benchmark/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use anyhow::Result;
use ogg_table::OggVorbisReader;

mod audio;

fn main() -> Result<()> {
for i in 0..5 {
let start_time = std::time::Instant::now();
Expand All @@ -11,10 +9,6 @@ fn main() -> Result<()> {
let mut ovr = OggVorbisReader::new(rdr)?;
let data = ovr.decode(0, 1000000000000)?;
println!("{i} {} {:?}", data[0].len(), start_time.elapsed());
if false {
let mut out_file = std::fs::File::create("foo.wav")?;
audio::write_wav(&mut out_file, &data[0], 24000)?;
}
}
Ok(())
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anyhow::Result;
pub mod ogg;
pub mod ogg_vorbis;
pub mod vorbis;
pub mod wav;

pub use ogg_vorbis::OggVorbisReader;

Expand Down
File renamed without changes.

0 comments on commit 489c65a

Please sign in to comment.