Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,5 @@
# demands to the code style (yet).

hard_tabs = true
normalize_comments = false
max_width = 120
ideal_width = 100
space_before_type_annotation = true
space_before_bound = false
space_after_type_annotation_colon = false
space_after_bound_colon = true
spaces_around_ranges = true
match_block_trailing_comma = true
match_wildcard_trailing_comma = true
wrap_match_arms = false
fn_brace_style = "PreferSameLine"
item_brace_style = "PreferSameLine"
fn_args_layout = "Block"
where_pred_indent = "Block"
generics_indent = "Block"
struct_lit_style = "Block"
fn_call_style = "Block"
chain_indent = "Block"
take_source_hints = true
trailing_comma = "Vertical"
fn_args_density = "Compressed"
where_density = "Compressed"
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ keywords = ["ogg", "vorbis", "decoder", "audio"]
categories = ["compression", "multimedia::audio", "multimedia::encoding"]
documentation = "https://docs.rs/lewton"
readme = "README.md"
edition = "2015"
rust-version = "1.56.0"
edition = "2024"
rust-version = "1.95.0"

[features]
default = ["ogg"]
async_ogg = ["ogg", "ogg/async", "futures", "tokio-io"]
ogg = ["dep:ogg"]
async_ogg = ["ogg", "ogg/async", "dep:futures", "dep:tokio-io"]
capi = []

[[example]]
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-check-cfg=cfg(cargo_c)");
}
15 changes: 10 additions & 5 deletions examples/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
// under the CC-0 license:
// https://creativecommons.org/publicdomain/zero/1.0/

extern crate lewton;
extern crate byteorder;
extern crate lewton;

fn main() {
match run() {
Ok(_) =>(),
Ok(_) => (),
Err(err) => println!("Error: {}", err),
}
}

use std::env;
use lewton::VorbisError;
use lewton::inside_ogg::OggStreamReader;
use std::env;
use std::fs::File;
use std::time::Instant;

pub fn run() -> Result<(), VorbisError> {
let file_path = env::args().nth(1).expect("No arg found. Please specify a file to open.");
let file_path = env::args()
.nth(1)
.expect("No arg found. Please specify a file to open.");
println!("Opening file: {}", file_path);
let f = File::open(file_path).expect("Can't open file");

Expand All @@ -41,7 +43,10 @@ pub fn run() -> Result<(), VorbisError> {
}
let decode_duration = Instant::now() - start_decode_time;
println!("The piece is {} s long ({} packets).", len_play, n);
println!("Decoded in {} s.", decode_duration.as_secs() as f64 + (decode_duration.subsec_nanos() as f64) / 1_000_000_000.0);
println!(
"Decoded in {} s.",
decode_duration.as_secs() as f64 + (decode_duration.subsec_nanos() as f64) / 1_000_000_000.0
);

Ok(())
}
30 changes: 16 additions & 14 deletions examples/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@
// https://creativecommons.org/publicdomain/zero/1.0/

extern crate alto;
extern crate lewton;
extern crate byteorder;
extern crate lewton;

use std::env;
use alto::{Alto, Mono, Source, Stereo};
use lewton::VorbisError;
use lewton::inside_ogg::OggStreamReader;
use std::env;
use std::fs::File;
use std::thread::sleep;
use std::time::{Instant, Duration};
use alto::{Alto, Mono, Stereo, Source};
use std::time::{Duration, Instant};

fn main() {
match run() {
Ok(_) =>(),
Ok(_) => (),
Err(err) => println!("Error: {}", err),
}
}

fn run() -> Result<(), VorbisError> {
let file_path = env::args().nth(1).expect("No arg found. Please specify a file to open.");
let file_path = env::args()
.nth(1)
.expect("No arg found. Please specify a file to open.");
println!("Opening file: {}", file_path);
let f = File::open(file_path).expect("Can't open file");

Expand All @@ -35,8 +37,7 @@ fn run() -> Result<(), VorbisError> {
let al = Alto::load_default().expect("Could not load alto");
let device = al.open(None).expect("Could not open device");
let cxt = device.new_context(None).expect("Could not create context");
let mut str_src = cxt.new_streaming_source()
.expect("could not create streaming src");
let mut str_src = cxt.new_streaming_source().expect("could not create streaming src");
let sample_rate = srr.ident_hdr.audio_sample_rate as i32;

if srr.ident_hdr.audio_channels > 2 {
Expand All @@ -51,16 +52,16 @@ fn run() -> Result<(), VorbisError> {
let mut len_play = 0.0;
let mut start_play_time = None;
let start_decode_time = Instant::now();
let sample_channels = srr.ident_hdr.audio_channels as f32 *
srr.ident_hdr.audio_sample_rate as f32;
let sample_channels = srr.ident_hdr.audio_channels as f32 * srr.ident_hdr.audio_sample_rate as f32;
while let Some(pck_samples) = srr.read_dec_packet_itl()? {
println!("Decoded packet no {}, with {} samples.", n, pck_samples.len());
n += 1;
let buf = match srr.ident_hdr.audio_channels {
1 => cxt.new_buffer::<Mono<i16>,_>(&pck_samples, sample_rate),
2 => cxt.new_buffer::<Stereo<i16>,_>(&pck_samples, sample_rate),
1 => cxt.new_buffer::<Mono<i16>, _>(&pck_samples, sample_rate),
2 => cxt.new_buffer::<Stereo<i16>, _>(&pck_samples, sample_rate),
n => panic!("unsupported number of channels: {}", n),
}.unwrap();
}
.unwrap();

str_src.queue_buffer(buf).unwrap();

Expand All @@ -75,7 +76,8 @@ fn run() -> Result<(), VorbisError> {
}
}
let total_duration = Duration::from_millis((len_play * 1000.0) as u64);
let sleep_duration = total_duration - match start_play_time {
let sleep_duration = total_duration
- match start_play_time {
None => {
str_src.play();
Duration::from_millis(0)
Expand Down
Loading