~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kscd/libwm/plat_irix.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: plat_irix.c,v 1.6 2001/04/10 17:34:52 dfoerste Exp $
 
3
 *
 
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 
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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
 
23
 *
 
24
 *
 
25
 * IRIX specific.
 
26
 *
 
27
 * Taken from the kscd distribution
 
28
 *
 
29
 * Paul Kendall
 
30
 * paul@orion.co.nz, or
 
31
 * paul@kcbbs.gen.nz
 
32
 */
 
33
 
 
34
static char plat_irix_id[] = "$Id: plat_irix.c,v 1.6 2001/04/10 17:34:52 dfoerste Exp $";
 
35
 
 
36
#if defined(sgi) || defined(__sgi)
 
37
 
 
38
#include "include/wm_config.h"
 
39
 
 
40
/*
 
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
 
44
 * CDDA yourself.
 
45
 *
 
46
 */
 
47
#undef CDDA
 
48
/*#define CDDA*/
 
49
 
 
50
#include <sys/types.h>
 
51
#include <sys/time.h>
 
52
#include <stdio.h>
 
53
#include <ctype.h>
 
54
#include <string.h>
 
55
#include <fcntl.h>
 
56
#include <stdlib.h>
 
57
#include <unistd.h>
 
58
#include <signal.h>
 
59
#include <sigfpe.h>
 
60
#include <dmedia/cdaudio.h>
 
61
#include <dmedia/audio.h>
 
62
#include <errno.h>
 
63
 
 
64
#include "include/wm_struct.h"
 
65
#include "include/wm_cdtext.h"
 
66
 
 
67
#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
 
68
 
 
69
void *malloc();
 
70
char *strchr();
 
71
 
 
72
int     min_volume = 0;
 
73
int     max_volume = 255;
 
74
 
 
75
extern char     *cd_device;
 
76
 
 
77
#ifdef CDDA
 
78
static int playing = STOPPED;
 
79
static CDPLAYER *icd;
 
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} };
 
85
static int cdtrack=0;
 
86
static int cdframe=0;
 
87
static int cdstopframe=0;
 
88
 
 
89
/*
 
90
 * Platform specific internal functions for CDDA
 
91
 */
 
92
void
 
93
cbprognum(void *arg, CDDATATYPES type, CDPROGNUM* prognum)
 
94
{
 
95
  cdtrack = prognum->value;
 
96
} /* cbprognum() */
 
97
 
 
98
void
 
99
cbabstime(void *arg, CDDATATYPES type, struct cdtimecode* atime)
 
100
{
 
101
  cdframe = CDtctoframe(atime);
 
102
  if( cdframe == cdstopframe )
 
103
    playing = STOPPED;
 
104
} /* cbabstime() */
 
105
 
 
106
void
 
107
cbplayaudio(void *arg, CDDATATYPES type, short* audio)
 
108
{
 
109
        if(playing != PLAYING) return;
 
110
        ALwritesamps(audioport, audio, CDDA_NUMSAMPLES);
 
111
} /* cbplayaudio() */
 
112
 
 
113
static void 
 
114
alarmsignal()
 
115
{
 
116
  int n, i;
 
117
  if(playing != PLAYING) return;
 
118
  if( ALgetfilled(audioport) < CDDA_NUMSAMPLES*8 ) 
 
119
    {
 
120
      /* Only get more samples and play them if we're getting low
 
121
       * this ensures that the CD stays close to the sound
 
122
       */
 
123
      n = CDreadda(icd, cdbuf, 12);
 
124
      if( n == 0 ) return;
 
125
      for( i=0 ; i<12 ; i++ )
 
126
        CDparseframe(icdp, &cdbuf[i]);
 
127
    }
 
128
  signal(SIGALRM, alarmsignal);
 
129
  setitimer(ITIMER_REAL, &audiotimer, NULL);
 
130
} /* alarmsignal() */
 
131
#endif
 
