/usr/include/plib/sl.h is in libplib-dev 1.8.5-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | /*
PLIB - A Suite of Portable Game Libraries
Copyright (C) 1998,2002 Steve Baker
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information visit http://plib.sourceforge.net
$Id: sl.h 1924 2004-04-06 13:32:26Z sjbaker $
*/
#ifndef __SL_H__
#define __SL_H__ 1
#include <stdio.h>
#include "slPortability.h"
#ifdef SL_USING_OSS_AUDIO
#define SLDSP_DEFAULT_DEVICE "/dev/dsp"
#elif defined(UL_WIN32)
#define SLDSP_DEFAULT_DEVICE "dsp"
#elif defined(UL_BSD)
#define SLDSP_DEFAULT_DEVICE "/dev/audio"
#elif defined(UL_IRIX)
#define SLDSP_DEFAULT_DEVICE "dsp" // dummy ...
#elif defined(UL_AIX)
#define SLDSP_DEFAULT_DEVICE "dsp" // dummy ...
#elif defined(UL_SOLARIS)
#define SLDSP_DEFAULT_DEVICE "/dev/audio"
#elif defined(UL_HPUX)
#define SLDSP_DEFAULT_DEVICE "/dev/audio"
#elif defined(UL_MACINTOSH) || defined(UL_MAC_OSX)
#define SLDSP_DEFAULT_DEVICE "dsp" // dummy
#else
#error "Port me !"
#endif
# define SL_TRUE 1
# define SL_FALSE 0
typedef unsigned char Uchar ;
typedef unsigned short Ushort ;
#define SL_DEFAULT_SAMPLING_RATE 11025
class slSample ;
class slPlayer ;
class slSamplePlayer ;
class slEnvelope ;
class slScheduler ;
class slDSP ;
extern const char *__slPendingError ;
class slDSP
{
private:
int stereo ;
int rate ;
int bps ;
int error ;
int fd ;
#if defined(SL_USING_OSS_AUDIO)
audio_buf_info buff_info ;
#elif defined(UL_BSD)
audio_info_t ainfo; // ioctl structure
audio_offset_t audio_offset; // offset in audiostream
long counter; // counter-written packets
#elif defined(UL_SOLARIS)
audio_info_t ainfo;
long counter;
#elif defined(UL_IRIX)
ALconfig config; // configuration stuff
ALport port; // .. we are here
#elif defined(UL_MACINTOSH) || defined(UL_MAC_OSX)
// Size of the data chunks written with write().
// This should be a multiple of 1024.
#define BUFFER_SIZE 8192
// Size of storage space for sound data.
// This should be evenly divisible by BUFFER_SIZE.
#define VIRTUAL_BUFFER_SIZE 131072
SndChannelPtr sndChannel ; // sound channel we are using
ExtSoundHeader extSndHeader ; // sound header for bufferCmd
SndCommand currentCmd ; // command we are sending to chnl
OSErr osErr ;
char *buf ; // buffer containing sound data
char *rpos ; // read position for buffer
char *wpos ; // write position for buffer
char *ptr ; // ptr to data from write()
float bytesPerSample ; // conversions
float bytesPerSecond ;
float secondsPerPacket ;
float secLeft ; // seconds left in buffer
float secUsed ; // seconds used in buffer
UnsignedWide lastTime ; // used for timing in secondsUsed()
UnsignedWide currTime ;
#endif
#if !defined(UL_WIN32) && !defined(UL_MACINTOSH) && !defined(UL_MAC_OSX)
int ioctl ( int cmd, int param = 0 )
{
if ( error ) return param ;
if ( ::ioctl ( fd, cmd, & param ) == -1 )
{
perror ( "slDSP: ioctl" ) ;
error = SL_TRUE ;
}
return param ;
}
#elif defined(UL_WIN32)
#define BUFFER_COUNT (3*8)
#define BUFFER_SIZE (1024*1)
friend void CALLBACK waveOutProc( HWAVEOUT hwo, UINT uMsg,
DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
HWAVEOUT hWaveOut; // device handle
WAVEFORMATEX Format; // open needs this
MMTIME mmt; // timing
WAVEHDR *wavehdr[ BUFFER_COUNT ]; // for round robin ..
int curr_header; // index of actual wavehdr
int counter; // counter-written packets
DWORD written; // counter-written samples
#endif
void open ( const char *device, int _rate, int _stereo, int _bps ) ;
void close () ;
void getBufferInfo () ;
void write ( void *buffer, size_t length ) ;
protected:
void setError () { error = SL_TRUE ; }
int getDriverBufferSize () ;
public:
slDSP ( int _rate = SL_DEFAULT_SAMPLING_RATE,
int _stereo = SL_FALSE, int _bps = 8 )
{
open ( SLDSP_DEFAULT_DEVICE, _rate, _stereo, _bps ) ;
}
slDSP ( const char *device, int _rate = SL_DEFAULT_SAMPLING_RATE,
int _stereo = SL_FALSE, int _bps = 8 )
{
open ( device, _rate, _stereo, _bps ) ;
}
~slDSP () { close () ; }
float secondsRemaining () ;
float secondsUsed () ;
void play ( void *buffer, size_t length ) { write ( buffer, length ) ; }
/* This was a typo - but people use it */
int not_working() const { return error ; }
int notWorking () const { return error ; }
int getBps () const { return bps ; }
int getRate () const { return rate ; }
int getStereo() const { return stereo ; }
void sync () ;
void stop () ;
} ;
class slSample
{
int ref_count ;
protected:
char *comment;
int rate ;
int bps ;
int stereo ;
Uchar *buffer ;
int length ;
void init ()
{
ref_count = 0 ;
comment = NULL ;
buffer = NULL ;
length = 0 ;
rate = SL_DEFAULT_SAMPLING_RATE ;
bps = 8 ;
stereo = SL_FALSE ;
}
public:
slSample () { init () ; }
slSample ( const Uchar *buff, int leng )
{
init () ;
setBuffer ( buff, leng ) ;
}
slSample ( const char *fname, const class slDSP *dsp = NULL )
{
if ( dsp != NULL && dsp->notWorking () )
dsp = NULL ;
init () ;
loadFile ( fname ) ;
autoMatch ( dsp ) ;
}
~slSample ()
{
if ( ref_count != 0 && __slPendingError == NULL )
__slPendingError =
"slSample: FATAL ERROR - Application deleted a sample while it was playing." ;
delete [] buffer ;
}
void ref () { ref_count++ ; }
void unRef () { ref_count-- ; }
int getPlayCount () const { return ref_count ; }
char *getComment () const { return comment ; }
void setComment ( const char *nc )
{
delete [] comment ;
comment = ulStrDup ( nc ) ;
}
Uchar *getBuffer () const { return buffer ; }
int getLength () const { return length ; }
void autoMatch ( const slDSP *dsp ) ;
void setBuffer ( const Uchar *buff, int leng )
{
delete [] buffer ;
buffer = new Uchar [ leng ] ;
if ( buff != NULL )
memcpy ( buffer, buff, leng ) ;
length = leng ;
}
/* These routines only set flags - use changeXXX () to convert a sound */
void setRate ( int r ) { rate = r ; }
void setBps ( int b ) { bps = b ; }
void setStereo ( int s ) { stereo = s ; }
int getRate () const { return rate ; }
int getBps () const { return bps ; }
int getStereo () const { return stereo ; }
float getDuration () const { return (float) getLength() /
(float) ( (getStereo()?2.0f:1.0f)*
(getBps()/8.0f)*getRate() ) ; }
int loadFile ( const char *fname ) ;
int loadRawFile ( const char *fname ) ;
int loadAUFile ( const char *fname ) ;
int loadWavFile ( const char *fname ) ;
void changeRate ( int r ) ;
void changeBps ( int b ) ;
void changeStereo ( int s ) ;
void changeToUnsigned () ;
void adjustVolume ( float vol ) ;
void print ( FILE *fd ) const
{
if ( buffer == NULL )
{
fprintf ( fd, "Empty sample buffer\n" ) ;
}
else
{
fprintf ( fd, "\"%s\"\n",(getComment() == NULL ||
getComment()[0]=='\0') ? "Sample" : comment ) ;
fprintf ( fd, "%s, %d bits per sample.\n",
getStereo() ? "Stereo" : "Mono", getBps() ) ;
fprintf ( fd, "%gKHz sample rate.\n", (float) getRate() / 1000.0f ) ;
fprintf ( fd, "%d bytes of samples == %g seconds duration.\n", getLength(), getDuration() ) ;
}
}
} ;
enum slSampleStatus
{
SL_SAMPLE_WAITING, /* Sound hasn't started playing yet */
SL_SAMPLE_RUNNING, /* Sound has started playing */
SL_SAMPLE_DONE , /* Sound is complete */
SL_SAMPLE_PAUSED /* Sound hasn't started playing yet */
} ;
enum slPreemptMode
{
SL_SAMPLE_CONTINUE, /* Don't allow yourself to be preempted */
SL_SAMPLE_ABORT , /* Abort playing the sound when preempted */
SL_SAMPLE_RESTART , /* Restart the sound when load permits */
SL_SAMPLE_MUTE , /* Continue silently until load permits */
SL_SAMPLE_DELAY /* Pause until load permits */
} ;
enum slReplayMode
{
SL_SAMPLE_LOOP, /* Loop sound so that it plays forever */
SL_SAMPLE_ONE_SHOT /* Play sound just once */
} ;
enum slEvent
{
SL_EVENT_COMPLETE, /* Sound finished playing */
SL_EVENT_LOOPED, /* Sound looped back to the start */
SL_EVENT_PREEMPTED /* Sound was preempted */
} ;
typedef void (*slCallBack) ( slSample *, slEvent, int ) ;
class slEnvelope
{
protected:
float *time ;
float *value ;
int nsteps ;
int ref_count ;
float previous_value ;
unsigned char prev_pitchenv ;
slReplayMode replay_mode ;
int getStepDelta ( float *_time, float *delta ) const ;
public:
slEnvelope ( int _nsteps, slReplayMode _rm, float *_times, float *_values )
{
ref_count = 0 ;
nsteps = _nsteps ;
time = new float [ nsteps ] ;
value = new float [ nsteps ] ;
memcpy ( time , _times , sizeof(float) * nsteps ) ;
memcpy ( value, _values, sizeof(float) * nsteps ) ;
prev_pitchenv = 0x80 ;
previous_value = 0.0f ;
replay_mode = _rm ;
}
slEnvelope ( int _nsteps = 1, slReplayMode _rm = SL_SAMPLE_ONE_SHOT )
{
ref_count = 0 ;
nsteps = _nsteps ;
time = new float [ nsteps ] ;
value = new float [ nsteps ] ;
prev_pitchenv = 0x80 ;
previous_value = 0.0f ;
for ( int i = 0 ; i < nsteps ; i++ )
time [ i ] = value [ i ] = 0.0 ;
replay_mode = _rm ;
}
~slEnvelope ()
{
if ( ref_count != 0 && __slPendingError == NULL )
__slPendingError =
"slEnvelope: FATAL ERROR - Application deleted an envelope while it was playing.\n" ;
delete [] time ;
delete [] value ;
}
void ref () { ref_count++ ; }
void unRef () { ref_count-- ; }
int getPlayCount () const { return ref_count ; }
void applyToLPFilter ( unsigned char *dst,
unsigned char *src,
int nframes, int start ) ;
void setStep ( int n, float _time, float _value )
{
if ( n >= 0 && n < nsteps )
{
time [ n ] = _time ;
value [ n ] = _value ;
}
}
float getStepValue ( int s ) const { return value [ s ] ; }
float getStepTime ( int s ) const { return time [ s ] ; }
int getNumSteps () const { return nsteps ; }
float getValue ( float _time ) const ;
void applyToPitch ( Uchar *dst, slPlayer *src, int nframes, int start, int next_env ) ;
void applyToInvPitch ( Uchar *dst, slPlayer *src, int nframes, int start, int next_env ) ;
void applyToVolume ( Uchar *dst, Uchar *src, int nframes, int start ) ;
void applyToInvVolume ( Uchar *dst, Uchar *src, int nframes, int start ) ;
} ;
#define SL_MAX_PRIORITY 16
#define SL_MAX_SAMPLES 32
#define SL_MAX_CALLBACKS (SL_MAX_SAMPLES * 2)
#define SL_MAX_ENVELOPES 32
#define SL_MAX_MIXERINPUTS 16
enum slEnvelopeType
{
SL_PITCH_ENVELOPE , SL_INVERSE_PITCH_ENVELOPE ,
SL_VOLUME_ENVELOPE, SL_INVERSE_VOLUME_ENVELOPE,
SL_FILTER_ENVELOPE, SL_INVERSE_FILTER_ENVELOPE,
SL_PAN_ENVELOPE , SL_INVERSE_PAN_ENVELOPE ,
SL_ECHO_ENVELOPE , SL_INVERSE_ECHO_ENVELOPE ,
SL_NULL_ENVELOPE
} ;
struct slPendingCallBack
{
slCallBack callback ;
slSample *sample ;
slEvent event ;
int magic ;
} ;
class slPlayer
{
protected:
slEnvelope *env [ SL_MAX_ENVELOPES ] ;
slEnvelopeType env_type [ SL_MAX_ENVELOPES ] ;
int env_start_time [ SL_MAX_ENVELOPES ] ;
slReplayMode replay_mode ;
slPreemptMode preempt_mode ;
slSampleStatus status ;
int priority ;
slCallBack callback ;
int magic ;
virtual void low_read ( int nframes, Uchar *dest ) = 0 ;
virtual void skip ( int nframes ) = 0 ;
public:
slPlayer ( slReplayMode rp_mode = SL_SAMPLE_ONE_SHOT,
int pri = 0, slPreemptMode pr_mode = SL_SAMPLE_DELAY,
int _magic = 0, slCallBack cb = NULL )
{
magic = _magic ;
callback = cb ;
for ( int i = 0 ; i < SL_MAX_ENVELOPES ; i++ )
{
env [ i ] = NULL ;
env_type [ i ] = SL_NULL_ENVELOPE ;
}
status = SL_SAMPLE_WAITING ;
replay_mode = rp_mode ;
preempt_mode = pr_mode ;
priority = pri ;
}
virtual ~slPlayer () ;
slPreemptMode getPreemptMode () const { return preempt_mode ; }
int getPriority () const
{
return ( isRunning() &&
preempt_mode == SL_SAMPLE_CONTINUE ) ? (SL_MAX_PRIORITY+1) :
priority ;
}
void addEnvelope ( int i, slEnvelope *_env, slEnvelopeType _type ) ;
virtual void pause ()
{
if ( status != SL_SAMPLE_DONE )
status = SL_SAMPLE_PAUSED ;
}
virtual void resume ()
{
if ( status == SL_SAMPLE_PAUSED )
status = SL_SAMPLE_RUNNING ;
}
virtual void reset ()
{
status = SL_SAMPLE_WAITING ;
}
virtual void start ()
{
status = SL_SAMPLE_RUNNING ;
}
virtual void stop ()
{
status = SL_SAMPLE_DONE ;
}
int getMagic () const { return magic ; }
int isWaiting () const { return status == SL_SAMPLE_WAITING ; }
int isPaused () const { return status == SL_SAMPLE_PAUSED ; }
int isRunning () const { return status == SL_SAMPLE_RUNNING ; }
int isDone () const { return status == SL_SAMPLE_DONE ; }
virtual int preempt ( int delay ) ;
virtual slSample *getSample () const = 0 ;
void read ( int nframes, Uchar *dest, int next_env = 0 ) ;
} ;
class MODfile ;
class slMODPlayer : public slPlayer
{
MODfile *mf ;
void low_read ( int nframes, Uchar *dest ) ;
void init ( const char *fname ) ;
public:
slMODPlayer ( const char *fname, slReplayMode rp_mode = SL_SAMPLE_ONE_SHOT,
int pri = 0, slPreemptMode pr_mode = SL_SAMPLE_DELAY,
int _magic = 0, slCallBack cb = NULL ) :
slPlayer ( rp_mode, pri, pr_mode, _magic, cb )
{
init ( fname ) ;
reset () ;
}
~slMODPlayer () ;
int preempt ( int delay ) ;
virtual slSample *getSample () const { return NULL ; }
void skip ( int nframes ) ;
} ;
class slSamplePlayer : public slPlayer
{
int lengthRemaining ; /* Sample frames remaining until repeat */
Uchar *bufferPos ; /* Sample frame to replay next */
slSample *sample ;
void low_read ( int nframes, Uchar *dest ) ;
public:
slSamplePlayer ( slSample *s, slReplayMode rp_mode = SL_SAMPLE_ONE_SHOT,
int pri = 0, slPreemptMode pr_mode = SL_SAMPLE_DELAY,
int _magic = 0, slCallBack cb = NULL ) :
slPlayer ( rp_mode, pri, pr_mode, _magic, cb )
{
sample = s ;
if ( sample ) sample -> ref () ;
reset () ;
}
~slSamplePlayer () ;
int preempt ( int delay ) ;
void reset ()
{
slPlayer::reset () ;
lengthRemaining = sample->getLength () ;
bufferPos = sample->getBuffer () ;
}
void start ()
{
slPlayer::start () ;
lengthRemaining = sample->getLength () ;
bufferPos = sample->getBuffer () ;
}
void stop ()
{
slPlayer::stop () ;
lengthRemaining = 0 ;
bufferPos = NULL ;
}
slSample *getSample () const { return sample ; }
void skip ( int nframes ) ;
} ;
class slScheduler : public slDSP
{
slPendingCallBack pending_callback [ SL_MAX_CALLBACKS ] ;
int num_pending_callbacks ;
float safety_margin ;
int mixer_buffer_size, mixer_gain ;
float seconds_per_buffer;
Uchar *mixer_buffer ;
Uchar *mixer_inputs [ SL_MAX_MIXERINPUTS + 1 ] ;
Uchar *mixer ;
int amount_left ;
slPlayer *player [ SL_MAX_SAMPLES ] ;
slPlayer *music ;
void init () ;
void realUpdate ( int dump_first = SL_FALSE ) ;
void initBuffers () ;
int now ;
static slScheduler *current ;
public:
slScheduler ( int _rate = SL_DEFAULT_SAMPLING_RATE ) : slDSP ( _rate, SL_FALSE, 8 ) { init () ; }
slScheduler ( const char *device,
int _rate = SL_DEFAULT_SAMPLING_RATE ) : slDSP ( device, _rate, SL_FALSE, 8 ) { init () ; }
~slScheduler () ;
static slScheduler *getCurrent () { return current ; }
int getTimeNow () const { return now ; }
float getElapsedTime ( int then ) const { return (float)(now-then)/(float)getRate() ; }
void setMaxConcurrent ( int mc );
int getMaxConcurrent () const ;
void flushCallBacks () ;
void addCallBack ( slCallBack c, slSample *s, slEvent e, int m ) ;
void update () { realUpdate ( SL_FALSE ) ; }
void dumpUpdate () { realUpdate ( SL_TRUE ) ; }
void resumeSample ( slSample *s = NULL, int magic = 0 ) ;
void resumeMusic ( int magic = 0 ) ;
void pauseSample ( slSample *s = NULL, int magic = 0 ) ;
void pauseMusic ( int magic = 0 ) ;
void stopSample ( slSample *s = NULL, int magic = 0 ) ;
void stopMusic ( int magic = 0 ) ;
void addSampleEnvelope ( slSample *s = NULL, int magic = 0,
int slot = 1, slEnvelope *e = NULL,
slEnvelopeType t = SL_VOLUME_ENVELOPE ) ;
void addMusicEnvelope ( int magic = 0,
int slot = 1, slEnvelope *e = NULL,
slEnvelopeType t = SL_VOLUME_ENVELOPE ) ;
int loopSample ( slSample *s, int pri = 0,
slPreemptMode mode = SL_SAMPLE_MUTE,
int magic = 0, slCallBack cb = NULL ) ;
int loopMusic ( const char *fname, int pri = 0,
slPreemptMode mode = SL_SAMPLE_MUTE,
int magic = 0, slCallBack cb = NULL ) ;
int playSample ( slSample *s, int pri = 1,
slPreemptMode mode = SL_SAMPLE_ABORT,
int magic = 0, slCallBack cb = NULL ) ;
int playMusic ( const char *fname, int pri = 1,
slPreemptMode mode = SL_SAMPLE_ABORT,
int magic = 0, slCallBack cb = NULL ) ;
void setSafetyMargin ( float seconds ) { safety_margin = seconds ; }
} ;
#endif
|