Crate cd_da_reader

Crate cd_da_reader 

Source
Expand description

§CD-DA (or audio CD) reading library

This library provides cross-platform audio CD reading capability, it works on Windows, macOS and Linux. It is intended to be a low-level library, and only allows you read TOC and tracks, and you need to provide valid CD drive name. Currently, the functionality is very basic, and there is no way to specify subchannel info, access hidden track or read CD text.

The library works by issuing direct SCSI commands.

§Example

use cd_da_reader::CdReader;

fn read_cd() -> Result<(), Box<dyn std::error::Error>> {
  let reader = CdReader::open(r"\\.\E:")?;
  let toc = reader.read_toc()?;
  println!("{:#?}", toc);
  let data = reader.read_track(&toc, 11)?;
  let wav_track = CdReader::create_wav(data);
  std::fs::write("myfile.wav", wav_track)?;
  Ok(())
}

This function reads an audio CD on Windows, you can check your drive letter in the File Explorer. On macOS, you can run diskutil list and look for the Audio CD in the list (it should be something like “disk4”), and on Linux you can check it using cat /proc/sys/dev/cdrom/info, it will be like “/dev/sr0”.

§Metadata

This library does not provide any direct metadata, and audio CDs typically do not carry it by themselves. To obtain it, you’d need to get it from a place like MusicBrainz. You should have all necessary information in the TOC struct to calculate the audio CD ID.

Structs§

CdReader
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.
Toc
Table of Contents, read directly from the Audio CD. The most important part is the tracks vector, which allows you to read raw track data.
Track
Representation of the track from TOC, purely in terms of data location on the CD.