|
Discman
|
Abstracts the host's disc drive. More...
#include <cd_drive.h>


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. | |
Abstracts the host's disc drive.
Definition at line 39 of file cd_drive.h.
| typedef sigc::signal<void()> CDDrive::sig_eject |
"Eject requested" signal type.
Definition at line 48 of file cd_drive.h.
| CDDrive::CDDrive | ( | ) |
CDDrive constructor.
Definition at line 130 of file cd_drive.cc.
| CDDrive::~CDDrive | ( | ) |
CDDrive destructor.
Definition at line 146 of file cd_drive.cc.
|
staticprivate |
Returns the paths of device nodes corresponding to disc drives with discs that can be opened.
Definition at line 179 of file cd_drive.cc.
| bool CDDrive::done | ( | ) |
Whether the current track has been played or ripped through.
Definition at line 358 of file cd_drive.cc.
| void CDDrive::eject | ( | ) |
Ejects the disc in the drive.
| NoDiscPresentException |
Definition at line 161 of file cd_drive.cc.
| float CDDrive::elapsed | ( | ) |
The elapsed duration of the track in fractional seconds.
Definition at line 330 of file cd_drive.cc.
|
private |
Finds a disc drive on the host with an audio disc inside.
Definition at line 251 of file cd_drive.cc.
| 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.
|
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.
Implements Producer< int16_t >.
Definition at line 364 of file cd_drive.cc.
|
delete |
|
private |
Opens the disc for reading.
Definition at line 282 of file cd_drive.cc.
| bool CDDrive::present | ( | ) | const |
Returns whether a disc is in the drive.
Definition at line 157 of file cd_drive.cc.
| 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.
|
delete |
| void CDDrive::resize_buffer | ( | unsigned int | sectors | ) |
Resizes the audio buffer.
| [in] | sectors | How many CD audio frames (1 frame = 1/75 seconds) to size the buffer to. |
Definition at line 50 of file cd_drive.cc.
| unsigned int CDDrive::seconds | ( | ) | const |
The duration of the entire disc in whole seconds.
Definition at line 354 of file cd_drive.cc.
| CDDrive::sig_eject CDDrive::signal_eject | ( | ) |
Getter for ::_signal_eject.
Definition at line 292 of file cd_drive.cc.
| unsigned int CDDrive::track | ( | ) | const |
Returns the 1-based index of the current track.
Definition at line 326 of file cd_drive.cc.
| 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.
| unsigned int CDDrive::tracks | ( | ) | const |
Returns the number of tracks on the disc.
Definition at line 306 of file cd_drive.cc.
|
private |
Sets the current disc track using 1-based indexing.
Definition at line 296 of file cd_drive.cc.
|
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.
|
private |
The 0-based index into the write buffer.
Definition at line 156 of file cd_drive.h.
|
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.
|
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.
|
private |
The number of CD frames in the audio buffer.
Definition at line 127 of file cd_drive.h.
|
private |
The 0-based index into the read buffer.
Definition at line 159 of file cd_drive.h.
|
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.
|
private |
The path to the device node of the disc drive.
Definition at line 141 of file cd_drive.h.
|
private |
A cdio handle to the disc drive.
Definition at line 142 of file cd_drive.h.
|
private |
The 0-based index just past the end of the read buffer.
Definition at line 160 of file cd_drive.h.
|
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.
|
private |
Used to poll for the first openable disc drive.
Definition at line 144 of file cd_drive.h.
|
private |
Used to read audio samples into the audio buffer.
Definition at line 143 of file cd_drive.h.
|
private |
Emitted when the disc is successfully ejected.
Definition at line 125 of file cd_drive.h.
|
private |
The current track being played or ripped.
Definition at line 158 of file cd_drive.h.
|
staticconstexpr |
The audio buffer size when playing, in CD audio frames.
Definition at line 42 of file cd_drive.h.
|
staticconstexpr |
The audio buffer size when ripping, in CD audio frames.
Definition at line 43 of file cd_drive.h.
|
staticconstexprprivate |
The number of bytes in one CD audio sample (an int16_t).
Definition at line 122 of file cd_drive.h.
|
staticconstexpr |
CD audio sample rate.
Definition at line 45 of file cd_drive.h.