132
 
 
133
/*--------------------------------------------------------*
 
134
 * Initialize the drive.  A no-op for the generic driver.
 
135
 *--------------------------------------------------------*/
 
136
int
 
137
gen_init( struct wm_drive *d )
 
138
{
 
139
#ifdef CDDA
 
140
  long Param[4];
 
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);
 
150
  
 
151
  /* setup cdparser */
 
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);
 
156
  
 
157
  /* Lets handle those floating point exceptions expeditiously. */
 
158
  sigfpe_[_UNDERFL].repls = _ZERO;
 
159
  handle_sigfpes(_ON, _EN_UNDERFL, NULL, _ABORT_ON_ERROR, NULL);
 
160
#endif
 
161
  return 0;
 
162
} /* gen_init() */
 
163
 
 
164
/*-------------------------------------------------------------*
 
165
 * Open the CD and figure out which kind of drive is attached.
 
166
 *-------------------------------------------------------------*/
 
167
int
 
168
wmcd_open( struct wm_drive *d )
 
169
{
 
170
  int   fd;
 
171
  CDSTATUS s;
 
172
  
 
173
  if (d->fd < 0)                /* Device already open? */
 
174
    {
 
175
      if (cd_device == NULL)
 
176
        cd_device = DEFAULT_CD_DEVICE;
 
177
      
 
178
      d->fd = 1;
 
179
      
 
180
      /* Now fill in the relevant parts of the wm_drive structure. */
 
181
      fd = d->fd;
 
182
      *d = *(find_drive_struct("", "", ""));
 
183
      d->fd = fd;
 
184
      (d->init)(d);
 
185
      
 
186
      d->daux = CDopen(cd_device,"r");
 
187
      if (d->daux == 0)
 
188
        {
 
189
          return (-6);
 
190
        }
 
191
#ifdef CDDA
 
192
      icd = d->daux;
 
193
#endif
 
194
    } else {
 
195
      wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_open(): [device is open (fd=%d)]\n", d->fd);
 
196
    }
 
197
  
 
198
  CDgetstatus(d->daux, &s);
 
199
  if( s.state==CD_NODISC || s.state==CD_ERROR )
 
200
    return 1;
 
201
  
 
202
  return (0);
 
203
} /* wmcd_open() */
 
204
 
 
205
/*
 
206
 * Re-Open the device if it is open.
 
207
 */
 
208
int
 
209
wmcd_reopen( struct wm_drive *d )
 
210
{
 
211
  int status;
 
212
  
 
213
  do {
 
214
    wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_reopen\n");
 
215
    if (d->fd >= 0)             /* Device really open? */
 
216
      {
 
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? */
 
220
        d->fd = -1;
 
221
      }
 
222
    wm_susleep( 1000 );
 
223
    wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calling wmcd_open()\n");
 
224
    status = wmcd_open( d ); /* open it as usual */
 
225
    wm_susleep( 1000 );
 
226
  } while ( status != 0 );
 
227
  return status;
 
228
} /* wmcd_reopen() */
 
229
 
 
230
 
 
231
/*----------------------------------*
 
232
 * Send a SCSI command out the bus.
 
233
 *----------------------------------*/
 
234
int 
 
235
wm_scsi( struct wm_drive *d, unsigned char *xcdb, int cdblen, 
 
236
         char *retbuf, int retbuflen, int getreply)
 
237
{
 
238
  return -1;
 
239
} /* wm_scsi() */
 
240
 
 
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
 *--------------------------------------------------------------------------*/
 
246
int
 
247
gen_get_drive_status( struct wm_drive *d, enum wm_cd_modes oldmode,
 
248
                      enum wm_cd_modes *mode, int *pos, int *track,
 
249
                      int *index )
 
