Discman
Loading...
Searching...
No Matches
CDDrive Class Reference

Abstracts the host's disc drive. More...

#include <cd_drive.h>

Inheritance diagram for CDDrive:
Collaboration diagram for CDDrive:

Classes

struct  DiscErrorException
 Thrown when the audio CD was recognized but could not be opened for reading. More...
 
struct  DriveErrorException
 Thrown when an audio CD was internally expected in the disc drive but could not be recognized. More...
 
struct  NoDiscPresentException
 Called when the presumption that a disc is present is false. More...
 
class  Poller
 The Poller uses a separate thread to poll the host for a disc drive with an audio CD. More...
 
class  Reader
 The Reader uses a separate thread to load data into the CDDrive's ring buffer. More...
 

Public Types

typedef sigc::signal< void()> sig_eject
 "Eject requested" signal type.
 

Public Member Functions

 CDDrive ()
 CDDrive constructor.
 
 ~CDDrive ()
 CDDrive destructor.
 
bool present () const
 Returns whether a disc is in the drive.
 
void eject ()
 Ejects the disc in the drive.
 
unsigned int tracks () const
 Returns the number of tracks on the disc.
 
void track (const int track)
 Sets the current track to the given 1-based index.
 
unsigned int track () const
 Returns the 1-based index of the current track.
 
lba_t lba (const track_t track) const
 Returns the LBA (large block address) of the start of the given track on the disc.
 
float elapsed ()
 The elapsed duration of the track in fractional seconds.
 
float progress ()
 The percentage completion of the rip of the current track (0.0 - 1.0).
 
unsigned int seconds () const
 The duration of the entire disc in whole seconds.
 
void resize_buffer (unsigned int sectors)
 Resizes the audio buffer.
 
int16_t next () override
 Provides the next audio sample from the current track. This is one half of an audio frame which contains a left and right sample.
 
void register_consumer (const Consumer< int16_t > *const)=delete
 Deleted. This Producer does not support multiple Consumers.
 
int16_t next_for_consumer (const Consumer< int16_t > *const)=delete
 Deleted. This Producer does not support multiple Consumers.
 
bool done ()
 Whether the current track has been played or ripped through.
 
sig_eject signal_eject ()
 Getter for ::_signal_eject.
 
- Public Member Functions inherited from Producer< int16_t >
int16_t next (const Consumer< int16_t > *const consumer)
 When a Producer has multiple Consumers, each Consumer must call this overloaded version of next().
 
void register_consumer (const Consumer< int16_t > *const consumer)
 Use this method to maintain state associated with a particular Consumer. The state can be used to retrieve the right datum for the Consumer.
 

Static Public Attributes

static constexpr int BUFFER_SIZE_PLAYING = 2048
 The audio buffer size when playing, in CD audio frames.
 
static constexpr int BUFFER_SIZE_RIPPING = 512
 The audio buffer size when ripping, in CD audio frames.
 
static constexpr int SAMPLE_RATE = 44100
 CD audio sample rate.
 

Private Member Functions

bool identify ()
 Finds a disc drive on the host with an audio disc inside.
 
void open ()
 Opens the disc for reading.
 
void update_track (const unsigned int track)
 Sets the current disc track using 1-based indexing.
 

Static Private Member Functions

static std::vector< std::string > devices ()
 Returns the paths of device nodes corresponding to disc drives with discs that can be opened.
 

Private Attributes

sig_eject _sig_eject
 Emitted when the disc is successfully ejected.
 
int _bufferSectors
 The number of CD frames in the audio buffer.
 
int _bufferSamples
 The number of audio samples (one half of an audio frame) in the audio buffer.
 
std::string _device
 The path to the device node of the disc drive.
 
cdrom_drive_t * _drive
 A cdio handle to the disc drive.
 
Reader_reader
 Used to read audio samples into the audio buffer.
 
Poller_poller
 Used to poll for the first openable disc drive.
 
int16_t * _buffers [2]
 A ring buffer of size 2. One buffer has new audio samples written to it. When that buffer is full, it is designated as the read buffer and the write buffer begins filling immediately. This facilitates streaming the audio samples from the disc at a constant rate.
 
uint8_t _buffer
 The 0-based index of the buffer in the ring currently designated as the write buffer.
 
unsigned int _buffer_idx
 The 0-based index into the write buffer.
 
