Skip to content
Merged
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ let data = reader.read_track(&toc, 1)?;
This is a blocking call and takes a lot of time (depends on the track length and CD/drive quality due to retries). If you want to do something with the data as it comes, use streaming API:

```rust
use cd_da_reader::{CdReader, TrackStreamOptions};
use cd_da_reader::CdReader;

let reader = CdReader::open_default()?;
let toc = reader.read_toc()?;

let options = TrackStreamOptions::default();

let mut stream = reader.open_track_stream(&toc, 1, options)?;
let mut stream = reader.open_track_stream(&toc, 1)?;
while let Some(chunk) = stream.next_chunk()? {
// do something with the chunk directly
}
Expand Down
5 changes: 2 additions & 3 deletions examples/stream_last_track.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Reads the last audio track using the streaming API and saves it as a WAV file.
use cd_da_reader::{CdReader, TrackStreamOptions};
use cd_da_reader::CdReader;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let reader = CdReader::open_default()?;
Expand All @@ -13,8 +13,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.ok_or("no audio tracks found")?;

println!("Streaming track {}...", last_audio.number);
let mut stream =
reader.open_track_stream(&toc, last_audio.number, TrackStreamOptions::default())?;
let mut stream = reader.open_track_stream(&toc, last_audio.number)?;

let mut pcm = Vec::new();
while let Some(chunk) = stream.next_chunk()? {
Expand Down
5 changes: 2 additions & 3 deletions examples/stream_with_progress.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Streams the first audio track while printing a live progress line.
use cd_da_reader::{CdReader, TrackStreamOptions};
use cd_da_reader::CdReader;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let reader = CdReader::open_default()?;
Expand All @@ -11,8 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.find(|t| t.is_audio)
.ok_or("no audio tracks found")?;

let mut stream =
reader.open_track_stream(&toc, first_audio.number, TrackStreamOptions::default())?;
let mut stream = reader.open_track_stream(&toc, first_audio.number)?;

let total_secs = stream.total_seconds();
println!(
Expand Down
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@
//! use the streaming API instead:
//!
//! ```no_run
//! use cd_da_reader::{CdReader, TrackStreamOptions};
//! use cd_da_reader::CdReader;
//!
//! let reader = CdReader::open_default()?;
//! let toc = reader.read_toc()?;
//!
//! let options = TrackStreamOptions::default();
//!
//! let mut stream = reader.open_track_stream(&toc, 1, options)?;
//! let mut stream = reader.open_track_stream(&toc, 1)?;
//! while let Some(chunk) = stream.next_chunk()? {
//! // process chunk — raw PCM, 2 352 bytes per sector
//! }
Expand Down
15 changes: 11 additions & 4 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,20 @@ impl<'a> TrackStream<'a> {
}

impl CdReader {
/// Open a streaming reader for a specific track in the provided TOC.
/// It is important to create track streams through this method so the
/// drive session is managed through a single CDReader instance.
/// Open a streaming reader for an audio track using the default options.
pub fn open_track_stream<'a>(
&'a self,
toc: &Toc,
track_no: u8,
) -> Result<TrackStream<'a>, CdReaderError> {
self.open_track_stream_with_options(toc, track_no, TrackStreamOptions::default())
}

/// Open a streaming reader using explicit sector-format, retry, and chunk options.
///
/// Use [`TrackStream::next_chunk`] to pull sector-aligned chunks in the
/// format selected in [`TrackStreamOptions`].
pub fn open_track_stream<'a>(
pub fn open_track_stream_with_options<'a>(
&'a self,
toc: &Toc,
track_no: u8,
Expand Down
Loading