250
{
 
251
#ifdef CDDA
 
252
  *mode = playing;
 
253
  *track = cdtrack;
 
254
  *pos = cdframe;
 
255
  *index = 0;
 
256
#else
 
257
  CDSTATUS s;
 
258
  if( CDgetstatus(d->daux, &s)==0 )
 
259
    return -1;
 
260
  *pos = CDmsftoframe(s.min,s.sec,s.frame);
 
261
  *track = s.track;
 
262
  *index = 0;
 
263
  switch( s.state )
 
264
    {
 
265
    case CD_READY:      *mode = WM_CDM_STOPPED;
 
266
      break;
 
267
    case CD_STILL:
 
268
    case CD_PAUSED: *mode = WM_CDM_PAUSED;
 
269
      break;
 
270
    case CD_PLAYING: *mode = WM_CDM_PLAYING;
 
271
      break;
 
272
    default:            *mode = WM_CDM_UNKNOWN;
 
273
    }
 
274
#endif
 
275
  return 0;
 
276
} /* gen_get_drive_status() */
 
277
 
 
278
/*-------------------------------------*
 
279
 * Get the number of tracks on the CD.
 
280
 *-------------------------------------*/
 
281
int
 
282
gen_get_trackcount( struct wm_drive *d, int *tracks )
 
283
{
 
284
  CDSTATUS s;
 
285
  if( CDgetstatus(d->daux, &s)==0 )
 
286
    return -1;
 
287
  *tracks = s.last;
 
288
  return 0;
 
289
} /* gen_get_trackcount() */
 
290
 
 
291
/*---------------------------------------------------------*
 
292
 * Get the start time and mode (data or audio) of a track.
 
293
 *---------------------------------------------------------*/
 
294
int
 
295
gen_get_trackinfo( struct wm_drive *d, int track, int *data, int *startframe)
 
296
{
 
297
  CDTRACKINFO i;
 
298
  int ret = CDgettrackinfo(d->daux, track, &i);
 
299
  if( ret == 0 )
 
300
    return -1;
 
301
  *data = 0;
 
302
  *startframe = CDmsftoframe(i.start_min,i.start_sec,i.start_frame);
 
303
  return 0;
 
304
} /* gen_get_trackinfo() */
 
305
 
 
306
/*-------------------------------------*
 
307
 * Get the number of frames on the CD.
 
308
 *-------------------------------------*/
 
309
int
 
310
gen_get_cdlen( struct wm_drive *d, int *frames )
 
311
{
 
312
  CDSTATUS s;
 
313
  if( CDgetstatus(d->daux, &s)==0 )
 
314
    return -1;
 
315
  *frames = CDmsftoframe(s.total_min,s.total_sec,s.total_frame);
 
316
  return 0;
 
317
} /* gen_get_cdlen() */
 
318
 
 
319
/*------------------------------------------------------------*
 
320
 * Play the CD from one position to another (both in frames.)
 
321
 *------------------------------------------------------------*/
 
322
int
 
323
gen_play( struct wm_drive *d, int start, int end )
 
324
{
 
325
#ifdef CDDA
 
326
  int m, s, f;
 
327
  CDframetomsf(start, &m, &s, &f);
 
328
  CDseek(icd, m, s, f);
 
329
  cdstopframe = end;
 
330
  playing = PLAYING;
 
331
  signal(SIGALRM, alarmsignal);
 
332
  setitimer(ITIMER_REAL, &audiotimer, NULL);
 
333
#else
 
334
  int m, s, f;
 
335
  CDframetomsf(start, &m, &s, &f);
 
336
  CDplayabs(d->daux, m, s, f, 1);
 
337
#endif
 
338
  return 0;
 
339
} /* gen_play() */
 
340
 
 
341
/*---------------*
 
342
 * Pause the CD.
 
343
 *---------------*/
 
344
int
 
345
gen_pause( struct wm_drive *d )
 
346
{
 
347
#ifdef CDDA
 
348
  playing = WM_CDM_PAUSED;
 
349
#else
 
350
  CDSTATUS s;
 
351
  if( CDgetstatus(d->daux, &s)==0 )
 
352
    return -1;
 
353
  if(s.state == CD_PLAYING)
 
354
    CDtogglepause(d->daux);
 
355
#endif
 
356
  return 0;
 
357
} /* gen_pause() */
 