unsigned int _track
 The current track being played or ripped.
 
unsigned int _cursor
 The 0-based index into the read buffer.
 
unsigned int _end
 The 0-based index just past the end of the read buffer.
 
std::mutex _load_lock
 Provides mutually exclusive access to the drive and audio buffers between the application thread and the Reader thread.
 
std::mutex _cursor_lock
 Provides mutually exclusive access to the track cursor between the the application thread and the PortAudio callback thread.
 

Static Private Attributes

static constexpr int BYTES_PER_SAMPLE = sizeof(int16_t)
 The number of bytes in one CD audio sample (an int16_t).
 

Additional Inherited Members

- Protected Member Functions inherited from Producer< int16_t >
Consumer< int16_t > * current_consumer () const
 Getter for _current_consumer.
 

Detailed Description

Abstracts the host's disc drive.

See also
Producer/Consumer.

Definition at line 39 of file cd_drive.h.

Member Typedef Documentation

◆ sig_eject

typedef sigc::signal<void()> CDDrive::sig_eject

"Eject requested" signal type.

Definition at line 48 of file cd_drive.h.

Constructor & Destructor Documentation

◆ CDDrive()

CDDrive::CDDrive ( )

CDDrive constructor.

Definition at line 130 of file cd_drive.cc.

◆ ~CDDrive()

CDDrive::~CDDrive ( )

CDDrive destructor.

Definition at line 146 of file cd_drive.cc.

Member Function Documentation

◆ devices()

std::vector< std::string > CDDrive::devices ( )
staticprivate

Returns the paths of device nodes corresponding to disc drives with discs that can be opened.

Returns
A list of device node paths.

Definition at line 179 of file cd_drive.cc.

◆ done()

bool CDDrive::done ( )

Whether the current track has been played or ripped through.

Definition at line 358 of file cd_drive.cc.

◆ eject()

void CDDrive::eject ( )

Ejects the disc in the drive.

Exceptions
NoDiscPresentException

Definition at line 161 of file cd_drive.cc.

◆ elapsed()

float CDDrive::elapsed ( )

The elapsed duration of the track in fractional seconds.

Definition at line 330 of file cd_drive.cc.

◆ identify()

bool CDDrive::identify ( )
private

Finds a disc drive on the host with an audio disc inside.

Definition at line 251 of file cd_drive.cc.

◆ lba()

lba_t CDDrive::lba ( const track_t track) const

Returns the LBA (large block address) of the start of the given track on the disc.

Definition at line 348 of file cd_drive.cc.

◆ next()

int16_t CDDrive::next ( )
overridevirtual

Provides the next audio sample from the current track. This is one half of an audio frame which contains a left and right sample.

Returns
The audio sample.

Implements Producer< int16_t >.

Definition at line 364 of file cd_drive.cc.

◆ next_for_consumer()

int16_t CDDrive::next_for_consumer ( const Consumer< int16_t > * const )
delete

Deleted. This Producer does not support multiple Consumers.

See also
Producer::next_for_consumer(const Consumer<int16_t>* const).

◆ open()

void CDDrive::open ( )
private

Opens the disc for reading.

Definition at line 282 of file cd_drive.cc.

◆ present()

bool CDDrive::present ( ) const

Returns whether a disc is in the drive.

Definition at line 157 of file cd_drive.cc.

◆ progress()

float CDDrive::progress ( )

The percentage completion of the rip of the current track (0.0 - 1.0).

Definition at line 340 of file cd_drive.cc.

◆ register_consumer()

void CDDrive::register_consumer ( const Consumer< int16_t > * const )
delete

Deleted. This Producer does not support multiple Consumers.

See also
Producer::register_consumer(const Consumer<int16_t>* const).

◆ resize_buffer()

void CDDrive::resize_buffer ( unsigned int sectors)

Resizes the audio buffer.

Parameters
[in]sectorsHow many CD audio frames (1 frame = 1/75 seconds) to size the buffer to.

Definition at line 50 of file cd_drive.cc.

◆ seconds()

unsigned int CDDrive::seconds ( ) const

The duration of the entire disc in whole seconds.

Definition at line 354 of file cd_drive.cc.

◆ signal_eject()

CDDrive::sig_eject CDDrive::signal_eject ( )

Getter for ::_signal_eject.

