2
cdda input class based on cdparanoia
3
Copyright (C) 2000 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
20
#include "cddaInputStream.h"
21
#include "inputDetector.h"
24
void paranoiaCallback(long, int) {
25
//cout << "long:"<<a<<" int:"<<b<<endl;
28
CDDAInputStream::CDDAInputStream() {
36
CDDAInputStream::~CDDAInputStream() {
40
// here we should encdoe the track Nr. as well
42
int CDDAInputStream::getTrackAndDevice(const char* url) {
44
// dest = "cdda:/dev/cdrom/track01.cda"
45
char* noprotoString=InputDetector::removeProtocol(url);
46
// noprotoString="/dev/cdrom/track01.cda"
47
char* filename=InputDetector::getFilename(noprotoString);
48
// filename="track01.cda"
49
char* filenameNoExt=InputDetector::getWithoutExtension(filename);
50
// filenameNoExt="track01"
51
char* dir=InputDetector::removeExtension(noprotoString,filename);
53
device=InputDetector::removeSlash(dir);
55
if (filenameNoExt != NULL) {
56
matches=sscanf(filenameNoExt,"track%02d",&track);
59
cout << "no trackNumber found using default"<<endl;
61
cout << "device:"<<device<<" track:"<<track<<endl;
63
if (noprotoString != NULL) {
66
if (filename != NULL) {
69
if (filenameNoExt != NULL) {
76
cout << "no device found, using any"<<endl;
82
int CDDAInputStream::open(const char* dest) {
83
if (getTrackAndDevice(dest) == true) {
84
drive = cdda_identify(device, CDDA_MESSAGE_PRINTIT, 0);
88
cout << "cdda_identify failed trying to find a device"<<endl;
89
drive=cdda_find_a_cdrom(CDDA_MESSAGE_PRINTIT, 0);
92
cout << "nope. nothing found. give up"<<endl;
95
cout << "cdda_open -s"<<endl;
96
if (cdda_open(drive) != 0) {
97
cout << "cdda_open(drive) failed"<<endl;
101
cout << "cdda_open -e"<<endl;
103
// debug things a bit
104
int trackCount = drive->tracks;
105
for (int i = 1; i <= trackCount; i++) {
106
if (IS_AUDIO(drive, i)) {
107
printf("track%02d.cda\n", i);
109
printf("no audio:%d\n",i);
113
paranoia = paranoia_init(drive);
114
if (paranoia == NULL) {
115
cout << "paranoia init failed"<<endl;
120
firstSector=cdda_track_firstsector(drive, track);
121
lastSector=cdda_track_lastsector(drive, track);
122
currentSector=firstSector;
123
// paranoia && drive != NULL -> initialized!
125
int paranoiaLevel = PARANOIA_MODE_FULL ^ PARANOIA_MODE_NEVERSKIP;
126
paranoia_modeset(paranoia, paranoiaLevel);
127
cdda_verbose_set(drive, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);
128
paranoia_seek(paranoia, firstSector, SEEK_SET);
134
void CDDAInputStream::close() {
135
if (isOpen() == false) {
140
if (paranoia != NULL) {
141
paranoia_free(paranoia);
144
if (device != NULL) {
151
int CDDAInputStream::isOpen() {
152
return (drive != NULL);
156
int CDDAInputStream::eof() {
157
if (isOpen()==false) {
160
if (currentSector >= lastSector) {
167
int CDDAInputStream::read(char* dest,int len) {
168
if (len != 2*CD_FRAMESIZE_RAW) {
169
cout << "len must be 2*CD_FRAMESIZE_RAW"<<endl;
172
int16_t * buf = paranoia_read(paranoia, paranoiaCallback);
175
cout << "paranoia_read failed"<<endl;
179
memcpy(dest,buf,sizeof(int16_t)*CD_FRAMESIZE_RAW);
180
return CD_FRAMESIZE_RAW;
184
int CDDAInputStream::seek(long bytePos) {
185
int byteLength=getByteLength();
186
float ratio=(float)bytePos/(float)(byteLength+1);
187
float wantSector=ratio*(float)((lastSector-firstSector));
189
currentSector=(int)wantSector;
190
cout << "paranoia_seek:"<<currentSector<<endl;
191
paranoia_seek(paranoia, currentSector, SEEK_SET);
196
void CDDAInputStream::clear() {
197
cout << "direct virtual call CDDAInputStream::clear:"<<endl;
201
long CDDAInputStream::getByteLength() {
202
int sectors=lastSector-firstSector;
203
int bytes=sectors*CD_FRAMESIZE_RAW*sizeof(int16_t);
204
cout << "getByteLength:"<<bytes<<endl;
209
long CDDAInputStream::getBytePosition() {
210
int readSectors=currentSector-firstSector;
211
int bytes=readSectors*CD_FRAMESIZE_RAW*sizeof(int16_t);