21#include <cdio/paranoia/paranoia.h>
22#include <cdio/cd_types.h>
28#include <linux/cdrom.h>
29#include <sigc++/signal.h>
53 const char*
what()
const throw() {
54 return "CD-ROM drive could not be identified.";
60 const char*
what()
const throw() {
61 return "No disc present.";
68 const char*
what()
const throw() {
69 return "Could not open disc.";
85 unsigned int tracks()
const;
88 unsigned int track()
const;
91 lba_t
lba(
const track_t
track)
const;
104 int16_t
next()
override;
136 static std::vector<std::string>
devices();
The Poller uses a separate thread to poll the host for a disc drive with an audio CD.
Poller(CDDrive &drive)
Poller constructor.
std::mutex _exit_lock
Provides mutually exclusive access to the _exit member between the the application thread and the Pol...
bool _exit
Stores a request to exit poll().
~Poller()
Poller destructor.
std::thread _thread
The thread used to run poll().
void poll()
The execution loop performed by the thread.
CDDrive & _drive
The parent CDDrive.
The Reader uses a separate thread to load data into the CDDrive's ring buffer.
Action
Actions are taken consecutively. Setting an action on the Reader takes effect after its current actio...
void buffer(const int buffer)
Sets the index of the buffer in the CDDrive's ring buffer to read samples into.
Action _action
The current or next action to be taken by the Reader.
std::thread _thread
The thread used to run loop().
void loop()
The execution loop performed by the thread.
cdrom_paranoia_t * _paranoia
cdio handle to the sample reader.
void load()
Fills the current buffer with audio samples.
CDDrive & _drive
The parent CDDrive.
Reader(CDDrive &drive)
Reader constructor.
int _buffer
The index of the buffer in the CDDrive's ring buffer to read samples into.
~Reader()
Reader destructor.
Action action()
Returns the current Reader action in a thread-safe way.
std::mutex _action_lock
Provides mutually exclusive access to the _action member between the the application thread and the R...
int16_t * _buffers[2]
A ring buffer of size 2. One buffer has new audio samples written to it. When that buffer is full,...
std::mutex _load_lock
Provides mutually exclusive access to the drive and audio buffers between the application thread and ...
Poller * _poller
Used to poll for the first openable disc drive.
void update_track(const unsigned int track)
Sets the current disc track using 1-based indexing.
float progress()
The percentage completion of the rip of the current track (0.0 - 1.0).
bool present() const
Returns whether a disc is in the drive.
void eject()
Ejects the disc in the drive.
unsigned int _end
The 0-based index just past the end of the read buffer.
void track(const int track)
Sets the current track to the given 1-based index.
~CDDrive()
CDDrive destructor.
sigc::signal< void()> sig_eject
"Eject requested" signal type.
lba_t lba(const track_t track) const
Returns the LBA (large block address) of the start of the given track on the disc.
unsigned int _cursor
The 0-based index into the read buffer.
void register_consumer(const Consumer< int16_t > *const)=delete
Deleted. This Producer does not support multiple Consumers.
cdrom_drive_t * _drive
A cdio handle to the disc drive.
bool identify()
Finds a disc drive on the host with an audio disc inside.
bool done()
Whether the current track has been played or ripped through.
static constexpr int BUFFER_SIZE_PLAYING
The audio buffer size when playing, in CD audio frames.
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.
int16_t next() override
Provides the next audio sample from the current track. This is one half of an audio frame which conta...
std::string _device
The path to the device node of the disc drive.
unsigned int seconds() const
The duration of the entire disc in whole seconds.
int _bufferSamples
The number of audio samples (one half of an audio frame) in the audio buffer.
float elapsed()
The elapsed duration of the track in fractional seconds.
int16_t next_for_consumer(const Consumer< int16_t > *const)=delete
Deleted. This Producer does not support multiple Consumers.
int _bufferSectors
The number of CD frames in the audio buffer.
CDDrive()
CDDrive constructor.
static constexpr int BUFFER_SIZE_RIPPING
The audio buffer size when ripping, in CD audio frames.
sig_eject _sig_eject
Emitted when the disc is successfully ejected.
static constexpr int BYTES_PER_SAMPLE
The number of bytes in one CD audio sample (an int16_t).
std::mutex _cursor_lock
Provides mutually exclusive access to the track cursor between the the application thread and the Por...
static constexpr int SAMPLE_RATE
CD audio sample rate.
sig_eject signal_eject()
Getter for ::_signal_eject.
void open()
Opens the disc for reading.
static std::vector< std::string > devices()
Returns the paths of device nodes corresponding to disc drives with discs that can be opened.
unsigned int _track
The current track being played or ripped.
void resize_buffer(unsigned int sectors)
Resizes the audio buffer.
Reader * _reader
Used to read audio samples into the audio buffer.
unsigned int tracks() const
Returns the number of tracks on the disc.
unsigned int track() const
Returns the 1-based index of the current track.
Thrown when the audio CD was recognized but could not be opened for reading.
const char * what() const
Thrown when an audio CD was internally expected in the disc drive but could not be recognized.
const char * what() const
Called when the presumption that a disc is present is false.
const char * what() const