pub trait AudioSectorReader {
type Error: Error + Send + Sync + 'static;
// Required method
fn read_audio_sectors(
&self,
start_lba: u32,
count: u32,
) -> Result<Vec<u8>, Self::Error>;
}Expand description
A source of raw CD-DA audio sectors.
This trait separates source-specific I/O from the crate’s track-level logic.
Meaning that you can provide your implementation for any source which can provide
audio CD sectors, like a disc image, decoded container, in-memory disc, or a remote
source. read_track and open_track_stream use a caller-provided Toc to calculate
sector ranges, then retrieve those sectors through read_audio_sectors.
Implementations are responsible only for reading sectors. They do not build
the Toc, select tracks, calculate track boundaries, or account for
CD-Extra session gaps. The backing’s sector address space must agree with the
start_lba and leadout_lba values in the supplied Toc; layout differences
are expressed separately through TrackBounds.
§Audio format
Each sector must contain exactly 2,352 bytes of headerless PCM audio:
- 44,100 sample frames per second
- signed 16-bit little-endian samples
- two interleaved channels, left followed by right
- 588 stereo sample frames per sector
One sector therefore represents 1/75 second of audio. Returned data must not
include a WAV header, CD sector headers, subchannel data, or padding. It is
byte-for-byte compatible with CdReader::read_track and can be passed
directly to create_wav.
§Addressing and read semantics
start_lba is an absolute sector index within the backing, not an offset
relative to a track. A request covers the half-open range
start_lba..start_lba + count.
Calls are independent and may be repeated or issued out of order, such as
after seeking a stream. On success, the returned vector must contain exactly
count * 2352 bytes. A zero-sector request should return an empty vector.
Invalid ranges, short reads, and decoding or I/O failures must return an
error rather than partial data.
The method takes &self so callers can retain a shared reference to the
source. Implementations backed by a mutable file cursor or decoder should
use positioned reads or interior mutability.
Required Associated Types§
Required Methods§
Sourcefn read_audio_sectors(
&self,
start_lba: u32,
count: u32,
) -> Result<Vec<u8>, Self::Error>
fn read_audio_sectors( &self, start_lba: u32, count: u32, ) -> Result<Vec<u8>, Self::Error>
Read the sector range start_lba..start_lba + count.
A successful call returns exactly count * 2352 bytes in the format
described by AudioSectorReader.
§Errors
Returns an error if the complete requested range cannot be returned.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl AudioSectorReader for CdReader
The physical drive is itself an AudioSectorReader, so drive-backed and
file-backed code can share the generic read_track path. This uses the
default read options (audio sectors, default retry policy); for explicit
control, prefer the inherent CdReader::read_track_with_options.
impl AudioSectorReader for CdReader
The physical drive is itself an AudioSectorReader, so drive-backed and
file-backed code can share the generic read_track path. This uses the
default read options (audio sectors, default retry policy); for explicit
control, prefer the inherent CdReader::read_track_with_options.