Definition at line 292 of file cd_drive.cc.

◆ track() [1/2]

unsigned int CDDrive::track ( ) const

Returns the 1-based index of the current track.

Definition at line 326 of file cd_drive.cc.

◆ track() [2/2]

void CDDrive::track ( const int track)

Sets the current track to the given 1-based index.

Definition at line 312 of file cd_drive.cc.

◆ tracks()

unsigned int CDDrive::tracks ( ) const

Returns the number of tracks on the disc.

Definition at line 306 of file cd_drive.cc.

◆ update_track()

void CDDrive::update_track ( const unsigned int track)
private

Sets the current disc track using 1-based indexing.

Definition at line 296 of file cd_drive.cc.

Member Data Documentation

◆ _buffer

uint8_t CDDrive::_buffer
private

The 0-based index of the buffer in the ring currently designated as the write buffer.

Definition at line 155 of file cd_drive.h.

◆ _buffer_idx

unsigned int CDDrive::_buffer_idx
private

The 0-based index into the write buffer.

Definition at line 156 of file cd_drive.h.

◆ _buffers

int16_t* CDDrive::_buffers[2]
private

A ring buffer of size 2. One buffer has new audio samples written to it. When that buffer is full, it is designated as the read buffer and the write buffer begins filling immediately. This facilitates streaming the audio samples from the disc at a constant rate.

Definition at line 153 of file cd_drive.h.

◆ _bufferSamples

int CDDrive::_bufferSamples
private

The number of audio samples (one half of an audio frame) in the audio buffer.

Definition at line 128 of file cd_drive.h.

◆ _bufferSectors

int CDDrive::_bufferSectors
private

The number of CD frames in the audio buffer.

Definition at line 127 of file cd_drive.h.

◆ _cursor

unsigned int CDDrive::_cursor
private

The 0-based index into the read buffer.

Definition at line 159 of file cd_drive.h.

◆ _cursor_lock

std::mutex CDDrive::_cursor_lock
private

Provides mutually exclusive access to the track cursor between the the application thread and the PortAudio callback thread.

Definition at line 168 of file cd_drive.h.

◆ _device

std::string CDDrive::_device
private

The path to the device node of the disc drive.

Definition at line 141 of file cd_drive.h.

◆ _drive

cdrom_drive_t* CDDrive::_drive
private

A cdio handle to the disc drive.

Definition at line 142 of file cd_drive.h.

◆ _end

unsigned int CDDrive::_end
private

The 0-based index just past the end of the read buffer.

Definition at line 160 of file cd_drive.h.

◆ _load_lock

std::mutex CDDrive::_load_lock
private

Provides mutually exclusive access to the drive and audio buffers between the application thread and the Reader thread.

Definition at line 164 of file cd_drive.h.

◆ _poller

Poller* CDDrive::_poller
private

Used to poll for the first openable disc drive.

Definition at line 144 of file cd_drive.h.

◆ _reader

Reader* CDDrive::_reader
private

Used to read audio samples into the audio buffer.

Definition at line 143 of file cd_drive.h.

◆ _sig_eject

sig_eject CDDrive::_sig_eject
private

Emitted when the disc is successfully ejected.

Definition at line 125 of file cd_drive.h.

◆ _track

unsigned int CDDrive::_track
private

The current track being played or ripped.

Definition at line 158 of file cd_drive.h.

◆ BUFFER_SIZE_PLAYING

int CDDrive::BUFFER_SIZE_PLAYING = 2048
staticconstexpr

The audio buffer size when playing, in CD audio frames.

Definition at line 42 of file cd_drive.h.

◆ BUFFER_SIZE_RIPPING

int CDDrive::BUFFER_SIZE_RIPPING = 512
staticconstexpr

The audio buffer size when ripping, in CD audio frames.

Definition at line 43 of file cd_drive.h.

◆ BYTES_PER_SAMPLE

int CDDrive::BYTES_PER_SAMPLE = sizeof(int16_t)
staticconstexprprivate

The number of bytes in one CD audio sample (an int16_t).

Definition at line 122 of file cd_drive.h.

◆ SAMPLE_RATE

int CDDrive::SAMPLE_RATE = 44100
staticconstexpr

CD audio sample rate.

Definition at line 45 of file cd_drive.h.


The documentation for this class was generated from the following files: