2
* $Id: plat_irix.c,v 1.6 2001/04/10 17:34:52 dfoerste Exp $
4
* This file is part of WorkMan, the civilized CD player library
5
* (c) 1991-1997 by Steven Grimm (original author)
6
* (c) by Dirk Fļæ½rsterling (current 'author' = maintainer)
7
* The maintainer can be contacted by his e-mail address:
8
* milliByte@DeathsDoor.com
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Library General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Library General Public License for more details.
20
* You should have received a copy of the GNU Library General Public
21
* License along with this library; if not, write to the Free
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
* Taken from the kscd distribution
30
* paul@orion.co.nz, or
34
static char plat_irix_id[] = "$Id: plat_irix.c,v 1.6 2001/04/10 17:34:52 dfoerste Exp $";
36
#if defined(sgi) || defined(__sgi)
38
#include "include/wm_config.h"
41
* Yes, it was designed for WorkMan 1.4b3
42
* Because I did start over from 1.3a, I disable it here.
43
* There is no guarantee of getting working code by defining
50
#include <sys/types.h>
60
#include <dmedia/cdaudio.h>
61
#include <dmedia/audio.h>
64
#include "include/wm_struct.h"
65
#include "include/wm_cdtext.h"
67
#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
75
extern char *cd_device;
78
static int playing = STOPPED;
80
static CDPARSER *icdp;
81
static CDFRAME cdbuf[12];
82
static ALport audioport;
83
static ALconfig aconfig;
84
static struct itimerval audiotimer = { {0,0}, {0,25000} };
87
static int cdstopframe=0;
90
* Platform specific internal functions for CDDA
93
cbprognum(void *arg, CDDATATYPES type, CDPROGNUM* prognum)
95
cdtrack = prognum->value;
99
cbabstime(void *arg, CDDATATYPES type, struct cdtimecode* atime)
101
cdframe = CDtctoframe(atime);
102
if( cdframe == cdstopframe )
107
cbplayaudio(void *arg, CDDATATYPES type, short* audio)
109
if(playing != PLAYING) return;
110
ALwritesamps(audioport, audio, CDDA_NUMSAMPLES);
111
} /* cbplayaudio() */
117
if(playing != PLAYING) return;
118
if( ALgetfilled(audioport) < CDDA_NUMSAMPLES*8 )
120
/* Only get more samples and play them if we're getting low
121
* this ensures that the CD stays close to the sound
123
n = CDreadda(icd, cdbuf, 12);
125
for( i=0 ; i<12 ; i++ )
126
CDparseframe(icdp, &cdbuf[i]);
128
signal(SIGALRM, alarmsignal);
129
setitimer(ITIMER_REAL, &audiotimer, NULL);
130
} /* alarmsignal() */
133
/*--------------------------------------------------------*
134
* Initialize the drive. A no-op for the generic driver.
135
*--------------------------------------------------------*/
137
gen_init( struct wm_drive *d )
141
/* Set the audio rate to 44100Hz 16bit 2s-comp stereo */
142
aconfig = ALnewconfig();
143
ALsetwidth(aconfig, AL_SAMPLE_16);
144
ALsetsampfmt(aconfig, AL_SAMPFMT_TWOSCOMP);
145
ALsetchannels(aconfig, 2);
146
Param[0] = AL_OUTPUT_RATE; Param[1] = AL_RATE_44100;
147
Param[2] = AL_CHANNEL_MODE; Param[3] = AL_STEREO;
148
ALsetparams(AL_DEFAULT_DEVICE, Param, 4);
149
audioport = ALopenport("KDE KSCD Audio", "w", aconfig);
152
icdp = CDcreateparser();
153
CDaddcallback(icdp, cd_audio, (CDCALLBACKFUNC)cbplayaudio, 0);
154
CDaddcallback(icdp, cd_pnum, (CDCALLBACKFUNC)cbprognum, 0);
155
CDaddcallback(icdp, cd_atime, (CDCALLBACKFUNC)cbabstime, 0);
157
/* Lets handle those floating point exceptions expeditiously. */
158
sigfpe_[_UNDERFL].repls = _ZERO;
159
handle_sigfpes(_ON, _EN_UNDERFL, NULL, _ABORT_ON_ERROR, NULL);
164
/*-------------------------------------------------------------*
165
* Open the CD and figure out which kind of drive is attached.
166
*-------------------------------------------------------------*/
168
wmcd_open( struct wm_drive *d )
173
if (d->fd < 0) /* Device already open? */
175
if (cd_device == NULL)
176
cd_device = DEFAULT_CD_DEVICE;
180
/* Now fill in the relevant parts of the wm_drive structure. */
182
*d = *(find_drive_struct("", "", ""));
186
d->daux = CDopen(cd_device,"r");
195
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_open(): [device is open (fd=%d)]\n", d->fd);
198
CDgetstatus(d->daux, &s);
199
if( s.state==CD_NODISC || s.state==CD_ERROR )
206
* Re-Open the device if it is open.
209
wmcd_reopen( struct wm_drive *d )
214
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_reopen\n");
215
if (d->fd >= 0) /* Device really open? */
217
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n");
218
status = close( d->fd ); /* close it! */
219
/* we know, that the file is closed, do we? */
223
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calling wmcd_open()\n");
224
status = wmcd_open( d ); /* open it as usual */
226
} while ( status != 0 );
228
} /* wmcd_reopen() */
231
/*----------------------------------*
232
* Send a SCSI command out the bus.
233
*----------------------------------*/
235
wm_scsi( struct wm_drive *d, unsigned char *xcdb, int cdblen,
236
char *retbuf, int retbuflen, int getreply)
241
/*--------------------------------------------------------------------------*
242
* Get the current status of the drive: the current play mode, the absolute
243
* position from start of disc (in frames), and the current track and index
244
* numbers if the CD is playing or paused.
245
*--------------------------------------------------------------------------*/
247
gen_get_drive_status( struct wm_drive *d, enum wm_cd_modes oldmode,
248
enum wm_cd_modes *mode, int *pos, int *track,
258
if( CDgetstatus(d->daux, &s)==0 )
260
*pos = CDmsftoframe(s.min,s.sec,s.frame);
265
case CD_READY: *mode = WM_CDM_STOPPED;
268
case CD_PAUSED: *mode = WM_CDM_PAUSED;
270
case CD_PLAYING: *mode = WM_CDM_PLAYING;
272
default: *mode = WM_CDM_UNKNOWN;
276
} /* gen_get_drive_status() */
278
/*-------------------------------------*
279
* Get the number of tracks on the CD.
280
*-------------------------------------*/
282
gen_get_trackcount( struct wm_drive *d, int *tracks )
285
if( CDgetstatus(d->daux, &s)==0 )
289
} /* gen_get_trackcount() */
291
/*---------------------------------------------------------*
292
* Get the start time and mode (data or audio) of a track.
293
*---------------------------------------------------------*/
295
gen_get_trackinfo( struct wm_drive *d, int track, int *data, int *startframe)
298
int ret = CDgettrackinfo(d->daux, track, &i);
302
*startframe = CDmsftoframe(i.start_min,i.start_sec,i.start_frame);
304
} /* gen_get_trackinfo() */
306
/*-------------------------------------*
307
* Get the number of frames on the CD.
308
*-------------------------------------*/
310
gen_get_cdlen( struct wm_drive *d, int *frames )
313
if( CDgetstatus(d->daux, &s)==0 )
315
*frames = CDmsftoframe(s.total_min,s.total_sec,s.total_frame);
317
} /* gen_get_cdlen() */
319
/*------------------------------------------------------------*
320
* Play the CD from one position to another (both in frames.)
321
*------------------------------------------------------------*/
323
gen_play( struct wm_drive *d, int start, int end )
327
CDframetomsf(start, &m, &s, &f);
328
CDseek(icd, m, s, f);
331
signal(SIGALRM, alarmsignal);
332
setitimer(ITIMER_REAL, &audiotimer, NULL);
335
CDframetomsf(start, &m, &s, &f);
336
CDplayabs(d->daux, m, s, f, 1);
345
gen_pause( struct wm_drive *d )
348
playing = WM_CDM_PAUSED;
351
if( CDgetstatus(d->daux, &s)==0 )
353
if(s.state == CD_PLAYING)
354
CDtogglepause(d->daux);
359
/*-------------------------------------------------*
360
* Resume playing the CD (assuming it was paused.)
361
*-------------------------------------------------*/
363
gen_resume( struct wm_drive *d )
366
playing = WM_CDM_PLAYING;
367
signal(SIGALRM, alarmsignal);
368
setitimer(ITIMER_REAL, &audiotimer, NULL);
371
if( CDgetstatus(d->daux, &s)==0 )
373
if(s.state == CD_PAUSED)
374
CDtogglepause(d->daux);
383
gen_stop( struct wm_drive *d )
386
playing = WM_CDM_STOPPED;
393
/*----------------------------------------*
394
* Eject the current CD, if there is one.
395
*----------------------------------------*/
397
gen_eject( struct wm_drive *d )
400
playing = WM_CDM_STOPPED;
406
/*----------------------------------------*
409
* Please edit and send changes to
410
* milliByte@Deathsdoor.com
411
*----------------------------------------*/
414
gen_closetray(struct wm_drive *d)
420
return(wmcd_reopen(d));
425
/* Always succeed if the drive can't close */
427
#endif /* CAN_CLOSE */
428
} /* gen_closetray() */
430
/*---------------------------------------------------------------------*
431
* Set the volume level for the left and right channels. Their values
432
* range from 0 to 100.
433
*---------------------------------------------------------------------*/
435
gen_set_volume( struct wm_drive *d, int left, int right )
438
Param[0] = AL_LEFT_SPEAKER_GAIN; Param[1] = left*255/100;
439
Param[2] = AL_RIGHT_SPEAKER_GAIN; Param[3] = right*255/100;
440
ALsetparams(AL_DEFAULT_DEVICE, Param, 4);
442
} /* gen_set_volume() */
444
/*---------------------------------------------------------------------*
445
* Read the initial volume from the drive, if available. Each channel
446
* ranges from 0 to 100, with -1 indicating data not available.
447
*---------------------------------------------------------------------*/
449
gen_get_volume( struct wm_drive *d, int *left, int *right )
452
Param[0] = AL_LEFT_SPEAKER_GAIN; Param[1] = 0;
453
Param[2] = AL_RIGHT_SPEAKER_GAIN; Param[3] = 0;
454
ALgetparams(AL_DEFAULT_DEVICE, Param, 4);
455
*left = Param[1] * 100 / 255;
456
*right = Param[3] * 100 / 255;
458
} /* gen_get_volume() */
461
/*------------------------------------------------------------------------*
462
* gen_get_cdtext(drive, buffer, lenght)
463
*------------------------------------------------------------------------*/
466
gen_get_cdtext(struct wm_drive *d, unsigned char **pp_buffer, int *p_buffer_lenght)
468
return -1; /* no SCSI, no CDTEXT */
469
} /* gen_get_cdtext() */