358
 
 
359
/*-------------------------------------------------*
 
360
 * Resume playing the CD (assuming it was paused.)
 
361
 *-------------------------------------------------*/
 
362
int
 
363
gen_resume( struct wm_drive *d )
 
364
{
 
365
#ifdef CDDA
 
366
  playing = WM_CDM_PLAYING;
 
367
  signal(SIGALRM, alarmsignal);
 
368
  setitimer(ITIMER_REAL, &audiotimer, NULL);
 
369
#else
 
370
  CDSTATUS s;
 
371
  if( CDgetstatus(d->daux, &s)==0 )
 
372
    return -1;
 
373
  if(s.state == CD_PAUSED)
 
374
    CDtogglepause(d->daux);
 
375
#endif
 
376
  return 0;
 
377
} /* gen_resume() */
 
378
 
 
379
/*--------------*
 
380
 * Stop the CD.
 
381
 *--------------*/
 
382
int
 
383
gen_stop( struct wm_drive *d )
 
384
{
 
385
#ifdef CDDA
 
386
  playing = WM_CDM_STOPPED;
 
387
#else
 
388
  CDstop(d->daux);
 
389
#endif
 
390
  return 0;
 
391
} /* gen_stop() */
 
392
 
 
393
/*----------------------------------------*
 
394
 * Eject the current CD, if there is one.
 
395
 *----------------------------------------*/
 
396
int
 
397
gen_eject( struct wm_drive *d )
 
398
{
 
399
#ifdef CDDA
 
400
  playing = WM_CDM_STOPPED;
 
401
#endif
 
402
  CDeject(d->daux);
 
403
  return 0;
 
404
} /* gen_eject() */
 
405
 
 
406
/*----------------------------------------*
 
407
 * Close the CD tray
 
408
 *
 
409
 * Please edit and send changes to
 
410
 * milliByte@Deathsdoor.com
 
411
 *----------------------------------------*/
 
412
 
 
413
int 
 
414
gen_closetray(struct wm_drive *d)
 
415
{
 
416
#ifdef CAN_CLOSE
 
417
  if(!close(d->fd))
 
418
    {
 
419
      d->fd=-1;
 
420
      return(wmcd_reopen(d));
 
421
    } else {
 
422
      return(-1);
 
423
    }
 
424
#else
 
425
  /* Always succeed if the drive can't close */
 
426
  return(0);
 
427
#endif /* CAN_CLOSE */
 
428
} /* gen_closetray() */
 
429
 
 
430
/*---------------------------------------------------------------------*
 
431
 * Set the volume level for the left and right channels.  Their values
 
432
 * range from 0 to 100.
 
433
 *---------------------------------------------------------------------*/
 
434
int
 
435
gen_set_volume( struct wm_drive *d, int left, int right )
 
436
{
 
437
  long Param[4];
 
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);
 
441
  return 0;
 
442
} /* gen_set_volume() */
 
443
 
 
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
 *---------------------------------------------------------------------*/
 
448
int
 
449
gen_get_volume( struct wm_drive *d, int *left, int *right )
 
450
{
 
451
  long Param[4];
 
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;
 
457
  return 0;
 
458
} /* gen_get_volume() */
 
459
 
 
460
 
 
461
/*------------------------------------------------------------------------*
 
462
 * gen_get_cdtext(drive, buffer, lenght)
 
463
 *------------------------------------------------------------------------*/
 
464
 
 
465
int
 
466
gen_get_cdtext(struct wm_drive *d, unsigned char **pp_buffer, int *p_buffer_lenght)
 
467
{
 
468
  return -1; /* no SCSI, no CDTEXT */
 
469
} /* gen_get_cdtext() */
 
470
 
 
471
 
 
472
#endif
 
473