pub struct CdReader {}Expand description
Helper struct to interact with the audio CD. While it doesn’t hold any internal data
directly, it implements Drop trait, so that the CD drive handle is properly closed.
Please note that you should not read multiple CDs at the same time, and preferably do not use it in multiple threads. CD drives are a physical thing and they really want to have exclusive access, because of that currently only sequential access is supported.
Implementations§
Source§impl CdReader
impl CdReader
Sourcepub fn open(path: &str) -> Result<Self>
pub fn open(path: &str) -> Result<Self>
Opens a CD drive at the specified path in order to read data.
It is crucial to call this function and not to create the Reader by yourself, as each OS needs its own way of handling the drive acess.
You don’t need to close the drive, it will be handled automatically
when the CdReader is dropped. On macOS, that will cause the CD drive
to be remounted, and the default application (like Apple Music) will
be called.
§Arguments
path- The device path (e.g., “/dev/sr0” on Linux, “disk6” on macOS, and r“\.\E:“ on Windows)
§Errors
Returns an error if the drive cannot be opened
Sourcepub fn create_wav(data: Vec<u8>) -> Vec<u8> ⓘ
pub fn create_wav(data: Vec<u8>) -> Vec<u8> ⓘ
While this is a low-level library and does not include any codecs to compress the audio, it includes a helper function to convert raw PCM data into a wav file, which is done by prepending a 44 RIFF bytes header
§Arguments
data- vector of bytes received fromread_trackfunction
Sourcepub fn read_toc(&self) -> Result<Toc, Error>
pub fn read_toc(&self) -> Result<Toc, Error>
Read Table of Contents for the opened drive. You’ll likely only need to access
tracks from the returned value in order to iterate and read each track’s raw data.
Please note that each track in the vector has number property, which you should use
when calling read_track, as it doesn’t start with 0. It is important to do so,
because in the future it might include 0 for the hidden track.
Sourcepub fn read_track(&self, toc: &Toc, track_no: u8) -> Result<Vec<u8>>
pub fn read_track(&self, toc: &Toc, track_no: u8) -> Result<Vec<u8>>
Read raw data for the specified track number from the TOC.
It returns raw PCM data, but if you want to save it directly and make it playable,
wrap the result with create_wav function, that will prepend a RIFF header and
make it a proper music file.