92
94
* need to exit right away so the UI doesn't show the user any CDDA controls.
95
wmcdda_init(char **bufadr, long *buflenadr, int init_fd, char *devname)
97
wmcdda_init(struct cdda_device* pdev, struct cdda_block *block)
97
struct cdrom_cdda cdda;
99
*bufadr = malloc(numblocks * CDDABLKSIZE * 2);
103
*buflenadr = numblocks * CDDABLKSIZE;
105
/*init_fd = open(devname, 0);
107
init_fd = open("/dev/rdsk/c0t6d0s2", 0);
109
init_fd = wmcdda_open(devname);
99
struct cdrom_cdda cdda;
105
for (i = 0; i < pdev->numblocks; i++) {
107
pdev->blocks[i].buflen = pdev->frames_at_once * CDDABLKSIZE;
108
pdev->blocks[i].buf = malloc(pdev->blocks[i].buflen);
109
if (!pdev->blocks[i].buf)
113
pdev->fd = open(pdev->devname, 0);
115
pdev->fd = open("/dev/rdsk/c0t6d0s2", 0);
113
119
cdda.cdda_addr = 200;
114
120
cdda.cdda_length = 1;
115
cdda.cdda_data = *bufadr;
121
cdda.cdda_data = pdev->blocks[0].buf;
116
122
cdda.cdda_subcode = CDROM_DA_SUBQ;
118
if (ioctl(init_fd, CDROMCDDA, &cdda) < 0)
124
if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0)
126
block->status = WM_CDM_STOPPED;
129
block->status = WM_CDM_STOPPED;
133
block->status = WM_CDM_EJECTED;
129
* Try to open the CD device
132
wmcdda_open(char *devname)
136
fd = open(devname, 0);
138
fd = open("/dev/rdsk/c0t6d0s2", 0);
145
139
* Close the CD-ROM device in preparation for exiting.
142
wmcdda_close(struct cdda_device* pdev)
152
for (i = 0; i < pdev->numblocks; i++) {
153
free(pdev->blocks[i].buf);
154
pdev->blocks[i].buf = 0;
155
pdev->blocks[i].buflen = 0;
154
162
* Set up for playing the CD. Actually this doesn't play a thing, just sets a
155
163
* couple variables so we'll know what to do when we're called.
158
166
wmcdda_setup(int start, int end, int realstart)
160
168
current_position = start - 150;
175
184
* Returns number of bytes read, -1 on error, 0 if stopped for a benign reason.
178
wmcdda_read(int fd, unsigned char *rawbuf, long buflen,
179
struct cdda_block *block)
187
wmcdda_read(struct cdda_device* pdev, struct cdda_block *block)
181
struct cdrom_cdda cdda;
186
if ((direction > 0 && current_position >= ending_position) ||
187
(direction < 0 && current_position < starting_position))
189
block->status = WMCDDA_DONE;
193
cdda.cdda_addr = current_position;
194
if (ending_position && current_position + numblocks > ending_position)
195
cdda.cdda_length = ending_position - current_position;
197
cdda.cdda_length = numblocks;
198
cdda.cdda_data = rawbuf;
199
cdda.cdda_subcode = CDROM_DA_SUBQ;
201
if (ioctl(fd, CDROMCDDA, &cdda) < 0)
203
if (errno == ENXIO) /* CD ejected! */
205
block->status = WMCDDA_EJECTED;
209
if (current_position + numblocks > ending_position)
212
* Hit the end of the CD, probably.
214
block->status = WMCDDA_DONE;
218
/* Sometimes it fails once, dunno why */
219
if (ioctl(fd, CDROMCDDA, &cdda) < 0)
221
if (ioctl(fd, CDROMCDDA, &cdda) < 0)
223
if (ioctl(fd, CDROMCDDA, &cdda) < 0)
226
block->status = WMCDDA_ERROR;
236
* We want speed=148 to advance by cdda_length, but
237
* speed=256 to advance cdda_length * 4.
239
current_position = current_position +
240
(cdda.cdda_length * direction * (speed - 112)) / 36;
243
current_position = current_position +
244
cdda.cdda_length * direction;
246
for (blk = 0; blk < numblocks; blk++)
249
* New valid Q-subchannel information? Update the block
252
q = &rawbuf[blk * CDDABLKSIZE + SAMPLES_PER_BLK * 4];
255
block->status = WMCDDA_OK;
256
block->track = unbcd[q[1]];
257
block->index = unbcd[q[2]];
258
block->minute = unbcd[q[7]];
259
block->second = unbcd[q[8]];
260
block->frame = unbcd[q[9]];
264
return (cdda.cdda_length * CDDABLKSIZE);
189
struct cdrom_cdda cdda;
193
unsigned char* rawbuf = block->buf;
195
if(pdev->fd < 0 && (wmcdda_init(pdev, block) < 0)) {
200
* Hit the end of the CD, probably.
202
if ((direction > 0 && current_position >= ending_position) ||
203
(direction < 0 && current_position < starting_position))
205
block->status = WM_CDM_TRACK_DONE;
209
cdda.cdda_addr = current_position;
210
if (ending_position && current_position + pdev->frames_at_once > ending_position)
211
cdda.cdda_length = ending_position - current_position;
213
cdda.cdda_length = pdev->frames_at_once;
214
cdda.cdda_data = (unsigned char*)block->buf;
215
cdda.cdda_subcode = CDROM_DA_SUBQ;
217
if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0)
219
if (errno == ENXIO) /* CD ejected! */
221
block->status = WM_CDM_EJECTED;
225
/* Sometimes it fails once, dunno why */
226
if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0)
228
if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0)
230
if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0)
233
block->status = WM_CDM_CDDAERROR;
243
* We want speed=148 to advance by cdda_length, but
244
* speed=256 to advance cdda_length * 4.
246
current_position = current_position +
247
(cdda.cdda_length * direction * (speed - 112)) / 36;
250
current_position = current_position + cdda.cdda_length * direction;
252
for (blk = 0; blk < numblocks; blk++)
255
* New valid Q-subchannel information? Update the block
258
q = &rawbuf[blk * CDDABLKSIZE + SAMPLES_PER_BLK * 4];
261
block->track = unbcd[q[1]];
262
block->index = unbcd[q[2]];
263
/*block->minute = unbcd[q[7]];
264
block->second = unbcd[q[8]];*/
265
block->frame = unbcd[q[9]];
266
block->status = WM_CDM_PLAYING;
267
block->buflen = cdda.cdda_length;
271
return wmcdda_normalize(block);